Thursday, December 02, 2010

Your Japanese Name for iOS, part 10

Morning. Now I know how to read data in with JSON, so it's time to extract that data from the SVG files. For this I'm going to use minidom, which conveniently is already included with Python. Input is going to be a directory of SVG files, and output will be the stroke, segment and waypoint JSON that iOS will then later read in. Minidom lets you deal with XML just like from Javascript. You can use things like getElementById and getElementsByTagName. In this case I wanted to get all the positions of the SVG elements:

dom = xml.dom.minidom.parse("some_svg_file.svg")
coords = []
for rect in dom.documentElement.getElementsByTagName("rect"):
attr = rect.getAttribute
coords.append([attr("x"), attr("y")])
print coords

With similar fiddling I was able to make a script that turns the whole directory into a single JSON file with all the info required to show the strokes, segments and waypoints. Next I need to complete drawing the remaining characters and then start working on reading this structure on iOS and showing the waypoints as circles.


Drawing these characters is a lot of work. 90% complete, tomorrow I'll have all 80 of them done.