void GuiPainter::text(int x, int y, docstring const & s, FontInfo const & f)
{
- text(x, y, s, f, false, 0.0, 0.0);
+ text(x, y, s, f, Auto, 0.0, 0.0);
}
-void GuiPainter::do_drawText(int x, int y, QString str, bool rtl, FontInfo const & f, QFont ff)
+void GuiPainter::do_drawText(int x, int y, QString str,
+ GuiPainter::Direction const dir,
+ FontInfo const & f, QFont ff)
{
setQPainterPen(computeColor(f.realColor()));
if (font() != ff)
/* Use unicode override characters to enforce drawing direction
* Source: http://www.iamcal.com/understanding-bidirectional-text/
*/
- if (rtl)
+ if (dir == RtL)
// Right-to-left override: forces to draw text right-to-left
str = QChar(0x202E) + str;
- else
+ else if (dir == LtR)
// Left-to-right override: forces to draw text left-to-right
str = QChar(0x202D) + str;
drawText(x, y, str);
* Keep it here for now, in case it can be helpful
*/
//This is much stronger than setLayoutDirection.
- int flag = rtl ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
- drawText(x + (rtl ? textwidth : 0), y - fm.maxAscent(), 0, 0,
+ int flag = 0;
+ if (dir == RtL)
+ flag = Qt::TextForceRightToLeft;
+ else if (dir == LtR)
+ flag = Qt::TextForceLeftToRight;
+ drawText(x + ((dir == RtL) ? textwidth : 0), y - fm.maxAscent(), 0, 0,
flag | Qt::TextDontClip,
str);
#endif
void GuiPainter::text(int x, int y, docstring const & s,
- FontInfo const & f, bool const rtl,
+ FontInfo const & f, Direction const dir,
double const wordspacing, double const tw)
{
//LYXERR0("text: x=" << x << ", s=" << s);
#endif
pm.fill(Qt::transparent);
GuiPainter p(&pm, pixelRatio());
- p.do_drawText(-lb, mA, str, rtl, f, ff);
+ p.do_drawText(-lb, mA, str, dir, f, ff);
QPixmapCache::insert(key, pm);
//LYXERR(Debug::PAINTING, "h=" << h << " mA=" << mA << " mD=" << mD
// << " w=" << w << " lb=" << lb << " tw=" << textwidth
}
// don't use the pixmap cache,
- do_drawText(x, y, str, rtl, f, ff);
+ do_drawText(x, y, str, dir, f, ff);
//LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
// << " at " << x << "," << y);
}
void GuiPainter::text(int x, int y, docstring const & str, Font const & f,
double const wordspacing, double const tw)
{
- text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft(), wordspacing, tw);
+ text(x, y, str, f.fontInfo(), f.isVisibleRightToLeft() ? RtL : LtR,
+ wordspacing, tw);
}
{
GuiFontMetrics const & fm = getFontMetrics(f.fontInfo());
FontInfo fi = f.fontInfo();
- bool const rtl = f.isVisibleRightToLeft();
+ Direction const dir = f.isVisibleRightToLeft() ? RtL : LtR;
// dimensions
int const ascent = fm.maxAscent();
int const height = fm.maxAscent() + fm.maxDescent();
- int xmin = fm.pos2x(str, from, rtl, wordspacing);
- int xmax = fm.pos2x(str, to, rtl, wordspacing);
+ int xmin = fm.pos2x(str, from, dir == RtL, wordspacing);
+ int xmax = fm.pos2x(str, to, dir == RtL, wordspacing);
if (xmin > xmax)
swap(xmin, xmax);
fi.setPaintColor(other);
QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
setClipRegion(clip);
- text(x, y, str, fi, rtl, wordspacing, tw);
+ text(x, y, str, fi, dir, wordspacing, tw);
// Then the part in normal color
// Note that in Qt5, it is not possible to use Qt::UniteClip,
fi.setPaintColor(orig);
QRegion region(viewport());
setClipRegion(region - clip);
- text(x, y, str, fi, rtl, wordspacing, tw);
+ text(x, y, str, fi, dir, wordspacing, tw);
setClipping(false);
}