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 Fri, 2005-05-27 at 21:15 +0200, Elias Pschernig wrote:
> > 
> > Yeah, but post the patch first.
> 
> Ok, attached. Also made the comments from the last patch shorter.
> 

Updated patch.

-- 
Elias Pschernig
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	30 May 2005 11:04:58 -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,23 @@ 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) {
-         destroy_font(f);
+      if(!f2) {
+         if (f)
+            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 transpose
+       * it so it starts at begin.
+       */
+      transpose_font(f2, begin - 32);
+
+      /* FIXME: More efficient way than to repeatedely merge into a new font? */
       if (f) {
          f3 = f;
          f = merge_fonts(f2, f3);
@@ -89,10 +93,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;
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	30 May 2005 11:04:58 -0000
@@ -640,7 +640,7 @@ static int mono_get_font_range_begin(FON
 
 /* mono_get_font_range_end:
  *  (mono vtable entry)
- *  Get last character for font range. Pass -1 to search the entire font
+ *  Get one past last character for font range. Pass -1 to search the entire font
  */
 static int mono_get_font_range_end(FONT* f, int range)
 {
@@ -689,7 +689,7 @@ static FONT_MONO_DATA *mono_copy_glyph_r
    newmf->begin = begin;
    newmf->end = end;
    newmf->next = NULL;
-   num = end - begin+1;
+   num = end - begin;
 
    gl = newmf->glyphs = _al_malloc(num * sizeof *gl);
    for (c=0; c<num; c++) {
@@ -1054,7 +1054,7 @@ static int color_get_font_range_begin(FO
 
 /* color_get_font_range_end:
  *  (color vtable entry)
- *  Get last character for font.
+ *  Get one past last character for font.
  */
 static int color_get_font_range_end(FONT* f, int range)
 {
@@ -1088,7 +1088,7 @@ static int color_get_font_range_end(FONT
 static FONT_COLOR_DATA* upgrade_to_color_data(FONT_MONO_DATA* mf)
 {
     FONT_COLOR_DATA* cf = _al_malloc(sizeof *cf);
-    BITMAP** bits = _al_malloc((mf->end - mf->begin+1)*sizeof *bits);
+    BITMAP** bits = _al_malloc((mf->end - mf->begin)*sizeof *bits);
     int i;
 
     cf->begin = mf->begin;
@@ -1096,7 +1096,7 @@ static FONT_COLOR_DATA* upgrade_to_color
     cf->bitmaps = bits;
     cf->next = 0;
 
-    for(i = mf->begin; i <= mf->end; i++) {
+    for(i = mf->begin; i < mf->end; i++) {
         FONT_GLYPH* g = mf->glyphs[i - mf->begin];
         BITMAP* b = create_bitmap_ex(8, g->w, g->h);
         clear_to_color(b, 0);
@@ -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)
 {


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