2017-02-12 00:05:27 -06:00
|
|
|
// 12 february 2017
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2017-02-15 15:22:42 -06:00
|
|
|
// LONGTERM FUTURE for typographic features, on 10.10 we can use OpenType tags directly!
|
|
|
|
|
2017-02-14 13:57:56 -06:00
|
|
|
// this is what AppKit does internally
|
|
|
|
// WebKit does this too; see https://github.com/adobe/webkit/blob/master/Source/WebCore/platform/graphics/mac/GraphicsContextMac.mm
|
|
|
|
static NSColor *spellingColor = nil;
|
|
|
|
static NSColor *grammarColor = nil;
|
|
|
|
static NSColor *auxiliaryColor = nil;
|
|
|
|
|
|
|
|
static NSColor *tryColorNamed(NSString *name)
|
|
|
|
{
|
|
|
|
NSImage *img;
|
|
|
|
|
|
|
|
img = [NSImage imageNamed:name];
|
|
|
|
if (img == nil)
|
|
|
|
return nil;
|
|
|
|
return [NSColor colorWithPatternImage:img];
|
|
|
|
}
|
|
|
|
|
|
|
|
void initUnderlineColors(void)
|
|
|
|
{
|
|
|
|
spellingColor = tryColorNamed(@"NSSpellingDot");
|
|
|
|
if (spellingColor == nil) {
|
|
|
|
// WebKit says this is needed for "older systems"; not sure how old, but 10.11 AppKit doesn't look for this
|
|
|
|
spellingColor = tryColorNamed(@"SpellingDot");
|
|
|
|
if (spellingColor == nil)
|
|
|
|
spellingColor = [NSColor redColor];
|
|
|
|
}
|
|
|
|
[spellingColor retain]; // override autoreleasing
|
|
|
|
|
|
|
|
grammarColor = tryColorNamed(@"NSGrammarDot");
|
|
|
|
if (grammarColor == nil) {
|
|
|
|
// WebKit says this is needed for "older systems"; not sure how old, but 10.11 AppKit doesn't look for this
|
|
|
|
grammarColor = tryColorNamed(@"GrammarDot");
|
|
|
|
if (grammarColor == nil)
|
|
|
|
grammarColor = [NSColor greenColor];
|
|
|
|
}
|
|
|
|
[grammarColor retain]; // override autoreleasing
|
|
|
|
|
|
|
|
auxiliaryColor = tryColorNamed(@"NSCorrectionDot");
|
|
|
|
if (auxiliaryColor == nil) {
|
|
|
|
// WebKit says this is needed for "older systems"; not sure how old, but 10.11 AppKit doesn't look for this
|
|
|
|
auxiliaryColor = tryColorNamed(@"CorrectionDot");
|
|
|
|
if (auxiliaryColor == nil)
|
|
|
|
auxiliaryColor = [NSColor blueColor];
|
|
|
|
}
|
|
|
|
[auxiliaryColor retain]; // override autoreleasing
|
|
|
|
}
|
|
|
|
|
|
|
|
void uninitUnderlineColors(void)
|
|
|
|
{
|
|
|
|
[auxiliaryColor release];
|
|
|
|
[grammarColor release];
|
|
|
|
[spellingColor release];
|
|
|
|
}
|
|
|
|
|
2017-02-12 00:05:27 -06:00
|
|
|
// unlike the other systems, Core Text rolls family, size, weight, italic, width, AND opentype features into the "font" attribute
|
2017-02-12 12:41:52 -06:00
|
|
|
// 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?
|
2017-02-12 00:05:27 -06:00
|
|
|
// TODO see if we could use NSAttributedString?
|
|
|
|
// TODO consider renaming this struct and the fep variable(s)
|
2017-05-30 12:06:58 -05:00
|
|
|
// TODO restructure all this so the important details at the top are below with the combined font attributes type?
|
2017-05-30 12:18:13 -05:00
|
|
|
// TODO in fact I should just write something to explain everything in this file...
|
2017-02-12 00:05:27 -06:00
|
|
|
struct foreachParams {
|
|
|
|
CFMutableAttributedStringRef mas;
|
2017-05-30 12:06:58 -05:00
|
|
|
NSMutableDictionary *combinedFontAttrs; // keys are CFIndex in mas, values are combinedFontAttr objects
|
2017-02-12 00:05:27 -06:00
|
|
|
uiDrawFontDescriptor *defaultFont;
|
2017-02-13 01:10:39 -06:00
|
|
|
NSMutableArray *backgroundBlocks;
|
2017-02-12 00:05:27 -06:00
|
|
|
};
|
|
|
|
|
2017-05-30 12:06:58 -05:00
|
|
|
@interface combinedFontAttr : NSObject
|
|
|
|
@property const char *family;
|
|
|
|
@property double size;
|
|
|
|
@property uiDrawTextWeight weight;
|
|
|
|
@property uiDrawTextItalic italic;
|
|
|
|
@property uiDrawTextStretch stretch;
|
|
|
|
@property const uiOpenTypeFeatures *features;
|
|
|
|
- (id)initWithDefaultFont:(uiDrawFontDescriptor *)defaultFont;
|
|
|
|
- (BOOL)same:(combinedFontAttr *)b;
|
2017-05-30 12:18:13 -05:00
|
|
|
- (CTFontRef)toCTFont;
|
2017-05-30 12:06:58 -05:00
|
|
|
@end
|
2017-02-13 09:34:25 -06:00
|
|
|
|
2017-05-30 12:06:58 -05:00
|
|
|
@implementation combinedFontAttr
|
|
|
|
|
|
|
|
- (id)initWithDefaultFont:(uiDrawFontDescriptor *)defaultFont
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2017-05-30 12:18:13 -05:00
|
|
|
// TODO define behaviors if defaultFont->Family or any attribute Family is NULL, same with other invalid values
|
2017-05-30 12:06:58 -05:00
|
|
|
self.family = defaultFont->Family;
|
|
|
|
self.size = defaultFont->Size;
|
|
|
|
self.weight = defaultFont->Weight;
|
|
|
|
self.italic = defaultFont->Italic;
|
|
|
|
self.stretch = defaultFont->Stretch;
|
|
|
|
self.features = NULL;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO deduplicate this with common/attrlist.c
|
|
|
|
- (BOOL)same:(combinedFontAttr *)b
|
|
|
|
{
|
|
|
|
// TODO should this be case-insensitive?
|
|
|
|
if (strcmp(self.family, b.family) != 0)
|
|
|
|
return NO;
|
|
|
|
// TODO use a closest match?
|
|
|
|
if (self.size != b.size)
|
|
|
|
return NO;
|
|
|
|
if (self.weight != b.weight)
|
|
|
|
return NO;
|
|
|
|
if (self.italic != b.italic)
|
|
|
|
return NO;
|
|
|
|
if (self.stretch != b.stretch)
|
|
|
|
return NO;
|
|
|
|
// TODO make this part of uiOpenTypeFeaturesEqual() on all platforms
|
|
|
|
if (self.features == NULL && b.features == NULL)
|
|
|
|
return YES;
|
|
|
|
if (self.features != NULL && b.features == NULL)
|
|
|
|
return NO;
|
|
|
|
if (self.features == NULL && b.features != NULL)
|
|
|
|
return NO;
|
|
|
|
if (!uiOpenTypeFeaturesEqual(self.features, b.features))
|
|
|
|
return NO;
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-05-30 12:18:13 -05:00
|
|
|
- (CTFontRef)toCTFont
|
|
|
|
{
|
|
|
|
uiDrawFontDescriptor uidesc;
|
|
|
|
CTFontDescriptorRef desc;
|
|
|
|
CTFontRef font;
|
|
|
|
|
|
|
|
uidesc.Family = self.family;
|
|
|
|
uidesc.Size = self.size;
|
|
|
|
uidesc.Weight = self.weight;
|
|
|
|
uidesc.Italic = self.italic;
|
|
|
|
uidesc.Stretch = self.stretch;
|
|
|
|
desc = fontdescToCTFontDescriptor(&uidesc);
|
|
|
|
if (self.features != NULL)
|
|
|
|
desc = fontdescAppendFeatures(desc, self.features);
|
|
|
|
font = CTFontCreateWithFontDescriptor(desc, self.size, NULL);
|
|
|
|
CFRelease(desc); // TODO correct?
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
2017-05-30 12:06:58 -05:00
|
|
|
@end
|
2017-02-13 09:34:25 -06:00
|
|
|
|
2017-05-30 13:38:25 -05:00
|
|
|
// TODO merge this with adjustFontInRange() (and TODO figure out why they were separate in the first place; probably Windows?)
|
2017-02-12 00:05:27 -06:00
|
|
|
static void ensureFontInRange(struct foreachParams *p, size_t start, size_t end)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
NSNumber *n;
|
2017-05-30 12:06:58 -05:00
|
|
|
combinedFontAttr *new;
|
2017-02-12 00:05:27 -06:00
|
|
|
|
|
|
|
for (i = start; i < end; i++) {
|
|
|
|
n = [NSNumber numberWithInteger:i];
|
2017-05-30 12:06:58 -05:00
|
|
|
if ([p->combinedFontAttrs objectForKey:n] != nil)
|
2017-02-12 00:05:27 -06:00
|
|
|
continue;
|
2017-05-30 12:06:58 -05:00
|
|
|
new = [[combinedFontAttr alloc] initWithDefaultFont:p->defaultFont];
|
|
|
|
[p->combinedFontAttrs setObject:new forKey:n];
|
2017-02-12 00:05:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 12:06:58 -05:00
|
|
|
static void adjustFontInRange(struct foreachParams *p, size_t start, size_t end, void (^adj)(combinedFontAttr *cfa))
|
2017-02-12 00:05:27 -06:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
NSNumber *n;
|
2017-05-30 12:06:58 -05:00
|
|
|
combinedFontAttr *cfa;
|
2017-02-12 00:05:27 -06:00
|
|
|
|
|
|
|
for (i = start; i < end; i++) {
|
|
|
|
n = [NSNumber numberWithInteger:i];
|
2017-05-30 12:06:58 -05:00
|
|
|
v = (combinedFontAttr *) [p->combinedFontAttrs objectForKey:n];
|
|
|
|
adj(cfa);
|
2017-02-12 00:05:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:10:39 -06:00
|
|
|
static backgroundBlock mkBackgroundBlock(size_t start, size_t end, double r, double g, double b, double a)
|
|
|
|
{
|
|
|
|
return Block_copy(^(uiDrawContext *c, uiDrawTextLayout *layout, double x, double y) {
|
|
|
|
uiDrawBrush brush;
|
|
|
|
|
|
|
|
brush.Type = uiDrawBrushTypeSolid;
|
|
|
|
brush.R = r;
|
|
|
|
brush.G = g;
|
|
|
|
brush.B = b;
|
|
|
|
brush.A = a;
|
|
|
|
drawTextBackground(c, x, y, layout, start, end, &brush, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:57:56 -06:00
|
|
|
static CGColorRef mkcolor(uiAttributeSpec *spec)
|
|
|
|
{
|
|
|
|
CGColorSpaceRef colorspace;
|
|
|
|
CGColorRef color;
|
|
|
|
CGFloat components[4];
|
|
|
|
|
|
|
|
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);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2017-02-12 13:11:25 -06:00
|
|
|
static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data)
|
2017-02-12 00:05:27 -06:00
|
|
|
{
|
|
|
|
struct foreachParams *p = (struct foreachParams *) data;
|
2017-02-12 19:27:47 -06:00
|
|
|
CFRange range;
|
|
|
|
CGColorRef color;
|
2017-02-13 01:10:39 -06:00
|
|
|
size_t ostart, oend;
|
|
|
|
backgroundBlock block;
|
2017-02-14 13:57:56 -06:00
|
|
|
int32_t us;
|
|
|
|
CFNumberRef num;
|
2017-02-12 00:05:27 -06:00
|
|
|
|
2017-02-13 01:10:39 -06:00
|
|
|
ostart = start;
|
|
|
|
oend = end;
|
2017-02-12 00:05:27 -06:00
|
|
|
start = attrstrUTF8ToUTF16(s, start);
|
|
|
|
end = attrstrUTF8ToUTF16(s, end);
|
2017-02-12 19:27:47 -06:00
|
|
|
range.location = start;
|
|
|
|
range.length = end - start;
|
2017-02-12 13:11:25 -06:00
|
|
|
switch (spec->Type) {
|
2017-02-12 00:05:27 -06:00
|
|
|
case uiAttributeFamily:
|
|
|
|
ensureFontInRange(p, start, end);
|
2017-05-30 12:06:58 -05:00
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.family = spec->Family;
|
2017-02-12 00:05:27 -06:00
|
|
|
});
|
|
|
|
break;
|
2017-02-12 12:41:52 -06:00
|
|
|
case uiAttributeSize:
|
|
|
|
ensureFontInRange(p, start, end);
|
2017-05-30 12:06:58 -05:00
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.size = spec->Double;
|
2017-02-12 12:41:52 -06:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case uiAttributeWeight:
|
|
|
|
ensureFontInRange(p, start, end);
|
2017-05-30 12:06:58 -05:00
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.weight = (uiDrawTextWeight) (spec->Value);
|
2017-02-12 12:41:52 -06:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case uiAttributeItalic:
|
|
|
|
ensureFontInRange(p, start, end);
|
2017-05-30 12:06:58 -05:00
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.italic = (uiDrawTextItalic) (spec->Value);
|
2017-02-12 12:41:52 -06:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case uiAttributeStretch:
|
|
|
|
ensureFontInRange(p, start, end);
|
2017-05-30 12:06:58 -05:00
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.stretch = (uiDrawTextStretch) (spec->Value);
|
2017-02-12 12:41:52 -06:00
|
|
|
});
|
|
|
|
break;
|
2017-02-12 19:27:47 -06:00
|
|
|
case uiAttributeColor:
|
2017-02-14 13:57:56 -06:00
|
|
|
color = mkcolor(spec);
|
2017-02-12 19:27:47 -06:00
|
|
|
CFAttributedStringSetAttribute(p->mas, range, kCTForegroundColorAttributeName, color);
|
|
|
|
CFRelease(color);
|
|
|
|
break;
|
2017-02-13 01:10:39 -06:00
|
|
|
case uiAttributeBackground:
|
|
|
|
block = mkBackgroundBlock(ostart, oend,
|
|
|
|
spec->R, spec->G, spec->B, spec->A);
|
|
|
|
[p->backgroundBlocks addObject:block];
|
|
|
|
Block_release(block);
|
|
|
|
break;
|
2017-02-14 13:57:56 -06:00
|
|
|
case uiAttributeUnderline:
|
|
|
|
switch (spec->Value) {
|
|
|
|
case uiDrawUnderlineStyleNone:
|
|
|
|
us = kCTUnderlineStyleNone;
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineStyleSingle:
|
|
|
|
us = kCTUnderlineStyleSingle;
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineStyleDouble:
|
|
|
|
us = kCTUnderlineStyleDouble;
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineStyleSuggestion:
|
|
|
|
// TODO incorrect if a solid color
|
|
|
|
us = kCTUnderlineStyleThick;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
num = CFNumberCreate(NULL, kCFNumberSInt32Type, &us);
|
|
|
|
CFAttributedStringSetAttribute(p->mas, range, kCTUnderlineStyleAttributeName, num);
|
|
|
|
CFRelease(num);
|
|
|
|
break;
|
|
|
|
case uiAttributeUnderlineColor:
|
|
|
|
switch (spec->Value) {
|
|
|
|
case uiDrawUnderlineColorCustom:
|
|
|
|
color = mkcolor(spec);
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineColorSpelling:
|
|
|
|
color = [spellingColor CGColor];
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineColorGrammar:
|
|
|
|
color = [grammarColor CGColor];
|
|
|
|
break;
|
|
|
|
case uiDrawUnderlineColorAuxiliary:
|
|
|
|
color = [auxiliaryColor CGColor];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CFAttributedStringSetAttribute(p->mas, range, kCTUnderlineColorAttributeName, color);
|
|
|
|
if (spec->Value == uiDrawUnderlineColorCustom)
|
|
|
|
CFRelease(color);
|
|
|
|
break;
|
2017-05-19 14:48:15 -05:00
|
|
|
case uiAttributeFeatures:
|
2017-05-30 12:06:58 -05:00
|
|
|
ensureFontInRange(p, start, end);
|
|
|
|
adjustFontInRange(p, start, end, ^(combinedFontAttr *cfa) {
|
|
|
|
cfa.features = spec->Features;
|
|
|
|
});
|
2017-02-15 22:10:23 -06:00
|
|
|
break;
|
2017-05-19 14:48:15 -05:00
|
|
|
default:
|
|
|
|
// TODO complain
|
|
|
|
;
|
2017-02-12 00:05:27 -06:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-30 13:38:25 -05:00
|
|
|
static BOOL cfaIsEqual(combinedFontAttr *a, combinedFontAttr *b)
|
|
|
|
{
|
|
|
|
if (a == nil && b == nil)
|
|
|
|
return YES;
|
|
|
|
if (a == nil || b == nil)
|
|
|
|
return NO;
|
|
|
|
return [a same:b];
|
|
|
|
}
|
|
|
|
|
2017-02-12 00:05:27 -06:00
|
|
|
static void applyAndFreeFontAttributes(struct foreachParams *p)
|
|
|
|
{
|
2017-05-30 13:38:25 -05:00
|
|
|
CFIndex i;
|
|
|
|
combinedFontAttr *cfa, *cfab;
|
|
|
|
CTFontRef defaultFont;
|
|
|
|
CTFontRef font;
|
|
|
|
CFRange range;
|
|
|
|
|
|
|
|
// first get the default font as a CTFontRef
|
|
|
|
cfa = [[combinedFontAttr alloc] initWithDefaultFont:p->defaultFont];
|
|
|
|
defaultFont = [cfa toCTFont];
|
|
|
|
[cfa release];
|
|
|
|
|
|
|
|
// now go through, fililng in the font attribute for successive ranges of identical combinedFontAttrs
|
|
|
|
// we are best off treating series of identical fonts as single ranges ourselves for parity across platforms, even if OS X does something similar itself
|
|
|
|
// this also avoids breaking apart surrogate pairs (though IIRC OS X doing the something similar itself might make this a non-issue here)
|
|
|
|
cfa = nil;
|
|
|
|
n = CFAttributedStringGetLength(p->mas);
|
|
|
|
range.location = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
NSNumber *nn;
|
|
|
|
|
|
|
|
nn = [NSNumber numberWithInteger:i];
|
|
|
|
cfab = (combinedFontAttr *) [p->combinedFontAttrs objectForKey:nn];
|
|
|
|
if (cfaIsEqual(cfa, cfab))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// the font has changed; write out the old one
|
|
|
|
range.length = i - range.location;
|
|
|
|
if (cfa == nil) {
|
|
|
|
font = defaultFont;
|
|
|
|
CFRetain(font);
|
|
|
|
} else
|
|
|
|
font = [cfa toCTFont];
|
2017-02-12 00:05:27 -06:00
|
|
|
CFAttributedStringSetAttribute(p->mas, range, kCTFontAttributeName, font);
|
|
|
|
CFRelease(font);
|
2017-05-30 13:38:25 -05:00
|
|
|
// and start this run
|
|
|
|
cfa = cfab;
|
|
|
|
range.location = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and finally, write out the last range
|
|
|
|
range.length = i - range.location;
|
|
|
|
if (cfa == nil) {
|
|
|
|
font = defaultFont;
|
|
|
|
CFRetain(font);
|
|
|
|
} else
|
|
|
|
font = [cfa toCTFont];
|
|
|
|
CFAttributedStringSetAttribute(p->mas, range, kCTFontAttributeName, font);
|
|
|
|
CFRelease(font);
|
|
|
|
|
|
|
|
CFRelease(defaultFont);
|
2017-02-12 00:05:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static const CTTextAlignment ctaligns[] = {
|
|
|
|
[uiDrawTextLayoutAlignLeft] = kCTTextAlignmentLeft,
|
|
|
|
[uiDrawTextLayoutAlignCenter] = kCTTextAlignmentCenter,
|
|
|
|
[uiDrawTextLayoutAlignRight] = kCTTextAlignmentRight,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CTParagraphStyleRef mkParagraphStyle(uiDrawTextLayoutParams *p)
|
|
|
|
{
|
|
|
|
CTParagraphStyleRef ps;
|
|
|
|
CTParagraphStyleSetting settings[16];
|
|
|
|
size_t nSettings = 0;
|
|
|
|
|
|
|
|
settings[nSettings].spec = kCTParagraphStyleSpecifierAlignment;
|
|
|
|
settings[nSettings].valueSize = sizeof (CTTextAlignment);
|
|
|
|
settings[nSettings].value = ctaligns + p->Align;
|
|
|
|
nSettings++;
|
|
|
|
|
|
|
|
ps = CTParagraphStyleCreate(settings, nSettings);
|
|
|
|
if (ps == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2017-02-13 01:10:39 -06:00
|
|
|
CFAttributedStringRef attrstrToCoreFoundation(uiDrawTextLayoutParams *p, NSArray **backgroundBlocks)
|
2017-02-12 00:05:27 -06:00
|
|
|
{
|
|
|
|
CFStringRef cfstr;
|
|
|
|
CFMutableDictionaryRef defaultAttrs;
|
|
|
|
CTFontRef defaultCTFont;
|
|
|
|
CTParagraphStyleRef ps;
|
|
|
|
CFAttributedStringRef base;
|
|
|
|
CFMutableAttributedStringRef mas;
|
|
|
|
struct foreachParams fep;
|
2017-02-15 15:22:42 -06:00
|
|
|
struct fontParams ffp;
|
2017-02-12 00:05:27 -06:00
|
|
|
|
|
|
|
cfstr = CFStringCreateWithCharacters(NULL, attrstrUTF16(p->String), attrstrUTF16Len(p->String));
|
|
|
|
if (cfstr == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
defaultAttrs = CFDictionaryCreateMutable(NULL, 0,
|
|
|
|
&kCFCopyStringDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
if (defaultAttrs == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
2017-02-15 15:22:42 -06:00
|
|
|
memset(&ffp, 0, sizeof (struct fontParams));
|
|
|
|
ffp.desc = *(p->DefaultFont);
|
|
|
|
defaultCTFont = fontdescToCTFont(&ffp);
|
2017-02-12 00:05:27 -06:00
|
|
|
CFDictionaryAddValue(defaultAttrs, kCTFontAttributeName, defaultCTFont);
|
|
|
|
CFRelease(defaultCTFont);
|
|
|
|
ps = mkParagraphStyle(p);
|
|
|
|
CFDictionaryAddValue(defaultAttrs, kCTParagraphStyleAttributeName, ps);
|
|
|
|
CFRelease(ps);
|
|
|
|
|
|
|
|
base = CFAttributedStringCreate(NULL, cfstr, defaultAttrs);
|
|
|
|
if (base == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
CFRelease(cfstr);
|
|
|
|
CFRelease(defaultAttrs);
|
|
|
|
mas = CFAttributedStringCreateMutableCopy(NULL, 0, base);
|
|
|
|
CFRelease(base);
|
|
|
|
|
|
|
|
CFAttributedStringBeginEditing(mas);
|
|
|
|
fep.mas = mas;
|
2017-05-30 13:38:25 -05:00
|
|
|
fep.combinedFontAttrs = [NSMutableDictionary new];
|
2017-02-12 00:05:27 -06:00
|
|
|
fep.defaultFont = p->DefaultFont;
|
2017-02-13 01:10:39 -06:00
|
|
|
fep.backgroundBlocks = [NSMutableArray new];
|
2017-02-12 00:05:27 -06:00
|
|
|
uiAttributedStringForEachAttribute(p->String, processAttribute, &fep);
|
|
|
|
applyAndFreeFontAttributes(&fep);
|
2017-05-30 13:38:25 -05:00
|
|
|
[fep.combinedFontAttrs release];
|
2017-02-12 00:05:27 -06:00
|
|
|
CFAttributedStringEndEditing(mas);
|
|
|
|
|
2017-02-13 01:10:39 -06:00
|
|
|
*backgroundBlocks = fep.backgroundBlocks;
|
2017-02-12 00:05:27 -06:00
|
|
|
return mas;
|
|
|
|
}
|