Skip to content

Commit 12eff67

Browse files
adamgitadamgit
authored andcommitted
FIXED: SVGKit now scales images in a standards-compliant way.
NB: it ALSO has some backup techniques - c.f. SVGKImage setScale: - for the cases where the SVG-Spec standard approach WONT work
1 parent 90bd8e8 commit 12eff67

File tree

16 files changed

+606
-111
lines changed

16 files changed

+606
-111
lines changed
Lines changed: 119 additions & 0 deletions
Loading
Lines changed: 119 additions & 0 deletions
Loading

Demo-iOS.xcodeproj/project.pbxproj

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
663FCFF616C9AF3C00CCBFB3 /* Sample Licenses from svg-android project.txt in Resources */ = {isa = PBXBuildFile; fileRef = 663FCFF516C9AF3C00CCBFB3 /* Sample Licenses from svg-android project.txt */; };
2020
663FD00416CAB16B00CCBFB3 /* groups-and-layers-test.svg in Resources */ = {isa = PBXBuildFile; fileRef = 663FD00316CAB16B00CCBFB3 /* groups-and-layers-test.svg */; };
2121
6649E0AD1617479200AFE92A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6649E0AC1617479200AFE92A /* QuartzCore.framework */; };
22-
6649E10D1617577000AFE92A /* libSVGKit-iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6649E10A1617574700AFE92A /* libSVGKit-iOS.a */; };
22+
6649E10D1617577000AFE92A /* libSVGKit-iOS.1.1.0pre.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6649E10A1617574700AFE92A /* libSVGKit-iOS.1.1.0pre.a */; };
2323
6649E10F1617578500AFE92A /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 6649E10E1617578500AFE92A /* libxml2.dylib */; };
2424
665E07F316CE81DD00D6934D /* g-element-applies-rotation.svg in Resources */ = {isa = PBXBuildFile; fileRef = 665E07F216CE81DD00D6934D /* g-element-applies-rotation.svg */; };
2525
6661A77D1698BBE20061E349 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6661A77C1698BBE20061E349 /* CoreText.framework */; };
@@ -30,6 +30,8 @@
3030
66A09CAA16CFE67B003CD5CD /* text01.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A09CA416CFE67B003CD5CD /* text01.svg */; };
3131
66A09CAB16CFE67B003CD5CD /* tspan01.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A09CA516CFE67B003CD5CD /* tspan01.svg */; };
3232
66A9F4441688C66E000D4A2E /* RainbowWing.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66A9F4431688C66E000D4A2E /* RainbowWing.svg */; };
33+
66E785AB171A228A001EF59D /* svg-with-explicit-width.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */; };
34+
66E785AD171A2345001EF59D /* svg-with-explicit-width-large.svg in Resources */ = {isa = PBXBuildFile; fileRef = 66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */; };
3335
66E8626B1688BA0B0059C9C4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 66E862581688BA0B0059C9C4 /* AppDelegate.m */; };
3436
66E8626C1688BA0B0059C9C4 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 66E862591688BA0B0059C9C4 /* Default-568h@2x.png */; };
3537
66E8626E1688BA0B0059C9C4 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 66E8625D1688BA0B0059C9C4 /* DetailViewController.m */; };
@@ -70,7 +72,7 @@
7072
remoteGlobalIDString = 6639618E16145D0400E58CCA;
7173
remoteInfo = "SVGKit-iOS";
7274
};
73-
6649E10B1617575500AFE92A /* PBXContainerItemProxy */ = {
75+
66E785A8171A1208001EF59D /* PBXContainerItemProxy */ = {
7476
isa = PBXContainerItemProxy;
7577
containerPortal = 6649E1021617574600AFE92A /* SVGKit-iOS.xcodeproj */;
7678
proxyType = 1;
@@ -104,6 +106,8 @@
104106
66A09CA416CFE67B003CD5CD /* text01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = text01.svg; sourceTree = "<group>"; };
105107
66A09CA516CFE67B003CD5CD /* tspan01.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = tspan01.svg; sourceTree = "<group>"; };
106108
66A9F4431688C66E000D4A2E /* RainbowWing.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = RainbowWing.svg; sourceTree = "<group>"; };
109+
66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width.svg"; sourceTree = "<group>"; };
110+
66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "svg-with-explicit-width-large.svg"; sourceTree = "<group>"; };
107111
66E862571688BA0B0059C9C4 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
108112
66E862581688BA0B0059C9C4 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
109113
66E862591688BA0B0059C9C4 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
@@ -149,7 +153,7 @@
149153
files = (
150154
6661A77D1698BBE20061E349 /* CoreText.framework in Frameworks */,
151155
6649E10F1617578500AFE92A /* libxml2.dylib in Frameworks */,
152-
6649E10D1617577000AFE92A /* libSVGKit-iOS.a in Frameworks */,
156+
6649E10D1617577000AFE92A /* libSVGKit-iOS.1.1.0pre.a in Frameworks */,
153157
6649E0AD1617479200AFE92A /* QuartzCore.framework in Frameworks */,
154158
661A0DCF161727CF008D5FBE /* UIKit.framework in Frameworks */,
155159
661A0DD1161727CF008D5FBE /* Foundation.framework in Frameworks */,
@@ -207,7 +211,7 @@
207211
6649E1031617574600AFE92A /* Products */ = {
208212
isa = PBXGroup;
209213
children = (
210-
6649E10A1617574700AFE92A /* libSVGKit-iOS.a */,
214+
6649E10A1617574700AFE92A /* libSVGKit-iOS.1.1.0pre.a */,
211215
);
212216
name = Products;
213217
sourceTree = "<group>";
@@ -291,6 +295,8 @@
291295
66A9F4431688C66E000D4A2E /* RainbowWing.svg */,
292296
66E862881688BA510059C9C4 /* Reinel_compass_rose-simplified-for-testing.svg */,
293297
66E862891688BA510059C9C4 /* Reinel_compass_rose.svg */,
298+
66E785AA171A228A001EF59D /* svg-with-explicit-width.svg */,
299+
66E785AC171A2345001EF59D /* svg-with-explicit-width-large.svg */,
294300
66E8628A1688BA510059C9C4 /* test-wave-1.svg */,
295301
66E8628B1688BA510059C9C4 /* Text.svg */,
296302
66E8628C1688BA510059C9C4 /* uk-only.svg */,
@@ -313,7 +319,7 @@
313319
buildRules = (
314320
);
315321
dependencies = (
316-
6649E10C1617575500AFE92A /* PBXTargetDependency */,
322+
66E785A9171A1208001EF59D /* PBXTargetDependency */,
317323
);
318324
name = "Demo-iOS";
319325
productName = iOSDemo;
@@ -353,10 +359,10 @@
353359
/* End PBXProject section */
354360

355361
/* Begin PBXReferenceProxy section */
356-
6649E10A1617574700AFE92A /* libSVGKit-iOS.a */ = {
362+
6649E10A1617574700AFE92A /* libSVGKit-iOS.1.1.0pre.a */ = {
357363
isa = PBXReferenceProxy;
358364
fileType = archive.ar;
359-
path = "libSVGKit-iOS.a";
365+
path = "libSVGKit-iOS.1.1.0pre.a";
360366
remoteRef = 6649E1091617574700AFE92A /* PBXContainerItemProxy */;
361367
sourceTree = BUILT_PRODUCTS_DIR;
362368
};
@@ -409,6 +415,8 @@
409415
66A09CAA16CFE67B003CD5CD /* text01.svg in Resources */,
410416
66A09CAB16CFE67B003CD5CD /* tspan01.svg in Resources */,
411417
66324BE216D24FA4001C1E83 /* rounded-rects.svg in Resources */,
418+
66E785AB171A228A001EF59D /* svg-with-explicit-width.svg in Resources */,
419+
66E785AD171A2345001EF59D /* svg-with-explicit-width-large.svg in Resources */,
412420
);
413421
runOnlyForDeploymentPostprocessing = 0;
414422
};
@@ -429,10 +437,10 @@
429437
/* End PBXSourcesBuildPhase section */
430438

431439
/* Begin PBXTargetDependency section */
432-
6649E10C1617575500AFE92A /* PBXTargetDependency */ = {
440+
66E785A9171A1208001EF59D /* PBXTargetDependency */ = {
433441
isa = PBXTargetDependency;
434442
name = "SVGKit-iOS";
435-
targetProxy = 6649E10B1617575500AFE92A /* PBXContainerItemProxy */;
443+
targetProxy = 66E785A8171A1208001EF59D /* PBXContainerItemProxy */;
436444
};
437445
/* End PBXTargetDependency section */
438446

Source/DOM classes/SVG-DOM/SVGFitToViewBox.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
#import <QuartzCore/QuartzCore.h>
1212

13+
#import "SVGRect.h"
14+
1315
@protocol SVGFitToViewBox <NSObject>
1416

15-
@property (nonatomic) /* SVGAnimatedRect */ CGRect viewBox;
17+
@property (nonatomic) /* SVGAnimatedRect */ SVGRect viewBox;
1618

1719
@end

Source/DOM classes/SVG-DOM/SVGHelperUtilities.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,27 @@ +(CGAffineTransform) transformRelativeIncludingViewportForTransformableOrViewpor
4545
Optional relative transform: if incoming element establishes a viewport, do something clever; for everything else, use identity
4646
*/
4747
if( transformableOrSVGSVGElement.viewportElement == nil // if it's nil, it means THE OPPOSITE of what you'd expect - it means that it IS the viewport element - SVG Spec REQUIRES this
48-
|| transformableOrSVGSVGElement.viewportElement == transformableOrSVGSVGElement // if it's some-other-object, then: we simply don't need to worry about it
48+
|| transformableOrSVGSVGElement.viewportElement == transformableOrSVGSVGElement // ?? I don't understand: ?? if it's something other than itself, then: we simply don't need to worry about it ??
4949
)
5050
{
5151
SVGElement<SVGFitToViewBox>* svgSVGElement = (SVGElement<SVGFitToViewBox>*) transformableOrSVGSVGElement;
5252

53-
/** Calculate the "implicit" viewport transform (caused by the <SVG> tag's possible "viewBox" attribute) */
54-
CGRect frameViewBox = svgSVGElement.viewBox;
55-
CGRect frameViewport = CGRectFromSVGRect( ((SVGSVGElement*)svgSVGElement).viewport );
56-
57-
if( ! CGRectIsEmpty( frameViewBox ) )
53+
/**
54+
Calculate the "implicit" viewport transform (caused by the <SVG> tag's possible "viewBox" attribute)
55+
56+
*/
57+
SVGRect frameViewBox = svgSVGElement.viewBox;
58+
if( SVGRectIsInitialized( frameViewBox ) )
5859
{
59-
CGAffineTransform translateToViewBox = CGAffineTransformMakeTranslation( -frameViewBox.origin.x, -frameViewBox.origin.y );
60-
CGAffineTransform scaleToViewBox = CGAffineTransformMakeScale( frameViewport.size.width / frameViewBox.size.width, frameViewport.size.height / frameViewBox.size.height);
60+
/* (NB: the viewport will ALWAYS have a value: UNLESS the SVG is so crappy it has NEITHER a viewbox NOR an explicit width
61+
and height in the root <SVG> tag.
62+
63+
...but since we know we already have a viewbox, we can rely upon there being a viewport too.
64+
*/
65+
SVGRect frameViewport = ((SVGSVGElement*)svgSVGElement).viewport;
66+
67+
CGAffineTransform translateToViewBox = CGAffineTransformMakeTranslation( -frameViewBox.x, -frameViewBox.y );
68+
CGAffineTransform scaleToViewBox = CGAffineTransformMakeScale( frameViewport.width / frameViewBox.width, frameViewport.height / frameViewBox.height);
6169
optionalViewportTransform = CGAffineTransformConcat( translateToViewBox, scaleToViewBox );
6270
}
6371
else

0 commit comments

Comments
 (0)