diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /vcl/qa/cppunit/physicalfontface.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream/4%7.4.7.tar.xz libreoffice-upstream/4%7.4.7.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vcl/qa/cppunit/physicalfontface.cxx')
-rw-r--r-- | vcl/qa/cppunit/physicalfontface.cxx | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/physicalfontface.cxx b/vcl/qa/cppunit/physicalfontface.cxx new file mode 100644 index 000000000..87fdc382b --- /dev/null +++ b/vcl/qa/cppunit/physicalfontface.cxx @@ -0,0 +1,301 @@ +/* -*- 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 <sal/config.h> + +#include <test/bootstrapfixture.hxx> +#include <cppunit/TestAssert.h> + +#include <tools/degree.hxx> + +#include <vcl/font.hxx> + +#include <font/PhysicalFontFace.hxx> +#include <fontattributes.hxx> + +#include "fontmocks.hxx" + +#include <memory> + +const sal_IntPtr FONTID = 1; + +class VclPhysicalFontFaceTest : public test::BootstrapFixture +{ +public: + VclPhysicalFontFaceTest() + : BootstrapFixture(true, false) + { + } + + void testShouldCompareAsLesserFontFaceWithShorterWidth(); + void testShouldCompareAsGreaterFontFaceWithLongerWidth(); + void testShouldCompareAsLesserFontFaceWithLighterWeight(); + void testShouldCompareAsGreaterFontFaceWithHeavierWeight(); + void testShouldCompareAsLesserFontFaceWithLesserItalics(); + void testShouldCompareAsGreaterFontFaceWithGreaterItalics(); + void testShouldCompareAsGreaterFontFaceWitHigherAlphabeticalFamilyName(); + void testShouldCompareAsGreaterFontFaceWitLesserAlphabeticalFamilyName(); + void testShouldCompareAsGreaterFontFaceWithHigherAlphabeticalStyleName(); + void testShouldCompareAsGreaterFontFaceWithLesserAlphabeticalStyleName(); + void testShouldCompareAsSameFontFace(); + void testMatchStatusValue(); + + CPPUNIT_TEST_SUITE(VclPhysicalFontFaceTest); + CPPUNIT_TEST(testShouldCompareAsLesserFontFaceWithShorterWidth); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWithLongerWidth); + CPPUNIT_TEST(testShouldCompareAsLesserFontFaceWithLighterWeight); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWithHeavierWeight); + CPPUNIT_TEST(testShouldCompareAsLesserFontFaceWithLesserItalics); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWithGreaterItalics); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWitHigherAlphabeticalFamilyName); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWitLesserAlphabeticalFamilyName); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWithHigherAlphabeticalStyleName); + CPPUNIT_TEST(testShouldCompareAsGreaterFontFaceWithLesserAlphabeticalStyleName); + CPPUNIT_TEST(testShouldCompareAsSameFontFace); + CPPUNIT_TEST(testMatchStatusValue); + + CPPUNIT_TEST_SUITE_END(); +}; + +void VclPhysicalFontFaceTest::testShouldCompareAsLesserFontFaceWithShorterWidth() +{ + FontAttributes aFontAttrsShorterWidth; + aFontAttrsShorterWidth.SetWidthType(WIDTH_CONDENSED); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrsShorterWidth, FONTID)); + + FontAttributes aFontAttrsLongerWidth; + aFontAttrsLongerWidth.SetWidthType(WIDTH_NORMAL); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsLongerWidth, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithLongerWidth() +{ + FontAttributes aFontAttrsLongerWidth; + aFontAttrsLongerWidth.SetWidthType(WIDTH_NORMAL); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrsLongerWidth, FONTID)); + + FontAttributes aFontAttrsShorterWidth; + aFontAttrsShorterWidth.SetWidthType(WIDTH_CONDENSED); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsShorterWidth, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsLesserFontFaceWithLighterWeight() +{ + FontAttributes aFontAttrsLighterWeight; + aFontAttrsLighterWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsLighterWeight.SetWeight(WEIGHT_THIN); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrsLighterWeight, FONTID)); + + FontAttributes aFontAttrsHeavierWeight; + aFontAttrsHeavierWeight.SetWeight(WEIGHT_BOLD); + aFontAttrsHeavierWeight.SetWidthType(WIDTH_NORMAL); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsHeavierWeight, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithHeavierWeight() +{ + FontAttributes aFontAttrsHeavierWeight; + aFontAttrsHeavierWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsHeavierWeight.SetWeight(WEIGHT_BOLD); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrsHeavierWeight, FONTID)); + + FontAttributes aFontAttrsLighterWeight; + aFontAttrsLighterWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsLighterWeight.SetWeight(WEIGHT_THIN); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsLighterWeight, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsLesserFontFaceWithLesserItalics() +{ + FontAttributes aFontAttrsLesserItalics; + aFontAttrsLesserItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsLesserItalics.SetWeight(WEIGHT_THIN); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrsLesserItalics, FONTID)); + + FontAttributes aFontAttrsGreaterItalics; + aFontAttrsGreaterItalics.SetWeight(WEIGHT_BOLD); + aFontAttrsGreaterItalics.SetWidthType(WIDTH_NORMAL); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsGreaterItalics, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithGreaterItalics() +{ + FontAttributes aFontAttrsGreaterItalics; + aFontAttrsGreaterItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsGreaterItalics.SetWeight(WEIGHT_BOLD); + rtl::Reference<TestFontFace> aTestedFontFace( + new TestFontFace(aFontAttrsGreaterItalics, FONTID)); + + FontAttributes aFontAttrsLesserItalics; + aFontAttrsLesserItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsLesserItalics.SetWeight(WEIGHT_THIN); + rtl::Reference<TestFontFace> aComparedToFontFace( + new TestFontFace(aFontAttrsLesserItalics, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWitHigherAlphabeticalFamilyName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("B family"); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("A Family"); + rtl::Reference<TestFontFace> aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWitLesserAlphabeticalFamilyName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("A family"); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("B Family"); + rtl::Reference<TestFontFace> aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithHigherAlphabeticalStyleName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("DejaVu Sans"); + aFontAttrs1.SetStyleName("B Style"); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("DejaVu Sans"); + aFontAttrs2.SetStyleName("A Style"); + rtl::Reference<TestFontFace> aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithLesserAlphabeticalStyleName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("DejaVu Sans"); + aFontAttrs1.SetStyleName("A Style"); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("DejaVu Sans"); + aFontAttrs2.SetStyleName("B Style"); + rtl::Reference<TestFontFace> aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsSameFontFace() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("DejaVu Sans"); + aFontAttrs1.SetStyleName("Style"); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("DejaVu Sans"); + aFontAttrs2.SetStyleName("Style"); + rtl::Reference<TestFontFace> aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testMatchStatusValue() +{ + FontAttributes aFontAttrs; + aFontAttrs.SetFamilyName("DejaVu Sans"); + aFontAttrs.SetStyleName("Book"); + aFontAttrs.SetPitch(FontPitch::PITCH_VARIABLE); + aFontAttrs.SetWidthType(WIDTH_NORMAL); + aFontAttrs.SetWeight(WEIGHT_BOLD); + rtl::Reference<TestFontFace> aTestedFontFace(new TestFontFace(aFontAttrs, FONTID)); + + std::unique_ptr<OUString> pTargetStyleName(new OUString("Book")); + vcl::font::FontMatchStatus aFontMatchStatus = { 0, pTargetStyleName.get() }; + + vcl::Font aTestFont("DejaVu Sans", "Book", Size(0, 36)); + + vcl::font::FontSelectPattern aFSP(aTestFont, "DejaVu Sans", Size(0, 36), 36, true); + aFSP.mbEmbolden = false; + aFSP.mnOrientation = Degree10(10); + aFSP.SetWeight(WEIGHT_BOLD); + aFSP.SetPitch(FontPitch::PITCH_VARIABLE); + aFSP.maTargetName = "DejaVu Sans"; + + const int EXPECTED_FAMILY = 240'000; + const int EXPECTED_STYLE = 120'000; + const int EXPECTED_PITCH = 20'000; + const int EXPECTED_WIDTHTYPE = 400; + const int EXPECTED_WEIGHT = 1'000; + const int EXPECTED_ITALIC = 900; + const int EXPECTED_ORIENTATION = 80; + + const int EXPECTED_MATCH = EXPECTED_FAMILY + EXPECTED_STYLE + EXPECTED_PITCH + + EXPECTED_WIDTHTYPE + EXPECTED_WEIGHT + EXPECTED_ITALIC + + EXPECTED_ORIENTATION; + + CPPUNIT_ASSERT(aTestedFontFace->IsBetterMatch(aFSP, aFontMatchStatus)); + CPPUNIT_ASSERT_EQUAL(EXPECTED_MATCH, aFontMatchStatus.mnFaceMatch); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(VclPhysicalFontFaceTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |