示例#1
0
#!/usr/bin/python
"""svg2bnd.py -- Converts a path in an SVG file to a boundary for Voro++."""

import sys, re
from svgfig import svg, pathdata
from math import sqrt

if len(sys.argv) < 2:
    print 'Usage: svg2bnd <file>'
    sys.exit(0)
stage = 0
count = 0
obj = svg.load(sys.argv[1])
semitotal = 0
for key, elem in obj.walk():
    if isinstance(elem, svg.SVG):
        if elem.tag == 'path':
            print '# Start'
            redo = 0
            commandStr = elem[u'd']
            commandStr = re.sub('([0-9])-', ' -', commandStr)
            # HACK: Add some spaces to ease along parsing.
            commands = pathdata.parse(commandStr)
            lx, ly = 0.0, 0.0
            x, y = 0.0, 0.0
            xs = []
            ys = []
            for c in commands:
                d = c[0]

                if d == u'L' or d == u'M':  # Absolute position line
示例#2
0
#!/usr/bin/python

import os, types, re, inspect

from svgfig.svg import SVG as XML
from svgfig.svg import load

import svgfig, svgfig.interactive
for module in svgfig.__all__: exec("import svgfig.%s" % module)

docs = []
for f in os.listdir("source"):
    if f[0] != "." and f[-4:] == ".xml":
        docs.extend(load("source/%s" % f).children)

def order(a, b, model):
    ai, bi = None, None
    try:
        ai = model.index(a.name)
    except ValueError: pass
    try:
        bi = model.index(b.name)
    except ValueError: pass

    if ai is None and bi is None:
        return cmp((a.module, a.name), (b.module, b.name))
    elif ai is not None and bi is None:
        return -1
    elif ai is None and bi is not None:
        return 1
    else: