Przeglądaj źródła

Update library "github "SVGKit/SVGKit" "3.x""

marinofaggiana 5 lat temu
rodzic
commit
891c093def
25 zmienionych plików z 211 dodań i 216 usunięć
  1. 1 1
      Cartfile
  2. 1 1
      Cartfile.resolved
  3. 13 32
      Carthage/Checkouts/SVGKit/README.mdown
  4. 1 1
      Carthage/Checkouts/SVGKit/Source/DOM classes/Core DOM/DOMGlobalSettings.h
  5. 2 1
      Carthage/Checkouts/SVGKit/Source/DOM classes/SVG-DOM/SVGLength.m
  6. 1 1
      Carthage/Checkouts/SVGKit/Source/DOM classes/SVG-DOM/SVGNumber.h
  7. 1 1
      Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGElement.h
  8. 17 8
      Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGElement.m
  9. 15 5
      Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGImageElement.m
  10. 18 5
      Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGSVGElement.m
  11. 4 2
      Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGTextElement.m
  12. 1 51
      Carthage/Checkouts/SVGKit/Source/Exporters/SVGKImage+CGContext.m
  13. 1 1
      Carthage/Checkouts/SVGKit/Source/Foundation additions/NSData+NSInputStream.h
  14. 7 1
      Carthage/Checkouts/SVGKit/Source/Foundation additions/NSData+NSInputStream.m
  15. 15 20
      Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserGradient.m
  16. 33 35
      Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserSVG.m
  17. 13 21
      Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserStyles.m
  18. 5 1
      Carthage/Checkouts/SVGKit/Source/Parsers/SVGKPointsAndPathsParser.m
  19. 18 0
      Carthage/Checkouts/SVGKit/Source/QuartzCore additions/CALayerWithClipRender.m
  20. 3 0
      Carthage/Checkouts/SVGKit/Source/SVGKImage.h
  21. 25 11
      Carthage/Checkouts/SVGKit/Source/SVGKImage.m
  22. 2 0
      Carthage/Checkouts/SVGKit/Source/SVGKit.h
  23. 8 2
      Carthage/Checkouts/SVGKit/Source/Sources/SVGKSourceURL.m
  24. 4 7
      Carthage/Checkouts/SVGKit/Source/UIKit additions/SVGKFastImageView.m
  25. 2 8
      Carthage/Checkouts/SVGKit/Source/UIKit additions/SVGKLayeredImageView.m

+ 1 - 1
Cartfile

@@ -8,7 +8,7 @@ github "calimarkus/JDStatusBarNotification" == 1.6.0
 github "ChangbaDevs/KTVHTTPCache" == 2.0.1
 github "jdg/MBProgressHUD" == 1.1.0
 github "realm/realm-cocoa" == 3.17.1
-github "SVGKit/SVGKit" == 2.1.0
+github "SVGKit/SVGKit" "3.x"
 github "WeTransfer/WeScan" == 1.1.0
 github "malcommac/SwiftRichString" == 3.0.0
 github "yannickl/QRCodeReader.swift" >= 10.1.0

+ 1 - 1
Cartfile.resolved

@@ -2,7 +2,7 @@ github "AssistoLab/DropDown" "v2.3.13"
 github "ChangbaDevs/KTVHTTPCache" "2.0.1"
 github "CocoaLumberjack/CocoaLumberjack" "3.5.3"
 github "MortimerGoro/MGSwipeTableCell" "1.6.8"
-github "SVGKit/SVGKit" "2.1.0"
+github "SVGKit/SVGKit" "39dd210fd47e3195f57f914354ffd2d0b4b8ff1c"
 github "WeTransfer/WeScan" "v1.1.0"
 github "WenchaoD/FSCalendar" "2.8.0"
 github "calimarkus/JDStatusBarNotification" "1.6.0"

+ 13 - 32
Carthage/Checkouts/SVGKit/README.mdown

