Skip to content

Commit 66689e4

Browse files
adamgitadamgit
authored andcommitted
Fixed: major bug with [NSCharacterSet SVGWhitespaceCharacterSet]
1 parent aa5ea02 commit 66689e4

File tree

3 files changed

+78
-14
lines changed

3 files changed

+78
-14
lines changed

SVGKit-iOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
036A524C16E87693008C1140 /* NSCharacterSet+SVGKExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 036A524A16E87693008C1140 /* NSCharacterSet+SVGKExtensions.h */; };
10+
036A524C16E87693008C1140 /* NSCharacterSet+SVGKExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 036A524A16E87693008C1140 /* NSCharacterSet+SVGKExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
1111
036A524D16E87693008C1140 /* NSCharacterSet+SVGKExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 036A524B16E87693008C1140 /* NSCharacterSet+SVGKExtensions.m */; };
12-
6616CB11171078E800109FF3 /* SVGKSourceString.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB0F171078E800109FF3 /* SVGKSourceString.h */; };
12+
6616CB11171078E800109FF3 /* SVGKSourceString.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB0F171078E800109FF3 /* SVGKSourceString.h */; settings = {ATTRIBUTES = (Public, ); }; };
1313
6616CB12171078E800109FF3 /* SVGKSourceString.m in Sources */ = {isa = PBXBuildFile; fileRef = 6616CB10171078E800109FF3 /* SVGKSourceString.m */; };
14-
6616CB151710790200109FF3 /* SVGKSourceLocalFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB131710790200109FF3 /* SVGKSourceLocalFile.h */; };
14+
6616CB151710790200109FF3 /* SVGKSourceLocalFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB131710790200109FF3 /* SVGKSourceLocalFile.h */; settings = {ATTRIBUTES = (Public, ); }; };
1515
6616CB161710790200109FF3 /* SVGKSourceLocalFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 6616CB141710790200109FF3 /* SVGKSourceLocalFile.m */; };
16-
6616CB191710798300109FF3 /* SVGKSourceURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB171710798300109FF3 /* SVGKSourceURL.h */; };
16+
6616CB191710798300109FF3 /* SVGKSourceURL.h in Headers */ = {isa = PBXBuildFile; fileRef = 6616CB171710798300109FF3 /* SVGKSourceURL.h */; settings = {ATTRIBUTES = (Public, ); }; };
1717
6616CB1A1710798300109FF3 /* SVGKSourceURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 6616CB181710798300109FF3 /* SVGKSourceURL.m */; };
1818
661ADBF216CC2FBE006F4BC3 /* SVGTextPositioningElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 661ADBF016CC2FBE006F4BC3 /* SVGTextPositioningElement.h */; settings = {ATTRIBUTES = (Public, ); }; };
1919
661ADBF316CC2FBE006F4BC3 /* SVGTextPositioningElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 661ADBF116CC2FBE006F4BC3 /* SVGTextPositioningElement.m */; };

Source/UIKit additions/NSCharacterSet+SVGKExtensions.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ + (NSCharacterSet *)SVGWhitespaceCharacterSet;
1919
static NSCharacterSet *sWhitespaceCharacterSet = nil;
2020
static dispatch_once_t onceToken;
2121
dispatch_once(&onceToken, ^{
22-
sWhitespaceCharacterSet = [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%c%c%c%c", 0x20, 0x9, 0xD, 0xA]];
22+
sWhitespaceCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%c%c%c%c", 0x20, 0x9, 0xD, 0xA]] retain];
2323
});
24+
2425
return sWhitespaceCharacterSet;
2526
}
2627

Source/UIKit additions/SVGKLayeredImageView.m

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#import <QuartzCore/QuartzCore.h>
44

