[cairo] [PATCH]A cairo-ps-surface.c issue for modern finicky versions of ghostscript

Behdad Esfahbod behdad at behdad.org
Wed Dec 12 12:52:30 PST 2007


On Sun, 2007-12-02 at 19:29 +1030, Adrian Johnson wrote:
> 
> 
> The x coordindate -2096679 is off the page. I've seen this problem
> before when using pango with bitmap fonts. PS and PDF files would have
> large negative numbers in the moveto used to position text. However
> the
> text would appear ok in PNG files. Using gdb I confirmed that pango is
> passing in large negative coordinates to cairo_show_glyphs(). There is
> also a bug report here
> 
>   http://bugs.freedesktop.org/show_bug.cgi?id=10118
> 
> and pango bug report here
> 
>   http://bugzilla.gnome.org/show_bug.cgi?id=474418
> 
> The pango developers do not appear to have made any progress on this
> bug.

The bug was tracked down today:

  http://bugzilla.gnome.org/show_bug.cgi?id=503212

It was indeed a cairo issue as I expected.  And a very easy one:  for
bitmap fonts, face->units_per_EM is zero, and if metrics hinting is
disabled, cairo-ft is dividing by that value.

The fix is pretty simple too, I had the same issue in firefox2+pango
printing code and figured it out, kinda.  At the same time I was
surprised that cairo doesn't deal with it, but it didn't click.  It was
last yearish though.

What I did was first, to use a function like:

+static FT_UShort
+get_upm (FT_Face face)
+{
+  FT_UShort upm = face->units_per_EM;
+
+  if (!upm)
+    upm = 1000; // bitmap font or something
+
+  return upm;
+}
+

in all places, to avoid having to audit all code, but the actual trick
was in using face->size->metrics.x_ppem and face->size->metrics.y_ppem.
I remember that wasn't enough in that case and I needed the dpi and
fontconfig wasn't helping, so I filed:

  http://bugzilla.gnome.org/show_bug.cgi?id=503212

but I think cairo has that information already.  Another point is that
with screen at least, bitmap fonts are not scaled.  But that doesn't
make any sense on vector backends.  Not sure what the actual glyph code
in PS/PDF is doing.  Got to check and make sure metrics match those.

That's it for now.  Need to get to some other work for today.  I'll try
to look into it tomorrow, but helps if Adrian wants to fix it faster. ;)


Cheers,

-- 
behdad
http://behdad.org/

...very few phenomena can pull someone out of Deep Hack Mode, with two
noted exceptions: being struck by lightning, or worse, your *computer*
being struck by lightning.  -- Matt Welsh



More information about the cairo mailing list