summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2021-06-24 18:58:39 +0200
committerBartosz Kosiorek <gang65@poczta.onet.pl>2021-07-01 23:50:31 +0200
commit574dc1e8ff6ea4214fefd91216fca5146a4ff13e (patch)
treefb64a4c43f46109af7b11c616e76af563f5606fe /drawinglayer
parenta1e03b970f49efbfacb7888d31ecd944750a5956 (diff)
EMF+ tdf#142995 tdf#142997 tdf#143076 Add alignment support for DrawString
With this commit, real size of the text is used to make proper horizontal alignment. Additionally vertical alignment is added and fix for Center alignment was applied Change-Id: I17d9fd7de7f00f5e69f99c5b09061eb6059be67e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117794 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx44
-rw-r--r--drawinglayer/source/tools/emfpstringformat.cxx8
2 files changed, 30 insertions, 22 deletions
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index b052c1551d69..dff19563002d 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -34,6 +34,7 @@
#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
+#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
#include <drawinglayer/primitive2d/textprimitive2d.hxx>
#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
@@ -1566,25 +1567,35 @@ namespace emfplushelper
css::lang::Locale locale;
double stringAlignmentHorizontalOffset = 0.0;
+ double stringAlignmentVerticalOffset = font->emSize;
if (stringFormat)
{
- SAL_WARN_IF(stringFormat->DirectionRightToLeft(), "drawinglayer.emf", "EMF+\t DrawString Alignment TODO For a right-to-left layout rectangle, the origin should be at the upper right.");
+ LanguageTag aLanguageTag(static_cast<LanguageType>(stringFormat->language));
+ locale = aLanguageTag.getLocale();
+ drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
+
+ aTextLayouter.setFontAttribute(fontAttribute, font->emSize,
+ font->emSize, locale);
+
+ double fTextWidth = aTextLayouter.getTextWidth(text, 0, stringLength);
+ SAL_WARN_IF(stringFormat->DirectionRightToLeft(), "drawinglayer.emf",
+ "EMF+\t DrawString Alignment TODO For a right-to-left layout rectangle, the origin should be at the upper right.");
if (stringFormat->stringAlignment == StringAlignmentNear)
- // Alignment is to the left side of the layout rectangle (lx, ly, lw, lh)
- {
+ // Alignment is to the left side of the layout rectangle (lx, ly, lw, lh)
stringAlignmentHorizontalOffset = stringFormat->leadingMargin * font->emSize;
- } else if (stringFormat->stringAlignment == StringAlignmentCenter)
- // Alignment is centered between the origin and extent of the layout rectangle
- {
- stringAlignmentHorizontalOffset = 0.5 * lw + stringFormat->leadingMargin * font->emSize - 0.3 * font->emSize * stringLength;
- } else if (stringFormat->stringAlignment == StringAlignmentFar)
- // Alignment is to the right side of the layout rectangle
- {
- stringAlignmentHorizontalOffset = lw - stringFormat->trailingMargin * font->emSize - 0.6 * font->emSize * stringLength;
- }
-
- LanguageTag aLanguageTag(static_cast< LanguageType >(stringFormat->language));
- locale = aLanguageTag.getLocale();
+ else if (stringFormat->stringAlignment == StringAlignmentCenter)
+ // Alignment is centered between the origin and extent of the layout rectangle
+ stringAlignmentHorizontalOffset = 0.5 * lw + (stringFormat->leadingMargin - stringFormat->trailingMargin) * font->emSize - 0.5 * fTextWidth;
+ else if (stringFormat->stringAlignment == StringAlignmentFar)
+ // Alignment is to the right side of the layout rectangle
+ stringAlignmentHorizontalOffset = lw - stringFormat->trailingMargin * font->emSize - fTextWidth;
+
+ if (stringFormat->lineAlign == StringAlignmentNear)
+ stringAlignmentVerticalOffset = font->emSize;
+ else if (stringFormat->lineAlign == StringAlignmentCenter)
+ stringAlignmentVerticalOffset = 0.5 * lh + 0.5 * font->emSize;
+ else if (stringFormat->lineAlign == StringAlignmentFar)
+ stringAlignmentVerticalOffset = lh;
}
else
{
@@ -1598,7 +1609,8 @@ namespace emfplushelper
const basegfx::B2DHomMatrix transformMatrix = basegfx::utils::createScaleTranslateB2DHomMatrix(
::basegfx::B2DSize(font->emSize, font->emSize),
- ::basegfx::B2DPoint(lx + stringAlignmentHorizontalOffset, ly + font->emSize));
+ ::basegfx::B2DPoint(lx + stringAlignmentHorizontalOffset,
+ ly + stringAlignmentVerticalOffset));
Color uncorrectedColor = EMFPGetBrushColorOrARGBColor(flags, brushId);
Color color;
diff --git a/drawinglayer/source/tools/emfpstringformat.cxx b/drawinglayer/source/tools/emfpstringformat.cxx
index 63cc42471b3b..071493c13062 100644
--- a/drawinglayer/source/tools/emfpstringformat.cxx
+++ b/drawinglayer/source/tools/emfpstringformat.cxx
@@ -217,18 +217,14 @@ namespace emfplushelper
SAL_INFO("drawinglayer.emf", "EMF+\t\tTabStopCount: " << tabStopCount);
SAL_INFO("drawinglayer.emf", "EMF+\t\tRangeCount: " << rangeCount);
- SAL_WARN_IF(stringAlignment != StringAlignment::StringAlignmentNear, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:StringAlignment");
- SAL_WARN_IF(lineAlign != StringAlignment::StringAlignmentNear, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:lineAlign");
SAL_WARN_IF(digitSubstitution != StringDigitSubstitution::StringDigitSubstitutionNone,
- "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:digitSubstitution");
+ "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:digitSubstitution");
SAL_WARN_IF(firstTabOffset != 0.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:firstTabOffset");
SAL_WARN_IF(hotkeyPrefix != HotkeyPrefix::HotkeyPrefixNone, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:hotkeyPrefix");
- SAL_WARN_IF(leadingMargin != 0.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:leadingMargin");
- SAL_WARN_IF(trailingMargin != 0.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:trailingMargin");
SAL_WARN_IF(tracking != 1.0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:tracking");
SAL_WARN_IF(trimming != StringTrimming::StringTrimmingNone, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:trimming");
SAL_WARN_IF(tabStopCount, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:tabStopCount");
- SAL_WARN_IF(rangeCount, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:StringFormatData");
+ SAL_WARN_IF(rangeCount != 0, "drawinglayer.emf", "EMF+\t TODO EMFPStringFormat:StringFormatData");
}
}