[cairo] Userfont hinting

Peter Clifton pcjc2 at cam.ac.uk
Sat May 10 18:27:23 PDT 2008


On Sat, 2008-05-10 at 17:03 +0100, Peter Clifton wrote:
> On Sat, 2008-05-10 at 15:52 +0100, Peter Clifton wrote:
> > On Sat, 2008-05-10 at 15:01 +0200, Behdad Esfahbod wrote:
> > > Ok, try what I pushed now.  I modified your source and it works
> > > correctly for whatever I tested from 10^-29 to 10^+29.  Test case
> > > attached.  I may clean it up and add to the test suite if you don't
> > > mind.
> > 
> > That would be cool, thanks!
> > 
> > I'll report back on gschem, and the original trigger once I've got that
> > branch working again. (I've been shuffling code about).
> 
> It works great, thanks!
> 
> (Now.. to fix my support for rotated text...)

Try this attached test-case.

It appears that the user-font code in cairo doesn't compute the correct
extents at various rotations.

Adding some (graphical) instrumentation revealed that the image surfaces
being used by cairo are far larger than necessary for a tight surface
just big enough for the glyph.

I'll post some patches I used to hack this into working, but someone
with a clue (Behdad?) should take a look :)

It seems that setting the ctm on the analysis surface doesn't have the
desired effect, (to rotate the replayed meta-surface strokes as they go
down), and only seems to serve to bloat the bounding box for rotated
glyphs.

e.g.:

     /\
    /  \
   /    \
  /------\   _ x axis.
 / | /\ | \  /|
/  |/  \|  \/
\  |\  /|  /
 \ | \/ | /
  \------/
   \    /
    \  /
     \/
      \ |
      _\| y axis.
       

Inner box is the glyph being drawn (supposed to be a rotated rectangle).
In font space, this is upright:
  _                                /\
 |_| in user space, it is rotated: \/

If we analyse this with an identity ctm, we get bounds as the middle
rectangle. (x and y axies horizontal & vertical). It seems that by
setting the analysis surface ctm to the scale_inverse matrix from the
scaled_font, we only increase the bounds further (outer box).


I've had a stab at bodging around this by setting the device_transform
matrix on the analysis surface. This also required extending the
implementation of _cairo_path_fixed_device_transform(...) to work with
an arbitrary matrix.

I repeatedly fell over the fixed-point scaling in the analysis surface
though, so what I have may still be wrong.


Note the change from offsetting the glyph image by its (font space)
bearings, to its (device space) bounding box.


-- 
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!)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: userfont.c
Type: text/x-csrc
Size: 4487 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080511/ece6fbc1/attachment.c 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: userfont_rotation.diff
Type: text/x-patch
Size: 3841 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080511/ece6fbc1/attachment.bin 


More information about the cairo mailing list