Add DotCode to Studio

This commit is contained in:
Robin Stuart 2016-08-14 09:58:38 +01:00
parent bcad6504b5
commit 532247e97a
3 changed files with 610 additions and 617 deletions

View File

@ -1,6 +1,7 @@
/***************************************************************************
* Copyright (C) 2008 by BogDan Vatra *
* bogdan@licentia.eu *
* Copyright (C) 2010-2016 Robin Stuart *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@ -17,8 +18,7 @@
#include "qzint.h"
#include <stdio.h>
namespace Zint
{
namespace Zint {
static const qreal maxi_diagonal = 11;
static const qreal maxi_width = 1.73205807568877 * maxi_diagonal / 2;
@ -26,8 +26,7 @@ static const char* fontstyle="Arial";
static const int fontPixelSizeSmall = 6;
static const int fontPixelSizeLarge = 8;
QZint::QZint()
{
QZint::QZint() {
m_symbol = BARCODE_CODE128;
m_height = 50;
m_border = NO_BORDER;
@ -44,14 +43,12 @@ QZint::QZint()
m_hidetext = FALSE;
}
QZint::~QZint()
{
QZint::~QZint() {
if (m_zintSymbol)
ZBarcode_Delete(m_zintSymbol);
}
void QZint::encode()
{
void QZint::encode() {
if (m_zintSymbol)
ZBarcode_Delete(m_zintSymbol);
@ -86,165 +83,146 @@ void QZint::encode()
m_zintSymbol->height = 33;
switch (m_zintSymbol->output_options) {
case 0: m_border = NO_BORDER; break;
case 2: m_border = BIND; break;
case 4: m_border = BOX; break;
case 0: m_border = NO_BORDER;
break;
case 2: m_border = BIND;
break;
case 4: m_border = BOX;
break;
}
m_borderWidth = (BorderType) m_zintSymbol->border_width;
m_whitespace = m_zintSymbol->whitespace_width;
}
int QZint::symbol()
{
int QZint::symbol() {
return m_symbol;
}
void QZint::setSymbol(int symbol)
{
void QZint::setSymbol(int symbol) {
m_symbol = symbol;
}
void QZint::setInputMode(int input_mode)
{
void QZint::setInputMode(int input_mode) {
m_input_mode = input_mode;
}
QString QZint::text()
{
QString QZint::text() {
return m_text;
}
void QZint::setText(const QString & text)
{
void QZint::setText(const QString & text) {
m_text = text;
}
QString QZint::primaryMessage()
{
QString QZint::primaryMessage() {
return m_primaryMessage;
}
void QZint::setPrimaryMessage(const QString & primaryMessage)
{
void QZint::setPrimaryMessage(const QString & primaryMessage) {
m_primaryMessage = primaryMessage;
}
int QZint::height()
{
int QZint::height() {
encode();
return (m_zintSymbol->height + (m_border != NO_BORDER) ? m_borderWidth * 2 : 0)*(m_zintSymbol->symbology == BARCODE_MAXICODE ? (maxi_width + 1) : 1);
}
void QZint::setHeight(int height)
{
void QZint::setHeight(int height) {
m_height = height;
}
void QZint::setWidth(int width)
{
void QZint::setWidth(int width) {
m_width = width;
}
void QZint::setOption3(int option)
{
void QZint::setOption3(int option) {
m_option_3 = option;
}
int QZint::width()
{
int QZint::width() {
encode();
return (m_zintSymbol->width + (m_border == BOX) ? m_borderWidth * 2 : 0)*(m_zintSymbol->symbology == BARCODE_MAXICODE ? (maxi_width + 1) : 1);
}
float QZint::scale()
{
float QZint::scale() {
return m_scale;
}
void QZint::setScale(float scale)
{
void QZint::setScale(float scale) {
m_scale = scale;
}
QColor QZint::fgColor()
{
QColor QZint::fgColor() {
return m_fgColor;
}
void QZint::setFgColor(const QColor & fgColor)
{
void QZint::setFgColor(const QColor & fgColor) {
m_fgColor = fgColor;
}
QColor QZint::bgColor()
{
QColor QZint::bgColor() {
return m_bgColor;
}
void QZint::setBgColor(const QColor & bgColor)
{
void QZint::setBgColor(const QColor & bgColor) {
m_bgColor = bgColor;
}
QZint::BorderType QZint::borderType()
{
QZint::BorderType QZint::borderType() {
return m_border;
}
void QZint::setBorderType(BorderType border)
{
void QZint::setBorderType(BorderType border) {
m_border = border;
}
int QZint::borderWidth()
{
int QZint::borderWidth() {
return m_borderWidth;
}
void QZint::setBorderWidth(int boderWidth)
{
void QZint::setBorderWidth(int boderWidth) {
if (boderWidth < 1 || boderWidth > 16)
boderWidth = 1;
m_borderWidth = boderWidth;
}
void QZint::setWhitespace(int whitespace)
{
void QZint::setWhitespace(int whitespace) {
m_whitespace = whitespace;
}
int QZint::pdf417CodeWords()
{
int QZint::pdf417CodeWords() {
return m_pdf417CodeWords;
}
void QZint::setPdf417CodeWords(int pdf417CodeWords)
{
void QZint::setPdf417CodeWords(int pdf417CodeWords) {
m_pdf417CodeWords = pdf417CodeWords;
}
int QZint::securityLevel()
{
int QZint::securityLevel() {
return m_securityLevel;
}
void QZint::setSecurityLevel(int securityLevel)
{
void QZint::setSecurityLevel(int securityLevel) {
m_securityLevel = securityLevel;
}
QString QZint::error_message()
{
QString QZint::error_message() {
return m_lastError;
}
int QZint::mode()
{
int QZint::mode() {
return m_securityLevel;
}
void QZint::setMode(int securityLevel)
{
void QZint::setMode(int securityLevel) {
m_securityLevel = securityLevel;
}
void QZint::setHideText(bool hide)
{
void QZint::setHideText(bool hide) {
m_hidetext = hide;
}
bool QZint::save_to_file(QString filename)
{
bool QZint::save_to_file(QString filename) {
if (m_zintSymbol)
ZBarcode_Delete(m_zintSymbol);
@ -287,32 +265,28 @@ bool QZint::save_to_file(QString filename)
error = ZBarcode_Print(m_zintSymbol, 0);
if (error > ZINT_WARN_INVALID_OPTION)
m_lastError = m_zintSymbol->errtxt;
if(error == 0) { return true; } else { return false; }
if (error == 0) {
return true;
} else {
return false;
}
}
int QZint::module_set(int y_coord, int x_coord)
{
int QZint::module_set(int y_coord, int x_coord) {
int x_char, x_sub, result;
x_char = x_coord / 7;
x_sub = x_coord % 7;
result = 0;
switch(x_sub) {
case 0: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x01) != 0) { result = 1; } break;
case 1: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x02) != 0) { result = 1; } break;
case 2: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x04) != 0) { result = 1; } break;
case 3: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x08) != 0) { result = 1; } break;
case 4: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x10) != 0) { result = 1; } break;
case 5: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x20) != 0) { result = 1; } break;
case 6: if((m_zintSymbol->encoded_data[y_coord][x_char] & 0x40) != 0) { result = 1; } break;
if (m_zintSymbol->encoded_data[y_coord][x_char] & (0x01 << x_sub)) {
result = 1;
}
return result;
}
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode)
{
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) {
encode();
bool textdone;
int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0;
@ -323,8 +297,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
QFont fontLarge(fontstyle);
fontLarge.setPixelSize(fontPixelSizeLarge);
if (m_lastError.length())
{
if (m_lastError.length()) {
painter.setFont(fontLarge);
painter.drawText(paintRect, Qt::AlignCenter, m_lastError);
return;
@ -337,31 +310,32 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
int zrow_height = m_zintSymbol->height;
int zrows = 0;
for (int i=0;i<m_zintSymbol->rows;i++)
{
for (int i = 0; i < m_zintSymbol->rows; i++) {
zrow_height -= m_zintSymbol->row_height[i];
if (!m_zintSymbol->row_height[i])
zrows++;
}
if (zrows)
{
if (zrows) {
zrow_height /= zrows;
for (int i = 0; i < m_zintSymbol->rows; i++)
if (!m_zintSymbol->row_height[i])
m_zintSymbol->row_height[i] = zrow_height;
}
else
} else
m_zintSymbol->height -= zrow_height;
qreal gwidth = m_zintSymbol->width;
qreal gheight = m_zintSymbol->height;
if (m_zintSymbol->symbology == BARCODE_MAXICODE)
{
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
gheight *= (maxi_width);
gwidth *= (maxi_width + 1);
}
if (m_zintSymbol->output_options &= BARCODE_DOTTY_MODE) {
gwidth += 2.0;
gheight += 2.0;
}
qreal xsf = 1;
qreal ysf = 1;
qreal textoffset = 0;
@ -375,21 +349,17 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
textoffset = 0;
}
gwidth += m_zintSymbol->whitespace_width * 2;
switch(mode)
{
switch (mode) {
case IgnoreAspectRatio:
xsf = (qreal) paintRect.width() / gwidth;
ysf = (qreal) paintRect.height() / gheight;
break;
case KeepAspectRatio:
if (paintRect.width()/gwidth<paintRect.height()/gheight)
{
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
ysf = xsf = (qreal) paintRect.width() / gwidth;
ytr += (qreal) (paintRect.height() - gheight * ysf) / 2;
}
else
{
} else {
ysf = xsf = (qreal) paintRect.height() / gheight;
xtr += (qreal) (paintRect.width() - gwidth * xsf) / 2;
}
@ -414,8 +384,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
QPainterPath pt;
if (m_zintSymbol->symbology != BARCODE_MAXICODE) {
/* Draw boundary bars or boxes around the symbol */
switch(m_border)
{
switch (m_border) {
case BOX:
painter.fillRect(0, m_borderWidth, m_borderWidth, m_zintSymbol->height, QBrush(m_fgColor));
painter.fillRect(m_zintSymbol->width + xoffset + xoffset + m_borderWidth, m_borderWidth, m_borderWidth, m_zintSymbol->height, QBrush(m_fgColor));
@ -433,7 +402,8 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
default:
painter.translate(m_zintSymbol->whitespace_width, 0);
break;;
break;
;
}
}
@ -478,17 +448,13 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
p.setWidth(1);
painter.setPen(p);
if (m_zintSymbol->symbology == BARCODE_MAXICODE)
{
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
/* Draw Maxicode with hexagons */
painter.save();
painter.setRenderHint(QPainter::Antialiasing);
for (int r=0;r<m_zintSymbol->rows;r++)
{
for (int c=0;c<m_zintSymbol->width;c++)
{
if (module_set(r, c))
{
for (int r = 0; r < m_zintSymbol->rows; r++) {
for (int c = 0; c < m_zintSymbol->width; c++) {
if (module_set(r, c)) {
qreal col = (qreal) c * (maxi_width + 1)+(r % 2)*((maxi_width + 1) / 2);
qreal row = (qreal) r * (maxi_width + 1)*0.868;
QPainterPath pt;
@ -510,16 +476,28 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.drawEllipse(QPointF(14.5 * w, 16.5 * w * 0.868), w + w * 1.5, w + w * 1.5);
painter.drawEllipse(QPointF(14.5 * w, 16.5 * w * 0.868), w + w * 3, w + w * 3);
painter.restore();
} else if (m_zintSymbol->output_options &= BARCODE_DOTTY_MODE) {
/* Draw with dots (circles) */
p.setColor(m_fgColor);
p.setWidth(0);
painter.setPen(p);
painter.setBrush(QBrush(m_fgColor));
painter.setRenderHint(QPainter::Antialiasing);
for (int r = 0; r < m_zintSymbol->rows; r++) {
for (int c = 0; c < m_zintSymbol->width; c++) {
if (module_set(r, c)) {
painter.drawEllipse(QPointF((r + 1.0), (c + 1.0)), 0.5, 0.5);
}
else
{
}
}
} else {
/* Draw all other symbols with rectangles */
int y = 0;
for (int row=0;row<m_zintSymbol->rows;row++)
{
for (int row = 0; row < m_zintSymbol->rows; row++) {
for (int i = 0; i < m_zintSymbol->width; i++) {
if (module_set(row, i))
{
if (module_set(row, i)) {
int ed = module_set(row, i);
int linewidth = 0;
for (int j = i; j < m_zintSymbol->width; j++, linewidth++)
@ -564,8 +542,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.setFont(fontLarge);
painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 29, 9, Qt::AlignCenter, caption.mid(0, 4));
painter.drawText(35 + xoffset, m_zintSymbol->height + yoffset, 29, 9, Qt::AlignCenter, caption.mid(4, 4));
if(caption.size() == 11) { /* EAN-2 */ painter.drawText(76 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); };
if(caption.size() == 14) { /* EAN-5 */ painter.drawText(76 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
if (caption.size() == 11) {
/* EAN-2 */ painter.drawText(76 + xoffset, addon_text_height, 20, 9, Qt::AlignCenter, caption.mid(9, 2));
};
if (caption.size() == 14) {
/* EAN-5 */ painter.drawText(76 + xoffset, addon_text_height, 47, 9, Qt::AlignCenter, caption.mid(9, 5));
};
painter.setFont(fontSmall);
textdone = true;
break;
@ -582,8 +564,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 9, Qt::AlignCenter, caption.mid(0, 1));
painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9, Qt::AlignCenter, caption.mid(1, 6));
painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 43, 9, Qt::AlignCenter, caption.mid(7, 6));
if(caption.size() == 16) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(14,2)); };
if(caption.size() == 19) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(14,5)); };
if (caption.size() == 16) {
/* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9, Qt::AlignCenter, caption.mid(14, 2));
};
if (caption.size() == 19) {
/* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9, Qt::AlignCenter, caption.mid(14, 5));
};
painter.setFont(fontSmall);
textdone = true;
break;
@ -641,8 +627,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.setFont(fontLarge);
painter.drawText(11 + xoffset, m_zintSymbol->height + yoffset, 35, 9, Qt::AlignCenter, caption.mid(1, 5));
painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 35, 9, Qt::AlignCenter, caption.mid(6, 5));
if(caption.size() == 15) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(13,2)); };
if(caption.size() == 18) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(13,5)); };
if (caption.size() == 15) {
/* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9, Qt::AlignCenter, caption.mid(13, 2));
};
if (caption.size() == 18) {
/* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9, Qt::AlignCenter, caption.mid(13, 5));
};
painter.setFont(fontSmall);
textdone = true;
}
@ -658,8 +648,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.drawText(51 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7, Qt::AlignCenter, caption.mid(7, 1));
painter.setFont(fontLarge);
painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9, Qt::AlignCenter, caption.mid(1, 6));
if(caption.size() == 11) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); };
if(caption.size() == 14) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
if (caption.size() == 11) {
/* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 20, 9, Qt::AlignCenter, caption.mid(9, 2));
};
if (caption.size() == 14) {
/* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 47, 9, Qt::AlignCenter, caption.mid(9, 5));
};
painter.setFont(fontSmall);
textdone = true;
}
@ -672,15 +666,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.restore();
}
const QString & QZint::lastError()
{
const QString & QZint::lastError() {
return m_lastError;
}
bool QZint::hasErrors()
{
bool QZint::hasErrors() {
return m_lastError.length();
}
}

View File

@ -56,6 +56,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl)
"Data Matrix (ISO 16022)",
"Deutsche Post Identcode",
"Deutsche Post Leitcode",
"DotCode",
"Dutch Post KIX",
"EAN-14",
"European Article Number (EAN)",

View File

@ -63,6 +63,7 @@ public:
DATAMATRIX =71,
DPIDENT =22,
DPLEIT =21,
DOTCODE =115,
KIX =90,
EAN14 =72,
EANX =13,