summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qdistancefield.cpp5
-rw-r--r--src/gui/text/qfontdatabase.cpp85
-rw-r--r--src/gui/text/qfontdatabase.h2
-rw-r--r--src/gui/text/qfontengine.cpp214
-rw-r--r--src/gui/text/qfontengine_ft.cpp11
-rw-r--r--src/gui/text/qfontengine_p.h48
-rw-r--r--src/gui/text/qfontengine_qpf2.cpp2
-rw-r--r--src/gui/text/qfragmentmap_p.h2
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp2
-rw-r--r--src/gui/text/qtextdocument.cpp168
-rw-r--r--src/gui/text/qtextdocument.h11
-rw-r--r--src/gui/text/qtextdocument_p.cpp2
-rw-r--r--src/gui/text/qtextengine.cpp4
-rw-r--r--src/gui/text/qtextformat.cpp20
14 files changed, 347 insertions, 229 deletions
diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp
index b2d0298e04..10fe1a2c84 100644
--- a/src/gui/text/qdistancefield.cpp
+++ b/src/gui/text/qdistancefield.cpp
@@ -34,6 +34,7 @@
#include "qdistancefield_p.h"
#include <qmath.h>
#include <private/qdatabuffer_p.h>
+#include <private/qimage_p.h>
#include <private/qpathsimplifier_p.h>
QT_BEGIN_NAMESPACE
@@ -987,12 +988,12 @@ QImage QDistanceField::toImage(QImage::Format format) const
if (isNull())
return QImage();
- QImage image(d->width, d->height, format == QImage::Format_Indexed8 ?
+ QImage image(d->width, d->height, qt_depthForFormat(format) == 8 ?
format : QImage::Format_ARGB32_Premultiplied);
if (image.isNull())
return image;
- if (format == QImage::Format_Indexed8) {
+ if (image.depth() == 8) {
for (int y = 0; y < d->height; ++y)
memcpy(image.scanLine(y), scanLine(y), d->width);
} else {
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 99814dba82..8134e3012b 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -84,20 +84,22 @@ static int getFontWeight(const QString &weightString)
{
QString s = weightString.toLower();
- // Test in decreasing order of commonness
- if (s == QLatin1String("normal")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Normal"), Qt::CaseInsensitive) == 0)
+ // Order here is important. We want to match the common cases first, but we
+ // must also take care to acknowledge the cost of our tests.
+ //
+ // As a result, we test in two orders; the order of commonness, and the
+ // order of "expense".
+ //
+ // A simple string test is the cheapest, so let's do that first.
+ if (s == QLatin1String("normal"))
return QFont::Normal;
if (s == QLatin1String("medium"))
return qt_mediumFontWeight;
- if (s == QLatin1String("bold")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("bold"))
return QFont::Bold;
- if (s == QLatin1String("demibold") || s == QLatin1String("demi bold")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("demibold") || s == QLatin1String("demi bold"))
return QFont::DemiBold;
- if (s == QLatin1String("black")
- || s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
+ if (s == QLatin1String("black"))
return QFont::Black;
if (s == QLatin1String("light"))
return QFont::Light;
@@ -106,23 +108,48 @@ static int getFontWeight(const QString &weightString)
if (s == QLatin1String("extralight"))
return qt_extralightFontWeight;
- if (s.contains(QLatin1String("bold"))
- || s.contains(QCoreApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive)) {
- if (s.contains(QLatin1String("demi"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Demi"), Qt::CaseInsensitive) == 0)
- return (int) QFont::DemiBold;
- return (int) QFont::Bold;
+ // Next up, let's see if contains() matches: slightly more expensive, but
+ // still fast enough.
+ if (s.contains(QLatin1String("bold"))) {
+ if (s.contains(QLatin1String("demi")))
+ return QFont::DemiBold;
+ return QFont::Bold;
}
+ if (s.contains(QLatin1String("light")))
+ return QFont::Light;
+ if (s.contains(QLatin1String("black")))
+ return QFont::Black;
- if (s.contains(QLatin1String("light"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Light"), Qt::CaseInsensitive) == 0)
- return (int) QFont::Light;
+ // Now, we perform string translations & comparisons with those.
+ // These are (very) slow compared to simple string ops, so we do these last.
+ // As using translated values for such things is not very common, this should
+ // not be too bad.
+ QString translatedNormal = QCoreApplication::translate("QFontDatabase", "Normal").toLower();
+ if (s == translatedNormal)
+ return QFont::Normal;
+ QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower();
+ if (s == translatedBold)
+ return QFont::Bold;
+ QString translatedDemiBold = QCoreApplication::translate("QFontDatabase", "Demi Bold").toLower();
+ if (s == translatedDemiBold)
+ return QFont::DemiBold;
+ QString translatedBlack = QCoreApplication::translate("QFontDatabase", "Black").toLower();
+ if (s == translatedBlack)
+ return QFont::Black;
- if (s.contains(QLatin1String("black"))
- || s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
- return (int) QFont::Black;
+ // And now the contains() checks for the translated strings.
+ if (s.contains(translatedBold)) {
+ QString translatedDemi = QCoreApplication::translate("QFontDatabase", "Demi").toLower();
+ if (s == translatedDemi)
+ return QFont::DemiBold;
+ return QFont::Bold;
+ }
+
+ QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower();
+ if (s == translatedLight || s.contains(translatedLight))
+ return QFont::Light;
- return (int) QFont::Normal;
+ return QFont::Normal;
}
// convert 0 ~ 1000 integer to QFont::Weight
@@ -1117,7 +1144,10 @@ static int match(int script, const QFontDef &request,
load(family_name, script);
- const size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem + QFontDatabase::WritingSystemsCount, script) - scriptForWritingSystem;
+ size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem +
+ QFontDatabase::WritingSystemsCount, script) - scriptForWritingSystem;
+ if (writingSystem >= QFontDatabase::WritingSystemsCount)
+ writingSystem = QFontDatabase::Any;
QFontDatabasePrivate *db = privateDb();
for (int x = 0; x < db->count; ++x) {
@@ -1562,6 +1592,15 @@ bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &sty
QtFontStyle::Key styleKey(style);
QtFontFamily *f = d->family(familyName);
+ if (!f) {
+ for (int i = 0; i < d->count; i++) {
+ if (d->families[i]->matchesFamilyName(familyName)) {
+ f = d->families[i];
+ f->ensurePopulated();
+ break;
+ }
+ }
+ }
if (!f) return smoothScalable;
for (int j = 0; j < f->count; j++) {
diff --git a/src/gui/text/qfontdatabase.h b/src/gui/text/qfontdatabase.h
index d7d8745f12..5688ce6b7a 100644
--- a/src/gui/text/qfontdatabase.h
+++ b/src/gui/text/qfontdatabase.h
@@ -159,7 +159,7 @@ private:
friend class QFontPrivate;
friend class QFontDialog;
friend class QFontDialogPrivate;
- friend class QFontEngineMultiBasicImpl;
+ friend class QFontEngineMulti;
QFontDatabasePrivate *d;
};
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index b2a7a8e91f..af37c05e41 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -761,7 +761,7 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &t)
{
QImage i = alphaMapForGlyph(glyph);
if (t.type() > QTransform::TxTranslate)
- i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
+ i = i.transformed(t).convertToFormat(QImage::Format_Alpha8);
Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
return i;
@@ -774,7 +774,7 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, con
QImage i = alphaMapForGlyph(glyph, subPixelPosition);
if (t.type() > QTransform::TxTranslate)
- i = i.transformed(t).convertToFormat(QImage::Format_Indexed8);
+ i = i.transformed(t).convertToFormat(QImage::Format_Alpha8);
Q_ASSERT(i.depth() <= 8); // To verify that transformed didn't change the format...
return i;
@@ -785,12 +785,11 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed /*subPixelPosition
QImage alphaMask = alphaMapForGlyph(glyph, t);
QImage rgbMask(alphaMask.width(), alphaMask.height(), QImage::Format_RGB32);
- QVector<QRgb> colorTable = alphaMask.colorTable();
for (int y=0; y<alphaMask.height(); ++y) {
uint *dst = (uint *) rgbMask.scanLine(y);
uchar *src = (uchar *) alphaMask.scanLine(y);
for (int x=0; x<alphaMask.width(); ++x) {
- int val = qAlpha(colorTable.at(src[x]));
+ int val = src[x];
dst[x] = qRgb(val, val, val);
}
}
@@ -871,20 +870,16 @@ QImage QFontEngine::alphaMapForGlyph(glyph_t glyph)
p.drawPath(path);
p.end();
- QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- indexed.setColorTable(colors);
+ QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8);
for (int y=0; y<im.height(); ++y) {
- uchar *dst = (uchar *) indexed.scanLine(y);
+ uchar *dst = (uchar *) alphaMap.scanLine(y);
uint *src = (uint *) im.scanLine(y);
for (int x=0; x<im.width(); ++x)
dst[x] = qAlpha(src[x]);
}
- return indexed;
+ return alphaMap;
}
void QFontEngine::removeGlyphFromCache(glyph_t)
@@ -1535,14 +1530,10 @@ bool QFontEngineBox::canRender(const QChar *, int) const
QImage QFontEngineBox::alphaMapForGlyph(glyph_t)
{
- QImage image(_size, _size, QImage::Format_Indexed8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- image.setColorTable(colors);
+ QImage image(_size, _size, QImage::Format_Alpha8);
image.fill(0);
- // can't use qpainter for index8; so use setPixel to draw our rectangle.
+ // FIXME: use qpainter
for (int i=2; i <= _size-3; ++i) {
image.setPixel(i, 2, 255);
image.setPixel(i, _size-3, 255);
@@ -1563,34 +1554,103 @@ static inline uchar highByte(glyph_t glyph)
static inline glyph_t stripped(glyph_t glyph)
{ return glyph & 0x00ffffff; }
-QFontEngineMulti::QFontEngineMulti(int engineCount)
- : QFontEngine(Multi)
+QFontEngineMulti::QFontEngineMulti(QFontEngine *engine, int script, const QStringList &fallbackFamilies)
+ : QFontEngine(Multi),
+ m_fallbackFamilies(fallbackFamilies),
+ m_script(script),
+ m_fallbackFamiliesQueried(!m_fallbackFamilies.isEmpty())
{
- engines.fill(0, engineCount);
- cache_cost = 0;
+ Q_ASSERT(engine && engine->type() != QFontEngine::Multi);
+
+ if (m_fallbackFamilies.isEmpty()) {
+ // defer obtaining the fallback families until loadEngine(1)
+ m_fallbackFamilies << QString();
+ }
+
+ m_engines.fill(0, m_fallbackFamilies.size() + 1);
+
+ engine->ref.ref();
+ m_engines[0] = engine;
+
+ fontDef = engine->fontDef;
+ cache_cost = engine->cache_cost;
}
QFontEngineMulti::~QFontEngineMulti()
{
- for (int i = 0; i < engines.size(); ++i) {
- QFontEngine *fontEngine = engines.at(i);
+ for (int i = 0; i < m_engines.size(); ++i) {
+ QFontEngine *fontEngine = m_engines.at(i);
if (fontEngine && !fontEngine->ref.deref())
delete fontEngine;
}
}
+void QFontEngineMulti::ensureFallbackFamiliesQueried()
+{
+ if (QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration()) {
+ const QStringList fallbackFamilies = integration->fontDatabase()->fallbacksForFamily(fontDef.family,
+ QFont::Style(fontDef.style),
+ QFont::AnyStyle,
+ QChar::Script(m_script));
+ setFallbackFamiliesList(fallbackFamilies);
+ }
+}
+
+void QFontEngineMulti::setFallbackFamiliesList(const QStringList &fallbackFamilies)
+{
+ Q_ASSERT(!m_fallbackFamiliesQueried);
+
+ m_fallbackFamilies = fallbackFamilies;
+
+ m_engines.resize(m_fallbackFamilies.size() + 1);
+
+ if (m_fallbackFamilies.isEmpty()) {
+ // turns out we lied about having any fallback at all
+ QFontEngine *engine = m_engines.at(0);
+ engine->ref.ref();
+ m_engines[1] = engine;
+ m_fallbackFamilies << fontDef.family;
+ }
+
+ m_fallbackFamiliesQueried = true;
+}
+
+void QFontEngineMulti::ensureEngineAt(int at)
+{
+ Q_ASSERT(m_fallbackFamiliesQueried);
+ Q_ASSERT(at < m_engines.size());
+ if (!m_engines.at(at)) {
+ QFontEngine *engine = loadEngine(at);
+ if (!engine)
+ engine = new QFontEngineBox(fontDef.pixelSize);
+ Q_ASSERT(engine && engine->type() != QFontEngine::Multi);
+ engine->ref.ref();
+ m_engines[at] = engine;
+ }
+}
+
+QFontEngine *QFontEngineMulti::loadEngine(int at)
+{
+ QFontDef request(fontDef);
+ request.styleStrategy |= QFont::NoFontMerging;
+ request.family = fallbackFamilyAt(at - 1);
+
+ return QFontDatabase::findFont(m_script, /*fontprivate = */0, request, /*multi = */false);
+}
+
glyph_t QFontEngineMulti::glyphIndex(uint ucs4) const
{
glyph_t glyph = engine(0)->glyphIndex(ucs4);
if (glyph == 0 && ucs4 != QChar::LineSeparator) {
- const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
- for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) {
- QFontEngine *engine = engines.at(x);
+ if (!m_fallbackFamiliesQueried)
+ const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
+ for (int x = 1, n = qMin(m_engines.size(), 256); x < n; ++x) {
+ QFontEngine *engine = m_engines.at(x);
if (!engine) {
if (!shouldLoadFontEngineForCharacter(x, ucs4))
continue;
- const_cast<QFontEngineMulti *>(this)->loadEngine(x);
- engine = engines.at(x);
+ const_cast<QFontEngineMulti *>(this)->ensureEngineAt(x);
+ engine = m_engines.at(x);
}
Q_ASSERT(engine != 0);
if (engine->type() == Box)
@@ -1615,20 +1675,22 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
if (!engine(0)->stringToCMap(str, len, glyphs, nglyphs, flags))
return false;
- const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
int glyph_pos = 0;
QStringIterator it(str, str + len);
while (it.hasNext()) {
const uint ucs4 = it.peekNext();
if (glyphs->glyphs[glyph_pos] == 0 && ucs4 != QChar::LineSeparator) {
- for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) {
- if (engines.at(x) == 0 && !shouldLoadFontEngineForCharacter(x, ucs4))
- continue;
-
- QFontEngine *engine = engines.at(x);
+ if (!m_fallbackFamiliesQueried)
+ const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
+ for (int x = 1, n = qMin(m_engines.size(), 256); x < n; ++x) {
+ QFontEngine *engine = m_engines.at(x);
if (!engine) {
- const_cast<QFontEngineMulti *>(this)->loadEngine(x);
- engine = engines.at(x);
+ if (!shouldLoadFontEngineForCharacter(x, ucs4))
+ continue;
+ const_cast<QFontEngineMulti *>(this)->ensureEngineAt(x);
+ engine = m_engines.at(x);
+ if (!engine)
+ continue;
}
Q_ASSERT(engine != 0);
if (engine->type() == Box)
@@ -1883,7 +1945,6 @@ void QFontEngineMulti::doKerning(QGlyphLayout *glyphs, QFontEngine::ShaperFlags
glyph_metrics_t QFontEngineMulti::boundingBox(glyph_t glyph)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->boundingBox(stripped(glyph));
}
@@ -1962,111 +2023,34 @@ bool QFontEngineMulti::canRender(const QChar *string, int len) const
QImage QFontEngineMulti::alphaMapForGlyph(glyph_t glyph)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->alphaMapForGlyph(stripped(glyph));
}
QImage QFontEngineMulti::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->alphaMapForGlyph(stripped(glyph), subPixelPosition);
}
QImage QFontEngineMulti::alphaMapForGlyph(glyph_t glyph, const QTransform &t)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->alphaMapForGlyph(stripped(glyph), t);
}
QImage QFontEngineMulti::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->alphaMapForGlyph(stripped(glyph), subPixelPosition, t);
}
QImage QFontEngineMulti::alphaRGBMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t)
{
const int which = highByte(glyph);
- Q_ASSERT(which < engines.size());
return engine(which)->alphaRGBMapForGlyph(stripped(glyph), subPixelPosition, t);
}
/*
- Creates a new multi engine.
-
- This function takes ownership of the QFontEngine, increasing it's refcount.
-*/
-QFontEngineMultiBasicImpl::QFontEngineMultiBasicImpl(QFontEngine *fe, int _script, const QStringList &fallbacks)
- : QFontEngineMulti(fallbacks.size() + 1),
- fallbackFamilies(fallbacks), script(_script)
- , fallbacksQueried(true)
-{
- init(fe);
-}
-
-QFontEngineMultiBasicImpl::QFontEngineMultiBasicImpl(QFontEngine *fe, int _script)
- : QFontEngineMulti(2)
- , script(_script)
- , fallbacksQueried(false)
-{
- fallbackFamilies << QString();
- init(fe);
-}
-
-void QFontEngineMultiBasicImpl::init(QFontEngine *fe)
-{
- Q_ASSERT(fe && fe->type() != QFontEngine::Multi);
- engines[0] = fe;
- fe->ref.ref();
- fontDef = engines[0]->fontDef;
- cache_cost = fe->cache_cost;
-}
-
-void QFontEngineMultiBasicImpl::loadEngine(int at)
-{
- ensureFallbackFamiliesQueried();
- Q_ASSERT(at < engines.size());
- Q_ASSERT(engines.at(at) == 0);
- QFontDef request = fontDef;
- request.styleStrategy |= QFont::NoFontMerging;
- request.family = fallbackFamilies.at(at-1);
- engines[at] = QFontDatabase::findFont(script,
- /*fontprivate = */0,
- request, /*multi = */false);
- Q_ASSERT(engines[at]);
- engines[at]->ref.ref();
- engines[at]->fontDef = request;
-}
-void QFontEngineMultiBasicImpl::ensureFallbackFamiliesQueried()
-{
- if (fallbacksQueried)
- return;
- QStringList fallbacks = QGuiApplicationPrivate::instance()->platformIntegration()->fontDatabase()->fallbacksForFamily(engine(0)->fontDef.family, QFont::Style(engine(0)->fontDef.style)
- , QFont::AnyStyle, QChar::Script(script));
- setFallbackFamiliesList(fallbacks);
-}
-
-void QFontEngineMultiBasicImpl::setFallbackFamiliesList(const QStringList &fallbacks)
-{
- // Original FontEngine to restore after the fill.
- QFontEngine *fe = engines[0];
- fallbackFamilies = fallbacks;
- if (!fallbackFamilies.isEmpty()) {
- engines.fill(0, fallbackFamilies.size() + 1);
- engines[0] = fe;
- } else {
- // Turns out we lied about having any fallback at all.
- fallbackFamilies << fe->fontDef.family;
- engines[1] = fe;
- fe->ref.ref();
- }
- fallbacksQueried = true;
-}
-
-/*
This is used indirectly by Qt WebKit when using QTextLayout::setRawFont
The purpose of this is to provide the necessary font fallbacks when drawing complex
@@ -2074,7 +2058,7 @@ void QFontEngineMultiBasicImpl::setFallbackFamiliesList(const QStringList &fallb
the same raw font over and over again, we want to cache the corresponding multi font engine
as it may contain fallback font engines already.
*/
-QFontEngine* QFontEngineMultiBasicImpl::createMultiFontEngine(QFontEngine *fe, int script)
+QFontEngine *QFontEngineMulti::createMultiFontEngine(QFontEngine *fe, int script)
{
QFontEngine *engine = 0;
QFontCache::Key key(fe->fontDef, script, /*multi = */true);
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 8191629003..ef397e532c 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -1797,7 +1797,7 @@ QImage *QFontEngineFT::lockedAlphaMapForGlyph(glyph_t glyphIndex, QFixed subPixe
format = QImage::Format_Mono;
break;
case Format_A8:
- format = QImage::Format_Indexed8;
+ format = QImage::Format_Alpha8;
break;
case Format_A32:
format = QImage::Format_ARGB32;
@@ -1940,13 +1940,8 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g, QFixed subPixelPosition, const
const int pitch = antialias ? (glyph->width + 3) & ~3 : ((glyph->width + 31)/32) * 4;
- QImage img(glyph->width, glyph->height, antialias ? QImage::Format_Indexed8 : QImage::Format_Mono);
- if (antialias) {
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- img.setColorTable(colors);
- } else {
+ QImage img(glyph->width, glyph->height, antialias ? QImage::Format_Alpha8 : QImage::Format_Mono);
+ if (!antialias) {
QVector<QRgb> colors(2);
colors[0] = qRgba(0, 0, 0, 0);
colors[1] = qRgba(0, 0, 0, 255);
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index 9364b82bed..5ed53a4338 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -385,7 +385,7 @@ private:
class Q_GUI_EXPORT QFontEngineMulti : public QFontEngine
{
public:
- explicit QFontEngineMulti(int engineCount);
+ explicit QFontEngineMulti(QFontEngine *engine, int script, const QStringList &fallbackFamilies = QStringList());
~QFontEngineMulti();
virtual glyph_t glyphIndex(uint ucs4) const;
@@ -418,46 +418,28 @@ public:
virtual bool canRender(const QChar *string, int len) const;
- QFontEngine *engine(int at) const
- {Q_ASSERT(at < engines.size()); return engines.at(at); }
+ inline int fallbackFamilyCount() const { return m_fallbackFamilies.size(); }
+ inline QString fallbackFamilyAt(int at) const { return m_fallbackFamilies.at(at); }
- inline void ensureEngineAt(int at)
- {
- if (at >= engines.size() || engines.at(at) == 0)
- loadEngine(at);
- }
-
- virtual bool shouldLoadFontEngineForCharacter(int at, uint ucs4) const;
- virtual void setFallbackFamiliesList(const QStringList &) {}
-
-protected:
- friend class QRawFont;
- virtual void loadEngine(int at) = 0;
- virtual void ensureFallbackFamiliesQueried() {}
- QVector<QFontEngine *> engines;
-};
+ void setFallbackFamiliesList(const QStringList &fallbackFamilies);
-class Q_GUI_EXPORT QFontEngineMultiBasicImpl : public QFontEngineMulti
-{
-public:
- QFontEngineMultiBasicImpl(QFontEngine *fe, int script, const QStringList &fallbacks);
- QFontEngineMultiBasicImpl(QFontEngine *fe, int script);
+ inline QFontEngine *engine(int at) const
+ { Q_ASSERT(at < m_engines.size()); return m_engines.at(at); }
- void loadEngine(int at);
- static QFontEngine* createMultiFontEngine(QFontEngine *fe, int script);
+ void ensureEngineAt(int at);
- int fallbackFamilyCount() const { return fallbackFamilies.size(); }
- QString fallbackFamilyAt(int at) const { return fallbackFamilies.at(at); }
+ static QFontEngine *createMultiFontEngine(QFontEngine *fe, int script);
+protected:
virtual void ensureFallbackFamiliesQueried();
- virtual void setFallbackFamiliesList(const QStringList &fallbacks);
+ virtual bool shouldLoadFontEngineForCharacter(int at, uint ucs4) const;
+ virtual QFontEngine *loadEngine(int at);
private:
- void init(QFontEngine *fe);
-
- mutable QStringList fallbackFamilies;
- int script;
- mutable bool fallbacksQueried;
+ QVector<QFontEngine *> m_engines;
+ QStringList m_fallbackFamilies;
+ const int m_script;
+ bool m_fallbackFamiliesQueried;
};
class QTestFontEngine : public QFontEngineBox
diff --git a/src/gui/text/qfontengine_qpf2.cpp b/src/gui/text/qfontengine_qpf2.cpp
index 4785902c99..8e924102e5 100644
--- a/src/gui/text/qfontengine_qpf2.cpp
+++ b/src/gui/text/qfontengine_qpf2.cpp
@@ -396,7 +396,7 @@ QImage QFontEngineQPF2::alphaMapForGlyph(glyph_t g)
const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph);
- QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Indexed8);
+ QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Alpha8);
return image;
}
diff --git a/src/gui/text/qfragmentmap_p.h b/src/gui/text/qfragmentmap_p.h
index 012d3c25ce..a19e3d9ea3 100644
--- a/src/gui/text/qfragmentmap_p.h
+++ b/src/gui/text/qfragmentmap_p.h
@@ -249,6 +249,8 @@ uint QFragmentMapData<Fragment>::createFragment()
uint freePos = head->freelist;
if (freePos == head->allocated) {
// need to create some free space
+ if (freePos >= uint(MaxAllocSize) / fragmentSize)
+ qBadAlloc();
uint needed = qAllocMore((freePos+1)*fragmentSize, 0);
Q_ASSERT(needed/fragmentSize > head->allocated);
Fragment *newFragments = (Fragment *)realloc(fragments, needed);
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index f18ddbab8a..d10cc8fed0 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -314,7 +314,7 @@ void QPlatformFontDatabase::invalidate()
*/
QFontEngineMulti *QPlatformFontDatabase::fontEngineMulti(QFontEngine *fontEngine, QChar::Script script)
{
- return new QFontEngineMultiBasicImpl(fontEngine, script);
+ return new QFontEngineMulti(fontEngine, script);
}
/*!
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index ea2b794feb..3a11266e0a 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -40,6 +40,7 @@
#include "qtextlist.h"
#include <qdebug.h>
#include <qregexp.h>
+#include <qregularexpression.h>
#include <qvarlengtharray.h>
#include <qtextcodec.h>
#include <qthread.h>
@@ -1269,8 +1270,6 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op
}
/*!
- \fn QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cursor, FindFlags options) const
-
Finds the next occurrence of the string, \a subString, in the document.
The search starts at the position of the given \a cursor, and proceeds
forwards through the document unless specified otherwise in the search
@@ -1285,14 +1284,14 @@ QTextCursor QTextDocument::find(const QString &subString, int from, FindFlags op
By default the search is case-sensitive, and can match text anywhere in the
document.
*/
-QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &from, FindFlags options) const
+QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &cursor, FindFlags options) const
{
int pos = 0;
- if (!from.isNull()) {
+ if (!cursor.isNull()) {
if (options & QTextDocument::FindBackward)
- pos = from.selectionStart();
+ pos = cursor.selectionStart();
else
- pos = from.selectionEnd();
+ pos = cursor.selectionEnd();
}
QRegExp expr(subString);
expr.setPatternSyntax(QRegExp::FixedString);
@@ -1302,8 +1301,9 @@ QTextCursor QTextDocument::find(const QString &subString, const QTextCursor &fro
}
+#ifndef QT_NO_REGEXP
static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int offset,
- QTextDocument::FindFlags options, QTextCursor &cursor)
+ QTextDocument::FindFlags options, QTextCursor *cursor)
{
QRegExp expr(expression);
QString text = block.text();
@@ -1332,18 +1332,16 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
}
if (idx == -1)
return false;
- cursor = QTextCursor(block.docHandle(), block.position() + idx);
- cursor.setPosition(cursor.position() + expr.matchedLength(), QTextCursor::KeepAnchor);
+ *cursor = QTextCursor(block.docHandle(), block.position() + idx);
+ cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor);
return true;
}
/*!
- \fn QTextCursor QTextDocument::find(const QRegExp & expr, int position, FindFlags options) const
-
\overload
Finds the next occurrence, matching the regular expression, \a expr, in the document.
- The search starts at the given \a position, and proceeds forwards
+ The search starts at the given \a from position, and proceeds forwards
through the document unless specified otherwise in the search options.
The \a options control the type of search performed. The FindCaseSensitively
option is ignored for this overload, use QRegExp::caseSensitivity instead.
@@ -1351,7 +1349,7 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
Returns a cursor with the match selected if a match was found; otherwise
returns a null cursor.
- If the \a position is 0 (the default) the search begins from the beginning
+ If the \a from position is 0 (the default) the search begins from the beginning
of the document; otherwise it begins at the specified position.
*/
QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags options) const
@@ -1376,7 +1374,7 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
if (!(options & FindBackward)) {
int blockOffset = qMax(0, pos - block.position());
while (block.isValid()) {
- if (findInBlock(block, expr, blockOffset, options, cursor))
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;
blockOffset = 0;
block = block.next();
@@ -1384,7 +1382,7 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
} else {
int blockOffset = pos - block.position();
while (block.isValid()) {
- if (findInBlock(block, expr, blockOffset, options, cursor))
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
return cursor;
block = block.previous();
blockOffset = block.length() - 1;
@@ -1395,10 +1393,10 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
}
/*!
- \fn QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const
+ \overload
Finds the next occurrence, matching the regular expression, \a expr, in the document.
- The search starts at the position of the given \a cursor, and proceeds
+ The search starts at the position of the given \a from cursor, and proceeds
forwards through the document unless specified otherwise in the search
options. The \a options control the type of search performed. The FindCaseSensitively
option is ignored for this overload, use QRegExp::caseSensitivity instead.
@@ -1406,24 +1404,150 @@ QTextCursor QTextDocument::find(const QRegExp & expr, int from, FindFlags option
Returns a cursor with the match selected if a match was found; otherwise
returns a null cursor.
- If the given \a cursor has a selection, the search begins after the
+ If the given \a from cursor has a selection, the search begins after the
selection; otherwise it begins at the cursor's position.
By default the search is case-sensitive, and can match text anywhere in the
document.
*/
-QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &from, FindFlags options) const
+QTextCursor QTextDocument::find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options) const
{
int pos = 0;
- if (!from.isNull()) {
+ if (!cursor.isNull()) {
if (options & QTextDocument::FindBackward)
- pos = from.selectionStart();
+ pos = cursor.selectionStart();
else
- pos = from.selectionEnd();
+ pos = cursor.selectionEnd();
}
return find(expr, pos, options);
}
+#endif // QT_REGEXP
+
+#ifndef QT_NO_REGULAREXPRESSION
+static bool findInBlock(const QTextBlock &block, const QRegularExpression &expression, int offset,
+ QTextDocument::FindFlags options, QTextCursor *cursor)
+{
+ QRegularExpression expr(expression);
+ if (!(options & QTextDocument::FindCaseSensitively))
+ expr.setPatternOptions(expr.patternOptions() | QRegularExpression::CaseInsensitiveOption);
+ else
+ expr.setPatternOptions(expr.patternOptions() & ~QRegularExpression::CaseInsensitiveOption);
+
+ QString text = block.text();
+ text.replace(QChar::Nbsp, QLatin1Char(' '));
+ QRegularExpressionMatch match;
+ int idx = -1;
+
+ while (offset >= 0 && offset <= text.length()) {
+ idx = (options & QTextDocument::FindBackward) ?
+ text.lastIndexOf(expr, offset, &match) : text.indexOf(expr, offset, &match);
+ if (idx == -1)
+ return false;
+
+ if (options & QTextDocument::FindWholeWords) {
+ const int start = idx;
+ const int end = start + match.capturedLength();
+ if ((start != 0 && text.at(start - 1).isLetterOrNumber())
+ || (end != text.length() && text.at(end).isLetterOrNumber())) {
+ //if this is not a whole word, continue the search in the string
+ offset = (options & QTextDocument::FindBackward) ? idx-1 : end+1;
+ idx = -1;
+ continue;
+ }
+ }
+ //we have a hit, return the cursor for that.
+ break;
+ }
+ if (idx == -1)
+ return false;
+ *cursor = qMove(QTextCursor(block.docHandle(), block.position() + idx));
+ cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
+ return true;
+}
+
+/*!
+ \since 5.5
+
+ Finds the next occurrence, matching the regular expression, \a expr, in the document.
+ The search starts at the given \a from position, and proceeds forwards
+ through the document unless specified otherwise in the search options.
+ The \a options control the type of search performed.
+
+ Returns a cursor with the match selected if a match was found; otherwise
+ returns a null cursor.
+
+ If the \a from position is 0 (the default) the search begins from the beginning
+ of the document; otherwise it begins at the specified position.
+*/
+QTextCursor QTextDocument::find(const QRegularExpression &expr, int from, FindFlags options) const
+{
+ Q_D(const QTextDocument);
+
+ if (!expr.isValid())
+ return QTextCursor();
+
+ int pos = from;
+ //the cursor is positioned between characters, so for a backward search
+ //do not include the character given in the position.
+ if (options & FindBackward) {
+ --pos ;
+ if (pos < 0)
+ return QTextCursor();
+ }
+
+ QTextCursor cursor;
+ QTextBlock block = d->blocksFind(pos);
+
+ if (!(options & FindBackward)) {
+ int blockOffset = qMax(0, pos - block.position());
+ while (block.isValid()) {
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
+ return cursor;
+ blockOffset = 0;
+ block = block.next();
+ }
+ } else {
+ int blockOffset = pos - block.position();
+ while (block.isValid()) {
+ if (findInBlock(block, expr, blockOffset, options, &cursor))
+ return cursor;
+ block = block.previous();
+ blockOffset = block.length() - 1;
+ }
+ }
+
+ return QTextCursor();
+}
+
+/*!
+ \since 5.5
+
+ Finds the next occurrence, matching the regular expression, \a expr, in the document.
+ The search starts at the position of the given \a cursor, and proceeds
+ forwards through the document unless specified otherwise in the search
+ options. The \a options control the type of search performed.
+
+ Returns a cursor with the match selected if a match was found; otherwise
+ returns a null cursor.
+ If the given \a cursor has a selection, the search begins after the
+ selection; otherwise it begins at the cursor's position.
+
+ By default the search is case-sensitive, and can match text anywhere in the
+ document.
+*/
+QTextCursor QTextDocument::find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options) const
+{
+ int pos = 0;
+ if (!cursor.isNull()) {
+ if (options & QTextDocument::FindBackward)
+ pos = cursor.selectionStart();
+ else
+ pos = cursor.selectionEnd();
+ }
+ return find(expr, pos, options);
+}
+#endif // QT_NO_REGULAREXPRESSION
/*!
\fn QTextObject *QTextDocument::createObject(const QTextFormat &format)
diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h
index 2329a9e721..271c29b16b 100644
--- a/src/gui/text/qtextdocument.h
+++ b/src/gui/text/qtextdocument.h
@@ -160,10 +160,17 @@ public:
Q_DECLARE_FLAGS(FindFlags, FindFlag)
QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
- QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
+ QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = 0) const;
+#ifndef QT_NO_REGEXP
QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
- QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
+ QTextCursor find(const QRegExp &expr, const QTextCursor &cursor, FindFlags options = 0) const;
+#endif
+
+#ifndef QT_NO_REGULAREXPRESSION
+ QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = 0) const;
+ QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = 0) const;
+#endif
QTextFrame *frameAt(int pos) const;
QTextFrame *rootFrame() const;
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index 8ff15106e3..d30ff78b8f 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -125,14 +125,12 @@ static bool isValidBlockSeparator(QChar ch)
|| ch == QTextEndOfFrame;
}
-#if !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS)
static bool noBlockInString(const QString &str)
{
return !str.contains(QChar::ParagraphSeparator)
&& !str.contains(QTextBeginningOfFrame)
&& !str.contains(QTextEndOfFrame);
}
-#endif
bool QTextUndoCommand::tryMerge(const QTextUndoCommand &other)
{
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index d156124b98..ff84bc0cca 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1950,7 +1950,7 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix
if (feCache.prevFontEngine && feCache.prevFontEngine->type() == QFontEngine::Multi && feCache.prevScript == script) {
engine = feCache.prevFontEngine;
} else {
- engine = QFontEngineMultiBasicImpl::createMultiFontEngine(rawFont.d->fontEngine, script);
+ engine = QFontEngineMulti::createMultiFontEngine(rawFont.d->fontEngine, script);
feCache.prevFontEngine = engine;
feCache.prevScript = script;
engine->ref.ref();
@@ -1965,7 +1965,7 @@ QFontEngine *QTextEngine::fontEngine(const QScriptItem &si, QFixed *ascent, QFix
} else {
QFontEngine *scEngine = rawFont.d->fontEngine->cloneWithSize(smallCapsFraction * rawFont.pixelSize());
scEngine->ref.ref();
- scaledEngine = QFontEngineMultiBasicImpl::createMultiFontEngine(scEngine, script);
+ scaledEngine = QFontEngineMulti::createMultiFontEngine(scEngine, script);
scaledEngine->ref.ref();
feCache.prevScaledFontEngine = scaledEngine;
// If scEngine is not ref'ed by scaledEngine, make sure it is deallocated and not leaked.
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index cecfd85df1..1502758ee8 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -258,20 +258,6 @@ private:
friend QDataStream &operator>>(QDataStream &, QTextFormat &);
};
-// this is only safe because sizeof(int) == sizeof(float)
-static inline uint hash(float d)
-{
-#ifdef Q_CC_GNU
- // this is a GCC extension and isn't guaranteed to work in other compilers
- // the reinterpret_cast below generates a strict-aliasing warning with GCC
- union { float f; uint u; } cvt;
- cvt.f = d;
- return cvt.u;
-#else
- return reinterpret_cast<uint&>(d);
-#endif
-}
-
static inline uint hash(const QColor &color)
{
return (color.isValid()) ? color.rgba() : 0x234109;
@@ -279,7 +265,7 @@ static inline uint hash(const QColor &color)
static inline uint hash(const QPen &pen)
{
- return hash(pen.color()) + hash(pen.widthF());
+ return hash(pen.color()) + qHash(pen.widthF());
}
static inline uint hash(const QBrush &brush)
@@ -292,7 +278,7 @@ static inline uint variantHash(const QVariant &variant)
// simple and fast hash functions to differentiate between type and value
switch (variant.userType()) { // sorted by occurrence frequency
case QVariant::String: return qHash(variant.toString());
- case QVariant::Double: return hash(variant.toDouble());
+ case QVariant::Double: return qHash(variant.toDouble());
case QVariant::Int: return 0x811890 + variant.toInt();
case QVariant::Brush:
return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
@@ -303,7 +289,7 @@ static inline uint variantHash(const QVariant &variant)
case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
case QVariant::TextLength:
return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
- case QMetaType::Float: return hash(variant.toFloat());
+ case QMetaType::Float: return qHash(variant.toFloat());
case QVariant::Invalid: return 0;
default: break;
}