Attempted to write the font enumeration code for OS X. It does not work yet (memory management is borked and duplicate removal does not work, period).
This commit is contained in:
parent
9efb452b2e
commit
bcc17a4e6d
|
@ -447,3 +447,97 @@ void uiDrawRestore(uiDrawContext *c)
|
|||
{
|
||||
CGContextRestoreGState(c->c);
|
||||
}
|
||||
|
||||
// TODO for all relevant routines, make sure we are freeing memory correctly
|
||||
// TODO make sure allocation failures throw exceptions?
|
||||
struct uiDrawFontFamilies {
|
||||
/*
|
||||
CFNumberRef one;
|
||||
CFDictionaryRef options;
|
||||
CTFontCollectionRef collection;
|
||||
CFArrayRef fonts;
|
||||
*/
|
||||
NSFontCollection *collection;
|
||||
NSArray *fonts;
|
||||
};
|
||||
|
||||
uiDrawFontFamilies *uiDrawListFontFamilies(void)
|
||||
{
|
||||
uiDrawFontFamilies *ff;
|
||||
/*
|
||||
const void *keys[1];
|
||||
const void *values[1];
|
||||
SInt32 one = 1;
|
||||
*/
|
||||
|
||||
ff = uiNew(uiDrawFontFamilies);
|
||||
|
||||
/*
|
||||
ff->one = CFNumberCreate(NULL, kCFNumberSInt32Type, &one);
|
||||
|
||||
// needed as the matching descriptors can have
|
||||
keys[0] = kCTFontCollectionRemoveDuplicatesOption;
|
||||
values[0] = ff->one;
|
||||
// TODO kCTFontCollectionIncludeDisabledFontsOption? the Windows code enumerates hidden fonts; disable that?
|
||||
ff->options = CFDictionaryCreate(NULL,
|
||||
keys, values, 1,
|
||||
NULL, NULL);
|
||||
NSLog(@"%@", ff->options);
|
||||
|
||||
ff->collection = CTFontCollectionCreateFromAvailableFonts(ff->options);
|
||||
ff->fonts = CTFontCollectionCreateMatchingFontDescriptors(ff->collection);
|
||||
*/
|
||||
|
||||
ff->collection = [NSFontCollection fontCollectionWithAllAvailableDescriptors];
|
||||
ff->fonts = [ff->collection matchingDescriptorsWithOptions:[NSDictionary
|
||||
dictionaryWithObject:@YES // TODO
|
||||
forKey:NSFontCollectionRemoveDuplicatesOption]];
|
||||
|
||||
return ff;
|
||||
}
|
||||
|
||||
uintmax_t uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff)
|
||||
{
|
||||
// return CFArrayGetCount(ff->fonts);
|
||||
return [ff->fonts count];
|
||||
}
|
||||
|
||||
char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, uintmax_t n)
|
||||
{
|
||||
/*
|
||||
CTFontDescriptorRef font;
|
||||
CFStringRef familystr;
|
||||
char *family;
|
||||
|
||||
font = (CTFontDescriptorRef) CFArrayGetValueAtIndex(ff->fonts, n);
|
||||
familystr = (CFStringRef) CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
|
||||
// TODO create a uiDarwinCFStringToText()?
|
||||
family = uiDarwinNSStringToText((NSString *) familystr);
|
||||
CFRelease(familystr);
|
||||
// Get Rule means we do not free font
|
||||
return family;
|
||||
*/
|
||||
NSFontDescriptor *desc;
|
||||
NSString *familystr;
|
||||
char *family;
|
||||
|
||||
desc = (NSFontDescriptor *) [ff->fonts objectAtIndex:n];
|
||||
familystr = (NSString *) [desc objectForKey:NSFontFamilyAttribute];
|
||||
family = uiDarwinNSStringToText(familystr);
|
||||
// TODO release familystr and desc?
|
||||
return family;
|
||||
}
|
||||
|
||||
void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff)
|
||||
{
|
||||
/*
|
||||
CFRelease(ff->fonts);
|
||||
// TODO is this correct?
|
||||
CFRelease(ff->collection);
|
||||
CFRelease(ff->options);
|
||||
CFRelease(ff->one);
|
||||
*/
|
||||
//TODO [ff->fonts release];
|
||||
//TODO [ff->collection release];
|
||||
uiFree(ff);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue