1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-01-07 20:17:06 +00:00

Full multibyte option_3 for QR, HANXIN, GRIDMATRIX

This commit is contained in:
gitlost
2020-04-02 14:41:13 +01:00
parent f02851b3c1
commit 61cd413fe4
18 changed files with 653 additions and 434 deletions

View File

@@ -1570,7 +1570,7 @@ INTERNAL int gb2312_utf8tomb(struct zint_symbol *symbol, const unsigned char sou
}
/* Convert UTF-8 string to single byte ECI and place in array of ints */
INTERNAL int gb2312_utf8tosb(int eci, const unsigned char source[], size_t* p_length, unsigned int* gbdata) {
INTERNAL int gb2312_utf8tosb(int eci, const unsigned char source[], size_t* p_length, unsigned int* gbdata, int full_multibyte) {
int error_number;
#ifndef _MSC_VER
unsigned char single_byte[*p_length + 1];
@@ -1584,30 +1584,38 @@ INTERNAL int gb2312_utf8tosb(int eci, const unsigned char source[], size_t* p_le
return error_number;
}
gb2312_cpy(single_byte, p_length, gbdata);
gb2312_cpy(single_byte, p_length, gbdata, full_multibyte);
return 0;
}
/* Copy byte input stream to array of ints, putting double-bytes that match GRIDMATRIX Chinese mode in single entry */
INTERNAL void gb2312_cpy(const unsigned char source[], size_t* p_length, unsigned int* gbdata) {
/* 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[], size_t* p_length, unsigned int* gbdata, int full_multibyte) {
unsigned int i, j, length;
unsigned char c1, c2;
for (i = 0, j = 0, length = *p_length; i < length; i++, j++) {
if (length - i >= 2) {
c1 = source[i];
c2 = source[i + 1];
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;
i++;
if (full_multibyte) {
for (i = 0, j = 0, length = *p_length; i < length; i++, j++) {
if (length - i >= 2) {
c1 = source[i];
c2 = source[i + 1];
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;
i++;
} else {
gbdata[j] = c1;
}
} else {
gbdata[j] = c1;
gbdata[j] = source[i];
}
} else {
gbdata[j] = source[i];
}
*p_length = j;
} else {
/* Straight copy */
for (i = 0, length = *p_length; i < length; i++) {
gbdata[i] = source[i];
}
}
*p_length = j;
}