[cairo] Rendering underlines / overbars with pangocairo

Peter Clifton pcjc2 at cam.ac.uk
Thu Dec 18 08:07:03 PST 2008


On Thu, 2008-12-18 at 15:45 +0000, Peter Clifton wrote:
> On Thu, 2008-12-18 at 01:36 -0500, Behdad Esfahbod wrote:
> > Peter Clifton wrote:
> > 
> > > However, it appears that the overbar doesn't fade out. When zoomed far
> > > out, you see very bold pixel aligned overbars, with some faded
> > > anti-aliased text in the few pixels below.
> > > 
> > > Poking in Pango, (and I'm a complete noob there), I'm wondering if the
> > > font metrics are coming through pangogc-font.c 's get_face_metrics()
> > > function. (The platform is Linux, and text is being rendered via
> > > cairo). 
> > 
> > Hi Peter,
> > 
> > I think you are hitting this bug:
> > 
> >   http://bugzilla.gnome.org/show_bug.cgi?id=457990
> > 
> > It's a very ugly bug.  I'll see if I can fix it soon.
> > 
> > One way to work around it is to make sure your ctm is identity and modify the
> > font matrix instead.  Ugly, I know.
> 
> I think my CTM is identity already.. my user spece coodinates are in
> pixels, since that was easiest for transitioning away from the old GDK
> drawing routines, and because we do hinting of lines to the pixel grid.
> 
> Is pangofc-font.c likely to be involved for the cairo backend? If so,
> then I can't hope to get an underline thickness metric less than
> PANGO_SCALE due to the quantisation here:
> 
>   if (fcfont->is_hinted)
>     {
>       pango_quantize_line_geometry (&metrics->underline_thickness,
>                                     &metrics->underline_position);
>       pango_quantize_line_geometry (&metrics->strikethrough_thickness,
>                                     &metrics->strikethrough_position);
>     }
> 
> It would appear that the strokes in the font aren't being quantized at
> small sizes though, since they fade as the font becomes unreadably
> small.

The following patch gives me the desired behaviour, my overbar (made
with thickness underline metrics), now fades (due to width < 1
anti-aliasing) with the stroke of the font, looking much more uniform
than before. It still achieves the desired non-blurred look buy hinting
the position, and only allowing non-integer widths for width < 1.

--- pango-utils.c.old	2008-12-18 16:00:18.000000000 +0000
+++ pango-utils.c	2008-12-18 16:04:03.000000000 +0000
@@ -1488,9 +1488,11 @@
  * multiples of %PANGO_SCALE. The purpose of this function is to avoid
  * such lines looking blurry.
  *
- * Care is taken to make sure @thickness is at least one pixel when this
- * function returns, but returned @position may become zero as a result
- * of rounding.
+ * If the input @thickness is less than one pixel, it is passed through
+ * unchanged to allow the intensity of the resulting line to fade with
+ * the stroke of the font.
+ *
+ * The returned @position may become zero as a result of rounding.
  *
  * Since: 1.12
  */
@@ -1513,7 +1515,8 @@
       *position = new_center + (PANGO_SCALE * thickness_pixels) / 2;
     }
 
-  *thickness = thickness_pixels * PANGO_SCALE;
+  if (*thickness > PANGO_SCALE)
+    *thickness = thickness_pixels * PANGO_SCALE;
 }
 
 /**


-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



More information about the cairo mailing list