From 1c1b16a20658e8cb8f7ca1a20c4961ca204f686b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 12 Feb 2017 13:41:52 -0500 Subject: [PATCH] More attributes. Beyond this point I'd need to either redefine the way attributes are specified or make more header macros. --- darwin/attrstr.m | 25 +++++++++++++++++++ examples/drawtext/attributes.c | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/darwin/attrstr.m b/darwin/attrstr.m index 49f0d20a..d1298944 100644 --- a/darwin/attrstr.m +++ b/darwin/attrstr.m @@ -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; diff --git a/examples/drawtext/attributes.c b/examples/drawtext/attributes.c index b66635df..428c1275 100644 --- a/examples/drawtext/attributes.c +++ b/examples/drawtext/attributes.c @@ -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";