mirror of
https://git.code.sf.net/p/zint/code
synced 2025-06-03 08:28:44 -04:00
vector.c: string halign; POSTNET/PLANET: 1 module space; ZBarcode_Cap(); GUI settings
This commit is contained in:
parent
3f5ac34057
commit
36c19053d7
169 changed files with 10975 additions and 8318 deletions
|
@ -5,6 +5,7 @@ project(QZint)
|
|||
include_directories(BEFORE "${CMAKE_SOURCE_DIR}/backend" )
|
||||
|
||||
set(QZint_SRCS qzint.cpp)
|
||||
QT5_WRAP_CPP(QZint_SRCS qzint.h)
|
||||
|
||||
add_library(QZint SHARED ${QZint_SRCS})
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
***************************************************************************/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
//#include <QDebug>
|
||||
#include "qzint.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
@ -25,30 +26,36 @@
|
|||
#include <QPainterPath>
|
||||
|
||||
namespace Zint {
|
||||
static const char* fontstyle = "Arial";
|
||||
static const int fontPixelSizeSmall = 8;
|
||||
static const int fontPixelSizeLarge = 12;
|
||||
static const char *fontStyle = "Helvetica";
|
||||
static const char *fontStyleError = "Helvetica";
|
||||
static const int fontSizeError = 14; /* Point size */
|
||||
|
||||
QZint::QZint() {
|
||||
m_symbol = BARCODE_CODE128;
|
||||
m_height = 0;
|
||||
m_border = NO_BORDER;
|
||||
m_borderType = 0;
|
||||
m_borderWidth = 0;
|
||||
m_fontSetting = 0;
|
||||
m_securityLevel = -1;
|
||||
m_fgColor = Qt::black;
|
||||
m_bgColor = Qt::white;
|
||||
m_cmyk = false;
|
||||
m_zintSymbol = NULL;
|
||||
m_error = 0;
|
||||
m_input_mode = UNICODE_MODE;
|
||||
m_scale = 1.0;
|
||||
m_scale = 1.0f;
|
||||
m_option_3 = 0;
|
||||
m_hidetext = 0;
|
||||
m_dot_size = 4.0 / 5.0;
|
||||
m_show_hrt = 1;
|
||||
m_eci = 0;
|
||||
m_dotty = false;
|
||||
m_dot_size = 4.0f / 5.0f;
|
||||
target_size_horiz = 0;
|
||||
target_size_vert = 0;
|
||||
m_option_2 = 0;
|
||||
m_whitespace = 0;
|
||||
m_gssep = false;
|
||||
m_reader_init = false;
|
||||
m_rotate_angle = 0;
|
||||
m_debug = false;
|
||||
}
|
||||
|
||||
|
@ -63,7 +70,7 @@ namespace Zint {
|
|||
|
||||
m_lastError.clear();
|
||||
m_zintSymbol = ZBarcode_Create();
|
||||
m_zintSymbol->output_options |= m_border;
|
||||
m_zintSymbol->output_options |= m_borderType | m_fontSetting;
|
||||
m_zintSymbol->symbology = m_symbol;
|
||||
m_zintSymbol->height = m_height;
|
||||
m_zintSymbol->whitespace_width = m_whitespace;
|
||||
|
@ -71,17 +78,20 @@ namespace Zint {
|
|||
m_zintSymbol->option_1 = m_securityLevel;
|
||||
m_zintSymbol->input_mode = m_input_mode;
|
||||
m_zintSymbol->option_2 = m_option_2;
|
||||
m_zintSymbol->dot_size = m_dot_size;
|
||||
if (m_hidetext) {
|
||||
m_zintSymbol->show_hrt = 0;
|
||||
} else {
|
||||
m_zintSymbol->show_hrt = 1;
|
||||
if (m_dotty) {
|
||||
m_zintSymbol->output_options |= BARCODE_DOTTY_MODE;
|
||||
}
|
||||
m_zintSymbol->dot_size = m_dot_size;
|
||||
m_zintSymbol->show_hrt = m_show_hrt ? 1 : 0;
|
||||
m_zintSymbol->eci = m_eci;
|
||||
m_zintSymbol->option_3 = m_option_3;
|
||||
m_zintSymbol->scale = m_scale;
|
||||
if (m_gssep) {
|
||||
m_zintSymbol->output_options |= GS1_GS_SEPARATOR;
|
||||
}
|
||||
if (m_reader_init) {
|
||||
m_zintSymbol->output_options |= READER_INIT;
|
||||
}
|
||||
if (m_debug) {
|
||||
m_zintSymbol->debug |= ZINT_DEBUG_PRINT;
|
||||
}
|
||||
|
@ -94,25 +104,25 @@ namespace Zint {
|
|||
if (m_bgColor.alpha() != 0xff) {
|
||||
strcat(m_zintSymbol->bgcolour, m_bgColor.name(QColor::HexArgb).toLatin1().mid(1,2));
|
||||
}
|
||||
if (m_cmyk) {
|
||||
m_zintSymbol->output_options |= CMYK_COLOUR;
|
||||
}
|
||||
strcpy(m_zintSymbol->primary, m_primaryMessage.toLatin1().left(127));
|
||||
}
|
||||
|
||||
void QZint::encode() {
|
||||
resetSymbol();
|
||||
QByteArray bstr = m_text.toUtf8();
|
||||
m_error = ZBarcode_Encode_and_Buffer_Vector(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length(), 0);
|
||||
m_error = ZBarcode_Encode_and_Buffer_Vector(m_zintSymbol, (unsigned char *) bstr.data(), bstr.length(), 0); /* Note do our own rotation */
|
||||
m_lastError = m_zintSymbol->errtxt;
|
||||
|
||||
switch (m_zintSymbol->output_options & (BARCODE_BIND | BARCODE_BOX)) {
|
||||
case 0: m_border = NO_BORDER;
|
||||
break;
|
||||
case 2: m_border = BIND;
|
||||
break;
|
||||
case 4: m_border = BOX;
|
||||
break;
|
||||
if (m_error < ZINT_ERROR) {
|
||||
m_borderType = m_zintSymbol->output_options & (BARCODE_BIND | BARCODE_BOX);
|
||||
m_height = m_zintSymbol->height;
|
||||
m_borderWidth = m_zintSymbol->border_width;
|
||||
m_whitespace = m_zintSymbol->whitespace_width;
|
||||
emit encoded();
|
||||
}
|
||||
m_borderWidth = m_zintSymbol->border_width;
|
||||
m_whitespace = m_zintSymbol->whitespace_width;
|
||||
}
|
||||
|
||||
int QZint::symbol() const {
|
||||
|
@ -175,6 +185,14 @@ namespace Zint {
|
|||
m_scale = scale;
|
||||
}
|
||||
|
||||
bool QZint::dotty() const {
|
||||
return m_dotty;
|
||||
}
|
||||
|
||||
void QZint::setDotty(bool dotty) {
|
||||
m_dotty = dotty;
|
||||
}
|
||||
|
||||
void QZint::setDotSize(float dot_size) {
|
||||
m_dot_size = dot_size;
|
||||
}
|
||||
|
@ -195,12 +213,22 @@ namespace Zint {
|
|||
m_bgColor = bgColor;
|
||||
}
|
||||
|
||||
QZint::BorderType QZint::borderType() const {
|
||||
return m_border;
|
||||
void QZint::setCMYK(bool cmyk) {
|
||||
m_cmyk = cmyk;
|
||||
}
|
||||
|
||||
void QZint::setBorderType(BorderType border) {
|
||||
m_border = border;
|
||||
int QZint::borderType() const {
|
||||
return m_borderType;
|
||||
}
|
||||
|
||||
void QZint::setBorderType(int borderTypeIndex) {
|
||||
if (borderTypeIndex == 1) {
|
||||
m_borderType = BARCODE_BIND;
|
||||
} else if (borderTypeIndex == 2) {
|
||||
m_borderType = BARCODE_BOX;
|
||||
} else {
|
||||
m_borderType = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int QZint::borderWidth() const {
|
||||
|
@ -233,8 +261,20 @@ namespace Zint {
|
|||
m_securityLevel = securityLevel;
|
||||
}
|
||||
|
||||
void QZint::setHideText(bool hide) {
|
||||
m_hidetext = hide;
|
||||
void QZint::setFontSetting(int fontSettingIndex) {
|
||||
if (fontSettingIndex == 1) {
|
||||
m_fontSetting = BOLD_TEXT;
|
||||
} else if (fontSettingIndex == 2) {
|
||||
m_fontSetting = SMALL_TEXT;
|
||||
} else if (fontSettingIndex == 3) {
|
||||
m_fontSetting = SMALL_TEXT | BOLD_TEXT;
|
||||
} else {
|
||||
m_fontSetting = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setShowText(bool show) {
|
||||
m_show_hrt = show;
|
||||
}
|
||||
|
||||
void QZint::setTargetSize(int width, int height) {
|
||||
|
@ -246,10 +286,68 @@ namespace Zint {
|
|||
m_gssep = gssep;
|
||||
}
|
||||
|
||||
int QZint::rotateAngle() const {
|
||||
return m_rotate_angle;
|
||||
}
|
||||
|
||||
void QZint::setRotateAngle(int rotateIndex) {
|
||||
if (rotateIndex == 1) {
|
||||
m_rotate_angle = 90;
|
||||
} else if (rotateIndex == 2) {
|
||||
m_rotate_angle = 180;
|
||||
} else if (rotateIndex == 3) {
|
||||
m_rotate_angle = 270;
|
||||
} else {
|
||||
m_rotate_angle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setECI(int ECIIndex) {
|
||||
if (ECIIndex >= 1 && ECIIndex <= 11) {
|
||||
m_eci = ECIIndex + 2;
|
||||
} else if (ECIIndex >= 12 && ECIIndex <= 15) {
|
||||
m_eci = ECIIndex + 3;
|
||||
} else if (ECIIndex >= 16 && ECIIndex <= 26) {
|
||||
m_eci = ECIIndex + 4;
|
||||
} else if (ECIIndex == 27) {
|
||||
m_eci = 899; /* 8-bit binary data TODO: support */
|
||||
} else {
|
||||
m_eci = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::setReaderInit(bool reader_init) {
|
||||
m_reader_init = reader_init;
|
||||
}
|
||||
|
||||
void QZint::setDebug(bool debug) {
|
||||
m_debug = debug;
|
||||
}
|
||||
|
||||
bool QZint::hasHRT(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_HRT);
|
||||
}
|
||||
|
||||
bool QZint::isExtendable(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_EXTENDABLE);
|
||||
}
|
||||
|
||||
bool QZint::supportsECI(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_ECI);
|
||||
}
|
||||
|
||||
bool QZint::isFixedRatio(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_FIXED_RATIO);
|
||||
}
|
||||
|
||||
bool QZint::isDotty(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_DOTTY);
|
||||
}
|
||||
|
||||
bool QZint::supportsReaderInit(int symbology) const {
|
||||
return ZBarcode_Cap(symbology ? symbology : m_symbol, ZINT_CAP_READER_INIT);
|
||||
}
|
||||
|
||||
int QZint::getError() const {
|
||||
return m_error;
|
||||
}
|
||||
|
@ -270,8 +368,8 @@ namespace Zint {
|
|||
resetSymbol();
|
||||
strcpy(m_zintSymbol->outfile, filename.toLatin1().left(255));
|
||||
QByteArray bstr = m_text.toUtf8();
|
||||
m_error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length(), 0);
|
||||
if (m_error >= 5) {
|
||||
m_error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char *) bstr.data(), bstr.length(), m_rotate_angle);
|
||||
if (m_error >= ZINT_ERROR) {
|
||||
m_lastError = m_zintSymbol->errtxt;
|
||||
return false;
|
||||
} else {
|
||||
|
@ -279,6 +377,35 @@ namespace Zint {
|
|||
}
|
||||
}
|
||||
|
||||
Qt::GlobalColor QZint::colourToQtColor(int colour) {
|
||||
switch (colour) {
|
||||
case 1: // Cyan
|
||||
return Qt::cyan;
|
||||
break;
|
||||
case 2: // Blue
|
||||
return Qt::blue;
|
||||
break;
|
||||
case 3: // Magenta
|
||||
return Qt::magenta;
|
||||
break;
|
||||
case 4: // Red
|
||||
return Qt::red;
|
||||
break;
|
||||
case 5: // Yellow
|
||||
return Qt::yellow;
|
||||
break;
|
||||
case 6: // Green
|
||||
return Qt::green;
|
||||
break;
|
||||
case 8: // White
|
||||
return Qt::white;
|
||||
break;
|
||||
default:
|
||||
return Qt::black;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) {
|
||||
struct zint_vector_rect *rect;
|
||||
struct zint_vector_hexagon *hex;
|
||||
|
@ -290,140 +417,143 @@ namespace Zint {
|
|||
|
||||
encode();
|
||||
|
||||
QFont fontSmall(fontstyle);
|
||||
fontSmall.setPixelSize(fontPixelSizeSmall);
|
||||
QFont fontLarge(fontstyle);
|
||||
fontLarge.setPixelSize(fontPixelSizeLarge);
|
||||
painter.save();
|
||||
|
||||
if (m_error >= 5) {
|
||||
// Display error message instead of barcode
|
||||
fontLarge.setPointSize(14);
|
||||
painter.setFont(fontLarge);
|
||||
painter.drawText(paintRect, Qt::AlignCenter, m_lastError);
|
||||
if (m_error >= ZINT_ERROR) {
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QFont font(fontStyleError, fontSizeError);
|
||||
painter.setFont(font);
|
||||
painter.drawText(paintRect, Qt::AlignCenter | Qt::TextWordWrap, m_lastError);
|
||||
painter.restore();
|
||||
return;
|
||||
}
|
||||
|
||||
painter.save();
|
||||
painter.setClipRect(paintRect, Qt::IntersectClip);
|
||||
|
||||
qreal xtr = paintRect.x();
|
||||
qreal ytr = paintRect.y();
|
||||
qreal scale;
|
||||
|
||||
|
||||
qreal gwidth = m_zintSymbol->vector->width;
|
||||
qreal gheight = m_zintSymbol->vector->height;
|
||||
|
||||
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
|
||||
scale = paintRect.width() / gwidth;
|
||||
if (m_rotate_angle == 90 || m_rotate_angle == 270) {
|
||||
if (paintRect.width() / gheight < paintRect.height() / gwidth) {
|
||||
scale = paintRect.width() / gheight;
|
||||
} else {
|
||||
scale = paintRect.height() / gwidth;
|
||||
}
|
||||
} else {
|
||||
scale = paintRect.height() / gheight;
|
||||
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
|
||||
scale = paintRect.width() / gwidth;
|
||||
} else {
|
||||
scale = paintRect.height() / gheight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xtr += (qreal) (paintRect.width() - gwidth * scale) / 2.0;
|
||||
ytr += (qreal) (paintRect.height() - gheight * scale) / 2.0;
|
||||
|
||||
painter.setBackground(QBrush(m_bgColor));
|
||||
painter.fillRect(paintRect, QBrush(m_bgColor));
|
||||
|
||||
|
||||
if (m_rotate_angle) {
|
||||
painter.translate(paintRect.width() / 2.0, paintRect.height() / 2.0); // Need to rotate around centre
|
||||
painter.rotate(m_rotate_angle);
|
||||
painter.translate(-paintRect.width() / 2.0, -paintRect.height() / 2.0); // Undo
|
||||
}
|
||||
|
||||
painter.translate(xtr, ytr);
|
||||
painter.scale(scale, scale);
|
||||
|
||||
|
||||
//Red square for diagnostics
|
||||
//painter.fillRect(QRect(0, 0, m_zintSymbol->vector->width, m_zintSymbol->vector->height), QBrush(QColor(255,0,0,255)));
|
||||
|
||||
QPen p;
|
||||
|
||||
p.setWidth(1);
|
||||
p.setColor(m_fgColor);
|
||||
painter.setPen(p);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
// Plot rectangles
|
||||
rect = m_zintSymbol->vector->rectangles;
|
||||
while (rect) {
|
||||
if (rect->colour == -1) {
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(m_fgColor));
|
||||
} else {
|
||||
switch(rect->colour) {
|
||||
case 1: // Cyan
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::cyan));
|
||||
break;
|
||||
case 2: // Blue
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::blue));
|
||||
break;
|
||||
case 3: // Magenta
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::magenta));
|
||||
break;
|
||||
case 4: // Red
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::red));
|
||||
break;
|
||||
case 5: // Yellow
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::yellow));
|
||||
break;
|
||||
case 6: // Green
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::green));
|
||||
break;
|
||||
case 8: // White
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::white));
|
||||
break;
|
||||
default:
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(Qt::black));
|
||||
break;
|
||||
if (rect) {
|
||||
QBrush brush(Qt::SolidPattern);
|
||||
while (rect) {
|
||||
if (rect->colour == -1) {
|
||||
brush.setColor(m_fgColor);
|
||||
} else {
|
||||
brush.setColor(colourToQtColor(rect->colour));
|
||||
}
|
||||
painter.fillRect(QRectF(rect->x, rect->y, rect->width, rect->height), brush);
|
||||
rect = rect->next;
|
||||
}
|
||||
rect = rect->next;
|
||||
}
|
||||
|
||||
|
||||
// Plot hexagons
|
||||
hex = m_zintSymbol->vector->hexagons;
|
||||
while (hex) {
|
||||
radius = hex->diameter / 2.0;
|
||||
|
||||
QPainterPath pt;
|
||||
pt.moveTo(hex->x, hex->y + (1.0 * radius));
|
||||
pt.lineTo(hex->x + (0.86 * radius), hex->y + (0.5 * radius));
|
||||
pt.lineTo(hex->x + (0.86 * radius), hex->y - (0.5 * radius));
|
||||
pt.lineTo(hex->x, hex->y - (1.0 * radius));
|
||||
pt.lineTo(hex->x - (0.86 * radius), hex->y - (0.5 * radius));
|
||||
pt.lineTo(hex->x - (0.86 * radius), hex->y + (0.5 * radius));
|
||||
pt.lineTo(hex->x, hex->y + (1.0 * radius));
|
||||
painter.fillPath(pt, QBrush(m_fgColor));
|
||||
|
||||
hex = hex->next;
|
||||
if (hex) {
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QBrush brush(m_fgColor);
|
||||
while (hex) {
|
||||
radius = hex->diameter / 2.0;
|
||||
|
||||
QPainterPath pt;
|
||||
pt.moveTo(hex->x, hex->y + (1.0 * radius));
|
||||
pt.lineTo(hex->x + (0.86 * radius), hex->y + (0.5 * radius));
|
||||
pt.lineTo(hex->x + (0.86 * radius), hex->y - (0.5 * radius));
|
||||
pt.lineTo(hex->x, hex->y - (1.0 * radius));
|
||||
pt.lineTo(hex->x - (0.86 * radius), hex->y - (0.5 * radius));
|
||||
pt.lineTo(hex->x - (0.86 * radius), hex->y + (0.5 * radius));
|
||||
pt.lineTo(hex->x, hex->y + (1.0 * radius));
|
||||
painter.fillPath(pt, brush);
|
||||
|
||||
hex = hex->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Plot dots (circles)
|
||||
circle = m_zintSymbol->vector->circles;
|
||||
while (circle) {
|
||||
if (circle->colour) {
|
||||
p.setColor(m_bgColor);
|
||||
p.setWidth(0);
|
||||
painter.setPen(p);
|
||||
painter.setBrush(QBrush(m_bgColor));
|
||||
} else {
|
||||
p.setColor(m_fgColor);
|
||||
p.setWidth(0);
|
||||
painter.setPen(p);
|
||||
painter.setBrush(QBrush(m_fgColor));
|
||||
if (circle) {
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QPen p;
|
||||
while (circle) {
|
||||
if (circle->colour) { // Set means use background colour
|
||||
p.setColor(m_bgColor);
|
||||
p.setWidth(0);
|
||||
painter.setPen(p);
|
||||
painter.setBrush(QBrush(m_bgColor));
|
||||
} else {
|
||||
p.setColor(m_fgColor);
|
||||
p.setWidth(0);
|
||||
painter.setPen(p);
|
||||
painter.setBrush(QBrush(m_fgColor));
|
||||
}
|
||||
painter.drawEllipse(QPointF(circle->x, circle->y), (double) circle->diameter / 2.0, (double) circle->diameter / 2.0);
|
||||
circle = circle->next;
|
||||
}
|
||||
painter.drawEllipse(QPointF(circle->x, circle->y), (double) circle->diameter / 2.0, (double) circle->diameter / 2.0);
|
||||
circle = circle->next;
|
||||
}
|
||||
|
||||
|
||||
// Plot text
|
||||
string = m_zintSymbol->vector->strings;
|
||||
if (string) {
|
||||
painter.setFont(fontLarge);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
bool bold = (m_zintSymbol->output_options & BOLD_TEXT) && (!isExtendable() || (m_zintSymbol->output_options & SMALL_TEXT));
|
||||
QFont font(fontStyle, -1 /*pointSize*/, bold ? QFont::Bold : -1);
|
||||
while (string) {
|
||||
font.setPixelSize(string->fsize);
|
||||
painter.setFont(font);
|
||||
QString content = QString::fromUtf8((const char *) string->text);
|
||||
/* string->y is baseline of font */
|
||||
if (string->halign == 1) { /* Left align */
|
||||
painter.drawText(QPointF(string->x, string->y), content);
|
||||
} else {
|
||||
QFontMetrics fm(painter.fontMetrics());
|
||||
int width = fm.boundingRect(content).width();
|
||||
if (string->halign == 2) { /* Right align */
|
||||
painter.drawText(QPointF(string->x - width, string->y), content);
|
||||
} else { /* Centre align */
|
||||
painter.drawText(QPointF(string->x - (width / 2.0), string->y), content);
|
||||
}
|
||||
}
|
||||
string = string->next;
|
||||
}
|
||||
}
|
||||
QFontMetrics fm(fontLarge);
|
||||
while (string) {
|
||||
QString content = QString::fromUtf8((const char *) string->text, -1);
|
||||
int width = fm.width(content, -1);
|
||||
int height = fm.height();
|
||||
painter.drawText(string->x - (width / 2.0), string->y - height, width, height, Qt::AlignHCenter | Qt::AlignBottom, content);
|
||||
string = string->next;
|
||||
}
|
||||
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,18 +19,16 @@
|
|||
#define BARCODERENDER_H
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
|
||||
#include "zint.h"
|
||||
|
||||
namespace Zint
|
||||
{
|
||||
|
||||
class QZint
|
||||
class QZint : public QObject
|
||||
{
|
||||
private:
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum BorderType{NO_BORDER=0, BIND=2, BOX=4};
|
||||
enum AspectRatioMode{IgnoreAspectRatio=0, KeepAspectRatio=1, CenterBarCode=2};
|
||||
|
||||
public:
|
||||
|
@ -60,6 +58,9 @@ public:
|
|||
float scale() const;
|
||||
void setScale(float scale);
|
||||
|
||||
bool dotty() const;
|
||||
void setDotty(bool botty);
|
||||
|
||||
void setDotSize(float dot_size);
|
||||
|
||||
QColor fgColor() const;
|
||||
|
@ -68,8 +69,10 @@ public:
|
|||
QColor bgColor() const;
|
||||
void setBgColor(const QColor & bgColor);
|
||||
|
||||
BorderType borderType() const;
|
||||
void setBorderType(BorderType border);
|
||||
void setCMYK(bool cmyk);
|
||||
|
||||
int borderType() const;
|
||||
void setBorderType(int borderTypeIndex);
|
||||
|
||||
int borderWidth() const;
|
||||
void setBorderWidth(int boderWidth);
|
||||
|
@ -82,14 +85,30 @@ public:
|
|||
|
||||
void setWhitespace(int whitespace);
|
||||
|
||||
void setHideText(bool hide);
|
||||
void setFontSetting(int fontSettingIndex);
|
||||
|
||||
void setShowText(bool show);
|
||||
|
||||
void setTargetSize(int width, int height);
|
||||
|
||||
void setGSSep(bool gssep);
|
||||
|
||||
int rotateAngle() const;
|
||||
void setRotateAngle(int rotateIndex);
|
||||
|
||||
void setECI(int ECIIndex);
|
||||
|
||||
void setReaderInit(bool reader_init);
|
||||
|
||||
void setDebug(bool debug);
|
||||
|
||||
bool hasHRT(int symbology = 0) const;
|
||||
bool isExtendable(int symbology = 0) const;
|
||||
bool supportsECI(int symbology = 0) const;
|
||||
bool isFixedRatio(int symbology = 0) const;
|
||||
bool isDotty(int symbology = 0) const;
|
||||
bool supportsReaderInit(int symbology = 0) const;
|
||||
|
||||
int getError() const;
|
||||
|
||||
QString error_message() const;
|
||||
|
@ -101,33 +120,43 @@ public:
|
|||
|
||||
void render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode=IgnoreAspectRatio);
|
||||
|
||||
signals:
|
||||
void encoded();
|
||||
|
||||
private:
|
||||
void resetSymbol();
|
||||
void encode();
|
||||
static Qt::GlobalColor colourToQtColor(int colour);
|
||||
|
||||
private:
|
||||
int m_symbol;
|
||||
QString m_text;
|
||||
QString m_primaryMessage;
|
||||
int m_height;
|
||||
BorderType m_border;
|
||||
int m_borderType;
|
||||
int m_borderWidth;
|
||||
int m_fontSetting;
|
||||
int m_option_2;
|
||||
int m_securityLevel;
|
||||
int m_input_mode;
|
||||
QColor m_fgColor;
|
||||
QColor m_bgColor;
|
||||
bool m_cmyk;
|
||||
QString m_lastError;
|
||||
int m_error;
|
||||
int m_whitespace;
|
||||
zint_symbol * m_zintSymbol;
|
||||
float m_scale;
|
||||
int m_option_3;
|
||||
bool m_hidetext;
|
||||
bool m_show_hrt;
|
||||
int m_eci;
|
||||
int m_rotate_angle;
|
||||
bool m_dotty;
|
||||
float m_dot_size;
|
||||
int target_size_horiz;
|
||||
int target_size_vert;
|
||||
bool m_gssep;
|
||||
bool m_reader_init;
|
||||
bool m_debug;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue