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
@ -612,7 +612,7 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour
|
||||
}
|
||||
}
|
||||
|
||||
switch (symbol->input_mode) {
|
||||
switch (symbol->input_mode & 0x07) {
|
||||
case DATA_MODE:
|
||||
case GS1_MODE:
|
||||
memcpy(preprocessed, source, in_length);
|
||||
@ -861,7 +861,14 @@ int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string,
|
||||
hex1 = ctoi(input_string[in_posn + 2]);
|
||||
hex2 = ctoi(input_string[in_posn + 3]);
|
||||
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;
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "233: Corrupt escape character in input data");
|
||||
|
@ -223,8 +223,6 @@ extern "C" {
|
||||
#define DATA_MODE 0
|
||||
#define UNICODE_MODE 1
|
||||
#define GS1_MODE 2
|
||||
#define KANJI_MODE 3
|
||||
#define SJIS_MODE 4
|
||||
#define ESCAPE_MODE 8
|
||||
|
||||
// Data Matrix specific options
|
||||
|
@ -432,8 +432,6 @@ int main(int argc, char **argv) {
|
||||
{"primary", 1, 0, 0},
|
||||
{"scale", 1, 0, 0},
|
||||
{"gs1", 0, 0, 0},
|
||||
{"kanji", 0, 0, 0},
|
||||
{"sjis", 0, 0, 0},
|
||||
{"binary", 0, 0, 0},
|
||||
{"notext", 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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
strncpy(my_symbol->fgcolour, optarg, 7);
|
||||
|
Loading…
Reference in New Issue
Block a user