Add compliant height, using ZINT_COMPLIANT_HEIGHT flag for back-compatibility

Rename barcode funcs to same as BARCODE_XXX name
library: barcode funcs array for dispatch, used for ZBarcode_ValidID() also
general: change is_sane() comparison to nonzero from ZINT_ERROR_INVALID_OPTION
MAILMARK: fuller error messages
CODABAR: add option to show check character in HRT
zint.h: use 0xNNNN for OR-able defines
GUI: add guard descent height reset button, add Zint version to window title,
  static get_zint_version() method, use QStringLiteral (QSL shorthand),
  use SIGNAL(toggled()), add errtxt "popup" and status bar, add icons,
  add saveAs shortcut, add main menu, context menus and actions, add help,
  reset_view() -> reset_colours(), add copy to clipboard as EMF/GIF/PNG/TIF,
  lessen triggering of update_preview(), shorten names of getters/setters,
  simplify/shorten some update_preview() logic in switch,
  CODEONE disable structapp for Version S
qzint.cpp: add on_errored signal, add missing getters, add test
This commit is contained in:
gitlost 2021-10-09 00:13:39 +01:00
parent 206ae26d20
commit 72eac41c34
82 changed files with 5570 additions and 3774 deletions

View file

@ -64,7 +64,7 @@ static char check_digit(const unsigned int count) {
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
const char *table[10], const char *start_stop[2], const int error_base) {
int i, error_number;
int i;
char dest[512]; /* Largest destination 6 + (80 + 1) * 6 + 5 + 1 = 498 */
unsigned char temp[80 + 1 + 1]; /* Largest maximum 80 */
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
@ -74,11 +74,10 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[],
sprintf(symbol->errtxt, "%d: Input too long (%d character maximum)", error_base, max);
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
/* errtxt 302: 304: 306: 308: */
sprintf(symbol->errtxt, "%d: Invalid character in data (digits only)", error_base + 1);
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
ustrcpy(temp, source);
@ -107,46 +106,44 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[],
symbol->text[length - 1] = '\0';
}
return error_number;
return 0;
}
/* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int c25standard(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25MatrixStartStop, 301);
}
/* Code 2 of 5 Industrial */
INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int c25ind(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 45, C25IndustTable, C25IndustStartStop, 303);
}
/* Code 2 of 5 IATA */
INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int c25iata(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 45, C25IndustTable, C25IataLogicStartStop, 305);
}
/* Code 2 of 5 Data Logic */
INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25_common(symbol, source, length, 80, C25MatrixTable, C25IataLogicStartStop, 307);
}
/* Common to Interleaved, ITF-14, DP Leitcode, DP Identcode */
static int c25inter_common(struct zint_symbol *symbol, unsigned char source[], int length,
const int dont_set_height) {
int i, j, error_number;
int i, j, error_number = 0;
char bars[7], spaces[7], mixed[14], dest[512]; /* 4 + (90 + 2) * 5 + 3 + 1 = 468 */
unsigned char temp[90 + 2 + 1];
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
float height;
if (length > 90) {
strcpy(symbol->errtxt, "309: Input too long (90 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "310: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
temp[0] = '\0';
@ -199,26 +196,29 @@ static int c25inter_common(struct zint_symbol *symbol, unsigned char source[], i
}
if (!dont_set_height) {
#ifdef COMPLIANT_HEIGHTS
/* ISO/IEC 16390:2007 Section 4.4 min height 5mm or 15% of symbol width whichever greater where
(P = character pairs, N = wide/narrow ratio = 3) width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */
height = (float) ((18.0 * (length / 2) + 9.0) * 0.15);
if (height < (float) (5.0 / 0.33)) { /* Taking X = 0.330mm from Annex D.3.1 (application specification) */
height = (float) (5.0 / 0.33);
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* ISO/IEC 16390:2007 Section 4.4 min height 5mm or 15% of symbol width whichever greater where
(P = character pairs, N = wide/narrow ratio = 3)
width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */
/* Taking X = 0.330mm from Annex D.3.1 (application specification) */
const float min_height_min = stripf(5.0f / 0.33f);
float min_height = stripf((18.0f * (length / 2) + 9.0f) * 0.15f);
if (min_height < min_height_min) {
min_height = min_height_min;
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
}
return error_number;
}
/* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */
INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length) {
return c25inter_common(symbol, source, length, 0 /*dont_set_height*/);
}
@ -232,10 +232,9 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "312: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Add leading zeros as required */
@ -261,14 +260,14 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
}
if (error_number < ZINT_ERROR) {
#ifdef COMPLIANT_HEIGHTS
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**): (note bind/box additional to
symbol->height), same as GS1-128: "in case of further space constraints"
height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */
warn_number = set_height(symbol, (float) (5.8 / 1.016), (float) (31.75 / 0.495), 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**): (note bind/box additional
to symbol->height), same as GS1-128: "in case of further space constraints"
height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */
warn_number = set_height(symbol, stripf(5.8f / 1.016f), stripf(31.75f / 0.495f), 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
return error_number ? error_number : warn_number;
@ -286,10 +285,9 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
strcpy(symbol->errtxt, "313: Input wrong length (13 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "314: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
zeroes = 13 - length;
@ -325,10 +323,9 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len
strcpy(symbol->errtxt, "315: Input wrong length (11 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "316: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
zeroes = 11 - length;

View file

@ -88,7 +88,7 @@ static void rs_error(char data_pattern[]) {
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
/* Handles Australia Posts's 4 State Codes */
INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically
(i.e. the FCC doesn't need to be specified by the user) dependent
on the length of the input string */
@ -108,10 +108,9 @@ INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[],
char localstr[30];
/* Check input immediately to catch nuls */
error_number = is_sane(GDSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(GDSET, source, length) != 0) {
strcpy(symbol->errtxt, "404: Invalid character in data (alphanumerics, space and \"#\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
strcpy(localstr, "");
@ -127,23 +126,25 @@ INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[],
break;
case 16:
strcpy(fcc, "59");
error_number = is_sane(NEON, source, length);
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "402: Invalid character in data (digits only for length 16)");
return ZINT_ERROR_INVALID_DATA;
}
break;
case 18:
strcpy(fcc, "62");
break;
case 23:
strcpy(fcc, "62");
error_number = is_sane(NEON, source, length);
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "406: Invalid character in data (digits only for length 23)");
return ZINT_ERROR_INVALID_DATA;
}
break;
default:
strcpy(symbol->errtxt, "401: Auspost input is wrong length (8, 13, 16, 18 or 23 characters only)");
return ZINT_ERROR_TOO_LONG;
}
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "402: Invalid character in data (digits only for lengths 16 and 23)");
return error_number;
}
} else {
int zeroes;
if (length > 8) {
@ -174,10 +175,9 @@ INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[],
/* Verify that the first 8 characters are numbers */
memcpy(dpid, localstr, 8);
dpid[8] = '\0';
error_number = is_sane(NEON, (unsigned char *) dpid, 8);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, (unsigned char *) dpid, 8) != 0) {
strcpy(symbol->errtxt, "405: Invalid character in DPID (first 8 characters) (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Start character */
@ -238,21 +238,23 @@ INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[],
writer += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* Australia Post Customer Barcoding Technical Specifications (Revised Aug 2012) Dimensions, placement and
printing p.12
https://auspost.com.au/content/dam/auspost_corp/media/documents/customer-barcode-technical-specifications-aug2012.pdf
X 0.5mm (average of 0.4mm - 0.6mm), min height 4.2mm / 0.6mm (X max) = 7, max 5.6mm / 0.4mm (X min) = 14
Tracker 1.3mm (average of 1mm - 1.6mm), Ascender/Descender 3.15mm (average of 2.6mm - 3.7mm) less T = 1.85mm
*/
symbol->row_height[0] = 1.85f / 0.5f; /* 3.7 */
symbol->row_height[1] = 1.3f / 0.5f; /* 2.6 */
error_number = daft_set_height(symbol, 7.0f, 14.0f); /* Note using max X for minimum and min X for maximum */
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Australia Post Customer Barcoding Technical Specifications (Revised Aug 2012) Dimensions, placement and
printing p.12
(https://auspost.com.au/content/dam/auspost_corp/media/documents/
customer-barcode-technical-specifications-aug2012.pdf)
X 0.5mm (average of 0.4mm - 0.6mm), min height 4.2mm / 0.6mm (X max) = 7, max 5.6mm / 0.4mm (X min) = 14
Tracker 1.3mm (average of 1mm - 1.6mm)
Ascender/Descender 3.15mm (average of 2.6mm - 3.7mm) less T = 1.85mm
*/
symbol->row_height[0] = 3.7f; /* 1.85f / 0.5f */
symbol->row_height[1] = 2.6f; /* 1.3f / 0.5f */
error_number = daft_set_height(symbol, 7.0f, 14.0f); /* Note using max X for minimum and min X for maximum */
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->width = writer - 1;

View file

@ -1445,7 +1445,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], int lengt
}
/* Encodes Aztec runes as specified in ISO/IEC 24778:2008 Annex A */
INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned int input_value;
int error_number, i, y, x, r;
char binary_string[28];

View file

@ -39,7 +39,7 @@
#include <assert.h>
#include "common.h"
INTERNAL int code_128(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length);
#define uchar unsigned char
@ -601,7 +601,7 @@ static void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
/* Main function called by zint framework
*/
INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int length) {
int charCur, dataLength;
int error_number;
int rows, columns, useColumns;
@ -613,7 +613,6 @@ INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int l
int emptyColumns;
char dest[1000];
int r, c;
float min_row_height = 0.0f;
#ifdef _MSC_VER
CharacterSetTable *T;
unsigned char *data;
@ -627,20 +626,20 @@ INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int l
/* option1: rows <= 0: automatic, 1..44 */
rows = symbol->option_1;
if (rows == 1) {
error_number = code_128(symbol, source, length); /* Only returns errors, not warnings */
error_number = code128(symbol, source, length); /* Only returns errors, not warnings */
if (error_number < ZINT_ERROR) {
symbol->output_options |= BARCODE_BIND;
if (symbol->border_width == 0) { /* Allow override if non-zero */
symbol->border_width = 1; /* AIM ISS-X-24 Section 4.6.1 b) (note change from previous default 2) */
}
symbol->text[0] = '\0'; /* Disable HRT for compatibility with CODABLOCKF */
#ifdef COMPLIANT_HEIGHTS
/* AIM ISS-X-24 Section 4.5.1 minimum row height 8 (for compatibility with CODABLOCKF, not specced for
CODE128) */
error_number = set_height(symbol, 8.0f, 10.0f, 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 5.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* AIM ISS-X-24 Section 4.5.1 minimum row height 8 (for compatibility with CODABLOCKF, not specced for
CODE128) */
error_number = set_height(symbol, 8.0f, 10.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 5.0f, 0.0f, 1 /*no_errtxt*/);
}
}
return error_number;
}
@ -961,17 +960,17 @@ INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int l
expand(symbol, dest);
}
#ifdef COMPLIANT_HEIGHTS
/* AIM ISS-X-24 Section 4.6.1 minimum row height; use 10 * rows as default for back-compatibility */
min_row_height = (float) (0.55 * useColumns + 3.0);
if (min_row_height < 8.0f) {
min_row_height = 8.0f;
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* AIM ISS-X-24 Section 4.6.1 minimum row height; use 10 * rows as default */
float min_row_height = stripf(0.55f * useColumns + 3.0f);
if (min_row_height < 8.0f) {
min_row_height = 8.0f;
}
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows,
0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
}
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
symbol->output_options |= BARCODE_BIND;

View file

