summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2009-05-19 14:45:28 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2009-05-19 14:45:28 (GMT)
commit8821284ac4e55caf5fe712fca002e79220e9cf7e (patch)
treeb1d82e77ee04ee50b24298ae58f46c0980ec0e5d /src/gui/text
parent2c5b7fe040575aa2ee560117c1c3455724c2f9ae (diff)
parent13f703741dee67adc7d92e4bcf525431334c9a60 (diff)
downloadQt-8821284ac4e55caf5fe712fca002e79220e9cf7e.zip
Qt-8821284ac4e55caf5fe712fca002e79220e9cf7e.tar.gz
Qt-8821284ac4e55caf5fe712fca002e79220e9cf7e.tar.bz2
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt into 4.5
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qcssparser.cpp35
-rw-r--r--src/gui/text/qfont.cpp10
-rw-r--r--src/gui/text/qfontdatabase_win.cpp12
-rw-r--r--src/gui/text/qfontdatabase_x11.cpp2
-rw-r--r--src/gui/text/qfontengine.cpp39
-rw-r--r--src/gui/text/qfontengine_ft.cpp53
-rw-r--r--src/gui/text/qfontengine_mac.mm31
-rw-r--r--src/gui/text/qfontengine_p.h4
-rw-r--r--src/gui/text/qfontengine_win.cpp6
-rw-r--r--src/gui/text/qtextcursor.cpp5
-rw-r--r--src/gui/text/qtextdocument.cpp2
-rw-r--r--src/gui/text/qtextformat.cpp2
-rw-r--r--src/gui/text/qtextformat.h6
-rw-r--r--src/gui/text/qtextlayout.cpp62
-rw-r--r--src/gui/text/qtextobject.cpp2
-rw-r--r--src/gui/text/qtexttable.cpp7
16 files changed, 205 insertions, 73 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index db1e781..38621c1 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -278,19 +278,15 @@ static const QCssKnownValue values[NumKnownValues - 1] = {
{ "xx-large", Value_XXLarge }
};
+//Map id to strings as they appears in the 'values' array above
+static const int indexOfId[NumKnownValues] = { 0, 40, 47, 41, 48, 53, 34, 26, 68, 69, 25, 42, 5, 62, 46,
+ 29, 57, 58, 27, 50, 60, 6, 10, 38, 55, 19, 13, 17, 18, 20, 21, 49, 24, 45, 65, 36, 3, 2, 39, 61, 16,
+ 11, 56, 14, 32, 63, 54, 64, 33, 67, 8, 28, 37, 12, 35, 59, 7, 9, 4, 66, 52, 22, 23, 30, 31, 1, 15, 0,
+ 51, 44, 43 };
+
QString Value::toString() const
{
- static int indexOfId[NumKnownValues - 1];
- static bool hasCachedIndexes = false;
-
if (type == KnownIdentifier) {
- if (!hasCachedIndexes) {
- for (int i = 0; i < NumKnownValues - 1; ++i)
- indexOfId[values[i].id] = i;
-
- hasCachedIndexes = true;
- }
-
return QLatin1String(values[indexOfId[variant.toInt()]].name);
} else {
return variant.toString();
@@ -1165,13 +1161,20 @@ static bool setFontWeightFromValue(const Value &value, QFont *font)
return true;
}
-static bool setFontFamilyFromValues(const QVector<Value> &values, QFont *font)
+/** \internal
+ * parse the font family from the values (starting from index \a start)
+ * and set it the \a font
+ * \returns true if a family was extracted.
+ */
+static bool setFontFamilyFromValues(const QVector<Value> &values, QFont *font, int start = 0)
{
QString family;
- for (int i = 0; i < values.count(); ++i) {
+ for (int i = start; i < values.count(); ++i) {
const Value &v = values.at(i);
- if (v.type == Value::TermOperatorComma)
- break;
+ if (v.type == Value::TermOperatorComma) {
+ family += QLatin1Char(',');
+ continue;
+ }
const QString str = v.variant.toString();
if (str.isEmpty())
break;
@@ -1225,9 +1228,7 @@ static void parseShorthandFontProperty(const QVector<Value> &values, QFont *font
}
if (i < values.count()) {
- QString fam = values.at(i).variant.toString();
- if (!fam.isEmpty())
- font->setFamily(fam);
+ setFontFamilyFromValues(values, font, i);
}
}
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 43f5b1e..f73ffb5 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -890,7 +890,10 @@ int QFont::pointSize() const
*/
void QFont::setPointSize(int pointSize)
{
- Q_ASSERT_X (pointSize > 0, "QFont::setPointSize", "point size must be greater than 0");
+ if (pointSize <= 0) {
+ qWarning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize);
+ return;
+ }
detach();
@@ -909,7 +912,10 @@ void QFont::setPointSize(int pointSize)
*/
void QFont::setPointSizeF(qreal pointSize)
{
- Q_ASSERT_X(pointSize > 0.0, "QFont::setPointSizeF", "point size must be greater than 0");
+ if (pointSize <= 0) {
+ qWarning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize);
+ return;
+ }
detach();
diff --git a/src/gui/text/qfontdatabase_win.cpp b/src/gui/text/qfontdatabase_win.cpp
index c9f5586..780ae28 100644
--- a/src/gui/text/qfontdatabase_win.cpp
+++ b/src/gui/text/qfontdatabase_win.cpp
@@ -699,6 +699,7 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
}
bool stockFont = false;
+ bool preferClearTypeAA = false;
HFONT hfont = 0;
@@ -799,10 +800,12 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
#endif
if (request.styleStrategy & QFont::PreferAntialias) {
- if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP)
+ if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) {
qual = 5; // == CLEARTYPE_QUALITY;
- else
+ preferClearTypeAA = true;
+ } else {
qual = ANTIALIASED_QUALITY;
+ }
} else if (request.styleStrategy & QFont::NoAntialias) {
qual = NONANTIALIASED_QUALITY;
}
@@ -884,6 +887,9 @@ QFontEngine *loadEngine(int script, const QFontPrivate *fp, const QFontDef &requ
}
QFontEngineWin *few = new QFontEngineWin(font_name, hfont, stockFont, lf);
+ if (preferClearTypeAA)
+ few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask;
+
// Also check for OpenType tables when using complex scripts
// ### TODO: This only works for scripts that require OpenType. More generally
// for scripts that do not require OpenType we should just look at the list of
@@ -1134,7 +1140,7 @@ static void getFamiliesAndSignatures(const QByteArray &fontData, QFontDatabasePr
signature.fsUsb[1] = qFromBigEndian<quint32>(table + 46);
signature.fsUsb[2] = qFromBigEndian<quint32>(table + 50);
signature.fsUsb[3] = qFromBigEndian<quint32>(table + 54);
-
+
signature.fsCsb[0] = qFromBigEndian<quint32>(table + 78);
signature.fsCsb[1] = qFromBigEndian<quint32>(table + 82);
}
diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp
index 15e626e..70e1599 100644
--- a/src/gui/text/qfontdatabase_x11.cpp
+++ b/src/gui/text/qfontdatabase_x11.cpp
@@ -494,7 +494,7 @@ static inline bool isFixedPitch(char **tokens)
Fills in a font definition (QFontDef) from an XLFD (X Logical Font
Description).
- Returns true if the the given xlfd is valid.
+ Returns true if the given xlfd is valid.
*/
bool qt_fillFontDef(const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc)
{
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 47fe5c2..d7a9c23 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -624,6 +624,45 @@ QImage QFontEngine::alphaRGBMapForGlyph(glyph_t glyph, int /* margin */, const Q
return rgbMask;
}
+QImage QFontEngine::alphaMapForGlyph(glyph_t glyph)
+{
+ glyph_metrics_t gm = boundingBox(glyph);
+ int glyph_x = qFloor(gm.x.toReal());
+ int glyph_y = qFloor(gm.y.toReal());
+ int glyph_width = qCeil((gm.x + gm.width).toReal()) - glyph_x;
+ int glyph_height = qCeil((gm.y + gm.height).toReal()) - glyph_y;
+
+ if (glyph_width <= 0 || glyph_height <= 0)
+ return QImage();
+ QFixedPoint pt;
+ pt.x = 0;
+ pt.y = -glyph_y; // the baseline
+ QPainterPath path;
+ QImage im(glyph_width + qAbs(glyph_x) + 4, glyph_height, QImage::Format_ARGB32_Premultiplied);
+ im.fill(Qt::transparent);
+ QPainter p(&im);
+ p.setRenderHint(QPainter::Antialiasing);
+ addGlyphsToPath(&glyph, &pt, 1, &path, 0);
+ p.setPen(Qt::NoPen);
+ p.setBrush(Qt::black);
+ 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);
+
+ for (int y=0; y<im.height(); ++y) {
+ uchar *dst = (uchar *) indexed.scanLine(y);
+ uint *src = (uint *) im.scanLine(y);
+ for (int x=0; x<im.width(); ++x)
+ dst[x] = qAlpha(src[x]);
+ }
+
+ return indexed;
+}
void QFontEngine::removeGlyphFromCache(glyph_t)
{
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index cb0b436..6f5ee1f 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -613,7 +613,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd)
subpixelType = Subpixel_None;
lcdFilterType = 0;
#if defined(FT_LCD_FILTER_H)
- lcdFilterType = (int) FT_LCD_FILTER_DEFAULT;
+ lcdFilterType = (int)((quintptr) FT_LCD_FILTER_DEFAULT);
#endif
defaultFormat = Format_None;
canUploadGlyphsToServer = false;
@@ -1521,6 +1521,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
return false;
}
+#if !defined(QT_NO_FONTCONFIG)
+ extern QMutex *qt_fontdatabase_mutex();
+ QMutex *mtx = 0;
+#endif
+
bool mirrored = flags & QTextEngine::RightToLeft;
int glyph_pos = 0;
if (freetype->symbol_map) {
@@ -1533,6 +1538,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
if ( !glyphs->glyphs[glyph_pos] ) {
glyph_t glyph;
#if !defined(QT_NO_FONTCONFIG)
+ if (!mtx) {
+ mtx = qt_fontdatabase_mutex();
+ mtx->lock();
+ }
+
if (FcCharSetHasChar(freetype->charset, uc)) {
#else
if (false) {
@@ -1561,20 +1571,26 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
if (mirrored)
uc = QChar::mirroredChar(uc);
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
- if (!glyphs->glyphs[glyph_pos]
+ if (!glyphs->glyphs[glyph_pos]) {
#if !defined(QT_NO_FONTCONFIG)
- && FcCharSetHasChar(freetype->charset, uc)
+ if (!mtx) {
+ mtx = qt_fontdatabase_mutex();
+ mtx->lock();
+ }
+
+ if (FcCharSetHasChar(freetype->charset, uc))
#endif
- ) {
- redo:
- glyph_t glyph = FT_Get_Char_Index(face, uc);
- if (!glyph && (uc == 0xa0 || uc == 0x9)) {
- uc = 0x20;
- goto redo;
+ {
+ redo:
+ glyph_t glyph = FT_Get_Char_Index(face, uc);
+ if (!glyph && (uc == 0xa0 || uc == 0x9)) {
+ uc = 0x20;
+ goto redo;
+ }
+ glyphs->glyphs[glyph_pos] = glyph;
+ if (uc < QFreetypeFace::cmapCacheSize)
+ freetype->cmapCache[uc] = glyph;
}
- glyphs->glyphs[glyph_pos] = glyph;
- if (uc < QFreetypeFace::cmapCacheSize)
- freetype->cmapCache[uc] = glyph;
}
++glyph_pos;
}
@@ -1583,6 +1599,11 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
*nglyphs = glyph_pos;
glyphs->numGlyphs = glyph_pos;
+#if !defined(QT_NO_FONTCONFIG)
+ if (mtx)
+ mtx->unlock();
+#endif
+
if (flags & QTextEngine::GlyphIndicesOnly)
return true;
@@ -1788,9 +1809,11 @@ QImage QFontEngineFT::alphaMapForGlyph(glyph_t g)
GlyphFormat glyph_format = antialias ? Format_A8 : Format_Mono;
- Glyph *glyph = loadGlyph(g, glyph_format);
- if (!glyph)
- return QImage();
+ Glyph *glyph = defaultGlyphSet.outline_drawing ? 0 : loadGlyph(g, glyph_format);
+ if (!glyph) {
+ unlockFace();
+ return QFontEngine::alphaMapForGlyph(g);
+ }
const int pitch = antialias ? (glyph->width + 3) & ~3 : ((glyph->width + 31)/32) * 4;
diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm
index 40d145a..425cab2 100644
--- a/src/gui/text/qfontengine_mac.mm
+++ b/src/gui/text/qfontengine_mac.mm
@@ -120,7 +120,7 @@ OSStatus QMacFontPath::closePath(void *data)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool)
+QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning)
: QFontEngineMulti(0)
{
this->fontDef = fontDef;
@@ -149,11 +149,15 @@ QCoreTextFontEngineMulti::QCoreTextFontEngineMulti(const ATSFontFamilyRef &, con
CFRetain(ctfont);
}
- const void *keys[] = { NSFontAttributeName };
- const void *values[] = { ctfont };
- attributeDict = CFDictionaryCreate(0, keys, values, 1,
+ attributeDict = CFDictionaryCreateMutable(0, 2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
+ CFDictionaryAddValue(attributeDict, NSFontAttributeName, ctfont);
+ if (!kerning) {
+ float zero = 0.0;
+ QCFType<CFNumberRef> noKern = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero);
+ CFDictionaryAddValue(attributeDict, kCTKernAttributeName, &noKern);
+ }
QCoreTextFontEngine *fe = new QCoreTextFontEngine(ctfont, fontDef, this);
fe->ref.ref();
@@ -277,10 +281,11 @@ bool QCoreTextFontEngineMulti::stringToCMap(const QChar *str, int len, QGlyphLay
outAdvances_x[idx] = QFixed::fromReal(tmpPoints[i + 1].x - tmpPoints[i].x);
outAdvances_y[idx] = QFixed::fromReal(tmpPoints[i + 1].y - tmpPoints[i].y);
}
- double runWidth = ceil(CTRunGetTypographicBounds(run, range, 0, 0, 0));
- runWidth += tmpPoints[0].x;
+ CGSize lastGlyphAdvance;
+ CTFontGetAdvancesForGlyphs(runFont, kCTFontHorizontalOrientation, tmpGlyphs + glyphCount - 1, &lastGlyphAdvance, 1);
+
outGlyphs[rtl ? 0 : (glyphCount - 1)] = tmpGlyphs[glyphCount - 1] | fontIndex;
- outAdvances_x[rtl ? 0 : (glyphCount - 1)] = QFixed::fromReal(runWidth - tmpPoints[glyphCount - 1].x);
+ outAdvances_x[rtl ? 0 : (glyphCount - 1)] = QFixed::fromReal(lastGlyphAdvance.width).ceil();
}
outGlyphs += glyphCount;
outAttributes += glyphCount;
@@ -365,26 +370,26 @@ glyph_metrics_t QCoreTextFontEngine::boundingBox(glyph_t glyph)
ret.y = -QFixed::fromReal(rect.origin.y) - ret.height;
CGSize advances[1];
CTFontGetAdvancesForGlyphs(ctfont, kCTFontHorizontalOrientation, &g, advances, 1);
- ret.xoff = QFixed::fromReal(advances[0].width);
- ret.yoff = QFixed::fromReal(advances[0].height);
+ ret.xoff = QFixed::fromReal(advances[0].width).ceil();
+ ret.yoff = QFixed::fromReal(advances[0].height).ceil();
return ret;
}
QFixed QCoreTextFontEngine::ascent() const
{
- return QFixed::fromReal(CTFontGetAscent(ctfont));
+ return QFixed::fromReal(CTFontGetAscent(ctfont)).ceil();
}
QFixed QCoreTextFontEngine::descent() const
{
- return QFixed::fromReal(CTFontGetDescent(ctfont));
+ return QFixed::fromReal(CTFontGetDescent(ctfont)).ceil();
}
QFixed QCoreTextFontEngine::leading() const
{
- return QFixed::fromReal(CTFontGetLeading(ctfont));
+ return QFixed::fromReal(CTFontGetLeading(ctfont)).ceil();
}
QFixed QCoreTextFontEngine::xHeight() const
{
- return QFixed::fromReal(CTFontGetXHeight(ctfont));
+ return QFixed::fromReal(CTFontGetXHeight(ctfont)).ceil();
}
QFixed QCoreTextFontEngine::averageCharWidth() const
{
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h
index e289aa9..dc18991 100644
--- a/src/gui/text/qfontengine_p.h
+++ b/src/gui/text/qfontengine_p.h
@@ -178,7 +178,7 @@ public:
* Create a qimage with the alpha values for the glyph.
* Returns an image indexed_8 with index values ranging from 0=fully transparant to 255=opaque
*/
- virtual QImage alphaMapForGlyph(glyph_t) = 0;
+ virtual QImage alphaMapForGlyph(glyph_t);
virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t);
virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
@@ -480,7 +480,7 @@ private:
uint fontIndexForFont(CTFontRef id) const;
CTFontRef ctfont;
- mutable QCFType<CFDictionaryRef> attributeDict;
+ mutable QCFType<CFMutableDictionaryRef> attributeDict;
friend class QFontDialogPrivate;
};
diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp
index 1996d44..bf3a176 100644
--- a/src/gui/text/qfontengine_win.cpp
+++ b/src/gui/text/qfontengine_win.cpp
@@ -1406,8 +1406,8 @@ QNativeImage *QFontEngineWin::drawGDIGlyph(HFONT font, glyph_t glyph, int margin
#endif
#endif
- QNativeImage *ni = new QNativeImage(iw + 2 * margin,
- ih + 2 * margin,
+ QNativeImage *ni = new QNativeImage(iw + 2 * margin + 2,
+ ih + 2 * margin + 2,
QNativeImage::systemFormat(), true);
ni->image.fill(0xffffffff);
@@ -1449,7 +1449,7 @@ QImage QFontEngineWin::alphaMapForGlyph(glyph_t glyph, const QTransform &xform)
font = CreateFontIndirectW(&lf);
}
- QNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform);
+ QNativeImage *mask = drawGDIGlyph(font, glyph, 2, xform);
if (mask == 0)
return QImage();
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index c327b9f..48963bb 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -1074,7 +1074,10 @@ QTextCursor::QTextCursor(const QTextCursor &cursor)
}
/*!
- Makes a copy of \a cursor and assigns it to this QTextCursor.
+ Makes a copy of \a cursor and assigns it to this QTextCursor. Note
+ that QTextCursor is an \l{Implicitly Shared Classes}{implicitly
+ shared} class.
+
*/
QTextCursor &QTextCursor::operator=(const QTextCursor &cursor)
{
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index e84b324..873f846 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -287,7 +287,7 @@ QTextCodec *Qt::codecForHtml(const QByteArray &ba)
that inform connected editor widgets about the state of the undo/redo
system.
- \sa QTextCursor QTextEdit \link richtext.html Rich Text Processing\endlink
+ \sa QTextCursor, QTextEdit, \link richtext.html Rich Text Processing\endlink , {Text Object Example}
*/
/*!
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 21bfc4d..38ac4ca 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -1449,7 +1449,7 @@ void QTextCharFormat::setUnderlineStyle(UnderlineStyle style)
/*!
\since 4.5
\fn bool QTextCharFormat::fontKerning() const
- Returns true if the the font kerning is enabled.
+ Returns true if the font kerning is enabled.
\sa setFontKerning()
\sa font()
diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h
index 0571d75..8eaeeb1 100644
--- a/src/gui/text/qtextformat.h
+++ b/src/gui/text/qtextformat.h
@@ -232,6 +232,12 @@ public:
ImageWidth = 0x5010,
ImageHeight = 0x5011,
+ // internal
+ /*
+ SuppressText = 0x5012,
+ SuppressBackground = 0x513
+ */
+
// selection properties
FullWidthSelection = 0x06000,
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 434d1ca..fa624ef 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -61,6 +61,8 @@
QT_BEGIN_NAMESPACE
#define ObjectSelectionBrush (QTextFormat::ForegroundBrush + 1)
+#define SuppressText 0x5012
+#define SuppressBackground 0x513
static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line)
{
@@ -1143,6 +1145,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
}
QPainterPath excludedRegion;
+ QPainterPath textDoneRegion;
for (int i = 0; i < selections.size(); ++i) {
FormatRange selection = selections.at(i);
const QBrush bg = selection.format.background();
@@ -1202,23 +1205,55 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
}
+
+ bool hasText = (selection.format.foreground().style() != Qt::NoBrush);
+ bool hasBackground= (selection.format.background().style() != Qt::NoBrush);
+
+ if (hasBackground) {
+ selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush));
+ // don't just clear the property, set an empty brush that overrides a potential
+ // background brush specified in the text
+ selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush());
+ selection.format.clearProperty(QTextFormat::OutlinePen);
+ }
+
+ selection.format.setProperty(SuppressText, !hasText);
+
+ if (hasText && !hasBackground && !(textDoneRegion & region).isEmpty())
+ continue;
+
p->save();
p->setClipPath(region, Qt::IntersectClip);
- selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush));
- // don't just clear the property, set an empty brush that overrides a potential
- // background brush specified in the text
- selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush());
- selection.format.clearProperty(QTextFormat::OutlinePen);
-
for (int line = firstLine; line < lastLine; ++line) {
QTextLine l(line, d);
l.draw(p, position, &selection);
}
p->restore();
- if (selection.format.foreground().style() != Qt::NoBrush) // i.e. we have drawn text
- excludedRegion += region;
+ if (hasText) {
+ textDoneRegion += region;
+ } else {
+ if (hasBackground)
+ textDoneRegion -= region;
+ }
+
+ excludedRegion += region;
+ }
+
+ QPainterPath needsTextButNoBackground = excludedRegion - textDoneRegion;
+ if (!needsTextButNoBackground.isEmpty()){
+ p->save();
+ p->setClipPath(needsTextButNoBackground, Qt::IntersectClip);
+ FormatRange selection;
+ selection.start = 0;
+ selection.length = INT_MAX;
+ selection.format.setProperty(SuppressBackground, true);
+ for (int line = firstLine; line < lastLine; ++line) {
+ QTextLine l(line, d);
+ l.draw(p, position, &selection);
+ }
+ p->restore();
}
if (!excludedRegion.isEmpty()) {
@@ -1912,14 +1947,17 @@ static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si,
static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r)
{
QBrush c = chf.foreground();
- if (c.style() == Qt::NoBrush)
+ if (c.style() == Qt::NoBrush) {
p->setPen(defaultPen);
+ }
QBrush bg = chf.background();
- if (bg.style() != Qt::NoBrush)
+ if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool())
p->fillRect(r, bg);
- if (c.style() != Qt::NoBrush)
+ if (c.style() != Qt::NoBrush) {
p->setPen(QPen(c, 0));
+ }
+
}
/*!
@@ -1933,7 +1971,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR
const QScriptLine &line = eng->lines[i];
QPen pen = p->pen();
- bool noText = (selection && selection->format.foreground().style() == Qt::NoBrush);
+ bool noText = (selection && selection->format.property(SuppressText).toBool());
if (!line.length) {
if (selection
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index 3f4c8e5..71b68e0 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -76,7 +76,7 @@ QT_BEGIN_NAMESPACE
objects, you will also need to reimplement QTextDocument::createObject()
which acts as a factory method for creating text objects.
- \sa QTextDocument
+ \sa QTextDocument, {Text Object Example}
*/
/*!
diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp
index ba1c04f..48708c9 100644
--- a/src/gui/text/qtexttable.cpp
+++ b/src/gui/text/qtexttable.cpp
@@ -525,7 +525,12 @@ void QTextTablePrivate::update() const
Rows and columns within a QTextTable can be merged and split using
the mergeCells() and splitCell() functions. However, only cells that span multiple
rows or columns can be split. (Merging or splitting does not increase or decrease
- the number of rows and columns.)
+ the number of rows and columns.)
+
+ Note that if you have merged multiple columns and rows into one cell, you will not
+ be able to split the merged cell into new cells spanning over more than one row
+ or column. To be able to split cells spanning over several rows and columns you
+ need to do this over several iterations.
\table 80%
\row