Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 810 lines (632 sloc) 19.07 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
//
// DTCoreTextFontDescriptor.m
// DTCoreText
//
// Created by Oliver Drobnik on 1/26/11.
// Copyright 2011 Drobnik.com. All rights reserved.
//

#import "DTCoreTextFontDescriptor.h"
#import "DTVersion.h"

static NSCache *_fontCache = nil;
static NSMutableDictionary *_fontOverrides = nil;
static dispatch_queue_t _fontQueue;

// adds "STHeitiSC-Light" font for cascading fix on iOS 5
static BOOL _needsChineseFontCascadeFix = NO;

@implementation DTCoreTextFontDescriptor
{
NSString *_fontFamily;
NSString *_fontName;

CGFloat _pointSize;

CTFontSymbolicTraits _stylisticTraits;
CTFontStylisticClass _stylisticClass;
    
BOOL _smallCapsFeature;
}

+ (void)initialize
{
// only this class (and not subclasses) do this
if (self == [DTCoreTextFontDescriptor class])
{
_fontCache = [[NSCache alloc] init];

_fontQueue = dispatch_queue_create("DTCoreTextFontDescriptor", 0);

// init/load of overrides
_fontOverrides = [[NSMutableDictionary alloc] init];

NSString *path = [[NSBundle mainBundle] pathForResource:@"DTCoreTextFontOverrides" ofType:@"plist"];
NSArray *fileArray = [NSArray arrayWithContentsOfFile:path];

for (NSDictionary *oneOverride in fileArray)
{
NSString *fontFamily = [oneOverride objectForKey:@"FontFamily"];
NSString *overrideFontName = [oneOverride objectForKey:@"OverrideFontName"];
BOOL bold = [[oneOverride objectForKey:@"Bold"] boolValue];
BOOL italic = [[oneOverride objectForKey:@"Italic"] boolValue];
BOOL smallcaps = [[oneOverride objectForKey:@"SmallCaps"] boolValue];

if (smallcaps)
{
[DTCoreTextFontDescriptor setSmallCapsFontName:overrideFontName forFontFamily:fontFamily bold:bold italic:italic];
}
else
{
[DTCoreTextFontDescriptor setOverrideFontName:overrideFontName forFontFamily:fontFamily bold:bold italic:italic];
}
}
}
#if TARGET_OS_IPHONE
// workaround for iOS 5.x bug: global font cascade table has incorrect bold font for Chinese characters in Chinese locale


DTVersion *version = [DTVersion osVersion];

// seems to be fixed in iOS 6
if (version.major<6)
{
_needsChineseFontCascadeFix = YES;
}
#endif
}

+ (void)setSmallCapsFontName:(NSString *)fontName forFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
{
NSString *key = [NSString stringWithFormat:@"%@-%d-%d-smallcaps", fontFamily, bold, italic];
[_fontOverrides setObject:fontName forKey:key];
}

+ (NSString *)smallCapsFontNameforFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
{
NSString *key = [NSString stringWithFormat:@"%@-%d-%d-smallcaps", fontFamily, bold, italic];
return [_fontOverrides objectForKey:key];
}

+ (void)setOverrideFontName:(NSString *)fontName forFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
{
NSString *key = [NSString stringWithFormat:@"%@-%d-%d-override", fontFamily, bold, italic];
[_fontOverrides setObject:fontName forKey:key];
}

+ (NSString *)overrideFontNameforFontFamily:(NSString *)fontFamily bold:(BOOL)bold italic:(BOOL)italic
{
NSString *key = [NSString stringWithFormat:@"%@-%d-%d-override", fontFamily, bold, italic];
return [_fontOverrides objectForKey:key];
}

#pragma mark Initializing

+ (DTCoreTextFontDescriptor *)fontDescriptorWithFontAttributes:(NSDictionary *)attributes
{
return [[DTCoreTextFontDescriptor alloc] initWithFontAttributes:attributes];
}

+ (DTCoreTextFontDescriptor *)fontDescriptorForCTFont:(CTFontRef)ctFont
{
return [[DTCoreTextFontDescriptor alloc] initWithCTFont:ctFont];
}

- (id)initWithFontAttributes:(NSDictionary *)attributes
{
self = [super init];
if (self)
{
[self setFontAttributes:attributes];
}

return self;
}

- (id)initWithCTFontDescriptor:(CTFontDescriptorRef)ctFontDescriptor
{
self = [super init];
if (self)
{
CFDictionaryRef dict = CTFontDescriptorCopyAttributes(ctFontDescriptor);

CFDictionaryRef traitsDict = CTFontDescriptorCopyAttribute(ctFontDescriptor, kCTFontTraitsAttribute);
CTFontSymbolicTraits traitsValue = [[(__bridge NSDictionary *)traitsDict objectForKey:(id)kCTFontSymbolicTrait] unsignedIntValue];
CFRelease(traitsDict);

self.symbolicTraits = traitsValue;

[self setFontAttributes:CFBridgingRelease(dict)];

// also get family name

CFStringRef familyName = CTFontDescriptorCopyAttribute(ctFontDescriptor, kCTFontFamilyNameAttribute);
self.fontFamily = CFBridgingRelease(familyName);
}

return self;
}

- (id)initWithCTFont:(CTFontRef)ctFont
{
self = [super init];
if (self)
{
CTFontDescriptorRef fd = CTFontCopyFontDescriptor(ctFont);
CFDictionaryRef dict = CTFontDescriptorCopyAttributes(fd);

CFDictionaryRef traitsDict = CTFontDescriptorCopyAttribute(fd, kCTFontTraitsAttribute);
CTFontSymbolicTraits traitsValue = [[(__bridge NSDictionary *)traitsDict objectForKey:(id)kCTFontSymbolicTrait] unsignedIntValue];
CFRelease(traitsDict);
CFRelease(fd);

self.symbolicTraits = traitsValue;

[self setFontAttributes:CFBridgingRelease(dict)];
//CFRelease(dict);

// also get the family while we're at it
CFStringRef cfStr = CTFontCopyFamilyName(ctFont);

if (cfStr)
{
self.fontFamily = CFBridgingRelease(cfStr);
}
}

return self;
}

- (NSString *)description
{
NSMutableString *string = [NSMutableString string];

[string appendFormat:@"<%@", [self class]];


if (self.fontName)
{
[string appendFormat:@" name=\'%@\'", self.fontName];
}

if (_fontFamily)
{
[string appendFormat:@" family=\'%@\'", _fontFamily];
}

[string appendFormat:@" size:%.0f", _pointSize];

NSMutableArray *tmpTraits = [NSMutableArray array];

if (_stylisticTraits & kCTFontBoldTrait)
{
[tmpTraits addObject:@" bold"];
}

if (_stylisticTraits & kCTFontItalicTrait)
{
[tmpTraits addObject:@" italic"];
}

if (_stylisticTraits & kCTFontMonoSpaceTrait)
{
[tmpTraits addObject:@" monospace"];
}

if (_stylisticTraits & kCTFontCondensedTrait)
{
[tmpTraits addObject:@" condensed"];
}

if (_stylisticTraits & kCTFontExpandedTrait)
{
[tmpTraits addObject:@" expanded"];
}

if (_stylisticTraits & kCTFontVerticalTrait)
{
[tmpTraits addObject:@"vertical"];
}

if (_stylisticTraits & kCTFontUIOptimizedTrait)
{
[tmpTraits addObject:@" UI optimized"];
}


if ([tmpTraits count])
{
[string appendString:@" attributes="];
[string appendString:[tmpTraits componentsJoinedByString:@", "]];
}

[string appendString:@">"];

return string;
}

- (NSDictionary *)fontAttributes
{
NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary];

NSMutableDictionary *traitsDict = [NSMutableDictionary dictionary];

CTFontSymbolicTraits theSymbolicTraits = _stylisticTraits | _stylisticClass;

if (theSymbolicTraits)
{
[traitsDict setObject:[NSNumber numberWithUnsignedInt:theSymbolicTraits] forKey:(id)kCTFontSymbolicTrait];
}

if ([traitsDict count])
{
[tmpDict setObject:traitsDict forKey:(id)kCTFontTraitsAttribute];
}

if (_fontFamily)
{
[tmpDict setObject:_fontFamily forKey:(id)kCTFontFamilyNameAttribute];
}

if (_fontName)
{
[tmpDict setObject:_fontName forKey:(id)kCTFontNameAttribute];
}

// we need size because that's what makes a font unique, for searching it's ignored anyway
[tmpDict setObject:[NSNumber numberWithFloat:_pointSize] forKey:(id)kCTFontSizeAttribute];


if (_smallCapsFeature)
{
NSNumber *typeNum = [NSNumber numberWithInteger:3];
NSNumber *selNum = [NSNumber numberWithInteger:3];

NSDictionary *setting = [NSDictionary dictionaryWithObjectsAndKeys:selNum, (id)kCTFontFeatureSelectorIdentifierKey,
typeNum, (id)kCTFontFeatureTypeIdentifierKey, nil];

NSArray *featureSettings = [NSArray arrayWithObject:setting];

[tmpDict setObject:featureSettings forKey:(id)kCTFontFeatureSettingsAttribute];
}

if (!self.boldTrait && _needsChineseFontCascadeFix)
{
CTFontDescriptorRef desc = CTFontDescriptorCreateWithNameAndSize(CFSTR("STHeitiSC-Light"), self.pointSize);

[tmpDict setObject:[NSArray arrayWithObject:(__bridge_transfer id) desc] forKey:(id)kCTFontCascadeListAttribute];
}

//return [NSDictionary dictionaryWithDictionary:tmpDict];
// converting to non-mutable costs 42% of entire method
return tmpDict;
}

- (NSDictionary *)fontAttributesWithOverrideFontName:(NSString *)overrideFontName
{
NSMutableDictionary *tmpAttributes = [[self fontAttributes] mutableCopy];

// remove family
[tmpAttributes removeObjectForKey:(id)kCTFontFamilyNameAttribute];

// replace font name
[tmpAttributes setObject:overrideFontName forKey:(id)kCTFontNameAttribute];

return tmpAttributes;
}

- (BOOL)supportsNativeSmallCaps
{
if ([DTCoreTextFontDescriptor smallCapsFontNameforFontFamily:_fontFamily bold:self.boldTrait italic:self.italicTrait])
{
return YES;
}

CTFontRef tmpFont = [self newMatchingFont];

BOOL smallCapsSupported = NO;

// check if this font supports small caps
CFArrayRef fontFeatures = CTFontCopyFeatures(tmpFont);

if (fontFeatures)
{
for (NSDictionary *oneFeature in (__bridge NSArray *)fontFeatures)
{
NSInteger featureTypeIdentifier = [[oneFeature objectForKey:(id)kCTFontFeatureTypeIdentifierKey] integerValue];

if (featureTypeIdentifier == 3) // Letter Case
{
NSArray *featureSelectors = [oneFeature objectForKey:(id)kCTFontFeatureTypeSelectorsKey];

for (NSDictionary *oneFeatureSelector in featureSelectors)
{
NSInteger featureSelectorIdentifier = [[oneFeatureSelector objectForKey:(id)kCTFontFeatureSelectorIdentifierKey] integerValue];

if (featureSelectorIdentifier == 3) // Small Caps
{
// hooray, small caps supported!
smallCapsSupported = YES;

break;
}
}

break;
}
}

CFRelease(fontFeatures);
}

if (tmpFont)
{
CFRelease(tmpFont);
}

return smallCapsSupported;
}

#pragma mark Finding Font

- (BOOL)_fontIsOblique:(CTFontRef)font
{
NSDictionary *traits = (__bridge_transfer NSDictionary *)CTFontCopyTraits(font);

CGFloat slant = [[traits objectForKey:(id)kCTFontSlantTrait] floatValue];
BOOL hasItalicTrait = ([[traits objectForKey:(id)kCTFontSymbolicTrait] unsignedIntValue] & kCTFontItalicTrait) ==kCTFontItalicTrait;

if (!hasItalicTrait || slant<0.01)
{
return NO;
}

// font HAS italic trait AND sufficient slant angle
return YES;

}

- (CTFontRef)_findOrMakeMatchingFont
{
NSNumber *cacheKey = [NSNumber numberWithUnsignedInteger:[self hash]];

CTFontRef cachedFont = (__bridge_retained CTFontRef)[_fontCache objectForKey:cacheKey];

if (cachedFont)
{
return cachedFont;
}

CTFontDescriptorRef fontDesc = NULL;

CTFontRef matchingFont;

NSString *overrideName = nil;

// override fontName if a small caps or regular override is registered
if (_fontFamily)
{
if (_smallCapsFeature)
{
overrideName = [DTCoreTextFontDescriptor smallCapsFontNameforFontFamily:_fontFamily bold:self.boldTrait italic:self.italicTrait];
}
else
{
overrideName = [DTCoreTextFontDescriptor overrideFontNameforFontFamily:_fontFamily bold:self.boldTrait italic:self.italicTrait];
}
}

// if we use the chinese font cascade fix we cannot use fast method as it does not allow specifying the custom cascade list
BOOL useFastFontCreation = !(_needsChineseFontCascadeFix && !self.boldTrait);

if (useFastFontCreation && (_fontName || overrideName))
{
NSString *usedName = overrideName?overrideName:_fontName;

matchingFont = CTFontCreateWithName((__bridge CFStringRef)usedName, _pointSize, NULL);
}
else
{
NSDictionary *attributes;

if (overrideName)
{
attributes = [self fontAttributesWithOverrideFontName:overrideName];
}
else
{
attributes = [self fontAttributes];
}

fontDesc = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attributes);

// we need font family, font name or an overridden font name for fast font creation
if (_fontFamily||_fontName||overrideName)
{
// fast font creation
matchingFont = CTFontCreateWithFontDescriptor(fontDesc, _pointSize, NULL);
}
else
{
// without font name or family we need to do expensive search
// otherwise we always get Helvetica

NSMutableSet *set = [NSMutableSet setWithObject:(id)kCTFontTraitsAttribute];

if (_fontFamily)
{
[set addObject:(id)kCTFontFamilyNameAttribute];
}

if (_smallCapsFeature)
{
[set addObject:(id)kCTFontFeaturesAttribute];
}

CTFontDescriptorRef matchingDesc = CTFontDescriptorCreateMatchingFontDescriptor(fontDesc, (__bridge CFSetRef)set);

if (matchingDesc)
{
matchingFont = CTFontCreateWithFontDescriptor(matchingDesc, _pointSize, NULL);
CFRelease(matchingDesc);
}
else
{
matchingFont = nil;
}
}

// check if we indeed got an oblique font if we wanted one

if (matchingFont)
{
if (self.italicTrait)
{
if (![self _fontIsOblique:matchingFont])
{
// need to synthesize slant
CGAffineTransform slantMatrix = { 1, 0, 0.25, 1, 0, 0 };

CFRelease(matchingFont);
matchingFont = CTFontCreateWithFontDescriptor(fontDesc, _pointSize, &slantMatrix);
}
}
}

CFRelease(fontDesc);
}

if (matchingFont)
{
// cache it
[_fontCache setObject:(__bridge id)(matchingFont) forKey:cacheKey];
}

return matchingFont; // returns a +1 reference
}

- (CTFontRef)newMatchingFont
{
__block CTFontRef retFont;

// all calls get queued
dispatch_sync(_fontQueue, ^{
retFont = [self _findOrMakeMatchingFont];
});

return retFont;
}

// two font descriptors are equal if their attributes has identical hash codes
- (NSUInteger)hash
{
NSUInteger calcHash = 7;

calcHash = calcHash*31 + _pointSize;
calcHash = calcHash*31 + (_stylisticClass | _stylisticTraits);
calcHash = calcHash*31 + [_fontName hash];
calcHash = calcHash*31 + [_fontFamily hash];

return calcHash;
}

- (BOOL)isEqual:(id)object
{
return (([object isKindOfClass:[DTCoreTextFontDescriptor class]]) && ([self hash] == [object hash]));
}


#pragma mark NSCoding

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:self.fontName forKey:@"FontName"];
[encoder encodeObject:self.fontFamily forKey:@"FontFamily"];
[encoder encodeBool:self.boldTrait forKey:@"BoldTrait"];
[encoder encodeBool:self.italicTrait forKey:@"ItalicTrait"];
}

- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];

if (self)
{
self.fontName = [decoder decodeObjectForKey:@"FontName"];
self.fontFamily = [decoder decodeObjectForKey:@"FontFamily"];
self.boldTrait = [decoder decodeBoolForKey:@"BoldTrait"];
self.italicTrait = [decoder decodeBoolForKey:@"ItalicTrait"];
}

return self;
}


#pragma mark Copying

- (id)copyWithZone:(NSZone *)zone
{
DTCoreTextFontDescriptor *newDesc = [[DTCoreTextFontDescriptor allocWithZone:zone] initWithFontAttributes:[self fontAttributes]];
newDesc.pointSize = self.pointSize;
if (_stylisticClass)
{
newDesc.stylisticClass = self.stylisticClass;
}

return newDesc;
}


#pragma mark Properties
- (void)setStylisticClass:(CTFontStylisticClass)newClass
{
self.fontFamily = nil;

_stylisticClass = newClass;
}


- (void)setFontAttributes:(NSDictionary *)attributes
{
if (!attributes)
{
self.fontFamily = nil;
self.fontName = nil;
self.pointSize = 12;

_stylisticTraits = 0;
_stylisticClass = 0;
}

NSDictionary *traitsDict = [attributes objectForKey:(id)kCTFontTraitsAttribute];

if (traitsDict)
{
CTFontSymbolicTraits traitsValue = [[traitsDict objectForKey:(id)kCTFontSymbolicTrait ] unsignedIntValue];
self.symbolicTraits = traitsValue;
}

NSNumber *pointNum = [attributes objectForKey:(id)kCTFontSizeAttribute];
if (pointNum)
{
_pointSize = [pointNum floatValue];
}

NSString *family = [attributes objectForKey:(id)kCTFontFamilyNameAttribute];

if (family)
{
self.fontFamily = family;
}

NSString *name = [attributes objectForKey:(id)kCTFontNameAttribute];

if (name)
{
self.fontName = name;
}
}

- (CTFontSymbolicTraits)symbolicTraits
{
// symbolic traits include both stylistic traits as well as stylistic class
return _stylisticTraits | _stylisticClass;
}

- (void)setSymbolicTraits:(CTFontSymbolicTraits)theSymbolicTraits
{
// symbolic traits include both stylistic traits as well as stylistic class
_stylisticTraits = theSymbolicTraits & ~kCTFontClassMaskTrait;
_stylisticClass = theSymbolicTraits & kCTFontClassMaskTrait;
}

// a representation of this font in CSS style
- (NSString *)cssStyleRepresentation
{
NSMutableString *retString = [NSMutableString string];

if (_fontFamily)
{
[retString appendFormat:@"font-family:'%@';", _fontFamily];
}

[retString appendFormat:@"font-size:%.0fpx;", _pointSize];

if (self.italicTrait)
{
[retString appendString:@"font-style:italic;"];
}

if (self.boldTrait)
{
[retString appendString:@"font-weight:bold;"];
}

// return nil if no content
if ([retString length])
{
return retString;
}
else
{
return nil;
}
}

- (void)setBoldTrait:(BOOL)boldTrait
{
if (boldTrait)
{
_stylisticTraits |= kCTFontBoldTrait;
}
else
{
_stylisticTraits &= ~kCTFontBoldTrait;
}
}

- (BOOL)boldTrait
{
return (_stylisticTraits & kCTFontBoldTrait)!=0;
}

- (void)setItalicTrait:(BOOL)italicTrait
{
if (italicTrait)
{
_stylisticTraits |= kCTFontItalicTrait;
}
else
{
_stylisticTraits &= ~kCTFontItalicTrait;
}
}

- (BOOL)italicTrait
{
return (_stylisticTraits & kCTFontItalicTrait)!=0;
}

- (void)setExpandedTrait:(BOOL)expandedTrait
{
if (expandedTrait)
{
_stylisticTraits |= kCTFontExpandedTrait;
}
else
{
_stylisticTraits &= ~kCTFontExpandedTrait;
}
}

- (BOOL)expandedTrait
{
return (_stylisticTraits & kCTFontExpandedTrait)!=0;
}

- (void)setCondensedTrait:(BOOL)condensedTrait
{
if (condensedTrait)
{
_stylisticTraits |= kCTFontCondensedTrait;
}
else
{
_stylisticTraits &= ~kCTFontCondensedTrait;
}
}

- (BOOL)condensedTrait
{
return (_stylisticTraits & kCTFontCondensedTrait)!=0;
}

- (void)setMonospaceTrait:(BOOL)monospaceTrait
{
if (monospaceTrait)
{
_stylisticTraits |= kCTFontMonoSpaceTrait;
}
else
{
_stylisticTraits &= ~kCTFontMonoSpaceTrait;
}
}

- (BOOL)monospaceTrait
{
return (_stylisticTraits & kCTFontMonoSpaceTrait)!=0;
}

- (void)setVerticalTrait:(BOOL)verticalTrait
{
if (verticalTrait)
{
_stylisticTraits |= kCTFontVerticalTrait;
}
else
{
_stylisticTraits &= ~kCTFontVerticalTrait;
}
}

- (BOOL)verticalTrait
{
return (_stylisticTraits & kCTFontVerticalTrait)!=0;
}

- (void)setUIoptimizedTrait:(BOOL)UIoptimizedTrait
{
if (UIoptimizedTrait)
{
_stylisticTraits |= kCTFontUIOptimizedTrait;
}
else
{
_stylisticTraits &= ~kCTFontUIOptimizedTrait;
}
}

- (BOOL)UIoptimizedTrait
{
return (_stylisticTraits & kCTFontUIOptimizedTrait)!=0;
}

- (void)setPointSize:(CGFloat)pointSize
{
_pointSize = roundf(pointSize);
}

@synthesize fontFamily = _fontFamily;
@synthesize fontName = _fontName;
@synthesize pointSize = _pointSize;

@synthesize symbolicTraits;

@synthesize stylisticClass = _stylisticClass;
@synthesize smallCapsFeature = _smallCapsFeature;

@end
Something went wrong with that request. Please try again.