drawinglayer/source/primitive2d/textlayoutdevice.cxx  |   52 ++++++++++---
 drawinglayer/source/processor2d/vclprocessor2d.cxx    |   30 ++++++-
 emfio/qa/cppunit/emf/EmfImportTest.cxx                |   50 +++++-------
 include/drawinglayer/primitive2d/textlayoutdevice.hxx |    2 
 svgio/qa/cppunit/SvgImportTest.cxx                    |   70 +++++++++---------
 svgio/source/svgreader/svgcharacternode.cxx           |   28 ++++---
 6 files changed, 144 insertions(+), 88 deletions(-)

New commits:
commit cc3663bbaed4f65d64154e5f9abb51a5f622f710
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Apr 16 10:48:06 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Apr 20 11:28:34 2024 +0200

    tdf#160702: improve text positioning
    
    Opening an SVG with text in different elements (e.g., tspans) in the
    same text element performs calculations to position the parts properly
    (i.e., the next part will start where the previous part ended, unless
    the position in overridden explicitly). These calculations require to
    know the text widths. The first problem leas here: the text width was
    calculated for a typically small text size (numerically equal to the
    pixel size defined in the SVG), but these calculations aren't truly
    linear, because font rendering may change depending on font height.
    Additionally, the rounding gives much higher error in smaller sizes
    than in larger. There was already a workaround for a similar problem
    in ViewRedirector::createRedirectedPrimitive2DSequence, where a large
    font (with 100 times greater height) was used to increase correctness.
    This was also used here, with the same large height (50000) used as a
    reference.
    
    Then, at the time of wrawing the text at different zoom levels, the
    code in VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D
    creates a font of a calculated size, and uses it to output the text.
    But the font is always created with an integral height, which means,
    that for a wanted height of 2.5 (in a zoomed out view), the really
    used height will be 3, which is 20% larger; or for wanted height of
    2.4, the actual height will be 2 (20% smaller). This resulted in odd
    jumps of the text widths, when the text may overlap the following
    part, or conversely, create a big gap before the next gap. To try to
    mitigate that, the function now takes the difference between the
    wanted and the actual font size into account, and adjusts the MapMode
    accordingly. This doesn't fix the jumping completely (e.g., because
    of the mentioned special handling of small font sizes in the fonts
    thenselves, like hinting), but still makes the calculations much more
    stable, decreasing the amount of jumping. Similar changes are made in
    TextLayouterDevice.
    
    Use of the functions that return text size as a double, not rounded
    value, should additionally help improving stability.
    
    Change-Id: I455845d8ca43ee9c06a0fc980947f35d8a25797a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166238
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/drawinglayer/source/primitive2d/textlayoutdevice.cxx 
b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
index 5145d84ed2b6..cb3af255fd0e 100644
--- a/drawinglayer/source/primitive2d/textlayoutdevice.cxx
+++ b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
@@ -22,6 +22,8 @@
 #include <algorithm>
 
 #include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
 #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
 #include <comphelper/processfactory.hxx>
@@ -162,56 +164,69 @@ TextLayouterDevice::TextLayouterDevice()
 
 TextLayouterDevice::~TextLayouterDevice() COVERITY_NOEXCEPT_FALSE { 
releaseGlobalVirtualDevice(); }
 
-void TextLayouterDevice::setFont(const vcl::Font& rFont) { 
mrDevice.SetFont(rFont); }
+void TextLayouterDevice::setFont(const vcl::Font& rFont)
+{
+    mrDevice.SetFont(rFont);
+    mnFontScalingFixX = 1.0;
+    mnFontScalingFixY = 1.0;
+}
 
 void TextLayouterDevice::setFontAttribute(const attribute::FontAttribute& 
rFontAttribute,
                                           double fFontScaleX, double 
fFontScaleY,
                                           const css::lang::Locale& rLocale)
 {
-    setFont(getVclFontFromFontAttribute(rFontAttribute, fFontScaleX, 
fFontScaleY, 0.0, rLocale));
+    vcl::Font aFont
+        = getVclFontFromFontAttribute(rFontAttribute, fFontScaleX, 
fFontScaleY, 0.0, rLocale);
+    setFont(aFont);
+    Size aFontSize = aFont.GetFontSize();
+    mnFontScalingFixY = fFontScaleY / aFontSize.Height();
+    mnFontScalingFixX = fFontScaleX / (aFontSize.Width() ? aFontSize.Width() : 
aFontSize.Height());
 }
 
 double TextLayouterDevice::getOverlineOffset() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
     double fRet = (rMetric.GetInternalLeading() / 2.0) - rMetric.GetAscent();
