Expand ECI support and enforce binary mode when ECI is set

This commit is contained in:
Robin Stuart 2017-07-23 17:59:51 +01:00
parent d818d1aecc
commit 451f0150d8
6 changed files with 52 additions and 10 deletions

View file

@ -1212,6 +1212,11 @@ int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length
unsigned char* masked_codeword_array;
unsigned char* codeword_array = (unsigned char *) _alloca(length * 3 * sizeof (unsigned char));
#endif /* _MSC_VER */
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
data_length = dotcode_encode_message(symbol, source, length, codeword_array, &binary_finish);

View file

@ -1053,6 +1053,11 @@ int grid_matrix(struct zint_symbol *symbol, const unsigned char source[], size_t
}
if (symbol->output_options & READER_INIT) reader = 1;
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
error_number = gm_encode(gbdata, length, binary, reader, symbol->eci, symbol->debug);
if (error_number != 0) {

View file

@ -485,7 +485,6 @@ static int supports_eci(const int symbology) {
case BARCODE_DOTCODE:
case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN:
case BARCODE_UPNQR:
result = 1;
break;
}
@ -991,6 +990,10 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source,int
if ((symbol->input_mode < 0) || (symbol->input_mode > 2)) {
symbol->input_mode = DATA_MODE;
}
if (symbol->eci != 3) {
symbol->input_mode = DATA_MODE;
}
if (symbol->input_mode == GS1_MODE) {
for (i = 0; i < in_length; i++) {

View file

@ -559,12 +559,10 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len
/* 366 */
static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_t length) {
int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset;
int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr;
int total, chainemc[2700], mclength, c1, c2, c3, dummy[35];
char pattern[580];
int debug = symbol->debug;
codeerr = 0;
/* 456 */
indexliste = 0;
indexchaine = 0;
@ -639,6 +637,11 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
}
}
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
for (i = 0; i < indexliste; i++) {
switch (liste[1][i]) {
case TEX: /* 547 - text mode */
@ -821,7 +824,7 @@ static int pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size
symbol->width =(int)strlen(pattern);
/* 843 */
return codeerr;
return 0;
}
/* 345 */
@ -863,6 +866,9 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], const size_t l
strcpy(symbol->errtxt, "Data too long for specified number of columns (D65)");
error_number = ZINT_ERROR_TOO_LONG;
break;
case ZINT_ERROR_INVALID_OPTION:
error_number = codeerr;
break;
default:
strcpy(symbol->errtxt, "Something strange happened (D66)");
error_number = ZINT_ERROR_ENCODING_PROBLEM;
@ -936,6 +942,11 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], const size_
mclength++;
}
if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "Invalid ECI");
return ZINT_ERROR_INVALID_OPTION;
}
if (symbol->eci != 3) {
/* Encoding ECI assignment number, according to Table 8 */
if (symbol->eci <= 899) {

View file

@ -424,9 +424,8 @@ The --binary option prevents Zint from performing any convertion of the data
before placing in the barcode symbol and should be used if you are encoding raw
binary or encrypted data.
If your platform does not use Unicode or if you are using data from file which
is not stored in UTF-8 then you can specify the encoding by using the --binary
switch in combination with the --eci= switch followed by the appropriate number
If you are using data from file which is not UTF-8 formatted then you can
specify the encoding by using the --eci= switch followed by the appropriate number
from the table below. This procedure adds an ECI flag in the barcode data which
tells the barcode reader to change character encoding.
@ -448,13 +447,25 @@ ECI Code | Character Encoding Scheme
16 | ISO-8859-14 - Latin alphabet No. 8 (Celtic)
17 | ISO-8859-15 - Latin alphabet No. 9
18 | ISO-8859-16 - Latin alphabet No. 10
20 * | Shift-JIS (JISX 0208 amd JISX 0201)
21 | Windows-1250 - Latin 2 (Central Europe)
22 | Windows-1251 - Cyrillic
23 | Windows-1252 - Latin 1
24 | Windows-1256 - Arabic
25 * | UCS-2 Unicode (High order byte first)
26 | Unicode (UTF-8)
27 | ISO-646:1991 7-bit character set
28 * | Big-5 (Taiwan) Chinese Character Set
29 * | GB (PRC) Chinese Character Set
30 * | Korean Character Set (KSX1001:1998)
--------------------------------------------------------
* Note: When using the ECI flag Zint will treat all input data as raw binary.
This means that data which is encoded using a multiple-byte encoding schemes
(other than UTF-8) will not use optimal compression. It is therefore
recommended that data using these schemes be converted to UTF-8 using iconv
or similar before passing it to Zint.
4.11 Batch processing
---------------------
Data can be batch processed by reading from a text file and producing a
@ -553,7 +564,7 @@ options available, and also gives the exact version of the software.
The -t or --types option gives the table of symbologies along with the symbol
ID numbers.
The -e or --ecinos option gives a list of the ECI codes supported by Zint.
The -e or --ecinos option gives a list of the ECI codes.
4.16 Other output options
-------------------------

View file

@ -134,11 +134,18 @@ void show_eci(void) {
"16: ISO-8859-14 - Latin alphabet No. 8 (Celtic)\n"
"17: ISO-8859-15 - Latin alphabet No. 9\n"
"18: ISO-8859-16 - Latin alphabet No. 10\n"
"20: ** Shift-JIS (JISX 0208 amd JISX 0201)\n"
"21: Windows-1250\n"
"22: Windows-1251\n"
"23: Windows-1252\n"
"24: Windows-1256\n"
"25: ** UCS-2 Unicode (High order byte first)\n"
"26: Unicode (UTF-8)\n"
"27: ISO-646:1991 7-bit character set\n"
"28: ** Big-5 (Taiwan) Chinese Character Set\n"
"29: ** GB (PRC) Chinese Character Set\n"
"30: ** Korean Character Set (KSX1001:1998)\n"
"** See note in section 4.10 of the manual"
);
}
@ -683,7 +690,7 @@ int main(int argc, char **argv) {
strncpy(filetype, optarg, (size_t) 3);
}
if (!strcmp(long_options[option_index].name, "eci")) {
if ((atoi(optarg) >= 0) && (atoi(optarg) <= 30)) {
if ((atoi(optarg) >= 0) && (atoi(optarg) <= 999999)) {
my_symbol->eci = atoi(optarg);
} else {
fprintf(stderr, "Invalid ECI code (A18)\n");