Toby Wilson
Toby Wilson

Reputation: 1507

Truetype font spacing?

I'm in the process of vectorizing true type fonts to render them as Direct3D primitives. So far I've successfully managed to extract the glyphs using GetGlyphOutline, and render them as linelist primitives. Anyway, on to the spacing...

How can I find out the spacing between characters, or how/where is it determined? Clearly the spaces vary with non-monospace fonts.

Is there a GDI+ or other windows function call to determine the spacing?

Upvotes: 0

Views: 2216

Answers (2)

Dwayne Robinson
Dwayne Robinson

Reputation: 2409

You are referring to the advance width of the glyphs (stored in the hmtx table of the font, or vmtx for vertical text). Via GDI, which it sounds like you are using rather than DirectWrite, you can use:

  1. GetCharABCWidthsI if you already have an array of glyph ids. This approach can support any character in Unicode including extended CJK and newer additions like Egyptian heiroglyphics, not just the lower basic multilingual plane.
  2. GetCharWidth32 for character widths - limited to the basic plane, but the simple option.
  3. Call GetGlyphOutline with GGO_METRICS and use gmCellIncX. This returns more fields than you're probably interested in though.

Kerning is an additional optional adjustment to the nominal advance, such as in the word "AVATAR" where 'A' and 'V' would be shifter closer for aesthetic purposes.

Upvotes: 2

Alex K.
Alex K.

Reputation: 175748

I don't know anything about direct3d, but if your just after the metrics they are stored in the typefaces kerning table; GetKerningPairs will tell you the correct placement for sets of character pairs.

Upvotes: 1

Related Questions