-    return fRet;
+    return fRet * mnFontScalingFixY;
 }
 
 double TextLayouterDevice::getUnderlineOffset() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
     double fRet = rMetric.GetDescent() / 2.0;
-    return fRet;
+    return fRet * mnFontScalingFixY;
 }
 
 double TextLayouterDevice::getStrikeoutOffset() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
     double fRet = (rMetric.GetAscent() - rMetric.GetInternalLeading()) / 3.0;
-    return fRet;
+    return fRet * mnFontScalingFixY;
 }
 
 double TextLayouterDevice::getOverlineHeight() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
     double fRet = rMetric.GetInternalLeading() / 2.5;
-    return fRet;
+    return fRet * mnFontScalingFixY;
 }
 
 double TextLayouterDevice::getUnderlineHeight() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
     double fRet = rMetric.GetDescent() / 4.0;
-    return fRet;
+    return fRet * mnFontScalingFixY;
 }
 
-double TextLayouterDevice::getTextHeight() const { return 
mrDevice.GetTextHeight(); }
+double TextLayouterDevice::getTextHeight() const
+{
+    return mrDevice.GetTextHeightDouble() * mnFontScalingFixY;
+}
 
 double TextLayouterDevice::getTextWidth(const OUString& rText, sal_uInt32 
nIndex,
                                         sal_uInt32 nLength) const
 {
-    return mrDevice.GetTextWidth(rText, nIndex, nLength);
+    return mrDevice.GetTextWidthDouble(rText, nIndex, nLength) * 
mnFontScalingFixX;
 }
 
 void TextLayouterDevice::getTextOutlines(basegfx::B2DPolyPolygonVector& 
rB2DPolyPolyVector,
@@ -245,6 +260,13 @@ void 
TextLayouterDevice::getTextOutlines(basegfx::B2DPolyPolygonVector& rB2DPoly
     {
         mrDevice.GetTextOutlines(rB2DPolyPolyVector, rText, nIndex, nIndex, 
nLength);
     }
+    if (!rtl_math_approxEqual(mnFontScalingFixY, 1.0)
+        || !rtl_math_approxEqual(mnFontScalingFixX, 1.0))
+    {
+        auto scale = 
basegfx::utils::createScaleB2DHomMatrix(mnFontScalingFixX, mnFontScalingFixY);
+        for (auto& poly : rB2DPolyPolyVector)
+            poly.transform(scale);
+    }
 }
 
 basegfx::B2DRange TextLayouterDevice::getTextBoundRect(const OUString& rText, 
sal_uInt32 nIndex,
@@ -262,6 +284,12 @@ basegfx::B2DRange 
TextLayouterDevice::getTextBoundRect(const OUString& rText, sa
     {
         basegfx::B2DRange aRect;
         mrDevice.GetTextBoundRect(aRect, rText, nIndex, nIndex, nLength);
+        if (!rtl_math_approxEqual(mnFontScalingFixY, 1.0)
+            || !rtl_math_approxEqual(mnFontScalingFixX, 1.0))
+        {
+            aRect.transform(
+                basegfx::utils::createScaleB2DHomMatrix(mnFontScalingFixX, 
mnFontScalingFixY));
+        }
         return aRect;
     }
 
@@ -271,13 +299,13 @@ basegfx::B2DRange 
TextLayouterDevice::getTextBoundRect(const OUString& rText, sa
 double TextLayouterDevice::getFontAscent() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
-    return rMetric.GetAscent();
+    return rMetric.GetAscent() * mnFontScalingFixY;
 }
 
 double TextLayouterDevice::getFontDescent() const
 {
     const ::FontMetric& rMetric = mrDevice.GetFontMetric();
-    return rMetric.GetDescent();
+    return rMetric.GetDescent() * mnFontScalingFixY;
 }
 
 void TextLayouterDevice::addTextRectActions(const ::tools::Rectangle& 
rRectangle,
@@ -305,7 +333,7 @@ std::vector<double> TextLayouterDevice::getTextArray(const 
OUString& rText, sal_
         mrDevice.GetTextArray(rText, &aArray, nIndex, nTextLength, bCaret);
         aRetval.reserve(aArray.size());
         for (size_t i = 0, nEnd = aArray.size(); i < nEnd; ++i)
-            aRetval.push_back(aArray[i]);
+            aRetval.push_back(aArray[i] * mnFontScalingFixX);
     }
 
     return aRetval;
diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx 
b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index a65a295d5758..0c5f70bb530b 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -180,7 +180,8 @@ void 
VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(
             }
 
             // Don't draw fonts without height
-            if (aFont.GetFontHeight() <= 0)
+            Size aResultFontSize = aFont.GetFontSize();
+            if (aResultFontSize.Height() <= 0)
                 return;
 
             // set FillColor Attribute
@@ -408,8 +409,31 @@ void 
VclProcessor2D::RenderTextSimpleOrDecoratedPortionPrimitive2D(
             else
             {
                 const basegfx::B2DPoint aPoint(aLocalTransform * 
basegfx::B2DPoint(0.0, 0.0));
-                aStartPoint = 
Point(basegfx::fround<tools::Long>(aPoint.getX()),
-                                    
basegfx::fround<tools::Long>(aPoint.getY()));
+                double aPointX = aPoint.getX(), aPointY = aPoint.getY();
+
+                // aFont has an integer size; we must scale a bit for precision
+                double nFontScalingFixY = aFontScaling.getY() / 
aResultFontSize.Height();
+                double nFontScalingFixX = aFontScaling.getX()
+                                          / (aResultFontSize.Width() ? 
aResultFontSize.Width()
+                                                                     : 
aResultFontSize.Height());
+
+                if (!rtl_math_approxEqual(nFontScalingFixY, 1.0)
+                    || !rtl_math_approxEqual(nFontScalingFixX, 1.0))
+                {
+                    MapMode aMapMode = mpOutputDevice->GetMapMode();
+                    aMapMode.SetScaleX(aMapMode.GetScaleX() * 
nFontScalingFixX);
+                    aMapMode.SetScaleY(aMapMode.GetScaleY() * 
nFontScalingFixY);
+
+                    mpOutputDevice->Push(vcl::PushFlags::MAPMODE);
+                    mpOutputDevice->SetRelativeMapMode(aMapMode);
+                    bChangeMapMode = true;
+
+                    aPointX /= nFontScalingFixX;
+                    aPointY /= nFontScalingFixY;
+                }
+
+                aStartPoint = Point(basegfx::fround<tools::Long>(aPointX),
+                                    basegfx::fround<tools::Long>(aPointY));
             }
 
             // tdf#152990 set the font after the MapMode is (potentially) set 
so canvas uses the desired
diff --git a/include/drawinglayer/primitive2d/textlayoutdevice.hxx 
b/include/drawinglayer/primitive2d/textlayoutdevice.hxx
index 6f98b50a4f06..db019494a8c0 100644
--- a/include/drawinglayer/primitive2d/textlayoutdevice.hxx
+++ b/include/drawinglayer/primitive2d/textlayoutdevice.hxx
@@ -63,6 +63,8 @@ class DRAWINGLAYER_DLLPUBLIC TextLayouterDevice
     /// internally used VirtualDevice
     SolarMutexGuard maSolarGuard;
     VirtualDevice& mrDevice;
+    double mnFontScalingFixX = 1.0;
+    double mnFontScalingFixY = 1.0;
 
 public:
     /// constructor/destructor
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx 
b/svgio/qa/cppunit/SvgImportTest.cxx
index 03daa49ff9b1..93921d1b4cb0 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -787,12 +787,12 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf93583)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"width"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"height"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"text"_ostr, " first");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "127");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "129");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "303");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"width"_ostr, "32");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"height"_ostr, "32");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"text"_ostr, " line");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"x"_ostr, "187");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"x"_ostr, "188");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"y"_ostr, "303");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"width"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"height"_ostr, "16");
@@ -806,7 +806,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156616)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"x"_ostr, "114");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"y"_ostr, "103");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"text"_ostr, " line");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "142");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "143");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "103");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"text"_ostr, "Second line");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]"_ostr, 
"x"_ostr, "114");
@@ -815,7 +815,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156616)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]"_ostr, 
"x"_ostr, "87");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]"_ostr, 
"y"_ostr, "153");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]"_ostr, 
"text"_ostr, " line");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]"_ostr, 
"x"_ostr, "115");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]"_ostr, 
"x"_ostr, "116");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]"_ostr, 
"y"_ostr, "153");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]"_ostr, 
"text"_ostr, "Second line");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]"_ostr, 
"x"_ostr, "77");
@@ -824,7 +824,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156616)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]"_ostr, 
"x"_ostr, "59");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]"_ostr, 
"y"_ostr, "203");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]"_ostr, 
"text"_ostr, " line");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]"_ostr, 
"x"_ostr, "87");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]"_ostr, 
"x"_ostr, "88");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]"_ostr, 
"y"_ostr, "203");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]"_ostr, 
"text"_ostr, "Second line");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]"_ostr, 
"x"_ostr, "40");
@@ -1367,11 +1367,11 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf95400)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"x"_ostr, "30");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"y"_ostr, "20");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"text"_ostr, "ABC");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx0"_ostr, "36");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx1"_ostr, "69");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx2"_ostr, "102");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx0"_ostr, 36, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx1"_ostr, 69, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx2"_ostr, 102, 0.5);
 
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"width"_ostr, "48");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"width"_ostr, "50");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"height"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "30");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "30");
@@ -1427,7 +1427,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTextAnchor)
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[11]"_ostr, "y"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[11]"_ostr, "text"_ostr, "B");
 
-    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[12]"_ostr, "x"_ostr, "83");
+    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[12]"_ostr, "x"_ostr, "82");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[12]"_ostr, "y"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[12]"_ostr, "text"_ostr, "C");
 
@@ -1442,7 +1442,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTextAnchor)
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[14]"_ostr, "y"_ostr, "50");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[14]"_ostr, "text"_ostr, "B");
 
-    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[15]"_ostr, "x"_ostr, "66");
+    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[15]"_ostr, "x"_ostr, "65");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[15]"_ostr, "y"_ostr, "50");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[15]"_ostr, "text"_ostr, "C");
 
@@ -1454,7 +1454,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTextAnchor)
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[17]"_ostr, "y"_ostr, "60");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[17]"_ostr, "text"_ostr, "B");
 
-    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[18]"_ostr, "x"_ostr, "49");
+    assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[18]"_ostr, "x"_ostr, "48");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[18]"_ostr, "y"_ostr, "60");
     assertXPath(pDocument, 
"/primitive2D/transform/textsimpleportion[18]"_ostr, "text"_ostr, "C");
 }
@@ -1479,9 +1479,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156577)
     // Without the fix in place, this test would have failed with
     // - Expected: 22
     // - Actual  : 52
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx0"_ostr, "22");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx1"_ostr, "53");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx2"_ostr, "94");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx0"_ostr, 22, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx1"_ostr, 52, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx2"_ostr, 93, 0.5);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf156283)
@@ -1493,9 +1493,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156283)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"x"_ostr, "30");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"y"_ostr, "20");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"text"_ostr, "ABC");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx0"_ostr, "41");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx1"_ostr, "52");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx2"_ostr, "63");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx0"_ostr, 41, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx1"_ostr, 52, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx2"_ostr, 62, 0.5);
 
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"width"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"height"_ostr, "16");
@@ -1506,9 +1506,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156283)
     // Without the fix in place, this test would have failed with
     // - Expected: 41
     // - Actual  : 12
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx0"_ostr, "41");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx1"_ostr, "52");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx2"_ostr, "63");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx0"_ostr, 41, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx1"_ostr, 51, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx2"_ostr, 62, 0.5);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf156569)
@@ -1520,22 +1520,22 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156569)
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"x"_ostr, "0");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"y"_ostr, "20");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"text"_ostr, "ABC");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx0"_ostr, "40");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx1"_ostr, "80");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]"_ostr, 
"dx2"_ostr, "91");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx0"_ostr, 40, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx1"_ostr, 80, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[1]"_ostr, "dx2"_ostr, 91, 0.5);
 
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"width"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"height"_ostr, "16");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"x"_ostr, "0");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "30");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"text"_ostr, "ABC");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx0"_ostr, "40");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx0"_ostr, 40, 0.5);
 
     // Without the fix in place, this test would have failed with
     // - Expected: 80
     // - Actual  : 51
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx1"_ostr, "80");
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"dx2"_ostr, "91");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/textsimpleportion[2]"_ostr, "dx2"_ostr, 91, 0.5);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf156837)
@@ -1552,7 +1552,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156837)
     // Without the fix in place, this test would have failed with
     // - Expected: 94
     // - Actual  : 103
