mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Allow selection of GS1 mode on GS1 symbols
Because some symbols require GS1 data, selecting GS1 mode for them would result in GS1 parsing being done twice, corrupting the data. Fixes #165 reported by Gregory Van Vooren
This commit is contained in:
parent
eb3a004ace
commit
ff2ceea361
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
|
||||||
Bugfixes thanks to Christian Sakowski and BogDan Vatra
|
Bugfixes thanks to Christian Sakowski and BogDan Vatra
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -689,11 +689,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
float glyph_count;
|
float glyph_count;
|
||||||
char dest[1000];
|
char dest[1000];
|
||||||
int separator_row, linkage_flag, c_count;
|
int separator_row, linkage_flag, c_count;
|
||||||
#ifndef _MSC_VER
|
|
||||||
char reduced[length + 1];
|
|
||||||
#else
|
|
||||||
char* reduced = (char*) _alloca(length + 1);
|
|
||||||
#endif
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
strcpy(dest, "");
|
strcpy(dest, "");
|
||||||
linkage_flag = 0;
|
linkage_flag = 0;
|
||||||
@ -726,20 +722,12 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
symbol->rows += 1;
|
symbol->rows += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symbol->input_mode != GS1_MODE) {
|
|
||||||
/* GS1 data has not been checked yet */
|
|
||||||
error_number = gs1_verify(symbol, source, length, reduced);
|
|
||||||
if (error_number != 0) {
|
|
||||||
return error_number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
|
/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
|
||||||
indexliste = 0;
|
indexliste = 0;
|
||||||
indexchaine = 0;
|
indexchaine = 0;
|
||||||
|
|
||||||
mode = parunmodd(reduced[indexchaine]);
|
mode = parunmodd(source[indexchaine]);
|
||||||
if (reduced[indexchaine] == '[') {
|
if (source[indexchaine] == '[') {
|
||||||
mode = ABORC;
|
mode = ABORC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,16 +737,16 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
list[1][indexliste] = mode;
|
list[1][indexliste] = mode;
|
||||||
while ((list[1][indexliste] == mode) && (indexchaine < (int) strlen(reduced))) {
|
while ((list[1][indexliste] == mode) && (indexchaine < (int) ustrlen(source))) {
|
||||||
list[0][indexliste]++;
|
list[0][indexliste]++;
|
||||||
indexchaine++;
|
indexchaine++;
|
||||||
mode = parunmodd(reduced[indexchaine]);
|
mode = parunmodd(source[indexchaine]);
|
||||||
if (reduced[indexchaine] == '[') {
|
if (source[indexchaine] == '[') {
|
||||||
mode = ABORC;
|
mode = ABORC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexliste++;
|
indexliste++;
|
||||||
} while (indexchaine < (int) strlen(reduced));
|
} while (indexchaine < (int) ustrlen(source));
|
||||||
|
|
||||||
dxsmooth(&indexliste);
|
dxsmooth(&indexliste);
|
||||||
|
|
||||||
@ -786,7 +774,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
c_count = 0;
|
c_count = 0;
|
||||||
for (i = 0; i < read; i++) {
|
for (i = 0; i < read; i++) {
|
||||||
if (set[i] == 'C') {
|
if (set[i] == 'C') {
|
||||||
if (reduced[i] == '[') {
|
if (source[i] == '[') {
|
||||||
if (c_count & 1) {
|
if (c_count & 1) {
|
||||||
if ((i - c_count) != 0) {
|
if ((i - c_count) != 0) {
|
||||||
set[i - c_count] = 'B';
|
set[i - c_count] = 'B';
|
||||||
@ -826,7 +814,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
being too long */
|
being too long */
|
||||||
last_set = ' ';
|
last_set = ' ';
|
||||||
glyph_count = 0.0;
|
glyph_count = 0.0;
|
||||||
for (i = 0; i < (int) strlen(reduced); i++) {
|
for (i = 0; i < (int) ustrlen(source); i++) {
|
||||||
if ((set[i] == 'a') || (set[i] == 'b')) {
|
if ((set[i] == 'a') || (set[i] == 'b')) {
|
||||||
glyph_count = glyph_count + 1.0;
|
glyph_count = glyph_count + 1.0;
|
||||||
}
|
}
|
||||||
@ -837,7 +825,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((set[i] == 'C') && (reduced[i] != '[')) {
|
if ((set[i] == 'C') && (source[i] != '[')) {
|
||||||
glyph_count = glyph_count + 0.5;
|
glyph_count = glyph_count + 0.5;
|
||||||
} else {
|
} else {
|
||||||
glyph_count = glyph_count + 1.0;
|
glyph_count = glyph_count + 1.0;
|
||||||
@ -897,20 +885,20 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
bar_characters++;
|
bar_characters++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reduced[read] != '[') {
|
if (source[read] != '[') {
|
||||||
switch (set[read]) { /* Encode data characters */
|
switch (set[read]) { /* Encode data characters */
|
||||||
case 'A':
|
case 'A':
|
||||||
case 'a':
|
case 'a':
|
||||||
c128_set_a(reduced[read], dest, values, &bar_characters);
|
c128_set_a(source[read], dest, values, &bar_characters);
|
||||||
read++;
|
read++;
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
case 'b':
|
case 'b':
|
||||||
c128_set_b(reduced[read], dest, values, &bar_characters);
|
c128_set_b(source[read], dest, values, &bar_characters);
|
||||||
read++;
|
read++;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
c128_set_c(reduced[read], reduced[read + 1], dest, values, &bar_characters);
|
c128_set_c(source[read], source[read + 1], dest, values, &bar_characters);
|
||||||
read += 2;
|
read += 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -920,7 +908,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
bar_characters++;
|
bar_characters++;
|
||||||
read++;
|
read++;
|
||||||
}
|
}
|
||||||
} while (read < (int) strlen(reduced));
|
} while (read < (int) ustrlen(source));
|
||||||
|
|
||||||
/* "...note that the linkage flag is an extra code set character between
|
/* "...note that the linkage flag is an extra code set character between
|
||||||
the last data character and the Symbol Check Character" (GS1 Specification) */
|
the last data character and the Symbol Check Character" (GS1 Specification) */
|
||||||
@ -931,7 +919,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
/* CC-A or CC-B 2D component */
|
/* CC-A or CC-B 2D component */
|
||||||
switch (set[strlen(reduced) - 1]) {
|
switch (set[ustrlen(source) - 1]) {
|
||||||
case 'A': linkage_flag = 100;
|
case 'A': linkage_flag = 100;
|
||||||
break;
|
break;
|
||||||
case 'B': linkage_flag = 99;
|
case 'B': linkage_flag = 99;
|
||||||
@ -942,7 +930,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
/* CC-C 2D component */
|
/* CC-C 2D component */
|
||||||
switch (set[strlen(reduced) - 1]) {
|
switch (set[ustrlen(source) - 1]) {
|
||||||
case 'A': linkage_flag = 99;
|
case 'A': linkage_flag = 99;
|
||||||
break;
|
break;
|
||||||
case 'B': linkage_flag = 101;
|
case 'B': linkage_flag = 101;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2008-2019 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
|
||||||
@ -1618,10 +1618,8 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
unsigned int bs = 20 * rs;
|
unsigned int bs = 20 * rs;
|
||||||
unsigned int pri_len;
|
unsigned int pri_len;
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
char reduced[rs];
|
|
||||||
char binary_string[bs];
|
char binary_string[bs];
|
||||||
#else
|
#else
|
||||||
char* reduced = (char*) _alloca(rs);
|
|
||||||
char* binary_string = (char*) _alloca(bs);
|
char* binary_string = (char*) _alloca(bs);
|
||||||
#endif
|
#endif
|
||||||
struct zint_symbol *linear;
|
struct zint_symbol *linear;
|
||||||
@ -1648,11 +1646,6 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_number = gs1_verify(symbol, source, length, reduced);
|
|
||||||
if (error_number != 0) {
|
|
||||||
return error_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol->symbology == BARCODE_EAN128_CC) {
|
if (symbol->symbology == BARCODE_EAN128_CC) {
|
||||||
/* Do a test run of encoding the linear component to establish its width */
|
/* Do a test run of encoding the linear component to establish its width */
|
||||||
linear_width = linear_dummy_run((unsigned char *) symbol->primary, pri_len);
|
linear_width = linear_dummy_run((unsigned char *) symbol->primary, pri_len);
|
||||||
@ -1705,7 +1698,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cc_mode == 1) {
|
if (cc_mode == 1) {
|
||||||
i = cc_binary_string(symbol, reduced, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
i = cc_binary_string(symbol, (char *) source, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
||||||
if (i == ZINT_ERROR_TOO_LONG) {
|
if (i == ZINT_ERROR_TOO_LONG) {
|
||||||
cc_mode = 2;
|
cc_mode = 2;
|
||||||
}
|
}
|
||||||
@ -1713,7 +1706,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
|
|
||||||
if (cc_mode == 2) {
|
if (cc_mode == 2) {
|
||||||
/* If the data didn't fit into CC-A it is recalculated for CC-B */
|
/* If the data didn't fit into CC-A it is recalculated for CC-B */
|
||||||
i = cc_binary_string(symbol, reduced, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
i = cc_binary_string(symbol, (char *) source, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
||||||
if (i == ZINT_ERROR_TOO_LONG) {
|
if (i == ZINT_ERROR_TOO_LONG) {
|
||||||
if (symbol->symbology != BARCODE_EAN128_CC) {
|
if (symbol->symbology != BARCODE_EAN128_CC) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
@ -1725,7 +1718,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
|
|
||||||
if (cc_mode == 3) {
|
if (cc_mode == 3) {
|
||||||
/* If the data didn't fit in CC-B (and linear part is GS1-128) it is recalculated for CC-C */
|
/* If the data didn't fit in CC-B (and linear part is GS1-128) it is recalculated for CC-C */
|
||||||
i = cc_binary_string(symbol, reduced, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
i = cc_binary_string(symbol, (char *) source, binary_string, cc_mode, &cc_width, &ecc_level, linear_width);
|
||||||
if (i == ZINT_ERROR_TOO_LONG) {
|
if (i == ZINT_ERROR_TOO_LONG) {
|
||||||
return ZINT_ERROR_TOO_LONG;
|
return ZINT_ERROR_TOO_LONG;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* library.c - external functions of libzint
|
/* library.c - external functions of libzint
|
||||||
|
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2009-2018 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2009-2019 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
|
||||||
@ -184,11 +184,7 @@ extern int ultracode(struct zint_symbol *symbol, const unsigned char source[], c
|
|||||||
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
|
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
|
||||||
extern int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */
|
extern int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */
|
||||||
|
|
||||||
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */
|
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels - depreciated */
|
||||||
|
|
||||||
//extern int ps_plot(struct zint_symbol *symbol); /* Plot to EPS */
|
|
||||||
//extern int svg_plot(struct zint_symbol *symbol); /* Plot to SVG */
|
|
||||||
//extern int emf_plot(struct zint_symbol *symbol); /* Plot to Metafile */
|
|
||||||
|
|
||||||
void error_tag(char error_string[], int error_number) {
|
void error_tag(char error_string[], int error_number) {
|
||||||
|
|
||||||
@ -386,11 +382,11 @@ static void check_row_heights(struct zint_symbol *symbol) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gs1_compliant(const int symbology) {
|
static int check_force_gs1(const int symbology) {
|
||||||
/* Returns 1 if symbology supports GS1 data */
|
/* Returns 1 if symbology MUST have GS1 data */
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
switch (symbology) {
|
switch (symbology) {
|
||||||
case BARCODE_EAN128:
|
case BARCODE_EAN128:
|
||||||
case BARCODE_RSS_EXP:
|
case BARCODE_RSS_EXP:
|
||||||
@ -405,6 +401,19 @@ static int gs1_compliant(const int symbology) {
|
|||||||
case BARCODE_RSS14STACK_CC:
|
case BARCODE_RSS14STACK_CC:
|
||||||
case BARCODE_RSS14_OMNI_CC:
|
case BARCODE_RSS14_OMNI_CC:
|
||||||
case BARCODE_RSS_EXPSTACK_CC:
|
case BARCODE_RSS_EXPSTACK_CC:
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gs1_compliant(const int symbology) {
|
||||||
|
/* Returns 1 if symbology supports GS1 data */
|
||||||
|
|
||||||
|
int result = check_force_gs1(symbology);
|
||||||
|
|
||||||
|
switch (symbology) {
|
||||||
case BARCODE_CODE16K:
|
case BARCODE_CODE16K:
|
||||||
case BARCODE_AZTEC:
|
case BARCODE_AZTEC:
|
||||||
case BARCODE_DATAMATRIX:
|
case BARCODE_DATAMATRIX:
|
||||||
@ -1146,7 +1155,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Start acting on input mode */
|
/* Start acting on input mode */
|
||||||
if (input_mode == GS1_MODE) {
|
if ((input_mode == GS1_MODE) || (check_force_gs1(symbol->symbology))) {
|
||||||
for (i = 0; i < in_length; i++) {
|
for (i = 0; i < in_length; i++) {
|
||||||
if (source[i] == '\0') {
|
if (source[i] == '\0') {
|
||||||
strcpy(symbol->errtxt, "219: NULL characters not permitted in GS1 mode");
|
strcpy(symbol->errtxt, "219: NULL characters not permitted in GS1 mode");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
libzint - the open source barcode library
|
libzint - the open source barcode library
|
||||||
Copyright (C) 2008-2017 Robin Stuart <rstuart114@gmail.com>
|
Copyright (C) 2008-2019 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
|
||||||
@ -1865,23 +1865,14 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
int check_char, c_odd, c_even, elements[235], pattern_width, reader, writer;
|
int check_char, c_odd, c_even, elements[235], pattern_width, reader, writer;
|
||||||
int separator_row;
|
int separator_row;
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
char reduced[src_len + 1], binary_string[(7 * src_len) + 1];
|
char binary_string[(7 * src_len) + 1];
|
||||||
#else
|
#else
|
||||||
char* reduced = (char*) _alloca(src_len + 1);
|
|
||||||
char* binary_string = (char*) _alloca((7 * src_len) + 1);
|
char* binary_string = (char*) _alloca((7 * src_len) + 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
separator_row = 0;
|
separator_row = 0;
|
||||||
reader = 0;
|
reader = 0;
|
||||||
|
|
||||||
if (symbol->input_mode != GS1_MODE) {
|
|
||||||
/* GS1 data has not been verified yet */
|
|
||||||
i = gs1_verify(symbol, source, src_len, reduced);
|
|
||||||
if (i != 0) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((symbol->symbology == BARCODE_RSS_EXP_CC) || (symbol->symbology == BARCODE_RSS_EXPSTACK_CC)) {
|
if ((symbol->symbology == BARCODE_RSS_EXP_CC) || (symbol->symbology == BARCODE_RSS_EXPSTACK_CC)) {
|
||||||
/* make space for a composite separator pattern */
|
/* make space for a composite separator pattern */
|
||||||
separator_row = symbol->rows;
|
separator_row = symbol->rows;
|
||||||
@ -1897,7 +1888,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
|||||||
strcat(binary_string, "0");
|
strcat(binary_string, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
i = rss_binary_string(symbol, reduced, binary_string);
|
i = rss_binary_string(symbol, (char *) source, binary_string);
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user