Re: [AD] load_font patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sunday 16 January 2005 23:08, Evert Glebbeek wrote:
> Update #2, the scripted (.txt) font loader is attached. Really a lot 
> simpler than the old code in the datfont.c plugin, if you ask me. More 
> flexibel too, since the old one only really worked with bitmaps.
> As yet untested, but I'm going to sleep now.

Commited, with bugfixes and some modifications based on Bob's suggestion.
Proposed documentation update attached.

Evert
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.290
diff -u -p -r1.290 allegro._tx
--- docs/src/allegro._tx	16 Jan 2005 11:18:20 -0000	1.290
+++ docs/src/allegro._tx	20 Jan 2005 21:34:15 -0000
@@ -5976,21 +5976,7 @@ Fonts
 Allegro provides routines for loading fonts from GRX format .fnt files, 8x8
 or 8x16 BIOS format .fnt files, and from bitmap images, 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. The script file 
-contains a number of lines in the format "filename start end", which specify 
-the source file for that range of characters, the Unicode value of the first 
-character in the range, and the end character in the range (optional, if
-left out, the entire input file will be grabbed). If the filename is replaced
-by a hyphen, more characters will be grabbed from the previous input file.
-For example, the script:
-<textblock>
-   ascii.fnt 0x20 0x7F
-   - 0xA0 0xFF
-   dingbats.fnt 0x1000
-<endblock>
-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.
+of different source files for each range of characters.
 
 By default, Allegro can only use bitmapped (non-scalable) fonts. If you want
 to use True Type fonts, you will need to use an add-on library.
@@ -6017,7 +6003,7 @@ to use True Type fonts, you will need to
 
 @@FONT *@load_font(const char *filename, RGB *pal, void *param);
 @xref register_font_file_type, load_bitmap, load_dat_font
-@domain.hid load_bios_font, load_grx_font, load_grx_or_bios_font, load_bitmap_font
+@xref load_bios_font, load_grx_font, load_grx_or_bios_font, load_bitmap_font, load_txt_font
 @shortdesc Loads a font from a file.
    Loads a font from a file. At present, this supports loading fonts from
    a GRX format .fnt file, a 8x8 or 8x16 BIOS format .fnt file or any bitmap
@@ -6049,6 +6035,111 @@ to use True Type fonts, you will need to
    responsible for destroying the font when you are finished with it to
    avoid memory leaks.
 
+@@int @is_color_font(FONT *f)
+@xref is_mono_font
+@shortdesc Returns TRUE if a font is a colour font.
+   This function returns TRUE if the font is an Allegro colour font (as opposed
+   to a monochrome font).
+@retval
+   TRUE if the font is a colour font, FALSE if it is not.
+
+@@int @is_mono_font(FONT *f)
+@xref is_color_font
+@shortdesc Returns TRUE if a font is a monochrome font.
+   This function returns TRUE if the font is an Allegro monochrome font (as
+   opposed to a colour font).
+@retval
+   TRUE if the font is a monochrome font, FALSE if it is not.
+
+@@int @get_font_range_begin(FONT *f)
+@xref get_font_range_end
+@shortdesc Returns the start of a character range in a font.
+   This function returns the start of the character range for the font f, or
+   -1 if that information is not available for the selected font. Example:
+<codeblock>
+      printf("The font has a character range of %d - %d\n", 
+             get_font_range_begin(font), get_font_range_end(font));
+      <endblock>
+@retval
+   The first character in the font range, or -1 if that information is not 
+   available.
+
+@@int @get_font_range_end(FONT *f)
+@xref get_font_range_begin
+@shortdesc Returns the last character of a character range in a font.
+   This function returns the last character of the character ramge for the 
+   font f. Note that not all characters in the range returned by 
+   get_font_range_begin() and get_font_range_end() need to be available in the
+   font! Example:
+<codeblock>
+      printf("The font has a character range of %d - %d\n", 
+             get_font_range_begin(font), get_font_range_end(font));
+      <endblock>
+@retval
+   The last character in the font range, or -1 if that information is not 
+   available.
+
+@@FONT *@extract_font_range(FONT *f, int begin, int end)
+@xref get_font_range_begin, get_font_range_end, merge_fonts
+@shortdesc Extracts a range pf characters from a font.
+   This function extracts a character range from a font and returns a new font
+   that contains only the range of characters selected by this function. You
+   can pass -1 for either the lower or upper bound if you want to select all
+   characters from the start or the end of the font.
+   Example:
+<codeblock>
+      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 */
+      fontopy = extract_font_range(myfont, -1, -1);
+      <endblock>
+@retval
+   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.
+
+@@FONT *@merge_fonts(FONT *f1, FONT *f2)
+@xref extract_font_range, is_color_font, is_mono_font
+@shortdesc Merges two fonts into one font.
+   This function merges the character ranges from two fonts and returns a new
+   font containing all characters in the old fonts. In general, you cannot
+   merge fonts of different types (eg, TrueType fonts and bitmapped fonts),
+   but as a special case, this function can promote a monochrome bitmapped font
+   to a colour font and merge those. 
+   Example:
+<codeblock>
+      FONT *myfont;
+      FONT *myfancy_font;
+      FONT *lower_range;
+      FONT *upper_range;
+      FONT *capitals;
+      FONT *combined_font;
+      FONT *tempfont;
+      ...
+      /* Create a font that contains the capatials from  */
+      /* the fancy font but other characters from myfont */
+      lower_range = extarct_font_range(myfont, -1, 'A'-1);
+      upper_range = extarct_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(combined_font);<endblock>
+@retval
+   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.
+
 @@FONT *@load_dat_font(const char *filename, RGB *pal, void *param)
 @xref register_font_file_type, load_font
 @shortdesc Loads a FONT from an Allegro datafile.
@@ -6151,6 +6242,30 @@ to use True Type fonts, you will need to
    responsible for destroying the font when you are finished with it to
    avoid memory leaks.
 
+@@FONT *@load_txt_font(const char *filename, RGB *pal, void *param)
+@xref register_font_file_type, load_font
+@shortdesc Loads a font script.
+   This function can be used to load scripted fonts. The script file 
+   contains a number of lines in the format "filename start end", which specify 
+   the source file for that range of characters, the Unicode value of the first 
+   character in the range, and the end character in the range (optional, if
+   left out, the entire input file will be grabbed). If the filename is 
+   replaced by a hyphen, more characters will be grabbed from the previous 
+   input file. 
+   For example, the script:
+   <textblock>
+      ascii.fnt 0x20 0x7F
+      - 0xA0 0xFF
+      dingbats.fnt 0x1000
+   <endblock>
+   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.
+@retval
+   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.
+
 
 
 @heading
Index: include/allegro/font.h


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/