* Add FT_GetFilePath_From_Mac_ATS_Name as replacement for FT_GetFile_From_Mac_ATS_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 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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
diff --git a/ChangeLog b/ChangeLog
index a2d2e93..8d02b70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2007-02-05 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+ * include/freetype/ftmac.h (FT_GetFilePath_From_Mac_ATS_Name):
+ Introduced as replacement of FT_GetFile_From_Mac_ATS_Name.
+ * src/base/ftmac.c (FT_GetFilePath_From_Mac_ATS_Name): Ditto.
+ (FT_GetFile_From_Mac_ATS_Name): Rewritten as wrapper of
+ FT_GetFilePath_From_Mac_ATS_Name.
+ * builds/mac/ftmac.c: Ditto.
+
+2007-02-05 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+
* include/freetype/ftmac.h: Fixed wrong comment, FSSpec of
FT_GetFile_From_Mac_Name, FT_GetFile_From_Mac_ATS_Name are
for passing to FT_New_Face_From_FSSpec.
diff --git a/builds/mac/ftmac.c b/builds/mac/ftmac.c
index 59e9992..484784c 100644
--- a/builds/mac/ftmac.c
+++ b/builds/mac/ftmac.c
@@ -243,22 +243,34 @@
#endif /* HAVE_QUICKDRAW_CARBON */
-#if !HAVE_ATS
-
- FT_EXPORT_DEF( FT_Error )
- FT_GetFile_From_Mac_ATS_Name( const char* fontName,
- FSSpec* pathSpec,
- FT_Long* face_index )
+#if HAVE_ATS
+
+ /* Private function. */
+ /* The FSSpec type has been discouraged for a long time, */
+ /* but for some reason, there is no FSRef version of */
+ /* ATSFontGetFileSpecification(), so we made our own. */
+ /* Apple will provide one eventually. */
+ static OSStatus
+ FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
+ FSRef* ats_font_ref )
{
- return FT_Err_Unimplemented_Feature;
+ OSStatus err;
+ FSSpec spec;
+
+ err = ATSFontGetFileSpecification( ats_font_id, &spec );
+ if ( noErr == err )
+ {
+ err = FSpMakeFSRef( &spec, ats_font_ref );
+ }
+
+ return err;
}
-#else
- FT_EXPORT_DEF( FT_Error )
- FT_GetFile_From_Mac_ATS_Name( const char* fontName,
- FSSpec* pathSpec,
- FT_Long* face_index )
+ static FT_Error
+ FT_GetFileRef_From_Mac_ATS_Name( const char* fontName,
+ FSRef* ats_font_ref,
+ FT_Long* face_index )
{
CFStringRef cf_fontName;
ATSFontRef ats_font_id;
@@ -274,36 +286,104 @@
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
return FT_Err_Unknown_File_Format;
- if ( 0 != ATSFontGetFileSpecification( ats_font_id, pathSpec ) )
+ if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
return FT_Err_Unknown_File_Format;
/* face_index calculation by searching preceding fontIDs */
/* with same FSRef */
{
- int i;
- FSSpec f;
+ ATSFontRef id2 = ats_font_id - 1;
+ FSRef ref2;
- for ( i = 1; i < ats_font_id; i++ )
+ while ( id2 > 0 )
{
- if ( 0 != ATSFontGetFileSpecification( ats_font_id - i,
- &f ) ||
- f.vRefNum != pathSpec->vRefNum ||
- f.parID != pathSpec->parID ||
- f.name[0] != pathSpec->name[0] ||
- 0 != ft_strncmp( (char *)f.name + 1,
- (char *)pathSpec->name + 1,
- f.name[0] ) )
+ if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
break;
+ if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
+ break;
+
+ id2 --;
}
- *face_index = ( i - 1 );
+ *face_index = ats_font_id - ( id2 + 1 );
}
+
+ return FT_Err_Ok;
+ }
+
+#endif
+
+#if !HAVE_ATS
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
+ UInt8* path,
+ UInt32 maxPathSize,
+ FT_Long* face_index )
+ {
+ return FT_Err_Unimplemented_Feature;
+ }
+
+#else
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
+ UInt8* path,
+ UInt32 maxPathSize,
+ FT_Long* face_index )
+ {
+ FSRef ref;
+ FT_Error err;
+
+
+ err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
+ if ( FT_Err_Ok != err )
+ return err;
+
+ if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
+ return FT_Err_Unknown_File_Format;
+
return FT_Err_Ok;
}
#endif /* HAVE_ATS */
+#if !HAVE_FSSPEC
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFile_From_Mac_ATS_Name( const char* fontName,
+ FSSpec* pathSpec,
+ FT_Long* face_index )
+ {
+ return FT_Err_Unimplemented_Feature;
+ }
+
+#else
+
+ /* This function is deprecated because FSSpec is deprecated in Mac OS X */
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFile_From_Mac_ATS_Name( const char* fontName,
+ FSSpec* pathSpec,
+ FT_Long* face_index )
+ {
+ FSRef ref;
+ FT_Error err;
+
+ err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
+ if ( FT_Err_Ok != err )
+ return err;
+
+ if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
+ pathSpec, NULL ) )
+ return FT_Err_Unknown_File_Format;
+
+ return FT_Err_Ok;
+ }
+
+#endif
+
+
#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO
#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer )
diff --git a/include/freetype/ftmac.h b/include/freetype/ftmac.h
index 3b472aa..4529fe2 100644
--- a/include/freetype/ftmac.h
+++ b/include/freetype/ftmac.h
@@ -150,6 +150,37 @@ FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_GetFilePath_From_Mac_ATS_Name */
+ /* */
+ /* <Description> */
+ /* Return a pathname of the disk file and face index for given font */
+ /* name which is handled by ATS framework. */
+ /* */
+ /* <Input> */
+ /* fontName :: Mac OS name of the font in ATS framework. */
+ /* */
+ /* <Output> */
+ /* path :: Buffer to store pathname of the file. For passing */
+ /* to @FT_New_Face. The client must allocate this */
+ /* buffer before calling this function. */
+ /* */
+ /* maxPathSize :: Lengths of the buffer `path' that client allocated. */
+ /* */
+ /* face_index :: Index of the face. For passing to @FT_New_Face. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ FT_EXPORT( FT_Error )
+ FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
+ UInt8* path,
+ UInt32 maxPathSize,
+ FT_Long* face_index );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_New_Face_From_FSSpec */
/* */
/* <Description> */
diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index 07a2dc7..c8d06b0 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -108,10 +108,32 @@
}
- FT_EXPORT_DEF( FT_Error )
- FT_GetFile_From_Mac_ATS_Name( const char* fontName,
- FSSpec* pathSpec,
- FT_Long* face_index )
+ /* Private function. */
+ /* The FSSpec type has been discouraged for a long time, */
+ /* but for some reason, there is no FSRef version of */
+ /* ATSFontGetFileSpecification(), so we made our own. */
+ /* Apple will provide one eventually. */
+ static OSStatus
+ FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
+ FSRef* ats_font_ref )
+ {
+ OSStatus err;
+ FSSpec spec;
+
+ err = ATSFontGetFileSpecification( ats_font_id, &spec );
+ if ( noErr == err )
+ {
+ err = FSpMakeFSRef( &spec, ats_font_ref );
+ }
+
+ return err;
+ }
+
+
+ static FT_Error
+ FT_GetFileRef_From_Mac_ATS_Name( const char* fontName,
+ FSRef* ats_font_ref,
+ FT_Long* face_index )
{
CFStringRef cf_fontName;
ATSFontRef ats_font_id;
@@ -127,31 +149,75 @@
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
return FT_Err_Unknown_File_Format;
- if ( 0 != ATSFontGetFileSpecification( ats_font_id, pathSpec ) )
+ if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
return FT_Err_Unknown_File_Format;
/* face_index calculation by searching preceding fontIDs */
/* with same FSRef */
{
- int i;
- FSSpec f;
+ ATSFontRef id2 = ats_font_id - 1;
+ FSRef ref2;
- for ( i = 1; i < ats_font_id; i++ )
+ while ( id2 > 0 )
{
- if ( 0 != ATSFontGetFileSpecification( ats_font_id - i,
- &f ) ||
- f.vRefNum != pathSpec->vRefNum ||
- f.parID != pathSpec->parID ||
- f.name[0] != pathSpec->name[0] ||
- 0 != ft_strncmp( (char *)f.name + 1,
- (char *)pathSpec->name + 1,
- f.name[0] ) )
+ if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
break;
+ if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
+ break;
+
+ id2 --;
}
- *face_index = ( i - 1 );
+ *face_index = ats_font_id - ( id2 + 1 );
}
+
+ return FT_Err_Ok;
+ }
+
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
+ UInt8* path,
+ UInt32 maxPathSize,
+ FT_Long* face_index )
+ {
+ FSRef ref;
+ FT_Error err;
+
+
+ err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
+ if ( FT_Err_Ok != err )
+ return err;
+
+ if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
+ return FT_Err_Unknown_File_Format;
+
+ return FT_Err_Ok;
+ }
+
+
+ /* This function is deprecated because FSSpec is deprecated in Mac OS X */
+ FT_EXPORT_DEF( FT_Error )
+ FT_GetFile_From_Mac_ATS_Name( const char* fontName,
+ FSSpec* pathSpec,
+ FT_Long* face_index )
+ {
+#if __LP64__
+ return FT_Err_Unimplemented_Feature;
+#else
+ FSRef ref;
+ FT_Error err;
+
+ err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
+ if ( FT_Err_Ok != err )
+ return err;
+
+ if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
+ pathSpec, NULL ) )
+ return FT_Err_Unknown_File_Format;
+
return FT_Err_Ok;
+#endif
}