From 4c02660ed6766f2ddcc238d91ad5aa83bbce8b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ball=C3=A9?= Date: Thu, 24 Sep 2015 16:00:23 +0100 Subject: [PATCH 1/5] added a fancy svg mode that does as described in https://github.com/fukuchi/libqrencode/issues/69 --- qrenc.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 248 insertions(+), 6 deletions(-) diff --git a/qrenc.c b/qrenc.c index 32118723..c3ed121e 100644 --- a/qrenc.c +++ b/qrenc.c @@ -43,6 +43,7 @@ static int structured = 0; static int rle = 0; static int svg_path = 0; static int micro = 0; +static int ascii_plus = 0; static QRecLevel level = QR_ECLEVEL_L; static QRencodeMode hint = QR_MODE_8; static unsigned char fg_color[4] = {0, 0, 0, 255}; @@ -55,6 +56,7 @@ enum imageType { PNG32_TYPE, EPS_TYPE, SVG_TYPE, + FSVG1_TYPE, XPM_TYPE, ANSI_TYPE, ANSI256_TYPE, @@ -78,6 +80,7 @@ static const struct option options[] = { {"type" , required_argument, NULL, 't'}, {"structured" , no_argument , NULL, 'S'}, {"kanji" , no_argument , NULL, 'k'}, + {"ascii-plus" , required_argument, NULL, 'A'}, {"casesensitive", no_argument , NULL, 'c'}, {"ignorecase" , no_argument , NULL, 'i'}, {"8bit" , no_argument , NULL, '8'}, @@ -91,7 +94,7 @@ static const struct option options[] = { {NULL, 0, NULL, 0} }; -static char *optstring = "ho:r:l:s:v:m:d:t:Skci8MV"; +static char *optstring = "ho:r:l:s:v:m:d:t:A:Skci8MV"; static void usage(int help, int longopt, int status) { @@ -125,12 +128,13 @@ static void usage(int help, int longopt, int status) " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n" " -d NUMBER, --dpi=NUMBER\n" " specify the DPI of the generated PNG. (default=72)\n\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8},\n" -" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1},\n" +" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1}\n" " specify the type of the generated image. (default=PNG)\n\n" " -S, --structured\n" " make structured symbols. Version must be specified.\n\n" " -k, --kanji assume that the input text contains kanji (shift-jis).\n\n" +" -A NUMBER, --ascii-plus=NUMBER shows in ascii type the internal structure of the qrcode.\n\n" " -c, --casesensitive\n" " encode lower-case alphabet characters in 8-bit mode. (default)\n\n" " -i, --ignorecase\n" @@ -178,10 +182,11 @@ static void usage(int help, int longopt, int status) " -v NUMBER specify the minimum version of the symbol. (default=auto)\n" " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n" " -d NUMBER specify the DPI of the generated PNG. (default=72)\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1}\n" " specify the type of the generated image. (default=PNG)\n" " -S make structured symbols. Version must be specified.\n" " -k assume that the input text contains kanji (shift-jis).\n" +" -A NUMBER, --ascii-plus=NUMBER shows in ascii type the internal structure of the qrcode.\n\n" " -c encode lower-case alphabet characters in 8-bit mode. (default)\n" " -i ignore case distinctions and use only upper-case characters.\n" " -8 encode entire data in 8-bit mode. -k, -c and -i will be ignored.\n" @@ -521,6 +526,229 @@ static void writeSVG_drawModules(FILE *fp, int x, int y, int width, const char* } } +static void writeFSVG1_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp," \ + \ + \ + ", + color,x*10,y*10, + color,x*10,y*10, + color,x*10,y*10, + color,x*10,y*10 + ); + fprintf(fp," ",color,x*10,y*10 + ); +} + +static int writeFSVG1(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG1_drawModules(fp,x,y,fg); + else writeFSVG1_drawModules(fp,x,y,bg); + } else writeFSVG1_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + static int writeSVG(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -950,10 +1178,12 @@ static int writeASCII(const QRcode *qrcode, const char *outfile, int invert) for(x = 0; x < qrcode->width; x++) { if(row[x]&0x1) { - *p++ = black; + if(ascii_plus)*p++=ascii_plus&row[x]?'1':' '; + else *p++ = black; *p++ = black; } else { - *p++ = white; + if(ascii_plus)*p++=ascii_plus&row[x]?'1':' '; + else *p++ = white; *p++ = white; } } @@ -1024,6 +1254,9 @@ static void qrencode(const unsigned char *intext, int length, const char *outfil case SVG_TYPE: writeSVG(qrcode, outfile); break; + case FSVG1_TYPE: + writeFSVG1(qrcode, outfile); + break; case XPM_TYPE: writeXPM(qrcode, outfile); break; @@ -1081,6 +1314,7 @@ static void qrencodeStructured(const unsigned char *intext, int length, const ch type_suffix = ".eps"; break; case SVG_TYPE: + case FSVG1_TYPE: type_suffix = ".svg"; break; case XPM_TYPE: @@ -1152,6 +1386,9 @@ static void qrencodeStructured(const unsigned char *intext, int length, const ch case SVG_TYPE: writeSVG(p->code, filename); break; + case FSVG1_TYPE: + writeFSVG1(p->code, filename); + break; case XPM_TYPE: writeXPM(p->code, filename); break; @@ -1272,6 +1509,8 @@ int main(int argc, char **argv) image_type = EPS_TYPE; } else if(strcasecmp(optarg, "svg") == 0) { image_type = SVG_TYPE; + } else if(strcasecmp(optarg, "fsvg1") == 0) { + image_type = FSVG1_TYPE; } else if(strcasecmp(optarg, "xpm") == 0) { image_type = XPM_TYPE; } else if(strcasecmp(optarg, "ansi") == 0) { @@ -1297,6 +1536,9 @@ int main(int argc, char **argv) case 'k': hint = QR_MODE_KANJI; break; + case 'A': + ascii_plus = atoi(optarg); + break; case 'c': casesensitive = 1; break; From 24d18074bddb6767050a5ac4553f405f0bb0b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ball=C3=A9?= Date: Thu, 22 Oct 2015 11:04:20 +0100 Subject: [PATCH 2/5] added two more svg modes that have no transparency and suitable for teeshirt printing --- qrenc.c | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 372 insertions(+), 3 deletions(-) diff --git a/qrenc.c b/qrenc.c index c3ed121e..972ab357 100644 --- a/qrenc.c +++ b/qrenc.c @@ -57,6 +57,8 @@ enum imageType { EPS_TYPE, SVG_TYPE, FSVG1_TYPE, + FSVG2_TYPE, + FSVG3_TYPE, XPM_TYPE, ANSI_TYPE, ANSI256_TYPE, @@ -128,8 +130,8 @@ static void usage(int help, int longopt, int status) " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n" " -d NUMBER, --dpi=NUMBER\n" " specify the DPI of the generated PNG. (default=72)\n\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1},\n" -" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1,FSVG2,FSVG3},\n" +" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1,FSVG2,FSVG3}\n" " specify the type of the generated image. (default=PNG)\n\n" " -S, --structured\n" " make structured symbols. Version must be specified.\n\n" @@ -182,7 +184,7 @@ static void usage(int help, int longopt, int status) " -v NUMBER specify the minimum version of the symbol. (default=auto)\n" " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n" " -d NUMBER specify the DPI of the generated PNG. (default=72)\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,FSVG1,FSVG2,FSVG3}\n" " specify the type of the generated image. (default=PNG)\n" " -S make structured symbols. Version must be specified.\n" " -k assume that the input text contains kanji (shift-jis).\n" @@ -596,6 +598,57 @@ static void writeFSVG1_drawModules(FILE *fp, int x, int y, const char* color) ); } +static void writeFSVG2_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp,"" + ,color,x*10+5,y*10+5 + ); +} + +static void writeFSVG3_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp,"\ + \ + \ + \ + " + ,color,x*10+1.8436925,y*10+1.755784 + ,color,x*10+1.2843877,y*10+6.8829622 + ,color,x*10+5.0531077,y*10+4.9817958 + ,color,x*10+7.2622757,y*10+8.4027872 + ,color,x*10+8.0230665,y*10+1.6966467 + ); +} + static int writeFSVG1(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -749,6 +802,312 @@ static int writeFSVG1(const QRcode *qrcode, const char *outfile) return 0; } +static int writeFSVG2(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG2_drawModules(fp,x,y,fg); + else writeFSVG2_drawModules(fp,x,y,bg); + } else writeFSVG2_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + +static int writeFSVG3(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG3_drawModules(fp,x,y,fg); + else writeFSVG3_drawModules(fp,x,y,bg); + } else writeFSVG3_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + static int writeSVG(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -1257,6 +1616,12 @@ static void qrencode(const unsigned char *intext, int length, const char *outfil case FSVG1_TYPE: writeFSVG1(qrcode, outfile); break; + case FSVG2_TYPE: + writeFSVG2(qrcode, outfile); + break; + case FSVG3_TYPE: + writeFSVG3(qrcode, outfile); + break; case XPM_TYPE: writeXPM(qrcode, outfile); break; @@ -1511,6 +1876,10 @@ int main(int argc, char **argv) image_type = SVG_TYPE; } else if(strcasecmp(optarg, "fsvg1") == 0) { image_type = FSVG1_TYPE; + } else if(strcasecmp(optarg, "fsvg2") == 0) { + image_type = FSVG2_TYPE; + } else if(strcasecmp(optarg, "fsvg3") == 0) { + image_type = FSVG3_TYPE; } else if(strcasecmp(optarg, "xpm") == 0) { image_type = XPM_TYPE; } else if(strcasecmp(optarg, "ansi") == 0) { From 992289fd38af8b8a0093530e162e8b63938343b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ball=C3=A9?= Date: Thu, 24 Sep 2015 16:00:23 +0100 Subject: [PATCH 3/5] added a fancy svg mode that does as described in https://github.com/fukuchi/libqrencode/issues/69 --- qrenc.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 248 insertions(+), 6 deletions(-) diff --git a/qrenc.c b/qrenc.c index 4ae6cce7..95c81f91 100644 --- a/qrenc.c +++ b/qrenc.c @@ -46,6 +46,7 @@ static int rle = 0; static int svg_path = 0; static int micro = 0; static int inline_svg = 0; +static int ascii_plus = 0; static QRecLevel level = QR_ECLEVEL_L; static QRencodeMode hint = QR_MODE_8; static unsigned char fg_color[4] = {0, 0, 0, 255}; @@ -58,6 +59,7 @@ enum imageType { PNG32_TYPE, EPS_TYPE, SVG_TYPE, + FSVG1_TYPE, XPM_TYPE, ANSI_TYPE, ANSI256_TYPE, @@ -84,6 +86,7 @@ static const struct option options[] = { {"type" , required_argument, NULL, 't'}, {"structured" , no_argument , NULL, 'S'}, {"kanji" , no_argument , NULL, 'k'}, + {"ascii-plus" , required_argument, NULL, 'A'}, {"casesensitive", no_argument , NULL, 'c'}, {"ignorecase" , no_argument , NULL, 'i'}, {"8bit" , no_argument , NULL, '8'}, @@ -98,7 +101,7 @@ static const struct option options[] = { {NULL, 0, NULL, 0} }; -static char *optstring = "ho:r:l:s:v:m:d:t:Skci8MV"; +static char *optstring = "ho:r:l:s:v:m:d:t:A:Skci8MV"; static void usage(int help, int longopt, int status) { @@ -132,12 +135,13 @@ static void usage(int help, int longopt, int status) " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n" " -d NUMBER, --dpi=NUMBER\n" " specify the DPI of the generated PNG. (default=72)\n\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8},\n" -" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1},\n" +" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1}\n" " specify the type of the generated image. (default=PNG)\n\n" " -S, --structured\n" " make structured symbols. Version must be specified.\n\n" " -k, --kanji assume that the input text contains kanji (shift-jis).\n\n" +" -A NUMBER, --ascii-plus=NUMBER shows in ascii type the internal structure of the qrcode.\n\n" " -c, --casesensitive\n" " encode lower-case alphabet characters in 8-bit mode. (default)\n\n" " -i, --ignorecase\n" @@ -186,10 +190,11 @@ static void usage(int help, int longopt, int status) " -v NUMBER specify the minimum version of the symbol. (default=auto)\n" " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n" " -d NUMBER specify the DPI of the generated PNG. (default=72)\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1}\n" " specify the type of the generated image. (default=PNG)\n" " -S make structured symbols. Version must be specified.\n" " -k assume that the input text contains kanji (shift-jis).\n" +" -A NUMBER, --ascii-plus=NUMBER shows in ascii type the internal structure of the qrcode.\n\n" " -c encode lower-case alphabet characters in 8-bit mode. (default)\n" " -i ignore case distinctions and use only upper-case characters.\n" " -8 encode entire data in 8-bit mode. -k, -c and -i will be ignored.\n" @@ -531,6 +536,229 @@ static void writeSVG_drawModules(FILE *fp, int x, int y, int width, const char* } } +static void writeFSVG1_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp," \ + \ + \ + ", + color,x*10,y*10, + color,x*10,y*10, + color,x*10,y*10, + color,x*10,y*10 + ); + fprintf(fp," ",color,x*10,y*10 + ); +} + +static int writeFSVG1(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG1_drawModules(fp,x,y,fg); + else writeFSVG1_drawModules(fp,x,y,bg); + } else writeFSVG1_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + static int writeSVG(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -978,10 +1206,12 @@ static int writeASCII(const QRcode *qrcode, const char *outfile, int invert) for(x = 0; x < qrcode->width; x++) { if(row[x]&0x1) { - *p++ = black; + if(ascii_plus)*p++=ascii_plus&row[x]?'1':' '; + else *p++ = black; *p++ = black; } else { - *p++ = white; + if(ascii_plus)*p++=ascii_plus&row[x]?'1':' '; + else *p++ = white; *p++ = white; } } @@ -1050,6 +1280,9 @@ static void qrencode(const unsigned char *intext, int length, const char *outfil case SVG_TYPE: writeSVG(qrcode, outfile); break; + case FSVG1_TYPE: + writeFSVG1(qrcode, outfile); + break; case XPM_TYPE: writeXPM(qrcode, outfile); break; @@ -1116,6 +1349,7 @@ static void qrencodeStructured(const unsigned char *intext, int length, const ch type_suffix = ".eps"; break; case SVG_TYPE: + case FSVG1_TYPE: type_suffix = ".svg"; break; case XPM_TYPE: @@ -1189,6 +1423,9 @@ static void qrencodeStructured(const unsigned char *intext, int length, const ch case SVG_TYPE: writeSVG(p->code, filename); break; + case FSVG1_TYPE: + writeFSVG1(p->code, filename); + break; case XPM_TYPE: writeXPM(p->code, filename); break; @@ -1316,6 +1553,8 @@ int main(int argc, char **argv) image_type = EPS_TYPE; } else if(strcasecmp(optarg, "svg") == 0) { image_type = SVG_TYPE; + } else if(strcasecmp(optarg, "fsvg1") == 0) { + image_type = FSVG1_TYPE; } else if(strcasecmp(optarg, "xpm") == 0) { image_type = XPM_TYPE; } else if(strcasecmp(optarg, "ansi") == 0) { @@ -1347,6 +1586,9 @@ int main(int argc, char **argv) case 'k': hint = QR_MODE_KANJI; break; + case 'A': + ascii_plus = atoi(optarg); + break; case 'c': casesensitive = 1; break; From f19d9b4cd8e4014373613b047aacc604e976e21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ball=C3=A9?= Date: Thu, 22 Oct 2015 11:04:20 +0100 Subject: [PATCH 4/5] added two more svg modes that have no transparency and suitable for teeshirt printing --- qrenc.c | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 372 insertions(+), 3 deletions(-) diff --git a/qrenc.c b/qrenc.c index 95c81f91..8e9db7d3 100644 --- a/qrenc.c +++ b/qrenc.c @@ -60,6 +60,8 @@ enum imageType { EPS_TYPE, SVG_TYPE, FSVG1_TYPE, + FSVG2_TYPE, + FSVG3_TYPE, XPM_TYPE, ANSI_TYPE, ANSI256_TYPE, @@ -135,8 +137,8 @@ static void usage(int help, int longopt, int status) " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n" " -d NUMBER, --dpi=NUMBER\n" " specify the DPI of the generated PNG. (default=72)\n\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1},\n" -" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1,FSVG2,FSVG3},\n" +" --type={PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1,FSVG2,FSVG3}\n" " specify the type of the generated image. (default=PNG)\n\n" " -S, --structured\n" " make structured symbols. Version must be specified.\n\n" @@ -190,7 +192,7 @@ static void usage(int help, int longopt, int status) " -v NUMBER specify the minimum version of the symbol. (default=auto)\n" " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n" " -d NUMBER specify the DPI of the generated PNG. (default=72)\n" -" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1}\n" +" -t {PNG,PNG32,EPS,SVG,XPM,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8,ANSI256UTF8,FSVG1,FSVG2,FSVG3}\n" " specify the type of the generated image. (default=PNG)\n" " -S make structured symbols. Version must be specified.\n" " -k assume that the input text contains kanji (shift-jis).\n" @@ -606,6 +608,57 @@ static void writeFSVG1_drawModules(FILE *fp, int x, int y, const char* color) ); } +static void writeFSVG2_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp,"" + ,color,x*10+5,y*10+5 + ); +} + +static void writeFSVG3_drawModules(FILE *fp, int x, int y, const char* color) +{ + fprintf(fp,"\ + \ + \ + \ + " + ,color,x*10+1.8436925,y*10+1.755784 + ,color,x*10+1.2843877,y*10+6.8829622 + ,color,x*10+5.0531077,y*10+4.9817958 + ,color,x*10+7.2622757,y*10+8.4027872 + ,color,x*10+8.0230665,y*10+1.6966467 + ); +} + static int writeFSVG1(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -759,6 +812,312 @@ static int writeFSVG1(const QRcode *qrcode, const char *outfile) return 0; } +static int writeFSVG2(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG2_drawModules(fp,x,y,fg); + else writeFSVG2_drawModules(fp,x,y,bg); + } else writeFSVG2_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + +static int writeFSVG3(const QRcode *qrcode, const char *outfile) +{ + FILE *fp; + unsigned char *row, *p; + int x, y; + int symwidth, realwidth; + char fg[7], bg[7]; + + size=10; //size forced due to design of dots. + + fp = openFile(outfile); + + symwidth = qrcode->width + margin * 2; + realwidth = symwidth * size; + + snprintf(fg, 7, "%02x%02x%02x", fg_color[0], fg_color[1], fg_color[2]); + snprintf(bg, 7, "%02x%02x%02x", bg_color[0], bg_color[1], bg_color[2]); + + /* XML declaration */ + fputs( "\n", fp ); + + /* DTD + No document type specified because "while a DTD is provided in [the SVG] + specification, the use of DTDs for validating XML documents is known to + be problematic. In particular, DTDs do not handle namespaces gracefully. + It is *not* recommended that a DOCTYPE declaration be included in SVG + documents." + http://www.w3.org/TR/2003/REC-SVG11-20030114/intro.html#Namespace + */ + + /* Vanity remark */ + fprintf(fp, "\n", QRcode_APIVersionString()); + + /* SVG code start */ + fprintf(fp, "\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + image/svg+xml\ + \ + \ + \ + \ + \ + " ,realwidth , realwidth + ); + + /* Write data */ + p = qrcode->data; + for(y = 0; y < qrcode->width+2*margin; y++) { + row = (p+((y-margin)*qrcode->width)); + for(x = 0; x < qrcode->width+2*margin; x++) { + if(y>=margin && y-marginwidth && x>=margin && x-marginwidth) { + if(*(row+x-margin)&0x1) writeFSVG3_drawModules(fp,x,y,fg); + else writeFSVG3_drawModules(fp,x,y,bg); + } else writeFSVG3_drawModules(fp,x,y,bg); + } + } + + /* Close group */ + fputs("\t\n", fp); + + /* Close SVG code */ + fputs("\n", fp); + fclose(fp); + + return 0; +} + static int writeSVG(const QRcode *qrcode, const char *outfile) { FILE *fp; @@ -1283,6 +1642,12 @@ static void qrencode(const unsigned char *intext, int length, const char *outfil case FSVG1_TYPE: writeFSVG1(qrcode, outfile); break; + case FSVG2_TYPE: + writeFSVG2(qrcode, outfile); + break; + case FSVG3_TYPE: + writeFSVG3(qrcode, outfile); + break; case XPM_TYPE: writeXPM(qrcode, outfile); break; @@ -1555,6 +1920,10 @@ int main(int argc, char **argv) image_type = SVG_TYPE; } else if(strcasecmp(optarg, "fsvg1") == 0) { image_type = FSVG1_TYPE; + } else if(strcasecmp(optarg, "fsvg2") == 0) { + image_type = FSVG2_TYPE; + } else if(strcasecmp(optarg, "fsvg3") == 0) { + image_type = FSVG3_TYPE; } else if(strcasecmp(optarg, "xpm") == 0) { image_type = XPM_TYPE; } else if(strcasecmp(optarg, "ansi") == 0) { From dbbe6b3a8d394651b266d9b25af3b65aedc5f744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Ball=C3=A9?= Date: Fri, 19 Apr 2019 14:37:41 +0200 Subject: [PATCH 5/5] dot size --- qrenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qrenc.c b/qrenc.c index 8e9db7d3..77b6efc9 100644 --- a/qrenc.c +++ b/qrenc.c @@ -614,7 +614,7 @@ static void writeFSVG2_drawModules(FILE *fp, int x, int y, const char* color) style='fill:#%s;fill-opacity:1;fill-rule:evenodd;stroke:none'\ cx='%d'\ cy='%d'\ - r='3.5' />" + r='4.5' />" ,color,x*10+5,y*10+5 ); }