]> git.lyx.org Git - features.git/commitdiff
str_metrics: Prevent clipping of chars with negative bearing
authorVincent van Ravesteijn <vfr@lyx.org>
Tue, 6 Jan 2015 17:48:19 +0000 (18:48 +0100)
committerVincent van Ravesteijn <vfr@lyx.org>
Tue, 6 Jan 2015 21:02:07 +0000 (22:02 +0100)
This happens when part of the word is selected.

To reproduce:
1. Start a new document
2. Type "af"
3. Select 'a'
4. Observe that the right part of the 'f' is clipped away.

This patch uses QRegion to set a clip region that is everything except
the part that is drawn in another color.

Fixes: #9223.
src/frontends/qt4/GuiPainter.cpp

index 5730819a02a4ee7708f4b20b12036848490f05be..95ab52a98f34b76fb4730e71c52f56fa44ca731a 100644 (file)
@@ -465,15 +465,16 @@ int GuiPainter::text(int x, int y, docstring const & str, Font const & f,
        // First the part in other color
        Color const orig = fi.realColor();
        fi.setPaintColor(other);
-       setClipRect(QRect(x + xmin, y - ascent, xmax - xmin, height));
+       QRegion const clip(x + xmin, y - ascent, xmax - xmin, height);
+       setClipRegion(clip);
        int const textwidth = text(x, y, str, fi, rtl);
 
        // Then the part in normal color
-       // Note that in Qt5, it is not possible to use Qt::UniteClip
+       // Note that in Qt5, it is not possible to use Qt::UniteClip,
+       // therefore QRegion is used.
        fi.setPaintColor(orig);
-       setClipRect(QRect(x, y - ascent, xmin, height));
-       text(x, y, str, fi, rtl);
-       setClipRect(QRect(x + xmax, y - ascent, textwidth - xmax, height));
+       QRegion region(viewport());
+       setClipRegion(region - clip);
        text(x, y, str, fi, rtl);
        setClipping(false);