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 Mon, 2005-05-30 at 23:42 +0200, Evert Glebbeek wrote:
> > Updated patch.
> 
> Looks good except for one thing:
> 
> - *  Get last character for font.
> + *  Get one past last character for font.
> 
> The original behavior is the intended (and documented) one, we shouldn't
> change it. That probably means there need to be a few more tweaks and fixes
> in places where get_font_range_end() is called.
> 

Ah, yes, I grepped for all internal uses of those functions and adjusted
them by one. New attempt attached. The "last" variables are now actually
the last character, but "end" inside the font structure is one past the
last (well, the end :P). For 4.3.x, we might be able to de-confuse this
and change it to always use inclusive range, which I agree is more
logical - but for now, not worth breaking AllegroGL because of it.

Speaking of AllegroGL, this reminds me again, we definitely should try
to get Bob to do a synchronized release of AllegroGL when 4.2.0 is
released. Judging from allegro.cc, AllegroGL is quite popular, either
directly or through OpenLayer, so releasing 4.2.0 with only the CVS
AllegroGL working together with it seems strange.. maybe even could have
an AllegroGL 0.3.0 (or whatever the next would be) beta1 together with
4.2.0 beta4 (RC1?). The final 0.3.0 could then be delayed after Allegro
4.2.0 in case there are a lot of issues, but at least there would be a
version to get along with it (but I don't think there are any issues).

-- 
Elias Pschernig
Index: tools/plugins/datfont.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/plugins/datfont.c,v
retrieving revision 1.27
diff -u -p -r1.27 datfont.c
--- tools/plugins/datfont.c	3 May 2005 20:56:46 -0000	1.27
+++ tools/plugins/datfont.c	31 May 2005 12:35:45 -0000
@@ -751,7 +751,7 @@ static char *range_getter(int index, int
         return 0;
     }
 
-    sprintf(buf, "%04X-%04X, color", get_font_range_begin(f, index), get_font_range_end(f, index) - 1);
+    sprintf(buf, "%04X-%04X, color", get_font_range_begin(f, index), get_font_range_end(f, index));
 
     return buf;
 }
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	31 May 2005 12:35:45 -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 last character for font range. Pass -1 to search the entire font.
  */
 static int mono_get_font_range_end(FONT* f, int range)
 {
@@ -656,9 +656,8 @@ static int mono_get_font_range_end(FONT*
 
    while(mf && (n<=range || range==-1)) {
       FONT_MONO_DATA* next = mf->next;
-        
       if (!next || range == n)
-         return mf->end;
+         return mf->end - 1;
       mf = next;
       n++;
    }
@@ -689,7 +688,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++) {
@@ -737,12 +736,12 @@ FONT *mono_extract_font_range(FONT *f, i
    /* Get real character ranges */
    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;
    while (mfin) {
       /* Check if we've found the proper range */
-      if ((first >= mfin->begin) && (last<=mfin->end)) {
+      if ((first >= mfin->begin) && (last<mfin->end)) {
          int local_begin, local_end;
          
          local_begin = MAX(mfin->begin, first);
@@ -1054,7 +1053,7 @@ static int color_get_font_range_begin(FO
 
 /* color_get_font_range_end:
  *  (color vtable entry)
- *  Get last character for font.
+ *  Get last character for font range.
  */
 static int color_get_font_range_end(FONT* f, int range)
 {
@@ -1070,9 +1069,8 @@ static int color_get_font_range_end(FONT
 
    while(cf && (n<=range || range==-1)) {
       FONT_COLOR_DATA* next = cf->next;
-        
       if (!next || range == n)
-         return cf->end;
+         return cf->end - 1;
       cf = next;
       n++;
    }
@@ -1088,7 +1086,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 +1094,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 +1156,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 +1164,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,12 +1199,12 @@ 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) {
       /* Check if we've found the proper range */
-      if ((first >= cfin->begin) && (last<=cfin->end)) {
+      if ((first >= cfin->begin) && (last<cfin->end)) {
          int local_begin, local_end;
          
          local_begin = MAX(cfin->begin, first);
@@ -1222,7 +1220,7 @@ FONT *color_extract_font_range(FONT *f, 
       }
       cfin = cfin->next;
    }
-   
+
    return fontout;
 }
 
@@ -1402,7 +1400,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)
 {
@@ -1462,13 +1460,13 @@ int get_font_range_begin(FONT *f, int ra
 
 /* get_font_range_end:
  *  Returns the last character for the font in question, or -1 if that
- *   information is not available.
+ *  information is not available.
  */
 int get_font_range_end(FONT *f, int range)
 {
    if (f->vtable->get_font_range_end)
       return f->vtable->get_font_range_end(f, range);
-   
+
    return -1;
 }
 
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	31 May 2005 12:35:45 -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;


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