mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Use internal vector format in Qt backend
This commit is contained in:
parent
30fcd7986c
commit
656c8132a8
@ -181,11 +181,13 @@ extern int vin(struct zint_symbol *symbol, const unsigned char source[], const s
|
||||
extern int mailmark(struct zint_symbol *symbol, const unsigned char source[], const size_t in_length); /* Royal Mail 4-state Mailmark */
|
||||
|
||||
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
|
||||
extern int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EPS/EMF/SVG */
|
||||
|
||||
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */
|
||||
extern int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to new vector format */
|
||||
|
||||
//extern int ps_plot(struct zint_symbol *symbol); /* Plot to EPS */
|
||||
//extern int svg_plot(struct zint_symbol *symbol); /* Plot to SVG */
|
||||
extern int emf_plot(struct zint_symbol *symbol); /* Plot to Metafile */
|
||||
//extern int emf_plot(struct zint_symbol *symbol); /* Plot to Metafile */
|
||||
|
||||
void error_tag(char error_string[], int error_number) {
|
||||
|
||||
@ -1251,13 +1253,13 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) {
|
||||
error_number = dump_plot(symbol);
|
||||
} else
|
||||
if (!(strcmp(output, "EPS"))) {
|
||||
error_number = vector_plot(symbol, rotate_angle, OUT_EPS_FILE);
|
||||
error_number = plot_vector(symbol, rotate_angle, OUT_EPS_FILE);
|
||||
} else
|
||||
if (!(strcmp(output, "SVG"))) {
|
||||
error_number = vector_plot(symbol, rotate_angle, OUT_SVG_FILE);
|
||||
error_number = plot_vector(symbol, rotate_angle, OUT_SVG_FILE);
|
||||
} else
|
||||
if (!(strcmp(output, "EMF"))) {
|
||||
error_number = vector_plot(symbol, rotate_angle, OUT_EMF_FILE);
|
||||
error_number = plot_vector(symbol, rotate_angle, OUT_EMF_FILE);
|
||||
} else {
|
||||
strcpy(symbol->errtxt, "225: Unknown output format");
|
||||
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
||||
@ -1298,6 +1300,26 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) {
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Buffer_Vector(struct zint_symbol *symbol, int rotate_angle) {
|
||||
int error_number;
|
||||
|
||||
switch (rotate_angle) {
|
||||
case 0:
|
||||
case 90:
|
||||
case 180:
|
||||
case 270:
|
||||
break;
|
||||
default:
|
||||
strcpy(symbol->errtxt, "228: Invalid rotation angle");
|
||||
error_tag(symbol->errtxt, ZINT_ERROR_INVALID_OPTION);
|
||||
return ZINT_ERROR_INVALID_OPTION;
|
||||
}
|
||||
|
||||
error_number = plot_vector(symbol, rotate_angle, OUT_BUFFER);
|
||||
error_tag(symbol->errtxt, error_number);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
|
||||
int error_number;
|
||||
int first_err;
|
||||
@ -1333,6 +1355,24 @@ int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input,
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Encode_and_Buffer_Vector(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) {
|
||||
int error_number;
|
||||
int first_err;
|
||||
|
||||
error_number = ZBarcode_Encode(symbol, input, length);
|
||||
if (error_number >= 5) {
|
||||
return error_number;
|
||||
}
|
||||
|
||||
first_err = error_number;
|
||||
error_number = ZBarcode_Buffer_Vector(symbol, rotate_angle);
|
||||
if (error_number == 0) {
|
||||
error_number = first_err;
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
|
||||
FILE *file;
|
||||
unsigned char *buffer;
|
||||
@ -1428,6 +1468,24 @@ int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename,
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, char *filename, int rotate_angle) {
|
||||
int error_number;
|
||||
int first_err;
|
||||
|
||||
error_number = ZBarcode_Encode_File(symbol, filename);
|
||||
if (error_number >= 5) {
|
||||
return error_number;
|
||||
}
|
||||
|
||||
first_err = error_number;
|
||||
error_number = ZBarcode_Buffer_Vector(symbol, rotate_angle);
|
||||
if (error_number == 0) {
|
||||
error_number = first_err;
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/*
|
||||
* Rendering support, initially added by Sam Lown.
|
||||
*
|
||||
|
@ -296,7 +296,7 @@ void vector_reduce_rectangles(struct zint_symbol *symbol) {
|
||||
return;
|
||||
}
|
||||
|
||||
int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
int error_number;
|
||||
struct zint_vector *vector;
|
||||
struct zint_vector_rect *rectangle, *rect, *last_rectangle = NULL;
|
||||
@ -455,8 +455,8 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
}
|
||||
}
|
||||
|
||||
vector->width = ceil(symbol->width + xoffset + xoffset);
|
||||
vector->height = ceil(symbol->height + text_offset + yoffset + yoffset);
|
||||
vector->width = ceil(symbol->width + (2.0 * xoffset));
|
||||
vector->height = ceil(symbol->height + text_offset + (2.0 * yoffset));
|
||||
|
||||
large_bar_height = (symbol->height - preset_height) / large_bar_count;
|
||||
|
||||
@ -527,21 +527,21 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
|
||||
// Plot Maxicode symbols
|
||||
if (symbol->symbology == BARCODE_MAXICODE) {
|
||||
vector->width = 37.0 + xoffset;
|
||||
vector->height = 36.0 + yoffset;
|
||||
vector->width = 37.0 + (2.0 * xoffset);
|
||||
vector->height = 36.0 + (2.0 * yoffset);
|
||||
|
||||
// Bullseye
|
||||
struct zint_vector_circle *circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 10.85, 0);
|
||||
struct zint_vector_circle *circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 10.85, 0);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 8.97, 1);
|
||||
circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 8.97, 1);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 7.10, 0);
|
||||
circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 7.10, 0);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 5.22, 1);
|
||||
circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 5.22, 1);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 3.31, 0);
|
||||
circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 3.31, 0);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
circle = vector_plot_create_circle(17.88 + (xoffset / 2.0), 17.8 + (yoffset / 2.0), 1.43, 1);
|
||||
circle = vector_plot_create_circle(17.88 + xoffset, 17.8 + yoffset, 1.43, 1);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
|
||||
/* Hexagons */
|
||||
@ -549,7 +549,8 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
for (i = 0; i < symbol->width; i++) {
|
||||
if (module_is_set(symbol, r, i)) {
|
||||
//struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 0.88) + ((r & 1) ? 1.76 : 1.32)), ((r * 0.76) + 0.76), symbol->dot_size);
|
||||
struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 1.23) + 0.615 + ((r & 1) ? 0.615 : 0.0)), ((r * 1.067) + 0.715), symbol->dot_size);
|
||||
struct zint_vector_hexagon *hexagon = vector_plot_create_hexagon(((i * 1.23) + 0.615 + ((r & 1) ? 0.615 : 0.0)) + xoffset,
|
||||
((r * 1.067) + 0.715) + yoffset, symbol->dot_size);
|
||||
vector_plot_add_hexagon(symbol, hexagon, &last_hexagon);
|
||||
}
|
||||
}
|
||||
@ -561,7 +562,7 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
for (r = 0; r < symbol->rows; r++) {
|
||||
for (i = 0; i < symbol->width; i++) {
|
||||
if (module_is_set(symbol, r, i)) {
|
||||
struct zint_vector_circle *circle = vector_plot_create_circle(i + 0.5 + (xoffset / 2.0), r + 0.5 + (yoffset / 2.0), 1.0, 0);
|
||||
struct zint_vector_circle *circle = vector_plot_create_circle(i + 0.5 + xoffset, r + 0.5 + yoffset, 1.0, 0);
|
||||
vector_plot_add_circle(symbol, circle, &last_circle);
|
||||
}
|
||||
}
|
||||
@ -817,13 +818,15 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
}
|
||||
}
|
||||
if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) {
|
||||
rectangle = vector_plot_create_rect(0.0, 0.0, symbol->width + xoffset + xoffset, symbol->border_width);
|
||||
// Top
|
||||
rectangle = vector_plot_create_rect(0.0, 0.0, vector->width, symbol->border_width);
|
||||
if (symbol->symbology == BARCODE_CODABLOCKF) {
|
||||
rectangle->x = xoffset;
|
||||
rectangle->width -= (2.0 * xoffset);
|
||||
}
|
||||
vector_plot_add_rect(symbol, rectangle, &last_rectangle);
|
||||
rectangle = vector_plot_create_rect(0.0, symbol->height + symbol->border_width, symbol->width + xoffset + xoffset, symbol->border_width);
|
||||
// Bottom
|
||||
rectangle = vector_plot_create_rect(0.0, vector->height - symbol->border_width, vector->width, symbol->border_width);
|
||||
if (symbol->symbology == BARCODE_CODABLOCKF) {
|
||||
rectangle->x = xoffset;
|
||||
rectangle->width -= (2.0 * xoffset);
|
||||
@ -831,10 +834,11 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
vector_plot_add_rect(symbol, rectangle, &last_rectangle);
|
||||
}
|
||||
if (symbol->output_options & BARCODE_BOX) {
|
||||
/* side bars */
|
||||
rectangle = vector_plot_create_rect(0.0, 0.0, symbol->border_width, (symbol->height + (2 * symbol->border_width)));
|
||||
// Left
|
||||
rectangle = vector_plot_create_rect(0.0, 0.0, symbol->border_width, vector->height);
|
||||
vector_plot_add_rect(symbol, rectangle, &last_rectangle);
|
||||
rectangle = vector_plot_create_rect(symbol->width + xoffset + xoffset - symbol->border_width, 0.0, symbol->border_width, (symbol->height + (2 * symbol->border_width)));
|
||||
// Right
|
||||
rectangle = vector_plot_create_rect(vector->width - symbol->border_width, 0.0, symbol->border_width, vector->height);
|
||||
vector_plot_add_rect(symbol, rectangle, &last_rectangle);
|
||||
}
|
||||
|
||||
@ -852,10 +856,9 @@ int vector_plot(struct zint_symbol *symbol, int rotate_angle, int file_type) {
|
||||
case OUT_EMF_FILE:
|
||||
error_number = emf_plot(symbol);
|
||||
break;
|
||||
/* case OUT_BUFFER: No more work needed */
|
||||
}
|
||||
|
||||
vector_free(symbol);
|
||||
|
||||
return error_number;
|
||||
|
||||
}
|
||||
|
@ -311,8 +311,11 @@ extern "C" {
|
||||
ZINT_EXTERN int ZBarcode_Render(struct zint_symbol *symbol, const float width, const float height);
|
||||
|
||||
ZINT_EXTERN int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle);
|
||||
ZINT_EXTERN int ZBarcode_Buffer_Vector(struct zint_symbol *symbol, int rotate_angle);
|
||||
ZINT_EXTERN int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
||||
ZINT_EXTERN int ZBarcode_Encode_and_Buffer_Vector(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle);
|
||||
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
||||
ZINT_EXTERN int ZBarcode_Encode_File_and_Buffer_Vector(struct zint_symbol *symbol, char *filename, int rotate_angle);
|
||||
|
||||
ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
|
||||
ZINT_EXTERN int ZBarcode_Version();
|
||||
|
@ -19,9 +19,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Zint {
|
||||
|
||||
static const qreal maxi_diagonal = 11;
|
||||
static const qreal maxi_width = 1.73205807568877 * maxi_diagonal / 2;
|
||||
static const char* fontstyle = "Arial";
|
||||
static const int fontPixelSizeSmall = 6;
|
||||
static const int fontPixelSizeLarge = 8;
|
||||
@ -81,12 +78,9 @@ namespace Zint {
|
||||
QByteArray bstr = m_text.toUtf8();
|
||||
QByteArray pstr = m_primaryMessage.left(99).toLatin1();
|
||||
strcpy(m_zintSymbol->primary, pstr.data());
|
||||
m_error = ZBarcode_Encode(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length());
|
||||
m_error = ZBarcode_Encode_and_Buffer_Vector(m_zintSymbol, (unsigned char*) bstr.data(), bstr.length(), 0);
|
||||
m_lastError = m_zintSymbol->errtxt;
|
||||
|
||||
if (m_zintSymbol->symbology == BARCODE_MAXICODE)
|
||||
m_zintSymbol->height = 33;
|
||||
|
||||
switch (m_zintSymbol->output_options) {
|
||||
case 0: m_border = NO_BORDER;
|
||||
break;
|
||||
@ -132,11 +126,6 @@ namespace Zint {
|
||||
m_primaryMessage = primaryMessage;
|
||||
}
|
||||
|
||||
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) {
|
||||
m_height = height;
|
||||
}
|
||||
@ -149,11 +138,6 @@ namespace Zint {
|
||||
m_option_3 = option;
|
||||
}
|
||||
|
||||
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() const {
|
||||
return m_scale;
|
||||
}
|
||||
@ -287,30 +271,16 @@ namespace Zint {
|
||||
}
|
||||
}
|
||||
|
||||
int QZint::module_set(int y_coord, int x_coord) const {
|
||||
int x_char, x_sub, result;
|
||||
|
||||
x_char = x_coord / 7;
|
||||
x_sub = x_coord % 7;
|
||||
result = 0;
|
||||
|
||||
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) {
|
||||
bool textdone;
|
||||
int comp_offset = 0;
|
||||
int xoffset = m_whitespace;
|
||||
int main_width = 0, addon_text_height = 0;
|
||||
int yoffset = 0;
|
||||
struct zint_vector_rect *rect;
|
||||
struct zint_vector_hexagon *hex;
|
||||
struct zint_vector_circle *circle;
|
||||
struct zint_vector_string *string;
|
||||
qreal ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy;
|
||||
qreal radius;
|
||||
|
||||
encode();
|
||||
|
||||
QString caption = QString::fromUtf8((const char *) m_zintSymbol->text, -1);
|
||||
QFont fontSmall(fontstyle);
|
||||
fontSmall.setPixelSize(fontPixelSizeSmall);
|
||||
QFont fontLarge(fontstyle);
|
||||
@ -329,357 +299,100 @@ namespace Zint {
|
||||
|
||||
qreal xtr = paintRect.x();
|
||||
qreal ytr = paintRect.y();
|
||||
qreal scale;
|
||||
|
||||
int zrow_height = m_zintSymbol->height;
|
||||
int zrows = 0;
|
||||
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) {
|
||||
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
|
||||
m_zintSymbol->height -= zrow_height;
|
||||
|
||||
|
||||
qreal gwidth = m_zintSymbol->width;
|
||||
qreal gheight = m_zintSymbol->height;
|
||||
if (m_zintSymbol->symbology == BARCODE_MAXICODE) {
|
||||
gwidth = (33.0 * maxi_width);
|
||||
gheight = (32.0 * maxi_width);
|
||||
}
|
||||
|
||||
if (m_zintSymbol->output_options & BARCODE_DOTTY_MODE) {
|
||||
gwidth += 2.0;
|
||||
gheight += 2.0;
|
||||
}
|
||||
|
||||
qreal xsf = 1;
|
||||
qreal ysf = 1;
|
||||
qreal textoffset = 0;
|
||||
|
||||
gwidth += ((m_border == BOX) ? m_borderWidth * 2 : 0);
|
||||
gheight += ((m_border != NO_BORDER) ? m_borderWidth * 2 : 0);
|
||||
if (QString((const char*) m_zintSymbol->text).isEmpty() == false) {
|
||||
textoffset = 9;
|
||||
gheight += textoffset;
|
||||
} else {
|
||||
textoffset = 0;
|
||||
}
|
||||
gwidth += m_zintSymbol->whitespace_width * 2;
|
||||
qreal gwidth = m_zintSymbol->vector->width;
|
||||
qreal gheight = m_zintSymbol->vector->height;
|
||||
|
||||
if (paintRect.width() / gwidth < paintRect.height() / gheight) {
|
||||
ysf = xsf = (qreal) paintRect.width() / gwidth;
|
||||
ytr += (qreal) (paintRect.height() - gheight * ysf) / 2;
|
||||
scale = (qreal) paintRect.width() / gwidth;
|
||||
ytr += (qreal) (paintRect.height() - gheight * scale) / 2;
|
||||
} else {
|
||||
ysf = xsf = (qreal) paintRect.height() / gheight;
|
||||
xtr += (qreal) (paintRect.width() - gwidth * xsf) / 2;
|
||||
scale = (qreal) paintRect.height() / gheight;
|
||||
xtr += (qreal) (paintRect.width() - gwidth * scale) / 2;
|
||||
}
|
||||
|
||||
painter.setBackground(QBrush(m_bgColor));
|
||||
painter.fillRect(paintRect, QBrush(m_bgColor));
|
||||
|
||||
painter.translate(xtr, ytr);
|
||||
painter.scale(xsf, ysf);
|
||||
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.setColor(m_fgColor);
|
||||
p.setWidth(m_borderWidth);
|
||||
painter.setPen(p);
|
||||
|
||||
if (m_zintSymbol->symbology != BARCODE_MAXICODE) {
|
||||
/* Draw boundary bars or boxes around the symbol */
|
||||
switch (m_border) {
|
||||
case BOX:
|
||||
painter.fillRect(0, m_borderWidth, m_borderWidth, m_zintSymbol->height, QBrush(m_fgColor));
|
||||
painter.fillRect(m_zintSymbol->width + m_zintSymbol->whitespace_width + m_zintSymbol->whitespace_width + m_borderWidth, m_borderWidth, m_borderWidth, m_zintSymbol->height, QBrush(m_fgColor));
|
||||
painter.fillRect(0, 0, m_zintSymbol->width + m_zintSymbol->whitespace_width + m_zintSymbol->whitespace_width + m_borderWidth + m_borderWidth, m_borderWidth, QBrush(m_fgColor));
|
||||
painter.fillRect(0, m_zintSymbol->height + m_borderWidth, m_zintSymbol->width + m_zintSymbol->whitespace_width + m_zintSymbol->whitespace_width + m_borderWidth + m_borderWidth, m_borderWidth, QBrush(m_fgColor));
|
||||
painter.translate(m_borderWidth + m_zintSymbol->whitespace_width, m_borderWidth);
|
||||
yoffset = m_borderWidth;
|
||||
break;
|
||||
case BIND:
|
||||
if (m_zintSymbol->symbology != BARCODE_CODABLOCKF) {
|
||||
painter.fillRect(0, 0, m_zintSymbol->width + m_zintSymbol->whitespace_width + m_zintSymbol->whitespace_width, m_borderWidth, QBrush(m_fgColor));
|
||||
painter.fillRect(0, m_zintSymbol->height, m_zintSymbol->width + m_zintSymbol->whitespace_width + m_zintSymbol->whitespace_width, m_borderWidth, QBrush(m_fgColor));
|
||||
} else {
|
||||
painter.fillRect(m_zintSymbol->whitespace_width, 0, m_zintSymbol->width, m_borderWidth, QBrush(m_fgColor));
|
||||
painter.fillRect(m_zintSymbol->whitespace_width, m_zintSymbol->height, m_zintSymbol->width, m_borderWidth, QBrush(m_fgColor));
|
||||
}
|
||||
painter.translate(m_zintSymbol->whitespace_width, m_borderWidth);
|
||||
yoffset = m_borderWidth;
|
||||
break;
|
||||
|
||||
default:
|
||||
painter.translate(m_zintSymbol->whitespace_width, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (!(module_set(m_zintSymbol->rows - 1, comp_offset))) {
|
||||
comp_offset++;
|
||||
}
|
||||
xoffset = comp_offset;
|
||||
|
||||
/* Set up some values for displaying EAN and UPC symbols correctly */
|
||||
main_width = m_zintSymbol->width;
|
||||
if ((((m_zintSymbol->symbology == BARCODE_EANX) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_EANX_CC))
|
||||
|| (m_zintSymbol->symbology == BARCODE_ISBNX)) {
|
||||
switch (caption.size()) {
|
||||
case 13: /* EAN 13 */
|
||||
case 16:
|
||||
case 19:
|
||||
if (m_zintSymbol->whitespace_width == 0) {
|
||||
m_zintSymbol->whitespace_width = 10;
|
||||
}
|
||||
main_width = 96 + comp_offset;
|
||||
break;
|
||||
default:
|
||||
main_width = 68 + comp_offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (((m_zintSymbol->symbology == BARCODE_UPCA) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) {
|
||||
if (m_zintSymbol->whitespace_width == 0) {
|
||||
m_zintSymbol->whitespace_width = 10;
|
||||
}
|
||||
main_width = 96 + comp_offset;
|
||||
}
|
||||
|
||||
if (((m_zintSymbol->symbology == BARCODE_UPCE) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) {
|
||||
if (m_zintSymbol->whitespace_width == 0) {
|
||||
m_zintSymbol->whitespace_width = 10;
|
||||
}
|
||||
main_width = 51 + comp_offset;
|
||||
}
|
||||
|
||||
p.setWidth(1);
|
||||
painter.setPen(p);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
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)) {
|
||||
qreal col = (qreal) c * (maxi_width + 1)+(r % 2)*((maxi_width + 1) / 2);
|
||||
qreal row = (qreal) r * (maxi_width + 1)*0.868;
|
||||
QPainterPath pt;
|
||||
pt.moveTo(col + maxi_width / 2, row);
|
||||
pt.lineTo(col + maxi_width, row + maxi_diagonal / 4);
|
||||
pt.lineTo(col + maxi_width, row + (maxi_diagonal - maxi_diagonal / 4));
|
||||
pt.lineTo(col + maxi_width / 2, row + maxi_diagonal);
|
||||
pt.lineTo(col, row + (maxi_diagonal - maxi_diagonal / 4));
|
||||
pt.lineTo(col, row + maxi_diagonal / 4);
|
||||
pt.lineTo(col + maxi_width / 2, row);
|
||||
painter.fillPath(pt, QBrush(m_fgColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
p.setWidth(maxi_width);
|
||||
painter.setPen(p);
|
||||
const qreal w = maxi_width + 1;
|
||||
painter.drawEllipse(QPointF(14.5 * w, 16.5 * w * 0.868), w, w);
|
||||
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((c + 1.0), (r + 1.0)), m_dot_size / 2.0, m_dot_size / 2.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Draw all other symbols with rectangles */
|
||||
int y = 0;
|
||||
for (int row = 0; row < m_zintSymbol->rows; row++) {
|
||||
for (int i = 0; i < m_zintSymbol->width; 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++)
|
||||
if (ed != module_set(row, j))
|
||||
break;
|
||||
QColor color;
|
||||
color = m_fgColor;
|
||||
|
||||
if (!((i > main_width) && (row == m_zintSymbol->rows - 1))) {
|
||||
painter.fillRect(i, y, linewidth, m_zintSymbol->row_height[row], QBrush(color));
|
||||
} else {
|
||||
painter.fillRect(i, y + 8, linewidth, m_zintSymbol->row_height[row] - 3, QBrush(color));
|
||||
addon_text_height = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Add row binding */
|
||||
if (((m_zintSymbol->symbology == BARCODE_CODE16K)
|
||||
|| (m_zintSymbol->symbology == BARCODE_CODE49)) && (row != 0)) {
|
||||
painter.fillRect(0, y - 1, m_zintSymbol->width, 2, QBrush(m_fgColor));
|
||||
}
|
||||
if ((m_zintSymbol->symbology == BARCODE_CODABLOCKF) && (row != 0)) {
|
||||
painter.fillRect(11, y - 1, m_zintSymbol->width - 25, 2, QBrush(m_fgColor));
|
||||
}
|
||||
y += m_zintSymbol->row_height[row];
|
||||
}
|
||||
// Plot rectangles
|
||||
rect = m_zintSymbol->vector->rectangles;
|
||||
while (rect) {
|
||||
painter.fillRect(rect->x, rect->y, rect->width, rect->height, QBrush(m_fgColor));
|
||||
rect = rect->next;
|
||||
}
|
||||
|
||||
textdone = false;
|
||||
// Plot hexagons
|
||||
hex = m_zintSymbol->vector->hexagons;
|
||||
while (hex) {
|
||||
radius = hex->diameter / 2.0;
|
||||
|
||||
if (m_hidetext == false) {
|
||||
painter.setFont(fontSmall);
|
||||
if (((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) ||
|
||||
(m_zintSymbol->symbology == BARCODE_ISBNX)) {
|
||||
/* Add bridge and format text for EAN */
|
||||
switch (caption.size()) {
|
||||
case 8:
|
||||
case 11:
|
||||
case 14:
|
||||
painter.fillRect(0 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(2 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(32 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(34 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(64 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(66 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
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));
|
||||
};
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
break;
|
||||
case 13:
|
||||
case 16:
|
||||
case 19:
|
||||
painter.fillRect(0 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(2 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(46 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(48 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(92 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(94 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.setFont(fontLarge);
|
||||
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));
|
||||
};
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
break;
|
||||
}
|
||||
if (textdone == false) {
|
||||
painter.setFont(fontLarge);
|
||||
painter.drawText(0, m_zintSymbol->height, m_zintSymbol->width, 9, Qt::AlignCenter, caption);
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
}
|
||||
}
|
||||
ay = hex->y + (1.0 * radius);
|
||||
by = hex->y + (0.5 * radius);
|
||||
cy = hex->y - (0.5 * radius);
|
||||
dy = hex->y - (1.0 * radius);
|
||||
ey = hex->y - (0.5 * radius);
|
||||
fy = hex->y + (0.5 * radius);
|
||||
ax = hex->x;
|
||||
bx = hex->x + (0.86 * radius);
|
||||
cx = hex->x + (0.86 * radius);
|
||||
dx = hex->x;
|
||||
ex = hex->x - (0.86 * radius);
|
||||
fx = hex->x - (0.86 * radius);
|
||||
|
||||
if ((m_zintSymbol->symbology == BARCODE_UPCA) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) {
|
||||
/* Add bridge and format text for UPC-A */
|
||||
int block_width;
|
||||
bool latch = true;
|
||||
QPainterPath pt;
|
||||
pt.moveTo(ax, ay);
|
||||
pt.lineTo(bx, by);
|
||||
pt.lineTo(cx, cy);
|
||||
pt.lineTo(dx, dy);
|
||||
pt.lineTo(ex, ey);
|
||||
pt.lineTo(fx, fy);
|
||||
pt.lineTo(ax, ay);
|
||||
painter.fillPath(pt, QBrush(m_fgColor));
|
||||
|
||||
int j = 0 + comp_offset;
|
||||
do {
|
||||
block_width = 0;
|
||||
do {
|
||||
block_width++;
|
||||
} while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j));
|
||||
if (latch == true) {
|
||||
/* a bar */
|
||||
painter.fillRect(j + xoffset - comp_offset, m_zintSymbol->height, block_width, 5, QBrush(m_fgColor));
|
||||
latch = false;
|
||||
} else {
|
||||
/* a space */
|
||||
latch = true;
|
||||
}
|
||||
j += block_width;
|
||||
} while (j < 11 + comp_offset);
|
||||
painter.fillRect(46 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(48 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
latch = true;
|
||||
j = 85 + comp_offset;
|
||||
do {
|
||||
block_width = 0;
|
||||
do {
|
||||
block_width++;
|
||||
} while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j));
|
||||
if (latch == true) {
|
||||
/* a bar */
|
||||
painter.fillRect(j + xoffset - comp_offset, m_zintSymbol->height, block_width, 5, QBrush(m_fgColor));
|
||||
latch = false;
|
||||
} else {
|
||||
/* a space */
|
||||
latch = true;
|
||||
}
|
||||
j += block_width;
|
||||
} while (j < 96 + comp_offset);
|
||||
painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7, Qt::AlignCenter, caption.mid(0, 1));
|
||||
painter.drawText(96 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7, Qt::AlignCenter, caption.mid(11, 1));
|
||||
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));
|
||||
};
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
}
|
||||
|
||||
if ((m_zintSymbol->symbology == BARCODE_UPCE) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) {
|
||||
/* Add bridge and format text for UPC-E */
|
||||
painter.fillRect(0 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(2 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(46 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(48 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.fillRect(50 + xoffset, m_zintSymbol->height, 1, 5, QBrush(m_fgColor));
|
||||
painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7, Qt::AlignCenter, caption.mid(0, 1));
|
||||
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));
|
||||
};
|
||||
painter.setFont(fontSmall);
|
||||
textdone = true;
|
||||
}
|
||||
} /* if (m_hidetext == false) */
|
||||
|
||||
if ((m_hidetext == false) && (textdone == false)) {
|
||||
/* Add text to any other symbol */
|
||||
painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7, Qt::AlignCenter, caption);
|
||||
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));
|
||||
}
|
||||
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);
|
||||
}
|
||||
while (string) {
|
||||
painter.drawText(0.0, string->y, m_zintSymbol->vector->width, 7, Qt::AlignCenter, QString::fromUtf8((const char *) string->text, -1));
|
||||
string = string->next;
|
||||
}
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user