5+
#import "SVGKSourceString.h"
6+
57
@interface SVGKLayeredImageView()
68
@property(nonatomic,retain) CAShapeLayer* internalBorderLayer;
79
@end
@@ -41,17 +43,78 @@ - (id)initWithSVGKImage:(SVGKImage*) im
4143
if( im == nil )
4244
{
4345
NSLog(@"[%@] WARNING: you have initialized an [%@] with a blank image (nil). Possibly because you're using Storyboards or NIBs which Apple won't allow us to decorate. Make sure you assign an SVGKImage to the .image property!", [self class], [self class]);
46+
47+
self = [super initWithFrame:CGRectMake(0,0,100,100)]; // coincides with the inline SVG below!
48+
if( self )
49+
{
50+
self.backgroundColor = [UIColor clearColor];
51+
52+
NSString* svgStringDefaultContents = @"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\
53+
\
54+
<svg\
55+
xmlns:svg=\"http://www.w3.org/2000/svg\"\
56+
xmlns=\"http://www.w3.org/2000/svg\"\
57+
width=\"100\"\
58+
height=\"100\"\
59+
id=\"svg2\"\
60+
version=\"1.1\"\
61+
<defs\
62+
id=\"defs4\" />\
63+
<metadata\
64+
id=\"metadata7\">\
65+
</metadata>\
66+
<g\
67+
id=\"layer1\"\
68+
transform=\"translate(0,-952.36218)\">\
69+
<rect\
70+
style=\"opacity:0.98000003999999996;color:#000000;fill:#bf01ff;fill-opacity:0.99607843;fill-rule:nonzero;stroke:none;stroke-width:3;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate\"\
71+
id=\"rect2985\"\
72+
width=\"100\"\
73+
height=\"100\"\
74+
x=\"0\"\
75+
y=\"952.36218\" />\
76+
<text\
77+
xml:space=\"preserve\"\
78+
style=\"font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#f6ff0f;fill-opacity:1;stroke:none;font-family:Sans\"\
79+
x=\"6.3190379\"\
80+
y=\"991.14648\"\
81+
id=\"text3755\"\
82+
><tspan\
83+
x=\"6.3190379\"\
84+
y=\"991.14648\"\
85+
id=\"tspan3759\"\
86+
style=\"font-size:24px;fill:#f6ff0f;fill-opacity:1\">Missing</tspan></text>\
87+
<text\
88+
xml:space=\"preserve\"\
89+
style=\"font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#fffc45;fill-opacity:1;stroke:none;font-family:Sans\"\
90+
x=\"26.460968\"\
91+
y=\"1030.2456\"\
92+
id=\"text3763\"\
93+
><tspan\
94+
id=\"tspan3765\"\
95+
x=\"26.460968\"\
96+
y=\"1030.2456\"\
97+
style=\"font-size:24px;fill:#fffc45;fill-opacity:1\">SVG</tspan></text>\
98+
</g>\
99+
</svg>";
100+
101+
SVGKImage* defaultBlankImage = [SVGKImage imageWithSource:[SVGKSourceString sourceFromContentsOfString:svgStringDefaultContents]];
102+
103+
((SVGKLayer*) self.layer).SVGImage = defaultBlankImage;
104+
}
44105
}
45-
46-
self = [super init];
47-
if (self)
106+
else
48107
{
49-
self.frame = CGRectMake( 0,0, im.CALayerTree.frame.size.width, im.CALayerTree.frame.size.height ); // default: 0,0 to width x height of original image
50-
self.backgroundColor = [UIColor clearColor];
51-
52-
((SVGKLayer*) self.layer).SVGImage = im;
53-
54-
}
108+
self = [super initWithFrame:CGRectMake( 0,0, im.CALayerTree.frame.size.width, im.CALayerTree.frame.size.height )]; // default: 0,0 to width x height of original image];
109+
if (self)
110+
{
111+
self.backgroundColor = [UIColor clearColor];
112+
113+
((SVGKLayer*) self.layer).SVGImage = im;
114+
115+
}
116+
}
117+
55118
return self;
56119
}
57120

0 commit comments

Comments
 (0)