svgio/qa/cppunit/SvgImportTest.cxx          |   12 ++++++++++++
 svgio/qa/cppunit/data/RTLtext.svg           |    6 ++++--
 svgio/source/svgreader/svgcharacternode.cxx |   12 ++++++++++--
 3 files changed, 26 insertions(+), 4 deletions(-)

New commits:
commit 4d9a323a83b4198289cf12cabfe1642ed0e9f0d8
Author:     Xisco Fauli <[email protected]>
AuthorDate: Tue Sep 16 10:40:27 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Tue Sep 16 15:28:30 2025 +0200

    tdf#168378: invert text anchor in RTL
    
    Change-Id: Ia9b7e526ab20cbcdb521f965a5a2dc0726894209
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191018
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/svgio/qa/cppunit/SvgImportTest.cxx 
b/svgio/qa/cppunit/SvgImportTest.cxx
index 24eeb8f562a9..1387ec6543c8 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -2132,6 +2132,18 @@ CPPUNIT_TEST_FIXTURE(Test, testRTLtext)
 
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", 
"text", u"داستان SVG 1.1 SE طولا ني است.");
     assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", 
"rtl", u"true");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "x", 
u"57");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "y", 
u"50");
+
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", 
"text", u"داستان SVG 1.2 SE طولا ني است.");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", 
"rtl", u"true");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "x", 
u"179");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "y", 
u"100");
+
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", 
"text", u"داستان SVG 1.3 SE طولا ني است.");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", 
"rtl", u"true");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "x", 
u"300");
+    assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "y", 
u"150");
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testCssClassRedefinition)
diff --git a/svgio/qa/cppunit/data/RTLtext.svg 
b/svgio/qa/cppunit/data/RTLtext.svg
index f360fc559dc6..40dff70d904e 100644
--- a/svgio/qa/cppunit/data/RTLtext.svg
+++ b/svgio/qa/cppunit/data/RTLtext.svg
@@ -1,7 +1,9 @@
 <svg
-  viewBox="0 0 600 72"
+  width="600 px" height="600 px"
   xmlns="http://www.w3.org/2000/svg";
   direction="rtl"
   font-family="DejaVu Sans">
-  <text x="300" y="50" text-anchor="middle">داستان SVG 1.1 SE طولا ني 
است.</text>
+  <text x="300" y="50" text-anchor="start">داستان SVG 1.1 SE طولا ني 
است.</text>
+  <text x="300" y="100" text-anchor="middle">داستان SVG 1.2 SE طولا ني 
است.</text>
+  <text x="300" y="150" text-anchor="end">داستان SVG 1.3 SE طولا ني است.</text>
 </svg>
diff --git a/svgio/source/svgreader/svgcharacternode.cxx 
b/svgio/source/svgreader/svgcharacternode.cxx
index 9ce8f50ab67b..138e259bcbe7 100644
--- a/svgio/source/svgreader/svgcharacternode.cxx
+++ b/svgio/source/svgreader/svgcharacternode.cxx
@@ -240,6 +240,8 @@ namespace svgio::svgreader
             // get TextAlign
             TextAlign aTextAlign(rSvgStyleAttributes.getTextAlign());
 
+            bool bRTL(FontDirection::RTL == 
rSvgStyleAttributes.getFontDirection());
+
             // map TextAnchor to TextAlign, there seems not to be a difference
             if(TextAnchor::notset != rSvgStyleAttributes.getTextAnchor())
             {
@@ -247,7 +249,10 @@ namespace svgio::svgreader
                 {
                     case TextAnchor::start:
                     {
-                        aTextAlign = TextAlign::left;
+                        if (bRTL)
+                            aTextAlign = TextAlign::right;
+                        else
+                            aTextAlign = TextAlign::left;
                         break;
                     }
                     case TextAnchor::middle:
@@ -257,7 +262,10 @@ namespace svgio::svgreader
                     }
                     case TextAnchor::end:
                     {
-                        aTextAlign = TextAlign::right;
+                        if (bRTL)
+                            aTextAlign = TextAlign::left;
+                        else
+                            aTextAlign = TextAlign::right;
                         break;
                     }
                     default:

Reply via email to