import sys

scale = 0.75

def scale_svg(lines):
    svg = "".join(lines)
    head, viewbox = svg.split("viewBox=\"", maxsplit=1)
    viewbox, tail = viewbox.split('"', maxsplit=1)
    x, y, width, height = map(float, viewbox.split())
    yield head
    yield f'viewBox="{x} {y} {width * scale} {height * scale}"'
    yield tail

def transform():
    with open(sys.argv[1]) as f:
        svg_lines = []

        for line in f.readlines():
            if line.strip().startswith("<svg"):
                svg_lines.append(line)
            elif svg_lines != []:
                svg_lines.append(line)
                if line.strip().endswith(">"):
                    yield from scale_svg(svg_lines)
                    svg_lines = []
            else:
                yield line

lines = list(transform())
with open(sys.argv[1], 'w') as f:
    f.write(''.join(lines))
