More reworking the OS X attributed string code. Now we need to rework the AAT code somewhat too.

This commit is contained in:
Pietro Gagliardi 2017-05-30 13:18:13 -04:00
parent e356f1c48a
commit c4dd85bece
3 changed files with 24 additions and 16 deletions

View File

@ -61,6 +61,7 @@ void uninitUnderlineColors(void)
// TODO see if we could use NSAttributedString? // TODO see if we could use NSAttributedString?
// TODO consider renaming this struct and the fep variable(s) // 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 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 { struct foreachParams {
CFMutableAttributedStringRef mas; CFMutableAttributedStringRef mas;
NSMutableDictionary *combinedFontAttrs; // keys are CFIndex in mas, values are combinedFontAttr objects NSMutableDictionary *combinedFontAttrs; // keys are CFIndex in mas, values are combinedFontAttr objects
@ -77,6 +78,7 @@ struct foreachParams {
@property const uiOpenTypeFeatures *features; @property const uiOpenTypeFeatures *features;
- (id)initWithDefaultFont:(uiDrawFontDescriptor *)defaultFont; - (id)initWithDefaultFont:(uiDrawFontDescriptor *)defaultFont;
- (BOOL)same:(combinedFontAttr *)b; - (BOOL)same:(combinedFontAttr *)b;
- (CTFontRef)toCTFont;
@end @end
@implementation combinedFontAttr @implementation combinedFontAttr
@ -85,6 +87,7 @@ struct foreachParams {
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
// TODO define behaviors if defaultFont->Family or any attribute Family is NULL, same with other invalid values
self.family = defaultFont->Family; self.family = defaultFont->Family;
self.size = defaultFont->Size; self.size = defaultFont->Size;
self.weight = defaultFont->Weight; self.weight = defaultFont->Weight;
@ -122,6 +125,25 @@ struct foreachParams {
return YES; 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 @end
static void ensureFontInRange(struct foreachParams *p, size_t start, size_t 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; 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) static void applyAndFreeFontAttributes(struct foreachParams *p)
{ {
[p->converted enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSValue *val, BOOL *stop) { [p->converted enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSValue *val, BOOL *stop) {

View File

@ -255,9 +255,7 @@ CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd)
} }
// fortunately features that aren't supported are simply ignored, so we can copy them all in // 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 CTFontDescriptorRef fontdescAppendFeatures(CTFontDescriptorRef desc, const uiOpenTypeFeatures *otf)
// 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 new; CTFontDescriptorRef new;
CFMutableArrayRef outerArray; CFMutableArrayRef outerArray;

View File

@ -143,7 +143,7 @@ extern void doManualResize(NSWindow *w, NSEvent *initialEvent, uiWindowResizeEdg
// fontmatch.m // fontmatch.m
extern CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd); 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); extern void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescriptor *uidesc);
// attrstr.m // attrstr.m