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.
This commit is contained in:
Werner Lemberg 2002-06-16 01:14:16 +00:00
parent ec6a0a1612
commit 4c1c87af69
6 changed files with 45 additions and 15 deletions

View File

@ -1,3 +1,22 @@
2002-06-14 Detlef Würkner <TetiSoft@apg.lahn.de>
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 <TetiSoft@apg.lahn.de>
Add new cmap support to BDF driver

View File

@ -2424,6 +2424,12 @@ FT_BEGIN_HEADER
/* <Return> */
/* The glyph index. 0 means `undefined character code'. */
/* */
/* <Note> */
/* 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 );

View File

@ -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;

View File

@ -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];

View File

@ -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;

View File

@ -716,7 +716,6 @@ THE SOFTWARE.
}
FT_Stream_ExitFrame( stream );
j--;
if ( FT_NEW_ARRAY( encoding, j ) )
goto Bail;