al_grab_font_from_bitmap(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_grab_font_from_bitmap β€” Allegro 5 API πŸ’–

okay bestie, buckle up, we're in the allegro5 corner of the Allegro reference manual and this function is lowkey iconic. it's giving font-forging sorcery. ✨


✨ NAME ✨

al_grab_font_from_bitmap β€” Allegro 5 API 🫢


🌸 SYNOPSIS 🌸

#include <allegro5/allegro_font.h>

ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp,
   int ranges_n, const int ranges[])

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically: this function takes an Allegro bitmap and creates a brand new font out of it. πŸ’… And here's the best part β€” you can delete the bitmap after the function returns, because the font keeps its own little copy for itself. no take-backs needed, she's self-sufficient. πŸ‘‘

Parameters, babes:

  • bmp β€” the bitmap with the glyphs drawn onto it 🎨
  • n β€” how many unicode ranges are chillin' in that bitmap. (that's ranges_n in the signature, iykyk)
  • ranges β€” n pairs of first and last unicode point to map glyphs to, one pair per range πŸ“‹

πŸŽ€ the bitmap format, bestie πŸŽ€

The bitmap format looks like this lil example right here, which has three glyphs for 1, 2 and 3:

"............."
". 1 .222.333."
". 1 .  2.  3."
". 1 .222.333."
". 1 .2  .  3."
". 1 .222.333."
"............."

In that lil illustration up there, the dot is for pixels having the background color. and how do we know what the background color is? it's determined by the color of the top left pixel in the bitmap. periodt. πŸ’…

there should be a border of at least 1 pixel with this color to the bitmap edge and between all the glyphs. do not skip the border, bestie, she needs her personal space. πŸ™ˆ

Each glyph lives inside a rectangle of pixels that does not contain the background color. The height of all glyph rectangles should be the same, but the width can vary. slay, flexible queens. 🌈

The placement of the rectangles does not matter β€” except that glyphs get scanned from left to right and top to bottom to match them up with the unicode codepoints you specified. so like, order matters even if position doesn't. noted. πŸ“

The glyphs will simply be drawn using al_draw_bitmap(3alleg5), so usually you're gonna want the rectangles filled with full transparency and the glyphs drawn in opaque white. that's the vibe check that passes. βœ…


⭐ Examples ⭐

int ranges[] = {32, 126};
al_grab_font_from_bitmap(bitmap, 1, ranges)
int ranges[] = {
    0x0020, 0x007F,  /* ASCII */
    0x00A1, 0x00FF,  /* Latin 1 */
    0x0100, 0x017F,  /* Extended-A */
    0x20AC, 0x20AC}; /* Euro */
al_grab_font_from_bitmap(bitmap, 4, ranges)

okay so let's decode these πŸ‘‡

The first example will grab glyphs for the 95 standard printable ASCII characters, beginning with the space character (32) and ending with the tilde character (126). classic. πŸŽ€

The second example is the multi-range one and it's giving organized:

  1. maps the first 96 glyphs found in the bitmap to the ASCII range
  2. the next 95 glyphs to Latin 1
  3. the next 128 glyphs to Extended-A
  4. and the last glyph to the Euro character πŸ’Ά

and ngl, that's literally just the characters found in the Allegro 4 font. history lesson, bestie. πŸ“š


πŸ’œ SEE ALSO πŸ’œ


that's the whole page, no cap. this was the Allegro reference manual, al_grab_font_from_bitmap(3alleg5), and that footer energy is giving Allegro reference manual forever and always. πŸ«Άβœ¨πŸ’– go forth and grab some fonts, bestie, you're gonna ate. πŸ’…πŸŽ€

πŸ“¦ where this page comes from