From 9f012d5e0ca42cf37dd8aff94df0418345fc469d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20B=C3=BCchau?= Date: Thu, 29 Jul 2021 10:30:09 +0200 Subject: [PATCH 1/2] Only add SVG background if not fully transparent This enables removing the background by adding e.g. --background=00000000 which can help when importing the resulting SVG into other software (like OpenSCAD) and the (invisible) background is then still recognised as an object. --- qrenc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/qrenc.c b/qrenc.c index c09c4ab6..441a4ce3 100644 --- a/qrenc.c +++ b/qrenc.c @@ -588,11 +588,13 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) fputs("\t\n", fp); /* Make solid background */ - if(bg_color[3] != 255) { - fprintf(fp, "\t\t\n", symwidth, symwidth, bg, bg_opacity); - } else { - fprintf(fp, "\t\t\n", symwidth, symwidth, bg); - } + if(bg_color[3] > 0) { + if(bg_color[3] != 255) { + fprintf(fp, "\t\t\n", symwidth, symwidth, bg, bg_opacity); + } else { + fprintf(fp, "\t\t\n", symwidth, symwidth, bg); + } + } if(svg_path) { if(fg_color[3] != 255) { From 09df5ebed93fe7cbc9db2196eaf902afeb354ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20B=C3=BCchau?= Date: Thu, 29 Jul 2021 14:54:09 +0200 Subject: [PATCH 2/2] Introduce --svg-no-background option This options causes `qrencode` to not put any background rectangle into the SVG output. This rectangle might be unwanted, e.g. when importing with OpenSCAD where setting the background alpha channel to 0 is not enough. --- qrenc.c | 6 +++++- qrencode.1.in | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/qrenc.c b/qrenc.c index 441a4ce3..a67b5c4f 100644 --- a/qrenc.c +++ b/qrenc.c @@ -44,6 +44,7 @@ static int dpi = 72; static int structured = 0; static int rle = 0; static int svg_path = 0; +static int svg_no_background = 0; static int micro = 0; static int inline_svg = 0; static int strict_versioning = 0; @@ -91,6 +92,7 @@ static const struct option options[] = { {"micro" , no_argument , NULL, 'M'}, {"rle" , no_argument , &rle, 1}, {"svg-path" , no_argument , &svg_path, 1}, + {"svg-no-background", no_argument , &svg_no_background, 1}, {"inline" , no_argument , &inline_svg, 1}, {"strict-version", no_argument , &strict_versioning, 1}, {"foreground" , required_argument, NULL, 'f'}, @@ -155,6 +157,8 @@ static void usage(int help, int longopt, int status) " specify foreground/background color in hexadecimal notation.\n" " 6-digit (RGB) or 8-digit (RGBA) form are supported.\n" " Color output support available only in PNG, EPS and SVG.\n\n" +" --svg-no-background\n" +" don't add a background for SVG output.\n\n" " --strict-version\n" " disable automatic version number adjustment. If the input data is\n" " too large for the specified version, the program exits with the\n" @@ -588,7 +592,7 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) fputs("\t\n", fp); /* Make solid background */ - if(bg_color[3] > 0) { + if(!svg_no_background) { if(bg_color[3] != 255) { fprintf(fp, "\t\t\n", symwidth, symwidth, bg, bg_opacity); } else { diff --git a/qrencode.1.in b/qrencode.1.in index c8e31da1..8ca07ba9 100644 --- a/qrencode.1.in +++ b/qrencode.1.in @@ -73,6 +73,9 @@ enable run-length encoding for SVG. .B \-\-svg-path use single path to draw modules for SVG. .TP +.B \-\-svg-no-background +don't add a background for SVG output. +.TP .B \-\-inline only useful for SVG output, generates an SVG without the XML tag. .TP