diff --git a/darwin/attrstr.m b/darwin/attrstr.m index 4ce242d1..60120af9 100644 --- a/darwin/attrstr.m +++ b/darwin/attrstr.m @@ -61,6 +61,7 @@ void uninitUnderlineColors(void) // TODO see if we could use NSAttributedString? // TODO consider renaming this struct and the fep variable(s) // TODO restructure all this so the important details at the top are below with the combined font attributes type? +// TODO in fact I should just write something to explain everything in this file... struct foreachParams { CFMutableAttributedStringRef mas; NSMutableDictionary *combinedFontAttrs; // keys are CFIndex in mas, values are combinedFontAttr objects @@ -77,6 +78,7 @@ struct foreachParams { @property const uiOpenTypeFeatures *features; - (id)initWithDefaultFont:(uiDrawFontDescriptor *)defaultFont; - (BOOL)same:(combinedFontAttr *)b; +- (CTFontRef)toCTFont; @end @implementation combinedFontAttr @@ -85,6 +87,7 @@ struct foreachParams { { self = [super init]; if (self) { + // TODO define behaviors if defaultFont->Family or any attribute Family is NULL, same with other invalid values self.family = defaultFont->Family; self.size = defaultFont->Size; self.weight = defaultFont->Weight; @@ -122,6 +125,25 @@ struct foreachParams { return YES; } +- (CTFontRef)toCTFont +{ + uiDrawFontDescriptor uidesc; + CTFontDescriptorRef desc; + CTFontRef font; + + uidesc.Family = self.family; + uidesc.Size = self.size; + uidesc.Weight = self.weight; + uidesc.Italic = self.italic; + uidesc.Stretch = self.stretch; + desc = fontdescToCTFontDescriptor(&uidesc); + if (self.features != NULL) + desc = fontdescAppendFeatures(desc, self.features); + font = CTFontCreateWithFontDescriptor(desc, self.size, NULL); + CFRelease(desc); // TODO correct? + return font; +} + @end static void ensureFontInRange(struct foreachParams *p, size_t start, size_t end) @@ -319,18 +341,6 @@ static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t return 0; } -static CTFontRef fontdescToCTFont(struct fontParams *fp) -{ - CTFontDescriptorRef desc; - CTFontRef font; - - desc = fontdescToCTFontDescriptor(&(fp->desc)); - desc = fontdescAppendFeatures(desc, fp->featureTypes, fp->featureSelectors, fp->nFeatures); - font = CTFontCreateWithFontDescriptor(desc, fp->desc.Size, NULL); - CFRelease(desc); // TODO correct? - return font; -} - static void applyAndFreeFontAttributes(struct foreachParams *p) { [p->converted enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSValue *val, BOOL *stop) { diff --git a/darwin/fontmatch.m b/darwin/fontmatch.m index 0c87a427..ba740933 100644 --- a/darwin/fontmatch.m +++ b/darwin/fontmatch.m @@ -255,9 +255,7 @@ CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd) } // fortunately features that aren't supported are simply ignored, so we can copy them all in -// LONGTERM FUTURE when we switch to 10.9, the language parameter won't be needed anymore -// LONGTERM FUTURE and on 10.10 we can use OpenType tags directly! -CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uint16_t *types, const uint16_t *selectors, size_t n) +CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uiOpenTypeFeatures *otf) { CTFontDescriptorRef new; CFMutableArrayRef outerArray; diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index c22c82b6..4020dd27 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -143,7 +143,7 @@ extern void doManualResize(NSWindow *w, NSEvent *initialEvent, uiWindowResizeEdg // fontmatch.m extern CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd); -extern CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uint16_t *types, const uint16_t *selectors, size_t n); +extern CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uiOpenTypeFeatures *otf); extern void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescriptor *uidesc); // attrstr.m