From 29dbb4932527ac06eaf553d7c58cd63601017bf8 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 22 Oct 2017 10:55:50 +0100 Subject: [PATCH] Add escape sequence support to GUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also ensures that CR/LF formatted files remain unaltered when importing Fixes #72 reported by SiniĊĦa Sudec --- backend/library.c | 2 +- backend_qt/qzint.cpp | 6 +++--- frontend_qt/datawindow.cpp | 24 +++++++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/backend/library.c b/backend/library.c index 9db839e8..e7a898b5 100644 --- a/backend/library.c +++ b/backend/library.c @@ -852,7 +852,7 @@ 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; + escaped_string[out_posn] = (hex1 << 4) + hex2; in_posn += 4; } else { strcpy(symbol->errtxt, "233: Corrupt escape character in input data"); diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 3a472d9f..a42c9d07 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -37,7 +37,7 @@ namespace Zint { m_bgColor = Qt::white; m_zintSymbol = 0; m_error = 0; - m_input_mode = UNICODE_MODE; + m_input_mode = UNICODE_MODE + ESCAPE_MODE; m_scale = 1.0; m_option_3 = 0; m_hidetext = 0; @@ -65,7 +65,7 @@ namespace Zint { m_zintSymbol->whitespace_width = m_whitespace; m_zintSymbol->border_width = m_borderWidth; 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->dot_size = m_dot_size; if (m_hidetext) { @@ -252,7 +252,7 @@ namespace Zint { m_zintSymbol->whitespace_width = m_whitespace; m_zintSymbol->border_width = m_borderWidth; 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->dot_size = m_dot_size; if (m_hidetext) { diff --git a/frontend_qt/datawindow.cpp b/frontend_qt/datawindow.cpp index c62199d7..e6255ddc 100644 --- a/frontend_qt/datawindow.cpp +++ b/frontend_qt/datawindow.cpp @@ -77,7 +77,8 @@ void DataWindow::from_file() QString filename; QFile file; QByteArray outstream; - + QString escape_string; + open_dialog.setWindowTitle("Open File"); 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.")); return; } - + 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(); settings.setValue("studio/default_dir", filename.mid(0, filename.lastIndexOf(QDir::separator())));