Added the foreground color attribute. Considering making the background color a background BRUSH attribute instead...
This commit is contained in:
parent
261dd4851a
commit
44f24fc900
|
@ -295,6 +295,12 @@ static int specsIdentical(struct attr *attr, uiAttributeSpec *spec)
|
||||||
case uiAttributeSize:
|
case uiAttributeSize:
|
||||||
// TODO use a closest match?
|
// TODO use a closest match?
|
||||||
return attr->spec.Double == spec->Double;
|
return attr->spec.Double == spec->Double;
|
||||||
|
case uiAttributeColor:
|
||||||
|
// TODO use a closest match?
|
||||||
|
return attr->spec.R == spec->R &&
|
||||||
|
attr->spec.G == spec->G &&
|
||||||
|
attr->spec.B == spec->B &&
|
||||||
|
attr->spec.A == spec->A;
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
// handles the rest
|
// handles the rest
|
||||||
|
|
|
@ -43,9 +43,15 @@ static void adjustFontInRange(struct foreachParams *p, size_t start, size_t end,
|
||||||
static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data)
|
static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data)
|
||||||
{
|
{
|
||||||
struct foreachParams *p = (struct foreachParams *) data;
|
struct foreachParams *p = (struct foreachParams *) data;
|
||||||
|
CFRange range;
|
||||||
|
CGColorSpaceRef colorspace;
|
||||||
|
CGColorRef color;
|
||||||
|
CGFloat components[4];
|
||||||
|
|
||||||
start = attrstrUTF8ToUTF16(s, start);
|
start = attrstrUTF8ToUTF16(s, start);
|
||||||
end = attrstrUTF8ToUTF16(s, end);
|
end = attrstrUTF8ToUTF16(s, end);
|
||||||
|
range.location = start;
|
||||||
|
range.length = end - start;
|
||||||
switch (spec->Type) {
|
switch (spec->Type) {
|
||||||
case uiAttributeFamily:
|
case uiAttributeFamily:
|
||||||
ensureFontInRange(p, start, end);
|
ensureFontInRange(p, start, end);
|
||||||
|
@ -77,6 +83,20 @@ static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t
|
||||||
desc->Stretch = (uiDrawTextStretch) (spec->Value);
|
desc->Stretch = (uiDrawTextStretch) (spec->Value);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case uiAttributeColor:
|
||||||
|
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
||||||
|
if (colorspace == NULL) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
components[0] = spec->R;
|
||||||
|
components[1] = spec->G;
|
||||||
|
components[2] = spec->B;
|
||||||
|
components[3] = spec->A;
|
||||||
|
color = CGColorCreate(colorspace, components);
|
||||||
|
CFRelease(colorspace);
|
||||||
|
CFAttributedStringSetAttribute(p->mas, range, kCTForegroundColorAttributeName, color);
|
||||||
|
CFRelease(color);
|
||||||
|
break;
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -218,6 +218,10 @@ static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b)
|
||||||
// gradients need a color space
|
// gradients need a color space
|
||||||
// for consistency with windows, use sRGB
|
// for consistency with windows, use sRGB
|
||||||
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
||||||
|
if (colorspace == NULL) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
// TODO add NULL check to other uses of CGColorSpace
|
||||||
|
|
||||||
// make the gradient
|
// make the gradient
|
||||||
colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
|
colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]");
|
||||||
|
|
|
@ -62,6 +62,20 @@ static void setupAttributedString(void)
|
||||||
|
|
||||||
uiAttributedStringAppendUnattributed(attrstr, ", ");
|
uiAttributedStringAppendUnattributed(attrstr, ", ");
|
||||||
|
|
||||||
|
next = "multiple colors";
|
||||||
|
start = uiAttributedStringLen(attrstr);
|
||||||
|
end = start + strlen(next);
|
||||||
|
uiAttributedStringAppendUnattributed(attrstr, next);
|
||||||
|
spec.Type = uiAttributeColor;
|
||||||
|
// Direct2D "Crimson" (#DC143C)
|
||||||
|
spec.R = 0.8627450980392156;
|
||||||
|
spec.G = 0.0784313725490196;
|
||||||
|
spec.B = 0.2352941176470588;
|
||||||
|
spec.A = 0.75;
|
||||||
|
uiAttributedStringSetAttribute(attrstr, &spec, start, end);
|
||||||
|
|
||||||
|
uiAttributedStringAppendUnattributed(attrstr, ", ");
|
||||||
|
|
||||||
next = "multiple TODO";
|
next = "multiple TODO";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,12 @@ typedef struct uiAttributedString uiAttributedString;
|
||||||
typedef struct uiAttributeSpec uiAttributeSpec;
|
typedef struct uiAttributeSpec uiAttributeSpec;
|
||||||
|
|
||||||
_UI_ENUM(uiAttribute) {
|
_UI_ENUM(uiAttribute) {
|
||||||
// TODO once we allow loading fonts in memory we can't use just one pointer anymore
|
|
||||||
uiAttributeFamily,
|
uiAttributeFamily,
|
||||||
// TODO no guarantee this can fit in a uintptr_t; we need a better way to store these...
|
uiAttributeSize, // use Double
|
||||||
uiAttributeSize,
|
|
||||||
uiAttributeWeight,
|
uiAttributeWeight,
|
||||||
uiAttributeItalic,
|
uiAttributeItalic,
|
||||||
uiAttributeStretch,
|
uiAttributeStretch,
|
||||||
|
uiAttributeColor, // use R, G, B, A
|
||||||
// TODO
|
// TODO
|
||||||
// TODO uiAttributeSystem,
|
// TODO uiAttributeSystem,
|
||||||
// TODO uiAttributeCustom,
|
// TODO uiAttributeCustom,
|
||||||
|
@ -18,6 +17,10 @@ struct uiAttributeSpec {
|
||||||
uiAttribute Type;
|
uiAttribute Type;
|
||||||
uintptr_t Value;
|
uintptr_t Value;
|
||||||
double Double;
|
double Double;
|
||||||
|
double R;
|
||||||
|
double G;
|
||||||
|
double B;
|
||||||
|
double A;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*uiAttributedStringForEachAttributeFunc)(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data);
|
typedef int (*uiAttributedStringForEachAttributeFunc)(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data);
|
||||||
|
|
Loading…
Reference in New Issue