mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Allow escape character processing
Fixes #101 reported by Martin Zizka Converts \xNN characters > 0x7c to UTF-8 if appropriate Removes some redundant legacy code
This commit is contained in:
parent
909e307636
commit
dddf2934fc
@ -568,7 +568,7 @@ int ZBarcode_ValidID(int symbol_id) {
|
|||||||
|
|
||||||
static int extended_charset(struct zint_symbol *symbol, const unsigned char *source, const int length) {
|
static int extended_charset(struct zint_symbol *symbol, const unsigned char *source, const int length) {
|
||||||
int error_number = 0;
|
int error_number = 0;
|
||||||
|
|
||||||
/* These are the "elite" standards which can support multiple character sets */
|
/* These are the "elite" standards which can support multiple character sets */
|
||||||
switch (symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_QRCODE: error_number = qr_code(symbol, source, length);
|
case BARCODE_QRCODE: error_number = qr_code(symbol, source, length);
|
||||||
@ -595,7 +595,7 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
|
|||||||
#else
|
#else
|
||||||
unsigned char* preprocessed = (unsigned char*) _alloca(in_length + 1);
|
unsigned char* preprocessed = (unsigned char*) _alloca(in_length + 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (symbol->symbology == BARCODE_CODE16K) {
|
if (symbol->symbology == BARCODE_CODE16K) {
|
||||||
symbol->whitespace_width = 16;
|
symbol->whitespace_width = 16;
|
||||||
symbol->border_width = 2;
|
symbol->border_width = 2;
|
||||||
@ -611,8 +611,8 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
|
|||||||
symbol->output_options += BARCODE_BOX;
|
symbol->output_options += BARCODE_BOX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (symbol->input_mode) {
|
switch (symbol->input_mode & 0x07) {
|
||||||
case DATA_MODE:
|
case DATA_MODE:
|
||||||
case GS1_MODE:
|
case GS1_MODE:
|
||||||
memcpy(preprocessed, source, in_length);
|
memcpy(preprocessed, source, in_length);
|
||||||
@ -626,7 +626,7 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, in_length);
|
case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, in_length);
|
||||||
break;
|
break;
|
||||||
@ -814,7 +814,7 @@ int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string,
|
|||||||
|
|
||||||
in_posn = 0;
|
in_posn = 0;
|
||||||
out_posn = 0;
|
out_posn = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (input_string[in_posn] == '\\') {
|
if (input_string[in_posn] == '\\') {
|
||||||
switch (input_string[in_posn + 1]) {
|
switch (input_string[in_posn + 1]) {
|
||||||
@ -861,7 +861,14 @@ int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string,
|
|||||||
hex1 = ctoi(input_string[in_posn + 2]);
|
hex1 = ctoi(input_string[in_posn + 2]);
|
||||||
hex2 = ctoi(input_string[in_posn + 3]);
|
hex2 = ctoi(input_string[in_posn + 3]);
|
||||||
if ((hex1 >= 0) && (hex2 >= 0)) {
|
if ((hex1 >= 0) && (hex2 >= 0)) {
|
||||||
escaped_string[out_posn] = (hex1 << 4) + hex2;
|
if (hex1 > 7 && (symbol->input_mode & UNICODE_MODE) != 0) {
|
||||||
|
// Convert to UTF-8
|
||||||
|
escaped_string[out_posn] = 0xc0 + (hex1 >> 2);
|
||||||
|
out_posn++;
|
||||||
|
escaped_string[out_posn] = 0x80 + ((hex1 & 0x03) << 4) + hex2;
|
||||||
|
} else {
|
||||||
|
escaped_string[out_posn] = (hex1 << 4) + hex2;
|
||||||
|
}
|
||||||
in_posn += 4;
|
in_posn += 4;
|
||||||
} else {
|
} else {
|
||||||
strcpy(symbol->errtxt, "233: Corrupt escape character in input data");
|
strcpy(symbol->errtxt, "233: Corrupt escape character in input data");
|
||||||
@ -881,11 +888,11 @@ int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string,
|
|||||||
}
|
}
|
||||||
out_posn++;
|
out_posn++;
|
||||||
} while (in_posn < *length);
|
} while (in_posn < *length);
|
||||||
|
|
||||||
memcpy(input_string, escaped_string, out_posn);
|
memcpy(input_string, escaped_string, out_posn);
|
||||||
input_string[out_posn] = '\0';
|
input_string[out_posn] = '\0';
|
||||||
*length = out_posn;
|
*length = out_posn;
|
||||||
|
|
||||||
error_number = 0;
|
error_number = 0;
|
||||||
|
|
||||||
return error_number;
|
return error_number;
|
||||||
@ -1115,7 +1122,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
|
|||||||
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (symbol->symbology) {
|
switch (symbol->symbology) {
|
||||||
case BARCODE_QRCODE:
|
case BARCODE_QRCODE:
|
||||||
case BARCODE_MICROQR:
|
case BARCODE_MICROQR:
|
||||||
|
@ -223,8 +223,6 @@ extern "C" {
|
|||||||
#define DATA_MODE 0
|
#define DATA_MODE 0
|
||||||
#define UNICODE_MODE 1
|
#define UNICODE_MODE 1
|
||||||
#define GS1_MODE 2
|
#define GS1_MODE 2
|
||||||
#define KANJI_MODE 3
|
|
||||||
#define SJIS_MODE 4
|
|
||||||
#define ESCAPE_MODE 8
|
#define ESCAPE_MODE 8
|
||||||
|
|
||||||
// Data Matrix specific options
|
// Data Matrix specific options
|
||||||
|
@ -432,8 +432,6 @@ int main(int argc, char **argv) {
|
|||||||
{"primary", 1, 0, 0},
|
{"primary", 1, 0, 0},
|
||||||
{"scale", 1, 0, 0},
|
{"scale", 1, 0, 0},
|
||||||
{"gs1", 0, 0, 0},
|
{"gs1", 0, 0, 0},
|
||||||
{"kanji", 0, 0, 0},
|
|
||||||
{"sjis", 0, 0, 0},
|
|
||||||
{"binary", 0, 0, 0},
|
{"binary", 0, 0, 0},
|
||||||
{"notext", 0, 0, 0},
|
{"notext", 0, 0, 0},
|
||||||
{"square", 0, 0, 0},
|
{"square", 0, 0, 0},
|
||||||
@ -489,14 +487,12 @@ int main(int argc, char **argv) {
|
|||||||
if (!strcmp(long_options[option_index].name, "gs1")) {
|
if (!strcmp(long_options[option_index].name, "gs1")) {
|
||||||
my_symbol->input_mode = GS1_MODE;
|
my_symbol->input_mode = GS1_MODE;
|
||||||
}
|
}
|
||||||
if (!strcmp(long_options[option_index].name, "kanji")) {
|
|
||||||
my_symbol->input_mode = KANJI_MODE;
|
|
||||||
}
|
|
||||||
if (!strcmp(long_options[option_index].name, "sjis")) {
|
|
||||||
my_symbol->input_mode = SJIS_MODE;
|
|
||||||
}
|
|
||||||
if (!strcmp(long_options[option_index].name, "binary")) {
|
if (!strcmp(long_options[option_index].name, "binary")) {
|
||||||
my_symbol->input_mode = DATA_MODE;
|
if (my_symbol->input_mode & ESCAPE_MODE) {
|
||||||
|
my_symbol->input_mode = DATA_MODE + ESCAPE_MODE;
|
||||||
|
} else {
|
||||||
|
my_symbol->input_mode = DATA_MODE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!strcmp(long_options[option_index].name, "fg")) {
|
if (!strcmp(long_options[option_index].name, "fg")) {
|
||||||
strncpy(my_symbol->fgcolour, optarg, 7);
|
strncpy(my_symbol->fgcolour, optarg, 7);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user