How to import/parse SVG into UIBezierpaths, NSBezierpaths, CGPaths? [closed] - iphone

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to import paths from a vector drawing program into the ios environment. I would like to get them into CGpaths or UIbezierpaths. I am most interested in importing paths from adobe illustrator. The best way seems to save as an svg and then import.
I have found some resources for parsing exported SVG files that describe the paths. However, everything I have found only deals with absolute paths and not relative paths. The path below has capital C's and lowercase C's. I know how to parse the capital C (absolute paths) but I have no idea how to parse the lowercase c's (relative paths)
I am looking for help with writing a parser for importing svg files into ios/cocoa. I think there is a big need for this judging by searching the internet for weeks.
Here, is an example of a path I would like to import into my iphone app. I am not looking to import the image, I want the path itself. So, I can manipulate it. Any help would be much appreciated.
x="0px" y="0px" width="320px" height="436px" viewBox="-1.4 -0.5 320 436"
d="M294.1,116C290.6,1.4,170.9,0.4,159.6,0.5
C148.3,0.4,28.7,1.4,25.2,116c-3.7,120.3-49.6,141.4-5.9,233.9c41.3,87.4,130.7,87,140.4,86.7c9.7,0.3,99.1,0.8,140.4-86.7
C343.7,257.4,297.8,236.3,294.1,116z
If this was all absolute paths I would be able to solve this now. It is the relative (i.e. lowecase (c) paths) that are really confusing me.

Alright folks, if you're willing to pay for it. This tool will solve all your issues. You can import svg or psd and will produce the code for you. I've used it and it is amazing!
http://www.paintcodeapp.com/