@ -1,7 +1,8 @@
/* code.c - Handles Code 11, 39, 39+, 93, PZN, Channel and VIN */
/* LOGMARS MIL-STD-1189 Rev. B https://apps.dtic.mil/dtic/tr/fulltext/u2/a473534.pdf */
/* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf */
/* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA-Info_Check_Digit_Calculations_PZN_PPN_UDI_EN.pdf */
/* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/
IFA-Info_Check_Digit_Calculations_PZN_PPN_UDI_EN.pdf */
/*
libzint - the open source barcode library
@ -98,11 +99,11 @@ static const char *C93Table[47] = {
};
/* *********************** CODE 11 ******************** */
INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
int i;
int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
int weight[122], error_number;
int weight[122], error_number = 0;
char dest[750]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 == 750 */
char checkstr[3];
int num_check_digits;
@ -114,10 +115,9 @@ INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int len
strcpy(symbol->errtxt, "320: Input too long (121 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SODIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SODIUM, source, length) != 0) {
strcpy(symbol->errtxt, "321: Invalid character in data (digits and \"-\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if (symbol->option_2 < 0 || symbol->option_2 > 2) {
@ -215,13 +215,12 @@ INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int len
}
/* Code 39 */
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length) {
int i;
int counter;
int error_number;
int error_number = 0;
char dest[880]; /* 10 (Start) + 85 * 10 + 10 (Check) + 9 (Stop) + 1 = 880 */
char localstr[2] = {0};
float height;
counter = 0;
@ -242,10 +241,9 @@ INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length)
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(SILVER, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SILVER, source, length) != 0) {
strcpy(symbol->errtxt, "324: Invalid character in data (alphanumerics, space and \"-.$/+%\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Start character */
@ -291,26 +289,27 @@ INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length)
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
if (symbol->symbology == BARCODE_LOGMARS) {
/* MIL-STD-1189 Rev. B Section 5.2
Min height 0.25" / 0.04" (X max) = 6.25
Default height 0.625" (average of 0.375" - 0.875") / 0.01375" (average of 0.0075" - 0.02") ~ 45.45 */
height = (float) (0.625 / 0.01375);
error_number = set_height(symbol, 6.25f, height, (float) (0.875 / 0.0075), 0 /*no_errtxt*/);
} else if (symbol->symbology == BARCODE_CODE39 || symbol->symbology == BARCODE_EXCODE39
|| symbol->symbology == BARCODE_HIBC_39) {
/* ISO/IEC 16388:2007 4.4 (e) recommended min height 5.0mm or 15% of width excluding quiet zones;
as X left to application specification use
width = (C + 2) * (3 * N + 6) * X + (C + 1) * I = (C + 2) * 9 + C + 1) * X = (10 * C + 19) */
height = (float) ((10.0 * (symbol->option_2 == 1 ? length + 1 : length) + 19.0) * 0.15);
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
if (symbol->output_options & COMPLIANT_HEIGHT) {
if (symbol->symbology == BARCODE_LOGMARS) {
/* MIL-STD-1189 Rev. B Section 5.2
Min height 0.25" / 0.04" (X max) = 6.25
Default height 0.625" (average of 0.375" - 0.875") / 0.01375" (average of 0.0075" - 0.02") ~ 45.45 */
error_number = set_height(symbol, 6.25f, stripf(0.625f / 0.01375f), stripf(0.875f / 0.0075f),
0 /*no_errtxt*/);
} else if (symbol->symbology == BARCODE_CODE39 || symbol->symbology == BARCODE_EXCODE39
|| symbol->symbology == BARCODE_HIBC_39) {
/* ISO/IEC 16388:2007 4.4 (e) recommended min height 5.0mm or 15% of width excluding quiet zones;
as X left to application specification use
width = (C + 2) * (3 * N + 6) * X + (C + 1) * I = (C + 2) * 9 + C + 1) * X = (10 * C + 19);
use 50 as default as none recommended */
const float min_height = stripf((10.0f * (symbol->option_2 == 1 ? length + 1 : length) + 19.0f) * 0.15f);
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
0 /*no_errtxt*/);
}
// PZN and CODE32 set their own heights
} else {
(void) set_height(symbol, 0.0f, 50.f, 0.0f, 1 /*no_errtxt*/);
}
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->symbology == BARCODE_CODE39) {
ustrcpy(symbol->text, "*");
@ -325,7 +324,7 @@ INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length)
}
/* Pharmazentral Nummer (PZN) */
INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes;
unsigned int count, check_digit;
@ -335,10 +334,9 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i
strcpy(symbol->errtxt, "325: Input wrong length (7 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "326: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
localstr[0] = '-';
@ -364,29 +362,29 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i
}
localstr[8] = itoc(check_digit);
localstr[9] = '\0';
error_number = c39(symbol, (unsigned char *) localstr, 9);
error_number = code39(symbol, (unsigned char *) localstr, 9);
ustrcpy(symbol->text, "PZN ");
ustrcat(symbol->text, localstr);
#ifdef COMPLIANT_HEIGHTS
/* Technical Information regarding PZN Coding V 2.1 (25 Feb 2019) Code size
https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf
"normal" X 0.25mm (0.187mm - 0.45mm), height 8mm - 20mm for 0.25mm X, 10mm mentioned so use that as default,
10mm / 0.25mm = 40 */
if (error_number < ZINT_ERROR) {
error_number = set_height(symbol, (float) (8.0 / 0.45), 40.0f, (float) (20.0 / 0.187), 0 /*no_errtxt*/);
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Technical Information regarding PZN Coding V 2.1 (25 Feb 2019) Code size
https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf
"normal" X 0.25mm (0.187mm - 0.45mm), height 8mm - 20mm for 0.25mm X, 10mm mentioned so use that
as default, 10mm / 0.25mm = 40 */
if (error_number < ZINT_ERROR) {
error_number = set_height(symbol, stripf(8.0f / 0.45f), 40.0f, stripf(20.0f / 0.187f), 0 /*no_errtxt*/);
}
} else {
if (error_number < ZINT_ERROR) {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
#else
if (error_number < ZINT_ERROR) {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
/* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned char buffer[85 * 2 + 1] = {0};
int i;
@ -408,21 +406,21 @@ INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length
}
/* Then sends the buffer to the C39 function */
error_number = c39(symbol, buffer, (int) ustrlen(buffer));
error_number = code39(symbol, buffer, (int) ustrlen(buffer));
for (i = 0; i < length; i++)
symbol->text[i] = source[i] >= ' ' && source[i] != 0x7F ? source[i] : ' ';
symbol->text[length] = '\0';
symbol->text[length] = '\0'; /* Chops off check digit */
return error_number;
}
/* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int length) {
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
shift characters 1, 2, 3 and 4 respectively. These characters are never used by
c39() and ec39() */
`code39()` and `excode39()` */
int i;
int h, weight, c, k, error_number = 0;
@ -430,7 +428,6 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length)
char buffer[216]; /* 107*2 (107 full ASCII) + 1 = 215 */
char dest[668]; /* 6 (Start) + 107*6 + 2*6 (Checks) + 7 (Stop) + 1 (NUL) = 668 */
char set_copy[] = SILVER;
float height;
/* Suppresses clang-tidy clang-analyzer-core.CallAndMessage warning */
assert(length > 0);
@ -503,19 +500,15 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length)
strcat(dest, "1111411");
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* ANSI/AIM BC5-1995 Section 2.6 minimum height 0.2" or 15% of symbol length, whichever is greater
0.2" / 0.0075" (min X) = ~26.66; symbol length = (9 * (C + 4) + 1) * X + 2 * Q = symbol->width + 20 */
height = (float) ((symbol->width + 20) * 0.15);
if (height < 0.2f / 0.0075f) {
height = 0.2f / 0.0075f;
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* ANSI/AIM BC5-1995 Section 2.6 minimum height 0.2" or 15% of symbol length, whichever is greater
no max X given so for min height use symbol length = (9 * (C + 4) + 1) * X + 2 * Q = symbol->width + 20;
use 40 as default height based on figures in spec */
float min_height = stripf((symbol->width + 20) * 0.15f);
error_number = set_height(symbol, min_height, min_height > 40.0f ? min_height : 40.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
/* Using 50 as default for back-compatibility */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->option_2 == 1) {
symbol->text[length] = set_copy[c];
@ -578,12 +571,18 @@ static void CHNCHR(int channels, long target_value, int B[8], int S[8]) {
/* Use of initial pre-calculations taken from Barcode Writer in Pure PostScript (BWIPP)
* Copyright (c) 2004-2020 Terry Burton (MIT/X-Consortium license) */
static channel_precalc initial_precalcs[6] = {
{ 0, { 1, 1, 1, 1, 1, 2, 1, 2, }, { 1, 1, 1, 1, 1, 1, 1, 3, }, { 1, 1, 1, 1, 1, 3, 2, }, { 1, 1, 1, 1, 1, 3, 3, }, },
{ 0, { 1, 1, 1, 1, 2, 1, 1, 3, }, { 1, 1, 1, 1, 1, 1, 1, 4, }, { 1, 1, 1, 1, 4, 3, 3, }, { 1, 1, 1, 1, 4, 4, 4, }, },
{ 0, { 1, 1, 1, 2, 1, 1, 2, 3, }, { 1, 1, 1, 1, 1, 1, 1, 5, }, { 1, 1, 1, 5, 4, 4, 4, }, { 1, 1, 1, 5, 5, 5, 5, }, },
{ 0, { 1, 1, 2, 1, 1, 2, 1, 4, }, { 1, 1, 1, 1, 1, 1, 1, 6, }, { 1, 1, 6, 5, 5, 5, 4, }, { 1, 1, 6, 6, 6, 6, 6, }, },
{ 0, { 1, 2, 1, 1, 2, 1, 1, 5, }, { 1, 1, 1, 1, 1, 1, 1, 7, }, { 1, 7, 6, 6, 6, 5, 5, }, { 1, 7, 7, 7, 7, 7, 7, }, },
{ 0, { 2, 1, 1, 2, 1, 1, 2, 5, }, { 1, 1, 1, 1, 1, 1, 1, 8, }, { 8, 7, 7, 7, 6, 6, 6, }, { 8, 8, 8, 8, 8, 8, 8, }, },
{ 0, { 1, 1, 1, 1, 1, 2, 1, 2, }, { 1, 1, 1, 1, 1, 1, 1, 3, }, { 1, 1, 1, 1, 1, 3, 2, },
{ 1, 1, 1, 1, 1, 3, 3, }, },
{ 0, { 1, 1, 1, 1, 2, 1, 1, 3, }, { 1, 1, 1, 1, 1, 1, 1, 4, }, { 1, 1, 1, 1, 4, 3, 3, },
{ 1, 1, 1, 1, 4, 4, 4, }, },
{ 0, { 1, 1, 1, 2, 1, 1, 2, 3, }, { 1, 1, 1, 1, 1, 1, 1, 5, }, { 1, 1, 1, 5, 4, 4, 4, },
{ 1, 1, 1, 5, 5, 5, 5, }, },
{ 0, { 1, 1, 2, 1, 1, 2, 1, 4, }, { 1, 1, 1, 1, 1, 1, 1, 6, }, { 1, 1, 6, 5, 5, 5, 4, },
{ 1, 1, 6, 6, 6, 6, 6, }, },
{ 0, { 1, 2, 1, 1, 2, 1, 1, 5, }, { 1, 1, 1, 1, 1, 1, 1, 7, }, { 1, 7, 6, 6, 6, 5, 5, },
{ 1, 7, 7, 7, 7, 7, 7, }, },
{ 0, { 2, 1, 1, 2, 1, 1, 2, 5, }, { 1, 1, 1, 1, 1, 1, 1, 8, }, { 8, 7, 7, 7, 6, 6, 6, },
{ 8, 8, 8, 8, 8, 8, 8, }, },
};
int bmax[7], smax[7];
long value = 0;
@ -655,24 +654,22 @@ nb0: if (++B[0] <= bmax[0]) goto lb0;
}
/* Channel Code - According to ANSI/AIM BC12-1998 */
INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int length) {
static int max_ranges[] = { -1, -1, -1, 26, 292, 3493, 44072, 576688, 7742862 };
int S[8] = {0}, B[8] = {0};
long target_value = 0;
char pattern[30];
int channels, i;
int error_number, zeroes;
int error_number = 0, zeroes;
char hrt[9];
float height;
if (length > 7) {
strcpy(symbol->errtxt, "333: Input too long (7 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "334: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
@ -735,17 +732,15 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in
expand(symbol, pattern);
#ifdef COMPLIANT_HEIGHTS
/* ANSI/AIM BC12-1998 gives min height as 5mm or 15% of length but X left as application specification so use
15% of length where
length = (3 (quiet zones) + 9 (finder) + 4 * channels - 2) * X */
height = (float) ((10 + 4 * channels) * 0.15);
/* Using 50 as default for back-compatibility */
error_number = set_height(symbol, height > 50.0f ? height : 50.0f, height, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* ANSI/AIM BC12-1998 gives min height as 5mm or 15% of length; X left as application specification so use
length = 1X (left qz) + (9 (finder) + 4 * 8 - 2) * X + 2X (right qz);
use 20 as default based on figures in spec */
const float min_height = stripf((1 + 9 + 4 * channels - 2 + 2) * 0.15f);
error_number = set_height(symbol, min_height, 20.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
return error_number;
}
@ -771,7 +766,7 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
}
// Check input characters, I, O and Q are not allowed
if (is_sane(ARSENIC, source, length) == ZINT_ERROR_INVALID_DATA) {
if (is_sane(ARSENIC, source, length) != 0) {
sprintf(symbol->errtxt, "337: Invalid character in data (\"%s\" only)", ARSENIC);
return ZINT_ERROR_INVALID_DATA;
}

View file

@ -957,7 +957,7 @@ static void block_copy(struct zint_symbol *symbol, char datagrid[136][120], cons
}
}
INTERNAL int code_one(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int codeone(struct zint_symbol *symbol, unsigned char source[], int length) {
int size = 1, i, j;
char datagrid[136][120];
@ -972,6 +972,10 @@ INTERNAL int code_one(struct zint_symbol *symbol, unsigned char source[], int le
}
if (symbol->structapp.count) {
if (symbol->option_2 == 9) { /* Version S */
strcpy(symbol->errtxt, "714: Structured Append not available for Version S");
return ZINT_ERROR_INVALID_OPTION;
}
if ((symbol->input_mode & 0x07) == GS1_MODE) {
strcpy(symbol->errtxt, "710: Cannot have Structured Append and GS1 mode at the same time");
return ZINT_ERROR_INVALID_OPTION;
@ -997,15 +1001,11 @@ INTERNAL int code_one(struct zint_symbol *symbol, unsigned char source[], int le
unsigned int data[30], ecc[15];
int block_width;
if (symbol->structapp.count) { /* Version S */
strcpy(symbol->errtxt, "714: Structured Append not supported for Version S");
return ZINT_ERROR_INVALID_OPTION;
}
if (length > 18) {
strcpy(symbol->errtxt, "514: Input data too long for Version S");
return ZINT_ERROR_TOO_LONG;
}
if (is_sane(NEON, source, length) == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "515: Invalid input data (Version S encodes numeric input only)");
return ZINT_ERROR_INVALID_DATA;
}

View file

@ -300,7 +300,7 @@ STATIC_UNLESS_ZINT_TEST int hrt_cpy_iso8859_1(struct zint_symbol *symbol, const
}
/* Handle Code 128, 128B and HIBC 128 */
INTERNAL int code_128(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, k, values[C128_MAX] = {0}, bar_characters, read, total_sum;
int error_number, indexchaine, indexliste, f_state;
int sourcelen;
@ -705,7 +705,7 @@ INTERNAL int code_128(struct zint_symbol *symbol, unsigned char source[], int le
}
/* Handle EAN-128 (Now known as GS1-128), and composite version if `cc_mode` set */
INTERNAL int ean_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode,
INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode,
const int cc_rows) {
int i, j, values[C128_MAX] = {0}, bar_characters, read, total_sum;
int error_number, warn_number = 0, indexchaine, indexliste;
@ -1014,23 +1014,26 @@ INTERNAL int ean_128_cc(struct zint_symbol *symbol, unsigned char source[], int
}
}
#ifdef COMPLIANT_HEIGHTS
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**):
same as ITF-14: "in case of further space constraints" height 5.8mm / 1.016mm (X max) ~ 5.7;
default 31.75mm / 0.495mm ~ 64.14 */
if (symbol->symbology == BARCODE_GS1_128_CC) {
/* Pass back via temporary linear structure */
symbol->height = symbol->height ? (float) (5.8 / 1.016) : (float) (31.75 / 0.495);
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**):
same as ITF-14: "in case of further space constraints" height 5.8mm / 1.016mm (X max) ~ 5.7;
default 31.75mm / 0.495mm ~ 64.14 */
const float min_height = stripf(5.8f / 1.016f);
const float default_height = stripf(31.75f / 0.495f);
if (symbol->symbology == BARCODE_GS1_128_CC) {
/* Pass back via temporary linear structure */
symbol->height = symbol->height ? min_height : default_height;
} else {
warn_number = set_height(symbol, min_height, default_height, 0.0f, 0 /*no_errtxt*/);
}
} else {
warn_number = set_height(symbol, (float) (5.8 / 1.016), (float) (31.75 / 0.495), 0.0f, 0 /*no_errtxt*/);
const float height = 50.0f;
if (symbol->symbology == BARCODE_GS1_128_CC) {
symbol->height = height - cc_rows * (cc_mode == 3 ? 3 : 2) - 1.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
}
#else
if (symbol->symbology == BARCODE_GS1_128_CC) {
symbol->height = 50.0f - cc_rows * (cc_mode == 3 ? 3 : 2) - 1.0f;
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
#endif
for (i = 0; i < length; i++) {
if (source[i] == '[') {
@ -1046,12 +1049,12 @@ INTERNAL int ean_128_cc(struct zint_symbol *symbol, unsigned char source[], int
}
/* Handle EAN-128 (Now known as GS1-128) */
INTERNAL int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
return ean_128_cc(symbol, source, length, 0 /*cc_mode*/, 0 /*cc_rows*/);
INTERNAL int gs1_128(struct zint_symbol *symbol, unsigned char source[], int length) {
return gs1_128_cc(symbol, source, length, 0 /*cc_mode*/, 0 /*cc_rows*/);
}
/* Add check digit if encoding an NVE18 symbol */
INTERNAL int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int nve18(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, count, check_digit;
int error_number, zeroes;
unsigned char ean128_equiv[23];
@ -1061,10 +1064,9 @@ INTERNAL int nve_18(struct zint_symbol *symbol, unsigned char source[], int leng
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "346: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
zeroes = 17 - length;
@ -1083,13 +1085,13 @@ INTERNAL int nve_18(struct zint_symbol *symbol, unsigned char source[], int leng
ean128_equiv[21] = itoc(check_digit);
ean128_equiv[22] = '\0';
error_number = ean_128(symbol, ean128_equiv, 22);
error_number = gs1_128(symbol, ean128_equiv, 22);
return error_number;
}
/* EAN-14 - A version of EAN-128 */
INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int ean14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, count, check_digit;
int error_number, zeroes;
unsigned char ean128_equiv[19];
@ -1099,10 +1101,9 @@ INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int leng
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "348: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
zeroes = 13 - length;
@ -1121,7 +1122,7 @@ INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int leng
ean128_equiv[17] = itoc(check_digit);
ean128_equiv[18] = '\0';
error_number = ean_128(symbol, ean128_equiv, 18);
error_number = gs1_128(symbol, ean128_equiv, 18);
return error_number;
}
@ -1129,7 +1130,7 @@ INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int leng
/* DPD (Deutsher Paket Dienst) Code */
/* Specification at ftp://dpd.at/Datenspezifikationen/EN/gbs_V4.0.2_hauptdokument.pdf
* or https://docplayer.net/33728877-Dpd-parcel-label-specification.html */
INTERNAL int dpd_parcel(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number = 0;
int i, p;
unsigned char identifier;
@ -1144,10 +1145,9 @@ INTERNAL int dpd_parcel(struct zint_symbol *symbol, unsigned char source[], int
identifier = source[0];
to_upper(source + 1);
error_number = is_sane(KRSET, source + 1, length - 1);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(KRSET, source + 1, length - 1) != 0) {
strcpy(symbol->errtxt, "300: Invalid character in DPD data (alphanumerics only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if ((identifier < 32) || (identifier > 127)) {
@ -1155,16 +1155,16 @@ INTERNAL int dpd_parcel(struct zint_symbol *symbol, unsigned char source[], int
return ZINT_ERROR_INVALID_DATA;
}
error_number = code_128(symbol, source, length); /* Only returns errors, not warnings */
error_number = code128(symbol, source, length); /* Only returns errors, not warnings */
if (error_number < ZINT_ERROR) {
#ifdef COMPLIANT_HEIGHTS
/* Specification DPD and primetime Parcel Despatch 4.0.2 Section 5.5.1
25mm / 0.4mm (X max) = 62.5 min, 25mm / 0.375 (X) ~ 66.66 default */
error_number = set_height(symbol, 62.5f, (float) (25.0 / 0.375), 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Specification DPD and primetime Parcel Despatch 4.0.2 Section 5.5.1
25mm / 0.4mm (X max) = 62.5 min, 25mm / 0.375 (X) ~ 66.66 default */
error_number = set_height(symbol, 62.5f, stripf(25.0f / 0.375f), 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
cd = mod;

View file

@ -119,8 +119,6 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
int error_number = 0, first_sum, second_sum;
int input_length;
int gs1, c_count;
int separator;
float min_row_height = 0.0f;
/* Suppresses clang-analyzer-core.UndefinedBinaryOperatorResult warning on fset which is fully set */
assert(length > 0);
@ -490,16 +488,17 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len
symbol->rows = rows;
symbol->width = 70;
#ifdef COMPLIANT_HEIGHTS
separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
/* BS EN 12323:2005 Section 4.5 (d) minimum 8X; use 10 * rows as default for back-compatibility */
min_row_height = 8.0f + separator;
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void)&separator;
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 12323:2005 Section 4.5 (d) minimum 8X; use 10X as default
Section 4.5 (b) H = X[r(h + g) + g] = rows * row_height + (rows - 1) * separator as borders not included
in symbol->height (added on) */
const int separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
const float min_row_height = stripf((8.0f * rows + separator * (rows - 1)) / rows);
const float default_height = 10.0f * rows + separator * (rows - 1);
error_number = set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
}
symbol->output_options |= BARCODE_BIND;

View file

@ -39,7 +39,7 @@
/* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */
INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value;
char intermediate[170] = "";
int codewords[170], codeword_count;
@ -49,8 +49,6 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
char pattern[80];
int gs1;
int h, len;
int separator;
float min_row_height = 0.0f;
int error_number = 0;
if (length > 81) {
@ -351,16 +349,17 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
symbol->rows = rows;
symbol->width = (int) strlen(pattern);
#ifdef COMPLIANT_HEIGHTS
separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
/* ANSI/AIM BC6-2000 Section 2.6 minimum 8X; use 10 * rows as default for back-compatibility */
min_row_height = 8.0f + separator;
error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f,
0 /*no_errtxt*/);
#else
(void)&separator;
(void) set_height(symbol, min_row_height, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* ANSI/AIM BC6-2000 Section 2.6 minimum 8X; use 10X as default
Formula 2 H = ((h + g)r + g)X = rows * row_height + (rows - 1) * separator as borders not included
in symbol->height (added on) */
const int separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1;
const float min_row_height = stripf((8.0f * rows + separator * (rows - 1)) / rows);
const float default_height = 10.0f * rows + separator * (rows - 1);
error_number = set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/);
}
symbol->output_options |= BARCODE_BIND;

View file

@ -406,11 +406,11 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
if (zero_count) {
if (symbol->height) {
row_height = (symbol->height - fixed_height) / zero_count;
row_height = stripf((symbol->height - fixed_height) / zero_count);
} else if (default_height) {
row_height = default_height / zero_count;
row_height = stripf(default_height / zero_count);
} else {
row_height = min_row_height;
row_height = stripf(min_row_height);
}
if (row_height < 0.5f) { /* Absolute minimum */
row_height = 0.5f;
@ -421,9 +421,9 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height,
strcpy(symbol->errtxt, "247: Height not compliant with standards");
}
}
symbol->height = row_height * zero_count + fixed_height;
symbol->height = stripf(row_height * zero_count + fixed_height);
} else {
symbol->height = fixed_height; /* Ignore any given height */
symbol->height = stripf(fixed_height); /* Ignore any given height */
}
if (max_height && symbol->height > max_height) {
error_number = ZINT_WARN_NONCOMPLIANT;

View file

@ -63,18 +63,18 @@
#define UINT unsigned short
#include "composite.h"
INTERNAL int ean_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode,
INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode,
const int cc_rows);
INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[],
unsigned char local_source[], int *p_with_addon);
INTERNAL int rss14_stk_set_height(struct zint_symbol *symbol, const int first_row);
INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int rss_date(const unsigned char source[], const int src_posn);
INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row);
INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows);
INTERNAL int dbar_date(const unsigned char source[], const int src_posn);
static int _min(const int first, const int second) {
@ -889,7 +889,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
if ((source[0] == '1') && ((source[1] == '0') || (source[1] == '1') || (source[1] == '7'))) {
/* Source starts (10), (11) or (17) */
if (source[1] == '0' || rss_date(source, 2) >= 0) { /* Check date valid if (11) or (17) */
if (source[1] == '0' || dbar_date(source, 2) >= 0) { /* Check date valid if (11) or (17) */
encoding_method = 2;
}
} else if ((source[0] == '9') && (source[1] == '0')) {
@ -913,7 +913,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
} else {
/* Production Date (11) or Expiration Date (17) */
bp = bin_append_posn(rss_date(source, 2), 16, binary_string, bp);
bp = bin_append_posn(dbar_date(source, 2), 16, binary_string, bp);
if (source[1] == '1') {
/* Production Date AI 11 */
@ -1257,7 +1257,7 @@ static int linear_dummy_run(int input_mode, unsigned char *source, const int len
dummy = ZBarcode_Create();
dummy->symbology = BARCODE_GS1_128_CC;
dummy->input_mode = input_mode;
error_number = ean_128_cc(dummy, source, length, 3 /*cc_mode*/, 0 /*cc_rows*/);
error_number = gs1_128_cc(dummy, source, length, 3 /*cc_mode*/, 0 /*cc_rows*/);
linear_width = dummy->width;
if (error_number >= ZINT_ERROR) {
strcpy(errtxt, dummy->errtxt);
@ -1434,6 +1434,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
linear->symbology = symbol->symbology;
linear->input_mode = symbol->input_mode;
linear->output_options = symbol->output_options;
linear->option_2 = symbol->option_2;
/* If symbol->height given minimum row height will be returned, else default height */
linear->height = symbol->height;
@ -1450,16 +1451,16 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
break;
case BARCODE_GS1_128_CC:
/* GS1-128 needs to know which type of 2D component is used */
error_number = ean_128_cc(linear, (unsigned char *) symbol->primary, pri_len, cc_mode, symbol->rows);
error_number = gs1_128_cc(linear, (unsigned char *) symbol->primary, pri_len, cc_mode, symbol->rows);
break;
case BARCODE_DBAR_OMN_CC:
error_number = rss14_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_omn_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_DBAR_LTD_CC:
error_number = rsslimited_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_ltd_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_DBAR_EXP_CC:
error_number = rssexpanded_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_exp_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_UPCA_CC:
error_number = eanx_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
@ -1468,13 +1469,13 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
error_number = eanx_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_DBAR_STK_CC:
error_number = rss14_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_omn_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_DBAR_OMNSTK_CC:
error_number = rss14_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_omn_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
case BARCODE_DBAR_EXPSTK_CC:
error_number = rssexpanded_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
error_number = dbar_exp_cc(linear, (unsigned char *) symbol->primary, pri_len, symbol->rows);
break;
}
@ -1605,23 +1606,23 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
symbol->width += top_shift;
}
symbol->rows += linear->rows;
#ifdef COMPLIANT_HEIGHTS
if (symbol->symbology == BARCODE_DBAR_STK_CC) {
/* Databar Stacked needs special treatment due to asymmetric rows */
warn_number = rss14_stk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/);
if (symbol->output_options & COMPLIANT_HEIGHT) {
if (symbol->symbology == BARCODE_DBAR_STK_CC) {
/* Databar Stacked needs special treatment due to asymmetric rows */
warn_number = dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/);
} else {
/* If symbol->height given then min row height was returned, else default height */
warn_number = set_height(symbol, symbol->height ? linear->height : 0.0f,
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
}
} else {
/* If symbol->height given then min row height was returned, else default height */
warn_number = set_height(symbol, symbol->height ? linear->height : 0.0f,
symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/);
if (symbol->symbology == BARCODE_DBAR_STK_CC) {
(void) dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/);
} else {
(void) set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height,
0.0f, 1 /*no_errtxt*/);
}
}
#else
if (symbol->symbology == BARCODE_DBAR_STK_CC) {
(void) rss14_stk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/);
} else {
(void) set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height,
0.0f, 1 /*no_errtxt*/);
}
#endif
ustrcpy(symbol->text, linear->text);

View file

@ -1144,7 +1144,7 @@ static void add_tail(unsigned char target[], int tp, const int tail_length) {
}
}
static int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], int inputlen) {
static int datamatrix_200(struct zint_symbol *symbol, const unsigned char source[], int inputlen) {
int i, skew = 0;
unsigned char binary[2200];
int binlen;
@ -1266,12 +1266,12 @@ static int data_matrix_200(struct zint_symbol *symbol, const unsigned char sourc
return error_number;
}
INTERNAL int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int datamatrix(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number;
if (symbol->option_1 <= 1) {
/* ECC 200 */
error_number = data_matrix_200(symbol, source, length);
error_number = datamatrix_200(symbol, source, length);
} else {
/* ECC 000 - 140 */
strcpy(symbol->errtxt, "524: Older Data Matrix standards are no longer supported");

View file

@ -1006,7 +1006,7 @@ static void place_layer_id(char *grid, int size, int layers, int modules, int ec
}
}
INTERNAL int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int gridmatrix(struct zint_symbol *symbol, unsigned char source[], int length) {
int size, modules, error_number;
int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level;
int x, y, i;

View file

@ -1448,7 +1448,7 @@ static void hx_apply_bitmask(unsigned char *grid, const int size, const int vers
}
/* Han Xin Code - main */
INTERNAL int han_xin(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int hanxin(struct zint_symbol *symbol, unsigned char source[], int length) {
int est_binlen;
int ecc_level = symbol->option_1;
int i, j, j_max, version;

View file

@ -244,7 +244,7 @@ static unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned cha
INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float max_height);
INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int length) {
char data_pattern[200];
int error_number;
int i, j, read;
@ -434,22 +434,22 @@ INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int lengt
read += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* USPS-B-3200 Section 2.3.1
Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025"),
height 0.125" - 0.165"
Tracker 0.048" (average of 0.039" - 0.057")
Ascender/descender 0.0965" (average of 0.082" - 0.111") less T = 0.0485"
*/
symbol->row_height[0] = 0.0485f * 43; /* 2.0855 */
symbol->row_height[1] = 0.048f * 43; /* 2.064 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, 0.125f * 39 /*4.875*/, 0.165f * 47 /*7.755*/);
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* USPS-B-3200 Section 2.3.1
Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025"),
height 0.125" - 0.165"
Tracker 0.048" (average of 0.039" - 0.057")
Ascender/descender 0.0965" (average of 0.082" - 0.111") less T = 0.0485"
*/
symbol->row_height[0] = stripf(0.0485f * 43); /* 2.0855 */
symbol->row_height[1] = stripf(0.048f * 43); /* 2.064 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, stripf(0.125f * 39) /*4.875*/, stripf(0.165f * 47) /*7.755*/);
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
(void) daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->width = read - 1;
return error_number;

View file

@ -132,80 +132,75 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
}
INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 3 from 9 (or Code 39) */
/* Pharmazentral Nummer (PZN) */
INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 3 from 9 (or Code 39) */
INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmazentral Nummer (PZN) */
/* Extended Code 3 from 9 (or Code 39+) */
INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int length);
/* Codabar - a simple substitution cipher */
INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length);
/* Code 2 of 5 Standard (& Matrix) */
INTERNAL int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length);
/* Code 2 of 5 Industrial */
INTERNAL int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */
/* Code 2 of 5 Interleaved */
INTERNAL int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length);
/* Code 2 of 5 Data Logic */
INTERNAL int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int c25standard(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int c25ind(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Industrial */
INTERNAL int c25iata(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */
INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Interleaved */
INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Data Logic */
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length); /* ITF-14 */
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */
/* Code 93 - a re-working of Code 39+, generates 2 check digits */
INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int code_128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */
INTERNAL int ean_128(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-128 (GS1-128) */
INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */
INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */
INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */
INTERNAL int gs1_128(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-128 (GS1-128) */
INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */
INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */
INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen ASCII */
INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen Numeric */
INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* Plessey Code */
INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */
INTERNAL int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */
INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */
INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */
INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */
INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode Two Track */
INTERNAL int post_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* Postnet */
INTERNAL int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* PLANET */
INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int length); /* Postnet */
INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int length); /* PLANET */
/* Intelligent Mail (aka USPS OneCode) */
INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */
/* Australia Post 4-state */
INTERNAL int australia_post(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */
INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */
INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */
INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */
INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length); /* Micro PDF417 */
INTERNAL int pdf417(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */
INTERNAL int micropdf417(struct zint_symbol *symbol, unsigned char chaine[], int length); /* Micro PDF417 */
INTERNAL int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */
INTERNAL int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */
INTERNAL int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */
INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */
INTERNAL int dbar_omn(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */
INTERNAL int dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */
INTERNAL int dbar_exp(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */
INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */
INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */
INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */
INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Code */
INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */
INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */
INTERNAL int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */
INTERNAL int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */
INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */
INTERNAL int ean14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */
INTERNAL int nve18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */
INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int length); /* Micro QR Code */
INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */
INTERNAL int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */
INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */
INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 49 */
INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */
INTERNAL int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */
INTERNAL int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Grid Matrix */
INTERNAL int han_xin(struct zint_symbol *symbol, unsigned char source[], int length); /* Han Xin */
INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */
INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */
INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */
INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 49 */
INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */
INTERNAL int codeone(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */
INTERNAL int gridmatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Grid Matrix */
INTERNAL int hanxin(struct zint_symbol *symbol, unsigned char source[], int length); /* Han Xin */
INTERNAL int dotcode(struct zint_symbol *symbol, unsigned char source[], int length); /* DotCode */
INTERNAL int codablock(struct zint_symbol *symbol, unsigned char source[], int length); /* Codablock */
INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int length); /* Codablock */
INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int length); /* UPNQR */
INTERNAL int qr_code(struct zint_symbol *symbol, unsigned char source[], int length); /* QR Code */
INTERNAL int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Data Matrix (IEC16022) */
INTERNAL int qrcode(struct zint_symbol *symbol, unsigned char source[], int length); /* QR Code */
INTERNAL int datamatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Data Matrix (IEC16022) */
/* VIN Code (Vehicle Identification Number) */
INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length);
/* Royal Mail 4-state Mailmark */
INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int length); /* Ultracode */
INTERNAL int ultra(struct zint_symbol *symbol, unsigned char source[], int length); /* Ultracode */
INTERNAL int rmqr(struct zint_symbol *symbol, unsigned char source[], int length); /* rMQR */
INTERNAL int dpd_parcel(struct zint_symbol *symbol, unsigned char source[], int length); /* DPD Code */
INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length); /* DPD Code */
INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */
@ -299,7 +294,7 @@ static int dump_plot(struct zint_symbol *symbol) {
/* Process health industry bar code data */
static int hibc(struct zint_symbol *symbol, unsigned char source[], int length) {
int i;
int counter, error_number;
int counter, error_number = 0;
char to_process[113], check_digit;
/* without "+" and check: max 110 characters in HIBC 2.6 */
@ -308,10 +303,9 @@ static int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(TECHNETIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(TECHNETIUM, source, length) != 0) {
strcpy(symbol->errtxt, "203: Invalid character in data (alphanumerics, space and \"-.$/+%\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
counter = 41;
@ -355,35 +349,35 @@ static int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
switch (symbol->symbology) {
case BARCODE_HIBC_128:
error_number = code_128(symbol, (unsigned char *) to_process, length);
error_number = code128(symbol, (unsigned char *) to_process, length);
ustrcpy(symbol->text, "*");
ustrcat(symbol->text, to_process);
ustrcat(symbol->text, "*");
break;
case BARCODE_HIBC_39:
symbol->option_2 = 0;
error_number = c39(symbol, (unsigned char *) to_process, length);
error_number = code39(symbol, (unsigned char *) to_process, length);
ustrcpy(symbol->text, "*");
ustrcat(symbol->text, to_process);
ustrcat(symbol->text, "*");
break;
case BARCODE_HIBC_DM:
error_number = dmatrix(symbol, (unsigned char *) to_process, length);
error_number = datamatrix(symbol, (unsigned char *) to_process, length);
break;
case BARCODE_HIBC_QR:
error_number = qr_code(symbol, (unsigned char *) to_process, length);
error_number = qrcode(symbol, (unsigned char *) to_process, length);
break;
case BARCODE_HIBC_PDF:
error_number = pdf417enc(symbol, (unsigned char *) to_process, length);
error_number = pdf417(symbol, (unsigned char *) to_process, length);
break;
case BARCODE_HIBC_MICPDF:
error_number = micro_pdf417(symbol, (unsigned char *) to_process, length);
error_number = micropdf417(symbol, (unsigned char *) to_process, length);
break;
case BARCODE_HIBC_AZTEC:
error_number = aztec(symbol, (unsigned char *) to_process, length);
break;
case BARCODE_HIBC_BLOCKF:
error_number = codablock(symbol, (unsigned char *) to_process, length);
error_number = codablockf(symbol, (unsigned char *) to_process, length);
break;
}
@ -542,6 +536,41 @@ static int has_hrt(const int symbology) {
return 1;
}
/* Used for dispatching barcodes and for whether symbol id valid */
typedef int (*barcode_func_t)(struct zint_symbol *, unsigned char *, int);
static const barcode_func_t barcode_funcs[146] = {
NULL, code11, c25standard, c25inter, c25iata, /*0-4*/
NULL, c25logic, c25ind, code39, excode39, /*5-9*/
NULL, NULL, NULL, eanx, eanx, /*10-14*/
NULL, gs1_128, NULL, codabar, NULL, /*15-19*/
code128, dpleit, dpident, code16k, code49, /*20-24*/
code93, NULL, NULL, flat, dbar_omn, /*25-29*/
dbar_ltd, dbar_exp, telepen, NULL, eanx, /*30-34*/
eanx, NULL, eanx, eanx, NULL, /*35-39*/
postnet, NULL, NULL, NULL, NULL, /*40-44*/
NULL, NULL, msi_plessey, NULL, fim, /*45-49*/
code39, pharma, pzn, pharma_two, NULL, /*50-54*/
pdf417, pdf417, maxicode, qrcode, NULL, /*55-59*/
code128, NULL, NULL, auspost, NULL, /*60-64*/
NULL, auspost, auspost, auspost, eanx, /*65-69*/
rm4scc, datamatrix, ean14, vin, codablockf, /*70-74*/
nve18, japanpost, koreapost, NULL, dbar_omn, /*75-79*/
dbar_omn, dbar_exp, planet, NULL, micropdf417, /*80-84*/
usps_imail, plessey, telepen_num, NULL, itf14, /*85-89*/
kix, NULL, aztec, daft, NULL, /*90-94*/
NULL, dpd, microqr, hibc, hibc, /*95-99*/
NULL, NULL, hibc, NULL, hibc, /*100-104*/
NULL, hibc, NULL, hibc, NULL, /*105-109*/
hibc, NULL, hibc, NULL, NULL, /*110-114*/
dotcode, hanxin, NULL, NULL, NULL, /*115-119*/
NULL, mailmark, NULL, NULL, NULL, /*120-124*/
NULL, NULL, NULL, azrune, code32, /*125-129*/
composite, composite, composite, composite, composite, /*130-134*/
composite, composite, composite, composite, composite, /*135-139*/
channel, codeone, gridmatrix, upnqr, ultra, /*140-144*/
rmqr,
};
static int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length);
static int extended_or_reduced_charset(struct zint_symbol *symbol, unsigned char *source, const int length) {
@ -549,17 +578,13 @@ static int extended_or_reduced_charset(struct zint_symbol *symbol, unsigned char
switch (symbol->symbology) {
/* These are the "elite" standards which have support for specific character sets */
case BARCODE_QRCODE: error_number = qr_code(symbol, source, length);
break;
case BARCODE_MICROQR: error_number = microqr(symbol, source, length);
break;
case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length);
break;
case BARCODE_HANXIN: error_number = han_xin(symbol, source, length);
break;
case BARCODE_UPNQR: error_number = upnqr(symbol, source, length);
break;
case BARCODE_RMQR: error_number = rmqr(symbol, source, length);
case BARCODE_QRCODE:
case BARCODE_MICROQR:
case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN:
case BARCODE_UPNQR:
case BARCODE_RMQR:
error_number = (*barcode_funcs[symbol->symbology])(symbol, source, length);
break;
default: error_number = reduced_charset(symbol, source, length);
break;
@ -568,8 +593,8 @@ static int extended_or_reduced_charset(struct zint_symbol *symbol, unsigned char
return error_number;
}
/* These are the "norm" standards which only support Latin-1 at most, though a few support ECI */
static int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) {
/* These are the "norm" standards which only support Latin-1 at most, though a few support ECI */
int error_number = 0;
unsigned char *preprocessed = source;
@ -594,169 +619,7 @@ static int reduced_charset(struct zint_symbol *symbol, unsigned char *source, in
}
}
switch (symbol->symbology) {
case BARCODE_C25STANDARD: error_number = matrix_two_of_five(symbol, preprocessed, length);
break;
case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length);
break;
case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length);
break;
case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length);
break;
case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length);
break;
case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length);
break;
case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length);
break;
case BARCODE_UPCA:
case BARCODE_UPCA_CHK:
case BARCODE_UPCE:
case BARCODE_UPCE_CHK:
case BARCODE_EANX:
case BARCODE_EANX_CHK:
case BARCODE_ISBNX:
error_number = eanx(symbol, preprocessed, length);
break;
case BARCODE_GS1_128: error_number = ean_128(symbol, preprocessed, length);
break;
case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length);
break;
case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length);
break;
case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length);
break;
case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length);
break;
case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length);
break;
case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length);
break;
case BARCODE_CODE128:
case BARCODE_CODE128B:
error_number = code_128(symbol, preprocessed, length);
break;
case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length);
break;
case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length);
break;
case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length);
break;
case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length);
break;
case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length);
break;
case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length);
break;
case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length);
break;
case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length);
break;
case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length);
break;
case BARCODE_FIM: error_number = fim(symbol, preprocessed, length);
break;
case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length);
break;
case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length);
break;
case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length);
break;
case BARCODE_AUSPOST:
case BARCODE_AUSREPLY:
case BARCODE_AUSROUTE:
case BARCODE_AUSREDIRECT:
error_number = australia_post(symbol, preprocessed, length);
break;
case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length);
break;
case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length);
break;
case BARCODE_USPS_IMAIL: error_number = imail(symbol, preprocessed, length);
break;
case BARCODE_DBAR_OMN:
case BARCODE_DBAR_STK:
case BARCODE_DBAR_OMNSTK:
error_number = rss14(symbol, preprocessed, length);
break;
case BARCODE_DBAR_LTD: error_number = rsslimited(symbol, preprocessed, length);
break;
case BARCODE_DBAR_EXP:
case BARCODE_DBAR_EXPSTK:
error_number = rssexpanded(symbol, preprocessed, length);
break;
case BARCODE_EANX_CC:
case BARCODE_GS1_128_CC:
case BARCODE_DBAR_OMN_CC:
case BARCODE_DBAR_LTD_CC:
case BARCODE_DBAR_EXP_CC:
case BARCODE_UPCA_CC:
case BARCODE_UPCE_CC:
case BARCODE_DBAR_STK_CC:
case BARCODE_DBAR_OMNSTK_CC:
case BARCODE_DBAR_EXPSTK_CC:
error_number = composite(symbol, preprocessed, length);
break;
case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length);
break;
case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length);
break;
case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length);
break;
case BARCODE_EAN14:
error_number = ean_14(symbol, preprocessed, length);
break;
case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length);
break;
case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length);
break;
case BARCODE_HIBC_128:
case BARCODE_HIBC_39:
case BARCODE_HIBC_DM:
case BARCODE_HIBC_QR:
case BARCODE_HIBC_PDF:
case BARCODE_HIBC_MICPDF:
case BARCODE_HIBC_AZTEC:
case BARCODE_HIBC_BLOCKF:
error_number = hibc(symbol, preprocessed, length);
break;
case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length);
break;
case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length);
break;
case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length);
break;
case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length);
break;
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length);
break;
case BARCODE_PDF417:
case BARCODE_PDF417COMP:
error_number = pdf417enc(symbol, preprocessed, length);
break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length);
break;
case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length);
break;
case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length);
break;
case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, length);
break;
case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed, length);
break;
case BARCODE_VIN: error_number = vin(symbol, preprocessed, length);
break;
case BARCODE_MAILMARK: error_number = mailmark(symbol, preprocessed, length);
break;
case BARCODE_ULTRA: error_number = ultracode(symbol, preprocessed, length);
break;
case BARCODE_DPD: error_number = dpd_parcel(symbol, preprocessed, length);
break;
default: /* Should never happen */
strcpy(symbol->errtxt, "001: Internal error"); /* Not reached */
error_number = ZINT_ERROR_ENCODING_PROBLEM;
break;
}
error_number = (*barcode_funcs[symbol->symbology])(symbol, preprocessed, length);
return error_number;
}
@ -1484,31 +1347,14 @@ int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, const cha
return error_number;
}
/* Checks whether a symbology is supported */
int ZBarcode_ValidID(int symbol_id) {
/* Checks whether a symbology is supported */
static const unsigned char ids[146] = {
0, 1, 2, 3, 4, 0, 6, 7, 8, 9,
0, 0, 0, 13, 14, 0, 16, 0, 18, 0,
20, 21, 22, 23, 24, 25, 0, 0, 28, 29,
30, 31, 32, 0, 34, 35, 0, 37, 38, 0,
40, 0, 0, 0, 0, 0, 0, 47, 0, 49,
50, 51, 52, 53, 0, 55, 56, 57, 58, 0,
60, 0, 0, 63, 0, 0, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 0, 79,
80, 81, 82, 0, 84, 85, 86, 87, 0, 89,
90, 0, 92, 93, 0, 0, 96, 97, 98, 99,
0, 0, 102, 0, 104, 0, 106, 0, 108, 0,
110, 0, 112, 0, 0, 115, 116, 0, 0, 0,
0, 121, 0, 0, 0, 0, 0, 0, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
140, 141, 142, 143, 144, 145,
};
if (symbol_id <= 0 || symbol_id > 145) {
return 0;
}
return ids[symbol_id] != 0;
return barcode_funcs[symbol_id] != NULL;
}
/* Return the capability flags for symbology `symbol_id` that match `cap_flag` */
@ -1628,6 +1474,36 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) {
break;
}
}
if ((cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) && !is_fixed_ratio(symbol_id)) {
switch (symbol_id) {
/* These don't have a compliant height defined */
case BARCODE_CODE11: /* TODO: Find doc */
case BARCODE_C25STANDARD: /* For C25 only have doc for C25INTER */
case BARCODE_C25IATA:
case BARCODE_C25LOGIC:
case BARCODE_C25IND:
case BARCODE_CODE128: /* Left to application */
case BARCODE_CODE128B:
case BARCODE_DPLEIT: /* TODO: Find doc */
case BARCODE_DPIDENT: /* TODO: Find doc */
case BARCODE_FLAT: /* TODO: Find doc */
case BARCODE_MSI_PLESSEY: /* TODO: Find doc */
case BARCODE_PDF417: /* Has compliant height but already warns & uses for default */
case BARCODE_PDF417COMP:
case BARCODE_VIN: /* Spec unlikely */
case BARCODE_KOREAPOST: /* TODO: Find doc */
case BARCODE_MICROPDF417: /* See PDF417 */
case BARCODE_PLESSEY: /* TODO: Find doc */
case BARCODE_DAFT: /* Generic */
case BARCODE_HIBC_128: /* See CODE128 */
case BARCODE_HIBC_PDF: /* See PDF417 */
case BARCODE_HIBC_MICPDF: /* See PDF417 */
break;
default:
result |= ZINT_CAP_COMPLIANT_HEIGHT;
break;
}
}
return result;
}

