mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-17 00:24:35 -04: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
3 changed files with 22 additions and 21 deletions
|
@ -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 DATA_MODE:
|
||||||
case GS1_MODE:
|
case GS1_MODE:
|
||||||
memcpy(preprocessed, source, in_length);
|
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]);
|
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)) {
|
||||||
|
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;
|
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");
|
||||||
|
|
|
@ -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,15 +487,13 @@ 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")) {
|
||||||
|
if (my_symbol->input_mode & ESCAPE_MODE) {
|
||||||
|
my_symbol->input_mode = DATA_MODE + ESCAPE_MODE;
|
||||||
|
} else {
|
||||||
my_symbol->input_mode = DATA_MODE;
|
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…
Add table
Add a link
Reference in a new issue