diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-19 14:48:16 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-01-14 12:45:26 (GMT) |
commit | 26372057d92564da9baf6d17c685fd1b22ff4b8a (patch) | |
tree | 000c726950e7251a706ff294a211c886cd8731ec | |
parent | 5d0f93a3d6d3d99d86d181ee3cc559a6782be4ee (diff) | |
download | Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.zip Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.tar.gz Qt-26372057d92564da9baf6d17c685fd1b22ff4b8a.tar.bz2 |
Simplify QStaticText
Not much to gain by going directly to the QTextEngine, and the code
is a lot simpler if we just use the QTextLayout instead.
-rw-r--r-- | src/gui/painting/qpainter.cpp | 27 | ||||
-rw-r--r-- | src/gui/text/qstatictext.cpp | 42 | ||||
-rw-r--r-- | src/gui/text/qstatictext_p.h | 4 |
3 files changed, 21 insertions, 52 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index f5bd2c5..a890d63 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5707,32 +5707,9 @@ void QPainter::drawText(const QPointF &p, const QString &str) void QPainter::drawStaticText(const QPointF &p, const QStaticText &staticText) { const QStaticTextPrivate *staticText_d = QStaticTextPrivate::get(&staticText); - const QTextEngine &engine = staticText_d->engine; - const QVarLengthArray<int> &visualOrder = staticText_d->visualOrder; + QTextLayout *textLayout = staticText_d->textLayout; - QFixed x = QFixed::fromReal(p.x()); - QFixed ox = x; - - int nItems = engine.layoutData->items.size(); - for (int i = 0; i < nItems; ++i) { - int item = visualOrder[i]; - const QScriptItem &si = engine.layoutData->items.at(item); - if (si.analysis.flags >= QScriptAnalysis::TabOrObject) { - x += si.width; - continue; - } - QFont f = engine.font(si); - QTextItemInt gf(si, &f); - gf.glyphs = engine.shapedGlyphs(&si); - gf.chars = engine.layoutData->string.unicode() + si.position; - gf.num_chars = engine.length(item); - gf.width = si.width; - gf.logClusters = engine.logClusters(&si); - - drawTextItem(QPointF(x.toReal(), p.y()), gf); - - x += si.width; - } + textLayout->draw(this, p); } /*! diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 90b1145..bb83fd1 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -51,6 +51,11 @@ QStaticText::QStaticText(const QString &text, const QFont &font) d->init(text, font); } +QStaticTextPrivate::QStaticTextPrivate() + : textLayout(0) +{ +} + QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) { return q->d_ptr; @@ -58,34 +63,21 @@ QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) void QStaticTextPrivate::init(const QString &text, const QFont &font) { - engine.text = text; - engine.fnt = font; - - /*engine.option.setTextDirection(d->state->layoutDirection); - if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) { - engine.ignoreBidi = true; - engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft); - }*/ + Q_ASSERT(textLayout == 0); + textLayout = new QTextLayout(text, font); + textLayout->setCacheEnabled(true); - engine.itemize(); - QScriptLine line; - line.length = text.length(); - engine.shapeLine(line); + QFontMetrics fontMetrics(font); - int nItems = engine.layoutData->items.size(); - visualOrder = QVarLengthArray<int>(nItems); - QVarLengthArray<uchar> levels(nItems); - for (int i = 0; i < nItems; ++i) - levels[i] = engine.layoutData->items[i].analysis.bidiLevel; - QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); + textLayout->beginLayout(); + int h = fontMetrics.ascent(); + QTextLine line; + if ((line = textLayout->createLine()).isValid()) { + line.setLineWidth(fontMetrics.width(text)); + line.setPosition(QPointF(0, h)); + h += line.height(); + } - /*if (justificationPadding > 0) { - engine.option.setAlignment(Qt::AlignJustify); - engine.forceJustification = true; - // this works because justify() is only interested in the difference between width and textWidth - line.width = justificationPadding; - engine.justify(line); - }*/ } QT_END_NAMESPACE diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index ad70b1e..c9abee3 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -9,10 +9,10 @@ class QStaticText; class QStaticTextPrivate { public: + QStaticTextPrivate(); void init(const QString &text, const QFont &font); - QTextEngine engine; - QVarLengthArray<int> visualOrder; + QTextLayout *textLayout; static QStaticTextPrivate *get(const QStaticText *q); }; |