-    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "95");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"y"_ostr, "94");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"height"_ostr, "10");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, 
"text"_ostr, " 3");
 }
@@ -1566,8 +1566,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156271)
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "x"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "y"_ostr, "10");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "text"_ostr, "AB");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "dx0"_ostr, "-30");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "dx1"_ostr, "-19");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "dx0"_ostr, -30, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[1]"_ostr, "dx1"_ostr, -19, 0.5);
 
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "width"_ostr, "16");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "height"_ostr, "16");
@@ -1578,24 +1578,24 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156271)
     // Without the fix in place, this test would have failed with
     // - Expected: -30
     // - Actual  : 0
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "dx0"_ostr, "-30");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "dx1"_ostr, "-19");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "dx0"_ostr, -30, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[2]"_ostr, "dx1"_ostr, -19, 0.5);
 
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "width"_ostr, "16");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "height"_ostr, "16");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "x"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "y"_ostr, "30");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "text"_ostr, "AB");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "dx0"_ostr, "-30");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "dx1"_ostr, "-19");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "dx0"_ostr, -30, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[3]"_ostr, "dx1"_ostr, -19, 0.5);
 
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "width"_ostr, "16");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "height"_ostr, "16");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "x"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "y"_ostr, "40");
     assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "text"_ostr, "AB");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "dx0"_ostr, "12");
