aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-01-29 23:20:16 +0100
committerjaseg <git@jaseg.de>2021-01-29 23:20:16 +0100
commit52dcceb87f5847dc235f5b5965f57881f327143c (patch)
treef4979228c2b1c85a9628ff892305c8fbdc4aaccb /src/main.cpp
parenta34efc058a18021143b75e30efdfd8dd0e72df10 (diff)
downloadgerbolyze-52dcceb87f5847dc235f5b5965f57881f327143c.tar.gz
gerbolyze-52dcceb87f5847dc235f5b5965f57881f327143c.tar.bz2
gerbolyze-52dcceb87f5847dc235f5b5965f57881f327143c.zip
Add support for preserveAspectRatio for both SVG and bitmap input
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 931ab74..915b71f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -64,6 +64,9 @@ int main(int argc, char **argv) {
{"size", {"-s", "--size"},
"Bitmap mode only: Physical size of output image in mm. Format: 12.34x56.78",
1},
+ {"preserve_aspect_ratio", {"-a", "--preserve-aspect-ratio"},
+ "Bitmap mode only: Preserve aspect ratio of image. Allowed values are meet, slice. Can also parse full SVG preserveAspectRatio syntax.",
+ 1},
{"skip_usvg", {"--no-usvg"},
"Do not preprocess input using usvg (do not use unless you know *exactly* what you're doing)",
0},
@@ -252,7 +255,19 @@ int main(int argc, char **argv) {
<< width << " " << height << "\" "
<< "xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << endl;
- svg << "<image width=\"" << width << "\" height=\"" << height << "\" x=\"0\" y=\"0\" xlink:href=\"data:image/png;base64,";
+ string par_attr = "none";
+ if (args["preserve_aspect_ratio"]) {
+ string aspect_ratio = args["preserve_aspect_ratio"].as<string>();
+ if (aspect_ratio == "meet") {
+ par_attr = "xMidYMid meet";
+ } else if (aspect_ratio == "slice") {
+ par_attr = "xMidYMid slice";
+ } else {
+ par_attr = aspect_ratio;
+ }
+ }
+ svg << "<image width=\"" << width << "\" height=\"" << height << "\" x=\"0\" y=\"0\" preserveAspectRatio=\""
+ << par_attr << "\" xlink:href=\"data:image/png;base64,";
/* c++ has the best hacks */
std::ostringstream sstr;