/* -*- 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/.
*/
void VclPhysicalFontCollectionTest::testShouldCreateAndAddFontFamilyToCollection()
{
vcl::font::PhysicalFontCollection aFontCollection;
CPPUNIT_ASSERT_EQUAL_MESSAGE("Empty font collection", static_cast<int>(0),
aFontCollection.Count());
// please note that fonts created this way are NOT normalized and will not be found if you search for them in the collection
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindOrCreateFontFamily(u"Test Font Family Name"_ustr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Does not have only one font family in collection", static_cast<int>(1), aFontCollection.Count());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct", u"Test Font Family Name"_ustr,
pFontFamily->GetSearchName());
vcl::font::PhysicalFontFamily* pFontFamily2
= aFontCollection.FindOrCreateFontFamily(u"Test Font Family Name"_ustr);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Still only one font family in collection", static_cast<int>(1),
aFontCollection.Count());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct", u"Test Font Family Name"_ustr,
pFontFamily2->GetSearchName());
}
void VclPhysicalFontCollectionTest::testShouldFindFontFamily()
{ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
vcl::font::PhysicalFontCollection aFontCollection;
aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Test Font Family Name"));
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindFontFamily(u"Test Font Family Name");
CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct",
GetEnglishSearchFontName(u"Test Font Family Name"),
pFontFamily->GetSearchName());
}
void VclPhysicalFontCollectionTest::testShouldNotFindFontFamily()
{ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
vcl::font::PhysicalFontCollection aFontCollection;
aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Test Font Family Name"));
void VclPhysicalFontCollectionTest::testShouldFindFontFamilyByTokenNames()
{ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
vcl::font::PhysicalFontCollection aFontCollection;
aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Test Font Family Name"));
OUString sTokenNames(GetEnglishSearchFontName(u"Test Font Family Name;"));
sTokenNames += GetEnglishSearchFontName(u"Test 2");
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindFontFamilyByTokenNames(u"Test Font Family Name");
CPPUNIT_ASSERT_MESSAGE("Did not find the font family", pFontFamily);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name incorrect",
GetEnglishSearchFontName(u"Test Font Family Name"),
pFontFamily->GetSearchName());
}
void VclPhysicalFontCollectionTest::testShouldFindNoFamilyWithWorthlessAttributes()
{ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
vcl::font::PhysicalFontCollection aFontCollection;
aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Test Font Family Name"));
// interestingly, you need to normalize the name still
vcl::font::PhysicalFontFamily* pFontFamily = aFontCollection.FindOrCreateFontFamily(
GetEnglishSearchFontName(u"시험")); // Korean for "test"
AddNormalFontFace(pFontFamily, u"시험"_ustr);
vcl::font::PhysicalFontFamily* pCJKFamily = aFontCollection.FindFontFamilyByAttributes(
ImplFontAttrs::CJK, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NORMAL, u"");
CPPUNIT_ASSERT_MESSAGE("family not found", pCJKFamily);
CPPUNIT_ASSERT_EQUAL_MESSAGE("cjk family not found", GetEnglishSearchFontName(u"시험"),
pCJKFamily->GetSearchName());
}
CPPUNIT_ASSERT_MESSAGE("match for family not possible, but was found anyway",
!aFontCollection.FindFontFamilyByAttributes(ImplFontAttrs::Normal,
WEIGHT_NORMAL, WIDTH_NORMAL,
ITALIC_NORMAL, u""));
}
// note that for this test, it is irrelevant what the search name is for PhysicalFontFamily, // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindOrCreateFontFamily(u"Matching family name"_ustr);
AddNormalFontFace(pFontFamily, GetEnglishSearchFontName(u"Matching family name"));
CPPUNIT_ASSERT_MESSAGE("No family found",
aFontCollection.FindFontFamilyByAttributes(
ImplFontAttrs::Normal, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE,
u"Matching family name"));
}
// note that for this test, it is irrelevant what the search name is for PhysicalFontFamily, // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Matching family name"));
FontAttributes aFontAttr;
aFontAttr.SetFamilyName(GetEnglishSearchFontName(u"Matching family name"));
aFontAttr.SetFamilyType(FAMILY_MODERN);
aFontAttr.SetWeight(WEIGHT_NORMAL);
TestFontFace* pFontFace = new TestFontFace(aFontAttr, FONTID);
pFontFamily->AddFontFace(pFontFace);
CPPUNIT_ASSERT_MESSAGE("No fixed family found",
aFontCollection.FindFontFamilyByAttributes(
ImplFontAttrs::Fixed, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE,
GetEnglishSearchFontName(u"Matching family name")));
}
// note that for this test, it is irrelevant what the search name is for PhysicalFontFamily, // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
vcl::font::PhysicalFontFamily* pFontFamily
= aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName(u"Matching family name"));
FontAttributes aFontAttr;
aFontAttr.SetFamilyName(GetEnglishSearchFontName(u"Matching family name"));
aFontAttr.SetFamilyType(FAMILY_SWISS);
aFontAttr.SetWeight(WEIGHT_NORMAL);
TestFontFace* pFontFace = new TestFontFace(aFontAttr, FONTID);
pFontFamily->AddFontFace(pFontFace);
CPPUNIT_ASSERT_MESSAGE("Fixed family found",
aFontCollection.FindFontFamilyByAttributes(
ImplFontAttrs::Fixed, WEIGHT_NORMAL, WIDTH_NORMAL, ITALIC_NONE,
GetEnglishSearchFontName(u"Matching family name")));
}
CPPUNIT_ASSERT_MESSAGE("SansSerif family not found",
aFontCollection.FindFontFamilyByAttributes(ImplFontAttrs::SansSerif,
WEIGHT_NORMAL, WIDTH_NORMAL,
ITALIC_NONE, u""));
}
CPPUNIT_ASSERT_MESSAGE("Decorative family not found",
aFontCollection.FindFontFamilyByAttributes(ImplFontAttrs::Decorative,
WEIGHT_NORMAL, WIDTH_NORMAL,
ITALIC_NORMAL, u""));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.