Reintegrated everything and fixed more compiler errors. Now we have to deal with linker errors, and then with testing to see if everything worked...

This commit is contained in:
Pietro Gagliardi 2017-11-03 20:59:27 -04:00
parent 2276a136cb
commit e0b584082d
5 changed files with 53 additions and 52 deletions

View File

@ -21,6 +21,8 @@ list(APPEND _LIBUI_SOURCES
darwin/entry.m darwin/entry.m
darwin/fontbutton.m darwin/fontbutton.m
darwin/fontmatch.m darwin/fontmatch.m
darwin/fonttraits.m
darwin/fontvariation.m
darwin/form.m darwin/form.m
darwin/future.m darwin/future.m
darwin/graphemes.m darwin/graphemes.m

View File

@ -38,7 +38,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey;
if (self) { if (self) {
self->font = f; self->font = f;
CFRetain(self->font); CFRetain(self->font);
self->desc = CTFontCopyDescriptor(self->font); self->desc = CTFontCopyFontDescriptor(self->font);
if (![self prepare]) { if (![self prepare]) {
[self release]; [self release];
return nil; return nil;
@ -72,7 +72,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey;
REL(self->subFamilyName); REL(self->subFamilyName);
REL(self->preferredSubFamilyName); REL(self->preferredSubFamilyName);
REL(self->postScriptName); REL(self->postScriptName);
REL(self->variations); REL(self->variation);
REL(self->styleName); REL(self->styleName);
REL(self->traits); REL(self->traits);
CFRelease(self->desc); CFRelease(self->desc);
@ -91,8 +91,8 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey;
self->width = 0; self->width = 0;
self->didStyleName = NO; self->didStyleName = NO;
self->styleName = NULL; self->styleName = NULL;
self->didVariations = NO; self->didVariation = NO;
self->variations = NULL; self->variation = NULL;
self->hasRegistrationScope = NO; self->hasRegistrationScope = NO;
self->registrationScope = 0; self->registrationScope = 0;
self->didPostScriptName = NO; self->didPostScriptName = NO;
@ -186,14 +186,14 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey;
return self->styleName; return self->styleName;
} }
- (CFDictionaryRef)variations - (CFDictionaryRef)variation
{ {
if (!self->didVariations) { if (!self->didVariation) {
self->didVariations = YES; self->didVariation = YES;
self->variations = (CFDictionaryRef) CTFontDescriptorCopyAttribute(self->desc, kCTFontVariationsAttribute); self->variation = (CFDictionaryRef) CTFontDescriptorCopyAttribute(self->desc, kCTFontVariationAttribute);
// This being NULL is used to determine whether a font uses variations at all, so we don't need to worry now. // This being NULL is used to determine whether a font uses variations at all, so we don't need to worry now.
} }
return self->variations; return self->variation;
} }
- (BOOL)hasRegistrationScope - (BOOL)hasRegistrationScope
@ -235,7 +235,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey;
} }
#define FONTNAME(sel, did, var, key) \ #define FONTNAME(sel, did, var, key) \
- (CFString)sel \ - (CFStringRef)sel \
{ \ { \
if (!did) { \ if (!did) { \
did = YES; \ did = YES; \
@ -298,7 +298,7 @@ static const double *italicClosenesses[] = {
// Core Text doesn't seem to differentiate between Italic and Oblique. // Core Text doesn't seem to differentiate between Italic and Oblique.
// Pango's Core Text code just does a g_strrstr() (backwards case-sensitive search) for "Oblique" in the font's style name (see https://git.gnome.org/browse/pango/tree/pango/pangocoretext-fontmap.c); let's do that too I guess // Pango's Core Text code just does a g_strrstr() (backwards case-sensitive search) for "Oblique" in the font's style name (see https://git.gnome.org/browse/pango/tree/pango/pangocoretext-fontmap.c); let's do that too I guess
static uiDrawTextFontItalic guessItalicOblique(fontStyleData *d) static uiDrawTextItalic guessItalicOblique(fontStyleData *d)
{ {
CFStringRef styleName; CFStringRef styleName;
BOOL isOblique; BOOL isOblique;
@ -313,8 +313,8 @@ static uiDrawTextFontItalic guessItalicOblique(fontStyleData *d)
isOblique = YES; isOblique = YES;
} }
if (isOblique) if (isOblique)
return uiDrawFontItalicOblique; return uiDrawTextItalicOblique;
return uiDrawFontItalicItalic; return uiDrawTextItalicItalic;
} }
// Italics are hard because Core Text does NOT distinguish between italic and oblique. // Italics are hard because Core Text does NOT distinguish between italic and oblique.
@ -359,11 +359,11 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiDrawFontDes
return against; return against;
} }
current = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matches, 0); current = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matching, 0);
d = [[fontStyleData alloc] initWithDescriptor:current]; d = [[fontStyleData alloc] initWithDescriptor:current];
axisDict = nil; axisDict = nil;
if ([d variations] != nil) if ([d variation] != NULL)
axisDict = mkAxisDict(d, [d table:kCTFontTableAvar]); axisDict = mkVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]);
closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]"); closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]");
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@ -384,7 +384,7 @@ static CTFontDescriptorRef matchStyle(CTFontDescriptorRef against, uiDrawFontDes
// now figure out the 3-space difference between the three and sort by that // now figure out the 3-space difference between the three and sort by that
// TODO merge this loop with the previous loop? // TODO merge this loop with the previous loop?
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
double weight, stretch; double weight, italic, stretch;
weight = (double) (closeness[i].weight); weight = (double) (closeness[i].weight);
weight *= weight; weight *= weight;
@ -443,7 +443,7 @@ CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd)
basedesc = CTFontDescriptorCreateWithAttributes(attrs); basedesc = CTFontDescriptorCreateWithAttributes(attrs);
CFRelease(attrs); // TODO correct? CFRelease(attrs); // TODO correct?
return matchTraits(basedesc, fd); return matchStyle(basedesc, fd);
} }
// fortunately features that aren't supported are simply ignored, so we can copy them all in // fortunately features that aren't supported are simply ignored, so we can copy them all in
@ -483,10 +483,10 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript
uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily); uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily);
CFRelease(cffamily); CFRelease(cffamily);
d = [[fontStyleData alloc] initWithDescriptor:current]; d = [[fontStyleData alloc] initWithDescriptor:ctdesc];
axisDict = nil; axisDict = nil;
if ([d variations] != nil) if ([d variation] != NULL)
axisDict = mkAxisDict(d, [d table:kCTFontTableAvar]); axisDict = mkVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]);
fillDescStyleFields(d, axisDict, uidesc); fillDescStyleFields(d, axisDict, uidesc);
if (axisDict != nil) if (axisDict != nil)
[axisDict release]; [axisDict release];