-    assertXPath(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "dx1"_ostr, "23");
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "dx0"_ostr, 12, 0.5);
+    assertXPathDoubleValue(pDocument, 
"/primitive2D/transform/mask/textsimpleportion[4]"_ostr, "dx1"_ostr, 22, 0.5);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf159968)
diff --git a/svgio/source/svgreader/svgcharacternode.cxx 
b/svgio/source/svgreader/svgcharacternode.cxx
index 02bc3911a3b8..7fdac9e92bc5 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -138,11 +138,11 @@ namespace svgio::svgreader
         {
             // prepare retval, index and length
             rtl::Reference<BasePrimitive2D> pRetval;
-            sal_uInt32 nLength(getText().getLength());
+            const sal_uInt32 nLength(getText().getLength());
 
             if(nLength)
             {
-                sal_uInt32 nIndex(0);
+                const sal_uInt32 nIndex(0);
 
                 // prepare FontAttribute
                 const drawinglayer::attribute::FontAttribute 
aFontAttribute(getFontAttribute(rSvgStyleAttributes));
@@ -154,9 +154,12 @@ namespace svgio::svgreader
                 // prepare locale
                 css::lang::Locale aLocale;
 
-                // prepare TextLayouterDevice
+                // prepare TextLayouterDevice; use a larger font size for more 
linear size
+                // calculations. Similar to nTextSizeFactor in 
sd/source/ui/view/sdview.cxx
+                // (ViewRedirector::createRedirectedPrimitive2DSequence).
+                const double sizeFactor = fFontHeight < 50000 ? 50000 / 
fFontHeight : 1.0;
                 TextLayouterDevice aTextLayouterDevice;
-                aTextLayouterDevice.setFontAttribute(aFontAttribute, 
fFontWidth, fFontHeight, aLocale);
+                aTextLayouterDevice.setFontAttribute(aFontAttribute, 
fFontWidth * sizeFactor, fFontHeight * sizeFactor, aLocale);
 
                 // prepare TextArray
                 ::std::vector< double > aTextArray(rSvgTextPosition.getX());
@@ -190,13 +193,13 @@ namespace svgio::svgreader
                         {
                             fComulativeDx += aDxArray[a];
                         }
-                        aTextArray.push_back(aExtendArray[a] + fStartX + 
fComulativeDx);
+                        aTextArray.push_back(aExtendArray[a] / sizeFactor + 
fStartX + fComulativeDx);
                     }
                 }
 
                 // get current TextPosition and TextWidth in units
                 basegfx::B2DPoint aPosition(rSvgTextPosition.getPosition());
