Code Monkey home page Code Monkey logo

svgkit's Introduction

SVGKit

SVGKit is a Cocoa framework for rendering SVG files as Core Animation layers. All shapes are represented by instances of the CAShapeLayer class, and are, by design, animatable. SVGKit works on OS X and iOS.

PLEASE DO NOT USE THIS BRANCH - USE THE 2013base BRANCH INSTEAD.

Direct link to 2013base: https://github.com/SVGKit/SVGKit/tree/2013base

(we are in the process of upgrading everything to the 2013base branch. When all the bugs are fixed, that branch WILL OVERWRITE THIS BRANCH)

Note: 2013base is NOT BACKWARDS COMPATIBLE (lots of the bugs were to do with violations of the SVG Spec, and it's not possible to maintain backwards compatibility)

PLEASE CONVERT YOUR CODE TO THE 2013base BRANCH NOW, AND LOG ANY ISSUES YOU FIND ASAP!

Xcode Projects Included

  • SVGKit - the core library, builds the frameworks, also runs a shell script to build a fat lib
  • SVGPadDemo - demo using the core libs on iOS
  • SVGTesterDemo - demo + test app that uses core libs on OSX

Fetching

git clone <svgkit url>

# if you want to export CALayers using the iPad project....
cd SVGKit/
git submodule init
git submodule update

Without the git submodules, the iOS test project will fail to compile. You don't need the calayer exporter to use SVGKit, it's just something nice for debugging in the simulator. If you don't care about that, you don't need them.

iOS

iOS support is robust. The development team uses iOS as the primary target.

Desktop

Desktop support is... not quite as robust. You may find many places things fail or break entirely. We try to keep up with it, and we appreciate any help we can get.

Cross Platform Library Build

To build a single library that can be linked from the simulator and from a device, you'll need to do these steps:

  1. Open the project "XcodeProjects/SVGKit/SVGKit"
  2. Select the target "SVGKit Library > iOS Device" scheme selector dropdown in the top left
  3. In the main content area, select the "Build Phases" tab, expand the "Run Script" step, and make sure "Run script only when installing" is not checked.
  4. Build
  5. Select Window > Organizer > Projects > SVGKit, then follow the link arrow to the "Derived Data" folder.
  6. Using finder, navigate to Build > Products > Debug-universal
  7. Drag/drop the library file, and the headers folder (should be called "usr") into your iPhone/iPad project.
  8. Edit your build settings and set "C/C++ Compiler Version" = "LLVM Compiler 2.0"
  9. Edit your build settings and add "Other Linker Flags" = "-ObjC"
  10. Edit your build settings and add "Header Search Paths" = "/usr/include/libxml2"
  11. Add the framework "libxml2.dylib"

Using on iOS

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];

    NSString* svgFilename = @"Monkey";

    NSLog( @"[%@] Loading SVG document, filename = %@", [self class], svgFilename );

    /** Optional: if you're using the parser extensions, add them here
    [SVGDocument addSVGParserExtension:[[SVGParserConquest alloc] init]];
    */

    SVGDocument* svgDocument = [SVGDocument documentNamed:svgFilename];

    SVGDocumentView* docView = [SVGDocumentView documentViewWithDocument:svgDocument];

    [self.window.layer addSublayer:docView.rootLayer];  

    return YES;
}

Using on OS X

SVGDocument *document = [SVGDocument documentNamed:@"image"]; // located in the application bundle
// or...
SVGDocument *document = [[SVGDocument alloc] initWithContentsOfFile:@"filepath"]; // possibly not in application bundle

// then
NSView *v = ... ;  // make sure your instance of `NSView` is layer-backed.
[v setWantsLayer:YES];
[v.layer addSublayer:[document layerTree]];

Your SVG file should now be rendered on-screen. You can query for specific layers by using the layerWithIdentifier: method, also defined on SVGDocument. The identifier corresponds to the id attribute defined on elements. Once a reference to a subclass of CALayer is returned, its properties can be animated using implicit or explicit Core Animation animations.

ARC Support

Call us old fashioned, to stay compatible with a wider variety of environments we don't use ARC in SVGKit.
There is a fork of the code that is ARC based but because of the other many big changes happening, it is severely out of date and is more there for "historical purposes". Linking from an ARC project should not pose an issue, but do let us know if you run into one. If you did not do the cross-compile using our build script mentioned above and did a drag-drop install like some folks like to do, then remember to pass -fno-objc-arc on each of the .m files using the build settings. You can read more about ARC build flags here.

I did all that, it doesn't work, you guys suck.

Please report any issues or suggest improvements in the issue tracker and include as much detail as you can including build output, logs, error messages, stack traces, example code, whatever. This is a volunteer effort, we have wives, kids, businesses, and apps of our own, please be patient with us.

svgkit's People

Contributors

adamgit avatar mattrajca avatar meric avatar notjosh avatar stich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.