2008-07-14 09:15:55 +12:00
|
|
|
|
/* medical.c - Handles 1 track and 2 track pharmacode and Codabar */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
libzint - the open source barcode library
|
2020-06-05 05:45:25 +12:00
|
|
|
|
Copyright (C) 2008 - 2020 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 23:50:15 +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
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
|
INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length);
|
2019-12-19 13:37:55 +13:00
|
|
|
|
|
2008-07-14 09:15:55 +12:00
|
|
|
|
/* Codabar table checked against EN 798:1995 */
|
|
|
|
|
|
2020-06-05 05:45:25 +12:00
|
|
|
|
#define CALCIUM "0123456789-$:/.+ABCD"
|
|
|
|
|
#define CALCIUM_INNER "0123456789-$:/.+"
|
2008-09-03 07:44:41 +12:00
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
static const char *CodaTable[20] = {
|
|
|
|
|
"11111221", "11112211", "11121121", "22111111", "11211211", "21111211",
|
|
|
|
|
"12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121",
|
|
|
|
|
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
|
INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other
|
|
|
|
|
commonly used one-dimensional barcode schemes, pharmacode does not store the data in a
|
|
|
|
|
form corresponding to the human-readable digits; the number is encoded in binary, rather
|
|
|
|
|
than decimal. Pharmacode is read from right to left: with n as the bar position starting
|
|
|
|
|
at 0 on the right, each narrow bar adds 2n to the value and each wide bar adds 2(2^n).
|
|
|
|
|
The minimum barcode is 2 bars and the maximum 16, so the smallest number that could
|
|
|
|
|
be encoded is 3 (2 narrow bars) and the biggest is 131070 (16 wide bars)."
|
|
|
|
|
- http://en.wikipedia.org/wiki/Pharmacode */
|
|
|
|
|
|
|
|
|
|
/* This code uses the One Track Pharamacode calculating algorithm as recommended by
|
2020-10-01 00:19:12 +13:00
|
|
|
|
the specification at http://www.laetus.com/laetus.php?request=file&id=69
|
|
|
|
|
(http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf) */
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
|
|
unsigned long int tester;
|
|
|
|
|
int counter, error_number, h;
|
|
|
|
|
char inter[18] = {0}; /* 131070 -> 17 bits */
|
|
|
|
|
char dest[64]; /* 17 * 2 + 1 */
|
|
|
|
|
|
|
|
|
|
if (length > 6) {
|
2021-06-13 03:01:16 +12:00
|
|
|
|
strcpy(symbol->errtxt, "350: Input too long (6 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
|
}
|
|
|
|
|
error_number = is_sane(NEON, source, length);
|
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2021-07-07 06:53:31 +12:00
|
|
|
|
strcpy(symbol->errtxt, "351: Invalid character in data (digits only)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tester = atoi((char*) source);
|
|
|
|
|
|
|
|
|
|
if ((tester < 3) || (tester > 131070)) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "352: Data out of range (3 to 131070)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (!(tester & 1)) {
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(inter, "W");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
tester = (tester - 2) / 2;
|
|
|
|
|
} else {
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(inter, "N");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
tester = (tester - 1) / 2;
|
|
|
|
|
}
|
|
|
|
|
} while (tester != 0);
|
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
|
h = (int) strlen(inter) - 1;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
*dest = '\0';
|
|
|
|
|
for (counter = h; counter >= 0; counter--) {
|
|
|
|
|
if (inter[counter] == 'W') {
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(dest, "32");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
} else {
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(dest, "12");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expand(symbol, dest);
|
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
|
#ifdef COMPLIANT_HEIGHTS
|
|
|
|
|
/* Laetus Pharmacode Guide 1.2 Standard one-track height 8mm / 0.5mm (X) */
|
|
|
|
|
error_number = set_height(symbol, 16.0f, 0.0f, 0.0f, 0 /*no_errtxt*/);
|
|
|
|
|
#else
|
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
|
static int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char dest[]) {
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* This code uses the Two Track Pharamacode defined in the document at
|
|
|
|
|
http://www.laetus.com/laetus.php?request=file&id=69 and using a modified
|
|
|
|
|
algorithm from the One Track system. This standard accepts integet values
|
|
|
|
|
from 4 to 64570080. */
|
|
|
|
|
|
|
|
|
|
unsigned long int tester;
|
|
|
|
|
int counter, h;
|
|
|
|
|
char inter[17];
|
|
|
|
|
int error_number;
|
|
|
|
|
|
|
|
|
|
tester = atoi((char*) source);
|
|
|
|
|
|
|
|
|
|
if ((tester < 4) || (tester > 64570080)) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "353: Data out of range (4 to 64570080)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
|
}
|
|
|
|
|
error_number = 0;
|
|
|
|
|
strcpy(inter, "");
|
|
|
|
|
do {
|
|
|
|
|
switch (tester % 3) {
|
|
|
|
|
case 0:
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(inter, "3");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
tester = (tester - 3) / 3;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(inter, "1");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
tester = (tester - 1) / 3;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2016-03-03 10:12:38 +13:00
|
|
|
|
strcat(inter, "2");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
tester = (tester - 2) / 3;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (tester != 0);
|
|
|
|
|
|
2020-12-23 23:57:24 +13:00
|
|
|
|
h = (int) strlen(inter) - 1;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
for (counter = h; counter >= 0; counter--) {
|
|
|
|
|
dest[h - counter] = inter[counter];
|
|
|
|
|
}
|
|
|
|
|
dest[h + 1] = '\0';
|
|
|
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 13:37:55 +13:00
|
|
|
|
INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* Draws the patterns for two track pharmacode */
|
|
|
|
|
char height_pattern[200];
|
|
|
|
|
unsigned int loopey, h;
|
|
|
|
|
int writer;
|
2021-06-20 00:11:23 +12:00
|
|
|
|
int error_number;
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
strcpy(height_pattern, "");
|
|
|
|
|
|
|
|
|
|
if (length > 8) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "354: Input too long (8 character maximum");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
|
}
|
|
|
|
|
error_number = is_sane(NEON, source, length);
|
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2021-07-07 06:53:31 +12:00
|
|
|
|
strcpy(symbol->errtxt, "355: Invalid character in data (digits only)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
error_number = pharma_two_calc(symbol, source, height_pattern);
|
|
|
|
|
if (error_number != 0) {
|
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writer = 0;
|
2020-12-23 23:57:24 +13:00
|
|
|
|
h = (int) strlen(height_pattern);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
for (loopey = 0; loopey < h; loopey++) {
|
|
|
|
|
if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) {
|
|
|
|
|
set_module(symbol, 0, writer);
|
|
|
|
|
}
|
|
|
|
|
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) {
|
|
|
|
|
set_module(symbol, 1, writer);
|
|
|
|
|
}
|
|
|
|
|
writer += 2;
|
|
|
|
|
}
|
|
|
|
|
symbol->rows = 2;
|
|
|
|
|
symbol->width = writer - 1;
|
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
|
#ifdef COMPLIANT_HEIGHTS
|
|
|
|
|
/* Laetus Pharmacode Guide 1.4
|
|
|
|
|
Two-track height min 8mm / 2mm (X max) = 4, standard 8mm / 1mm = 8, max 12mm / 0.8mm (X min) = 15 */
|
|
|
|
|
error_number = set_height(symbol, 2.0f, 8.0f, 15.0f, 0 /*no_errtxt*/);
|
|
|
|
|
#else
|
|
|
|
|
(void) set_height(symbol, 0.0f, 10.0f, 0.0f, 1 /*no_errtxt*/);
|
|
|
|
|
#endif
|
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
|
|
|
|
/* The Codabar system consisting of simple substitution */
|
2019-12-19 13:37:55 +13:00
|
|
|
|
INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
|
|
int i, error_number;
|
|
|
|
|
char dest[512];
|
2020-12-23 23:57:24 +13:00
|
|
|
|
int add_checksum, count = 0, checksum;
|
2021-06-20 00:11:23 +12:00
|
|
|
|
int d_chars = 0;
|
|
|
|
|
float height;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
|
|
strcpy(dest, "");
|
|
|
|
|
|
|
|
|
|
if (length > 60) { /* No stack smashing please */
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "356: Input too long (60 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
|
}
|
2020-06-05 05:45:25 +12:00
|
|
|
|
/* BS EN 798:1995 4.2 "'Codabar' symbols shall consist of ... b) start character;
|
2021-06-20 00:11:23 +12:00
|
|
|
|
c) one or more symbol characters representing data ... d) stop character ..." */
|
2020-06-05 05:45:25 +12:00
|
|
|
|
if (length < 3) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "362: Input too short (3 character minimum)");
|
2020-06-05 05:45:25 +12:00
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
}
|
2020-06-05 05:45:25 +12:00
|
|
|
|
to_upper(source);
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* Codabar must begin and end with the characters A, B, C or D */
|
2016-03-03 10:12:38 +13:00
|
|
|
|
if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C')
|
2016-02-20 23:50:15 +13:00
|
|
|
|
&& (source[0] != 'D')) {
|
2020-06-05 05:45:25 +12:00
|
|
|
|
strcpy(symbol->errtxt, "358: Does not begin with \"A\", \"B\", \"C\" or \"D\"");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
|
}
|
|
|
|
|
if ((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
|
|
|
|
|
(source[length - 1] != 'C') && (source[length - 1] != 'D')) {
|
2020-06-05 05:45:25 +12:00
|
|
|
|
strcpy(symbol->errtxt, "359: Does not end with \"A\", \"B\", \"C\" or \"D\"");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_INVALID_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 05:45:25 +12:00
|
|
|
|
/* And must not use A, B, C or D otherwise (BS EN 798:1995 4.3.2) */
|
|
|
|
|
error_number = is_sane(CALCIUM_INNER, source + 1, length - 2);
|
|
|
|
|
if (error_number) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
if (is_sane(CALCIUM, source + 1, length - 2) == 0) {
|
|
|
|
|
strcpy(symbol->errtxt, "363: Cannot contain \"A\", \"B\", \"C\" or \"D\"");
|
|
|
|
|
} else {
|
2021-07-07 06:53:31 +12:00
|
|
|
|
sprintf(symbol->errtxt, "357: Invalid character in data (\"%s\" only)", CALCIUM);
|
2021-06-11 05:04:27 +12:00
|
|
|
|
}
|
2020-06-05 05:45:25 +12:00
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_checksum = symbol->option_2 == 1;
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
for (i = 0; i < length; i++) {
|
2021-06-11 03:20:14 +12:00
|
|
|
|
static const char calcium[] = CALCIUM;
|
2020-06-05 05:45:25 +12:00
|
|
|
|
if (add_checksum) {
|
Merge String Constant
The `CALCIUM` "name" is a macro which expands to a string constant.
Referencing the macro twice will cause it to be expanded twice, resulting
in two string instances which have identical content. By default, gcc will
deduplicate these two strings into the same memory region as gcc detects
the duplicated constant, even when optimization turned off (see
-fmerge-constants and -fmerge-all-constants GCC options).
The C Language specification does not require duplicated constants to be
deduplicated, and, in fact, the GCC manual page also explicitly states
this optimization is not performed for all targets.
Visual C++, in debug mode, does not deduplicate constants. This results
in `count += strchr(CALCIUM,x) - CALCIUM` yielding to negative values as
the substracted CALCIUM's expansion resides on a greater memory address
then the memory allocated for the expansion passed to `strchr`. The
value of `count` is used to compute the checksum, which then is not only
faulty, but also used as an array index without previously checking
whether or not the index is within the array bounds (modulo of a negative
integer is negative, which means out of bounds). This will cause very
difficult to predict behavior, in most cases, however, it will cause a
segmentation fault.
Manually allocate a memory range to contain the string, and use
this range instead of expanding the macro multiple times.
2021-06-10 01:37:16 +12:00
|
|
|
|
count += strchr(calcium, source[i]) - calcium;
|
2020-06-05 05:45:25 +12:00
|
|
|
|
if (i + 1 == length) {
|
|
|
|
|
checksum = count % 16;
|
|
|
|
|
if (checksum) {
|
|
|
|
|
checksum = 16 - checksum;
|
|
|
|
|
}
|
|
|
|
|
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
|
|
|
|
printf("Codabar: %s, count %d, checksum %d\n", source, count, checksum);
|
|
|
|
|
}
|
|
|
|
|
strcat(dest, CodaTable[checksum]);
|
|
|
|
|
}
|
|
|
|
|
}
|
Merge String Constant
The `CALCIUM` "name" is a macro which expands to a string constant.
Referencing the macro twice will cause it to be expanded twice, resulting
in two string instances which have identical content. By default, gcc will
deduplicate these two strings into the same memory region as gcc detects
the duplicated constant, even when optimization turned off (see
-fmerge-constants and -fmerge-all-constants GCC options).
The C Language specification does not require duplicated constants to be
deduplicated, and, in fact, the GCC manual page also explicitly states
this optimization is not performed for all targets.
Visual C++, in debug mode, does not deduplicate constants. This results
in `count += strchr(CALCIUM,x) - CALCIUM` yielding to negative values as
the substracted CALCIUM's expansion resides on a greater memory address
then the memory allocated for the expansion passed to `strchr`. The
value of `count` is used to compute the checksum, which then is not only
faulty, but also used as an array index without previously checking
whether or not the index is within the array bounds (modulo of a negative
integer is negative, which means out of bounds). This will cause very
difficult to predict behavior, in most cases, however, it will cause a
segmentation fault.
Manually allocate a memory range to contain the string, and use
this range instead of expanding the macro multiple times.
2021-06-10 01:37:16 +12:00
|
|
|
|
lookup(calcium, CodaTable, source[i], dest);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
if (source[i] == '/' || source[i] == ':' || source[i] == '.' || source[i] == '+') { /* Wide data characters */
|
|
|
|
|
d_chars++;
|
|
|
|
|
}
|
2016-02-20 23:50:15 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expand(symbol, dest);
|
2021-06-20 00:11:23 +12:00
|
|
|
|
|
|
|
|
|
#ifdef COMPLIANT_HEIGHTS
|
|
|
|
|
/* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.191mm (X) ~ 26.178 or 15% of width where (taking N = narrow/wide ratio
|
|
|
|
|
as 2 and I = X) width = ((2 * N + 5) * C + (N – 1) * (D + 2)) * X + I * (C – 1) + 2Q
|
|
|
|
|
= ((4 + 5) * C + (D + 2) + C - 1 + 2 * 10) * X = (10 * C + D + 21) * X
|
|
|
|
|
Length (C) includes start/stop chars */
|
|
|
|
|
height = (float) ((10.0 * ((add_checksum ? length + 1 : length) + 2.0) + d_chars + 21.0) * 0.15);
|
|
|
|
|
if (height < (float) (5.0 / 0.191)) {
|
|
|
|
|
height = (float) (5.0 / 0.191);
|
|
|
|
|
}
|
|
|
|
|
/* Using 50 as default as none recommended */
|
|
|
|
|
error_number = set_height(symbol, height, height > 50.0f ? height : 50.0f, 0.0f, 0 /*no_errtxt*/);
|
|
|
|
|
#else
|
|
|
|
|
height = 50.0f;
|
|
|
|
|
(void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
ustrcpy(symbol->text, source);
|
|
|
|
|
return error_number;
|
2008-09-03 07:44:41 +12:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* Italian Pharmacode */
|
2019-12-19 13:37:55 +13:00
|
|
|
|
INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int length) {
|
2021-06-20 00:11:23 +12:00
|
|
|
|
int i, zeroes, error_number = 0, checksum, checkpart, checkdigit;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
char localstr[10], risultante[7];
|
2017-09-11 03:03:09 +12:00
|
|
|
|
long int pharmacode, devisor;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
int codeword[6];
|
|
|
|
|
char tabella[34];
|
|
|
|
|
|
|
|
|
|
/* Validate the input */
|
|
|
|
|
if (length > 8) {
|
2021-06-11 05:04:27 +12:00
|
|
|
|
strcpy(symbol->errtxt, "360: Input too long (8 character maximum)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return ZINT_ERROR_TOO_LONG;
|
|
|
|
|
}
|
|
|
|
|
error_number = is_sane(NEON, source, length);
|
|
|
|
|
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
2021-07-07 06:53:31 +12:00
|
|
|
|
strcpy(symbol->errtxt, "361: Invalid character in data (digits only)");
|
2016-02-20 23:50:15 +13:00
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add leading zeros as required */
|
|
|
|
|
zeroes = 8 - length;
|
|
|
|
|
memset(localstr, '0', zeroes);
|
2020-06-05 05:45:25 +12:00
|
|
|
|
ustrcpy(localstr + zeroes, source);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
|
|
/* Calculate the check digit */
|
|
|
|
|
checksum = 0;
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
checkpart = ctoi(localstr[i * 2]);
|
|
|
|
|
checksum += checkpart;
|
|
|
|
|
checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
|
|
|
|
|
if (checkpart >= 10) {
|
|
|
|
|
checksum += (checkpart - 10) + 1;
|
|
|
|
|
} else {
|
|
|
|
|
checksum += checkpart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add check digit to data string */
|
|
|
|
|
checkdigit = checksum % 10;
|
|
|
|
|
localstr[8] = itoc(checkdigit);
|
|
|
|
|
localstr[9] = '\0';
|
|
|
|
|
|
|
|
|
|
/* Convert string into an integer value */
|
|
|
|
|
pharmacode = atoi(localstr);
|
|
|
|
|
|
|
|
|
|
/* Convert from decimal to base-32 */
|
|
|
|
|
devisor = 33554432;
|
|
|
|
|
for (i = 5; i >= 0; i--) {
|
2017-10-24 08:34:31 +13:00
|
|
|
|
long int remainder;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
codeword[i] = pharmacode / devisor;
|
2017-10-17 06:26:54 +13:00
|
|
|
|
remainder = pharmacode % devisor;
|
2016-02-20 23:50:15 +13:00
|
|
|
|
pharmacode = remainder;
|
|
|
|
|
devisor /= 32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Look up values in 'Tabella di conversione' */
|
|
|
|
|
strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
|
|
|
|
|
for (i = 5; i >= 0; i--) {
|
|
|
|
|
risultante[5 - i] = tabella[codeword[i]];
|
|
|
|
|
}
|
|
|
|
|
risultante[6] = '\0';
|
|
|
|
|
/* Plot the barcode using Code 39 */
|
2020-12-23 23:57:24 +13:00
|
|
|
|
error_number = c39(symbol, (unsigned char*) risultante, (int) strlen(risultante));
|
2016-02-20 23:50:15 +13:00
|
|
|
|
if (error_number != 0) {
|
|
|
|
|
return error_number;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 00:11:23 +12:00
|
|
|
|
#ifdef COMPLIANT_HEIGHTS
|
|
|
|
|
/* Allegato A Caratteristiche tecniche del bollino farmaceutico
|
|
|
|
|
https://www.gazzettaufficiale.it/do/atto/serie_generale/caricaPdf?cdimg=14A0566800100010110001&dgu=2014-07-18&art.dataPubblicazioneGazzetta=2014-07-18&art.codiceRedazionale=14A05668&art.num=1&art.tiposerie=SG
|
|
|
|
|
X given as 0.250mm; height (and quiet zones) left to ISO/IEC 16388:2007 (Code 39)
|
|
|
|
|
So min height 5mm = 5mm / 0.25mm = 20 > 15% of width, i.e. (10 * 8 + 19) * 0.15 = 14.85 */
|
|
|
|
|
error_number = set_height(symbol, 20.0f, 20.0f, 0.0f, 0 /*no_errtxt*/); /* Use as default also */
|
|
|
|
|
#else
|
|
|
|
|
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-20 23:50:15 +13:00
|
|
|
|
/* Override the normal text output with the Pharmacode number */
|
2020-06-05 05:45:25 +12:00
|
|
|
|
ustrcpy(symbol->text, "A");
|
|
|
|
|
ustrcat(symbol->text, localstr);
|
2016-02-20 23:50:15 +13:00
|
|
|
|
|
|
|
|
|
return error_number;
|
2008-07-14 09:15:55 +12:00
|
|
|
|
}
|