[cairo] Userfont hinting

Peter Clifton pcjc2 at cam.ac.uk
Mon May 5 03:42:22 PDT 2008


On Mon, 2008-05-05 at 03:29 -0400, Behdad Esfahbod wrote:
> On Sat, 2008-05-03 at 18:23 +0100, Peter Clifton wrote:
> > 
> >   x3 = 21.5;
> >   y3 = 0;
> >   cairo_device_to_user (cr, &x3, &y3);
> >   metrics->x_advance = x3;
> >   metrics->y_advance = y3;
> 
> This is very wrong and breaks badly for rotated text.  But anyway, you
> *are* setting to a half integer.

Yes.. I did find it was broken for rotated text.. I guess I need to
figure out the projected distance in the direction of the baseline and
perpendicular to it?

> Lemme back up a bit.  Can you please succinctly summarize what you are
> trying to achieve, and what doesn't work?

I'm trying to replace text drawing in gEDA/gschem with cairo (as part of
a general attempt to replace the non anti-aliased GDK drawing). gschem
previously drew its own fonts with little line segments, but with Cario
this becomes too slow.
 
I started writing replacement, cairo based rendering code for gschem:

http://repo.or.cz/w/geda-gaf/pcjc2.git?a=shortlog;h=refs/heads/cairo_experiment

The userfont code is the last patch I have applied in my stgit series before pushing:

http://repo.or.cz/w/geda-gaf/pcjc2.git?a=commitdiff;h=46406c411b4016078c5cee89131a81a353dfeded

And the specific files:

http://repo.or.cz/w/geda-gaf/pcjc2.git?a=blob;f=gschem/src/gschem_cairo.c;h=f016b6e9a7f85809e51a16d07ea31e089ff69cb6
http://repo.or.cz/w/geda-gaf/pcjc2.git?a=blob;f=gschem/src/o_text.c;h=5bbb9c639f47e85a72f6cf3ba3205b3c364ca897

(Yes, I realise the {x,y}_advance metrics will be wrong there too).



For the simple test-case I posted, there should be two lines of glyphs
drawn. One shows sharp, and correctly pixel aligned. The second (where I
requested a larger size), does not end up pixel aligned.

Does the test-case show this for you? (If not there could be some bug
in the way I rebased the userfont branch on top of cairo's git HEAD.


This kind of effect manifests in the gschem rendering code at at some
zoom levels. The gschem code picks the text size it wants with
cairo_set_font_size (), passing a desired height in user-space, which in
this case is pixels. (SCREENabs converts mili-inches to pixels at the
current zoom level).


Thanks for looking - I'm guessing there is a good chance I've just
misunderstood something about how to use the fonts, but if we look at
the test case for a moment, why does the size requested with
cairo_set_font_size () affect the pixel alignment in the way it seems
to?

Best regards,

-- 
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