CEPNET: height/quiet zones, backend_tcl, test suite

This commit is contained in:
gitlost
2022-08-20 20:45:51 +01:00
parent 400f124a04
commit b42f456b88
12 changed files with 1642 additions and 1576 deletions

View File

@ -1,4 +1,4 @@
/* postal.c - Handles PostNet, PLANET, FIM. RM4SCC and Flattermarken */
/* postal.c - Handles POSTNET, PLANET, CEPNet, FIM. RM4SCC and Flattermarken */
/*
libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
@ -88,7 +88,7 @@ static const char JapanTable[19][3] = {
{'2','4','3'}, {'4','2','3'}, {'4','4','1'}, {'1','1','1'}
};
/* Set height for POSTNET/PLANET codes, maintaining ratio */
/* Set height for POSTNET/PLANET/CEPNet codes, maintaining ratio */
static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.4.2.5 POSTNET Barcode Dimensions and
Spacing
@ -97,10 +97,12 @@ static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
Half bar height 0.05" +- 0.01; 0.040" (min) / 0.025" (X max) = 1.6 min, 0.060" (max) / 0.015" (X min) = 4 max
Full bar height 0.125" +- 0.01; 0.115" (min) / 0.025" (X max) = 4.6 min, 0.135" (max) / 0.015" (X min) = 9 max
*/
/* CEPNet e Código Bidimensional Datamatrix 2D (26/05/2021) 3.3.2 Arquitetura das barras - same as POSTNET */
int error_number = 0;
float h_ratio; /* Half ratio */
if (symbol->output_options & COMPLIANT_HEIGHT) {
/* No legacy for CEPNet as new */
if ((symbol->output_options & COMPLIANT_HEIGHT) || symbol->symbology == BARCODE_CEPNET) {
symbol->row_height[0] = stripf(0.075f * 43); /* 3.225 */
symbol->row_height[1] = stripf(0.05f * 43); /* 2.15 */
} else {
@ -131,11 +133,10 @@ static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
return error_number;
}
/* Handles the PostNet system used for Zip codes in the US */
/* Also handles Brazilian CEPNet - more information at
* https://silo.tips/download/sumario-4-regras-de-endereamento
* https://barcodeguide.seagullscientific.com/Content/Symbologies/CEPNet.htm
* TODO: Check compliant symbol sizes */
/* Handles the POSTNET system used for Zip codes in the US */
/* Also handles Brazilian CEPNet - more information CEPNet e Código Bidimensional Datamatrix 2D (26/05/2021) at
* https://www.correios.com.br/enviar/correspondencia/arquivos/nacional/guia-tecnico-cepnet-e-2d-triagem-enderecamento-27-04-2021.pdf/view
*/
static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[], char *d, const int length) {
int i, sum, check_digit;
int error_number = 0;
@ -147,7 +148,7 @@ static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[],
if (symbol->symbology == BARCODE_CEPNET) {
if (length != 8) {
strcpy(symbol->errtxt, "499: Input is wrong length (should be 8 digits)");
strcpy(symbol->errtxt, "780: Input is wrong length (should be 8 digits)");
error_number = ZINT_WARN_NONCOMPLIANT;
}
} else {
@ -175,13 +176,15 @@ static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[],
memcpy(d, PNTable[check_digit], 5);
d += 5;
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
/* stop character */
strcpy(d, "L");
return error_number;
}
/* Puts PostNet barcodes into the pattern matrix */
/* Puts POSTNET barcodes into the pattern matrix */
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;
@ -241,6 +244,8 @@ static int planet_enc(struct zint_symbol *symbol, const unsigned char source[],
memcpy(d, PLTable[check_digit], 5);
d += 5;
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
/* stop character */
strcpy(d, "L");
@ -406,7 +411,7 @@ INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height,
}
/* Handles the 4 State barcodes used in the UK by Royal Mail */
static void rm4scc_enc(const int *posns, char *d, const int length) {
static void rm4scc_enc(const struct zint_symbol *symbol, const int *posns, char *d, const int length) {
int i;
int top, bottom, row, column, check_digit;
@ -436,6 +441,8 @@ static void rm4scc_enc(const int *posns, char *d, const int length) {
memcpy(d, RoyalTable[check_digit], 4);
d += 4;
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
/* stop character */
strcpy(d, "0");
}
@ -457,7 +464,7 @@ INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int leng
strcpy(symbol->errtxt, "489: Invalid character in data (alphanumerics only)");
return ZINT_ERROR_INVALID_DATA;
}
rm4scc_enc(posns, height_pattern, length);
rm4scc_enc(symbol, posns, height_pattern, length);
writer = 0;
h = (int) strlen(height_pattern);