コード例 #1
0
ファイル: __init__.py プロジェクト: kstolzenberg/prk_story
def parse_transform(e, path):

    """ Transform the path according to a defined matrix.

    Attempts to extract a transform="matrix()|translate()" attribute.
    Transforms the path accordingly.

    """

    t = get_attribute(e, "transform", default="")

    for mode in ("matrix", "translate"):
        if t.startswith(mode):
            v = t.replace(mode, "").lstrip("(").rstrip(")")
            v = v.replace(", ", ",").replace(" ", ",")
            v = [float(x) for x in v.split(",")]
            from plotdevice.gfx import Transform
            t = Transform()
            if mode == "matrix":
                t._set_matrix(v)
            elif mode == "translate":
                t.translate(*v)
            path = t.transformBezierPath(path)
            break

    # Transformations can also be defined as <g transform="matrix()"><path /><g>
    # instead of <g><path transform="matrix() /></g>.
    e = e.parentNode
    if e and e.tagName == "g":
        path = parse_transform(e, path)

    return path
コード例 #2
0
def add_transform_matrix(e, path):

    """ Transform the path according to a defined matrix.

    Attempts to extract a transform="matrix()" attribute.
    Transforms the path according to this matrix.

    """

    matrix = e.getAttribute("transform")
    if matrix.startswith("matrix("):

        matrix = matrix.replace("matrix(", "").rstrip(")")
        matrix = matrix.split(",")
        matrix = [float(v) for v in matrix]

        from plotdevice.gfx import Transform
        t = Transform()
        t._set_matrix(matrix)
        path = t.transformBezierPath(path)

    return path