There's an open-source SVG library in ObjectiveC, specifically for iOS (and OS X, although the OS X build is a bit behind):
https://github.com/SVGKit/SVGKit/
(I've been using this on iOS projects since the start of this year, it works well)
2018 update: OSX support is now in, and SVGKit renders most SVG's fast + accurately. On the downside, advanced text features aren't all supported (e.g. yes to gradient-fill, but no to complex text-layout).
As of early 2012, it's not a 100% implementation of the SVG spec, but there's a lot of people working on getting it there.

If you're willing to do some translation from JS to ObjC, then you might find this project helpful:
https://github.com/thelonious/svg-2d
Particularly, the path.js file which includes a parseData method, taking care of relative and absolute path commands.
https://github.com/thelonious/svg-2d/blob/master/shapes/path/Path.js
I should mention that I wrote this code years ago, but I have translated it to Java and C# and have used in professional products (can't share that code, unfortunately) and it seemed to work well in those environments as well.
HTH
Kevin

Sketch 3 on Mac App Store is good at editing (can be better than PaintCode) and then exporting as SVG to PaintCode.
To get from PaintCode back to Sketch save as PDF and imports ok
https://itunes.apple.com/gb/app/sketch-3/id852320343?mt=12
Make sure canvas size in both is set to the same and in your views bounds else youll need to scale the context.

SVGgh contains a class, SVGPathGenerator, which will convert an SVG path to a CGPathRef:
+(CGPathRef) newCGPathFromSVGPath:(NSString*)anSVGPath whileApplyingTransform:(CGAffineTransform)aTransform;
You can use it to do exactly what you request.
[Swift 3 Update] If you want a pure Swift solution. My (in progress) Scalar2D library has an extension on CGPath that creates a CGPath from an SVG path.

This solution is a straight conversion of an SVG path string to UIBezierPath. It worked great for my app where I had to draw the united states as a UIView.
https://github.com/ap4y/UIBezierPath-SVG

Oneliner that adds an SVG to an NSView:
addSubView(SVGParser.svg(FileParser.xml(~/Desktop/test.svg)))
SVGLib for swift: https://github.com/eonist/swift-utils

Related

Tag based file system [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
All OSs that exist right now work in files and folders. I was thinking that there are may other ways of storing files. Would it be a better way to store files by tags, for example:
A file called "music1" can have a tag "2013", if the music was made in 2013. The same file can have another tag called "Music", to say that the file is music, another file called "video1" could have the "2013" tag, but also have the "Video" tag instead of the "Music" one. This would be useful, because you could search for tags and generate nice-looking maps of all the files you have.
Here is an example:
In this example, files are in green. Each file has some tags(blue),and some special tags(red). Special tags contain things like the user(only the user in the tag can see files tagged USER:Username) and File type(instead of file extension). Tags in yellow are system filetypes that do not require a program to run them(like .exe in windows)
Black lines link tags to files
Red lines link special tags to files
Blue lines link what the file type(or file) is opened by. For example, the music is an ogg file. It is opened by OggViewer, which is a jar file opened by java. Java is opened by the system.
As far as I know, there is a nice file system level solution to your need called NHFS or nonhierarchical file system. Also available a FUSE based mountable file system called TMSU that may satisfy you.
It could have merit, for example I'm utterly disinterested in the file names/paths of my tens of thousands of music files; I only really care about the artist,title,album,year,etc of them, which is the way my music player (quodlibet) displays them. Choosing a set of music to put on another device or to send to someone could then be as easily as selecting an album (instead of browing to /home/me/music/who/knows/what/someartist - somealbum).
There is TagsForAll for windows. It is a file manager based on tags. Tags can have hierarchical structure. User interface is very simple but nice. Free version fully functional and save tags in database, Pro version save tags also within NTFS stream to a file.
Microsoft tried to do something like that with WinFS
but gave up on it. It would be great if they could get it to work.
There are some other (old, archived) projects implement this idea:
http://nascent.freeshell.org/programming/TagFS/
https://code.google.com/p/dhtfs/
https://code.google.com/p/tagfilesystem/
http://www.tagsistant.net/
Only the last seems to be releasing recent versions.
I think the idea has a future. I've pondered this same idea before. And tags fundamentally work better for most content than folders do; however, I wonder if the hierarchical structure of folders isn't actually better suited for files. In other words, though I like the idea of using tags on many levels I wonder if it would actually increase the overall complexity. For example, consider how tags could be used successfully to manage versioned software libraries. I'm afraid we won't know the answer until someone starts using the concept instead of folders for an entire OS. It'll be interesting to see/try.

interactive pdf on the iOS

I have been looking for a way to present an interactive pdf file (created by in-design) on
the iPhone. I read a bunch of questions here but none says how to do it. The pdf file contain the text and in the middle it contains a 3d module, but when I present it on the iPhone it shows only the text and an empty white box where the module should appear.
Is it even possible to do it?
I'll be glad for any assistant on this subject or even where to look.
Thanks in advance,
Shahar.
Apple's PDF parser does not support 3D stuff. You're better of implementing the 3D part yourself and just adding that as a UIView on top of the PDF. There are several PDF frameworks that help with that (see https://stackoverflow.com/questions/3801358/pdf-parsing-library-for-ios)
Another alternative might be licensing Adobe's iOS rendering engine. But I doubt that they already added 3D support (or that they will be). Also, from what my sources tell me, pricing is rather high and apparently the framework not very developer friendly. (But I haven't used it myself)

Are there any tutorials on coding a parser for SVG files to be used by box2D?

I am trying to create an iPhone game with fairly large levels. Hard coding the platforms and physics objects is very time consuming. I have seen some people have made their own parsers for svg files to use in box2D, and Riq is selling levelSVG but it is a little pricey for me at the moment, and I only need basic features. Is there a tutorial on how to code a parser available online?
Have you taken a look at SVGQuartzRenderer? It is designed to render SVG files in Quartz, so I imagine you might be able to pull out the SVG parsing code from this. It's opensource, MIT license.
I don't know about any tutorials but its fairly easy to do this using an XML parsing library. In my project I use MiniDOM to load an svg file and then I convert the elements into objects in the box2d word. The only thing that I had to do manually was the parsing of the path element.
I've written an extensive tutorial on how to parse SVG files using Apache Batik SVG library. Included with the tutorial are a set of classes and a function I wrote in Java which will generate a set of Vec2 points given the location of the SVG file. If you're using Objective C you could try to port the scripts or at least get an idea of the process involved. The scripts support multiple paths per SVG file, transformations, straight lines and quadratic splines. The first tutorial in the series can be found here.

Show PDF in iPad using CGPDF APIs [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have learned Apple has release CGPDF APIs in SDK 3.2 for drawing PDF context.
What I understand from these APIs is that you can draw a PDF to a data object or a PDF file. You can then export it, may be, to your sandbox's directory OR add as an attachment in the mail.
But I am not sure if we can use these APIs to read a PDF from application bundle and show it to the user page-by-page on the screen. What I want to do is open a PDF of a magazine in a magazine reader app.
I was also wondering if we can identify the links in a PDF file and open them in the app.
Let me know if have done OR doing anything like this.
Thanks
AJ
In API documentation there is a way to load a PDF (with Quartz):
CGPDFDocument is the object you need
and CGPDFDocumentCreateWithURL is probably the constructor you are looking for.
Here are some examples on how to do it:
http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF109
I have spent a lot of time on this - and it seems you need to use CATiledLayers to zoom those PDFs properly!
There are some good examples on the net on how to do that...
I will put a link/solution here as soon as I have something ready!
Displaying the PDF with the Quartz APIs is pretty easy. But there's no native support for link annotations. Basically, you need to parse the "Annots" dictionary inside the pdf, and then find the correct page (which can be GoTo references, or named references, or ~10 other types; see the Adobe PDF Reference 1.7 document, the section about Actions), and the calculate the coordinates to the displayed page.
I've written a [commercial] library that includes parsing link annotations, and many more features. You may wanna check out http://pspdfkit.com

How can I take a screenshot of website with Perl? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I take screenshots with Perl?
How can I take a screenshot from a site (in batch mode) using Perl? I.e. solution should produce image file (say .png) given an URL. It would be nice, if no X Window system will be required for solution to work.
I'd use WWW::Mechanize::Firefox. Unfortunately it does need X (at least on non-OS X *NIX), but you can use xvfb to run it headless.
In the past I needed to convert a web page to PDF.
I used http://code.google.com/p/wkhtmltopdf/ and it worked beautifully (it's using the excellent WebKit engine). Problem is it's not Perl-based and it doesn't produce an image, but a PDF. Try it, it might suit your needs (` No longer requires an XServer to be running (however the X11 client libs must be installed' )
If your going to go beyond screen shots, finding a binding for Watir would be my advice. The ability to get javascript, java/flash/activex embedd scripting working is nice (for some value of nice)