Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* t42objs.c */ |
| 4 | /* */ |
| 5 | /* Type 42 objects manager (body). */ |
| 6 | /* */ |
Werner Lemberg | b442ca1 | 2003-04-23 15:50:27 +0000 | [diff] [blame] | 7 | /* Copyright 2002, 2003 by Roberto Alameda. */ |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 8 | /* */ |
| 9 | /* This file is part of the FreeType project, and may only be used, */ |
| 10 | /* modified, and distributed under the terms of the FreeType project */ |
| 11 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 12 | /* this file you indicate that you have read the license and */ |
| 13 | /* understand and accept it fully. */ |
| 14 | /* */ |
| 15 | /***************************************************************************/ |
| 16 | |
| 17 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 18 | #include "t42objs.h" |
| 19 | #include "t42parse.h" |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 20 | #include "t42error.h" |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 21 | #include FT_INTERNAL_DEBUG_H |
| 22 | #include FT_INTERNAL_STREAM_H |
| 23 | #include FT_LIST_H |
| 24 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 25 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 26 | #undef FT_COMPONENT |
| 27 | #define FT_COMPONENT trace_t42 |
| 28 | |
| 29 | |
| 30 | static FT_Error |
| 31 | T42_Open_Face( T42_Face face ) |
| 32 | { |
| 33 | T42_LoaderRec loader; |
| 34 | T42_Parser parser; |
| 35 | T1_Font type1 = &face->type1; |
| 36 | FT_Memory memory = face->root.memory; |
| 37 | FT_Error error; |
| 38 | |
| 39 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
| 40 | |
| 41 | |
| 42 | t42_loader_init( &loader, face ); |
| 43 | |
| 44 | parser = &loader.parser; |
| 45 | |
| 46 | if ( FT_ALLOC( face->ttf_data, 12 ) ) |
| 47 | goto Exit; |
| 48 | |
| 49 | error = t42_parser_init( parser, |
| 50 | face->root.stream, |
| 51 | memory, |
| 52 | psaux); |
| 53 | if ( error ) |
| 54 | goto Exit; |
| 55 | |
| 56 | error = t42_parse_dict( face, &loader, parser->base_dict, parser->base_len ); |
| 57 | |
| 58 | if ( type1->font_type != 42 ) |
| 59 | { |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 60 | error = T42_Err_Unknown_File_Format; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 61 | goto Exit; |
| 62 | } |
| 63 | |
| 64 | /* now, propagate the charstrings and glyphnames tables */ |
| 65 | /* to the Type1 data */ |
| 66 | type1->num_glyphs = loader.num_glyphs; |
| 67 | |
| 68 | if ( !loader.charstrings.init ) { |
| 69 | FT_ERROR(( "T42_Open_Face: no charstrings array in face!\n" )); |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 70 | error = T42_Err_Invalid_File_Format; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 73 | loader.charstrings.init = 0; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 74 | type1->charstrings_block = loader.charstrings.block; |
| 75 | type1->charstrings = loader.charstrings.elements; |
| 76 | type1->charstrings_len = loader.charstrings.lengths; |
| 77 | |
| 78 | /* we copy the glyph names `block' and `elements' fields; */ |
| 79 | /* the `lengths' field must be released later */ |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 80 | type1->glyph_names_block = loader.glyph_names.block; |
| 81 | type1->glyph_names = (FT_String**)loader.glyph_names.elements; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 82 | loader.glyph_names.block = 0; |
| 83 | loader.glyph_names.elements = 0; |
| 84 | |
| 85 | /* we must now build type1.encoding when we have a custom array */ |
| 86 | if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY ) |
| 87 | { |
| 88 | FT_Int charcode, idx, min_char, max_char; |
| 89 | FT_Byte* char_name; |
| 90 | FT_Byte* glyph_name; |
| 91 | |
| 92 | |
| 93 | /* OK, we do the following: for each element in the encoding */ |
| 94 | /* table, look up the index of the glyph having the same name */ |
| 95 | /* as defined in the CharStrings array. */ |
| 96 | /* The index is then stored in type1.encoding.char_index, and */ |
| 97 | /* the name in type1.encoding.char_name */ |
| 98 | |
| 99 | min_char = +32000; |
| 100 | max_char = -32000; |
| 101 | |
| 102 | charcode = 0; |
| 103 | for ( ; charcode < loader.encoding_table.max_elems; charcode++ ) |
| 104 | { |
| 105 | type1->encoding.char_index[charcode] = 0; |
| 106 | type1->encoding.char_name [charcode] = (char *)".notdef"; |
| 107 | |
| 108 | char_name = loader.encoding_table.elements[charcode]; |
| 109 | if ( char_name ) |
| 110 | for ( idx = 0; idx < type1->num_glyphs; idx++ ) |
| 111 | { |
| 112 | glyph_name = (FT_Byte*)type1->glyph_names[idx]; |
| 113 | if ( ft_strcmp( (const char*)char_name, |
| 114 | (const char*)glyph_name ) == 0 ) |
| 115 | { |
| 116 | type1->encoding.char_index[charcode] = (FT_UShort)idx; |
| 117 | type1->encoding.char_name [charcode] = (char*)glyph_name; |
| 118 | |
| 119 | /* Change min/max encoded char only if glyph name is */ |
| 120 | /* not /.notdef */ |
| 121 | if ( ft_strcmp( (const char*)".notdef", |
| 122 | (const char*)glyph_name ) != 0 ) |
| 123 | { |
| 124 | if ( charcode < min_char ) min_char = charcode; |
| 125 | if ( charcode > max_char ) max_char = charcode; |
| 126 | } |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | type1->encoding.code_first = min_char; |
| 132 | type1->encoding.code_last = max_char; |
| 133 | type1->encoding.num_chars = loader.num_chars; |
| 134 | } |
| 135 | |
| 136 | Exit: |
| 137 | t42_loader_done( &loader ); |
| 138 | return error; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /***************** Driver Functions *************/ |
| 143 | |
| 144 | |
| 145 | FT_LOCAL_DEF( FT_Error ) |
| 146 | T42_Face_Init( FT_Stream stream, |
| 147 | T42_Face face, |
| 148 | FT_Int face_index, |
| 149 | FT_Int num_params, |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 150 | FT_Parameter* params ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 151 | { |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 152 | FT_Error error; |
| 153 | PSNames_Service psnames; |
| 154 | PSAux_Service psaux; |
| 155 | FT_Face root = (FT_Face)&face->root; |
| 156 | T1_Font type1 = &face->type1; |
| 157 | PS_FontInfo info = &type1->font_info; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 158 | |
| 159 | FT_UNUSED( num_params ); |
| 160 | FT_UNUSED( params ); |
| 161 | FT_UNUSED( face_index ); |
| 162 | FT_UNUSED( stream ); |
| 163 | |
| 164 | |
| 165 | face->ttf_face = NULL; |
| 166 | face->root.num_faces = 1; |
| 167 | |
| 168 | face->psnames = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), |
| 169 | "psnames" ); |
| 170 | psnames = (PSNames_Service)face->psnames; |
| 171 | |
| 172 | face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), |
| 173 | "psaux" ); |
| 174 | psaux = (PSAux_Service)face->psaux; |
| 175 | |
| 176 | /* open the tokenizer, this will also check the font format */ |
| 177 | error = T42_Open_Face( face ); |
| 178 | if ( error ) |
| 179 | goto Exit; |
| 180 | |
| 181 | /* if we just wanted to check the format, leave successfully now */ |
| 182 | if ( face_index < 0 ) |
| 183 | goto Exit; |
| 184 | |
| 185 | /* check the face index */ |
| 186 | if ( face_index != 0 ) |
| 187 | { |
| 188 | FT_ERROR(( "T42_Face_Init: invalid face index\n" )); |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 189 | error = T42_Err_Invalid_Argument; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 190 | goto Exit; |
| 191 | } |
| 192 | |
| 193 | /* Now, load the font program into the face object */ |
| 194 | |
| 195 | /* Init the face object fields */ |
| 196 | /* Now set up root face fields */ |
| 197 | |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 198 | root->num_glyphs = type1->num_glyphs; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 199 | root->num_charmaps = 0; |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 200 | root->face_index = face_index; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 201 | |
| 202 | root->face_flags = FT_FACE_FLAG_SCALABLE; |
| 203 | root->face_flags |= FT_FACE_FLAG_HORIZONTAL; |
| 204 | root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES; |
| 205 | |
Werner Lemberg | 64f1ba9 | 2003-07-25 22:09:53 +0000 | [diff] [blame^] | 206 | if ( info->is_fixed_pitch ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 207 | root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; |
| 208 | |
| 209 | /* XXX: TODO -- add kerning with .afm support */ |
| 210 | |
| 211 | /* get style name -- be careful, some broken fonts only */ |
| 212 | /* have a `/FontName' dictionary entry! */ |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 213 | root->family_name = info->family_name; |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 214 | /* assume "Regular" style if we don't know better */ |
| 215 | root->style_name = (char *)"Regular"; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 216 | if ( root->family_name ) |
| 217 | { |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 218 | char* full = info->full_name; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 219 | char* family = root->family_name; |
| 220 | |
| 221 | |
| 222 | if ( full ) |
| 223 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 224 | while ( *full ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 225 | { |
Werner Lemberg | fdc042b | 2003-06-12 04:59:07 +0000 | [diff] [blame] | 226 | if ( *full == *family ) |
| 227 | { |
| 228 | family++; |
| 229 | full++; |
| 230 | } |
| 231 | else |
| 232 | { |
| 233 | if ( *full == ' ' || *full == '-' ) |
| 234 | full++; |
| 235 | else if ( *family == ' ' || *family == '-' ) |
| 236 | family++; |
| 237 | else |
| 238 | { |
| 239 | if ( !*family ) |
| 240 | root->style_name = full; |
| 241 | break; |
| 242 | } |
| 243 | } |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 244 | } |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 245 | } |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
| 249 | /* do we have a `/FontName'? */ |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 250 | if ( type1->font_name ) |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 251 | root->family_name = type1->font_name; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* no embedded bitmap support */ |
| 255 | root->num_fixed_sizes = 0; |
| 256 | root->available_sizes = 0; |
| 257 | |
| 258 | /* Load the TTF font embedded in the T42 font */ |
| 259 | error = FT_New_Memory_Face( FT_FACE_LIBRARY( face ), |
| 260 | face->ttf_data, |
| 261 | face->ttf_size, |
| 262 | 0, |
| 263 | &face->ttf_face ); |
| 264 | if ( error ) |
| 265 | goto Exit; |
| 266 | |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 267 | FT_Done_Size( face->ttf_face->size ); |
| 268 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 269 | /* Ignore info in FontInfo dictionary and use the info from the */ |
| 270 | /* loaded TTF font. The PostScript interpreter also ignores it. */ |
| 271 | root->bbox = face->ttf_face->bbox; |
| 272 | root->units_per_EM = face->ttf_face->units_per_EM; |
| 273 | |
| 274 | root->ascender = face->ttf_face->ascender; |
| 275 | root->descender = face->ttf_face->descender; |
| 276 | root->height = face->ttf_face->height; |
| 277 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 278 | root->max_advance_width = face->ttf_face->max_advance_width; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 279 | root->max_advance_height = face->ttf_face->max_advance_height; |
| 280 | |
Werner Lemberg | 64f1ba9 | 2003-07-25 22:09:53 +0000 | [diff] [blame^] | 281 | root->underline_position = info->underline_position >> 16; |
| 282 | root->underline_thickness = info->underline_thickness >> 16; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 283 | |
| 284 | root->internal->max_points = 0; |
| 285 | root->internal->max_contours = 0; |
| 286 | |
| 287 | /* compute style flags */ |
| 288 | root->style_flags = 0; |
Werner Lemberg | 64f1ba9 | 2003-07-25 22:09:53 +0000 | [diff] [blame^] | 289 | if ( info->italic_angle ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 290 | root->style_flags |= FT_STYLE_FLAG_ITALIC; |
| 291 | |
| 292 | if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD ) |
| 293 | root->style_flags |= FT_STYLE_FLAG_BOLD; |
| 294 | |
| 295 | if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL ) |
| 296 | root->face_flags |= FT_FACE_FLAG_VERTICAL; |
| 297 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 298 | { |
| 299 | if ( psnames && psaux ) |
| 300 | { |
| 301 | FT_CharMapRec charmap; |
| 302 | T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes; |
| 303 | FT_CMap_Class clazz; |
| 304 | |
| 305 | |
| 306 | charmap.face = root; |
| 307 | |
| 308 | /* first of all, try to synthetize a Unicode charmap */ |
| 309 | charmap.platform_id = 3; |
| 310 | charmap.encoding_id = 1; |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 311 | charmap.encoding = FT_ENCODING_UNICODE; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 312 | |
| 313 | FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL ); |
| 314 | |
| 315 | /* now, generate an Adobe Standard encoding when appropriate */ |
| 316 | charmap.platform_id = 7; |
| 317 | clazz = NULL; |
| 318 | |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 319 | switch ( type1->encoding_type ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 320 | { |
| 321 | case T1_ENCODING_TYPE_STANDARD: |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 322 | charmap.encoding = FT_ENCODING_ADOBE_STANDARD; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 323 | charmap.encoding_id = 0; |
| 324 | clazz = cmap_classes->standard; |
| 325 | break; |
| 326 | |
| 327 | case T1_ENCODING_TYPE_EXPERT: |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 328 | charmap.encoding = FT_ENCODING_ADOBE_EXPERT; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 329 | charmap.encoding_id = 1; |
| 330 | clazz = cmap_classes->expert; |
| 331 | break; |
| 332 | |
| 333 | case T1_ENCODING_TYPE_ARRAY: |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 334 | charmap.encoding = FT_ENCODING_ADOBE_CUSTOM; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 335 | charmap.encoding_id = 2; |
| 336 | clazz = cmap_classes->custom; |
| 337 | break; |
| 338 | |
| 339 | case T1_ENCODING_TYPE_ISOLATIN1: |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 340 | charmap.encoding = FT_ENCODING_ADOBE_LATIN_1; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 341 | charmap.encoding_id = 3; |
| 342 | clazz = cmap_classes->unicode; |
| 343 | break; |
| 344 | |
| 345 | default: |
| 346 | ; |
| 347 | } |
| 348 | |
| 349 | if ( clazz ) |
| 350 | FT_CMap_New( clazz, NULL, &charmap, NULL ); |
| 351 | |
David Turner | fed59b7 | 2002-07-17 22:51:06 +0000 | [diff] [blame] | 352 | #if 0 |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 353 | /* Select default charmap */ |
| 354 | if (root->num_charmaps) |
| 355 | root->charmap = root->charmaps[0]; |
David Turner | fed59b7 | 2002-07-17 22:51:06 +0000 | [diff] [blame] | 356 | #endif |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 357 | } |
| 358 | } |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 359 | Exit: |
| 360 | return error; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | FT_LOCAL_DEF( void ) |
| 365 | T42_Face_Done( T42_Face face ) |
| 366 | { |
| 367 | T1_Font type1; |
| 368 | PS_FontInfo info; |
| 369 | FT_Memory memory; |
| 370 | |
| 371 | |
| 372 | if ( face ) |
| 373 | { |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 374 | type1 = &face->type1; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 375 | info = &type1->font_info; |
| 376 | memory = face->root.memory; |
| 377 | |
| 378 | /* delete internal ttf face prior to freeing face->ttf_data */ |
| 379 | if ( face->ttf_face ) |
| 380 | FT_Done_Face( face->ttf_face ); |
| 381 | |
| 382 | /* release font info strings */ |
| 383 | FT_FREE( info->version ); |
| 384 | FT_FREE( info->notice ); |
| 385 | FT_FREE( info->full_name ); |
| 386 | FT_FREE( info->family_name ); |
| 387 | FT_FREE( info->weight ); |
| 388 | |
| 389 | /* release top dictionary */ |
| 390 | FT_FREE( type1->charstrings_len ); |
| 391 | FT_FREE( type1->charstrings ); |
| 392 | FT_FREE( type1->glyph_names ); |
| 393 | |
| 394 | FT_FREE( type1->charstrings_block ); |
| 395 | FT_FREE( type1->glyph_names_block ); |
| 396 | |
| 397 | FT_FREE( type1->encoding.char_index ); |
| 398 | FT_FREE( type1->encoding.char_name ); |
| 399 | FT_FREE( type1->font_name ); |
| 400 | |
Werner Lemberg | 65ba724 | 2003-05-30 09:12:50 +0000 | [diff] [blame] | 401 | FT_FREE( type1->paint_type ); |
| 402 | FT_FREE( type1->stroke_width ); |
| 403 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 404 | FT_FREE( face->ttf_data ); |
| 405 | |
| 406 | #if 0 |
| 407 | /* release afm data if present */ |
| 408 | if ( face->afm_data ) |
| 409 | T1_Done_AFM( memory, (T1_AFM*)face->afm_data ); |
| 410 | #endif |
| 411 | |
| 412 | /* release unicode map, if any */ |
| 413 | FT_FREE( face->unicode_map.maps ); |
| 414 | face->unicode_map.num_maps = 0; |
| 415 | |
| 416 | face->root.family_name = 0; |
| 417 | face->root.style_name = 0; |
| 418 | } |
| 419 | } |
| 420 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 421 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 422 | /*************************************************************************/ |
| 423 | /* */ |
| 424 | /* <Function> */ |
| 425 | /* T42_Driver_Init */ |
| 426 | /* */ |
| 427 | /* <Description> */ |
| 428 | /* Initializes a given Type 42 driver object. */ |
| 429 | /* */ |
| 430 | /* <Input> */ |
| 431 | /* driver :: A handle to the target driver object. */ |
| 432 | /* */ |
| 433 | /* <Return> */ |
| 434 | /* FreeType error code. 0 means success. */ |
| 435 | /* */ |
| 436 | FT_LOCAL_DEF( FT_Error ) |
| 437 | T42_Driver_Init( T42_Driver driver ) |
| 438 | { |
| 439 | FT_Module ttmodule; |
| 440 | |
| 441 | |
| 442 | ttmodule = FT_Get_Module( FT_MODULE(driver)->library, "truetype" ); |
| 443 | driver->ttclazz = (FT_Driver_Class)ttmodule->clazz; |
| 444 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 445 | return T42_Err_Ok; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
| 449 | FT_LOCAL_DEF( void ) |
| 450 | T42_Driver_Done( T42_Driver driver ) |
| 451 | { |
| 452 | FT_UNUSED( driver ); |
| 453 | } |
| 454 | |
| 455 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 456 | |
| 457 | |
| 458 | FT_LOCAL_DEF( FT_Error ) |
| 459 | T42_Size_Init( T42_Size size ) |
| 460 | { |
| 461 | FT_Face face = size->root.face; |
| 462 | T42_Face t42face = (T42_Face)face; |
| 463 | FT_Size ttsize; |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 464 | FT_Error error = T42_Err_Ok; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 465 | |
| 466 | |
| 467 | error = FT_New_Size( t42face->ttf_face, &ttsize ); |
| 468 | size->ttsize = ttsize; |
| 469 | |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 470 | FT_Activate_Size( ttsize ); |
| 471 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 472 | return error; |
| 473 | } |
| 474 | |
| 475 | |
| 476 | FT_LOCAL_DEF( void ) |
| 477 | T42_Size_Done( T42_Size size ) |
| 478 | { |
| 479 | FT_Face face = size->root.face; |
| 480 | T42_Face t42face = (T42_Face)face; |
| 481 | FT_ListNode node; |
| 482 | |
| 483 | |
| 484 | node = FT_List_Find( &t42face->ttf_face->sizes_list, size->ttsize ); |
| 485 | if ( node ) |
| 486 | { |
| 487 | FT_Done_Size( size->ttsize ); |
| 488 | size->ttsize = NULL; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
| 493 | FT_LOCAL_DEF( FT_Error ) |
| 494 | T42_GlyphSlot_Init( T42_GlyphSlot slot ) |
| 495 | { |
| 496 | FT_Face face = slot->root.face; |
| 497 | T42_Face t42face = (T42_Face)face; |
| 498 | FT_GlyphSlot ttslot; |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 499 | FT_Error error = T42_Err_Ok; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 500 | |
| 501 | |
| 502 | if ( face->glyph == NULL ) |
| 503 | { |
| 504 | /* First glyph slot for this face */ |
| 505 | slot->ttslot = t42face->ttf_face->glyph; |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | error = FT_New_GlyphSlot( t42face->ttf_face, &ttslot ); |
| 510 | slot->ttslot = ttslot; |
| 511 | } |
| 512 | |
| 513 | return error; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | FT_LOCAL_DEF( void ) |
| 518 | T42_GlyphSlot_Done( T42_GlyphSlot slot ) |
| 519 | { |
| 520 | FT_Face face = slot->root.face; |
| 521 | T42_Face t42face = (T42_Face)face; |
| 522 | FT_GlyphSlot cur = t42face->ttf_face->glyph; |
| 523 | |
| 524 | |
| 525 | while ( cur ) |
| 526 | { |
| 527 | if ( cur == slot->ttslot ) |
| 528 | { |
| 529 | FT_Done_GlyphSlot( slot->ttslot ); |
| 530 | break; |
| 531 | } |
| 532 | |
| 533 | cur = cur->next; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 538 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 539 | FT_LOCAL_DEF( FT_Error ) |
| 540 | T42_Size_SetChars( T42_Size size, |
| 541 | FT_F26Dot6 char_width, |
| 542 | FT_F26Dot6 char_height, |
| 543 | FT_UInt horz_resolution, |
| 544 | FT_UInt vert_resolution ) |
| 545 | { |
| 546 | FT_Face face = size->root.face; |
| 547 | T42_Face t42face = (T42_Face)face; |
| 548 | |
| 549 | |
Werner Lemberg | 779afe4 | 2003-06-22 15:33:53 +0000 | [diff] [blame] | 550 | FT_Activate_Size( size->ttsize ); |
David Turner | d1214ac | 2002-07-17 21:14:23 +0000 | [diff] [blame] | 551 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 552 | return FT_Set_Char_Size( t42face->ttf_face, |
| 553 | char_width, |
| 554 | char_height, |
| 555 | horz_resolution, |
| 556 | vert_resolution ); |
| 557 | } |
| 558 | |
| 559 | |
| 560 | FT_LOCAL_DEF( FT_Error ) |
| 561 | T42_Size_SetPixels( T42_Size size, |
| 562 | FT_UInt pixel_width, |
| 563 | FT_UInt pixel_height ) |
| 564 | { |
| 565 | FT_Face face = size->root.face; |
| 566 | T42_Face t42face = (T42_Face)face; |
| 567 | |
| 568 | |
Werner Lemberg | 779afe4 | 2003-06-22 15:33:53 +0000 | [diff] [blame] | 569 | FT_Activate_Size( size->ttsize ); |
David Turner | d1214ac | 2002-07-17 21:14:23 +0000 | [diff] [blame] | 570 | |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 571 | return FT_Set_Pixel_Sizes( t42face->ttf_face, |
| 572 | pixel_width, |
| 573 | pixel_height ); |
| 574 | } |
| 575 | |
| 576 | |
| 577 | static void |
David Turner | 66cbc20 | 2003-03-20 07:04:40 +0000 | [diff] [blame] | 578 | t42_glyphslot_clear( FT_GlyphSlot slot ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 579 | { |
| 580 | /* free bitmap if needed */ |
David Turner | 66cbc20 | 2003-03-20 07:04:40 +0000 | [diff] [blame] | 581 | ft_glyphslot_free_bitmap( slot ); |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 582 | |
| 583 | /* clear all public fields in the glyph slot */ |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 584 | FT_ZERO( &slot->metrics ); |
| 585 | FT_ZERO( &slot->outline ); |
| 586 | FT_ZERO( &slot->bitmap ); |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 587 | |
| 588 | slot->bitmap_left = 0; |
| 589 | slot->bitmap_top = 0; |
| 590 | slot->num_subglyphs = 0; |
| 591 | slot->subglyphs = 0; |
| 592 | slot->control_data = 0; |
| 593 | slot->control_len = 0; |
| 594 | slot->other = 0; |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 595 | slot->format = FT_GLYPH_FORMAT_NONE; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 596 | |
| 597 | slot->linearHoriAdvance = 0; |
| 598 | slot->linearVertAdvance = 0; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | FT_LOCAL_DEF( FT_Error ) |
| 603 | T42_GlyphSlot_Load( FT_GlyphSlot glyph, |
| 604 | FT_Size size, |
| 605 | FT_Int glyph_index, |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 606 | FT_Int32 load_flags ) |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 607 | { |
| 608 | FT_Error error; |
| 609 | T42_GlyphSlot t42slot = (T42_GlyphSlot)glyph; |
| 610 | T42_Size t42size = (T42_Size)size; |
| 611 | FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz; |
| 612 | |
Werner Lemberg | bd8e324 | 2002-06-12 08:43:58 +0000 | [diff] [blame] | 613 | |
David Turner | 66cbc20 | 2003-03-20 07:04:40 +0000 | [diff] [blame] | 614 | t42_glyphslot_clear( t42slot->ttslot ); |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 615 | error = ttclazz->load_glyph( t42slot->ttslot, |
| 616 | t42size->ttsize, |
| 617 | glyph_index, |
| 618 | load_flags | FT_LOAD_NO_BITMAP ); |
| 619 | |
| 620 | if ( !error ) |
| 621 | { |
| 622 | glyph->metrics = t42slot->ttslot->metrics; |
| 623 | |
| 624 | glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance; |
| 625 | glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance; |
| 626 | |
| 627 | glyph->format = t42slot->ttslot->format; |
| 628 | glyph->outline = t42slot->ttslot->outline; |
| 629 | |
| 630 | glyph->bitmap = t42slot->ttslot->bitmap; |
| 631 | glyph->bitmap_left = t42slot->ttslot->bitmap_left; |
| 632 | glyph->bitmap_top = t42slot->ttslot->bitmap_top; |
David Turner | d1214ac | 2002-07-17 21:14:23 +0000 | [diff] [blame] | 633 | |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 634 | glyph->num_subglyphs = t42slot->ttslot->num_subglyphs; |
| 635 | glyph->subglyphs = t42slot->ttslot->subglyphs; |
David Turner | d1214ac | 2002-07-17 21:14:23 +0000 | [diff] [blame] | 636 | |
David Turner | a1e4565 | 2002-06-11 20:35:58 +0000 | [diff] [blame] | 637 | glyph->control_data = t42slot->ttslot->control_data; |
| 638 | glyph->control_len = t42slot->ttslot->control_len; |
David Turner | 9f95bab | 2002-06-07 07:23:06 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | return error; |
| 642 | } |
| 643 | |
| 644 | |
Werner Lemberg | 8c90c22 | 2002-06-08 06:47:18 +0000 | [diff] [blame] | 645 | /* END */ |