In function parse_encoding, initialize encoding_table.elements to have .notdef in each entry. In function parse_charstrings, place the .notdef glyph in index 0, and add a .notdef glyph if it is missing. In function Z1_Open_Face, only change min/max encoded char if it is not .notdef.
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
diff --git a/src/type1z/z1load.c b/src/type1z/z1load.c
index d14a166..c066915 100644
--- a/src/type1z/z1load.c
+++ b/src/type1z/z1load.c
@@ -969,6 +969,13 @@
return;
}
+ /* We need to `zero' out encoding_table.elements */
+ for ( n = 0 ; n < count ; n++ )
+ {
+ char *notdef = ".notdef";
+ Z1_Add_Table( char_table, n, notdef, 8 );
+ }
+
/* Now, we will need to read a record of the form */
/* ... charcode /charname ... for each entry in our table */
/* */
@@ -1170,7 +1177,8 @@
FT_Byte* cur;
FT_Byte* limit = parser->root.limit;
FT_Int n;
-
+ FT_UInt notdef_index = 0;
+ FT_Byte notdef_found = 0;
if ( loader->num_glyphs )
/* with synthetic fonts, it's possible we get here twice */
@@ -1180,15 +1188,15 @@
if ( parser->root.error )
return;
- /* initialize tables */
+ /* initialize tables, adding space for `swap' at table end */
error = psaux->ps_table_funcs->init( code_table,
- loader->num_glyphs,
+ loader->num_glyphs + 1,
memory );
if ( error )
goto Fail;
error = psaux->ps_table_funcs->init( name_table,
- loader->num_glyphs,
+ loader->num_glyphs + 1,
memory );
if ( error )
goto Fail;
@@ -1199,7 +1207,6 @@
FT_Int size;
FT_Byte* base;
-
/* the format is simple: */
/* `/glyphname' + binary data */
/* */
@@ -1243,6 +1250,14 @@
/* add a trailing zero to the name table */
name_table->elements[n][len] = '\0';
+ /* record index of /.notdef */
+ if ( strcmp( (const char*)".notdef",
+ (const char*)(name_table->elements[n]) ) == 0 )
+ {
+ notdef_index = n;
+ notdef_found = 1;
+ }
+
parser->root.cursor = cur2;
if ( !read_binary_data( parser, &size, &base ) )
return;
@@ -1263,7 +1278,94 @@
break;
}
}
+
loader->num_glyphs = n;
+
+ /* if /.notdef is found but does not occupy index 0, do our magic. */
+ if ( strcmp( (const char*)".notdef",
+ (const char*)name_table->elements[0] ) &&
+ notdef_found )
+ {
+
+ /* Swap glyph in index 0 with /.notdef glyph. First, add index 0 */
+ /* name/code to end of table. Then place notdef_index name/code into */
+ /* index 0. Then take end of table name/code and place it into index */
+ /* notdef_index. */
+
+ error = Z1_Add_Table( name_table, n,
+ name_table->elements[0],
+ name_table->lengths [0] );
+ if ( error )
+ goto Fail;
+ error = Z1_Add_Table( code_table, n,
+ code_table->elements[0],
+ code_table->lengths [0] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( name_table, 0,
+ name_table->elements[notdef_index],
+ name_table->lengths [notdef_index] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( code_table, 0,
+ code_table->elements[notdef_index],
+ code_table->lengths [notdef_index] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( name_table, notdef_index,
+ name_table->elements[n],
+ name_table->lengths [n] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( code_table, notdef_index,
+ code_table->elements[n],
+ code_table->lengths [n] );
+ if ( error )
+ goto Fail;
+
+ }
+ else if ( !notdef_found )
+ {
+
+ /* notdef_index is already 0, or /.notdef is undefined in */
+ /* charstrings dictionary. Worry about /.notdef undefined. */
+ /* we take index 0 and add it to the end of the table(s) */
+ /* and add our own /.notdef glyph to index 0. */
+
+ /* 0 333 hsbw endchar */
+ FT_Byte notdef_glyph[] = {0x8B,0xF7,0xE1,0x0D,0x0E};
+ char *notdef_name = ".notdef";
+
+ error = Z1_Add_Table( name_table, n,
+ name_table->elements[0],
+ name_table->lengths [0] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( code_table, n,
+ code_table->elements[0],
+ code_table->lengths [0] );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( name_table, 0, notdef_name, 8 );
+ if ( error )
+ goto Fail;
+
+ error = Z1_Add_Table( code_table, 0, notdef_glyph, 5 );
+
+ if ( error )
+ goto Fail;
+
+ /* we added a glyph. */
+ loader->num_glyphs = n + 1;
+
+ }
+
return;
Fail:
@@ -1569,8 +1671,14 @@
type1->encoding.char_index[charcode] = index;
type1->encoding.char_name [charcode] = (char*)glyph_name;
- if (charcode < min_char) min_char = charcode;
- if (charcode > max_char) max_char = charcode;
+ /* Change min/max encoded char only if glyph name is */
+ /* not /.notdef */
+ if ( strcmp( (const char*)".notdef",
+ (const char*)glyph_name ) != 0 )
+ {
+ if (charcode < min_char) min_char = charcode;
+ if (charcode > max_char) max_char = charcode;
+ }
break;
}
}