mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-13 06:34:32 -04: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
4 changed files with 45 additions and 64 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
/*
|
||||
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
|
||||
|
||||
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;
|
||||
char dest[1000];
|
||||
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;
|
||||
strcpy(dest, "");
|
||||
linkage_flag = 0;
|
||||
|
@ -726,20 +722,12 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||
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 */
|
||||
indexliste = 0;
|
||||
indexchaine = 0;
|
||||
|
||||
mode = parunmodd(reduced[indexchaine]);
|
||||
if (reduced[indexchaine] == '[') {
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
if (source[indexchaine] == '[') {
|
||||
mode = ABORC;
|
||||
}
|
||||
|
||||
|
@ -749,16 +737,16 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||
|
||||
do {
|
||||
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]++;
|
||||
indexchaine++;
|
||||
mode = parunmodd(reduced[indexchaine]);
|
||||
if (reduced[indexchaine] == '[') {
|
||||
mode = parunmodd(source[indexchaine]);
|
||||
if (source[indexchaine] == '[') {
|
||||
mode = ABORC;
|
||||
}
|
||||
}
|
||||
indexliste++;
|
||||
} while (indexchaine < (int) strlen(reduced));
|
||||
} while (indexchaine < (int) ustrlen(source));
|
||||
|
||||
dxsmooth(&indexliste);
|
||||
|
||||
|
@ -786,7 +774,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||
c_count = 0;
|
||||
for (i = 0; i < read; i++) {
|
||||
if (set[i] == 'C') {
|
||||
if (reduced[i] == '[') {
|
||||
if (source[i] == '[') {
|
||||
if (c_count & 1) {
|
||||
if ((i - c_count) != 0) {
|
||||
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 */
|
||||
last_set = ' ';
|
||||
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')) {
|
||||
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;
|
||||
} else {
|
||||
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++;
|
||||
}
|
||||
|
||||
if (reduced[read] != '[') {
|
||||
if (source[read] != '[') {
|
||||
switch (set[read]) { /* Encode data characters */
|
||||
case 'A':
|
||||
case 'a':
|
||||
c128_set_a(reduced[read], dest, values, &bar_characters);
|
||||
c128_set_a(source[read], dest, values, &bar_characters);
|
||||
read++;
|
||||
break;
|
||||
case 'B':
|
||||
case 'b':
|
||||
c128_set_b(reduced[read], dest, values, &bar_characters);
|
||||
c128_set_b(source[read], dest, values, &bar_characters);
|
||||
read++;
|
||||
break;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -920,7 +908,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||
bar_characters++;
|
||||
read++;
|
||||
}
|
||||
} while (read < (int) strlen(reduced));
|
||||
} while (read < (int) ustrlen(source));
|
||||
|
||||
/* "...note that the linkage flag is an extra code set character between
|
||||
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 2:
|
||||
/* CC-A or CC-B 2D component */
|
||||
switch (set[strlen(reduced) - 1]) {
|
||||
switch (set[ustrlen(source) - 1]) {
|
||||
case 'A': linkage_flag = 100;
|
||||
break;
|
||||
case 'B': linkage_flag = 99;
|
||||
|
@ -942,7 +930,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t len
|
|||
break;
|
||||
case 3:
|
||||
/* CC-C 2D component */
|
||||
switch (set[strlen(reduced) - 1]) {
|
||||
switch (set[ustrlen(source) - 1]) {
|
||||
case 'A': linkage_flag = 99;
|
||||
break;
|
||||
case 'B': linkage_flag = 101;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue