I would recommend using the 3rd method.

The first approach is instantiating an NSFont instance for all available faces.
Instantiating NSFont has additional costs over just querying font descriptors 
(the font instance references graphics attributes, for example).
The resource should be deallocated after the autorelease/garbage collection 
run, but it's a resource-intensive operation.

The second approach is using the font descriptor's matching facility.  It 
should be efficient. but still more costly than querying via NSFontManager 
since the available font info is being cached by the system for you.

>   I note that the first one and
> third find extra fonts: "AquaKana", "AquaKana-Bold", ".Keyboard",
> "LastResort", and sometimes others, depending on the system.  
You should be able to filter them out if the family name starts with a period 
character.

-[NSFontDescriptor fontAttributes] returns the set of attributes describing the 
font face.  The covered character set is a part of font, not an attribute 
describing the font.  So, an NSFontDescriptor instance can return the character 
set information, but the font attributes (which is merely an NSDictionary) 
can't.

> And as a final note, passing "0123456789" to my original function does
> indeed return a non-zero result.  In fact, my original function seems to
> return exactly the same results as the second function above (except in
> the special cases I mentioned in my first post).  Very curious.  Any
> idea why?  Should I still file a bug report as you suggested?

It appears the attribute is being ignored.  I believe it should return the zero 
result if you specified the attribute as a mandatory match.

Aki

On 2011/02/01, at 20:27, Brian Schack wrote:

> Aki,
> 
> Many thanks for the reply.  Taking your suggestion, I found three
> possible routes to rewriting the function (given below).  All seem to
> work.
> 
> One uses NSFontManager and NSFont:
> 
>    NSArray *fontNames = [[NSFontManager sharedFontManager] availableFonts];
>    for (NSString *fontName in fontNames) {
>       NSFont *f = [NSFont fontWithName:fontName size:0.0];
>       if ([[f coveredCharacterSet] isSupersetOfSet:cset]) {
>           [result addObject:f];
>       }
>    }
> 
> The second uses NSFontDescriptor and NSFont:
> 
>    NSArray *fonts = [[NSFontDescriptor fontDescriptorWithFontAttributes:nil]
>                        matchingFontDescriptorsWithMandatoryKeys:nil];
>    for (NSFontDescriptor *fd in fonts) {
>       NSFont *f = [NSFont fontWithDescriptor:fd size:0.0];
>       if ([[f coveredCharacterSet] isSupersetOfSet:cset]) {
>           [result addObject:f];
>       }
>    }
> 
> The third uses NSFontManager and NSFontDescriptor, and I think is the
> closest to what you suggested:
> 
>    NSArray *fontNames = [[NSFontManager sharedFontManager] availableFonts];
>    for (NSString *fontName in fontNames) {
>       NSFontDescriptor *fd = 
>           [NSFontDescriptor fontDescriptorWithName:fontName size:0.0];
>       NSCharacterSet *s = [fd objectForKey:NSFontCharacterSetAttribute];
>       if ([s isSupersetOfSet:cset]) {
>           [result addObject:fd];
>       }
>    }
> 
> Is any to be preferred over the others?  I note that the first one and
> third find extra fonts: "AquaKana", "AquaKana-Bold", ".Keyboard",
> "LastResort", and sometimes others, depending on the system.  
> 
> Note as well that in the third, if I replace
> 
> NSCharacterSet *s = [fd objectForKey:NSFontCharacterSetAttribute];
> 
> by
> 
> NSCharacterSet *s = 
>  [[fd fontAttributes] objectForKey:NSFontCharacterSetAttribute];
> 
> then s is NULL.  Why?
> 
> And as a final note, passing "0123456789" to my original function does
> indeed return a non-zero result.  In fact, my original function seems to
> return exactly the same results as the second function above (except in
> the special cases I mentioned in my first post).  Very curious.  Any
> idea why?  Should I still file a bug report as you suggested?
> 
> Brian

_______________________________________________

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