- if (!use_pixmap_cache_) {
- // don't use the pixmap cache,
- // draw directly onto the painting device
- setQPainterPen(computeColor(f.realColor()));
- if (font() != ff)
- setFont(ff);
- // We need to draw the text as LTR as we use our own bidi code.
- QPainter::setLayoutDirection(Qt::LeftToRight);
- drawText(x, y, str);
- //LYXERR(Debug::PAINTING, "draw " << string(str.toUtf8())
- // << " at " << x << "," << y);
- return textwidth;
- }
+ if (use_pixmap_cache_) {
+ QPixmap pm;
+ QString key = generateStringSignature(str, f);
+
+ // Warning: Left bearing is in general negative! Only the case
+ // where left bearing is negative is of interest WRT the
+ // pixmap width and the text x-position.
+ // Only the left bearing of the first character is important
+ // as we always write from left to right, even for
+ // right-to-left languages.
+ int const lb = min(fm.lbearing(s[0]), 0);
+ int const mA = fm.maxAscent();
+ if (QPixmapCache::find(key, pm)) {
+ // Draw the cached pixmap.
+ drawPixmap(x + lb, y - mA, pm);
+ return textwidth;
+ }