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

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.

Related

Import .ai (illustrator file) in Unity and display them

I want to load an illustrator file in my game. Unity should recognize different layers, colors, and forms, and layers with text and display them in a 2d canvas.
The goal is that the players can click on different forms and that unity recognize them as individual forms. Do you know any unity asset or a way to make this possible?
For example when you import an image like this as an illustrator file -> https://www.mandala-bilder.de/mandala/erwachsenemandalas/mandala-ideen-erwachsene.pdf
I thought about an SVG file but then I canĀ“t use the different layers.
Illustrator has a proprietary file format, it has no publicly available documentation for newer versions. While you can dig out old specifications (this is why some programs only support AI files saved in ancient versions) http://www.idea2ic.com/File_Formats/Adobe%20Illustrator%20File%20Format.pdf I do not think you can just go in and start supporting a 2021 variant without requesting (and motivating) the spec from Adobe. They might also want to charge you for it.
SVG on the other hand is free and it's spec is public so there is much widely spread support. also SVG supports groups which can get your around the need for layers
Vector Express is a free conversion API you should be able to use. (requires a network connection, though)
https://github.com/smidyo/vectorexpress-api
You should be able to POST a request (https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html) to this endpoint, with the raw AI file as the body:
POST https://vector.express/api/v2/public/convert/ai/gs/pdf/psd2svg/svg/
This will return a JSON object with a link to an SVG file that you can then download and display.

Illustrator add class to svg group

i have searched from hours to find a solution to export a SVG with class on the group element. Is it possible this thing?
I have found a program inkscape which can edit in XML mode and add the attribute. The problem is that inkscape insert too much garbage code to use in the web.
Can it be done in illustrator or program in which the SVG stays with clean code.
Edit - 06.12.2015
For now there is not a good program solution, the best tool to do is inkscape.
For this to work you need to use the XML ediotor in the program, so it is not very user friendly also it includes too much markup in SVG.
This is an explanation by Adobe on how to export SVG from Illustrator CC.
they don't mention classes though.
how about ID's? might be equally useful
Illustrator wraps every layer in a g element that gets his ID from the layer's name.
you could use it to construct your svg accordingly and get each group of elements with the id you want.
the latest version of AI spits pretty clean code I think.
but you could use an online tool to optimise it.

Can cairo load a PDF?

This sounds really simple, but I can't find a way to load a PDF into Cairo. I want to be able to do cairo.PDFSurface.create_from_pdf in the same way I do cairo.ImageSurface.create_from_png (yes I'm using the Python bindings but that's neither here nor there).
The documentation doesn't appear to give any hints.
No, cairo cannot read PDFs. However, poppler can load PDFs an paint them onto a cairo context - http://poppler.freedesktop.org/
(Oh and create_from_png() is part of cairo's toy API. It works, but you are recommended to use some "real" API which can do more things than just loading PNGs)

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)

adding text to TIFF

I need to add text string to a TIFF image. I am planning to use libTIFF for editing the TIFF image. The plan is to convert text to image using freetype2 and then somehow render the text image on to TIFF. Is this the right approach?
Any pointers on how to convert text to image? I saw the sample code of ft2 - initialising the library, creating face and then setting character sizes. But not sure what to do next? any pointers appreaciated.
One way could be using ImageMagick. They have tools for image composition and text rendering. (and many more)
Although ImageMagick is primarily used from the command line (especially in web environments) several language interfaces are available, too. Java, C, C++, ...
ImgSource is a really nice library for C/C++ on Windows, and it can do this out of the box.
http://www.smalleranimals.com/isource.htm
It's not free, but it's pretty cheap ($59)
You don't tell us which language you need to use, should it be portable or for a given platform, etc.
Using a ready to use existing graphic library, like the (big!) ImageMagick or others like libGD or DevIL might be the easiest way, lot of them have binding for lot of languages.
if youre on windows and in c++ then it's pretty easy to use gdiplus for drawing fonts. you have access to any installed font and you can save the raster out as tiff or jpeg etc as well using the one api.
of course you could also use some combo of freetype and libtiff, but you'll have to build those libs for win32. not that its hard, just more fussing around you may not want to do.