From 2c2026df66f237b7313397dd74f6bc3212b94596 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Tue, 26 Apr 2011 12:34:00 +0200 Subject: Set the default graphics system to raster. This change is specific to Mac OS X/Cocoa. Reviewed-by: Lars Knoll --- src/gui/painting/qgraphicssystemfactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qgraphicssystemfactory.cpp b/src/gui/painting/qgraphicssystemfactory.cpp index 62a60d7..6212674 100644 --- a/src/gui/painting/qgraphicssystemfactory.cpp +++ b/src/gui/painting/qgraphicssystemfactory.cpp @@ -74,7 +74,7 @@ QGraphicsSystem *QGraphicsSystemFactory::create(const QString& key) if (system.isEmpty()) { system = QLatin1String("runtime"); } -#elif defined (QT_GRAPHICSSYSTEM_RASTER) && !defined(Q_WS_WIN) && !defined(Q_OS_SYMBIAN) || defined(Q_WS_X11) +#elif defined (QT_GRAPHICSSYSTEM_RASTER) && !defined(Q_WS_WIN) && !defined(Q_OS_SYMBIAN) || defined(Q_WS_X11) || (defined (Q_WS_MAC) && defined(QT_MAC_USE_COCOA)) if (system.isEmpty()) { system = QLatin1String("raster"); } -- cgit v0.12 From 244fedd484b022881b906b1bc794d5af19d02843 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 29 Apr 2011 12:26:08 +0200 Subject: Change the repaint() to an update(). Forcing to repaint might cause a recursive repaint. Since there is no apparent reason to directly repaint, we just call update(). Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qwidget_mac.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 354f05b..8dc9d2e 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -2733,7 +2733,7 @@ QWidget::macCGHandle() const return handle(); } -void qt_mac_repaintParentUnderAlienWidget(QWidget *alienWidget) +void qt_mac_updateParentUnderAlienWidget(QWidget *alienWidget) { QWidget *nativeParent = alienWidget->nativeParentWidget(); if (!nativeParent) @@ -2741,7 +2741,7 @@ void qt_mac_repaintParentUnderAlienWidget(QWidget *alienWidget) QPoint globalPos = alienWidget->mapToGlobal(QPoint(0, 0)); QRect dirtyRect = QRect(nativeParent->mapFromGlobal(globalPos), alienWidget->size()); - nativeParent->repaint(dirtyRect); + nativeParent->update(dirtyRect); } void QWidget::destroy(bool destroyWindow, bool destroySubWindows) @@ -2752,7 +2752,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) if (!isWindow() && parentWidget()) parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); if (!internalWinId()) - qt_mac_repaintParentUnderAlienWidget(this); + qt_mac_updateParentUnderAlienWidget(this); d->deactivateWidgetCleanup(); qt_mac_event_release(this); if(testAttribute(Qt::WA_WState_Created)) { @@ -3683,7 +3683,7 @@ void QWidgetPrivate::hide_sys() [view setHidden:YES]; } else { // INVARIANT: q is alien. Repaint where q is placed instead: - qt_mac_repaintParentUnderAlienWidget(q); + qt_mac_updateParentUnderAlienWidget(q); } #endif } -- cgit v0.12 From 75d2387fbf005b022437855ab6433790372639f8 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Mon, 2 May 2011 10:52:25 +0200 Subject: Fix the update() autotest for raster. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the CoreGraphics engine, we expect the test to fail with update(), but with the raster engine the behavior is the same across platforms. Hence we don't need a special case for Mac OS X with the raster engine. Reviewed-by: Samuel Rødal --- tests/auto/qwidget/tst_qwidget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 35014c9..9c2f6ea 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -4738,7 +4738,8 @@ void tst_QWidget::update() QCOMPARE(w.visibleRegion(), expectedVisible); QCOMPARE(w.paintedRegion, expectedVisible); #ifdef QT_MAC_USE_COCOA - QEXPECT_FAIL(0, "Cocoa compositor says to paint this.", Continue); + if (QApplicationPrivate::graphics_system_name != QLatin1String("raster")) + QEXPECT_FAIL(0, "Cocoa compositor says to paint this.", Continue); #endif QCOMPARE(child.numPaintEvents, 0); -- cgit v0.12 From 747962e6ec20a59b7e2ed67c5cd685258f199a86 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Tue, 3 May 2011 14:28:56 +0200 Subject: Change the repaint() call to an update(). In show_sys(), if we directly call repaint() this will triggers too many UpdateRequest events. This fixes the qwidget autotest "compatibilityChildInsertedEvents". Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qwidget_mac.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 8dc9d2e..27a1bb6 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3526,8 +3526,8 @@ void QWidgetPrivate::show_sys() // INVARIANT: q is native. Just show the view: [view setHidden:NO]; } else { - // INVARIANT: q is alien. Repaint q instead: - q->repaint(); + // INVARIANT: q is alien. Update q instead: + q->update(); } #endif } -- cgit v0.12 From 2c6af885d959f90b801c74dc5d389a720dc9fd1d Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Tue, 3 May 2011 14:29:36 +0200 Subject: Fix the autotest condition. The previous preprocessor directive was aimed to exclude Mac OS X. With the raster engine, the behavior is unified and we don't need to have a separate path for Mac OS X/Cocoa. The new condition excludes only Mac OS X with a graphics system other than raster or Carbon. Reviewed-by: Jiang Jiang --- tests/auto/qwidget/tst_qwidget.cpp | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 9c2f6ea..e266efb 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -6337,11 +6337,15 @@ void tst_QWidget::compatibilityChildInsertedEvents() expected = EventRecorder::EventList() << qMakePair(&widget, QEvent::PolishRequest) - << qMakePair(&widget, QEvent::Type(QEvent::User + 1)) -#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) || defined(Q_WS_QPA) - << qMakePair(&widget, QEvent::UpdateRequest) -#endif - ; + << qMakePair(&widget, QEvent::Type(QEvent::User + 1)); + +#ifndef QT_MAC_USE_CARBON +#ifdef QT_MAC_USE_COCOA + if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) +#endif // QT_MAC_USE_COCOA + expected << qMakePair(&widget, QEvent::UpdateRequest); +#endif // !QT_MAC_USE_CARBON + QCOMPARE(spy.eventList(), expected); } @@ -6433,11 +6437,15 @@ void tst_QWidget::compatibilityChildInsertedEvents() #endif << qMakePair(&widget, QEvent::PolishRequest) << qMakePair(&widget, QEvent::Type(QEvent::User + 1)) - << qMakePair(&widget, QEvent::Type(QEvent::User + 2)) -#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) || defined(Q_WS_QPA) - << qMakePair(&widget, QEvent::UpdateRequest) -#endif - ; + << qMakePair(&widget, QEvent::Type(QEvent::User + 2)); + +#ifndef QT_MAC_USE_CARBON +#ifdef QT_MAC_USE_COCOA + if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) +#endif // QT_MAC_USE_COCOA + expected << qMakePair(&widget, QEvent::UpdateRequest); +#endif // !QT_MAC_USE_CARBON + QCOMPARE(spy.eventList(), expected); } @@ -6529,11 +6537,15 @@ void tst_QWidget::compatibilityChildInsertedEvents() #endif << qMakePair(&widget, QEvent::PolishRequest) << qMakePair(&widget, QEvent::Type(QEvent::User + 1)) - << qMakePair(&widget, QEvent::Type(QEvent::User + 2)) -#if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_QWS) || defined(Q_WS_S60) || defined(Q_WS_QPA) - << qMakePair(&widget, QEvent::UpdateRequest) -#endif - ; + << qMakePair(&widget, QEvent::Type(QEvent::User + 2)); + +#ifndef QT_MAC_USE_CARBON +#ifdef QT_MAC_USE_COCOA + if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) +#endif // QT_MAC_USE_COCOA + expected << qMakePair(&widget, QEvent::UpdateRequest); +#endif // !QT_MAC_USE_CARBON + QCOMPARE(spy.eventList(), expected); } } -- cgit v0.12 From 5aa5c2e2935c1829cc6965198968699f17c24ec0 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 4 May 2011 10:52:20 +0200 Subject: Include pixel size of font in exported HTML from QTextDocument When you copy-pasted rich text in which the font size had been set using setPixelSize() the font size would be mysteriously forgotten. The pixel size property in QTextCharFormat was added ad hoc, and not integrated in the HTML exporter. Task-number: QT-4792 Reviewed-by: Gunnar --- src/gui/text/qtextdocument.cpp | 8 ++++++++ tests/auto/qtextdocument/tst_qtextdocument.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 36f3c6c..9169955 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2099,6 +2099,10 @@ QString QTextHtmlExporter::toHtml(const QByteArray &encoding, ExportMode mode) html += QLatin1String(" font-size:"); html += QString::number(defaultCharFormat.fontPointSize()); html += QLatin1String("pt;"); + } else if (defaultCharFormat.hasProperty(QTextFormat::FontPixelSize)) { + html += QLatin1String(" font-size:"); + html += QString::number(defaultCharFormat.intProperty(QTextFormat::FontPixelSize)); + html += QLatin1String("px;"); } html += QLatin1String(" font-weight:"); @@ -2179,6 +2183,10 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) html += QLatin1Char(';'); attributesEmitted = true; } + } else if (format.hasProperty(QTextFormat::FontPixelSize)) { + html += QLatin1String(" font-size:"); + html += QString::number(format.intProperty(QTextFormat::FontPixelSize)); + html += QLatin1String("px;"); } if (format.hasProperty(QTextFormat::FontWeight) diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 6675c99..26fa43d 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -180,6 +180,8 @@ private slots: void escape_data(); void escape(); + void copiedFontSize(); + private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); @@ -2734,5 +2736,29 @@ void tst_QTextDocument::escape() QCOMPARE(Qt::escape(original), expected); } +void tst_QTextDocument::copiedFontSize() +{ + QTextDocument documentInput; + QTextDocument documentOutput; + + QFont fontInput; + fontInput.setPixelSize(24); // With pixels font size is not transfered in html + + QTextCursor cursorInput(&documentInput); + QTextCharFormat formatInput = cursorInput.charFormat(); + formatInput.setFont(fontInput); + cursorInput.insertText("Should be the same font", formatInput); + cursorInput.select(QTextCursor::Document); + + QTextDocumentFragment fragmentInput(cursorInput); + QString html = fragmentInput.toHtml(); + + QTextCursor cursorOutput(&documentOutput); + QTextDocumentFragment fragmentOutput = QTextDocumentFragment::fromHtml(html); + cursorOutput.insertFragment(fragmentOutput); + + QCOMPARE(cursorOutput.charFormat().font().pixelSize(), 24); +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" -- cgit v0.12 From c8f299b7e675c839b16d750cd2633a57cdd0526f Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 4 May 2011 16:06:06 +0200 Subject: Add a way to retrieve CTFontRef from QFont Since macFontID restricts to quint32, we have to return that in QFont::handle. Task-number: QTBUG-17890 Reviewed-by: Eskil --- src/gui/text/qfont_mac.cpp | 7 ++++--- src/gui/text/qfontengine_coretext_p.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qfont_mac.cpp b/src/gui/text/qfont_mac.cpp index daf68c0..044fd84 100644 --- a/src/gui/text/qfont_mac.cpp +++ b/src/gui/text/qfont_mac.cpp @@ -43,6 +43,7 @@ #include "qfont_p.h" #include "qfontengine_p.h" #include "qfontengine_mac_p.h" +#include "qfontengine_coretext_p.h" #include "qfontinfo.h" #include "qfontmetrics.h" #include "qpaintdevice.h" @@ -119,10 +120,10 @@ quint32 QFont::macFontID() const // ### need 64-bit version // Returns an ATSUFonFamilyRef Qt::HANDLE QFont::handle() const { -#if 0 +#ifdef QT_MAC_USE_COCOA QFontEngine *fe = d->engineForScript(QUnicodeTables::Common); - if (fe && fe->type() == QFontEngine::Mac) - return (Qt::HANDLE)static_cast(fe)->fontFamilyRef(); + if (fe && fe->type() == QFontEngine::Multi) + return (Qt::HANDLE)static_cast(fe)->macFontID(); #endif return 0; } diff --git a/src/gui/text/qfontengine_coretext_p.h b/src/gui/text/qfontengine_coretext_p.h index bb80a9b..3775bc6 100644 --- a/src/gui/text/qfontengine_coretext_p.h +++ b/src/gui/text/qfontengine_coretext_p.h @@ -124,6 +124,8 @@ public: QScriptItem *si) const; virtual const char *name() const { return "CoreText"; } + inline CTFontRef macFontID() const { return ctfont; } + protected: virtual void loadEngine(int at); -- cgit v0.12 From 111accbf9aaf95b052448ecb70937c61e9b59d66 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 5 May 2011 13:17:26 +0200 Subject: Only enable design metrics for scalable fonts Bitmap fonts don't have linear advance at all. Reviewed-by: Eskil --- src/gui/text/qfontengine_ft.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 237cde4..4dae2a3 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -1597,7 +1597,7 @@ void QFontEngineFT::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlag FT_Face face = 0; bool design = (default_hint_style == HintNone || default_hint_style == HintLight || - (flags & HB_ShaperFlag_UseDesignMetrics)); + (flags & HB_ShaperFlag_UseDesignMetrics)) && FT_IS_SCALABLE(freetype->face); for (int i = 0; i < glyphs->numGlyphs; i++) { Glyph *g = defaultGlyphSet.getGlyph(glyphs->glyphs[i]); if (g) { -- cgit v0.12 From 7ac511d8d906575dff1a02361e31251b244d3b3a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 5 May 2011 13:43:13 +0200 Subject: Remove misspelled comment in tst_qtextdocument.cpp The comment was copy-pasted, spelling error and all, from the example in the bug report, and really doesn't make any sense at all in this context. Reviewed-by: TrustMe --- tests/auto/qtextdocument/tst_qtextdocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 26fa43d..7aa6578 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -2742,7 +2742,7 @@ void tst_QTextDocument::copiedFontSize() QTextDocument documentOutput; QFont fontInput; - fontInput.setPixelSize(24); // With pixels font size is not transfered in html + fontInput.setPixelSize(24); QTextCursor cursorInput(&documentInput); QTextCharFormat formatInput = cursorInput.charFormat(); -- cgit v0.12 From 55446d104db77fc7994ab12352b1c08bb7b63346 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 6 May 2011 10:25:20 +0200 Subject: Fix QPainter::drawGlyphs() with non-affine transformation When the matrix has an non-affine transformation, the text will have to be rendered using the default path-renderer. This means going through the drawTextItem() path (since drawStaticText() has no support for those transformations) and it also means not pre-transforming the coordinates, since the default implementation of drawTextItem() supports transformations. Task-number: QTBUG-18214 Reviewed-by: Jiang Jiang --- src/gui/painting/qpainter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 9e28102..ee960d1 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5819,6 +5819,13 @@ void QPainter::drawGlyphs(const QPointF &position, const QGlyphs &glyphs) d->extended != 0 ? qt_paintengine_supports_transformations(d->extended->type()) : qt_paintengine_supports_transformations(d->engine->type()); + + // If the matrix is not affine, the paint engine will fall back to + // drawing the glyphs as paths, which in turn means we should not + // preprocess the glyph positions + if (!d->state->matrix.isAffine()) + paintEngineSupportsTransformations = true; + for (int i=0; imatrix.isAffine()) { QStaticTextItem staticTextItem; staticTextItem.color = state->pen.color(); staticTextItem.font = state->font; -- cgit v0.12 From 891b6ac7236d21b69bdb54b00051422cee004059 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 6 May 2011 13:31:43 +0200 Subject: Add internal documentation for QUnifiedToolbarSurface. This document is aimed for developers. This is why it is directly written in the header file. This is not part of the public API. Reviewed-by: Richard Moe Gustavsen --- src/gui/painting/qunifiedtoolbarsurface_mac_p.h | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h index 0a7ebf1..6b1243e 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h +++ b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h @@ -65,6 +65,39 @@ QT_BEGIN_NAMESPACE class QNativeImage; +// +// This is the implementation of the unified toolbar on Mac OS X +// with the graphics system raster. +// +// General idea: +// ------------- +// We redirect the painting of widgets inside the unified toolbar +// to a special window surface, the QUnifiedToolbarSurface. +// We need a separate window surface because the unified toolbar +// is out of the content view. +// The input system is the same as for the unified toolbar with the +// native (CoreGraphics) engine. +// +// Execution flow: +// --------------- +// The unified toolbar is triggered by QMainWindow::setUnifiedTitleAndToolBarOnMac(). +// It calls QMainWindowLayout::insertIntoMacToolbar() which will +// set all the appropriate variables (offsets, redirection, ...). +// When Qt tells a widget to repaint, QWidgetPrivate::drawWidget() +// checks if the widget is inside the unified toolbar and exits without +// painting is that is the case. +// We trigger the rendering of the unified toolbar in QWidget::repaint() +// and QWidget::update(). +// We keep track of flush requests via "flushRequested" variable. That +// allow flush() to be a no-op if no repaint occured for a widget. +// We rely on the needsDisplay: and drawRect: mecanism for drawing our +// content into the graphics context. +// +// Notes: +// ------ +// The painting of items inside the unified toolbar is expensive. +// Too many repaints will drastically slow down the whole application. +// class QUnifiedToolbarSurfacePrivate { -- cgit v0.12 From a423ff5474b89028eeca95b254f5184311c8223b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 6 May 2011 15:23:43 +0200 Subject: Remove warning from QColor::setNamedColor(). This warning is pointless as the user can anyway check if the color is valid after making the call by calling isValid(). Using isValidColor() could be used but it has a big performance overhead as validation then needs to be done twice. Task-number: QTBUG-19098 Reviewed-by: Erik Verbruggen --- src/gui/painting/qcolor.cpp | 3 +-- tests/auto/qcolor/tst_qcolor.cpp | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index ff6c24e..cd87d21 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -532,8 +532,7 @@ QString QColor::name() const void QColor::setNamedColor(const QString &name) { - if (!setColorFromString(name)) - qWarning("QColor::setNamedColor: Unknown color name '%s'", name.toLatin1().constData()); + setColorFromString(name); } /*! diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp index d42c26c..b02537e 100644 --- a/tests/auto/qcolor/tst_qcolor.cpp +++ b/tests/auto/qcolor/tst_qcolor.cpp @@ -1506,7 +1506,6 @@ void tst_QColor::setallowX11ColorNames() for (int i = 0; i < x11RgbTblSize; ++i) { QString colorName = QLatin1String(x11RgbTbl[i].name); QColor color; - QTest::ignoreMessage(QtWarningMsg, QString("QColor::setNamedColor: Unknown color name '%1'").arg(colorName).toLatin1()); color.setNamedColor(colorName); QVERIFY(!color.isValid()); } @@ -1528,7 +1527,6 @@ void tst_QColor::setallowX11ColorNames() for (int i = 0; i < x11RgbTblSize; ++i) { QString colorName = QLatin1String(x11RgbTbl[i].name); QColor color; - QTest::ignoreMessage(QtWarningMsg, QString("QColor::setNamedColor: Unknown color name '%1'").arg(colorName).toLatin1()); color.setNamedColor(colorName); QVERIFY(!color.isValid()); } -- cgit v0.12 From 821b8b540af491ce60d35bd84d3c91399ecc0d16 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 6 May 2011 15:45:37 +0200 Subject: Fix QRawFont::setPixelSize() on Mac When refactoring the setPixelSize() code of QRawFont, it was broken on Mac. To avoid making the same mistake again, I've added a simple autotest to check that the pixel size is actually set. Reviewed-by: Jiang Jiang --- src/gui/text/qfontengine_coretext.mm | 2 +- tests/auto/qrawfont/tst_qrawfont.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfontengine_coretext.mm b/src/gui/text/qfontengine_coretext.mm index d4df218..cbf51e6 100644 --- a/src/gui/text/qfontengine_coretext.mm +++ b/src/gui/text/qfontengine_coretext.mm @@ -871,7 +871,7 @@ QFontEngine *QCoreTextFontEngine::cloneWithSize(qreal pixelSize) const newFontDef.pixelSize = pixelSize; newFontDef.pointSize = pixelSize * 72.0 / qt_defaultDpi(); - return new QCoreTextFontEngine(cgFont, fontDef); + return new QCoreTextFontEngine(cgFont, newFontDef); } QT_END_NAMESPACE diff --git a/tests/auto/qrawfont/tst_qrawfont.cpp b/tests/auto/qrawfont/tst_qrawfont.cpp index 4b42c74..ad16a9a 100644 --- a/tests/auto/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/qrawfont/tst_qrawfont.cpp @@ -91,6 +91,9 @@ private slots: void unsupportedWritingSystem_data(); void unsupportedWritingSystem(); + + void rawFontSetPixelSize_data(); + void rawFontSetPixelSize(); #endif // QT_NO_RAWFONT }; @@ -807,6 +810,39 @@ void tst_QRawFont::unsupportedWritingSystem() fontDatabase.removeApplicationFont(id); } +void tst_QRawFont::rawFontSetPixelSize_data() +{ + QTest::addColumn("hintingPreference"); + + QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting; + QTest::newRow("No hinting preference") << QFont::PreferNoHinting; + QTest::newRow("Vertical hinting preference") << QFont::PreferVerticalHinting; + QTest::newRow("Full hinting preference") << QFont::PreferFullHinting; +} + +void tst_QRawFont::rawFontSetPixelSize() +{ + QFETCH(QFont::HintingPreference, hintingPreference); + + QTextLayout layout("Foobar"); + + QFont font = layout.font(); + font.setHintingPreference(hintingPreference); + font.setPixelSize(12); + layout.setFont(font); + + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QGlyphs glyphs = layout.glyphs().at(0); + QRawFont rawFont = glyphs.font(); + QCOMPARE(rawFont.pixelSize(), 12.0); + + rawFont.setPixelSize(24); + QCOMPARE(rawFont.pixelSize(), 24.0); +} + #endif // QT_NO_RAWFONT QTEST_MAIN(tst_QRawFont) -- cgit v0.12 From 84ef364302728b68d2d29ea9c4ccbec32c7bb115 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 10 May 2011 09:43:00 +0200 Subject: Rename QGlyphs -> QGlyphRun API clean-up for QGlyphRun: 1. QGlyphs -> QGlyphRun 2. QGlyphRun's font()/setFont() -> rawFont()/setRawFont() 3. QPainter::drawGlyphs() -> drawGlyphRun() 4. QTextLayout and QTextFragment's glyphs() -> glyphRuns() Reviewed-by: Jiang Jiang --- src/gui/painting/qpaintbuffer.cpp | 6 +- src/gui/painting/qpainter.cpp | 18 +- src/gui/painting/qpainter.h | 4 +- src/gui/text/qglyphrun.cpp | 324 ++++++++++++++++++ src/gui/text/qglyphrun.h | 107 ++++++ src/gui/text/qglyphrun_p.h | 103 ++++++ src/gui/text/qglyphs.cpp | 323 ------------------ src/gui/text/qglyphs.h | 107 ------ src/gui/text/qglyphs_p.h | 103 ------ src/gui/text/qrawfont.cpp | 18 +- src/gui/text/qtextlayout.cpp | 22 +- src/gui/text/qtextlayout.h | 6 +- src/gui/text/qtextobject.cpp | 10 +- src/gui/text/qtextobject.h | 4 +- src/gui/text/text.pri | 10 +- tests/auto/gui.pro | 2 +- tests/auto/qglyphrun/qglyphrun.pro | 11 + tests/auto/qglyphrun/test.ttf | Bin 0 -> 3712 bytes tests/auto/qglyphrun/tst_qglyphrun.cpp | 582 +++++++++++++++++++++++++++++++++ tests/auto/qglyphs/qglyphs.pro | 11 - tests/auto/qglyphs/test.ttf | Bin 3712 -> 0 bytes tests/auto/qglyphs/tst_qglyphs.cpp | 582 --------------------------------- tests/auto/qrawfont/tst_qrawfont.cpp | 16 +- 23 files changed, 1185 insertions(+), 1184 deletions(-) create mode 100644 src/gui/text/qglyphrun.cpp create mode 100644 src/gui/text/qglyphrun.h create mode 100644 src/gui/text/qglyphrun_p.h delete mode 100644 src/gui/text/qglyphs.cpp delete mode 100644 src/gui/text/qglyphs.h delete mode 100644 src/gui/text/qglyphs_p.h create mode 100644 tests/auto/qglyphrun/qglyphrun.pro create mode 100644 tests/auto/qglyphrun/test.ttf create mode 100644 tests/auto/qglyphrun/tst_qglyphrun.cpp delete mode 100644 tests/auto/qglyphs/qglyphs.pro delete mode 100644 tests/auto/qglyphs/test.ttf delete mode 100644 tests/auto/qglyphs/tst_qglyphs.cpp diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp index 51171c5..6f6cd6f 100644 --- a/src/gui/painting/qpaintbuffer.cpp +++ b/src/gui/painting/qpaintbuffer.cpp @@ -1768,12 +1768,12 @@ void QPainterReplayer::process(const QPaintBufferCommand &cmd) rawFontD->fontEngine = fontD->engineForScript(QUnicodeTables::Common); rawFontD->fontEngine->ref.ref(); - QGlyphs glyphs; - glyphs.setFont(rawFont); + QGlyphRun glyphs; + glyphs.setRawFont(rawFont); glyphs.setGlyphIndexes(glyphIndexes); glyphs.setPositions(positions); - painter->drawGlyphs(QPointF(), glyphs); + painter->drawGlyphRun(QPointF(), glyphs); break; } #endif diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index ee960d1..7130fbf 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -62,7 +62,7 @@ #include "qthread.h" #include "qvarlengtharray.h" #include "qstatictext.h" -#include "qglyphs.h" +#include "qglyphrun.h" #include #include @@ -73,7 +73,7 @@ #include #include #include -#include +#include #include #include @@ -5798,19 +5798,19 @@ void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QR \since 4.8 - \sa QGlyphs::setFont(), QGlyphs::setPositions(), QGlyphs::setGlyphIndexes() + \sa QGlyphRun::setRawFont(), QGlyphRun::setPositions(), QGlyphRun::setGlyphIndexes() */ #if !defined(QT_NO_RAWFONT) -void QPainter::drawGlyphs(const QPointF &position, const QGlyphs &glyphs) +void QPainter::drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun) { Q_D(QPainter); - QRawFont font = glyphs.font(); + QRawFont font = glyphRun.rawFont(); if (!font.isValid()) return; - QVector glyphIndexes = glyphs.glyphIndexes(); - QVector glyphPositions = glyphs.positions(); + QVector glyphIndexes = glyphRun.glyphIndexes(); + QVector glyphPositions = glyphRun.positions(); int count = qMin(glyphIndexes.size(), glyphPositions.size()); QVarLengthArray fixedPointPositions(count); @@ -5833,8 +5833,8 @@ void QPainter::drawGlyphs(const QPointF &position, const QGlyphs &glyphs) fixedPointPositions[i] = QFixedPoint::fromPointF(processedPosition); } - d->drawGlyphs(glyphIndexes.data(), fixedPointPositions.data(), count, font, glyphs.overline(), - glyphs.underline(), glyphs.strikeOut()); + d->drawGlyphs(glyphIndexes.data(), fixedPointPositions.data(), count, font, glyphRun.overline(), + glyphRun.underline(), glyphRun.strikeOut()); } void QPainterPrivate::drawGlyphs(quint32 *glyphArray, QFixedPoint *positions, int glyphCount, diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 1a432e6..601c386 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -79,7 +79,7 @@ class QTextItem; class QMatrix; class QTransform; class QStaticText; -class QGlyphs; +class QGlyphRun; class QPainterPrivateDeleter; @@ -400,7 +400,7 @@ public: Qt::LayoutDirection layoutDirection() const; #if !defined(QT_NO_RAWFONT) - void drawGlyphs(const QPointF &position, const QGlyphs &glyphs); + void drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun); #endif void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText); diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp new file mode 100644 index 0000000..ea52788 --- /dev/null +++ b/src/gui/text/qglyphrun.cpp @@ -0,0 +1,324 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qglobal.h" + +#if !defined(QT_NO_RAWFONT) + +#include "qglyphrun.h" +#include "qglyphrun_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QGlyphRun + \brief The QGlyphRun class provides direct access to the internal glyphs in a font. + \since 4.8 + + \ingroup text + \mainclass + + When Qt displays a string of text encoded in Unicode, it will first convert the Unicode points + into a list of glyph indexes and a list of positions based on one or more fonts. The Unicode + representation of the text and the QFont object will in this case serve as a convenient + abstraction that hides the details of what actually takes place when displaying the text + on-screen. For instance, by the time the text actually reaches the screen, it may be represented + by a set of fonts in addition to the one specified by the user, e.g. in case the originally + selected font did not support all the writing systems contained in the text. + + Under certain circumstances, it can be useful as an application developer to have more low-level + control over which glyphs in a specific font are drawn to the screen. This could for instance + be the case in applications that use an external font engine and text shaper together with Qt. + QGlyphRun provides an interface to the raw data needed to get text on the screen. It + contains a list of glyph indexes, a position for each glyph and a font. + + It is the user's responsibility to ensure that the selected font actually contains the + provided glyph indexes. + + QTextLayout::glyphRuns() or QTextFragment::glyphRuns() can be used to convert unicode encoded + text into a list of QGlyphRun objects, and QPainter::drawGlyphRun() can be used to draw the + glyphs. + + \note Please note that QRawFont is considered local to the thread in which it is constructed. + This in turn means that a new QRawFont will have to be created and set on the QGlyphRun if it is + moved to a different thread. If the QGlyphRun contains a reference to a QRawFont from a different + thread than the current, it will not be possible to draw the glyphs using a QPainter, as the + QRawFont is considered invalid and inaccessible in this case. +*/ + + +/*! + Constructs an empty QGlyphRun object. +*/ +QGlyphRun::QGlyphRun() : d(new QGlyphRunPrivate) +{ +} + +/*! + Constructs a QGlyphRun object which is a copy of \a other. +*/ +QGlyphRun::QGlyphRun(const QGlyphRun &other) +{ + d = other.d; +} + +/*! + Destroys the QGlyphRun. +*/ +QGlyphRun::~QGlyphRun() +{ + // Required for QExplicitlySharedDataPointer +} + +/*! + \internal +*/ +void QGlyphRun::detach() +{ + if (d->ref != 1) + d.detach(); +} + +/*! + Assigns \a other to this QGlyphRun object. +*/ +QGlyphRun &QGlyphRun::operator=(const QGlyphRun &other) +{ + d = other.d; + return *this; +} + +/*! + Compares \a other to this QGlyphRun object. Returns true if the list of glyph indexes, + the list of positions and the font are all equal, otherwise returns false. +*/ +bool QGlyphRun::operator==(const QGlyphRun &other) const +{ + return ((d == other.d) + || (d->glyphIndexes == other.d->glyphIndexes + && d->glyphPositions == other.d->glyphPositions + && d->overline == other.d->overline + && d->underline == other.d->underline + && d->strikeOut == other.d->strikeOut + && d->rawFont == other.d->rawFont)); +} + +/*! + 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); +} + +/*! + \internal + + Adds together the lists of glyph indexes and positions in \a other and this QGlyphRun + object and returns the result. The font in the returned QGlyphRun will be the same as in + this QGlyphRun object. +*/ +QGlyphRun QGlyphRun::operator+(const QGlyphRun &other) const +{ + QGlyphRun ret(*this); + ret += other; + return ret; +} + +/*! + \internal + + Appends the glyph indexes and positions in \a other to this QGlyphRun object and returns + a reference to the current object. +*/ +QGlyphRun &QGlyphRun::operator+=(const QGlyphRun &other) +{ + detach(); + + d->glyphIndexes += other.d->glyphIndexes; + d->glyphPositions += other.d->glyphPositions; + + return *this; +} + +/*! + Returns the font selected for this QGlyphRun object. + + \sa setRawFont() +*/ +QRawFont QGlyphRun::rawFont() const +{ + return d->rawFont; +} + +/*! + Sets the font in which to look up the glyph indexes to \a font. + + \sa rawFont(), setGlyphIndexes() +*/ +void QGlyphRun::setRawFont(const QRawFont &rawFont) +{ + detach(); + d->rawFont = rawFont; +} + +/*! + Returns the glyph indexes for this QGlyphRun object. + + \sa setGlyphIndexes(), setPositions() +*/ +QVector QGlyphRun::glyphIndexes() const +{ + return d->glyphIndexes; +} + +/*! + Set the glyph indexes for this QGlyphRun object to \a glyphIndexes. The glyph indexes must + be valid for the selected font. +*/ +void QGlyphRun::setGlyphIndexes(const QVector &glyphIndexes) +{ + detach(); + d->glyphIndexes = glyphIndexes; +} + +/*! + Returns the position of the edge of the baseline for each glyph in this set of glyph indexes. +*/ +QVector QGlyphRun::positions() const +{ + return d->glyphPositions; +} + +/*! + Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to + \a positions. +*/ +void QGlyphRun::setPositions(const QVector &positions) +{ + detach(); + d->glyphPositions = positions; +} + +/*! + Clears all data in the QGlyphRun object. +*/ +void QGlyphRun::clear() +{ + detach(); + d->glyphPositions = QVector(); + d->glyphIndexes = QVector(); + d->rawFont = QRawFont(); + d->strikeOut = false; + d->overline = false; + d->underline = false; +} + +/*! + Returns true if this QGlyphRun should be painted with an overline decoration. + + \sa setOverline() +*/ +bool QGlyphRun::overline() const +{ + return d->overline; +} + +/*! + Indicates that this QGlyphRun should be painted with an overline decoration if \a overline is true. + Otherwise the QGlyphRun should be painted with no overline decoration. + + \sa overline() +*/ +void QGlyphRun::setOverline(bool overline) +{ + detach(); + d->overline = overline; +} + +/*! + Returns true if this QGlyphRun should be painted with an underline decoration. + + \sa setUnderline() +*/ +bool QGlyphRun::underline() const +{ + return d->underline; +} + +/*! + Indicates that this QGlyphRun should be painted with an underline decoration if \a underline is + true. Otherwise the QGlyphRun should be painted with no underline decoration. + + \sa underline() +*/ +void QGlyphRun::setUnderline(bool underline) +{ + detach(); + d->underline = underline; +} + +/*! + Returns true if this QGlyphRun should be painted with a strike out decoration. + + \sa setStrikeOut() +*/ +bool QGlyphRun::strikeOut() const +{ + return d->strikeOut; +} + +/*! + Indicates that this QGlyphRun should be painted with an strike out decoration if \a strikeOut is + true. Otherwise the QGlyphRun should be painted with no strike out decoration. + + \sa strikeOut() +*/ +void QGlyphRun::setStrikeOut(bool strikeOut) +{ + detach(); + d->strikeOut = strikeOut; +} + +QT_END_NAMESPACE + +#endif // QT_NO_RAWFONT diff --git a/src/gui/text/qglyphrun.h b/src/gui/text/qglyphrun.h new file mode 100644 index 0000000..dcc166e --- /dev/null +++ b/src/gui/text/qglyphrun.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGLYPHRUN_H +#define QGLYPHRUN_H + +#include +#include +#include +#include + +#if !defined(QT_NO_RAWFONT) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QGlyphRunPrivate; +class Q_GUI_EXPORT QGlyphRun +{ +public: + QGlyphRun(); + QGlyphRun(const QGlyphRun &other); + ~QGlyphRun(); + + QRawFont rawFont() const; + void setRawFont(const QRawFont &rawFont); + + QVector glyphIndexes() const; + void setGlyphIndexes(const QVector &glyphIndexes); + + QVector positions() const; + void setPositions(const QVector &positions); + + void clear(); + + QGlyphRun &operator=(const QGlyphRun &other); + bool operator==(const QGlyphRun &other) const; + bool operator!=(const QGlyphRun &other) const; + + void setOverline(bool overline); + bool overline() const; + + void setUnderline(bool underline); + bool underline() const; + + void setStrikeOut(bool strikeOut); + bool strikeOut() const; + +private: + friend class QGlyphRunPrivate; + friend class QTextLine; + + QGlyphRun operator+(const QGlyphRun &other) const; + QGlyphRun &operator+=(const QGlyphRun &other); + + void detach(); + QExplicitlySharedDataPointer d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QT_NO_RAWFONT + +#endif // QGLYPHS_H diff --git a/src/gui/text/qglyphrun_p.h b/src/gui/text/qglyphrun_p.h new file mode 100644 index 0000000..4aa01d6 --- /dev/null +++ b/src/gui/text/qglyphrun_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGLYPHRUN_P_H +#define QGLYPHRUN_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include "qglyphrun.h" +#include "qrawfont.h" + +#include + +#if !defined(QT_NO_RAWFONT) + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QGlyphRunPrivate: public QSharedData +{ +public: + QGlyphRunPrivate() + : overline(false) + , underline(false) + , strikeOut(false) + { + } + + QGlyphRunPrivate(const QGlyphRunPrivate &other) + : QSharedData(other) + , glyphIndexes(other.glyphIndexes) + , glyphPositions(other.glyphPositions) + , rawFont(other.rawFont) + , overline(other.overline) + , underline(other.underline) + , strikeOut(other.strikeOut) + { + } + + QVector glyphIndexes; + QVector glyphPositions; + QRawFont rawFont; + + uint overline : 1; + uint underline : 1; + uint strikeOut : 1; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QGLYPHS_P_H + +#endif // QT_NO_RAWFONT diff --git a/src/gui/text/qglyphs.cpp b/src/gui/text/qglyphs.cpp deleted file mode 100644 index cfea6ec..0000000 --- a/src/gui/text/qglyphs.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglobal.h" - -#if !defined(QT_NO_RAWFONT) - -#include "qglyphs.h" -#include "qglyphs_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QGlyphs - \brief The QGlyphs class provides direct access to the internal glyphs in a font. - \since 4.8 - - \ingroup text - \mainclass - - When Qt displays a string of text encoded in Unicode, it will first convert the Unicode points - into a list of glyph indexes and a list of positions based on one or more fonts. The Unicode - representation of the text and the QFont object will in this case serve as a convenient - abstraction that hides the details of what actually takes place when displaying the text - on-screen. For instance, by the time the text actually reaches the screen, it may be represented - by a set of fonts in addition to the one specified by the user, e.g. in case the originally - selected font did not support all the writing systems contained in the text. - - Under certain circumstances, it can be useful as an application developer to have more low-level - control over which glyphs in a specific font are drawn to the screen. This could for instance - be the case in applications that use an external font engine and text shaper together with Qt. - QGlyphs provides an interface to the raw data needed to get text on the screen. It - contains a list of glyph indexes, a position for each glyph and a font. - - It is the user's responsibility to ensure that the selected font actually contains the - provided glyph indexes. - - QTextLayout::glyphs() or QTextFragment::glyphs() can be used to convert unicode encoded text - into a list of QGlyphs objects, and QPainter::drawGlyphs() can be used to draw the glyphs. - - \note Please note that QRawFont is considered local to the thread in which it is constructed. - This in turn means that a new QRawFont will have to be created and set on the QGlyphs if it is - moved to a different thread. If the QGlyphs contains a reference to a QRawFont from a different - thread than the current, it will not be possible to draw the glyphs using a QPainter, as the - QRawFont is considered invalid and inaccessible in this case. -*/ - - -/*! - Constructs an empty QGlyphs object. -*/ -QGlyphs::QGlyphs() : d(new QGlyphsPrivate) -{ -} - -/*! - Constructs a QGlyphs object which is a copy of \a other. -*/ -QGlyphs::QGlyphs(const QGlyphs &other) -{ - d = other.d; -} - -/*! - Destroys the QGlyphs. -*/ -QGlyphs::~QGlyphs() -{ - // Required for QExplicitlySharedDataPointer -} - -/*! - \internal -*/ -void QGlyphs::detach() -{ - if (d->ref != 1) - d.detach(); -} - -/*! - Assigns \a other to this QGlyphs object. -*/ -QGlyphs &QGlyphs::operator=(const QGlyphs &other) -{ - d = other.d; - return *this; -} - -/*! - Compares \a other to this QGlyphs object. Returns true if the list of glyph indexes, - the list of positions and the font are all equal, otherwise returns false. -*/ -bool QGlyphs::operator==(const QGlyphs &other) const -{ - return ((d == other.d) - || (d->glyphIndexes == other.d->glyphIndexes - && d->glyphPositions == other.d->glyphPositions - && d->overline == other.d->overline - && d->underline == other.d->underline - && d->strikeOut == other.d->strikeOut - && d->font == other.d->font)); -} - -/*! - Compares \a other to this QGlyphs object. Returns true if any of the list of glyph - indexes, the list of positions or the font are different, otherwise returns false. -*/ -bool QGlyphs::operator!=(const QGlyphs &other) const -{ - return !(*this == other); -} - -/*! - \internal - - Adds together the lists of glyph indexes and positions in \a other and this QGlyphs - object and returns the result. The font in the returned QGlyphs will be the same as in - this QGlyphs object. -*/ -QGlyphs QGlyphs::operator+(const QGlyphs &other) const -{ - QGlyphs ret(*this); - ret += other; - return ret; -} - -/*! - \internal - - Appends the glyph indexes and positions in \a other to this QGlyphs object and returns - a reference to the current object. -*/ -QGlyphs &QGlyphs::operator+=(const QGlyphs &other) -{ - detach(); - - d->glyphIndexes += other.d->glyphIndexes; - d->glyphPositions += other.d->glyphPositions; - - return *this; -} - -/*! - Returns the font selected for this QGlyphs object. - - \sa setFont() -*/ -QRawFont QGlyphs::font() const -{ - return d->font; -} - -/*! - Sets the font in which to look up the glyph indexes to \a font. - - \sa font(), setGlyphIndexes() -*/ -void QGlyphs::setFont(const QRawFont &font) -{ - detach(); - d->font = font; -} - -/*! - Returns the glyph indexes for this QGlyphs object. - - \sa setGlyphIndexes(), setPositions() -*/ -QVector QGlyphs::glyphIndexes() const -{ - return d->glyphIndexes; -} - -/*! - Set the glyph indexes for this QGlyphs object to \a glyphIndexes. The glyph indexes must - be valid for the selected font. -*/ -void QGlyphs::setGlyphIndexes(const QVector &glyphIndexes) -{ - detach(); - d->glyphIndexes = glyphIndexes; -} - -/*! - Returns the position of the edge of the baseline for each glyph in this set of glyph indexes. -*/ -QVector QGlyphs::positions() const -{ - return d->glyphPositions; -} - -/*! - Sets the positions of the edge of the baseline for each glyph in this set of glyph indexes to - \a positions. -*/ -void QGlyphs::setPositions(const QVector &positions) -{ - detach(); - d->glyphPositions = positions; -} - -/*! - Clears all data in the QGlyphs object. -*/ -void QGlyphs::clear() -{ - detach(); - d->glyphPositions = QVector(); - d->glyphIndexes = QVector(); - d->font = QRawFont(); - d->strikeOut = false; - d->overline = false; - d->underline = false; -} - -/*! - Returns true if this QGlyphs should be painted with an overline decoration. - - \sa setOverline() -*/ -bool QGlyphs::overline() const -{ - return d->overline; -} - -/*! - Indicates that this QGlyphs should be painted with an overline decoration if \a overline is true. - Otherwise the QGlyphs should be painted with no overline decoration. - - \sa overline() -*/ -void QGlyphs::setOverline(bool overline) -{ - detach(); - d->overline = overline; -} - -/*! - Returns true if this QGlyphs should be painted with an underline decoration. - - \sa setUnderline() -*/ -bool QGlyphs::underline() const -{ - return d->underline; -} - -/*! - Indicates that this QGlyphs should be painted with an underline decoration if \a underline is - true. Otherwise the QGlyphs should be painted with no underline decoration. - - \sa underline() -*/ -void QGlyphs::setUnderline(bool underline) -{ - detach(); - d->underline = underline; -} - -/*! - Returns true if this QGlyphs should be painted with a strike out decoration. - - \sa setStrikeOut() -*/ -bool QGlyphs::strikeOut() const -{ - return d->strikeOut; -} - -/*! - Indicates that this QGlyphs should be painted with an strike out decoration if \a strikeOut is - true. Otherwise the QGlyphs should be painted with no strike out decoration. - - \sa strikeOut() -*/ -void QGlyphs::setStrikeOut(bool strikeOut) -{ - detach(); - d->strikeOut = strikeOut; -} - -QT_END_NAMESPACE - -#endif // QT_NO_RAWFONT diff --git a/src/gui/text/qglyphs.h b/src/gui/text/qglyphs.h deleted file mode 100644 index 4d7dcaf..0000000 --- a/src/gui/text/qglyphs.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLYPHS_H -#define QGLYPHS_H - -#include -#include -#include -#include - -#if !defined(QT_NO_RAWFONT) - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class QGlyphsPrivate; -class Q_GUI_EXPORT QGlyphs -{ -public: - QGlyphs(); - QGlyphs(const QGlyphs &other); - ~QGlyphs(); - - QRawFont font() const; - void setFont(const QRawFont &font); - - QVector glyphIndexes() const; - void setGlyphIndexes(const QVector &glyphIndexes); - - QVector positions() const; - void setPositions(const QVector &positions); - - void clear(); - - QGlyphs &operator=(const QGlyphs &other); - bool operator==(const QGlyphs &other) const; - bool operator!=(const QGlyphs &other) const; - - void setOverline(bool overline); - bool overline() const; - - void setUnderline(bool underline); - bool underline() const; - - void setStrikeOut(bool strikeOut); - bool strikeOut() const; - -private: - friend class QGlyphsPrivate; - friend class QTextLine; - - QGlyphs operator+(const QGlyphs &other) const; - QGlyphs &operator+=(const QGlyphs &other); - - void detach(); - QExplicitlySharedDataPointer d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QT_NO_RAWFONT - -#endif // QGLYPHS_H diff --git a/src/gui/text/qglyphs_p.h b/src/gui/text/qglyphs_p.h deleted file mode 100644 index 944f777..0000000 --- a/src/gui/text/qglyphs_p.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLYPHS_P_H -#define QGLYPHS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of internal files. This header file may change from version to version -// without notice, or even be removed. -// -// We mean it. -// - -#include "qglyphs.h" -#include "qrawfont.h" - -#include - -#if !defined(QT_NO_RAWFONT) - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QGlyphsPrivate: public QSharedData -{ -public: - QGlyphsPrivate() - : overline(false) - , underline(false) - , strikeOut(false) - { - } - - QGlyphsPrivate(const QGlyphsPrivate &other) - : QSharedData(other) - , glyphIndexes(other.glyphIndexes) - , glyphPositions(other.glyphPositions) - , font(other.font) - , overline(other.overline) - , underline(other.underline) - , strikeOut(other.strikeOut) - { - } - - QVector glyphIndexes; - QVector glyphPositions; - QRawFont font; - - uint overline : 1; - uint underline : 1; - uint strikeOut : 1; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QGLYPHS_P_H - -#endif // QT_NO_RAWFONT diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 46c892c..4f2a01e 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -78,7 +78,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 - combination with the QGlyphs class to draw specific glyph indexes at specific positions, and + 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. QRawFont only provides support for the main font technologies: GDI and DirectWrite on Windows @@ -87,9 +87,9 @@ QT_BEGIN_NAMESPACE QRawFont can be constructed in a number of ways: \list - \o \l It can be constructed by calling QTextLayout::glyphs() or QTextFragment::glyphs(). The - returned QGlyphs objects will contain QRawFont objects which represent the actual fonts - used to render each portion of the text. + \o \l It can be constructed by calling QTextLayout::glyphRuns() or QTextFragment::glyphRuns(). + The returned QGlyphRun objects will contain QRawFont objects which represent the actual + fonts used to render each portion of the text. \o \l It can be constructed by passing a QFont object to QRawFont::fromFont(). The function will return a QRawFont object representing the font that will be selected as response to the QFont query and the selected writing system. @@ -234,7 +234,7 @@ void QRawFont::loadFromData(const QByteArray &fontData, 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. - \sa pathForGlyph(), QPainter::drawGlyphs() + \sa pathForGlyph(), QPainter::drawGlyphRun() */ QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType, const QTransform &transform) const @@ -426,9 +426,9 @@ int QRawFont::weight() const underlying font. Note that in cases where there are other tables in the font that affect the shaping of the text, the returned glyph indexes will not correctly represent the rendering of the text. To get the correctly shaped text, you can use QTextLayout to lay out and shape the - text, and then call QTextLayout::glyphs() to get the set of glyph index list and QRawFont pairs. + text, and then call QTextLayout::glyphRuns() to get the set of glyph index list and QRawFont pairs. - \sa advancesForGlyphIndexes(), QGlyphs, QTextLayout::glyphs(), QTextFragment::glyphs() + \sa advancesForGlyphIndexes(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns() */ QVector QRawFont::glyphIndexesForString(const QString &text) const { @@ -587,12 +587,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ layout.beginLayout(); QTextLine line = layout.createLine(); layout.endLayout(); - QList list = layout.glyphs(); + QList list = layout.glyphRuns(); if (list.size()) { // 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++) { - QGlyphs glyphs = list.at(i); + QGlyphRun glyphs = list.at(i); QRawFont rawfont = glyphs.font(); if (rawfont.familyName() == font.family()) return rawfont; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 01748b9..1280b46 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -52,8 +52,8 @@ #include "qtextformat_p.h" #include "qstyleoption.h" #include "qpainterpath.h" -#include "qglyphs.h" -#include "qglyphs_p.h" +#include "qglyphrun.h" +#include "qglyphrun_p.h" #include "qrawfont.h" #include "qrawfont_p.h" #include @@ -994,12 +994,12 @@ static inline QRectF clipIfValid(const QRectF &rect, const QRectF &clip) \since 4.8 - \sa draw(), QPainter::drawGlyphs() + \sa draw(), QPainter::drawGlyphRun() */ #if !defined(QT_NO_RAWFONT) -QList QTextLayout::glyphs() const +QList QTextLayout::glyphRuns() const { - QList glyphs; + QList glyphs; for (int i=0; ilines.size(); ++i) glyphs += QTextLine(i, d).glyphs(-1, -1); @@ -2093,15 +2093,15 @@ namespace { \since 4.8 - \sa QTextLayout::glyphs() + \sa QTextLayout::glyphRuns() */ #if !defined(QT_NO_RAWFONT) -QList QTextLine::glyphs(int from, int length) const +QList QTextLine::glyphs(int from, int length) const { const QScriptLine &line = eng->lines[i]; if (line.length == 0) - return QList(); + return QList(); QHash glyphLayoutHash; @@ -2166,7 +2166,7 @@ QList QTextLine::glyphs(int from, int length) const } } - QHash, QGlyphs> glyphsHash; + QHash, QGlyphRun> glyphsHash; QList keys = glyphLayoutHash.uniqueKeys(); for (int i=0; i QTextLine::glyphs(int from, int length) const positions.append(positionsArray.at(i).toPointF() + pos); } - QGlyphs glyphIndexes; + QGlyphRun glyphIndexes; glyphIndexes.setGlyphIndexes(glyphs); glyphIndexes.setPositions(positions); glyphIndexes.setOverline(flags.testFlag(QTextItem::Overline)); glyphIndexes.setUnderline(flags.testFlag(QTextItem::Underline)); glyphIndexes.setStrikeOut(flags.testFlag(QTextItem::StrikeOut)); - glyphIndexes.setFont(font); + glyphIndexes.setRawFont(font); QPair key(fontEngine, int(flags)); if (!glyphsHash.contains(key)) diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index 6aa81f9..8fe488a 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include QT_BEGIN_HEADER @@ -174,7 +174,7 @@ public: qreal maximumWidth() const; #if !defined(QT_NO_RAWFONT) - QList glyphs() const; + QList glyphRuns() const; #endif QTextEngine *engine() const { return d; } @@ -249,7 +249,7 @@ private: void layout_helper(int numGlyphs); #if !defined(QT_NO_RAWFONT) - QList glyphs(int from, int length) const; + QList glyphs(int from, int length) const; #endif friend class QTextLayout; diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 5c1c8b9..8dabcc7 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -1664,25 +1664,25 @@ QTextBlock::iterator &QTextBlock::iterator::operator--() Returns the glyphs of this text fragment. The positions of the glyphs are relative to the position of the QTextBlock's layout. - \sa QGlyphs, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphs() + \sa QGlyphRun, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphRun() */ #if !defined(QT_NO_RAWFONT) -QList QTextFragment::glyphs() const +QList QTextFragment::glyphRuns() const { if (!p || !n) - return QList(); + return QList(); int pos = position(); int len = length(); if (len == 0) - return QList(); + return QList(); int blockNode = p->blockMap().findNode(pos); const QTextBlockData *blockData = p->blockMap().fragment(blockNode); QTextLayout *layout = blockData->layout; - QList ret; + QList ret; for (int i=0; ilineCount(); ++i) { QTextLine textLine = layout->lineAt(i); ret += textLine.glyphs(pos, len); diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h index ad8e657..1588349 100644 --- a/src/gui/text/qtextobject.h +++ b/src/gui/text/qtextobject.h @@ -44,7 +44,7 @@ #include #include -#include +#include QT_BEGIN_HEADER @@ -317,7 +317,7 @@ public: QString text() const; #if !defined(QT_NO_RAWFONT) - QList glyphs() const; + QList glyphRuns() const; #endif private: diff --git a/src/gui/text/text.pri b/src/gui/text/text.pri index e5d57d0..b6cdc52 100644 --- a/src/gui/text/text.pri +++ b/src/gui/text/text.pri @@ -40,10 +40,10 @@ HEADERS += \ text/qtextodfwriter_p.h \ text/qstatictext_p.h \ text/qstatictext.h \ - text/qglyphs.h \ - text/qglyphs_p.h \ text/qrawfont.h \ - text/qrawfont_p.h + text/qrawfont_p.h \ + text/qglyphrun.h \ + text/qglyphrun_p.h SOURCES += \ text/qfont.cpp \ @@ -74,8 +74,8 @@ SOURCES += \ text/qzip.cpp \ text/qtextodfwriter.cpp \ text/qstatictext.cpp \ - text/qglyphs.cpp \ - text/qrawfont.cpp + text/qrawfont.cpp \ + text/qglyphrun.cpp win32 { SOURCES += \ diff --git a/tests/auto/gui.pro b/tests/auto/gui.pro index 22c5e51..42c8fb4 100644 --- a/tests/auto/gui.pro +++ b/tests/auto/gui.pro @@ -58,7 +58,7 @@ SUBDIRS=\ qfontdialog \ qfontmetrics \ qformlayout \ - qglyphs \ + qglyphrun \ qgraphicsanchorlayout \ qgraphicsanchorlayout1 \ qgraphicseffect \ diff --git a/tests/auto/qglyphrun/qglyphrun.pro b/tests/auto/qglyphrun/qglyphrun.pro new file mode 100644 index 0000000..480ad5b --- /dev/null +++ b/tests/auto/qglyphrun/qglyphrun.pro @@ -0,0 +1,11 @@ +load(qttest_p4) +QT = core gui + +SOURCES += \ + tst_qglyphrun.cpp + +wince*|symbian*: { + DEFINES += SRCDIR=\\\"\\\" +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} diff --git a/tests/auto/qglyphrun/test.ttf b/tests/auto/qglyphrun/test.ttf new file mode 100644 index 0000000..9043a57 Binary files /dev/null and b/tests/auto/qglyphrun/test.ttf differ diff --git a/tests/auto/qglyphrun/tst_qglyphrun.cpp b/tests/auto/qglyphrun/tst_qglyphrun.cpp new file mode 100644 index 0000000..aefc228 --- /dev/null +++ b/tests/auto/qglyphrun/tst_qglyphrun.cpp @@ -0,0 +1,582 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include +#include + +// #define DEBUG_SAVE_IMAGE + +class tst_QGlyphRun: public QObject +{ + Q_OBJECT + +#if !defined(QT_NO_RAWFONT) +private slots: + void initTestCase(); + void cleanupTestCase(); + + void constructionAndDestruction(); + void copyConstructor(); + void assignment(); + void equalsOperator_data(); + void equalsOperator(); + void textLayoutGlyphIndexes(); + void drawExistingGlyphs(); + void drawNonExistentGlyphs(); + void drawMultiScriptText1(); + void drawMultiScriptText2(); + void drawStruckOutText(); + void drawOverlinedText(); + void drawUnderlinedText(); + void drawRightToLeft(); + void detach(); + +private: + int m_testFontId; + QFont m_testFont; +#endif // QT_NO_RAWFONT + +}; + +#if !defined(QT_NO_RAWFONT) + +Q_DECLARE_METATYPE(QGlyphRun); + +void tst_QGlyphRun::initTestCase() +{ + m_testFontId = QFontDatabase::addApplicationFont(SRCDIR "test.ttf"); + QVERIFY(m_testFontId >= 0); + + m_testFont = QFont("QtsSpecialTestFont"); + + QCOMPARE(QFontInfo(m_testFont).family(), QString::fromLatin1("QtsSpecialTestFont")); +} + +void tst_QGlyphRun::cleanupTestCase() +{ + QFontDatabase::removeApplicationFont(m_testFontId); +} + +void tst_QGlyphRun::constructionAndDestruction() +{ + QGlyphRun glyphIndexes; +} + +static QGlyphRun make_dummy_indexes() +{ + QGlyphRun glyphs; + + QVector glyphIndexes; + QVector positions; + QFont font; + font.setPointSize(18); + + glyphIndexes.append(1); + glyphIndexes.append(2); + glyphIndexes.append(3); + + positions.append(QPointF(1, 2)); + positions.append(QPointF(3, 4)); + positions.append(QPointF(5, 6)); + + glyphs.setRawFont(QRawFont::fromFont(font)); + glyphs.setGlyphIndexes(glyphIndexes); + glyphs.setPositions(positions); + + return glyphs; +} + +void tst_QGlyphRun::copyConstructor() +{ + QGlyphRun glyphs; + + { + QVector glyphIndexes; + QVector positions; + QFont font; + font.setPointSize(18); + + glyphIndexes.append(1); + glyphIndexes.append(2); + glyphIndexes.append(3); + + positions.append(QPointF(1, 2)); + positions.append(QPointF(3, 4)); + positions.append(QPointF(5, 6)); + + glyphs.setRawFont(QRawFont::fromFont(font)); + glyphs.setGlyphIndexes(glyphIndexes); + glyphs.setPositions(positions); + } + + QGlyphRun otherGlyphs(glyphs); + QCOMPARE(otherGlyphs.rawFont(), glyphs.rawFont()); + QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes()); + QCOMPARE(glyphs.positions(), otherGlyphs.positions()); +} + +void tst_QGlyphRun::assignment() +{ + QGlyphRun glyphs(make_dummy_indexes()); + + QGlyphRun otherGlyphs = glyphs; + QCOMPARE(otherGlyphs.rawFont(), glyphs.rawFont()); + QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes()); + QCOMPARE(glyphs.positions(), otherGlyphs.positions()); +} + +void tst_QGlyphRun::equalsOperator_data() +{ + QTest::addColumn("one"); + QTest::addColumn("two"); + QTest::addColumn("equals"); + + QGlyphRun one(make_dummy_indexes()); + QGlyphRun two(make_dummy_indexes()); + + QTest::newRow("Identical") << one << two << true; + + { + QGlyphRun busted(two); + + QVector positions = busted.positions(); + positions[2] += QPointF(1, 1); + busted.setPositions(positions); + + + QTest::newRow("Different positions") << one << busted << false; + } + + { + QGlyphRun busted(two); + + QFont font; + font.setPixelSize(busted.rawFont().pixelSize() * 2); + busted.setRawFont(QRawFont::fromFont(font)); + + QTest::newRow("Different fonts") << one << busted << false; + } + + { + QGlyphRun busted(two); + + QVector glyphIndexes = busted.glyphIndexes(); + glyphIndexes[2] += 1; + busted.setGlyphIndexes(glyphIndexes); + + QTest::newRow("Different glyph indexes") << one << busted << false; + } + +} + +void tst_QGlyphRun::equalsOperator() +{ + QFETCH(QGlyphRun, one); + QFETCH(QGlyphRun, two); + QFETCH(bool, equals); + + QCOMPARE(one == two, equals); + QCOMPARE(one != two, !equals); +} + + +void tst_QGlyphRun::textLayoutGlyphIndexes() +{ + QString s; + s.append(QLatin1Char('A')); + s.append(QChar(0xe000)); + + QTextLayout layout(s); + layout.setFont(m_testFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + QList listOfGlyphs = layout.glyphRuns(); + QCOMPARE(listOfGlyphs.size(), 1); + + QGlyphRun glyphs = listOfGlyphs.at(0); + + QCOMPARE(glyphs.glyphIndexes().size(), 2); + QCOMPARE(glyphs.glyphIndexes().at(0), quint32(2)); + QCOMPARE(glyphs.glyphIndexes().at(1), quint32(1)); +} + +void tst_QGlyphRun::drawExistingGlyphs() +{ + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QString s; + s.append(QLatin1Char('A')); + s.append(QChar(0xe000)); + + QTextLayout layout(s); + layout.setFont(m_testFont); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphRun glyphs = layout.glyphRuns().size() > 0 + ? layout.glyphRuns().at(0) + : QGlyphRun(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawExistingGlyphs_textLayoutDraw.png"); + drawGlyphs.save("drawExistingGlyphs_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); +} + +void tst_QGlyphRun::drawNonExistentGlyphs() +{ + QVector glyphIndexes; + glyphIndexes.append(3); + + QVector glyphPositions; + glyphPositions.append(QPointF(0, 0)); + + QGlyphRun glyphs; + glyphs.setGlyphIndexes(glyphIndexes); + glyphs.setPositions(glyphPositions); + glyphs.setRawFont(QRawFont::fromFont(m_testFont)); + + QPixmap image(1000, 1000); + image.fill(Qt::white); + + QPixmap imageBefore = image; + { + QPainter p(&image); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + image.save("drawNonExistentGlyphs.png"); +#endif + + QCOMPARE(image, imageBefore); // Should be unchanged +} + +void tst_QGlyphRun::drawMultiScriptText1() +{ + QString text; + text += QChar(0x03D0); // Greek, beta + + QTextLayout textLayout(text); + textLayout.beginLayout(); + textLayout.createLine(); + textLayout.endLayout(); + + QPixmap textLayoutDraw(1000, 1000); + textLayoutDraw.fill(Qt::white); + + QPixmap drawGlyphs(1000, 1000); + drawGlyphs.fill(Qt::white); + + QList glyphsList = textLayout.glyphRuns(); + QCOMPARE(glyphsList.size(), 1); + + { + QPainter p(&textLayoutDraw); + textLayout.draw(&p, QPointF(50, 50)); + } + + { + QPainter p(&drawGlyphs); + foreach (QGlyphRun glyphs, glyphsList) + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawMultiScriptText1_textLayoutDraw.png"); + drawGlyphs.save("drawMultiScriptText1_drawGlyphIndexes.png"); +#endif + + QCOMPARE(drawGlyphs, textLayoutDraw); +} + + +void tst_QGlyphRun::drawMultiScriptText2() +{ + QString text; + text += QChar(0x0621); // Arabic, Hamza + text += QChar(0x03D0); // Greek, beta + + QTextLayout textLayout(text); + textLayout.beginLayout(); + textLayout.createLine(); + textLayout.endLayout(); + + QPixmap textLayoutDraw(1000, 1000); + textLayoutDraw.fill(Qt::white); + + QPixmap drawGlyphs(1000, 1000); + drawGlyphs.fill(Qt::white); + + QList glyphsList = textLayout.glyphRuns(); + QCOMPARE(glyphsList.size(), 2); + + { + QPainter p(&textLayoutDraw); + textLayout.draw(&p, QPointF(50, 50)); + } + + { + QPainter p(&drawGlyphs); + foreach (QGlyphRun glyphs, glyphsList) + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawMultiScriptText2_textLayoutDraw.png"); + drawGlyphs.save("drawMultiScriptText2_drawGlyphIndexes.png"); +#endif + + QCOMPARE(drawGlyphs, textLayoutDraw); +} + +void tst_QGlyphRun::detach() +{ + QGlyphRun glyphs; + + glyphs.setGlyphIndexes(QVector() << 1 << 2 << 3); + + QGlyphRun otherGlyphs; + otherGlyphs = glyphs; + + QCOMPARE(otherGlyphs.glyphIndexes(), glyphs.glyphIndexes()); + + otherGlyphs.setGlyphIndexes(QVector() << 4 << 5 << 6); + + QCOMPARE(otherGlyphs.glyphIndexes(), QVector() << 4 << 5 << 6); + QCOMPARE(glyphs.glyphIndexes(), QVector() << 1 << 2 << 3); +} + +void tst_QGlyphRun::drawStruckOutText() +{ + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setStrikeOut(true); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphRun glyphs = layout.glyphRuns().size() > 0 + ? layout.glyphRuns().at(0) + : QGlyphRun(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawStruckOutText_textLayoutDraw.png"); + drawGlyphs.save("drawStruckOutText_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); +} + +void tst_QGlyphRun::drawOverlinedText() +{ + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setOverline(true); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphRun glyphs = layout.glyphRuns().size() > 0 + ? layout.glyphRuns().at(0) + : QGlyphRun(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawOverlineText_textLayoutDraw.png"); + drawGlyphs.save("drawOverlineText_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); +} + +void tst_QGlyphRun::drawUnderlinedText() +{ + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QString s = QString::fromLatin1("Foobar"); + + QFont font; + font.setUnderline(true); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphRun glyphs = layout.glyphRuns().size() > 0 + ? layout.glyphRuns().at(0) + : QGlyphRun(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawUnderlineText_textLayoutDraw.png"); + drawGlyphs.save("drawUnderlineText_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); +} + +void tst_QGlyphRun::drawRightToLeft() +{ + QString s; + s.append(QChar(1575)); + s.append(QChar(1578)); + + QPixmap textLayoutDraw(1000, 1000); + QPixmap drawGlyphs(1000, 1000); + + textLayoutDraw.fill(Qt::white); + drawGlyphs.fill(Qt::white); + + QFont font; + font.setUnderline(true); + + QTextLayout layout(s); + layout.setFont(font); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + { + QPainter p(&textLayoutDraw); + layout.draw(&p, QPointF(50, 50)); + } + + QGlyphRun glyphs = layout.glyphRuns().size() > 0 + ? layout.glyphRuns().at(0) + : QGlyphRun(); + + { + QPainter p(&drawGlyphs); + p.drawGlyphRun(QPointF(50, 50), glyphs); + } + +#if defined(DEBUG_SAVE_IMAGE) + textLayoutDraw.save("drawRightToLeft_textLayoutDraw.png"); + drawGlyphs.save("drawRightToLeft_drawGlyphIndexes.png"); +#endif + + QCOMPARE(textLayoutDraw, drawGlyphs); + +} + +#endif // QT_NO_RAWFONT + +QTEST_MAIN(tst_QGlyphRun) +#include "tst_qglyphrun.moc" + diff --git a/tests/auto/qglyphs/qglyphs.pro b/tests/auto/qglyphs/qglyphs.pro deleted file mode 100644 index 5084cf9..0000000 --- a/tests/auto/qglyphs/qglyphs.pro +++ /dev/null @@ -1,11 +0,0 @@ -load(qttest_p4) -QT = core gui - -SOURCES += \ - tst_qglyphs.cpp - -wince*|symbian*: { - DEFINES += SRCDIR=\\\"\\\" -} else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" -} \ No newline at end of file diff --git a/tests/auto/qglyphs/test.ttf b/tests/auto/qglyphs/test.ttf deleted file mode 100644 index 9043a57..0000000 Binary files a/tests/auto/qglyphs/test.ttf and /dev/null differ diff --git a/tests/auto/qglyphs/tst_qglyphs.cpp b/tests/auto/qglyphs/tst_qglyphs.cpp deleted file mode 100644 index ffa0d00..0000000 --- a/tests/auto/qglyphs/tst_qglyphs.cpp +++ /dev/null @@ -1,582 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include -#include -#include - -// #define DEBUG_SAVE_IMAGE - -class tst_QGlyphs: public QObject -{ - Q_OBJECT - -#if !defined(QT_NO_RAWFONT) -private slots: - void initTestCase(); - void cleanupTestCase(); - - void constructionAndDestruction(); - void copyConstructor(); - void assignment(); - void equalsOperator_data(); - void equalsOperator(); - void textLayoutGlyphIndexes(); - void drawExistingGlyphs(); - void drawNonExistentGlyphs(); - void drawMultiScriptText1(); - void drawMultiScriptText2(); - void drawStruckOutText(); - void drawOverlinedText(); - void drawUnderlinedText(); - void drawRightToLeft(); - void detach(); - -private: - int m_testFontId; - QFont m_testFont; -#endif // QT_NO_RAWFONT - -}; - -#if !defined(QT_NO_RAWFONT) - -Q_DECLARE_METATYPE(QGlyphs); - -void tst_QGlyphs::initTestCase() -{ - m_testFontId = QFontDatabase::addApplicationFont(SRCDIR "test.ttf"); - QVERIFY(m_testFontId >= 0); - - m_testFont = QFont("QtsSpecialTestFont"); - - QCOMPARE(QFontInfo(m_testFont).family(), QString::fromLatin1("QtsSpecialTestFont")); -} - -void tst_QGlyphs::cleanupTestCase() -{ - QFontDatabase::removeApplicationFont(m_testFontId); -} - -void tst_QGlyphs::constructionAndDestruction() -{ - QGlyphs glyphIndexes; -} - -static QGlyphs make_dummy_indexes() -{ - QGlyphs glyphs; - - QVector glyphIndexes; - QVector positions; - QFont font; - font.setPointSize(18); - - glyphIndexes.append(1); - glyphIndexes.append(2); - glyphIndexes.append(3); - - positions.append(QPointF(1, 2)); - positions.append(QPointF(3, 4)); - positions.append(QPointF(5, 6)); - - glyphs.setFont(QRawFont::fromFont(font)); - glyphs.setGlyphIndexes(glyphIndexes); - glyphs.setPositions(positions); - - return glyphs; -} - -void tst_QGlyphs::copyConstructor() -{ - QGlyphs glyphs; - - { - QVector glyphIndexes; - QVector positions; - QFont font; - font.setPointSize(18); - - glyphIndexes.append(1); - glyphIndexes.append(2); - glyphIndexes.append(3); - - positions.append(QPointF(1, 2)); - positions.append(QPointF(3, 4)); - positions.append(QPointF(5, 6)); - - glyphs.setFont(QRawFont::fromFont(font)); - glyphs.setGlyphIndexes(glyphIndexes); - glyphs.setPositions(positions); - } - - QGlyphs otherGlyphs(glyphs); - QCOMPARE(otherGlyphs.font(), glyphs.font()); - QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes()); - QCOMPARE(glyphs.positions(), otherGlyphs.positions()); -} - -void tst_QGlyphs::assignment() -{ - QGlyphs glyphs(make_dummy_indexes()); - - QGlyphs otherGlyphs = glyphs; - QCOMPARE(otherGlyphs.font(), glyphs.font()); - QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes()); - QCOMPARE(glyphs.positions(), otherGlyphs.positions()); -} - -void tst_QGlyphs::equalsOperator_data() -{ - QTest::addColumn("one"); - QTest::addColumn("two"); - QTest::addColumn("equals"); - - QGlyphs one(make_dummy_indexes()); - QGlyphs two(make_dummy_indexes()); - - QTest::newRow("Identical") << one << two << true; - - { - QGlyphs busted(two); - - QVector positions = busted.positions(); - positions[2] += QPointF(1, 1); - busted.setPositions(positions); - - - QTest::newRow("Different positions") << one << busted << false; - } - - { - QGlyphs busted(two); - - QFont font; - font.setPixelSize(busted.font().pixelSize() * 2); - busted.setFont(QRawFont::fromFont(font)); - - QTest::newRow("Different fonts") << one << busted << false; - } - - { - QGlyphs busted(two); - - QVector glyphIndexes = busted.glyphIndexes(); - glyphIndexes[2] += 1; - busted.setGlyphIndexes(glyphIndexes); - - QTest::newRow("Different glyph indexes") << one << busted << false; - } - -} - -void tst_QGlyphs::equalsOperator() -{ - QFETCH(QGlyphs, one); - QFETCH(QGlyphs, two); - QFETCH(bool, equals); - - QCOMPARE(one == two, equals); - QCOMPARE(one != two, !equals); -} - - -void tst_QGlyphs::textLayoutGlyphIndexes() -{ - QString s; - s.append(QLatin1Char('A')); - s.append(QChar(0xe000)); - - QTextLayout layout(s); - layout.setFont(m_testFont); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - QList listOfGlyphs = layout.glyphs(); - QCOMPARE(listOfGlyphs.size(), 1); - - QGlyphs glyphs = listOfGlyphs.at(0); - - QCOMPARE(glyphs.glyphIndexes().size(), 2); - QCOMPARE(glyphs.glyphIndexes().at(0), quint32(2)); - QCOMPARE(glyphs.glyphIndexes().at(1), quint32(1)); -} - -void tst_QGlyphs::drawExistingGlyphs() -{ - QPixmap textLayoutDraw(1000, 1000); - QPixmap drawGlyphs(1000, 1000); - - textLayoutDraw.fill(Qt::white); - drawGlyphs.fill(Qt::white); - - QString s; - s.append(QLatin1Char('A')); - s.append(QChar(0xe000)); - - QTextLayout layout(s); - layout.setFont(m_testFont); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - { - QPainter p(&textLayoutDraw); - layout.draw(&p, QPointF(50, 50)); - } - - QGlyphs glyphs = layout.glyphs().size() > 0 - ? layout.glyphs().at(0) - : QGlyphs(); - - { - QPainter p(&drawGlyphs); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawExistingGlyphs_textLayoutDraw.png"); - drawGlyphs.save("drawExistingGlyphs_drawGlyphIndexes.png"); -#endif - - QCOMPARE(textLayoutDraw, drawGlyphs); -} - -void tst_QGlyphs::drawNonExistentGlyphs() -{ - QVector glyphIndexes; - glyphIndexes.append(3); - - QVector glyphPositions; - glyphPositions.append(QPointF(0, 0)); - - QGlyphs glyphs; - glyphs.setGlyphIndexes(glyphIndexes); - glyphs.setPositions(glyphPositions); - glyphs.setFont(QRawFont::fromFont(m_testFont)); - - QPixmap image(1000, 1000); - image.fill(Qt::white); - - QPixmap imageBefore = image; - { - QPainter p(&image); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - image.save("drawNonExistentGlyphs.png"); -#endif - - QCOMPARE(image, imageBefore); // Should be unchanged -} - -void tst_QGlyphs::drawMultiScriptText1() -{ - QString text; - text += QChar(0x03D0); // Greek, beta - - QTextLayout textLayout(text); - textLayout.beginLayout(); - textLayout.createLine(); - textLayout.endLayout(); - - QPixmap textLayoutDraw(1000, 1000); - textLayoutDraw.fill(Qt::white); - - QPixmap drawGlyphs(1000, 1000); - drawGlyphs.fill(Qt::white); - - QList glyphsList = textLayout.glyphs(); - QCOMPARE(glyphsList.size(), 1); - - { - QPainter p(&textLayoutDraw); - textLayout.draw(&p, QPointF(50, 50)); - } - - { - QPainter p(&drawGlyphs); - foreach (QGlyphs glyphs, glyphsList) - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawMultiScriptText1_textLayoutDraw.png"); - drawGlyphs.save("drawMultiScriptText1_drawGlyphIndexes.png"); -#endif - - QCOMPARE(drawGlyphs, textLayoutDraw); -} - - -void tst_QGlyphs::drawMultiScriptText2() -{ - QString text; - text += QChar(0x0621); // Arabic, Hamza - text += QChar(0x03D0); // Greek, beta - - QTextLayout textLayout(text); - textLayout.beginLayout(); - textLayout.createLine(); - textLayout.endLayout(); - - QPixmap textLayoutDraw(1000, 1000); - textLayoutDraw.fill(Qt::white); - - QPixmap drawGlyphs(1000, 1000); - drawGlyphs.fill(Qt::white); - - QList glyphsList = textLayout.glyphs(); - QCOMPARE(glyphsList.size(), 2); - - { - QPainter p(&textLayoutDraw); - textLayout.draw(&p, QPointF(50, 50)); - } - - { - QPainter p(&drawGlyphs); - foreach (QGlyphs glyphs, glyphsList) - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawMultiScriptText2_textLayoutDraw.png"); - drawGlyphs.save("drawMultiScriptText2_drawGlyphIndexes.png"); -#endif - - QCOMPARE(drawGlyphs, textLayoutDraw); -} - -void tst_QGlyphs::detach() -{ - QGlyphs glyphs; - - glyphs.setGlyphIndexes(QVector() << 1 << 2 << 3); - - QGlyphs otherGlyphs; - otherGlyphs = glyphs; - - QCOMPARE(otherGlyphs.glyphIndexes(), glyphs.glyphIndexes()); - - otherGlyphs.setGlyphIndexes(QVector() << 4 << 5 << 6); - - QCOMPARE(otherGlyphs.glyphIndexes(), QVector() << 4 << 5 << 6); - QCOMPARE(glyphs.glyphIndexes(), QVector() << 1 << 2 << 3); -} - -void tst_QGlyphs::drawStruckOutText() -{ - QPixmap textLayoutDraw(1000, 1000); - QPixmap drawGlyphs(1000, 1000); - - textLayoutDraw.fill(Qt::white); - drawGlyphs.fill(Qt::white); - - QString s = QString::fromLatin1("Foobar"); - - QFont font; - font.setStrikeOut(true); - - QTextLayout layout(s); - layout.setFont(font); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - { - QPainter p(&textLayoutDraw); - layout.draw(&p, QPointF(50, 50)); - } - - QGlyphs glyphs = layout.glyphs().size() > 0 - ? layout.glyphs().at(0) - : QGlyphs(); - - { - QPainter p(&drawGlyphs); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawStruckOutText_textLayoutDraw.png"); - drawGlyphs.save("drawStruckOutText_drawGlyphIndexes.png"); -#endif - - QCOMPARE(textLayoutDraw, drawGlyphs); -} - -void tst_QGlyphs::drawOverlinedText() -{ - QPixmap textLayoutDraw(1000, 1000); - QPixmap drawGlyphs(1000, 1000); - - textLayoutDraw.fill(Qt::white); - drawGlyphs.fill(Qt::white); - - QString s = QString::fromLatin1("Foobar"); - - QFont font; - font.setOverline(true); - - QTextLayout layout(s); - layout.setFont(font); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - { - QPainter p(&textLayoutDraw); - layout.draw(&p, QPointF(50, 50)); - } - - QGlyphs glyphs = layout.glyphs().size() > 0 - ? layout.glyphs().at(0) - : QGlyphs(); - - { - QPainter p(&drawGlyphs); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawOverlineText_textLayoutDraw.png"); - drawGlyphs.save("drawOverlineText_drawGlyphIndexes.png"); -#endif - - QCOMPARE(textLayoutDraw, drawGlyphs); -} - -void tst_QGlyphs::drawUnderlinedText() -{ - QPixmap textLayoutDraw(1000, 1000); - QPixmap drawGlyphs(1000, 1000); - - textLayoutDraw.fill(Qt::white); - drawGlyphs.fill(Qt::white); - - QString s = QString::fromLatin1("Foobar"); - - QFont font; - font.setUnderline(true); - - QTextLayout layout(s); - layout.setFont(font); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - { - QPainter p(&textLayoutDraw); - layout.draw(&p, QPointF(50, 50)); - } - - QGlyphs glyphs = layout.glyphs().size() > 0 - ? layout.glyphs().at(0) - : QGlyphs(); - - { - QPainter p(&drawGlyphs); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawUnderlineText_textLayoutDraw.png"); - drawGlyphs.save("drawUnderlineText_drawGlyphIndexes.png"); -#endif - - QCOMPARE(textLayoutDraw, drawGlyphs); -} - -void tst_QGlyphs::drawRightToLeft() -{ - QString s; - s.append(QChar(1575)); - s.append(QChar(1578)); - - QPixmap textLayoutDraw(1000, 1000); - QPixmap drawGlyphs(1000, 1000); - - textLayoutDraw.fill(Qt::white); - drawGlyphs.fill(Qt::white); - - QFont font; - font.setUnderline(true); - - QTextLayout layout(s); - layout.setFont(font); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); - - { - QPainter p(&textLayoutDraw); - layout.draw(&p, QPointF(50, 50)); - } - - QGlyphs glyphs = layout.glyphs().size() > 0 - ? layout.glyphs().at(0) - : QGlyphs(); - - { - QPainter p(&drawGlyphs); - p.drawGlyphs(QPointF(50, 50), glyphs); - } - -#if defined(DEBUG_SAVE_IMAGE) - textLayoutDraw.save("drawRightToLeft_textLayoutDraw.png"); - drawGlyphs.save("drawRightToLeft_drawGlyphIndexes.png"); -#endif - - QCOMPARE(textLayoutDraw, drawGlyphs); - -} - -#endif // QT_NO_RAWFONT - -QTEST_MAIN(tst_QGlyphs) -#include "tst_qglyphs.moc" - diff --git a/tests/auto/qrawfont/tst_qrawfont.cpp b/tests/auto/qrawfont/tst_qrawfont.cpp index ad16a9a..cf46471 100644 --- a/tests/auto/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/qrawfont/tst_qrawfont.cpp @@ -296,12 +296,12 @@ void tst_QRawFont::textLayout() layout.createLine(); layout.endLayout(); - QList glyphss = layout.glyphs(); - QCOMPARE(glyphss.size(), 1); + QList glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 1); - QGlyphs glyphs = glyphss.at(0); + QGlyphRun glyphs = glyphRuns.at(0); - QRawFont rawFont = glyphs.font(); + QRawFont rawFont = glyphs.rawFont(); QVERIFY(rawFont.isValid()); QCOMPARE(rawFont.familyName(), familyName); QCOMPARE(rawFont.pixelSize(), 18.0); @@ -795,11 +795,11 @@ void tst_QRawFont::unsupportedWritingSystem() layout.createLine(); layout.endLayout(); - QList glyphss = layout.glyphs(); - QCOMPARE(glyphss.size(), 1); + QList glyphRuns = layout.glyphRuns(); + QCOMPARE(glyphRuns.size(), 1); - QGlyphs glyphs = glyphss.at(0); - QRawFont layoutFont = glyphs.font(); + QGlyphRun glyphs = glyphRuns.at(0); + QRawFont layoutFont = glyphs.rawFont(); QVERIFY(layoutFont.familyName() != QString::fromLatin1("QtBidiTestFont")); QCOMPARE(layoutFont.pixelSize(), 12.0); -- cgit v0.12 From 4b95d9939db75d7bd55db4bbbf2d67af459f7eb5 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 10 May 2011 13:06:57 +0200 Subject: Compile on Mac Missing API update in Q_WS_MAC block Reviewed-by: Jiang Jiang --- src/gui/text/qrawfont.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 4f2a01e..29394e9 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -593,11 +593,11 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ // 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.font(); + QRawFont rawfont = glyphs.rawFont(); if (rawfont.familyName() == font.family()) return rawfont; } - return list.at(0).font(); + return list.at(0).rawFont(); } return QRawFont(); #else -- cgit v0.12 From 965af9eb2932efae5d736df54c3859460017b6a5 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 10 May 2011 13:30:33 +0200 Subject: Add some QRawFont related low level functions to avoid extra copying Added functions: - QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const - QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const Reviewed-by: Eskil --- src/gui/text/qrawfont.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++---- src/gui/text/qrawfont.h | 2 ++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 29394e9..44ddfd2 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -428,7 +428,7 @@ int QRawFont::weight() const of the text. To get the correctly shaped text, you can use QTextLayout to lay out and shape the text, and then call QTextLayout::glyphRuns() to get the set of glyph index list and QRawFont pairs. - \sa advancesForGlyphIndexes(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns() + \sa advancesForGlyphIndexes(), glyphIndexesForChars(), QGlyphRun, QTextLayout::glyphRuns(), QTextFragment::glyphRuns() */ QVector QRawFont::glyphIndexesForString(const QString &text) const { @@ -437,11 +437,9 @@ QVector QRawFont::glyphIndexesForString(const QString &text) const int nglyphs = text.size(); QVarLengthGlyphLayoutArray glyphs(nglyphs); - if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &nglyphs, - QTextEngine::GlyphIndicesOnly)) { + if (!glyphIndexesForChars(text.data(), text.size(), glyphs.glyphs, &nglyphs)) { glyphs.resize(nglyphs); - if (!d->fontEngine->stringToCMap(text.data(), text.size(), &glyphs, &nglyphs, - QTextEngine::GlyphIndicesOnly)) { + if (!glyphIndexesForChars(text.data(), text.size(), glyphs.glyphs, &nglyphs)) { Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice"); return QVector(); } @@ -455,6 +453,26 @@ QVector QRawFont::glyphIndexesForString(const QString &text) const } /*! + Converts a string of unicode points to glyph indexes using the CMAP table in the + underlying font. The function works like glyphIndexesForString() except it take + an array (\a chars), the results will be returned though \a glyphIndexes array + and number of glyphs will be set in \a numGlyphs. The size of \a glyphIndexes array + must be at least \a numChars, if that's still not enough, this function will return + false, then you can resize \a glyphIndexes from the size returned in \a numGlyphs. + + \sa glyphIndexesForString(), advancesForGlyphIndexes(), QGlyphs, QTextLayout::glyphs(), QTextFragment::glyphs() +*/ +bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const +{ + if (!isValid()) + return false; + + QGlyphLayout glyphs; + glyphs.glyphs = glyphIndexes; + return d->fontEngine->stringToCMap(chars, numChars, &glyphs, numGlyphs, QTextEngine::GlyphIndicesOnly); +} + +/*! Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances give the distance from the position of a given glyph to where the next glyph should be drawn to make it appear as if the two glyphs are unspaced. @@ -480,6 +498,36 @@ QVector QRawFont::advancesForGlyphIndexes(const QVector &glyph } /*! + Returns the QRawFont's advances for each of the \a glyphIndexes in pixel units. The advances + give the distance from the position of a given glyph to where the next glyph should be drawn + to make it appear as if the two glyphs are unspaced. The glyph indexes are given with the + array \a glyphIndexes while the results are returned through \a advances, both of them must + have \a numGlyphs elements. + + \sa QTextLine::horizontalAdvance(), QFontMetricsF::width() +*/ +bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const +{ + if (!isValid()) + return false; + + QGlyphLayout glyphs; + glyphs.glyphs = const_cast(glyphIndexes); + glyphs.numGlyphs = numGlyphs; + QVarLengthArray advances_x(numGlyphs); + QVarLengthArray advances_y(numGlyphs); + glyphs.advances_x = advances_x.data(); + glyphs.advances_y = advances_y.data(); + + d->fontEngine->recalcAdvances(&glyphs, 0); + + for (int i=0; i glyphIndexesForString(const QString &text) const; QVector advancesForGlyphIndexes(const QVector &glyphIndexes) const; + bool glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const; + bool advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const; QImage alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType = SubPixelAntialiasing, -- cgit v0.12 From 0ad6cec5d77fffa5d64b841bd7496088df6fcaab Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 10 May 2011 14:01:43 +0200 Subject: Build fix for tst_qrawfont Reviewed-by: Eskil --- tests/auto/qrawfont/tst_qrawfont.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qrawfont/tst_qrawfont.cpp b/tests/auto/qrawfont/tst_qrawfont.cpp index cf46471..8c58407 100644 --- a/tests/auto/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/qrawfont/tst_qrawfont.cpp @@ -835,8 +835,8 @@ void tst_QRawFont::rawFontSetPixelSize() layout.createLine(); layout.endLayout(); - QGlyphs glyphs = layout.glyphs().at(0); - QRawFont rawFont = glyphs.font(); + QGlyphRun glyphs = layout.glyphRuns().at(0); + QRawFont rawFont = glyphs.rawFont(); QCOMPARE(rawFont.pixelSize(), 12.0); rawFont.setPixelSize(24); -- cgit v0.12 From a368c351928a95d21663bbd0404f887cc3cf7974 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 11 May 2011 11:24:57 +0200 Subject: Fix misspelled word in comment. Reviewed-by: trustme --- src/gui/painting/qunifiedtoolbarsurface_mac_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h index 6b1243e..ce07f5c 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac_p.h +++ b/src/gui/painting/qunifiedtoolbarsurface_mac_p.h @@ -89,7 +89,7 @@ class QNativeImage; // We trigger the rendering of the unified toolbar in QWidget::repaint() // and QWidget::update(). // We keep track of flush requests via "flushRequested" variable. That -// allow flush() to be a no-op if no repaint occured for a widget. +// allow flush() to be a no-op if no repaint occurred for a widget. // We rely on the needsDisplay: and drawRect: mecanism for drawing our // content into the graphics context. // -- cgit v0.12 From 360c5f2c39a39c2a8296f21e6f5f577367610853 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 11 May 2011 13:30:35 +0200 Subject: Move the painting redirection to the unified toolbar surface. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the new parent of a widget is inside the unified toolbar, we need to update the redirection. Task-number: QTBUG-18150 Reviewed-by: Samuel Rødal --- src/gui/kernel/qwidget.cpp | 10 ---------- src/gui/kernel/qwidget_mac.mm | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 80d7b85..4c1a6dd 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1389,16 +1389,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) QApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); extraPaintEngine = 0; - -#ifdef QT_MAC_USE_COCOA - // If we add a child to the unified toolbar, we have to redirect the painting. - if (parentWidget && parentWidget->d_func() && parentWidget->d_func()->isInUnifiedToolbar) { - if (parentWidget->d_func()->unifiedSurface) { - QWidget *toolbar = parentWidget->d_func()->toolbar_ancestor; - parentWidget->d_func()->unifiedSurface->recursiveRedirect(toolbar, toolbar, toolbar->d_func()->toolbar_offset); - } - } -#endif // QT_MAC_USE_COCOA } diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 27a1bb6..468de22 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3032,6 +3032,16 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) q->setAttribute(Qt::WA_WState_Hidden); q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); +#ifdef QT_MAC_USE_COCOA + // If we add a child to the unified toolbar, we have to redirect the painting. + if (parent && parent->d_func() && parent->d_func()->isInUnifiedToolbar) { + if (parent->d_func()->unifiedSurface) { + QWidget *toolbar = parent->d_func()->toolbar_ancestor; + parent->d_func()->unifiedSurface->recursiveRedirect(toolbar, toolbar, toolbar->d_func()->toolbar_offset); + } + } +#endif // QT_MAC_USE_COCOA + if (wasCreated) { transferChildren(); #ifndef QT_MAC_USE_COCOA -- cgit v0.12 From 5eba82b752e85a5d6cb3a893214ed2646d75f362 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 11 May 2011 12:13:01 +0200 Subject: Move QTextCursor::MoveStyle to Qt namespace We cannot use QTextCursor::MoveStyle enums in QTextLine because QTextCursor is not a QObject, while referring to that enum in Q_PROPERTY requires it to be. That's why we need to move the enums in Qt namespace. Reviewed-by: David Boddie --- src/corelib/global/qnamespace.h | 6 ++++++ src/gui/text/qtextcursor.cpp | 18 +++++++++--------- src/gui/text/qtextcursor.h | 4 ---- src/gui/text/qtextdocument.cpp | 6 +++--- src/gui/text/qtextdocument.h | 6 +++--- src/gui/text/qtextdocument_p.cpp | 2 +- src/gui/text/qtextdocument_p.h | 2 +- src/gui/text/qtextengine_p.h | 2 +- src/gui/text/qtextlayout.cpp | 14 +++++++------- src/gui/text/qtextlayout.h | 4 ++-- src/gui/widgets/qlinecontrol.cpp | 2 +- src/gui/widgets/qlinecontrol_p.h | 8 ++++---- src/gui/widgets/qlineedit.cpp | 8 ++++---- src/gui/widgets/qlineedit.h | 5 +++-- tests/auto/qcomplextext/tst_qcomplextext.cpp | 2 +- tests/auto/qlineedit/tst_qlineedit.cpp | 4 ++-- tests/auto/qtextedit/tst_qtextedit.cpp | 4 ++-- 17 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 75ce68a..f086513 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -94,6 +94,7 @@ Qt { Q_ENUMS(GestureState) Q_ENUMS(GestureType) #endif + Q_ENUMS(CursorMoveStyle) #endif // (defined(Q_MOC_RUN) || defined(QT_JAMBI_RUN)) #if defined(Q_MOC_RUN) @@ -1784,6 +1785,11 @@ public: NavigationModeCursorAuto, NavigationModeCursorForceVisible }; + + enum CursorMoveStyle { + LogicalMoveStyle, + VisualMoveStyle + }; } #ifdef Q_MOC_RUN ; diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index 4f6857a..17bcc6c 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -362,7 +362,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor currentCharFormat = -1; bool adjustX = true; QTextBlock blockIt = block(); - bool visualMovement = priv->defaultCursorMoveStyle == QTextCursor::Visual; + bool visualMovement = priv->defaultCursorMoveStyle == Qt::VisualMoveStyle; if (!blockIt.isValid()) return false; @@ -2568,18 +2568,18 @@ QTextDocument *QTextCursor::document() const } /*! - \enum QTextCursor::MoveStyle + \enum Qt::CursorMoveStyle - This enum describes the movement style available to QTextCursor. The options + This enum describes the movement style available to text cursors. The options are: - \value Logical Within a left-to-right text block, increase cursor position - when pressing left arrow key, decrease cursor position when pressing the - right arrow key. If the text block is right-to-left, the opposite behavior + \value LogicalMoveStyle Within a left-to-right text block, decrease cursor + position when pressing left arrow key, increase cursor position when pressing + the right arrow key. If the text block is right-to-left, the opposite behavior applies. - \value Visual Pressing the left arrow key will always cause the cursor to move - left, regardless of the text's writing direction. The same behavior applies to - right arrow key. + \value VisualMoveStyle Pressing the left arrow key will always cause the cursor + to move left, regardless of the text's writing direction. Pressing the right + arrow key will always cause the cursor to move right. */ QT_END_NAMESPACE diff --git a/src/gui/text/qtextcursor.h b/src/gui/text/qtextcursor.h index 9e4c0b8..4eaeb41 100644 --- a/src/gui/text/qtextcursor.h +++ b/src/gui/text/qtextcursor.h @@ -86,10 +86,6 @@ public: MoveAnchor, KeepAnchor }; - enum MoveStyle { - Logical, - Visual - }; void setPosition(int pos, MoveMode mode = MoveAnchor); int position() const; diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 9169955..0d33912 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -589,9 +589,9 @@ void QTextDocument::setDefaultTextOption(const QTextOption &option) \since 4.8 The default cursor movement style is used by all QTextCursor objects - created from the document. The default is QTextCursor::Logical. + created from the document. The default is Qt::LogicalMoveStyle. */ -QTextCursor::MoveStyle QTextDocument::defaultCursorMoveStyle() const +Qt::CursorMoveStyle QTextDocument::defaultCursorMoveStyle() const { Q_D(const QTextDocument); return d->defaultCursorMoveStyle; @@ -602,7 +602,7 @@ QTextCursor::MoveStyle QTextDocument::defaultCursorMoveStyle() const Set the default cursor movement style. */ -void QTextDocument::setDefaultCursorMoveStyle(QTextCursor::MoveStyle style) +void QTextDocument::setDefaultCursorMoveStyle(Qt::CursorMoveStyle style) { Q_D(QTextDocument); d->defaultCursorMoveStyle = style; diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e515b36..b826dc1 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -46,7 +46,6 @@ #include #include #include -#include QT_BEGIN_HEADER @@ -70,6 +69,7 @@ class QUrl; class QVariant; class QRectF; class QTextOption; +class QTextCursor; template class QVector; @@ -269,8 +269,8 @@ public: QTextOption defaultTextOption() const; void setDefaultTextOption(const QTextOption &option); - QTextCursor::MoveStyle defaultCursorMoveStyle() const; - void setDefaultCursorMoveStyle(QTextCursor::MoveStyle style); + Qt::CursorMoveStyle defaultCursorMoveStyle() const; + void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style); Q_SIGNALS: void contentsChange(int from, int charsRemoves, int charsAdded); diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 779b1ff..640f7aa 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -209,7 +209,7 @@ QTextDocumentPrivate::QTextDocumentPrivate() defaultTextOption.setTabStop(80); // same as in qtextengine.cpp defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - defaultCursorMoveStyle = QTextCursor::Logical; + defaultCursorMoveStyle = Qt::LogicalMoveStyle; indentWidth = 40; documentMargin = 4; diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index 6563920..e72d676 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -342,7 +342,7 @@ private: public: QTextOption defaultTextOption; - QTextCursor::MoveStyle defaultCursorMoveStyle; + Qt::CursorMoveStyle defaultCursorMoveStyle; #ifndef QT_NO_CSSPARSER QCss::StyleSheet parsedDefaultStyleSheet; #endif diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index c476485..e06ca1c 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -598,7 +598,7 @@ public: inline bool visualCursorMovement() const { return (visualMovement || - (block.docHandle() ? block.docHandle()->defaultCursorMoveStyle == QTextCursor::Visual : false)); + (block.docHandle() ? block.docHandle()->defaultCursorMoveStyle == Qt::VisualMoveStyle : false)); } struct SpecialData { diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 1280b46..07aeb72 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -579,27 +579,27 @@ bool QTextLayout::cacheEnabled() const } /*! - Set the visual cursor movement style. If the QTextLayout is backed by + Set the cursor movement style. If the QTextLayout is backed by a document, you can ignore this and use the option in QTextDocument, this option is for widgets like QLineEdit or custom widgets without - a QTextDocument. Default value is QTextCursor::Logical. + a QTextDocument. Default value is Qt::LogicalMoveStyle. \sa setCursorMoveStyle() */ -void QTextLayout::setCursorMoveStyle(QTextCursor::MoveStyle style) +void QTextLayout::setCursorMoveStyle(Qt::CursorMoveStyle style) { - d->visualMovement = style == QTextCursor::Visual ? true : false; + d->visualMovement = style == Qt::VisualMoveStyle ? true : false; } /*! The cursor movement style of this QTextLayout. The default is - QTextCursor::Logical. + Qt::LogicalMoveStyle. \sa setCursorMoveStyle() */ -QTextCursor::MoveStyle QTextLayout::cursorMoveStyle() const +Qt::CursorMoveStyle QTextLayout::cursorMoveStyle() const { - return d->visualMovement ? QTextCursor::Visual : QTextCursor::Logical; + return d->visualMovement ? Qt::VisualMoveStyle : Qt::LogicalMoveStyle; } /*! diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index 8fe488a..89fbfb2 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -137,8 +137,8 @@ public: void setCacheEnabled(bool enable); bool cacheEnabled() const; - void setCursorMoveStyle(QTextCursor::MoveStyle style); - QTextCursor::MoveStyle cursorMoveStyle() const; + void setCursorMoveStyle(Qt::CursorMoveStyle style); + Qt::CursorMoveStyle cursorMoveStyle() const; void beginLayout(); void endLayout(); diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index 4fb0f0c..2a15555 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -1593,7 +1593,7 @@ void QLineControl::processKeyEvent(QKeyEvent* event) } bool unknown = false; - bool visual = cursorMoveStyle() == QTextCursor::Visual; + bool visual = cursorMoveStyle() == Qt::VisualMoveStyle; if (false) { } diff --git a/src/gui/widgets/qlinecontrol_p.h b/src/gui/widgets/qlinecontrol_p.h index 0655276..9764ba9 100644 --- a/src/gui/widgets/qlinecontrol_p.h +++ b/src/gui/widgets/qlinecontrol_p.h @@ -160,8 +160,8 @@ public: int cursorWidth() const { return m_cursorWidth; } void setCursorWidth(int value) { m_cursorWidth = value; } - QTextCursor::MoveStyle cursorMoveStyle() const { return m_textLayout.cursorMoveStyle(); } - void setCursorMoveStyle(QTextCursor::MoveStyle style) { m_textLayout.setCursorMoveStyle(style); } + Qt::CursorMoveStyle cursorMoveStyle() const { return m_textLayout.cursorMoveStyle(); } + void setCursorMoveStyle(Qt::CursorMoveStyle style) { m_textLayout.setCursorMoveStyle(style); } void moveCursor(int pos, bool mark = false); void cursorForward(bool mark, int steps) @@ -169,11 +169,11 @@ public: int c = m_cursor; if (steps > 0) { while (steps--) - c = cursorMoveStyle() == QTextCursor::Visual ? m_textLayout.rightCursorPosition(c) + c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.rightCursorPosition(c) : m_textLayout.nextCursorPosition(c); } else if (steps < 0) { while (steps++) - c = cursorMoveStyle() == QTextCursor::Visual ? m_textLayout.leftCursorPosition(c) + c = cursorMoveStyle() == Qt::VisualMoveStyle ? m_textLayout.leftCursorPosition(c) : m_textLayout.previousCursorPosition(c); } moveCursor(c, mark); diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 43c3f52..3c9874e 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1116,24 +1116,24 @@ void QLineEdit::setDragEnabled(bool b) \brief the movement style of cursor in this line edit \since 4.8 - When this property is set to QTextCursor::Visual, the line edit will use visual + When this property is set to Qt::VisualMoveStyle, the line edit will use visual movement style. Pressing the left arrow key will always cause the cursor to move left, regardless of the text's writing direction. The same behavior applies to right arrow key. - When the property is QTextCursor::Logical (the default), within a LTR text block, + When the property is Qt::LogicalMoveStyle (the default), within a LTR text block, increase cursor position when pressing left arrow key, decrease cursor position when pressing the right arrow key. If the text block is right to left, the opposite behavior applies. */ -QTextCursor::MoveStyle QLineEdit::cursorMoveStyle() const +Qt::CursorMoveStyle QLineEdit::cursorMoveStyle() const { Q_D(const QLineEdit); return d->control->cursorMoveStyle(); } -void QLineEdit::setCursorMoveStyle(QTextCursor::MoveStyle style) +void QLineEdit::setCursorMoveStyle(Qt::CursorMoveStyle style) { Q_D(QLineEdit); d->control->setCursorMoveStyle(style); diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h index 73a736c..e88273f 100644 --- a/src/gui/widgets/qlineedit.h +++ b/src/gui/widgets/qlineedit.h @@ -85,6 +85,7 @@ class Q_GUI_EXPORT QLineEdit : public QWidget Q_PROPERTY(bool redoAvailable READ isRedoAvailable) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) + Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle) public: explicit QLineEdit(QWidget* parent=0); @@ -159,8 +160,8 @@ public: void setDragEnabled(bool b); bool dragEnabled() const; - void setCursorMoveStyle(QTextCursor::MoveStyle style); - QTextCursor::MoveStyle cursorMoveStyle() const; + void setCursorMoveStyle(Qt::CursorMoveStyle style); + Qt::CursorMoveStyle cursorMoveStyle() const; QString inputMask() const; void setInputMask(const QString &inputMask); diff --git a/tests/auto/qcomplextext/tst_qcomplextext.cpp b/tests/auto/qcomplextext/tst_qcomplextext.cpp index 58b31b4..ae63bac 100644 --- a/tests/auto/qcomplextext/tst_qcomplextext.cpp +++ b/tests/auto/qcomplextext/tst_qcomplextext.cpp @@ -214,7 +214,7 @@ void tst_QComplexText::bidiCursorMovement() QTextOption option = layout.textOption(); option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); layout.setTextOption(option); - layout.setCursorMoveStyle(QTextCursor::Visual); + layout.setCursorMoveStyle(Qt::VisualMoveStyle); bool moved; int oldPos, newPos = 0; qreal x, newX; diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index f45481c..d5d9029 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -3815,7 +3815,7 @@ void tst_QLineEdit::bidiVisualMovement() QLineEdit le; le.setText(logical); - le.setCursorMoveStyle(QTextCursor::Visual); + le.setCursorMoveStyle(Qt::VisualMoveStyle); le.setCursorPosition(0); bool moved; @@ -3863,7 +3863,7 @@ void tst_QLineEdit::bidiLogicalMovement() QLineEdit le; le.setText(logical); - le.setCursorMoveStyle(QTextCursor::Logical); + le.setCursorMoveStyle(Qt::LogicalMoveStyle); le.setCursorPosition(0); bool moved; diff --git a/tests/auto/qtextedit/tst_qtextedit.cpp b/tests/auto/qtextedit/tst_qtextedit.cpp index 5a64593..992d2f2 100644 --- a/tests/auto/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/qtextedit/tst_qtextedit.cpp @@ -2292,7 +2292,7 @@ void tst_QTextEdit::bidiVisualMovement() option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); ed->document()->setDefaultTextOption(option); - ed->document()->setDefaultCursorMoveStyle(QTextCursor::Visual); + ed->document()->setDefaultCursorMoveStyle(Qt::VisualMoveStyle); ed->moveCursor(QTextCursor::Start); ed->show(); @@ -2346,7 +2346,7 @@ void tst_QTextEdit::bidiLogicalMovement() option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); ed->document()->setDefaultTextOption(option); - ed->document()->setDefaultCursorMoveStyle(QTextCursor::Logical); + ed->document()->setDefaultCursorMoveStyle(Qt::LogicalMoveStyle); ed->moveCursor(QTextCursor::Start); ed->show(); -- cgit v0.12 From 8a5e82732be3aac37d14ef85c6974add46c6b65f Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 11 May 2011 15:21:14 +0200 Subject: Fix tst_QVariant::invalidColor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since a423ff5474b89028eeca95b254f5184311c8223b, the warning message is no longer produced. Reviewed-by: Samuel Rødal --- tests/auto/qvariant/tst_qvariant.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 6ebe84e..3e65d7e 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -2650,7 +2650,6 @@ void tst_QVariant::invalidAsByteArray() void tst_QVariant::invalidQColor() const { QVariant va("An invalid QColor::name() value."); - QTest::ignoreMessage(QtWarningMsg, "QColor::setNamedColor: Unknown color name 'An invalid QColor::name() value.'"); QVERIFY(va.canConvert(QVariant::Color)); QVERIFY(!va.convert(QVariant::Color)); -- cgit v0.12 From 4d2edca95edbb93fb7c79c4ddb19e12cc4416ff2 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Wed, 11 May 2011 10:53:00 +0200 Subject: Check if OES_texture_npot is present on OpenGL ES 2. Unless the OES_texture_npot extension is present, non-power- of-two textures have some restrictions on OpenGL ES 2. Reviewed-by: Samuel --- src/opengl/qglfunctions.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/opengl/qglfunctions.cpp b/src/opengl/qglfunctions.cpp index be8219a..9137e0f 100644 --- a/src/opengl/qglfunctions.cpp +++ b/src/opengl/qglfunctions.cpp @@ -211,19 +211,24 @@ QGLFunctions::QGLFunctions(const QGLContext *context) static int qt_gl_resolve_features() { #if defined(QT_OPENGL_ES_2) - return QGLFunctions::Multitexture | - QGLFunctions::Shaders | - QGLFunctions::Buffers | - QGLFunctions::Framebuffers | - QGLFunctions::BlendColor | - QGLFunctions::BlendEquation | - QGLFunctions::BlendEquationSeparate | - QGLFunctions::BlendFuncSeparate | - QGLFunctions::BlendSubtract | - QGLFunctions::CompressedTextures | - QGLFunctions::Multisample | - QGLFunctions::StencilSeparate | - QGLFunctions::NPOTTextures; + int features = QGLFunctions::Multitexture | + QGLFunctions::Shaders | + QGLFunctions::Buffers | + QGLFunctions::Framebuffers | + QGLFunctions::BlendColor | + QGLFunctions::BlendEquation | + QGLFunctions::BlendEquationSeparate | + QGLFunctions::BlendFuncSeparate | + QGLFunctions::BlendSubtract | + QGLFunctions::CompressedTextures | + QGLFunctions::Multisample | + QGLFunctions::StencilSeparate; + QGLExtensionMatcher extensions; + if (extensions.match("GL_OES_texture_npot")) + features |= QGLFunctions::NPOTTextures; + if (extensions.match("GL_IMG_texture_npot")) + features |= QGLFunctions::NPOTTextures; + return features; #elif defined(QT_OPENGL_ES) int features = QGLFunctions::Multitexture | QGLFunctions::Buffers | @@ -240,6 +245,8 @@ static int qt_gl_resolve_features() features |= QGLFunctions::BlendSubtract; if (extensions.match("GL_OES_texture_npot")) features |= QGLFunctions::NPOTTextures; + if (extensions.match("GL_IMG_texture_npot")) + features |= QGLFunctions::NPOTTextures; return features; #else int features = 0; -- cgit v0.12 From c5846314dfd80e7f7f32ba737f1884dcccbbd80d Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Wed, 11 May 2011 16:56:24 +0200 Subject: Fix QGLWidget::renderPixmap for raster engine on Mac The QPixmap buffer is backed by QRasterPixmapData instead of QMacPixmapData for the raster engine, thus we have to update qt_mac_pixmap_get_base() and qt_mac_pixmap_get_bytes_per_line(), so that QGLWidget can locate the offscreen buffer from a QPixmap. Reviewed-by: Fabien Freling --- src/gui/image/qpixmap_mac.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp index 72e2aa6..e107d88 100644 --- a/src/gui/image/qpixmap_mac.cpp +++ b/src/gui/image/qpixmap_mac.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -73,12 +74,18 @@ static int qt_pixmap_serial = 0; Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix) { - return static_cast(pix->data.data())->pixels; + if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) + return reinterpret_cast(static_cast(pix->data.data())->buffer()->bits()); + else + return static_cast(pix->data.data())->pixels; } Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix) { - return static_cast(pix->data.data())->bytesPerRow; + if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) + return static_cast(pix->data.data())->buffer()->bytesPerLine(); + else + return static_cast(pix->data.data())->bytesPerRow; } void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t) -- cgit v0.12