EANX/UPCA/UPCE_CHK handling + various raster/vector fixes; ISBNX add-ons

This commit is contained in:
gitlost 2019-11-11 21:38:21 +00:00
parent 42587c2d21
commit 793a990c01
8 changed files with 530 additions and 128 deletions

View file

@ -220,13 +220,13 @@ int is_stackable(const int symbology) {
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
int is_extendable(const int symbology) {
if (symbology == BARCODE_EANX) {
if (symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK) {
return 1;
}
if (symbology == BARCODE_UPCA) {
if (symbology == BARCODE_UPCA || symbology == BARCODE_UPCA_CHK) {
return 1;
}
if (symbology == BARCODE_UPCE) {
if (symbology == BARCODE_UPCE || symbology == BARCODE_UPCE_CHK) {
return 1;
}
if (symbology == BARCODE_ISBNX) {

View file

@ -29,6 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include <stdio.h>
#ifdef _MSC_VER
@ -680,29 +681,20 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
to_latin1(symbol->text, local_text);
} else {
/* No text needed */
switch (symbol->symbology) {
case BARCODE_EANX:
case BARCODE_EANX_CC:
case BARCODE_ISBNX:
case BARCODE_UPCA:
case BARCODE_UPCE:
case BARCODE_UPCA_CC:
case BARCODE_UPCE_CC:
/* For these symbols use dummy text to ensure formatting is done
* properly even if no text is required */
for (i = 0; i < ustrlen(symbol->text); i++) {
if (symbol->text[i] == '+') {
local_text[i] = '+';
} else {
local_text[i] = ' ';
}
local_text[ustrlen(symbol->text)] = '\0';
if (is_extendable(symbol->symbology)) {
/* For these symbols use dummy text to ensure formatting is done
* properly even if no text is required */
for (i = 0; i < ustrlen(symbol->text); i++) {
if (symbol->text[i] == '+') {
local_text[i] = '+';
} else {
local_text[i] = ' ';
}
break;
default:
/* For everything else, just remove the text */
local_text[0] = '\0';
break;
local_text[ustrlen(symbol->text)] = '\0';
}
} else {
/* For everything else, just remove the text */
local_text[0] = '\0';
}
}
@ -738,13 +730,15 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
large_bar_height = (symbol->height - preset_height) / large_bar_count;
}
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
comp_offset++;
if (is_composite(symbol->symbology)) {
while (!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
comp_offset++;
}
}
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
|| (symbol->symbology == BARCODE_ISBNX)) {
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
switch (ustrlen(local_text)) {
case 13: /* EAN 13 */
case 16:
@ -757,20 +751,18 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
default:
main_width = 68 + comp_offset;
}
}
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|| (symbol->symbology == BARCODE_UPCA_CC)) {
if (symbol->whitespace_width == 0) {
symbol->whitespace_width = 10;
main_width = 96 + comp_offset;
}
}
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
main_width = 96 + comp_offset;
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|| (symbol->symbology == BARCODE_UPCE_CC)) {
if (symbol->whitespace_width == 0) {
symbol->whitespace_width = 10;
main_width = 51 + comp_offset;
}
main_width = 51 + comp_offset;
}
latch = 0;
@ -867,7 +859,8 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
xoffset += comp_offset;
if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) {
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
/* guard bar extensions and text formatting for EAN8 and EAN13 */
switch (ustrlen(local_text)) {
case 8: /* EAN-8 */
@ -945,9 +938,9 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
break;
}
}
if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|| (symbol->symbology == BARCODE_UPCA_CC)) {
/* guard bar extensions and text formatting for UPCA */
latch = 1;
@ -1018,9 +1011,8 @@ int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int data_t
break;
}
}
if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|| (symbol->symbology == BARCODE_UPCE_CC)) {
/* guard bar extensions and text formatting for UPCE */
draw_bar(pixelbuf, (0 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);
draw_bar(pixelbuf, (2 + xoffset) * 2, 1 * 2, (4 + (int) yoffset) * 2, 5 * 2, image_width, image_height);

View file

@ -56,5 +56,7 @@ zint_add_test(mailmark, test_mailmark)
zint_add_test(maxicode, test_maxicode)
zint_add_test(postal, test_postal)
zint_add_test(qr, test_qr)
zint_add_test(raster, test_raster)
zint_add_test(rss, test_rss)
zint_add_test(upcean, test_upcean)
zint_add_test(vector, test_vector)

102
backend/tests/test_raster.c Normal file
View file

@ -0,0 +1,102 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
static void test_chk_extendable(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
int ret;
int expected_height;
int expected_rows;
int expected_width;
int expected_bitmap_width;
int expected_bitmap_height;
int expected_addon_text_row;
int expected_addon_text_col;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_EANX_CHK, "1234567890128+12", 0, 50, 1, 124, 288, 118, 5, 224 },
/* 1*/ { BARCODE_UPCA_CHK, "12345678905+12345", 0, 50, 1, 151, 342, 118, 5, 258 },
/* 2*/ { BARCODE_UPCE_CHK, "12345670+12", 0, 50, 1, 80, 200, 118, 5, 147 },
};
int data_size = sizeof(data) / sizeof(struct item);
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
int length = strlen(data[i].data);
ret = ZBarcode_Encode_and_Buffer(symbol, data[i].data, length, 0);
assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
assert_nonnull(symbol->bitmap, "i:%d (%d) symbol->bitmap NULL\n", i, data[i].symbology);
assert_equal(symbol->height, data[i].expected_height, "i:%d (%d) symbol->height %d != %d\n", i, data[i].symbology, symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%d) symbol->rows %d != %d\n", i, data[i].symbology, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d (%d) symbol->width %d != %d\n", i, data[i].symbology, symbol->width, data[i].expected_width);
assert_equal(symbol->bitmap_width, data[i].expected_bitmap_width, "i:%d (%d) symbol->bitmap_width %d != %d\n", i, data[i].symbology, symbol->bitmap_width, data[i].expected_bitmap_width);
assert_equal(symbol->bitmap_height, data[i].expected_bitmap_height, "i:%d (%d) symbol->bitmap_height %d != %d\n", i, data[i].symbology, symbol->bitmap_height, data[i].expected_bitmap_height);
int addon_text_bits_set = 0;
int row = data[i].expected_addon_text_row;
for (int column = data[i].expected_addon_text_col; column < data[i].expected_addon_text_col + 48; column++) {
int j = (row * symbol->bitmap_width + column) * 3;
if (symbol->bitmap[j] == 0 && symbol->bitmap[j + 1] == 0 && symbol->bitmap[j + 2] == 0) { // Black
addon_text_bits_set = 1;
break;
}
}
assert_nonzero(addon_text_bits_set, "i:%d (%d) addon_text_bits_set zero\n", i, data[i].symbology);
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_chk_extendable();
testReport();
return 0;
}

