-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfont_transform.py
executable file
·31 lines (25 loc) · 972 Bytes
/
font_transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import argparse
import xml.etree.ElementTree as etree
from svgrasterize import Path, svg_transform
def main():
parser = argparse.ArgumentParser("simple utility to apply transformation to SVG font")
parser.add_argument("transform", help="SVG transformation to be appliied")
parser.add_argument("font", help="SVG font")
parser.add_argument("output", help="transormed SVG font")
args = parser.parse_args()
tr = svg_transform(args.transform)
etree.register_namespace("", "http://www.w3.org/2000/svg")
font = etree.parse(args.font)
root = font.getroot()
for glyph in root.findall(
"svg:defs/svg:font/svg:glyph",
dict(svg="http://www.w3.org/2000/svg"),
):
d = glyph.attrib.get("d")
if d is None:
continue
glyph.attrib["d"] = Path.from_svg(d).transform(tr).to_svg()
font.write(args.output, xml_declaration=True)
if __name__ == "__main__":
main()