diff --git a/ChangeLog b/ChangeLog index d4240a043..81fb71828 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2002-06-14 Detlef Würkner + + Fix glyph indices to make index zero always the undefined glyph. + + * src/bdf/bdfdrivr.c (bdf_cmap_init): Don't decrease + cmap->num_encodings. + (bdf_cmap_char_index, bdf_cmap_char_next, BDF_Get_Char_Index): + Increase result by 1 for normal cases. + (BDF_Glyph_Load): Decrease index by 1. + + * src/pcf/pcfdriver.c (pcf_cmap_char_index, pcf_cmap_char_next, + PCF_Char_Get_Index): Increase result by 1 for normal cases. + (PCF_Glyph_Load): Decrease index by 1. + * src/pcf/pcfread.c (pcf_get_encodings): Don't decrease j for + allocating `encoding'. + + * src/base/ftobjs.c (FT_Load_Glyph, FT_Get_Glyph_Name): Fix + bounding tests. + 2002-06-14 Detlef Würkner Add new cmap support to BDF driver diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 80851d1c0..2aafc3a7f 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -2424,6 +2424,12 @@ FT_BEGIN_HEADER /* */ /* The glyph index. 0 means `undefined character code'. */ /* */ + /* */ + /* FreeType computes its own glyph indices which are not necessarily */ + /* the same as used in the font in case the font is based on glyph */ + /* indices. Reason for this behaviour is to assure that index 0 is */ + /* never used, representing the missing glyph. */ + /* */ FT_EXPORT( FT_UInt ) FT_Get_Char_Index( FT_Face face, FT_ULong charcode ); diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 8b20c1612..0fce50cd7 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -402,7 +402,7 @@ if ( !face || !face->size || !face->glyph ) return FT_Err_Invalid_Face_Handle; - if ( glyph_index >= (FT_UInt)face->num_glyphs ) + if ( glyph_index > (FT_UInt)face->num_glyphs ) return FT_Err_Invalid_Argument; slot = face->glyph; @@ -1676,9 +1676,9 @@ if ( buffer && buffer_max > 0 ) ((FT_Byte*)buffer)[0] = 0; - if ( face && - glyph_index < (FT_UInt)face->num_glyphs && - FT_HAS_GLYPH_NAMES( face ) ) + if ( face && + glyph_index <= (FT_UInt)face->num_glyphs && + FT_HAS_GLYPH_NAMES( face ) ) { /* now, lookup for glyph name */ FT_Driver driver = face->driver; diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c index 0e8275853..4a97e3d6a 100644 --- a/src/bdf/bdfdrivr.c +++ b/src/bdf/bdfdrivr.c @@ -64,7 +64,7 @@ THE SOFTWARE. BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap ); - cmap->num_encodings = face->bdffont->glyphs_used - 1; + cmap->num_encodings = face->bdffont->glyphs_used; cmap->encodings = face->en_table; return FT_Err_Ok; @@ -101,7 +101,7 @@ THE SOFTWARE. if ( charcode == code ) { - result = encodings[mid].glyph; + result = encodings[mid].glyph + 1; break; } @@ -138,7 +138,7 @@ THE SOFTWARE. if ( charcode == code ) { - result = encodings[mid].glyph; + result = encodings[mid].glyph + 1; goto Exit; } @@ -152,7 +152,7 @@ THE SOFTWARE. if ( min < cmap->num_encodings ) { charcode = encodings[min].enc; - result = encodings[min].glyph; + result = encodings[min].glyph + 1; } Exit: @@ -196,10 +196,10 @@ THE SOFTWARE. else if ( char_code > en_table[mid].enc ) low = mid + 1; else - return en_table[mid].glyph; + return en_table[mid].glyph + 1; } - return face->bdffont->default_glyph; + return face->bdffont->default_glyph + 1; } @@ -560,6 +560,9 @@ THE SOFTWARE. goto Exit; } + if ( glyph_index > 0 ) + glyph_index--; + /* slot, bitmap => freetype, glyph => bdflib */ glyph = face->bdffont->glyphs[glyph_index]; diff --git a/src/pcf/pcfdriver.c b/src/pcf/pcfdriver.c index a1636e04b..c9e3972bf 100644 --- a/src/pcf/pcfdriver.c +++ b/src/pcf/pcfdriver.c @@ -95,7 +95,7 @@ THE SOFTWARE. if ( charcode == code ) { - result = encodings[mid].glyph; + result = encodings[mid].glyph + 1; break; } @@ -132,7 +132,7 @@ THE SOFTWARE. if ( charcode == code ) { - result = encodings[mid].glyph; + result = encodings[mid].glyph + 1; goto Exit; } @@ -146,7 +146,7 @@ THE SOFTWARE. if ( min < cmap->num_encodings ) { charcode = encodings[min].enc; - result = encodings[min].glyph; + result = encodings[min].glyph + 1; } Exit: @@ -187,7 +187,7 @@ THE SOFTWARE. else if ( char_code > en_table[mid].enc ) low = mid + 1; else - return en_table[mid].glyph; + return en_table[mid].glyph + 1; } return 0; @@ -433,6 +433,9 @@ THE SOFTWARE. goto Exit; } + if ( glyph_index > 0 ) + glyph_index--; + metric = face->metrics + glyph_index; bitmap->rows = metric->ascent + metric->descent; diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 96f484181..6a1a8a296 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -716,7 +716,6 @@ THE SOFTWARE. } FT_Stream_ExitFrame( stream ); - j--; if ( FT_NEW_ARRAY( encoding, j ) ) goto Bail;