Source code elsie/render/backends/svg/query.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from ....utils.sxml import Xml
from ...inkscape import InkscapeShell
from .utils import svg_begin, svg_end


def compute_query(inkscape: InkscapeShell, method: str, data: str):
    xml = Xml()
    svg_begin(xml)
    xml.raw_text(data)
    svg_end(xml)

    if method == "inkscape-w":
        return inkscape.get_width(xml.to_string(), "target")
    elif method == "inkscape-h":
        return inkscape.get_height(xml.to_string(), "target")
    elif method == "inkscape-x":
        return inkscape.get_x(xml.to_string(), "target")
    else:
        raise Exception("Invalid method: " + repr(method))