View File

@ -10,8 +10,8 @@
double width; double width;
BOOL didStyleName; BOOL didStyleName;
CFStringRef styleName; CFStringRef styleName;
BOOL didVariations; BOOL didVariation;
CFDictionaryRef variations; CFDictionaryRef variation;
BOOL hasRegistrationScope; BOOL hasRegistrationScope;
CTFontManagerScope registrationScope; CTFontManagerScope registrationScope;
BOOL didPostScriptName; BOOL didPostScriptName;
@ -38,7 +38,7 @@
- (double)weight; - (double)weight;
- (double)width; - (double)width;
- (CFStringRef)styleName; - (CFStringRef)styleName;
- (CFDictionaryRef)variations; - (CFDictionaryRef)variation;
- (BOOL)hasRegistrationScope; - (BOOL)hasRegistrationScope;
- (CTFontManagerScope)registrationScope; - (CTFontManagerScope)registrationScope;
- (CFStringRef)postScriptName; - (CFStringRef)postScriptName;

View File

@ -31,7 +31,7 @@ static BOOL fontRegistered(fontStyleData *d)
// Core Text does (usWidthClass / 10) - 0.5 here. // Core Text does (usWidthClass / 10) - 0.5 here.
// This roughly maps to our values with increments of 0.1, except for the fact 0 and 10 are allowed by Core Text, despite being banned by TrueType and OpenType themselves. // This roughly maps to our values with increments of 0.1, except for the fact 0 and 10 are allowed by Core Text, despite being banned by TrueType and OpenType themselves.
// We'll just treat them as identical to 1 and 9, respectively. // We'll just treat them as identical to 1 and 9, respectively.
static const uiDrawFontStretch os2WidthsToStretches[] = { static const uiDrawTextStretch os2WidthsToStretches[] = {
uiDrawTextStretchUltraCondensed, uiDrawTextStretchUltraCondensed,
uiDrawTextStretchUltraCondensed, uiDrawTextStretchUltraCondensed,
uiDrawTextStretchExtraCondensed, uiDrawTextStretchExtraCondensed,
@ -59,7 +59,7 @@ static void trySecondaryOS2Values(fontStyleData *d, uiDrawFontDescriptor *out, B
CFDataRef os2; CFDataRef os2;
uint16_t usWeightClass, usWidthClass; uint16_t usWeightClass, usWidthClass;
CFStringRef psname; CFStringRef psname;
CFStringRef *ex; const CFStringRef *ex;
*hasWeight = NO; *hasWeight = NO;
*hasWidth = NO; *hasWidth = NO;
@ -82,7 +82,7 @@ static void trySecondaryOS2Values(fontStyleData *d, uiDrawFontDescriptor *out, B
usWeightClass |= (uint16_t) (b[5]); usWeightClass |= (uint16_t) (b[5]);
if (usWeightClass <= 1000) { if (usWeightClass <= 1000) {
if (usWeightClass < 11) if (usWeightClass < 11)
usWeigthClass *= 100; usWeightClass *= 100;
*hasWeight = YES; *hasWeight = YES;
} }
@ -127,9 +127,6 @@ static BOOL testTTFOTFSubfamilyName(CFStringRef name, CFStringRef want)
static BOOL testTTFOTFSubfamilyNames(fontStyleData *d, CFStringRef want) static BOOL testTTFOTFSubfamilyNames(fontStyleData *d, CFStringRef want)
{ {
CGFontRef font;
CFString *key;
switch ([d fontFormat]) { switch ([d fontFormat]) {
case kCTFontFormatOpenTypePostScript: case kCTFontFormatOpenTypePostScript:
case kCTFontFormatOpenTypeTrueType: case kCTFontFormatOpenTypeTrueType:
@ -151,15 +148,15 @@ static BOOL testTTFOTFSubfamilyNames(fontStyleData *d, CFStringRef want)
} }
// work around a bug in libFontRegistry.dylib // work around a bug in libFontRegistry.dylib
static BOOL shouldReallyBeThin(CTFontDescriptorRef desc) static BOOL shouldReallyBeThin(fontStyleData *d)
{ {
return testTTFOTFSubfamilyNames(desc, CFSTR("W1")); return testTTFOTFSubfamilyNames(d, CFSTR("W1"));
} }
// work around a bug in libFontRegistry.dylib // work around a bug in libFontRegistry.dylib
static BOOL shouldReallyBeSemiCondensed(CTFontDescriptorRef desc) static BOOL shouldReallyBeSemiCondensed(fontStyleData *d)
{ {
return testTTFOTFSubfamilyNames(desc, CFSTR("Semi Condensed")); return testTTFOTFSubfamilyNames(d, CFSTR("Semi Condensed"));
} }
void processFontTraits(fontStyleData *d, uiDrawFontDescriptor *out) void processFontTraits(fontStyleData *d, uiDrawFontDescriptor *out)

View File

@ -88,7 +88,7 @@ static double fixed214ToDouble(fixed214 f)
base = 1; base = 1;
break; break;
case 2: case 2:
base = -2: base = -2;
break; break;
case 3: case 3:
base = -1; base = -1;
@ -105,14 +105,14 @@ static fixed1616 fixed214ToFixed1616(fixed214 f)
t = (int32_t) ((int16_t) f); t = (int32_t) ((int16_t) f);
t <<= 2; t <<= 2;
x = (uint32_t) t; x = (uint32_t) t;
return (float1616) (x - 0x00000002); return (fixed1616) (x - 0x00000002);
} }
static const fixed1616Negative1 = 0xFFFF0000; static const fixed1616 fixed1616Negative1 = 0xFFFF0000;
static const fixed1616Zero = 0x00000000; static const fixed1616 fixed1616Zero = 0x00000000;
static const fixed1616Positive1 = 0x00010000; static const fixed1616 fixed1616Positive1 = 0x00010000;
static fixed1616 normalize1616(fixed1616 val, fixed1616 min, fixed1616 max, fixed1616 def) static fixed1616 fixed1616Normalize(fixed1616 val, fixed1616 min, fixed1616 max, fixed1616 def)
{ {
if (val < min) if (val < min)
val = min; val = min;
@ -133,8 +133,8 @@ static fixed214 normalizedTo214(fixed1616 val, const fixed1616 *avarMappings, si
val = fixed1616Positive1; val = fixed1616Positive1;
if (avarCount != 0) { if (avarCount != 0) {
size_t start, end; size_t start, end;
float1616 startFrom, endFrom; fixed1616 startFrom, endFrom;
float1616 startTo, endTo; fixed1616 startTo, endTo;
for (end = 0; end < avarCount; end += 2) { for (end = 0; end < avarCount; end += 2) {
endFrom = avarMappings[end]; endFrom = avarMappings[end];
@ -175,6 +175,7 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n)
nEntries = nextuint16be(); nEntries = nextuint16be();
*n = nEntries * 2; *n = nEntries * 2;
entries = (fixed1616 *) uiAlloc(*n * sizeof (fixed1616), "fixed1616[]"); entries = (fixed1616 *) uiAlloc(*n * sizeof (fixed1616), "fixed1616[]");
p = entries;
for (i = 0; i < *n; i++) { for (i = 0; i < *n; i++) {
*p++ = fixed214ToFixed1616((fixed214) nextuint16be()); *p++ = fixed214ToFixed1616((fixed214) nextuint16be());
off += 2; off += 2;
@ -182,13 +183,13 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n)
return entries; return entries;
} }
staatic BOOL extractAxisDictValue(CFDictionaryRef dict, CFStringRef key, fixed1616 *out) static BOOL extractAxisDictValue(CFDictionaryRef dict, CFStringRef key, fixed1616 *out)
{ {
CFNumberRef num; CFNumberRef num;
double v; double v;
num = (CFNumberRef) CFDictionaryGetValue(dict, key); num = (CFNumberRef) CFDictionaryGetValue(dict, key);
if (CFNumberGetValue(num, kCFNumberTypeDouble, &v) == false) if (CFNumberGetValue(num, kCFNumberDoubleType, &v) == false)
return NO; return NO;
*out = doubleToFixed1616(v); *out = doubleToFixed1616(v);
return YES; return YES;
@ -244,7 +245,7 @@ fail:
fixed214 n2; fixed214 n2;
n = doubleToFixed1616(d); n = doubleToFixed1616(d);
n = fixed16161Normalize(n, self->min, self->max, self->def); n = fixed1616Normalize(n, self->min, self->max, self->def);
n2 = normalizedTo214(n, self->avarMappings, self->avarCount); n2 = normalizedTo214(n, self->avarMappings, self->avarCount);
return fixed214ToDouble(n2); return fixed214ToDouble(n2);
} }
@ -257,22 +258,22 @@ NSDictionary *mkVariationAxisDict(CFArrayRef axes, CFDataRef avarTable)
CFIndex i, n; CFIndex i, n;
NSMutableDictionary *out; NSMutableDictionary *out;
n = CFArrayGetLength(axes); n = CFArrayGetCount(axes);
out = [NSMutableDictionary new]; out = [NSMutableDictionary new];
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
CFNumberRef key; CFNumberRef key;
axis = (CFDictionaryRef) CFArrayGetValueAtIndex(axes, i); axis = (CFDictionaryRef) CFArrayGetValueAtIndex(axes, i);
key = (CFNumberRef) CFDictionaryGetValue(axis, kCTFontVariationAxisIdentifierKey); key = (CFNumberRef) CFDictionaryGetValue(axis, kCTFontVariationAxisIdentifierKey);
[out setObject:[[fvarAxis alloc] initWithIndex:i dict:axis avarTable:table] [out setObject:[[fvarAxis alloc] initWithIndex:i dict:axis avarTable:avarTable]
forKey:((NSNumber *) key)]; forKey:((NSNumber *) key)];
} }
if (table != NULL) if (avarTable != NULL)
CFRelease(table); CFRelease(avarTable);
return out; return out;
} }
#define fvarAxisKey(n) [NSNumber numberWithUnsignedInteger:k] #define fvarAxisKey(n) [NSNumber numberWithUnsignedInteger:n]
static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key, double *out) static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key, double *out)
{ {
@ -285,7 +286,7 @@ static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key,
num = (CFNumberRef) CFDictionaryGetValue(var, (CFNumberRef) key); num = (CFNumberRef) CFDictionaryGetValue(var, (CFNumberRef) key);
if (num == nil) if (num == nil)
return NO; return NO;
if (CFNumberGetValue(num, kCFNumberTypeDouble, out) == false) { if (CFNumberGetValue(num, kCFNumberDoubleType, out) == false) {
// TODO // TODO
return NO; return NO;
} }
@ -295,12 +296,13 @@ static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key,
void processFontVariation(fontStyleData *d, NSDictionary *axisDict, uiDrawFontDescriptor *out) void processFontVariation(fontStyleData *d, NSDictionary *axisDict, uiDrawFontDescriptor *out)
{ {
CFDictionaryRef var;
double v; double v;
out->Weight = uiDrawTextWeightNormal; out->Weight = uiDrawTextWeightNormal;
out->Stretch = uiDrawTextStretchNormal; out->Stretch = uiDrawTextStretchNormal;
var = [d variations]; var = [d variation];
if (tryAxis(axisDict, var, fvarAxisKey(fvarWeight), &v)) { if (tryAxis(axisDict, var, fvarAxisKey(fvarWeight), &v)) {
// v is now a value between -1 and 1 scaled linearly between discrete points // v is now a value between -1 and 1 scaled linearly between discrete points