From 051ef6f294e8cbfa1e30e99e7fd4cf5fb38393f4 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 (cherry picked from commit 84ef364302728b68d2d29ea9c4ccbec32c7bb115) --- 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 +- 8 files changed, 602 insertions(+), 602 deletions(-) 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 (limited to 'tests') diff --git a/tests/auto/gui.pro b/tests/auto/gui.pro index 0d77fff413..6de8ab9303 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 0000000000..480ad5b9a4 --- /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 0000000000..9043a576ef 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 0000000000..aefc228001 --- /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 5084cf9908..0000000000 --- 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 9043a576ef..0000000000 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 ffa0d002c3..0000000000 --- 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 ad16a9a75b..cf46471033 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 v1.2.3