2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
#include <qglyphrun.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qtextlayout.h>
|
|
|
|
#include <qfontdatabase.h>
|
|
|
|
|
|
|
|
// #define DEBUG_SAVE_IMAGE
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
class tst_QGlyphRun: public QObject
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
#if !defined(QT_NO_RAWFONT)
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
2011-08-08 00:31:58 +00:00
|
|
|
void init();
|
2011-04-27 10:05:43 +00:00
|
|
|
void cleanupTestCase();
|
|
|
|
|
|
|
|
void constructionAndDestruction();
|
|
|
|
void copyConstructor();
|
|
|
|
void assignment();
|
|
|
|
void equalsOperator_data();
|
|
|
|
void equalsOperator();
|
2012-10-11 03:23:32 +00:00
|
|
|
void isEmpty();
|
2011-04-27 10:05:43 +00:00
|
|
|
void textLayoutGlyphIndexes();
|
|
|
|
void drawExistingGlyphs();
|
|
|
|
void drawNonExistentGlyphs();
|
|
|
|
void drawMultiScriptText1();
|
|
|
|
void drawMultiScriptText2();
|
|
|
|
void drawStruckOutText();
|
|
|
|
void drawOverlinedText();
|
|
|
|
void drawUnderlinedText();
|
|
|
|
void drawRightToLeft();
|
|
|
|
void detach();
|
2011-05-10 13:08:29 +00:00
|
|
|
void setRawData();
|
|
|
|
void setRawDataAndGetAsVector();
|
2012-10-11 03:23:32 +00:00
|
|
|
void boundingRect();
|
2014-08-15 13:55:12 +00:00
|
|
|
void mixedScripts();
|
2016-01-27 16:02:41 +00:00
|
|
|
void multiLineBoundingRect();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_testFontId;
|
|
|
|
QFont m_testFont;
|
2011-08-08 00:31:58 +00:00
|
|
|
bool m_testFont_ok;
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif // QT_NO_RAWFONT
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(QT_NO_RAWFONT)
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
Q_DECLARE_METATYPE(QGlyphRun);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::initTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-08-08 00:31:58 +00:00
|
|
|
m_testFont_ok = false;
|
|
|
|
|
2014-07-10 10:04:49 +00:00
|
|
|
m_testFontId = QFontDatabase::addApplicationFont(QFINDTESTDATA("test.ttf"));
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(m_testFontId >= 0);
|
|
|
|
|
|
|
|
m_testFont = QFont("QtsSpecialTestFont");
|
|
|
|
|
|
|
|
QCOMPARE(QFontInfo(m_testFont).family(), QString::fromLatin1("QtsSpecialTestFont"));
|
2011-08-08 00:31:58 +00:00
|
|
|
|
|
|
|
m_testFont_ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGlyphRun::init()
|
|
|
|
{
|
2011-10-19 02:53:13 +00:00
|
|
|
if (!m_testFont_ok)
|
|
|
|
QSKIP("Test font is not working correctly");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::cleanupTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QFontDatabase::removeApplicationFont(m_testFontId);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::constructionAndDestruction()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphIndexes;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
static QGlyphRun make_dummy_indexes()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVector<quint32> glyphIndexes;
|
|
|
|
QVector<QPointF> 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));
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
glyphs.setRawFont(QRawFont::fromFont(font));
|
2011-04-27 10:05:43 +00:00
|
|
|
glyphs.setGlyphIndexes(glyphIndexes);
|
|
|
|
glyphs.setPositions(positions);
|
|
|
|
|
|
|
|
return glyphs;
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::copyConstructor()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QVector<quint32> glyphIndexes;
|
|
|
|
QVector<QPointF> 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));
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
glyphs.setRawFont(QRawFont::fromFont(font));
|
2011-04-27 10:05:43 +00:00
|
|
|
glyphs.setGlyphIndexes(glyphIndexes);
|
|
|
|
glyphs.setPositions(positions);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun otherGlyphs(glyphs);
|
|
|
|
QCOMPARE(otherGlyphs.rawFont(), glyphs.rawFont());
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes());
|
|
|
|
QCOMPARE(glyphs.positions(), otherGlyphs.positions());
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::assignment()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs(make_dummy_indexes());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun otherGlyphs = glyphs;
|
|
|
|
QCOMPARE(otherGlyphs.rawFont(), glyphs.rawFont());
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(glyphs.glyphIndexes(), otherGlyphs.glyphIndexes());
|
|
|
|
QCOMPARE(glyphs.positions(), otherGlyphs.positions());
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::equalsOperator_data()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QTest::addColumn<QGlyphRun>("one");
|
|
|
|
QTest::addColumn<QGlyphRun>("two");
|
2011-04-27 10:05:43 +00:00
|
|
|
QTest::addColumn<bool>("equals");
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun one(make_dummy_indexes());
|
|
|
|
QGlyphRun two(make_dummy_indexes());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTest::newRow("Identical") << one << two << true;
|
|
|
|
|
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun busted(two);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVector<QPointF> positions = busted.positions();
|
|
|
|
positions[2] += QPointF(1, 1);
|
|
|
|
busted.setPositions(positions);
|
|
|
|
|
|
|
|
|
|
|
|
QTest::newRow("Different positions") << one << busted << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun busted(two);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QFont font;
|
2011-05-10 07:43:00 +00:00
|
|
|
font.setPixelSize(busted.rawFont().pixelSize() * 2);
|
|
|
|
busted.setRawFont(QRawFont::fromFont(font));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTest::newRow("Different fonts") << one << busted << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun busted(two);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVector<quint32> glyphIndexes = busted.glyphIndexes();
|
|
|
|
glyphIndexes[2] += 1;
|
|
|
|
busted.setGlyphIndexes(glyphIndexes);
|
|
|
|
|
|
|
|
QTest::newRow("Different glyph indexes") << one << busted << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::equalsOperator()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QFETCH(QGlyphRun, one);
|
|
|
|
QFETCH(QGlyphRun, two);
|
2011-04-27 10:05:43 +00:00
|
|
|
QFETCH(bool, equals);
|
|
|
|
|
|
|
|
QCOMPARE(one == two, equals);
|
|
|
|
QCOMPARE(one != two, !equals);
|
|
|
|
}
|
|
|
|
|
2012-10-11 03:23:32 +00:00
|
|
|
void tst_QGlyphRun::isEmpty()
|
|
|
|
{
|
|
|
|
QGlyphRun glyphs;
|
|
|
|
QVERIFY(glyphs.isEmpty());
|
|
|
|
|
|
|
|
glyphs.setGlyphIndexes(QVector<quint32>() << 1 << 2 << 3);
|
|
|
|
QVERIFY(!glyphs.isEmpty());
|
|
|
|
|
|
|
|
glyphs.clear();
|
|
|
|
QVERIFY(glyphs.isEmpty());
|
|
|
|
|
|
|
|
QVector<quint32> glyphIndexes = QVector<quint32>() << 1 << 2 << 3;
|
|
|
|
QVector<QPointF> positions = QVector<QPointF>() << QPointF(0, 0) << QPointF(0, 0) << QPointF(0, 0);
|
|
|
|
glyphs.setRawData(glyphIndexes.constData(), positions.constData(), glyphIndexes.size());
|
|
|
|
QVERIFY(!glyphs.isEmpty());
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::textLayoutGlyphIndexes()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QString s;
|
|
|
|
s.append(QLatin1Char('A'));
|
|
|
|
s.append(QChar(0xe000));
|
|
|
|
|
|
|
|
QTextLayout layout(s);
|
|
|
|
layout.setFont(m_testFont);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QList<QGlyphRun> listOfGlyphs = layout.glyphRuns();
|
2011-08-05 04:17:30 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(listOfGlyphs.size(), 1);
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = listOfGlyphs.at(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(glyphs.glyphIndexes().size(), 2);
|
|
|
|
QCOMPARE(glyphs.glyphIndexes().at(0), quint32(2));
|
|
|
|
QCOMPARE(glyphs.glyphIndexes().at(1), quint32(1));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawExistingGlyphs()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
layout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().size() > 0
|
|
|
|
? layout.glyphRuns().at(0)
|
|
|
|
: QGlyphRun();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawExistingGlyphs_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawExistingGlyphs_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(textLayoutDraw, drawGlyphs);
|
|
|
|
}
|
|
|
|
|
2011-05-10 13:08:29 +00:00
|
|
|
void tst_QGlyphRun::setRawData()
|
|
|
|
{
|
|
|
|
QGlyphRun glyphRun;
|
|
|
|
glyphRun.setRawFont(QRawFont::fromFont(m_testFont));
|
|
|
|
glyphRun.setGlyphIndexes(QVector<quint32>() << 2 << 2 << 2);
|
|
|
|
glyphRun.setPositions(QVector<QPointF>() << QPointF(2, 3) << QPointF(20, 3) << QPointF(10, 20));
|
|
|
|
|
|
|
|
QPixmap baseline(100, 50);
|
|
|
|
baseline.fill(Qt::white);
|
|
|
|
{
|
|
|
|
QPainter p(&baseline);
|
|
|
|
p.drawGlyphRun(QPointF(3, 2), glyphRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
QGlyphRun baselineCopied = glyphRun;
|
|
|
|
|
|
|
|
quint32 glyphIndexArray[3] = { 2, 2, 2 };
|
|
|
|
QPointF glyphPositionArray[3] = { QPointF(2, 3), QPointF(20, 3), QPointF(10, 20) };
|
|
|
|
|
|
|
|
glyphRun.setRawData(glyphIndexArray, glyphPositionArray, 3);
|
|
|
|
|
|
|
|
QPixmap rawDataGlyphs(100, 50);
|
|
|
|
rawDataGlyphs.fill(Qt::white);
|
|
|
|
{
|
|
|
|
QPainter p(&rawDataGlyphs);
|
|
|
|
p.drawGlyphRun(QPointF(3, 2), glyphRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 otherGlyphIndexArray[1] = { 2 };
|
|
|
|
QPointF otherGlyphPositionArray[1] = { QPointF(2, 3) };
|
|
|
|
|
|
|
|
glyphRun.setRawData(otherGlyphIndexArray, otherGlyphPositionArray, 1);
|
|
|
|
|
|
|
|
QPixmap baselineCopiedPixmap(100, 50);
|
|
|
|
baselineCopiedPixmap.fill(Qt::white);
|
|
|
|
{
|
|
|
|
QPainter p(&baselineCopiedPixmap);
|
|
|
|
p.drawGlyphRun(QPointF(3, 2), baselineCopied);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
baseline.save("setRawData_baseline.png");
|
|
|
|
rawDataGlyphs.save("setRawData_rawDataGlyphs.png");
|
|
|
|
baselineCopiedPixmap.save("setRawData_baselineCopiedPixmap.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(rawDataGlyphs, baseline);
|
|
|
|
QCOMPARE(baselineCopiedPixmap, baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QGlyphRun::setRawDataAndGetAsVector()
|
|
|
|
{
|
|
|
|
QVector<quint32> glyphIndexArray;
|
|
|
|
glyphIndexArray << 3 << 2 << 1 << 4;
|
|
|
|
|
|
|
|
QVector<QPointF> glyphPositionArray;
|
|
|
|
glyphPositionArray << QPointF(1, 2) << QPointF(3, 4) << QPointF(5, 6) << QPointF(7, 8);
|
|
|
|
|
|
|
|
QGlyphRun glyphRun;
|
|
|
|
glyphRun.setRawData(glyphIndexArray.constData(), glyphPositionArray.constData(), 4);
|
|
|
|
|
|
|
|
QVector<quint32> glyphIndexes = glyphRun.glyphIndexes();
|
|
|
|
QVector<QPointF> glyphPositions = glyphRun.positions();
|
|
|
|
|
|
|
|
QCOMPARE(glyphIndexes.size(), 4);
|
|
|
|
QCOMPARE(glyphPositions.size(), 4);
|
|
|
|
|
|
|
|
QCOMPARE(glyphIndexes, glyphIndexArray);
|
|
|
|
QCOMPARE(glyphPositions, glyphPositionArray);
|
|
|
|
|
|
|
|
QGlyphRun otherGlyphRun;
|
|
|
|
otherGlyphRun.setGlyphIndexes(glyphIndexArray);
|
|
|
|
otherGlyphRun.setPositions(glyphPositionArray);
|
|
|
|
|
|
|
|
QCOMPARE(glyphRun, otherGlyphRun);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawNonExistentGlyphs()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QVector<quint32> glyphIndexes;
|
2014-08-15 13:55:12 +00:00
|
|
|
glyphIndexes.append(4);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVector<QPointF> glyphPositions;
|
|
|
|
glyphPositions.append(QPointF(0, 0));
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs;
|
2011-04-27 10:05:43 +00:00
|
|
|
glyphs.setGlyphIndexes(glyphIndexes);
|
|
|
|
glyphs.setPositions(glyphPositions);
|
2011-05-10 07:43:00 +00:00
|
|
|
glyphs.setRawFont(QRawFont::fromFont(m_testFont));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QPixmap image(1000, 1000);
|
|
|
|
image.fill(Qt::white);
|
|
|
|
|
|
|
|
QPixmap imageBefore = image;
|
|
|
|
{
|
|
|
|
QPainter p(&image);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
image.save("drawNonExistentGlyphs.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(image, imageBefore); // Should be unchanged
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawMultiScriptText1()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
text += QChar(0x03D0); // Greek, beta
|
|
|
|
|
|
|
|
QTextLayout textLayout(text);
|
2012-05-15 17:02:53 +00:00
|
|
|
textLayout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
textLayout.beginLayout();
|
|
|
|
textLayout.createLine();
|
|
|
|
textLayout.endLayout();
|
|
|
|
|
|
|
|
QPixmap textLayoutDraw(1000, 1000);
|
|
|
|
textLayoutDraw.fill(Qt::white);
|
|
|
|
|
|
|
|
QPixmap drawGlyphs(1000, 1000);
|
|
|
|
drawGlyphs.fill(Qt::white);
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(glyphsList.size(), 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
textLayout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
foreach (QGlyphRun glyphs, glyphsList)
|
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawMultiScriptText1_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawMultiScriptText1_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(drawGlyphs, textLayoutDraw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawMultiScriptText2()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
text += QChar(0x0621); // Arabic, Hamza
|
|
|
|
text += QChar(0x03D0); // Greek, beta
|
|
|
|
|
|
|
|
QTextLayout textLayout(text);
|
2012-05-15 17:02:53 +00:00
|
|
|
textLayout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
textLayout.beginLayout();
|
|
|
|
textLayout.createLine();
|
|
|
|
textLayout.endLayout();
|
|
|
|
|
|
|
|
QPixmap textLayoutDraw(1000, 1000);
|
|
|
|
textLayoutDraw.fill(Qt::white);
|
|
|
|
|
|
|
|
QPixmap drawGlyphs(1000, 1000);
|
|
|
|
drawGlyphs.fill(Qt::white);
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(glyphsList.size(), 2);
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
textLayout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
foreach (QGlyphRun glyphs, glyphsList)
|
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawMultiScriptText2_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawMultiScriptText2_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(drawGlyphs, textLayoutDraw);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::detach()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
glyphs.setGlyphIndexes(QVector<quint32>() << 1 << 2 << 3);
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun otherGlyphs;
|
2011-04-27 10:05:43 +00:00
|
|
|
otherGlyphs = glyphs;
|
|
|
|
|
|
|
|
QCOMPARE(otherGlyphs.glyphIndexes(), glyphs.glyphIndexes());
|
|
|
|
|
|
|
|
otherGlyphs.setGlyphIndexes(QVector<quint32>() << 4 << 5 << 6);
|
|
|
|
|
|
|
|
QCOMPARE(otherGlyphs.glyphIndexes(), QVector<quint32>() << 4 << 5 << 6);
|
|
|
|
QCOMPARE(glyphs.glyphIndexes(), QVector<quint32>() << 1 << 2 << 3);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawStruckOutText()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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);
|
Accept error margin in QGlyphRun/QStaticText test for decorations
When calculating the width of a text for drawing decorations on top,
we use the effective advance of the whole text after it has been
through the shaper.
However, in the case of QStaticText and QGlyphRun, there is shortcut:
Since we only have the glyph indexes and position of each glyph,
we use the position + advance of the right-most glyph to find the
right-most edge of the decoration. For this, however, we use the
advance of the glyph *out of context* of the rest of the string,
because the whole idea is to avoid doing the shaping of the string
with every draw call. In some rare cases, the advance of the
right-most character, in the context of the string, is different
from the advance of the standalone glyph.
Now, one way of fixing this would be to store the width of the
text in QStaticText and QGlyphRun, but since it is a very rare
artifact which is barely visible, I have opted to just work around
it in the test instead, the workaround being to force integer
metrics so that we don't get the small 0.2 pixel error.
Task-number: QTBUG-55217
Change-Id: I8d16d52f2ef27275cabb7d3865aeeaa31617ba3d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-02-02 11:29:44 +00:00
|
|
|
font.setStyleStrategy(QFont::ForceIntegerMetrics);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTextLayout layout(s);
|
|
|
|
layout.setFont(font);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
layout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().size() > 0
|
|
|
|
? layout.glyphRuns().at(0)
|
|
|
|
: QGlyphRun();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawStruckOutText_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawStruckOutText_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(textLayoutDraw, drawGlyphs);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawOverlinedText()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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);
|
Accept error margin in QGlyphRun/QStaticText test for decorations
When calculating the width of a text for drawing decorations on top,
we use the effective advance of the whole text after it has been
through the shaper.
However, in the case of QStaticText and QGlyphRun, there is shortcut:
Since we only have the glyph indexes and position of each glyph,
we use the position + advance of the right-most glyph to find the
right-most edge of the decoration. For this, however, we use the
advance of the glyph *out of context* of the rest of the string,
because the whole idea is to avoid doing the shaping of the string
with every draw call. In some rare cases, the advance of the
right-most character, in the context of the string, is different
from the advance of the standalone glyph.
Now, one way of fixing this would be to store the width of the
text in QStaticText and QGlyphRun, but since it is a very rare
artifact which is barely visible, I have opted to just work around
it in the test instead, the workaround being to force integer
metrics so that we don't get the small 0.2 pixel error.
Task-number: QTBUG-55217
Change-Id: I8d16d52f2ef27275cabb7d3865aeeaa31617ba3d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-02-02 11:29:44 +00:00
|
|
|
font.setStyleStrategy(QFont::ForceIntegerMetrics);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTextLayout layout(s);
|
|
|
|
layout.setFont(font);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
layout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().size() > 0
|
|
|
|
? layout.glyphRuns().at(0)
|
|
|
|
: QGlyphRun();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawOverlineText_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawOverlineText_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(textLayoutDraw, drawGlyphs);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawUnderlinedText()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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);
|
Accept error margin in QGlyphRun/QStaticText test for decorations
When calculating the width of a text for drawing decorations on top,
we use the effective advance of the whole text after it has been
through the shaper.
However, in the case of QStaticText and QGlyphRun, there is shortcut:
Since we only have the glyph indexes and position of each glyph,
we use the position + advance of the right-most glyph to find the
right-most edge of the decoration. For this, however, we use the
advance of the glyph *out of context* of the rest of the string,
because the whole idea is to avoid doing the shaping of the string
with every draw call. In some rare cases, the advance of the
right-most character, in the context of the string, is different
from the advance of the standalone glyph.
Now, one way of fixing this would be to store the width of the
text in QStaticText and QGlyphRun, but since it is a very rare
artifact which is barely visible, I have opted to just work around
it in the test instead, the workaround being to force integer
metrics so that we don't get the small 0.2 pixel error.
Task-number: QTBUG-55217
Change-Id: I8d16d52f2ef27275cabb7d3865aeeaa31617ba3d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-02-02 11:29:44 +00:00
|
|
|
font.setStyleStrategy(QFont::ForceIntegerMetrics);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QTextLayout layout(s);
|
|
|
|
layout.setFont(font);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
layout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().size() > 0
|
|
|
|
? layout.glyphRuns().at(0)
|
|
|
|
: QGlyphRun();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawUnderlineText_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawUnderlineText_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(textLayoutDraw, drawGlyphs);
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
void tst_QGlyphRun::drawRightToLeft()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
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);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&textLayoutDraw);
|
|
|
|
layout.draw(&p, QPointF(50, 50));
|
|
|
|
}
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().size() > 0
|
|
|
|
? layout.glyphRuns().at(0)
|
|
|
|
: QGlyphRun();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&drawGlyphs);
|
2011-05-10 07:43:00 +00:00
|
|
|
p.drawGlyphRun(QPointF(50, 50), glyphs);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG_SAVE_IMAGE)
|
|
|
|
textLayoutDraw.save("drawRightToLeft_textLayoutDraw.png");
|
|
|
|
drawGlyphs.save("drawRightToLeft_drawGlyphIndexes.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QCOMPARE(textLayoutDraw, drawGlyphs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-11 03:23:32 +00:00
|
|
|
void tst_QGlyphRun::boundingRect()
|
|
|
|
{
|
|
|
|
QString s(QLatin1String("AbCdE"));
|
|
|
|
|
|
|
|
QRawFont rawFont(QRawFont::fromFont(QFont()));
|
|
|
|
QVERIFY(rawFont.isValid());
|
|
|
|
QVector<quint32> glyphIndexes = rawFont.glyphIndexesForString(s);
|
|
|
|
QVector<QPointF> positions = rawFont.advancesForGlyphIndexes(glyphIndexes);
|
|
|
|
QCOMPARE(glyphIndexes.size(), s.size());
|
|
|
|
QCOMPARE(positions.size(), glyphIndexes.size());
|
|
|
|
|
|
|
|
QGlyphRun glyphs;
|
|
|
|
glyphs.setRawFont(rawFont);
|
|
|
|
glyphs.setGlyphIndexes(glyphIndexes);
|
|
|
|
glyphs.setPositions(positions);
|
|
|
|
|
|
|
|
QRectF boundingRect = glyphs.boundingRect();
|
|
|
|
|
|
|
|
glyphs.clear();
|
|
|
|
glyphs.setRawFont(rawFont);
|
|
|
|
glyphs.setRawData(glyphIndexes.constData(), positions.constData(), glyphIndexes.size());
|
|
|
|
QCOMPARE(glyphs.boundingRect(), boundingRect);
|
|
|
|
|
|
|
|
boundingRect = QRectF(0, 0, 1, 1);
|
|
|
|
glyphs.setBoundingRect(boundingRect);
|
|
|
|
QCOMPARE(glyphs.boundingRect(), boundingRect);
|
|
|
|
}
|
|
|
|
|
2014-08-15 13:55:12 +00:00
|
|
|
void tst_QGlyphRun::mixedScripts()
|
|
|
|
{
|
|
|
|
QString s;
|
|
|
|
s += QChar(0x31); // The character '1'
|
|
|
|
s += QChar(0xbc14); // Hangul character
|
|
|
|
|
|
|
|
QTextLayout layout;
|
|
|
|
layout.setFont(m_testFont);
|
|
|
|
layout.setText(s);
|
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
QList<QGlyphRun> glyphRuns = layout.glyphRuns();
|
2018-05-16 06:37:16 +00:00
|
|
|
#ifdef Q_OS_WINRT
|
|
|
|
QEXPECT_FAIL("", "Hangul character not rendered on winrt", Continue);
|
|
|
|
#endif
|
2014-08-15 13:55:12 +00:00
|
|
|
QCOMPARE(glyphRuns.size(), 2);
|
|
|
|
}
|
|
|
|
|
2016-01-27 16:02:41 +00:00
|
|
|
void tst_QGlyphRun::multiLineBoundingRect()
|
|
|
|
{
|
|
|
|
QTextLayout layout;
|
|
|
|
layout.setText("Foo Bar");
|
|
|
|
layout.beginLayout();
|
|
|
|
|
|
|
|
QTextLine line = layout.createLine();
|
|
|
|
line.setNumColumns(4);
|
|
|
|
line.setPosition(QPointF(0, 0));
|
|
|
|
|
|
|
|
line = layout.createLine();
|
|
|
|
line.setPosition(QPointF(0, 10));
|
|
|
|
|
|
|
|
layout.endLayout();
|
|
|
|
|
|
|
|
QCOMPARE(layout.lineCount(), 2);
|
|
|
|
|
|
|
|
QList<QGlyphRun> firstLineGlyphRuns = layout.lineAt(0).glyphRuns();
|
|
|
|
QList<QGlyphRun> allGlyphRuns = layout.glyphRuns();
|
|
|
|
QCOMPARE(firstLineGlyphRuns.size(), 1);
|
|
|
|
QCOMPARE(allGlyphRuns.size(), 1);
|
|
|
|
|
|
|
|
QGlyphRun firstLineGlyphRun = firstLineGlyphRuns.first();
|
|
|
|
QGlyphRun allGlyphRun = allGlyphRuns.first();
|
|
|
|
|
|
|
|
QVERIFY(firstLineGlyphRun.boundingRect().height() < allGlyphRun.boundingRect().height());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif // QT_NO_RAWFONT
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QTEST_MAIN(tst_QGlyphRun)
|
|
|
|
#include "tst_qglyphrun.moc"
|
2011-04-27 10:05:43 +00:00
|
|
|
|