[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Devel] Fixes for glyph index problems
From: |
Detlef Würkner |
Subject: |
[Devel] Fixes for glyph index problems |
Date: |
Fri, 14 Jun 2002 20:02:13 +0200 |
Hello!
A zero returncode from FT_Get_Char_Index() is supposed to indicate
an error. The current PCF and BDF drivers return zero for the first
glyph which fails with e.g. the glyph cache code. To avoid that I
changed the BDF and PCF drivers to work like the FNT driver: return
index+1 instead of index when asked for it, use index-1 instead of
index for glyph loading.
This changes enabled usage of the first glyph for BDF and PCF,
for usage of the last glyph three additional bugs had to be fixed:
- the cmap of the BDF driver missed the last entry (my fault).
- the encoding table of the PCF driver missed the last entry.
- FT_Load_Glyph() and FT_Get_Glyph() reported an error if
glyph_index == face->num_glyphs which already was wrong with
the FNT driver. Didn't check if this changes also fix loading
of the last glyph for e.g. the TT and PS drivers or if they
result in accessing a non-existant last glyph, and my debugging
environment wont report memory reads from beyond the end of an
array, so please test the FT_Load_Glyph() and FT_Get_Glyph()
changes with the font drivers for scalable fonts.
----8<----
--- freetype2-current/src/bdf/bdfdrivr.c.ori Fri Jun 14 09:06:46 2002
+++ freetype2-current/src/bdf/bdfdrivr.c Fri Jun 14 14:48:43 2002
@@ -64,7 +64,7 @@
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 @@
if ( charcode == code )
{
- result = encodings[mid].glyph;
+ result = encodings[mid].glyph + 1;
break;
}
@@ -138,7 +138,7 @@
if ( charcode == code )
{
- result = encodings[mid].glyph;
+ result = encodings[mid].glyph + 1;
goto Exit;
}
@@ -152,7 +152,7 @@
if ( min < cmap->num_encodings )
{
charcode = encodings[min].enc;
- result = encodings[min].glyph;
+ result = encodings[min].glyph + 1;
}
Exit:
@@ -196,10 +196,10 @@
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;
}
@@ -559,6 +559,9 @@
error = BDF_Err_Invalid_Argument;
goto Exit;
}
+
+ if ( glyph_index > 0 )
+ glyph_index--;
/* slot, bitmap => freetype, glyph => bdflib */
glyph = face->bdffont->glyphs[glyph_index];
--- freetype2-current/src/pcf/pcfdriver.c.ori Mon Jun 10 22:41:57 2002
+++ freetype2-current/src/pcf/pcfdriver.c Fri Jun 14 17:00:22 2002
@@ -95,7 +95,7 @@
if ( charcode == code )
{
- result = encodings[mid].glyph;
+ result = encodings[mid].glyph + 1;
break;
}
@@ -132,7 +132,7 @@
if ( charcode == code )
{
- result = encodings[mid].glyph;
+ result = encodings[mid].glyph + 1;
goto Exit;
}
@@ -146,7 +146,7 @@
if ( min < cmap->num_encodings )
{
charcode = encodings[min].enc;
- result = encodings[min].glyph;
+ result = encodings[min].glyph + 1;
}
Exit:
@@ -187,7 +187,7 @@
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;
@@ -432,6 +432,9 @@
error = PCF_Err_Invalid_Argument;
goto Exit;
}
+
+ if ( glyph_index > 0 )
+ glyph_index--;
metric = face->metrics + glyph_index;
--- freetype2-current/src/pcf/pcfread.c.ori Tue Apr 16 13:39:17 2002
+++ freetype2-current/src/pcf/pcfread.c Fri Jun 14 17:08:12 2002
@@ -716,7 +716,6 @@
}
FT_Stream_ExitFrame( stream );
- j--;
if ( FT_NEW_ARRAY( encoding, j ) )
goto Bail;
--- freetype2-current/src/base/ftobjs.c.ori Mon Jun 10 23:03:35 2002
+++ freetype2-current/src/base/ftobjs.c Fri Jun 14 14:44:26 2002
@@ -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;
----8<----
Ciao, Detlef
--
_ // address@hidden
\X/ Detlef Wuerkner, Langgoens/Germany
- [Devel] Fixes for glyph index problems,
Detlef Würkner <=