summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-10 14:16:17 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-10 14:16:17 (GMT)
commit727ec8c564a3947784bfe371b39615f965d530ec (patch)
treed4360972a21f8d24214b7a0c5ec7277391479192 /src/gui/text
parentef9e7168a8ed3e8149204cf6c604a38db35245c0 (diff)
parent01a045084ad45da37e6b79938354c82419c0a83e (diff)
downloadQt-727ec8c564a3947784bfe371b39615f965d530ec.zip
Qt-727ec8c564a3947784bfe371b39615f965d530ec.tar.gz
Qt-727ec8c564a3947784bfe371b39615f965d530ec.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontengine_ft.cpp70
-rw-r--r--src/gui/text/qfontengine_ft_p.h16
-rw-r--r--src/gui/text/qstatictext.cpp6
-rw-r--r--src/gui/text/qsyntaxhighlighter.cpp95
-rw-r--r--src/gui/text/qtextengine.cpp6
-rw-r--r--src/gui/text/qtextengine_p.h1
-rw-r--r--src/gui/text/qtextlayout.cpp2
7 files changed, 138 insertions, 58 deletions
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 17ade64..6b40aad 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -746,7 +746,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format)
QFontEngineFT::Glyph *QFontEngineFT::loadGlyphMetrics(QGlyphSet *set, uint glyph) const
{
- Glyph *g = set->glyph_data.value(glyph);
+ Glyph *g = set->getGlyph(glyph);
if (g)
return g;
@@ -858,10 +858,10 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph
}
}
- Glyph *g = set->glyph_data.value(glyph);
+ Glyph *g = set->getGlyph(glyph);
if (g && g->format == format) {
if (uploadToServer && !g->uploadedToServer) {
- set->glyph_data[glyph] = 0;
+ set->setGlyph(glyph, 0);
delete g;
g = 0;
} else {
@@ -1158,7 +1158,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph
uploadGlyphToServer(set, glyph, g, &info, glyph_buffer_size);
}
- set->glyph_data[glyph] = g;
+ set->setGlyph(glyph, g);
return g;
}
@@ -1381,8 +1381,7 @@ QFontEngineFT::QGlyphSet *QFontEngineFT::loadTransformedGlyphSet(const QTransfor
}
gs = &transformedGlyphSets[0];
- qDeleteAll(gs->glyph_data);
- gs->glyph_data.clear();
+ gs->clear();
gs->id = allocateServerGlyphSet();
@@ -1398,7 +1397,7 @@ bool QFontEngineFT::loadGlyphs(QGlyphSet *gs, glyph_t *glyphs, int num_glyphs, G
FT_Face face = 0;
for (int i = 0; i < num_glyphs; ++i) {
- Glyph *glyph = gs->glyph_data.value(glyphs[i]);
+ Glyph *glyph = gs->getGlyph(glyphs[i]);
if (glyph == 0 || glyph->format != format) {
if (!face) {
face = lockFace();
@@ -1635,7 +1634,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlag
FT_Face face = 0;
if (flags & QTextEngine::DesignMetrics) {
for (int i = 0; i < glyphs->numGlyphs; i++) {
- Glyph *g = defaultGlyphSet.glyph_data.value(glyphs->glyphs[i]);
+ Glyph *g = defaultGlyphSet.getGlyph(glyphs->glyphs[i]);
if (g) {
glyphs->advances_x[i] = QFixed::fromFixed(g->linearAdvance);
} else {
@@ -1648,7 +1647,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlag
}
} else {
for (int i = 0; i < glyphs->numGlyphs; i++) {
- Glyph *g = defaultGlyphSet.glyph_data.value(glyphs->glyphs[i]);
+ Glyph *g = defaultGlyphSet.getGlyph(glyphs->glyphs[i]);
if (g) {
glyphs->advances_x[i] = QFixed(g->advance);
} else {
@@ -1677,7 +1676,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(const QGlyphLayout &glyphs)
QFixed ymax = 0;
QFixed xmax = 0;
for (int i = 0; i < glyphs.numGlyphs; i++) {
- Glyph *g = defaultGlyphSet.glyph_data.value(glyphs.glyphs[i]);
+ Glyph *g = defaultGlyphSet.getGlyph(glyphs.glyphs[i]);
if (!g) {
if (!face)
face = lockFace();
@@ -1719,7 +1718,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph)
{
FT_Face face = 0;
glyph_metrics_t overall;
- Glyph *g = defaultGlyphSet.glyph_data.value(glyph);
+ Glyph *g = defaultGlyphSet.getGlyph(glyph);
if (!g) {
face = lockFace();
g = loadGlyph(glyph, Format_None, true);
@@ -1783,8 +1782,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph, const QTransform &matr
transformedGlyphSets.prepend(QGlyphSet());
}
glyphSet = &transformedGlyphSets[0];
- qDeleteAll(glyphSet->glyph_data);
- glyphSet->glyph_data.clear();
+ glyphSet->clear();
glyphSet->id = allocateServerGlyphSet();
glyphSet->transformationMatrix = m;
}
@@ -1792,7 +1790,7 @@ glyph_metrics_t QFontEngineFT::boundingBox(glyph_t glyph, const QTransform &matr
} else {
glyphSet = &defaultGlyphSet;
}
- Glyph * g = glyphSet->glyph_data.value(glyph);
+ Glyph * g = glyphSet->getGlyph(glyph);
if (!g) {
face = lockFace();
g = loadGlyphMetrics(glyphSet, glyph);
@@ -1881,7 +1879,7 @@ QImage QFontEngineFT::alphaRGBMapForGlyph(glyph_t g, int margin, const QTransfor
void QFontEngineFT::removeGlyphFromCache(glyph_t glyph)
{
- delete defaultGlyphSet.glyph_data.take(glyph);
+ defaultGlyphSet.removeGlyphFromCache(glyph);
}
int QFontEngineFT::glyphCount() const
@@ -1937,11 +1935,53 @@ QFontEngineFT::QGlyphSet::QGlyphSet()
transformationMatrix.yy = 0x10000;
transformationMatrix.xy = 0;
transformationMatrix.yx = 0;
+ memset(fast_glyph_data, 0, sizeof(fast_glyph_data));
+ fast_glyph_count = 0;
}
QFontEngineFT::QGlyphSet::~QGlyphSet()
{
+ clear();
+}
+
+void QFontEngineFT::QGlyphSet::clear()
+{
+ if (fast_glyph_count > 0) {
+ for (int i = 0; i < 256; ++i) {
+ if (fast_glyph_data[i]) {
+ delete fast_glyph_data[i];
+ fast_glyph_data[i] = 0;
+ }
+ }
+ fast_glyph_count = 0;
+ }
qDeleteAll(glyph_data);
+ glyph_data.clear();
+}
+
+void QFontEngineFT::QGlyphSet::removeGlyphFromCache(int index)
+{
+ if (index < 256) {
+ if (fast_glyph_data[index]) {
+ delete fast_glyph_data[index];
+ fast_glyph_data[index] = 0;
+ if (fast_glyph_count > 0)
+ --fast_glyph_count;
+ }
+ } else {
+ delete glyph_data.take(index);
+ }
+}
+
+void QFontEngineFT::QGlyphSet::setGlyph(int index, Glyph *glyph)
+{
+ if (index < 256) {
+ if (!fast_glyph_data[index])
+ ++fast_glyph_count;
+ fast_glyph_data[index] = glyph;
+ } else {
+ glyph_data.insert(index, glyph);
+ }
}
unsigned long QFontEngineFT::allocateServerGlyphSet()
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index 98dd002..12b7da8 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -180,7 +180,21 @@ public:
FT_Matrix transformationMatrix;
unsigned long id; // server sided id, GlyphSet for X11
bool outline_drawing;
+
+ void removeGlyphFromCache(int index);
+ void clear();
+ inline Glyph *getGlyph(int index) const
+ {
+ if (index < 256)
+ return fast_glyph_data[index];
+ return glyph_data.value(index);
+ }
+ void setGlyph(int index, Glyph *glyph);
+
+private:
mutable QHash<int, Glyph *> glyph_data; // maps from glyph index to glyph data
+ mutable Glyph *fast_glyph_data[256]; // for fast lookup of glyphs < 256
+ mutable int fast_glyph_count;
};
virtual QFontEngine::FaceId faceId() const;
@@ -252,7 +266,7 @@ public:
QGlyphSet *defaultGlyphs() { return &defaultGlyphSet; }
GlyphFormat defaultGlyphFormat() const { return defaultFormat; }
- inline Glyph *cachedGlyph(glyph_t g) const { return defaultGlyphSet.glyph_data.value(g); }
+ inline Glyph *cachedGlyph(glyph_t g) const { return defaultGlyphSet.getGlyph(g); }
QGlyphSet *loadTransformedGlyphSet(const QTransform &matrix);
bool loadGlyphs(QGlyphSet *gs, glyph_t *glyphs, int num_glyphs, GlyphFormat format = Format_Render);
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index 8fe4c47..1fabf12 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -282,8 +282,10 @@ QString QStaticText::text() const
}
/*!
- Sets the performance hint of the QStaticText. This hint can be used to customize how much
- caching is done internally to improve performance.
+ Sets the performance hint of the QStaticText according to the \a
+ performanceHint provided. The \a performanceHint is used to
+ customize how much caching is done internally to improve
+ performance.
The default is QStaticText::ModerateCaching.
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp
index 6750c09..e594b7e 100644
--- a/src/gui/text/qsyntaxhighlighter.cpp
+++ b/src/gui/text/qsyntaxhighlighter.cpp
@@ -59,23 +59,24 @@ class QSyntaxHighlighterPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QSyntaxHighlighter)
public:
- inline QSyntaxHighlighterPrivate() : rehighlightPending(false) {}
+ inline QSyntaxHighlighterPrivate()
+ : rehighlightPending(false), inReformatBlocks(false)
+ {}
QPointer<QTextDocument> doc;
void _q_reformatBlocks(int from, int charsRemoved, int charsAdded);
- void reformatBlock(QTextBlock block);
-
+ void reformatBlocks(int from, int charsRemoved, int charsAdded);
+ void reformatBlock(const QTextBlock &block);
+
inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) {
- QObject::disconnect(doc, SIGNAL(contentsChange(int,int,int)),
- q_func(), SLOT(_q_reformatBlocks(int,int,int)));
+ inReformatBlocks = true;
cursor.beginEditBlock();
int from = cursor.position();
cursor.movePosition(operation);
- _q_reformatBlocks(from, 0, cursor.position() - from);
+ reformatBlocks(from, 0, cursor.position() - from);
cursor.endEditBlock();
- QObject::connect(doc, SIGNAL(contentsChange(int,int,int)),
- q_func(), SLOT(_q_reformatBlocks(int,int,int)));
+ inReformatBlocks = false;
}
inline void _q_delayedRehighlight() {
@@ -83,17 +84,19 @@ public:
return;
rehighlightPending = false;
q_func()->rehighlight();
- return;
}
void applyFormatChanges();
QVector<QTextCharFormat> formatChanges;
QTextBlock currentBlock;
bool rehighlightPending;
+ bool inReformatBlocks;
};
void QSyntaxHighlighterPrivate::applyFormatChanges()
{
+ bool formatsChanged = false;
+
QTextLayout *layout = currentBlock.layout();
QList<QTextLayout::FormatRange> ranges = layout->additionalFormats();
@@ -101,19 +104,26 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
const int preeditAreaStart = layout->preeditAreaPosition();
const int preeditAreaLength = layout->preeditAreaText().length();
- QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
- while (it != ranges.end()) {
- if (it->start >= preeditAreaStart
- && it->start + it->length <= preeditAreaStart + preeditAreaLength)
- ++it;
- else
- it = ranges.erase(it);
+ if (preeditAreaLength != 0) {
+ QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
+ while (it != ranges.end()) {
+ if (it->start >= preeditAreaStart
+ && it->start + it->length <= preeditAreaStart + preeditAreaLength) {
+ ++it;
+ } else {
+ it = ranges.erase(it);
+ formatsChanged = true;
+ }
+ }
+ } else if (!ranges.isEmpty()) {
+ ranges.clear();
+ formatsChanged = true;
}
QTextCharFormat emptyFormat;
QTextLayout::FormatRange r;
- r.start = r.length = -1;
+ r.start = -1;
int i = 0;
while (i < formatChanges.count()) {
@@ -135,34 +145,46 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
r.length = i - r.start;
- if (r.start >= preeditAreaStart) {
- r.start += preeditAreaLength;
- } else if (r.start + r.length >= preeditAreaStart) {
- r.length += preeditAreaLength;
+ if (preeditAreaLength != 0) {
+ if (r.start >= preeditAreaStart)
+ r.start += preeditAreaLength;
+ else if (r.start + r.length >= preeditAreaStart)
+ r.length += preeditAreaLength;
}
ranges << r;
- r.start = r.length = -1;
+ formatsChanged = true;
+ r.start = -1;
}
if (r.start != -1) {
r.length = formatChanges.count() - r.start;
- if (r.start >= preeditAreaStart) {
- r.start += preeditAreaLength;
- } else if (r.start + r.length >= preeditAreaStart) {
- r.length += preeditAreaLength;
+ if (preeditAreaLength != 0) {
+ if (r.start >= preeditAreaStart)
+ r.start += preeditAreaLength;
+ else if (r.start + r.length >= preeditAreaStart)
+ r.length += preeditAreaLength;
}
ranges << r;
+ formatsChanged = true;
}
- layout->setAdditionalFormats(ranges);
+ if (formatsChanged) {
+ layout->setAdditionalFormats(ranges);
+ doc->markContentsDirty(currentBlock.position(), currentBlock.length());
+ }
}
void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int charsAdded)
{
- Q_UNUSED(charsRemoved);
+ if (!inReformatBlocks)
+ reformatBlocks(from, charsRemoved, charsAdded);
+}
+
+void QSyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int charsAdded)
+{
rehighlightPending = false;
QTextBlock block = doc->findBlock(from);
@@ -191,21 +213,18 @@ void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, in
formatChanges.clear();
}
-void QSyntaxHighlighterPrivate::reformatBlock(QTextBlock block)
+void QSyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block)
{
Q_Q(QSyntaxHighlighter);
Q_ASSERT_X(!currentBlock.isValid(), "QSyntaxHighlighter::reformatBlock()", "reFormatBlock() called recursively");
currentBlock = block;
- QTextBlock previous = block.previous();
formatChanges.fill(QTextCharFormat(), block.length() - 1);
q->highlightBlock(block.text());
applyFormatChanges();
- doc->markContentsDirty(block.position(), block.length());
-
currentBlock = QTextBlock();
}
@@ -349,8 +368,8 @@ void QSyntaxHighlighter::setDocument(QTextDocument *doc)
if (d->doc) {
connect(d->doc, SIGNAL(contentsChange(int,int,int)),
this, SLOT(_q_reformatBlocks(int,int,int)));
- QTimer::singleShot(0, this, SLOT(_q_delayedRehighlight()));
d->rehighlightPending = true;
+ QTimer::singleShot(0, this, SLOT(_q_delayedRehighlight()));
}
}
@@ -391,11 +410,16 @@ void QSyntaxHighlighter::rehighlight()
void QSyntaxHighlighter::rehighlightBlock(const QTextBlock &block)
{
Q_D(QSyntaxHighlighter);
- if (!d->doc)
+ if (!d->doc || !block.isValid() || block.document() != d->doc)
return;
+ const bool rehighlightPending = d->rehighlightPending;
+
QTextCursor cursor(block);
d->rehighlight(cursor, QTextCursor::EndOfBlock);
+
+ if (rehighlightPending)
+ d->rehighlightPending = rehighlightPending;
}
/*!
@@ -460,7 +484,6 @@ void QSyntaxHighlighter::rehighlightBlock(const QTextBlock &block)
void QSyntaxHighlighter::setFormat(int start, int count, const QTextCharFormat &format)
{
Q_D(QSyntaxHighlighter);
-
if (start < 0 || start >= d->formatChanges.count())
return;
@@ -628,7 +651,7 @@ QTextBlockUserData *QSyntaxHighlighter::currentBlockUserData() const
\since 4.4
Returns the current text block.
- */
+*/
QTextBlock QSyntaxHighlighter::currentBlock() const
{
Q_D(const QSyntaxHighlighter);
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 02eae98..b826588 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -81,7 +81,7 @@ public:
void generate(int start, int length, QFont::Capitalization caps)
{
if ((int)caps == (int)QFont::SmallCaps)
- generateScriptItemsSmallCaps(m_string.utf16(), start, length);
+ generateScriptItemsSmallCaps(reinterpret_cast<const ushort *>(m_string.unicode()), start, length);
else if(caps == QFont::Capitalize)
generateScriptItemsCapitalize(start, length);
else if(caps != QFont::MixedCase) {
@@ -1434,9 +1434,7 @@ void QTextEngine::itemize() const
layoutData->hasBidi = bidiItemize(const_cast<QTextEngine *>(this), analysis, control);
}
- const ushort *unicode = layoutData->string.utf16();
- // correctly assign script, isTab and isObject to the script analysis
- const ushort *uc = unicode;
+ const ushort *uc = reinterpret_cast<const ushort *>(layoutData->string.unicode());
const ushort *e = uc + length;
int lastScript = QUnicodeTables::Common;
while (uc < e) {
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index f36cbd2..5054b66 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -382,6 +382,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine
QFixed y;
QFixed width;
QFixed textWidth;
+ QFixed textAdvance;
int from;
signed int length : 29;
mutable uint justified : 1;
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index af91603..cc6793d 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1875,6 +1875,7 @@ void QTextLine::layout_helper(int maxGlyphs)
line.textWidth += lbh.softHyphenWidth;
}
+ line.textAdvance = line.textWidth;
line.textWidth += lbh.rightBearing;
goto found;
@@ -1885,6 +1886,7 @@ void QTextLine::layout_helper(int maxGlyphs)
}
LB_DEBUG("reached end of line");
lbh.checkFullOtherwiseExtend(line);
+ line.textAdvance = line.textWidth;
line.textWidth += lbh.rightBearing;
found: