2008-07-14 09:15:55 +12:00
|
|
|
/* 2of5.c - Handles Code 2 of 5 barcodes */
|
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2022-07-15 03:01:30 +12:00
|
|
|
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
|
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 22:38:03 +13:00
|
|
|
*/
|
2022-07-15 03:01:30 +12:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2008-07-14 09:15:55 +12:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "common.h"
|
2021-06-27 22:47:55 +12:00
|
|
|
#include "gs1.h"
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char C25MatrixTable[10][6] = {
|
|
|
|
{'1','1','3','3','1','1'}, {'3','1','1','1','3','1'}, {'1','3','1','1','3','1'}, {'3','3','1','1','1','1'},
|
|
|
|
{'1','1','3','1','3','1'}, {'3','1','3','1','1','1'}, {'1','3','3','1','1','1'}, {'1','1','1','3','3','1'},
|
|
|
|
{'3','1','1','3','1','1'}, {'1','3','1','3','1','1'}
|
2016-02-20 22:38:03 +13:00
|
|
|
};
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char C25IndustTable[10][10] = {
|
|
|
|
{'1','1','1','1','3','1','3','1','1','1'}, {'3','1','1','1','1','1','1','1','3','1'},
|
|
|
|
{'1','1','3','1','1','1','1','1','3','1'}, {'3','1','3','1','1','1','1','1','1','1'},
|
|
|
|
{'1','1','1','1','3','1','1','1','3','1'}, {'3','1','1','1','3','1','1','1','1','1'},
|
|
|
|
{'1','1','3','1','3','1','1','1','1','1'}, {'1','1','1','1','1','1','3','1','3','1'},
|
|
|
|
{'3','1','1','1','1','1','3','1','1','1'}, {'1','1','3','1','1','1','3','1','1','1'}
|
2016-02-20 22:38:03 +13:00
|
|
|
};
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
/* Note `c25_common()` assumes Stop string length one less than Start */
|
|
|
|
static const char *C25MatrixStartStop[2] = { "411111", "41111" };
|
2021-05-18 07:04:00 +12:00
|
|
|
static const char *C25IndustStartStop[2] = { "313111", "31113" };
|
|
|
|
static const char *C25IataLogicStartStop[2] = { "1111", "311" };
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static const char C25InterTable[10][5] = {
|
|
|
|
{'1','1','3','3','1'}, {'3','1','1','1','3'}, {'1','3','1','1','3'}, {'3','3','1','1','1'}, {'1','1','3','1','3'},
|
|
|
|
{'3','1','3','1','1'}, {'1','3','3','1','1'}, {'1','1','1','3','3'}, {'3','1','1','3','1'}, {'1','3','1','3','1'}
|
2016-02-20 22:38:03 +13:00
|
|
|
};
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
static char c25_check_digit(const unsigned int count) {
|
2016-02-20 22:38:03 +13:00
|
|
|
return itoc((10 - (count % 10)) % 10);
|
2011-03-08 22:58:48 +13:00
|
|
|
}
|
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
/* Common to Standard (Matrix), Industrial, IATA, and Data Logic */
|
|
|
|
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
|
2021-10-21 11:05:30 +13:00
|
|
|
const int is_matrix, const char *start_stop[2], const int start_length, const int error_base) {
|
2008-07-14 09:15:55 +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
|
|
|
int i;
|
2021-10-21 11:05:30 +13:00
|
|
|
char dest[500]; /* Largest destination 6 + (80 + 1) * 6 + 5 + 1 = 498 */
|
|
|
|
char *d = dest;
|
|
|
|
unsigned char temp[80 + 1 + 1]; /* Largest maximum 80 + optional check digit */
|
2021-05-18 07:04:00 +12:00
|
|
|
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
if (length > max) {
|
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-29 09:42:44 +13:00
|
|
|
/* errtxt 301: 303: 305: 307: */
|
2021-07-07 06:53:31 +12:00
|
|
|
sprintf(symbol->errtxt, "%d: Input too long (%d character maximum)", error_base, max);
|
2016-02-20 22:38:03 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
if (!is_sane(NEON_F, source, length)) {
|
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-29 09:42:44 +13:00
|
|
|
/* errtxt 302: 304: 306: 308: */
|
2021-07-07 06:53:31 +12:00
|
|
|
sprintf(symbol->errtxt, "%d: Invalid character in data (digits only)", error_base + 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 ZINT_ERROR_INVALID_DATA;
|
2016-02-20 22:38:03 +13:00
|
|
|
}
|
2012-12-30 07:37:03 +13:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
ustrcpy(temp, source);
|
|
|
|
|
|
|
|
if (have_checkdigit) {
|
|
|
|
/* Add standard GS1 check digit */
|
2021-06-27 22:47:55 +12:00
|
|
|
temp[length] = gs1_check_digit(source, length);
|
2021-05-18 07:04:00 +12:00
|
|
|
temp[++length] = '\0';
|
|
|
|
}
|
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
/* Start character */
|
|
|
|
memcpy(d, start_stop[0], start_length);
|
|
|
|
d += start_length;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
if (is_matrix) {
|
|
|
|
for (i = 0; i < length; i++, d += 6) {
|
|
|
|
memcpy(d, C25MatrixTable[temp[i] - '0'], 6);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < length; i++, d += 10) {
|
|
|
|
memcpy(d, C25IndustTable[temp[i] - '0'], 10);
|
|
|
|
}
|
2016-02-20 22:38:03 +13:00
|
|
|
}
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
/* Stop character */
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, start_stop[1], start_length - 1);
|
|
|
|
d += start_length - 1;
|
2012-12-30 07:37:03 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, dest, d - dest);
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
ustrcpy(symbol->text, temp);
|
|
|
|
if (symbol->option_2 == 2) {
|
|
|
|
/* Remove check digit from HRT */
|
|
|
|
symbol->text[length - 1] = '\0';
|
2016-02-20 22:38:03 +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
|
|
|
return 0;
|
2021-05-18 07:04:00 +12:00
|
|
|
}
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
/* Code 2 of 5 Standard (Code 2 of 5 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 c25standard(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
return c25_common(symbol, source, length, 80, 1 /*is_matrix*/, C25MatrixStartStop, 6, 301);
|
2021-05-18 07:04:00 +12:00
|
|
|
}
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
/* Code 2 of 5 Industrial */
|
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 c25ind(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
return c25_common(symbol, source, length, 45, 0 /*is_matrix*/, C25IndustStartStop, 6, 303);
|
2021-05-18 07:04:00 +12:00
|
|
|
}
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
/* Code 2 of 5 IATA */
|
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 c25iata(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
return c25_common(symbol, source, length, 45, 0 /*is_matrix*/, C25IataLogicStartStop, 4, 305);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
/* Code 2 of 5 Data Logic */
|
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 c25logic(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
return c25_common(symbol, source, length, 80, 1 /*is_matrix*/, C25IataLogicStartStop, 4, 307);
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
/* Common to Interleaved, ITF-14, DP Leitcode, DP Identcode */
|
2021-10-21 11:05:30 +13:00
|
|
|
static int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length,
|
2021-06-20 00:11:23 +12:00
|
|
|
const int dont_set_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
|
|
|
int i, j, error_number = 0;
|
2021-10-21 11:05:30 +13:00
|
|
|
char dest[468]; /* 4 + (90 + 2) * 5 + 3 + 1 = 468 */
|
|
|
|
char *d = dest;
|
2021-05-18 07:04:00 +12:00
|
|
|
unsigned char temp[90 + 2 + 1];
|
|
|
|
int have_checkdigit = symbol->option_2 == 1 || symbol->option_2 == 2;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
if (length > 90) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "309: Input too long (90 character maximum)");
|
2016-02-20 22:38:03 +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, "310: 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 22:38:03 +13:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
temp[0] = '\0';
|
2016-02-20 22:38:03 +13:00
|
|
|
/* Input must be an even number of characters for Interlaced 2 of 5 to work:
|
2021-05-18 07:04:00 +12:00
|
|
|
if an odd number of characters has been entered and no check digit or an even number and have check digit
|
|
|
|
then add a leading zero */
|
|
|
|
if (((length & 1) && !have_checkdigit) || (!(length & 1) && have_checkdigit)) {
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(temp, "0");
|
2016-02-20 22:38:03 +13:00
|
|
|
length++;
|
|
|
|
}
|
2020-12-23 23:57:24 +13:00
|
|
|
ustrncat(temp, source, length);
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-05-18 07:04:00 +12:00
|
|
|
if (have_checkdigit) {
|
|
|
|
/* Add standard GS1 check digit */
|
2021-06-27 22:47:55 +12:00
|
|
|
temp[length] = gs1_check_digit(temp, length);
|
2021-05-18 07:04:00 +12:00
|
|
|
temp[++length] = '\0';
|
|
|
|
}
|
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
/* start character */
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, "1111", 4);
|
|
|
|
d += 4;
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
for (i = 0; i < length; i += 2) {
|
2021-10-21 11:05:30 +13:00
|
|
|
/* look up the bars and the spaces */
|
|
|
|
const char *const bars = C25InterTable[temp[i] - '0'];
|
|
|
|
const char *const spaces = C25InterTable[temp[i + 1] - '0'];
|
2016-02-20 22:38:03 +13:00
|
|
|
|
|
|
|
/* then merge (interlace) the strings together */
|
2021-10-21 11:05:30 +13:00
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
*d++ = bars[j];
|
|
|
|
*d++ = spaces[j];
|
2016-02-20 22:38:03 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop character */
|
2021-10-21 11:05:30 +13:00
|
|
|
memcpy(d, "311", 3);
|
|
|
|
d += 3;
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
expand(symbol, dest, d - dest);
|
2021-05-18 07:04:00 +12:00
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
ustrcpy(symbol->text, temp);
|
2021-05-18 07:04:00 +12:00
|
|
|
if (symbol->option_2 == 2) {
|
|
|
|
/* Remove check digit from HRT */
|
|
|
|
symbol->text[length - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
if (!dont_set_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
|
|
|
if (symbol->output_options & COMPLIANT_HEIGHT) {
|
|
|
|
/* ISO/IEC 16390:2007 Section 4.4 min height 5mm or 15% of symbol width whichever greater where
|
|
|
|
(P = character pairs, N = wide/narrow ratio = 3)
|
|
|
|
width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */
|
|
|
|
/* Taking X = 0.330mm from Annex D.3.1 (application specification) */
|
|
|
|
const float min_height_min = stripf(5.0f / 0.33f);
|
|
|
|
float min_height = stripf((18.0f * (length / 2) + 9.0f) * 0.15f);
|
|
|
|
if (min_height < min_height_min) {
|
|
|
|
min_height = min_height_min;
|
|
|
|
}
|
|
|
|
/* Using 50 as default as none recommended */
|
|
|
|
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
|
|
|
|
0 /*no_errtxt*/);
|
|
|
|
} else {
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
/* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */
|
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 c25inter(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-10-21 11:05:30 +13:00
|
|
|
return c25_inter_common(symbol, source, length, 0 /*dont_set_height*/);
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Interleaved 2-of-5 (ITF-14) */
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-06-20 00:11:23 +12:00
|
|
|
int i, error_number, warn_number = 0, zeroes;
|
2021-05-18 07:04:00 +12:00
|
|
|
unsigned char localstr[16] = {0};
|
2016-02-20 22:38:03 +13:00
|
|
|
|
|
|
|
if (length > 13) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "311: Input too long (13 character maximum)");
|
2016-02-20 22:38:03 +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, "312: 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 22:38:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add leading zeros as required */
|
|
|
|
zeroes = 13 - length;
|
|
|
|
for (i = 0; i < zeroes; i++) {
|
|
|
|
localstr[i] = '0';
|
|
|
|
}
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(localstr + zeroes, source);
|
2016-02-20 22:38:03 +13:00
|
|
|
|
|
|
|
/* Calculate the check digit - the same method used for EAN-13 */
|
2021-06-27 22:47:55 +12:00
|
|
|
localstr[13] = gs1_check_digit(localstr, 13);
|
2016-02-20 22:38:03 +13:00
|
|
|
localstr[14] = '\0';
|
2021-10-21 11:05:30 +13:00
|
|
|
error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(symbol->text, localstr);
|
2020-07-16 06:00:12 +12:00
|
|
|
|
2020-07-30 21:09:17 +12:00
|
|
|
if (!((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND))) {
|
2022-07-15 03:01:30 +12:00
|
|
|
/* If no option has been selected then uses default box option */
|
2020-07-30 21:09:17 +12:00
|
|
|
symbol->output_options |= BARCODE_BOX;
|
|
|
|
if (symbol->border_width == 0) { /* Allow override if non-zero */
|
2021-01-29 12:41:54 +13:00
|
|
|
/* GS1 General Specifications 21.0.1 Sections 5.3.2.4 & 5.3.6 (4.83 / 1.016 ~ 4.75) */
|
2020-07-30 21:09:17 +12:00
|
|
|
symbol->border_width = 5; /* Note change from previous value 8 */
|
|
|
|
}
|
2020-07-16 06:00:12 +12:00
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
if (error_number < ZINT_ERROR) {
|
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) {
|
|
|
|
/* GS1 General Specifications 21.0.1 5.12.3.2 table 2, including footnote (**): (note bind/box additional
|
|
|
|
to symbol->height), same as GS1-128: "in case of further space constraints"
|
|
|
|
height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */
|
|
|
|
warn_number = set_height(symbol, stripf(5.8f / 1.016f), stripf(31.75f / 0.495f), 0.0f, 0 /*no_errtxt*/);
|
|
|
|
} else {
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
return error_number ? error_number : warn_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2022-08-06 10:51:24 +12:00
|
|
|
/* Deutsche Post Leitcode */
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-02-20 22:38:03 +13:00
|
|
|
int i, error_number;
|
|
|
|
unsigned int count;
|
2021-10-21 11:05:30 +13:00
|
|
|
int factor;
|
2021-05-18 07:04:00 +12:00
|
|
|
unsigned char localstr[16] = {0};
|
2016-02-20 22:38:03 +13:00
|
|
|
int zeroes;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
if (length > 13) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "313: Input wrong length (13 character maximum)");
|
2016-02-20 22:38:03 +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, "314: 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 22:38:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
zeroes = 13 - length;
|
|
|
|
for (i = 0; i < zeroes; i++)
|
|
|
|
localstr[i] = '0';
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(localstr + zeroes, source);
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
factor = 4;
|
2016-02-20 22:38:03 +13:00
|
|
|
for (i = 12; i >= 0; i--) {
|
2021-10-21 11:05:30 +13:00
|
|
|
count += factor * ctoi(localstr[i]);
|
|
|
|
factor ^= 0x0D; /* Toggles 4 and 9 */
|
2016-02-20 22:38:03 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
localstr[13] = c25_check_digit(count);
|
2016-02-20 22:38:03 +13:00
|
|
|
localstr[14] = '\0';
|
2021-10-21 11:05:30 +13:00
|
|
|
error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(symbol->text, localstr);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* TODO: Find documentation on BARCODE_DPLEIT dimensions/height */
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
/* Deutsche Post Identcode */
|
2019-12-19 13:37:55 +13:00
|
|
|
INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-02-20 22:38:03 +13:00
|
|
|
int i, error_number, zeroes;
|
|
|
|
unsigned int count;
|
2021-10-21 11:05:30 +13:00
|
|
|
int factor;
|
2021-05-18 07:04:00 +12:00
|
|
|
unsigned char localstr[16] = {0};
|
2016-02-20 22:38:03 +13:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
if (length > 11) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "315: Input wrong length (11 character maximum)");
|
2016-02-20 22:38:03 +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, "316: 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 22:38:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
zeroes = 11 - length;
|
|
|
|
for (i = 0; i < zeroes; i++)
|
|
|
|
localstr[i] = '0';
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(localstr + zeroes, source);
|
2016-02-20 22:38:03 +13:00
|
|
|
|
2021-10-21 11:05:30 +13:00
|
|
|
factor = 4;
|
2016-02-20 22:38:03 +13:00
|
|
|
for (i = 10; i >= 0; i--) {
|
2021-10-21 11:05:30 +13:00
|
|
|
count += factor * ctoi(localstr[i]);
|
|
|
|
factor ^= 0x0D; /* Toggles 4 and 9 */
|
2016-02-20 22:38:03 +13:00
|
|
|
}
|
2021-10-21 11:05:30 +13:00
|
|
|
localstr[11] = c25_check_digit(count);
|
2016-02-20 22:38:03 +13:00
|
|
|
localstr[12] = '\0';
|
2021-10-21 11:05:30 +13:00
|
|
|
error_number = c25_inter_common(symbol, localstr, 12, 1 /*dont_set_height*/);
|
2020-06-05 05:45:25 +12:00
|
|
|
ustrcpy(symbol->text, localstr);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2022-07-15 03:01:30 +12:00
|
|
|
/* TODO: Find documentation on BARCODE_DPIDENT dimensions/height */
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2016-02-20 22:38:03 +13:00
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
2022-07-15 03:01:30 +12:00
|
|
|
|
|
|
|
/* vim: set ts=4 sw=4 et : */
|