mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Code format and audit, part 3
Update copyright info, remove unused code, etc.
This commit is contained in:
parent
8a88ffdd7b
commit
660d8148bd
128
backend/ps.c
128
backend/ps.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -38,12 +38,7 @@
|
|||||||
|
|
||||||
#define SSET "0123456789ABCDEF"
|
#define SSET "0123456789ABCDEF"
|
||||||
|
|
||||||
/* This file has expanded quite a bit since version 1.5 in order to accomodate
|
int ps_plot(struct zint_symbol *symbol) {
|
||||||
the formatting rules for EAN and UPC symbols as set out in EN 797:1995 - the
|
|
||||||
down side of this support is that the code is now vertually unreadable! */
|
|
||||||
|
|
||||||
int ps_plot(struct zint_symbol *symbol)
|
|
||||||
{
|
|
||||||
int i, block_width, latch, r, this_row;
|
int i, block_width, latch, r, this_row;
|
||||||
float textpos, large_bar_height, preset_height, row_height, row_posn;
|
float textpos, large_bar_height, preset_height, row_height, row_posn;
|
||||||
FILE *feps;
|
FILE *feps;
|
||||||
@ -59,41 +54,41 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
int plot_text = 1;
|
int plot_text = 1;
|
||||||
const char *locale = NULL;
|
const char *locale = NULL;
|
||||||
|
|
||||||
row_height=0;
|
row_height = 0;
|
||||||
textdone = 0;
|
textdone = 0;
|
||||||
main_width = symbol->width;
|
main_width = symbol->width;
|
||||||
strcpy(addon, "");
|
strcpy(addon, "");
|
||||||
comp_offset = 0;
|
comp_offset = 0;
|
||||||
addon_text_posn = 0.0;
|
addon_text_posn = 0.0;
|
||||||
|
|
||||||
if((symbol->output_options & BARCODE_STDOUT) != 0) {
|
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
|
||||||
feps = stdout;
|
feps = stdout;
|
||||||
} else {
|
} else {
|
||||||
feps = fopen(symbol->outfile, "w");
|
feps = fopen(symbol->outfile, "w");
|
||||||
}
|
}
|
||||||
if(feps == NULL) {
|
if (feps == NULL) {
|
||||||
strcpy(symbol->errtxt, "Could not open output file");
|
strcpy(symbol->errtxt, "Could not open output file");
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sort out colour options */
|
/* sort out colour options */
|
||||||
to_upper((unsigned char*)symbol->fgcolour);
|
to_upper((unsigned char*) symbol->fgcolour);
|
||||||
to_upper((unsigned char*)symbol->bgcolour);
|
to_upper((unsigned char*) symbol->bgcolour);
|
||||||
|
|
||||||
if(strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if(strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
@ -119,9 +114,9 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
large_bar_count = 0;
|
large_bar_count = 0;
|
||||||
preset_height = 0.0;
|
preset_height = 0.0;
|
||||||
for(i = 0; i < symbol->rows; i++) {
|
for (i = 0; i < symbol->rows; i++) {
|
||||||
preset_height += symbol->row_height[i];
|
preset_height += symbol->row_height[i];
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
large_bar_count++;
|
large_bar_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,18 +126,18 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
symbol->height = preset_height;
|
symbol->height = preset_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
||||||
comp_offset++;
|
comp_offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
||||||
|| (symbol->symbology == BARCODE_ISBNX)) {
|
|| (symbol->symbology == BARCODE_ISBNX)) {
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 13: /* EAN 13 */
|
case 13: /* EAN 13 */
|
||||||
case 16:
|
case 16:
|
||||||
case 19:
|
case 19:
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
}
|
}
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
@ -153,14 +148,14 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 51 + comp_offset;
|
main_width = 51 + comp_offset;
|
||||||
}
|
}
|
||||||
@ -169,8 +164,8 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
latch = 0;
|
latch = 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
/* Isolate add-on text */
|
/* Isolate add-on text */
|
||||||
if(is_extendable(symbol->symbology)) {
|
if (is_extendable(symbol->symbology)) {
|
||||||
for(i = 0; i < ustrlen(symbol->text); i++) {
|
for (i = 0; i < ustrlen(symbol->text); i++) {
|
||||||
if (latch == 1) {
|
if (latch == 1) {
|
||||||
addon[r] = symbol->text[i];
|
addon[r] = symbol->text[i];
|
||||||
r++;
|
r++;
|
||||||
@ -182,10 +177,10 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
addon[r] = '\0';
|
addon[r] = '\0';
|
||||||
|
|
||||||
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
|
if ((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
|
||||||
plot_text = 0;
|
plot_text = 0;
|
||||||
}
|
}
|
||||||
if(plot_text) {
|
if (plot_text) {
|
||||||
textoffset = 9;
|
textoffset = 9;
|
||||||
} else {
|
} else {
|
||||||
textoffset = 0;
|
textoffset = 0;
|
||||||
@ -196,13 +191,13 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
/* Start writing the header */
|
/* Start writing the header */
|
||||||
fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
|
fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
|
||||||
fprintf(feps, "%%%%Creator: Zint %s\n", ZINT_VERSION);
|
fprintf(feps, "%%%%Creator: Zint %s\n", ZINT_VERSION);
|
||||||
if(ustrlen(symbol->text) != 0) {
|
if (ustrlen(symbol->text) != 0) {
|
||||||
fprintf(feps, "%%%%Title: %s\n",symbol->text);
|
fprintf(feps, "%%%%Title: %s\n", symbol->text);
|
||||||
} else {
|
} else {
|
||||||
fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
|
fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
|
||||||
}
|
}
|
||||||
fprintf(feps, "%%%%Pages: 0\n");
|
fprintf(feps, "%%%%Pages: 0\n");
|
||||||
if(symbol->symbology != BARCODE_MAXICODE) {
|
if (symbol->symbology != BARCODE_MAXICODE) {
|
||||||
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
|
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
|
||||||
} else {
|
} else {
|
||||||
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
|
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
|
||||||
@ -224,13 +219,13 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
|
||||||
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", (symbol->height + textoffset + yoffset + yoffset) * scaler, (symbol->width + xoffset + xoffset) * scaler);
|
fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", (symbol->height + textoffset + yoffset + yoffset) * scaler, (symbol->width + xoffset + xoffset) * scaler);
|
||||||
|
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
default_text_posn = 0.5 * scaler;
|
default_text_posn = 0.5 * scaler;
|
||||||
} else {
|
} else {
|
||||||
default_text_posn = (symbol->border_width + 0.5) * scaler;
|
default_text_posn = (symbol->border_width + 0.5) * scaler;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_MAXICODE) {
|
if (symbol->symbology == BARCODE_MAXICODE) {
|
||||||
/* Maxicode uses hexagons */
|
/* Maxicode uses hexagons */
|
||||||
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
|
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
|
||||||
|
|
||||||
@ -242,7 +237,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
|
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
|
||||||
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + 72.0 + symbol->border_width) * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
|
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + 72.0 + symbol->border_width) * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
|
||||||
}
|
}
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
fprintf(feps, "TE\n");
|
fprintf(feps, "TE\n");
|
||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
@ -256,9 +251,9 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 10.85 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 8.97 * scaler, (44.73 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 10.85 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 8.97 * scaler, (44.73 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
||||||
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 7.10 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, (40.98 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 7.10 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, (40.98 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
||||||
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, (37.19 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, (37.19 + xoffset) * scaler, (35.60 + yoffset) * scaler);
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
for(i = 0; i < symbol->width; i++) {
|
for (i = 0; i < symbol->width; i++) {
|
||||||
if(module_is_set(symbol, r, i)) {
|
if (module_is_set(symbol, r, i)) {
|
||||||
/* Dump a hexagon */
|
/* Dump a hexagon */
|
||||||
my = ((symbol->rows - r - 1)) * 2.135 + 1.43;
|
my = ((symbol->rows - r - 1)) * 2.135 + 1.43;
|
||||||
ay = my + 1.0 + yoffset;
|
ay = my + 1.0 + yoffset;
|
||||||
@ -282,21 +277,21 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology != BARCODE_MAXICODE) {
|
if (symbol->symbology != BARCODE_MAXICODE) {
|
||||||
/* everything else uses rectangles (or squares) */
|
/* everything else uses rectangles (or squares) */
|
||||||
/* Works from the bottom of the symbol up */
|
/* Works from the bottom of the symbol up */
|
||||||
int addon_latch = 0;
|
int addon_latch = 0;
|
||||||
|
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
|
this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
|
||||||
if(symbol->row_height[this_row] == 0) {
|
if (symbol->row_height[this_row] == 0) {
|
||||||
row_height = large_bar_height;
|
row_height = large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_height = symbol->row_height[this_row];
|
row_height = symbol->row_height[this_row];
|
||||||
}
|
}
|
||||||
row_posn = 0;
|
row_posn = 0;
|
||||||
for(i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
||||||
if(symbol->row_height[symbol->rows - i - 1] == 0) {
|
if (symbol->row_height[symbol->rows - i - 1] == 0) {
|
||||||
row_posn += large_bar_height;
|
row_posn += large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_posn += symbol->row_height[symbol->rows - i - 1];
|
row_posn += symbol->row_height[symbol->rows - i - 1];
|
||||||
@ -308,7 +303,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler);
|
fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler);
|
||||||
i = 0;
|
i = 0;
|
||||||
if(module_is_set(symbol, this_row, 0)) {
|
if (module_is_set(symbol, this_row, 0)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
} else {
|
} else {
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -319,14 +314,14 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
||||||
if((addon_latch == 0) && (r == 0) && (i > main_width)) {
|
if ((addon_latch == 0) && (r == 0) && (i > main_width)) {
|
||||||
fprintf(feps, "TE\n");
|
fprintf(feps, "TE\n");
|
||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
fprintf(feps, "%.2f %.2f ", (row_height - 5.0) * scaler, (row_posn - 5.0) * scaler);
|
fprintf(feps, "%.2f %.2f ", (row_height - 5.0) * scaler, (row_posn - 5.0) * scaler);
|
||||||
addon_text_posn = row_posn + row_height - 8.0;
|
addon_text_posn = row_posn + row_height - 8.0;
|
||||||
addon_latch = 1;
|
addon_latch = 1;
|
||||||
}
|
}
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset) * scaler, block_width * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset) * scaler, block_width * scaler);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -347,7 +342,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
||||||
(symbol->symbology == BARCODE_ISBNX)) {
|
(symbol->symbology == BARCODE_ISBNX)) {
|
||||||
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 8: /* EAN-8 */
|
case 8: /* EAN-8 */
|
||||||
case 11:
|
case 11:
|
||||||
case 14:
|
case 14:
|
||||||
@ -360,7 +355,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "TB %.2f %.2f TR\n", (34 + xoffset) * scaler, 1 * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (34 + xoffset) * scaler, 1 * scaler);
|
||||||
fprintf(feps, "TB %.2f %.2f TR\n", (64 + xoffset) * scaler, 1 * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (64 + xoffset) * scaler, 1 * scaler);
|
||||||
fprintf(feps, "TB %.2f %.2f TR\n", (66 + xoffset) * scaler, 1 * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (66 + xoffset) * scaler, 1 * scaler);
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i];
|
textpart[i] = symbol->text[i];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
@ -376,7 +371,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i + 4];
|
textpart[i] = symbol->text[i + 4];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
@ -391,7 +386,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
fprintf(feps, "matrix currentmatrix\n");
|
fprintf(feps, "matrix currentmatrix\n");
|
||||||
fprintf(feps, "/Helvetica findfont\n");
|
fprintf(feps, "/Helvetica findfont\n");
|
||||||
@ -445,7 +440,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -459,7 +454,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 7];
|
textpart[i] = symbol->text[i + 7];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -474,7 +469,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
fprintf(feps, "matrix currentmatrix\n");
|
fprintf(feps, "matrix currentmatrix\n");
|
||||||
fprintf(feps, "/Helvetica findfont\n");
|
fprintf(feps, "/Helvetica findfont\n");
|
||||||
@ -518,7 +513,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -537,7 +532,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
|
fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -561,7 +556,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[5] = '\0';
|
textpart[5] = '\0';
|
||||||
@ -575,7 +570,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 6];
|
textpart[i] = symbol->text[i + 6];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -602,7 +597,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
fprintf(feps, "matrix currentmatrix\n");
|
fprintf(feps, "matrix currentmatrix\n");
|
||||||
fprintf(feps, "/Helvetica findfont\n");
|
fprintf(feps, "/Helvetica findfont\n");
|
||||||
@ -655,7 +650,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "-2 div 0 rmoveto\n");
|
fprintf(feps, "-2 div 0 rmoveto\n");
|
||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -682,7 +677,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, " (%s) show\n", textpart);
|
fprintf(feps, " (%s) show\n", textpart);
|
||||||
fprintf(feps, "setmatrix\n");
|
fprintf(feps, "setmatrix\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
fprintf(feps, "matrix currentmatrix\n");
|
fprintf(feps, "matrix currentmatrix\n");
|
||||||
fprintf(feps, "/Helvetica findfont\n");
|
fprintf(feps, "/Helvetica findfont\n");
|
||||||
@ -714,17 +709,17 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
xoffset -= comp_offset;
|
xoffset -= comp_offset;
|
||||||
|
|
||||||
switch(symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_MAXICODE:
|
case BARCODE_MAXICODE:
|
||||||
/* Do nothing! (It's already been done) */
|
/* Do nothing! (It's already been done) */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if((symbol->output_options & BARCODE_BIND) != 0) {
|
if ((symbol->output_options & BARCODE_BIND) != 0) {
|
||||||
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
||||||
/* row binding */
|
/* row binding */
|
||||||
fprintf(feps, "TE\n");
|
fprintf(feps, "TE\n");
|
||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
for(r = 1; r < symbol->rows; r++) {
|
for (r = 1; r < symbol->rows; r++) {
|
||||||
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
|
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -735,7 +730,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
|
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
|
||||||
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
|
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
|
||||||
}
|
}
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
fprintf(feps, "TE\n");
|
fprintf(feps, "TE\n");
|
||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
@ -746,7 +741,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Put the human readable text at the bottom */
|
/* Put the human readable text at the bottom */
|
||||||
if(plot_text && (textdone == 0)) {
|
if (plot_text && (textdone == 0)) {
|
||||||
fprintf(feps, "TE\n");
|
fprintf(feps, "TE\n");
|
||||||
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
|
||||||
fprintf(feps, "matrix currentmatrix\n");
|
fprintf(feps, "matrix currentmatrix\n");
|
||||||
@ -762,7 +757,7 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
fprintf(feps, "\nshowpage\n");
|
fprintf(feps, "\nshowpage\n");
|
||||||
|
|
||||||
if(symbol->output_options & BARCODE_STDOUT) {
|
if (symbol->output_options & BARCODE_STDOUT) {
|
||||||
fflush(feps);
|
fflush(feps);
|
||||||
} else {
|
} else {
|
||||||
fclose(feps);
|
fclose(feps);
|
||||||
@ -773,4 +768,3 @@ int ps_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1580
backend/qr.c
1580
backend/qr.c
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
|
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -29,7 +29,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LEVEL_L 1
|
#define LEVEL_L 1
|
||||||
#define LEVEL_M 2
|
#define LEVEL_M 2
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// It is not written with high efficiency in mind, so is probably
|
// It is not written with high efficiency in mind, so is probably
|
||||||
// not suitable for real-time encoding. The aim was to keep it
|
// not suitable for real-time encoding. The aim was to keep it
|
||||||
@ -68,8 +68,7 @@ static int *logt = NULL, *alog = NULL, *rspoly = NULL;
|
|||||||
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
|
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
|
||||||
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
|
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
|
||||||
|
|
||||||
void rs_init_gf(int poly)
|
void rs_init_gf(int poly) {
|
||||||
{
|
|
||||||
int m, b, p, v;
|
int m, b, p, v;
|
||||||
|
|
||||||
// Find the top bit, and hence the symbol size
|
// Find the top bit, and hence the symbol size
|
||||||
@ -82,8 +81,8 @@ void rs_init_gf(int poly)
|
|||||||
|
|
||||||
// Calculate the log/alog tables
|
// Calculate the log/alog tables
|
||||||
logmod = (1 << m) - 1;
|
logmod = (1 << m) - 1;
|
||||||
logt = (int *)malloc(sizeof(int) * (logmod + 1));
|
logt = (int *) malloc(sizeof (int) * (logmod + 1));
|
||||||
alog = (int *)malloc(sizeof(int) * logmod);
|
alog = (int *) malloc(sizeof (int) * logmod);
|
||||||
|
|
||||||
for (p = 1, v = 0; v < logmod; v++) {
|
for (p = 1, v = 0; v < logmod; v++) {
|
||||||
alog[v] = p;
|
alog[v] = p;
|
||||||
@ -101,11 +100,10 @@ void rs_init_gf(int poly)
|
|||||||
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
|
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
|
||||||
// For ECC200, index is 1.
|
// For ECC200, index is 1.
|
||||||
|
|
||||||
void rs_init_code(int nsym, int index)
|
void rs_init_code(int nsym, int index) {
|
||||||
{
|
|
||||||
int i, k;
|
int i, k;
|
||||||
|
|
||||||
rspoly = (int *)malloc(sizeof(int) * (nsym + 1));
|
rspoly = (int *) malloc(sizeof (int) * (nsym + 1));
|
||||||
|
|
||||||
rlen = nsym;
|
rlen = nsym;
|
||||||
|
|
||||||
@ -122,8 +120,7 @@ void rs_init_code(int nsym, int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rs_encode(int len, unsigned char *data, unsigned char *res)
|
void rs_encode(int len, unsigned char *data, unsigned char *res) {
|
||||||
{
|
|
||||||
int i, k, m;
|
int i, k, m;
|
||||||
for (i = 0; i < rlen; i++)
|
for (i = 0; i < rlen; i++)
|
||||||
res[i] = 0;
|
res[i] = 0;
|
||||||
@ -142,8 +139,8 @@ void rs_encode(int len, unsigned char *data, unsigned char *res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rs_encode_long(int len, unsigned int *data, unsigned int *res)
|
/* The same as above but for larger bitlengths - Aztec code compatible */
|
||||||
{ /* The same as above but for larger bitlengths - Aztec code compatible */
|
void rs_encode_long(int len, unsigned int *data, unsigned int *res) {
|
||||||
int i, k, m;
|
int i, k, m;
|
||||||
for (i = 0; i < rlen; i++)
|
for (i = 0; i < rlen; i++)
|
||||||
res[i] = 0;
|
res[i] = 0;
|
||||||
@ -162,8 +159,8 @@ void rs_encode_long(int len, unsigned int *data, unsigned int *res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rs_free(void)
|
/* Free memory */
|
||||||
{ /* Free memory */
|
void rs_free(void) {
|
||||||
free(logt);
|
free(logt);
|
||||||
free(alog);
|
free(alog);
|
||||||
free(rspoly);
|
free(rspoly);
|
||||||
|
@ -34,15 +34,14 @@
|
|||||||
#define __REEDSOL_H
|
#define __REEDSOL_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
extern void rs_init_gf(int poly);
|
extern void rs_init_gf(int poly);
|
||||||
extern void rs_init_code(int nsym, int index);
|
extern void rs_init_code(int nsym, int index);
|
||||||
extern void rs_encode(int len, unsigned char *data, unsigned char *res);
|
extern void rs_encode(int len, unsigned char *data, unsigned char *res);
|
||||||
extern void rs_encode_long(int len, unsigned int *data, unsigned int *res);
|
extern void rs_encode_long(int len, unsigned int *data, unsigned int *res);
|
||||||
extern void rs_free(void);
|
extern void rs_free(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
161
backend/render.c
161
backend/render.c
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -34,7 +34,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -56,8 +56,7 @@ int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexag
|
|||||||
|
|
||||||
int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string);
|
int render_plot_add_string(struct zint_symbol *symbol, unsigned char *text, float x, float y, float fsize, float width, struct zint_render_string **last_string);
|
||||||
|
|
||||||
int render_plot(struct zint_symbol *symbol, float width, float height)
|
int render_plot(struct zint_symbol *symbol, float width, float height) {
|
||||||
{
|
|
||||||
struct zint_render *render;
|
struct zint_render *render;
|
||||||
struct zint_render_line *line, *last_line = NULL;
|
struct zint_render_line *line, *last_line = NULL;
|
||||||
struct zint_render_string *last_string = NULL;
|
struct zint_render_string *last_string = NULL;
|
||||||
@ -81,7 +80,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
int upceanflag = 0;
|
int upceanflag = 0;
|
||||||
|
|
||||||
// Allocate memory for the rendered version
|
// Allocate memory for the rendered version
|
||||||
render = symbol->rendered = (struct zint_render *) malloc(sizeof(struct zint_render));
|
render = symbol->rendered = (struct zint_render *) malloc(sizeof (struct zint_render));
|
||||||
render->lines = NULL;
|
render->lines = NULL;
|
||||||
render->strings = NULL;
|
render->strings = NULL;
|
||||||
render->rings = NULL;
|
render->rings = NULL;
|
||||||
@ -104,8 +103,8 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
latch = 0;
|
latch = 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
/* Isolate add-on text */
|
/* Isolate add-on text */
|
||||||
if(is_extendable(symbol->symbology)) {
|
if (is_extendable(symbol->symbology)) {
|
||||||
for(i = 0; i < ustrlen(symbol->text); i++) {
|
for (i = 0; i < ustrlen(symbol->text); i++) {
|
||||||
if (latch == 1) {
|
if (latch == 1) {
|
||||||
addon[r] = symbol->text[i];
|
addon[r] = symbol->text[i];
|
||||||
r++;
|
r++;
|
||||||
@ -117,7 +116,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
}
|
}
|
||||||
addon[r] = '\0';
|
addon[r] = '\0';
|
||||||
|
|
||||||
if((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)) {
|
if ((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)) {
|
||||||
hide_text = 1;
|
hide_text = 1;
|
||||||
text_height = text_offset = 0.0;
|
text_height = text_offset = 0.0;
|
||||||
} else {
|
} else {
|
||||||
@ -131,18 +130,18 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
* borders or white space to add.
|
* borders or white space to add.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
while(!(module_is_set(symbol, symbol->rows - 1, symbol_lead_in))) {
|
while (!(module_is_set(symbol, symbol->rows - 1, symbol_lead_in))) {
|
||||||
symbol_lead_in++;
|
symbol_lead_in++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
||||||
|| (symbol->symbology == BARCODE_ISBNX)) {
|
|| (symbol->symbology == BARCODE_ISBNX)) {
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 13: /* EAN 13 */
|
case 13: /* EAN 13 */
|
||||||
case 16:
|
case 16:
|
||||||
case 19:
|
case 19:
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
}
|
}
|
||||||
main_symbol_width_x = 96 + symbol_lead_in;
|
main_symbol_width_x = 96 + symbol_lead_in;
|
||||||
@ -160,7 +159,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
main_symbol_width_x = 68 + symbol_lead_in;
|
main_symbol_width_x = 68 + symbol_lead_in;
|
||||||
upceanflag = 8;
|
upceanflag = 8;
|
||||||
}
|
}
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 11:
|
case 11:
|
||||||
case 16:
|
case 16:
|
||||||
/* EAN-2 add-on */
|
/* EAN-2 add-on */
|
||||||
@ -176,11 +175,11 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
||||||
upceanflag = 12;
|
upceanflag = 12;
|
||||||
if(symbol->whitespace_width < 10) {
|
if (symbol->whitespace_width < 10) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_symbol_width_x = 96 + symbol_lead_in;
|
main_symbol_width_x = 96 + symbol_lead_in;
|
||||||
}
|
}
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 15:
|
case 15:
|
||||||
/* EAN-2 add-on */
|
/* EAN-2 add-on */
|
||||||
addon_width_x = 31;
|
addon_width_x = 31;
|
||||||
@ -194,11 +193,11 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
||||||
upceanflag = 6;
|
upceanflag = 6;
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_symbol_width_x = 51 + symbol_lead_in;
|
main_symbol_width_x = 51 + symbol_lead_in;
|
||||||
}
|
}
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 11:
|
case 11:
|
||||||
/* EAN-2 add-on */
|
/* EAN-2 add-on */
|
||||||
addon_width_x = 31;
|
addon_width_x = 31;
|
||||||
@ -219,9 +218,9 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
// Determine if height should be overridden
|
// Determine if height should be overridden
|
||||||
large_bar_count = 0;
|
large_bar_count = 0;
|
||||||
preset_height = 0.0;
|
preset_height = 0.0;
|
||||||
for(i = 0; i < symbol->rows; i++) {
|
for (i = 0; i < symbol->rows; i++) {
|
||||||
preset_height += symbol->row_height[i];
|
preset_height += symbol->row_height[i];
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
large_bar_count++;
|
large_bar_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +249,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
}
|
}
|
||||||
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
||||||
|
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
default_text_posn = (symbol->height + text_offset + symbol->border_width + symbol->border_width) * scaler;
|
default_text_posn = (symbol->height + text_offset + symbol->border_width + symbol->border_width) * scaler;
|
||||||
} else {
|
} else {
|
||||||
default_text_posn = (symbol->height + text_offset + symbol->border_width) * scaler;
|
default_text_posn = (symbol->height + text_offset + symbol->border_width) * scaler;
|
||||||
@ -261,32 +260,32 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
|
|
||||||
/* Set minimum size of symbol */
|
/* Set minimum size of symbol */
|
||||||
/* Barcode must be at least 2mm high by 2mm across */
|
/* Barcode must be at least 2mm high by 2mm across */
|
||||||
if(render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST) {
|
if (render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST) {
|
||||||
render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST;
|
render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 2.0) * GL_CONST;
|
||||||
}
|
}
|
||||||
if(render->width < (2.0 * GL_CONST)) {
|
if (render->width < (2.0 * GL_CONST)) {
|
||||||
render->width = (2.0 * GL_CONST);
|
render->width = (2.0 * GL_CONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_CODABAR) {
|
if (symbol->symbology == BARCODE_CODABAR) {
|
||||||
/* The minimum X-dimension of Codabar is 0.191mm. The minimum bar height is 5mm */
|
/* The minimum X-dimension of Codabar is 0.191mm. The minimum bar height is 5mm */
|
||||||
if(x_dimension < 0.191) {
|
if (x_dimension < 0.191) {
|
||||||
render->width = 0.191 * GL_CONST * total_area_width_x;
|
render->width = 0.191 * GL_CONST * total_area_width_x;
|
||||||
}
|
}
|
||||||
if(render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST) {
|
if (render->height < ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST) {
|
||||||
render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST;
|
render->height = ((x_dimension * ((2 * symbol->border_width) + text_offset + text_height)) + 5.0) * GL_CONST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_CODE49) {
|
if (symbol->symbology == BARCODE_CODE49) {
|
||||||
/* The minimum X-dimension of Code 49 is 0.191mm */
|
/* The minimum X-dimension of Code 49 is 0.191mm */
|
||||||
if(x_dimension < 0.191) {
|
if (x_dimension < 0.191) {
|
||||||
render->width = 0.191 * GL_CONST * total_area_width_x;
|
render->width = 0.191 * GL_CONST * total_area_width_x;
|
||||||
render->height = render->width / symbol_aspect;
|
render->height = render->width / symbol_aspect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(upceanflag != 0) {
|
if (upceanflag != 0) {
|
||||||
/* The X-dimension of UPC/EAN symbols is fixed at 0.330mm */
|
/* The X-dimension of UPC/EAN symbols is fixed at 0.330mm */
|
||||||
/* NOTE: This code will need adjustment before it correctly deals with composite symbols */
|
/* NOTE: This code will need adjustment before it correctly deals with composite symbols */
|
||||||
render->width = 0.330 * GL_CONST * total_area_width_x;
|
render->width = 0.330 * GL_CONST * total_area_width_x;
|
||||||
@ -311,32 +310,32 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_ONECODE) {
|
if (symbol->symbology == BARCODE_ONECODE) {
|
||||||
/* The size of USPS Intelligent Mail barcode is fixed */
|
/* The size of USPS Intelligent Mail barcode is fixed */
|
||||||
render->width = 0.508 * GL_CONST * total_area_width_x;
|
render->width = 0.508 * GL_CONST * total_area_width_x;
|
||||||
render->height = 4.064 * GL_CONST;
|
render->height = 4.064 * GL_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) {
|
if ((symbol->symbology == BARCODE_POSTNET) || (symbol->symbology == BARCODE_PLANET)) {
|
||||||
/* The size of PostNet and PLANET are fized */
|
/* The size of PostNet and PLANET are fized */
|
||||||
render->width = 0.508 * GL_CONST * total_area_width_x;
|
render->width = 0.508 * GL_CONST * total_area_width_x;
|
||||||
render->height = 2.921 * GL_CONST;
|
render->height = 2.921 * GL_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) ||
|
if (((symbol->symbology == BARCODE_AUSPOST) || (symbol->symbology == BARCODE_AUSREPLY)) ||
|
||||||
((symbol->symbology == BARCODE_AUSROUTE) || (symbol->symbology == BARCODE_AUSREDIRECT))) {
|
((symbol->symbology == BARCODE_AUSROUTE) || (symbol->symbology == BARCODE_AUSREDIRECT))) {
|
||||||
/* Australia Post use the same sizes as USPS */
|
/* Australia Post use the same sizes as USPS */
|
||||||
render->width = 0.508 * GL_CONST * total_area_width_x;
|
render->width = 0.508 * GL_CONST * total_area_width_x;
|
||||||
render->height = 4.064 * GL_CONST;
|
render->height = 4.064 * GL_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) {
|
if ((symbol->symbology == BARCODE_RM4SCC) || (symbol->symbology == BARCODE_KIX)) {
|
||||||
/* Royal Mail and KIX Code uses 22 bars per inch */
|
/* Royal Mail and KIX Code uses 22 bars per inch */
|
||||||
render->width = 0.577 * GL_CONST * total_area_width_x;
|
render->width = 0.577 * GL_CONST * total_area_width_x;
|
||||||
render->height = 5.22 * GL_CONST;
|
render->height = 5.22 * GL_CONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_MAXICODE) {
|
if (symbol->symbology == BARCODE_MAXICODE) {
|
||||||
/* Maxicode is a fixed size */
|
/* Maxicode is a fixed size */
|
||||||
scaler = GL_CONST; /* Converts from millimeters to the scale used by glabels */
|
scaler = GL_CONST; /* Converts from millimeters to the scale used by glabels */
|
||||||
render->width = 28.16 * scaler;
|
render->width = 28.16 * scaler;
|
||||||
@ -351,9 +350,9 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
render_plot_add_ring(symbol, ring, &last_ring);
|
render_plot_add_ring(symbol, ring, &last_ring);
|
||||||
|
|
||||||
/* Hexagons */
|
/* Hexagons */
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
for(i = 0; i < symbol->width; i++) {
|
for (i = 0; i < symbol->width; i++) {
|
||||||
if(module_is_set(symbol, r, i)) {
|
if (module_is_set(symbol, r, i)) {
|
||||||
hexagon = render_plot_create_hexagon(((i * 0.88) + (r & 1 ? 1.76 : 1.32)) * scaler, ((r * 0.76) + 0.76) * scaler);
|
hexagon = render_plot_create_hexagon(((i * 0.88) + (r & 1 ? 1.76 : 1.32)) * scaler, ((r * 0.76) + 0.76) * scaler);
|
||||||
render_plot_add_hexagon(symbol, hexagon, &last_hexagon);
|
render_plot_add_hexagon(symbol, hexagon, &last_hexagon);
|
||||||
}
|
}
|
||||||
@ -365,16 +364,16 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
/* Works from the bottom of the symbol up */
|
/* Works from the bottom of the symbol up */
|
||||||
int addon_latch = 0;
|
int addon_latch = 0;
|
||||||
|
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
this_row = r;
|
this_row = r;
|
||||||
if(symbol->row_height[this_row] == 0) {
|
if (symbol->row_height[this_row] == 0) {
|
||||||
row_height = large_bar_height;
|
row_height = large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_height = symbol->row_height[this_row];
|
row_height = symbol->row_height[this_row];
|
||||||
}
|
}
|
||||||
row_posn = 0;
|
row_posn = 0;
|
||||||
for(i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
row_posn += large_bar_height;
|
row_posn += large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_posn += symbol->row_height[i];
|
row_posn += symbol->row_height[i];
|
||||||
@ -383,7 +382,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
row_posn += yoffset;
|
row_posn += yoffset;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if(module_is_set(symbol, this_row, 0)) {
|
if (module_is_set(symbol, this_row, 0)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
} else {
|
} else {
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -394,13 +393,13 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
||||||
if((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_symbol_width_x)) {
|
if ((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_symbol_width_x)) {
|
||||||
addon_text_posn = row_posn * scaler;
|
addon_text_posn = row_posn * scaler;
|
||||||
addon_latch = 1;
|
addon_latch = 1;
|
||||||
}
|
}
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
if(addon_latch == 0) {
|
if (addon_latch == 0) {
|
||||||
line = render_plot_create_line((i + xoffset) * scaler, (row_posn) * scaler, block_width * scaler, row_height * scaler);
|
line = render_plot_create_line((i + xoffset) * scaler, (row_posn) * scaler, block_width * scaler, row_height * scaler);
|
||||||
} else {
|
} else {
|
||||||
line = render_plot_create_line((i + xoffset) * scaler, (row_posn + 10.0) * scaler, block_width * scaler, (row_height - 5.0) * scaler);
|
line = render_plot_create_line((i + xoffset) * scaler, (row_posn + 10.0) * scaler, block_width * scaler, (row_height - 5.0) * scaler);
|
||||||
@ -425,11 +424,11 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
row_posn = (row_posn + large_bar_height) * scaler;
|
row_posn = (row_posn + large_bar_height) * scaler;
|
||||||
|
|
||||||
if (!hide_text) {
|
if (!hide_text) {
|
||||||
if(upceanflag == 8) {
|
if (upceanflag == 8) {
|
||||||
/* guard bar extensions and text formatting for EAN-8 */
|
/* guard bar extensions and text formatting for EAN-8 */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 10:
|
case 10:
|
||||||
@ -442,21 +441,21 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i];
|
textpart[i] = symbol->text[i];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
textpos = 17;
|
textpos = 17;
|
||||||
textwidth = 4.0 * 8.5;
|
textwidth = 4.0 * 8.5;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i + 4];
|
textpart[i] = symbol->text[i + 4];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
textpos = 50;
|
textpos = 50;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 86;
|
textpos = xoffset + 86;
|
||||||
textwidth = 2.0 * 8.5;
|
textwidth = 2.0 * 8.5;
|
||||||
@ -471,11 +470,11 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(upceanflag == 13) {
|
if (upceanflag == 13) {
|
||||||
/* guard bar extensions and text formatting for EAN-13 */
|
/* guard bar extensions and text formatting for EAN-13 */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 14:
|
case 14:
|
||||||
@ -494,21 +493,21 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
textwidth = 8.5;
|
textwidth = 8.5;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
|
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
textpos = 25;
|
textpos = 25;
|
||||||
textwidth = 6.0 * 8.5;
|
textwidth = 6.0 * 8.5;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 7];
|
textpart[i] = symbol->text[i + 7];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
textpos = 72;
|
textpos = 72;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 114;
|
textpos = xoffset + 114;
|
||||||
textwidth = 2.0 * 8.5;
|
textwidth = 2.0 * 8.5;
|
||||||
@ -526,7 +525,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
/* guard bar extensions and text formatting for UPCA */
|
/* guard bar extensions and text formatting for UPCA */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
@ -548,14 +547,14 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
textpos = -5;
|
textpos = -5;
|
||||||
textwidth = 6.2;
|
textwidth = 6.2;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[5] = '\0';
|
textpart[5] = '\0';
|
||||||
textpos = 27;
|
textpos = 27;
|
||||||
textwidth = 5.0 * 8.5;
|
textwidth = 5.0 * 8.5;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn, 11.0 * scaler, textwidth * scaler, &last_string);
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 6];
|
textpart[i] = symbol->text[i + 6];
|
||||||
}
|
}
|
||||||
textpos = 68;
|
textpos = 68;
|
||||||
@ -566,7 +565,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
textwidth = 6.2;
|
textwidth = 6.2;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 116;
|
textpos = xoffset + 116;
|
||||||
textwidth = 2.0 * 8.5;
|
textwidth = 2.0 * 8.5;
|
||||||
@ -584,7 +583,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
/* guard bar extensions and text formatting for UPCE */
|
/* guard bar extensions and text formatting for UPCE */
|
||||||
i = 0;
|
i = 0;
|
||||||
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
for (line = symbol->rendered->lines; line != NULL; line = line->next) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 14:
|
case 14:
|
||||||
@ -601,7 +600,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
textpos = -5;
|
textpos = -5;
|
||||||
textwidth = 6.2;
|
textwidth = 6.2;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -614,7 +613,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
textwidth = 6.2;
|
textwidth = 6.2;
|
||||||
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
render_plot_add_string(symbol, (unsigned char *) textpart, (textpos + xoffset) * scaler, default_text_posn + (2.0 * scaler), 8.0 * scaler, textwidth * scaler, &last_string);
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 70;
|
textpos = xoffset + 70;
|
||||||
textwidth = 2.0 * 8.5;
|
textwidth = 2.0 * 8.5;
|
||||||
@ -635,15 +634,15 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_MAXICODE:
|
case BARCODE_MAXICODE:
|
||||||
/* Do nothing! */
|
/* Do nothing! */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if((symbol->output_options & BARCODE_BIND) != 0) {
|
if ((symbol->output_options & BARCODE_BIND) != 0) {
|
||||||
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
||||||
/* row binding */
|
/* row binding */
|
||||||
for(r = 1; r < symbol->rows; r++) {
|
for (r = 1; r < symbol->rows; r++) {
|
||||||
line = render_plot_create_line(xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler);
|
line = render_plot_create_line(xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler);
|
||||||
render_plot_add_line(symbol, line, &last_line);
|
render_plot_add_line(symbol, line, &last_line);
|
||||||
}
|
}
|
||||||
@ -655,7 +654,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
line = render_plot_create_line(0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
line = render_plot_create_line(0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
||||||
render_plot_add_line(symbol, line, &last_line);
|
render_plot_add_line(symbol, line, &last_line);
|
||||||
}
|
}
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
line = render_plot_create_line(0, 0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
line = render_plot_create_line(0, 0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
||||||
render_plot_add_line(symbol, line, &last_line);
|
render_plot_add_line(symbol, line, &last_line);
|
||||||
@ -671,18 +670,16 @@ int render_plot(struct zint_symbol *symbol, float width, float height)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new line with its memory allocated ready for adding to the
|
* Create a new line with its memory allocated ready for adding to the
|
||||||
* rendered structure.
|
* rendered structure.
|
||||||
*
|
*
|
||||||
* This is much quicker than writing out each line manually (in some cases!)
|
* This is much quicker than writing out each line manually (in some cases!)
|
||||||
*/
|
*/
|
||||||
struct zint_render_line *render_plot_create_line(float x, float y, float width, float length)
|
struct zint_render_line *render_plot_create_line(float x, float y, float width, float length) {
|
||||||
{
|
|
||||||
struct zint_render_line *line;
|
struct zint_render_line *line;
|
||||||
|
|
||||||
line = (struct zint_render_line*) malloc(sizeof(struct zint_render_line));
|
line = (struct zint_render_line*) malloc(sizeof (struct zint_render_line));
|
||||||
line->next = NULL;
|
line->next = NULL;
|
||||||
line->x = x;
|
line->x = x;
|
||||||
line->y = y;
|
line->y = y;
|
||||||
@ -696,8 +693,7 @@ struct zint_render_line *render_plot_create_line(float x, float y, float width,
|
|||||||
* Add the line to the current rendering and update the last line's
|
* Add the line to the current rendering and update the last line's
|
||||||
* next value.
|
* next value.
|
||||||
*/
|
*/
|
||||||
int render_plot_add_line(struct zint_symbol *symbol, struct zint_render_line *line, struct zint_render_line **last_line)
|
int render_plot_add_line(struct zint_symbol *symbol, struct zint_render_line *line, struct zint_render_line **last_line) {
|
||||||
{
|
|
||||||
if (*last_line)
|
if (*last_line)
|
||||||
(*last_line)->next = line;
|
(*last_line)->next = line;
|
||||||
else
|
else
|
||||||
@ -707,11 +703,10 @@ int render_plot_add_line(struct zint_symbol *symbol, struct zint_render_line *li
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct zint_render_ring *render_plot_create_ring(float x, float y, float radius, float line_width)
|
struct zint_render_ring *render_plot_create_ring(float x, float y, float radius, float line_width) {
|
||||||
{
|
|
||||||
struct zint_render_ring *ring;
|
struct zint_render_ring *ring;
|
||||||
|
|
||||||
ring = (struct zint_render_ring *) malloc(sizeof(struct zint_render_ring));
|
ring = (struct zint_render_ring *) malloc(sizeof (struct zint_render_ring));
|
||||||
ring->next = NULL;
|
ring->next = NULL;
|
||||||
ring->x = x;
|
ring->x = x;
|
||||||
ring->y = y;
|
ring->y = y;
|
||||||
@ -721,8 +716,7 @@ struct zint_render_ring *render_plot_create_ring(float x, float y, float radius,
|
|||||||
return ring;
|
return ring;
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ring, struct zint_render_ring **last_ring)
|
int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ring, struct zint_render_ring **last_ring) {
|
||||||
{
|
|
||||||
if (*last_ring)
|
if (*last_ring)
|
||||||
(*last_ring)->next = ring;
|
(*last_ring)->next = ring;
|
||||||
else
|
else
|
||||||
@ -732,11 +726,10 @@ int render_plot_add_ring(struct zint_symbol *symbol, struct zint_render_ring *ri
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct zint_render_hexagon *render_plot_create_hexagon(float x, float y)
|
struct zint_render_hexagon *render_plot_create_hexagon(float x, float y) {
|
||||||
{
|
|
||||||
struct zint_render_hexagon *hexagon;
|
struct zint_render_hexagon *hexagon;
|
||||||
|
|
||||||
hexagon = (struct zint_render_hexagon*) malloc(sizeof(struct zint_render_hexagon));
|
hexagon = (struct zint_render_hexagon*) malloc(sizeof (struct zint_render_hexagon));
|
||||||
hexagon->next = NULL;
|
hexagon->next = NULL;
|
||||||
hexagon->x = x;
|
hexagon->x = x;
|
||||||
hexagon->y = y;
|
hexagon->y = y;
|
||||||
@ -744,8 +737,7 @@ struct zint_render_hexagon *render_plot_create_hexagon(float x, float y)
|
|||||||
return hexagon;
|
return hexagon;
|
||||||
}
|
}
|
||||||
|
|
||||||
int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexagon *hexagon, struct zint_render_hexagon **last_hexagon)
|
int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexagon *hexagon, struct zint_render_hexagon **last_hexagon) {
|
||||||
{
|
|
||||||
if (*last_hexagon)
|
if (*last_hexagon)
|
||||||
(*last_hexagon)->next = hexagon;
|
(*last_hexagon)->next = hexagon;
|
||||||
else
|
else
|
||||||
@ -761,18 +753,17 @@ int render_plot_add_hexagon(struct zint_symbol *symbol, struct zint_render_hexag
|
|||||||
*/
|
*/
|
||||||
int render_plot_add_string(struct zint_symbol *symbol,
|
int render_plot_add_string(struct zint_symbol *symbol,
|
||||||
unsigned char *text, float x, float y, float fsize, float width,
|
unsigned char *text, float x, float y, float fsize, float width,
|
||||||
struct zint_render_string **last_string)
|
struct zint_render_string **last_string) {
|
||||||
{
|
|
||||||
struct zint_render_string *string;
|
struct zint_render_string *string;
|
||||||
|
|
||||||
string = (struct zint_render_string*) malloc(sizeof(struct zint_render_string));
|
string = (struct zint_render_string*) malloc(sizeof (struct zint_render_string));
|
||||||
string->next = NULL;
|
string->next = NULL;
|
||||||
string->x = x;
|
string->x = x;
|
||||||
string->y = y;
|
string->y = y;
|
||||||
string->width = width;
|
string->width = width;
|
||||||
string->fsize = fsize;
|
string->fsize = fsize;
|
||||||
string->length = ustrlen(text);
|
string->length = ustrlen(text);
|
||||||
string->text = (unsigned char*) malloc(sizeof(unsigned char) * (ustrlen(text) + 1));
|
string->text = (unsigned char*) malloc(sizeof (unsigned char) * (ustrlen(text) + 1));
|
||||||
ustrcpy(string->text, text);
|
ustrcpy(string->text, text);
|
||||||
|
|
||||||
if (*last_string)
|
if (*last_string)
|
||||||
|
1312
backend/rss.c
1312
backend/rss.c
File diff suppressed because it is too large
Load Diff
109
backend/rss.h
109
backend/rss.h
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2007 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2007-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define NUMERIC 110
|
#define NUMERIC 110
|
||||||
#define ALPHA 97
|
#define ALPHA 97
|
||||||
@ -38,12 +38,30 @@
|
|||||||
#define ALPHA_OR_ISO 121
|
#define ALPHA_OR_ISO 121
|
||||||
|
|
||||||
/* RSS-14 Tables */
|
/* RSS-14 Tables */
|
||||||
static int g_sum_table[9] = { 0, 161, 961, 2015, 2715, 0, 336, 1036, 1516};
|
static int g_sum_table[9] = {
|
||||||
static int t_table[9] = { 1, 10, 34, 70, 126, 4, 20, 48, 81};
|
0, 161, 961, 2015, 2715, 0, 336, 1036, 1516
|
||||||
static int modules_odd[9] = { 12, 10, 8, 6, 4, 5, 7, 9, 11 };
|
};
|
||||||
static int modules_even[9] = { 4, 6, 8, 10, 12, 10, 8, 6, 4 };
|
|
||||||
static int widest_odd[9] = { 8, 6, 4, 3, 1, 2, 4, 6, 8 };
|
static int t_table[9] = {
|
||||||
static int widest_even[9] = { 1, 3, 5, 6, 8, 7, 5, 3, 1 };
|
1, 10, 34, 70, 126, 4, 20, 48, 81
|
||||||
|
};
|
||||||
|
|
||||||
|
static int modules_odd[9] = {
|
||||||
|
12, 10, 8, 6, 4, 5, 7, 9, 11
|
||||||
|
};
|
||||||
|
|
||||||
|
static int modules_even[9] = {
|
||||||
|
4, 6, 8, 10, 12, 10, 8, 6, 4
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_odd[9] = {
|
||||||
|
8, 6, 4, 3, 1, 2, 4, 6, 8
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_even[9] = {
|
||||||
|
1, 3, 5, 6, 8, 7, 5, 3, 1
|
||||||
|
};
|
||||||
|
|
||||||
static int widths[8];
|
static int widths[8];
|
||||||
static int finder_pattern[45] = {
|
static int finder_pattern[45] = {
|
||||||
3, 8, 2, 1, 1,
|
3, 8, 2, 1, 1,
|
||||||
@ -56,7 +74,9 @@ static int finder_pattern[45] = {
|
|||||||
1, 5, 7, 1, 1,
|
1, 5, 7, 1, 1,
|
||||||
1, 3, 9, 1, 1
|
1, 3, 9, 1, 1
|
||||||
};
|
};
|
||||||
static int checksum_weight[32] = { /* Table 5 */
|
|
||||||
|
static int checksum_weight[32] = {
|
||||||
|
/* Table 5 */
|
||||||
1, 3, 9, 27, 2, 6, 18, 54,
|
1, 3, 9, 27, 2, 6, 18, 54,
|
||||||
4, 12, 36, 29, 8, 24, 72, 58,
|
4, 12, 36, 29, 8, 24, 72, 58,
|
||||||
16, 48, 65, 37, 32, 17, 51, 74,
|
16, 48, 65, 37, 32, 17, 51, 74,
|
||||||
@ -64,15 +84,32 @@ static int checksum_weight[32] = { /* Table 5 */
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* RSS Limited Tables */
|
/* RSS Limited Tables */
|
||||||
static int t_even_ltd[7] = { 28, 728, 6454, 203, 2408, 1, 16632 };
|
static int t_even_ltd[7] = {
|
||||||
static int modules_odd_ltd[7] = { 17, 13, 9, 15, 11, 19, 7 };
|
28, 728, 6454, 203, 2408, 1, 16632
|
||||||
static int modules_even_ltd[7] = { 9, 13, 17, 11, 15, 7, 19 };
|
};
|
||||||
static int widest_odd_ltd[7] = { 6, 5, 3, 5, 4, 8, 1 };
|
|
||||||
static int widest_even_ltd[7] = { 3, 4, 6, 4, 5, 1, 8 };
|
static int modules_odd_ltd[7] = {
|
||||||
static int checksum_weight_ltd[28] = { /* Table 7 */
|
17, 13, 9, 15, 11, 19, 7
|
||||||
|
};
|
||||||
|
|
||||||
|
static int modules_even_ltd[7] = {
|
||||||
|
9, 13, 17, 11, 15, 7, 19
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_odd_ltd[7] = {
|
||||||
|
6, 5, 3, 5, 4, 8, 1
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_even_ltd[7] = {
|
||||||
|
3, 4, 6, 4, 5, 1, 8
|
||||||
|
};
|
||||||
|
|
||||||
|
static int checksum_weight_ltd[28] = {
|
||||||
|
/* Table 7 */
|
||||||
1, 3, 9, 27, 81, 65, 17, 51, 64, 14, 42, 37, 22, 66,
|
1, 3, 9, 27, 81, 65, 17, 51, 64, 14, 42, 37, 22, 66,
|
||||||
20, 60, 2, 6, 18, 54, 73, 41, 34, 13, 39, 28, 84, 74
|
20, 60, 2, 6, 18, 54, 73, 41, 34, 13, 39, 28, 84, 74
|
||||||
};
|
};
|
||||||
|
|
||||||
static int finder_pattern_ltd[1246] = {
|
static int finder_pattern_ltd[1246] = {
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 2, 1, 1,
|
||||||
@ -166,13 +203,32 @@ static int finder_pattern_ltd[1246] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* RSS Expanded Tables */
|
/* RSS Expanded Tables */
|
||||||
static int g_sum_exp[5] = { 0, 348, 1388, 2948, 3988 };
|
static int g_sum_exp[5] = {
|
||||||
static int t_even_exp[5] = { 4, 20, 52, 104, 204 };
|
0, 348, 1388, 2948, 3988
|
||||||
static int modules_odd_exp[5] = { 12, 10, 8, 6, 4 };
|
};
|
||||||
static int modules_even_exp[5] = { 5, 7, 9, 11, 13 };
|
|
||||||
static int widest_odd_exp[5] = { 7, 5, 4, 3, 1 };
|
static int t_even_exp[5] = {
|
||||||
static int widest_even_exp[5] = { 2, 4, 5, 6, 8 };
|
4, 20, 52, 104, 204
|
||||||
static int checksum_weight_exp[184] = { /* Table 14 */
|
};
|
||||||
|
|
||||||
|
static int modules_odd_exp[5] = {
|
||||||
|
12, 10, 8, 6, 4
|
||||||
|
};
|
||||||
|
|
||||||
|
static int modules_even_exp[5] = {
|
||||||
|
5, 7, 9, 11, 13
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_odd_exp[5] = {
|
||||||
|
7, 5, 4, 3, 1
|
||||||
|
};
|
||||||
|
|
||||||
|
static int widest_even_exp[5] = {
|
||||||
|
2, 4, 5, 6, 8
|
||||||
|
};
|
||||||
|
|
||||||
|
static int checksum_weight_exp[184] = {
|
||||||
|
/* Table 14 */
|
||||||
1, 3, 9, 27, 81, 32, 96, 77,
|
1, 3, 9, 27, 81, 32, 96, 77,
|
||||||
20, 60, 180, 118, 143, 7, 21, 63,
|
20, 60, 180, 118, 143, 7, 21, 63,
|
||||||
189, 145, 13, 39, 117, 140, 209, 205,
|
189, 145, 13, 39, 117, 140, 209, 205,
|
||||||
@ -197,7 +253,9 @@ static int checksum_weight_exp[184] = { /* Table 14 */
|
|||||||
55, 165, 73, 8, 24, 72, 5, 15,
|
55, 165, 73, 8, 24, 72, 5, 15,
|
||||||
45, 135, 194, 160, 58, 174, 100, 89
|
45, 135, 194, 160, 58, 174, 100, 89
|
||||||
};
|
};
|
||||||
static int finder_pattern_exp[60] = { /* Table 15 */
|
|
||||||
|
static int finder_pattern_exp[60] = {
|
||||||
|
/* Table 15 */
|
||||||
1, 8, 4, 1, 1,
|
1, 8, 4, 1, 1,
|
||||||
1, 1, 4, 8, 1,
|
1, 1, 4, 8, 1,
|
||||||
3, 6, 4, 1, 1,
|
3, 6, 4, 1, 1,
|
||||||
@ -211,7 +269,9 @@ static int finder_pattern_exp[60] = { /* Table 15 */
|
|||||||
2, 2, 9, 1, 1,
|
2, 2, 9, 1, 1,
|
||||||
1, 1, 9, 2, 2
|
1, 1, 9, 2, 2
|
||||||
};
|
};
|
||||||
static int finder_sequence[198] = { /* Table 16 */
|
|
||||||
|
static int finder_sequence[198] = {
|
||||||
|
/* Table 16 */
|
||||||
1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0,
|
1, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 6, 3, 8, 0, 0, 0, 0, 0, 0, 0,
|
1, 6, 3, 8, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -223,6 +283,7 @@ static int finder_sequence[198] = { /* Table 16 */
|
|||||||
1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 0,
|
1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 0,
|
||||||
1, 2, 3, 4, 5, 8, 7, 10, 9, 12, 11
|
1, 2, 3, 4, 5, 8, 7, 10, 9, 12, 11
|
||||||
};
|
};
|
||||||
|
|
||||||
static int weight_rows[210] = {
|
static int weight_rows[210] = {
|
||||||
0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 5, 6, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 5, 6, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
13692
backend/sjis.h
13692
backend/sjis.h
File diff suppressed because it is too large
Load Diff
130
backend/svg.c
130
backend/svg.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -38,8 +38,7 @@
|
|||||||
|
|
||||||
#define SSET "0123456789ABCDEF"
|
#define SSET "0123456789ABCDEF"
|
||||||
|
|
||||||
int svg_plot(struct zint_symbol *symbol)
|
int svg_plot(struct zint_symbol *symbol) {
|
||||||
{
|
|
||||||
int i, block_width, latch, r, this_row;
|
int i, block_width, latch, r, this_row;
|
||||||
float textpos, large_bar_height, preset_height, row_height, row_posn = 0.0;
|
float textpos, large_bar_height, preset_height, row_height, row_posn = 0.0;
|
||||||
FILE *fsvg;
|
FILE *fsvg;
|
||||||
@ -53,41 +52,41 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
int plot_text = 1;
|
int plot_text = 1;
|
||||||
const char *locale = NULL;
|
const char *locale = NULL;
|
||||||
|
|
||||||
row_height=0;
|
row_height = 0;
|
||||||
textdone = 0;
|
textdone = 0;
|
||||||
main_width = symbol->width;
|
main_width = symbol->width;
|
||||||
strcpy(addon, "");
|
strcpy(addon, "");
|
||||||
comp_offset = 0;
|
comp_offset = 0;
|
||||||
addon_text_posn = 0.0;
|
addon_text_posn = 0.0;
|
||||||
|
|
||||||
if((symbol->output_options & BARCODE_STDOUT) != 0) {
|
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
|
||||||
fsvg = stdout;
|
fsvg = stdout;
|
||||||
} else {
|
} else {
|
||||||
fsvg = fopen(symbol->outfile, "w");
|
fsvg = fopen(symbol->outfile, "w");
|
||||||
}
|
}
|
||||||
if(fsvg == NULL) {
|
if (fsvg == NULL) {
|
||||||
strcpy(symbol->errtxt, "Could not open output file");
|
strcpy(symbol->errtxt, "Could not open output file");
|
||||||
return ZINT_ERROR_FILE_ACCESS;
|
return ZINT_ERROR_FILE_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sort out colour options */
|
/* sort out colour options */
|
||||||
to_upper((unsigned char*)symbol->fgcolour);
|
to_upper((unsigned char*) symbol->fgcolour);
|
||||||
to_upper((unsigned char*)symbol->bgcolour);
|
to_upper((unsigned char*) symbol->bgcolour);
|
||||||
|
|
||||||
if(strlen(symbol->fgcolour) != 6) {
|
if (strlen(symbol->fgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
if(strlen(symbol->bgcolour) != 6) {
|
if (strlen(symbol->bgcolour) != 6) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
error_number = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->bgcolour));
|
||||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
@ -100,9 +99,9 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
large_bar_count = 0;
|
large_bar_count = 0;
|
||||||
preset_height = 0.0;
|
preset_height = 0.0;
|
||||||
for(i = 0; i < symbol->rows; i++) {
|
for (i = 0; i < symbol->rows; i++) {
|
||||||
preset_height += symbol->row_height[i];
|
preset_height += symbol->row_height[i];
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
large_bar_count++;
|
large_bar_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,18 +111,18 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
symbol->height = preset_height;
|
symbol->height = preset_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
|
||||||
comp_offset++;
|
comp_offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|
||||||
|| (symbol->symbology == BARCODE_ISBNX)) {
|
|| (symbol->symbology == BARCODE_ISBNX)) {
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 13: /* EAN 13 */
|
case 13: /* EAN 13 */
|
||||||
case 16:
|
case 16:
|
||||||
case 19:
|
case 19:
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
}
|
}
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
@ -134,14 +133,14 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 96 + comp_offset;
|
main_width = 96 + comp_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
|
||||||
if(symbol->whitespace_width == 0) {
|
if (symbol->whitespace_width == 0) {
|
||||||
symbol->whitespace_width = 10;
|
symbol->whitespace_width = 10;
|
||||||
main_width = 51 + comp_offset;
|
main_width = 51 + comp_offset;
|
||||||
}
|
}
|
||||||
@ -150,8 +149,8 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
latch = 0;
|
latch = 0;
|
||||||
r = 0;
|
r = 0;
|
||||||
/* Isolate add-on text */
|
/* Isolate add-on text */
|
||||||
if(is_extendable(symbol->symbology)) {
|
if (is_extendable(symbol->symbology)) {
|
||||||
for(i = 0; i < ustrlen(symbol->text); i++) {
|
for (i = 0; i < ustrlen(symbol->text); i++) {
|
||||||
if (latch == 1) {
|
if (latch == 1) {
|
||||||
addon[r] = symbol->text[i];
|
addon[r] = symbol->text[i];
|
||||||
r++;
|
r++;
|
||||||
@ -163,10 +162,10 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
addon[r] = '\0';
|
addon[r] = '\0';
|
||||||
|
|
||||||
if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
|
if ((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
|
||||||
plot_text = 0;
|
plot_text = 0;
|
||||||
}
|
}
|
||||||
if(plot_text) {
|
if (plot_text) {
|
||||||
textoffset = 9;
|
textoffset = 9;
|
||||||
} else {
|
} else {
|
||||||
textoffset = 0;
|
textoffset = 0;
|
||||||
@ -178,13 +177,13 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
|
fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
|
||||||
fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
|
fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
|
||||||
fprintf(fsvg, " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
|
fprintf(fsvg, " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
|
||||||
if(symbol->symbology != BARCODE_MAXICODE) {
|
if (symbol->symbology != BARCODE_MAXICODE) {
|
||||||
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
|
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
|
||||||
} else {
|
} else {
|
||||||
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
|
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
|
||||||
}
|
}
|
||||||
fprintf(fsvg, " xmlns=\"http://www.w3.org/2000/svg\">\n");
|
fprintf(fsvg, " xmlns=\"http://www.w3.org/2000/svg\">\n");
|
||||||
if(ustrlen(symbol->text) != 0) {
|
if (ustrlen(symbol->text) != 0) {
|
||||||
fprintf(fsvg, " <desc>%s\n", symbol->text);
|
fprintf(fsvg, " <desc>%s\n", symbol->text);
|
||||||
} else {
|
} else {
|
||||||
fprintf(fsvg, " <desc>Zint Generated Symbol\n");
|
fprintf(fsvg, " <desc>Zint Generated Symbol\n");
|
||||||
@ -192,19 +191,19 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " </desc>\n");
|
fprintf(fsvg, " </desc>\n");
|
||||||
fprintf(fsvg, "\n <g id=\"barcode\" fill=\"#%s\">\n", symbol->fgcolour);
|
fprintf(fsvg, "\n <g id=\"barcode\" fill=\"#%s\">\n", symbol->fgcolour);
|
||||||
|
|
||||||
if(symbol->symbology != BARCODE_MAXICODE) {
|
if (symbol->symbology != BARCODE_MAXICODE) {
|
||||||
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler), symbol->bgcolour);
|
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler), symbol->bgcolour);
|
||||||
} else {
|
} else {
|
||||||
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler), symbol->bgcolour);
|
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler), symbol->bgcolour);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
|
||||||
default_text_posn = (symbol->height + textoffset + symbol->border_width + symbol->border_width) * scaler;
|
default_text_posn = (symbol->height + textoffset + symbol->border_width + symbol->border_width) * scaler;
|
||||||
} else {
|
} else {
|
||||||
default_text_posn = (symbol->height + textoffset + symbol->border_width) * scaler;
|
default_text_posn = (symbol->height + textoffset + symbol->border_width) * scaler;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology == BARCODE_MAXICODE) {
|
if (symbol->symbology == BARCODE_MAXICODE) {
|
||||||
/* Maxicode uses hexagons */
|
/* Maxicode uses hexagons */
|
||||||
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
|
float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;
|
||||||
|
|
||||||
@ -214,7 +213,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (72.0 + symbol->border_width) * scaler, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (72.0 + symbol->border_width) * scaler, (74.0 + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
||||||
}
|
}
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, symbol->border_width * scaler, (72.0 + (2 * symbol->border_width)) * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, symbol->border_width * scaler, (72.0 + (2 * symbol->border_width)) * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (74.0 + xoffset + xoffset - symbol->border_width) * scaler, 0.0, symbol->border_width * scaler, (72.0 + (2 * symbol->border_width)) * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (74.0 + xoffset + xoffset - symbol->border_width) * scaler, 0.0, symbol->border_width * scaler, (72.0 + (2 * symbol->border_width)) * scaler);
|
||||||
@ -225,9 +224,9 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, symbol->bgcolour);
|
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, symbol->bgcolour);
|
||||||
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, symbol->bgcolour);
|
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\" fill=\"#%s\" />\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, symbol->bgcolour);
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
for(i = 0; i < symbol->width; i++) {
|
for (i = 0; i < symbol->width; i++) {
|
||||||
if(module_is_set(symbol, r, i)) {
|
if (module_is_set(symbol, r, i)) {
|
||||||
/* Dump a hexagon */
|
/* Dump a hexagon */
|
||||||
my = r * 2.135 + 1.43;
|
my = r * 2.135 + 1.43;
|
||||||
ay = my + 1.0 + yoffset;
|
ay = my + 1.0 + yoffset;
|
||||||
@ -236,7 +235,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
dy = my - 1.0 + yoffset;
|
dy = my - 1.0 + yoffset;
|
||||||
ey = my - 0.5 + yoffset;
|
ey = my - 0.5 + yoffset;
|
||||||
fy = my + 0.5 + yoffset;
|
fy = my + 0.5 + yoffset;
|
||||||
if(r & 1) {
|
if (r & 1) {
|
||||||
mx = (2.46 * i) + 1.23 + 1.23;
|
mx = (2.46 * i) + 1.23 + 1.23;
|
||||||
} else {
|
} else {
|
||||||
mx = (2.46 * i) + 1.23;
|
mx = (2.46 * i) + 1.23;
|
||||||
@ -253,21 +252,21 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(symbol->symbology != BARCODE_MAXICODE) {
|
if (symbol->symbology != BARCODE_MAXICODE) {
|
||||||
/* everything else uses rectangles (or squares) */
|
/* everything else uses rectangles (or squares) */
|
||||||
/* Works from the bottom of the symbol up */
|
/* Works from the bottom of the symbol up */
|
||||||
int addon_latch = 0;
|
int addon_latch = 0;
|
||||||
|
|
||||||
for(r = 0; r < symbol->rows; r++) {
|
for (r = 0; r < symbol->rows; r++) {
|
||||||
this_row = r;
|
this_row = r;
|
||||||
if(symbol->row_height[this_row] == 0) {
|
if (symbol->row_height[this_row] == 0) {
|
||||||
row_height = large_bar_height;
|
row_height = large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_height = symbol->row_height[this_row];
|
row_height = symbol->row_height[this_row];
|
||||||
}
|
}
|
||||||
row_posn = 0;
|
row_posn = 0;
|
||||||
for(i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
||||||
if(symbol->row_height[i] == 0) {
|
if (symbol->row_height[i] == 0) {
|
||||||
row_posn += large_bar_height;
|
row_posn += large_bar_height;
|
||||||
} else {
|
} else {
|
||||||
row_posn += symbol->row_height[i];
|
row_posn += symbol->row_height[i];
|
||||||
@ -276,7 +275,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
row_posn += yoffset;
|
row_posn += yoffset;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if(module_is_set(symbol, this_row, 0)) {
|
if (module_is_set(symbol, this_row, 0)) {
|
||||||
latch = 1;
|
latch = 1;
|
||||||
} else {
|
} else {
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -287,13 +286,13 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
|
||||||
if((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_width)) {
|
if ((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_width)) {
|
||||||
addon_text_posn = (row_posn + 8.0) * scaler;
|
addon_text_posn = (row_posn + 8.0) * scaler;
|
||||||
addon_latch = 1;
|
addon_latch = 1;
|
||||||
}
|
}
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
if(addon_latch == 0) {
|
if (addon_latch == 0) {
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, row_posn * scaler, block_width * scaler, row_height * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, row_posn * scaler, block_width * scaler, row_height * scaler);
|
||||||
} else {
|
} else {
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, (row_posn + 10.0) * scaler, block_width * scaler, (row_height - 5.0) * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset) * scaler, (row_posn + 10.0) * scaler, block_width * scaler, (row_height - 5.0) * scaler);
|
||||||
@ -313,11 +312,11 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
xoffset += comp_offset;
|
xoffset += comp_offset;
|
||||||
row_posn = (row_posn + large_bar_height) * scaler;
|
row_posn = (row_posn + large_bar_height) * scaler;
|
||||||
|
|
||||||
if(plot_text) {
|
if (plot_text) {
|
||||||
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
|
||||||
(symbol->symbology == BARCODE_ISBNX)) {
|
(symbol->symbology == BARCODE_ISBNX)) {
|
||||||
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
/* guard bar extensions and text formatting for EAN8 and EAN13 */
|
||||||
switch(ustrlen(symbol->text)) {
|
switch (ustrlen(symbol->text)) {
|
||||||
case 8: /* EAN-8 */
|
case 8: /* EAN-8 */
|
||||||
case 11:
|
case 11:
|
||||||
case 14:
|
case 14:
|
||||||
@ -327,7 +326,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (34 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (34 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (64 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (64 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (66 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (66 + xoffset) * scaler, row_posn, scaler, 5.0 * scaler);
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i];
|
textpart[i] = symbol->text[i];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
@ -336,7 +335,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
textpart[i] = symbol->text[i + 4];
|
textpart[i] = symbol->text[i + 4];
|
||||||
}
|
}
|
||||||
textpart[4] = '\0';
|
textpart[4] = '\0';
|
||||||
@ -346,7 +345,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 86;
|
textpos = xoffset + 86;
|
||||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
||||||
@ -380,7 +379,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -389,7 +388,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 7];
|
textpart[i] = symbol->text[i + 7];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -399,7 +398,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 114;
|
textpos = xoffset + 114;
|
||||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
||||||
@ -430,7 +429,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -449,7 +448,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
do {
|
do {
|
||||||
block_width++;
|
block_width++;
|
||||||
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
|
||||||
if(latch == 1) {
|
if (latch == 1) {
|
||||||
/* a bar */
|
/* a bar */
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (i + xoffset - comp_offset) * scaler, row_posn, block_width * scaler, 5.0 * scaler);
|
||||||
latch = 0;
|
latch = 0;
|
||||||
@ -466,7 +465,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[5] = '\0';
|
textpart[5] = '\0';
|
||||||
@ -475,7 +474,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 11.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
textpart[i] = symbol->text[i + 6];
|
textpart[i] = symbol->text[i + 6];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -492,7 +491,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 116;
|
textpos = xoffset + 116;
|
||||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
||||||
@ -525,7 +524,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
for(i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
textpart[i] = symbol->text[i + 1];
|
textpart[i] = symbol->text[i + 1];
|
||||||
}
|
}
|
||||||
textpart[6] = '\0';
|
textpart[6] = '\0';
|
||||||
@ -542,7 +541,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " %s\n", textpart);
|
fprintf(fsvg, " %s\n", textpart);
|
||||||
fprintf(fsvg, " </text>\n");
|
fprintf(fsvg, " </text>\n");
|
||||||
textdone = 1;
|
textdone = 1;
|
||||||
switch(strlen(addon)) {
|
switch (strlen(addon)) {
|
||||||
case 2:
|
case 2:
|
||||||
textpos = xoffset + 70;
|
textpos = xoffset + 70;
|
||||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", textpos * scaler, addon_text_posn * scaler);
|
||||||
@ -564,15 +563,15 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
xoffset -= comp_offset;
|
xoffset -= comp_offset;
|
||||||
|
|
||||||
switch(symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_MAXICODE:
|
case BARCODE_MAXICODE:
|
||||||
/* Do nothing! (It's already been done) */
|
/* Do nothing! (It's already been done) */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if((symbol->output_options & BARCODE_BIND) != 0) {
|
if ((symbol->output_options & BARCODE_BIND) != 0) {
|
||||||
if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
if ((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
|
||||||
/* row binding */
|
/* row binding */
|
||||||
for(r = 1; r < symbol->rows; r++) {
|
for (r = 1; r < symbol->rows; r++) {
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", xoffset * scaler, ((r * row_height) + yoffset - 1) * scaler, symbol->width * scaler, 2.0 * scaler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -581,7 +580,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, (symbol->height + symbol->border_width) * scaler, (symbol->width + xoffset + xoffset) * scaler, symbol->border_width * scaler);
|
||||||
}
|
}
|
||||||
if((symbol->output_options & BARCODE_BOX) != 0) {
|
if ((symbol->output_options & BARCODE_BOX) != 0) {
|
||||||
/* side bars */
|
/* side bars */
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", 0.0, 0.0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
||||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, 0.0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, 0.0, symbol->border_width * scaler, (symbol->height + (2 * symbol->border_width)) * scaler);
|
||||||
@ -590,7 +589,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Put the human readable text at the bottom */
|
/* Put the human readable text at the bottom */
|
||||||
if(plot_text && (textdone == 0)) {
|
if (plot_text && (textdone == 0)) {
|
||||||
textpos = symbol->width / 2.0;
|
textpos = symbol->width / 2.0;
|
||||||
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", (textpos + xoffset) * scaler, default_text_posn);
|
fprintf(fsvg, " <text x=\"%.2f\" y=\"%.2f\" text-anchor=\"middle\"\n", (textpos + xoffset) * scaler, default_text_posn);
|
||||||
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
fprintf(fsvg, " font-family=\"Helvetica\" font-size=\"%.1f\" fill=\"#%s\" >\n", 8.0 * scaler, symbol->fgcolour);
|
||||||
@ -600,7 +599,7 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
fprintf(fsvg, " </g>\n");
|
fprintf(fsvg, " </g>\n");
|
||||||
fprintf(fsvg, "</svg>\n");
|
fprintf(fsvg, "</svg>\n");
|
||||||
|
|
||||||
if(symbol->output_options & BARCODE_STDOUT) {
|
if (symbol->output_options & BARCODE_STDOUT) {
|
||||||
fflush(fsvg);
|
fflush(fsvg);
|
||||||
} else {
|
} else {
|
||||||
fclose(fsvg);
|
fclose(fsvg);
|
||||||
@ -611,4 +610,3 @@ int svg_plot(struct zint_symbol *symbol)
|
|||||||
|
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -28,7 +28,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SODIUM "0123456789X"
|
#define SODIUM "0123456789X"
|
||||||
|
|
||||||
@ -37,8 +37,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static char *TeleTable[] =
|
static char *TeleTable[] ={
|
||||||
{
|
|
||||||
"1111111111111111", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
|
"1111111111111111", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
|
||||||
"31333111", "1131113131", "33113131", "1111333111", "3111113131", "1113133111", "1311133111", "111111113131",
|
"31333111", "1131113131", "33113131", "1111333111", "3111113131", "1113133111", "1311133111", "111111113131",
|
||||||
"3131113111", "11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
|
"3131113111", "11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
|
||||||
@ -53,11 +52,11 @@ static char *TeleTable[] =
|
|||||||
"3113131111", "1131111133", "33111133", "111113131111", "3111111133", "111311131111", "131111131111", "111111111133",
|
"3113131111", "1131111133", "33111133", "111113131111", "3111111133", "111311131111", "131111131111", "111111111133",
|
||||||
"31311313", "113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313", "11111131111111",
|
"31311313", "113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313", "11111131111111",
|
||||||
"3133111111", "1131111313", "33111313", "111133111111", "3111111313", "111313111111", "131113111111", "111111111313",
|
"3133111111", "1131111313", "33111313", "111133111111", "3111111313", "111313111111", "131113111111", "111111111313",
|
||||||
"313111111111", "1131131113", "33131113", "11113111111111","3111131113", "113311111111", "131311111111", "111111131113",
|
"313111111111", "1131131113", "33131113", "11113111111111", "3111131113", "113311111111", "131311111111", "111111131113",
|
||||||
"3113111113", "11311111111111","331111111111","111113111113", "31111111111111","111311111113","131111111113"};
|
"3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113"
|
||||||
|
};
|
||||||
|
|
||||||
int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
||||||
{
|
|
||||||
unsigned int i, count, check_digit;
|
unsigned int i, count, check_digit;
|
||||||
int error_number;
|
int error_number;
|
||||||
char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */
|
char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */
|
||||||
@ -66,15 +65,15 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if(src_len > 30) {
|
if (src_len > 30) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
/* Start character */
|
/* Start character */
|
||||||
strcpy(dest, TeleTable['_']);
|
strcpy(dest, TeleTable['_']);
|
||||||
|
|
||||||
for(i = 0; i < src_len; i++) {
|
for (i = 0; i < src_len; i++) {
|
||||||
if(source[i] > 126) {
|
if (source[i] > 126) {
|
||||||
/* Cannot encode extended ASCII */
|
/* Cannot encode extended ASCII */
|
||||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
@ -84,15 +83,17 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_digit = 127 - (count % 127);
|
check_digit = 127 - (count % 127);
|
||||||
if(check_digit == 127) { check_digit = 0; }
|
if (check_digit == 127) {
|
||||||
|
check_digit = 0;
|
||||||
|
}
|
||||||
concat(dest, TeleTable[check_digit]);
|
concat(dest, TeleTable[check_digit]);
|
||||||
|
|
||||||
/* Stop character */
|
/* Stop character */
|
||||||
concat(dest, TeleTable['z']);
|
concat(dest, TeleTable['z']);
|
||||||
|
|
||||||
expand(symbol, dest);
|
expand(symbol, dest);
|
||||||
for(i = 0; i < src_len; i++) {
|
for (i = 0; i < src_len; i++) {
|
||||||
if(source[i] == '\0') {
|
if (source[i] == '\0') {
|
||||||
symbol->text[i] = ' ';
|
symbol->text[i] = ' ';
|
||||||
} else {
|
} else {
|
||||||
symbol->text[i] = source[i];
|
symbol->text[i] = source[i];
|
||||||
@ -102,8 +103,7 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
||||||
{
|
|
||||||
unsigned int i, count, check_digit, glyph;
|
unsigned int i, count, check_digit, glyph;
|
||||||
int error_number, temp_length = src_len;
|
int error_number, temp_length = src_len;
|
||||||
char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
|
char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
|
||||||
@ -112,21 +112,20 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
error_number = 0;
|
error_number = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if(temp_length > 60) {
|
if (temp_length > 60) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
ustrcpy(temp, source);
|
ustrcpy(temp, source);
|
||||||
to_upper(temp);
|
to_upper(temp);
|
||||||
error_number = is_sane(NEON, temp, temp_length);
|
error_number = is_sane(NEON, temp, temp_length);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a leading zero if required */
|
/* Add a leading zero if required */
|
||||||
if (temp_length & 1)
|
if (temp_length & 1) {
|
||||||
{
|
|
||||||
memmove(temp + 1, temp, temp_length);
|
memmove(temp + 1, temp, temp_length);
|
||||||
temp[0] = '0';
|
temp[0] = '0';
|
||||||
|
|
||||||
@ -136,14 +135,13 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
/* Start character */
|
/* Start character */
|
||||||
strcpy(dest, TeleTable['_']);
|
strcpy(dest, TeleTable['_']);
|
||||||
|
|
||||||
for (i = 0; i < temp_length; i += 2)
|
for (i = 0; i < temp_length; i += 2) {
|
||||||
{
|
if (temp[i] == 'X') {
|
||||||
if(temp[i] == 'X') {
|
|
||||||
strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
|
strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(temp[i + 1] == 'X') {
|
if (temp[i + 1] == 'X') {
|
||||||
glyph = ctoi(temp[i]) + 17;
|
glyph = ctoi(temp[i]) + 17;
|
||||||
count += glyph;
|
count += glyph;
|
||||||
} else {
|
} else {
|
||||||
@ -155,7 +153,9 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_digit = 127 - (count % 127);
|
check_digit = 127 - (count % 127);
|
||||||
if(check_digit == 127) { check_digit = 0; }
|
if (check_digit == 127) {
|
||||||
|
check_digit = 0;
|
||||||
|
}
|
||||||
concat(dest, TeleTable[check_digit]);
|
concat(dest, TeleTable[check_digit]);
|
||||||
|
|
||||||
/* Stop character */
|
/* Stop character */
|
||||||
@ -165,4 +165,3 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
ustrcpy(symbol->text, temp);
|
ustrcpy(symbol->text, temp);
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
499
backend/upcean.c
499
backend/upcean.c
@ -1,7 +1,7 @@
|
|||||||
/* upcean.c - Handles UPC, EAN and ISBN
|
/* upcean.c - Handles UPC, EAN and ISBN
|
||||||
|
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -27,7 +27,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SODIUM "0123456789+"
|
#define SODIUM "0123456789+"
|
||||||
#define EAN2 102
|
#define EAN2 102
|
||||||
@ -40,22 +40,47 @@
|
|||||||
|
|
||||||
/* UPC and EAN tables checked against EN 797:1996 */
|
/* UPC and EAN tables checked against EN 797:1996 */
|
||||||
|
|
||||||
static const char *UPCParity0[10] = {"BBBAAA", "BBABAA", "BBAABA", "BBAAAB", "BABBAA", "BAABBA", "BAAABB",
|
static const char *UPCParity0[10] = {
|
||||||
"BABABA", "BABAAB", "BAABAB"}; /* Number set for UPC-E symbol (EN Table 4) */
|
/* Number set for UPC-E symbol (EN Table 4) */
|
||||||
static const char *UPCParity1[10] = {"AAABBB", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA",
|
"BBBAAA", "BBABAA", "BBAABA", "BBAAAB", "BABBAA", "BAABBA", "BAAABB",
|
||||||
"ABABAB", "ABABBA", "ABBABA"}; /* Not covered by BS EN 797:1995 */
|
"BABABA", "BABAAB", "BAABAB"
|
||||||
static const char *EAN2Parity[4] = {"AA", "AB", "BA", "BB"}; /* Number sets for 2-digit add-on (EN Table 6) */
|
};
|
||||||
static const char *EAN5Parity[10] = {"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA",
|
|
||||||
"ABAAB", "AABAB"}; /* Number set for 5-digit add-on (EN Table 7) */
|
|
||||||
static const char *EAN13Parity[10] = {"AAAAA", "ABABB", "ABBAB", "ABBBA", "BAABB", "BBAAB", "BBBAA", "BABAB",
|
|
||||||
"BABBA", "BBABA"}; /* Left hand of the EAN-13 symbol (EN Table 3) */
|
|
||||||
static const char *EANsetA[10] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213",
|
|
||||||
"3112"}; /* Representation set A and C (EN Table 1) */
|
|
||||||
static const char *EANsetB[10] = {"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121",
|
|
||||||
"2113"}; /* Representation set B (EN Table 1) */
|
|
||||||
|
|
||||||
char upc_check(char source[])
|
static const char *UPCParity1[10] = {
|
||||||
{ /* Calculate the correct check digit for a UPC barcode */
|
/* Not covered by BS EN 797:1995 */
|
||||||
|
"AAABBB", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA",
|
||||||
|
"ABABAB", "ABABBA", "ABBABA"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *EAN2Parity[4] = {
|
||||||
|
/* Number sets for 2-digit add-on (EN Table 6) */
|
||||||
|
"AA", "AB", "BA", "BB"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *EAN5Parity[10] = {
|
||||||
|
/* Number set for 5-digit add-on (EN Table 7) */
|
||||||
|
"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA",
|
||||||
|
"ABAAB", "AABAB"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *EAN13Parity[10] = {
|
||||||
|
/* Left hand of the EAN-13 symbol (EN Table 3) */
|
||||||
|
"AAAAA", "ABABB", "ABBAB", "ABBBA", "BAABB", "BBAAB", "BBBAA", "BABAB",
|
||||||
|
"BABBA", "BBABA"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *EANsetA[10] = {
|
||||||
|
/* Representation set A and C (EN Table 1) */
|
||||||
|
"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213","3112"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *EANsetB[10] = {
|
||||||
|
/* Representation set B (EN Table 1) */
|
||||||
|
"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121", "2113"
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Calculate the correct check digit for a UPC barcode */
|
||||||
|
char upc_check(char source[]) {
|
||||||
unsigned int i, count, check_digit;
|
unsigned int i, count, check_digit;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
@ -68,24 +93,24 @@ char upc_check(char source[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check_digit = 10 - (count%10);
|
check_digit = 10 - (count % 10);
|
||||||
if (check_digit == 10) { check_digit = 0; }
|
if (check_digit == 10) {
|
||||||
|
check_digit = 0;
|
||||||
|
}
|
||||||
return itoc(check_digit);
|
return itoc(check_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void upca_draw(char source[], char dest[])
|
/* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */
|
||||||
{ /* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */
|
void upca_draw(char source[], char dest[]) {
|
||||||
unsigned int i, half_way;
|
unsigned int i, half_way;
|
||||||
|
|
||||||
half_way = strlen(source) / 2;
|
half_way = strlen(source) / 2;
|
||||||
|
|
||||||
/* start character */
|
/* start character */
|
||||||
concat (dest, "111");
|
concat(dest, "111");
|
||||||
|
|
||||||
for(i = 0; i <= strlen(source); i++)
|
for (i = 0; i <= strlen(source); i++) {
|
||||||
{
|
if (i == half_way) {
|
||||||
if (i == half_way)
|
|
||||||
{
|
|
||||||
/* middle character - separates manufacturer no. from product no. */
|
/* middle character - separates manufacturer no. from product no. */
|
||||||
/* also inverts right hand characters */
|
/* also inverts right hand characters */
|
||||||
concat(dest, "11111");
|
concat(dest, "11111");
|
||||||
@ -95,60 +120,64 @@ void upca_draw(char source[], char dest[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "111");
|
concat(dest, "111");
|
||||||
}
|
}
|
||||||
|
|
||||||
void upca(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
/* Make a UPC A barcode when we haven't been given the check digit */
|
||||||
{ /* Make a UPC A barcode when we haven't been given the check digit */
|
void upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||||
int length;
|
int length;
|
||||||
char gtin[15];
|
char gtin[15];
|
||||||
|
|
||||||
strcpy(gtin, (char*)source);
|
strcpy(gtin, (char*) source);
|
||||||
length = strlen(gtin);
|
length = strlen(gtin);
|
||||||
gtin[length] = upc_check(gtin);
|
gtin[length] = upc_check(gtin);
|
||||||
gtin[length + 1] = '\0';
|
gtin[length + 1] = '\0';
|
||||||
upca_draw(gtin, dest);
|
upca_draw(gtin, dest);
|
||||||
ustrcpy(symbol->text, (unsigned char*)gtin);
|
ustrcpy(symbol->text, (unsigned char*) gtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
/* UPC E is a zero-compressed version of UPC A */
|
||||||
{ /* UPC E is a zero-compressed version of UPC A */
|
void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||||
unsigned int i, num_system;
|
unsigned int i, num_system;
|
||||||
char emode, equivalent[12], check_digit, parity[8], temp[8];
|
char emode, equivalent[12], check_digit, parity[8], temp[8];
|
||||||
char hrt[9];
|
char hrt[9];
|
||||||
|
|
||||||
/* Two number systems can be used - system 0 and system 1 */
|
/* Two number systems can be used - system 0 and system 1 */
|
||||||
if(ustrlen(source) == 7) {
|
if (ustrlen(source) == 7) {
|
||||||
switch(source[0]) {
|
switch (source[0]) {
|
||||||
case '0': num_system = 0; break;
|
case '0': num_system = 0;
|
||||||
case '1': num_system = 1; break;
|
break;
|
||||||
default: num_system = 0; source[0] = '0'; break;
|
case '1': num_system = 1;
|
||||||
|
break;
|
||||||
|
default: num_system = 0;
|
||||||
|
source[0] = '0';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
strcpy(temp, (char*)source);
|
strcpy(temp, (char*) source);
|
||||||
strcpy(hrt, (char*)source);
|
strcpy(hrt, (char*) source);
|
||||||
for(i = 1; i <= 7; i++) {
|
for (i = 1; i <= 7; i++) {
|
||||||
source[i - 1] = temp[i];
|
source[i - 1] = temp[i];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
num_system = 0;
|
num_system = 0;
|
||||||
hrt[0] = '0';
|
hrt[0] = '0';
|
||||||
hrt[1] = '\0';
|
hrt[1] = '\0';
|
||||||
concat(hrt, (char*)source);
|
concat(hrt, (char*) source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
|
/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
|
||||||
emode = source[5];
|
emode = source[5];
|
||||||
for(i = 0; i < 11; i++) {
|
for (i = 0; i < 11; i++) {
|
||||||
equivalent[i] = '0';
|
equivalent[i] = '0';
|
||||||
}
|
}
|
||||||
if(num_system == 1) { equivalent[0] = temp[0]; }
|
if (num_system == 1) {
|
||||||
|
equivalent[0] = temp[0];
|
||||||
|
}
|
||||||
equivalent[1] = source[0];
|
equivalent[1] = source[0];
|
||||||
equivalent[2] = source[1];
|
equivalent[2] = source[1];
|
||||||
equivalent[11] = '\0';
|
equivalent[11] = '\0';
|
||||||
|
|
||||||
switch(emode)
|
switch (emode) {
|
||||||
{
|
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
@ -161,7 +190,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
equivalent[3] = source[2];
|
equivalent[3] = source[2];
|
||||||
equivalent[9] = source[3];
|
equivalent[9] = source[3];
|
||||||
equivalent[10] = source[4];
|
equivalent[10] = source[4];
|
||||||
if(((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
|
if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
|
||||||
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
|
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
|
||||||
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
||||||
}
|
}
|
||||||
@ -170,7 +199,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
equivalent[3] = source[2];
|
equivalent[3] = source[2];
|
||||||
equivalent[4] = source[3];
|
equivalent[4] = source[3];
|
||||||
equivalent[10] = source[4];
|
equivalent[10] = source[4];
|
||||||
if(source[3] == '0') {
|
if (source[3] == '0') {
|
||||||
/* Note 2 - "X4 shall not be equal to 0" */
|
/* Note 2 - "X4 shall not be equal to 0" */
|
||||||
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
||||||
}
|
}
|
||||||
@ -184,7 +213,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
equivalent[4] = source[3];
|
equivalent[4] = source[3];
|
||||||
equivalent[5] = source[4];
|
equivalent[5] = source[4];
|
||||||
equivalent[10] = emode;
|
equivalent[10] = emode;
|
||||||
if(source[4] == '0') {
|
if (source[4] == '0') {
|
||||||
/* Note 3 - "X5 shall not be equal to 0" */
|
/* Note 3 - "X5 shall not be equal to 0" */
|
||||||
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
strcpy(symbol->errtxt, "Invalid UPC-E data");
|
||||||
}
|
}
|
||||||
@ -196,7 +225,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
check_digit = upc_check(equivalent);
|
check_digit = upc_check(equivalent);
|
||||||
|
|
||||||
/* Use the number system and check digit information to choose a parity scheme */
|
/* Use the number system and check digit information to choose a parity scheme */
|
||||||
if(num_system == 1) {
|
if (num_system == 1) {
|
||||||
strcpy(parity, UPCParity1[ctoi(check_digit)]);
|
strcpy(parity, UPCParity1[ctoi(check_digit)]);
|
||||||
} else {
|
} else {
|
||||||
strcpy(parity, UPCParity0[ctoi(check_digit)]);
|
strcpy(parity, UPCParity0[ctoi(check_digit)]);
|
||||||
@ -205,94 +234,86 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
/* Take all this information and make the barcode pattern */
|
/* Take all this information and make the barcode pattern */
|
||||||
|
|
||||||
/* start character */
|
/* start character */
|
||||||
concat (dest, "111");
|
concat(dest, "111");
|
||||||
|
|
||||||
for(i = 0; i <= ustrlen(source); i++) {
|
for (i = 0; i <= ustrlen(source); i++) {
|
||||||
switch(parity[i]) {
|
switch (parity[i]) {
|
||||||
case 'A': lookup(NEON, EANsetA, source[i], dest); break;
|
case 'A': lookup(NEON, EANsetA, source[i], dest);
|
||||||
case 'B': lookup(NEON, EANsetB, source[i], dest); break;
|
break;
|
||||||
|
case 'B': lookup(NEON, EANsetB, source[i], dest);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "111111");
|
concat(dest, "111111");
|
||||||
|
|
||||||
hrt[7] = check_digit;
|
hrt[7] = check_digit;
|
||||||
hrt[8] = '\0';
|
hrt[8] = '\0';
|
||||||
ustrcpy(symbol->text, (unsigned char*)hrt);
|
ustrcpy(symbol->text, (unsigned char*) hrt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* EAN-2 and EAN-5 add-on codes */
|
||||||
void add_on(unsigned char source[], char dest[], int mode)
|
void add_on(unsigned char source[], char dest[], int mode) {
|
||||||
{ /* EAN-2 and EAN-5 add-on codes */
|
|
||||||
char parity[6];
|
char parity[6];
|
||||||
unsigned int i, code_type;
|
unsigned int i, code_type;
|
||||||
|
|
||||||
/* If an add-on then append with space */
|
/* If an add-on then append with space */
|
||||||
if (mode != 0)
|
if (mode != 0) {
|
||||||
{
|
|
||||||
concat(dest, "9");
|
concat(dest, "9");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start character */
|
/* Start character */
|
||||||
concat (dest, "112");
|
concat(dest, "112");
|
||||||
|
|
||||||
/* Determine EAN2 or EAN5 add-on */
|
/* Determine EAN2 or EAN5 add-on */
|
||||||
if(ustrlen(source) == 2)
|
if (ustrlen(source) == 2) {
|
||||||
{
|
|
||||||
code_type = EAN2;
|
code_type = EAN2;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
code_type = EAN5;
|
code_type = EAN5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate parity for EAN2 */
|
/* Calculate parity for EAN2 */
|
||||||
if(code_type == EAN2)
|
if (code_type == EAN2) {
|
||||||
{
|
|
||||||
int code_value, parity_bit;
|
int code_value, parity_bit;
|
||||||
|
|
||||||
code_value = (10 * ctoi(source[0])) + ctoi(source[1]);
|
code_value = (10 * ctoi(source[0])) + ctoi(source[1]);
|
||||||
parity_bit = code_value%4;
|
parity_bit = code_value % 4;
|
||||||
strcpy(parity, EAN2Parity[parity_bit]);
|
strcpy(parity, EAN2Parity[parity_bit]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(code_type == EAN5)
|
if (code_type == EAN5) {
|
||||||
{
|
|
||||||
int values[6], parity_sum, parity_bit;
|
int values[6], parity_sum, parity_bit;
|
||||||
|
|
||||||
for(i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++) {
|
||||||
{
|
|
||||||
values[i] = ctoi(source[i]);
|
values[i] = ctoi(source[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
parity_sum = (3 * (values[0] + values[2] + values[4]));
|
parity_sum = (3 * (values[0] + values[2] + values[4]));
|
||||||
parity_sum += (9 * (values[1] + values[3]));
|
parity_sum += (9 * (values[1] + values[3]));
|
||||||
|
|
||||||
parity_bit = parity_sum%10;
|
parity_bit = parity_sum % 10;
|
||||||
strcpy(parity, EAN5Parity[parity_bit]);
|
strcpy(parity, EAN5Parity[parity_bit]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < ustrlen(source); i++)
|
for (i = 0; i < ustrlen(source); i++) {
|
||||||
{
|
switch (parity[i]) {
|
||||||
switch(parity[i]) {
|
case 'A': lookup(NEON, EANsetA, source[i], dest);
|
||||||
case 'A': lookup(NEON, EANsetA, source[i], dest); break;
|
break;
|
||||||
case 'B': lookup(NEON, EANsetB, source[i], dest); break;
|
case 'B': lookup(NEON, EANsetB, source[i], dest);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Glyph separator */
|
/* Glyph separator */
|
||||||
if(i != (ustrlen(source) - 1))
|
if (i != (ustrlen(source) - 1)) {
|
||||||
{
|
concat(dest, "11");
|
||||||
concat (dest, "11");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ************************ EAN-13 ****************** */
|
/* ************************ EAN-13 ****************** */
|
||||||
|
/* Calculate the correct check digit for a EAN-13 barcode */
|
||||||
char ean_check(char source[])
|
char ean_check(char source[]) {
|
||||||
{ /* Calculate the correct check digit for a EAN-13 barcode */
|
|
||||||
int i;
|
int i;
|
||||||
unsigned int h, count, check_digit;
|
unsigned int h, count, check_digit;
|
||||||
|
|
||||||
@ -306,19 +327,20 @@ char ean_check(char source[])
|
|||||||
count += 2 * ctoi(source[i]);
|
count += 2 * ctoi(source[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_digit = 10 - (count%10);
|
check_digit = 10 - (count % 10);
|
||||||
if (check_digit == 10) { check_digit = 0; }
|
if (check_digit == 10) {
|
||||||
|
check_digit = 0;
|
||||||
|
}
|
||||||
return itoc(check_digit);
|
return itoc(check_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||||
{
|
|
||||||
unsigned int length, i, half_way;
|
unsigned int length, i, half_way;
|
||||||
char parity[6];
|
char parity[6];
|
||||||
char gtin[15];
|
char gtin[15];
|
||||||
|
|
||||||
strcpy(parity, "");
|
strcpy(parity, "");
|
||||||
strcpy(gtin, (char*)source);
|
strcpy(gtin, (char*) source);
|
||||||
|
|
||||||
/* Add the appropriate check digit */
|
/* Add the appropriate check digit */
|
||||||
length = strlen(gtin);
|
length = strlen(gtin);
|
||||||
@ -332,69 +354,64 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
|||||||
half_way = 7;
|
half_way = 7;
|
||||||
|
|
||||||
/* start character */
|
/* start character */
|
||||||
concat (dest, "111");
|
concat(dest, "111");
|
||||||
length = strlen(gtin);
|
length = strlen(gtin);
|
||||||
for(i = 1; i <= length; i++)
|
for (i = 1; i <= length; i++) {
|
||||||
{
|
if (i == half_way) {
|
||||||
if (i == half_way)
|
|
||||||
{
|
|
||||||
/* middle character - separates manufacturer no. from product no. */
|
/* middle character - separates manufacturer no. from product no. */
|
||||||
/* also inverses right hand characters */
|
/* also inverses right hand characters */
|
||||||
concat (dest, "11111");
|
concat(dest, "11111");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(((i > 1) && (i < 7)) && (parity[i - 2] == 'B'))
|
if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) {
|
||||||
{
|
|
||||||
lookup(NEON, EANsetB, gtin[i], dest);
|
lookup(NEON, EANsetB, gtin[i], dest);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
lookup(NEON, EANsetA, gtin[i], dest);
|
lookup(NEON, EANsetA, gtin[i], dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stop character */
|
/* stop character */
|
||||||
concat (dest, "111");
|
concat(dest, "111");
|
||||||
|
|
||||||
ustrcpy(symbol->text, (unsigned char*)gtin);
|
ustrcpy(symbol->text, (unsigned char*) gtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
/* Make an EAN-8 barcode when we haven't been given the check digit */
|
||||||
{ /* Make an EAN-8 barcode when we haven't been given the check digit */
|
void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
||||||
/* EAN-8 is basically the same as UPC-A but with fewer digits */
|
/* EAN-8 is basically the same as UPC-A but with fewer digits */
|
||||||
int length;
|
int length;
|
||||||
char gtin[10];
|
char gtin[10];
|
||||||
|
|
||||||
strcpy(gtin, (char*)source);
|
strcpy(gtin, (char*) source);
|
||||||
length = strlen(gtin);
|
length = strlen(gtin);
|
||||||
gtin[length] = upc_check(gtin);
|
gtin[length] = upc_check(gtin);
|
||||||
gtin[length + 1] = '\0';
|
gtin[length + 1] = '\0';
|
||||||
upca_draw(gtin, dest);
|
upca_draw(gtin, dest);
|
||||||
ustrcpy(symbol->text, (unsigned char*)gtin);
|
ustrcpy(symbol->text, (unsigned char*) gtin);
|
||||||
}
|
}
|
||||||
|
|
||||||
char isbn13_check(unsigned char source[]) /* For ISBN(13) only */
|
/* For ISBN(13) only */
|
||||||
{
|
char isbn13_check(unsigned char source[]) {
|
||||||
unsigned int i, weight, sum, check, h;
|
unsigned int i, weight, sum, check, h;
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
weight = 1;
|
weight = 1;
|
||||||
h = ustrlen(source) - 1;
|
h = ustrlen(source) - 1;
|
||||||
|
|
||||||
for(i = 0; i < h; i++)
|
for (i = 0; i < h; i++) {
|
||||||
{
|
|
||||||
sum += ctoi(source[i]) * weight;
|
sum += ctoi(source[i]) * weight;
|
||||||
if(weight == 1) weight = 3; else weight = 1;
|
if (weight == 1) weight = 3;
|
||||||
|
else weight = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
check = sum % 10;
|
check = sum % 10;
|
||||||
check = 10 - check;
|
check = 10 - check;
|
||||||
if(check == 10) check = 0;
|
if (check == 10) check = 0;
|
||||||
return itoc(check);
|
return itoc(check);
|
||||||
}
|
}
|
||||||
|
|
||||||
char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
/* For ISBN(10) and SBN only */
|
||||||
{
|
char isbn_check(unsigned char source[]) {
|
||||||
unsigned int i, weight, sum, check, h;
|
unsigned int i, weight, sum, check, h;
|
||||||
char check_char;
|
char check_char;
|
||||||
|
|
||||||
@ -402,49 +419,46 @@ char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
|||||||
weight = 1;
|
weight = 1;
|
||||||
h = ustrlen(source) - 1;
|
h = ustrlen(source) - 1;
|
||||||
|
|
||||||
for(i = 0; i < h; i++)
|
for (i = 0; i < h; i++) {
|
||||||
{
|
|
||||||
sum += ctoi(source[i]) * weight;
|
sum += ctoi(source[i]) * weight;
|
||||||
weight++;
|
weight++;
|
||||||
}
|
}
|
||||||
|
|
||||||
check = sum % 11;
|
check = sum % 11;
|
||||||
check_char = itoc(check);
|
check_char = itoc(check);
|
||||||
if(check == 10) { check_char = 'X'; }
|
if (check == 10) {
|
||||||
|
check_char = 'X';
|
||||||
|
}
|
||||||
return check_char;
|
return check_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char dest[]) /* Make an EAN-13 barcode from an SBN or ISBN */
|
/* Make an EAN-13 barcode from an SBN or ISBN */
|
||||||
{
|
int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char dest[]) {
|
||||||
int i, error_number;
|
int i, error_number;
|
||||||
char check_digit;
|
char check_digit;
|
||||||
|
|
||||||
to_upper(source);
|
to_upper(source);
|
||||||
error_number = is_sane("0123456789X", source, src_len);
|
error_number = is_sane("0123456789X", source, src_len);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in input");
|
strcpy(symbol->errtxt, "Invalid characters in input");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Input must be 9, 10 or 13 characters */
|
/* Input must be 9, 10 or 13 characters */
|
||||||
if(((src_len < 9) || (src_len > 13)) || ((src_len > 10) && (src_len < 13)))
|
if (((src_len < 9) || (src_len > 13)) || ((src_len > 10) && (src_len < 13))) {
|
||||||
{
|
|
||||||
strcpy(symbol->errtxt, "Input wrong length");
|
strcpy(symbol->errtxt, "Input wrong length");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(src_len == 13) /* Using 13 character ISBN */
|
if (src_len == 13) /* Using 13 character ISBN */ {
|
||||||
{
|
if (!(((source[0] == '9') && (source[1] == '7')) &&
|
||||||
if(!(((source[0] == '9') && (source[1] == '7')) &&
|
((source[2] == '8') || (source[2] == '9')))) {
|
||||||
((source[2] == '8') || (source[2] == '9'))))
|
|
||||||
{
|
|
||||||
strcpy(symbol->errtxt, "Invalid ISBN");
|
strcpy(symbol->errtxt, "Invalid ISBN");
|
||||||
return ZINT_ERROR_INVALID_DATA;
|
return ZINT_ERROR_INVALID_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
check_digit = isbn13_check(source);
|
check_digit = isbn13_check(source);
|
||||||
if (source[src_len - 1] != check_digit)
|
if (source[src_len - 1] != check_digit) {
|
||||||
{
|
|
||||||
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
||||||
return ZINT_ERROR_INVALID_CHECK;
|
return ZINT_ERROR_INVALID_CHECK;
|
||||||
}
|
}
|
||||||
@ -453,16 +467,13 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int
|
|||||||
ean13(symbol, source, dest);
|
ean13(symbol, source, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(src_len == 10) /* Using 10 digit ISBN */
|
if (src_len == 10) /* Using 10 digit ISBN */ {
|
||||||
{
|
|
||||||
check_digit = isbn_check(source);
|
check_digit = isbn_check(source);
|
||||||
if(check_digit != source[src_len - 1])
|
if (check_digit != source[src_len - 1]) {
|
||||||
{
|
|
||||||
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
||||||
return ZINT_ERROR_INVALID_CHECK;
|
return ZINT_ERROR_INVALID_CHECK;
|
||||||
}
|
}
|
||||||
for(i = 13; i > 0; i--)
|
for (i = 13; i > 0; i--) {
|
||||||
{
|
|
||||||
source[i] = source[i - 3];
|
source[i] = source[i - 3];
|
||||||
}
|
}
|
||||||
source[0] = '9';
|
source[0] = '9';
|
||||||
@ -473,26 +484,22 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int
|
|||||||
ean13(symbol, source, dest);
|
ean13(symbol, source, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(src_len == 9) /* Using 9 digit SBN */
|
if (src_len == 9) /* Using 9 digit SBN */ {
|
||||||
{
|
|
||||||
/* Add leading zero */
|
/* Add leading zero */
|
||||||
for(i = 10; i > 0; i--)
|
for (i = 10; i > 0; i--) {
|
||||||
{
|
|
||||||
source[i] = source[i - 1];
|
source[i] = source[i - 1];
|
||||||
}
|
}
|
||||||
source[0] = '0';
|
source[0] = '0';
|
||||||
|
|
||||||
/* Verify check digit */
|
/* Verify check digit */
|
||||||
check_digit = isbn_check(source);
|
check_digit = isbn_check(source);
|
||||||
if(check_digit != source[ustrlen(source) - 1])
|
if (check_digit != source[ustrlen(source) - 1]) {
|
||||||
{
|
|
||||||
strcpy(symbol->errtxt, "Incorrect SBN check");
|
strcpy(symbol->errtxt, "Incorrect SBN check");
|
||||||
return ZINT_ERROR_INVALID_CHECK;
|
return ZINT_ERROR_INVALID_CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert to EAN-13 number */
|
/* Convert to EAN-13 number */
|
||||||
for(i = 13; i > 0; i--)
|
for (i = 13; i > 0; i--) {
|
||||||
{
|
|
||||||
source[i] = source[i - 3];
|
source[i] = source[i - 3];
|
||||||
}
|
}
|
||||||
source[0] = '9';
|
source[0] = '9';
|
||||||
@ -506,18 +513,18 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add leading zeroes to EAN and UPC strings */
|
||||||
void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsigned char local_source[]) {
|
void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsigned char local_source[]) {
|
||||||
/* Add leading zeroes to EAN and UPC strings */
|
|
||||||
unsigned char first_part[20], second_part[20], zfirst_part[20], zsecond_part[20];
|
unsigned char first_part[20], second_part[20], zfirst_part[20], zsecond_part[20];
|
||||||
int with_addon = 0;
|
int with_addon = 0;
|
||||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h;
|
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h;
|
||||||
|
|
||||||
h = ustrlen(source);
|
h = ustrlen(source);
|
||||||
for(i = 0; i < h; i++) {
|
for (i = 0; i < h; i++) {
|
||||||
if(source[i] == '+') {
|
if (source[i] == '+') {
|
||||||
with_addon = 1;
|
with_addon = 1;
|
||||||
} else {
|
} else {
|
||||||
if(with_addon == 0) {
|
if (with_addon == 0) {
|
||||||
first_len++;
|
first_len++;
|
||||||
} else {
|
} else {
|
||||||
second_len++;
|
second_len++;
|
||||||
@ -525,34 +532,48 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ustrcpy(first_part, (unsigned char *)"");
|
ustrcpy(first_part, (unsigned char *) "");
|
||||||
ustrcpy(second_part, (unsigned char *)"");
|
ustrcpy(second_part, (unsigned char *) "");
|
||||||
ustrcpy(zfirst_part, (unsigned char *)"");
|
ustrcpy(zfirst_part, (unsigned char *) "");
|
||||||
ustrcpy(zsecond_part, (unsigned char *)"");
|
ustrcpy(zsecond_part, (unsigned char *) "");
|
||||||
|
|
||||||
/* Split input into two strings */
|
/* Split input into two strings */
|
||||||
for(i = 0; i < first_len; i++) {
|
for (i = 0; i < first_len; i++) {
|
||||||
first_part[i] = source[i];
|
first_part[i] = source[i];
|
||||||
first_part[i + 1] = '\0';
|
first_part[i + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < second_len; i++) {
|
for (i = 0; i < second_len; i++) {
|
||||||
second_part[i] = source[i + first_len + 1];
|
second_part[i] = source[i + first_len + 1];
|
||||||
second_part[i + 1] = '\0';
|
second_part[i + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate target lengths */
|
/* Calculate target lengths */
|
||||||
if(second_len <= 5) { zsecond_len = 5; }
|
if (second_len <= 5) {
|
||||||
if(second_len <= 2) { zsecond_len = 2; }
|
zsecond_len = 5;
|
||||||
if(second_len == 0) { zsecond_len = 0; }
|
}
|
||||||
switch(symbol->symbology) {
|
if (second_len <= 2) {
|
||||||
|
zsecond_len = 2;
|
||||||
|
}
|
||||||
|
if (second_len == 0) {
|
||||||
|
zsecond_len = 0;
|
||||||
|
}
|
||||||
|
switch (symbol->symbology) {
|
||||||
case BARCODE_EANX:
|
case BARCODE_EANX:
|
||||||
case BARCODE_EANX_CC:
|
case BARCODE_EANX_CC:
|
||||||
if(first_len <= 12) { zfirst_len = 12; }
|
if (first_len <= 12) {
|
||||||
if(first_len <= 7) { zfirst_len = 7; }
|
zfirst_len = 12;
|
||||||
if(second_len == 0) {
|
}
|
||||||
if(first_len <= 5) { zfirst_len = 5; }
|
if (first_len <= 7) {
|
||||||
if(first_len <= 2) { zfirst_len = 2; }
|
zfirst_len = 7;
|
||||||
|
}
|
||||||
|
if (second_len == 0) {
|
||||||
|
if (first_len <= 5) {
|
||||||
|
zfirst_len = 5;
|
||||||
|
}
|
||||||
|
if (first_len <= 2) {
|
||||||
|
zfirst_len = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_UPCA:
|
case BARCODE_UPCA:
|
||||||
@ -561,38 +582,43 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
|
|||||||
break;
|
break;
|
||||||
case BARCODE_UPCE:
|
case BARCODE_UPCE:
|
||||||
case BARCODE_UPCE_CC:
|
case BARCODE_UPCE_CC:
|
||||||
if(first_len == 7) { zfirst_len = 7; }
|
if (first_len == 7) {
|
||||||
if(first_len <= 6) { zfirst_len = 6; }
|
zfirst_len = 7;
|
||||||
|
}
|
||||||
|
if (first_len <= 6) {
|
||||||
|
zfirst_len = 6;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_ISBNX:
|
case BARCODE_ISBNX:
|
||||||
if(first_len <= 9) { zfirst_len = 9; }
|
if (first_len <= 9) {
|
||||||
|
zfirst_len = 9;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Add leading zeroes */
|
/* Add leading zeroes */
|
||||||
for(i = 0; i < (zfirst_len - first_len); i++) {
|
for (i = 0; i < (zfirst_len - first_len); i++) {
|
||||||
uconcat(zfirst_part, (unsigned char *)"0");
|
uconcat(zfirst_part, (unsigned char *) "0");
|
||||||
}
|
}
|
||||||
uconcat(zfirst_part, first_part);
|
uconcat(zfirst_part, first_part);
|
||||||
for(i = 0; i < (zsecond_len - second_len); i++) {
|
for (i = 0; i < (zsecond_len - second_len); i++) {
|
||||||
uconcat(zsecond_part, (unsigned char *)"0");
|
uconcat(zsecond_part, (unsigned char *) "0");
|
||||||
}
|
}
|
||||||
uconcat(zsecond_part, second_part);
|
uconcat(zsecond_part, second_part);
|
||||||
|
|
||||||
/* Copy adjusted data back to local_source */
|
/* Copy adjusted data back to local_source */
|
||||||
uconcat(local_source, zfirst_part);
|
uconcat(local_source, zfirst_part);
|
||||||
if(zsecond_len != 0) {
|
if (zsecond_len != 0) {
|
||||||
uconcat(local_source, (unsigned char *)"+");
|
uconcat(local_source, (unsigned char *) "+");
|
||||||
uconcat(local_source, zsecond_part);
|
uconcat(local_source, zsecond_part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
/* splits string to parts before and after '+' parts */
|
||||||
{
|
int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
||||||
/* splits string to parts before and after '+' parts */
|
unsigned char first_part[20] = {0}, second_part[20] = {0}, dest[1000] = {0};
|
||||||
unsigned char first_part[20] = { 0 }, second_part[20] = { 0 }, dest[1000] = { 0 };
|
unsigned char local_source[20] = {0};
|
||||||
unsigned char local_source[20] = { 0 };
|
|
||||||
unsigned int latch, reader, writer, with_addon;
|
unsigned int latch, reader, writer, with_addon;
|
||||||
int error_number, i;
|
int error_number, i;
|
||||||
|
|
||||||
@ -601,50 +627,50 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
latch = FALSE;
|
latch = FALSE;
|
||||||
writer = 0;
|
writer = 0;
|
||||||
|
|
||||||
if(src_len > 19) {
|
if (src_len > 19) {
|
||||||
strcpy(symbol->errtxt, "Input too long");
|
strcpy(symbol->errtxt, "Input too long");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
if(symbol->symbology != BARCODE_ISBNX) {
|
if (symbol->symbology != BARCODE_ISBNX) {
|
||||||
/* ISBN has it's own checking routine */
|
/* ISBN has it's own checking routine */
|
||||||
error_number = is_sane("0123456789+", source, src_len);
|
error_number = is_sane("0123456789+", source, src_len);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error_number = is_sane("0123456789Xx", source, src_len);
|
error_number = is_sane("0123456789Xx", source, src_len);
|
||||||
if(error_number == ZINT_ERROR_INVALID_DATA) {
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||||
strcpy(symbol->errtxt, "Invalid characters in input");
|
strcpy(symbol->errtxt, "Invalid characters in input");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Add leading zeroes */
|
/* Add leading zeroes */
|
||||||
ustrcpy(local_source, (unsigned char *)"");
|
ustrcpy(local_source, (unsigned char *) "");
|
||||||
if(symbol->symbology == BARCODE_ISBNX) {
|
if (symbol->symbology == BARCODE_ISBNX) {
|
||||||
to_upper(local_source);
|
to_upper(local_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
ean_leading_zeroes(symbol, source, local_source);
|
ean_leading_zeroes(symbol, source, local_source);
|
||||||
|
|
||||||
for(reader = 0; reader <= ustrlen(local_source); reader++)
|
for (reader = 0; reader <= ustrlen(local_source); reader++) {
|
||||||
{
|
if (source[reader] == '+') {
|
||||||
if(source[reader] == '+') { with_addon = TRUE; }
|
with_addon = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = 0;
|
reader = 0;
|
||||||
if(with_addon) {
|
if (with_addon) {
|
||||||
do {
|
do {
|
||||||
if(local_source[reader] == '+') {
|
if (local_source[reader] == '+') {
|
||||||
first_part[writer] = '\0';
|
first_part[writer] = '\0';
|
||||||
latch = TRUE;
|
latch = TRUE;
|
||||||
reader++;
|
reader++;
|
||||||
writer = 0;
|
writer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(latch) {
|
if (latch) {
|
||||||
second_part[writer] = local_source[reader];
|
second_part[writer] = local_source[reader];
|
||||||
reader++;
|
reader++;
|
||||||
writer++;
|
writer++;
|
||||||
@ -655,25 +681,28 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
}
|
}
|
||||||
} while (reader <= ustrlen(local_source));
|
} while (reader <= ustrlen(local_source));
|
||||||
} else {
|
} else {
|
||||||
strcpy((char*)first_part, (char*)local_source);
|
strcpy((char*) first_part, (char*) local_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (symbol->symbology) {
|
||||||
switch(symbol->symbology)
|
|
||||||
{
|
|
||||||
case BARCODE_EANX:
|
case BARCODE_EANX:
|
||||||
switch(ustrlen(first_part))
|
switch (ustrlen(first_part)) {
|
||||||
{
|
case 2: add_on(first_part, (char*) dest, 0);
|
||||||
case 2: add_on(first_part, (char*)dest, 0); ustrcpy(symbol->text, first_part); break;
|
ustrcpy(symbol->text, first_part);
|
||||||
case 5: add_on(first_part, (char*)dest, 0); ustrcpy(symbol->text, first_part); break;
|
break;
|
||||||
case 7: ean8(symbol, first_part, (char*)dest); break;
|
case 5: add_on(first_part, (char*) dest, 0);
|
||||||
case 12: ean13(symbol, first_part, (char*)dest); break;
|
ustrcpy(symbol->text, first_part);
|
||||||
default: strcpy(symbol->errtxt, "Invalid length input"); return ZINT_ERROR_TOO_LONG;
|
break;
|
||||||
|
case 7: ean8(symbol, first_part, (char*) dest);
|
||||||
|
break;
|
||||||
|
case 12: ean13(symbol, first_part, (char*) dest);
|
||||||
|
break;
|
||||||
|
default: strcpy(symbol->errtxt, "Invalid length input");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_EANX_CC:
|
case BARCODE_EANX_CC:
|
||||||
switch(ustrlen(first_part))
|
switch (ustrlen(first_part)) { /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
|
||||||
{ /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */
|
|
||||||
case 7: set_module(symbol, symbol->rows, 1);
|
case 7: set_module(symbol, symbol->rows, 1);
|
||||||
set_module(symbol, symbol->rows, 67);
|
set_module(symbol, symbol->rows, 67);
|
||||||
set_module(symbol, symbol->rows + 1, 0);
|
set_module(symbol, symbol->rows + 1, 0);
|
||||||
@ -684,7 +713,8 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
symbol->row_height[symbol->rows + 1] = 2;
|
symbol->row_height[symbol->rows + 1] = 2;
|
||||||
symbol->row_height[symbol->rows + 2] = 2;
|
symbol->row_height[symbol->rows + 2] = 2;
|
||||||
symbol->rows += 3;
|
symbol->rows += 3;
|
||||||
ean8(symbol, first_part, (char*)dest); break;
|
ean8(symbol, first_part, (char*) dest);
|
||||||
|
break;
|
||||||
case 12:set_module(symbol, symbol->rows, 1);
|
case 12:set_module(symbol, symbol->rows, 1);
|
||||||
set_module(symbol, symbol->rows, 95);
|
set_module(symbol, symbol->rows, 95);
|
||||||
set_module(symbol, symbol->rows + 1, 0);
|
set_module(symbol, symbol->rows + 1, 0);
|
||||||
@ -695,20 +725,22 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
symbol->row_height[symbol->rows + 1] = 2;
|
symbol->row_height[symbol->rows + 1] = 2;
|
||||||
symbol->row_height[symbol->rows + 2] = 2;
|
symbol->row_height[symbol->rows + 2] = 2;
|
||||||
symbol->rows += 3;
|
symbol->rows += 3;
|
||||||
ean13(symbol, first_part, (char*)dest); break;
|
ean13(symbol, first_part, (char*) dest);
|
||||||
default: strcpy(symbol->errtxt, "Invalid length EAN input"); return ZINT_ERROR_TOO_LONG;
|
break;
|
||||||
|
default: strcpy(symbol->errtxt, "Invalid length EAN input");
|
||||||
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_UPCA:
|
case BARCODE_UPCA:
|
||||||
if(ustrlen(first_part) == 11) {
|
if (ustrlen(first_part) == 11) {
|
||||||
upca(symbol, first_part, (char*)dest);
|
upca(symbol, first_part, (char*) dest);
|
||||||
} else {
|
} else {
|
||||||
strcpy(symbol->errtxt, "Input wrong length");
|
strcpy(symbol->errtxt, "Input wrong length");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_UPCA_CC:
|
case BARCODE_UPCA_CC:
|
||||||
if(ustrlen(first_part) == 11) {
|
if (ustrlen(first_part) == 11) {
|
||||||
set_module(symbol, symbol->rows, 1);
|
set_module(symbol, symbol->rows, 1);
|
||||||
set_module(symbol, symbol->rows, 95);
|
set_module(symbol, symbol->rows, 95);
|
||||||
set_module(symbol, symbol->rows + 1, 0);
|
set_module(symbol, symbol->rows + 1, 0);
|
||||||
@ -719,22 +751,22 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
symbol->row_height[symbol->rows + 1] = 2;
|
symbol->row_height[symbol->rows + 1] = 2;
|
||||||
symbol->row_height[symbol->rows + 2] = 2;
|
symbol->row_height[symbol->rows + 2] = 2;
|
||||||
symbol->rows += 3;
|
symbol->rows += 3;
|
||||||
upca(symbol, first_part, (char*)dest);
|
upca(symbol, first_part, (char*) dest);
|
||||||
} else {
|
} else {
|
||||||
strcpy(symbol->errtxt, "UPCA input wrong length");
|
strcpy(symbol->errtxt, "UPCA input wrong length");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_UPCE:
|
case BARCODE_UPCE:
|
||||||
if((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
|
if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
|
||||||
upce(symbol, first_part, (char*)dest);
|
upce(symbol, first_part, (char*) dest);
|
||||||
} else {
|
} else {
|
||||||
strcpy(symbol->errtxt, "Input wrong length");
|
strcpy(symbol->errtxt, "Input wrong length");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_UPCE_CC:
|
case BARCODE_UPCE_CC:
|
||||||
if((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
|
if ((ustrlen(first_part) >= 6) && (ustrlen(first_part) <= 7)) {
|
||||||
set_module(symbol, symbol->rows, 1);
|
set_module(symbol, symbol->rows, 1);
|
||||||
set_module(symbol, symbol->rows, 51);
|
set_module(symbol, symbol->rows, 51);
|
||||||
set_module(symbol, symbol->rows + 1, 0);
|
set_module(symbol, symbol->rows + 1, 0);
|
||||||
@ -745,30 +777,29 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
symbol->row_height[symbol->rows + 1] = 2;
|
symbol->row_height[symbol->rows + 1] = 2;
|
||||||
symbol->row_height[symbol->rows + 2] = 2;
|
symbol->row_height[symbol->rows + 2] = 2;
|
||||||
symbol->rows += 3;
|
symbol->rows += 3;
|
||||||
upce(symbol, first_part, (char*)dest);
|
upce(symbol, first_part, (char*) dest);
|
||||||
} else {
|
} else {
|
||||||
strcpy(symbol->errtxt, "UPCE input wrong length");
|
strcpy(symbol->errtxt, "UPCE input wrong length");
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BARCODE_ISBNX:
|
case BARCODE_ISBNX:
|
||||||
error_number = isbn(symbol, first_part, ustrlen(first_part), (char*)dest);
|
error_number = isbn(symbol, first_part, ustrlen(first_part), (char*) dest);
|
||||||
if(error_number > 4) {
|
if (error_number > 4) {
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch(ustrlen(second_part))
|
switch (ustrlen(second_part)) {
|
||||||
{
|
|
||||||
case 0: break;
|
case 0: break;
|
||||||
case 2:
|
case 2:
|
||||||
add_on(second_part, (char*)dest, 1);
|
add_on(second_part, (char*) dest, 1);
|
||||||
uconcat(symbol->text, (unsigned char*)"+");
|
uconcat(symbol->text, (unsigned char*) "+");
|
||||||
uconcat(symbol->text, second_part);
|
uconcat(symbol->text, second_part);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
add_on(second_part, (char*)dest, 1);
|
add_on(second_part, (char*) dest, 1);
|
||||||
uconcat(symbol->text, (unsigned char*)"+");
|
uconcat(symbol->text, (unsigned char*) "+");
|
||||||
uconcat(symbol->text, second_part);
|
uconcat(symbol->text, second_part);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -776,15 +807,15 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
|
||||||
expand(symbol, (char*)dest);
|
expand(symbol, (char*) dest);
|
||||||
|
|
||||||
switch(symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_EANX_CC:
|
case BARCODE_EANX_CC:
|
||||||
case BARCODE_UPCA_CC:
|
case BARCODE_UPCA_CC:
|
||||||
case BARCODE_UPCE_CC:
|
case BARCODE_UPCE_CC:
|
||||||
/* shift the symbol to the right one space to allow for separator bars */
|
/* shift the symbol to the right one space to allow for separator bars */
|
||||||
for(i = (symbol->width + 1); i >= 1; i--) {
|
for (i = (symbol->width + 1); i >= 1; i--) {
|
||||||
if(module_is_set(symbol, symbol->rows - 1, i - 1)) {
|
if (module_is_set(symbol, symbol->rows - 1, i - 1)) {
|
||||||
set_module(symbol, symbol->rows - 1, i);
|
set_module(symbol, symbol->rows - 1, i);
|
||||||
} else {
|
} else {
|
||||||
unset_module(symbol, symbol->rows - 1, i);
|
unset_module(symbol, symbol->rows - 1, i);
|
||||||
@ -796,12 +827,8 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if((symbol->errtxt[0] == 'w') && (error_number == 0)) {
|
if ((symbol->errtxt[0] == 'w') && (error_number == 0)) {
|
||||||
error_number = 1; /* flag UPC-E warnings */
|
error_number = 1; /* flag UPC-E warnings */
|
||||||
}
|
}
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* zint.h - definitions for libzint
|
/* zint.h - definitions for libzint
|
||||||
|
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
@ -27,7 +27,7 @@
|
|||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
SUCH DAMAGE.
|
SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ZINT_H
|
#ifndef ZINT_H
|
||||||
#define ZINT_H
|
#define ZINT_H
|
||||||
@ -36,38 +36,38 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
struct zint_render_line {
|
struct zint_render_line {
|
||||||
float x, y, length, width;
|
float x, y, length, width;
|
||||||
struct zint_render_line *next; /* Pointer to next line */
|
struct zint_render_line *next; /* Pointer to next line */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zint_render_string {
|
struct zint_render_string {
|
||||||
float x, y, fsize;
|
float x, y, fsize;
|
||||||
float width; /* Suggested string width, may be 0 if none recommended */
|
float width; /* Suggested string width, may be 0 if none recommended */
|
||||||
int length;
|
int length;
|
||||||
unsigned char *text;
|
unsigned char *text;
|
||||||
struct zint_render_string *next; /* Pointer to next character */
|
struct zint_render_string *next; /* Pointer to next character */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zint_render_ring {
|
struct zint_render_ring {
|
||||||
float x, y, radius, line_width;
|
float x, y, radius, line_width;
|
||||||
struct zint_render_ring *next; /* Pointer to next ring */
|
struct zint_render_ring *next; /* Pointer to next ring */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zint_render_hexagon {
|
struct zint_render_hexagon {
|
||||||
float x, y;
|
float x, y;
|
||||||
struct zint_render_hexagon *next; /* Pointer to next hexagon */
|
struct zint_render_hexagon *next; /* Pointer to next hexagon */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zint_render {
|
struct zint_render {
|
||||||
float width, height;
|
float width, height;
|
||||||
struct zint_render_line *lines; /* Pointer to first line */
|
struct zint_render_line *lines; /* Pointer to first line */
|
||||||
struct zint_render_string *strings; /* Pointer to first string */
|
struct zint_render_string *strings; /* Pointer to first string */
|
||||||
struct zint_render_ring *rings; /* Pointer to first ring */
|
struct zint_render_ring *rings; /* Pointer to first ring */
|
||||||
struct zint_render_hexagon *hexagons; /* Pointer to first hexagon */
|
struct zint_render_hexagon *hexagons; /* Pointer to first hexagon */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zint_symbol {
|
struct zint_symbol {
|
||||||
int symbology;
|
int symbology;
|
||||||
int height;
|
int height;
|
||||||
int whitespace_width;
|
int whitespace_width;
|
||||||
@ -93,10 +93,10 @@ struct zint_symbol {
|
|||||||
int bitmap_width;
|
int bitmap_width;
|
||||||
int bitmap_height;
|
int bitmap_height;
|
||||||
struct zint_render *rendered;
|
struct zint_render *rendered;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Tbarcode 7 codes */
|
/* Tbarcode 7 codes */
|
||||||
#define BARCODE_CODE11 1
|
#define BARCODE_CODE11 1
|
||||||
#define BARCODE_C25MATRIX 2
|
#define BARCODE_C25MATRIX 2
|
||||||
#define BARCODE_C25INTER 3
|
#define BARCODE_C25INTER 3
|
||||||
@ -153,7 +153,7 @@ struct zint_symbol {
|
|||||||
#define BARCODE_ONECODE 85
|
#define BARCODE_ONECODE 85
|
||||||
#define BARCODE_PLESSEY 86
|
#define BARCODE_PLESSEY 86
|
||||||
|
|
||||||
/* Tbarcode 8 codes */
|
/* Tbarcode 8 codes */
|
||||||
#define BARCODE_TELEPEN_NUM 87
|
#define BARCODE_TELEPEN_NUM 87
|
||||||
#define BARCODE_ITF14 89
|
#define BARCODE_ITF14 89
|
||||||
#define BARCODE_KIX 90
|
#define BARCODE_KIX 90
|
||||||
@ -161,7 +161,7 @@ struct zint_symbol {
|
|||||||
#define BARCODE_DAFT 93
|
#define BARCODE_DAFT 93
|
||||||
#define BARCODE_MICROQR 97
|
#define BARCODE_MICROQR 97
|
||||||
|
|
||||||
/* Tbarcode 9 codes */
|
/* Tbarcode 9 codes */
|
||||||
#define BARCODE_HIBC_128 98
|
#define BARCODE_HIBC_128 98
|
||||||
#define BARCODE_HIBC_39 99
|
#define BARCODE_HIBC_39 99
|
||||||
#define BARCODE_HIBC_DM 102
|
#define BARCODE_HIBC_DM 102
|
||||||
@ -171,7 +171,7 @@ struct zint_symbol {
|
|||||||
#define BARCODE_HIBC_BLOCKF 110
|
#define BARCODE_HIBC_BLOCKF 110
|
||||||
#define BARCODE_HIBC_AZTEC 112
|
#define BARCODE_HIBC_AZTEC 112
|
||||||
|
|
||||||
/* Zint specific */
|
/* Zint specific */
|
||||||
#define BARCODE_AZRUNE 128
|
#define BARCODE_AZRUNE 128
|
||||||
#define BARCODE_CODE32 129
|
#define BARCODE_CODE32 129
|
||||||
#define BARCODE_EANX_CC 130
|
#define BARCODE_EANX_CC 130
|
||||||
@ -213,34 +213,34 @@ struct zint_symbol {
|
|||||||
#define ZINT_ERROR_MEMORY 11
|
#define ZINT_ERROR_MEMORY 11
|
||||||
|
|
||||||
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_MSC_VER)
|
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_MSC_VER)
|
||||||
# if defined (DLL_EXPORT) || defined(PIC) || defined(_USRDLL)
|
#if defined (DLL_EXPORT) || defined(PIC) || defined(_USRDLL)
|
||||||
# define ZINT_EXTERN __declspec(dllexport)
|
#define ZINT_EXTERN __declspec(dllexport)
|
||||||
# elif defined(ZINT_DLL)
|
#elif defined(ZINT_DLL)
|
||||||
# define ZINT_EXTERN __declspec(dllimport)
|
#define ZINT_EXTERN __declspec(dllimport)
|
||||||
# else
|
|
||||||
# define ZINT_EXTERN extern
|
|
||||||
# endif
|
|
||||||
#else
|
#else
|
||||||
# define ZINT_EXTERN extern
|
#define ZINT_EXTERN extern
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define ZINT_EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZINT_EXTERN struct zint_symbol *ZBarcode_Create(void);
|
ZINT_EXTERN struct zint_symbol *ZBarcode_Create(void);
|
||||||
ZINT_EXTERN void ZBarcode_Clear(struct zint_symbol *symbol);
|
ZINT_EXTERN void ZBarcode_Clear(struct zint_symbol *symbol);
|
||||||
ZINT_EXTERN void ZBarcode_Delete(struct zint_symbol *symbol);
|
ZINT_EXTERN void ZBarcode_Delete(struct zint_symbol *symbol);
|
||||||
|
|
||||||
ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input, int length);
|
ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input, int length);
|
||||||
ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename);
|
ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename);
|
||||||
ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle);
|
||||||
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
||||||
ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
||||||
|
|
||||||
ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, float width, float height);
|
ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, float width, float height);
|
||||||
|
|
||||||
ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
|
||||||
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
||||||
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
||||||
|
|
||||||
ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
|
ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user