From 51f0e3dbe5f2720510072fbcd984b0362b81735f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 3 Nov 2017 18:41:13 -0400 Subject: [PATCH] Folded all CFNumber accesses into [self prepare] for error checking. This shouldn't make things *significantly* slower... --- doc/export/fontmatch.m | 48 +++++++++++++++++------------------------- doc/export/fontstyle.h | 2 -- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/doc/export/fontmatch.m b/doc/export/fontmatch.m index 74cbe2e1..ddb7b906 100644 --- a/doc/export/fontmatch.m +++ b/doc/export/fontmatch.m @@ -78,6 +78,7 @@ - (BOOL)prepare { CFNumberRef num; + Boolean success; self->traits = NULL; self->symbolic = 0; @@ -87,12 +88,10 @@ self->styleName = NULL; self->didVariations = NO; self->variations = NULL; - self->didRegistrationScope = NO; self->hasRegistrationScope = NO; self->registrationScope = 0; self->didPostScriptName = NO; self->postScriptName = NULL; - self->didFontFormat = NO; self->fontFormat = 0; self->didPreferredSubFamilyName = NO; self->preferredSubFamilyName = NULL; @@ -129,6 +128,24 @@ if (CFNumberGetValue(num, kCFNumberDoubleType, &(self->width)) == false) return NO; + // do these now for the sake of error checking + num = (CFNumberRef) CTFontDescriptorCopyAttribute(desc, kCTFontRegistrationScopeAttribute); + self->hasRegistrationScope = num != NULL; + if (self->hasRegistrationScope) { + success = CFNumberGetValue(num, kCFNumberSInt32Type, &(self->registrationScope)); + CFRelease(num); + if (success == false) + return NO; + } + + num = (CFNumberRef) CTFontDescriptorCopyAttribute(self->desc, kCTFontFormatAttribute); + if (num == NULL) + return NO; + success = CFNumberGetValue(num, kCFNumberSInt32Type, &(self->fontFormat)); + CFRelease(num); + if (success == false) + return NO; + return YES; } @@ -176,25 +193,11 @@ - (BOOL)hasRegistrationScope { - if (!self->didRegistrationScope) { - CFNumberRef num; - - self->didRegistrationScope = YES; - num = (CFNumberRef) CTFontDescriptorCopyAttribute(desc, kCTFontRegistrationScopeAttribute); - self->hasRegistrationScope = num != NULL; - if (self->hasRegistrationScope) { - if (CFNumberGetValue(num, kCFNumberSInt32Type, &(self->registrationScope)) == false) { - // TODO - } - CFRelease(num); - } - } return self->hasRegistrationScope; } - (CTFontManagerScope)registrationScope { - [self hasRegistrationScope]; return self->registrationScope; } @@ -216,19 +219,6 @@ - (CTFontFormat)fontFormat { - if (!self->didFontFormat) { - CFNumberRef num; - - self->didFontFormat = YES; - num = (CFNumberRef) CTFontDescriptorCopyAttribute(self->desc, kCTFontFormatAttribute); - if (num == NULL) { - // TODO - } - if (CFNumberGetValue(num, kCFNumberSInt32Type, &(self->fontFormat)) == false) { - // TODO - } - CFRelease(num); - } return self->fontFormat; } diff --git a/doc/export/fontstyle.h b/doc/export/fontstyle.h index c94ef3fd..636e0992 100644 --- a/doc/export/fontstyle.h +++ b/doc/export/fontstyle.h @@ -12,12 +12,10 @@ CFStringRef styleName; BOOL didVariations; CFDictionaryRef variations; - BOOL didRegistrationScope; BOOL hasRegistrationScope; CTFontManagerScope registrationScope; BOOL didPostScriptName; CFStringRef postScriptName; - BOOL didFontFormat; CTFontFormat fontFormat; BOOL didPreferredSubFamilyName; CFStringRef preferredSubFamilyName;