summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-04 11:17:47 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-08-04 11:17:47 (GMT)
commitbe212bf108e71ba3b5b75802b1f4de6613ba315c (patch)
treec541ad12e8698f04e8fe386c2e1b94e8baca6c1b /src/gui/text
parent67ae1b0dac175f48875507f3187ed49276a29ddf (diff)
parente6bb00250b321b149dd80259dc4f479088d5949b (diff)
downloadQt-be212bf108e71ba3b5b75802b1f4de6613ba315c.zip
Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.gz
Qt-be212bf108e71ba3b5b75802b1f4de6613ba315c.tar.bz2
Merge commit 'origin/master'
Conflicts: src/corelib/global/qglobal.h src/corelib/kernel/qmetatype.cpp src/corelib/kernel/qobject.cpp src/corelib/thread/qthread_unix.cpp src/gui/graphicsview/qgraphicssceneevent.h src/gui/itemviews/qheaderview.h src/gui/kernel/qapplication_qws.cpp src/gui/kernel/qgesture.h src/gui/kernel/qgesturerecognizer.h src/gui/painting/qpaintengine_raster.cpp src/network/access/qhttpnetworkreply.cpp src/network/access/qnetworkcookie.h src/network/socket/qnativesocketengine_unix.cpp
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qabstractfontengine_qws.h4
-rw-r--r--src/gui/text/qabstracttextdocumentlayout.h2
-rw-r--r--src/gui/text/qfontdatabase.cpp4
-rw-r--r--src/gui/text/qfontdatabase_qws.cpp86
-rw-r--r--src/gui/text/qfontdatabase_s60.cpp21
-rw-r--r--src/gui/text/qfontengine.cpp4
-rw-r--r--src/gui/text/qfontengine_ft.cpp19
-rw-r--r--src/gui/text/qfontengine_ft_p.h2
-rw-r--r--src/gui/text/qfontengine_s60.cpp8
-rw-r--r--src/gui/text/qfontengine_win.cpp11
-rw-r--r--src/gui/text/qfragmentmap_p.h13
-rw-r--r--src/gui/text/qsyntaxhighlighter.h2
-rw-r--r--src/gui/text/qtextcontrol_p.h2
-rw-r--r--src/gui/text/qtextdocument.h2
-rw-r--r--src/gui/text/qtextdocument_p.cpp76
-rw-r--r--src/gui/text/qtextdocumentlayout_p.h2
-rw-r--r--src/gui/text/qtextformat.cpp16
-rw-r--r--src/gui/text/qtextlist.h2
-rw-r--r--src/gui/text/qtextobject.h6
-rw-r--r--src/gui/text/qtexttable.cpp8
-rw-r--r--src/gui/text/qtexttable.h2
21 files changed, 162 insertions, 130 deletions
diff --git a/src/gui/text/qabstractfontengine_qws.h b/src/gui/text/qabstractfontengine_qws.h
index e6be611..8403f87 100644
--- a/src/gui/text/qabstractfontengine_qws.h
+++ b/src/gui/text/qabstractfontengine_qws.h
@@ -118,7 +118,7 @@ public:
virtual QList<QFontEngineInfo> availableFontEngines() const = 0;
private:
- Q_DECLARE_PRIVATE(QFontEnginePlugin)
+ Q_DECLARE_SCOPED_PRIVATE(QFontEnginePlugin)
Q_DISABLE_COPY(QFontEnginePlugin)
};
@@ -207,7 +207,7 @@ public:
*/
private:
- Q_DECLARE_PRIVATE(QAbstractFontEngine)
+ Q_DECLARE_SCOPED_PRIVATE(QAbstractFontEngine)
Q_DISABLE_COPY(QAbstractFontEngine)
};
diff --git a/src/gui/text/qabstracttextdocumentlayout.h b/src/gui/text/qabstracttextdocumentlayout.h
index 070c301..3681eec 100644
--- a/src/gui/text/qabstracttextdocumentlayout.h
+++ b/src/gui/text/qabstracttextdocumentlayout.h
@@ -62,7 +62,7 @@ class QTextFrame;
class Q_GUI_EXPORT QAbstractTextDocumentLayout : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QAbstractTextDocumentLayout)
+ Q_DECLARE_SCOPED_PRIVATE(QAbstractTextDocumentLayout)
public:
explicit QAbstractTextDocumentLayout(QTextDocument *doc);
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 844c3f9..d33cdf0 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -226,7 +226,9 @@ struct QtFontStyle
delete [] setwidthName;
#endif
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
- while (count--) {
+ while (count) {
+ // bitfield count-- in while condition does not work correctly in mwccsym2
+ count--;
#ifdef Q_WS_X11
free(pixelSizes[count].encodings);
#endif
diff --git a/src/gui/text/qfontdatabase_qws.cpp b/src/gui/text/qfontdatabase_qws.cpp
index 0407508..d731d21 100644
--- a/src/gui/text/qfontdatabase_qws.cpp
+++ b/src/gui/text/qfontdatabase_qws.cpp
@@ -762,21 +762,21 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
if (!privateDb()->count)
initializeDb();
- QFontEngine *fe = 0;
+ QScopedPointer<QFontEngine> fe;
if (fp) {
if (fp->rawMode) {
- fe = loadEngine(script, fp, request, 0, 0, 0, 0
- );
+ fe.reset(loadEngine(script, fp, request, 0, 0, 0, 0));
// if we fail to load the rawmode font, use a 12pixel box engine instead
- if (! fe) fe = new QFontEngineBox(12);
- return fe;
+ if (fe.isNull())
+ fe.reset(new QFontEngineBox(12));
+ return fe.take();
}
QFontCache::Key key(request, script);
- fe = QFontCache::instance()->findEngine(key);
- if (fe)
- return fe;
+ fe.reset(QFontCache::instance()->findEngine(key));
+ if (! fe.isNull())
+ return fe.take();
}
QString family_name, foundry_name;
@@ -800,11 +800,11 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
script, request.weight, request.style, request.stretch, request.pixelSize, pitch);
if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) {
- fe = new QTestFontEngine(request.pixelSize);
+ fe.reset(new QTestFontEngine(request.pixelSize));
fe->fontDef = request;
}
- if (!fe)
+ if (fe.isNull())
{
QtFontDesc desc;
match(script, request, family_name, foundry_name, force_encoding_id, &desc);
@@ -825,16 +825,28 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
'p', 0
);
- fe = loadEngine(script, fp, request, desc.family, desc.foundry, desc.style, desc.size
- );
+ fe.reset(loadEngine(script, fp, request, desc.family, desc.foundry, desc.style, desc.size
+ ));
} else {
FM_DEBUG(" NO MATCH FOUND\n");
}
- if (fe)
+ if (! fe.isNull())
initFontDef(desc, request, &fe->fontDef);
}
- if (fe) {
+#ifndef QT_NO_FREETYPE
+ if (! fe.isNull()) {
+ if (scriptRequiresOpenType(script) && fe->type() == QFontEngine::Freetype) {
+ HB_Face hbFace = static_cast<QFontEngineFT *>(fe.data())->harfbuzzFace();
+ if (!hbFace || !hbFace->supported_scripts[script]) {
+ FM_DEBUG(" OpenType support missing for script\n");
+ fe.reset(0);
+ }
+ }
+ }
+#endif
+
+ if (! fe.isNull()) {
if (fp) {
QFontDef def = request;
if (def.family.isEmpty()) {
@@ -842,32 +854,21 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
def.family = def.family.left(def.family.indexOf(QLatin1Char(',')));
}
QFontCache::Key key(def, script);
- QFontCache::instance()->insertEngine(key, fe);
- }
-
-#ifndef QT_NO_FREETYPE
- if (scriptRequiresOpenType(script) && fe->type() == QFontEngine::Freetype) {
- HB_Face hbFace = static_cast<QFontEngineFT *>(fe)->harfbuzzFace();
- if (!hbFace || !hbFace->supported_scripts[script]) {
- FM_DEBUG(" OpenType support missing for script\n");
- delete fe;
- fe = 0;
- }
+ QFontCache::instance()->insertEngine(key, fe.data());
}
-#endif
}
- if (!fe) {
+ if (fe.isNull()) {
if (!request.family.isEmpty())
return 0;
FM_DEBUG("returning box engine");
- fe = new QFontEngineBox(request.pixelSize);
+ fe.reset(new QFontEngineBox(request.pixelSize));
if (fp) {
QFontCache::Key key(request, script);
- QFontCache::instance()->insertEngine(key, fe);
+ QFontCache::instance()->insertEngine(key, fe.data());
}
}
@@ -877,7 +878,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
fe->fontDef.pointSize = request.pointSize;
}
- return fe;
+ return fe.take();
}
void QFontDatabase::load(const QFontPrivate *d, int script)
@@ -898,7 +899,13 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
if (!d->engineData) {
// create a new one
d->engineData = new QFontEngineData;
- QFontCache::instance()->insertEngineData(key, d->engineData);
+ QT_TRY {
+ QFontCache::instance()->insertEngineData(key, d->engineData);
+ } QT_CATCH(...) {
+ delete d->engineData;
+ d->engineData = 0;
+ QT_RETHROW;
+ }
} else {
d->engineData->ref.ref();
}
@@ -907,8 +914,6 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
// the cached engineData could have already loaded the engine we want
if (d->engineData->engines[script]) return;
- // load the font
- QFontEngine *engine = 0;
// double scale = 1.0; // ### TODO: fix the scale calculations
// list of families to try
@@ -940,20 +945,15 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
// null family means find the first font matching the specified script
family_list << QString();
+ // load the font
+ QFontEngine *engine = 0;
QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd();
- for (; ! engine && it != end; ++it) {
+ for (; !engine && it != end; ++it) {
req.family = *it;
engine = QFontDatabase::findFont(script, d, req);
- if (engine) {
- if (engine->type() != QFontEngine::Box)
- break;
-
- if (! req.family.isEmpty())
- engine = 0;
-
- continue;
- }
+ if (engine && (engine->type()==QFontEngine::Box) && !req.family.isEmpty())
+ engine = 0;
}
engine->ref.ref();
diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp
index 416c3d1..8176009 100644
--- a/src/gui/text/qfontdatabase_s60.cpp
+++ b/src/gui/text/qfontdatabase_s60.cpp
@@ -69,7 +69,7 @@ QFileInfoList alternativeFilePaths(const QString &path, const QStringList &nameF
const QString zDriveString("Z:/");
driveStrings.removeAll(zDriveString);
driveStrings.prepend(zDriveString);
-
+
QStringList uniqueFileNameList;
for (int i = driveStrings.count() - 1; i >= 0; --i) {
const QDir dirOnDrive(driveStrings.at(i) + path);
@@ -107,9 +107,12 @@ private:
QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation()
{
m_heap = User::ChunkHeap(NULL, 0x1000, 0x100000);
- m_store = CFontStore::NewL(m_heap);
- m_rasterizer = COpenFontRasterizer::NewL(TUid::Uid(0x101F7F5E));
- m_store->InstallRasterizerL(m_rasterizer);
+ QT_TRAP_THROWING(
+ m_store = CFontStore::NewL(m_heap);
+ m_rasterizer = COpenFontRasterizer::NewL(TUid::Uid(0x101F7F5E));
+ CleanupStack::PushL(m_rasterizer);
+ m_store->InstallRasterizerL(m_rasterizer);
+ CleanupStack::Pop(m_rasterizer););
QStringList filters;
filters.append(QString::fromLatin1("*.ttf"));
@@ -117,14 +120,14 @@ QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation()
const QFileInfoList fontFiles = alternativeFilePaths(QString::fromLatin1("resource\\Fonts"), filters);
foreach (const QFileInfo &fontFileInfo, fontFiles) {
const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath());
- m_store->AddFileL(qt_QString2TPtrC(fontFile));
+ TPtrC fontFilePtr(qt_QString2TPtrC(fontFile));
+ QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr));
}
}
QFontDatabaseS60StoreImplementation::~QFontDatabaseS60StoreImplementation()
{
qDeleteAll(m_extensions);
- delete m_rasterizer;
- delete m_store;
+ // TODO m_store cleanup removed because it was crashing
m_heap->Close();
}
@@ -218,7 +221,7 @@ static void initializeDb()
QS60Data::screenDevice()->TypefaceSupport(typefaceSupport, i);
CFont *font; // We have to get a font instance in order to know all the details
TFontSpec fontSpec(typefaceSupport.iTypeface.iName, 11);
- QS60Data::screenDevice()->GetNearestFontInPixels(font, fontSpec);
+ qt_throwIfError(QS60Data::screenDevice()->GetNearestFontInPixels(font, fontSpec));
if (font->TypeUid() == KCFbsFontUid) {
TOpenFontFaceAttrib faceAttrib;
const CFbsFont *cfbsFont = dynamic_cast<const CFbsFont *>(font);
@@ -390,7 +393,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
{
QFontEngine *fe = 0;
QFontDef req = d->request;
-
+
if (!d->engineData) {
const QFontCache::Key key(cleanedFontDef(req), script);
getEngineData(d, key);
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 730137e..794fd79 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -236,8 +236,10 @@ HB_Font QFontEngine::harfbuzzFont() const
HB_Face QFontEngine::harfbuzzFace() const
{
- if (!hbFace)
+ if (!hbFace) {
hbFace = qHBNewFace(const_cast<QFontEngine *>(this), hb_getSFntTable);
+ Q_CHECK_PTR(hbFace);
+ }
return hbFace;
}
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 499d28c..4c4438a 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -205,7 +205,9 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id)
FT_Init_FreeType(&freetypeData->library);
QFreetypeFace *freetype = freetypeData->faces.value(face_id, 0);
- if (!freetype) {
+ if (freetype) {
+ freetype->ref.ref();
+ } else {
QScopedPointer<QFreetypeFace> newFreetype(new QFreetypeFace);
FT_Face face;
QFile file(QString::fromUtf8(face_id.filename));
@@ -234,7 +236,8 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id)
newFreetype->face = face;
newFreetype->hbFace = qHBNewFace(face, hb_getSFntTable);
- newFreetype->ref = 0;
+ Q_CHECK_PTR(newFreetype->hbFace);
+ newFreetype->ref = 1;
newFreetype->xsize = 0;
newFreetype->ysize = 0;
newFreetype->matrix.xx = 0x10000;
@@ -289,10 +292,15 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id)
#endif
FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map);
- freetypeData->faces.insert(face_id, newFreetype.data());
+ QT_TRY {
+ freetypeData->faces.insert(face_id, newFreetype.data());
+ } QT_CATCH(...) {
+ newFreetype.take()->release(face_id);
+ // we could return null in principle instead of throwing
+ QT_RETHROW;
+ }
freetype = newFreetype.take();
}
- freetype->ref.ref();
return freetype;
}
@@ -306,7 +314,8 @@ void QFreetypeFace::release(const QFontEngine::FaceId &face_id)
if (charset)
FcCharSetDestroy(charset);
#endif
- freetypeData->faces.take(face_id);
+ if(freetypeData->faces.contains(face_id))
+ freetypeData->faces.take(face_id);
delete this;
}
if (freetypeData->faces.isEmpty()) {
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index aa1cd0a..0572e92 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -119,7 +119,7 @@ struct QFreetypeFace
static void addBitmapToPath(FT_GlyphSlot slot, const QFixedPoint &point, QPainterPath *path, bool = false);
private:
- friend class QScopedPointer<QFreetypeFace>;
+ friend class QScopedPointerDeleter<QFreetypeFace>;
QFreetypeFace() : _lock(QMutex::Recursive) {}
~QFreetypeFace() {}
QAtomicInt ref;
diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp
index f485afb..d1e591e 100644
--- a/src/gui/text/qfontengine_s60.cpp
+++ b/src/gui/text/qfontengine_s60.cpp
@@ -130,11 +130,11 @@ QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Exte
m_fontSizeInPixels = (request.pixelSize >= 0)?
request.pixelSize:pointsToPixels(request.pointSize);
QS60WindowSurface::unlockBitmapHeap();
- m_textRenderBitmap = new (ELeave) CFbsBitmap();
+ m_textRenderBitmap = q_check_ptr(new CFbsBitmap()); // CBase derived object needs check on new
const TSize bitmapSize(1, 1); // It is just a dummy bitmap that I need to keep the font alive (or maybe not)
- User::LeaveIfError(m_textRenderBitmap->Create(bitmapSize, EGray256));
- m_textRenderBitmapDevice = CFbsBitmapDevice::NewL(m_textRenderBitmap);
- User::LeaveIfError(m_textRenderBitmapDevice->CreateContext(m_textRenderBitmapGc));
+ qt_throwIfError(m_textRenderBitmap->Create(bitmapSize, EGray256));
+ QT_TRAP_THROWING(m_textRenderBitmapDevice = CFbsBitmapDevice::NewL(m_textRenderBitmap));
+ qt_throwIfError(m_textRenderBitmapDevice->CreateContext(m_textRenderBitmapGc));
cache_cost = sizeof(QFontEngineS60) + bitmapSize.iHeight * bitmapSize.iWidth * 4;
TFontSpec fontSpec(qt_QString2TPtrC(request.family), m_fontSizeInPixels);
diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp
index c6717e3..c42326f 100644
--- a/src/gui/text/qfontengine_win.cpp
+++ b/src/gui/text/qfontengine_win.cpp
@@ -390,7 +390,7 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
unsigned int glyph = glyphs->glyphs[glyph_pos];
if(int(glyph) >= designAdvancesSize) {
int newSize = (glyph + 256) >> 8 << 8;
- designAdvances = (QFixed *)realloc(designAdvances, newSize*sizeof(QFixed));
+ designAdvances = q_check_ptr((QFixed *)realloc(designAdvances, newSize*sizeof(QFixed)));
for(int i = designAdvancesSize; i < newSize; ++i)
designAdvances[i] = -1000000;
designAdvancesSize = newSize;
@@ -423,7 +423,8 @@ bool QFontEngineWin::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
if (glyph >= widthCacheSize) {
int newSize = (glyph + 256) >> 8 << 8;
- widthCache = (unsigned char *)realloc(widthCache, newSize*sizeof(QFixed));
+ widthCache = q_check_ptr((unsigned char *)realloc(widthCache,
+ newSize*sizeof(QFixed)));
memset(widthCache + widthCacheSize, 0, newSize - widthCacheSize);
widthCacheSize = newSize;
}
@@ -463,7 +464,8 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
unsigned int glyph = glyphs->glyphs[i];
if(int(glyph) >= designAdvancesSize) {
int newSize = (glyph + 256) >> 8 << 8;
- designAdvances = (QFixed *)realloc(designAdvances, newSize*sizeof(QFixed));
+ designAdvances = q_check_ptr((QFixed *)realloc(designAdvances,
+ newSize*sizeof(QFixed)));
for(int i = designAdvancesSize; i < newSize; ++i)
designAdvances[i] = -1000000;
designAdvancesSize = newSize;
@@ -490,7 +492,8 @@ void QFontEngineWin::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla
if (glyph >= widthCacheSize) {
int newSize = (glyph + 256) >> 8 << 8;
- widthCache = (unsigned char *)realloc(widthCache, newSize*sizeof(QFixed));
+ widthCache = q_check_ptr((unsigned char *)realloc(widthCache,
+ newSize*sizeof(QFixed)));
memset(widthCache + widthCacheSize, 0, newSize - widthCacheSize);
widthCacheSize = newSize;
}
diff --git a/src/gui/text/qfragmentmap_p.h b/src/gui/text/qfragmentmap_p.h
index c2ba2b4..9c2a673 100644
--- a/src/gui/text/qfragmentmap_p.h
+++ b/src/gui/text/qfragmentmap_p.h
@@ -222,13 +222,19 @@ QFragmentMapData<Fragment>::QFragmentMapData()
template <class Fragment>
void QFragmentMapData<Fragment>::init()
{
- fragments = (Fragment *)malloc(64*fragmentSize);
+ // the following code will realloc an existing fragment or create a new one.
+ // it will also ignore errors when shrinking an existing fragment.
+ Fragment *newFragments = (Fragment *)realloc(fragments, 64*fragmentSize);
+ if (newFragments) {
+ fragments = newFragments;
+ head->allocated = 64;
+ }
Q_CHECK_PTR(fragments);
+
head->tag = (((quint32)'p') << 24) | (((quint32)'m') << 16) | (((quint32)'a') << 8) | 'p'; //TAG('p', 'm', 'a', 'p');
head->root = 0;
head->freelist = 1;
head->node_count = 0;
- head->allocated = 64;
// mark all items to the right as unused
F(head->freelist).right = 0;
}
@@ -236,7 +242,7 @@ void QFragmentMapData<Fragment>::init()
template <class Fragment>
QFragmentMapData<Fragment>::~QFragmentMapData()
{
- free(head);
+ free(fragments);
}
template <class Fragment>
@@ -800,7 +806,6 @@ public:
inline void clear() {
for (Iterator it = begin(); !it.atEnd(); ++it)
it.value()->free();
- ::free(data.head);
data.init();
}
diff --git a/src/gui/text/qsyntaxhighlighter.h b/src/gui/text/qsyntaxhighlighter.h
index ee249b8..bfbb533 100644
--- a/src/gui/text/qsyntaxhighlighter.h
+++ b/src/gui/text/qsyntaxhighlighter.h
@@ -66,7 +66,7 @@ class QTextEdit;
class Q_GUI_EXPORT QSyntaxHighlighter : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QSyntaxHighlighter)
+ Q_DECLARE_SCOPED_PRIVATE(QSyntaxHighlighter)
public:
QSyntaxHighlighter(QObject *parent);
QSyntaxHighlighter(QTextDocument *parent);
diff --git a/src/gui/text/qtextcontrol_p.h b/src/gui/text/qtextcontrol_p.h
index eb0d749..59693ac 100644
--- a/src/gui/text/qtextcontrol_p.h
+++ b/src/gui/text/qtextcontrol_p.h
@@ -86,7 +86,7 @@ class QTimerEvent;
class Q_GUI_EXPORT QTextControl : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QTextControl)
+ Q_DECLARE_SCOPED_PRIVATE(QTextControl)
#ifndef QT_NO_TEXTHTMLPARSER
Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
#endif
diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h
index 40b6621..cfbb558 100644
--- a/src/gui/text/qtextdocument.h
+++ b/src/gui/text/qtextdocument.h
@@ -286,7 +286,7 @@ public:
QTextDocumentPrivate *docHandle() const;
private:
Q_DISABLE_COPY(QTextDocument)
- Q_DECLARE_PRIVATE(QTextDocument)
+ Q_DECLARE_SCOPED_PRIVATE(QTextDocument)
friend class QTextObjectPrivate;
};
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index e66b07c..88afe4a 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -188,6 +188,7 @@ QTextDocumentPrivate::QTextDocumentPrivate()
docChangeOldLength(0),
docChangeLength(0),
framesDirty(true),
+ rtFrame(0),
initialBlockCharFormatIndex(-1) // set correctly later in init()
{
editBlock = 0;
@@ -218,7 +219,6 @@ QTextDocumentPrivate::QTextDocumentPrivate()
void QTextDocumentPrivate::init()
{
- rtFrame = 0;
framesDirty = false;
bool undoState = undoEnabled;
@@ -241,42 +241,48 @@ void QTextDocumentPrivate::clear()
}
QList<QTextCursorPrivate *>oldCursors = cursors;
- cursors.clear();
- changedCursors.clear();
-
- QMap<int, QTextObject *>::Iterator objectIt = objects.begin();
- while (objectIt != objects.end()) {
- if (*objectIt != rtFrame) {
- delete *objectIt;
- objectIt = objects.erase(objectIt);
- } else {
- ++objectIt;
+ QT_TRY{
+ cursors.clear();
+ changedCursors.clear();
+
+ QMap<int, QTextObject *>::Iterator objectIt = objects.begin();
+ while (objectIt != objects.end()) {
+ if (*objectIt != rtFrame) {
+ delete *objectIt;
+ objectIt = objects.erase(objectIt);
+ } else {
+ ++objectIt;
+ }
}
- }
- // also clear out the remaining root frame pointer
- // (we're going to delete the object further down)
- objects.clear();
+ // also clear out the remaining root frame pointer
+ // (we're going to delete the object further down)
+ objects.clear();
- title.clear();
- undoState = 0;
- truncateUndoStack();
- text = QString();
- unreachableCharacterCount = 0;
- modifiedState = 0;
- modified = false;
- formats = QTextFormatCollection();
- int len = fragments.length();
- fragments.clear();
- blocks.clear();
- cachedResources.clear();
- delete rtFrame;
- init();
- cursors = oldCursors;
- inContentsChange = true;
- q->contentsChange(0, len, 0);
- inContentsChange = false;
- if (lout)
- lout->documentChanged(0, len, 0);
+ title.clear();
+ undoState = 0;
+ truncateUndoStack();
+ text = QString();
+ unreachableCharacterCount = 0;
+ modifiedState = 0;
+ modified = false;
+ formats = QTextFormatCollection();
+ int len = fragments.length();
+ fragments.clear();
+ blocks.clear();
+ cachedResources.clear();
+ delete rtFrame;
+ rtFrame = 0;
+ init();
+ cursors = oldCursors;
+ inContentsChange = true;
+ q->contentsChange(0, len, 0);
+ inContentsChange = false;
+ if (lout)
+ lout->documentChanged(0, len, 0);
+ } QT_CATCH(...) {
+ cursors = oldCursors; // at least recover the cursors
+ QT_RETHROW;
+ }
}
QTextDocumentPrivate::~QTextDocumentPrivate()
diff --git a/src/gui/text/qtextdocumentlayout_p.h b/src/gui/text/qtextdocumentlayout_p.h
index 41507b0..4dc18d0 100644
--- a/src/gui/text/qtextdocumentlayout_p.h
+++ b/src/gui/text/qtextdocumentlayout_p.h
@@ -65,7 +65,7 @@ class QTextDocumentLayoutPrivate;
class Q_AUTOTEST_EXPORT QTextDocumentLayout : public QAbstractTextDocumentLayout
{
- Q_DECLARE_PRIVATE(QTextDocumentLayout)
+ Q_DECLARE_SCOPED_PRIVATE(QTextDocumentLayout)
Q_OBJECT
Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
Q_PROPERTY(qreal idealWidth READ idealWidth)
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index a3dd83e..7f82365 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -3041,12 +3041,18 @@ int QTextFormatCollection::indexForFormat(const QTextFormat &format)
int idx = formats.size();
formats.append(format);
- QTextFormat &f = formats.last();
- if (!f.d)
- f.d = new QTextFormatPrivate;
- f.d->resolveFont(defaultFnt);
+ QT_TRY{
+ QTextFormat &f = formats.last();
+ if (!f.d)
+ f.d = new QTextFormatPrivate;
+ f.d->resolveFont(defaultFnt);
- hashes.insert(hash);
+ hashes.insert(hash);
+
+ } QT_CATCH(...) {
+ formats.pop_back();
+ QT_RETHROW;
+ }
return idx;
}
diff --git a/src/gui/text/qtextlist.h b/src/gui/text/qtextlist.h
index 04f1838..3d07be8 100644
--- a/src/gui/text/qtextlist.h
+++ b/src/gui/text/qtextlist.h
@@ -81,7 +81,7 @@ public:
private:
Q_DISABLE_COPY(QTextList)
- Q_DECLARE_PRIVATE(QTextList)
+ Q_DECLARE_SCOPED_PRIVATE(QTextList)
};
inline void QTextList::setFormat(const QTextListFormat &aformat)
diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h
index 4f239b2..f22f77c 100644
--- a/src/gui/text/qtextobject.h
+++ b/src/gui/text/qtextobject.h
@@ -84,7 +84,7 @@ protected:
QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
private:
- Q_DECLARE_PRIVATE(QTextObject)
+ Q_DECLARE_SCOPED_PRIVATE(QTextObject)
Q_DISABLE_COPY(QTextObject)
friend class QTextDocumentPrivate;
};
@@ -107,7 +107,7 @@ protected:
protected:
QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
private:
- Q_DECLARE_PRIVATE(QTextBlockGroup)
+ Q_DECLARE_SCOPED_PRIVATE(QTextBlockGroup)
Q_DISABLE_COPY(QTextBlockGroup)
friend class QTextDocumentPrivate;
};
@@ -182,7 +182,7 @@ protected:
QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
private:
friend class QTextDocumentPrivate;
- Q_DECLARE_PRIVATE(QTextFrame)
+ Q_DECLARE_SCOPED_PRIVATE(QTextFrame)
Q_DISABLE_COPY(QTextFrame)
};
Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp
index 11ea2a7..160eb35 100644
--- a/src/gui/text/qtexttable.cpp
+++ b/src/gui/text/qtexttable.cpp
@@ -446,9 +446,7 @@ void QTextTablePrivate::update() const
nRows = (cells.size() + nCols-1)/nCols;
// qDebug(">>>> QTextTablePrivate::update, nRows=%d, nCols=%d", nRows, nCols);
- int* newGrid = (int *)realloc(grid, nRows*nCols*sizeof(int));
- Q_CHECK_PTR(newGrid);
- grid = newGrid;
+ grid = q_check_ptr((int *)realloc(grid, nRows*nCols*sizeof(int)));
memset(grid, 0, nRows*nCols*sizeof(int));
QTextDocumentPrivate *p = pieceTable;
@@ -472,9 +470,7 @@ void QTextTablePrivate::update() const
cellIndices[i] = cell;
if (r + rowspan > nRows) {
- newGrid = (int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols);
- Q_CHECK_PTR(newGrid);
- grid = newGrid;
+ grid = q_check_ptr((int *)realloc(grid, sizeof(int)*(r + rowspan)*nCols));
memset(grid + (nRows*nCols), 0, sizeof(int)*(r+rowspan-nRows)*nCols);
nRows = r + rowspan;
}
diff --git a/src/gui/text/qtexttable.h b/src/gui/text/qtexttable.h
index 612c71c..2deb3fa 100644
--- a/src/gui/text/qtexttable.h
+++ b/src/gui/text/qtexttable.h
@@ -134,7 +134,7 @@ public:
private:
Q_DISABLE_COPY(QTextTable)
- Q_DECLARE_PRIVATE(QTextTable)
+ Q_DECLARE_SCOPED_PRIVATE(QTextTable)
friend class QTextTableCell;
};