Started cleaning up attrstr.m. This is gonna be fun...

This commit is contained in:
Pietro Gagliardi 2018-03-04 20:45:05 -05:00
parent 232b14ccde
commit 49c3f77d46
1 changed files with 13 additions and 29 deletions

View File

@ -59,7 +59,7 @@ void uiprivUninitUnderlineColors(void)
} }
// unlike the other systems, Core Text rolls family, size, weight, italic, width, AND opentype features into the "font" attribute // unlike the other systems, Core Text rolls family, size, weight, italic, width, AND opentype features into the "font" attribute
// TODO opentype features are lost, so a handful of fonts in the font panel ("Titling" variants of some fonts and possibly others but those are the examples I know about) cannot be represented by uiDrawFontDescriptor; what *can* we do about this since this info is NOT part of the font on other platforms? // TODO opentype features are lost when using uiDrawFontDescriptor, so a handful of fonts in the font panel ("Titling" variants of some fonts and possibly others but those are the examples I know about) cannot be represented by uiDrawFontDescriptor; what *can* we do about this since this info is NOT part of the font on other platforms?
// 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?
@ -100,7 +100,7 @@ struct foreachParams {
return self; return self;
} }
// TODO deduplicate this with common/attrlist.c // TODO deduplicate this with common/attribute.c
- (BOOL)same:(uiprivCombinedFontAttr *)b - (BOOL)same:(uiprivCombinedFontAttr *)b
{ {
// TODO should this be case-insensitive? // TODO should this be case-insensitive?
@ -135,7 +135,7 @@ struct foreachParams {
uidesc.Stretch = self.stretch; uidesc.Stretch = self.stretch;
desc = fontdescToCTFontDescriptor(&uidesc); desc = fontdescToCTFontDescriptor(&uidesc);
if (self.features != NULL) if (self.features != NULL)
desc = fontdescAppendFeatures(desc, self.features); desc = uiprivCTFontDescriptorAppendFeatures(desc, self.features);
font = CTFontCreateWithFontDescriptor(desc, self.size, NULL); font = CTFontCreateWithFontDescriptor(desc, self.size, NULL);
CFRelease(desc); // TODO correct? CFRelease(desc); // TODO correct?
return font; return font;
@ -143,22 +143,6 @@ struct foreachParams {
@end @end
// TODO merge this with adjustFontInRange() (and TODO figure out why they were separate in the first place; probably Windows?)
static void ensureFontInRange(struct foreachParams *p, size_t start, size_t end)
{
size_t i;
NSNumber *n;
uiprivCombinedFontAttr *new;
for (i = start; i < end; i++) {
n = [NSNumber numberWithInteger:i];
if ([p->combinedFontAttrs objectForKey:n] != nil)
continue;
new = [[uiprivCombinedFontAttr alloc] initWithDefaultFont:p->defaultFont];
[p->combinedFontAttrs setObject:new forKey:n];
}
}
static void adjustFontInRange(struct foreachParams *p, size_t start, size_t end, void (^adj)(uiprivCombinedFontAttr *cfa)) static void adjustFontInRange(struct foreachParams *p, size_t start, size_t end, void (^adj)(uiprivCombinedFontAttr *cfa))
{ {
size_t i; size_t i;
@ -168,6 +152,10 @@ static void adjustFontInRange(struct foreachParams *p, size_t start, size_t end,
for (i = start; i < end; i++) { for (i = start; i < end; i++) {
n = [NSNumber numberWithInteger:i]; n = [NSNumber numberWithInteger:i];
cfa = (uiprivCombinedFontAttr *) [p->combinedFontAttrs objectForKey:n]; cfa = (uiprivCombinedFontAttr *) [p->combinedFontAttrs objectForKey:n];
if (cfa == nil) {
cfa = [[uiprivCombinedFontAttr alloc] initWithDefaultFont:p->defaultFont];
[p->combinedFontAttrs setObject:cfa forKey:n];
}
adj(cfa); adj(cfa);
} }
} }
@ -192,6 +180,7 @@ static CGColorRef mkcolor(uiAttributeSpec *spec)
CGColorRef color; CGColorRef color;
CGFloat components[4]; CGFloat components[4];
// TODO we should probably just create this once and recycle it throughout program execution...
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
if (colorspace == NULL) { if (colorspace == NULL) {
// TODO // TODO
@ -205,7 +194,7 @@ static CGColorRef mkcolor(uiAttributeSpec *spec)
return color; return color;
} }
static uiForEach processAttribute(const uiAttributedString *s, const uiAttributeSpec *spec, size_t start, size_t end, void *data) static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute *attr, size_t start, size_t end, void *data)
{ {
struct foreachParams *p = (struct foreachParams *) data; struct foreachParams *p = (struct foreachParams *) data;
CFRange range; CFRange range;
@ -217,37 +206,33 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
ostart = start; ostart = start;
oend = end; oend = end;
start = attrstrUTF8ToUTF16(s, start); start = uiprivAttributedStringUTF8ToUTF16(s, start);
end = attrstrUTF8ToUTF16(s, end); end = uiprivAttributedStringUTF8ToUTF16(s, end);
range.location = start; range.location = start;
range.length = end - start; range.length = end - start;
switch (spec->Type) { switch (uiAttributeGetType(attr)) {
$$TODO_CONTINUE_HERE
case uiAttributeFamily: case uiAttributeFamily:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.family = spec->Family; cfa.family = spec->Family;
}); });
break; break;
case uiAttributeSize: case uiAttributeSize:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.size = spec->Double; cfa.size = spec->Double;
}); });
break; break;
case uiAttributeWeight: case uiAttributeWeight:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.weight = (uiDrawTextWeight) (spec->Value); cfa.weight = (uiDrawTextWeight) (spec->Value);
}); });
break; break;
case uiAttributeItalic: case uiAttributeItalic:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.italic = (uiDrawTextItalic) (spec->Value); cfa.italic = (uiDrawTextItalic) (spec->Value);
}); });
break; break;
case uiAttributeStretch: case uiAttributeStretch:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.stretch = (uiDrawTextStretch) (spec->Value); cfa.stretch = (uiDrawTextStretch) (spec->Value);
}); });
@ -303,7 +288,6 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
CFRelease(color); CFRelease(color);
break; break;
case uiAttributeFeatures: case uiAttributeFeatures:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) { adjustFontInRange(p, start, end, ^(uiprivCombinedFontAttr *cfa) {
cfa.features = spec->Features; cfa.features = spec->Features;
}); });