Re: [AD] load_font patch

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


At various times, Elias Pschernig wrote:
> - is_compatible_font should be documented or made internal
> 
> - Why is there no way to get information about the font ranges? I think
> get_font_range_[begin/end] should have an additional parameter, like
> this:
> 
> n = get_font_ranges(font) // return number of ranges in font
> get_font_range_begin(font, i) // return first character of range i,
> where i is in [0..n-1]
> 
> - load_dat_font
[...]
> Hm, maybe instead of using a pointer to int as last param, use a pointer
> to an array of two strings, which name the objects. Like this:
> 
> char const *names[] = {"myfont", "mypal"};
> load_data_font("my.dat", pal, names);
> The objects "myfont" and "mypal" simply are used as font and palette.

Ok, all implemented in the attached patches, one for documentation and one 
for the library itself. Still wants testing, which I may get round to 
doing later tonight, but I'll certainly do that before applying it. (I'm 
just posting it here to give someone else the chance to test it first ;)).

Evert
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.290
diff -u -r1.290 allegro._tx
--- docs/src/allegro._tx	16 Jan 2005 11:18:20 -0000	1.290
+++ docs/src/allegro._tx	22 Jan 2005 21:54:44 -0000
@@ -5976,24 +5976,10 @@
 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.
+to use TrueType fonts, you will need to use an add-on library.
 
 @\void @register_font_file_type(const char *ext,
 @@          FONT *(*load)(const char *filename, RGB *pal, void *param));
@@ -6017,7 +6003,7 @@
 
 @@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,28 +6035,182 @@
    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 color font.
