diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-12-09 13:23:02 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 13:07:11 (GMT) |
commit | eb674a7ff5fad2f4a76e3b20873c574eb8a6135f (patch) | |
tree | 958d115a90d12410aec322fcb5a55d2cebeb08ba /src/gui | |
parent | a9e08c091c822e65ae8453581c6fee4b94001682 (diff) | |
download | Qt-eb674a7ff5fad2f4a76e3b20873c574eb8a6135f.zip Qt-eb674a7ff5fad2f4a76e3b20873c574eb8a6135f.tar.gz Qt-eb674a7ff5fad2f4a76e3b20873c574eb8a6135f.tar.bz2 |
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.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qstatictext.cpp | 15 | ||||
-rw-r--r-- | 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 |