View file

@ -27,6 +27,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
@ -40,7 +41,7 @@ static void test_upce_length(void)
unsigned char* data;
int ret;
};
// Vi} :s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_UPCE, "12345", 0 },
/* 1*/ { BARCODE_UPCE_CHK, "12345", ZINT_ERROR_INVALID_CHECK },
@ -85,35 +86,50 @@ static void test_isbn(void)
struct item {
unsigned char* data;
int ret_encode;
float w;
float h;
int ret_vector;
};
// Vi} :s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "0", 0, 100, 30, 0 }, // Left zero-padded if < 10 chars
/* 1*/ { "12345678", ZINT_ERROR_INVALID_CHECK, 100, 30, -1 },
/* 2*/ { "12345679", 0, 100, 30, 0 }, // 9 is correct check digit
/* 3*/ { "123456789", 0, 100, 30, 0 },
/* 4*/ { "0123456789", 0, 100, 30, 0 },
/* 5*/ { "1234567890", ZINT_ERROR_INVALID_CHECK, 100, 30, -1 },
/* 6*/ { "123456789X", 0, 100, 30, 0 }, // X is correct check digit
/* 7*/ { "8175257660", 0, 100, 30, 0 }, // 0 is correct check digit
/* 8*/ { "0590764845", 0, 100, 30, 0 }, // 5 is correct check digit
/* 9*/ { "0906495741", 0, 100, 30, 0 }, // 1 is correct check digit
/*10*/ { "0140430016", 0, 100, 30, 0 }, // 6 is correct check digit
/*11*/ { "0571086187", 0, 100, 30, 0 }, // 7 is correct check digit
/*12*/ { "0486600882", 0, 100, 30, 0 }, // 2 is correct check digit
/*13*/ { "12345678901", ZINT_ERROR_TOO_LONG, 100, 30, -1 },
/*14*/ { "123456789012", ZINT_ERROR_TOO_LONG, 100, 30, -1 },
/*15*/ { "1234567890123", ZINT_ERROR_INVALID_DATA, 100, 30, -1 },
/*16*/ { "9784567890120", 0, 100, 30, 0 }, // 0 is correct check digit
/*17*/ { "9783161484100", 0, 100, 30, 0 }, // 0 is correct check digit
/*18*/ { "9781846688225", 0, 100, 30, 0 }, // 5 is correct check digit
/*19*/ { "9781847657954", 0, 100, 30, 0 }, // 4 is correct check digit
/*20*/ { "9781846688188", 0, 100, 30, 0 }, // 8 is correct check digit
/*21*/ { "9781847659293", 0, 100, 30, 0 }, // 3 is correct check digit
/*22*/ { "97845678901201", ZINT_ERROR_TOO_LONG, 100, 30, -1 },
/* 0*/ { "0", 0, 0 }, // Left zero-padded if < 10 chars
/* 1*/ { "12345678", ZINT_ERROR_INVALID_CHECK, -1 },
/* 2*/ { "12345679", 0, 0 }, // 9 is correct check digit
/* 3*/ { "123456789", 0, 0 },
/* 4*/ { "0123456789", 0, 0 },
/* 5*/ { "1234567890", ZINT_ERROR_INVALID_CHECK, -1 },
/* 6*/ { "123456789X", 0, 0 }, // X is correct check digit
/* 7*/ { "8175257660", 0, 0 }, // 0 is correct check digit
/* 8*/ { "0590764845", 0, 0 }, // 5 is correct check digit
/* 9*/ { "0906495741", 0, 0 }, // 1 is correct check digit
/*10*/ { "0140430016", 0, 0 }, // 6 is correct check digit
/*11*/ { "0571086187", 0, 0 }, // 7 is correct check digit
/*12*/ { "0486600882", 0, 0 }, // 2 is correct check digit
/*13*/ { "12345678901", ZINT_ERROR_TOO_LONG, -1 },
/*14*/ { "123456789012", ZINT_ERROR_TOO_LONG, -1 },
/*15*/ { "1234567890123", ZINT_ERROR_INVALID_DATA, -1 },
/*16*/ { "9784567890120", 0, 0 }, // 0 is correct check digit
/*17*/ { "9783161484100", 0, 0 }, // 0 is correct check digit
/*18*/ { "9781846688225", 0, 0 }, // 5 is correct check digit
/*19*/ { "9781847657954", 0, 0 }, // 4 is correct check digit
/*20*/ { "9781846688188", 0, 0 }, // 8 is correct check digit
/*21*/ { "9781847659293", 0, 0 }, // 3 is correct check digit
/*22*/ { "97845678901201", ZINT_ERROR_TOO_LONG, -1 },
/*23*/ { "3954994+12", 0, 0 },
/*24*/ { "3954994+12345", 0, 0 },
/*25*/ { "3954994+123456", ZINT_ERROR_TOO_LONG, -1 },
/*26*/ { "3954994+", 0, 0 },
/*27*/ { "61954993+1", 0, 0 },
/*28*/ { "61954993+123", 0, 0 },
/*29*/ { "361954999+12", 0, 0 },
/*30*/ { "361954999+1234", 0, 0 },
/*31*/ { "361954999+12", 0, 0 },
/*32*/ { "199900003X+12", 0, 0 },
/*33*/ { "199900003X+12345", 0, 0 },
/*34*/ { "9791234567896+12", 0, 0 },
/*35*/ { "9791234567896+12345", 0, 0 },
/*36*/ { "9791234567896+", 0, 0 },
/*37*/ { "97912345678961+", ZINT_ERROR_TOO_LONG, -1 },
/*38*/ { "97912345678961+12345", ZINT_ERROR_TOO_LONG, -1 },
/*39*/ { "9791234567896+123456", ZINT_ERROR_TOO_LONG, -1 },
};
int data_size = sizeof(data) / sizeof(struct item);
@ -148,14 +164,12 @@ static void test_vector_same(void)
int symbology;
unsigned char* data;
int ret_encode;
float w;
float h;
int ret_vector;
};
struct item data[] = {
/* 0*/ { BARCODE_UPCE, "123456", 0, 100, 30, 0 },
/* 1*/ { BARCODE_UPCE_CHK, "1234565", 0, 100, 30, 0 }, // 5 is correct check digit
/* 2*/ { BARCODE_ISBNX, "0195049969", 0, 100, 30, 0 }, // 9 is correct check digit
/* 0*/ { BARCODE_UPCE, "123456", 0, 0 },
/* 1*/ { BARCODE_UPCE_CHK, "1234565", 0, 0 }, // 5 is correct check digit
/* 2*/ { BARCODE_ISBNX, "0195049969", 0, 0 }, // 9 is correct check digit
};
int data_size = sizeof(data) / sizeof(struct item);

