Re: [AD] Old problems that still persist on Allegro 4.2 beta 3

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


On Thu, 2005-05-26 at 15:47 +0200, Elias Pschernig wrote:

> I'll also update the demo.dat font with all characters of the builtin
> font (using FreeSans.ttf, unless someone sends me a better one).
> 

Hm, harder than I thought. The attached patch allowed me to do it,
otherwise grabber and dat would choke on the same files for which 4.0.3
grabber and dat work fine. Oh, and it's quite late, so in fact, I'm not
very sure about the patch..

-- 
Elias Pschernig
Index: src/font.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/font.c,v
retrieving revision 1.19
diff -u -p -r1.19 font.c
--- src/font.c	16 May 2005 12:40:48 -0000	1.19
+++ src/font.c	26 May 2005 23:21:29 -0000
@@ -1158,7 +1158,7 @@ static FONT_COLOR_DATA *color_copy_glyph
    newcf->begin = begin;
    newcf->end = end;
    newcf->next = NULL;
-   num = end - begin+1;
+   num = end - begin;
 
    gl = newcf->bitmaps = _al_malloc(num * sizeof *gl);
    for (c=0; c<num; c++) {
@@ -1166,7 +1166,7 @@ static FONT_COLOR_DATA *color_copy_glyph
       gl[c] = create_bitmap_ex(8, g->w, g->h);
       blit(g, gl[c], 0, 0, 0, 0, g->w, g->h);
    }
-   
+
    return newcf;
 }
 
@@ -1201,7 +1201,7 @@ FONT *color_extract_font_range(FONT *f, 
    /* Get real character ranges */
    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;
    while (cfin) {
@@ -1402,7 +1402,7 @@ int is_compatible_font(FONT *f1, FONT *f
 /* extract_font_range:
  *  Extracts a character range from a font f, and returns a new font containing
  *   only the extracted characters.
- * Returns NULL if teh character range could not be extracted.
+ * Returns NULL if the character range could not be extracted.
  */
 FONT *extract_font_range(FONT *f, int begin, int end)
 {
Index: src/fonttxt.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fonttxt.c,v
retrieving revision 1.2
diff -u -p -r1.2 fonttxt.c
--- src/fonttxt.c	19 Mar 2005 11:15:06 -0000	1.2
+++ src/fonttxt.c	26 May 2005 23:21:29 -0000
@@ -27,7 +27,7 @@
 FONT *load_txt_font(AL_CONST char *filename, RGB *pal, void *param)
 {
    char buf[1024], *font_str, *start_str = 0, *end_str = 0;
-   FONT *f, *f2, *f3, *f4;
+   FONT *f, *f2, *f3;
    PACKFILE *pack;
    int begin, end;
 
@@ -35,7 +35,7 @@ FONT *load_txt_font(AL_CONST char *filen
    if (!pack) 
       return NULL;
 
-   f = f2 = f3 = f4 = NULL;
+   f = f2 = f3 = NULL;
 
    while(pack_fgets(buf, sizeof(buf)-1, pack)) {
       font_str = strtok(buf, " \t");
@@ -69,19 +69,29 @@ FONT *load_txt_font(AL_CONST char *filen
 
       /* Load the font that needs to be merged with the current font */
       if (font_str[0]) {
-         if (f4)
-            destroy_font(f4);
-         f4 = load_font(font_str, pal, param);
+         if (f2)
+            destroy_font(f2);
+         f2 = load_bitmap_font(font_str, pal, param);
       }
-      if(!f4) {
+      if(!f2) {
          destroy_font(f);
          pack_fclose(pack);
-
          return NULL;
       }
-      
-      /* Extract font range */
-      f2 = extract_font_range(f4, begin, end);
+
+      /* load_bitmap_font makes the font start with character 32, so f2 is a
+       * wrong font, we can't use functions like extract_font_range on it.
+       * Instead, we transpose all characters so they have the correct range
+       * again.
+       */
+      transpose_font(f2, begin - 32);
+
+      /* Merge with the main font
+       * TODO: This is somewhat inefficient currently, instead of simply adding the new
+       * range to the end of the list, we copy the whole font. With a complete
+       * unicode font, this may be bad.
+       * Probably need a vtable entry insert_font_range or something.
+       */
       if (f) {
          f3 = f;
          f = merge_fonts(f2, f3);
@@ -89,10 +99,9 @@ FONT *load_txt_font(AL_CONST char *filen
          destroy_font(f2);
       } else {
          f = f2;
-         f2 = NULL;
       }
+      f2 = NULL;
     }
-    destroy_font(f4);
 
     pack_fclose(pack);
     return f;


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