Improved font positioning in Qt backend

This commit is contained in:
Robin Stuart 2018-06-18 03:55:52 +01:00
parent 656c8132a8
commit ff332335ea

View File

@ -17,6 +17,7 @@
#include "qzint.h" #include "qzint.h"
#include <stdio.h> #include <stdio.h>
#include <QFontMetrics>
namespace Zint { namespace Zint {
static const char* fontstyle = "Arial"; static const char* fontstyle = "Arial";
@ -388,8 +389,12 @@ namespace Zint {
if (string) { if (string) {
painter.setFont(fontLarge); painter.setFont(fontLarge);
} }
QFontMetrics fm(fontLarge);
while (string) { while (string) {
painter.drawText(0.0, string->y, m_zintSymbol->vector->width, 7, Qt::AlignCenter, QString::fromUtf8((const char *) string->text, -1)); 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; string = string->next;
} }