From 3ed1b5692f698abc08babe623ea201e0adcb2d41 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Tue, 19 Jun 2018 03:56:44 +0100 Subject: [PATCH] Adjust vector border to place bottom border above text --- backend/vector.c | 6 +++--- backend_qt/qzint.cpp | 43 ++++++++++++++++--------------------------- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/backend/vector.c b/backend/vector.c index 2795f4b8..e39a18f5 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -826,7 +826,7 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) { } vector_plot_add_rect(symbol, rectangle, &last_rectangle); // Bottom - rectangle = vector_plot_create_rect(0.0, vector->height - symbol->border_width, vector->width, symbol->border_width); + rectangle = vector_plot_create_rect(0.0, vector->height - symbol->border_width - text_offset, vector->width, symbol->border_width); if (symbol->symbology == BARCODE_CODABLOCKF) { rectangle->x = xoffset; rectangle->width -= (2.0 * xoffset); @@ -835,10 +835,10 @@ int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) { } if (symbol->output_options & BARCODE_BOX) { // Left - rectangle = vector_plot_create_rect(0.0, 0.0, symbol->border_width, vector->height); + rectangle = vector_plot_create_rect(0.0, 0.0, symbol->border_width, vector->height - text_offset); vector_plot_add_rect(symbol, rectangle, &last_rectangle); // Right - rectangle = vector_plot_create_rect(vector->width - symbol->border_width, 0.0, symbol->border_width, vector->height); + rectangle = vector_plot_create_rect(vector->width - symbol->border_width, 0.0, symbol->border_width, vector->height - text_offset); vector_plot_add_rect(symbol, rectangle, &last_rectangle); } diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 4da613ce..f56284a2 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -17,12 +17,13 @@ #include "qzint.h" #include +#include #include namespace Zint { static const char* fontstyle = "Arial"; - static const int fontPixelSizeSmall = 6; - static const int fontPixelSizeLarge = 8; + static const int fontPixelSizeSmall = 8; + static const int fontPixelSizeLarge = 12; QZint::QZint() { m_symbol = BARCODE_CODE128; @@ -277,7 +278,6 @@ namespace Zint { 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(); @@ -306,12 +306,13 @@ namespace Zint { qreal gheight = m_zintSymbol->vector->height; if (paintRect.width() / gwidth < paintRect.height() / gheight) { - scale = (qreal) paintRect.width() / gwidth; - ytr += (qreal) (paintRect.height() - gheight * scale) / 2; + scale = (qreal) floor(paintRect.width() / gwidth); } else { - scale = (qreal) paintRect.height() / gheight; - xtr += (qreal) (paintRect.width() - gwidth * scale) / 2; + scale = (qreal) floor(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)); @@ -325,6 +326,7 @@ namespace Zint { QPen p; p.setWidth(1); + p.setColor(m_fgColor); painter.setPen(p); painter.setRenderHint(QPainter::Antialiasing); @@ -340,27 +342,14 @@ namespace Zint { while (hex) { radius = hex->diameter / 2.0; - 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); - 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); + 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;