merge_fonts(3alleg4)

πŸ’– merge_fonts β€” the Allegro manual, but make it cute πŸ’–

okay bestie, so we're in the Allegro manual (3alleg4) and today's main character is merge_fonts. it's a function. it's in the Allegro game programming library. let's get into it 🫢


✨ NAME ✨

merge_fonts β€” Merges two fonts into one font. Allegro game programming library. two fonts walk in, one font walks out πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

FONT *merge_fonts(FONT *f1, FONT *f2)

yes the include is literally just #include <allegro.h>, that's the whole vibe 🌈


πŸ¦‹ DESCRIPTION πŸ¦‹

so what this function does is merge the character ranges from two fonts and hand you back a brand new font that's got all the characters from both of the old ones. like combining two playlists into one ultimate playlist, no cap πŸŽ€

now here's the tea: in general you cannot merge fonts of different types (eg, TrueType fonts and bitmapped fonts) β€” they don't mix, it's giving oil and water 😭. BUT. as a special case, this function can promote a monochrome bitmapped font to a color font and merge those. so that one specific glow-up is allowed ✨

example time:

FONT *myfont;
FONT *myfancy_font;
FONT *lower_range;
FONT *upper_range;
FONT *capitals;
FONT *combined_font;
FONT *tempfont;
...
/* Create a font that contains the capitals from  */
/* the fancy font but other characters from myfont */
lower_range = extract_font_range(myfont, -1, 'A'-1);
upper_range = extract_font_range(myfont, 'Z'+1, -1);
capitals = extract_font_range(myfancy_font, 'A', 'Z');

tempfont = merge_fonts(lower_range, capitals);
combined_font = merge_fonts(tempfont, upper_range);

/* Clean up temporary fonts */
destroy_font(lower_range);
destroy_font(upper_range);
destroy_font(capitals);
destroy_font(tempfont);

look at that β€” capitals from the fancy font, everything else from myfont, all stitched together. iconic behaviour, honestly πŸ‘‘


πŸ’œ RETURN VALUE πŸ’œ

Returns a pointer to the new font, or NULL on error. and bestie, listen: you are responsible for destroying the font when you're done with it, so you don't leak memory. the cleanup is not optional, it's a lifestyle πŸ§ΉπŸ’–

not you forgetting to destroy_font and leaking memory all over the place... couldn't be you, right? 😭

🌈 SEE ALSO 🌈


and that's the whole page, bestie πŸ’… this was Allegro, version 4.4.3, and the page you just read is merge_fonts(3alleg4). go forth and merge those fonts, you absolute font-merging legend πŸŽ€βœ¨πŸ¦‹