Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGKLayeredImageView .actor missing Issue #5 #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
![](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

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)

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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

Expand Down
113 changes: 81 additions & 32 deletions SVGKit.SampleApp/ViewController.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
59 changes: 59 additions & 0 deletions SushiHangover.SVGKit/Additions/SVGKLayeredImageView.cs
Original file line number Diff line number Diff line change
@@ -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:");
}
}
}
}
6 changes: 3 additions & 3 deletions SushiHangover.SVGKit/ApiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ interface IDocumentStyle
}

// @protocol DocumentCSS <DocumentStyle>
[Protocol, Model]
[Protocol]
interface IDocumentCSS : IDocumentStyle
{
// @required -(CSSStyleDeclaration *)getOverrideStyle:(Element *)element pseudoElt:(NSString *)pseudoElt;
Expand Down Expand Up @@ -1096,7 +1096,7 @@ interface MediaList
interface NSCharacterSet_SVGKExtensions
{
// +(NSCharacterSet *)SVGWhitespaceCharacterSet;
[Static]
//[Static]
[Export("SVGWhitespaceCharacterSet")]
//[Verify (MethodToProperty)]
NSCharacterSet SVGWhitespaceCharacterSet();
Expand Down Expand Up @@ -2478,7 +2478,7 @@ interface SVGKPattern

// @interface SVGKLayeredImageView : SVGKImageView
[BaseType (typeof(SVGKImageView))]
interface SVGKLayeredImageView
interface SVGKLayeredImageView : SVGKImageView
{
}

Expand Down
4 changes: 2 additions & 2 deletions SushiHangover.SVGKit/SVGKit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<package>
<metadata>
<id>SushiHangover.SVGKit.Binding</id>
<version>1.0.3</version>
<version>1.0.4</version>
<description>
This is a Xamarin.iOS binding project for SVGKit v2.x
</description>
<title>SushiHangover.SVGKit.Binding</title>
<language>en-US</language>
<copyright>2016 - SushiHangover/RobertN</copyright>
<copyright>2016/2017 - SushiHangover/RobertN</copyright>
<authors>SushiHangover</authors>
<projectUrl>https://github.com/sushihangover/SVGKit.Binding</projectUrl>
<iconUrl>https://raw.githubusercontent.com/sushihangover/SVGKit.Binding/master/Media/icon.png</iconUrl>
Expand Down
6 changes: 5 additions & 1 deletion SushiHangover.SVGKit/SushiHangover.SVGKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Additions\SVGKLayeredImageView.cs" />
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
Expand All @@ -45,7 +46,7 @@
<ObjcBindingCoreSource Include="Extras.cs" />
</ItemGroup>
<ItemGroup>
<NativeReference Include="..\SVGKit\DerivedData\SVGKit-iOS\Build\Products\Release-universal\libSVGKit-iOS.2.0.0.a">
<NativeReference Include="..\SVGKit/build/Release-universal/libSVGKit-iOS.2.0.0.a">
<Kind>Static</Kind>
<ForceLoad>True</ForceLoad>
<Frameworks>CocoaLumberjack CoreText CoreImage QuartzCore CoreGraphics</Frameworks>
Expand All @@ -59,6 +60,9 @@
<ItemGroup>
<None Include="SVGKit.nuspec" />
</ItemGroup>
<ItemGroup>
<Folder Include="Additions\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
<Import Project="..\.nuget\NuGet.targets" Condition="Exists('..\.nuget\NuGet.targets')" />
</Project>