void test_apiversion(void) { int major_version, minor_version, micro_version; char *str, *str2; testStart("API Version check"); QRcode_APIVersion(&major_version, &minor_version, µ_version); assert_equal(major_version, MAJOR_VERSION, "Major version number mismatched: %d (%d expected)\n", major_version, MAJOR_VERSION); assert_equal(minor_version, MINOR_VERSION, "Minor version number mismatched: %d (%d expected)\n", minor_version, MINOR_VERSION); assert_equal(micro_version, MICRO_VERSION, "Micro version number mismatched: %d (%d expected)\n", micro_version, MICRO_VERSION); str = QRcode_APIVersionString(); str2 = QRcode_APIVersionString(); assert_zero(strcmp(VERSION, str), "Version string mismatched: %s (%s expected)\n", str, VERSION); assert_equal(str, str2, "Version strings are not identical."); testFinish(); }
static void usage(int help, int longopt) { fprintf(stderr, "qrencode version %s\n" "Copyright (C) 2006-2012 Kentaro Fukuchi\n", QRcode_APIVersionString()); if(help) { if(longopt) { fprintf(stderr, "Usage: qrencode [OPTION]... [STRING]\n" "Encode input data in a QR Code and save as a PNG or EPS image.\n\n" " -h, --help display the help message. -h displays only the help of short\n" " options.\n\n" " -o FILENAME, --output=FILENAME\n" " write image to FILENAME. If '-' is specified, the result\n" " will be output to standard output. If -S is given, structured\n" " symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n" " (suffix is removed from FILENAME, if specified)\n" " -s NUMBER, --size=NUMBER\n" " specify module size in dots (pixels). (default=3)\n\n" " -l {LMQH}, --level={LMQH}\n" " specify error correction level from L (lowest) to H (highest).\n" " (default=L)\n\n" " -v NUMBER, --symversion=NUMBER\n" " specify the version of the symbol. See SYMBOL VERSIONS for more\n" " information. (default=auto)\n\n" " -m NUMBER, --margin=NUMBER\n" " 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,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}, --type={PNG,EPS,\n" " SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\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" " -c, --casesensitive\n" " encode lower-case alphabet characters in 8-bit mode. (default)\n\n" " -i, --ignorecase\n" " ignore case distinctions and use only upper-case characters.\n\n" " -8, --8bit encode entire data in 8-bit mode. -k, -c and -i will be ignored.\n\n" " --rle enable run-length encoding for SVG.\n\n" " -M, --micro encode in a Micro QR Code. (experimental)\n\n" " --foreground=RRGGBB[AA]\n" " --background=RRGGBB[AA]\n" " 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 and SVG.\n" " -V, --version\n" " display the version number and copyrights of the qrencode.\n\n" " --verbose\n" " display verbose information to stderr.\n\n" " [STRING] input data. If it is not specified, data will be taken from\n" " standard input.\n\n" "*SYMBOL VERSIONS\n" " The symbol versions of QR Code range from Version 1 to Version\n" " 40. Each version has a different module configuration or number\n" " of modules, ranging from Version 1 (21 x 21 modules) up to\n" " Version 40 (177 x 177 modules). Each higher version number\n" " comprises 4 additional modules per side by default. See\n" " http://www.qrcode.com/en/about/version.html for a detailed\n" " version list.\n" ); } else { fprintf(stderr, "Usage: qrencode [OPTION]... [STRING]\n" "Encode input data in a QR Code and save as a PNG or EPS image.\n\n" " -h display this message.\n" " --help display the usage of long options.\n" " -o FILENAME write image to FILENAME. If '-' is specified, the result\n" " will be output to standard output. If -S is given, structured\n" " symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n" " (suffix is removed from FILENAME, if specified)\n" " -s NUMBER specify module size in dots (pixels). (default=3)\n" " -l {LMQH} specify error correction level from L (lowest) to H (highest).\n" " (default=L)\n" " -v NUMBER specify the 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,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\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" " -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" " -M encode in a Micro QR Code.\n" " --foreground=RRGGBB[AA]\n" " --background=RRGGBB[AA]\n" " 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 and SVG.\n" " -V display the version number and copyrights of the qrencode.\n" " [STRING] input data. If it is not specified, data will be taken from\n" " standard input.\n" ); } } }
static int writeSVG( QRcode *qrcode, const char *outfile ) { FILE *fp; unsigned char *row, *p; int x, y, x0, pen; int symwidth, realwidth; float scale; char fg[7], bg[7]; float fg_opacity; float bg_opacity; fp = openFile(outfile); scale = dpi * INCHES_PER_METER / 100.0; 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]); fg_opacity = (float)fg_color[3] / 255; bg_opacity = (float)bg_color[3] / 255; /* XML declaration */ fputs( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\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, "<!-- Created with qrencode %s (http://fukuchi.org/works/qrencode/index.html.en) -->\n", QRcode_APIVersionString() ); /* SVG code start */ fprintf( fp, "<svg width=\"%0.2fcm\" height=\"%0.2fcm\" viewBox=\"0 0 %d %d\""\ " preserveAspectRatio=\"none\" version=\"1.1\""\ " xmlns=\"http://www.w3.org/2000/svg\">\n", realwidth / scale, realwidth / scale, symwidth, symwidth ); /* Make named group */ fputs( "\t<g id=\"QRcode\">\n", fp ); /* Make solid background */ if(bg_color[3] != 255) { fprintf(fp, "\t\t<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" fill-opacity=\"%f\" />\n", symwidth, symwidth, bg, bg_opacity); } else { fprintf(fp, "\t\t<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", symwidth, symwidth, bg); } /* Create new viewbox for QR data */ fputs( "\t\t<g id=\"Pattern\">\n", fp); /* Write data */ p = qrcode->data; for(y=0; y<qrcode->width; y++) { row = (p+(y*qrcode->width)); if( !rle ) { /* no RLE */ for(x=0; x<qrcode->width; x++) { if(*(row+x)&0x1) { writeSVG_writeRect(fp, margin + x, margin + y, 1, fg, fg_opacity); } } } else { /* simple RLE */ pen = 0; x0 = 0; for(x=0; x<qrcode->width; x++) { if( !pen ) { pen = *(row+x)&0x1; x0 = x; } else { if(!(*(row+x)&0x1)) { writeSVG_writeRect(fp, x0 + margin, y + margin, x-x0, fg, fg_opacity); pen = 0; } } } if( pen ) { writeSVG_writeRect(fp, x0 + margin, y + margin, qrcode->width - x0, fg, fg_opacity); } } } /* Close QR data viewbox */ fputs( "\t\t</g>\n", fp ); /* Close group */ fputs( "\t</g>\n", fp ); /* Close SVG code */ fputs( "</svg>\n", fp ); fclose( fp ); return 0; }