* QLPainter.cpp:

- backport Stefan's fixes to the Pixmap cache (rev. 27091 and 27227)
	  in order to fix a crash on the Mac with combining characters (bug 5327).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@27250 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-11-04 17:01:02 +00:00
parent 33d3a68811
commit a32d1b0b29
2 changed files with 49 additions and 43 deletions

View File

@ -307,33 +307,23 @@ int QLPainter::text(int x, int y, docstring const & s,
return textwidth; return textwidth;
} }
if (!use_pixmap_cache_) { if (use_pixmap_cache_) {
// don't use the pixmap cache, QPixmap pm;
// draw directly onto the painting device QString key = generateStringSignature(str, f);
setQPainterPen(f.realColor()); // Warning: Left bearing is in general negative! Only the case
if (font() != fi.font) // where left bearing is negative is of interest WRT the the
setFont(fi.font); // pixmap width and the text x-position.
// We need to draw the text as LTR as we use our own bidi code. // Only the left bearing of the first character is important
setLayoutDirection(Qt::LeftToRight); // as we always write from left to right, even for
// We need to draw the text as LTR as we use our own bidi code. // right-to-left languages.
setLayoutDirection(Qt::LeftToRight); int const lb = std::min(fi.metrics->lbearing(s[0]), 0);
drawText(x, y, str); int const mA = fi.metrics->maxAscent();
//LYXERR(Debug::PAINTING) << "draw " << std::string(str.toUtf8()) if (QPixmapCache::find(key, pm)) {
// << " at " << x << "," << y << std::endl; // Draw the cached pixmap.
return textwidth; drawPixmap(x + lb, y - mA, pm);
} return textwidth;
}
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 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 = std::min(fi.metrics->lbearing(s[0]), 0);
int const mA = fi.metrics->maxAscent();
if (!QPixmapCache::find(key, pm)) {
// Only the right bearing of the last character is // Only the right bearing of the last character is
// important as we always write from left to right, // important as we always write from left to right,
// even for right-to-left languages. // even for right-to-left languages.
@ -341,25 +331,38 @@ int QLPainter::text(int x, int y, docstring const & s,
int const w = textwidth + rb - lb; int const w = textwidth + rb - lb;
int const mD = fi.metrics->maxDescent(); int const mD = fi.metrics->maxDescent();
int const h = mA + mD; int const h = mA + mD;
pm = QPixmap(w, h); if (w > 0 && h > 0) {
pm.fill(Qt::transparent); pm = QPixmap(w, h);
QLPainter p(&pm); pm.fill(Qt::transparent);
p.setQPainterPen(f.realColor()); QLPainter p(&pm);
if (p.font() != fi.font) p.setQPainterPen(f.realColor());
p.setFont(fi.font); if (p.font() != fi.font)
// We need to draw the text as LTR as we use our own bidi code. p.setFont(fi.font);
p.setLayoutDirection(Qt::LeftToRight); // We need to draw the text as LTR as we use our own bidi code.
p.drawText(-lb, mA, str); p.setLayoutDirection(Qt::LeftToRight);
QPixmapCache::insert(key, pm); p.drawText(-lb, mA, str);
/* QPixmapCache::insert(key, pm);
LYXERR(Debug::PAINTING) << "h=" << h << " mA=" << mA << " mD=" << mD /*
<< " w=" << w << " lb=" << lb << " tw=" << textwidth LYXERR(Debug::PAINTING) << "h=" << h << " mA=" << mA << " mD=" << mD
<< " rb=" << rb << endl; << " w=" << w << " lb=" << lb << " tw=" << textwidth
*/ << " rb=" << rb << endl;
*/
// Draw the new cached pixmap.
drawPixmap(x + lb, y - mA, pm);
return textwidth;
}
} }
// Draw the cached pixmap.
drawPixmap(x + lb, y - mA, pm);
// don't use the pixmap cache,
// draw directly onto the painting device
setQPainterPen(f.realColor());
if (font() != fi.font)
setFont(fi.font);
// 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 " << std::string(str.toUtf8())
// << " at " << x << "," << y << std::endl;
return textwidth; return textwidth;
} }

View File

@ -154,6 +154,9 @@ What's new
- Fix the input behaviour when multiple cells of a table were selected, - Fix the input behaviour when multiple cells of a table were selected,
including a possible assertion (bug 5225). including a possible assertion (bug 5225).
- Fix a crash on the Mac when using the pixmap cache with combining
characters (bug 5327).
- Empty lines are correctly removed when the cursor moves due to the - Empty lines are correctly removed when the cursor moves due to the
"cursor follows scrollbar" feature (bug 5065). "cursor follows scrollbar" feature (bug 5065).