[AD] extract font range fix

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


Hi!

The attached patch fixes two bugs in extract_font_range.

Let me explain the first one, fixed by replacing && with ||:
Picture a font with two non-colliding ranges: 30-60 and 80-100. When the one calls extract_font_range(font, -1, -1) it will fail because the given range fits none of the existing ranges. With this fix even extract_font_range(font, 50, 90) will work.

The second bug shows up when the one tries to copy the font with the extract_font_range(font, -1, -1) call. The new font will miss the last glyph.


--
Milan Mimica
http://sparklet.sf.net
--- src/font_old.c	2005-08-21 23:00:55.000000000 +0200
+++ src/font.c	2005-08-21 23:25:22.000000000 +0200
@@ -734,15 +734,15 @@ FONT *mono_extract_font_range(FONT *f, i
    fontout->data = NULL;
 
    /* 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);
+   last = (end>-1) ? MIN(end, mono_get_font_range_end(f, -1)) : mono_get_font_range_end(f, -1) + 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);
          local_end = MIN(mfin->end, last);
@@ -1200,15 +1200,15 @@ FONT *color_extract_font_range(FONT *f, 
    fontout->data = NULL;
 
    /* 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);
+   last = (end>-1) ? MIN(end, color_get_font_range_end(f, -1)) : color_get_font_range_end(f, -1) + 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);
          local_end = MIN(cfin->end, last);


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