From eb674a7ff5fad2f4a76e3b20873c574eb8a6135f Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 9 Dec 2009 14:23:02 +0100 Subject: Optimize drawStaticText() with rectangle destination In order to be feature consistent with drawText(), we have to clip the text whenever the text expands beyond its borders. This is a performance hit, but luckily we can detect the cases where it's necessary before-hand. --- src/gui/painting/qpainter.cpp | 2 +- src/gui/text/qstatictext.cpp | 15 +++++++++++---- src/gui/text/qstatictext_p.h | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 524f243..114492d 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5773,7 +5773,7 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static } bool restoreWhenFinished = false; - if (staticText_d->size.isValid()) { + if (staticText_d->needsClipRect) { save(); setClipRect(QRectF(position, staticText_d->size)); diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 9a0ddca..85d3c81 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -263,7 +263,7 @@ bool QStaticText::isEmpty() const } QStaticTextPrivate::QStaticTextPrivate() - : items(0), itemCount(0), glyphPool(0), positionPool(0) + : items(0), itemCount(0), glyphPool(0), positionPool(0), needsClipRect(false) { ref = 1; } @@ -482,10 +482,17 @@ void QStaticTextPrivate::init() painter.setFont(font); painter.setTransform(matrix); - if (size.isValid()) - painter.drawText(QRectF(QPointF(0, 0), size), text); - else + if (size.isValid()) { + QRectF boundingRect; + painter.drawText(QRectF(QPointF(0, 0), size), 0, text, &boundingRect); + + needsClipRect = boundingRect.width() > size.width() + || boundingRect.height() > size.height(); + + } else { painter.drawText(0, 0, text); + needsClipRect = false; + } } } diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index 4756773..0677920 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -62,7 +62,6 @@ class Q_GUI_EXPORT QStaticTextItem public: QStaticTextItem() : chars(0), numChars(0), fontEngine(0) {} - // ### Use constant length arrays here to minimize memory consumption QFixedPoint *glyphPositions; // 8 bytes per glyph glyph_t *glyphs; // 4 bytes per glyph const QChar *chars; // 2 bytes per glyph @@ -98,6 +97,8 @@ public: int itemCount; // 4 bytes per text glyph_t *glyphPool; // 4 bytes per text QFixedPoint *positionPool; // 4 bytes per text + + char needsClipRect : 1; // 1 byte per text // ================ // 144 bytes per text -- cgit v0.12