Initial implementation of NSFontCollection methods.

This commit is contained in:
Gregory John Casamento 2020-01-25 19:14:17 -05:00
parent 479dca0b6d
commit 73bbad4059
2 changed files with 28 additions and 10 deletions

View file

@ -51,14 +51,14 @@ APPKIT_EXPORT NSFontCollectionMatchingOptionKey const NSFontCollectionDisallowAu
typedef NSString* NSFontCollectionName;
@class NSMutableDictionary, NSMutableArray, GSFontEnumerator, NSArray, NSDictionary, NSError;
@class NSMutableDictionary, NSMutableArray, NSArray, NSDictionary, NSError;
@interface NSFontCollection : NSObject <NSCopying, NSMutableCopying, NSCoding>
{
NSMutableArray *_fonts;
NSMutableDictionary *_collectionDictionary;
NSMutableArray *_queryDescriptors;
NSMutableArray *_exclusionDescriptors;
GSFontEnumerator *_fontEnumerator;
}
// Initializers...

View file

@ -36,17 +36,17 @@
self = [super init];
if (self != nil)
{
_fontEnumerator = [[GSFontEnumerator alloc] init];
_collectionDictionary = [[NSMutableDictionary alloc] init];
_queryDescriptors = [[NSMutableArray alloc] init];
_exclusionDescriptors = [[NSMutableArray alloc] init];
_fonts = [[NSMutableArray alloc] initWithCapacity: 50];
_collectionDictionary = [[NSMutableDictionary alloc] initWithCapacity: 10];
_queryDescriptors = [[NSMutableArray alloc] initWithCapacity: 10];
_exclusionDescriptors = [[NSMutableArray alloc] initWithCapacity: 10];
}
return self;
}
- (void) dealloc
{
RELEASE(_fontEnumerator);
RELEASE(_fonts);
RELEASE(_collectionDictionary);
RELEASE(_queryDescriptors);
RELEASE(_exclusionDescriptors);
@ -55,12 +55,31 @@
+ (NSFontCollection *) fontCollectionWithDescriptors: (NSArray *)queryDescriptors
{
return nil;
NSFontCollection *fc = [[NSFontCollection alloc] init];
NSEnumerator *en = [queryDescriptors objectEnumerator];
GSFontEnumerator *fen = [GSFontEnumerator sharedEnumerator];
id d = nil;
while ((d = [en nextObject]) != nil)
{
NSArray *names = [fen availableFontNamesMatchingFontDescriptor: d];
id name = nil;
en = [names objectEnumerator];
while ((name = [en nextObject]) != nil)
{
NSFont *font = [NSFont fontWithName: name size: 0.0]; // get default size
[fc->_fonts addObject: font];
}
}
return fc;
}
+ (NSFontCollection *) fontCollectionWithAllAvailableDescriptors
{
return nil;
return [self fontCollectionWithDescriptors:
[[GSFontEnumerator sharedEnumerator] availableFontDescriptors]];
}
+ (NSFontCollection *) fontCollectionWithLocale: (NSLocale *)locale
@ -111,7 +130,6 @@
return nil;
}
// Descriptors
- (NSArray *) queryDescriptors // copy
{