+   This function returns TRUE if the font is an Allegro color font (as opposed
+   to a monochrome font).
+@retval
+   Returns TRUE if the font is a color 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 color font).
+@retval
+   Returns TRUE if the font is a monochrome font, FALSE if it is not.
+
+@@FONT *@is_compatible_font(FONT *f1, FONT *f2)
+@xref merge_fonts, is_color_font, is_mono_font
+@shortdesc Check if two fonts are of the same type.
+   This function compares the two fonts. If it returns TRUE, then you should
+   normally be able to merge the two fonts. If it returns FALSE, this is less
+   certain.
+@retval
+   Returns TRUE if the two fonts are of the same general type (both are color
+   fonts or both are monochrome fonts, for instance).
+
+@@int @get_font_ranges(FONT *f)
+@xref get_font_range_begin, get_font_range_end
+@shortdesc Returns the number of character ranges in a font.
+   This function returns the number of character ranges in a font. You should
+   query each of these ranges with get_font_range_begin() and
+   get_font_range_end() to find out what characters are availabel in the font.
+   Example:
+<codeblock>
+      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));
+      <endblock>
+@retval
+   Returns the number of continuous character ranges in a font, or -1 if that
+   information is not available.
+
+@@int @get_font_range_begin(FONT *f, int range)
+@xref get_font_ranges, 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. You can pass
+   -1 for the range parameter if you want to know the start of the whole font
+   range, or a number from 0 to (but not including) get_font_ranges(f) to get
+   the start of a specific character range in the font. Example:
+<codeblock>
+      printf("The font has a character range of %d - %d\n",
+             get_font_range_begin(font, -1), get_font_range_end(font, -1));
+      <endblock>
+@retval
+   Returns the first character in the font range, or -1 if that information
+   is not available.
+
+@@int @get_font_range_end(FONT *f, int range)
+@xref get_font_ranges, 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 range for the
+   font f. You can pass -1 for the range parameter if you want to know the
+   start of the whole font range, or a number from 0 to (but not including)
+   get_font_ranges(f) to get the start of a specific character range in the
+   font. You should check the start and end of all font ranges to see if a
+   specific character is actually available in the font. Not all characters in 
+   the range returned by get_font_range_begin(f, -1) and 
+   get_font_range_end(f, -1) need to be available! Example:
+<codeblock>
+      printf("The font has a character range of %d - %d\n",
+             get_font_range_begin(font, -1), get_font_range_end(font, -1));
+      <endblock>
+@retval
+   Returns 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 color 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.
-   Loads a FONT from an Allegro datafile. You can use the param parameter to
-   pass the sequential number of the FONT to load from the datafile (counting
-   from 0). If pal is not NULL, then the last palette entry found in the
-   datafile before the font was found is returned.
+   Loads a FONT from an Allegro datafile. You can set param parameter to
+   point to an array that holds two strings that identify the font and the 
+   palette in the datafile by name.
+   The first string in this list is the name of the font. You can pass NULL
+   here to just load the first font found in the datafile. The second string
+   can be used to specify the name of the palette associated with the font.
+   This is only returned if the pal parameter is not NULL. If you pass NULL
+   for the name of the palette, the last palette found before the font was
+   found is returned.
+   You can also pass NULL for param, which is treated as if you had passed NULL
+   for both strings seperately. In this case, the function will simply load the
+   first font it finds from the datafile and the palette that precedes it.
 
    For example, suppose you have a datafile named `fonts.dat' with the
    following contents:
 <textblock>
-      PAL   FONT_1_COLOURS
       FONT  FONT_1_DATA
-      PAL   FONT_2_COLOURS
       FONT  FONT_2_DATA
       FONT  FONT_3_DATA
+      PAL   FONT_1_PALETTE
+      PAL   FONT_2_PALETTE
 <endblock>
    Then the following code will load FONT_1_DATA as a FONT and return
-   FONT_1_COLOURS as the palette:
+   FONT_1_PALETTE as the palette:
 <codeblock>
       FONT *f;
       PALETTE pal;
+      char *names[] = { "FONT_1_DATA", "FONT_1_PALETTE" }
       
       f = load_dat_font("fonts.dat", pal, NULL);
 <endblock>
@@ -6079,18 +6219,15 @@
 <codeblock>
       FONT *f;
       PALETTE pal;
-      int n;
+      char *names[] = { "FONT_2_DATA", "FONT_2_PALETTE" }
       
-      n = 1;      /* Zero based! */
-      f = load_dat_font("fonts.dat", pal, &n);
+      f = load_dat_font("fonts.dat", pal, NULL);
 <endblock>
-   If you want to load the third font, but discard the palette from FONT_2,
-   use:
+   If you want to load the third font, but not bother with a palette, use:
 <codeblock>
       FONT *f;
-      int n;
+      char *names[] = { "FONT_3_DATA", NULL }
       
-      n = 2;      /* Zero based! */
       f = load_dat_font("fonts.dat", NULL, &n);<endblock>
 @retval
    Returns a pointer to the font or NULL on error. Remember that you are
@@ -6131,15 +6268,15 @@
 @xref register_font_file_type, load_font, load_bitmap, set_color_depth
 @shortdesc Grabs a font from a bitmap file.
    Tries to grab a font from a bitmap. The bitmap can be in any format that
-   load_bitmap understands but it must have a colour depth of 8 bits.
+   load_bitmap understands but it must have a color depth of 8 bits.
 
    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). Use colour 0 for the transparent
+   space (32) up to the tilde (126). Use color 0 for the transparent
    portions of the characters and fill the spaces between each letter with
    color 255.
    
-   Note that in each horizontal row the colour-0 bounding boxes around the
+   Note that in each horizontal row the color-0 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 
@@ -6151,6 +6288,30 @@
    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
? keyboard.dat
? language.dat
Index: include/allegro/internal/aintern.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/internal/aintern.h,v
retrieving revision 1.25
diff -u -p -r1.25 aintern.h
--- include/allegro/internal/aintern.h	20 Jan 2005 21:39:06 -0000	1.25
+++ include/allegro/internal/aintern.h	22 Jan 2005 21:56:44 -0000
@@ -230,8 +230,9 @@ typedef struct FONT_VTABLE
    AL_METHOD(void, render, (AL_CONST FONT *f, AL_CONST char *text, int fg, int bg, BITMAP *bmp, int x, int y));
    AL_METHOD(void, destroy, (FONT *f));
 
-   AL_METHOD(int, get_font_range_begin, (FONT *f));
-   AL_METHOD(int, get_font_range_end, (FONT *f));
+   AL_METHOD(int, get_font_ranges, (FONT *f));
+   AL_METHOD(int, get_font_range_begin, (FONT *f, int range));
+   AL_METHOD(int, get_font_range_end, (FONT *f, int range));
    AL_METHOD(FONT *, extract_font_range, (FONT *f, int begin, int end));
    AL_METHOD(FONT *, merge_fonts, (FONT *f1, FONT *f2));
 } FONT_VTABLE;
Index: src/font.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/font.c,v
retrieving revision 1.10
diff -u -p -r1.10 font.c
--- src/font.c	22 Jan 2005 13:31:52 -0000	1.10
+++ src/font.c	22 Jan 2005 21:56:46 -0000
@@ -578,45 +578,91 @@ static void mono_destroy(FONT* f)
 
 
 
-/* mono_get_font_range_begin:
+/* mono_get_font_ranges:
  *  (mono vtable entry)
- *  Get first character for font.
+ *  Returns the number of character ranges in a font, or -1 if that information
+ *   is not available.
  */
-static int mono_get_font_range_begin(FONT* f)
+int mono_get_font_ranges(FONT *f)
 {
     FONT_MONO_DATA* mf = 0;
+    int ranges = 0;
 
-    if (!f || !f->data) 
-      return -1;
+    if (!f) 
+        return -1;
 
     mf = (FONT_MONO_DATA*)(f->data);
-    return mf->begin;
+
+    while(mf) {
+        FONT_MONO_DATA* next = mf->next;
+        
+        ranges++;
+        if (!next)
+            return ranges;
+         mf = next;
+    }
+
+    return -1;
+}
+
+
+
+/* mono_get_font_range_begin:
+ *  (mono vtable entry)
+ *  Get first character for font range. Pass -1 to get the start of the font.
+ */
+static int mono_get_font_range_begin(FONT* f, int range)
+{
+   FONT_MONO_DATA* mf = 0;
+   int n;
+
+   if (!f || !f->data) 
+      return -1;
+      
+   if (range < 0)
+      range = 0;
+   n = 0;
+
+   mf = (FONT_MONO_DATA*)(f->data);
+   while(mf && n<=range) {
+      FONT_MONO_DATA* next = mf->next;
+        
+      if (!next || range == n)
+         return mf->begin;
+      mf = next;
+      n++;
+   }
+
+   return -1;
 }
 
 
 
 /* mono_get_font_range_end:
  *  (mono vtable entry)
- *  Get last character for font.
+ *  Get last character for font range. Pass -1 to search the entire font
  */
-static int mono_get_font_range_end(FONT* f)
+static int mono_get_font_range_end(FONT* f, int range)
 {
-    FONT_MONO_DATA* mf = 0;
+   FONT_MONO_DATA* mf = 0;
 
-    if (!f) 
-        return -1;
+   if (!f) 
+      return -1;
 
-    mf = (FONT_MONO_DATA*)(f->data);
+   n = 0;
 
-    while(mf) {
-        FONT_MONO_DATA* next = mf->next;
+   mf = (FONT_MONO_DATA*)(f->data);
+
+   while(mf && (n<=range || range==-1)) {
+      FONT_MONO_DATA* next = mf->next;
         
-        if (!next)
-            return mf->end;
-         mf = next;
-    }
+      if (!next || range == n)
+         return mf->end;
+      mf = next;
+      n++;
+   }
 
-    return -1;
+   return -1;
 }
 
 
@@ -688,8 +734,8 @@ FONT *mono_extract_font_range(FONT *f, i
    fontout->data = NULL;
 
    /* Get real character ranges */
-   first = MAX(begin, mono_get_font_range_begin(f));
-   last = (end>-1) ? MIN(end, mono_get_font_range_end(f)) : mono_get_font_range_end(f);
+   first = MAX(begin, mono_get_font_range_begin(f, -1));
+   last = (end>-1) ? MIN(end, mono_get_font_range_end(f, -1)) : mono_get_font_range_end(f, -1);
    
    mf = NULL;
    mfin = f->data;
@@ -895,19 +941,62 @@ static void color_destroy(FONT* f)
 
 
 
+/* color_get_font_ranges:
+ *  (color vtable entry)
+ *  Returns the number of character ranges in a font, or -1 if that information
+ *   is not available.
+ */
+int color_get_font_ranges(FONT *f)
+{
+    FONT_COLOR_DATA* cf = 0;
+    int ranges = 0;
+
+    if (!f) 
+        return -1;
+
+    cf = (FONT_COLOR_DATA*)(f->data);
+
+    while(cf) {
+        FONT_COLOR_DATA* next = cf->next;
+        
+        ranges++;
+        if (!next)
+            return ranges;
+         cf = next;
+    }
+
+    return -1;
+}
+
+
+
 /* color_get_font_range_begin:
  *  (color vtable entry)
  *  Get first character for font.
  */
-static int color_get_font_range_begin(FONT* f)
+static int color_get_font_range_begin(FONT* f, int range)
 {
-    FONT_COLOR_DATA* cf = 0;
+   FONT_COLOR_DATA* cf = 0;
+   int n;
 
-    if (!f || !f->data) 
+   if (!f || !f->data) 
       return -1;
+      
+   if (range < 0)
+      range = 0;
+   n = 0;
+
+   cf = (FONT_COLOR_DATA*)(f->data);
+   while(cf && n<=range) {
+      FONT_COLOR_DATA* next = cf->next;
+        
+      if (!next || range == n)
+         return cf->begin;
+      cf = next;
+      n++;
+   }
 
-    cf = (FONT_COLOR_DATA* )(f->data);
-    return cf->begin;
+   return -1;
 }
 
 
@@ -916,7 +1005,7 @@ static int color_get_font_range_begin(FO
  *  (color vtable entry)
  *  Get last character for font.
  */
-static int color_get_font_range_end(FONT* f)
+static int color_get_font_range_end(FONT* f, int range)
 {
     FONT_COLOR_DATA* cf = 0;
 
@@ -933,6 +1022,26 @@ static int color_get_font_range_end(FONT
     }
 
     return -1;
+
+   FONT_COLOR_DATA* cf = 0;
+
+   if (!f) 
+      return -1;
+
+   n = 0;
+
+   mf = (FONT_COLOR_DATA*)(f->data);
+
+   while(cf && (n<=range || range==-1)) {
+      FONT_COLOR_DATA* next = cf->next;
+        
+      if (!next || range == n)
+         return cf->end;
+      cf = next;
+      n++;
+   }
+
+   return -1;
 }
 
 
@@ -1055,8 +1164,8 @@ FONT *color_extract_font_range(FONT *f, 
    fontout->data = NULL;
 
    /* Get real character ranges */
-   first = MAX(begin, mono_get_font_range_begin(f));
-   last = (end>-1) ? MIN(end, mono_get_font_range_end(f)) : mono_get_font_range_end(f);
+   first = MAX(begin, color_get_font_range_begin(f, -1));
+   last = (end>-1) ? MIN(end, color_get_font_range_end(f, -1)) : color_get_font_range_end(f, -1);
    
    cf = NULL;
    cfin = f->data;
@@ -1148,92 +1257,6 @@ FONT *color_merge_fonts(FONT *font1, FON
 
    return fontout;
 }
-#if 0
-/* color_merge_fonts:
- *  (color vtable entry)
- *  Merges font2 with font1 and returns a new font
- */
-FONT *color_merge_fonts(FONT *font1, FONT *font2)
-{
-   FONT *fontout = NULL, *fontin = NULL;
-   FONT_COLOR_DATA *cf, *cf1, *cf2;
-   BITMAP **gl;
-   BITMAP *g;
-   int first, last, num, c;
-   int colconv;
-   
-   if (!font1 || !font2)
-      return NULL;
-   
-   /* Promote font 2 to colour if it is a monochrome font */
-   if (!is_color_font(font1))
-      return NULL;
-   
-   if (is_mono_font(font2))
-      fontin = upgrade_to_color(font2);
-   else
-      fontin = font2;
-
-   if (!is_color_font(font2))
-      return NULL;
-   
-   /* Get output font */
-   fontout = _al_malloc(sizeof *fontout);
-   fontout->height = font1->height;
-   fontout->vtable = font1->vtable;
-   cf = fontout->data = NULL;
-   
-   cf1 = font1->data;
-   cf2 = fontin->data;
-   
-   colconv = get_color_conversion();
-   set_color_conversion(COLORCONV_NONE);
-   
-   while (cf1 || cf2) {
-      if (cf1 && (!cf2 ||  (cf1->begin < cf2->begin))) {
-         if (cf) {
-            cf->next = _al_malloc(sizeof *cf);
-            cf = cf->next;
-         } else {
-            fontout->data = cf = _al_malloc(sizeof *cf);
-         }
-         num = cf1->end - cf1->begin+1;
-         cf->begin = cf1->begin;
-         cf->end = cf1->end;
-         gl = cf->bitmaps = _al_malloc(num *sizeof *gl);
-         for (c=0; c<num; c++) {
-            g = cf1->bitmaps[c];
-            gl[c] = create_bitmap_ex(8, g->w, g->h);
-            blit(g, gl[c], 0,0, 0,0, g->w,g->h);
-         }
-         cf1 = cf1->next;
-      } else {
-         if (cf) {
-            cf->next = _al_malloc(sizeof *cf);
-            cf = cf->next;
-         } else {
-            fontout->data = cf = _al_malloc(sizeof *cf);
-         }
-         num = cf2->end - cf2->begin+1;
-         cf->begin = cf2->begin;
-         cf->end = cf2->end;
-         gl = cf->bitmaps = _al_malloc(num * sizeof *gl);
-         for (c=0; c<num; c++) {
-            g = cf2->bitmaps[c];
-            gl[c] = create_bitmap_ex(8, g->w, g->h);
-            blit(g, gl[c], 0,0, 0,0, g->w,g->h);
-         }
-         cf2 = cf2->next;
-      }
-   }
-   set_color_conversion(colconv);
-   
-   if (fontin != font2)
-      destroy_font(fontin);
-   
-   return fontout;
-}
-#endif
 
 
 
@@ -1249,6 +1272,8 @@ FONT_VTABLE _font_vtable_mono = {
     mono_render,
     mono_destroy,
     
+
+    mono_get_font_ranges,
     mono_get_font_range_begin,
     mono_get_font_range_end,
     mono_extract_font_range,
@@ -1265,6 +1290,7 @@ FONT_VTABLE _font_vtable_color = {  
     color_render,
     color_destroy,
     
+    color_get_font_ranges,
     color_get_font_range_begin,
     color_get_font_range_end,
     color_extract_font_range,
@@ -1344,6 +1370,20 @@ FONT *merge_fonts(FONT *f1, FONT *f2)
 
 
 
+/* get_font_ranges:
+ *  Returns the number of character ranges in a font, or -1 if that information
+ *   is not available.
+ */
+int get_font_ranges(FONT *f)
+{
+   if (f->vtable->get_font_ranges)
+      return f->vtable->get_font_ranges(f);
+   
+   return -1;
+}
+
+
+
 /* get_font_range_begin:
  *  Returns the starting character for the font in question, or -1 if that
  *   information is not available.
Index: src/fontdat.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fontdat.c,v
retrieving revision 1.1
diff -u -p -r1.1 fontdat.c
--- src/fontdat.c	16 Jan 2005 11:14:48 -0000	1.1
+++ src/fontdat.c	22 Jan 2005 21:56:46 -0000
@@ -21,45 +21,76 @@
 #include "allegro.h"
 
 /* load_dat_font:
- *  Loads a font from the datafile named filename. The palette is set to the
- *  last palette encountered before the font. param points to an integer that
- *  specifies what font to load, if there is more than one in the datafile.
- *  Either of these may be NULL, in which case the palette is ignored and a
- *  value of 0 is used for the font index
+ *  Loads a font from the datafile named filename. param can optionally be set
+ *  to a list of two strings, which you can use to load a specific font and
+ *  palette from a datafile by name. If pal is NULL, or the second string
+ *  argument is NULL, no palette information is returned.
+ *  If param is NULL, the first font found in the datafile will be returned
+ *  and the last palette found prior to the font will be returned.
  */
 FONT *load_dat_font(AL_CONST char *filename, RGB *pal, void *param)
 {
    FONT *fnt;
    DATAFILE *df;
    RGB *p = NULL;
-   int font_index, c, n;
+   char **names;
+   int c, n, want_palette;
    ASSERT(filename);
    
+   /* Load font and palette by name? */
+   names = param;
+   
    fnt = NULL;
-   font_index = param?*(int *)param:0;
-   df = load_datafile(filename);
-   if (!df) {
-      return NULL;
+   p = NULL;
+
+   /* Load font by name? */
+   if (names && names[0]) {
+      df = load_datafile_object(filename, names[0]);
+      if (!df) {
+         return NULL;
+      }
+      fnt = df->dat;
+      df->dat = NULL;
+      unload_datafile_object(df);
+   }
+   
+   /* Load palette by name? */
+   want_palette = TRUE;
+   if (names && names[1]) {
+      df = load_datafile_object(filename, names[1]);
+      if (df) {
+         memcpy(pal, df->dat, sizeof(PALETTE));
+      }
+      unload_datafile_object(df);
+      want_palette = FALSE;
    }
-   n = 0;
-   for (c=0; df[c].type!=DAT_END; c++) {
-      if (df[c].type==DAT_PALETTE)
-         p = df[c].dat;
-      if (df[c].type==DAT_FONT) {
-         if (font_index==n) {
+   
+   if (!fnt || want_palette) {
+      df = load_datafile(filename);
+   
+      if (!df) {
+         return NULL;
+      }
+   
+      for (c=0; df[c].type!=DAT_END; c++) {
+         /* Only pick the last palette if no palette was named */
+         if (df[c].type==DAT_PALETTE && want_palette)
+            p = df[c].dat;
+         /* Only pick a font if no font was named */
+         if (df[c].type==DAT_FONT && !fnt) {
             fnt = df[c].dat;
             df[c].dat = NULL;
             break;
          }
-         else {
-            n++;
-         }
       }
-   }
-   if (p && pal && fnt) {
-      memcpy(pal, p, sizeof(PALETTE));
+   
+   
+      if (p && pal && want_palette && fnt) {
+         memcpy(pal, p, sizeof(PALETTE));
+      }
+   
+      unload_datafile(df);
    }
    
-   unload_datafile(df);
    return fnt;
 }


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