@@ -2,23 +2,18 @@
 
 SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links [are on the wiki](https://github.com/SVGKit/SVGKit/wiki)
 
-### Twitter
-
-We have a Twitter account http://twitter.com/SVGKit_free  you can follow for release info, or tweet at for contact (any bugs, please report via the Issues page instead).
 
 ## Versions:
 
 Latest info at: https://github.com/SVGKit/SVGKit/wiki/Versions
 
-  - v2.x = current "in development" branch with latest changes, fixes, features
+  - v3.x = current "in development" branch with latest changes, fixes, features
     - NB: this is now automatically selected in GitHub as the "default" branch when you visit SVGKit's project page
         
 # Getting Started
 
 ## Run the Demo - iOS
 
-  NB: April 2015: new Demo app, many more features, may have teething troubles with this one.
-
 1. Open up "Demo-iOS.xcodeproj", and run it (on simulator or device). Try different SVG's. Zoom, pan, and (with the Monkey only:) hit the "Animate" button. Tap the images to see bounding-boxes / hit dectection (might need you to hit the Debug button first)
 1. If you have ANY problems building the library and embedding it in your app, compare your build settings to the Demo-iOS build settings - if something's different, it's probably the problem.
 
@@ -31,9 +26,9 @@ You have 3 main options for installing SVGKit:
 1. Use Carthage
 1. Drag/drop the static library into your project, and configure the build settings in your project
 
-NB: the "static library" is our backwards-compatible, manual install that always works if you have problems either with CocoaPods or with the Framework. But the other two are a lot quicker/easier.
+NB: the "static library" is our backwards-compatible, manual install that always works if you have problems with CocoaPods/Carthage/Framework.
 
-## Use the Framework - drag, drop, done!
+## OPTION 1: Use the Framework - drag, drop, done!
 
 1. Open "SVGKit-iOS.xcodeproj"
 1. Build the project once
@@ -54,35 +49,33 @@ You MAY also need to add the following 3rd party Frameworks to your app (include
   - CocoaLumberjack (in the SVGKit-iOS project, select the "3rd-party-frameworks" folder, and drag/drop whichever versions you need: iOS, tvOS, etc)
     Remember to embed the library too (should show under Target -> General -> Embedded Binaries)
     
-## Using CocoaPods
+## OPTION 2: Using CocoaPods
 [CocoaPods](https://github.com/CocoaPods/CocoaPods) is a dependency manager for CocoaTouch. To do CocoaPods, adding the following in your podfile:
 
 ```
 pod 'SVGKit'
 ```
 
-It is also recommended that you setup your podfile to get SVGKit from this 2.x branch.
+It is also recommended that you setup your podfile to get SVGKit from the latest branch (October 2018: currently 3.x).
 
 ```
-pod 'SVGKit', :git => 'https://github.com/SVGKit/SVGKit.git', :branch => '2.x'
+pod 'SVGKit', :git => 'https://github.com/SVGKit/SVGKit.git', :branch => '3.x'
 ```
 
-## Using Carthage
+## OPTION 3: Using Carthage
 [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager for Cocoa. To use Carthage, adding the following in your Cartfile:
 
 ```
-github 'SVGKit/SVGKit'
+github "SVGKit/SVGKit"
 ```
 
-It is also recommended that you setup your Cartfile to get SVGKit from this 2.x branch.
+It is also recommended that you setup your Cartfile to get SVGKit from the current version (October 2018: 3.x branch).
 
 ```
-github "SVGKit/SVGKit" "2.x"
+github "SVGKit/SVGKit" "3.x"
 ```
 
-## Build the static library
-
-Until 2016, this was the PREFERRED way of shipping SVGKit.
+## OPTION 4: Build the static library
 
 We have a build script that automatically builds ALL versions of the library at once, and ships them as a single file: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4/3647187#3647187
 
@@ -109,7 +102,7 @@ Everything else is automatic.
 
 ## Usage - OS X
 
-SVG add the support for macOS from SVGKit 2.1.0.
+Added in version 2.1.0 / Autumn 2018: support for macOS.
 
 You can use nearly the same API like iOS. Including `SVGKFastImageView`, `SVGKLayeredImageView`, and you can use `SVGKImage.NSImage` to export SVG layer to bitmap image.
 
@@ -117,7 +110,7 @@ We also provide a macOS demo for SVGKit. To run the Demo, open `Demo-OSX.xcodepr
 
 ## Recipes for using the library
 
-Here are some posts on using SVGKit, with advice on which methods to use and why:
+Here are some old posts (some of these APIs have changed slightly since they were written) on using SVGKit, with advice on which methods to use and why:
 
   - GETTING STARTED, plus NEW FEATURES:  http://t-machine.org/index.php/2012/12/31/svgkit-2013-usage/
   - QUICK RECIPES for common uses:  http://t-machine.org/index.php/2013/01/02/svgkit-2013-recipes/
@@ -125,15 +118,3 @@ Here are some posts on using SVGKit, with advice on which methods to use and why
   - CONTRIBUTING to the project, CORE ARCHITECTURE: http://t-machine.org/index.php/2012/12/31/svgkit-2013-development/
  
   - (November 2013): New (experimental) feature - writing SVG's out to disk, preserving any changes you made programmatically: http://t-machine.org/index.php/2013/11/17/svgkit-programmatic-editing-of-svg-files-on-ios/
-
-
-### I get a crash with "unrecognized selector" ?
-
-If you get this error:
-
-"+[NSCharacterSet SVGWhitespaceCharacterSet]: unrecognized selector sent to class "
-
-... you're probably building the Static Library, but forgot to do the step below:
-
-"Edit your build settings and add "Other Linker Flags" = "-ObjC""
-

+ 1 - 1
Carthage/Checkouts/SVGKit/Source/DOM classes/Core DOM/DOMGlobalSettings.h

@@ -1 +1 @@
-#define DEBUG_DOM_PARSING 0
+#define DEBUG_DOM_PARSING 0

+ 2 - 1
Carthage/Checkouts/SVGKit/Source/DOM classes/SVG-DOM/SVGLength.m

@@ -209,7 +209,8 @@ static float cachedDevicePixelsPerInch;
 	|| [platform hasPrefix:@"iPad5,3"]
     || [platform hasPrefix:@"iPad5,4"]
 	|| [platform hasPrefix:@"iPad6"]
-    || [platform hasPrefix:@"iPad7"])
+    || [platform hasPrefix:@"iPad7"]
+    || [platform hasPrefix:@"iPad8"])
 		return 264.0f;
     
 	if( [platform hasPrefix:@"iPad"]) // catch-all for higher-end devices not yet existing

+ 1 - 1
Carthage/Checkouts/SVGKit/Source/DOM classes/SVG-DOM/SVGNumber.h

@@ -9,4 +9,4 @@
 typedef struct
 {
 	float value;
-} SVGNumber;
+} SVGNumber;

+ 1 - 1
Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGElement.h

@@ -61,4 +61,4 @@
 -(NSString*) cascadedValueForStylableProperty:(NSString*) stylableProperty;
 -(NSString*) cascadedValueForStylableProperty:(NSString*) stylableProperty inherit:(BOOL)inherit;
 
-@end
+@end

+ 17 - 8
Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGElement.m

@@ -481,16 +481,25 @@
     {
         if( element.className != nil )
         {
+            NSScanner *classNameScanner = [NSScanner scannerWithString:element.className];
+            NSMutableCharacterSet *whitespaceAndCommaSet = [NSMutableCharacterSet whitespaceCharacterSet];
+            NSString *substring;
+            
+            [whitespaceAndCommaSet addCharactersInString:@","];
             selector = [selector substringFromIndex:1];
             __block BOOL matched = NO;
-            [element.className enumerateSubstringsInRange:NSMakeRange(0, element.className.length) options:NSStringEnumerationByWords usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop)
-             {
-                 if( [substring isEqualToString:selector] )
-                 {
-                     matched = YES;
-                     *stop = YES;
-                 }
-             }];
+
+            while ([classNameScanner scanUpToCharactersFromSet:whitespaceAndCommaSet intoString:&substring])
+            {
+                if( [substring isEqualToString:selector] )
+                {
+                    matched = YES;
+                    break;
+                }
+				
+                if (!classNameScanner.isAtEnd)
+                    classNameScanner.scanLocation = classNameScanner.scanLocation+1L;
+            }
             if( matched )
             {
                 *specificity += 100;

+ 15 - 5
Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGImageElement.m

@@ -7,6 +7,7 @@
 #import "SVGKImage.h"
 #import "SVGKSourceURL.h"
 #import "SVGKSourceNSData.h"
+#import "SVGKInlineResource.h"
 
 CGImageRef SVGImageCGImage(UIImage *img)
 {
@@ -83,11 +84,15 @@ CGImageRef SVGImageCGImage(UIImage *img)
 	{
 		effectiveSource = [self.rootOfCurrentDocumentFragment.source sourceFromRelativePath:_href];
 		NSInputStream *stream = effectiveSource.stream;
-		[stream open]; // if we do this, we CANNOT parse from this source again in future
-        NSError *error = nil;
-		imageData = [NSData dataWithContentsOfStream:stream initialCapacity:NSUIntegerMax error:&error];
-		if( error )
-			SVGKitLogError(@"[%@] ERROR: unable to read stream from %@ into NSData: %@", [self class], _href, error);
+        if (stream) {
+            [stream open]; // if we do this, we CANNOT parse from this source again in future
+            NSError *error = nil;
+            imageData = [NSData dataWithContentsOfStream:stream initialCapacity:NSUIntegerMax error:&error];
+            if( error )
+                SVGKitLogError(@"[%@] ERROR: unable to read stream from %@ into NSData: %@", [self class], _href, error);
+        } else {
+            SVGKitLogError(@"[%@] ERROR: unable to load the source from URL: %@", [self class], _href);
+        }
 	}
 	
 	/** Now we have some raw bytes, try to load using Apple's image loaders
@@ -125,6 +130,11 @@ CGImageRef SVGImageCGImage(UIImage *img)
                 image = svg.UIImage;
             }
         }
+        
+        // If still fail, use the broken image placeholder
+        if (!image) {
+            image = SVGKGetBrokenImageRepresentation();
+        }
     }
     
 	if( image != nil )

+ 18 - 5
Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGSVGElement.m

@@ -154,6 +154,19 @@
 	NSString* stringWidth = [self getAttribute:@"width"];
 	NSString* stringHeight = [self getAttribute:@"height"];
 	
+    NSString* pos_x = [self getAttribute:@"x"];
+    NSString* pos_y = [self getAttribute:@"y"];
+    
+    if (pos_x == nil || pos_x.length < 1)
+        self.x = 0; // i.e. undefined
+    else
+        self.x = [SVGLength svgLengthFromNSString:pos_x];
+    
+    if (pos_y == nil || pos_y.length < 1)
+        self.y = 0; // i.e. undefined
+    else
+        self.y = [SVGLength svgLengthFromNSString:pos_y];
+    
 	if( stringWidth == nil || stringWidth.length < 1 )
 		self.width = nil; // i.e. undefined
 	else
@@ -177,11 +190,11 @@
 	if( self.height.unitType == SVG_LENGTHTYPE_PERCENTAGE )
 		self.height = nil;
 	
-	/* set the frameRequestedViewport appropriately (NB: spec doesn't allow for this but it REQUIRES it to be done and saved!) */
-	if( self.width != nil && self.height != nil )
-		self.requestedViewport = SVGRectMake( 0, 0, [self.width pixelsValue], [self.height pixelsValue] );
-	else
-		self.requestedViewport = SVGRectUninitialized();
+    /* set the frameRequestedViewport appropriately (NB: spec doesn't allow for this but it REQUIRES it to be done and saved!) */
+    if( self.width != nil && self.height != nil )
+        self.requestedViewport = SVGRectMake( [self.x pixelsValue], [self.y pixelsValue], [self.width pixelsValue], [self.height pixelsValue] );
+    else
+        self.requestedViewport = SVGRectUninitialized();
 	
 	
 	/**

+ 4 - 2
Carthage/Checkouts/SVGKit/Source/DOM classes/Unported or Partial DOM/SVGTextElement.m

@@ -5,6 +5,7 @@
 #import "SVGGradientLayer.h"
 #import "SVGHelperUtilities.h"
 #import "SVGUtils.h"
+#import "SVGTextLayer.h"
 
 @implementation SVGTextElement
 
@@ -27,7 +28,8 @@
 	 
 	 NB: the local bits (x/y offset) have to be pre-transformed by
 	 */
-	CGAffineTransform textTransformAbsoluteWithLocalPositionOffset = CGAffineTransformConcat( CGAffineTransformMakeTranslation( [self.x pixelsValue], [self.y pixelsValue]), textTransformAbsolute);
+    CGRect viewport = CGRectFromSVGRect(self.rootOfCurrentDocumentFragment.viewBox);
+	CGAffineTransform textTransformAbsoluteWithLocalPositionOffset = CGAffineTransformConcat( CGAffineTransformMakeTranslation( [self.x pixelsValueWithDimension:viewport.size.width], [self.y pixelsValueWithDimension:viewport.size.height]), textTransformAbsolute);
 	
 	/**
 	 Apple's CATextLayer is poor - one of those classes Apple hasn't finished writing?
@@ -118,7 +120,7 @@
 											  suggestedUntransformedSize.width,
 											  suggestedUntransformedSize.height); // everything's been pre-scaled by [self transformAbsolute]
 	
-    CATextLayer *label = [[CATextLayer alloc] init];
+    CATextLayer *label = [SVGTextLayer layer];
     [SVGHelperUtilities configureCALayer:label usingElement:self];
 	
 	/** This is complicated for three reasons.

+ 1 - 51
Carthage/Checkouts/SVGKit/Source/Exporters/SVGKImage+CGContext.m

@@ -30,10 +30,7 @@
 
 - (void)renderInContext:(CGContextRef)ctx
 {
-    CALayer *layerTree = self.CALayerTree;
-    [self temporaryWorkaroundPreprocessRenderingLayerTree:layerTree];
-	[layerTree renderInContext:ctx];
-    [self temporaryWorkaroundPostProcessRenderingLayerTree:layerTree];
+	[self.CALayerTree renderInContext:ctx];
 }
 
 /**
@@ -98,51 +95,4 @@
 	SVGKitLogVerbose(@"[%@] renderToContext: time taken to render CALayers to CGContext (perf improvements:%@): %2.3f seconds)", [self class], perfImprovements, -1.0f * [startTime timeIntervalSinceNow] );
 }
 
-/**
- macOS (at least macOS 10.13 still exist) contains bug in `-[CALayer renderInContext:]` method for `CATextLayer` or `CALayer` with CGImage contents
- which will use flipped coordinate system to draw text/image content. However, iOS/tvOS works fine. We have to hack to fix it. :)
- note when using sublayer drawing (`USE_SUBLAYERS_INSTEAD_OF_BLIT` = 1) this issue disappear
-
- @param layerTree layerTree
- */
-- (void)temporaryWorkaroundPreprocessRenderingLayerTree:(CALayer *)layerTree {
-#if SVGKIT_MAC
-    BOOL fixFlip = NO;
-    if ([layerTree isKindOfClass:[CATextLayer class]]) {
-        fixFlip = YES;
-    } else if (layerTree.contents != nil) {
-        fixFlip = YES;
-    }
-    if (fixFlip) {
-        // Hack to apply flip for content
-        NSAffineTransform *flip = [NSAffineTransform transform];
-        [flip translateXBy:0 yBy:layerTree.bounds.size.height];
-        [flip scaleXBy:1.0 yBy:-1.0];
-        [layerTree setValue:flip forKey:@"contentsTransform"];
-    }
-    for (CALayer *layer in layerTree.sublayers) {
-        [self temporaryWorkaroundPreprocessRenderingLayerTree:layer];
-    }
-#endif
-}
-
-- (void)temporaryWorkaroundPostProcessRenderingLayerTree:(CALayer *)layerTree {
-#if SVGKIT_MAC
-    BOOL fixFlip = NO;
-    if ([layerTree isKindOfClass:[CATextLayer class]]) {
-        fixFlip = YES;
-    } else if (layerTree.contents != nil) {
-        fixFlip = YES;
-    }
-    if (fixFlip) {
-        // Hack to recover flip for content
-        NSAffineTransform *flip = [NSAffineTransform transform];
-        [layerTree setValue:flip forKey:@"contentsTransform"];
-    }
-    for (CALayer *layer in layerTree.sublayers) {
-        [self temporaryWorkaroundPostProcessRenderingLayerTree:layer];
-    }
-#endif
-}
-
 @end

+ 1 - 1
Carthage/Checkouts/SVGKit/Source/Foundation additions/NSData+NSInputStream.h

@@ -17,4 +17,4 @@
  */
 +(NSData*)dataWithContentsOfStream:(NSInputStream*)input initialCapacity:(NSUInteger)capacity error:(NSError **)error;
 
-@end
+@end

+ 7 - 1
Carthage/Checkouts/SVGKit/Source/Foundation additions/NSData+NSInputStream.m

@@ -16,6 +16,12 @@
 
 
 +(NSData *)dataWithContentsOfStream:(NSInputStream *)input initialCapacity:(NSUInteger)capacity error:(NSError **)error {
+    if (!input) {
+        if (error) {
+            *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOENT userInfo:nil];
+        }
+        return nil;
+    }
     size_t bufsize = MIN(BUFSIZE, capacity);
     uint8_t * buf = malloc(bufsize);
     if (buf == NULL) {
@@ -57,4 +63,4 @@
 }
 
 
-@end
+@end

+ 15 - 20
Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserGradient.m

@@ -16,24 +16,25 @@
 #import "SVGLinearGradientElement.h"
 #import "SVGRadialGradientElement.h"
 
+@interface SVGKParserGradient ()
+@property (nonatomic) NSArray *supportedNamespaces;
+@property (nonatomic) NSArray *supportedTags;
+@end
+
 @implementation SVGKParserGradient
 
-//-(NSSet*) supportedNamespaces
-//{
-//    if( self->_supportedNamespaces == nil )
-//        self->_supportedNamespaces = [[NSSet alloc] initWithObjects:
-//                        @"http://www.w3.org/2000/svg",
-//                        nil];
-//	return self->_supportedNamespaces;
-//}
+-(NSArray *)supportedNamespaces
+{
+    if( _supportedNamespaces == nil )
+        _supportedNamespaces = @[@"http://www.w3.org/2000/svg"];
+    return _supportedNamespaces;
+}
 
-static NSSet *_svgGradientParserSupportedTags = nil;
--(NSSet *)supportedTags
+-(NSArray *)supportedTags
 {
-//    static NSSet *supportedTags = nil;
-    if( _svgGradientParserSupportedTags == nil )
-        _svgGradientParserSupportedTags = [[NSSet alloc] initWithObjects:@"linearGradient", @"radialGradient", @"stop", nil];
-    return _svgGradientParserSupportedTags;
+    if( _supportedTags == nil )
+        _supportedTags = @[@"linearGradient", @"radialGradient", @"stop"];
+    return _supportedTags;
 }
 
 -(Node *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(Node *)parentNode
@@ -97,12 +98,6 @@ static NSSet *_svgGradientParserSupportedTags = nil;
 //}
 
 
-+(void)trim
-{
-    _svgGradientParserSupportedTags = nil;
-}
-
-
 @end
 
 

+ 33 - 35
Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserSVG.m

@@ -21,57 +21,55 @@
 
 #import "SVGDocument_Mutable.h"
 
-@implementation SVGKParserSVG
+@interface SVGKParserSVG ()
+@property (nonatomic) NSArray *supportedNamespaces;
+@property (nonatomic) NSDictionary *elementMap;
+@end
 
-static NSDictionary *elementMap;
+@implementation SVGKParserSVG
 
-- (id)init {
-	self = [super init];
-	if (self) {
-		
-		if (!elementMap) {
-			elementMap = [NSDictionary dictionaryWithObjectsAndKeys:
-						   [SVGSVGElement class], @"svg",
-                          [SVGCircleElement class], @"circle",
-                          [SVGDescriptionElement class], @"description",
-                          [SVGEllipseElement class], @"ellipse",
-                          [SVGGElement class], @"g",
-                          [SVGClipPathElement class], @"clipPath",
-                          [SVGImageElement class], @"image",
-                          [SVGLineElement class], @"line",
-                          [SVGPathElement class], @"path",
-                          [SVGPolygonElement class], @"polygon",
-                          [SVGPolylineElement class], @"polyline",
-                          [SVGRectElement class], @"rect",
-                          [SVGSwitchElement class], @"switch",
-                          [SVGTitleElement class], @"title",
-                          [SVGTextElement class], @"text",
-                          [TinySVGTextAreaElement class], @"textArea",
-						   nil];
-		}
-	}
-	return self;
+- (NSDictionary *)elementMap {
+    if (!_elementMap) {
+        _elementMap = [NSDictionary dictionaryWithObjectsAndKeys:
+                      [SVGSVGElement class], @"svg",
+                      [SVGCircleElement class], @"circle",
+                      [SVGDescriptionElement class], @"description",
+                      [SVGEllipseElement class], @"ellipse",
+                      [SVGGElement class], @"g",
+                      [SVGClipPathElement class], @"clipPath",
+                      [SVGImageElement class], @"image",
+                      [SVGLineElement class], @"line",
+                      [SVGPathElement class], @"path",
+                      [SVGPolygonElement class], @"polygon",
+                      [SVGPolylineElement class], @"polyline",
+                      [SVGRectElement class], @"rect",
+                      [SVGSwitchElement class], @"switch",
+                      [SVGTitleElement class], @"title",
+                      [SVGTextElement class], @"text",
+                      [TinySVGTextAreaElement class], @"textArea",
+                      nil];
+    }
+    return _elementMap;
 }
 
-
--(NSArray*) supportedNamespaces
+-(NSArray *)supportedNamespaces
 {
-	return [NSArray arrayWithObjects:
-			 @"http://www.w3.org/2000/svg",
-			nil];
+    if( _supportedNamespaces == nil )
+        _supportedNamespaces = @[@"http://www.w3.org/2000/svg"];
+    return _supportedNamespaces;
 }
 
 /** "tags supported" is exactly the set of all SVGElement subclasses that already exist */
 -(NSArray*) supportedTags
 {
-	return [NSMutableArray arrayWithArray:[elementMap allKeys]];
+    return [self.elementMap allKeys];
 }
 
 - (Node*) handleStartElement:(NSString *)name document:(SVGKSource*) SVGKSource namePrefix:(NSString*)prefix namespaceURI:(NSString*) XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(Node*) parentNode
 {
 	if( [[self supportedNamespaces] containsObject:XMLNSURI] )
 	{
-		Class elementClass = [elementMap objectForKey:name];
+		Class elementClass = [self.elementMap objectForKey:name];
 		
 		if (!elementClass) {
 			elementClass = [SVGElement class];

+ 13 - 21
Carthage/Checkouts/SVGKit/Source/Parsers/Parser Extensions/SVGKParserStyles.m

@@ -11,25 +11,25 @@
 #import "CSSStyleSheet.h"
 #import "StyleSheetList+Mutable.h"
 
-@implementation SVGKParserStyles
+@interface SVGKParserStyles ()
+@property (nonatomic) NSArray *supportedNamespaces;
+@property (nonatomic) NSArray *supportedTags;
+@end
 
+@implementation SVGKParserStyles
 
-static NSSet *_svgParserStylesSupportedNamespaces = nil;
--(NSSet *) supportedNamespaces
+-(NSArray *)supportedNamespaces
 {
-    if( _svgParserStylesSupportedNamespaces == nil )
-        _svgParserStylesSupportedNamespaces = [[NSSet alloc] initWithObjects:
-        @"http://www.w3.org/2000/svg",
-        nil];
-	return _svgParserStylesSupportedNamespaces;
+    if( _supportedNamespaces == nil )
+        _supportedNamespaces = @[@"http://www.w3.org/2000/svg"];
+    return _supportedNamespaces;
 }
 
-static NSSet *_svgParserStylesSupportedTags = nil;
--(NSSet *)supportedTags
+-(NSArray *)supportedTags
 {
-    if( _svgParserStylesSupportedTags == nil )
-        _svgParserStylesSupportedTags = [[NSSet alloc] initWithObjects:@"style", nil];
-    return _svgParserStylesSupportedTags;
+    if( _supportedTags == nil )
+        _supportedTags = @[@"style"];
+    return _supportedTags;
 }
 
 -(Node *)handleStartElement:(NSString *)name document:(SVGKSource *)document namePrefix:(NSString *)prefix namespaceURI:(NSString *)XMLNSURI attributes:(NSMutableDictionary *)attributes parseResult:(SVGKParseResult *)parseResult parentNode:(Node *)parentNode
@@ -71,12 +71,4 @@ static NSSet *_svgParserStylesSupportedTags = nil;
 
 }
 
-
-+(void)trim
-{
-    _svgParserStylesSupportedTags = nil;
-    
-    _svgParserStylesSupportedNamespaces = nil;
-}
-
 @end

+ 5 - 1
Carthage/Checkouts/SVGKit/Source/Parsers/SVGKPointsAndPathsParser.m

@@ -854,7 +854,11 @@ static inline CGPoint SVGCurveReflectedControlPoint(SVGCurve prevCurve)
 		
 		numerator = MAX(0, numerator);
 		
-		lhs = sign * sqrt(numerator/denom);
+        if (denom == 0) {
+            lhs = 0;
+         }else {
+             lhs = sign * sqrt(numerator/denom);
+         }
 	}
 	
 	CGFloat cxp = lhs * (rx*y1p)/ry;

+ 18 - 0
Carthage/Checkouts/SVGKit/Source/QuartzCore additions/CALayerWithClipRender.m

@@ -8,6 +8,12 @@
 
 #import "CALayerWithClipRender.h"
 
+@interface CALayer (ContentsTransform)
+
+@property CGAffineTransform contentsTransform;
+
+@end
+
 @implementation CALayerWithClipRender
 
 - (void)renderInContext:(CGContextRef)ctx {
@@ -19,7 +25,19 @@
         self.mask = nil;
     }
     
+    // We use the flipped coordinate system on macOS, to match the behavior of iOS. However, the `contents` (which is a CGImageRef) bitmap provided by image element is not been flipped as we want. The `renderInContext:` which used by `SVGKFastImageView` will not correct this coordinate system issue, only `SVGKLayeredImageView` do. So we use the `contentsTransform` to manually fix it.
+#if SVGKIT_MAC
+    // If already flipped, which should be handled by Core Animation itself, ignore
+    if (self.contentsAreFlipped) {
+        [super renderInContext:ctx];
+    } else {
+        self.contentsTransform = CGAffineTransformMake(1, 0, 0, -1, 0, self.bounds.size.height);
+        [super renderInContext:ctx];
+        self.contentsTransform = CGAffineTransformIdentity;
+    }
+#else
     [super renderInContext:ctx];
+#endif
     
     if( mask != nil ) {
         self.mask = mask;

+ 3 - 0
Carthage/Checkouts/SVGKit/Source/SVGKImage.h

@@ -88,7 +88,9 @@ typedef void (^SVGKImageAsynchronousLoadingDelegate)(SVGKImage* loadedImage, SVG
  - Creates an SVGKSource so that you can later inspect exactly where it found the file
  */
 + (SVGKImage *)imageNamed:(NSString *)name;
++ (SVGKImage *)imageNamed:(NSString *)name withCacheKey:(NSString *)key;
 + (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
++ (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle withCacheKey:(NSString *)key;
 /**
  Almost identical to imageNamed: except that it performs the parse in a separate thread.
  
@@ -310,5 +312,6 @@ typedef void (^SVGKImageAsynchronousLoadingDelegate)(SVGKImage* loadedImage, SVG
 
 /** alters the SVG image's size directly (by changing the viewport) so that it will fit inside the specifed area without stretching or deforming */
 -(void) scaleToFitInside:(CGSize) maxSize;
++(void) clearCache;
 
 @end

+ 25 - 11
Carthage/Checkouts/SVGKit/Source/SVGKImage.m

@@ -81,27 +81,46 @@ static NSMutableDictionary* globalSVGKImageCache;
 	}
 }
 
-+(void) didReceiveMemoryWarningOrBackgroundNotification:(NSNotification*) notification
-{
++(void) clearCache {
 	if ([globalSVGKImageCache count] == 0) return;
 	
-	SVGKitLogWarn(@"[%@] Low-mem or background; purging cache of %lu SVGKImages...", self, (unsigned long)[globalSVGKImageCache count] );
+	SVGKitLogWarn(@"[%@] Low-mem, background or api clear; purging cache of %lu SVGKImages...", self, (unsigned long)[globalSVGKImageCache count] );
 	
 	[globalSVGKImageCache removeAllObjects]; // once they leave the cache, if they are no longer referred to, they should automatically dealloc
 }
+
++(void) didReceiveMemoryWarningOrBackgroundNotification:(NSNotification*) notification
+{
+	[self clearCache];
+}
 #endif
 
 #pragma mark - Convenience initializers
++ (SVGKImage *)imageNamed:(NSString *)name
+{
+    return [self imageNamed:name inBundle:[NSBundle mainBundle] withCacheKey:@""];
+}
+
++ (SVGKImage *)imageNamed:(NSString *)name withCacheKey:(NSString *)key
+{
+    return [self imageNamed:name inBundle:[NSBundle mainBundle] withCacheKey:key];
+}
 
 + (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle
+{
+     return [self imageNamed:name inBundle:[NSBundle mainBundle] withCacheKey:@""];
+}
+
++ (SVGKImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle withCacheKey:(NSString *)key
 {	
 #if ENABLE_GLOBAL_IMAGE_CACHE_FOR_SVGKIMAGE_IMAGE_NAMED
+    NSString* cacheName = [key length] > 0 ? key : name;
     if( globalSVGKImageCache == nil )
     {
         globalSVGKImageCache = [NSMutableDictionary new];
     }
     
-    SVGKImageCacheLine* cacheLine = [globalSVGKImageCache valueForKey:name];
+    SVGKImageCacheLine* cacheLine = [globalSVGKImageCache valueForKey:cacheName];
     if( cacheLine != nil )
     {
         cacheLine.numberOfInstances ++;
@@ -120,12 +139,12 @@ static NSMutableDictionary* globalSVGKImageCache;
 	if( result != nil )
 	{
     result->cameFromGlobalCache = TRUE;
-    result.nameUsedToInstantiate = name;
+    result.nameUsedToInstantiate = cacheName;
     
     SVGKImageCacheLine* newCacheLine = [[SVGKImageCacheLine alloc] init];
     newCacheLine.mainInstance = result;
     
-    [globalSVGKImageCache setValue:newCacheLine forKey:name];
+    [globalSVGKImageCache setValue:newCacheLine forKey:cacheName];
 	}
 	else
 	{
@@ -136,11 +155,6 @@ static NSMutableDictionary* globalSVGKImageCache;
     return result;
 }
 
-+ (SVGKImage *)imageNamed:(NSString *)name
-{
-    return [self imageNamed:name inBundle:[NSBundle mainBundle]];
-}
-
 +(SVGKParser *) imageAsynchronouslyNamed:(NSString *)name onCompletion:(SVGKImageAsynchronousLoadingDelegate)blockCompleted
 {
 	return [self imageWithSource:[SVGKSourceLocalFile internalSourceAnywhereInBundleUsingName:name] onCompletion:blockCompleted];

+ 2 - 0
Carthage/Checkouts/SVGKit/Source/SVGKit.h

@@ -155,6 +155,7 @@ FOUNDATION_EXPORT const unsigned char SVGKitFramework_VersionString[];
 #import "SVGKPointsAndPathsParser.h"
 #import "CALayer+RecursiveClone.h"
 #import "SVGGradientLayer.h"
+#import "SVGTextLayer.h"
 #import "CALayerWithChildHitTest.h"
 #import "CAShapeLayerWithHitTest.h"
 #import "CGPathAdditions.h"
@@ -172,3 +173,4 @@ FOUNDATION_EXPORT const unsigned char SVGKitFramework_VersionString[];
 #endif
 #import "NSData+NSInputStream.h"
 #import "SVGKSourceNSData.h"
+#import "SVGKInlineResource.h"

+ 8 - 2
Carthage/Checkouts/SVGKit/Source/Sources/SVGKSourceURL.m

@@ -9,6 +9,9 @@
 
 + (SVGKSource*)sourceFromURL:(NSURL*)u {
 	NSInputStream* stream = [self internalCreateInputStreamFromURL:u];
+    if (!stream) {
+        return nil;
+    }
 	
 	SVGKSourceURL* s = [[SVGKSourceURL alloc] initWithInputSteam:stream];
 	s.URL = u;
@@ -16,8 +19,11 @@
 	return s;
 }
 
-+(NSInputStream*) internalCreateInputStreamFromURL:(NSURL*) u
++(nullable NSInputStream*) internalCreateInputStreamFromURL:(nullable NSURL*) u
 {
+    if (!u) {
+        return nil;
+    }
 	NSInputStream* stream = [NSInputStream inputStreamWithURL:u];
 	
 	if( stream == nil )
@@ -31,7 +37,7 @@
 		
 		if( tempData == nil )
 		{
-			@throw [NSException exceptionWithName:@"NSDataCrashed" reason:[NSString stringWithFormat:@"Error internally in Apple's NSData trying to read from URL '%@'. Error = %@", u, errorWithNSData] userInfo:@{NSLocalizedDescriptionKey:errorWithNSData}];
+            SVGKitLogError(@"Error internally in Apple's NSData trying to read from URL '%@'. Error = %@", u, errorWithNSData);
 		}
 		else
 			stream = [[NSInputStream alloc] initWithData:tempData];

+ 4 - 7
Carthage/Checkouts/SVGKit/Source/UIKit additions/SVGKFastImageView.m

@@ -39,12 +39,7 @@
 	self = [super initWithFrame:frame];
 	if( self )
 	{
-#if SVGKIT_UIKIT
-		self.backgroundColor = [UIColor clearColor];
-#else
-        self.layer.backgroundColor = [NSColor clearColor].CGColor;
-#endif
-        
+        [self populateFromImage:nil];
 	}
 	return self;
 }
@@ -118,8 +113,10 @@
 -(void) removeInternalRedrawOnResizeObservers
 {
   if (!self.didRegisterInternalRedrawObservers) return;
-	[self removeObserver:self  forKeyPath:@"layer" context:(__bridge void * _Nullable)(internalContextPointerBecauseApplesDemandsIt)];
+	[self removeObserver:self forKeyPath:@"layer" context:(__bridge void * _Nullable)(internalContextPointerBecauseApplesDemandsIt)];
+#if !SVGKIT_MAC || USE_SUBLAYERS_INSTEAD_OF_BLIT
 	[self.layer removeObserver:self forKeyPath:@"transform" context:(__bridge void * _Nullable)(internalContextPointerBecauseApplesDemandsIt)];
+#endif
   self.didRegisterInternalRedrawObservers = false;
 }
 

Plik diff jest za duży
+ 2 - 8
Carthage/Checkouts/SVGKit/Source/UIKit additions/SVGKLayeredImageView.m


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików