Added support for Mac OS X .dfonts and also getting a filespec for a given font by name
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
diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index a2395fe..f56c429 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -66,6 +66,8 @@
#include <Resources.h>
#include <Fonts.h>
#include <Errors.h>
+#include <Files.h>
+#include <TextUtils.h>
#include <ctype.h> /* for isupper() and isalnum() */
@@ -132,6 +134,22 @@
return finfo.fdType;
}
+ /* is this a Mac OS X .dfont file */
+ static Boolean is_dfont( FSSpec* spec )
+ {
+ int nameLen = spec->name[0];
+
+ if ( spec->name[nameLen-5] == '.' &&
+ spec->name[nameLen-4] == 'd' &&
+ spec->name[nameLen-3] == 'f' &&
+ spec->name[nameLen-2] == 'o' &&
+ spec->name[nameLen-1] == 'n' &&
+ spec->name[nameLen] == 't')
+ return true;
+ else
+ return false;
+ }
+
/* Given a PostScript font name, create the Macintosh LWFN file name. */
static void
@@ -630,6 +648,50 @@
return error;
}
+ /* Create a new FT_Face from a file spec to a suitcase file. */
+ static FT_Error
+ FT_New_Face_From_dfont( FT_Library library,
+ FSSpec* spec,
+ FT_Long face_index,
+ FT_Face* aface )
+ {
+ FT_Error error = FT_Err_Ok;
+ short res_ref, res_index;
+ Handle fond;
+ FSRef hostContainerRef;
+
+ error = FSpMakeFSRef( spec, &hostContainerRef );
+ if ( error == noErr )
+ error = FSOpenResourceFile( &hostContainerRef, 0, NULL, fsRdPerm, &res_ref );
+
+ if ( error != noErr )
+ return FT_Err_Cannot_Open_Resource;
+
+ UseResFile( res_ref );
+
+ /* face_index may be -1, in which case we
+ just need to do a sanity check */
+ if ( face_index < 0 )
+ res_index = 1;
+ else
+ {
+ res_index = (short)( face_index + 1 );
+ face_index = 0;
+ }
+ fond = Get1IndResource( 'FOND', res_index );
+ if ( ResError() )
+ {
+ error = FT_Err_Cannot_Open_Resource;
+ goto Error;
+ }
+
+ error = FT_New_Face_From_FOND( library, fond, face_index, aface );
+
+Error:
+ CloseResFile( res_ref );
+ return error;
+ }
+
/* documentation in ftmac.h */
@@ -678,6 +740,72 @@
return FT_Err_Unknown_File_Format;
}
+ /* documentation in ftmac.h */
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFile_From_Mac_Name( char* fontName, FSSpec* pathSpec, FT_Long* face_index )
+{
+ OptionBits options = kFMUseGlobalScopeOption;
+ FMFontFamilyIterator famIter;
+ OSStatus status = FMCreateFontFamilyIterator(NULL, NULL, options, &famIter);
+ FMFont the_font = NULL;
+ FMFontFamily family = NULL;
+ *face_index = 0;
+ while (status == 0 && !the_font)
+ {
+ status = FMGetNextFontFamily(&famIter, &family);
+ if (status == 0)
+ {
+ int stat2;
+ FMFontFamilyInstanceIterator instIter;
+
+ /* get the family name */
+ Str255 famNameStr;
+ char famName[256];
+ FMGetFontFamilyName(family, famNameStr);
+ CopyPascalStringToC(famNameStr, famName);
+
+ /* iterate through the styles */
+ FMCreateFontFamilyInstanceIterator(family, &instIter);
+ *face_index = 0;
+ stat2 = 0;
+ while (stat2 == 0 && !the_font)
+ {
+ FMFontStyle style;
+ FMFontSize size;
+ FMFont font;
+ stat2 = FMGetNextFontFamilyInstance(&instIter, &font, &style, &size);
+ if (stat2 == 0 && size == 0)
+ {
+ /* build up a complete face name */
+ char fullName[256];
+ strcpy( fullName, famName );
+ if (style & bold)
+ strcat( fullName, " Bold" );
+ if (style & italic)
+ strcat( fullName, " Italic" );
+
+ /* compare with the name we are looking for */
+ if (strcmp( fullName, fontName ) == 0 )
+ {
+ /* found it! */
+ the_font = font;
+ }
+ else
+ ++(*face_index);
+ }
+ }
+ FMDisposeFontFamilyInstanceIterator(&instIter);
+ }
+ }
+ FMDisposeFontFamilyIterator(&famIter);
+
+ if ( the_font ) {
+ FMGetFontContainer(the_font, pathSpec);
+ return FT_Err_Ok;
+ } else
+ return FT_Err_Unknown_File_Format;
+
+}
/*************************************************************************/
/* */
@@ -713,7 +841,9 @@
return FT_New_Face_From_Suitcase( library, &spec, face_index, aface );
else if ( file_type == 'LWFN' )
return FT_New_Face_From_LWFN( library, &spec, face_index, aface );
- else
+ else if ( is_dfont( &spec ) )
+ return FT_New_Face_From_dfont( library, &spec, face_index, aface );
+ else /* let it fall through to normal loader (.ttf, .otf, etc.) */
{
args.flags = ft_open_pathname;
args.pathname = (char*)pathname;