2
0
mirror of https://github.com/zint/zint synced 2024-11-16 20:57:25 +13:00

CODEONE/ULTRA overrun fixes; TELEPEN fixes; CODEONE/LOGMARS/VIN/CODABAR options; GUI updates; tests

This commit is contained in:
gitlost
2020-06-04 18:45:25 +01:00
parent 8131471573
commit 6242e02638
80 changed files with 6393 additions and 2179 deletions

@ -34,17 +34,19 @@ namespace Zint {
m_securityLevel = -1;
m_fgColor = Qt::black;
m_bgColor = Qt::white;
m_zintSymbol = 0;
m_zintSymbol = NULL;
m_error = 0;
m_input_mode = UNICODE_MODE + ESCAPE_MODE;
m_input_mode = UNICODE_MODE;
m_scale = 1.0;
m_option_3 = 0;
m_hidetext = 0;
m_dot_size = 4.0 / 5.0;
target_size_horiz = 0;
target_size_vert = 0;
m_width = 0;
m_option_2 = 0;
m_whitespace = 0;
m_gssep = false;
m_debug = false;
}
QZint::~QZint() {
@ -52,20 +54,20 @@ namespace Zint {
ZBarcode_Delete(m_zintSymbol);
}
void QZint::encode() {
void QZint::resetSymbol() {
if (m_zintSymbol)
ZBarcode_Delete(m_zintSymbol);
m_lastError.clear();
m_zintSymbol = ZBarcode_Create();
m_zintSymbol->output_options = m_border;
m_zintSymbol->output_options |= m_border;
m_zintSymbol->symbology = m_symbol;
m_zintSymbol->height = m_height;
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->option_2 = m_width;
m_zintSymbol->option_2 = m_option_2;
m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) {
m_zintSymbol->show_hrt = 0;
@ -73,13 +75,27 @@ namespace Zint {
m_zintSymbol->show_hrt = 1;
}
m_zintSymbol->option_3 = m_option_3;
m_zintSymbol->scale = m_scale;
if (m_gssep) {
m_zintSymbol->output_options |= GS1_GS_SEPARATOR;
}
if (m_debug) {
m_zintSymbol->debug |= ZINT_DEBUG_PRINT;
}
strcpy(m_zintSymbol->fgcolour, m_fgColor.name().toLatin1().right(6));
strcpy(m_zintSymbol->bgcolour, m_bgColor.name().toLatin1().right(6));
strcpy(m_zintSymbol->primary, m_primaryMessage.toLatin1().left(127));
}
void QZint::encode() {
resetSymbol();
QByteArray bstr = m_text.toUtf8();
QByteArray pstr = m_primaryMessage.left(99).toLatin1();
strcpy(m_zintSymbol->primary, pstr.data());
m_error = ZBarcode_Encode_and_Buffer_Vector(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length(), 0);
m_lastError = m_zintSymbol->errtxt;
switch (m_zintSymbol->output_options) {
switch (m_zintSymbol->output_options & (BARCODE_BIND | BARCODE_BOX)) {
case 0: m_border = NO_BORDER;
break;
case 2: m_border = BIND;
@ -99,6 +115,10 @@ namespace Zint {
m_symbol = symbol;
}
int QZint::inputMode() const {
return m_input_mode;
}
void QZint::setInputMode(int input_mode) {
m_input_mode = input_mode;
}
@ -111,11 +131,6 @@ namespace Zint {
m_text = text;
}
void QZint::setTargetSize(int width, int height) {
target_size_horiz = width;
target_size_vert = height;
}
QString QZint::primaryMessage() const {
return m_primaryMessage;
}
@ -124,12 +139,20 @@ namespace Zint {
m_primaryMessage = primaryMessage;
}
int QZint::height() const {
return m_height;
}
void QZint::setHeight(int height) {
m_height = height;
}
void QZint::setWidth(int width) {
m_width = width;
int QZint::option2() const {
return m_option_2;
}
void QZint::setOption2(int option) {
m_option_2 = option;
}
void QZint::setOption3(int option) {
@ -193,14 +216,6 @@ namespace Zint {
void QZint::setSecurityLevel(int securityLevel) {
m_securityLevel = securityLevel;
}
int QZint::getError() {
return m_error;
}
QString QZint::error_message() const {
return m_lastError;
}
int QZint::mode() const {
return m_securityLevel;
@ -214,40 +229,39 @@ namespace Zint {
m_hidetext = hide;
}
void QZint::setTargetSize(int width, int height) {
target_size_horiz = width;
target_size_vert = height;
}
void QZint::setGSSep(bool gssep) {
m_gssep = gssep;
}
void QZint::setDebug(bool debug) {
m_debug = debug;
}
int QZint::getError() const {
return m_error;
}
QString QZint::error_message() const {
return m_lastError;
}
const QString & QZint::lastError() const {
return m_lastError;
}
bool QZint::hasErrors() const {
return m_lastError.length();
}
bool QZint::save_to_file(QString filename) {
if (m_zintSymbol)
ZBarcode_Delete(m_zintSymbol);
QString fg_colour_hash = m_fgColor.name();
QString bg_colour_hash = m_bgColor.name();
m_lastError.clear();
m_zintSymbol = ZBarcode_Create();
m_zintSymbol->output_options = m_border;
m_zintSymbol->symbology = m_symbol;
m_zintSymbol->height = m_height;
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->option_2 = m_width;
m_zintSymbol->dot_size = m_dot_size;
if (m_hidetext) {
m_zintSymbol->show_hrt = 0;
} else {
m_zintSymbol->show_hrt = 1;
}
m_zintSymbol->option_3 = m_option_3;
m_zintSymbol->scale = m_scale;
resetSymbol();
strcpy(m_zintSymbol->outfile, filename.toLatin1().left(255));
QByteArray bstr = m_text.toUtf8();
QByteArray pstr = m_primaryMessage.left(99).toLatin1();
QByteArray fstr = filename.left(255).toLatin1();
strcpy(m_zintSymbol->primary, pstr.data());
strcpy(m_zintSymbol->outfile, fstr.data());
QByteArray fgcol = fg_colour_hash.right(6).toLatin1();
QByteArray bgcol = bg_colour_hash.right(6).toLatin1();
strcpy(m_zintSymbol->fgcolour, fgcol.data());
strcpy(m_zintSymbol->bgcolour, bgcol.data());
m_error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length(), 0);
if (m_error >= 5) {
m_lastError = m_zintSymbol->errtxt;
@ -404,14 +418,4 @@ namespace Zint {
painter.restore();
}
const QString & QZint::lastError() const {
return m_lastError;
}
bool QZint::hasErrors() {
return m_lastError.length();
}
}

@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/* vim: set ts=4 sw=4 et : */
#ifndef BARCODERENDER_H
#define BARCODERENDER_H
@ -29,98 +30,105 @@ class QZint
private:
public:
enum BorderType{NO_BORDER=0, BIND=2, BOX=4};
enum AspectRatioMode{IgnoreAspectRatio=0, KeepAspectRatio=1, CenterBarCode=2};
enum BorderType{NO_BORDER=0, BIND=2, BOX=4};
enum AspectRatioMode{IgnoreAspectRatio=0, KeepAspectRatio=1, CenterBarCode=2};
public:
QZint();
~QZint();
QZint();
~QZint();
int symbol() const;
void setSymbol(int symbol);
void setSymbol(int symbol);
int inputMode() const;
void setInputMode(int input_mode);
QString text() const;
void setText(const QString & text);
void setText(const QString & text);
QString primaryMessage() const;
void setPrimaryMessage(const QString & primaryMessage);
void setPrimaryMessage(const QString & primaryMessage);
void setHeight(int height);
int height();
int height() const;
void setHeight(int height);
void setWidth(int width);
int width();
int option2() const;
void setOption2(int option);
void setOption3(int option);
QColor fgColor() const;
void setFgColor(const QColor & fgColor);
QColor bgColor() const;
void setBgColor(const QColor & bgColor);
BorderType borderType() const;
void setBorderType(BorderType border);
int borderWidth() const;
void setBorderWidth(int boderWidth);
int securityLevel() const;
void setSecurityLevel(int securityLevel);
int getError();
void setOption3(int option);
float scale() const;
void setScale(float scale);
void setScale(float scale);
void setDotSize(float dot_size);
void setDotSize(float dot_size);
QColor fgColor() const;
void setFgColor(const QColor & fgColor);
QColor bgColor() const;
void setBgColor(const QColor & bgColor);
BorderType borderType() const;
void setBorderType(BorderType border);
int borderWidth() const;
void setBorderWidth(int boderWidth);
int securityLevel() const;
void setSecurityLevel(int securityLevel);
int mode() const;
void setMode(int securityLevel);
void setMode(int securityLevel);
void setInputMode(int input_mode);
void setWhitespace(int whitespace);
void setWhitespace(int whitespace);
void setHideText(bool hide);
void setTargetSize(int width, int height);
void setGSSep(bool gssep);
void setDebug(bool debug);
int getError() const;
QString error_message() const;
void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio);
const QString & lastError() const;
bool hasErrors();
bool hasErrors() const;
bool save_to_file(QString filename);
bool save_to_file(QString filename);
void setHideText(bool hide);
void setTargetSize(int width, int height);
void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio);
private:
void encode();
int module_set(int y_coord, int x_coord) const;
void resetSymbol();
void encode();
private:
int m_symbol;
QString m_text;
QString m_primaryMessage;
int m_height;
BorderType m_border;
int m_borderWidth;
int m_width;
int m_securityLevel;
int m_input_mode;
QColor m_fgColor;
QColor m_bgColor;
QString m_lastError;
int m_error;
int m_whitespace;
zint_symbol * m_zintSymbol;
float m_scale;
int m_option_3;
bool m_hidetext;
int m_symbol;
QString m_text;
QString m_primaryMessage;
int m_height;
BorderType m_border;
int m_borderWidth;
int m_option_2;
int m_securityLevel;
int m_input_mode;
QColor m_fgColor;
QColor m_bgColor;
QString m_lastError;
int m_error;
int m_whitespace;
zint_symbol * m_zintSymbol;
float m_scale;
int m_option_3;
bool m_hidetext;
float m_dot_size;
int target_size_horiz;
int target_size_vert;
bool m_gssep;
bool m_debug;
};
}
#endif