]> git.lyx.org Git - features.git/commitdiff
* complete fix for #5327: switch back to normal drawing code if the cache
authorStefan Schimanski <sts@lyx.org>
Fri, 24 Oct 2008 22:49:17 +0000 (22:49 +0000)
committerStefan Schimanski <sts@lyx.org>
Fri, 24 Oct 2008 22:49:17 +0000 (22:49 +0000)
  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

index 68161d1be9edd4e561eb9dd1f2b6ba7dc20180ca..bda52f189049d209e71c050e24665e8db94da29a 100644 (file)
@@ -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;
 }