The third-party TrueType fonts that I own have a variety of structures. Here are the ones I've found:

1. Single Fonts with the ".ttf" file extension have only a data fork, and the name of the file seems to be the name of the font.

2. I've found two styles of font suitcase files:

a. One style has a resource fork that includes one or more 'FOND' resources -- one per font. The names of the 'FOND' resources seem to be the names of the font familes. They also include 'sfnt' resources, the names of which are the individual fonts. For example, Times New Roman has a single 'FOND' resource called "Times New Roman, and four 'sfnt' resources: "Times New Roman", "Times New Roman Bold", "Times New Roman Italic", and "Times New Roman Bold Italic".

b. The other style has a resource fork that includes a 'FOND' resource for each individual font, with the 'FOND' resource names being the names of the fonts. They also include 'sfnt' resources, but the 'sfnt' resources do not have names. (They just have resource IDs that match the resource IDs of the corresponding 'FOND' resources.) For example, Stones Sans ITC TT contains three 'FOND' resources: "Stones Sans ITC TT-Bold", "Stones Sans ITC TT-SemiIta", and "Stones Sans ITC TT-Semi".

It shouldn't be too hard to see whether one or more of these categories apply to all of the fonts that might be bundled with your application. If they do, you should be able to programmatically check the 'FOND' and 'sfnt' resources of each font file and build a list of your bundled fonts each time the app is launched. It's probably slower than just reading in a single plist, but may be a bit more flexible. Of course, font file formats are notoriously variable, so some odd format might cause an error at some point in the future.

If you aren't familiar with getting resources out of resource forks, the process goes a bit like this. (But don't try to use this code. Read through the Resource Manager documentation to make sure you understand what the routines are doing.)

NSString *filename; /* probably from -contentsOfDirectoryAtPath:error: */
FSRef theFsRef;
ResID theID;
ResType theType;
Str255 name; /* a Pascal string -- length byte followed by string -- typedef unsigned char Str255[256]; */
unsigned index;
Handle theResource;

[fileName getFSRef:&theFsRef];

SInt16 refNum = FSOpenResFile(&theFsRef,fsRdPerm); /* read-only, so you don't accidentally change it */

unsigned resCount = Count1Resources('sfnt');

for (index = 1;index <= resCount;index++)  /* NOTE: not zero-based */
{
        theResource = Get1IndResource('sfnt',index);

        if (theResource)
        {
                HLock(theResource);
        
                GetResInfo(theResource, &theID, &theType, name);

                /* If it has a name, add the name to an array, or something. */
                /* If it has no name, set a flag that tells you to run the */
                /* same kind of loop on the 'FOND' resources. */
        }
}

/* when all is done */
CloseResFile(refNum);

It should be fun if it doesn't get too crazy. Good luck.

--Mike Wright

On Oct 16, 2009, at 22:55 PM, XiaoGang Li <andrew.mac...@gmail.com> wrote:

Yes, it is really strange feature, this is used internal. My application is distributed with bundles of document templates. These templates should be
designed by your graphic designers before being distributed, using the
limited fonts installed in the bundle. Anyway, user can use other fonts
from  the system and third parties.

Your solution is good. At first, I think it is simple to list all the
limited fonts in the plist file, and it is easy to enumerate these fonts.
But, I think, when other font files are added to the bundle by other
engineer, I will update my plist file at the same time. this solution seems
unrobust.

Thanks again for your feedback.

On Fri, Oct 16, 2009 at 11:57 PM, Jens Alfke <j...@mooseyard.com> wrote:


On Oct 16, 2009, at 3:31 AM, XiaoGang Li wrote:

other uncontained fonts which come from the system or third party
application will be invalid in my application. when the users use my
application to draw text, only the fonts contained in the bundle should be
valid. This is the backgroud of my question.


I don't know what your applications does, but that seems like a really strange feature. I have a lot of fonts installed, and when I use an app I expect to be able to use them. If the app only let me use a couple of fonts
that were bundled with it, I'd call that a bug.

(Also, do you have permission to bundle these fonts? Most fonts can't be
re-distributed without a commercial license from the owner.)

  After getting the font name from the font used by the user, need to
check whether this font is valid, so, how to get the font information from
my font files.


Isn't the set of bundled fonts hard-coded? Just make a list of their names (maybe in a plist file) and read that. I think trying to extract the names out of the font files themselves would be much too difficult since there's
no API for it.

˜Jens

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to