diff --git a/darwin/CMakeLists.txt b/darwin/CMakeLists.txt index ef1d30b1..253b621c 100644 --- a/darwin/CMakeLists.txt +++ b/darwin/CMakeLists.txt @@ -21,6 +21,8 @@ list(APPEND _LIBUI_SOURCES darwin/entry.m darwin/fontbutton.m darwin/fontmatch.m + darwin/fonttraits.m + darwin/fontvariation.m darwin/form.m darwin/future.m darwin/graphemes.m diff --git a/doc/export/fontmatch.m b/darwin/fontmatch.m similarity index 94% rename from doc/export/fontmatch.m rename to darwin/fontmatch.m index 68e9d72b..6cec26b6 100644 --- a/doc/export/fontmatch.m +++ b/darwin/fontmatch.m @@ -38,7 +38,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey; if (self) { self->font = f; CFRetain(self->font); - self->desc = CTFontCopyDescriptor(self->font); + self->desc = CTFontCopyFontDescriptor(self->font); if (![self prepare]) { [self release]; return nil; @@ -72,7 +72,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey; REL(self->subFamilyName); REL(self->preferredSubFamilyName); REL(self->postScriptName); - REL(self->variations); + REL(self->variation); REL(self->styleName); REL(self->traits); CFRelease(self->desc); @@ -91,8 +91,8 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey; self->width = 0; self->didStyleName = NO; self->styleName = NULL; - self->didVariations = NO; - self->variations = NULL; + self->didVariation = NO; + self->variation = NULL; self->hasRegistrationScope = NO; self->registrationScope = 0; self->didPostScriptName = NO; @@ -186,14 +186,14 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey; return self->styleName; } -- (CFDictionaryRef)variations +- (CFDictionaryRef)variation { - if (!self->didVariations) { - self->didVariations = YES; - self->variations = (CFDictionaryRef) CTFontDescriptorCopyAttribute(self->desc, kCTFontVariationsAttribute); + if (!self->didVariation) { + self->didVariation = YES; + 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. } - return self->variations; + return self->variation; } - (BOOL)hasRegistrationScope @@ -235,7 +235,7 @@ extern const CFStringRef kCTFontPreferredFamilyNameKey; } #define FONTNAME(sel, did, var, key) \ - - (CFString)sel \ + - (CFStringRef)sel \ { \ if (!did) { \ did = YES; \ @@ -298,7 +298,7 @@ static const double *italicClosenesses[] = { // 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 -static uiDrawTextFontItalic guessItalicOblique(fontStyleData *d) +static uiDrawTextItalic guessItalicOblique(fontStyleData *d) { CFStringRef styleName; BOOL isOblique; @@ -313,8 +313,8 @@ static uiDrawTextFontItalic guessItalicOblique(fontStyleData *d) isOblique = YES; } if (isOblique) - return uiDrawFontItalicOblique; - return uiDrawFontItalicItalic; + return uiDrawTextItalicOblique; + return uiDrawTextItalicItalic; } // 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; } - current = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matches, 0); + current = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matching, 0); d = [[fontStyleData alloc] initWithDescriptor:current]; axisDict = nil; - if ([d variations] != nil) - axisDict = mkAxisDict(d, [d table:kCTFontTableAvar]); + if ([d variation] != NULL) + axisDict = mkVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]); closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]"); 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 // TODO merge this loop with the previous loop? for (i = 0; i < n; i++) { - double weight, stretch; + double weight, italic, stretch; weight = (double) (closeness[i].weight); weight *= weight; @@ -443,7 +443,7 @@ CTFontDescriptorRef fontdescToCTFontDescriptor(uiDrawFontDescriptor *fd) basedesc = CTFontDescriptorCreateWithAttributes(attrs); 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 @@ -483,10 +483,10 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily); CFRelease(cffamily); - d = [[fontStyleData alloc] initWithDescriptor:current]; + d = [[fontStyleData alloc] initWithDescriptor:ctdesc]; axisDict = nil; - if ([d variations] != nil) - axisDict = mkAxisDict(d, [d table:kCTFontTableAvar]); + if ([d variation] != NULL) + axisDict = mkVariationAxisDict([d variationAxes], [d table:kCTFontTableAvar]); fillDescStyleFields(d, axisDict, uidesc); if (axisDict != nil) [axisDict release]; diff --git a/doc/export/fontstyle.h b/darwin/fontstyle.h similarity index 95% rename from doc/export/fontstyle.h rename to darwin/fontstyle.h index a1bc66f7..8a27380c 100644 --- a/doc/export/fontstyle.h +++ b/darwin/fontstyle.h @@ -10,8 +10,8 @@ double width; BOOL didStyleName; CFStringRef styleName; - BOOL didVariations; - CFDictionaryRef variations; + BOOL didVariation; + CFDictionaryRef variation; BOOL hasRegistrationScope; CTFontManagerScope registrationScope; BOOL didPostScriptName; @@ -38,7 +38,7 @@ - (double)weight; - (double)width; - (CFStringRef)styleName; -- (CFDictionaryRef)variations; +- (CFDictionaryRef)variation; - (BOOL)hasRegistrationScope; - (CTFontManagerScope)registrationScope; - (CFStringRef)postScriptName; diff --git a/doc/export/fonttraits.m b/darwin/fonttraits.m similarity index 94% rename from doc/export/fonttraits.m rename to darwin/fonttraits.m index 6732b894..feb37b8b 100644 --- a/doc/export/fonttraits.m +++ b/darwin/fonttraits.m @@ -31,7 +31,7 @@ static BOOL fontRegistered(fontStyleData *d) // 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. // We'll just treat them as identical to 1 and 9, respectively. -static const uiDrawFontStretch os2WidthsToStretches[] = { +static const uiDrawTextStretch os2WidthsToStretches[] = { uiDrawTextStretchUltraCondensed, uiDrawTextStretchUltraCondensed, uiDrawTextStretchExtraCondensed, @@ -59,7 +59,7 @@ static void trySecondaryOS2Values(fontStyleData *d, uiDrawFontDescriptor *out, B CFDataRef os2; uint16_t usWeightClass, usWidthClass; CFStringRef psname; - CFStringRef *ex; + const CFStringRef *ex; *hasWeight = NO; *hasWidth = NO; @@ -82,7 +82,7 @@ static void trySecondaryOS2Values(fontStyleData *d, uiDrawFontDescriptor *out, B usWeightClass |= (uint16_t) (b[5]); if (usWeightClass <= 1000) { if (usWeightClass < 11) - usWeigthClass *= 100; + usWeightClass *= 100; *hasWeight = YES; } @@ -127,9 +127,6 @@ static BOOL testTTFOTFSubfamilyName(CFStringRef name, CFStringRef want) static BOOL testTTFOTFSubfamilyNames(fontStyleData *d, CFStringRef want) { - CGFontRef font; - CFString *key; - switch ([d fontFormat]) { case kCTFontFormatOpenTypePostScript: case kCTFontFormatOpenTypeTrueType: @@ -151,15 +148,15 @@ static BOOL testTTFOTFSubfamilyNames(fontStyleData *d, CFStringRef want) } // 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 -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) diff --git a/doc/export/fontvariation.m b/darwin/fontvariation.m similarity index 89% rename from doc/export/fontvariation.m rename to darwin/fontvariation.m index 0e4c993b..3c6e0005 100644 --- a/doc/export/fontvariation.m +++ b/darwin/fontvariation.m @@ -88,7 +88,7 @@ static double fixed214ToDouble(fixed214 f) base = 1; break; case 2: - base = -2: + base = -2; break; case 3: base = -1; @@ -105,14 +105,14 @@ static fixed1616 fixed214ToFixed1616(fixed214 f) t = (int32_t) ((int16_t) f); t <<= 2; x = (uint32_t) t; - return (float1616) (x - 0x00000002); + return (fixed1616) (x - 0x00000002); } -static const fixed1616Negative1 = 0xFFFF0000; -static const fixed1616Zero = 0x00000000; -static const fixed1616Positive1 = 0x00010000; +static const fixed1616 fixed1616Negative1 = 0xFFFF0000; +static const fixed1616 fixed1616Zero = 0x00000000; +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) val = min; @@ -133,8 +133,8 @@ static fixed214 normalizedTo214(fixed1616 val, const fixed1616 *avarMappings, si val = fixed1616Positive1; if (avarCount != 0) { size_t start, end; - float1616 startFrom, endFrom; - float1616 startTo, endTo; + fixed1616 startFrom, endFrom; + fixed1616 startTo, endTo; for (end = 0; end < avarCount; end += 2) { endFrom = avarMappings[end]; @@ -175,6 +175,7 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n) nEntries = nextuint16be(); *n = nEntries * 2; entries = (fixed1616 *) uiAlloc(*n * sizeof (fixed1616), "fixed1616[]"); + p = entries; for (i = 0; i < *n; i++) { *p++ = fixed214ToFixed1616((fixed214) nextuint16be()); off += 2; @@ -182,13 +183,13 @@ static fixed1616 *avarExtract(CFDataRef table, CFIndex index, size_t *n) return entries; } -staatic BOOL extractAxisDictValue(CFDictionaryRef dict, CFStringRef key, fixed1616 *out) +static BOOL extractAxisDictValue(CFDictionaryRef dict, CFStringRef key, fixed1616 *out) { CFNumberRef num; double v; num = (CFNumberRef) CFDictionaryGetValue(dict, key); - if (CFNumberGetValue(num, kCFNumberTypeDouble, &v) == false) + if (CFNumberGetValue(num, kCFNumberDoubleType, &v) == false) return NO; *out = doubleToFixed1616(v); return YES; @@ -244,7 +245,7 @@ fail: fixed214 n2; 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); return fixed214ToDouble(n2); } @@ -257,22 +258,22 @@ NSDictionary *mkVariationAxisDict(CFArrayRef axes, CFDataRef avarTable) CFIndex i, n; NSMutableDictionary *out; - n = CFArrayGetLength(axes); + n = CFArrayGetCount(axes); out = [NSMutableDictionary new]; for (i = 0; i < n; i++) { CFNumberRef key; axis = (CFDictionaryRef) CFArrayGetValueAtIndex(axes, i); 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)]; } - if (table != NULL) - CFRelease(table); + if (avarTable != NULL) + CFRelease(avarTable); 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) { @@ -285,7 +286,7 @@ static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key, num = (CFNumberRef) CFDictionaryGetValue(var, (CFNumberRef) key); if (num == nil) return NO; - if (CFNumberGetValue(num, kCFNumberTypeDouble, out) == false) { + if (CFNumberGetValue(num, kCFNumberDoubleType, out) == false) { // TODO return NO; } @@ -295,12 +296,13 @@ static BOOL tryAxis(NSDictionary *axisDict, CFDictionaryRef var, NSNumber *key, void processFontVariation(fontStyleData *d, NSDictionary *axisDict, uiDrawFontDescriptor *out) { + CFDictionaryRef var; double v; out->Weight = uiDrawTextWeightNormal; out->Stretch = uiDrawTextStretchNormal; - var = [d variations]; + var = [d variation]; if (tryAxis(axisDict, var, fvarAxisKey(fvarWeight), &v)) { // v is now a value between -1 and 1 scaled linearly between discrete points