al_get_glyph_advance(3alleg5)
β¨ NAME β¨
al_get_glyph_advance β ok so this is the Allegro 5 API function that tells you how far to nudge your cursor forward when you're drawing glyphs one at a time π
πΈ SYNOPSIS πΈ
#include <allegro5/allegro_font.h>
int al_get_glyph_advance(const ALLEGRO_FONT *f, int codepoint1, int codepoint2)
π DESCRIPTION π
Bestie. Listen. This function returns by how much the x position should be advanced for left to right text drawing when the glyph that corresponds to codepoint1 has been drawn, and the glyph that corresponds to codepoint2 will be the next one to be drawn. It's giving "how much space do I take up" energy, and it takes into consideration two things: the horizontal advance width of the glyph that corresponds with codepoint1, and the kerning between the glyphs of codepoint1 and codepoint2. No cap. β¨
So what even is kerning? Okay so kerning is the process of adjusting the spacing between glyphs in a font, to obtain a more visually pleasing result. It's literally the font author going "hmm, these two letters are too far apart, let me fix that". Kerning adjusts the space between two individual glyphs with an offset determined by the author of the font. The font said "I got this one" and honestly, slay. π
Some special-case lore you need to know:
- If you pass
ALLEGRO_NO_KERNINGascodepoint1thenal_get_glyph_advancewill return0. this can be useful when drawing the first character of a string in a loop. Very much the "nothing to see here, move along" of return values. π - Pass
ALLEGRO_NO_KERNINGascodepoint2to get the horizontal advance width of the glyph that corresponds tocodepoint1without taking any kerning into consideration. This can be used, for example, when drawing the last character of a string in a loop. You're at the end of the string, there is no next glyph, so like... no kerning possible, periodt.
And the edge cases, because of course there are edge cases:
- This function will return zero if the glyph of
codepoint1is not present in the font. Zero. Nothing. Gone. π«₯ - If the glyph of
codepoint2is not present in the font, the horizontal advance width of the glyph that corresponds tocodepoint1without taking any kerning into consideration is returned.
Now the workflow, bestie, write this down: when drawing a string one glyph at the time from the left to the right with kerning, the x position of the glyph should be incremented by the result of al_get_glyph_advance(3alleg5) applied to the previous glyph drawn and the next glyph to draw. That's the whole loop. That's the vibe. π
Heads up: the return value of this function is a recommended advance for optimal readability for left to right text determined by the author of the font. It's a suggestion, not a law. If you like, you may want to draw the glyphs of the font narrower or wider to each other than what al_get_glyph_advance(3alleg5) returns for style or effect. Go off, honestly. π
π¦ The Figure Moment π¦
In the figure below is an example of what the result of al_get_glyph_advance may be like for two glyphs A and l of the same font that has kerning for the "Al" pair, without and with the ALLEGRO_NO_KERNING flag.
First up, with kerning doing its little thing:
al_get_glyph_advance(font, 'A', 'l')
___|___
/ \
-------------
/\ -|
/ \ |
/____\ |
/ \ |
/ \ \_
-------------
And now, kerning switched off entirely:
al_get_glyph_advance(font, 'A', ALLEGRO_NO_KERNING)
____|____
/ \
---------------
/\ -|
/ \ |
/____\ |
/ \ |
/ \ \_
---------------
See how the little marker moved? That's the difference. Iconic behavior. π
β SINCE β
5.1.12 β she's been here a minute, respect her legacy. π«Ά
π SEE ALSO π
and that's the whole page babes!! this came to you straight out of the Allegro reference manual, al_get_glyph_advance(3alleg5), and if you got all the way down here then ily and go draw some beautifully kerned text πβ¨πΈ
π¦ where this page comes from
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms