Skip to content

Commit 71c13cf

Browse files
committed
Fix compile issue for font after macOS support, using the correspond AppKit API. Fix API warning
1 parent 12ecf80 commit 71c13cf

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

Source/AppKit additions/SVGKImageRep.m

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#import "SVGKImage+CGContext.h"
1717
#include <tgmath.h>
1818

19-
#define TEMPORARY_WARNING_FOR_APPLES_BROKEN_RENDERINCONTEXT_METHOD 1 // ONLY needed as temporary workaround for Apple's renderInContext bug breaking various bits of rendering: Gradients, Scaling, etc
20-
2119
@interface SVGKImageRep ()
2220
@property (nonatomic, strong, readwrite, setter = setTheSVG:) SVGKImage *image;
2321
@property (nonatomic, assign) BOOL antiAlias;
@@ -150,25 +148,6 @@ - (instancetype)initWithSVGImage:(SVGKImage*)theImage copy:(BOOL)copyImage
150148
}
151149

152150
self.image = theImage;
153-
154-
#if TEMPORARY_WARNING_FOR_APPLES_BROKEN_RENDERINCONTEXT_METHOD
155-
BOOL hasGrad = ![SVGKFastImageView svgImageHasNoGradients:self.image];
156-
157-
if (hasGrad) {
158-
NSString *errstuff;
159-
160-
if (hasGrad) {
161-
errstuff = @"gradients";
162-
}
163-
164-
if (errstuff == nil) {
165-
//We shouldn't get here!
166-
errstuff = @"";
167-
}
168-
169-
DDLogWarn(@"[%@] The image \"%@\" might have problems rendering correctly due to %@.", [self class], [self image], errstuff);
170-
}
171-
#endif
172151

173152
if (![self.image hasSize]) {
174153
self.image.size = CGSizeMake(32, 32);

Source/DOM classes/Unported or Partial DOM/SVGTextElement.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ + (UIFont *)matchedFontWithElement:(SVGElement *)svgElement {
241241
NSString *matchedFontFamily;
242242
if (actualFontFamilies) {
243243
// walkthrough all available font-families to find the best matched one
244-
NSSet<NSString *> *availableFontFamilies = [NSSet setWithArray:UIFont.familyNames];
244+
NSSet<NSString *> *availableFontFamilies;
245+
#if SVGKIT_MAC
246+
availableFontFamilies = [NSSet setWithArray:NSFontManager.sharedFontManager.availableFontFamilies];
247+
#else
248+
availableFontFamilies = [NSSet setWithArray:UIFont.familyNames];
249+
#endif
245250
for (NSString *fontFamily in actualFontFamilies) {
246251
if ([availableFontFamilies containsObject:fontFamily]) {
247252
matchedFontFamily = fontFamily;
@@ -306,16 +311,16 @@ + (NSDictionary *)fontAttributesWithFontFamily:(NSString *)fontFamily fontStyle:
306311
CTFontSymbolicTraits style = 0;
307312
if ([fontStyle isEqualToString:@"normal"]) {
308313
style |= 0;
309-
} else if ([fontStyle isEqualToString:@"italic"] || [fontStyle containsString:@"oblique"]) {
314+
} else if ([fontStyle isEqualToString:@"italic"] || [fontStyle rangeOfString:@"oblique"].location != NSNotFound) {
310315
// Actually we can control the detailed slant degree via `kCTFontSlantTrait`, but it's rare usage so treat them the same, TODO in the future
311316
style |= kCTFontItalicTrait;
312317
}
313318

314319
// CSS font stretch
315-
if ([fontStretch containsString:@"condensed"]) {
320+
if ([fontStretch rangeOfString:@"condensed"].location != NSNotFound) {
316321
// Actually we can control the detailed percent via `kCTFontWidthTrait`, but it's rare usage so treat them the same, TODO in the future
317322
style |= kCTFontTraitCondensed;
318-
} else if ([fontStretch containsString:@"expanded"]) {
323+
} else if ([fontStretch rangeOfString:@"expanded"].location != NSNotFound) {
319324
style |= kCTFontTraitExpanded;
320325
}
321326

Source/SVGKDefine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
#ifndef UIColor
5959
#define UIColor NSColor
6060
#endif
61+
#ifndef UIFont
62+
#define UIFont NSFont
63+
#endif
6164
#endif
6265

6366
#endif /* SVGKDefine_h */

0 commit comments

Comments
 (0)