[cairo] UserFont size issue (ImageSurface)

Ian Britten britten at caris.com
Wed Feb 4 13:11:09 PST 2009


Behdad Esfahbod wrote:
> You'd just need to draw in font space.  That is, your drawings are typically
> in a box of about 0 to 1 (assuming your font has zero descent).  

And if that assumption isn't true? ...  :(
It's very typical that these fonts are centred at (0,0), and thus their
EM runs from (-x,-y), (+x,+y).  Normally our driver/face hides that, but
maybe not in this case?

 > Anyway, try
> adding a few strokes to see what's going on.  Everything should just work.

I did one better (I think), and printed out the points from glyph_path()
(It's an 'N', upside down due to origin flipping)

With a PDF surface, I get these points:
     move -0.3466627455219995 0.4999997600928846
     line -0.3466627455219995 -0.4999997600928846
     line -0.2533088055215585 -0.4999997600928846
     line 0.2533088055215585 0.4999997600928846
     line 0.3466627455219995 0.4999997600928846
     line 0.3466627455219995 -0.4999997600928846
With a PNG surface, I get these points:
     move -1.2316120524949323 1.7787098309556870
     line -1.2316120524949323 -1.7787098309556870
     line -0.9000323108711681 -1.7787098309556870
     line 0.9000323108711681 1.7787098309556870
     line 1.2316120524949323 1.7787098309556870
     line 1.2316120524949323 -1.7787098309556870

Strangely, in this case I'm now using for testing, the PNG glyphs seem
to be drawing much *bigger* ??  Grrr - There's some sort of interaction
going on here that I just don't see...

> Somehow you are doing a scale somewhere maybe that you shouldn't do?

 From what I understand, and from the looks of the points, I guess I
agree.  The two sets of points should have been the same, shouldn't
they?  Same glyph, same user size, drawn in font space...  The only
apparent difference is the context they're being rendered to.

Note that for both of these cases, the glyph was rendered at exactly
the same user size (0.014)
My drawing code is basically:
     Cairo::Matrix fMatrix(Cairo::scaling_matrix(userSize, -userSize));
     fMatrix.rotate(inAngle); // zero in this case
     context.set_font_matrix(fMatrix);
     context.set_source_rgba(r, g, b, a);
     Cairo::RefPtr<Cairo::FontFace> fFace = // make custom user font
     context.set_font_face(fFace);
     context.show_glyphs(glyphs);

Here's hoping that something I've written will point to where the
root of the problem is, or at least where to look further...
As always, thanks for your help!
Ian



More information about the cairo mailing list