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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
diff --git a/ChangeLog b/ChangeLog
index d4240a0..81fb718 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
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
* src/bdf/bdfdrivr.c (BDF_CMapRec) [FT_CONFIG_OPTION_USE_CMAPS]:
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 80851d1..2aafc3a 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -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 );
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 8b20c16..0fce50c 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 0e82758..4a97e3d 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 a1636e0..c9e3972 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 96f4841..6a1a8a2 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;