summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-27 08:42:56 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-27 08:42:56 +0100
commit422153e18d7e0e4f5e3aab94eb4d05072ce21939 (patch)
tree2384d521a5534b0553211668e33c60d371725e03
parent13a6832bb4f9ec68d26ae59c8dd1260279e3e70a (diff)
add svg export
-rwxr-xr-xconvert.zsh4
-rwxr-xr-xlib/export-carriage.py57
2 files changed, 36 insertions, 25 deletions
diff --git a/convert.zsh b/convert.zsh
index c37a208..4efe7e2 100755
--- a/convert.zsh
+++ b/convert.zsh
@@ -310,7 +310,7 @@ function extract_wagons_heuristic {
echo "Page $(( start + i - 1 )): $target"
inkscape --export-filename=svg/${target}.svg tmp-$(( start + i - 1 )).pdf &> /dev/null
- lib/export-carriage.py svg/${target}.svg png/${target}.png
+ lib/export-carriage.py svg/${target}.svg png/${target}.png png/${target}.svg
done
}
@@ -335,7 +335,7 @@ extract_wagons $ic2_sk_offset $ic2_sk_bbox $ic2_sk_types
rm tmp-*
perl -MJSON -E 'say JSON->new->canonical->encode({map {$_ => true} @ARGV})' \
- png/*(:t:r) > png/wagons.json
+ png/*.png(:t:r) > png/wagons.json
chmod -R a+rX png
rsync -a --info=progress2 --delete png/ epicentre:web/org.finalrewind.lib/out/dbdb/db_wagen/
diff --git a/lib/export-carriage.py b/lib/export-carriage.py
index 69e5133..8f1e4e4 100755
--- a/lib/export-carriage.py
+++ b/lib/export-carriage.py
@@ -27,7 +27,7 @@ class SVGObject:
)
-def main(infile, outfile):
+def main(infile, *outfiles):
ret = subprocess.run(
["inkscape", "--query-all", infile], capture_output=True, check=True
)
@@ -56,34 +56,45 @@ def main(infile, outfile):
x_positions = list()
for o in objects:
- if (o.is_path or o.is_tspan) and (o.y < crop_y_min or o.y_ > crop_y_max):
+ if (o.is_path() or o.is_tspan()) and (o.y < crop_y_min or o.y_ > crop_y_max):
objects_to_delete.append(o.id)
- elif o.is_path and o.y >= crop_y_min and o.y_ <= crop_y_max:
- x_positions.append(o.x)
- x_positions.append(o.x_)
-
- crop_x_min = int(np.min(x_positions))
- crop_x_max = int(np.max(x_positions)) + 1
objects_to_delete = ",".join(objects_to_delete)
- export_area = f"--export-area={crop_x_min}:{crop_y_min}:{crop_x_max}:{crop_y_max}"
select_objects = f"--select={objects_to_delete}"
- subprocess.run(
- [
- "xvfb-run",
- "inkscape",
- export_area,
- select_objects,
- "--verb=EditDelete",
- "--batch-process",
- "--export-dpi=600",
- "-o",
- outfile,
- infile,
- ]
- )
+ for outfile in outfiles:
+ if outfile.endswith(".png"):
+ subprocess.run(
+ [
+ "xvfb-run",
+ "inkscape",
+ "--export-area-drawing",
+ select_objects,
+ "--verb=EditDelete",
+ "--batch-process",
+ "--export-dpi=600",
+ "-o",
+ outfile,
+ infile,
+ ]
+ )
+ elif outfile.endswith(".svg"):
+ subprocess.run(
+ [
+ "xvfb-run",
+ "inkscape",
+ "--export-area-drawing",
+ select_objects,
+ "--verb=EditDelete",
+ "--batch-process",
+ "-o",
+ outfile,
+ infile,
+ ]
+ )
+ else:
+ raise RuntimeError(f"Unsupported export format: {outfile}")
if __name__ == "__main__":