From d51c31ca8573caf4071833ba67d4d9c4412338d6 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Fri, 24 Oct 2008 22:49:17 +0000 Subject: [PATCH] * complete fix for #5327: switch back to normal drawing code if the cache pixmap would have non-positive width or height. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27091 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiPainter.cpp | 83 ++++++++++++++++---------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index 68161d1be9..bda52f1890 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -366,31 +366,24 @@ int GuiPainter::text(int x, int y, docstring const & s, return textwidth; } - 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; + } - 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 = min(fm.lbearing(s[0]), 0); - int const mA = fm.maxAscent(); - if (!QPixmapCache::find(key, pm)) { // Only the right bearing of the last character is // important as we always write from left to right, // even for right-to-left languages. @@ -398,28 +391,34 @@ int GuiPainter::text(int x, int y, docstring const & s, int const w = textwidth + rb - lb; int const mD = fm.maxDescent(); int const h = mA + mD; - if (w <= 0 || h <= 0) { - LYXERR(Debug::PAINTING, "Invalid pixmap cache image for '" << s << "' h=" << h << " w=" << w); + if (w > 0 && h > 0) { + pm = QPixmap(w, h); + pm.fill(Qt::transparent); + GuiPainter p(&pm); + p.setQPainterPen(computeColor(f.realColor())); + if (p.font() != ff) + p.setFont(ff); + // We need to draw the text as LTR as we use our own bidi code. + p.setLayoutDirection(Qt::LeftToRight); + p.drawText(-lb, mA, str); + QPixmapCache::insert(key, pm); + //LYXERR(Debug::PAINTING, "h=" << h << " mA=" << mA << " mD=" << mD + // << " w=" << w << " lb=" << lb << " tw=" << textwidth + // << " rb=" << rb); return textwidth; } - - pm = QPixmap(w, h); - pm.fill(Qt::transparent); - GuiPainter p(&pm); - p.setQPainterPen(computeColor(f.realColor())); - if (p.font() != ff) - p.setFont(ff); - // We need to draw the text as LTR as we use our own bidi code. - p.setLayoutDirection(Qt::LeftToRight); - p.drawText(-lb, mA, str); - QPixmapCache::insert(key, pm); - //LYXERR(Debug::PAINTING, "h=" << h << " mA=" << mA << " mD=" << mD - // << " w=" << w << " lb=" << lb << " tw=" << textwidth - // << " rb=" << rb); } - // Draw the cached pixmap. - drawPixmap(x + lb, y - mA, pm); + // 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; } -- 2.39.2