summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorSami Lempinen <sami.lempinen@nokia.com>2011-09-20 09:59:45 (GMT)
committerSami Lempinen <sami.lempinen@nokia.com>2011-09-20 09:59:45 (GMT)
commit03645fccea8f2bf997ed4191d7a67a0e93a977d6 (patch)
treeb9f1490bacd05aea265783bfb5d9e40fe6b2b0dc /src/gui
parenta0ad54acd33873316908080f432768fdf3e3bfc2 (diff)
parent367a89cf5cb1282d2e966c83869a56fd22745779 (diff)
downloadQt-03645fccea8f2bf997ed4191d7a67a0e93a977d6.zip
Qt-03645fccea8f2bf997ed4191d7a67a0e93a977d6.tar.gz
Qt-03645fccea8f2bf997ed4191d7a67a0e93a977d6.tar.bz2
Merge remote-tracking branch 'qt/4.8'
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/accessible/qaccessible_win.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp9
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp36
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp16
-rw-r--r--src/gui/kernel/qeventdispatcher_qpa.cpp2
-rw-r--r--src/gui/kernel/qkeysequence.cpp16
-rw-r--r--src/gui/painting/qpaintengine.cpp7
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp54
-rw-r--r--src/gui/styles/qcommonstyle.cpp18
-rw-r--r--src/gui/text/qfontengine.cpp5
-rw-r--r--src/gui/text/qfontengine_ft.cpp21
-rw-r--r--src/gui/text/qfontengine_ft_p.h15
-rw-r--r--src/gui/text/qfontengine_mac.mm23
-rw-r--r--src/gui/text/qfontengine_qpa.cpp13
-rw-r--r--src/gui/text/qfontengine_qpf.cpp13
-rw-r--r--src/gui/text/qfontengine_qws.cpp13
-rw-r--r--src/gui/text/qfontengine_s60.cpp13
-rw-r--r--src/gui/text/qfontengine_win.cpp13
-rw-r--r--src/gui/text/qfontengine_x11.cpp4
-rw-r--r--src/gui/text/qfontenginedirectwrite.cpp13
-rw-r--r--src/gui/text/qglyphrun.cpp33
-rw-r--r--src/gui/text/qglyphrun.h4
-rw-r--r--src/gui/text/qrawfont.cpp139
-rw-r--r--src/gui/text/qrawfont.h6
-rw-r--r--src/gui/text/qrawfont_p.h25
-rw-r--r--src/gui/text/qrawfont_win.cpp82
-rw-r--r--src/gui/text/qtextcontrol.cpp7
-rw-r--r--src/gui/text/qtextcursor.cpp4
-rw-r--r--src/gui/text/qtextengine.cpp21
-rw-r--r--src/gui/text/qtextengine_p.h4
-rw-r--r--src/gui/text/qtexthtmlparser.cpp12
-rw-r--r--src/gui/text/qtextlayout.cpp14
-rw-r--r--src/gui/widgets/qlinecontrol.cpp6
34 files changed, 294 insertions, 373 deletions
diff --git a/src/gui/accessible/qaccessible_win.cpp b/src/gui/accessible/qaccessible_win.cpp
index caabae5..1fd1bfd 100644
--- a/src/gui/accessible/qaccessible_win.cpp
+++ b/src/gui/accessible/qaccessible_win.cpp
@@ -1316,7 +1316,7 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accState(VARIANT varID, VARIAN
(*pvarState).vt = VT_I4;
AccessibleElement elem(varID.lVal, accessible);
- (*pvarState).lVal = elem.iface ? elem.iface->state(elem.entry) : 0;
+ (*pvarState).lVal = elem.iface ? elem.iface->state(elem.entry) : State(Normal);
return S_OK;
}
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index eaa8ac2..deda3ff 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -2966,11 +2966,12 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QList<QSimplexConstraint
AnchorData *ad = variables.at(i);
ad->sizeAtPreferred = ad->result - g_offset;
}
-
- // Make sure we delete the simplex solver -before- we delete the
- // constraints used by it.
- delete simplex;
}
+
+ // Make sure we delete the simplex solver -before- we delete the
+ // constraints used by it.
+ delete simplex;
+
// Delete constraints and variables we created.
qDeleteAll(preferredConstraints);
qDeleteAll(preferredVariables);
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 0c218fc..9092593 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -5378,11 +5378,9 @@ void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively()
{
QGraphicsItemPrivate *itemPrivate = this;
do {
- if (itemPrivate->graphicsEffect) {
+ if (itemPrivate->graphicsEffect && !itemPrivate->updateDueToGraphicsEffect) {
itemPrivate->notifyInvalidated = 1;
-
- if (!itemPrivate->updateDueToGraphicsEffect)
- static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
+ static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
}
} while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
}
@@ -5690,21 +5688,27 @@ void QGraphicsItem::update(const QRectF &rect)
d_ptr->invalidateParentGraphicsEffectsRecursively();
#endif //QT_NO_GRAPHICSEFFECT
- if (CacheMode(d_ptr->cacheMode) != NoCache) {
- // Invalidate cache.
- QGraphicsItemCache *cache = d_ptr->extraItemCache();
- if (!cache->allExposed) {
- if (rect.isNull()) {
- cache->allExposed = true;
- cache->exposed.clear();
- } else {
- cache->exposed.append(rect);
+#ifndef QT_NO_GRAPHICSEFFECT
+ if (!d_ptr->updateDueToGraphicsEffect) {
+#endif
+ if (CacheMode(d_ptr->cacheMode) != NoCache) {
+ // Invalidate cache.
+ QGraphicsItemCache *cache = d_ptr->extraItemCache();
+ if (!cache->allExposed) {
+ if (rect.isNull()) {
+ cache->allExposed = true;
+ cache->exposed.clear();
+ } else {
+ cache->exposed.append(rect);
+ }
}
+ // Only invalidate cache; item is already dirty.
+ if (d_ptr->fullUpdatePending)
+ return;
}
- // Only invalidate cache; item is already dirty.
- if (d_ptr->fullUpdatePending)
- return;
+#ifndef QT_NO_GRAPHICSEFFECT
}
+#endif
if (d_ptr->scene)
d_ptr->scene->d_func()->markDirty(this, rect);
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 1551944..867880c 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -3504,7 +3504,9 @@ bool QGraphicsScene::event(QEvent *event)
}
break;
case QEvent::WindowDeactivate:
- if (!--d->activationRefCount) {
+ if (d->activationRefCount > 0)
+ --d->activationRefCount;
+ if (!d->activationRefCount) {
if (d->activePanel) {
// Deactivate the active panel (but keep it so we can
// reactivate it later).
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 965b1b34..c275968 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -152,7 +152,7 @@ QT_BEGIN_NAMESPACE
\row \o Qt::WA_SetPalette
\o Set by setPalette().
\row \o Qt::WA_SetFont
- \o Set by setPalette().
+ \o Set by setFont().
\row \o Qt::WA_WindowPropagation
\o Enables propagation to window widgets.
\endtable
@@ -1173,6 +1173,12 @@ QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &
QApplication::sendEvent(this, &event);
break;
}
+ case ItemChildAddedChange: {
+ QGraphicsItem *child = qVariantValue<QGraphicsItem *>(value);
+ if (child->isWidget())
+ static_cast<QGraphicsWidget *>(child)->d_func()->resolveLayoutDirection();
+ break;
+ }
default:
break;
}
@@ -1668,7 +1674,7 @@ void QGraphicsWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
/*!
This event handler, for \a event, can be reimplemented in a subclass to
- receive notifications for Qt::GrabMouse events.
+ receive notifications for QEvent::GrabMouse events.
\sa grabMouse(), grabKeyboard()
*/
@@ -1679,7 +1685,7 @@ void QGraphicsWidget::grabMouseEvent(QEvent *event)
/*!
This event handler, for \a event, can be reimplemented in a subclass to
- receive notifications for Qt::UngrabMouse events.
+ receive notifications for QEvent::UngrabMouse events.
\sa ungrabMouse(), ungrabKeyboard()
*/
@@ -1690,7 +1696,7 @@ void QGraphicsWidget::ungrabMouseEvent(QEvent *event)
/*!
This event handler, for \a event, can be reimplemented in a subclass to
- receive notifications for Qt::GrabKeyboard events.
+ receive notifications for QEvent::GrabKeyboard events.
\sa grabKeyboard(), grabMouse()
*/
@@ -1701,7 +1707,7 @@ void QGraphicsWidget::grabKeyboardEvent(QEvent *event)
/*!
This event handler, for \a event, can be reimplemented in a subclass to
- receive notifications for Qt::UngrabKeyboard events.
+ receive notifications for QEvent::UngrabKeyboard events.
\sa ungrabKeyboard(), ungrabMouse()
*/
diff --git a/src/gui/kernel/qeventdispatcher_qpa.cpp b/src/gui/kernel/qeventdispatcher_qpa.cpp
index 200696d..3f2e8b2 100644
--- a/src/gui/kernel/qeventdispatcher_qpa.cpp
+++ b/src/gui/kernel/qeventdispatcher_qpa.cpp
@@ -284,7 +284,7 @@ int QEventDispatcherQPA::select(int nfds, fd_set *readfds, fd_set *writefds, fd_
Q_D(QEventDispatcherQPA);
int retVal = 0;
if (d->hasIntegration()) {
- qint64 timeoutmsec = 0;
+ qint64 timeoutmsec = 1000; // wait a second if we don't have timers
if (timeout)
timeoutmsec = timeout->tv_sec * 1000 + (timeout->tv_usec/1000);
d->selectReturnMutex->lock();
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 5fc72d4..469973f 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1381,11 +1381,11 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
QString p;
if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
- if (key < 0x10000) {
- p = QChar(key & 0xffff).toUpper();
+ if (!QChar::requiresSurrogates(key)) {
+ p = QChar(ushort(key)).toUpper();
} else {
- p = QChar((key-0x10000)/0x400+0xd800);
- p += QChar((key-0x10000)%400+0xdc00);
+ p += QChar(QChar::highSurrogate(key));
+ p += QChar(QChar::lowSurrogate(key));
}
} else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
p = nativeText ? QShortcut::tr("F%1").arg(key - Qt::Key_F1 + 1)
@@ -1418,11 +1418,11 @@ NonSymbol:
// Or else characters like Qt::Key_aring may not get displayed
// (Really depends on you locale)
if (!keyname[i].name) {
- if (key < 0x10000) {
- p = QChar(key & 0xffff).toUpper();
+ if (!QChar::requiresSurrogates(key)) {
+ p = QChar(ushort(key)).toUpper();
} else {
- p = QChar((key-0x10000)/0x400+0xd800);
- p += QChar((key-0x10000)%400+0xdc00);
+ p += QChar(QChar::highSurrogate(key));
+ p += QChar(QChar::lowSurrogate(key));
}
}
}
diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp
index c46513a..38ba6f9 100644
--- a/src/gui/painting/qpaintengine.cpp
+++ b/src/gui/painting/qpaintengine.cpp
@@ -756,14 +756,15 @@ void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
path.setFillRule(Qt::WindingFill);
#endif
if (ti.glyphs.numGlyphs)
- ti.fontEngine->addOutlineToPath(p.x(), p.y(), ti.glyphs, &path, ti.flags);
+ ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags);
if (!path.isEmpty()) {
- bool oldAA = painter()->renderHints() & QPainter::Antialiasing;
+ painter()->save();
painter()->setRenderHint(QPainter::Antialiasing,
bool((painter()->renderHints() & QPainter::TextAntialiasing)
&& !(painter()->font().styleStrategy() & QFont::NoAntialias)));
+ painter()->translate(p.x(), p.y());
painter()->fillPath(path, state->pen().brush());
- painter()->setRenderHint(QPainter::Antialiasing, oldAA);
+ painter()->restore();
}
}
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 36786c4..bcc5f9d 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3764,6 +3764,11 @@ extern "C" {
int q_gray_rendered_spans(QT_FT_Raster raster);
}
+static inline uchar *alignAddress(uchar *address, quintptr alignmentMask)
+{
+ return (uchar *)(((quintptr)address + alignmentMask) & ~alignmentMask);
+}
+
void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
ProcessSpans callback,
void *userData, QRasterBuffer *)
@@ -3791,19 +3796,10 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
// minimize memory reallocations. However if initial size for
// raster pool is changed for lower value, reallocations will
// occur normally.
- const int rasterPoolInitialSize = MINIMUM_POOL_SIZE;
- int rasterPoolSize = rasterPoolInitialSize;
- unsigned char *rasterPoolBase;
-#if defined(Q_WS_WIN64)
- rasterPoolBase =
- // We make use of setjmp and longjmp in qgrayraster.c which requires
- // 16-byte alignment, hence we hardcode this requirement here..
- (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
-#else
- unsigned char rasterPoolOnStack[rasterPoolInitialSize];
- rasterPoolBase = rasterPoolOnStack;
-#endif
- Q_CHECK_PTR(rasterPoolBase);
+ int rasterPoolSize = MINIMUM_POOL_SIZE;
+ uchar rasterPoolOnStack[MINIMUM_POOL_SIZE + 0xf];
+ uchar *rasterPoolBase = alignAddress(rasterPoolOnStack, 0xf);
+ uchar *rasterPoolOnHeap = 0;
qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize);
@@ -3839,31 +3835,20 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
// Out of memory, reallocate some more and try again...
if (error == -6) { // ErrRaster_OutOfMemory from qgrayraster.c
- int new_size = rasterPoolSize * 2;
- if (new_size > 1024 * 1024) {
+ rasterPoolSize *= 2;
+ if (rasterPoolSize > 1024 * 1024) {
qWarning("QPainter: Rasterization of primitive failed");
break;
}
rendered_spans += q_gray_rendered_spans(*grayRaster.data());
-#if defined(Q_WS_WIN64)
- _aligned_free(rasterPoolBase);
-#else
- if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- free(rasterPoolBase);
-#endif
+ free(rasterPoolOnHeap);
+ rasterPoolOnHeap = (uchar *)malloc(rasterPoolSize + 0xf);
- rasterPoolSize = new_size;
- rasterPoolBase =
-#if defined(Q_WS_WIN64)
- // We make use of setjmp and longjmp in qgrayraster.c which requires
- // 16-byte alignment, hence we hardcode this requirement here..
- (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
-#else
- (unsigned char *) malloc(rasterPoolSize);
-#endif
- Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
+ Q_CHECK_PTR(rasterPoolOnHeap); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
+
+ rasterPoolBase = alignAddress(rasterPoolOnHeap, 0xf);
qt_ft_grays_raster.raster_done(*grayRaster.data());
qt_ft_grays_raster.raster_new(grayRaster.data());
@@ -3873,12 +3858,7 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
}
}
-#if defined(Q_WS_WIN64)
- _aligned_free(rasterPoolBase);
-#else
- if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- free(rasterPoolBase);
-#endif
+ free(rasterPoolOnHeap);
}
void QRasterPaintEnginePrivate::recalculateFastImages()
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index ad0e151..327bedf 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -837,14 +837,12 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut
QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, int role) const
{
- Q_Q(const QCommonStyle);
-
const QWidget *widget = option->widget;
switch (role) {
case Qt::CheckStateRole:
if (option->features & QStyleOptionViewItemV2::HasCheckIndicator)
- return QSize(q->pixelMetric(QStyle::PM_IndicatorWidth, option, widget),
- q->pixelMetric(QStyle::PM_IndicatorHeight, option, widget));
+ return QSize(proxyStyle->pixelMetric(QStyle::PM_IndicatorWidth, option, widget),
+ proxyStyle->pixelMetric(QStyle::PM_IndicatorHeight, option, widget));
break;
case Qt::DisplayRole:
if (option->features & QStyleOptionViewItemV2::HasDisplay) {
@@ -855,7 +853,7 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, in
textLayout.setFont(option->font);
textLayout.setText(option->text);
const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText;
- const int textMargin = q->pixelMetric(QStyle::PM_FocusFrameHMargin, option, widget) + 1;
+ const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, option, widget) + 1;
QRect bounds = option->rect;
switch (option->decorationPosition) {
case QStyleOptionViewItem::Left:
@@ -919,9 +917,8 @@ static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth)
void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewItemV4 *option, const QRect &rect) const
{
- Q_Q(const QCommonStyle);
const QWidget *widget = option->widget;
- const int textMargin = q->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
+ const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText;
@@ -999,7 +996,6 @@ void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewIt
void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItemV4 *opt, QRect *checkRect,
QRect *pixmapRect, QRect *textRect, bool sizehint) const
{
- Q_Q(const QCommonStyle);
Q_ASSERT(checkRect && pixmapRect && textRect);
*pixmapRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DecorationRole));
*textRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DisplayRole));
@@ -1009,9 +1005,9 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItemV4 *opt, QRe
const bool hasCheck = checkRect->isValid();
const bool hasPixmap = pixmapRect->isValid();
const bool hasText = textRect->isValid();
- const int textMargin = hasText ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
- const int pixmapMargin = hasPixmap ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
- const int checkMargin = hasCheck ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
+ const int textMargin = hasText ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
+ const int pixmapMargin = hasPixmap ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
+ const int checkMargin = hasCheck ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
int x = opt->rect.left();
int y = opt->rect.top();
int w, h;
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index dec0982..c9b672b 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -280,6 +280,8 @@ void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform
int i = glyphs.numGlyphs;
int totalKashidas = 0;
while(i--) {
+ if (glyphs.attributes[i].dontPrint)
+ continue;
xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6);
ypos += glyphs.advances_y[i];
totalKashidas += glyphs.justifications[i].nKashidas;
@@ -1335,8 +1337,7 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
int glyph_pos = 0;
for (int i = 0; i < len; ++i) {
- bool surrogate = (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 && i < len-1
- && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000);
+ bool surrogate = (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate());
if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
QGlyphLayoutInstance tmp = glyphs->instance(glyph_pos);
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 9a5d9d6..e20aa25 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -78,6 +78,10 @@
#include FT_ERRORS_H
#endif
+#if !defined(QT_MAX_CACHED_GLYPH_SIZE)
+# define QT_MAX_CACHED_GLYPH_SIZE 64
+#endif
+
QT_BEGIN_NAMESPACE
/*
@@ -373,7 +377,7 @@ void QFreetypeFace::computeSize(const QFontDef &fontDef, int *xsize, int *ysize,
*xsize = *ysize = 0;
}
} else {
- *outline_drawing = (*xsize > (64<<6) || *ysize > (64<<6));
+ *outline_drawing = (*xsize > (QT_MAX_CACHED_GLYPH_SIZE<<6) || *ysize > (QT_MAX_CACHED_GLYPH_SIZE<<6));
}
}
@@ -1317,7 +1321,7 @@ QFontEngineFT::QGlyphSet *QFontEngineFT::loadTransformedGlyphSet(const QTransfor
if (!gs) {
// don't try to load huge fonts
- bool draw_as_outline = fontDef.pixelSize * qSqrt(qAbs(matrix.det())) >= 64;
+ bool draw_as_outline = fontDef.pixelSize * qSqrt(qAbs(matrix.det())) >= QT_MAX_CACHED_GLYPH_SIZE;
if (draw_as_outline)
return 0;
@@ -1418,15 +1422,12 @@ void QFontEngineFT::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_me
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
bool QFontEngineFT::canRender(const QChar *string, int len)
diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h
index 57811fa..95e5b82 100644
--- a/src/gui/text/qfontengine_ft_p.h
+++ b/src/gui/text/qfontengine_ft_p.h
@@ -196,12 +196,7 @@ public:
inline bool useFastGlyphData(glyph_t index, QFixed subPixelPosition) const {
return (index < 256 && subPixelPosition == 0);
}
- inline Glyph *getGlyph(glyph_t index, QFixed subPixelPosition = 0) const
- {
- if (useFastGlyphData(index, subPixelPosition))
- return fast_glyph_data[index];
- return glyph_data.value(GlyphAndSubPixelPosition(index, subPixelPosition));
- }
+ inline Glyph *getGlyph(glyph_t index, QFixed subPixelPosition = 0) const;
void setGlyph(glyph_t index, QFixed spp, Glyph *glyph);
private:
@@ -376,6 +371,14 @@ inline uint qHash(const QFontEngineFT::GlyphAndSubPixelPosition &g)
return (g.glyph << 8) | (g.subPixelPosition * 10).round().toInt();
}
+inline QFontEngineFT::Glyph *QFontEngineFT::QGlyphSet::getGlyph(glyph_t index, QFixed subPixelPosition) const
+{
+ if (useFastGlyphData(index, subPixelPosition))
+ return fast_glyph_data[index];
+ return glyph_data.value(GlyphAndSubPixelPosition(index, subPixelPosition));
+}
+
+
QT_END_NAMESPACE
#endif // QT_NO_FREETYPE
diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm
index 9d9eaed..6186b2f 100644
--- a/src/gui/text/qfontengine_mac.mm
+++ b/src/gui/text/qfontengine_mac.mm
@@ -257,10 +257,8 @@ static OSStatus atsuPostLayoutCallback(ATSULayoutOperationSelector selector, ATS
#if !defined(QT_NO_DEBUG)
int surrogates = 0;
const QChar *str = item->string;
- for (int i = item->from; i < item->from + item->length - 1; ++i) {
- surrogates += (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00
- && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000);
- }
+ for (int i = item->from; i < item->from + item->length - 1; ++i)
+ surrogates += (str[i].isHighSurrogate() && str[i+1].isLowSurrogate());
#endif
for (nextCharStop = item->from; nextCharStop < item->from + item->length; ++nextCharStop)
if (item->charAttributes[nextCharStop].charStop)
@@ -328,10 +326,8 @@ static OSStatus atsuPostLayoutCallback(ATSULayoutOperationSelector selector, ATS
if (charOffset < item->length - 1) {
QChar current = item->string[item->from + charOffset];
QChar next = item->string[item->from + charOffset + 1];
- if (current.unicode() >= 0xd800 && current.unicode() < 0xdc00
- && next.unicode() >= 0xdc00 && next.unicode() < 0xe000) {
+ if (current.isHighSurrogate() && next.isLowSurrogate())
item->log_clusters[charOffset + 1] = currentClusterGlyph;
- }
}
}
}
@@ -738,15 +734,12 @@ QFontEngineMac::~QFontEngineMac()
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
// Not used directly for shaping, only used to calculate m_averageCharWidth
diff --git a/src/gui/text/qfontengine_qpa.cpp b/src/gui/text/qfontengine_qpa.cpp
index cb1e7d6..c829c2f 100644
--- a/src/gui/text/qfontengine_qpa.cpp
+++ b/src/gui/text/qfontengine_qpa.cpp
@@ -226,15 +226,12 @@ QVariant QFontEngineQPA::extractHeaderField(const uchar *data, HeaderTag request
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data)
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp
index 30a1623..3db5ce1 100644
--- a/src/gui/text/qfontengine_qpf.cpp
+++ b/src/gui/text/qfontengine_qpf.cpp
@@ -278,15 +278,12 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
#ifdef QT_FONTS_ARE_RESOURCES
QFontEngineQPF::QFontEngineQPF(const QFontDef &def, const uchar *bytes, int size)
diff --git a/src/gui/text/qfontengine_qws.cpp b/src/gui/text/qfontengine_qws.cpp
index 237842b..ade283f 100644
--- a/src/gui/text/qfontengine_qws.cpp
+++ b/src/gui/text/qfontengine_qws.cpp
@@ -83,15 +83,12 @@ QT_BEGIN_NAMESPACE
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
#define FM_SMOOTH 1
diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp
index b0824cb..203b6e1 100644
--- a/src/gui/text/qfontengine_s60.cpp
+++ b/src/gui/text/qfontengine_s60.cpp
@@ -233,15 +233,12 @@ bool QSymbianTypeFaceExtras::symbianFontTableApiAvailable()
// duplicated from qfontengine_xyz.cpp
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
extern QString qt_symbian_fontNameWithAppFontMarker(const QString &fontName); // qfontdatabase_s60.cpp
diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp
index aef2145..fc11387 100644
--- a/src/gui/text/qfontengine_win.cpp
+++ b/src/gui/text/qfontengine_win.cpp
@@ -224,15 +224,12 @@ void QFontEngineWin::getCMap()
inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
int QFontEngineWin::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs, bool mirrored) const
diff --git a/src/gui/text/qfontengine_x11.cpp b/src/gui/text/qfontengine_x11.cpp
index 490866c..6e87f4c 100644
--- a/src/gui/text/qfontengine_x11.cpp
+++ b/src/gui/text/qfontengine_x11.cpp
@@ -358,9 +358,7 @@ bool QFontEngineXLFD::stringToCMap(const QChar *s, int len, QGlyphLayout *glyphs
QVarLengthArray<ushort> _s(len);
QChar *str = (QChar *)_s.data();
for (int i = 0; i < len; ++i) {
- if (i < len - 1
- && s[i].unicode() >= 0xd800 && s[i].unicode() < 0xdc00
- && s[i+1].unicode() >= 0xdc00 && s[i].unicode() < 0xe000) {
+ if (s[i].isHighSurrogate() && i < len-1 && s[i+1].isLowSurrogate()) {
*str = QChar();
++i;
} else {
diff --git a/src/gui/text/qfontenginedirectwrite.cpp b/src/gui/text/qfontenginedirectwrite.cpp
index d693273..5bac117 100644
--- a/src/gui/text/qfontenginedirectwrite.cpp
+++ b/src/gui/text/qfontenginedirectwrite.cpp
@@ -269,15 +269,12 @@ QFixed QFontEngineDirectWrite::emSquareSize() const
inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ uint ucs4 = str[i].unicode();
+ if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
+ ++i;
+ ucs4 = QChar::surrogateToUcs4( ucs4, str[i].unicode());
}
- return uc;
+ return ucs4;
}
bool QFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs,
diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp
index 442f7cc..7f43378 100644
--- a/src/gui/text/qglyphrun.cpp
+++ b/src/gui/text/qglyphrun.cpp
@@ -140,14 +140,18 @@ bool QGlyphRun::operator==(const QGlyphRun &other) const
return false;
}
- for (int i=0; i<qMax(d->glyphIndexDataSize, d->glyphPositionDataSize); ++i) {
- if (i < d->glyphIndexDataSize && d->glyphIndexData[i] != other.d->glyphIndexData[i])
- return false;
-
- if (i < d->glyphPositionDataSize && d->glyphPositionData[i] != other.d->glyphPositionData[i])
- return false;
+ if (d->glyphIndexData != other.d->glyphIndexData) {
+ for (int i = 0; i < d->glyphIndexDataSize; ++i) {
+ if (d->glyphIndexData[i] != other.d->glyphIndexData[i])
+ return false;
+ }
+ }
+ if (d->glyphPositionData != other.d->glyphPositionData) {
+ for (int i = 0; i < d->glyphPositionDataSize; ++i) {
+ if (d->glyphPositionData[i] != other.d->glyphPositionData[i])
+ return false;
+ }
}
-
return (d->overline == other.d->overline
&& d->underline == other.d->underline
@@ -156,13 +160,11 @@ bool QGlyphRun::operator==(const QGlyphRun &other) const
}
/*!
+ \fn bool QGlyphRun::operator!=(const QGlyphRun &other) const
+
Compares \a other to this QGlyphRun object. Returns true if any of the list of glyph
indexes, the list of positions or the font are different, otherwise returns false.
*/
-bool QGlyphRun::operator!=(const QGlyphRun &other) const
-{
- return !(*this == other);
-}
/*!
Returns the font selected for this QGlyphRun object.
@@ -294,6 +296,9 @@ bool QGlyphRun::overline() const
*/
void QGlyphRun::setOverline(bool overline)
{
+ if (d->overline == overline)
+ return;
+
detach();
d->overline = overline;
}
@@ -316,6 +321,9 @@ bool QGlyphRun::underline() const
*/
void QGlyphRun::setUnderline(bool underline)
{
+ if (d->underline == underline)
+ return;
+
detach();
d->underline = underline;
}
@@ -338,6 +346,9 @@ bool QGlyphRun::strikeOut() const
*/
void QGlyphRun::setStrikeOut(bool strikeOut)
{
+ if (d->strikeOut == strikeOut)
+ return;
+
detach();
d->strikeOut = strikeOut;
}
diff --git a/src/gui/text/qglyphrun.h b/src/gui/text/qglyphrun.h
index cf407a8..bc7f4ff 100644
--- a/src/gui/text/qglyphrun.h
+++ b/src/gui/text/qglyphrun.h
@@ -79,8 +79,10 @@ public:
void clear();
QGlyphRun &operator=(const QGlyphRun &other);
+
bool operator==(const QGlyphRun &other) const;
- bool operator!=(const QGlyphRun &other) const;
+ inline bool operator!=(const QGlyphRun &other) const
+ { return !operator==(other); }
void setOverline(bool overline);
bool overline() const;
diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp
index 60a6cb3..7c7d4eb 100644
--- a/src/gui/text/qrawfont.cpp
+++ b/src/gui/text/qrawfont.cpp
@@ -46,7 +46,6 @@
#include "qrawfont.h"
#include "qrawfont_p.h"
-#include <QtCore/qthread.h>
#include <QtCore/qendian.h>
QT_BEGIN_NAMESPACE
@@ -77,7 +76,7 @@ QT_BEGIN_NAMESPACE
A QRawFont object represents a single, physical instance of a given font in a given pixel size.
I.e. in the typical case it represents a set of TrueType or OpenType font tables and uses a
- user specified pixel size to convert metrics into logical pixel units. In can be used in
+ user specified pixel size to convert metrics into logical pixel units. It can be used in
combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and
also have accessors to some relevant data in the physical font.
@@ -190,8 +189,7 @@ QRawFont &QRawFont::operator=(const QRawFont &other)
*/
bool QRawFont::isValid() const
{
- Q_ASSERT(d->thread == 0 || d->thread == QThread::currentThread());
- return d->fontEngine != 0;
+ return d->isValid();
}
/*!
@@ -225,7 +223,7 @@ void QRawFont::loadFromData(const QByteArray &fontData,
qreal pixelSize,
QFont::HintingPreference hintingPreference)
{
- detach();
+ d.detach();
d->cleanUp();
d->hintingPreference = hintingPreference;
d->thread = QThread::currentThread();
@@ -240,20 +238,21 @@ void QRawFont::loadFromData(const QByteArray &fontData,
If \a antialiasingType is set to QRawFont::SubPixelAntialiasing, then the resulting image will be
in QImage::Format_RGB32 and the RGB values of each pixel will represent the subpixel opacities of
the pixel in the rasterization of the glyph. Otherwise, the image will be in the format of
- QImage::Format_A8 and each pixel will contain the opacity of the pixel in the rasterization.
+ QImage::Format_Indexed8 and each pixel will contain the opacity of the pixel in the
+ rasterization.
\sa pathForGlyph(), QPainter::drawGlyphRun()
*/
QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType,
const QTransform &transform) const
{
- if (!isValid())
+ if (!d->isValid())
return QImage();
if (antialiasingType == SubPixelAntialiasing)
return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), 0, transform);
- else
- return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
+
+ return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
}
/*!
@@ -266,7 +265,7 @@ QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialias
*/
QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const
{
- if (!isValid())
+ if (!d->isValid())
return QPainterPath();
QFixedPoint position;
@@ -284,16 +283,19 @@ bool QRawFont::operator==(const QRawFont &other) const
}
/*!
+ \fn bool QRawFont::operator!=(const QRawFont &other) const
+
+ Returns true if this QRawFont is not equal to \a other. Otherwise, returns false.
+*/
+
+/*!
Returns the ascent of this QRawFont in pixel units.
\sa QFontMetricsF::ascent()
*/
qreal QRawFont::ascent() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->ascent().toReal();
+ return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
}
/*!
@@ -303,10 +305,7 @@ qreal QRawFont::ascent() const
*/
qreal QRawFont::descent() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->descent().toReal();
+ return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
}
/*!
@@ -316,10 +315,7 @@ qreal QRawFont::descent() const
*/
qreal QRawFont::xHeight() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->xHeight().toReal();
+ return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
}
/*!
@@ -329,10 +325,7 @@ qreal QRawFont::xHeight() const
*/
qreal QRawFont::leading() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->leading().toReal();
+ return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
}
/*!
@@ -342,10 +335,7 @@ qreal QRawFont::leading() const
*/
qreal QRawFont::averageCharWidth() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->averageCharWidth().toReal();
+ return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
}
/*!
@@ -355,10 +345,7 @@ qreal QRawFont::averageCharWidth() const
*/
qreal QRawFont::maxCharWidth() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->maxCharWidth();
+ return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
}
/*!
@@ -370,10 +357,7 @@ qreal QRawFont::maxCharWidth() const
*/
qreal QRawFont::pixelSize() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->fontDef.pixelSize;
+ return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
}
/*!
@@ -386,10 +370,7 @@ qreal QRawFont::pixelSize() const
*/
qreal QRawFont::unitsPerEm() const
{
- if (!isValid())
- return 0.0;
-
- return d->fontEngine->emSquareSize().toReal();
+ return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
}
/*!
@@ -397,10 +378,7 @@ qreal QRawFont::unitsPerEm() const
*/
QString QRawFont::familyName() const
{
- if (!isValid())
- return QString();
-
- return d->fontEngine->fontDef.family;
+ return d->isValid() ? d->fontEngine->fontDef.family : QString();
}
/*!
@@ -410,10 +388,7 @@ QString QRawFont::familyName() const
*/
QString QRawFont::styleName() const
{
- if (!isValid())
- return QString();
-
- return d->fontEngine->fontDef.styleName;
+ return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
}
/*!
@@ -423,10 +398,7 @@ QString QRawFont::styleName() const
*/
QFont::Style QRawFont::style() const
{
- if (!isValid())
- return QFont::StyleNormal;
-
- return QFont::Style(d->fontEngine->fontDef.style);
+ return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
}
/*!
@@ -436,10 +408,7 @@ QFont::Style QRawFont::style() const
*/
int QRawFont::weight() const
{
- if (!isValid())
- return -1;
-
- return int(d->fontEngine->fontDef.weight);
+ return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
}
/*!
@@ -457,7 +426,7 @@ int QRawFont::weight() const
*/
QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const
{
- if (!isValid())
+ if (!d->isValid())
return QVector<quint32>();
int nglyphs = text.size();
@@ -490,7 +459,7 @@ QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const
*/
bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const
{
- if (!isValid())
+ if (!d->isValid())
return false;
QGlyphLayout glyphs;
@@ -507,7 +476,7 @@ bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *g
*/
QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const
{
- if (!isValid())
+ if (!d->isValid())
return QVector<QPointF>();
int numGlyphs = glyphIndexes.size();
@@ -534,7 +503,7 @@ QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyph
*/
bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const
{
- if (!isValid())
+ if (!d->isValid())
return false;
QGlyphLayout glyphs;
@@ -560,10 +529,7 @@ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *adv
*/
QFont::HintingPreference QRawFont::hintingPreference() const
{
- if (!isValid())
- return QFont::PreferDefaultHinting;
-
- return d->hintingPreference;
+ return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
}
/*!
@@ -574,7 +540,7 @@ QFont::HintingPreference QRawFont::hintingPreference() const
*/
QByteArray QRawFont::fontTable(const char *tagName) const
{
- if (!isValid())
+ if (!d->isValid())
return QByteArray();
const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName);
@@ -597,9 +563,9 @@ extern QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_tru
*/
QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
{
- if (isValid()) {
+ if (d->isValid()) {
QByteArray os2Table = fontTable("OS/2");
- if (!os2Table.isEmpty() && os2Table.size() > 86) {
+ if (os2Table.size() > 86) {
char *data = os2Table.data();
quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42);
quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78);
@@ -627,10 +593,7 @@ QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
*/
bool QRawFont::supportsCharacter(QChar character) const
{
- if (!isValid())
- return false;
-
- return d->fontEngine->canRender(&character, 1);
+ return d->isValid() && d->fontEngine->canRender(&character, 1);
}
/*!
@@ -641,9 +604,6 @@ bool QRawFont::supportsCharacter(QChar character) const
*/
bool QRawFont::supportsCharacter(quint32 ucs4) const
{
- if (!isValid())
- return false;
-
QChar str[2];
int len;
if (!QChar::requiresSurrogates(ucs4)) {
@@ -655,7 +615,7 @@ bool QRawFont::supportsCharacter(quint32 ucs4) const
len = 2;
}
- return d->fontEngine->canRender(str, len);
+ return d->isValid() && d->fontEngine->canRender(str, len);
}
// qfontdatabase.cpp
@@ -667,6 +627,7 @@ extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSyst
*/
QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem)
{
+ QRawFont rawFont;
#if defined(Q_WS_MAC)
QTextLayout layout(QFontDatabase::writingSystemSample(writingSystem), font);
layout.beginLayout();
@@ -677,14 +638,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
// Pick the one matches the family name we originally requested,
// if none of them match, just pick the first one
for (int i = 0; i < list.size(); i++) {
- QGlyphRun glyphs = list.at(i);
- QRawFont rawfont = glyphs.rawFont();
- if (rawfont.familyName() == font.family())
- return rawfont;
+ rawFont = list.at(i).rawFont();
+ if (rawFont.familyName() == font.family())
+ return rawFont;
}
return list.at(0).rawFont();
}
- return QRawFont();
#else
QFontPrivate *font_d = QFontPrivate::get(font);
int script = qt_script_for_writing_system(writingSystem);
@@ -700,15 +659,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
}
if (fe != 0) {
- QRawFont rawFont;
rawFont.d.data()->fontEngine = fe;
rawFont.d.data()->fontEngine->ref.ref();
rawFont.d.data()->hintingPreference = font.hintingPreference();
- return rawFont;
- } else {
- return QRawFont();
}
#endif
+ return rawFont;
}
/*!
@@ -719,7 +675,7 @@ void QRawFont::setPixelSize(qreal pixelSize)
if (d->fontEngine == 0)
return;
- detach();
+ d.detach();
QFontEngine *oldFontEngine = d->fontEngine;
d->fontEngine = d->fontEngine->cloneWithSize(pixelSize);
@@ -734,15 +690,6 @@ void QRawFont::setPixelSize(qreal pixelSize)
/*!
\internal
*/
-void QRawFont::detach()
-{
- if (d->ref != 1)
- d.detach();
-}
-
-/*!
- \internal
-*/
void QRawFontPrivate::cleanUp()
{
platformCleanUp();
diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h
index d5b5680..cf77996 100644
--- a/src/gui/text/qrawfont.h
+++ b/src/gui/text/qrawfont.h
@@ -81,7 +81,10 @@ public:
bool isValid() const;
QRawFont &operator=(const QRawFont &other);
+
bool operator==(const QRawFont &other) const;
+ inline bool operator!=(const QRawFont &other) const
+ { return !operator==(other); }
QString familyName() const;
QString styleName() const;
@@ -132,9 +135,6 @@ public:
private:
friend class QRawFontPrivate;
-
- void detach();
-
QExplicitlySharedDataPointer<QRawFontPrivate> d;
};
diff --git a/src/gui/text/qrawfont_p.h b/src/gui/text/qrawfont_p.h
index fdf7cad..3557751 100644
--- a/src/gui/text/qrawfont_p.h
+++ b/src/gui/text/qrawfont_p.h
@@ -54,7 +54,9 @@
//
#include "qrawfont.h"
+
#include "qfontengine_p.h"
+#include <QtCore/qthread.h>
#include <QtCore/qthreadstorage.h>
#if !defined(QT_NO_RAWFONT)
@@ -71,21 +73,17 @@ public:
, thread(0)
#if defined(Q_WS_WIN)
, fontHandle(NULL)
- , ptrAddFontMemResourceEx(NULL)
- , ptrRemoveFontMemResourceEx(NULL)
#endif
{}
QRawFontPrivate(const QRawFontPrivate &other)
- : hintingPreference(other.hintingPreference)
+ : fontEngine(other.fontEngine)
+ , hintingPreference(other.hintingPreference)
, thread(other.thread)
#if defined(Q_WS_WIN)
, fontHandle(NULL)
- , ptrAddFontMemResourceEx(other.ptrAddFontMemResourceEx)
- , ptrRemoveFontMemResourceEx(other.ptrRemoveFontMemResourceEx)
#endif
{
- fontEngine = other.fontEngine;
if (fontEngine != 0)
fontEngine->ref.ref();
}
@@ -96,6 +94,12 @@ public:
cleanUp();
}
+ inline bool isValid() const
+ {
+ Q_ASSERT(thread == 0 || thread == QThread::currentThread());
+ return fontEngine != 0;
+ }
+
void cleanUp();
void platformCleanUp();
void platformLoadFromData(const QByteArray &fontData,
@@ -111,14 +115,7 @@ public:
#if defined(Q_WS_WIN)
HANDLE fontHandle;
-
- typedef HANDLE (WINAPI *PtrAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *);
- typedef BOOL (WINAPI *PtrRemoveFontMemResourceEx)(HANDLE);
-
- PtrAddFontMemResourceEx ptrAddFontMemResourceEx;
- PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx;
-
-#endif // Q_WS_WIN
+#endif
};
QT_END_NAMESPACE
diff --git a/src/gui/text/qrawfont_win.cpp b/src/gui/text/qrawfont_win.cpp
index 779652f..a729e31 100644
--- a/src/gui/text/qrawfont_win.cpp
+++ b/src/gui/text/qrawfont_win.cpp
@@ -40,6 +40,9 @@
****************************************************************************/
#include "qrawfont_p.h"
+
+#if !defined(QT_NO_RAWFONT)
+
#include <private/qsystemlibrary_p.h>
#if !defined(QT_NO_DIRECTWRITE)
@@ -47,8 +50,6 @@
# include <dwrite.h>
#endif
-#if !defined(QT_NO_RAWFONT)
-
QT_BEGIN_NAMESPACE
namespace {
@@ -61,18 +62,16 @@ namespace {
operator T() const
{
T littleEndian = 0;
- for (int i=0; i<sizeof(T); ++i) {
+ for (int i = 0; i < int(sizeof(T)); ++i)
littleEndian |= data[i] << ((sizeof(T) - i - 1) * 8);
- }
return littleEndian;
}
BigEndian<T> &operator=(const T &t)
{
- for (int i=0; i<sizeof(T); ++i) {
+ for (int i = 0; i < int(sizeof(T)); ++i)
data[i] = ((t >> (sizeof(T) - i - 1) * 8) & 0xff);
- }
return *this;
}
@@ -157,7 +156,7 @@ namespace {
class EmbeddedFont
{
public:
- EmbeddedFont(const QByteArray &fontData);
+ EmbeddedFont(const QByteArray &fontData) : m_fontData(fontData) {}
QString changeFamilyName(const QString &newFamilyName);
QByteArray data() const { return m_fontData; }
@@ -168,10 +167,6 @@ namespace {
QByteArray m_fontData;
};
- EmbeddedFont::EmbeddedFont(const QByteArray &fontData) : m_fontData(fontData)
- {
- }
-
TableDirectory *EmbeddedFont::tableDirectoryEntry(const QByteArray &tagName)
{
Q_ASSERT(tagName.size() == 4);
@@ -214,9 +209,9 @@ namespace {
+ nameRecord->offset;
const BigEndian<quint16> *s = reinterpret_cast<const BigEndian<quint16> *>(ptr);
- for (int j=0; j<nameRecord->length / sizeof(quint16); ++j)
- name += QChar(s[j]);
-
+ const BigEndian<quint16> *e = s + nameRecord->length / sizeof(quint16);
+ while (s != e)
+ name += QChar(*s++);
break;
}
}
@@ -525,41 +520,49 @@ extern QFontEngine *qt_load_font_engine_win(const QFontDef &request);
// From qfontdatabase.cpp
extern QFont::Weight weightFromInteger(int weight);
-void QRawFontPrivate::platformCleanUp()
+typedef HANDLE (WINAPI *PtrAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *);
+static PtrAddFontMemResourceEx ptrAddFontMemResourceEx = 0;
+typedef BOOL (WINAPI *PtrRemoveFontMemResourceEx)(HANDLE);
+static PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = 0;
+
+static void resolveGdi32()
{
- if (fontHandle != NULL) {
- if (ptrRemoveFontMemResourceEx == NULL) {
- void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
- ptrRemoveFontMemResourceEx =
- reinterpret_cast<QRawFontPrivate::PtrRemoveFontMemResourceEx>(func);
+ static bool triedResolve = false;
+ if (!triedResolve) {
+ QSystemLibrary gdi32(QLatin1String("gdi32"));
+ if (gdi32.load()) {
+ ptrAddFontMemResourceEx = (PtrAddFontMemResourceEx)gdi32.resolve("AddFontMemResourceEx");
+ ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)gdi32.resolve("RemoveFontMemResourceEx");
}
- if (ptrRemoveFontMemResourceEx == NULL) {
- qWarning("QRawFont::platformCleanUp: Can't find RemoveFontMemResourceEx in gdi32");
- fontHandle = NULL;
- } else {
+ triedResolve = true;
+ }
+}
+
+void QRawFontPrivate::platformCleanUp()
+{
+ if (fontHandle != NULL) {
+ if (ptrRemoveFontMemResourceEx)
ptrRemoveFontMemResourceEx(fontHandle);
- fontHandle = NULL;
- }
+ fontHandle = NULL;
}
}
-void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData,
+void QRawFontPrivate::platformLoadFromData(const QByteArray &fontData,
qreal pixelSize,
QFont::HintingPreference hintingPreference)
{
- QByteArray fontData(_fontData);
EmbeddedFont font(fontData);
#if !defined(QT_NO_DIRECTWRITE)
if (hintingPreference == QFont::PreferDefaultHinting
- || hintingPreference == QFont::PreferFullHinting)
+ || hintingPreference == QFont::PreferFullHinting)
#endif
{
GUID guid;
CoCreateGuid(&guid);
- QString uniqueFamilyName = QString::fromLatin1("f")
+ QString uniqueFamilyName = QLatin1Char('f')
+ QString::number(guid.Data1, 36) + QLatin1Char('-')
+ QString::number(guid.Data2, 36) + QLatin1Char('-')
+ QString::number(guid.Data3, 36) + QLatin1Char('-')
@@ -571,22 +574,13 @@ void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData,
return;
}
- if (ptrAddFontMemResourceEx == NULL || ptrRemoveFontMemResourceEx == NULL) {
- void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx");
- ptrRemoveFontMemResourceEx =
- reinterpret_cast<QRawFontPrivate::PtrRemoveFontMemResourceEx>(func);
-
- func = QSystemLibrary::resolve(QLatin1String("gdi32"), "AddFontMemResourceEx");
- ptrAddFontMemResourceEx =
- reinterpret_cast<QRawFontPrivate::PtrAddFontMemResourceEx>(func);
- }
-
Q_ASSERT(fontHandle == NULL);
- if (ptrAddFontMemResourceEx != NULL && ptrRemoveFontMemResourceEx != NULL) {
+ resolveGdi32();
+ if (ptrAddFontMemResourceEx && ptrRemoveFontMemResourceEx) {
DWORD count = 0;
- fontData = font.data();
- fontHandle = ptrAddFontMemResourceEx(fontData.data(), fontData.size(), 0, &count);
-
+ QByteArray newFontData = font.data();
+ fontHandle = ptrAddFontMemResourceEx((void *)newFontData.constData(), newFontData.size(),
+ 0, &count);
if (count == 0 && fontHandle != NULL) {
ptrRemoveFontMemResourceEx(fontHandle);
fontHandle = NULL;
diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp
index bde2c34..aeeef85 100644
--- a/src/gui/text/qtextcontrol.cpp
+++ b/src/gui/text/qtextcontrol.cpp
@@ -1638,16 +1638,13 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons
return;
}
- if (!mousePressed)
- return;
-
const qreal mouseX = qreal(mousePos.x());
int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit);
if (newCursorPos == -1)
return;
- if (wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
+ if (mousePressed && wordSelectionEnabled && !selectedWordOnDoubleClick.hasSelection()) {
selectedWordOnDoubleClick = cursor;
selectedWordOnDoubleClick.select(QTextCursor::WordUnderCursor);
}
@@ -1656,7 +1653,7 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons
extendBlockwiseSelection(newCursorPos);
else if (selectedWordOnDoubleClick.hasSelection())
extendWordwiseSelection(newCursorPos, mouseX);
- else
+ else if (mousePressed)
setCursorPosition(newCursorPos, QTextCursor::KeepAnchor);
if (interactionFlags & Qt::TextEditable) {
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index 7e7ca6c..acef9fa 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -1511,11 +1511,11 @@ void QTextCursor::deletePreviousChar()
const QTextFragmentData * const frag = fragIt.value();
int fpos = fragIt.position();
QChar uc = d->priv->buffer().at(d->anchor - fpos + frag->stringPosition);
- if (d->anchor > fpos && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
+ if (d->anchor > fpos && uc.isLowSurrogate()) {
// second half of a surrogate, check if we have the first half as well,
// if yes delete both at once
uc = d->priv->buffer().at(d->anchor - 1 - fpos + frag->stringPosition);
- if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
+ if (uc.isHighSurrogate())
--d->anchor;
}
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index aa4a20d..2fc1dbd 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -968,7 +968,7 @@ void QTextEngine::shapeText(int item) const
}
for (int i = 0; i < si.num_glyphs; ++i)
- si.width += glyphs.advances_x[i];
+ si.width += glyphs.advances_x[i] * !glyphs.attributes[i].dontPrint;
}
static inline bool hasCaseChange(const QScriptItem &si)
@@ -993,8 +993,7 @@ static void heuristicSetGlyphAttributes(const QChar *uc, int length, QGlyphLayou
int glyph_pos = 0;
for (int i = 0; i < length; i++) {
- if (uc[i].unicode() >= 0xd800 && uc[i].unicode() < 0xdc00 && i < length-1
- && uc[i+1].unicode() >= 0xdc00 && uc[i+1].unicode() < 0xe000) {
+ if (uc[i].isHighSurrogate() && i < length-1 && uc[i+1].isLowSurrogate()) {
logClusters[i] = glyph_pos;
logClusters[++i] = glyph_pos;
} else {
@@ -1387,6 +1386,7 @@ QTextEngine::~QTextEngine()
if (!stackEngine)
delete layoutData;
delete specialData;
+ resetFontEngineCache();
}
const HB_CharAttributes *QTextEngine::attributes() const
@@ -1447,6 +1447,13 @@ static inline void releaseCachedFontEngine(QFontEngine *fontEngine)
}
}
+void QTextEngine::resetFontEngineCache()
+{
+ releaseCachedFontEngine(feCache.prevFontEngine);
+ releaseCachedFontEngine(feCache.prevScaledFontEngine);
+ feCache.reset();
+}
+
void QTextEngine::invalidate()
{
freeMemory();
@@ -1455,9 +1462,7 @@ void QTextEngine::invalidate()
if (specialData)
specialData->resolvedFormatIndices.clear();
- releaseCachedFontEngine(feCache.prevFontEngine);
- releaseCachedFontEngine(feCache.prevScaledFontEngine);
- feCache.reset();
+ resetFontEngineCache();
}
void QTextEngine::clearLineData()
@@ -2658,7 +2663,7 @@ void QTextEngine::splitItem(int item, int pos) const
QFixed w = 0;
const QGlyphLayout g = shapedGlyphs(&oldItem);
for(int j = 0; j < breakGlyph; ++j)
- w += g.advances_x[j];
+ w += g.advances_x[j] * !g.attributes[j].dontPrint;
newItem.width = oldItem.width - w;
oldItem.width = w;
@@ -2951,7 +2956,7 @@ int QTextEngine::lineNumberForTextPosition(int pos)
return lines.size() - 1;
for (int i = 0; i < lines.size(); ++i) {
const QScriptLine& line = lines[i];
- if (line.from + line.length > pos)
+ if (line.from + line.length + line.trailingSpaces > pos)
return i;
}
return -1;
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index b1bd0c3..9362022 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -376,7 +376,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine
{
// created and filled in QTextLine::layout_helper
QScriptLine()
- : from(0), length(0),
+ : from(0), trailingSpaces(0), length(0),
justified(0), gridfitted(0),
hasTrailingSpaces(0), leadingIncluded(0) {}
QFixed descent;
@@ -388,6 +388,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine
QFixed textWidth;
QFixed textAdvance;
int from;
+ unsigned short trailingSpaces;
signed int length : 28;
mutable uint justified : 1;
mutable uint gridfitted : 1;
@@ -628,6 +629,7 @@ public:
int lineNumberForTextPosition(int pos);
int positionAfterVisualMovement(int oldPos, QTextCursor::MoveOperation op);
void insertionPointsForLine(int lineNum, QVector<int> &insertionPoints);
+ void resetFontEngineCache();
private:
void setBoundary(int strPos) const;
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index 5b60dfa..d130c61 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -820,15 +820,11 @@ QString QTextHtmlParser::parseEntity()
if (uc >= 0x80 && uc < 0x80 + (sizeof(windowsLatin1ExtendedCharacters)/sizeof(windowsLatin1ExtendedCharacters[0])))
uc = windowsLatin1ExtendedCharacters[uc - 0x80];
QString str;
- if (uc > 0xffff) {
- // surrogate pair
- uc -= 0x10000;
- ushort high = uc/0x400 + 0xd800;
- ushort low = uc%0x400 + 0xdc00;
- str.append(QChar(high));
- str.append(QChar(low));
+ if (QChar::requiresSurrogates(uc)) {
+ str += QChar(QChar::highSurrogate(uc));
+ str += QChar(QChar::lowSurrogate(uc));
} else {
- str.append(QChar(uc));
+ str = QChar(uc);
}
return str;
}
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 4fd6ddf..d0c1a0e 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -375,7 +375,7 @@ QTextLayout::~QTextLayout()
void QTextLayout::setFont(const QFont &font)
{
d->fnt = font;
- d->feCache.reset();
+ d->resetFontEngineCache();
}
/*!
@@ -515,7 +515,7 @@ void QTextLayout::setAdditionalFormats(const QList<FormatRange> &formatList)
}
if (d->block.docHandle())
d->block.docHandle()->documentChange(d->block.position(), d->block.length());
- d->feCache.reset();
+ d->resetFontEngineCache();
}
/*!
@@ -814,7 +814,7 @@ QTextLine QTextLayout::createLine()
if (l && d->lines.at(l-1).length < 0) {
QTextLine(l-1, d).setNumColumns(INT_MAX);
}
- int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length : 0;
+ int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length + d->lines.at(l-1).trailingSpaces : 0;
int strlen = d->layoutData->string.length();
if (l && from >= strlen) {
if (!d->lines.at(l-1).length || d->layoutData->string.at(strlen - 1) != QChar::LineSeparator)
@@ -1708,6 +1708,7 @@ void QTextLine::layout_helper(int maxGlyphs)
{
QScriptLine &line = eng->lines[i];
line.length = 0;
+ line.trailingSpaces = 0;
line.textWidth = 0;
line.hasTrailingSpaces = false;
@@ -1931,7 +1932,7 @@ found:
if (eng->option.flags() & QTextOption::IncludeTrailingSpaces)
line.textWidth += lbh.spaceData.textWidth;
if (lbh.spaceData.length) {
- line.length += lbh.spaceData.length;
+ line.trailingSpaces = lbh.spaceData.length;
line.hasTrailingSpaces = true;
}
@@ -1995,7 +1996,7 @@ int QTextLine::textLength() const
&& eng->block.isValid() && i == eng->lines.count()-1) {
return eng->lines[i].length - 1;
}
- return eng->lines[i].length;
+ return eng->lines[i].length + eng->lines[i].trailingSpaces;
}
static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, QTextItemInt &gf, QTextEngine *eng,
@@ -2506,6 +2507,9 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
int pos = *cursorPos;
int itm;
+ const HB_CharAttributes *attributes = eng->attributes();
+ while (pos < line.from + line.length && !attributes[pos].charStop)
+ pos++;
if (pos == line.from + (int)line.length) {
// end of line ensure we have the last item on the line
itm = eng->findItem(pos-1);
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index a8031e7..d58da37 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -198,12 +198,10 @@ void QLineControl::backspace()
--m_cursor;
if (m_maskData)
m_cursor = prevMaskBlank(m_cursor);
- QChar uc = m_text.at(m_cursor);
- if (m_cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
+ if (m_cursor > 0 && m_text.at(m_cursor).isLowSurrogate()) {
// second half of a surrogate, check if we have the first half as well,
// if yes delete both at once
- uc = m_text.at(m_cursor - 1);
- if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) {
+ if (m_text.at(m_cursor - 1).isHighSurrogate()) {
internalDelete(true);
--m_cursor;
}