1
0

initial commit

This commit is contained in:
Ninjananas
2024-08-31 12:29:28 +02:00
commit 7bdea04111
12 changed files with 10584 additions and 0 deletions

58
extract.py Normal file
View File

@@ -0,0 +1,58 @@
from typing import *
import os
import subprocess
import re
GRAPHICS_FILE: str = "graphics.svg"
OUTPUT_DIR: str = "_graphics"
ID_REGEX: re.Pattern = re.compile("rbk_.*")
def get_all_ids(svg_file_name: str) -> List[str]:
objects: bytes = subprocess.check_output([
"inkscape",
"--query-all",
svg_file_name,
])
return [
obj.split(b",")[0].decode("utf-8")
for obj in
objects.splitlines()
]
def id_filter(svg_id: str) -> bool:
return ID_REGEX.match(svg_id) is not None
def export_objects(svg_file: str, object_ids: Iterable[str]) -> None:
for obj in object_ids:
command = [
"inkscape",
"--export-type=svg",
"--export-plain-svg",
"--vacuum-defs",
"--export-id-only",
"--export-id",
obj,
"-o",
OUTPUT_DIR + "/" + obj[4:],
svg_file,
]
print(f"exporting {obj[4:]}...", end="")
res = subprocess.check_output(command)
if res:
print(f" An error might have occurred:\n{res}")
else:
print(" done")
if __name__ == "__main__":
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
export_objects(
GRAPHICS_FILE,
filter(id_filter, get_all_ids(GRAPHICS_FILE)),
)