Setting Character Size in FreeType
Asked Answered
V

1

13

I'm a bit confused setting the character width and height fields of the character size object ( example from the as described in the FreeType tutorial)

error = FT_Set_Char_Size(
          face,    /* handle to face object           */
          0,       /* char_width in 1/64th of points  */
          16*64,   /* char_height in 1/64th of points */
          300,     /* horizontal device resolution    */
          300 );   /* vertical device resolution      */

Why are char_width and char_height specified? Shouldn't that depend on the actual glyph? For example the characters "w" and "l" have different widths and height.

Also, as I am not rendering to screen (I plan to use the raster font data for some other esoteric purpose) is it sufficient to use FT_Set_Pixel_Sizes instead?

Venu answered 17/11, 2016 at 14:27 Comment(0)
J
11

The functions FT_Set_Char_Size and FT_Set_Pixel_Sizes set the size, not of an individual character, but of the em square for the font, which is a notional square that may be as tall as the tallest character (e.g., a square bracket: '[') but may not in fact be the same height as any character; it simply defines a reference dimension. The main meaning of setting a size of 12pt is to create characters that usually fit on to baselines 12pt apart without clashing, and which harmonize with 12pt characters from other fonts. An 'em' is thus a typographic dimension representing the size of the font.

The height and width are separately settable so that you can create expanded (horizontally enlarged) or condensed (horizontally compressed) fonts by using a larger or smaller width than the height. Normally you leave the width at zero, meaning that the width of the em square is to be the same as the height, and the characters are to be created in their standard proportions and not stretched or shrunk.

There is no reason to use FT_Set_Char_Size rather than FT_Set_Pixel_Sizes other than the fact that FT_Set_Char_Size gives finer control; FT_Set_Pixel_Sizes does not allow fractional pixels, which are meaningful when creating anti-aliased glyphs. The end result is always calculated using both the em size and the display resolution.

In your case you might as well use FT_Set_Pixel_Sizes; but if you need a fractional pixel size, use FT_Set_Char_Sizes with height in 64ths of a pixel, width of zero, and zero for both horizontal and vertical device resolution; a resolution of 0 makes pixels the same size as points. So to get a pixel size of 11.5, you'd use

FT_Set_Char_Sizes(face,0,11 * 64 + 32,0,0);
Jeopardy answered 13/1, 2021 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.