-                double fTextWidth(aTextLayouterDevice.getTextWidth(getText(), 
nIndex, nLength));
+                double fTextWidth(aTextLayouterDevice.getTextWidth(getText(), 
nIndex, nLength) / sizeFactor);
 
                 // check for user-given TextLength
                 if(0.0 != rSvgTextPosition.getTextLength()
@@ -209,7 +212,10 @@ namespace svgio::svgreader
                         // spacing, need to create and expand TextArray
                         if(aTextArray.empty())
                         {
-                            aTextArray = 
aTextLayouterDevice.getTextArray(getText(), nIndex, nLength);
+                            auto 
aExtendArray(aTextLayouterDevice.getTextArray(getText(), nIndex, nLength));
+                            aTextArray.reserve(aExtendArray.size());
+                            for (auto n : aExtendArray)
+                                aTextArray.push_back(n / sizeFactor);
                         }
 
                         for(auto &a : aTextArray)
@@ -289,12 +295,12 @@ namespace svgio::svgreader
                     case DominantBaseline::Middle:
                     case DominantBaseline::Central:
                     {
-                        aPosition.setY(aPosition.getY() - aRange.getCenterY());
+                        aPosition.setY(aPosition.getY() - aRange.getCenterY() 
/ sizeFactor);
                         break;
                     }
                     case DominantBaseline::Hanging:
                     {
-                        aPosition.setY(aPosition.getY() - aRange.getMinY());
+                        aPosition.setY(aPosition.getY() - aRange.getMinY() / 
sizeFactor);
                         break;
                     }
                     default: // DominantBaseline::Auto
@@ -312,12 +318,12 @@ namespace svgio::svgreader
                 {
                     case BaselineShift::Sub:
                     {
-                        aPosition.setY(aPosition.getY() + 
aTextLayouterDevice.getUnderlineOffset());
+                        aPosition.setY(aPosition.getY() + 
aTextLayouterDevice.getUnderlineOffset() / sizeFactor);
                         break;
                     }
                     case BaselineShift::Super:
                     {
-                        aPosition.setY(aPosition.getY() + 
aTextLayouterDevice.getOverlineOffset());
+                        aPosition.setY(aPosition.getY() + 
aTextLayouterDevice.getOverlineOffset() / sizeFactor);
                         break;
                     }
                     case BaselineShift::Percentage:
commit cfa9990d470b10548c7fed64eb1182fea11d41e0
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Apr 20 12:02:58 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Apr 20 11:28:25 2024 +0200

    Enable this test on all platforms
    
    The original issue that prevented the test on Linux is reproducible.
    I didn't debug the cause, so this is just a workaround.
    
    Change-Id: Ifa8fa2a7884adabf797ea2d711f62b6be382dfec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166351
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx 
b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 53bfed56c5f2..8d6a52c5ade1 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -1398,47 +1398,43 @@ CPPUNIT_TEST_FIXTURE(Test, 
testExtTextOutOpaqueAndClipWMF)
     xmlDocUniquePtr pDocument = 
dumper.dumpAndParse(Primitive2DContainer(aSequence));
     CPPUNIT_ASSERT(pDocument);
 
-#ifdef MACOSX
     // On some operating systems (Linux on LO Jenkins CI), the `/mask/` string 
is not added to XPath
     // As a result tests are failing. On my Ubuntu 20.04 the `/mask/` string 
was added
-    // I would leave this test case for macOS to make sure there is no 
regression at least on one platform.
+
+    OString aPrefix = aXPathPrefix;
+    if (countXPathNodes(pDocument, aXPathPrefix + "mask"))
+        aPrefix += "mask/";
 
     // These values come from the fix for tdf#88163
-    assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor", 5);
-    assertXPath(pDocument, aXPathPrefix + 
"mask/polypolygoncolor[1]/polypolygon", "path"_ostr,
+    assertXPath(pDocument, aPrefix + "polypolygoncolor", 5);
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[1]/polypolygon", 
"path"_ostr,
                 "m7257 1836h320v3628h-320z");
-    assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor[1]", 
"color"_ostr, "#ff0000");
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[1]", "color"_ostr, 
"#ff0000");
 
