More attributes. Beyond this point I'd need to either redefine the way attributes are specified or make more header macros.

This commit is contained in:
Pietro Gagliardi 2017-02-12 13:41:52 -05:00
parent 5aaac84d55
commit 1c1b16a206
2 changed files with 70 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#import "uipriv_darwin.h"
// unlike the other systems, Core Text rolls family, size, weight, italic, width, AND opentype features into the "font" attribute
// TODO opentype features and AAT fvar table info is lost, so a handful of fonts in the font panel ("Titling" variants of some fonts and Skia 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 consider renaming this struct and the fep variable(s)
struct foreachParams {
@ -52,6 +53,30 @@ static int processAttribute(uiAttributedString *s, uiAttribute type, uintptr_t v
desc->Family = (char *) value;
});
break;
case uiAttributeSize:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiDrawFontDescriptor *desc) {
desc->Size = *((double *) value);
});
break;
case uiAttributeWeight:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiDrawFontDescriptor *desc) {
desc->Weight = (uiDrawTextWeight) value;
});
break;
case uiAttributeItalic:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiDrawFontDescriptor *desc) {
desc->Italic = (uiDrawTextItalic) value;
});
break;
case uiAttributeStretch:
ensureFontInRange(p, start, end);
adjustFontInRange(p, start, end, ^(uiDrawFontDescriptor *desc) {
desc->Stretch = (uiDrawTextStretch) value;
});
break;
// TODO
}
return 0;

View File

@ -22,6 +22,51 @@ static void setupAttributedString(void)
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "multiple sizes";
static double eighteen = 18;
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
uiAttributedStringSetAttribute(attrstr,
uiAttributeSize,
(uintptr_t) (&eighteen),
start, end);
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "multiple weights";
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
uiAttributedStringSetAttribute(attrstr,
uiAttributeWeight,
(uintptr_t) uiDrawTextWeightBold,
start, end);
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "multiple italics";
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
uiAttributedStringSetAttribute(attrstr,
uiAttributeItalic,
(uintptr_t) uiDrawTextItalicItalic,
start, end);
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "multiple stretches";
start = uiAttributedStringLen(attrstr);
end = start + strlen(next);
uiAttributedStringAppendUnattributed(attrstr, next);
uiAttributedStringSetAttribute(attrstr,
uiAttributeStretch,
(uintptr_t) uiDrawTextStretchCondensed,
start, end);
uiAttributedStringAppendUnattributed(attrstr, ", ");
next = "multiple TODO";
}
static char fontFamily[] = "Times New Roman";