diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-08-24 07:54:15 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-08-25 13:04:27 +0200 |
commit | 9ca3c6794ca1969f453ddaa66c4e02ac8c695cc6 (patch) | |
tree | 2ea75caefa815dca69ece9400f08e10f343b55fb /vcl/qa | |
parent | 19787042b1f139cb9c366801d283c6c0227e85e6 (diff) |
FeatureCollector: Detect ENUM features in OpenType fonts
A bit heavy handed, but the only way to detect the number of alternates
a feature has is to get the maximum number of alternates for all lookups
in all glyphs of this feature, which is what this code does.
Additionally, for cvXX features, parameter names from the font are used
when available.
Change-Id: Ib7f7ea5e5288b47b03dac8703668ca6c4007f517
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138749
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/FontFeatureTest.cxx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/FontFeatureTest.cxx b/vcl/qa/cppunit/FontFeatureTest.cxx index 103870306bcf..9858c96e0a9f 100644 --- a/vcl/qa/cppunit/FontFeatureTest.cxx +++ b/vcl/qa/cppunit/FontFeatureTest.cxx @@ -27,11 +27,13 @@ public: void testGetFontFeaturesGraphite(); void testGetFontFeaturesOpenType(); + void testGetFontFeaturesOpenTypeEnum(); void testParseFeature(); CPPUNIT_TEST_SUITE(FontFeatureTest); CPPUNIT_TEST(testGetFontFeaturesGraphite); CPPUNIT_TEST(testGetFontFeaturesOpenType); + CPPUNIT_TEST(testGetFontFeaturesOpenTypeEnum); CPPUNIT_TEST(testParseFeature); CPPUNIT_TEST_SUITE_END(); }; @@ -169,6 +171,65 @@ void FontFeatureTest::testGetFontFeaturesOpenType() #endif // HAVE_MORE_FONTS } +void FontFeatureTest::testGetFontFeaturesOpenTypeEnum() +{ +#if HAVE_MORE_FONTS + ScopedVclPtrInstance<VirtualDevice> aVDev(*Application::GetDefaultDevice(), + DeviceFormat::DEFAULT, DeviceFormat::DEFAULT); + aVDev->SetOutputSizePixel(Size(10, 10)); + + OUString aFontName("Reem Kufi"); + CPPUNIT_ASSERT(aVDev->IsFontAvailable(aFontName)); + + vcl::Font aFont = aVDev->GetFont(); + aFont.SetFamilyName(aFontName); + aFont.SetWeight(FontWeight::WEIGHT_NORMAL); + aFont.SetItalic(FontItalic::ITALIC_NORMAL); + aFont.SetWidthType(FontWidth::WIDTH_NORMAL); + aVDev->SetFont(aFont); + + std::vector<vcl::font::Feature> rFontFeatures; + CPPUNIT_ASSERT(aVDev->GetFontFeatures(rFontFeatures)); + + OUString aFeaturesString; + for (vcl::font::Feature const& rFeature : rFontFeatures) + aFeaturesString += vcl::font::featureCodeAsString(rFeature.m_nCode) + " "; + + CPPUNIT_ASSERT_EQUAL(size_t(10), rFontFeatures.size()); + + CPPUNIT_ASSERT_EQUAL(OUString("aalt case cv01 cv02 cv03 frac ordn sups " + "zero kern "), + aFeaturesString); + + // Check aalt feature + { + vcl::font::Feature& rFeature = rFontFeatures[0]; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("aalt"), rFeature.m_nCode); + + vcl::font::FeatureDefinition& rFeatureDefinition = rFeature.m_aDefinition; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("aalt"), rFeatureDefinition.getCode()); + CPPUNIT_ASSERT(!rFeatureDefinition.getDescription().isEmpty()); + CPPUNIT_ASSERT_EQUAL(vcl::font::FeatureParameterType::ENUM, rFeatureDefinition.getType()); + + CPPUNIT_ASSERT_EQUAL(size_t(3), rFeatureDefinition.getEnumParameters().size()); + + vcl::font::FeatureParameter const& rParameter1 = rFeatureDefinition.getEnumParameters()[0]; + CPPUNIT_ASSERT_EQUAL(uint32_t(0), rParameter1.getCode()); + CPPUNIT_ASSERT(!rParameter1.getDescription().isEmpty()); + + vcl::font::FeatureParameter const& rParameter2 = rFeatureDefinition.getEnumParameters()[1]; + CPPUNIT_ASSERT_EQUAL(uint32_t(1), rParameter2.getCode()); + CPPUNIT_ASSERT(!rParameter2.getDescription().isEmpty()); + + vcl::font::FeatureParameter const& rParameter3 = rFeatureDefinition.getEnumParameters()[2]; + CPPUNIT_ASSERT_EQUAL(uint32_t(2), rParameter3.getCode()); + CPPUNIT_ASSERT(!rParameter2.getDescription().isEmpty()); + } + + aVDev.disposeAndClear(); +#endif // HAVE_MORE_FONTS +} + void FontFeatureTest::testParseFeature() { { // No font features specified |