From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- vcl/qa/cppunit/physicalfontface.cxx | 301 ++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 vcl/qa/cppunit/physicalfontface.cxx (limited to 'vcl/qa/cppunit/physicalfontface.cxx') 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 + +#include +#include + +#include + +#include + +#include +#include + +#include "fontmocks.hxx" + +#include + +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 aTestedFontFace(new TestFontFace(aFontAttrsShorterWidth, FONTID)); + + FontAttributes aFontAttrsLongerWidth; + aFontAttrsLongerWidth.SetWidthType(WIDTH_NORMAL); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsLongerWidth, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithLongerWidth() +{ + FontAttributes aFontAttrsLongerWidth; + aFontAttrsLongerWidth.SetWidthType(WIDTH_NORMAL); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrsLongerWidth, FONTID)); + + FontAttributes aFontAttrsShorterWidth; + aFontAttrsShorterWidth.SetWidthType(WIDTH_CONDENSED); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsShorterWidth, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsLesserFontFaceWithLighterWeight() +{ + FontAttributes aFontAttrsLighterWeight; + aFontAttrsLighterWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsLighterWeight.SetWeight(WEIGHT_THIN); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrsLighterWeight, FONTID)); + + FontAttributes aFontAttrsHeavierWeight; + aFontAttrsHeavierWeight.SetWeight(WEIGHT_BOLD); + aFontAttrsHeavierWeight.SetWidthType(WIDTH_NORMAL); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsHeavierWeight, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithHeavierWeight() +{ + FontAttributes aFontAttrsHeavierWeight; + aFontAttrsHeavierWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsHeavierWeight.SetWeight(WEIGHT_BOLD); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrsHeavierWeight, FONTID)); + + FontAttributes aFontAttrsLighterWeight; + aFontAttrsLighterWeight.SetWidthType(WIDTH_NORMAL); + aFontAttrsLighterWeight.SetWeight(WEIGHT_THIN); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsLighterWeight, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsLesserFontFaceWithLesserItalics() +{ + FontAttributes aFontAttrsLesserItalics; + aFontAttrsLesserItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsLesserItalics.SetWeight(WEIGHT_THIN); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrsLesserItalics, FONTID)); + + FontAttributes aFontAttrsGreaterItalics; + aFontAttrsGreaterItalics.SetWeight(WEIGHT_BOLD); + aFontAttrsGreaterItalics.SetWidthType(WIDTH_NORMAL); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsGreaterItalics, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(-1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWithGreaterItalics() +{ + FontAttributes aFontAttrsGreaterItalics; + aFontAttrsGreaterItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsGreaterItalics.SetWeight(WEIGHT_BOLD); + rtl::Reference aTestedFontFace( + new TestFontFace(aFontAttrsGreaterItalics, FONTID)); + + FontAttributes aFontAttrsLesserItalics; + aFontAttrsLesserItalics.SetWidthType(WIDTH_NORMAL); + aFontAttrsLesserItalics.SetWeight(WEIGHT_THIN); + rtl::Reference aComparedToFontFace( + new TestFontFace(aFontAttrsLesserItalics, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWitHigherAlphabeticalFamilyName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("B family"); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("A Family"); + rtl::Reference aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(1), + aTestedFontFace->CompareIgnoreSize(*aComparedToFontFace)); +} + +void VclPhysicalFontFaceTest::testShouldCompareAsGreaterFontFaceWitLesserAlphabeticalFamilyName() +{ + FontAttributes aFontAttrs1; + aFontAttrs1.SetWidthType(WIDTH_NORMAL); + aFontAttrs1.SetWeight(WEIGHT_NORMAL); + aFontAttrs1.SetFamilyName("A family"); + rtl::Reference aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("B Family"); + rtl::Reference aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(-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 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 aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(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 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 aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(-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 aTestedFontFace(new TestFontFace(aFontAttrs1, FONTID)); + + FontAttributes aFontAttrs2; + aFontAttrs2.SetWidthType(WIDTH_NORMAL); + aFontAttrs2.SetWeight(WEIGHT_NORMAL); + aFontAttrs2.SetFamilyName("DejaVu Sans"); + aFontAttrs2.SetStyleName("Style"); + rtl::Reference aComparedToFontFace(new TestFontFace(aFontAttrs2, FONTID)); + + CPPUNIT_ASSERT_EQUAL(static_cast(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 aTestedFontFace(new TestFontFace(aFontAttrs, FONTID)); + + std::unique_ptr 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: */ -- cgit v1.2.3