-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc/usman: workaround: wrong viewbox for dot-generated SVG figures
See "Some figures in the Simulation Manual appear to be zoomed to their top-left corner" #1048 Since the viewBox correction factor differs from figure to figure, this fix is not perfect. factor=2.0 seems to be fine for most figures, and only seriously off (too much) for one. Both web and pdf renderings look ok.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# In Graphviz 2.x, dot-generated SVGs are faulty (view box too small), this script fixes it. | ||
# See https://github.com/omnetpp/omnetpp/issues/1048, https://gitlab.com/graphviz/graphviz/-/issues/1406 | ||
|
||
import sys | ||
import re | ||
|
||
if len(sys.argv) not in [2, 3]: | ||
print(f"Usage: python {sys.argv[0]} input.svg [viewbox-enhancing-factor]") | ||
sys.exit(1) | ||
|
||
input_file = sys.argv[1] | ||
factor = float(sys.argv[2]) if len(sys.argv) == 3 else 2.0 | ||
|
||
with open(input_file, "r") as file: | ||
svg_text = file.read() | ||
|
||
if re.search(r"Generated by graphviz version 2\.\d+\.\d+", svg_text): | ||
# Enlarge viewBox | ||
svg_text = re.sub(r'viewBox="([^"]+)"', lambda match: 'viewBox="' + ' '.join(str(float(value) * factor) for value in match.group(1).split()) + '"', svg_text) | ||
|
||
# Save the modified SVG back to the same file | ||
with open(input_file, "w") as file: | ||
file.write(svg_text) | ||
print(f"ViewBox modified and saved to {input_file}") | ||
else: | ||
print(f"Graphviz is NOT of version 2.x, ViewBox is probably OK, not touching it") |