2008-07-14 09:15:55 +12:00
|
|
|
/* postal.c - Handles PostNet, PLANET, FIM. RM4SCC and Flattermarken */
|
|
|
|
|
2017-10-24 08:37:52 +13:00
|
|
|
/*
|
2016-02-20 23:50:15 +13:00
|
|
|
libzint - the open source barcode library
|
2021-06-10 22:15:39 +12:00
|
|
|
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
|
2008-07-19 02:35:32 +12:00
|
|
|
Including bug fixes by Bryan Hatton
|
2013-05-17 05:26:38 +12:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
2017-10-24 08:37:52 +13:00
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
2013-05-17 05:26:38 +12:00
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
2017-10-24 08:37:52 +13:00
|
|
|
documentation and/or other materials provided with the distribution.
|
2013-05-17 05:26:38 +12:00
|
|
|
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
|
2017-10-24 08:37:52 +13:00
|
|
|
without specific prior written permission.
|
2013-05-17 05:26:38 +12:00
|
|
|
|
|
|
|
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
|
2017-10-24 08:37:52 +13:00
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
2013-05-17 05:26:38 +12:00
|
|
|
SUCH DAMAGE.
|
2016-02-20 23:50:15 +13:00
|
|
|
*/
|
2019-11-28 05:16:14 +13:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2008-07-14 09:15:55 +12:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-06-03 08:23:38 +12:00
|
|
|
#ifdef _MSC_VER
|
2017-10-24 08:37:52 +13:00
|
|
|
#include <malloc.h>
|
2009-06-03 08:23:38 +12:00
|
|
|
#endif
|
2008-07-14 09:15:55 +12:00
|
|
|
#include "common.h"
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char DAFTSET[] = "FADT";
|
|
|
|
static const char KRSET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
static const char KASUTSET[] = "1234567890-abcdefgh";
|
|
|
|
static const char CHKASUTSET[] = "0123456789-abcdefgh";
|
|
|
|
#define SHKASUTSET_F (IS_NUM_F | IS_MNS_F | IS_UPR_F) /* SHKASUTSET "1234567890-ABCDEFGHIJKLMNOPQRSTUVWXYZ" */
|
2008-07-14 09:15:55 +12:00
|
|
|
|
|
|
|
/* PostNet number encoding table - In this table L is long as S is short */
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char PNTable[10][5] = {
|
|
|
|
{'L','L','S','S','S'}, {'S','S','S','L','L'}, {'S','S','L','S','L'}, {'S','S','L','L','S'}, {'S','L','S','S','L'},
|
|
|
|
{'S','L','S','L','S'}, {'S','L','L','S','S'}, {'L','S','S','S','L'}, {'L','S','S','L','S'}, {'L','S','L','S','S'}
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char PLTable[10][5] = {
|
|
|
|
{'S','S','L','L','L'}, {'L','L','L','S','S'}, {'L','L','S','L','S'}, {'L','L','S','S','L'}, {'L','S','L','L','S'},
|
|
|
|
{'L','S','L','S','L'}, {'L','S','S','L','L'}, {'S','L','L','L','S'}, {'S','L','L','S','L'}, {'S','L','S','L','L'}
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char RoyalValues[36][2] = {
|
|
|
|
{ 1, 1 }, { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 0 }, { 2, 1 }, { 2, 2 }, { 2, 3 }, { 2, 4 },
|
|
|
|
{ 2, 5 }, { 2, 0 }, { 3, 1 }, { 3, 2 }, { 3, 3 }, { 3, 4 }, { 3, 5 }, { 3, 0 }, { 4, 1 }, { 4, 2 },
|
|
|
|
{ 4, 3 }, { 4, 4 }, { 4, 5 }, { 4, 0 }, { 5, 1 }, { 5, 2 }, { 5, 3 }, { 5, 4 }, { 5, 5 }, { 5, 0 },
|
|
|
|
{ 0, 1 }, { 0, 2 }, { 0, 3 }, { 0, 4 }, { 0, 5 }, { 0, 0 }
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2008-09-16 19:46:22 +12:00
|
|
|
/* 0 = Full, 1 = Ascender, 2 = Descender, 3 = Tracker */
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char RoyalTable[36][4] = {
|
|
|
|
{'3','3','0','0'}, {'3','2','1','0'}, {'3','2','0','1'}, {'2','3','1','0'}, {'2','3','0','1'}, {'2','2','1','1'},
|
|
|
|
{'3','1','2','0'}, {'3','0','3','0'}, {'3','0','2','1'}, {'2','1','3','0'}, {'2','1','2','1'}, {'2','0','3','1'},
|
|
|
|
{'3','1','0','2'}, {'3','0','1','2'}, {'3','0','0','3'}, {'2','1','1','2'}, {'2','1','0','3'}, {'2','0','1','3'},
|
|
|
|
{'1','3','2','0'}, {'1','2','3','0'}, {'1','2','2','1'}, {'0','3','3','0'}, {'0','3','2','1'}, {'0','2','3','1'},
|
|
|
|
{'1','3','0','2'}, {'1','2','1','2'}, {'1','2','0','3'}, {'0','3','1','2'}, {'0','3','0','3'}, {'0','2','1','3'},
|
|
|
|
{'1','1','2','2'}, {'1','0','3','2'}, {'1','0','2','3'}, {'0','1','3','2'}, {'0','1','2','3'}, {'0','0','3','3'}
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char FlatTable[10][4] = {
|
|
|
|
{'0','5','0','4'}, { "18" }, {'0','1','1','7'}, {'0','2','1','6'}, {'0','3','1','5'},
|
|
|
|
{'0','4','1','4'}, {'0','5','1','3'}, {'0','6','1','2'}, {'0','7','1','1'}, {'0','8','1','0'}
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char KoreaTable[10][10] = {
|
|
|
|
{'1','3','1','3','1','5','0','6','1','3'}, {'0','7','1','3','1','3','1','3','1','3'},
|
|
|
|
{'0','4','1','7','1','3','1','3','1','3'}, {'1','5','0','6','1','3','1','3','1','3'},
|
|
|
|
{'0','4','1','3','1','7','1','3','1','3'}, { "17171313" },
|
|
|
|
{'1','3','1','5','0','6','1','3','1','3'}, {'0','4','1','3','1','3','1','7','1','3'},
|
|
|
|
{ "17131713" }, { "13171713" }
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char JapanTable[19][3] = {
|
|
|
|
{'1','1','4'}, {'1','3','2'}, {'3','1','2'}, {'1','2','3'}, {'1','4','1'},
|
|
|
|
{'3','2','1'}, {'2','1','3'}, {'2','3','1'}, {'4','1','1'}, {'1','4','4'},
|
|
|
|
{'4','1','4'}, {'3','2','4'}, {'3','4','2'}, {'2','3','4'}, {'4','3','2'},
|
|
|
|
{'2','4','3'}, {'4','2','3'}, {'4','4','1'}, {'1','1','1'}
|
2016-02-20 23:50:15 +13:00
|
|
|
};
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
/* Set height for POSTNET/PLANET codes, maintaining ratio */
|
2021-07-14 06:56:53 +12:00
|
|
|
static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) {
|
2021-06-20 00:11:23 +12:00
|
|
|
/* USPS Domestic Mail Manual (USPS DMM 300) Jan 8, 2006 (updated 2011) 708.4.2.5 POSTNET Barcode Dimensions and
|
|
|
|
Spacing
|
|
|
|
http://web.archive.org/web/20061113174253/http://pe.usps.com/cpim/ftp/manuals/dmm300/full/mailingStandards.pdf
|
|
|
|
Using bar pitch as X (1" / 43) ~ 0.023" based on 22 bars + 21 spaces per inch (bar width 0.015" - 0.025")
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
int error_number = 0;
|
|
|
|
float h_ratio; /* Half ratio */
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
if (symbol->height) {
|
|
|
|
h_ratio = symbol->row_height[1] / (symbol->row_height[0] + symbol->row_height[1]); /* 0.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
|
|
|
symbol->row_height[1] = stripf(symbol->height * h_ratio);
|
2021-06-20 00:11:23 +12:00
|
|
|
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
|
|
|
|
symbol->row_height[1] = 0.5f;
|
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
|
|
|
symbol->row_height[0] = stripf(0.5f / h_ratio - 0.5f); /* 0.75 */
|
2021-06-20 00:11:23 +12: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
|
|
|
symbol->row_height[0] = stripf(symbol->height - symbol->row_height[1]);
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
symbol->height = stripf(symbol->row_height[0] + symbol->row_height[1]);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
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) {
|
|
|
|
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");
|
|
|
|
}
|
2021-07-14 06:56:53 +12:00
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Handles the PostNet system used for Zip codes in the US */
|
2021-10-21 11:05:30 +13:00
|
|
|
static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[], char *d, const int length) {
|
2020-06-05 05:45:25 +12:00
|
|
|
int i, sum, check_digit;
|
2021-07-14 06:56:53 +12:00
|
|
|
int error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-07-14 06:56:53 +12:00
|
|
|
if (length > 38) {
|
|
|
|
strcpy(symbol->errtxt, "480: Input too long (38 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-07-14 06:56:53 +12:00
|
|
|
if (length != 5 && length != 9 && length != 11) {
|
|
|
|
strcpy(symbol->errtxt, "479: Input length is not standard (5, 9 or 11 characters)");
|
|
|
|
error_number = ZINT_WARN_NONCOMPLIANT;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(NEON_F, source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "481: Invalid character in data (digits only)");
|
2021-07-14 06:56:53 +12:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
sum = 0;
|
|
|
|
|
|
|
|
/* start character */
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'L';
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0; i < length; i++, d += 5) {
|
|
|
|
const int val = source[i] - '0';
|
|
|
|
memcpy(d, PNTable[val], 5);
|
|
|
|
sum += val;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
check_digit = (10 - (sum % 10)) % 10;
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, PNTable[check_digit], 5);
|
|
|
|
d += 5;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
/* stop character */
|
2021-10-21 11:05:30 +13:00
|
|
|
strcpy(d, "L");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
2013-01-01 02:41:59 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Puts PostNet barcodes into the pattern matrix */
|
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
|
|
|
INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-07-14 06:56:53 +12:00
|
|
|
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
|
2016-02-20 23:50:15 +13:00
|
|
|
unsigned int loopey, h;
|
|
|
|
int writer;
|
2021-07-14 06:56:53 +12:00
|
|
|
int error_number, warn_number;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
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
|
|
|
error_number = postnet_enc(symbol, source, height_pattern, length);
|
2021-07-14 06:56:53 +12:00
|
|
|
if (error_number >= ZINT_ERROR) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer = 0;
|
2021-06-10 22:15:39 +12:00
|
|
|
h = (int) strlen(height_pattern);
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
if (height_pattern[loopey] == 'L') {
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
2020-10-01 00:19:12 +13:00
|
|
|
writer += 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-07-14 06:56:53 +12:00
|
|
|
warn_number = usps_set_height(symbol, error_number /*no_errtxt*/);
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->rows = 2;
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
2021-07-14 06:56:53 +12:00
|
|
|
return error_number ? error_number : warn_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2020-10-01 00:19:12 +13:00
|
|
|
/* Handles the PLANET system used for item tracking in the US */
|
2021-10-21 11:05:30 +13:00
|
|
|
static int planet_enc(struct zint_symbol *symbol, const unsigned char source[], char *d, const int length) {
|
2020-06-05 05:45:25 +12:00
|
|
|
int i, sum, check_digit;
|
2021-07-14 06:56:53 +12:00
|
|
|
int error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-07-14 06:56:53 +12:00
|
|
|
if (length > 38) {
|
|
|
|
strcpy(symbol->errtxt, "482: Input too long (38 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-07-14 06:56:53 +12:00
|
|
|
if (length != 11 && length != 13) {
|
|
|
|
strcpy(symbol->errtxt, "478: Input length is not standard (11 or 13 characters)");
|
|
|
|
error_number = ZINT_WARN_NONCOMPLIANT;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(NEON_F, source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "483: Invalid character in data (digits only)");
|
2021-07-14 06:56:53 +12:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
sum = 0;
|
|
|
|
|
|
|
|
/* start character */
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = 'L';
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0; i < length; i++, d += 5) {
|
|
|
|
const int val = source[i] - '0';
|
|
|
|
memcpy(d, PLTable[val], 5);
|
|
|
|
sum += val;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
check_digit = (10 - (sum % 10)) % 10;
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, PLTable[check_digit], 5);
|
|
|
|
d += 5;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
/* stop character */
|
2021-10-21 11:05:30 +13:00
|
|
|
strcpy(d, "L");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Puts PLANET barcodes into the pattern matrix */
|
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
|
|
|
INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-07-14 06:56:53 +12:00
|
|
|
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */
|
2016-02-20 23:50:15 +13:00
|
|
|
unsigned int loopey, h;
|
|
|
|
int writer;
|
2021-07-14 06:56:53 +12:00
|
|
|
int error_number, warn_number;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
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
|
|
|
error_number = planet_enc(symbol, source, height_pattern, length);
|
2021-07-14 06:56:53 +12:00
|
|
|
if (error_number >= ZINT_ERROR) {
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer = 0;
|
2021-06-10 22:15:39 +12:00
|
|
|
h = (int) strlen(height_pattern);
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
if (height_pattern[loopey] == 'L') {
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
2020-10-01 00:19:12 +13:00
|
|
|
writer += 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-07-14 06:56:53 +12:00
|
|
|
warn_number = usps_set_height(symbol, error_number /*no_errtxt*/);
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->rows = 2;
|
|
|
|
symbol->width = writer - 1;
|
2020-10-01 00:19:12 +13:00
|
|
|
|
2021-07-14 06:56:53 +12:00
|
|
|
return error_number ? error_number : warn_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Korean Postal Authority */
|
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
|
|
|
INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|
|
|
int total, loop, check, zeroes, error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
char localstr[8], dest[80];
|
2021-10-21 11:05:30 +13:00
|
|
|
char *d = dest;
|
|
|
|
int posns[6];
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
if (length > 6) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "484: Input too long (6 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(NEON_F, source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "485: Invalid character in data (digits only)");
|
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
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
zeroes = 6 - length;
|
|
|
|
memset(localstr, '0', zeroes);
|
2021-08-10 23:04:25 +12:00
|
|
|
ustrcpy(localstr + zeroes, source);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (loop = 0; loop < 6; loop++) {
|
2021-10-21 11:05:30 +13:00
|
|
|
posns[loop] = ctoi(localstr[loop]);
|
|
|
|
total += posns[loop];
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
check = 10 - (total % 10);
|
|
|
|
if (check == 10) {
|
|
|
|
check = 0;
|
|
|
|
}
|
|
|
|
localstr[6] = itoc(check);
|
|
|
|
localstr[7] = '\0';
|
2021-10-21 11:05:30 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loop = 5; loop >= 0; loop--) {
|
2021-10-21 11:05:30 +13:00
|
|
|
const char *const entry = KoreaTable[posns[loop]];
|
|
|
|
memcpy(d, entry, 10);
|
|
|
|
d += entry[8] ? 10 : 8;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, KoreaTable[check], 10);
|
|
|
|
d += KoreaTable[check][8] ? 10 : 8;
|
|
|
|
|
|
|
|
expand(symbol, dest, d - dest);
|
|
|
|
|
2021-08-10 23:04:25 +12:00
|
|
|
ustrcpy(symbol->text, localstr);
|
2020-10-01 00:19:12 +13:00
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
// TODO: Find documentation on BARCODE_KOREAPOST dimensions/height
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2008-12-08 09:11:50 +13:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* The simplest barcode symbology ever! Supported by MS Word, so here it is!
|
|
|
|
glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-06-20 00:11:23 +12:00
|
|
|
int error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
if (length > 1) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "486: Input too long (1 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((char) source[0]) {
|
|
|
|
case 'a':
|
|
|
|
case 'A':
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, "111515111", 9);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, "13111311131", 11);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
case 'C':
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, "11131313111", 11);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, "1111131311111", 13);
|
2016-02-20 23:50:15 +13:00
|
|
|
break;
|
2022-01-03 12:22:22 +13:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
expand(symbol, "1317131", 7);
|
|
|
|
break;
|
2016-02-20 23:50:15 +13:00
|
|
|
default:
|
2022-01-03 12:22:22 +13:00
|
|
|
strcpy(symbol->errtxt, "487: Invalid character in data (\"A\", \"B\", \"C\", \"D\" or \"E\" only)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
/* 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*/);
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
|
|
|
|
return error_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set height for DAFT-type codes, maintaining ratio. Expects row_height[0] & row_height[1] to be set */
|
|
|
|
/* Used by auspost.c also */
|
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
|
|
|
int error_number = 0;
|
|
|
|
float t_ratio; /* Tracker ratio */
|
|
|
|
|
|
|
|
if (symbol->height) {
|
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
|
|
|
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);
|
2021-06-20 00:11:23 +12:00
|
|
|
if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */
|
|
|
|
symbol->row_height[1] = 0.5f;
|
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
|
|
|
symbol->row_height[0] = stripf(0.25f / t_ratio - 0.25f);
|
2021-06-20 00:11:23 +12: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
|
|
|
symbol->row_height[0] = stripf(stripf(symbol->height - symbol->row_height[1]) / 2.0f);
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
if (symbol->row_height[0] < 0.5f) {
|
|
|
|
symbol->row_height[0] = 0.5f;
|
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
|
|
|
symbol->row_height[1] = stripf(t_ratio / (1.0f - t_ratio));
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
symbol->row_height[2] = symbol->row_height[0];
|
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
|
|
|
symbol->height = stripf(stripf(symbol->row_height[0] + symbol->row_height[1]) + symbol->row_height[2]);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
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) {
|
|
|
|
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");
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Handles the 4 State barcodes used in the UK by Royal Mail */
|
2021-10-21 11:05:30 +13:00
|
|
|
static void rm4scc_enc(const int *posns, char *d, const int length) {
|
2020-06-05 05:45:25 +12:00
|
|
|
int i;
|
2016-02-20 23:50:15 +13:00
|
|
|
int top, bottom, row, column, check_digit;
|
|
|
|
|
|
|
|
top = 0;
|
|
|
|
bottom = 0;
|
|
|
|
|
|
|
|
/* start character */
|
2021-10-21 11:05:30 +13:00
|
|
|
*d++ = '1';
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0; i < length; i++, d += 4) {
|
|
|
|
const int p = posns[i];
|
|
|
|
memcpy(d, RoyalTable[p], 4);
|
|
|
|
top += RoyalValues[p][0];
|
|
|
|
bottom += RoyalValues[p][1];
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the check digit */
|
|
|
|
row = (top % 6) - 1;
|
|
|
|
column = (bottom % 6) - 1;
|
|
|
|
if (row == -1) {
|
|
|
|
row = 5;
|
|
|
|
}
|
|
|
|
if (column == -1) {
|
|
|
|
column = 5;
|
|
|
|
}
|
|
|
|
check_digit = (6 * row) + column;
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, RoyalTable[check_digit], 4);
|
|
|
|
d += 4;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
/* stop character */
|
2021-10-21 11:05:30 +13:00
|
|
|
strcpy(d, "0");
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Puts RM4SCC into the data matrix */
|
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
|
|
|
INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-08-30 05:45:58 +12:00
|
|
|
char height_pattern[210];
|
2021-10-21 11:05:30 +13:00
|
|
|
int posns[50];
|
2020-06-05 05:45:25 +12:00
|
|
|
int loopey, h;
|
2016-02-20 23:50:15 +13:00
|
|
|
int writer;
|
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
|
|
|
int error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2016-08-30 05:45:58 +12:00
|
|
|
if (length > 50) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "488: Input too long (50 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
to_upper(source, length);
|
|
|
|
if (!is_sane_lookup(KRSET, 36, source, length, posns)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "489: Invalid character in data (alphanumerics only)");
|
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
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
rm4scc_enc(posns, height_pattern, length);
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
writer = 0;
|
2021-06-10 22:15:39 +12:00
|
|
|
h = (int) strlen(height_pattern);
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
|
|
|
if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
|
|
|
|
set_module(symbol, 2, writer);
|
|
|
|
}
|
|
|
|
writer += 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 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);
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->rows = 3;
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Handles Dutch Post TNT KIX symbols
|
2021-10-21 11:05:30 +13:00
|
|
|
The same as RM4SCC but without check digit or stop/start chars
|
2016-02-20 23:50:15 +13:00
|
|
|
Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
|
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
|
|
|
INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
char height_pattern[75];
|
|
|
|
char *d = height_pattern;
|
|
|
|
int posns[18];
|
2020-06-05 05:45:25 +12:00
|
|
|
int loopey;
|
2016-02-20 23:50:15 +13:00
|
|
|
int writer, i, h;
|
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
|
|
|
int error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
if (length > 18) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "490: Input too long (18 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
to_upper(source, length);
|
|
|
|
if (!is_sane_lookup(KRSET, 36, source, length, posns)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "491: Invalid character in data (alphanumerics only)");
|
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
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode data */
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0; i < length; i++, d += 4) {
|
|
|
|
memcpy(d, RoyalTable[posns[i]], 4);
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
writer = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
h = d - height_pattern;
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
|
|
|
if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
|
|
|
|
set_module(symbol, 2, writer);
|
|
|
|
}
|
|
|
|
writer += 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) {
|
|
|
|
/* 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);
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->rows = 3;
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
|
|
|
return error_number;
|
2008-09-16 19:46:22 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Handles DAFT Code symbols */
|
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
|
|
|
INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
int posns[100];
|
|
|
|
int loopey;
|
|
|
|
int writer;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (length > 100) {
|
|
|
|
strcpy(symbol->errtxt, "492: Input too long (100 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
to_upper(source, length);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane_lookup(DAFTSET, 4, source, length, posns)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "493: Invalid character in data (\"D\", \"A\", \"F\" and \"T\" only)");
|
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
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
writer = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
for (loopey = 0; loopey < length; loopey++) {
|
|
|
|
if ((posns[loopey] == 1) || (posns[loopey] == 0)) {
|
2016-02-20 23:50:15 +13:00
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
2021-10-21 11:05:30 +13:00
|
|
|
if ((posns[loopey] == 2) || (posns[loopey] == 0)) {
|
2016-02-20 23:50:15 +13:00
|
|
|
set_module(symbol, 2, writer);
|
|
|
|
}
|
|
|
|
writer += 2;
|
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
/* Allow ratio of tracker to be specified in thousandths */
|
|
|
|
if (symbol->option_2 >= 50 && symbol->option_2 <= 900) {
|
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
|
|
|
const float t_ratio = symbol->option_2 / 1000.0f;
|
2021-06-20 00:11:23 +12:00
|
|
|
if (symbol->height < 0.5f) {
|
|
|
|
symbol->height = 8.0f;
|
|
|
|
}
|
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
|
|
|
symbol->row_height[1] = stripf(symbol->height * t_ratio);
|
|
|
|
symbol->row_height[0] = stripf((symbol->height - symbol->row_height[1]) / 2.0);
|
2021-06-20 00:11:23 +12:00
|
|
|
} else {
|
|
|
|
symbol->row_height[0] = 3.0f;
|
|
|
|
symbol->row_height[1] = 2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DAFT generic barcode so no dimensions/height specification */
|
|
|
|
(void) daft_set_height(symbol, 0.0f, 0.0f);
|
2016-02-20 23:50:15 +13:00
|
|
|
symbol->rows = 3;
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
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
|
|
|
return 0;
|
2008-09-03 07:47:26 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Flattermarken - Not really a barcode symbology! */
|
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
|
|
|
INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|
|
|
int loop, error_number = 0;
|
2016-02-20 23:50:15 +13:00
|
|
|
char dest[512]; /* 90 * 4 + 1 ~ */
|
2021-10-21 11:05:30 +13:00
|
|
|
char *d = dest;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
if (length > 90) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "494: Input too long (90 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(NEON_F, source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "495: Invalid character in data (digits only)");
|
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
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loop = 0; loop < length; loop++) {
|
2021-10-21 11:05:30 +13:00
|
|
|
const char *const entry = FlatTable[source[loop] - '0'];
|
|
|
|
memcpy(d, entry, 4);
|
|
|
|
d += entry[2] ? 4 : 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, dest, d - dest);
|
2020-10-01 00:19:12 +13:00
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
// TODO: Find documentation on BARCODE_FLAT dimensions/height
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
2009-03-15 00:04:52 +13:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
/* Japanese Postal Code (Kasutama Barcode) */
|
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
|
|
|
INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|
|
|
int error_number = 0, h;
|
2016-02-20 23:50:15 +13:00
|
|
|
char pattern[69];
|
2021-10-21 11:05:30 +13:00
|
|
|
char *d = pattern;
|
2016-02-20 23:50:15 +13:00
|
|
|
int writer, loopey, inter_posn, i, sum, check;
|
|
|
|
char check_char;
|
2021-10-21 11:05:30 +13:00
|
|
|
char inter[20 + 1];
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2016-08-30 05:45:58 +12:00
|
|
|
if (length > 20) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "496: Input too long (20 character maximum)");
|
2016-08-30 05:45:58 +12:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
to_upper(source, length);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(SHKASUTSET_F, source, length)) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "497: Invalid character in data (alphanumerics and \"-\" only)");
|
2018-02-07 09:57:01 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
memset(inter, 'd', 20); /* Pad character CC4 */
|
|
|
|
inter[20] = '\0';
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
inter_posn = 0;
|
|
|
|
do {
|
2021-10-21 11:05:30 +13:00
|
|
|
if (((source[i] >= '0') && (source[i] <= '9')) || (source[i] == '-')) {
|
|
|
|
inter[inter_posn] = source[i];
|
2016-02-20 23:50:15 +13:00
|
|
|
inter_posn++;
|
|
|
|
} else {
|
2021-10-21 11:05:30 +13:00
|
|
|
if (source[i] <= 'J') {
|
2016-02-20 23:50:15 +13:00
|
|
|
inter[inter_posn] = 'a';
|
2021-10-21 11:05:30 +13:00
|
|
|
inter[inter_posn + 1] = source[i] - 'A' + '0';
|
|
|
|
} else if (source[i] <= 'T') {
|
2016-02-20 23:50:15 +13:00
|
|
|
inter[inter_posn] = 'b';
|
2021-10-21 11:05:30 +13:00
|
|
|
inter[inter_posn + 1] = source[i] - 'K' + '0';
|
|
|
|
} else { /* (source[i] >= 'U') && (source[i] <= 'Z') */
|
2016-02-20 23:50:15 +13:00
|
|
|
inter[inter_posn] = 'c';
|
2021-10-21 11:05:30 +13:00
|
|
|
inter[inter_posn + 1] = source[i] - 'U' + '0';
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
inter_posn += 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
} while ((i < length) && (inter_posn < 20));
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (i != length || inter[20] != '\0') {
|
|
|
|
strcpy(symbol->errtxt, "477: Input too long (20 symbol character maximum)");
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(d, "13", 2); /* Start */
|
|
|
|
d += 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
sum = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
for (i = 0; i < 20; i++, d += 3) {
|
|
|
|
memcpy(d, JapanTable[posn(KASUTSET, inter[i])], 3);
|
2016-02-20 23:50:15 +13:00
|
|
|
sum += posn(CHKASUTSET, inter[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate check digit */
|
|
|
|
check = 19 - (sum % 19);
|
|
|
|
if (check == 19) {
|
|
|
|
check = 0;
|
|
|
|
}
|
|
|
|
if (check <= 9) {
|
|
|
|
check_char = check + '0';
|
2019-11-28 05:16:14 +13:00
|
|
|
} else if (check == 10) {
|
2016-02-20 23:50:15 +13:00
|
|
|
check_char = '-';
|
2019-11-28 05:16:14 +13:00
|
|
|
} else {
|
2016-02-20 23:50:15 +13:00
|
|
|
check_char = (check - 11) + 'a';
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, JapanTable[posn(KASUTSET, check_char)], 3);
|
|
|
|
d += 3;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
2021-08-06 03:34:45 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check: %d, char: %c\n", check, check_char);
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, "31", 2); /* Stop */
|
|
|
|
d += 2;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
/* Resolve pattern to 4-state symbols */
|
|
|
|
writer = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
h = d - pattern;
|
2016-02-20 23:50:15 +13:00
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) {
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
}
|
|
|
|
set_module(symbol, 1, writer);
|
|
|
|
if ((pattern[loopey] == '3') || (pattern[loopey] == '1')) {
|
|
|
|
set_module(symbol, 2, writer);
|
|
|
|
}
|
|
|
|
writer += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol->rows = 3;
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
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) {
|
|
|
|
/* 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);
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
return error_number;
|
2009-03-15 00:04:52 +13:00
|
|
|
}
|