diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-04 09:17:42 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 12:48:38 (GMT) |
commit | 9e40703796bf2a2d9b1dbb4ad09c22f9d036c985 (patch) | |
tree | 3ac4af2bbbc6951e14743e257d830ac3adcf4116 | |
parent | e459416e357c86f32146de4e7dce220153a132b2 (diff) | |
download | Qt-9e40703796bf2a2d9b1dbb4ad09c22f9d036c985.zip Qt-9e40703796bf2a2d9b1dbb4ad09c22f9d036c985.tar.gz Qt-9e40703796bf2a2d9b1dbb4ad09c22f9d036c985.tar.bz2 |
Space optimization in QStaticText
The engine.layoutData's glyph count is the number allocated, which may
be larger than the actual number of glyphs. To minimize the space needed
we base allocation on "used" which contains the number of glyphs
actually used to represent the text.
-rw-r--r-- | src/gui/painting/qpainter.cpp | 8 | ||||
-rw-r--r-- | src/gui/text/qstatictext.cpp | 15 |
2 files changed, 9 insertions, 14 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 435ad9b..6bb8acd 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5729,12 +5729,8 @@ void QPainter::drawStaticText(const QPointF &position, const QStaticText &static QFixed x = QFixed::fromReal(position.x()); for (int i=0; i<staticText_d->items.size();++i) { QTextItemInt *gf = staticText_d->items.at(i); - if (gf->num_chars == 0) { - x += gf->width; - continue; - } - - drawTextItem(QPointF(x.toReal(), position.y()), *gf); + if (gf->num_chars != 0) + drawTextItem(QPointF(x.toReal(), position.y()), *gf); x += gf->width; } } diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 90fde9d..e9fd9c5 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -242,8 +242,8 @@ QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other) QStaticTextPrivate::~QStaticTextPrivate() { - delete glyphLayoutMemory; - delete logClusterMemory; + delete[] glyphLayoutMemory; + delete[] logClusterMemory; qDeleteAll(items); } @@ -254,11 +254,11 @@ QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) void QStaticTextPrivate::init() { - delete glyphLayoutMemory; - delete logClusterMemory; + delete[] glyphLayoutMemory; + delete[] logClusterMemory; qDeleteAll(items); - QStackTextEngine engine = QStackTextEngine(text, font); + QStackTextEngine engine(text, font); engine.itemize(); engine.option.setTextDirection(QApplication::layoutDirection()); @@ -273,7 +273,7 @@ void QStaticTextPrivate::init() levels[i] = engine.layoutData->items[i].analysis.bidiLevel; QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); - int numGlyphs = engine.layoutData->glyphLayout.numGlyphs; + int numGlyphs = engine.layoutData->used; glyphLayoutMemory = new char[QGlyphLayout::spaceNeededForGlyphLayout(numGlyphs)]; logClusterMemory = new unsigned short[numGlyphs]; @@ -289,10 +289,9 @@ void QStaticTextPrivate::init() gf->width = si.width; items.append(gf); continue; - } + } QTextItemInt *gf = new QTextItemInt(si, &f); - QGlyphLayout l = engine.shapedGlyphs(&si); gf->glyphs = l.clone(currentGlyphLayout); currentGlyphLayout += QGlyphLayout::spaceNeededForGlyphLayout(l.numGlyphs); |