Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FreeType - help me understand glyph's advance.y property

Tags:

freetype

I'm learning the basics of the FreeType API for use in OpenGL and I'm confused about one thing. You load the font, then you load each glyph one by one into the font's glyph slot. The glyph has a number of fields, including advance, which has an x and a y field. Now, I understand that it is stated that y isn't used much, but on the offchance that I am in a situation where y is used, what I don't understand is that each character is being rendered in isolation to the glyph slot, so how can the glyph know that all subsequent characters should be rendered with a specific fractional offset? What if you were to render a lot of the same character in succession? Wouldn't you end up with either a slow diagonal incline or decline in your final text block?

like image 400
Nathan Ridley Avatar asked Feb 17 '15 18:02

Nathan Ridley


People also ask

What is glyph advance?

The advance of a glyph is the distance from the glyph's origin to the origin of the next glyph along the baseline, which is either vertical or horizontal. Note that, in a GlyphVector , the distance from a glyph to its following glyph might not be the glyph's advance, because of kerning or other positioning adjustments.


1 Answers

Historically advance.y is mostly for vertical text, like used in Asia (FT_LOAD_VERTICAL_LAYOUT will trigger it.) In a normal rendering case, you should not get at the same time both non-zero values for advance.x and advance.y.

But it is also useful to use Freetype in a more generic way. If you want to write Latin upright text in a 30° inclined way, you still can use the same structures: you apply (through FT_Set_Transform) the 30° inclination matrix to each glyph, but also to the advance vector; and the result will indeed have a diagonal incline; as intended!

like image 62
AntoineL Avatar answered Jan 03 '23 12:01

AntoineL