Location of the fonts on the iPhone?
Asked Answered
S

2

6

I'm using the FreeType2 library in an iPhone project, and I'm trying to simply load a TTF file from the system, if possible.

FT_Library  library;
FT_Face face;
int error;


error = FT_Init_FreeType( &library );

if ( error == 0 )
     printf("Initialized FreeType2\r\n");   /* Prints */

error = FT_New_Face(library, "/System/Library/Fonts/Helvetica.ttf", 0, &face);

if ( error ==  FT_Err_Cannot_Open_Resource )
    printf("Font not found\r\n");         /* Prints */

That error seems to be for file not found. Is /System/Library/Fonts not the location of the fonts? Or, do iPhone apps simply not have any read access at all to that directory.

Thanks!

Stirpiculture answered 31/3, 2010 at 22:18 Comment(2)
Also, so everyone knows. I did go ahead and add a .ttf into my project to see if it would load that, and yes, it did. I'm just not sure if the system font is specified incorrectly, or if I don't have access to it.Stirpiculture
I would like to use FreeType because of portability reasons.Stirpiculture
G
4

To find the fonts installed on your device, load the font manifest (a plist):

NSDictionary *cgFonts = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/Fonts/CGFontCache.plist"];

Once you parse it, you'll find the entry for your font:

Helvetica = "/System/Library/Fonts/Cache/Helvetica.ttf";
Godavari answered 31/3, 2010 at 23:55 Comment(2)
modmyi.com/wiki/index.php/IPhone_Fonts Not sure how accurate this page is, but it's what I had used as a reference.Stirpiculture
You can always get the available fonts using the code listed in this article: excitabyte.wordpress.com/2010/03/24/…Godavari
V
3

They're either in /System/Library/Fonts/ or /System/Library/Fonts/Cache. However, I suspect that you may not have the required permissions to access those directories.

Vacuole answered 1/4, 2010 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.