Enforce DataBar height restrictions

This commit is contained in:
Robin Stuart 2016-10-14 18:56:49 +01:00
parent d6a1008ae7
commit dd80371b17
3 changed files with 35 additions and 0 deletions

View File

@ -272,3 +272,25 @@ int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int va
return error_number; return error_number;
} }
void set_minimum_height(struct zint_symbol *symbol, int min_height) {
/* Enforce minimum permissable height of rows */
int fixed_height = 0;
int zero_count = 0;
int i;
for (i = 0; i < symbol->rows; i++) {
fixed_height += symbol->row_height[i];
if (symbol->row_height[i] == 0) {
zero_count++;
}
}
if (((symbol->height - fixed_height) / zero_count) < min_height) {
for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i] == 0) {
symbol->row_height[i] = min_height;
}
}
}
}

View File

@ -72,6 +72,7 @@ extern "C" {
extern double froundup(const double input); extern double froundup(const double input);
extern int parunmodd(const unsigned char llyth); extern int parunmodd(const unsigned char llyth);
extern int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length); extern int utf8toutf16(struct zint_symbol *symbol, const unsigned char source[], int vals[], int *length);
extern void set_minimum_height(struct zint_symbol *symbol, int min_height);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -514,6 +514,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len) {
hrt[13] = itoc(check_digit); hrt[13] = itoc(check_digit);
strcat((char*) symbol->text, hrt); strcat((char*) symbol->text, hrt);
set_minimum_height(symbol, 14); // Minimum height is 14X for truncated symbol
} }
if ((symbol->symbology == BARCODE_RSS14STACK) || (symbol->symbology == BARCODE_RSS14STACK_CC)) { if ((symbol->symbology == BARCODE_RSS14STACK) || (symbol->symbology == BARCODE_RSS14STACK_CC)) {
@ -716,6 +718,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len) {
} }
} }
symbol->rows = symbol->rows + 1; symbol->rows = symbol->rows + 1;
set_minimum_height(symbol, 33);
} }
@ -1043,6 +1047,8 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len)
strcat((char*) symbol->text, hrt); strcat((char*) symbol->text, hrt);
set_minimum_height(symbol, 10);
return error_number; return error_number;
} }
@ -2502,5 +2508,11 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len)
} }
for (i = 0; i < symbol->rows; i++) {
if (symbol->row_height[i] == 0) {
symbol->row_height[i] = 34;
}
}
return 0; return 0;
} }