Add escape sequence support to GUI

Also ensures that CR/LF formatted files remain unaltered when importing
Fixes #72 reported by Siniša Sudec
This commit is contained in:
Robin Stuart 2017-10-22 10:55:50 +01:00
parent 0314ca65a8
commit 29dbb49325
3 changed files with 25 additions and 7 deletions

View File

@ -852,7 +852,7 @@ 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; 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");

View File

@ -37,7 +37,7 @@ namespace Zint {
m_bgColor = Qt::white; m_bgColor = Qt::white;
m_zintSymbol = 0; m_zintSymbol = 0;
m_error = 0; m_error = 0;
m_input_mode = UNICODE_MODE; m_input_mode = UNICODE_MODE + ESCAPE_MODE;
m_scale = 1.0; m_scale = 1.0;
m_option_3 = 0; m_option_3 = 0;
m_hidetext = 0; m_hidetext = 0;
@ -65,7 +65,7 @@ namespace Zint {
m_zintSymbol->whitespace_width = m_whitespace; m_zintSymbol->whitespace_width = m_whitespace;
m_zintSymbol->border_width = m_borderWidth; m_zintSymbol->border_width = m_borderWidth;
m_zintSymbol->option_1 = m_securityLevel; m_zintSymbol->option_1 = m_securityLevel;
m_zintSymbol->input_mode = m_input_mode; m_zintSymbol->input_mode = m_input_mode + ESCAPE_MODE;
m_zintSymbol->option_2 = m_width; m_zintSymbol->option_2 = m_width;
m_zintSymbol->dot_size = m_dot_size; m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) { if (m_hidetext) {
@ -252,7 +252,7 @@ namespace Zint {
m_zintSymbol->whitespace_width = m_whitespace; m_zintSymbol->whitespace_width = m_whitespace;
m_zintSymbol->border_width = m_borderWidth; m_zintSymbol->border_width = m_borderWidth;
m_zintSymbol->option_1 = m_securityLevel; m_zintSymbol->option_1 = m_securityLevel;
m_zintSymbol->input_mode = m_input_mode; m_zintSymbol->input_mode = m_input_mode + ESCAPE_MODE;
m_zintSymbol->option_2 = m_width; m_zintSymbol->option_2 = m_width;
m_zintSymbol->dot_size = m_dot_size; m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) { if (m_hidetext) {

View File

@ -77,7 +77,8 @@ void DataWindow::from_file()
QString filename; QString filename;
QFile file; QFile file;
QByteArray outstream; QByteArray outstream;
QString escape_string;
open_dialog.setWindowTitle("Open File"); open_dialog.setWindowTitle("Open File");
open_dialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString()); open_dialog.setDirectory(settings.value("studio/default_dir", QDir::toNativeSeparators(QDir::homePath())).toString());
@ -92,10 +93,27 @@ void DataWindow::from_file()
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file.")); QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
return; return;
} }
outstream = file.readAll(); outstream = file.readAll();
txtDataInput->setPlainText(QString(outstream)); /* Allow some non-printing (control) characters to be read from file
by converting them to escape sequences */
escape_string.clear();
escape_string.append(QString(outstream));
escape_string.replace((QChar)'\\', (QString)"\\\\", Qt::CaseInsensitive);
escape_string.replace((QChar)0x04, (QString)"\\E", Qt::CaseInsensitive); /* End of Transmission */
escape_string.replace((QChar)'\a', (QString)"\\a", Qt::CaseInsensitive); /* Bell */
escape_string.replace((QChar)'\b', (QString)"\\b", Qt::CaseInsensitive); /* Backspace */
escape_string.replace((QChar)'\t', (QString)"\\t", Qt::CaseInsensitive); /* Horizontal tab */
escape_string.replace((QChar)'\v', (QString)"\\v", Qt::CaseInsensitive); /* Vertical tab */
escape_string.replace((QChar)'\f', (QString)"\\f", Qt::CaseInsensitive); /* Form feed */
escape_string.replace((QChar)'\r', (QString)"\\r", Qt::CaseInsensitive); /* Carriage return */
escape_string.replace((QChar)0x1b, (QString)"\\e", Qt::CaseInsensitive); /* Escape */
escape_string.replace((QChar)0x1d, (QString)"\\G", Qt::CaseInsensitive); /* Group Separator */
escape_string.replace((QChar)0x1e, (QString)"\\R", Qt::CaseInsensitive); /* Record Separator */
txtDataInput->setPlainText(QString(escape_string));
file.close(); file.close();
settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator()))); settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));