CODE128: use int for glyph_count

This commit is contained in:
gitlost 2022-10-14 15:05:33 +01:00
parent 2c95718d4f
commit fbfaabf004

View File

@ -382,7 +382,7 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len
int error_number = 0, indexchaine, indexliste, f_state = 0; int error_number = 0, indexchaine, indexliste, f_state = 0;
int list[2][C128_MAX] = {{0}}; int list[2][C128_MAX] = {{0}};
char set[C128_MAX] = {0}, fset[C128_MAX], mode, last_set, current_set = ' '; char set[C128_MAX] = {0}, fset[C128_MAX], mode, last_set, current_set = ' ';
float glyph_count; int glyph_count = 0; /* Codeword estimate times 2 */
char dest[1000]; char dest[1000];
char *d = dest; char *d = dest;
@ -503,40 +503,39 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len
/* Now we can calculate how long the barcode is going to be - and stop it from /* Now we can calculate how long the barcode is going to be - and stop it from
being too long */ being too long */
last_set = set[0]; last_set = set[0];
glyph_count = 0.0f;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if ((set[i] == 'a') || (set[i] == 'b')) { if ((set[i] == 'a') || (set[i] == 'b')) {
glyph_count = glyph_count + 1.0f; glyph_count += 2; /* 1 codeword */
} }
if ((fset[i] == 'f') || (fset[i] == 'n')) { if ((fset[i] == 'f') || (fset[i] == 'n')) {
glyph_count = glyph_count + 1.0f; /* May be overestimate if in latch */ glyph_count += 2; /* May be overestimate if in latch */
} }
if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) { if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) {
if (set[i] != last_set) { if (set[i] != last_set) {
last_set = set[i]; last_set = set[i];
glyph_count = glyph_count + 1.0f; glyph_count += 2;
} }
} }
if (i == 0) { if (i == 0) {
if (fset[i] == 'F') { if (fset[i] == 'F') {
glyph_count = glyph_count + 2.0f; glyph_count += 4; /* 2 codewords */
} }
} else { } else {
if ((fset[i] == 'F') && (fset[i - 1] != 'F')) { if ((fset[i] == 'F') && (fset[i - 1] != 'F')) {
glyph_count = glyph_count + 2.0f; glyph_count += 4;
} }
if ((fset[i] != 'F') && (fset[i - 1] == 'F')) { if ((fset[i] != 'F') && (fset[i - 1] == 'F')) {
glyph_count = glyph_count + 2.0f; glyph_count += 4;
} }
} }
if (set[i] == 'C') { if (set[i] == 'C') {
glyph_count = glyph_count + 0.5f; glyph_count += 1; /* Half a codeword */
} else { } else {
glyph_count = glyph_count + 1.0f; glyph_count += 2;
} }
} }
if (glyph_count > 60.0f) { if (glyph_count > 120) { /* 60 * 2 */
strcpy(symbol->errtxt, "341: Input too long (60 symbol character maximum)"); strcpy(symbol->errtxt, "341: Input too long (60 symbol character maximum)");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
@ -732,7 +731,7 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int
int error_number, warn_number = 0, indexchaine, indexliste; int error_number, warn_number = 0, indexchaine, indexliste;
int list[2][C128_MAX] = {{0}}; int list[2][C128_MAX] = {{0}};
char set[C128_MAX] = {0}, mode, last_set; char set[C128_MAX] = {0}, mode, last_set;
float glyph_count; int glyph_count = 0; /* Codeword estimate times 2 */
char dest[1000]; char dest[1000];
char *d = dest; char *d = dest;
int separator_row = 0, linkage_flag = 0; int separator_row = 0, linkage_flag = 0;
@ -795,24 +794,23 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int
/* Now we can calculate how long the barcode is going to be - and stop it from /* Now we can calculate how long the barcode is going to be - and stop it from
being too long */ being too long */
last_set = set[0]; last_set = set[0];
glyph_count = 0.0f;
for (i = 0; i < reduced_length; i++) { for (i = 0; i < reduced_length; i++) {
if ((set[i] == 'A') || (set[i] == 'B') || (set[i] == 'C')) { if ((set[i] == 'A') || (set[i] == 'B') || (set[i] == 'C')) {
if (set[i] != last_set) { if (set[i] != last_set) {
last_set = set[i]; last_set = set[i];
glyph_count = glyph_count + 1.0f; glyph_count += 2; /* 1 codeword */
} }
} else if ((set[i] == 'a') || (set[i] == 'b')) { } else if ((set[i] == 'a') || (set[i] == 'b')) {
glyph_count = glyph_count + 1.0f; /* Not reached */ glyph_count += 2; /* Not reached */
} }
if ((set[i] == 'C') && (reduced[i] != '[')) { if ((set[i] == 'C') && (reduced[i] != '[')) {
glyph_count = glyph_count + 0.5f; glyph_count += 1; /* Half a codeword */
} else { } else {
glyph_count = glyph_count + 1.0f; glyph_count += 2;
} }
} }
if (glyph_count > 60.0f) { if (glyph_count > 120) { /* 60 * 2 */
strcpy(symbol->errtxt, "344: Input too long (60 symbol character maximum)"); strcpy(symbol->errtxt, "344: Input too long (60 symbol character maximum)");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }