starmath/inc/visitors.hxx    |    2 +-
 starmath/source/document.cxx |   24 ++++++++++++++++++------
 starmath/source/visitors.cxx |    8 ++++----
 3 files changed, 23 insertions(+), 11 deletions(-)

New commits:
commit f80c2c70756e3620daed6675c8546caca4153d4b
Author:     Khaled Hosny <[email protected]>
AuthorDate: Tue Aug 29 20:51:06 2023 +0300
Commit:     خالد حسني <[email protected]>
CommitDate: Mon Sep 4 18:18:37 2023 +0200

    tdf#134193: Fix inline editing with RTL direction
    
    Change-Id: I65d3ed0d7c56839ce3674318144269719b043ba5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156261
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <[email protected]>

diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index c1a2a8983286..338e93432ba1 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -219,7 +219,7 @@ public:
         , maPosition( position )
         , mrFormat( rFormat )
     {
-        if (mrFormat.IsRightToLeft())
+        if (mrFormat.IsRightToLeft() && mrDev.GetOutDevType() != OUTDEV_WINDOW)
             mrDev.ReMirror(maPosition);
         pTree->Accept( this );
     }
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 9bdaad7530e6..8f8e184470a0 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -332,8 +332,10 @@ void SmDocShell::DrawFormula(OutputDevice &rDev, Point 
&rPosition, bool bDrawSel
     rPosition.AdjustY(maFormat.GetDistance( DIS_TOPSPACE  ) );
 
     Point aPosition(rPosition);
-    if (bRTL)
-        aPosition.AdjustX(GetSize().Width() - 
maFormat.GetDistance(DIS_LEFTSPACE) - maFormat.GetDistance(DIS_RIGHTSPACE));
+    if (bRTL && rDev.GetOutDevType() != OUTDEV_WINDOW)
+        aPosition.AdjustX(GetSize().Width()
+                          - maFormat.GetDistance(DIS_LEFTSPACE)
+                          - maFormat.GetDistance(DIS_RIGHTSPACE));
 
     //! in case of high contrast-mode (accessibility option!)
     //! the draw mode needs to be set to default, because when embedding
@@ -353,11 +355,21 @@ void SmDocShell::DrawFormula(OutputDevice &rDev, Point 
&rPosition, bool bDrawSel
               vcl::PushFlags::RTLENABLED);
 
     // We want the device to always be LTR, we handle RTL formulas ourselves.
-    rDev.EnableRTL(false);
+    if (rDev.GetOutDevType() == OUTDEV_WINDOW)
+        rDev.EnableRTL(bRTL);
+    else
+        rDev.EnableRTL(false);
 
-    // For RTL formulas, we want the brackets to be mirrored.
-    rDev.SetLayoutMode(bRTL ? vcl::text::ComplexTextLayoutFlags::BiDiRtl
-                            : vcl::text::ComplexTextLayoutFlags::Default);
+    auto nLayoutFlags = vcl::text::ComplexTextLayoutFlags::Default;
+    if (bRTL)
+    {
+        // For RTL formulas, we want the brackets to be mirrored.
+        nLayoutFlags |= vcl::text::ComplexTextLayoutFlags::BiDiRtl;
+        if (rDev.GetOutDevType() == OUTDEV_WINDOW)
+            nLayoutFlags |= vcl::text::ComplexTextLayoutFlags::TextOriginLeft;
+    }
+
+    rDev.SetLayoutMode(nLayoutFlags);
 
     // Numbers should not be converted, for now.
     rDev.SetDigitLanguage( LANGUAGE_ENGLISH );
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index cece754de276..732c27f9840f 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -438,7 +438,7 @@ void SmDrawingVisitor::Visit( SmRootSymbolNode* pNode )
 
     tools::Rectangle  aBar( aBarPos, Size( nBarWidth, nBarHeight ) );
 
-    if (mrFormat.IsRightToLeft())
+    if (mrFormat.IsRightToLeft() && mrDev.GetOutDevType() != OUTDEV_WINDOW)
         mrDev.ReMirror(aBar);
 
     //! avoid GROWING AND SHRINKING of drawn rectangle when constantly
@@ -465,7 +465,7 @@ void SmDrawingVisitor::Visit( SmPolyLineNode* pNode )
                    + Point( nBorderwidth, nBorderwidth ) ),
           aPos ( maPosition + aOffset );
 
-    if (mrFormat.IsRightToLeft())
+    if (mrFormat.IsRightToLeft() && mrDev.GetOutDevType() != OUTDEV_WINDOW)
         mrDev.ReMirror(aPos);
 
     pNode->GetPolygon( ).Move( aPos.X( ), aPos.Y( ) );    //Works because 
Polygon wraps a pointer
@@ -497,7 +497,7 @@ void SmDrawingVisitor::Visit( SmRectangleNode* pNode )
 
     SAL_WARN_IF( aTmp.IsEmpty(), "starmath", "Empty rectangle" );
 
-    if (mrFormat.IsRightToLeft())
+    if (mrFormat.IsRightToLeft() && mrDev.GetOutDevType() != OUTDEV_WINDOW)
         mrDev.ReMirror(aTmp);
 
     //! avoid GROWING AND SHRINKING of drawn rectangle when constantly
@@ -521,7 +521,7 @@ void SmDrawingVisitor::DrawTextNode( SmTextNode* pNode )
     Point  aPos ( maPosition );
     aPos.AdjustY(pNode->GetBaselineOffset( ) );
 
-    if (mrFormat.IsRightToLeft())
+    if (mrFormat.IsRightToLeft() && mrDev.GetOutDevType() != OUTDEV_WINDOW)
         mrDev.ReMirror(aPos);
 
     // round to pixel coordinate

Reply via email to