Implemented text layout SetColor on OS X.
This commit is contained in:
parent
7a568f6bf4
commit
e786d664cb
|
@ -600,3 +600,28 @@ void doDrawText(CGContextRef c, CGFloat cheight, double x, double y, uiDrawTextL
|
|||
y -= yoff;
|
||||
CGContextSetTextPosition(c, x, y);
|
||||
#endif
|
||||
|
||||
// TODO length - 1?
|
||||
#define rangeToCFRange() CFRangeMake(startChar, endChar - startChar)
|
||||
|
||||
void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, intmax_t startChar, intmax_t endChar, double r, double g, double b, double a)
|
||||
{
|
||||
CGColorSpaceRef colorspace;
|
||||
CGFloat components[4];
|
||||
CGColorRef color;
|
||||
|
||||
// for consistency with windows, use sRGB
|
||||
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
||||
components[0] = r;
|
||||
components[1] = g;
|
||||
components[2] = b;
|
||||
components[3] = a;
|
||||
color = CGColorCreate(colorspace, components);
|
||||
CGColorSpaceRelease(colorspace);
|
||||
|
||||
CFAttributedStringSetAttribute(layout->mas,
|
||||
rangeToCFRange(),
|
||||
kCTForegroundColorAttributeName,
|
||||
color);
|
||||
CGColorRelease(color); // TODO safe?
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
|
||||
// TODO
|
||||
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
||||
family = uiEntryText(textFont);
|
||||
desc.Family = "Arial";
|
||||
desc.Size = 36;
|
||||
desc.Weight = uiDrawTextWeightNormal;
|
||||
|
@ -38,11 +37,11 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
desc.Stretch = uiDrawTextStretchNormal;
|
||||
font = uiDrawLoadClosestFont(&desc);
|
||||
|
||||
layout = uiDrawNewTextLayout(s, "One two three four", -1);
|
||||
uiDrawTextLayoutSetForegroundColor(layout,
|
||||
layout = uiDrawNewTextLayout("One two three four", font, -1);
|
||||
uiDrawTextLayoutSetColor(layout,
|
||||
4, 7,
|
||||
1, 0, 0, 1);
|
||||
uiDrawTextLayoutSetForegroundColor(layout,
|
||||
uiDrawTextLayoutSetColor(layout,
|
||||
8, 14,
|
||||
1, 0, 0.5, 0.5);
|
||||
uiDrawText(dp->Context, 10, 10, layout);
|
||||
|
|
Loading…
Reference in New Issue