mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Halo drawing performance improvement
This commit is contained in:
parent
3dfcf35e53
commit
76fb129651
@ -128,9 +128,10 @@ void TextPointItem::paint(QPainter *painter) const
|
||||
//painter->drawRect(_boundingRect);
|
||||
|
||||
QRectF textRect;
|
||||
bool hasHalo = halo().color().isValid() && halo().width() > 0;
|
||||
|
||||
if (!_icon.isNull()) {
|
||||
textRect = (_anchor != Text::Center)
|
||||
textRect = (_anchor != Text::Center || hasHalo)
|
||||
? computeTextRect(true) : _boundingRect;
|
||||
#ifdef ENABLE_HIDPI
|
||||
painter->drawImage(_pos - QPointF(_icon.width()
|
||||
@ -141,32 +142,33 @@ void TextPointItem::paint(QPainter *painter) const
|
||||
_icon.height() / 2), _icon);
|
||||
#endif // ENABLE_HIDPI
|
||||
} else
|
||||
textRect = _boundingRect;
|
||||
textRect = hasHalo ? computeTextRect(true) : _boundingRect;
|
||||
|
||||
|
||||
if (hasHalo) {
|
||||
QRect ir(textRect.toRect());
|
||||
QImage img(ir.size(), QImage::Format_ARGB32_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
QPainter ip(&img);
|
||||
ip.setPen(halo().color());
|
||||
ip.setFont(font());
|
||||
ip.drawText(img.rect(), FLAGS, text());
|
||||
|
||||
painter->drawImage(ir.x() - 1, ir.y() - 1, img);
|
||||
painter->drawImage(ir.x() + 1, ir.y() + 1, img);
|
||||
painter->drawImage(ir.x() - 1, ir.y() + 1, img);
|
||||
painter->drawImage(ir.x() + 1, ir.y() - 1, img);
|
||||
painter->drawImage(ir.x(), ir.y() - 1, img);
|
||||
painter->drawImage(ir.x(), ir.y() + 1, img);
|
||||
painter->drawImage(ir.x() - 1, ir.y(), img);
|
||||
painter->drawImage(ir.x() + 1, ir.y(), img);
|
||||
|
||||
painter->setFont(font());
|
||||
if (halo().color().isValid() && halo().width() > 0) {
|
||||
QPointF center(textRect.center());
|
||||
painter->setPen(halo().color());
|
||||
|
||||
textRect.moveCenter(QPointF(center.x() - 1, center.y() - 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x() + 1, center.y() + 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x() - 1, center.y() + 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x() + 1, center.y() - 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x(), center.y() - 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x(), center.y() + 1));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x() - 1, center.y()));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
textRect.moveCenter(QPointF(center.x() + 1, center.y()));
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
|
||||
textRect.moveCenter(center);
|
||||
}
|
||||
painter->setPen(pen());
|
||||
painter->drawText(ir, FLAGS, text());
|
||||
} else {
|
||||
painter->setFont(font());
|
||||
painter->setPen(pen());
|
||||
painter->drawText(textRect, FLAGS, text());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user