diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-06-15 18:50:00 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-06-16 14:28:40 +0200 |
commit | bda33ba2ce4d53214e1bd9ee62b05ced0525e8db (patch) | |
tree | 2668d78510ba316a40478b629d87009610d9e19c /vcl/qa/cppunit/FontFeatureTest.cxx | |
parent | 8dacd42f3af903ac3daeef8f4dd444ffc7e1a99c (diff) |
tdf#58941 implement retrieving font features and structures
This adds the following:
- Retrieving of features using HarfBuzz
- Retrieving of feature definitions from graphite fonts
- Adds description texts of OpenType features
- Tests for retrieving features (Linux Libertine G graphite font)
and making sure the features and definitions are what we
expect.
Change-Id: I51573fe086e59c6228cb546bbfac95ac53824c47
Reviewed-on: https://gerrit.libreoffice.org/55892
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa/cppunit/FontFeatureTest.cxx')
-rw-r--r-- | vcl/qa/cppunit/FontFeatureTest.cxx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/FontFeatureTest.cxx b/vcl/qa/cppunit/FontFeatureTest.cxx new file mode 100644 index 000000000000..0bb28e306139 --- /dev/null +++ b/vcl/qa/cppunit/FontFeatureTest.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <vcl/font/Feature.hxx> + +#include <vcl/virdev.hxx> +#include <vcl/svapp.hxx> + +class FontFeatureTest : public test::BootstrapFixture +{ +public: + FontFeatureTest() + : BootstrapFixture(true, false) + { + } + + void testGetFontFeatures(); + + CPPUNIT_TEST_SUITE(FontFeatureTest); + CPPUNIT_TEST(testGetFontFeatures); + CPPUNIT_TEST_SUITE_END(); +}; + +void FontFeatureTest::testGetFontFeatures() +{ + ScopedVclPtrInstance<VirtualDevice> aVDev(*Application::GetDefaultDevice(), + DeviceFormat::DEFAULT, DeviceFormat::DEFAULT); + aVDev->SetOutputSizePixel(Size(10, 10)); + + vcl::Font aFont = aVDev->GetFont(); + aFont.SetFamilyName("Linux Libertine G"); + aVDev->SetFont(aFont); + + std::vector<vcl::font::Feature> rFontFeatures; + CPPUNIT_ASSERT(aVDev->GetFontFeatures(rFontFeatures)); + + // We're interested only in defaults here + std::vector<vcl::font::Feature> rDefaultFontFeatures; + OUString aFeaturesString; + for (vcl::font::Feature const& rFeature : rFontFeatures) + { + if (rFeature.m_aID.m_aScriptCode == vcl::font::featureCode("DFLT") + && rFeature.m_aID.m_aLanguageCode == vcl::font::featureCode("dflt")) + { + rDefaultFontFeatures.push_back(rFeature); + aFeaturesString += vcl::font::featureCodeAsString(rFeature.m_aID.m_aFeatureCode) + " "; + } + } + + CPPUNIT_ASSERT_EQUAL(size_t(31), rDefaultFontFeatures.size()); + + OUString aExpectedFeaturesString = "aalt c2sc case ccmp dlig fina frac hlig " + "liga lnum nalt onum pnum salt sinf smcp " + "ss01 ss02 ss03 ss04 ss05 ss06 sups tnum " + "zero cpsp kern lfbd mark mkmk rtbd "; + CPPUNIT_ASSERT_EQUAL(aExpectedFeaturesString, aFeaturesString); + + // Check C2SC feature + { + vcl::font::Feature& rFeature = rDefaultFontFeatures[1]; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("c2sc"), rFeature.m_aID.m_aFeatureCode); + + vcl::font::FeatureDefinition& rFracFeatureDefinition = rFeature.m_aDefinition; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("c2sc"), rFracFeatureDefinition.getCode()); + CPPUNIT_ASSERT(!rFracFeatureDefinition.getDescription().isEmpty()); + CPPUNIT_ASSERT_EQUAL(vcl::font::FeatureParameterType::BOOL, + rFracFeatureDefinition.getType()); + + CPPUNIT_ASSERT_EQUAL(size_t(0), rFracFeatureDefinition.getEnumParameters().size()); + } + + // Check FRAC feature + { + vcl::font::Feature& rFeature = rDefaultFontFeatures[6]; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("frac"), rFeature.m_aID.m_aFeatureCode); + + vcl::font::FeatureDefinition& rFracFeatureDefinition = rFeature.m_aDefinition; + CPPUNIT_ASSERT_EQUAL(vcl::font::featureCode("frac"), rFracFeatureDefinition.getCode()); + CPPUNIT_ASSERT(!rFracFeatureDefinition.getDescription().isEmpty()); + CPPUNIT_ASSERT_EQUAL(vcl::font::FeatureParameterType::ENUM, + rFracFeatureDefinition.getType()); + + CPPUNIT_ASSERT_EQUAL(size_t(2), rFracFeatureDefinition.getEnumParameters().size()); + + vcl::font::FeatureParameter const& rParameter1 + = rFracFeatureDefinition.getEnumParameters()[0]; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), rParameter1.getCode()); + CPPUNIT_ASSERT(!rParameter1.getDescription().isEmpty()); + + vcl::font::FeatureParameter const& rParameter2 + = rFracFeatureDefinition.getEnumParameters()[1]; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), rParameter2.getCode()); + CPPUNIT_ASSERT(!rParameter2.getDescription().isEmpty()); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(FontFeatureTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |