From ef6fcd2a9eb117f7a0e36e84e5c8024526353f78 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 21 Sep 2014 18:45:43 +0200 Subject: [PATCH 1/5] Correctly sized col in color_set --- qrenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qrenc.c b/qrenc.c index 78f1c120..796ab01b 100644 --- a/qrenc.c +++ b/qrenc.c @@ -189,7 +189,7 @@ static int color_set(unsigned char color[4], const char *value) { int len = strlen(value); int i, count; - unsigned int col[3]; + unsigned int col[4]; if(len == 6) { count = sscanf(value, "%02x%02x%02x%n", &col[0], &col[1], &col[2], &len); if(count < 3 || len != 6) { From 3bd690b5fa165a5a79ea44ea54919eb58afef187 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 8 Feb 2014 13:14:09 +0100 Subject: [PATCH 2/5] SVG write: use styles instead of tag attributes This produces a smaller SVG (about 30% smaller for SVG without alpha channels, closer to 50% with alpha channels). --- qrenc.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/qrenc.c b/qrenc.c index 796ab01b..f9c1bf77 100644 --- a/qrenc.c +++ b/qrenc.c @@ -494,17 +494,10 @@ static int writeEPS(const QRcode *qrcode, const char *outfile) return 0; } -static void writeSVG_writeRect(FILE *fp, int x, int y, int width, const char* col, float opacity) +static void writeSVG_writeRect(FILE *fp, int x, int y, int width) { - if(fg_color[3] != 255) { - fprintf(fp, "\t\t\t\n", - x, y, width, col, opacity ); - } else { - fprintf(fp, "\t\t\t\n", - x, y, width, col ); - } + fprintf(fp, "\t\t\t\n", + x, y, width); } static int writeSVG(const QRcode *qrcode, const char *outfile) @@ -552,16 +545,35 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) " xmlns=\"http://www.w3.org/2000/svg\">\n", realwidth / scale, realwidth / scale, symwidth, symwidth ); + /* SVG CSS for styling */ + fputs( "\t\n", fp ); /* Make named group */ 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); - } + fprintf(fp, "\t\t\n", + symwidth, symwidth); /* Create new viewbox for QR data */ fputs( "\t\t\n", fp); @@ -575,9 +587,7 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) /* no RLE */ for(x=0; xwidth; x++) { if(*(row+x)&0x1) { - writeSVG_writeRect(fp, margin + x, - margin + y, 1, - fg, fg_opacity); + writeSVG_writeRect(fp, margin + x, margin + y, 1); } } } else { @@ -590,13 +600,13 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) x0 = x; } else { if(!(*(row+x)&0x1)) { - writeSVG_writeRect(fp, x0 + margin, y + margin, x-x0, fg, fg_opacity); + writeSVG_writeRect(fp, x0 + margin, y + margin, x-x0); pen = 0; } } } if( pen ) { - writeSVG_writeRect(fp, x0 + margin, y + margin, qrcode->width - x0, fg, fg_opacity); + writeSVG_writeRect(fp, x0 + margin, y + margin, qrcode->width - x0); } } } From e6acce9d991cbe553f8c75c72102449d45514a7b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 8 Feb 2014 13:43:27 +0100 Subject: [PATCH 3/5] Dimensionless SVG when DPI is zero Allow the generation of SVGs without explicit dimensions set by setting DPI to 0. Since SVGs are perfectly scalable, there is no need to set the size, in general. --- qrenc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qrenc.c b/qrenc.c index f9c1bf77..a74d6b6c 100644 --- a/qrenc.c +++ b/qrenc.c @@ -540,11 +540,19 @@ static int writeSVG(const QRcode *qrcode, const char *outfile) QRcode_APIVersionString() ); /* SVG code start */ - fprintf( fp, "\n", realwidth / scale, realwidth / scale, symwidth, symwidth - ); + ); + } else { + fprintf( fp, "\n", + symwidth, symwidth); + } /* SVG CSS for styling */ fputs( "\t