After drawing a glyph with freetype the pen is advanced as follows:
pen.x += face->glyph->advance.x;
pen.y += face->glyph->advance.y;
My question is, how do you set the initial pen position of the first character, relative to the upper left bound of the drawing surface?
{0,0}
isn't correct, as it would draw the first line mostly above the top of the drawing surface, and too close to the left bound.
I suspect it is some combination of:
struct FT_FaceRec {
...
FT_BBox bbox;
FT_UShort units_per_EM;
FT_Short ascender;
FT_Short descender;
FT_Short height;
FT_Short max_advance_width;
FT_Short max_advance_height;
...
}
but it isn't very clear.
For the record I ended up using as initial pen position:
pen.x = 0; pen.y = -face->size->metrics.ascender;
This seems to be the appropriate minimal border to the topleft of the origin of the first glyph.
Further, using face->size->metrics.descender past the last baseline (origin of the last glyph), for the bottom border. And using the x pen position after advancing (+= .advance.x) past the origin of the rightmost glyph as the minimal right side border.