More attributed string API work. Of note, decided to make each type of attribute have its own field in uiAttributeSpec, to make thinking about what to do next easier (and because why not).

This commit is contained in:
Pietro Gagliardi 2017-11-06 23:58:12 -05:00
parent e33879a283
commit bad2325323
2 changed files with 21 additions and 18 deletions

View File

@ -6,3 +6,4 @@ overlapping attributes of different types do not split each other
overlapping attributes of the same type but different values do split overlapping attributes of the same type but different values do split
empty string is allowed empty string is allowed
empty string cannot have attributes empty string cannot have attributes
font family names are case-insensitive both in attributes and in descriptors

View File

@ -1,29 +1,25 @@
// uiAttribute specifies the types of possible attributes that can be // uiAttribute specifies the types of possible attributes that can be
// applied to a uiAttributedString. For every byte in the // applied to a uiAttributedString. For every Unicode codepoint in the
// uiAttributedString, at most one value of each attribute type can // uiAttributedString, at most one value of each attribute type can
// be applied. // be applied.
// TODO just make a separate field in uiAttributeSpec for everything? or make attribute objects opaque instead? // TODO just make a separate field in uiAttributeSpec for everything? or make attribute objects opaque instead?
_UI_ENUM(uiAttribute) { _UI_ENUM(uiAttribute) {
// uiAttributeFamily changes the font family of the text it is // uiAttributeFamily changes the font family of the text it is
// applied to. Use the Family field of uiAttributeSpec. // applied to. Font family names are case-insensitive. Use the
// TODO this is case-insensitive on all platforms; codify this // Family field of uiAttributeSpec.
uiAttributeFamily, uiAttributeFamily,
// uiAttributeSize changes the size of the text it is applied to, // uiAttributeSize changes the size of the text it is applied to,
// in typographical points. Use the Double field of // in typographical points. Use the Size field of uiAttributeSpec.
// uiAttributeSpec.
uiAttributeSize, uiAttributeSize,
// uiAttributeWeight changes the weight of the text it is applied // uiAttributeWeight changes the weight of the text it is applied
// to. Use the Value field of uiAttributeSpec and the // to. Use the Weight field of uiAttributeSpec.
// uiDrawTextWeight constants.
uiAttributeWeight, uiAttributeWeight,
// uiAttributeItalic changes the italicness of the text it is applied // uiAttributeItalic changes the italicness of the text it is applied
// to. Use the Value field of uiAttributeSpec and the // to. Use the Italic field of uiAttributeSpec.
// uiDrawTextItalic constants.
uiAttributeItalic, uiAttributeItalic,
// uiAttributeStretch changes the stretch of the text it is applied // uiAttributeStretch changes the stretch of the text it is applied
// to. Use the Value field of uiAttributeSpec and the // to. Use the Stretch field of uiAttributeSpec.
// uiDrawTextStretch constants.
uiAttributeStretch, uiAttributeStretch,
// uiAttributeColor changes the color of the text it is applied to. // uiAttributeColor changes the color of the text it is applied to.
// Use the R, G, B, and A fields of uiAttributeSpec. // Use the R, G, B, and A fields of uiAttributeSpec.
@ -33,16 +29,18 @@ _UI_ENUM(uiAttribute) {
uiAttributeBackground, uiAttributeBackground,
// uiAttributeUnderline changes the underline style of the text // uiAttributeUnderline changes the underline style of the text
// it is applied to. Use the Value field of uiAttributeSpec and the // it is applied to. Use the UnderlineStyle field of
// uiDrawUnderlineStyle constants. // uiAttributeSpec.
uiAttributeUnderline, uiAttributeUnderline,
// uiAttributeUnderlineColor changes the color of any underline // uiAttributeUnderlineColor changes the color of any underline
// on the text it is applied to, regardless of the style. Use the // on the text it is applied to, regardless of the style. Use the
// Value field of uiAttributeSpec and the uiDrawUnderlineColor // UnderlineColor field of uiAttributeSpec, and also the R, G, B,
// constants (refer to its documentation for more information). // and A fields if specifying uiDrawUnderlineColorCustom.
// //
// If an underline style is applied but no underline color is // If an underline style is applied but no underline color is
// specified, the text color is used instead. // specified, the text color is used instead. If an underline color
// is specified without an underline style, the underline color
// attribute is ignored, but not elided.
uiAttributeUnderlineColor, uiAttributeUnderlineColor,
// uiAttributeFeatures changes the OpenType features of the // uiAttributeFeatures changes the OpenType features of the
@ -146,12 +144,16 @@ typedef struct uiAttributeSpec uiAttributeSpec;
struct uiAttributeSpec { struct uiAttributeSpec {
uiAttribute Type; uiAttribute Type;
const char *Family; const char *Family;
uintptr_t Value; double Size;
double Double; uiDrawTextWeight Weight;
uiDrawTextItalic Italic;
uiDrawTextStretch Stretch;
double R; double R;
double G; double G;
double B; double B;
double A; double A;
uiDrawUnderlineStyle UnderlineStyle;
uiDrawUnderlineColor UnderlineColor;
const uiOpenTypeFeatures *Features; const uiOpenTypeFeatures *Features;
}; };