diff --git a/README.md b/README.md index e2a3807..e649d53 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ +![](https://github.com/sushihangover/SVGKit.Binding/raw/master/Media/icon.png) -#SushiHangover.SVGKit +# SushiHangover.SVGKit This is a `Xamarin.iOS` binding project for `SVGKit` * SVGKit v2.x - live development, latest fixes/features * Xamarin.iOS Version: 10.4.0.4 -* Xcode 8.1 (11544) Build 8B62 +* Xcode Version 9.0 (9A235) -##SVGKit +## SVGKit >SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki @@ -15,19 +16,19 @@ Ref: [https://github.com/SVGKit/SVGKit](https://github.com/SVGKit/SVGKit) License : [https://github.com/SVGKit/SVGKit/blob/2.x/LICENSE](https://github.com/SVGKit/SVGKit/blob/2.x/LICENSE) -##Nuget: +## Nuget: `PM> Install-Package SushiHangover.SVGKit.Binding` Ref: [https://www.nuget.org/packages/SushiHangover.SVGKit.Binding](https://www.nuget.org/packages/SushiHangover.SVGKit.Binding) -##Issues? +## Issues? ###Binding Issues? [GitHub Issues](https://github.com/sushihangover/SVGKit.Binding/issues) -###SVGKit Library? [GitHub Issues](https://github.com/SVGKit/SVGKit/issues) +### SVGKit Library? [GitHub Issues](https://github.com/SVGKit/SVGKit/issues) -##Need Help? +## Need Help? Post general `SVGKit` questions on [StackOverflow](http://stackoverflow.com/questions/tagged/ios+svgkit) @@ -37,15 +38,15 @@ Specfic `Xamarin.iOS` & `SVGKit` questions on [StackOverflow] (http://stackoverf Tagged: **`[XAMARIN]`** **`[SVGKit]`** **`[Xamarin.iOS]`** **`[iOS]`** -##Usage: +## Usage: -###Namespace: `SVGKit` +### Namespace: `SVGKit` using SVGKit; -###Load SVG from a Bundle Resource +### Load SVG from a Bundle Resource -####Build action: `BundleResource` +#### Build action: `BundleResource` var image = new SVGKImage("Media/Sushi.svg"); var imageView = new SVGKFastImageView(image); @@ -54,9 +55,9 @@ Tagged: **`[XAMARIN]`** **`[SVGKit]`** **`[Xamarin.iOS]`** **`[iOS]`** ![](Media/SimulatorScreen.png) -###Load SVG from a Bundle Path +### Load SVG from a Bundle Path -####Build action: `Content` +#### Build action: `Content` var image = new SVGKImage(Path.Combine(NSBundle.MainBundle.BundlePath, "Media/Joker.svg")); var imageView = new SVGKFastImageView(image); @@ -65,20 +66,20 @@ Tagged: **`[XAMARIN]`** **`[SVGKit]`** **`[Xamarin.iOS]`** **`[iOS]`** ![](Media/SimulatorScreen2.png) -##Build: +## Build: -###Building `SushiHangover.SVGKit.Binding` +### Building `SushiHangover.SVGKit.Binding` -#####`xbuild` or `msbuild` based: +##### `msbuild` based: - xbuild /p:SolutionDir=./ /target:Clean /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj - xbuild /p:SolutionDir=./ /target:Build /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj + msbuild /p:SolutionDir=./ /target:Clean /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj + msbuild /p:SolutionDir=./ /target:Build /p:Configuration=Release SushiHangover.SVGKit/SushiHangover.SVGKit.csproj -#####Building `Target:Release` also builds the Nuget package: +##### Building `Target:Release` also builds the Nuget package: bin/Release/SushiHangover.SVGKit.Binding.1.x.x.nupkg -###Building a static `SVGKit` library: +### Building a static `SVGKit` library: pushd SVGKit xcodebuild -project SVGKit-iOS.xcodeproj clean @@ -89,14 +90,14 @@ Tagged: **`[XAMARIN]`** **`[SVGKit]`** **`[Xamarin.iOS]`** **`[iOS]`** **Note:** The output from xcrun/lipo should contain `armv7`, `arm64` and `x86_64` -##Binding Info: +## Binding Info: ###Xamarin Binding Guide [Binding Objective-C](https://developer.xamarin.com/guides/cross-platform/macios/binding/) -###Sharpie +### Sharpie sharpie -tlm-do-not-submit bind --output=SushiHangover.SVGKit --namespace=SushiHangover.SVGKit --sdk=iphoneos10.1 ./SVGKit/build/Release-universal/usr/local/include/*.h diff --git a/SVGKit b/SVGKit index 29b55f9..8949b61 160000 --- a/SVGKit +++ b/SVGKit @@ -1 +1 @@ -Subproject commit 29b55f9846b11d27fb22cf0ad164a4025de12c34 +Subproject commit 8949b61e7ae25529678e34a548288cc838061674 diff --git a/SVGKit.SampleApp/ViewController.cs b/SVGKit.SampleApp/ViewController.cs index a1e8e98..a413c94 100644 --- a/SVGKit.SampleApp/ViewController.cs +++ b/SVGKit.SampleApp/ViewController.cs @@ -1,39 +1,88 @@ using System; using UIKit; using SushiHangover.SVGKit; +using CoreAnimation; +using CoreGraphics; +using CoreFoundation; +using Foundation; namespace SVGKit.SampleApp { - public partial class ViewController : UIViewController - { - protected ViewController(IntPtr handle) : base(handle) - { - // Note: this .ctor should not contain any initialization logic. - } - - public override void ViewDidLoad() - { - base.ViewDidLoad(); - - var image = new SVGKImage("Media/Sushi.svg"); - var imageView = new SVGKFastImageView(image); - imageView.Frame = View.Frame; - View.Add(imageView); - } - - public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() - { - return UIInterfaceOrientationMask.LandscapeLeft; - } - - public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() - { - return UIInterfaceOrientation.LandscapeLeft; - } - - public override bool ShouldAutorotate() - { - return false; - } - } + public static class Extension + { + public static UIColor Inverse(this UIColor color) + { + try + { + var cgcolor = color.CGColor; + if (cgcolor.NumberOfComponents == 1) + return color; + + var comps = cgcolor.Components; + var newComps = new nfloat[comps.Length]; + var i = comps.Length - 1; + newComps[i] = comps[i]; + while (i-- > -0) + { + newComps[i] = 1 - comps[i]; + } + using (var newCGColor = new CGColor(cgcolor.ColorSpace, newComps)) + { + var newUIColor = UIColor.FromCGColor(newCGColor); + return newUIColor; + } + } + catch + { + return UIColor.Black; + } + } + } + + public partial class ViewController : UIViewController + { + NSTimer timer; + + protected ViewController(IntPtr handle) : base(handle) + { + // Note: this .ctor should not contain any initialization logic. + } + + public override void ViewDidLoad() + { + base.ViewDidLoad(); + + void RecurseLayers(CALayer[] layers) + { + foreach (var layer in layers) + { + if (layer is CAShapeLayer && (layer as CAShapeLayer).FillColor != null) + (layer as CAShapeLayer).FillColor = UIColor.FromCGColor((layer as CAShapeLayer).FillColor).Inverse().CGColor; + if (layer.Sublayers != null) + RecurseLayers(layer.Sublayers); + } + } + //var imageView = new SVGKLayeredImageView(new SVGKImage("Media/Sushi.svg")); + var imageView = new SVGKFastImageView(new SVGKImage("Media/Sushi.svg")); + imageView.Frame = View.Bounds; + View.Add(imageView); + //timer = NSTimer.CreateRepeatingScheduledTimer(2, (_) => InvokeOnMainThread(() => RecurseLayers(imageView.Layer.Sublayers))); + } + + + public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() + { + return UIInterfaceOrientationMask.LandscapeLeft; + } + + public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation() + { + return UIInterfaceOrientation.LandscapeLeft; + } + + public override bool ShouldAutorotate() + { + return false; + } + } } diff --git a/SushiHangover.SVGKit/Additions/SVGKLayeredImageView.cs b/SushiHangover.SVGKit/Additions/SVGKLayeredImageView.cs new file mode 100644 index 0000000..e2aec78 --- /dev/null +++ b/SushiHangover.SVGKit/Additions/SVGKLayeredImageView.cs @@ -0,0 +1,59 @@ +using System; +using System; +using System.Drawing; +using System.Diagnostics; +using System.ComponentModel; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +using UIKit; +using GLKit; +using Metal; +using MapKit; +using Photos; +using ModelIO; +using SceneKit; +using Contacts; +using Security; +using Messages; +using AudioUnit; +using CoreVideo; +using CoreMedia; +using QuickLook; +using CoreImage; +using SpriteKit; +using Foundation; +using CoreMotion; +using ObjCRuntime; +using AddressBook; +using MediaPlayer; +using GameplayKit; +using CoreGraphics; +using CoreLocation; +using AVFoundation; +using NewsstandKit; +using FileProvider; +using CoreAnimation; +using CoreFoundation; + +namespace SushiHangover.SVGKit +{ + public unsafe partial class SVGKLayeredImageView : SVGKImageView + { + [Export("initWithSVGKImage:")] + public SVGKLayeredImageView(SVGKImage im) : base (im) + { + if (im == null) + throw new ArgumentNullException("im"); + IsDirectBinding = GetType().Assembly == global::ApiDefinitions.Messaging.this_assembly; + if (IsDirectBinding) + { + InitializeHandle(global::ApiDefinitions.Messaging.IntPtr_objc_msgSend_IntPtr(this.Handle, Selector.GetHandle("initWithSVGKImage:"), im.Handle), "initWithSVGKImage:"); + } + else + { + InitializeHandle(global::ApiDefinitions.Messaging.IntPtr_objc_msgSendSuper_IntPtr(this.SuperHandle, Selector.GetHandle("initWithSVGKImage:"), im.Handle), "initWithSVGKImage:"); + } + } + } +} diff --git a/SushiHangover.SVGKit/ApiDefinitions.cs b/SushiHangover.SVGKit/ApiDefinitions.cs index 1fc70ce..7475ac1 100644 --- a/SushiHangover.SVGKit/ApiDefinitions.cs +++ b/SushiHangover.SVGKit/ApiDefinitions.cs @@ -1056,7 +1056,7 @@ interface IDocumentStyle } // @protocol DocumentCSS - [Protocol, Model] + [Protocol] interface IDocumentCSS : IDocumentStyle { // @required -(CSSStyleDeclaration *)getOverrideStyle:(Element *)element pseudoElt:(NSString *)pseudoElt; @@ -1096,7 +1096,7 @@ interface MediaList interface NSCharacterSet_SVGKExtensions { // +(NSCharacterSet *)SVGWhitespaceCharacterSet; - [Static] + //[Static] [Export("SVGWhitespaceCharacterSet")] //[Verify (MethodToProperty)] NSCharacterSet SVGWhitespaceCharacterSet(); @@ -2478,7 +2478,7 @@ interface SVGKPattern // @interface SVGKLayeredImageView : SVGKImageView [BaseType (typeof(SVGKImageView))] - interface SVGKLayeredImageView + interface SVGKLayeredImageView : SVGKImageView { } diff --git a/SushiHangover.SVGKit/SVGKit.nuspec b/SushiHangover.SVGKit/SVGKit.nuspec index b723ac8..27d3e3c 100644 --- a/SushiHangover.SVGKit/SVGKit.nuspec +++ b/SushiHangover.SVGKit/SVGKit.nuspec @@ -2,13 +2,13 @@ SushiHangover.SVGKit.Binding - 1.0.3 + 1.0.4 This is a Xamarin.iOS binding project for SVGKit v2.x SushiHangover.SVGKit.Binding en-US - 2016 - SushiHangover/RobertN + 2016/2017 - SushiHangover/RobertN SushiHangover https://github.com/sushihangover/SVGKit.Binding https://raw.githubusercontent.com/sushihangover/SVGKit.Binding/master/Media/icon.png diff --git a/SushiHangover.SVGKit/SushiHangover.SVGKit.csproj b/SushiHangover.SVGKit/SushiHangover.SVGKit.csproj index 997e1fd..438202c 100644 --- a/SushiHangover.SVGKit/SushiHangover.SVGKit.csproj +++ b/SushiHangover.SVGKit/SushiHangover.SVGKit.csproj @@ -36,6 +36,7 @@ + @@ -45,7 +46,7 @@ - + Static True CocoaLumberjack CoreText CoreImage QuartzCore CoreGraphics @@ -59,6 +60,9 @@ + + + \ No newline at end of file