New version of the Type 1 driver. Generates a Unicode charmap on the fly through the "psnames" module.. Now, we only need to support afm/pfm files (and maybe multiple masters) to call this driver finished !!
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index 0c974be..b137ddc 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -20,6 +20,7 @@
#include <ftdebug.h>
#include <ftstream.h>
+#include <psnames.h>
#undef FT_COMPONENT
#define FT_COMPONENT trace_t1driver
@@ -137,6 +138,172 @@
}
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* Get_Char_Index */
+ /* */
+ /* <Description> */
+ /* Uses a charmap to return a given character code's glyph index. */
+ /* */
+ /* <Input> */
+ /* charmap :: A handle to the source charmap object. */
+ /* charcode :: The character code. */
+ /* */
+ /* <Return> */
+ /* Glyph index. 0 means `undefined character code'. */
+ /* */
+ static
+ T1_UInt Get_Char_Index( FT_CharMap charmap,
+ T1_Long charcode )
+ {
+ T1_Face face;
+ T1_UInt result = 0;
+ PSNames_Interface* psnames;
+
+ face = (T1_Face)charmap->face;
+ psnames = (PSNames_Interface*)face->psnames;
+ if (psnames)
+ switch (charmap->encoding)
+ {
+ /********************************************************************/
+ /* */
+ /* Unicode encoding support */
+ /* */
+ case ft_encoding_unicode:
+ {
+ /* use the "psnames" module to synthetize the Unicode charmap */
+ result = psnames->lookup_unicode( &face->unicode_map,
+ (T1_ULong)charcode );
+
+ /* the function returns 0xFFFF when the Unicode charcode has */
+ /* no corresponding glyph.. */
+ if (result == 0xFFFF)
+ result = 0;
+ goto Exit;
+ }
+
+ /********************************************************************/
+ /* */
+ /* Custom Type 1 encoding */
+ /* */
+ case ft_encoding_adobe_custom:
+ {
+ T1_Encoding* encoding = &face->type1.encoding;
+ if (charcode >= encoding->code_first &&
+ charcode <= encoding->code_last)
+ {
+ result = encoding->char_index[charcode];
+ }
+ goto Exit;
+ }
+
+ /********************************************************************/
+ /* */
+ /* Adobe Standard & Expert encoding support */
+ /* */
+ default:
+ if (charcode < 256)
+ {
+ FT_UInt code;
+ FT_Int n;
+ const char* glyph_name;
+
+ code = psnames->adobe_std_encoding[charcode];
+ if (charmap->encoding == ft_encoding_adobe_expert)
+ code = psnames->adobe_expert_encoding[charcode];
+
+ glyph_name = psnames->adobe_std_strings(code);
+ if (!glyph_name) break;
+
+ for ( n = 0; n < face->type1.num_glyphs; n++ )
+ {
+ const char* gname = face->type1.glyph_names[n];
+
+ if ( gname && gname[0] == glyph_name[0] &&
+ strcmp( gname, glyph_name ) == 0 )
+ {
+ result = n;
+ break;
+ }
+ }
+ }
+ }
+ Exit:
+ return result;
+ }
+
+
+ static
+ T1_Error Init_Face( FT_Stream stream,
+ FT_Int face_index,
+ T1_Face face )
+ {
+ T1_Error error;
+
+ error = T1_Init_Face(stream, face_index, face);
+ if (!error)
+ {
+ FT_Face root = &face->root;
+ FT_CharMap charmap = face->charmaprecs;
+
+ /* synthetize a Unicode charmap if there is support in the "psnames" */
+ /* module.. */
+ if (face->psnames)
+ {
+ PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
+ if (psnames->unicode_value)
+ {
+ error = psnames->build_unicodes( root->memory,
+ face->type1.num_glyphs,
+ (const char**)face->type1.glyph_names,
+ &face->unicode_map );
+ if (!error)
+ {
+ root->charmap = charmap;
+ charmap->face = (FT_Face)face;
+ charmap->encoding = ft_encoding_unicode;
+ charmap->platform_id = 3;
+ charmap->encoding_id = 1;
+ charmap++;
+ }
+
+ /* simply clear the error in case of failure (which really) */
+ /* means that out of memory or no unicode glyph names */
+ error = 0;
+ }
+ }
+
+ /* now, support either the standard, expert, or custom encodings */
+ charmap->face = (FT_Face)face;
+ charmap->platform_id = 7; /* a new platform id for Adobe fonts ?? */
+
+ switch (face->type1.encoding_type)
+ {
+ case t1_encoding_standard:
+ charmap->encoding = ft_encoding_adobe_standard;
+ charmap->encoding_id = 0;
+ break;
+
+ case t1_encoding_expert:
+ charmap->encoding = ft_encoding_adobe_expert;
+ charmap->encoding_id = 1;
+ break;
+
+ default:
+ charmap->encoding = ft_encoding_adobe_custom;
+ charmap->encoding_id = 2;
+ break;
+ }
+
+ root->charmaps = face->charmaps;
+ root->num_charmaps = charmap - face->charmaprecs + 1;
+ face->charmaps[0] = &face->charmaprecs[0];
+ face->charmaps[1] = &face->charmaprecs[1];
+ }
+ return error;
+ }
+
/******************************************************************/
/* */
/* <Struct> FT_DriverInterface */
@@ -229,7 +396,7 @@
(FTDriver_doneDriver) T1_Done_Driver,
(FTDriver_getInterface) 0,
- (FTDriver_initFace) T1_Init_Face,
+ (FTDriver_initFace) Init_Face,
(FTDriver_doneFace) T1_Done_Face,
(FTDriver_getKerning) 0,
@@ -242,7 +409,7 @@
(FTDriver_doneGlyphSlot) T1_Done_GlyphSlot,
(FTDriver_loadGlyph) T1_Load_Glyph,
- (FTDriver_getCharIndex) 0,
+ (FTDriver_getCharIndex) Get_Char_Index,
};
diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c
index a6a020f..311145c 100644
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -268,7 +268,7 @@
n_base_points = cur->n_points;
/* save the left bearing and width of the base character */
- /* as they will be erase by the next load.. */
+ /* as they will be erased by the next load.. */
left_bearing = decoder->builder.left_bearing;
advance = decoder->builder.advance;
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 95be055..fff4bf7 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -25,6 +25,8 @@
#include <t1hinter.h>
#endif
+#include <psnames.h>
+
/* Required by tracing mode */
#undef FT_COMPONENT
#define FT_COMPONENT trace_t1objs
@@ -182,14 +184,27 @@
FT_Int face_index,
T1_Face face )
{
- T1_Tokenizer tokenizer;
- T1_Error error;
+ T1_Tokenizer tokenizer;
+ T1_Error error;
+ PSNames_Interface* psnames;
(void)face_index;
(void)face;
face->root.num_faces = 1;
+ psnames = (PSNames_Interface*)face->psnames;
+ if (!psnames)
+ {
+ /* look-up the PSNames driver */
+ FT_Driver psnames_driver;
+
+ psnames_driver = FT_Get_Driver( face->root.driver->library, "psnames" );
+ if (psnames_driver)
+ face->psnames = (PSNames_Interface*)
+ (psnames_driver->interface.format_interface);
+ }
+
/* open the tokenizer, this will also check the font format */
error = New_Tokenizer( stream, &tokenizer );
if (error) goto Fail;