View file

@ -33,9 +33,11 @@
/*
* Developed in accordance with "Royal Mail Mailmark barcode C encoding and deconding instructions"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf)
* (https://www.royalmail.com/sites/default/files/
* Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf)
* and "Royal Mail Mailmark barcode L encoding and decoding"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf)
* (https://www.royalmail.com/sites/default/files/
* Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf)
*
*/
@ -182,21 +184,21 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
// Format is in the range 0-4
format = ctoi(local_source[0]);
if ((format < 0) || (format > 4)) {
strcpy(symbol->errtxt, "582: Format out of range (0 to 4)");
strcpy(symbol->errtxt, "582: Format (1st character) out of range (0 to 4)");
return ZINT_ERROR_INVALID_DATA;
}
// Version ID is in the range 1-4
version_id = ctoi(local_source[1]) - 1;
if ((version_id < 0) || (version_id > 3)) {
strcpy(symbol->errtxt, "583: Version ID out of range (1 to 4)");
strcpy(symbol->errtxt, "583: Version ID (2nd character) out of range (1 to 4)");
return ZINT_ERROR_INVALID_DATA;
}
// Class is in the range 0-9,A-E
mail_class = ctoi(local_source[2]);
if ((mail_class < 0) || (mail_class > 14)) {
strcpy(symbol->errtxt, "584: Class out of range (0 to 9 and A to E)");
strcpy(symbol->errtxt, "584: Class (3rd character) out of range (0 to 9 and A to E)");
return ZINT_ERROR_INVALID_DATA;
}
@ -207,7 +209,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
supply_chain_id *= 10;
supply_chain_id += ctoi(local_source[i]);
} else {
strcpy(symbol->errtxt, "585: Invalid Supply Chain ID (digits only)");
sprintf(symbol->errtxt, "585: Invalid Supply Chain ID at character %d (digits only)", i);
return ZINT_ERROR_INVALID_DATA;
}
}
@ -219,7 +221,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
item_id *= 10;
item_id += ctoi(local_source[i]);
} else {
strcpy(symbol->errtxt, "586: Invalid Item ID (digits only)");
sprintf(symbol->errtxt, "586: Invalid Item ID at character %d (digits only)", i);
return ZINT_ERROR_INVALID_DATA;
}
}
@ -273,7 +275,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
// Verify postcode type
if (postcode_type != 7) {
if (verify_postcode(postcode, postcode_type) != 0) {
strcpy(symbol->errtxt, "587: Invalid postcode");
sprintf(symbol->errtxt, "587: Invalid postcode \"%s\"", postcode);
return ZINT_ERROR_INVALID_DATA;
}
}
@ -487,22 +489,24 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
j += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* Royal Mail Mailmark Barcode Definition Document (15 Sept 2015) Section 3.5.1
https://www.royalmail.com/sites/default/files/Royal-Mail-Mailmark-barcode-definition-document-September-2015.pdf
Using bar pitch as X (25.4mm / 42.3) ~ 0.6mm based on 21.2 bars + 21.1 spaces per 25.4mm (bar width 0.38-63mm)
Using recommended 1.9mm and 1.3mm heights for Ascender/Descenders and Trackers resp. as defaults
Min height 4.22mm * 39 (max pitch) / 25.4mm ~ 6.47, max height 5.84mm * 47 (min pitch) / 25.4mm ~ 10.8
*/
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 4.0f;
symbol->row_height[1] = 2.0f;
daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Royal Mail Mailmark Barcode Definition Document (15 Sept 2015) Section 3.5.1
(https://www.royalmail.com/sites/default/files/
Royal-Mail-Mailmark-barcode-definition-document-September-2015.pdf)
Using bar pitch as X (25.4mm / 42.3) ~ 0.6mm based on 21.2 bars + 21.1 spaces per 25.4mm (bar width
0.38mm - 0.63mm)
Using recommended 1.9mm and 1.3mm heights for Ascender/Descenders and Trackers resp. as defaults
Min height 4.22mm * 39 (max pitch) / 25.4mm ~ 6.47, max height 5.84mm * 47 (min pitch) / 25.4mm ~ 10.8
*/
symbol->row_height[0] = stripf((1.9f * 42.3f) / 25.4f); /* ~3.16 */
symbol->row_height[1] = stripf((1.3f * 42.3f) / 25.4f); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, stripf((4.22f * 39) / 25.4f), stripf((5.84f * 47) / 25.4f));
} else {
symbol->row_height[0] = 4.0f;
symbol->row_height[1] = 2.0f;
(void) daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->width = j - 1;

View file

@ -34,7 +34,7 @@
#include <stdio.h>
#include "common.h"
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length);
INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length);
/* Codabar table checked against EN 798:1995 */
@ -47,7 +47,7 @@ static const char *CodaTable[20] = {
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"
};
INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int length) {
/* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other
commonly used one-dimensional barcode schemes, pharmacode does not store the data in a
form corresponding to the human-readable digits; the number is encoded in binary, rather
@ -62,7 +62,7 @@ INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int
(http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf) */
unsigned long int tester;
int counter, error_number, h;
int counter, error_number = 0, h;
char inter[18] = {0}; /* 131070 -> 17 bits */
char dest[64]; /* 17 * 2 + 1 */
@ -70,10 +70,9 @@ INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int
strcpy(symbol->errtxt, "350: Input too long (6 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "351: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
tester = atoi((char *) source);
@ -105,12 +104,12 @@ INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* Laetus Pharmacode Guide 1.2 Standard one-track height 8mm / 0.5mm (X) */
error_number = set_height(symbol, 16.0f, 0.0f, 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Laetus Pharmacode Guide 1.2 Standard one-track height 8mm / 0.5mm (X) */
error_number = set_height(symbol, 16.0f, 0.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
return error_number;
}
@ -173,10 +172,9 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int
strcpy(symbol->errtxt, "354: Input too long (8 character maximum");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "355: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
error_number = pharma_two_calc(symbol, source, height_pattern);
if (error_number != 0) {
@ -197,13 +195,13 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int
symbol->rows = 2;
symbol->width = writer - 1;
#ifdef COMPLIANT_HEIGHTS
/* Laetus Pharmacode Guide 1.4
Two-track height min 8mm / 2mm (X max) = 4, standard 8mm / 1mm = 8, max 12mm / 0.8mm (X min) = 15 */
error_number = set_height(symbol, 2.0f, 8.0f, 15.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 10.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Laetus Pharmacode Guide 1.4
Two-track height min 8mm / 2mm (X max) = 4, standard 8mm / 1mm = 8, max 12mm / 0.8mm (X min) = 15 */
error_number = set_height(symbol, 2.0f, 8.0f, 15.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 10.0f, 0.0f, 1 /*no_errtxt*/);
}
return error_number;
}
@ -211,11 +209,11 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int
/* The Codabar system consisting of simple substitution */
INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number;
static const char calcium[] = CALCIUM;
int i, error_number = 0;
char dest[512];
int add_checksum, count = 0, checksum;
int add_checksum, count = 0, checksum = 0;
int d_chars = 0;
float height;
strcpy(dest, "");
@ -244,21 +242,23 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len
}
/* And must not use A, B, C or D otherwise (BS EN 798:1995 4.3.2) */
error_number = is_sane(CALCIUM_INNER, source + 1, length - 2);
if (error_number) {
if (is_sane(CALCIUM, source + 1, length - 2) == 0) {
if (is_sane(CALCIUM_INNER, source + 1, length - 2) != 0) {
if (is_sane(calcium, source + 1, length - 2) == 0) {
strcpy(symbol->errtxt, "363: Cannot contain \"A\", \"B\", \"C\" or \"D\"");
} else {
sprintf(symbol->errtxt, "357: Invalid character in data (\"%s\" only)", CALCIUM);
sprintf(symbol->errtxt, "357: Invalid character in data (\"%s\" only)", calcium);
}
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
add_checksum = symbol->option_2 == 1;
/* Add check character: 1 don't show to HRT, 2 do show to HRT
(unfortunately to maintain back-compatibility, this is reverse of C25) */
add_checksum = symbol->option_2 == 1 || symbol->option_2 == 2;
for (i = 0; i < length; i++) {
static const char calcium[] = CALCIUM;
if (add_checksum) {
/* BS EN 798:1995 A.3 suggests using ISO 7064 algorithm but leaves it application defined.
Following BWIPP and TEC-IT, use this simple mod-16 algorithm (not in ISO 7064) */
count += strchr(calcium, source[i]) - calcium;
if (i + 1 == length) {
checksum = count % 16;
@ -266,7 +266,7 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len
checksum = 16 - checksum;
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codabar: %s, count %d, checksum %d\n", source, count, checksum);
printf("Codabar: %s, count %d, checksum %d (%c)\n", source, count, checksum, calcium[checksum]);
}
strcat(dest, CodaTable[checksum]);
}
@ -279,23 +279,29 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.191mm (X) ~ 26.178 or 15% of width where (taking N = narrow/wide ratio
as 2 and I = X) width = ((2 * N + 5) * C + (N 1) * (D + 2)) * X + I * (C 1) + 2Q
= ((4 + 5) * C + (D + 2) + C - 1 + 2 * 10) * X = (10 * C + D + 21) * X
Length (C) includes start/stop chars */
height = (float) ((10.0 * ((add_checksum ? length + 1 : length) + 2.0) + d_chars + 21.0) * 0.15);
if (height < (float) (5.0 / 0.191)) {
height = (float) (5.0 / 0.191);
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.191mm (X) ~ 26.178 or 15% of width where (taking N = narrow/wide
ratio as 2 and I = X) width = ((2 * N + 5) * C + (N 1) * (D + 2)) * X + I * (C 1) + 2Q
= ((4 + 5) * C + (D + 2) + C - 1 + 2 * 10) * X = (10 * C + D + 21) * X
Length (C) includes start/stop chars */
const float min_height_min = stripf(5.0f / 0.191f);
float min_height = stripf((10.0f * ((add_checksum ? length + 1 : length) + 2.0f) + d_chars + 21.0f) * 0.15f);
if (min_height < min_height_min) {
min_height = min_height_min;
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
/* Using 50 as default as none recommended */
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
ustrcpy(symbol->text, source);
if (symbol->option_2 == 2) {
symbol->text[length - 1] = calcium[checksum]; /* Place before final A/B/C/D character (BS EN 798:1995 A.3) */
symbol->text[length] = source[length - 1];
symbol->text[length + 1] = '\0';
}
return error_number;
}
@ -312,10 +318,9 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng
strcpy(symbol->errtxt, "360: Input too long (8 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "361: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Add leading zeros as required */
@ -361,20 +366,22 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng
}
risultante[6] = '\0';
/* Plot the barcode using Code 39 */
error_number = c39(symbol, (unsigned char *) risultante, (int) strlen(risultante));
error_number = code39(symbol, (unsigned char *) risultante, (int) strlen(risultante));
if (error_number != 0) { /* Should never happen */
return error_number; /* Not reached */
}
#ifdef COMPLIANT_HEIGHTS
/* Allegato A Caratteristiche tecniche del bollino farmaceutico
https://www.gazzettaufficiale.it/do/atto/serie_generale/caricaPdf?cdimg=14A0566800100010110001&dgu=2014-07-18&art.dataPubblicazioneGazzetta=2014-07-18&art.codiceRedazionale=14A05668&art.num=1&art.tiposerie=SG
X given as 0.250mm; height (and quiet zones) left to ISO/IEC 16388:2007 (Code 39)
So min height 5mm = 5mm / 0.25mm = 20 > 15% of width, i.e. (10 * 8 + 19) * 0.15 = 14.85 */
error_number = set_height(symbol, 20.0f, 20.0f, 0.0f, 0 /*no_errtxt*/); /* Use as default also */
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Allegato A Caratteristiche tecniche del bollino farmaceutico
(https://www.gazzettaufficiale.it/do/atto/serie_generale/caricaPdf?cdimg=14A0566800100010110001
&dgu=2014-07-18&art.dataPubblicazioneGazzetta=2014-07-18&art.codiceRedazionale=14A05668&art.num=1
&art.tiposerie=SG)
X given as 0.250mm; height (and quiet zones) left to ISO/IEC 16388:2007 (Code 39)
So min height 5mm = 5mm / 0.25mm = 20 > 15% of width, i.e. (10 * 8 + 19) * 0.15 = 14.85 */
error_number = set_height(symbol, 20.0f, 20.0f, 0.0f, 0 /*no_errtxt*/); /* Use as default also */
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
/* Override the normal text output with the Pharmacode number */
ustrcpy(symbol->text, "A");

View file

@ -611,7 +611,7 @@ INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si) {
if (zero_count) {
large_bar_height = (symbol->height - fixed_height) / zero_count;
if (large_bar_height <= 0.0f) { /* Shouldn't happen but protect against memory access violations */
large_bar_height = 0.01f; /* Token positive value */
large_bar_height = 0.0078125f; /* Token positive value (exact float 2**-6) */
symbol->height = large_bar_height * zero_count + fixed_height;
}
if (si && !isfintf(large_bar_height * si)) {

View file

@ -508,7 +508,7 @@ static void numbprocess(int *chainemc, int *mclength, const unsigned char chaine
}
}
/* Initial processing of data, shared by `pdf417enc()` and `micro_pdf417()` */
/* Initial processing of data, shared by `pdf417()` and `micropdf417()` */
static int pdf417_initial(struct zint_symbol *symbol, unsigned char chaine[], const int length, const int is_micro,
int chainemc[PDF417_MAX_LEN], int *p_mclength, int structapp_cws[18], int *p_structapp_cp) {
int i, indexchaine, indexliste, mode;
@ -661,7 +661,7 @@ static int pdf417_initial(struct zint_symbol *symbol, unsigned char chaine[], co
}
/* 366 */
static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const int length) {
static int pdf417_enc(struct zint_symbol *symbol, unsigned char chaine[], const int length) {
int i, k, j, longueur, loop, mccorrection[520] = {0}, offset;
int total, chainemc[PDF417_MAX_LEN], mclength, c1, c2, c3, dummy[35];
char pattern[580];
@ -872,7 +872,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const int
}
/* 345 */
INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int pdf417(struct zint_symbol *symbol, unsigned char source[], int length) {
int codeerr, error_number;
error_number = 0;
@ -895,7 +895,7 @@ INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int l
}
/* 349 */
codeerr = pdf417(symbol, source, length);
codeerr = pdf417_enc(symbol, source, length);
/* 352 */
if (codeerr != 0) {
@ -907,7 +907,7 @@ INTERNAL int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int l
}
/* like PDF417 only much smaller! */
INTERNAL int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
INTERNAL int micropdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) {
int i, k, j, longueur, mccorrection[50] = {0}, offset;
int total, chainemc[PDF417_MAX_LEN], mclength, error_number = 0;
char pattern[580];

View file

@ -55,16 +55,15 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
unsigned char *checkptr;
static const char grid[9] = {1, 1, 1, 1, 0, 1, 0, 0, 1};
char dest[554]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 = 554 */
int error_number;
int error_number = 0;
if (length > 65) {
strcpy(symbol->errtxt, "370: Input too long (65 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(SSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SSET, source, length) != 0) {
strcpy(symbol->errtxt, "371: Invalid character in data (digits and \"ABCDEF\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if (!(checkptr = (unsigned char *) calloc(1, length * 4 + 8))) {
@ -155,7 +154,8 @@ static char msi_check_digit_mod11(const unsigned char source[], const int length
}
/* Plain MSI Plessey - does not calculate any check character */
static void msi_plessey(struct zint_symbol *symbol, const unsigned char source[], const int length, char dest[]) {
static void msi_plessey_nomod(struct zint_symbol *symbol, const unsigned char source[], const int length,
char dest[]) {
int i;
@ -290,8 +290,8 @@ static void msi_plessey_mod1110(struct zint_symbol *symbol, const unsigned char
}
}
INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number;
INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number = 0;
char dest[550]; /* 2 + 65 * 8 + 3 * 8 + 3 + 1 = 550 */
int check_option = symbol->option_2;
int no_checktext = 0;
@ -300,8 +300,7 @@ INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int
strcpy(symbol->errtxt, "372: Input too long (65 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number != 0) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "377: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
@ -318,7 +317,7 @@ INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int
strcpy(dest, "21");
switch (check_option) {
case 0: msi_plessey(symbol, source, length, dest);
case 0: msi_plessey_nomod(symbol, source, length, dest);
break;
case 1: msi_plessey_mod10(symbol, source, length, no_checktext, dest);
break;

View file

@ -95,41 +95,39 @@ static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
int error_number = 0;
float h_ratio; /* Half ratio */
#ifdef COMPLIANT_HEIGHTS
symbol->row_height[0] = 0.075f * 43; /* 3.225 */
symbol->row_height[1] = 0.05f * 43; /* 2.15 */
#else
symbol->row_height[0] = 6.0f;
symbol->row_height[1] = 6.0f;
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
symbol->row_height[0] = stripf(0.075f * 43); /* 3.225 */
symbol->row_height[1] = stripf(0.05f * 43); /* 2.15 */
} else {
symbol->row_height[0] = 6.0f;
symbol->row_height[1] = 6.0f;
}
if (symbol->height) {
h_ratio = symbol->row_height[1] / (symbol->row_height[0] + symbol->row_height[1]); /* 0.4 */
symbol->row_height[1] = symbol->height * h_ratio;
symbol->row_height[1] = stripf(symbol->height * h_ratio);
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
symbol->row_height[1] = 0.5f;
symbol->row_height[0] = 0.5f / h_ratio - 0.5f; /* 0.75 */
symbol->row_height[0] = stripf(0.5f / h_ratio - 0.5f); /* 0.75 */
} else {
symbol->row_height[0] = symbol->height - symbol->row_height[1];
symbol->row_height[0] = stripf(symbol->height - symbol->row_height[1]);
}
}
symbol->height = symbol->row_height[0] + symbol->row_height[1];
symbol->height = stripf(symbol->row_height[0] + symbol->row_height[1]);
#ifdef COMPLIANT_HEIGHTS
if (symbol->height < 4.6f || symbol->height > 9.0f) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "498: Height not compliant with standards");
if (symbol->output_options & COMPLIANT_HEIGHT) {
if (symbol->height < 4.6f || symbol->height > 9.0f) {
error_number = ZINT_WARN_NONCOMPLIANT;
if (!no_errtxt) {
strcpy(symbol->errtxt, "498: Height not compliant with standards");
}
}
}
#else
(void)&no_errtxt;
#endif
return error_number;
}
/* Handles the PostNet system used for Zip codes in the US */
static int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
static int postnet_enc(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
int i, sum, check_digit;
int error_number = 0;
@ -141,7 +139,7 @@ static int postnet(struct zint_symbol *symbol, unsigned char source[], char dest
strcpy(symbol->errtxt, "479: Input length is not standard (5, 9 or 11 characters)");
error_number = ZINT_WARN_NONCOMPLIANT;
}
if (is_sane(NEON, source, length) == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "481: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
@ -165,13 +163,13 @@ static int postnet(struct zint_symbol *symbol, unsigned char source[], char dest
}
/* Puts PostNet barcodes into the pattern matrix */
INTERNAL int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
unsigned int loopey, h;
int writer;
int error_number, warn_number;
error_number = postnet(symbol, source, height_pattern, length);
error_number = postnet_enc(symbol, source, height_pattern, length);
if (error_number >= ZINT_ERROR) {
return error_number;
}
@ -193,7 +191,7 @@ INTERNAL int post_plot(struct zint_symbol *symbol, unsigned char source[], int l
}
/* Handles the PLANET system used for item tracking in the US */
static int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
static int planet_enc(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) {
int i, sum, check_digit;
int error_number = 0;
@ -205,7 +203,7 @@ static int planet(struct zint_symbol *symbol, unsigned char source[], char dest[
strcpy(symbol->errtxt, "478: Input length is not standard (11 or 13 characters)");
error_number = ZINT_WARN_NONCOMPLIANT;
}
if (is_sane(NEON, source, length) == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "483: Invalid character in data (digits only)");
return ZINT_ERROR_INVALID_DATA;
}
@ -229,13 +227,13 @@ static int planet(struct zint_symbol *symbol, unsigned char source[], char dest[
}
/* Puts PLANET barcodes into the pattern matrix */
INTERNAL int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
unsigned int loopey, h;
int writer;
int error_number, warn_number;
error_number = planet(symbol, source, height_pattern, length);
error_number = planet_enc(symbol, source, height_pattern, length);
if (error_number >= ZINT_ERROR) {
return error_number;
}
@ -257,18 +255,17 @@ INTERNAL int planet_plot(struct zint_symbol *symbol, unsigned char source[], int
}
/* Korean Postal Authority */
INTERNAL int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int total, loop, check, zeroes, error_number;
INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int length) {
int total, loop, check, zeroes, error_number = 0;
char localstr[8], dest[80];
if (length > 6) {
strcpy(symbol->errtxt, "484: Input too long (6 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "485: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
zeroes = 6 - length;
memset(localstr, '0', zeroes);
@ -333,14 +330,14 @@ INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length)
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.9.3
X 0.03125" (1/32) +- 0.008" so X max 0.03925", height 0.625" (5/8) +- 0.125" (1/8) */
error_number = set_height(symbol, (float) (0.5 / 0.03925), 20.0f /*0.625 / 0.03125*/, (float) (0.75 / 0.02415),
0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.9.3
X 0.03125" (1/32) +- 0.008" so X max 0.03925", height 0.625" (5/8) +- 0.125" (1/8) */
error_number = set_height(symbol, stripf(0.5f / 0.03925f), 20.0f /*0.625 / 0.03125*/,
stripf(0.75f / 0.02415f), 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
return error_number;
}
@ -352,36 +349,34 @@ INTERNAL int daft_set_height(struct zint_symbol *symbol, float min_height, float
float t_ratio; /* Tracker ratio */
if (symbol->height) {
t_ratio = symbol->row_height[1] / (symbol->row_height[0] * 2 + symbol->row_height[1]);
symbol->row_height[1] = symbol->height * t_ratio;
t_ratio = stripf(symbol->row_height[1] / stripf(symbol->row_height[0] * 2 + symbol->row_height[1]));
symbol->row_height[1] = stripf(symbol->height * t_ratio);
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
symbol->row_height[1] = 0.5f;
symbol->row_height[0] = 0.25f / t_ratio - 0.25f;
symbol->row_height[0] = stripf(0.25f / t_ratio - 0.25f);
} else {
symbol->row_height[0] = (symbol->height - symbol->row_height[1]) / 2.0f;
symbol->row_height[0] = stripf(stripf(symbol->height - symbol->row_height[1]) / 2.0f);
}
if (symbol->row_height[0] < 0.5f) {
symbol->row_height[0] = 0.5f;
symbol->row_height[1] = t_ratio / (1.0f - t_ratio);
symbol->row_height[1] = stripf(t_ratio / (1.0f - t_ratio));
}
}
symbol->row_height[2] = symbol->row_height[0];
symbol->height = symbol->row_height[0] + symbol->row_height[1] + symbol->row_height[2];
symbol->height = stripf(stripf(symbol->row_height[0] + symbol->row_height[1]) + symbol->row_height[2]);
#ifdef COMPLIANT_HEIGHTS
if ((min_height && symbol->height < min_height) || (max_height && symbol->height > max_height)) {
error_number = ZINT_WARN_NONCOMPLIANT;
strcpy(symbol->errtxt, "499: Height not compliant with standards");
if (symbol->output_options & COMPLIANT_HEIGHT) {
if ((min_height && symbol->height < min_height) || (max_height && symbol->height > max_height)) {
error_number = ZINT_WARN_NONCOMPLIANT;
strcpy(symbol->errtxt, "499: Height not compliant with standards");
}
}
#else
(void)min_height; (void)max_height;
#endif
return error_number;
}
/* Handles the 4 State barcodes used in the UK by Royal Mail */
static char rm4scc(unsigned char source[], char dest[], int length) {
static char rm4scc_enc(unsigned char source[], char dest[], int length) {
int i;
int top, bottom, row, column, check_digit;
char values[3], set_copy[] = KRSET;
@ -418,11 +413,11 @@ static char rm4scc(unsigned char source[], char dest[], int length) {
}
/* Puts RM4SCC into the data matrix */
INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[210];
int loopey, h;
int writer;
int error_number;
int error_number = 0;
strcpy(height_pattern, "");
if (length > 50) {
@ -430,12 +425,11 @@ INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(KRSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(KRSET, source, length) != 0) {
strcpy(symbol->errtxt, "489: Invalid character in data (alphanumerics only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/*check = */rm4scc(source, height_pattern, length);
/*check = */rm4scc_enc(source, height_pattern, length);
writer = 0;
h = (int) strlen(height_pattern);
@ -450,21 +444,22 @@ INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int
writer += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* Royal Mail Know How User's Manual Appendix C: using CBC
https://web.archive.org/web/20120120060743/http://www.royalmail.com/sites/default/files/docs/pdf/Know How 2006 PIP vs 1.6a Accepted Changes.pdf
Bar pitch and min/maxes same as Mailmark, so using recommendations from Royal Mail Mailmark Barcode Definition
Document (15 Sept 2015) Section 3.5.1
*/
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Royal Mail Know How User's Manual Appendix C: using CBC
(https://web.archive.org/web/20120120060743/
http://www.royalmail.com/sites/default/files/docs/pdf/Know How 2006 PIP vs 1.6a Accepted Changes.pdf)
Bar pitch and min/maxes same as Mailmark, so using recommendations from
Royal Mail Mailmark Barcode Definition Document (15 Sept 2015) Section 3.5.1
*/
symbol->row_height[0] = stripf((1.9f * 42.3f) / 25.4f); /* ~3.16 */
symbol->row_height[1] = stripf((1.3f * 42.3f) / 25.4f); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, stripf((4.22f * 39) / 25.4f), stripf((5.84f * 47) / 25.4f));
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
(void) daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->width = writer - 1;
@ -474,11 +469,11 @@ INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int
/* Handles Dutch Post TNT KIX symbols
The same as RM4SCC but without check digit
Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[75], localstr[20];
int loopey;
int writer, i, h;
int error_number;
int error_number = 0;
strcpy(height_pattern, "");
if (length > 18) {
@ -486,10 +481,9 @@ INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int le
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(KRSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(KRSET, source, length) != 0) {
strcpy(symbol->errtxt, "491: Invalid character in data (alphanumerics only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
ustrcpy(localstr, source);
@ -512,17 +506,17 @@ INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int le
writer += 2;
}
#ifdef COMPLIANT_HEIGHTS
/* Dimensions same as RM4SCC */
symbol->row_height[0] = (float) ((1.9 * 42.3) / 25.4); /* ~3.16 */
symbol->row_height[1] = (float) ((1.3 * 42.3) / 25.4); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, (float) ((4.22 * 39) / 25.4), (float) ((5.84 * 47) / 25.4));
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Dimensions same as RM4SCC */
symbol->row_height[0] = stripf((1.9f * 42.3f) / 25.4f); /* ~3.16 */
symbol->row_height[1] = stripf((1.3f * 42.3f) / 25.4f); /* ~2.16 */
/* Note using max X for minimum and min X for maximum */
error_number = daft_set_height(symbol, stripf((4.22f * 39) / 25.4f), stripf((5.84f * 47) / 25.4f));
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
(void) daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->width = writer - 1;
@ -530,10 +524,10 @@ INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int le
}
/* Handles DAFT Code symbols */
INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length) {
char height_pattern[100];
unsigned int loopey, h;
int writer, i, error_number;
int writer, i;
strcpy(height_pattern, "");
if (length > 50) {
@ -541,11 +535,10 @@ INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int l
return ZINT_ERROR_TOO_LONG;
}
to_upper(source);
error_number = is_sane(DAFTSET, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(DAFTSET, source, length) != 0) {
strcpy(symbol->errtxt, "493: Invalid character in data (\"D\", \"A\", \"F\" and \"T\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
for (i = 0; i < length; i++) {
@ -578,12 +571,12 @@ INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int l
/* Allow ratio of tracker to be specified in thousandths */
if (symbol->option_2 >= 50 && symbol->option_2 <= 900) {
float t_ratio = symbol->option_2 / 1000.0f;
const float t_ratio = symbol->option_2 / 1000.0f;
if (symbol->height < 0.5f) {
symbol->height = 8.0f;
}
symbol->row_height[1] = symbol->height * t_ratio;
symbol->row_height[0] = (float) ((symbol->height - symbol->row_height[1]) / 2.0);
symbol->row_height[1] = stripf(symbol->height * t_ratio);
symbol->row_height[0] = stripf((symbol->height - symbol->row_height[1]) / 2.0);
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
@ -594,22 +587,21 @@ INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int l
symbol->rows = 3;
symbol->width = writer - 1;
return error_number;
return 0;
}
/* Flattermarken - Not really a barcode symbology! */
INTERNAL int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) {
int loop, error_number;
INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length) {
int loop, error_number = 0;
char dest[512]; /* 90 * 4 + 1 ~ */
if (length > 90) {
strcpy(symbol->errtxt, "494: Input too long (90 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, length) != 0) {
strcpy(symbol->errtxt, "495: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
*dest = '\0';
for (loop = 0; loop < length; loop++) {
@ -624,8 +616,8 @@ INTERNAL int flattermarken(struct zint_symbol *symbol, unsigned char source[], i
}
/* Japanese Postal Code (Kasutama Barcode) */
INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number, h;
INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number = 0, h;
char pattern[69];
int writer, loopey, inter_posn, i, sum, check;
char check_char;
@ -645,7 +637,7 @@ INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int
ustrcpy(local_source, source);
to_upper(local_source);
if (is_sane(SHKASUTSET, local_source, length) == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SHKASUTSET, local_source, length) != 0) {
strcpy(symbol->errtxt, "497: Invalid character in data (alphanumerics and \"-\" only)");
return ZINT_ERROR_INVALID_DATA;
}
@ -722,19 +714,19 @@ INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int
symbol->rows = 3;
symbol->width = writer - 1;
#ifdef COMPLIANT_HEIGHTS
/* Japan Post Zip/Barcode Manual pp.11-12 https://www.post.japanpost.jp/zipcode/zipmanual/p11.html
X 0.6mm (0.5mm - 0.7mm)
Tracker height 1.2mm (1.05mm - 1.35mm) / 0.6mm = 2,
Ascender/descender = 1.2mm (Full 3.6mm (3.4mm - 3.6mm, max preferred) less T divided by 2) / 0.6mm = 2 */
symbol->row_height[0] = 2.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, (float) (3.4 / 0.7) /*~4.857*/, 3.6f / 0.5f /*7.2*/);
#else
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, 0.0f, 0.0f);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Japan Post Zip/Barcode Manual pp.11-12 https://www.post.japanpost.jp/zipcode/zipmanual/p11.html
X 0.6mm (0.5mm - 0.7mm)
Tracker height 1.2mm (1.05mm - 1.35mm) / 0.6mm = 2,
Ascender/descender = 1.2mm (Full 3.6mm (3.4mm - 3.6mm, max preferred) less T divided by 2) / 0.6mm = 2 */
symbol->row_height[0] = 2.0f;
symbol->row_height[1] = 2.0f;
error_number = daft_set_height(symbol, stripf(3.4f / 0.7f) /*~4.857*/, stripf(3.6f / 0.5f) /*7.2*/);
} else {
symbol->row_height[0] = 3.0f;
symbol->row_height[1] = 2.0f;
(void) daft_set_height(symbol, 0.0f, 0.0f);
}
return error_number;
}

View file

@ -1538,7 +1538,7 @@ static int getBinaryLength(const int version, char inputMode[], const unsigned i
return count;
}
INTERNAL int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int qrcode(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, est_binlen, prev_est_binlen;
int ecc_level, autosize, version, max_cw, target_codewords, blocks, size;
int bitmask, gs1;

View file

@ -158,7 +158,7 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const
}
/* Set GTIN-14 human readable text */
static void rss_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int src_len) {
static void dbar_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int src_len) {
int i;
unsigned char *hrt = symbol->text + 4;
@ -175,7 +175,7 @@ static void rss_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *
}
/* Expand from a width pattern to a bit pattern */
static int rss_expand(struct zint_symbol *symbol, int writer, int *p_latch, const int width) {
static int dbar_expand(struct zint_symbol *symbol, int writer, int *p_latch, const int width) {
int j;
int latch = *p_latch;
@ -194,7 +194,7 @@ static int rss_expand(struct zint_symbol *symbol, int writer, int *p_latch, cons
}
/* Adjust top/bottom separator for finder patterns */
static void rss14_finder_adjust(struct zint_symbol *symbol, const int separator_row, const int above_below,
static void dbar_omn_finder_adjust(struct zint_symbol *symbol, const int separator_row, const int above_below,
const int finder_start) {
int i, finder_end;
int module_row = separator_row + above_below;
@ -219,7 +219,7 @@ static void rss14_finder_adjust(struct zint_symbol *symbol, const int separator_
}
/* Top/bottom separator for DataBar */
static void rss14_separator(struct zint_symbol *symbol, int width, const int separator_row, const int above_below,
static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int separator_row, const int above_below,
const int finder_start, const int finder2_start, const int bottom_finder_value_3) {
int i, finder_end, finder_value_3_set;
int module_row = separator_row + above_below;
@ -242,16 +242,16 @@ static void rss14_separator(struct zint_symbol *symbol, int width, const int sep
}
} else {
if (finder_start) {
rss14_finder_adjust(symbol, separator_row, above_below, finder_start);
dbar_omn_finder_adjust(symbol, separator_row, above_below, finder_start);
}
if (finder2_start) {
rss14_finder_adjust(symbol, separator_row, above_below, finder2_start);
dbar_omn_finder_adjust(symbol, separator_row, above_below, finder2_start);
}
}
}
/* Set Databar Stacked height, maintaining 5:7 ratio of the 2 main row heights */
INTERNAL int rss14_stk_set_height(struct zint_symbol *symbol, const int first_row) {
INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row) {
int error_number = 0;
float fixed_height = 0.0f;
int second_row = first_row + 2; /* 2 row separator */
@ -263,33 +263,33 @@ INTERNAL int rss14_stk_set_height(struct zint_symbol *symbol, const int first_ro
}
}
if (symbol->height) {
symbol->row_height[first_row] = (symbol->height - fixed_height) * symbol->row_height[first_row] /
(symbol->row_height[first_row] + symbol->row_height[second_row]);
symbol->row_height[first_row] = stripf((symbol->height - fixed_height) * symbol->row_height[first_row] /
(symbol->row_height[first_row] + symbol->row_height[second_row]));
if (symbol->row_height[first_row] < 0.5f) { /* Absolute minimum */
symbol->row_height[first_row] = 0.5f;
symbol->row_height[second_row] = 0.7f;
} else {
symbol->row_height[second_row] = symbol->height - fixed_height - symbol->row_height[first_row];
symbol->row_height[second_row] = stripf(symbol->height - fixed_height - symbol->row_height[first_row]);
if (symbol->row_height[second_row] < 0.7f) {
symbol->row_height[second_row] = 0.7f;
}
}
}
symbol->height = symbol->row_height[first_row] + symbol->row_height[second_row] + fixed_height;
symbol->height = stripf(stripf(symbol->row_height[first_row] + symbol->row_height[second_row]) + fixed_height);
#ifdef COMPLIANT_HEIGHTS
if (symbol->row_height[first_row] < 5.0f || symbol->row_height[second_row] < 7.0f) {
error_number = ZINT_WARN_NONCOMPLIANT;
strcpy(symbol->errtxt, "379: Height not compliant with standards");
if (symbol->output_options & COMPLIANT_HEIGHT) {
if (symbol->row_height[first_row] < 5.0f || symbol->row_height[second_row] < 7.0f) {
error_number = ZINT_WARN_NONCOMPLIANT;
strcpy(symbol->errtxt, "379: Height not compliant with standards");
}
}
#endif
return error_number;
}
/* GS1 DataBar Omnidirectional/Truncated/Stacked, allowing for composite if `cc_rows` set */
INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
int error_number, i;
INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
int error_number = 0, i;
large_int accum;
uint64_t left_pair, right_pair;
int data_character[4] = {0}, data_group[4] = {0}, v_odd[4], v_even[4];
@ -304,10 +304,9 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
strcpy(symbol->errtxt, "380: Input too long (14 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, src_len) != 0) {
strcpy(symbol->errtxt, "381: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if (src_len == 14) { /* Verify check digit */
@ -405,7 +404,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
v_odd[2] = (data_character[2] - g_sum_table[data_group[2]]) / t_table[data_group[2]];
v_even[2] = (data_character[2] - g_sum_table[data_group[2]]) % t_table[data_group[2]];
/* Use RSS subset width algorithm */
/* Use DataBar subset width algorithm */
for (i = 0; i < 4; i++) {
if ((i == 0) || (i == 2)) {
getRSSwidths(widths, v_odd[i], modules_odd[data_group[i]], 4, widest_odd[data_group[i]], 1);
@ -477,42 +476,42 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
writer = 0;
latch = 0;
for (i = 0; i < 46; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
if (symbol->width < writer) {
symbol->width = writer;
}
if (symbol->symbology == BARCODE_DBAR_OMN_CC) {
/* separator pattern for composite symbol */
rss14_separator(symbol, 96, separator_row, 1 /*above*/, 18, 63, 0 /*bottom_finder_value_3*/);
dbar_omn_separator(symbol, 96, separator_row, 1 /*above*/, 18, 63, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
/* Set human readable text */
rss_set_gtin14_hrt(symbol, source, src_len);
dbar_set_gtin14_hrt(symbol, source, src_len);
#ifdef COMPLIANT_HEIGHTS
/* Minimum height is 13X for truncated symbol ISO/IEC 24724:2011 5.3.1
Default height is 33X for DataBar Omnidirectional ISO/IEC 24724:2011 5.2 */
if (symbol->symbology == BARCODE_DBAR_OMN_CC) {
symbol->height = symbol->height ? 13.0f : 33.0f; /* Pass back min row or default height */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Minimum height is 13X for truncated symbol ISO/IEC 24724:2011 5.3.1
Default height is 33X for DataBar Omnidirectional ISO/IEC 24724:2011 5.2 */
if (symbol->symbology == BARCODE_DBAR_OMN_CC) {
symbol->height = symbol->height ? 13.0f : 33.0f; /* Pass back min row or default height */
} else {
error_number = set_height(symbol, 13.0f, 33.0f, 0.0f, 0 /*no_errtxt*/);
}
} else {
error_number = set_height(symbol, 13.0f, 33.0f, 0.0f, 0 /*no_errtxt*/);
if (symbol->symbology == BARCODE_DBAR_OMN_CC) {
symbol->height = 14.0f; /* 14X truncated min row height used (should be 13X) */
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
#else
if (symbol->symbology == BARCODE_DBAR_OMN_CC) {
symbol->height = 14.0f; /* 14X truncated min row height used (should be 13X) */
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
#endif
} else if ((symbol->symbology == BARCODE_DBAR_STK) || (symbol->symbology == BARCODE_DBAR_STK_CC)) {
/* top row */
writer = 0;
latch = 0;
for (i = 0; i < 23; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
set_module(symbol, symbol->rows, writer);
unset_module(symbol, symbol->rows, writer + 1);
@ -525,7 +524,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
writer = 2;
latch = 1;
for (i = 23; i < 46; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
symbol->row_height[symbol->rows] = 7.0f; /* ISO/IEC 24724:2011 5.3.2.1 set to 7X */
@ -549,15 +548,15 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
if (symbol->symbology == BARCODE_DBAR_STK_CC) {
/* separator pattern for composite symbol */
rss14_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
dbar_omn_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
if (symbol->width < 50) {
symbol->width = 50;
}
if (symbol->symbology != BARCODE_DBAR_STK_CC) { /* Composite calls rss14_stk_set_height() itself */
error_number = rss14_stk_set_height(symbol, 0 /*first_row*/);
if (symbol->symbology != BARCODE_DBAR_STK_CC) { /* Composite calls dbar_omnstk_set_height() itself */
error_number = dbar_omnstk_set_height(symbol, 0 /*first_row*/);
}
} else if ((symbol->symbology == BARCODE_DBAR_OMNSTK) || (symbol->symbology == BARCODE_DBAR_OMNSTK_CC)) {
@ -565,7 +564,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
writer = 0;
latch = 0;
for (i = 0; i < 23; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
set_module(symbol, symbol->rows, writer);
unset_module(symbol, symbol->rows, writer + 1);
@ -577,7 +576,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
writer = 2;
latch = 1;
for (i = 23; i < 46; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
/* middle separator */
@ -587,12 +586,12 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
symbol->row_height[symbol->rows - 2] = 1;
/* top separator */
rss14_separator(symbol, 50, symbol->rows - 3, -1 /*below*/, 18, 0, 0 /*bottom_finder_value_3*/);
dbar_omn_separator(symbol, 50, symbol->rows - 3, -1 /*below*/, 18, 0, 0 /*bottom_finder_value_3*/);
symbol->row_height[symbol->rows - 3] = 1;
/* bottom separator */
/* 17 == 2 (guard) + 15 (inner char); +2 to skip over finder elements 4 & 5 (right to left) */
rss14_separator(symbol, 50, symbol->rows - 1, 1 /*above*/, 17 + 2, 0, c_right == 3);
dbar_omn_separator(symbol, 50, symbol->rows - 1, 1 /*above*/, 17 + 2, 0, c_right == 3);
symbol->row_height[symbol->rows - 1] = 1;
if (symbol->width < 50) {
symbol->width = 50;
@ -600,7 +599,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
if (symbol->symbology == BARCODE_DBAR_OMNSTK_CC) {
/* separator pattern for composite symbol */
rss14_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
dbar_omn_separator(symbol, 50, separator_row, 1 /*above*/, 18, 0, 0 /*bottom_finder_value_3*/);
}
symbol->rows = symbol->rows + 1;
@ -608,11 +607,11 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
if (symbol->symbology == BARCODE_DBAR_OMNSTK_CC) {
symbol->height = symbol->height ? 33.0f : 66.0f; /* Pass back min row or default height */
} else {
#ifdef COMPLIANT_HEIGHTS
error_number = set_height(symbol, 33.0f, 66.0f, 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 66.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
error_number = set_height(symbol, 33.0f, 66.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 66.0f, 0.0f, 1 /*no_errtxt*/);
}
}
}
@ -620,13 +619,13 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
}
/* GS1 DataBar Omnidirectional/Truncated/Stacked */
INTERNAL int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return rss14_cc(symbol, source, src_len, 0 /*cc_rows*/);
INTERNAL int dbar_omn(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return dbar_omn_cc(symbol, source, src_len, 0 /*cc_rows*/);
}
/* GS1 DataBar Limited, allowing for composite if `cc_rows` set */
INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
int error_number, i;
INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
int error_number = 0, i;
large_int accum;
uint64_t left_character, right_character;
int left_group, right_group, left_odd, left_even, right_odd, right_even;
@ -642,10 +641,9 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i
strcpy(symbol->errtxt, "382: Input too long (14 character maximum)");
return ZINT_ERROR_TOO_LONG;
}
error_number = is_sane(NEON, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, src_len) != 0) {
strcpy(symbol->errtxt, "383: Invalid character in data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
if (src_len == 14) { /* Verify check digit */
@ -778,7 +776,7 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i
writer = 0;
latch = 0;
for (i = 0; i < 47; i++) {
writer = rss_expand(symbol, writer, &latch, total_widths[i]);
writer = dbar_expand(symbol, writer, &latch, total_widths[i]);
}
if (symbol->width < writer) {
symbol->width = writer;
@ -795,29 +793,29 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i
}
/* Set human readable text */
rss_set_gtin14_hrt(symbol, source, src_len);
dbar_set_gtin14_hrt(symbol, source, src_len);
/* ISO/IEC 24724:2011 6.2 10X minimum height, use as default also */
if (symbol->symbology == BARCODE_DBAR_LTD_CC) {
symbol->height = 10.0f; /* Pass back min row == default height */
} else {
#ifdef COMPLIANT_HEIGHTS
error_number = set_height(symbol, 10.0f, 10.0f, 0.0f, 0 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
error_number = set_height(symbol, 10.0f, 10.0f, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
}
return error_number;
}
/* GS1 DataBar Limited */
INTERNAL int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return rsslimited_cc(symbol, source, src_len, 0 /*cc_rows*/);
INTERNAL int dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return dbar_ltd_cc(symbol, source, src_len, 0 /*cc_rows*/);
}
/* Check and convert date to RSS date value */
INTERNAL int rss_date(const unsigned char source[], const int src_posn) {
/* Check and convert date to DataBar date value */
INTERNAL int dbar_date(const unsigned char source[], const int src_posn) {
int yy = to_int(source + src_posn, 2);
int mm = to_int(source + src_posn + 2, 2);
int dd = to_int(source + src_posn + 4, 2);
@ -831,7 +829,7 @@ INTERNAL int rss_date(const unsigned char source[], const int src_posn) {
}
/* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */
static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char source[], char binary_string[],
static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned char source[], char binary_string[],
int cols_per_row, int *p_bp) {
int encoding_method, i, j, read_posn, debug = (symbol->debug & ZINT_DEBUG_PRINT), mode = NUMERIC;
char last_digit = '\0';
@ -884,7 +882,7 @@ static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char
} else if ((length == 34) && (source[26] == '1')
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& rss_date(source, 28) >= 0) {
&& dbar_date(source, 28) >= 0) {
/* (01), (310x) and (11) - metric weight and production date */
/* (01), (310x) and (13) - metric weight and packaging date */
@ -915,7 +913,7 @@ static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char
} else if ((length == 34) && (source[26] == '1')
&& (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
&& rss_date(source, 28) >= 0) {
&& dbar_date(source, 28) >= 0) {
/* (01), (320x) and (11) - English weight and production date */
/* (01), (320x) and (13) - English weight and packaging date */
@ -1045,7 +1043,7 @@ static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char
if (length == 34) {
/* Date information is included */
group_val = rss_date(source, 28);
group_val = dbar_date(source, 28);
} else {
group_val = 38400;
}
@ -1172,7 +1170,7 @@ static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char
}
/* Separator for DataBar Expanded Stacked and DataBar Expanded Composite */
static void rssexp_separator(struct zint_symbol *symbol, int width, const int cols, const int separator_row,
static void dbar_exp_separator(struct zint_symbol *symbol, int width, const int cols, const int separator_row,
const int above_below, const int special_case_row, const int left_to_right, const int odd_last_row,
int *p_v2_latch) {
int i, i_start, i_end, j, k;
@ -1239,7 +1237,7 @@ static void rssexp_separator(struct zint_symbol *symbol, int width, const int co
}
/* GS1 DataBar Expanded, setting linkage for composite if `cc_rows` set */
INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, const int cc_rows) {
int error_number, warn_number = 0;
int i, j, k, p, codeblocks, data_chars, vs, group, v_odd, v_even;
int latch;
@ -1298,7 +1296,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
}
}
error_number = rssexp_binary_string(symbol, reduced, binary_string, cols_per_row, &bp);
error_number = dbar_exp_binary_string(symbol, reduced, binary_string, cols_per_row, &bp);
if (error_number != 0) {
return error_number;
}
@ -1431,7 +1429,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
writer = 0;
latch = 0;
for (i = 0; i < pattern_width; i++) {
writer = rss_expand(symbol, writer, &latch, elements[i]);
writer = dbar_expand(symbol, writer, &latch, elements[i]);
}
if (symbol->width < writer) {
symbol->width = writer;
@ -1534,7 +1532,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
writer = 0;
for (i = 0; i < elements_in_sub; i++) {
writer = rss_expand(symbol, writer, &latch, sub_elements[i]);
writer = dbar_expand(symbol, writer, &latch, sub_elements[i]);
}
if (symbol->width < writer) {
symbol->width = writer;
@ -1550,14 +1548,14 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
symbol->row_height[symbol->rows - 2] = 1;
/* bottom separator pattern (above current row) */
rssexp_separator(symbol, writer, reader, symbol->rows - 1, 1 /*above*/, special_case_row,
dbar_exp_separator(symbol, writer, reader, symbol->rows - 1, 1 /*above*/, special_case_row,
left_to_right, odd_last_row, &v2_latch);
symbol->row_height[symbol->rows - 1] = 1;
}
if (current_row != stack_rows) {
/* top separator pattern (below current row) */
rssexp_separator(symbol, writer, reader, symbol->rows + 1, -1 /*below*/, 0 /*special_case_row*/,
dbar_exp_separator(symbol, writer, reader, symbol->rows + 1, -1 /*below*/, 0 /*special_case_row*/,
left_to_right, 0 /*odd_last_row*/, &v2_latch);
symbol->row_height[symbol->rows + 1] = 1;
}
@ -1569,7 +1567,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
if (symbol->symbology == BARCODE_DBAR_EXP_CC || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) {
/* Composite separator */
rssexp_separator(symbol, symbol->width, 4, separator_row, 1 /*above*/, 0 /*special_case_row*/,
dbar_exp_separator(symbol, symbol->width, 4, separator_row, 1 /*above*/, 0 /*special_case_row*/,
1 /*left_to_right*/, 0 /*odd_last_row*/, NULL);
}
@ -1578,21 +1576,21 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
if (symbol->symbology == BARCODE_DBAR_EXP_CC || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) {
symbol->height = symbol->height ? 34.0f : 34.0f * stack_rows; /* Pass back min row or default height */
} else {
#ifdef COMPLIANT_HEIGHTS
if (warn_number) {
(void) set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/);
if (symbol->output_options & COMPLIANT_HEIGHT) {
if (warn_number) {
(void) set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/);
} else {
warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/);
}
} else {
warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/);
(void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/);
}
#else
(void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/);
#endif
}
return error_number ? error_number : warn_number;
}
/* GS1 DataBar Expanded */
INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return rssexpanded_cc(symbol, source, src_len, 0 /*cc_rows*/);
INTERNAL int dbar_exp(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return dbar_exp_cc(symbol, source, src_len, 0 /*cc_rows*/);
}

View file

@ -40,22 +40,38 @@
#include "common.h"
static char *TeleTable[] = {
"31313131", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
"31333111", "1131113131", "33113131", "1111333111", "3111113131", "1113133111", "1311133111", "111111113131",
"3131113111", "11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
"31131331", "113111113111", "3311113111", "1111131331", "311111113111", "1113111331", "1311111331", "11111111113111",
"31313311", "1131311131", "33311131", "1111313311", "3111311131", "11333311", "13133311", "111111311131",
"31331131", "1131113311", "33113311", "1111331131", "3111113311", "1113131131", "1311131131", "111111113311",
"3131111131", "1131131311", "33131311", "111131111131", "3111131311", "1133111131", "1313111131", "111111131311",
"3113111311", "113111111131", "3311111131", "111113111311", "311111111131", "111311111311", "131111111311", "11111111111131",
"3131311111", "11313133", "333133", "111131311111", "31113133", "1133311111", "1313311111", "1111113133",
"313333", "113111311111", "3311311111", "11113333", "311111311111", "11131333", "13111333", "11111111311111",
"31311133", "1131331111", "33331111", "1111311133", "3111331111", "11331133", "13131133", "111111331111",
"3113131111", "1131111133", "33111133", "111113131111", "3111111133", "111311131111", "131111131111", "111111111133",
"31311313", "113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313", "11111131111111",
"3133111111", "1131111313", "33111313", "111133111111", "3111111313", "111313111111", "131113111111", "111111111313",
"313111111111", "1131131113", "33131113", "11113111111111", "3111131113", "113311111111", "131311111111", "111111131113",
"3113111113", "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113", "1111111111111111",
"31313131", "1131313111", "33313111", "1111313131",
"3111313111", "11333131", "13133131", "111111313111",
"31333111", "1131113131", "33113131", "1111333111",
"3111113131", "1113133111", "1311133111", "111111113131",
"3131113111", "11313331", "333331", "111131113111",
"31113331", "1133113111", "1313113111", "1111113331",
"31131331", "113111113111", "3311113111", "1111131331",
"311111113111", "1113111331", "1311111331", "11111111113111",
"31313311", "1131311131", "33311131", "1111313311",
"3111311131", "11333311", "13133311", "111111311131",
"31331131", "1131113311", "33113311", "1111331131",
"3111113311", "1113131131", "1311131131", "111111113311",
"3131111131", "1131131311", "33131311", "111131111131",
"3111131311", "1133111131", "1313111131", "111111131311",
"3113111311", "113111111131", "3311111131", "111113111311",
"311111111131", "111311111311", "131111111311", "11111111111131",
"3131311111", "11313133", "333133", "111131311111",
"31113133", "1133311111", "1313311111", "1111113133",
"313333", "113111311111", "3311311111", "11113333",
"311111311111", "11131333", "13111333", "11111111311111",
"31311133", "1131331111", "33331111", "1111311133",
"3111331111", "11331133", "13131133", "111111331111",
"3113131111", "1131111133", "33111133", "111113131111",
"3111111133", "111311131111", "131111131111", "111111111133",
"31311313", "113131111111", "3331111111", "1111311313",
"311131111111", "11331313", "13131313", "11111131111111",
"3133111111", "1131111313", "33111313", "111133111111",
"3111111313", "111313111111", "131113111111", "111111111313",
"313111111111", "1131131113", "33131113", "11113111111111",
"3111131113", "113311111111", "131311111111", "111111131113",
"3113111113", "11311111111111", "331111111111", "111113111113",
"31111111111111", "111311111113", "131111111113", "1111111111111111",
};
INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) {
@ -97,13 +113,13 @@ INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int src
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
/* Default height from various Telepen docs is based on default 26pt at X 0.01125" (average of 0.01" - 0.0125")
= (26 / 72) / 0.01125 ~ 32; no min height specified */
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/);
#else
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* Default height from various Telepen docs is based on default 26pt at X 0.01125"
(average of 0.01" - 0.0125") = (26 / 72) / 0.01125 ~ 32; no min height specified */
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
}
for (i = 0; i < src_len; i++) {
if (source[i] == '\0') {
@ -118,7 +134,7 @@ INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int src
INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) {
int count, check_digit, glyph;
int error_number;
int error_number = 0;
int i;
char dest[521]; /* 12 (start) + 30 * 16 (max for DELs) + 16 (check digit) + 12 (stop) + 1 = 521 */
unsigned char temp[64];
@ -131,10 +147,9 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int
}
ustrcpy(temp, source);
to_upper(temp);
error_number = is_sane(SODIUM, temp, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SODIUM, temp, src_len) != 0) {
strcpy(symbol->errtxt, "393: Invalid character in data (digits and \"X\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Add a leading zero if required */
@ -178,11 +193,11 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int
expand(symbol, dest);
#ifdef COMPLIANT_HEIGHTS
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */
#else
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
}
ustrcpy(symbol->text, temp);
return error_number;

View file

@ -150,10 +150,10 @@ static void test_input(int index, int debug) {
/* 3*/ { BARCODE_AUSPOST, "12345678ABcd!", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 404: Invalid character in data (alphanumerics, space and \"#\" only)" },
/* 4*/ { BARCODE_AUSPOST, "12345678ABcd#", 0, 3, 103, "" },
/* 5*/ { BARCODE_AUSPOST, "1234567890123456", 0, 3, 103, "" },
/* 6*/ { BARCODE_AUSPOST, "123456789012345A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character in data (digits only for lengths 16 and 23)" },
/* 6*/ { BARCODE_AUSPOST, "123456789012345A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character in data (digits only for length 16)" },
/* 7*/ { BARCODE_AUSPOST, "12345678ABCDefgh #", 0, 3, 133, "" }, // Length 18
/* 8*/ { BARCODE_AUSPOST, "12345678901234567890123", 0, 3, 133, "" },
/* 9*/ { BARCODE_AUSPOST, "1234567890123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 402: Invalid character in data (digits only for lengths 16 and 23)" },
/* 9*/ { BARCODE_AUSPOST, "1234567890123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 406: Invalid character in data (digits only for length 23)" },
/* 10*/ { BARCODE_AUSPOST, "1234567", ZINT_ERROR_TOO_LONG, -1, -1, "Error 401: Auspost input is wrong length (8, 13, 16, 18 or 23 characters only)" }, // No leading zeroes added
/* 11*/ { BARCODE_AUSREPLY, "12345678", 0, 3, 73, "" },
/* 12*/ { BARCODE_AUSREPLY, "1234567", 0, 3, 73, "" }, // Leading zeroes added

View file

@ -270,7 +270,8 @@ static void test_input(int index, int debug) {
/* 32*/ { -1, -1, -1, { 0, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 712: Structured Append index out of range (1-2)", },
/* 33*/ { -1, -1, -1, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 712: Structured Append index out of range (1-2)", },
/* 34*/ { -1, -1, -1, { 1, 2, "1" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 713: Structured Append ID not available for Code One", },
/* 35*/ { -1, -1, 9, { 1, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not supported for Version S", },
/* 35*/ { -1, -1, 9, { 1, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", },
/* 36*/ { -1, -1, 9, { 3, 2, "" }, "123456789012ABCDEFGHI", -1, ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 714: Structured Append not available for Version S", }, // Trumps other checking
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;

View file

@ -471,10 +471,10 @@ static void test_cap(int index) {
/* 0*/ { BARCODE_CODE128, ZINT_CAP_HRT, ZINT_CAP_HRT },
/* 1*/ { BARCODE_CODE128, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_GS1, ZINT_CAP_HRT | ZINT_CAP_STACKABLE },
/* 2*/ { BARCODE_PDF417, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE, ZINT_CAP_ECI | ZINT_CAP_READER_INIT },
/* 3*/ { BARCODE_QRCODE, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP, ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP },
/* 4*/ { BARCODE_EANX_CC, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES },
/* 3*/ { BARCODE_QRCODE, ZINT_CAP_HRT | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP },
/* 4*/ { BARCODE_EANX_CC, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT, ZINT_CAP_HRT | ZINT_CAP_COMPOSITE | ZINT_CAP_EXTENDABLE | ZINT_CAP_GS1 | ZINT_CAP_QUIET_ZONES | ZINT_CAP_COMPLIANT_HEIGHT },
/* 5*/ { BARCODE_HANXIN, ZINT_CAP_DOTTY | ZINT_CAP_QUIET_ZONES | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK },
/* 6*/ { BARCODE_CODE11, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE, 0 },
/* 6*/ { BARCODE_CODE11, ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_COMPLIANT_HEIGHT, 0 },
/* 7*/ { BARCODE_POSTNET, ZINT_CAP_HRT | ZINT_CAP_STACKABLE | ZINT_CAP_EXTENDABLE | ZINT_CAP_COMPOSITE | ZINT_CAP_ECI | ZINT_CAP_GS1 | ZINT_CAP_DOTTY | ZINT_CAP_FIXED_RATIO | ZINT_CAP_READER_INIT | ZINT_CAP_FULL_MULTIBYTE | ZINT_CAP_MASK | ZINT_CAP_STRUCTAPP, 0 },
/* 8*/ { 0, 0, 0 },
};
@ -495,6 +495,95 @@ static void test_cap(int index) {
testFinish();
}
static void test_cap_compliant_height() {
int symbol_id;
int ret;
testStart("test_cap_compliant_height");
for (symbol_id = 1; symbol_id <= BARCODE_RMQR; symbol_id++) {
if (!ZBarcode_ValidID(symbol_id)) continue;
ret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT);
switch (symbol_id) {
//case BARCODE_CODE11: /* TODO: Find doc */
case BARCODE_C25INTER:
case BARCODE_CODE39:
case BARCODE_EXCODE39:
case BARCODE_EANX:
case BARCODE_EANX_CHK:
case BARCODE_GS1_128:
case BARCODE_CODABAR:
//case BARCODE_DPLEIT: /* TODO: Find doc */
//case BARCODE_DPIDENT: /* TODO: Find doc */
case BARCODE_CODE16K:
case BARCODE_CODE49:
case BARCODE_CODE93:
//case BARCODE_FLAT: /* TODO: Find doc */
case BARCODE_DBAR_OMN:
case BARCODE_DBAR_LTD:
case BARCODE_DBAR_EXP:
case BARCODE_TELEPEN:
case BARCODE_UPCA:
case BARCODE_UPCA_CHK:
case BARCODE_UPCE:
case BARCODE_UPCE_CHK:
case BARCODE_POSTNET:
//case BARCODE_MSI_PLESSEY: /* TODO: Find doc */
case BARCODE_FIM:
case BARCODE_LOGMARS:
case BARCODE_PHARMA:
case BARCODE_PZN:
case BARCODE_PHARMA_TWO:
case BARCODE_AUSPOST:
case BARCODE_AUSREPLY:
case BARCODE_AUSROUTE:
case BARCODE_AUSREDIRECT:
case BARCODE_ISBNX:
case BARCODE_RM4SCC:
case BARCODE_EAN14:
//case BARCODE_VIN: /* Spec unlikely */
case BARCODE_CODABLOCKF:
case BARCODE_NVE18:
case BARCODE_JAPANPOST:
//case BARCODE_KOREAPOST: /* TODO: Find doc */
case BARCODE_DBAR_STK:
case BARCODE_DBAR_OMNSTK:
case BARCODE_DBAR_EXPSTK:
case BARCODE_PLANET:
case BARCODE_USPS_IMAIL:
//case BARCODE_PLESSEY: /* TODO: Find doc */
case BARCODE_TELEPEN_NUM:
case BARCODE_ITF14:
case BARCODE_KIX:
case BARCODE_DPD:
case BARCODE_HIBC_39:
case BARCODE_HIBC_BLOCKF:
case BARCODE_MAILMARK:
case BARCODE_CODE32:
case BARCODE_EANX_CC:
case BARCODE_GS1_128_CC:
case BARCODE_DBAR_OMN_CC:
case BARCODE_DBAR_LTD_CC:
case BARCODE_DBAR_EXP_CC:
case BARCODE_UPCA_CC:
case BARCODE_UPCE_CC:
case BARCODE_DBAR_STK_CC:
case BARCODE_DBAR_OMNSTK_CC:
case BARCODE_DBAR_EXPSTK_CC:
case BARCODE_CHANNEL:
assert_equal(ret, ZINT_CAP_COMPLIANT_HEIGHT, "symbol_id %d (%s) ret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n", symbol_id, testUtilBarcodeName(symbol_id), ret);
break;
default:
assert_zero(ret, "symbol_id %d (%s) ret 0x%X non-zero\n", symbol_id, testUtilBarcodeName(symbol_id), ret);
break;
}
}
testFinish();
}
static void test_encode_file_empty(void) {
int ret;
struct zint_symbol *symbol;
@ -950,6 +1039,7 @@ int main(int argc, char *argv[]) {
{ "test_input_mode", test_input_mode, 1, 0, 1 },
{ "test_escape_char_process", test_escape_char_process, 1, 1, 1 },
{ "test_cap", test_cap, 1, 0, 0 },
{ "test_cap_compliant_height", test_cap_compliant_height, 0, 0, 0 },
{ "test_encode_file_empty", test_encode_file_empty, 0, 0, 0 },
{ "test_encode_file_too_large", test_encode_file_too_large, 0, 0, 0 },
{ "test_encode_file_unreadable", test_encode_file_unreadable, 0, 0, 0 },

View file

@ -103,10 +103,13 @@ static void test_hrt(int index, int debug) {
/* 0*/ { BARCODE_CODABAR, -1, "A1234B", "A1234B" },
/* 1*/ { BARCODE_CODABAR, -1, "a1234c", "A1234C" }, // Converts to upper
/* 2*/ { BARCODE_CODABAR, 1, "A1234B", "A1234B" }, // Check not included
/* 3*/ { BARCODE_PHARMA, -1, "123456", "" }, // None
/* 4*/ { BARCODE_PHARMA_TWO, -1, "123456", "" }, // None
/* 5*/ { BARCODE_CODE32, -1, "123456", "A001234564" },
/* 6*/ { BARCODE_CODE32, -1, "12345678", "A123456788" },
/* 3*/ { BARCODE_CODABAR, 2, "A1234B", "A12345B" }, // Check included
/* 4*/ { BARCODE_CODABAR, 1, "A123456A", "A123456A" }, // Check not included
/* 5*/ { BARCODE_CODABAR, 2, "A123456A", "A123456$A" }, // Check included
/* 6*/ { BARCODE_PHARMA, -1, "123456", "" }, // None
/* 7*/ { BARCODE_PHARMA_TWO, -1, "123456", "" }, // None
/* 8*/ { BARCODE_CODE32, -1, "123456", "A001234564" },
/* 9*/ { BARCODE_CODE32, -1, "12345678", "A123456788" },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -648,6 +648,7 @@ const char *testUtilOutputOptionsName(int output_options) {
{ "OUT_BUFFER_INTERMEDIATE", OUT_BUFFER_INTERMEDIATE, 1024 },
{ "BARCODE_QUIET_ZONES", BARCODE_QUIET_ZONES, 2048 },
{ "BARCODE_NO_QUIET_ZONES", BARCODE_NO_QUIET_ZONES, 4096 },
{ "COMPLIANT_HEIGHT", COMPLIANT_HEIGHT, 0x2000 },
};
static int const data_size = ARRAY_SIZE(data);
int set = 0;

View file

@ -872,7 +872,7 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c
return codeword_count;
}
INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int length) {
INTERNAL int ultra(struct zint_symbol *symbol, unsigned char source[], int length) {
int data_cw_count = 0;
int acc, qcc;
int scr[3] = {0}, scr_cw_count = 0; /* Symbol Control Region (only if have Structured Append) */

View file

@ -30,9 +30,9 @@
*/
/* vim: set ts=4 sw=4 et : */
#define SODIUM "0123456789+"
#define ISBN_SANE "0123456789X"
#define ISBN_ADDON_SANE "0123456789Xx+"
#define SODIUM "0123456789+"
#define ISBNX_SANE "0123456789X"
#define ISBNX_ADDON_SANE "0123456789Xx+"
#define EAN2 102
#define EAN5 105
@ -108,7 +108,6 @@ static void upca_draw(const unsigned char source[], const int length, char dest[
/* Make a UPC-A barcode, allowing for composite if `cc_rows` set */
static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) {
unsigned char *gtin = symbol->text;
float height;
int error_number = 0;
ustrcpy(gtin, source);
@ -130,23 +129,23 @@ static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int
upca_draw(gtin, length, dest);
#ifdef COMPLIANT_HEIGHTS
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
height = (float) (22.85 / 0.33);
if (symbol->symbology == BARCODE_UPCA_CC) {
symbol->height = height; /* Pass back min row == default height */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
const float height = stripf(22.85f / 0.33f);
if (symbol->symbology == BARCODE_UPCA_CC) {
symbol->height = height; /* Pass back min row == default height */
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
}
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
const float height = 50.0f;
if (symbol->symbology == BARCODE_UPCA_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
}
#else
height = 50.0f;
if (symbol->symbology == BARCODE_UPCA_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
@ -163,7 +162,6 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
char src_check_digit = '\0';
unsigned char equivalent[12];
unsigned char *hrt = symbol->text;
float height;
int error_number = 0;
if (length == 8 || symbol->symbology == BARCODE_UPCE_CHK) {
@ -297,23 +295,23 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
printf("UPC-E: %s, equivalent: %s, hrt: %s, Check digit: %c\n", source, equivalent, hrt, check_digit);
}
#ifdef COMPLIANT_HEIGHTS
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
height = (float) (22.85 / 0.33);
if (symbol->symbology == BARCODE_UPCE_CC) {
symbol->height = height; /* Pass back min row == default height */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
const float height = stripf(22.85f / 0.33f);
if (symbol->symbology == BARCODE_UPCE_CC) {
symbol->height = height; /* Pass back min row == default height */
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
}
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
const float height = 50.0f;
if (symbol->symbology == BARCODE_UPCE_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
}
#else
height = 50.0f;
if (symbol->symbology == BARCODE_UPCE_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
@ -390,7 +388,6 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in
int i, half_way;
char parity[6];
unsigned char *gtin = symbol->text;
float height;
int error_number = 0;
parity[0] = '\0';
@ -437,23 +434,23 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in
/* stop character */
strcat(dest, "111");
#ifdef COMPLIANT_HEIGHTS
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
height = (float) (22.85 / 0.33);
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height; /* Pass back min row == default height */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 22.85mm / 0.33mm (X) ~ 69.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
const float height = stripf(22.85f / 0.33f);
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height; /* Pass back min row == default height */
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
}
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
const float height = 50.0f;
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
}
#else
height = 50.0f;
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
@ -465,7 +462,6 @@ static int ean13(struct zint_symbol *symbol, const unsigned char source[], int l
static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) {
/* EAN-8 is basically the same as UPC-A but with fewer digits */
unsigned char *gtin = symbol->text;
float height;
int error_number = 0;
ustrcpy(gtin, source);
@ -487,23 +483,23 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int
upca_draw(gtin, length, dest);
#ifdef COMPLIANT_HEIGHTS
/* BS EN 797:1996 4.5.1 Nominal dimensions 18.23mm / 0.33mm (X) ~ 55.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
height = (float) (18.23 / 0.33);
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height; /* Pass back min row == default height */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* BS EN 797:1996 4.5.1 Nominal dimensions 18.23mm / 0.33mm (X) ~ 55.24,
same as minimum GS1 General Specifications 21.0.1 5.12.3.1 */
const float height = stripf(18.23f / 0.33f);
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height; /* Pass back min row == default height */
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
}
} else {
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
const float height = 50.0f;
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
}
#else
height = 50.0f;
if (symbol->symbology == BARCODE_EANX_CC) {
symbol->height = height - cc_rows * 2 - 6.0f;
} else {
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
}
#endif
return error_number;
}
@ -514,7 +510,7 @@ static int ean8(struct zint_symbol *symbol, const unsigned char source[], int le
}
/* For ISBN(10) and SBN only */
static char isbn_check(const unsigned char source[], const int length) {
static char isbnx_check(const unsigned char source[], const int length) {
int i, weight, sum, check;
char check_char;
@ -535,15 +531,14 @@ static char isbn_check(const unsigned char source[], const int length) {
}
/* Make an EAN-13 barcode from an SBN or ISBN */
static int isbn(struct zint_symbol *symbol, unsigned char source[], const int src_len, char dest[]) {
int i, error_number;
static int isbnx(struct zint_symbol *symbol, unsigned char source[], const int src_len, char dest[]) {
int i;
char check_digit;
to_upper(source);
error_number = is_sane(ISBN_SANE, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(ISBNX_SANE, source, src_len) != 0) {
strcpy(symbol->errtxt, "277: Invalid character in data (digits and \"X\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Input must be 9, 10 or 13 characters */
@ -560,10 +555,9 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const int sr
}
/* "X" can only occur in last position */
error_number = is_sane(NEON, source, 12);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, 12) != 0) {
strcpy(symbol->errtxt, "282: Invalid character in data, \"X\" allowed in last position only");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
check_digit = gs1_check_digit(source, 12);
@ -584,13 +578,12 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const int sr
}
/* "X" can only occur in last position */
error_number = is_sane(NEON, source, 9);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, source, 9) != 0) {
strcpy(symbol->errtxt, "296: Invalid character in data, \"X\" allowed in last position only");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
check_digit = isbn_check(source, 9);
check_digit = isbnx_check(source, 9);
if (check_digit != source[9]) {
sprintf(symbol->errtxt, "281: Invalid %s check digit '%c', expecting '%c'", src_len == 9 ? "SBN" : "ISBN",
source[9], check_digit);
@ -758,10 +751,9 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
char dest[1000] = {0};
int latch, reader, writer;
int with_addon;
int error_number, i, plus_count;
int error_number = 0, i, plus_count;
int addon_gap = 0;
int first_part_len, second_part_len;
float height;
latch = FALSE;
writer = 0;
@ -772,16 +764,14 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
}
if (symbol->symbology != BARCODE_ISBNX) {
/* ISBN has its own sanity routine */
error_number = is_sane(SODIUM, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(SODIUM, source, src_len) != 0) {
strcpy(symbol->errtxt, "284: Invalid character in data (digits and \"+\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
} else {
error_number = is_sane(ISBN_ADDON_SANE, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(ISBNX_ADDON_SANE, source, src_len) != 0) {
strcpy(symbol->errtxt, "285: Invalid character in data (digits, \"X\" and \"+\" only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
/* Add-on will be checked separately to be numeric only below */
}
@ -845,25 +835,23 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
switch (first_part_len) {
case 2: ean_add_on(first_part, first_part_len, dest, 0);
ustrcpy(symbol->text, first_part);
#ifdef COMPLIANT_HEIGHTS
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-5 */
height = (float) (21.9 / 0.33); /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-5 */
const float height = stripf(21.9f / 0.33f); /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
break;
case 5: ean_add_on(first_part, first_part_len, dest, 0);
ustrcpy(symbol->text, first_part);
#ifdef COMPLIANT_HEIGHTS
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */
height = (float) (21.9 / 0.33); /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
#else
height = 50.0f;
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */
const float height = stripf(21.9f / 0.33f); /* 21.9mm / 0.33mm ~ 66.36 */
error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/);
} else {
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
}
break;
case 7:
case 8: error_number = ean8(symbol, first_part, first_part_len, dest);
@ -961,7 +949,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
}
break;
case BARCODE_ISBNX:
error_number = isbn(symbol, first_part, first_part_len, dest);
error_number = isbnx(symbol, first_part, first_part_len, dest);
break;
}
@ -972,10 +960,9 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
second_part_len = (int) ustrlen(second_part);
if (symbol->symbology == BARCODE_ISBNX) { /* Need to further check that add-on numeric only */
error_number = is_sane(NEON, second_part, second_part_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
if (is_sane(NEON, second_part, second_part_len) != 0) {
strcpy(symbol->errtxt, "295: Invalid add-on data (digits only)");
return error_number;
return ZINT_ERROR_INVALID_DATA;
}
}

View file

@ -30,8 +30,6 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif

View file

@ -110,7 +110,7 @@ extern "C" {
int fontsize; /* Unused */
int input_mode; /* Encoding of input data (see DATA_MODE etc below). Default DATA_MODE */
int eci; /* Extended Channel Interpretation. Default 0 (none) */
float dot_size; /* Size of dots used in BARCODE_DOTTY_MODE */
float dot_size; /* Size of dots used in BARCODE_DOTTY_MODE. Default 0.8 */
float guard_descent; /* Height in X-dimensions that UPC/EAN guard bars descend. Default 5 */
struct zint_structapp structapp; /* Structured Append info. Default structapp.count 0 (none) */
int warn_level; /* Affects error/warning value returned by Zint API (see WARN_XXX below) */
@ -255,29 +255,31 @@ extern "C" {
#define BARCODE_RMQR 145 /* Rectangular Micro QR Code (rMQR) */
/* Output options (`symbol->output_options`) */
#define BARCODE_NO_ASCII 1 /* Legacy (no-op) */
#define BARCODE_BIND 2 /* Boundary bars above & below the symbol and between stacked symbols */
#define BARCODE_BOX 4 /* Box around symbol */
#define BARCODE_STDOUT 8 /* Output to stdout */
#define READER_INIT 16 /* Reader Initialisation (Programming) */
#define SMALL_TEXT 32 /* Use smaller font */
#define BOLD_TEXT 64 /* Use bold font */
#define CMYK_COLOUR 128 /* CMYK colour space (Encapsulated PostScript and TIF) */
#define BARCODE_DOTTY_MODE 256 /* Plot a matrix symbol using dots rather than squares */
#define GS1_GS_SEPARATOR 512 /* Use GS instead of FNC1 as GS1 separator (Data Matrix) */
#define OUT_BUFFER_INTERMEDIATE 1024 /* Return ASCII values in bitmap buffer (OUT_BUFFER only) */
#define BARCODE_QUIET_ZONES 2048 /* Add compliant quiet zones (additional to any specified whitespace) */
/* Note: CODE16K, CODE49, CODABLOCKF, ITF14, UPC/EAN have default quiet zones */
#define BARCODE_NO_QUIET_ZONES 4096 /* Disable quiet zones, notably those with defaults as listed above */
#define BARCODE_NO_ASCII 0x0001 /* Legacy (no-op) */
#define BARCODE_BIND 0x0002 /* Boundary bars above & below the symbol and between stacked symbols */
#define BARCODE_BOX 0x0004 /* Box around symbol */
#define BARCODE_STDOUT 0x0008 /* Output to stdout */
#define READER_INIT 0x0010 /* Reader Initialisation (Programming) */
#define SMALL_TEXT 0x0020 /* Use smaller font */
#define BOLD_TEXT 0x0040 /* Use bold font */
#define CMYK_COLOUR 0x0080 /* CMYK colour space (Encapsulated PostScript and TIF) */
#define BARCODE_DOTTY_MODE 0x0100 /* Plot a matrix symbol using dots rather than squares */
#define GS1_GS_SEPARATOR 0x0200 /* Use GS instead of FNC1 as GS1 separator (Data Matrix) */
#define OUT_BUFFER_INTERMEDIATE 0x0400 /* Return ASCII values in bitmap buffer (OUT_BUFFER only) */
#define BARCODE_QUIET_ZONES 0x0800 /* Add compliant quiet zones (additional to any specified whitespace) */
/* Note: CODE16K, CODE49, CODABLOCKF, ITF14, UPC/EAN have default quiet zones
*/
#define BARCODE_NO_QUIET_ZONES 0x1000 /* Disable quiet zones, notably those with defaults as listed above */
#define COMPLIANT_HEIGHT 0x2000 /* Warn if height not compliant and use standard height (if any) as default */
/* Input data types (`symbol->input_mode`) */
#define DATA_MODE 0 /* Binary */
#define UNICODE_MODE 1 /* UTF-8 */
#define GS1_MODE 2 /* GS1 */
/* The following may be OR-ed with above */
#define ESCAPE_MODE 8 /* Process escape sequences */
#define GS1PARENS_MODE 16 /* Process parentheses as GS1 AI delimiters (instead of square brackets) */
#define GS1NOCHECK_MODE 32 /* Do not check validity of GS1 data (except that printable ASCII only) */
#define ESCAPE_MODE 0x0008 /* Process escape sequences */
#define GS1PARENS_MODE 0x0010 /* Process parentheses as GS1 AI delimiters (instead of square brackets) */
#define GS1NOCHECK_MODE 0x0020 /* Do not check validity of GS1 data (except that printable ASCII only) */
/* Data Matrix specific options (`symbol->option_3`) */
#define DM_SQUARE 100 /* Only consider square versions on automatic symbol size selection */
@ -290,46 +292,47 @@ extern "C" {
#define ULTRA_COMPRESSION 128 /* Enable Ultracode compression (experimental) */
/* Warning and error conditions (API return values) */
#define ZINT_WARN_INVALID_OPTION 2 /* Invalid option given but overridden by Zint */
#define ZINT_WARN_USES_ECI 3 /* Automatic ECI inserted by Zint */
#define ZINT_WARN_NONCOMPLIANT 4 /* Symbol created not compliant with standards */
#define ZINT_ERROR 5 /* Warn/error marker, not returned */
#define ZINT_ERROR_TOO_LONG 5 /* Input data wrong length */
#define ZINT_ERROR_INVALID_DATA 6 /* Input data incorrect */
#define ZINT_ERROR_INVALID_CHECK 7 /* Input check digit incorrect */
#define ZINT_ERROR_INVALID_OPTION 8 /* Incorrect option given */
#define ZINT_ERROR_ENCODING_PROBLEM 9 /* Internal error (should not happen) */
#define ZINT_ERROR_FILE_ACCESS 10 /* Error opening output file */
#define ZINT_ERROR_MEMORY 11 /* Memory allocation (malloc) failure */
#define ZINT_ERROR_FILE_WRITE 12 /* Error writing to output file */
#define ZINT_ERROR_USES_ECI 13 /* Error counterpart of warning if WARN_FAIL_ALL set (see below) */
#define ZINT_ERROR_NONCOMPLIANT 14 /* Error counterpart of warning if WARN_FAIL_ALL set */
#define ZINT_WARN_INVALID_OPTION 2 /* Invalid option given but overridden by Zint */
#define ZINT_WARN_USES_ECI 3 /* Automatic ECI inserted by Zint */
#define ZINT_WARN_NONCOMPLIANT 4 /* Symbol created not compliant with standards */
#define ZINT_ERROR 5 /* Warn/error marker, not returned */
#define ZINT_ERROR_TOO_LONG 5 /* Input data wrong length */
#define ZINT_ERROR_INVALID_DATA 6 /* Input data incorrect */
#define ZINT_ERROR_INVALID_CHECK 7 /* Input check digit incorrect */
#define ZINT_ERROR_INVALID_OPTION 8 /* Incorrect option given */
#define ZINT_ERROR_ENCODING_PROBLEM 9 /* Internal error (should not happen) */
#define ZINT_ERROR_FILE_ACCESS 10 /* Error opening output file */
#define ZINT_ERROR_MEMORY 11 /* Memory allocation (malloc) failure */
#define ZINT_ERROR_FILE_WRITE 12 /* Error writing to output file */
#define ZINT_ERROR_USES_ECI 13 /* Error counterpart of warning if WARN_FAIL_ALL set (see below) */
#define ZINT_ERROR_NONCOMPLIANT 14 /* Error counterpart of warning if WARN_FAIL_ALL set */
/* Warning warn (`symbol->warn_level`) */
#define WARN_DEFAULT 0 /* Default behaviour */
#define WARN_FAIL_ALL 2 /* Treat warning as error */
/* Capability flags (ZBarcode_Cap() `cap_flag`) */
#define ZINT_CAP_HRT 0x0001 /* Prints Human Readable Text? */
#define ZINT_CAP_STACKABLE 0x0002 /* Is stackable? */
#define ZINT_CAP_EXTENDABLE 0x0004 /* Is extendable with add-on data? (Is UPC/EAN?) */
#define ZINT_CAP_COMPOSITE 0x0008 /* Can have composite data? */
#define ZINT_CAP_ECI 0x0010 /* Supports Extended Channel Interpretations? */
#define ZINT_CAP_GS1 0x0020 /* Supports GS1 data? */
#define ZINT_CAP_DOTTY 0x0040 /* Can be output as dots? */
#define ZINT_CAP_QUIET_ZONES 0x0080 /* Has default quiet zones? */
#define ZINT_CAP_FIXED_RATIO 0x0100 /* Has fixed width-to-height (aspect) ratio? */
#define ZINT_CAP_READER_INIT 0x0200 /* Supports Reader Initialisation? */
#define ZINT_CAP_FULL_MULTIBYTE 0x0400 /* Supports full-multibyte option? */
#define ZINT_CAP_MASK 0x0800 /* Is mask selectable? */
#define ZINT_CAP_STRUCTAPP 0x1000 /* Supports Structured Append? */
#define ZINT_CAP_HRT 0x0001 /* Prints Human Readable Text? */
#define ZINT_CAP_STACKABLE 0x0002 /* Is stackable? */
#define ZINT_CAP_EXTENDABLE 0x0004 /* Is extendable with add-on data? (Is UPC/EAN?) */
#define ZINT_CAP_COMPOSITE 0x0008 /* Can have composite data? */
#define ZINT_CAP_ECI 0x0010 /* Supports Extended Channel Interpretations? */
#define ZINT_CAP_GS1 0x0020 /* Supports GS1 data? */
#define ZINT_CAP_DOTTY 0x0040 /* Can be output as dots? */
#define ZINT_CAP_QUIET_ZONES 0x0080 /* Has default quiet zones? */
#define ZINT_CAP_FIXED_RATIO 0x0100 /* Has fixed width-to-height (aspect) ratio? */
#define ZINT_CAP_READER_INIT 0x0200 /* Supports Reader Initialisation? */
#define ZINT_CAP_FULL_MULTIBYTE 0x0400 /* Supports full-multibyte option? */
#define ZINT_CAP_MASK 0x0800 /* Is mask selectable? */
#define ZINT_CAP_STRUCTAPP 0x1000 /* Supports Structured Append? */
#define ZINT_CAP_COMPLIANT_HEIGHT 0x2000 /* Has compliant height? */
/* The largest amount of data that can be encoded is 4350 4-byte UTF-8 chars in Han Xin Code */
#define ZINT_MAX_DATA_LEN 17400
/* Debug flags (debug) */
#define ZINT_DEBUG_PRINT 1 /* Print debug info (if any) to stdout */
#define ZINT_DEBUG_TEST 2 /* For internal test use only */
#define ZINT_DEBUG_PRINT 0x0001 /* Print debug info (if any) to stdout */
#define ZINT_DEBUG_TEST 0x0002 /* For internal test use only */
#ifdef _WIN32
# if defined(DLL_EXPORT) || defined(PIC) || defined(_USRDLL)