|
26 | 26 | #endif
|
27 | 27 | #if SD_MAC
|
28 | 28 | static Class SDNSSVGImageRepClass = NULL;
|
| 29 | +static Ivar SDNSSVGImageRepDocumentIvar = NULL; |
29 | 30 | #endif
|
30 | 31 |
|
31 | 32 | static inline NSString *SDBase64DecodedString(NSString *base64String) {
|
@@ -60,6 +61,9 @@ + (void)initialize {
|
60 | 61 | #endif
|
61 | 62 | #if SD_MAC
|
62 | 63 | SDNSSVGImageRepClass = NSClassFromString(SDBase64DecodedString(@"X05TU1ZHSW1hZ2VSZXA="));
|
| 64 | + if (SDNSSVGImageRepClass) { |
| 65 | + SDNSSVGImageRepDocumentIvar = class_getInstanceVariable(SDNSSVGImageRepClass, SDBase64DecodedString(@"X2RvY3VtZW50").UTF8String); |
| 66 | + } |
63 | 67 | #endif
|
64 | 68 | }
|
65 | 69 |
|
@@ -125,12 +129,10 @@ - (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format o
|
125 | 129 | NSRect imageRect = NSMakeRect(0, 0, image.size.width, image.size.height);
|
126 | 130 | NSImageRep *imageRep = [image bestRepresentationForRect:imageRect context:nil hints:nil];
|
127 | 131 | if ([imageRep isKindOfClass:SDNSSVGImageRepClass]) {
|
128 |
| - Ivar ivar = class_getInstanceVariable(imageRep.class, SDBase64DecodedString(@"X2RvY3VtZW50").UTF8String); |
129 |
| - document = (__bridge CGSVGDocumentRef)(object_getIvar(imageRep, ivar)); |
| 132 | + document = (__bridge CGSVGDocumentRef)(object_getIvar(imageRep, SDNSSVGImageRepDocumentIvar)); |
130 | 133 | }
|
131 | 134 | #else
|
132 |
| - CGSVGDocumentRef (*method)(id,SEL) = (CGSVGDocumentRef (*)(id,SEL))[image methodForSelector:SDCGSVGDocumentSEL]; |
133 |
| - document = method(image, SDCGSVGDocumentSEL); |
| 135 | + document = ((CGSVGDocumentRef (*)(id,SEL))[image methodForSelector:SDCGSVGDocumentSEL])(image, SDCGSVGDocumentSEL); |
134 | 136 | #endif
|
135 | 137 | if (!document) {
|
136 | 138 | return nil;
|
@@ -159,7 +161,7 @@ - (UIImage *)createVectorSVGWithData:(nonnull NSData *)data {
|
159 | 161 | if (!document) {
|
160 | 162 | return nil;
|
161 | 163 | }
|
162 |
| - image = [UIImage performSelector:SDImageWithCGSVGDocumentSEL withObject:(__bridge id)(document)]; |
| 164 | + image = ((UIImage *(*)(id,SEL,CGSVGDocumentRef))[UIImage.class methodForSelector:SDImageWithCGSVGDocumentSEL])(UIImage.class, SDImageWithCGSVGDocumentSEL, document); |
163 | 165 | SDCGSVGDocumentRelease(document);
|
164 | 166 | #endif
|
165 | 167 | return image;
|
|
0 commit comments