Fix InsetCaption in RTL environment.

This requires to add a new mutable member, rtl_, to remember this context.

Part of bug #10531.
This commit is contained in:
Jean-Marc Lasgouttes 2021-01-26 17:55:09 +01:00
parent 81f757f364
commit bb8278e6ce
2 changed files with 16 additions and 4 deletions

View File

@ -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;
}

View File

@ -96,6 +96,8 @@ private:
///
mutable int labelwidth_ = 0;
///
mutable bool rtl_ = false;
///
std::string floattype_;
///
bool is_subfloat_ = false;