mirror of
https://git.code.sf.net/p/zint/code
synced 2025-12-28 07:17:08 +00:00
Add multiple segments support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, HANXIN, MAXICODE, MICROPDF417, PDF417, QRCODE, RMQR, ULTRA RMQR: fix ECI encoding (wrong bit length for indicator) MICROQR: check versions M1 and M2 for allowed characters so as to give better error messages DOTCODE: some small optimizations common.c: add is_chr(), segs_length(), segs_cpy() CODEONE/CODE128/DOTCODE/GRIDMATRIX/HANXIN/MAXICODE/QRCODE/ULTRA: add namespace prefixes to static funcs/data includes: use Z_ prefix, unuse double underscore prefixes (guard defines) manual.txt: compress some tables using double/treble column sets
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2019-2021 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2019-2022 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -27,7 +27,6 @@
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
/*
|
||||
* Adapted from GNU LIBICONV library and patched to add 2 duplicate mappings
|
||||
* for compatibility with GB 18030 subset:
|
||||
@@ -1543,7 +1542,7 @@ INTERNAL int gb2312_wctomb_zint(unsigned int *r, const unsigned int wc) {
|
||||
|
||||
/* Convert UTF-8 string to GB 2312 (EUC-CN) and place in array of ints */
|
||||
INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length,
|
||||
unsigned int *gbdata) {
|
||||
unsigned int *ddata) {
|
||||
int error_number;
|
||||
unsigned int i, length;
|
||||
#ifndef _MSC_VER
|
||||
@@ -1559,9 +1558,9 @@ INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[
|
||||
|
||||
for (i = 0, length = *p_length; i < length; i++) {
|
||||
if (utfdata[i] < 0x80) {
|
||||
gbdata[i] = utfdata[i];
|
||||
ddata[i] = utfdata[i];
|
||||
} else {
|
||||
if (!gb2312_wctomb_zint(gbdata + i, utfdata[i])) {
|
||||
if (!gb2312_wctomb_zint(ddata + i, utfdata[i])) {
|
||||
strcpy(symbol->errtxt, "810: Invalid character in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
@@ -1572,7 +1571,7 @@ INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[
|
||||
}
|
||||
|
||||
/* Convert UTF-8 string to ECI and place in array of ints */
|
||||
INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *gbdata,
|
||||
INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata,
|
||||
const int full_multibyte) {
|
||||
|
||||
if (is_eci_convertible(eci)) {
|
||||
@@ -1590,9 +1589,9 @@ INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int
|
||||
return error_number;
|
||||
}
|
||||
|
||||
gb2312_cpy(converted, p_length, gbdata, full_multibyte);
|
||||
gb2312_cpy(converted, p_length, ddata, full_multibyte);
|
||||
} else {
|
||||
gb2312_cpy(source, p_length, gbdata, full_multibyte);
|
||||
gb2312_cpy(source, p_length, ddata, full_multibyte);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1600,7 +1599,7 @@ INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int
|
||||
|
||||
/* If `full_multibyte` set, copy byte input stream to array of ints, putting double-bytes that match GRIDMATRIX
|
||||
* Chinese mode in a single entry. If `full_multibyte` not set, do a straight copy */
|
||||
INTERNAL void gb2312_cpy(const unsigned char source[], int *p_length, unsigned int *gbdata,
|
||||
INTERNAL void gb2312_cpy(const unsigned char source[], int *p_length, unsigned int *ddata,
|
||||
const int full_multibyte) {
|
||||
unsigned int i, j, length;
|
||||
unsigned char c1, c2;
|
||||
@@ -1613,20 +1612,34 @@ INTERNAL void gb2312_cpy(const unsigned char source[], int *p_length, unsigned i
|
||||
if (((c1 >= 0xA1 && c1 <= 0xA9) || (c1 >= 0xB0 && c1 <= 0xF7)) && c2 >= 0xA1 && c2 <= 0xFE) {
|
||||
/* This may or may not be valid GB 2312 (EUC-CN), but don't care as long as it can be encoded in
|
||||
* GRIDMATRIX Chinese mode */
|
||||
gbdata[j] = (c1 << 8) | c2;
|
||||
ddata[j] = (c1 << 8) | c2;
|
||||
i++;
|
||||
} else {
|
||||
gbdata[j] = c1;
|
||||
ddata[j] = c1;
|
||||
}
|
||||
} else {
|
||||
gbdata[j] = source[i];
|
||||
ddata[j] = source[i];
|
||||
}
|
||||
}
|
||||
*p_length = j;
|
||||
} else {
|
||||
/* Straight copy */
|
||||
for (i = 0, length = *p_length; i < length; i++) {
|
||||
gbdata[i] = source[i];
|
||||
ddata[i] = source[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Call `gb2312_cpy()` for each segment */
|
||||
INTERNAL void gb2312_cpy_segs(struct zint_seg segs[], const int seg_count, unsigned int *ddata,
|
||||
const int full_multibyte) {
|
||||
int i;
|
||||
unsigned int *dd = ddata;
|
||||
|
||||
for (i = 0; i < seg_count; i++) {
|
||||
gb2312_cpy(segs[i].source, &segs[i].length, dd, full_multibyte);
|
||||
dd += segs[i].length;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
Reference in New Issue
Block a user