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:
gitlost 2022-05-09 19:50:50 +01:00
parent 3b9d989894
commit f58c80e290
81 changed files with 12026 additions and 4701 deletions

View file

@ -197,6 +197,18 @@ INTERNAL int is_eci_convertible(const int eci) {
return 1;
}
/* Are any of the ECIs in the segments convertible from UTF-8?
Sets `convertible[]` for each, which must be at least `seg_count` in size */
INTERNAL int is_eci_convertible_segs(const struct zint_seg segs[], const int seg_count, int convertible[]) {
int ret = 0;
int i;
for (i = 0; i < seg_count; i++) {
convertible[i] = is_eci_convertible(segs[i].eci);
ret |= convertible[i];
}
return ret;
}
/* Calculate length required to convert UTF-8 to (double-byte) encoding */
INTERNAL int get_eci_length(const int eci, const unsigned char source[], int length) {
if (eci == 20) { /* Shift JIS */
@ -222,6 +234,18 @@ INTERNAL int get_eci_length(const int eci, const unsigned char source[], int len
return length;
}
/* Call `get_eci_length()` for each segment, returning total */
INTERNAL int get_eci_length_segs(const struct zint_seg segs[], const int seg_count) {
int length = 0;
int i;
for (i = 0; i < seg_count; i++) {
length += get_eci_length(segs[i].eci, segs[i].source, segs[i].length);
}
return length;
}
/* Convert UTF-8 Unicode to other character encodings */
INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length) {
@ -325,4 +349,37 @@ INTERNAL int get_best_eci(const unsigned char source[], int length) {
return 26; // If all of these fail, use Unicode!
}
/* Return 0 on failure, first ECI set on success */
INTERNAL int get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) {
int first_eci_set = 0;
int i;
for (i = 0; i < seg_count; i++) {
if (segs[i].eci == 0) {
int eci = get_best_eci(segs[i].source, segs[i].length);
if (eci == 0) {
return 0;
}
if (eci == 3) {
if (i != 0 && segs[i - 1].eci > 3) {
segs[i].eci = eci;
if (first_eci_set == 0) {
first_eci_set = eci;
}
}
} else {
segs[i].eci = eci;
if (first_eci_set == 0) {
first_eci_set = eci;
if (i == 0) {
symbol->eci = eci;
}
}
}
}
}
return first_eci_set;
}
/* vim: set ts=4 sw=4 et : */