Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Add unittests for font name selection.
Wolthera van Hövell tot Westerflierf260e859c31f
diff --git a/libs/flake/tests/TestSvgText.cpp b/libs/flake/tests/TestSvgText.cppindex 274ffe5a73..a6c5856bd6 100644--- a/libs/flake/tests/TestSvgText.cpp+++ b/libs/flake/tests/TestSvgText.cpp@@ -119,6 +119,7 @@ void TestSvgText::initTestCase()for (const char *const fontDir : {"fonts/CSSTest","fonts/testFontsCozens",+ "fonts/testFontNames",}) {QString fileName = TestUtil::fetchDataFileLazy(fontDir);bool res = KoFontRegistry::instance()->addFontFileDirectoryToRegistery(fileName);@@ -1819,7 +1820,70 @@ void TestSvgText::testWWSConverterSlant() {.arg(QString::number(expectedMode)).arg(QString::number(testedMode)).arg(first->family_name)- .toLatin1());+ .toLatin1());+}++void TestSvgText::testWWSConverterFamilyNames_data()+{+ QTest::addColumn<QString>("requestedFamily");+ QTest::addColumn<QString>("expectedFamily");+ QTest::addColumn<QString>("expectedStyle");++ /*+ * The following should select Font A. This is complicated by the fact that Font A has no typographic family, while B, C and D do,+ * which means it ought to select it by RIBBI family.+ */+ QTest::addRow("test typographic, ribbi same as typographic") << QString("Test Typographic Family") << QString("Test Typographic Family") << QString("A");+ QTest::addRow("test typographic, ribbi same as typographic, NL locale") << QString("Test Typografische Familie") << QString("Test Typographic Family") << QString("B");++ /**+ * Test selecting the ribbi name+ */+ QTest::addRow("test typographic, ribbi unique") << QString("Test Typographic RIBBI Family B") << QString("Test Typographic Family") << QString("B");+ /**+ * This tests whether the font is filtered separately when size is selected.+ */+ QTest::addRow("test typographic, ribbi same as typo, size different") << QString("Test Typographic Family Full C") << QString("Test Typographic Family") << QString("Regular");+ /**+ * Test selecting the font with a wws name.+ */+ QTest::addRow("test typographic, wws unique") << QString("Test Typographic WWS Family D") << QString("Test Typographic WWS Family D") << QString("Bold");+ QTest::addRow("test typographic, wws unique, NL locale") << QString("Test Typografische Familie WWS Familie D") << QString("Test Typographic WWS Family D") << QString("Bold");+ /**+ * Test selecting the font with a full name+ */+ QTest::addRow("test typographic, fullname") << QString("Test Typographic Family Full A") << QString("Test Typographic Family") << QString("A");++ QTest::addRow("test family, JA locale") << QString("CSSテスト フォント名") << QString("CSSTest FamilyName") << QString("Regular");+ // Test true type collections.+ QTest::addRow("test collection index") << QString("Test Collection Index B") << QString("Test Collection Index B") << QString("Regular");++}++void TestSvgText::testWWSConverterFamilyNames()+{+ const QMap<QString, qreal> axisSettings;+ QVector<int> lengths;+ QFETCH(QString, requestedFamily);+ QFETCH(QString, expectedFamily);+ QFETCH(QString, expectedStyle);++ const std::vector<FT_FaceSP> faces =+ KoFontRegistry::instance()->facesForCSSValues({requestedFamily}, lengths, axisSettings);++ QVERIFY(!faces.empty());++ FT_FaceSP first = faces.at(0);++ qDebug() << first->family_name << first->style_name;++ QVERIFY2(first->family_name == expectedFamily && first->style_name == expectedStyle,+ QString("Incorrect font-family, expected %1 - %2, got %3 - %4")+ .arg(expectedFamily)+ .arg(expectedStyle)+ .arg(first->family_name)+ .arg(first->style_name)+ .toLatin1());}/**diff --git a/libs/flake/tests/TestSvgText.h b/libs/flake/tests/TestSvgText.hindex ffd66f00ad..b8d21c9511 100644--- a/libs/flake/tests/TestSvgText.h+++ b/libs/flake/tests/TestSvgText.h@@ -65,10 +65,14 @@ private Q_SLOTS:void testUnicodeGraphemeClusters();void testFontSelectionForText();+void testWWSConverterWeight_data();void testWWSConverterWeight();void testWWSConverterSlant_data();void testWWSConverterSlant();+ void testWWSConverterFamilyNames_data();+ void testWWSConverterFamilyNames();+void testFontSizeConfiguration();void testFontSizeRender();diff --git a/libs/flake/tests/data/fonts/README b/libs/flake/tests/data/fonts/READMEindex 4305f96f3c..4ca3bb17d8 100644--- a/libs/flake/tests/data/fonts/README+++ b/libs/flake/tests/data/fonts/README@@ -11,3 +11,4 @@ Some fonts have an explicit license file, but not all. This should list the file- FreeSans.ttf -- Embedded http://www.gnu.org/copyleft/gpl.html "GNU General Public License as published by the Free Software Foundation, either version 3 of the License", Copyright 2002, 2003, 2005, 2008, 2009, 2010, 2012 GNU Freefont contributors.- krita-pixel-test.otb -- This fonts was made specifically for these unittests. Released under "SIL Open Font License, Version 1.1" embedded into the TTF, Copyright 2022 Wolthera van Hövell tot Westerflier.- FontWithFancyFeatures.otf -- This font is from the BSD-licensed web-platform-tests.+- TestTypographicFamily A, B, C, D and TestCollectionIndex.tcc -- These fonts were made specifically for these unittests. Released under "SIL Open Font License, Version 1.1" embedded into the TTF, Copyright 2022 Wolthera van Hövell tot Westerflier.diff --git a/libs/flake/tests/data/fonts/testFontNames/TestCollectionIndex.ttc b/libs/flake/tests/data/fonts/testFontNames/TestCollectionIndex.ttcnew file mode 100644index 0000000000..a3aa595a1aBinary files /dev/null and b/libs/flake/tests/data/fonts/testFontNames/TestCollectionIndex.ttc differdiff --git a/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyA.ttf b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyA.ttfnew file mode 100644index 0000000000..be92a8cfb2Binary files /dev/null and b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyA.ttf differdiff --git a/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyB.ttf b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyB.ttfnew file mode 100644index 0000000000..c52af83cbeBinary files /dev/null and b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyB.ttf differdiff --git a/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyC.ttf b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyC.ttfnew file mode 100644index 0000000000..51e2bb3bbfBinary files /dev/null and b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyC.ttf differdiff --git a/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyD.ttf b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyD.ttfnew file mode 100644index 0000000000..739572b676Binary files /dev/null and b/libs/flake/tests/data/fonts/testFontNames/TestTypographicFamilyD.ttf differ