Re: Bizarre behaviour of NSFontDescriptor and/or NSCharacterSet
Re: Bizarre behaviour of NSFontDescriptor and/or NSCharacterSet
- Subject: Re: Bizarre behaviour of NSFontDescriptor and/or NSCharacterSet
- From: Brian Schack <email@hidden>
- Date: Tue, 01 Feb 2011 21:27:10 -0700
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 (email@hidden)
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:
This email sent to email@hidden