Allegro provides routines for loading fonts directly from GRX format .fnt files, 8x8 or 8x16 BIOS format .fnt files, from bitmap images, from datafiles or you can import a multiple-range Unicode font by writing a .txt script that specifies a number of different source files for each range of characters.
By default, Allegro can only use bitmapped (non-scalable) fonts. If you want to use TrueType fonts, you will need to use an add-on library which allows you to load them on the fly (like AllegTTF or Glyph Keeper, listed among others at http://www.allegro.cc/) and render them directly, or generate a bitmapped version of a TrueType font with tools like TTF2PCX (http://www.talula.demon.co.uk/ttf2pcx/index.html).
The pal parameter can optionally be used to return a palette for the FONT. The parameter param can be anything you like: you can use this to pass information to your loading routine, such as for instance the font height, the character range to load or the index number of a font in a datafile. If you choose to write your own font loading code, your function should be prepared to deal with a value of NULL for either of these parameters.FONT *load_my_font(const char *filename, RGB *pal, void *param) { ... }
See also: load_font.
If the font contains palette information, then the palette is returned in the second parameter, which should be an array of 256 RGB structures (a PALETTE). The pal argument may be NULL. In this case, the palette data, if present, is simply not returned.
The third parameter can be used to pass specific information to a custom loader routine. Normally, you can just leave this as NULL. Note that another way of loading fonts is embedding them into a datafile and using the datafile related functions.
Example:
FONT *myfont; PALETTE palette; ... myfont = load_font("my_font.pcx", palette, NULL); if (!myfont) abort_on_error("Couldn't load font!"); ... textout_centre_ex(screen, myfont, "This is my own pretty font!", SCREEN_W / 2, SCREEN_H / 2, white, black); ... destroy_font(myfont);
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_bitmap, load_dat_font, load_bios_font, load_grx_font, load_grx_or_bios_font, load_bitmap_font, load_txt_font, destroy_font.
Examples using this: exfont.
See also: load_datafile_object, load_font.
Examples using this: exfont.
FONT *f = load_font("alphafont.tga", NULL, NULL); make_trans_font(f); set_alpha_blender(); textprintf_centre_ex(screen, f, 320, 240, -1, -1, "Anti-aliased Font!");
See also: is_trans_font, set_alpha_blender, load_font, draw_trans_sprite.
Return value: Returns TRUE if the font uses transparency, FALSE if it does not.
See also: make_trans_font, is_color_font, is_mono_font.
Return value: Returns TRUE if the font is a color font, FALSE if it is not.
See also: is_trans_font, is_mono_font.
Return value: Returns TRUE if the font is a monochrome font, FALSE if it is not.
See also: is_trans_font, is_color_font.
Return value: Returns TRUE if any alpha pixels are found, else FALSE.
See also: is_trans_font.
Return value: Returns TRUE if the two fonts are of the same general type (both are color fonts or both are monochrome fonts, for instance).
See also: merge_fonts, is_trans_font, is_color_font, is_mono_font.
FONT *f; int range; int n; ... range = get_font_ranges(f); printf("The font has %d character ranges:\n", range); for (n = 0; n < range; n++) printf("Range %d from 0x%03x - 0x%03x\n", get_font_range_begin(f, n), get_font_range_end(f, n));
Return value: Returns the number of continuous character ranges in a font, or -1 if that information is not available.
See also: get_font_range_begin, get_font_range_end, transpose_font.
printf("The font has a character range of %d - %d\n", get_font_range_begin(font, -1), get_font_range_end(font, -1));
Return value: Returns the first character in the font range, or -1 if that information is not available.
See also: get_font_ranges, get_font_range_end, transpose_font.
printf("The font has a character range of %d - %d\n", get_font_range_begin(font, -1), get_font_range_end(font, -1));
Return value: Returns the last character in the font range, or -1 if that information is not available.
See also: get_font_ranges, get_font_range_begin, transpose_font.
FONT *myfont; FONT *capitals; FONT *fontcopy; ... /* Create a font of only capital letters */ capitals = extract_font_range(myfont, 'A', 'Z'); /* Create a copy of the font */ fontcopy = extract_font_range(myfont, -1, -1); ... destroy_font(capitals); destroy_font(fontcopy);
Return value: Returns a pointer to the new font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: get_font_range_begin, get_font_range_end, merge_fonts, transpose_font.
Examples using this: exfont.
FONT *myfont; FONT *capitals; ... /* Create a font of only capital letters */ capitals = extract_font_range(myfont, 'A', 'Z'); /* Now transpose the characters in the font so that they will be used */ /* for the lower case letters a-z */ transpose_font(capitals, 'a'-'A'); textout_ex(screen, capitals, "allcaps", 100, 100, makecol(255,255,255), 0);
Return value: Returns 0 on success, -1 on failure.
See also: get_font_range_begin, get_font_range_end, merge_fonts, extract_font_range.
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);
Return value: Returns a pointer to the new font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: extract_font_range, is_trans_font, is_color_font, is_mono_font.
Examples using this: exfont.
For example, suppose you have a datafile named `fonts.dat' with the following contents:
Then the following code will load FONT_1_DATA as a FONT and return FONT_1_PALETTE as the palette:FONT FONT_1_DATA FONT FONT_2_DATA FONT FONT_3_DATA PAL FONT_1_PALETTE PAL FONT_2_PALETTE
If instead you want to load the second font, FONT_2, from the datafile, you would use:FONT *f; PALETTE pal; char *names[] = { "FONT_1_DATA", "FONT_1_PALETTE" } f = load_dat_font("fonts.dat", pal, names);
If you want to load the third font, but not bother with a palette, use:FONT *f; PALETTE pal; char *names[] = { "FONT_2_DATA", "FONT_2_PALETTE" } f = load_dat_font("fonts.dat", pal, names);
FONT *f; char *names[] = { "FONT_3_DATA", NULL } f = load_dat_font("fonts.dat", NULL, names);
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font.
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font.
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font.
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font.
The size of each character is determined by the layout of the image, which should be a rectangular grid containing all the ASCII characters from space (32) up to the tilde (126). The way the characters are separated depends on the color depth of the image file:
Note that in each horizontal row the bounding boxes around the characters should align and have the same height.
Probably the easiest way to get to grips with how this works is to load up the `demo.dat' file and export the TITLE_FONT into a PCX file. Have a look at the resulting picture in your paint program: that is the format a font should be in.
Take care with high and true color fonts: Allegro will convert these to the current color depth when you load the font. If you try to use a font on a bitmap with a different color depth Allegro will do color conversions on the fly, which will be rather slow. For optimal performance you should set the color depth to the color depth you want to use before loading any fonts.
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font, load_bitmap, set_color_depth, grab_font_from_bitmap.
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: load_bitmap_font.
would import the first 96 characters from ascii.fnt as the range 0x20-0x7F, the next 96 characters from ascii.fnt as the range 0xA0-0xFF, and the entire contents of dingbats.fnt starting at Unicode position 0x1000.ascii.fnt 0x20 0x7F - 0xA0 0xFF dingbats.fnt 0x1000
Return value: Returns a pointer to the font or NULL on error. Remember that you are responsible for destroying the font when you are finished with it to avoid memory leaks.
See also: register_font_file_type, load_font.