commit bb8278e6ce1f0fbc90eb90d7357829ba3def17e1
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Tue Jan 26 17:55:09 2021 +0100

    Fix InsetCaption in RTL environment.
    
    This requires to add a new mutable member, rtl_, to remember this context.
    
    Part of bug #10531.
---
 src/insets/InsetCaption.cpp |   18 ++++++++++++++----
 src/insets/InsetCaption.h   |    2 ++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp
index f97fade..981ffa8 100644
--- a/src/insets/InsetCaption.cpp
+++ b/src/insets/InsetCaption.cpp
@@ -82,7 +82,8 @@ void InsetCaption::cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        InsetText::cursorPos(bv, sl, boundary, x, y);
-       x += labelwidth_;
+       if (!rtl_)
+               x += labelwidth_;
 }
 
 
@@ -133,6 +134,8 @@ void InsetCaption::drawBackground(PainterInfo & pi, int x, 
int y) const
        TextMetrics & tm = pi.base.bv->textMetrics(&text());
        int const h = tm.height() + topOffset(pi.base.bv) + 
bottomOffset(pi.base.bv);
        int const yy = y - topOffset(pi.base.bv) - tm.ascent();
+       if (rtl_)
+               x+= + dimension(*pi.base.bv).wid - labelwidth_;
        pi.pain.fillRectangle(x, yy, labelwidth_, h, pi.backgroundColor(this));
 }
 
@@ -147,6 +150,7 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) 
const
 
        // Answer: the text inset (in buffer_funcs.cpp: setCaption).
 
+       rtl_ = !pi.ltr_pos;
        FontInfo tmpfont = pi.base.font;
        pi.base.font = pi.base.bv->buffer().params().getFont().fontInfo();
        pi.base.font.setColor(pi.textColor(pi.base.font.color()).baseColor);
@@ -154,9 +158,15 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) 
const
                pi.base.font.setStrikeout(FONT_ON);
        else if (isChanged() && lyxrc.ct_additions_underlined)
                pi.base.font.setUnderbar(FONT_ON);
-       int const xx = x + leftOffset(pi.base.bv);
-       pi.pain.text(xx, y, full_label_, pi.base.font);
-       InsetText::draw(pi, x + labelwidth_, y);
+       int const lo = leftOffset(pi.base.bv);
+       if (rtl_) {
+               InsetText::draw(pi, x, y);
+               pi.pain.text(x + dimension(*pi.base.bv).wid - labelwidth_ + lo,
+                            y, full_label_, pi.base.font);
+       } else {
+               pi.pain.text(x + lo, y, full_label_, pi.base.font);
+               InsetText::draw(pi, x + labelwidth_, y);
+       }
        pi.base.font = tmpfont;
 }
 
diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h
index c5a7d08..ed6dbbb 100644
--- a/src/insets/InsetCaption.h
+++ b/src/insets/InsetCaption.h
@@ -96,6 +96,8 @@ private:
        ///
        mutable int labelwidth_ = 0;
        ///
+       mutable bool rtl_ = false;
+       ///
        std::string floattype_;
        ///
        bool is_subfloat_ = false;
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to