[cairo] Font metrics under font transformations

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Thu Jan 13 08:35:49 PST 2005


On Mon, 2005-01-10 at 14:30 -0800, Keith Packard wrote:
> Now that we have an answer for glyph metrics under font transformations, 
> I'd like to see if anyone has an idea of what the font metrics should look 
> like.
> 
> Font metrics include three vertical spacing values and maximum advance 
> values in both directions (it's not a maximum advance vector as the values 
> are compared separately).
> 
> Keeping our 'rotated glyphs are weird' view of the world, one simple idea 
> would be to just return the 'scale only' metrics, ignoring the non-scale 
> portion of the font matrix.  This will be hard to document, and will 
> likely confuse anyone who does accidentally rotate a font.
> 
> An alternative would be to compute the vertical line spacing in user space 
> between adjacent lines; this works except for 90° rotations where it 
> produces an infinite result.  We could return 'inf/-inf' in this case if 
> necessary.
> 
> The third option is to return vectors for all of these values.  This will 
> complicated usage of these values in the 'normal' cases, but will 
> otherwise work just fine.  Note that 'max_x_advance' and 'max_y_advance' 
> will *also* be vectors as they point along the font space baseline.

  OK.  This discussion is becoming way too complicated for me to follow,
so let me just give my opinion before a 'monster' is created.

  I think most users don't want metrics to be affected by the CTM.  And
they don't want vectorial metrics either.  My ideal API would be one
that returned font metrics such that one could easily draw a bounding
box around a label without knowing or caring about any transformation
matrices in effect at the moment.  For example, suppose you have a
function:

  ( sorry, I don't know the actual Cairo API yet, so this is just a made
up API :P )

def framebox(ctx, txt, x, y):
    width, ascent, descent = ctx.labelmetrics(txt)
    ctx.moveto(x, y)
    ctx.show(txt)
    ctx.moveto(x, y - descent)
    ctx.lineto(x + width, y - descent)    
    ctx.lineto(x + width, y + ascent)    
    ctx.lineto(x, y + ascent)    
    ctx.lineto(x, y - descent)    

  
  The idea is that the function should not have to know what CTM is.
Calling framebox(ctx, "Hello", 0, 0) should draw text with a box around
it, but if you rotate everything 30 degrees, scale 2x, and add shearing,
still it should draw text with a box around it (although the box may no
longer be strictly rectangular).
  
  If you can keep the API this simple, please do so.

  Regards.

-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3086 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050113/49682a1c/smime.bin


More information about the cairo mailing list