-    assertXPath(pDocument, aXPathPrefix + 
"mask/polypolygoncolor[2]/polypolygon", "path"_ostr,
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[2]/polypolygon", 
"path"_ostr,
                 "m7257 5976h320v321h-320z");
-    assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor[2]", 
"color"_ostr, "#00ff00");
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[2]", "color"_ostr, 
"#00ff00");
 
-    assertXPath(pDocument, aXPathPrefix + 
"mask/polypolygoncolor[3]/polypolygon", "path"_ostr,
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[3]/polypolygon", 
"path"_ostr,
                 "m10203 5976h320v321h-320z");
-    assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor[3]", 
"color"_ostr, "#8080ff");
+    assertXPath(pDocument, aPrefix + "polypolygoncolor[3]", "color"_ostr, 
"#8080ff");
 
-    assertXPath(pDocument, aXPathPrefix + "mask/group", 5);
-    assertXPath(pDocument, aXPathPrefix + "mask/group[1]/polypolygoncolor", 
"color"_ostr,
-                "#00ff00");
-    assertXPath(pDocument, aXPathPrefix + "mask/group[1]/textsimpleportion", 
"text"_ostr, "ABCD");
-    assertXPath(pDocument, aXPathPrefix + "mask/group[1]/textsimpleportion", 
"fontcolor"_ostr,
-                "#000000");
+    assertXPath(pDocument, aPrefix + "group", 5);
+    assertXPath(pDocument, aPrefix + "group[1]/polypolygoncolor", 
"color"_ostr, "#00ff00");
+    assertXPath(pDocument, aPrefix + "group[1]/textsimpleportion", 
"text"_ostr, "ABCD");
+    assertXPath(pDocument, aPrefix + "group[1]/textsimpleportion", 
"fontcolor"_ostr, "#000000");
 
-    assertXPath(pDocument, aXPathPrefix + "mask/group[2]/polypolygoncolor", 
"color"_ostr,
-                "#8080ff");
-    assertXPath(pDocument, aXPathPrefix + "mask/group[2]/textsimpleportion", 
"text"_ostr, "MMMM");
-    assertXPath(pDocument, aXPathPrefix + "mask/group[2]/textsimpleportion", 
"fontcolor"_ostr,
-                "#000000");
+    assertXPath(pDocument, aPrefix + "group[2]/polypolygoncolor", 
"color"_ostr, "#8080ff");
+    assertXPath(pDocument, aPrefix + "group[2]/textsimpleportion", 
"text"_ostr, "MMMM");
+    assertXPath(pDocument, aPrefix + "group[2]/textsimpleportion", 
"fontcolor"_ostr, "#000000");
 
-    assertXPath(pDocument, aXPathPrefix + 
"mask/group[3]/mask/group/polypolygoncolor", "color"_ostr,
+    assertXPath(pDocument, aPrefix + "group[3]/mask/group/polypolygoncolor", 
"color"_ostr,
                 "#ff8000");
-    assertXPath(pDocument, aXPathPrefix + 
"mask/group[3]/mask/group/polypolygoncolor/polypolygon",
+    assertXPath(pDocument, aPrefix + 
"group[3]/mask/group/polypolygoncolor/polypolygon",
                 "path"_ostr, "m1067 1067h1317v473h-1317z");
-    assertXPath(pDocument, aXPathPrefix + 
"mask/group[3]/mask/group/textsimpleportion", "text"_ostr,
-                "OOOO");
-    assertXPath(pDocument, aXPathPrefix + 
"mask/group[3]/mask/group/textsimpleportion",
-                "fontcolor"_ostr, "#000000");
-#endif
+    assertXPath(pDocument, aPrefix + "group[3]/mask/group/textsimpleportion", 
"text"_ostr, "OOOO");
+    assertXPath(pDocument, aPrefix + "group[3]/mask/group/textsimpleportion", 
"fontcolor"_ostr,
+                "#000000");
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testPaletteWMF)

Reply via email to