Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ftmac.c */ |
| 4 | /* */ |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 5 | /* Mac FOND support. Written by just@letterror.com. */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 6 | /* */ |
Werner Lemberg | 415235d | 2001-06-28 17:49:10 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001 by */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 8 | /* Just van Rossum, David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
| 10 | /* This file is part of the FreeType project, and may only be used, */ |
| 11 | /* modified, and distributed under the terms of the FreeType project */ |
| 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 | /* this file you indicate that you have read the license and */ |
| 14 | /* understand and accept it fully. */ |
| 15 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
| 18 | |
| 19 | /* |
| 20 | Notes |
| 21 | |
| 22 | Mac suitcase files can (and often do!) contain multiple fonts. To |
| 23 | support this I use the face_index argument of FT_(Open|New)_Face() |
| 24 | functions, and pretend the suitcase file is a collection. |
| 25 | Warning: although the FOND driver sets face->num_faces field to the |
| 26 | number of available fonts, but the Type 1 driver sets it to 1 anyway. |
| 27 | So this field is currently not reliable, and I don't see a clean way |
| 28 | to resolve that. The face_index argument translates to |
| 29 | Get1IndResource( 'FOND', face_index + 1 ); |
| 30 | so clients should figure out the resource index of the FOND. |
| 31 | (I'll try to provide some example code for this at some point.) |
| 32 | |
| 33 | |
| 34 | The Mac FOND support works roughly like this: |
| 35 | |
| 36 | - Check whether the offered stream points to a Mac suitcase file. |
| 37 | This is done by checking the file type: it has to be 'FFIL' or 'tfil'. |
| 38 | The stream that gets passed to our init_face() routine is a stdio |
| 39 | stream, which isn't usable for us, since the FOND resources live |
| 40 | in the resource fork. So we just grab the stream->pathname field. |
| 41 | |
| 42 | - Read the FOND resource into memory, then check whether there is |
| 43 | a TrueType font and/or (!) a Type 1 font available. |
| 44 | |
| 45 | - If there is a Type 1 font available (as a separate 'LWFN' file), |
| 46 | read its data into memory, massage it slightly so it becomes |
| 47 | PFB data, wrap it into a memory stream, load the Type 1 driver |
| 48 | and delegate the rest of the work to it by calling FT_Open_Face(). |
| 49 | (XXX TODO: after this has been done, the kerning data from the FOND |
| 50 | resource should be appended to the face: on the Mac there are usually |
| 51 | no AFM files available. However, this is tricky since we need to map |
| 52 | Mac char codes to ps glyph names to glyph ID's...) |
| 53 | |
| 54 | - If there is a TrueType font (an 'sfnt' resource), read it into |
| 55 | memory, wrap it into a memory stream, load the TrueType driver |
| 56 | and delegate the rest of the work to it, by calling FT_Open_Face(). |
| 57 | */ |
| 58 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 59 | |
| 60 | #include <ft2build.h> |
| 61 | #include FT_FREETYPE_H |
| 62 | #include FT_INTERNAL_STREAM_H |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 63 | #include "truetype/ttobjs.h" |
| 64 | #include "type1/t1objs.h" |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 65 | |
| 66 | #include <Resources.h> |
| 67 | #include <Fonts.h> |
| 68 | #include <Errors.h> |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 69 | #include <Files.h> |
| 70 | #include <TextUtils.h> |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 71 | |
| 72 | #include <ctype.h> /* for isupper() and isalnum() */ |
| 73 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 74 | #include FT_MAC_H |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 75 | |
| 76 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 77 | /* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over |
| 78 | TrueType in case *both* are available (this is not common, |
| 79 | but it *is* possible). */ |
| 80 | #ifndef PREFER_LWFN |
| 81 | #define PREFER_LWFN 1 |
| 82 | #endif |
| 83 | |
| 84 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 85 | /* Quick'n'dirty Pascal string to C string converter. |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 86 | Warning: this call is not thread safe! Use with caution. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 87 | static char* |
| 88 | p2c_str( unsigned char* pstr ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 89 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 90 | static char cstr[256]; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 91 | |
| 92 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 93 | strncpy( cstr, (char*)pstr + 1, pstr[0] ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 94 | cstr[pstr[0]] = '\0'; |
| 95 | return cstr; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /* Given a pathname, fill in a file spec. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 100 | static int |
| 101 | file_spec_from_path( const char* pathname, |
| 102 | FSSpec* spec ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 103 | { |
| 104 | Str255 p_path; |
| 105 | FT_ULong path_len; |
| 106 | |
| 107 | |
| 108 | /* convert path to a pascal string */ |
| 109 | path_len = strlen( pathname ); |
| 110 | if ( path_len > 255 ) |
| 111 | return -1; |
| 112 | p_path[0] = (unsigned char)path_len; |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 113 | strncpy( (char*)p_path + 1, pathname, path_len ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 114 | |
| 115 | if ( FSMakeFSSpec( 0, 0, p_path, spec ) != noErr ) |
| 116 | return -1; |
| 117 | else |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* Return the file type of the file specified by spec. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 123 | static OSType |
| 124 | get_file_type( FSSpec* spec ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 125 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 126 | FInfo finfo; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 127 | |
| 128 | |
| 129 | if ( FSpGetFInfo( spec, &finfo ) != noErr ) |
| 130 | return 0; /* file might not exist */ |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 131 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 132 | return finfo.fdType; |
| 133 | } |
| 134 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 135 | |
| 136 | /* is this a Mac OS X .dfont file */ |
| 137 | static Boolean |
| 138 | is_dfont( FSSpec* spec ) |
| 139 | { |
| 140 | int nameLen = spec->name[0]; |
| 141 | |
| 142 | |
| 143 | if ( spec->name[nameLen - 5] == '.' && |
| 144 | spec->name[nameLen - 4] == 'd' && |
| 145 | spec->name[nameLen - 3] == 'f' && |
| 146 | spec->name[nameLen - 2] == 'o' && |
| 147 | spec->name[nameLen - 1] == 'n' && |
| 148 | spec->name[nameLen ] == 't' ) |
| 149 | return true; |
| 150 | else |
| 151 | return false; |
| 152 | } |
| 153 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 154 | |
| 155 | /* Given a PostScript font name, create the Macintosh LWFN file name. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 156 | static void |
| 157 | create_lwfn_name( char* ps_name, |
| 158 | Str255 lwfn_file_name ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 159 | { |
| 160 | int max = 5, count = 0; |
| 161 | FT_Byte* p = lwfn_file_name; |
| 162 | FT_Byte* q = (FT_Byte*)ps_name; |
| 163 | |
| 164 | |
| 165 | lwfn_file_name[0] = 0; |
| 166 | |
| 167 | while ( *q ) |
| 168 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 169 | if ( isupper( *q ) ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 170 | { |
| 171 | if ( count ) |
| 172 | max = 3; |
| 173 | count = 0; |
| 174 | } |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 175 | if ( count < max && ( isalnum( *q ) || *q == '_' ) ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 176 | { |
| 177 | *++p = *q; |
| 178 | lwfn_file_name[0]++; |
| 179 | count++; |
| 180 | } |
| 181 | q++; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /* Given a file reference, answer its location as a vRefNum |
| 187 | and a dirID. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 188 | static FT_Error |
| 189 | get_file_location( short ref_num, |
| 190 | short* v_ref_num, |
| 191 | long* dir_id, |
| 192 | unsigned char* file_name ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 193 | { |
| 194 | FCBPBRec pb; |
| 195 | OSErr error; |
| 196 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 197 | pb.ioNamePtr = file_name; |
| 198 | pb.ioVRefNum = 0; |
| 199 | pb.ioRefNum = ref_num; |
| 200 | pb.ioFCBIndx = 0; |
| 201 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 202 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 203 | error = PBGetFCBInfoSync( &pb ); |
| 204 | if ( error == noErr ) |
| 205 | { |
| 206 | *v_ref_num = pb.ioFCBVRefNum; |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 207 | *dir_id = pb.ioFCBParID; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 208 | } |
| 209 | return error; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* Make a file spec for an LWFN file from a FOND resource and |
| 214 | a file name. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 215 | static FT_Error |
| 216 | make_lwfn_spec( Handle fond, |
| 217 | unsigned char* file_name, |
| 218 | FSSpec* spec ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 219 | { |
| 220 | FT_Error error; |
| 221 | short ref_num, v_ref_num; |
| 222 | long dir_id; |
| 223 | Str255 fond_file_name; |
| 224 | |
| 225 | |
| 226 | ref_num = HomeResFile( fond ); |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 227 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 228 | error = ResError(); |
| 229 | if ( !error ) |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 230 | error = get_file_location( ref_num, &v_ref_num, |
| 231 | &dir_id, fond_file_name ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 232 | if ( !error ) |
| 233 | error = FSMakeFSSpec( v_ref_num, dir_id, file_name, spec ); |
| 234 | |
| 235 | return error; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /* Look inside the FOND data, answer whether there should be an SFNT |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 240 | resource, and answer the name of a possible LWFN Type 1 file. |
| 241 | |
| 242 | Thanks to Paul Miller (paulm@profoundeffects.com) for the fix |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 243 | to load a face OTHER than the first one in the FOND! |
| 244 | */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 245 | static void |
| 246 | parse_fond( char* fond_data, |
| 247 | short* have_sfnt, |
| 248 | short* sfnt_id, |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 249 | Str255 lwfn_file_name, |
| 250 | short face_index ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 251 | { |
| 252 | AsscEntry* assoc; |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 253 | AsscEntry* base_assoc; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 254 | FamRec* fond; |
| 255 | |
| 256 | |
| 257 | *sfnt_id = 0; |
| 258 | *have_sfnt = 0; |
| 259 | lwfn_file_name[0] = 0; |
| 260 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 261 | fond = (FamRec*)fond_data; |
| 262 | assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 ); |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 263 | base_assoc = assoc; |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 264 | assoc += face_index; /* add on the face_index! */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 265 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 266 | /* if the face at this index is not scalable, |
| 267 | fall back to the first one (old behavior) */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 268 | if ( assoc->fontSize == 0 ) |
| 269 | { |
| 270 | *have_sfnt = 1; |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 271 | *sfnt_id = assoc->fontID; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 272 | } |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 273 | else if ( base_assoc->fontSize == 0 ) |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 274 | { |
| 275 | *have_sfnt = 1; |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 276 | *sfnt_id = base_assoc->fontID; |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 277 | } |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 278 | |
| 279 | if ( fond->ffStylOff ) |
| 280 | { |
| 281 | unsigned char* p = (unsigned char*)fond_data; |
| 282 | StyleTable* style; |
| 283 | unsigned short string_count; |
| 284 | unsigned char* name_table = 0; |
| 285 | char ps_name[256]; |
| 286 | unsigned char* names[64]; |
| 287 | int i; |
| 288 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 289 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 290 | p += fond->ffStylOff; |
| 291 | style = (StyleTable*)p; |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 292 | p += sizeof ( StyleTable ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 293 | string_count = *(unsigned short*)(p); |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 294 | p += sizeof ( short ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 295 | |
| 296 | for ( i = 0 ; i < string_count && i < 64; i++ ) |
| 297 | { |
| 298 | names[i] = p; |
| 299 | p += names[i][0]; |
| 300 | p++; |
| 301 | } |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 302 | strcpy( ps_name, p2c_str( names[0] ) ); /* Family name */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 303 | |
| 304 | if ( style->indexes[0] > 1 ) |
| 305 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 306 | unsigned char* suffixes = names[style->indexes[0] - 1]; |
| 307 | |
| 308 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 309 | for ( i = 1; i <= suffixes[0]; i++ ) |
| 310 | strcat( ps_name, p2c_str( names[suffixes[i] - 1] ) ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 311 | } |
| 312 | create_lwfn_name( ps_name, lwfn_file_name ); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* Read Type 1 data from the POST resources inside the LWFN file, |
| 318 | return a PFB buffer. This is somewhat convoluted because the FT2 |
| 319 | PFB parser wants the ASCII header as one chunk, and the LWFN |
| 320 | chunks are often not organized that way, so we'll glue chunks |
| 321 | of the same type together. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 322 | static FT_Error |
| 323 | read_lwfn( FT_Memory memory, |
| 324 | FSSpec* lwfn_spec, |
| 325 | FT_Byte** pfb_data, |
| 326 | FT_ULong* size ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 327 | { |
| 328 | FT_Error error = FT_Err_Ok; |
| 329 | short res_ref, res_id; |
| 330 | unsigned char *buffer, *p, *size_p; |
| 331 | FT_ULong total_size = 0; |
| 332 | FT_ULong post_size, pfb_chunk_size; |
| 333 | Handle post_data; |
| 334 | char code, last_code; |
| 335 | |
| 336 | |
| 337 | res_ref = FSpOpenResFile( lwfn_spec, fsRdPerm ); |
| 338 | if ( ResError() ) |
| 339 | return FT_Err_Out_Of_Memory; |
| 340 | UseResFile( res_ref ); |
| 341 | |
| 342 | /* First pass: load all POST resources, and determine the size of |
| 343 | the output buffer. */ |
| 344 | res_id = 501; |
| 345 | last_code = -1; |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 346 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 347 | for (;;) |
| 348 | { |
| 349 | post_data = Get1Resource( 'POST', res_id++ ); |
| 350 | if ( post_data == NULL ) |
| 351 | break; /* we're done */ |
| 352 | |
| 353 | code = (*post_data)[0]; |
| 354 | |
| 355 | if ( code != last_code ) |
| 356 | { |
| 357 | if ( code == 5 ) |
| 358 | total_size += 2; /* just the end code */ |
| 359 | else |
| 360 | total_size += 6; /* code + 4 bytes chunk length */ |
| 361 | } |
| 362 | |
| 363 | total_size += GetHandleSize( post_data ) - 2; |
| 364 | last_code = code; |
| 365 | } |
| 366 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 367 | if ( FT_ALLOC( buffer, (FT_Long)total_size ) ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 368 | goto Error; |
| 369 | |
| 370 | /* Second pass: append all POST data to the buffer, add PFB fields. |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 371 | Glue all consecutive chunks of the same type together. */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 372 | p = buffer; |
| 373 | res_id = 501; |
| 374 | last_code = -1; |
| 375 | pfb_chunk_size = 0; |
| 376 | |
| 377 | for (;;) |
| 378 | { |
| 379 | post_data = Get1Resource( 'POST', res_id++ ); |
| 380 | if ( post_data == NULL ) |
| 381 | break; /* we're done */ |
| 382 | |
| 383 | post_size = (FT_ULong)GetHandleSize( post_data ) - 2; |
| 384 | code = (*post_data)[0]; |
| 385 | |
| 386 | if ( code != last_code ) |
| 387 | { |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 388 | if ( last_code != -1 ) |
| 389 | { |
| 390 | /* we're done adding a chunk, fill in the size field */ |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 391 | *size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF ); |
| 392 | *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF ); |
| 393 | *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF ); |
| 394 | *size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 395 | pfb_chunk_size = 0; |
| 396 | } |
| 397 | |
| 398 | *p++ = 0x80; |
| 399 | if ( code == 5 ) |
| 400 | *p++ = 0x03; /* the end */ |
| 401 | else if ( code == 2 ) |
| 402 | *p++ = 0x02; /* binary segment */ |
| 403 | else |
| 404 | *p++ = 0x01; /* ASCII segment */ |
| 405 | |
| 406 | if ( code != 5 ) |
| 407 | { |
| 408 | size_p = p; /* save for later */ |
| 409 | p += 4; /* make space for size field */ |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | memcpy( p, *post_data + 2, post_size ); |
| 414 | pfb_chunk_size += post_size; |
| 415 | p += post_size; |
| 416 | last_code = code; |
| 417 | } |
| 418 | |
| 419 | *pfb_data = buffer; |
| 420 | *size = total_size; |
| 421 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 422 | Error: |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 423 | CloseResFile( res_ref ); |
| 424 | return error; |
| 425 | } |
| 426 | |
| 427 | |
| 428 | /* Finalizer for a memory stream; gets called by FT_Done_Face(). |
| 429 | It frees the memory it uses. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 430 | static void |
| 431 | memory_stream_close( FT_Stream stream ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 432 | { |
| 433 | FT_Memory memory = stream->memory; |
| 434 | |
| 435 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 436 | FT_FREE( stream->base ); |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 437 | |
| 438 | stream->size = 0; |
| 439 | stream->base = 0; |
| 440 | stream->close = 0; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
| 444 | /* Create a new memory stream from a buffer and a size. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 445 | static FT_Error |
| 446 | new_memory_stream( FT_Library library, |
| 447 | FT_Byte* base, |
| 448 | FT_ULong size, |
| 449 | FT_Stream_Close close, |
| 450 | FT_Stream* astream ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 451 | { |
| 452 | FT_Error error; |
| 453 | FT_Memory memory; |
| 454 | FT_Stream stream; |
| 455 | |
| 456 | |
| 457 | if ( !library ) |
| 458 | return FT_Err_Invalid_Library_Handle; |
| 459 | |
| 460 | if ( !base ) |
| 461 | return FT_Err_Invalid_Argument; |
| 462 | |
| 463 | *astream = 0; |
| 464 | memory = library->memory; |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 465 | if ( FT_NEW( stream ) ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 466 | goto Exit; |
| 467 | |
David Turner | 53b3fa1 | 2002-02-24 05:26:57 +0000 | [diff] [blame] | 468 | FT_Stream_OpenMemory( library, |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 469 | base, |
| 470 | size, |
| 471 | stream ); |
| 472 | |
| 473 | stream->close = close; |
| 474 | |
| 475 | *astream = stream; |
| 476 | |
| 477 | Exit: |
| 478 | return error; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | /* Create a new FT_Face given a buffer and a driver name. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 483 | static FT_Error |
| 484 | open_face_from_buffer( FT_Library library, |
| 485 | FT_Byte* base, |
| 486 | FT_ULong size, |
| 487 | FT_Long face_index, |
| 488 | char* driver_name, |
| 489 | FT_Face* aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 490 | { |
| 491 | FT_Open_Args args; |
| 492 | FT_Error error; |
| 493 | FT_Stream stream; |
| 494 | FT_Memory memory = library->memory; |
| 495 | |
| 496 | |
| 497 | error = new_memory_stream( library, |
| 498 | base, |
| 499 | size, |
| 500 | memory_stream_close, |
| 501 | &stream ); |
| 502 | if ( error ) |
| 503 | { |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 504 | FT_FREE( base ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 505 | return error; |
| 506 | } |
| 507 | |
| 508 | args.flags = ft_open_stream; |
| 509 | args.stream = stream; |
| 510 | if ( driver_name ) |
| 511 | { |
| 512 | args.flags = args.flags | ft_open_driver; |
| 513 | args.driver = FT_Get_Module( library, driver_name ); |
| 514 | } |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 515 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 516 | error = FT_Open_Face( library, &args, face_index, aface ); |
Just van Rossum | 5fe94ff | 2000-07-28 02:25:23 +0000 | [diff] [blame] | 517 | if ( error == FT_Err_Ok ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 518 | (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; |
Just van Rossum | 5fe94ff | 2000-07-28 02:25:23 +0000 | [diff] [blame] | 519 | else |
| 520 | { |
David Turner | 53b3fa1 | 2002-02-24 05:26:57 +0000 | [diff] [blame] | 521 | FT_Stream_Close( stream ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 522 | FT_FREE( stream ); |
Just van Rossum | 5fe94ff | 2000-07-28 02:25:23 +0000 | [diff] [blame] | 523 | } |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 524 | return error; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | /* Create a new FT_Face from a file spec to an LWFN file. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 529 | static FT_Error |
| 530 | FT_New_Face_From_LWFN( FT_Library library, |
| 531 | FSSpec* spec, |
| 532 | FT_Long face_index, |
| 533 | FT_Face* aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 534 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 535 | FT_Byte* pfb_data; |
| 536 | FT_ULong pfb_size; |
| 537 | FT_Error error; |
| 538 | FT_Memory memory = library->memory; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 539 | |
| 540 | |
| 541 | error = read_lwfn( library->memory, spec, &pfb_data, &pfb_size ); |
| 542 | if ( error ) |
| 543 | return error; |
| 544 | |
| 545 | #if 0 |
| 546 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 547 | FILE* f; |
| 548 | char* path; |
| 549 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 550 | |
| 551 | path = p2c_str( spec->name ); |
| 552 | strcat( path, ".PFB" ); |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 553 | f = fopen( path, "wb" ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 554 | if ( f ) |
| 555 | { |
| 556 | fwrite( pfb_data, 1, pfb_size, f ); |
| 557 | fclose( f ); |
| 558 | } |
| 559 | } |
| 560 | #endif |
| 561 | |
| 562 | return open_face_from_buffer( library, |
| 563 | pfb_data, |
| 564 | pfb_size, |
| 565 | face_index, |
| 566 | "type1", |
| 567 | aface ); |
| 568 | } |
| 569 | |
| 570 | |
| 571 | /* Create a new FT_Face from an SFNT resource, specified by res ID. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 572 | static FT_Error |
| 573 | FT_New_Face_From_SFNT( FT_Library library, |
| 574 | short sfnt_id, |
| 575 | FT_Long face_index, |
| 576 | FT_Face* aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 577 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 578 | Handle sfnt = NULL; |
| 579 | FT_Byte* sfnt_data; |
| 580 | size_t sfnt_size; |
| 581 | FT_Stream stream = NULL; |
| 582 | FT_Error error = 0; |
| 583 | FT_Memory memory = library->memory; |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 584 | |
| 585 | |
| 586 | sfnt = GetResource( 'sfnt', sfnt_id ); |
| 587 | if ( ResError() ) |
| 588 | return FT_Err_Invalid_Handle; |
| 589 | |
| 590 | sfnt_size = (FT_ULong)GetHandleSize( sfnt ); |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame^] | 591 | if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 592 | { |
| 593 | ReleaseResource( sfnt ); |
| 594 | return error; |
| 595 | } |
| 596 | |
| 597 | HLock( sfnt ); |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 598 | memcpy( sfnt_data, *sfnt, sfnt_size ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 599 | HUnlock( sfnt ); |
| 600 | ReleaseResource( sfnt ); |
| 601 | |
| 602 | return open_face_from_buffer( library, |
| 603 | sfnt_data, |
| 604 | sfnt_size, |
| 605 | face_index, |
| 606 | "truetype", |
| 607 | aface ); |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /* Create a new FT_Face from a file spec to a suitcase file. */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 612 | static FT_Error |
| 613 | FT_New_Face_From_Suitcase( FT_Library library, |
| 614 | FSSpec* spec, |
| 615 | FT_Long face_index, |
| 616 | FT_Face* aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 617 | { |
| 618 | FT_Error error = FT_Err_Ok; |
| 619 | short res_ref, res_index; |
| 620 | Handle fond; |
| 621 | |
| 622 | |
| 623 | res_ref = FSpOpenResFile( spec, fsRdPerm ); |
| 624 | if ( ResError() ) |
| 625 | return FT_Err_Cannot_Open_Resource; |
| 626 | UseResFile( res_ref ); |
| 627 | |
| 628 | /* face_index may be -1, in which case we |
| 629 | just need to do a sanity check */ |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 630 | if ( face_index < 0 ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 631 | res_index = 1; |
| 632 | else |
| 633 | { |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 634 | res_index = (short)( face_index + 1 ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 635 | face_index = 0; |
| 636 | } |
| 637 | fond = Get1IndResource( 'FOND', res_index ); |
| 638 | if ( ResError() ) |
| 639 | { |
| 640 | error = FT_Err_Cannot_Open_Resource; |
| 641 | goto Error; |
| 642 | } |
| 643 | |
| 644 | error = FT_New_Face_From_FOND( library, fond, face_index, aface ); |
| 645 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 646 | Error: |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 647 | CloseResFile( res_ref ); |
| 648 | return error; |
| 649 | } |
| 650 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 651 | |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 652 | /* Create a new FT_Face from a file spec to a suitcase file. */ |
| 653 | static FT_Error |
| 654 | FT_New_Face_From_dfont( FT_Library library, |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 655 | FSSpec* spec, |
| 656 | FT_Long face_index, |
| 657 | FT_Face* aface ) |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 658 | { |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 659 | FT_Error error = FT_Err_Ok; |
| 660 | short res_ref, res_index; |
| 661 | Handle fond; |
| 662 | FSRef hostContainerRef; |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 663 | |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 664 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 665 | error = FSpMakeFSRef( spec, &hostContainerRef ); |
| 666 | if ( error == noErr ) |
| 667 | error = FSOpenResourceFile( &hostContainerRef, |
| 668 | 0, NULL, fsRdPerm, &res_ref ); |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 669 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 670 | if ( error != noErr ) |
| 671 | return FT_Err_Cannot_Open_Resource; |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 672 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 673 | UseResFile( res_ref ); |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 674 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 675 | /* face_index may be -1, in which case we |
| 676 | just need to do a sanity check */ |
| 677 | if ( face_index < 0 ) |
| 678 | res_index = 1; |
| 679 | else |
| 680 | { |
| 681 | res_index = (short)( face_index + 1 ); |
| 682 | face_index = 0; |
| 683 | } |
| 684 | fond = Get1IndResource( 'FOND', res_index ); |
| 685 | if ( ResError() ) |
| 686 | { |
| 687 | error = FT_Err_Cannot_Open_Resource; |
| 688 | goto Error; |
| 689 | } |
| 690 | |
| 691 | error = FT_New_Face_From_FOND( library, fond, face_index, aface ); |
| 692 | |
| 693 | Error: |
| 694 | CloseResFile( res_ref ); |
| 695 | return error; |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 698 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 699 | /* documentation in ftmac.h */ |
| 700 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 701 | FT_EXPORT_DEF( FT_Error ) |
| 702 | FT_New_Face_From_FOND( FT_Library library, |
| 703 | Handle fond, |
| 704 | FT_Long face_index, |
| 705 | FT_Face *aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 706 | { |
| 707 | short sfnt_id, have_sfnt, have_lwfn = 0; |
| 708 | Str255 lwfn_file_name; |
| 709 | short fond_id; |
| 710 | OSType fond_type; |
| 711 | Str255 fond_name; |
| 712 | FSSpec lwfn_spec; |
| 713 | FT_Error error = FT_Err_Unknown_File_Format; |
| 714 | |
| 715 | |
Werner Lemberg | c3b2160 | 2001-12-05 01:22:05 +0000 | [diff] [blame] | 716 | GetResInfo( fond, &fond_id, &fond_type, fond_name ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 717 | if ( ResError() != noErr || fond_type != 'FOND' ) |
| 718 | return FT_Err_Invalid_File_Format; |
| 719 | |
| 720 | HLock( fond ); |
Leonard Rosenthol | ae340bb | 2001-10-26 13:24:39 +0000 | [diff] [blame] | 721 | parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index ); |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 722 | HUnlock( fond ); |
| 723 | |
| 724 | if ( lwfn_file_name[0] ) |
| 725 | { |
| 726 | if ( make_lwfn_spec( fond, lwfn_file_name, &lwfn_spec ) == FT_Err_Ok ) |
| 727 | have_lwfn = 1; /* yeah, we got one! */ |
| 728 | else |
| 729 | have_lwfn = 0; /* no LWFN file found */ |
| 730 | } |
| 731 | |
| 732 | if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) ) |
| 733 | return FT_New_Face_From_LWFN( library, |
| 734 | &lwfn_spec, |
| 735 | face_index, |
| 736 | aface ); |
| 737 | else if ( have_sfnt ) |
| 738 | return FT_New_Face_From_SFNT( library, |
| 739 | sfnt_id, |
| 740 | face_index, |
| 741 | aface ); |
| 742 | |
| 743 | return FT_Err_Unknown_File_Format; |
| 744 | } |
| 745 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 746 | |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 747 | /* documentation in ftmac.h */ |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 748 | |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 749 | FT_EXPORT_DEF( FT_Error ) |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 750 | FT_GetFile_From_Mac_Name( char* fontName, |
| 751 | FSSpec* pathSpec, |
| 752 | FT_Long* face_index ) |
| 753 | { |
| 754 | OptionBits options = kFMUseGlobalScopeOption; |
| 755 | |
| 756 | FMFontFamilyIterator famIter; |
| 757 | OSStatus status = FMCreateFontFamilyIterator( NULL, NULL, |
| 758 | options, |
| 759 | &famIter ); |
| 760 | FMFont the_font = NULL; |
| 761 | FMFontFamily family = NULL; |
| 762 | |
| 763 | |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 764 | *face_index = 0; |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 765 | while ( status == 0 && !the_font ) |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 766 | { |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 767 | status = FMGetNextFontFamily( &famIter, &family ); |
| 768 | if ( status == 0 ) |
| 769 | { |
| 770 | int stat2; |
| 771 | FMFontFamilyInstanceIterator instIter; |
| 772 | Str255 famNameStr; |
| 773 | char famName[256]; |
| 774 | |
| 775 | |
| 776 | /* get the family name */ |
| 777 | FMGetFontFamilyName( family, famNameStr ); |
| 778 | CopyPascalStringToC( famNameStr, famName ); |
| 779 | |
| 780 | /* iterate through the styles */ |
| 781 | FMCreateFontFamilyInstanceIterator( family, &instIter ); |
| 782 | |
| 783 | *face_index = 0; |
| 784 | stat2 = 0; |
| 785 | while ( stat2 == 0 && !the_font ) |
| 786 | { |
| 787 | FMFontStyle style; |
| 788 | FMFontSize size; |
| 789 | FMFont font; |
| 790 | |
| 791 | |
| 792 | stat2 = FMGetNextFontFamilyInstance( &instIter, &font, |
| 793 | &style, &size ); |
| 794 | if ( stat2 == 0 && size == 0 ) |
| 795 | { |
| 796 | char fullName[256]; |
| 797 | |
| 798 | |
| 799 | /* build up a complete face name */ |
| 800 | strcpy( fullName, famName ); |
| 801 | if ( style & bold ) |
| 802 | strcat( fullName, " Bold" ); |
| 803 | if ( style & italic ) |
| 804 | strcat( fullName, " Italic" ); |
| 805 | |
| 806 | /* compare with the name we are looking for */ |
| 807 | if ( strcmp( fullName, fontName ) == 0 ) |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 808 | { |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 809 | /* found it! */ |
| 810 | the_font = font; |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 811 | } |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 812 | else |
| 813 | ++(*face_index); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | FMDisposeFontFamilyInstanceIterator( &instIter ); |
| 818 | } |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 819 | } |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 820 | |
| 821 | FMDisposeFontFamilyIterator( &famIter ); |
| 822 | |
| 823 | if ( the_font ) |
| 824 | { |
| 825 | FMGetFontContainer( the_font, pathSpec ); |
| 826 | return FT_Err_Ok; |
| 827 | } |
| 828 | else |
| 829 | return FT_Err_Unknown_File_Format; |
| 830 | } |
| 831 | |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 832 | |
| 833 | /*************************************************************************/ |
| 834 | /* */ |
| 835 | /* <Function> */ |
| 836 | /* FT_New_Face */ |
| 837 | /* */ |
| 838 | /* <Description> */ |
| 839 | /* This is the Mac-specific implementation of FT_New_Face. In */ |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 840 | /* addition to the standard FT_New_Face() functionality, it also */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 841 | /* accepts pathnames to Mac suitcase files. For further */ |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 842 | /* documentation see the original FT_New_Face() in freetype.h. */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 843 | /* */ |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 844 | FT_EXPORT_DEF( FT_Error ) |
| 845 | FT_New_Face( FT_Library library, |
| 846 | const char* pathname, |
| 847 | FT_Long face_index, |
| 848 | FT_Face *aface ) |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 849 | { |
| 850 | FT_Open_Args args; |
| 851 | FSSpec spec; |
| 852 | OSType file_type; |
| 853 | |
| 854 | |
| 855 | /* test for valid `library' and `aface' delayed to FT_Open_Face() */ |
| 856 | if ( !pathname ) |
| 857 | return FT_Err_Invalid_Argument; |
| 858 | |
| 859 | if ( file_spec_from_path( pathname, &spec ) ) |
| 860 | return FT_Err_Invalid_Argument; |
| 861 | |
| 862 | file_type = get_file_type( &spec ); |
| 863 | if ( file_type == 'FFIL' || file_type == 'tfil' ) |
| 864 | return FT_New_Face_From_Suitcase( library, &spec, face_index, aface ); |
| 865 | else if ( file_type == 'LWFN' ) |
| 866 | return FT_New_Face_From_LWFN( library, &spec, face_index, aface ); |
Leonard Rosenthol | 7013373 | 2001-12-06 17:52:06 +0000 | [diff] [blame] | 867 | else if ( is_dfont( &spec ) ) |
| 868 | return FT_New_Face_From_dfont( library, &spec, face_index, aface ); |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 869 | else /* let it fall through to normal loader (.ttf, .otf, etc.) */ |
Just van Rossum | ae4bcee | 2000-07-28 01:10:35 +0000 | [diff] [blame] | 870 | { |
| 871 | args.flags = ft_open_pathname; |
| 872 | args.pathname = (char*)pathname; |
| 873 | |
| 874 | return FT_Open_Face( library, &args, face_index, aface ); |
| 875 | } |
| 876 | } |
| 877 | |
Werner Lemberg | 05c21b8 | 2000-07-29 20:38:19 +0000 | [diff] [blame] | 878 | |
| 879 | /* END */ |