2022-12-09 02:48:31 +13:00
|
|
|
/* mailmark.c - Royal Mail 4-state and 2D Mailmark barcodes */
|
2018-02-07 09:57:01 +13:00
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2022-06-25 01:38:48 +12:00
|
|
|
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
|
2018-02-07 09:57:01 +13:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the project nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
SUCH DAMAGE.
|
|
|
|
*/
|
2022-06-25 01:38:48 +12:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2018-02-07 09:57:01 +13:00
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
/*
|
2018-02-07 09:57:01 +13:00
|
|
|
* Developed in accordance with "Royal Mail Mailmark barcode C encoding and deconding instructions"
|
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
2021-10-09 12:13:39 +13:00
|
|
|
* (https://www.royalmail.com/sites/default/files/
|
|
|
|
* Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf)
|
2018-02-07 09:57:01 +13:00
|
|
|
* and "Royal Mail Mailmark barcode L encoding and decoding"
|
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
2021-10-09 12:13:39 +13:00
|
|
|
* (https://www.royalmail.com/sites/default/files/
|
|
|
|
* Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf)
|
2021-06-10 22:15:39 +12:00
|
|
|
*
|
2018-02-07 09:57:01 +13:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "large.h"
|
|
|
|
#include "reedsol.h"
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
#define RUBIDIUM_F (IS_NUM_F | IS_UPR_F | IS_SPC_F) /* RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " */
|
2018-02-07 09:57:01 +13:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Allowed character values from Table 3 */
|
2018-02-07 09:57:01 +13:00
|
|
|
#define SET_F "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
#define SET_L "ABDEFGHJLNPQRSTUWXYZ"
|
|
|
|
#define SET_N "0123456789"
|
|
|
|
#define SET_S " "
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static const char mailmark_postcode_format[6][9] = {
|
2021-10-21 11:05:30 +13:00
|
|
|
{'F','N','F','N','L','L','N','L','S'}, {'F','F','N','N','L','L','N','L','S'},
|
|
|
|
{'F','F','N','N','N','L','L','N','L'}, {'F','F','N','F','N','L','L','N','L'},
|
|
|
|
{'F','N','N','L','L','N','L','S','S'}, {'F','N','N','N','L','L','N','L','S'}
|
2018-02-07 09:57:01 +13:00
|
|
|
};
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Data/Check Symbols from Table 5 */
|
2022-12-09 02:48:31 +13:00
|
|
|
static const unsigned char mailmark_data_symbol_odd[32] = {
|
2018-02-07 09:57:01 +13:00
|
|
|
0x01, 0x02, 0x04, 0x07, 0x08, 0x0B, 0x0D, 0x0E, 0x10, 0x13, 0x15, 0x16,
|
|
|
|
0x19, 0x1A, 0x1C, 0x1F, 0x20, 0x23, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x2F,
|
|
|
|
0x31, 0x32, 0x34, 0x37, 0x38, 0x3B, 0x3D, 0x3E
|
|
|
|
};
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static const unsigned char mailmark_data_symbol_even[30] = {
|
2018-02-07 09:57:01 +13:00
|
|
|
0x03, 0x05, 0x06, 0x09, 0x0A, 0x0C, 0x0F, 0x11, 0x12, 0x14, 0x17, 0x18,
|
|
|
|
0x1B, 0x1D, 0x1E, 0x21, 0x22, 0x24, 0x27, 0x28, 0x2B, 0x2D, 0x2E, 0x30,
|
|
|
|
0x33, 0x35, 0x36, 0x39, 0x3A, 0x3C
|
|
|
|
};
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static const unsigned short mailmark_extender_group_c[22] = {
|
2018-02-07 09:57:01 +13:00
|
|
|
3, 5, 7, 11, 13, 14, 16, 17, 19, 0, 1, 2, 4, 6, 8, 9, 10, 12, 15, 18, 20, 21
|
|
|
|
};
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static const unsigned short mailmark_extender_group_l[26] = {
|
2018-02-07 09:57:01 +13:00
|
|
|
2, 5, 7, 8, 13, 14, 15, 16, 21, 22, 23, 0, 1, 3, 4, 6, 9, 10, 11, 12, 17, 18, 19, 20, 24, 25
|
|
|
|
};
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static int mailmark_verify_character(char input, char type) {
|
2018-02-07 09:57:01 +13:00
|
|
|
int val = 0;
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
switch (type) {
|
|
|
|
case 'F':
|
|
|
|
val = posn(SET_F, input);
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
val = posn(SET_L, input);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
val = posn(SET_N, input);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
val = posn(SET_S, input);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
if (val == -1) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
static int mailmark_verify_postcode(const char postcode[10], int* p_postcode_type) {
|
|
|
|
int postcode_type;
|
2018-02-07 09:57:01 +13:00
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
/* Detect postcode type */
|
|
|
|
/* postcode_type is used to select which format of postcode
|
|
|
|
*
|
|
|
|
* 1 = FNFNLLNLS
|
|
|
|
* 2 = FFNNLLNLS
|
|
|
|
* 3 = FFNNNLLNL
|
|
|
|
* 4 = FFNFNLLNL
|
|
|
|
* 5 = FNNLLNLSS
|
|
|
|
* 6 = FNNNLLNLS
|
|
|
|
* 7 = International designation
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strcmp(postcode, "XY11 ") == 0) {
|
|
|
|
postcode_type = 7;
|
|
|
|
} else {
|
|
|
|
if (postcode[7] == ' ') {
|
|
|
|
postcode_type = 5;
|
|
|
|
} else {
|
|
|
|
if (postcode[8] == ' ') {
|
|
|
|
/* Types 1, 2 and 6 */
|
|
|
|
if (z_isdigit(postcode[1])) {
|
|
|
|
if (z_isdigit(postcode[2])) {
|
|
|
|
postcode_type = 6;
|
|
|
|
} else {
|
|
|
|
postcode_type = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
postcode_type = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Types 3 and 4 */
|
|
|
|
if (z_isdigit(postcode[3])) {
|
|
|
|
postcode_type = 3;
|
|
|
|
} else {
|
|
|
|
postcode_type = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_postcode_type) {
|
|
|
|
*p_postcode_type = postcode_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify postcode type */
|
|
|
|
if (postcode_type != 7) {
|
|
|
|
int i;
|
|
|
|
const char *const pattern = mailmark_postcode_format[postcode_type - 1];
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
if (!(mailmark_verify_character(postcode[i], pattern[i]))) {
|
|
|
|
return 1;
|
|
|
|
}
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
/* Royal Mail 4-state Mailmark */
|
|
|
|
INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
char local_source[28];
|
|
|
|
int format;
|
|
|
|
int version_id;
|
2018-03-30 21:46:54 +13:00
|
|
|
int mail_class;
|
2018-02-07 09:57:01 +13:00
|
|
|
int supply_chain_id;
|
2021-06-10 22:15:39 +12:00
|
|
|
unsigned int item_id;
|
2018-02-07 09:57:01 +13:00
|
|
|
char postcode[10];
|
|
|
|
int postcode_type;
|
2020-06-15 01:42:40 +12:00
|
|
|
large_int destination_postcode;
|
|
|
|
large_int b;
|
|
|
|
large_int cdv;
|
2018-04-06 21:50:19 +12:00
|
|
|
unsigned char data[26];
|
2018-02-07 09:57:01 +13:00
|
|
|
int data_top, data_step;
|
|
|
|
unsigned char check[7];
|
2021-06-10 22:15:39 +12:00
|
|
|
unsigned int extender[27];
|
2018-02-07 09:57:01 +13:00
|
|
|
char bar[80];
|
2021-10-21 11:05:30 +13:00
|
|
|
char *d = bar;
|
2018-02-07 09:57:01 +13:00
|
|
|
int check_count;
|
2020-05-22 05:22:28 +12:00
|
|
|
int i, j, len;
|
2020-11-28 01:54:44 +13:00
|
|
|
rs_t rs;
|
2021-06-20 00:11:23 +12:00
|
|
|
int error_number = 0;
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-10 20:26:33 +13:00
|
|
|
if (length > 26) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "580: Input too long (26 character maximum)");
|
2018-02-10 20:26:33 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2021-08-10 23:04:25 +12:00
|
|
|
ustrcpy(local_source, source);
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-10 20:26:33 +13:00
|
|
|
if (length < 22) {
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
if (length < 14) {
|
|
|
|
strcpy(symbol->errtxt, "588: Input too short (14 character minimum)");
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2018-02-10 20:26:33 +13:00
|
|
|
for (i = length; i <= 22; i++) {
|
|
|
|
strcat(local_source, " ");
|
|
|
|
}
|
|
|
|
length = 22;
|
- API: add new zint_symbol `dpmm` field for output resolution (BMP/
EMF/PCX/PNG/TIF only, i.e. excluding EPS, GIF & SVG)
- Add support for specifying scale by X-dimension and resolution
with new option `--scalexdimdp` for CLI/Tcl & new API function
`ZBarcode_Scale_From_XdimDp()` (+ `ZBarcode_XdimDp_From_Scale()`
& `ZBarcode_Default_Xdim()`) and new GUI popup; manual: document
- BMP/EMF/PCX/PNG/TIF: use new `dpmm` resolution field (for EMF
following Inkscape)
- backend_qt: add `dpmm()`, `vectorWidth()`, `vectorHeight()`,
`noPng()`, `getVersion()`, `takesGS1AIData()`, & `XdimDp` stuff
incl. new `QZintXdimDp` struct for passing around scale vars &
use in `getAsCLI()`; add comments
- Raise `scale` limit to 200 (from 100) to allow for large dpmm
- output: create directories & subdirectories as necessary for
output path using new function `out_fopen()` and use in BMP/EMF/
EPS/GIF/PCX/PNG/SVG/TIF
- DPLEIT/DPIDENT: format HRT according to (incomplete)
documentation, and set default height to 72X (from 50X)
- CODE128B renamed to CODE128AB as can use subsets A and/or B
- CODABAR: fix minimum height calc
- EMF: fix indexing of handles (zero-based not 1-based)
- GUI: fix symbology zap (previous technique of clearing and
re-loading settings without doing a sync no longer works);
fix UPCEAN guard descent enable
- MAILMARK: better error message if input < 14 characters
- GUI: add "Default" button for DAFT tracker ratio & enable/disable
various default buttons; use new `takesGS1AIData()` to
enable/disable GS1-specific checkboxes
- CLI: use new `validate_float()` to parse float options (7
significant digits allowed only, no scientific notation)
- DATAMATRIX/GRIDMATRIX/PDF417/QR/ULTRA: micro-optimize structapp
ID parse
- library/CLI: fiddle with static asserts (make CHAR_BIT sensitive,
supposedly)
- win32/README: update building libpng (assembly removed)
- README.linux: document incompatibility of Qt6 >= 6.3
- manual: expand Barcode Studio waffle
- test suite: change range separator to hyphen and allow multiple
excludes
2022-12-03 10:39:01 +13:00
|
|
|
} else if ((length > 22) && (length < 26)) {
|
2018-02-10 20:26:33 +13:00
|
|
|
for (i = length; i <= 26; i++) {
|
|
|
|
strcat(local_source, " ");
|
|
|
|
}
|
|
|
|
length = 26;
|
2021-06-10 22:15:39 +12:00
|
|
|
}
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
to_upper((unsigned char *) local_source, length);
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2020-06-15 01:42:40 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
2022-12-09 02:48:31 +13:00
|
|
|
printf("Producing 4-state Mailmark (%d): %s<end>\n", length, local_source);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(RUBIDIUM_F, (unsigned char *) local_source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "581: Invalid character in data (alphanumerics and space only)");
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Format is in the range 0-4 */
|
2018-02-07 09:57:01 +13:00
|
|
|
format = ctoi(local_source[0]);
|
|
|
|
if ((format < 0) || (format > 4)) {
|
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
2021-10-09 12:13:39 +13:00
|
|
|
strcpy(symbol->errtxt, "582: Format (1st character) out of range (0 to 4)");
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Version ID is in the range 1-4 */
|
2018-02-07 09:57:01 +13:00
|
|
|
version_id = ctoi(local_source[1]) - 1;
|
|
|
|
if ((version_id < 0) || (version_id > 3)) {
|
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
2021-10-09 12:13:39 +13:00
|
|
|
strcpy(symbol->errtxt, "583: Version ID (2nd character) out of range (1 to 4)");
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Class is in the range 0-9,A-E */
|
2018-03-30 21:46:54 +13:00
|
|
|
mail_class = ctoi(local_source[2]);
|
|
|
|
if ((mail_class < 0) || (mail_class > 14)) {
|
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
2021-10-09 12:13:39 +13:00
|
|
|
strcpy(symbol->errtxt, "584: Class (3rd character) out of range (0 to 9 and A to E)");
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L */
|
2018-02-07 09:57:01 +13:00
|
|
|
supply_chain_id = 0;
|
|
|
|
for (i = 3; i < (length - 17); i++) {
|
2022-06-25 01:38:48 +12:00
|
|
|
if (z_isdigit(local_source[i])) {
|
2018-02-07 09:57:01 +13:00
|
|
|
supply_chain_id *= 10;
|
|
|
|
supply_chain_id += ctoi(local_source[i]);
|
|
|
|
} else {
|
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
2021-10-09 12:13:39 +13:00
|
|
|
sprintf(symbol->errtxt, "585: Invalid Supply Chain ID at character %d (digits only)", i);
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Item ID is 8 digits */
|
2018-02-07 09:57:01 +13:00
|
|
|
item_id = 0;
|
|
|
|
for (i = length - 17; i < (length - 9); i++) {
|
2022-06-25 01:38:48 +12:00
|
|
|
if (z_isdigit(local_source[i])) {
|
2018-02-07 09:57:01 +13:00
|
|
|
item_id *= 10;
|
2021-06-10 22:15:39 +12:00
|
|
|
item_id += ctoi(local_source[i]);
|
2018-02-07 09:57:01 +13:00
|
|
|
} else {
|
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
2021-10-09 12:13:39 +13:00
|
|
|
sprintf(symbol->errtxt, "586: Invalid Item ID at character %d (digits only)", i);
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Separate Destination Post Code plus DPS field */
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
postcode[i] = local_source[(length - 9) + i];
|
|
|
|
}
|
|
|
|
postcode[9] = '\0';
|
2022-12-09 02:48:31 +13:00
|
|
|
if (mailmark_verify_postcode(postcode, &postcode_type) != 0) {
|
|
|
|
sprintf(symbol->errtxt, "587: Invalid postcode \"%s\"", postcode);
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Convert postcode to internal user field */
|
2020-06-15 01:42:40 +12:00
|
|
|
|
|
|
|
large_load_u64(&destination_postcode, 0);
|
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type != 7) {
|
2022-12-09 02:48:31 +13:00
|
|
|
const char *const pattern = mailmark_postcode_format[postcode_type - 1];
|
2018-02-07 09:57:01 +13:00
|
|
|
|
2020-06-15 01:42:40 +12:00
|
|
|
large_load_u64(&b, 0);
|
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
switch (pattern[i]) {
|
|
|
|
case 'F':
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&b, 26);
|
|
|
|
large_add_u64(&b, posn(SET_F, postcode[i]));
|
2018-02-07 09:57:01 +13:00
|
|
|
break;
|
|
|
|
case 'L':
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&b, 20);
|
|
|
|
large_add_u64(&b, posn(SET_L, postcode[i]));
|
2018-02-07 09:57:01 +13:00
|
|
|
break;
|
|
|
|
case 'N':
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&b, 10);
|
|
|
|
large_add_u64(&b, posn(SET_N, postcode[i]));
|
2018-02-07 09:57:01 +13:00
|
|
|
break;
|
2022-07-15 03:01:30 +12:00
|
|
|
/* case 'S' ignored as value is 0 */
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
|
|
|
|
large_load(&destination_postcode, &b);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* destination_postcode = a + b */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_load_u64(&b, 1);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 1) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&b, 5408000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 2) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&b, 5408000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 3) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&b, 54080000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 4) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&b, 140608000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 5) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&b, 208000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
if (postcode_type == 6) {
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&destination_postcode, &b);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Conversion from Internal User Fields to Consolidated Data Value */
|
|
|
|
/* Set CDV to 0 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_load_u64(&cdv, 0);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Destination Post Code plus DPS */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add(&cdv, &destination_postcode);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Multiply by 100,000,000 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 100000000);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Item ID */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&cdv, item_id);
|
|
|
|
|
2021-06-10 22:15:39 +12:00
|
|
|
if (length == 22) {
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Barcode C - Multiply by 100 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 100);
|
2018-02-07 09:57:01 +13:00
|
|
|
} else {
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Barcode L - Multiply by 1,000,000 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 1000000);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2020-06-15 01:42:40 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Supply Chain ID */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&cdv, supply_chain_id);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Multiply by 15 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 15);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Class */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&cdv, mail_class);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Multiply by 5 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 5);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Format */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&cdv, format);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Multiply by 4 */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_mul_u64(&cdv, 4);
|
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Add Version ID */
|
2020-06-15 01:42:40 +12:00
|
|
|
large_add_u64(&cdv, version_id);
|
|
|
|
|
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
2018-02-07 09:57:01 +13:00
|
|
|
printf("DPC type %d\n", postcode_type);
|
|
|
|
printf("CDV: ");
|
2020-06-15 01:42:40 +12:00
|
|
|
large_print(&cdv);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
if (length == 22) {
|
|
|
|
data_top = 15;
|
|
|
|
data_step = 8;
|
|
|
|
check_count = 6;
|
|
|
|
} else {
|
|
|
|
data_top = 18;
|
|
|
|
data_step = 10;
|
|
|
|
check_count = 7;
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Conversion from Consolidated Data Value to Data Numbers */
|
2018-02-07 09:57:01 +13:00
|
|
|
|
2020-06-15 01:42:40 +12:00
|
|
|
for (j = data_top; j >= (data_step + 1); j--) {
|
2020-12-23 23:57:24 +13:00
|
|
|
data[j] = (unsigned char) large_div_u64(&cdv, 32);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
for (j = data_step; j >= 0; j--) {
|
2020-12-23 23:57:24 +13:00
|
|
|
data[j] = (unsigned char) large_div_u64(&cdv, 30);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Generation of Reed-Solomon Check Numbers */
|
2020-11-28 01:54:44 +13:00
|
|
|
rs_init_gf(&rs, 0x25);
|
|
|
|
rs_init_code(&rs, check_count, 1);
|
|
|
|
rs_encode(&rs, (data_top + 1), data, check);
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Append check digits to data */
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 1; i <= check_count; i++) {
|
|
|
|
data[data_top + i] = check[check_count - i];
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2020-06-15 01:42:40 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
2018-02-07 09:57:01 +13:00
|
|
|
printf("Codewords: ");
|
|
|
|
for (i = 0; i <= data_top + check_count; i++) {
|
|
|
|
printf("%d ", (int) data[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Conversion from Data Numbers and Check Numbers to Data Symbols and Check Symbols */
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 0; i <= data_step; i++) {
|
2022-12-09 02:48:31 +13:00
|
|
|
data[i] = mailmark_data_symbol_even[data[i]];
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
for (i = data_step + 1; i <= (data_top + check_count); i++) {
|
2022-12-09 02:48:31 +13:00
|
|
|
data[i] = mailmark_data_symbol_odd[data[i]];
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Conversion from Data Symbols and Check Symbols to Extender Groups */
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
if (length == 22) {
|
2022-12-09 02:48:31 +13:00
|
|
|
extender[mailmark_extender_group_c[i]] = data[i];
|
2018-02-07 09:57:01 +13:00
|
|
|
} else {
|
2022-12-09 02:48:31 +13:00
|
|
|
extender[mailmark_extender_group_l[i]] = data[i];
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* Conversion from Extender Groups to Bar Identifiers */
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
2021-06-10 22:15:39 +12:00
|
|
|
switch (extender[i] & 0x24) {
|
2018-02-07 09:57:01 +13:00
|
|
|
case 0x24:
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'F';
|
2018-02-07 09:57:01 +13:00
|
|
|
break;
|
|
|
|
case 0x20:
|
|
|
|
if (i % 2) {
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'D';
|
2018-02-07 09:57:01 +13:00
|
|
|
} else {
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'A';
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
if (i % 2) {
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'A';
|
2018-02-07 09:57:01 +13:00
|
|
|
} else {
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'D';
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'T';
|
2018-02-07 09:57:01 +13:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extender[i] = extender[i] << 1;
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2020-06-15 01:42:40 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
2021-10-21 11:05:30 +13:00
|
|
|
printf("Bar pattern: %.*s\n", (int) (d - bar), bar);
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2018-02-07 09:57:01 +13:00
|
|
|
/* Translate 4-state data pattern to symbol */
|
|
|
|
j = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0, len = d - bar; i < len; i++) {
|
2018-02-07 09:57:01 +13:00
|
|
|
if ((bar[i] == 'F') || (bar[i] == 'A')) {
|
|
|
|
set_module(symbol, 0, j);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, j);
|
|
|
|
if ((bar[i] == 'F') || (bar[i] == 'D')) {
|
|
|
|
set_module(symbol, 2, j);
|
|
|
|
}
|
|
|
|
j += 2;
|
|
|
|
}
|
|
|
|
|
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
2021-10-09 12:13:39 +13:00
|
|
|
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);
|
|
|
|
}
|
2018-02-07 09:57:01 +13:00
|
|
|
symbol->rows = 3;
|
|
|
|
symbol->width = j - 1;
|
2021-06-10 22:15:39 +12:00
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
return error_number;
|
2018-02-07 09:57:01 +13:00
|
|
|
}
|
2022-06-25 01:38:48 +12:00
|
|
|
|
2022-12-09 02:48:31 +13:00
|
|
|
INTERNAL int datamatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count);
|
|
|
|
|
|
|
|
/* Royal Mail 2D Mailmark (CMDM) (Data Matrix) */
|
|
|
|
/* https://www.royalmailtechnical.com/rmt_docs/User_Guides_2021/Mailmark_Barcode_definition_document_20210215.pdf */
|
|
|
|
INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|
|
|
|
|
|
|
unsigned char local_source[90 + 1];
|
|
|
|
char postcode[10];
|
|
|
|
int i;
|
|
|
|
struct zint_seg segs[1];
|
|
|
|
|
|
|
|
if (length > 90) {
|
|
|
|
strcpy(symbol->errtxt, "589: Input too long (90 character maximum)");
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length < 28) { /* After adding prefix (4), blank Return to Sender Post Code (7), Reserved (6): 28 + 17 = 45 */
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "860: Input too short (28 character minimum)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add prefix if missing */
|
|
|
|
memcpy(local_source, source, 4);
|
|
|
|
to_upper(local_source, 3);
|
|
|
|
if (memcmp(local_source, "JGB ", 4) != 0) {
|
|
|
|
if (length > 86) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "861: Input too long (86 character maximum)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
ustrcpy(local_source, "JGB ");
|
|
|
|
ustrcpy(local_source + 4, source);
|
|
|
|
length += 4;
|
|
|
|
} else {
|
|
|
|
ustrcpy(local_source, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length < 32) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "862: Input too short (32 character minimum)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
if (length < 39) { /* Space-pad Return to Sender Post Code */
|
|
|
|
memset(local_source + length, ' ', 39 - length);
|
|
|
|
local_source[39] = '\0';
|
|
|
|
length = 39;
|
|
|
|
}
|
|
|
|
to_upper(local_source, 39);
|
|
|
|
|
|
|
|
if (length < 45) { /* Space-pad Reserved */
|
|
|
|
memset(local_source + length, ' ', 45 - length);
|
|
|
|
local_source[45] = '\0';
|
|
|
|
length = 45;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8: 24 x 24, 10: 32 x 32, 30: 16 x 48 */
|
|
|
|
if (symbol->option_2) {
|
|
|
|
if (symbol->option_2 != 8 && symbol->option_2 != 10 && symbol->option_2 != 30) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "863: Invalid symbol size selected (8, 10, 30 only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_OPTION;
|
|
|
|
}
|
|
|
|
if (symbol->option_2 == 8) {
|
|
|
|
if (length > 51) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "864: Input too long for selected size (51 character maximum)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
} else if (symbol->option_2 == 30) {
|
|
|
|
if (length > 70) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "865: Input too long for selected size (70 character maximum)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (length <= 51) {
|
|
|
|
symbol->option_2 = 8;
|
|
|
|
} else if (length <= 70 && (symbol->option_3 & 0x7F) != DM_SQUARE) {
|
|
|
|
symbol->option_2 = 30;
|
|
|
|
} else {
|
|
|
|
symbol->option_2 = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
|
|
|
printf("Producing 2D Mailmark %d (%d): %s<end>\n", symbol->option_2, length, local_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_sane(RUBIDIUM_F, local_source, 45)) {
|
2022-12-20 05:28:15 +13:00
|
|
|
strcpy(symbol->errtxt,
|
|
|
|
"866: Invalid character in data (alphanumerics and space only in first 45 characters)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Information Type ID */
|
|
|
|
/* Not checking that matches values listed in Mailmark Definition Document as contradicted by Mailmark Mailing
|
|
|
|
Requirements Section 5.7 which says 'P' for poll card is valid, which isn't listed */
|
|
|
|
if (local_source[4] == ' ') {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "867: Invalid Information Type ID (cannot be space)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
/* Version ID */
|
|
|
|
if (local_source[5] != '1') {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "868: Invalid Version ID (\"1\" only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
/* Class */
|
|
|
|
if (local_source[6] == ' ') {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "869: Invalid Class (cannot be space)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
/* Supply Chain ID */
|
|
|
|
if (cnt_digits(local_source, length, 7, 7) != 7) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "870: Invalid Supply Chain ID (7 digits only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
/* Item ID */
|
|
|
|
if (cnt_digits(local_source, length, 14, 8) != 8) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "871: Invalid Item ID (8 digits only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destination Post Code plus DPS field */
|
|
|
|
for (i = 0; i < 9; i++) {
|
|
|
|
postcode[i] = local_source[22 + i];
|
|
|
|
}
|
|
|
|
postcode[9] = '\0';
|
|
|
|
if (mailmark_verify_postcode(postcode, NULL) != 0) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "872: Invalid Destination Post Code plus DPS");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Service Type */
|
|
|
|
if (local_source[31] < '0' || local_source[31] > '6') {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "873: Invalid Service Type (\"0\" to \"6\" only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return to Sender Post Code */
|
|
|
|
if (memcmp(local_source + 32, " ", 7) != 0) { /* If not blank (allowed) */
|
|
|
|
for (i = 0; i < 7; i++) {
|
|
|
|
postcode[i] = local_source[32 + i];
|
|
|
|
}
|
|
|
|
/* Add dummy DPS */
|
|
|
|
for (i = 6; postcode[i] == ' '; i--); /* Skip any terminal spaces */
|
|
|
|
i++;
|
|
|
|
postcode[i++] = '1';
|
|
|
|
postcode[i++] = 'A';
|
|
|
|
while (i != 9) {
|
|
|
|
postcode[i++] = ' ';
|
|
|
|
}
|
|
|
|
postcode[9] = '\0';
|
|
|
|
if (mailmark_verify_postcode(postcode, NULL) != 0) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "874: Invalid Return to Sender Post Code");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserved */
|
|
|
|
if (memcmp(local_source + 39, " ", 6) != 0) {
|
2022-12-10 03:51:26 +13:00
|
|
|
strcpy(symbol->errtxt, "875: Invalid Reserved field (must be spaces only)");
|
2022-12-09 02:48:31 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
segs[0].eci = 0;
|
|
|
|
segs[0].source = local_source;
|
|
|
|
segs[0].length = length;
|
|
|
|
|
|
|
|
return datamatrix(symbol, segs, 1);
|
|
|
|
}
|
|
|
|
|
2022-06-25 01:38:48 +12:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|