318
backend/tests/test_vector.c Normal file
View file

@ -0,0 +1,318 @@
/*
libzint - the open source barcode library
Copyright (C) 2008-2019 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/* vim: set ts=4 sw=4 et : */
#include "testcommon.h"
//#define TEST_BUFFER_VECTOR_GENERATE_EXPECTED 1
static void test_buffer_vector(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
char* composite;
int expected_height;
int expected_rows;
int expected_width;
float expected_vector_width;
float expected_vector_height;
};
struct item data[] = {
/* 0*/ { BARCODE_CODE11, "0000000000", "", 50, 1, 99, 198.0, 118.0 },
/* 1*/ { BARCODE_C25MATRIX, "0000000000", "", 50, 1, 117, 234.0, 118.0 },
/* 2*/ { BARCODE_C25INTER, "0000000000", "", 50, 1, 99, 198.0, 118.0 },
/* 3*/ { BARCODE_C25IATA, "0000000000", "", 50, 1, 149, 298.0, 118.0 },
/* 4*/ { BARCODE_C25LOGIC, "0000000000", "", 50, 1, 109, 218.0, 118.0 },
/* 5*/ { BARCODE_C25IND, "0000000000", "", 50, 1, 159, 318.0, 118.0 },
/* 6*/ { BARCODE_CODE39, "0000000000", "", 50, 1, 155, 310.0, 118.0 },
/* 7*/ { BARCODE_EXCODE39, "0000000000", "", 50, 1, 155, 310.0, 118.0 },
/* 8*/ { BARCODE_EANX, "123456789012", "", 50, 1, 95, 230.0, 118.0 },
/* 9*/ { BARCODE_EANX_CHK, "1234567890128", "", 50, 1, 95, 230.0, 118.0 },
/* 10*/ { BARCODE_EAN128, "[01]12345678901234", "", 50, 1, 134, 268.0, 118.0 },
/* 11*/ { BARCODE_CODABAR, "A00000000B", "", 50, 1, 102, 204.0, 118.0 },
/* 12*/ { BARCODE_CODE128, "0000000000", "", 50, 1, 90, 180.0, 118.0 },
/* 13*/ { BARCODE_DPLEIT, "1234567890123", "", 50, 1, 135, 270.0, 118.0 },
/* 14*/ { BARCODE_DPIDENT, "12345678901", "", 50, 1, 117, 234.0, 118.0 },
/* 15*/ { BARCODE_CODE16K, "0000000000", "", 20, 2, 70, 212.0, 48.0 },
/* 16*/ { BARCODE_CODE49, "0000000000", "", 20, 2, 70, 188.0, 48.0 },
/* 17*/ { BARCODE_CODE93, "0000000000", "", 50, 1, 127, 254.0, 118.0 },
/* 18*/ { BARCODE_FLAT, "1234567890", "", 50, 1, 90, 180.0, 100.0 },
/* 19*/ { BARCODE_RSS14, "1234567890123", "", 50, 1, 96, 192.0, 118.0 },
/* 20*/ { BARCODE_RSS_LTD, "1234567890123", "", 50, 1, 74, 148.0, 118.0 },
/* 21*/ { BARCODE_RSS_EXP, "[01]12345678901234", "", 34, 1, 134, 268.0, 86.0 },
/* 22*/ { BARCODE_TELEPEN, "0000000000", "", 50, 1, 208, 416.0, 118.0 },
/* 23*/ { BARCODE_UPCA, "12345678904", "", 50, 1, 95, 230.0, 118.0 },
/* 24*/ { BARCODE_UPCA_CHK, "12345678905", "", 50, 1, 95, 230.0, 118.0 },
/* 25*/ { BARCODE_UPCE, "1234567", "", 50, 1, 51, 142.0, 118.0 },
/* 26*/ { BARCODE_UPCE_CHK, "12345670", "", 50, 1, 51, 142.0, 118.0 },
/* 27*/ { BARCODE_POSTNET, "00000000000", "", 12, 2, 185, 370.0, 24.0 },
/* 28*/ { BARCODE_MSI_PLESSEY, "0000000000", "", 50, 1, 127, 254.0, 118.0 },
/* 29*/ { BARCODE_FIM, "A", "", 50, 1, 17, 34.0, 100.0 },
/* 30*/ { BARCODE_LOGMARS, "0000000000", "", 50, 1, 207, 414.0, 118.0 },
/* 31*/ { BARCODE_PHARMA, "123456", "", 50, 1, 58, 116.0, 100.0 },
/* 32*/ { BARCODE_PZN, "123456", "", 50, 1, 142, 284.0, 118.0 },
/* 33*/ { BARCODE_PHARMA_TWO, "12345678", "", 10, 2, 29, 58.0, 20.0 },
/* 34*/ { BARCODE_PDF417, "0000000000", "", 21, 7, 103, 206.0, 42.0 },
/* 35*/ { BARCODE_PDF417TRUNC, "0000000000", "", 21, 7, 68, 136.0, 42.0 },
/* 36*/ { BARCODE_MAXICODE, "0000000000", "", 165, 33, 30, 74.0, 72.0 },
/* 37*/ { BARCODE_QRCODE, "1234567890AB", "", 21, 21, 21, 42.0, 42.0 },
/* 38*/ { BARCODE_CODE128B, "0000000000", "", 50, 1, 145, 290.0, 118.0 },
/* 39*/ { BARCODE_AUSPOST, "12345678901234567890123", "", 8, 3, 133, 266.0, 16.0 },
/* 40*/ { BARCODE_AUSREPLY, "12345678", "", 8, 3, 73, 146.0, 16.0 },
/* 41*/ { BARCODE_AUSROUTE, "12345678", "", 8, 3, 73, 146.0, 16.0 },
/* 42*/ { BARCODE_AUSREDIRECT, "12345678", "", 8, 3, 73, 146.0, 16.0 },
/* 43*/ { BARCODE_ISBNX, "123456789", "", 50, 1, 95, 230.0, 118.0 },
/* 44*/ { BARCODE_RM4SCC, "0000000000", "", 8, 3, 91, 182.0, 16.0 },
/* 45*/ { BARCODE_DATAMATRIX, "ABC", "", 10, 10, 10, 20.0, 20.0 },
/* 46*/ { BARCODE_EAN14, "1234567890123", "", 50, 1, 134, 268.0, 118.0 },
/* 47*/ { BARCODE_VIN, "00000000000000000", "", 50, 1, 246, 492.0, 118.0 },
/* 48*/ { BARCODE_CODABLOCKF, "0000000000", "", 10, 1, 90, 188.0, 28.0 },
/* 49*/ { BARCODE_NVE18, "12345678901234567", "", 50, 1, 156, 312.0, 118.0 },
/* 50*/ { BARCODE_JAPANPOST, "0000000000", "", 8, 3, 133, 266.0, 16.0 },
/* 51*/ { BARCODE_KOREAPOST, "123456", "", 50, 1, 167, 334.0, 118.0 },
/* 52*/ { BARCODE_RSS14STACK, "0000000000000", "", 13, 3, 50, 100.0, 26.0 },
/* 53*/ { BARCODE_RSS14STACK_OMNI, "0000000000000", "", 69, 5, 50, 100.0, 138.0 },
/* 54*/ { BARCODE_RSS_EXPSTACK, "[01]12345678901234", "", 71, 5, 102, 204.0, 142.0 },
/* 55*/ { BARCODE_PLANET, "00000000000", "", 12, 2, 185, 370.0, 24.0 },
/* 56*/ { BARCODE_MICROPDF417, "0000000000", "", 12, 6, 82, 164.0, 24.0 },
/* 57*/ { BARCODE_ONECODE, "12345678901234567890", "", 8, 3, 129, 258.0, 16.0 },
/* 58*/ { BARCODE_PLESSEY, "0000000000", "", 50, 1, 227, 454.0, 118.0 },
/* 59*/ { BARCODE_TELEPEN_NUM, "0000000000", "", 50, 1, 128, 256.0, 118.0 },
/* 60*/ { BARCODE_ITF14, "0000000000", "", 50, 1, 135, 382.0, 150.0 },
/* 61*/ { BARCODE_KIX, "123456ABCDE", "", 8, 3, 87, 174.0, 16.0 },
/* 62*/ { BARCODE_AZTEC, "1234567890AB", "", 15, 15, 15, 30.0, 30.0 },
/* 63*/ { BARCODE_DAFT, "DAFTDAFTDAFTDAFT", "", 8, 3, 31, 62.0, 16.0 },
/* 64*/ { BARCODE_MICROQR, "12345", "", 11, 11, 11, 22.0, 22.0 },
/* 65*/ { BARCODE_HIBC_128, "0000000000", "", 50, 1, 134, 268.0, 118.0 },
/* 66*/ { BARCODE_HIBC_39, "0000000000", "", 50, 1, 223, 446.0, 118.0 },
/* 67*/ { BARCODE_HIBC_DM, "ABC", "", 12, 12, 12, 24.0, 24.0 },
/* 68*/ { BARCODE_HIBC_QR, "1234567890AB", "", 21, 21, 21, 42.0, 42.0 },
/* 69*/ { BARCODE_HIBC_PDF, "0000000000", "", 27, 9, 103, 206.0, 54.0 },
/* 70*/ { BARCODE_HIBC_MICPDF, "0000000000", "", 34, 17, 38, 76.0, 68.0 },
/* 71*/ { BARCODE_HIBC_BLOCKF, "0000000000", "", 40, 4, 90, 188.0, 88.0 },
/* 72*/ { BARCODE_HIBC_AZTEC, "1234567890AB", "", 19, 19, 19, 38.0, 38.0 },
/* 73*/ { BARCODE_DOTCODE, "ABC", "", 11, 11, 16, 32.0, 22.0 },
/* 74*/ { BARCODE_HANXIN, "1234567890AB", "", 23, 23, 23, 46.0, 46.0 },
/* 75*/ { BARCODE_MAILMARK, "01000000000000000AA00AA0A", "", 10, 3, 155, 310.0, 20.0 },
/* 76*/ { BARCODE_AZRUNE, "255", "", 11, 11, 11, 22.0, 22.0 },
/* 77*/ { BARCODE_CODE32, "12345678", "", 50, 1, 103, 206.0, 118.0 },
/* 78*/ { BARCODE_EANX_CC, "123456789012", "[20]01", 50, 7, 99, 238.0, 118.0 },
/* 79*/ { BARCODE_EAN128_CC, "[01]12345678901234", "[20]01", 50, 5, 145, 290.0, 118.0 },
/* 80*/ { BARCODE_RSS14_CC, "1234567890123", "[20]01", 21, 5, 100, 200.0, 60.0 },
/* 81*/ { BARCODE_RSS_LTD_CC, "1234567890123", "[20]01", 19, 6, 74, 148.0, 56.0 },
/* 82*/ { BARCODE_RSS_EXP_CC, "[01]12345678901234", "[20]01", 41, 5, 134, 268.0, 100.0 },
/* 83*/ { BARCODE_UPCA_CC, "12345678901", "[20]01", 50, 7, 99, 238.0, 118.0 },
/* 84*/ { BARCODE_UPCE_CC, "1234567", "[20]01", 50, 9, 55, 150.0, 118.0 },
/* 85*/ { BARCODE_RSS14STACK_CC, "0000000000000", "[20]01", 24, 9, 56, 112.0, 48.0 },
/* 86*/ { BARCODE_RSS14_OMNI_CC, "0000000000000", "[20]01", 80, 11, 56, 112.0, 160.0 },
/* 87*/ { BARCODE_RSS_EXPSTACK_CC, "[01]12345678901234", "[20]01", 78, 9, 102, 204.0, 156.0 },
/* 88*/ { BARCODE_CHANNEL, "00", "", 50, 1, 19, 38.0, 118.0 },
/* 89*/ { BARCODE_CODEONE, "12345678901234567890", "", 22, 22, 22, 44.0, 44.0 },
/* 90*/ { BARCODE_GRIDMATRIX, "ABC", "", 18, 18, 18, 36.0, 36.0 },
/* 91*/ { BARCODE_UPNQR, "1234567890AB", "", 77, 77, 77, 154.0, 154.0 },
};
int data_size = sizeof(data) / sizeof(struct item);
char* text;
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
if (strlen(data[i].composite)) {
text = data[i].composite;
strcpy(symbol->primary, data[i].data);
} else {
text = data[i].data;
}
int length = strlen(text);
ret = ZBarcode_Encode(symbol, text, length);
assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt);
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
#ifdef TEST_BUFFER_VECTOR_GENERATE_EXPECTED
printf(" /*%3d*/ { %s, \"%s\", \"%s\", %d, %d, %d, %.1f, %.1f },\n",
i, testUtilBarcodeName(data[i].symbology), data[i].data, data[i].composite,
symbol->height, symbol->rows, symbol->width, symbol->vector->width, symbol->vector->height);
#else
assert_equal(symbol->height, data[i].expected_height, "i:%d (%s) symbol->height %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->height, data[i].expected_height);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d (%s) symbol->rows %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d (%s) symbol->width %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width);
assert_equal(symbol->vector->width, data[i].expected_vector_width, "i:%d (%s) symbol->vector->width %f != %f\n",
i, testUtilBarcodeName(data[i].symbology), symbol->vector->width, data[i].expected_vector_width);
assert_equal(symbol->vector->height, data[i].expected_vector_height, "i:%d (%s) symbol->vector->height %f != %f\n",
i, testUtilBarcodeName(data[i].symbology), symbol->vector->height, data[i].expected_vector_height);
#endif
ZBarcode_Delete(symbol);
}
testFinish();
}
// Checks that symbol lead-in (composite offset) isn't used to calc string position for non-composite barcodes
static void test_noncomposite_string_x(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
int expected_width;
float expected_string_x;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_RSS14, "1234567890123", 96, 96 },
/* 1*/ { BARCODE_RSS_LTD, "1234567890123", 74, 74 },
/* 2*/ { BARCODE_RSS_EXP, "[01]12345678901234", 134, 134 },
};
int data_size = sizeof(data) / sizeof(struct item);
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt);
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
assert_equal(symbol->width, data[i].expected_width, "i:%d (%s) symbol->width %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width);
assert_nonnull(symbol->vector->strings, "i:%d ZBarcode_Buffer_Vector(%d) vector->strings NULL\n", i, data[i].symbology);
assert_equal(symbol->vector->strings->x, data[i].expected_string_x,
"i:%d (%s) symbol->vector->strings->x %f != %f\n", i, testUtilBarcodeName(data[i].symbology), symbol->vector->strings->x, data[i].expected_string_x);
ZBarcode_Delete(symbol);
}
testFinish();
}
// Checks UPCA/UPCE main_symbol_width_x (used for addon formatting) set whether whitespace width set or not
static void test_upcean_whitespace_width(void)
{
testStart("");
int ret;
struct item {
int symbology;
unsigned char* data;
int whitespace_width;
int expected_width;
float expected_vector_width;
int expected_string_cnt;
float expected_string_y;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%2d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_UPCA, "12345678904+12345", 0, 151, 342.0, 5, 16.0 },
/* 1*/ { BARCODE_UPCA, "12345678904+12345", 11, 151, 342.0 + 4 * (11 - 10), 5, 16.0 },
/* 2*/ { BARCODE_UPCE, "1234567+12", 0, 80, 200.0, 4, 16.0 },
/* 3*/ { BARCODE_UPCE, "1234567+12", 8, 80, 200.0 + 4 * (8 - 10), 4, 16.0 }, // Note: change from previous behaviour where if whitespace < 10 then set to 10
};
int data_size = sizeof(data) / sizeof(struct item);
struct zint_vector_string* string;
int string_cnt;
for (int i = 0; i < data_size; i++) {
struct zint_symbol* symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
symbol->symbology = data[i].symbology;
symbol->input_mode = UNICODE_MODE;
symbol->whitespace_width = data[i].whitespace_width;
int length = strlen(data[i].data);
ret = ZBarcode_Encode(symbol, data[i].data, length);
assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt);
ret = ZBarcode_Buffer_Vector(symbol, 0);
assert_zero(ret, "i:%d ZBarcode_Buffer_Vector(%d) ret %d != 0\n", i, data[i].symbology, ret);
assert_nonnull(symbol->vector, "i:%d ZBarcode_Buffer_Vector(%d) vector NULL\n", i, data[i].symbology);
assert_equal(symbol->width, data[i].expected_width, "i:%d (%s) symbol->width %d != %d\n", i, testUtilBarcodeName(data[i].symbology), symbol->width, data[i].expected_width);
assert_equal(symbol->vector->width, data[i].expected_vector_width, "i:%d (%s) symbol->vector->width %f != %f\n",
i, testUtilBarcodeName(data[i].symbology), symbol->vector->width, data[i].expected_vector_width);
assert_nonnull(symbol->vector->strings, "i:%d ZBarcode_Buffer_Vector(%d) vector->strings NULL\n", i, data[i].symbology);
// Get add-on string (last)
for (string = symbol->vector->strings, string_cnt = 1; string->next; string_cnt++) {
string = string->next;
}
assert_equal(string_cnt, data[i].expected_string_cnt, "i:%d (%s) string_cnt %d != %d\n", i, testUtilBarcodeName(data[i].symbology), string_cnt, data[i].expected_string_cnt);
assert_equal(string->y, data[i].expected_string_y, "i:%d (%s) string->y %f != %f\n", i, testUtilBarcodeName(data[i].symbology), string->y, data[i].expected_string_y);
ZBarcode_Delete(symbol);
}
testFinish();
}
int main()
{
test_buffer_vector();
test_noncomposite_string_x();
test_upcean_whitespace_width();
testReport();
return 0;
}

