Quoth myself on Mar 25 at 10:22 am:
> I pre-applied the transformations and removed the style attributes
> that had default or unimportant values.  (The script to do the path
> math is attached.)

Now attached.
import re, numpy

def parse_xform(xform):
    [(name, args)] = re.findall(r"([a-z]+)\(([-0-9.,]+)\)", xform)
    args = map(float, args.split(","))
    if name == "translate":
        x, y = args
        return numpy.matrix([[1,0,x], [0,1,y], [0,0,1]])
    if name == "matrix":
        a, b, c, d, e, f = args
        return numpy.matrix([[a,c,e], [b,d,f], [0,0,1]])
    raise ValueError("Couldn't parse %r" % xform)

def parse_path(spath):
    # Parse an 'm' path
    pos = (0,0)
    res = []
    for op in spath.split():
        dx, dy = map(float, op.split(","))
        pos = (pos[0] + dx, pos[1] + dy)
        res.append(numpy.matrix([pos[0], pos[1], 1]).T)
    return res

def str_path(path):
    # Print an 'M' path (different from parse_path!)
    return " ".join("%.5f,%.5f" % (c[0][0], c[1][0]) for c in path)

# Star icons
xform = (parse_xform("translate(-242.81601,-315.59635)") *
         parse_xform("matrix(0.2484147,-0.02623394,0.02623394,0.2484147,174.63605,255.37691)"))
path = parse_path("290.25762,334.31206 -17.64143,-11.77975 -19.70508,7.85447 5.75171,-20.41814 -13.55925,-16.31348 21.19618,-0.83936 11.325,-17.93675 7.34825,19.89939 20.55849,5.22795 -16.65471,13.13786")
xpath = [xform * coord for coord in path]
# Path
print str_path(xpath)
# Stroke
print numpy.linalg.norm(xform * numpy.matrix([1, 0, 1]).T -
                        xform * numpy.matrix([0, 0, 1]).T)
print

# Tag icon
xform = parse_xform("translate(0,-1036.3622)")
path = parse_path("0.44642857,1040.9336 12.50000043,0 2.700893,3.6161 -2.700893,3.616 -12.50000043,0")
xpath = [xform * coord for coord in path]
# Path
print str_path(xpath)
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to