Correct large resolution font issue

This commit is contained in:
hooper114 2009-07-19 11:10:59 +00:00
parent af0ab57606
commit 0a7b0c80e4

View File

@ -16,13 +16,15 @@
#include "qzint.h" #include "qzint.h"
#include <stdio.h> #include <stdio.h>
#define SSET "0123456789ABCDEF"
namespace Zint namespace Zint
{ {
static const qreal maxi_diagonal=11; static const qreal maxi_diagonal=11;
static const qreal maxi_width=1.73205807568877*maxi_diagonal/2; static const qreal maxi_width=1.73205807568877*maxi_diagonal/2;
static const char* fontstyle="Ariel";
static const int fontPixelSizeSmall=6;
static const int fontPixelSizeLarge=8;
QZint::QZint() QZint::QZint()
{ {
@ -283,16 +285,20 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0; int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0;
int yoffset = 0; int yoffset = 0;
QString caption = (const char*)m_zintSymbol->text; QString caption = (const char*)m_zintSymbol->text;
QFont fontSmall(fontstyle);
fontSmall.setPixelSize(fontPixelSizeSmall);
QFont fontLarge(fontstyle);
fontLarge.setPixelSize(fontPixelSizeLarge);
if (m_lastError.length()) if (m_lastError.length())
{ {
painter.setFont(fontLarge);
painter.drawText(paintRect,Qt::AlignCenter,m_lastError); painter.drawText(paintRect,Qt::AlignCenter,m_lastError);
return; return;
} }
painter.save(); painter.save();
painter.setClipRect(paintRect,Qt::IntersectClip); painter.setClipRect(paintRect,Qt::IntersectClip);
painter.setRenderHint(QPainter::Antialiasing);
qreal xtr=paintRect.x(); qreal xtr=paintRect.x();
qreal ytr=paintRect.y(); qreal ytr=paintRect.y();
@ -538,7 +544,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
textdone = false; textdone = false;
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
if(((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) || if(((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) ||
(m_zintSymbol->symbology == BARCODE_ISBNX)) { (m_zintSymbol->symbology == BARCODE_ISBNX)) {
/* Add bridge and format text for EAN */ /* Add bridge and format text for EAN */
@ -552,12 +558,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.fillRect(34 + 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(64 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
painter.fillRect(66 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(66 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
painter.setFont(QFont("Ariel", 6)); painter.setFont(fontLarge);
painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 29, 9,Qt::AlignCenter, caption.mid(0,4)); 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)); 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() == 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() == 14) { /* EAN-5 */ painter.drawText(76 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
textdone = true; textdone = true;
break; break;
case 13: case 13:
@ -569,20 +575,20 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.fillRect(48 + 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(92 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
painter.fillRect(94 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(94 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor));
painter.setFont(QFont("Ariel", 6)); painter.setFont(fontLarge);
painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 9,Qt::AlignCenter, caption.mid(0,1)); 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(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)); 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() == 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() == 19) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(14,5)); };
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
textdone = true; textdone = true;
break; break;
} }
if(textdone == false) { if(textdone == false) {
painter.setFont(QFont("Ariel", 6)); painter.setFont(fontLarge);
painter.drawText(0, m_zintSymbol->height, m_zintSymbol->width, 9,Qt::AlignCenter, caption); painter.drawText(0, m_zintSymbol->height, m_zintSymbol->width, 9,Qt::AlignCenter, caption);
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
textdone = true; textdone = true;
} }
} }
@ -629,12 +635,12 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
} while (j < 96 + comp_offset); } while (j < 96 + comp_offset);
painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(0,1)); painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(0,1));
painter.drawText(96 + xoffset, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(11,1)); painter.drawText(96 + xoffset, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(11,1));
painter.setFont(QFont("Ariel", 6)); painter.setFont(fontLarge);
painter.drawText(11 + xoffset, m_zintSymbol->height + yoffset, 35, 9,Qt::AlignCenter, caption.mid(1,5)); 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)); 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() == 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() == 18) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(13,5)); };
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
textdone = true; textdone = true;
} }
@ -647,11 +653,11 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
painter.fillRect(50 + 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, 7, 7,Qt::AlignCenter, caption.mid(0,1)); painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(0,1));
painter.drawText(51 + xoffset, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(7,1)); painter.drawText(51 + xoffset, m_zintSymbol->height + yoffset, 7, 7,Qt::AlignCenter, caption.mid(7,1));
painter.setFont(QFont("Ariel", 6)); painter.setFont(fontLarge);
painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(1,6)); 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() == 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() == 14) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); };
painter.setFont(QFont("Ariel", 4)); painter.setFont(fontSmall);
textdone = true; textdone = true;
} }