View file

@ -716,7 +716,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return error_number;
}
} else {
error_number = is_sane("0123456789Xx", source, src_len);
error_number = is_sane("0123456789Xx+", source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "285: Invalid characters in input");
return error_number;

View file

@ -239,56 +239,25 @@ void vector_scale(struct zint_symbol *symbol) {
return;
}
void delete_last_rect(struct zint_vector_rect *rect) {
struct zint_vector_rect *local;
local = rect;
if (local->next == NULL) {
free(local);
return;
}
while (local->next->next != NULL) {
local = local->next;
}
free(local->next);
local->next = NULL;
}
void bump_up_rect(struct zint_vector_rect *rect) {
struct zint_vector_rect *local;
local = rect;
while (local->next) {
local->x = local->next->x;
local->y = local->next->y;
local->height = local->next->height;
local->width = local->next->width;
local = local->next;
}
}
void vector_reduce_rectangles(struct zint_symbol *symbol) {
// Looks for vertically aligned rectangles and merges them together
struct zint_vector_rect *rect, *target = NULL;
struct zint_vector_rect *rect, *target, *prev;
rect = symbol->vector->rectangles;
while (rect) {
target = rect->next;
prev = rect;
target = prev->next;
while (target) {
if ((rect->x == target->x) && (rect->width == target->width) && ((rect->y + rect->height) == target->y)) {
rect->height += target->height;
bump_up_rect(target);
delete_last_rect(symbol->vector->rectangles);
prev->next = target->next;
free(target);
} else {
target = target->next;
prev = target;
}
target = prev->next;
}
rect = rect->next;
@ -388,13 +357,15 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
* borders or white space to add.
*/
while (!(module_is_set(symbol, symbol->rows - 1, symbol_lead_in))) {
symbol_lead_in++;
if (is_composite(symbol->symbology)) {
while (!(module_is_set(symbol, symbol->rows - 1, symbol_lead_in))) {
symbol_lead_in++;
}
}
/* Certain symbols need whitespace otherwise characters get chopped off the sides */
if ((((symbol->symbology == BARCODE_EANX || symbol->symbology == BARCODE_EANX_CHK) && (symbol->rows == 1)) ||
(symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) {
if ((symbol->symbology == BARCODE_EANX) || (symbol->symbology == BARCODE_EANX_CHK)
|| (symbol->symbology == BARCODE_EANX_CC) || (symbol->symbology == BARCODE_ISBNX)) {
switch (ustrlen(symbol->text)) {
case 13: /* EAN 13 */
case 16:
@ -417,20 +388,20 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
main_symbol_width_x = 68 + symbol_lead_in;
upceanflag = 8;
}
} else if (((symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK) && (symbol->rows == 1))
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
|| (symbol->symbology == BARCODE_UPCA_CC)) {
upceanflag = 12;
if (symbol->whitespace_width < 10) {
if (symbol->whitespace_width == 0) {
symbol->whitespace_width = 10;
main_symbol_width_x = 96 + symbol_lead_in;
}
} else if (((symbol->symbology == BARCODE_UPCE || symbol->symbology == BARCODE_UPCE_CHK) && (symbol->rows == 1))
main_symbol_width_x = 96 + symbol_lead_in;
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
|| (symbol->symbology == BARCODE_UPCE_CC)) {
upceanflag = 6;
if (symbol->whitespace_width == 0) {
symbol->whitespace_width = 10;
main_symbol_width_x = 51 + symbol_lead_in;
}
main_symbol_width_x = 51 + symbol_lead_in;
}
if ((!symbol->show_hrt) || (ustrlen(symbol->text) == 0)) {
@ -461,7 +432,7 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
vector->width = (float)ceil(symbol->width + (2.0f * xoffset));
vector->height = (float)ceil(symbol->height + text_offset + (2.0f * yoffset));
large_bar_height = (symbol->height - preset_height) / large_bar_count;
large_bar_height = large_bar_count ? (symbol->height - preset_height) / large_bar_count : 0 /*Not used if large_bar_count zero*/;
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
default_text_posn = symbol->height + text_offset + symbol->border_width + symbol->border_width;
@ -500,7 +471,7 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
int block_width = 0;
do {
block_width++;
} while (i + block_width < symbol->width && module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
} while (i + block_width < symbol->width && module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
if ((addon_latch == 0) && (r == (symbol->rows - 1)) && (i > main_symbol_width_x)) {
addon_text_posn = row_posn + 8.0f;
addon_latch = 1;
@ -644,12 +615,13 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
}
/* Add the text */
xoffset += symbol_lead_in;
row_posn = row_posn + large_bar_height;
if (!hide_text) {
char textpart[10];
float textwidth;
xoffset += symbol_lead_in;
if (upceanflag == 8) {
for (i = 0; i < 4; i++) {
textpart[i] = symbol->text[i];
@ -791,6 +763,8 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
// caculate start xoffset to center text
vector_plot_add_string(symbol, symbol->text, (symbol->width / 2.0f) + xoffset, default_text_posn, text_height, (float)symbol->width, &last_string);
}
xoffset -= symbol_lead_in; // Restore xoffset
}
//Remove control characters from readable text