[cairo] Rendering line fonts

Ian Britten britten at caris.com
Fri Nov 21 10:57:03 PST 2008


Adrian Johnson wrote:
>> My only issue is that the fonts draw almost invisibly thin, and I'm
>> looking to get a lineweight applied to it (See screenshots).

>> We love the fact that our text is actually coming out as text in the
>> PDF (Rather than just lines, or an image), and would really like to
>> be able to keep this!  [ Without having to rewrite vast amounts of
>> our existing text handling code ;) ]
> 
> The PDF backend, when embedding font subsets of fonts that are not 
> natively supported (TrueType, CFF, Type 1), will try to obtain the path 
> of each glyph. If the paths are available a Type 1 font is created from 
> these paths and embedded in the PDF. 

That's cool!  I wondered how that was being done...

[ NB - This is probably a whole different discussion, but I noticed
that when I select my text in Acroread, the highlight boxes don't
match where the glyphs are drawn (Only with these custom fonts - TT
seems ok).  Looks like a font origin/baseline issue.  I haven't
looked into this yet, but if anyone is interested or concerned,
speak up and I'll try to collect up more details when I get a
minute... ]

> The paths are always filled. If you 
> want to stroke the paths you will need to make your FT driver create 
> paths that when filled form the strokes. 

Hmmm...  Although I see what you're saying, things are never that
simple (for me...  :( )
Since the thickness is a configurable attribute of the text and not
a property of the Face (Sortof like size, underline, angle, etc),
then I won't be able to compute the final polygon path until just
when it's being rendered.

> Your best option is to use the user font feature in cairo. It would take 
> very little effort create a user font with a render function that 
> strokes the glyph path. In the PDF/PS backends user fonts are embedded 
> as a Type 3 fonts.

So, given that the entry point to all this (within our rendering
framework) passes me an FT_Face and a character, then what you're
saying is that I'll have to:
- Examine the FT_Face, and determine if it's one of my stroke fonts.
   - If it's not, proceed with what I'm currently doing.
- See if it has any open lines/paths, or if it just polygons (Since
   our fonts could be either).
   - If it's just polygons, I can continue doing what I'm doing.
- Extract the linework from the FT_Face (Somehow - Hmmm... I wonder
   if I'll have to dive into an FT_Outline_Decompose() type of draw
   solution to get at them  :P  To be investigated...)
- Using the thickness for this text, and the just-extracted lines,
   proceed to the 'user font' stuff of Cairo (Which I haven't looked
   looked at closely yet - Sorry) and make up the glyph.
- Finally, render it as described by Behdad in his message:
       cairo_glyph_path (cr, &cairo_glyph, 1);
       cairo_stroke (cr);

[ (sigh) Doesn't really sound like something I want to get started
on on a Friday afternoon...  :P  Now you see why I kept pursuing
my initial (seemingly-simple) approach... ]

Again, thanks for the help and info so far!  I'll probably have
a few more questions before I get this squished though.  Gotta go
upgrade to 1.8.x first though...
Ian


More information about the cairo mailing list