]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Work around Pango fonts with fractional width.
authorSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 15:37:05 +0000 (16:37 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 15:43:33 +0000 (16:43 +0100)
By retrieving characters' widths using get_extents and not
get_pixel_extents, we can spot when they're not actually an exact
multiple of a pixel, and avoid getting confused by the overall width
of a long string being off by up to a pixel per character.

unix/gtkfont.c

index 2099c8332acd90e81904cc73a9f8444a43763f36..260c960237e821d47537470272e0525a461b110b 100644 (file)
@@ -1338,10 +1338,10 @@ static int pangofont_char_width(PangoLayout *layout, struct pangofont *pfont,
     /*
      * Here we check whether a character has the same width as the
      * character cell it'll be drawn in. Because profiling showed that
-     * pango_layout_get_pixel_extents() was a huge bottleneck when we
-     * were calling it every time we needed to know this, we instead
-     * call it only on characters we don't already know about, and
-     * cache the results.
+     * asking Pango for text sizes was a huge bottleneck when we were
+     * calling it every time we needed to know this, we instead call
+     * it only on characters we don't already know about, and cache
+     * the results.
      */
 
     if ((unsigned)uchr >= pfont->nwidthcache) {
@@ -1354,7 +1354,7 @@ static int pangofont_char_width(PangoLayout *layout, struct pangofont *pfont,
     if (pfont->widthcache[uchr] < 0) {
         PangoRectangle rect;
         pango_layout_set_text(layout, utfchr, utflen);
-        pango_layout_get_pixel_extents(layout, NULL, &rect);
+        pango_layout_get_extents(layout, NULL, &rect);
         pfont->widthcache[uchr] = rect.width;
     }
 
@@ -1437,6 +1437,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
     utfptr = utfstring;
     while (utflen > 0) {
        int clen, n;
+        int desired = cellwidth * PANGO_SCALE;
 
        /*
         * We want to display every character from this string in
@@ -1475,7 +1476,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
 
         if (is_rtl(string[0]) ||
             pangofont_char_width(layout, pfont, string[n-1],
-                                 utfptr, clen) != cellwidth) {
+                                 utfptr, clen) != desired) {
             /*
              * If this character is a right-to-left one, or has an
              * unusual width, then we must display it on its own.
@@ -1497,7 +1498,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
                 n++;
                 if (pangofont_char_width(layout, pfont,
                                          string[n-1], utfptr + oldclen,
-                                         clen - oldclen) != cellwidth) {
+                                         clen - oldclen) != desired) {
                     clen = oldclen;
                     n--;
                     break;