2008-07-14 09:15:55 +12:00
|
|
|
/* telepen.c - Handles Telepen and Telepen numeric */
|
|
|
|
|
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2021-06-20 00:11:23 +12:00
|
|
|
Copyright (C) 2008-2021 Robin Stuart <rstuart114@gmail.com>
|
2008-07-14 09:15:55 +12:00
|
|
|
|
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:
|
2008-07-14 09:15:55 +12:00
|
|
|
|
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.
|
2008-07-14 09:15:55 +12:00
|
|
|
|
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-21 00:29:19 +13:00
|
|
|
*/
|
2019-12-19 13:37:55 +13:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2008-07-14 09:15:55 +12:00
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
/* Telepen Barcode Symbology information and History (BSiH)
|
|
|
|
https://telepen.co.uk/wp-content/uploads/2018/10/Barcode-Symbology-information-and-History.pdf */
|
2020-06-05 05:45:25 +12:00
|
|
|
|
|
|
|
#define SODIUM "0123456789X"
|
2008-09-19 21:16:19 +12:00
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "common.h"
|
|
|
|
|
2016-03-03 10:12:38 +13:00
|
|
|
static char *TeleTable[] = {
|
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
|
|
|
"31313131", "1131313111", "33313111", "1111313131",
|
|
|
|
"3111313111", "11333131", "13133131", "111111313111",
|
|
|
|
"31333111", "1131113131", "33113131", "1111333111",
|
|
|
|
"3111113131", "1113133111", "1311133111", "111111113131",
|
|
|
|
"3131113111", "11313331", "333331", "111131113111",
|
|
|
|
"31113331", "1133113111", "1313113111", "1111113331",
|
|
|
|
"31131331", "113111113111", "3311113111", "1111131331",
|
|
|
|
"311111113111", "1113111331", "1311111331", "11111111113111",
|
|
|
|
"31313311", "1131311131", "33311131", "1111313311",
|
|
|
|
"3111311131", "11333311", "13133311", "111111311131",
|
|
|
|
"31331131", "1131113311", "33113311", "1111331131",
|
|
|
|
"3111113311", "1113131131", "1311131131", "111111113311",
|
|
|
|
"3131111131", "1131131311", "33131311", "111131111131",
|
|
|
|
"3111131311", "1133111131", "1313111131", "111111131311",
|
|
|
|
"3113111311", "113111111131", "3311111131", "111113111311",
|
|
|
|
"311111111131", "111311111311", "131111111311", "11111111111131",
|
|
|
|
"3131311111", "11313133", "333133", "111131311111",
|
|
|
|
"31113133", "1133311111", "1313311111", "1111113133",
|
|
|
|
"313333", "113111311111", "3311311111", "11113333",
|
|
|
|
"311111311111", "11131333", "13111333", "11111111311111",
|
|
|
|
"31311133", "1131331111", "33331111", "1111311133",
|
|
|
|
"3111331111", "11331133", "13131133", "111111331111",
|
|
|
|
"3113131111", "1131111133", "33111133", "111113131111",
|
|
|
|
"3111111133", "111311131111", "131111131111", "111111111133",
|
|
|
|
"31311313", "113131111111", "3331111111", "1111311313",
|
|
|
|
"311131111111", "11331313", "13131313", "11111131111111",
|
|
|
|
"3133111111", "1131111313", "33111313", "111133111111",
|
|
|
|
"3111111313", "111313111111", "131113111111", "111111111313",
|
|
|
|
"313111111111", "1131131113", "33131113", "11113111111111",
|
|
|
|
"3111131113", "113311111111", "131311111111", "111111131113",
|
|
|
|
"3113111113", "11311111111111", "331111111111", "111113111113",
|
|
|
|
"31111111111111", "111311111113", "131111111113", "1111111111111111",
|
2016-02-21 00:29:19 +13:00
|
|
|
};
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
|
|
|
int i, count, check_digit;
|
2016-02-21 00:29:19 +13:00
|
|
|
int error_number;
|
2020-06-05 05:45:25 +12:00
|
|
|
char dest[521]; /* 12 (start) + 30 * 16 (max for DELs) + 16 (check digit) + 12 (stop) + 1 = 521 */
|
2016-02-21 00:29:19 +13:00
|
|
|
|
|
|
|
error_number = 0;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
if (src_len > 30) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "390: Input too long (30 character maximum)");
|
2016-02-21 00:29:19 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
/* Start character */
|
|
|
|
strcpy(dest, TeleTable['_']);
|
|
|
|
|
|
|
|
for (i = 0; i < src_len; i++) {
|
2020-06-05 05:45:25 +12:00
|
|
|
if (source[i] > 127) {
|
2016-02-21 00:29:19 +13:00
|
|
|
/* Cannot encode extended ASCII */
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "391: Invalid character in input data, extended ASCII not allowed");
|
2016-02-21 00:29:19 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable[source[i]]);
|
2016-02-21 00:29:19 +13:00
|
|
|
count += source[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
check_digit = 127 - (count % 127);
|
|
|
|
if (check_digit == 127) {
|
|
|
|
check_digit = 0;
|
|
|
|
}
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable[check_digit]);
|
2016-02-21 00:29:19 +13:00
|
|
|
|
2021-07-27 02:29:05 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
|
|
|
|
|
2016-02-21 00:29:19 +13:00
|
|
|
/* Stop character */
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable['z']);
|
2016-02-21 00:29:19 +13:00
|
|
|
|
|
|
|
expand(symbol, dest);
|
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) {
|
|
|
|
/* Default height from various Telepen docs is based on default 26pt at X 0.01125"
|
|
|
|
(average of 0.01" - 0.0125") = (26 / 72) / 0.01125 ~ 32; no min height specified */
|
|
|
|
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/);
|
|
|
|
} else {
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2016-02-21 00:29:19 +13:00
|
|
|
for (i = 0; i < src_len; i++) {
|
|
|
|
if (source[i] == '\0') {
|
|
|
|
symbol->text[i] = ' ';
|
|
|
|
} else {
|
|
|
|
symbol->text[i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
symbol->text[src_len] = '\0';
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) {
|
|
|
|
int count, check_digit, glyph;
|
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;
|
2020-12-23 23:57:24 +13:00
|
|
|
int i;
|
2020-06-05 05:45:25 +12:00
|
|
|
char dest[521]; /* 12 (start) + 30 * 16 (max for DELs) + 16 (check digit) + 12 (stop) + 1 = 521 */
|
2016-02-21 00:29:19 +13:00
|
|
|
unsigned char temp[64];
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
if (src_len > 60) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "392: Input too long (60 character maximum)");
|
2016-02-21 00:29:19 +13:00
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
}
|
|
|
|
ustrcpy(temp, source);
|
|
|
|
to_upper(temp);
|
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 (is_sane(SODIUM, temp, src_len) != 0) {
|
2021-07-07 06:53:31 +12:00
|
|
|
strcpy(symbol->errtxt, "393: Invalid character in data (digits and \"X\" 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-21 00:29:19 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a leading zero if required */
|
2020-12-23 23:57:24 +13:00
|
|
|
if (src_len & 1) {
|
|
|
|
memmove(temp + 1, temp, src_len);
|
2016-02-21 00:29:19 +13:00
|
|
|
temp[0] = '0';
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
temp[++src_len] = '\0';
|
2016-02-21 00:29:19 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start character */
|
|
|
|
strcpy(dest, TeleTable['_']);
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
for (i = 0; i < src_len; i += 2) {
|
2016-02-21 00:29:19 +13:00
|
|
|
if (temp[i] == 'X') {
|
2017-07-28 03:01:53 +12:00
|
|
|
strcpy(symbol->errtxt, "394: Invalid position of X in Telepen data");
|
2016-02-21 00:29:19 +13:00
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp[i + 1] == 'X') {
|
|
|
|
glyph = ctoi(temp[i]) + 17;
|
|
|
|
count += glyph;
|
|
|
|
} else {
|
|
|
|
glyph = (10 * ctoi(temp[i])) + ctoi(temp[i + 1]);
|
|
|
|
glyph += 27;
|
|
|
|
count += glyph;
|
|
|
|
}
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable[glyph]);
|
2016-02-21 00:29:19 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
check_digit = 127 - (count % 127);
|
|
|
|
if (check_digit == 127) {
|
|
|
|
check_digit = 0;
|
|
|
|
}
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable[check_digit]);
|
2016-02-21 00:29:19 +13:00
|
|
|
|
2021-07-27 02:29:05 +12:00
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
|
|
|
|
|
2016-02-21 00:29:19 +13:00
|
|
|
/* Stop character */
|
2016-03-03 10:12:38 +13:00
|
|
|
strcat(dest, TeleTable['z']);
|
2016-02-21 00:29:19 +13:00
|
|
|
|
|
|
|
expand(symbol, dest);
|
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) {
|
|
|
|
(void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */
|
|
|
|
} else {
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/);
|
|
|
|
}
|
2021-06-20 00:11:23 +12:00
|
|
|
|
2016-02-21 00:29:19 +13:00
|
|
|
ustrcpy(symbol->text, temp);
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
}
|