1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <test/bootstrapfixture.hxx>
13 #include <cppunit/TestAssert.h>
15 #include <font/PhysicalFontCollection.hxx>
16 #include <font/PhysicalFontFamily.hxx>
18 #include "fontmocks.hxx"
22 constexpr int FONTID
= 1;
24 class VclPhysicalFontCollectionTest
: public test::BootstrapFixture
27 VclPhysicalFontCollectionTest()
28 : BootstrapFixture(true, false)
32 void testShouldCreateAndAddFontFamilyToCollection();
33 void testShouldFindFontFamily();
34 void testShouldNotFindFontFamily();
35 void testShouldFindFontFamilyByTokenNames();
36 void testShouldFindNoFamilyWithWorthlessAttributes();
37 void testShouldFindCJKFamily();
38 void testShouldNotFindCJKFamily();
39 void testShouldFindStarsymbolFamily();
40 void testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies();
41 void testShouldFindSymboltypeFamily();
42 void testShouldFindSymbolFamilyByMatchType();
43 void testImpossibleSymbolFamily();
44 void testShouldNotFindSymbolFamily();
45 void testShouldMatchFamilyName();
46 void testShouldMatchBrushScriptFamily();
47 void testShouldNotMatchBrushScriptFamily();
48 void testShouldMatchFixedFamily();
49 void testShouldNotMatchFixedFamily();
50 void testShouldMatchSerifFamily();
51 void testShouldNotMatchSerifFamily();
52 void testShouldMatchSansSerifFamily();
53 void testShouldNotMatchSansSerifFamily();
54 void testShouldMatchDecorativeFamily();
55 void testShouldFindTitlingFamily();
56 void testShouldFindCapitalsFamily();
57 void testShouldFindFamilyName();
58 void testShouldFindOtherStyleFamily();
59 void testShouldNotFindOtherStyleFamily();
60 void testShouldFindSchoolbookFamily();
62 CPPUNIT_TEST_SUITE(VclPhysicalFontCollectionTest
);
63 CPPUNIT_TEST(testShouldCreateAndAddFontFamilyToCollection
);
64 CPPUNIT_TEST(testShouldFindFontFamily
);
65 CPPUNIT_TEST(testShouldNotFindFontFamily
);
66 CPPUNIT_TEST(testShouldFindFontFamilyByTokenNames
);
67 CPPUNIT_TEST(testShouldFindNoFamilyWithWorthlessAttributes
);
68 CPPUNIT_TEST(testShouldFindCJKFamily
);
69 CPPUNIT_TEST(testShouldNotFindCJKFamily
);
70 CPPUNIT_TEST(testShouldFindStarsymbolFamily
);
71 CPPUNIT_TEST(testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies
);
72 CPPUNIT_TEST(testShouldFindSymboltypeFamily
);
73 CPPUNIT_TEST(testShouldFindSymbolFamilyByMatchType
);
74 CPPUNIT_TEST(testImpossibleSymbolFamily
);
75 CPPUNIT_TEST(testShouldNotFindSymbolFamily
);
76 CPPUNIT_TEST(testShouldMatchFamilyName
);
77 CPPUNIT_TEST(testShouldMatchBrushScriptFamily
);
78 CPPUNIT_TEST(testShouldNotMatchBrushScriptFamily
);
79 CPPUNIT_TEST(testShouldMatchFixedFamily
);
80 CPPUNIT_TEST(testShouldNotMatchFixedFamily
);
81 CPPUNIT_TEST(testShouldMatchSerifFamily
);
82 CPPUNIT_TEST(testShouldNotMatchSerifFamily
);
83 CPPUNIT_TEST(testShouldMatchSansSerifFamily
);
84 CPPUNIT_TEST(testShouldNotMatchSansSerifFamily
);
85 CPPUNIT_TEST(testShouldMatchDecorativeFamily
);
86 CPPUNIT_TEST(testShouldFindTitlingFamily
);
87 CPPUNIT_TEST(testShouldFindCapitalsFamily
);
88 CPPUNIT_TEST(testShouldFindFamilyName
);
89 CPPUNIT_TEST(testShouldFindOtherStyleFamily
);
90 CPPUNIT_TEST(testShouldNotFindOtherStyleFamily
);
91 CPPUNIT_TEST(testShouldFindSchoolbookFamily
);
92 CPPUNIT_TEST_SUITE_END();
95 void VclPhysicalFontCollectionTest::testShouldCreateAndAddFontFamilyToCollection()
97 vcl::font::PhysicalFontCollection aFontCollection
;
98 CPPUNIT_ASSERT_EQUAL_MESSAGE("Empty font collection", static_cast<int>(0),
99 aFontCollection
.Count());
101 // please note that fonts created this way are NOT normalized and will not be found if you search for them in the collection
102 vcl::font::PhysicalFontFamily
* pFontFamily
103 = aFontCollection
.FindOrCreateFontFamily(u
"Test Font Family Name"_ustr
);
104 CPPUNIT_ASSERT_EQUAL_MESSAGE("Does not have only one font family in collection",
105 static_cast<int>(1), aFontCollection
.Count());
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct", u
"Test Font Family Name"_ustr
,
107 pFontFamily
->GetSearchName());
109 vcl::font::PhysicalFontFamily
* pFontFamily2
110 = aFontCollection
.FindOrCreateFontFamily(u
"Test Font Family Name"_ustr
);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Still only one font family in collection", static_cast<int>(1),
112 aFontCollection
.Count());
113 CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct", u
"Test Font Family Name"_ustr
,
114 pFontFamily2
->GetSearchName());
117 void VclPhysicalFontCollectionTest::testShouldFindFontFamily()
119 // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
120 vcl::font::PhysicalFontCollection aFontCollection
;
121 aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Test Font Family Name"));
123 vcl::font::PhysicalFontFamily
* pFontFamily
124 = aFontCollection
.FindFontFamily(u
"Test Font Family Name");
125 CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name not correct",
126 GetEnglishSearchFontName(u
"Test Font Family Name"),
127 pFontFamily
->GetSearchName());
130 void VclPhysicalFontCollectionTest::testShouldNotFindFontFamily()
132 // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
133 vcl::font::PhysicalFontCollection aFontCollection
;
134 aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Test Font Family Name"));
136 CPPUNIT_ASSERT(!aFontCollection
.FindFontFamily(u
"blah"));
139 void VclPhysicalFontCollectionTest::testShouldFindFontFamilyByTokenNames()
141 // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
142 vcl::font::PhysicalFontCollection aFontCollection
;
143 aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Test Font Family Name"));
145 OUString
sTokenNames(GetEnglishSearchFontName(u
"Test Font Family Name;"));
146 sTokenNames
+= GetEnglishSearchFontName(u
"Test 2");
148 vcl::font::PhysicalFontFamily
* pFontFamily
149 = aFontCollection
.FindFontFamilyByTokenNames(u
"Test Font Family Name");
150 CPPUNIT_ASSERT_MESSAGE("Did not find the font family", pFontFamily
);
151 CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name incorrect",
152 GetEnglishSearchFontName(u
"Test Font Family Name"),
153 pFontFamily
->GetSearchName());
156 static void AddNormalFontFace(vcl::font::PhysicalFontFamily
* const pFontFamily
,
157 OUString
const& rFamilyName
)
159 FontAttributes aFontAttr
;
160 aFontAttr
.SetFamilyName(rFamilyName
);
161 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
162 pFontFamily
->AddFontFace(new TestFontFace(aFontAttr
, FONTID
));
165 void VclPhysicalFontCollectionTest::testShouldFindNoFamilyWithWorthlessAttributes()
167 // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
168 vcl::font::PhysicalFontCollection aFontCollection
;
169 aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Test Font Family Name"));
171 CPPUNIT_ASSERT(!aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::None
, WEIGHT_NORMAL
,
172 WIDTH_NORMAL
, ITALIC_NONE
, u
""));
175 void VclPhysicalFontCollectionTest::testShouldFindCJKFamily()
177 vcl::font::PhysicalFontCollection aFontCollection
;
179 // interestingly, you need to normalize the name still
180 vcl::font::PhysicalFontFamily
* pFontFamily
= aFontCollection
.FindOrCreateFontFamily(
181 GetEnglishSearchFontName(u
"시험")); // Korean for "test"
182 AddNormalFontFace(pFontFamily
, u
"시험"_ustr
);
184 vcl::font::PhysicalFontFamily
* pCJKFamily
= aFontCollection
.FindFontFamilyByAttributes(
185 ImplFontAttrs::CJK
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
, u
"");
186 CPPUNIT_ASSERT_MESSAGE("family not found", pCJKFamily
);
187 CPPUNIT_ASSERT_EQUAL_MESSAGE("cjk family not found", GetEnglishSearchFontName(u
"시험"),
188 pCJKFamily
->GetSearchName());
191 void VclPhysicalFontCollectionTest::testShouldNotFindCJKFamily()
193 vcl::font::PhysicalFontCollection aFontCollection
;
194 vcl::font::PhysicalFontFamily
* pFontFamily
195 = aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"No CJK characters"));
196 AddNormalFontFace(pFontFamily
, u
"No CJK characters"_ustr
);
198 CPPUNIT_ASSERT_MESSAGE("family found",
199 !aFontCollection
.FindFontFamilyByAttributes(
200 ImplFontAttrs::CJK
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NONE
, u
""));
203 void VclPhysicalFontCollectionTest::testShouldFindStarsymbolFamily()
205 vcl::font::PhysicalFontCollection aFontCollection
;
206 vcl::font::PhysicalFontFamily
* pFontFamily
207 = aFontCollection
.FindOrCreateFontFamily(u
"starsymbol"_ustr
);
208 AddNormalFontFace(pFontFamily
, u
"starsymbol"_ustr
);
210 CPPUNIT_ASSERT_MESSAGE("starsymbol created", pFontFamily
);
212 vcl::font::PhysicalFontFamily
* pStarsymbolFamily
= aFontCollection
.FindFontFamilyByAttributes(
213 ImplFontAttrs::Symbol
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
, u
"");
214 CPPUNIT_ASSERT_MESSAGE("family not found", pStarsymbolFamily
);
215 CPPUNIT_ASSERT_EQUAL_MESSAGE("starsymbol family not found", u
"starsymbol"_ustr
,
216 pStarsymbolFamily
->GetSearchName());
219 void VclPhysicalFontCollectionTest::testShouldFindOpensymbolFamilyWithMultipleSymbolFamilies()
221 vcl::font::PhysicalFontCollection aFontCollection
;
223 vcl::font::PhysicalFontFamily
* pOpenSymbolFamily
224 = aFontCollection
.FindOrCreateFontFamily(u
"opensymbol"_ustr
);
225 AddNormalFontFace(pOpenSymbolFamily
, u
"opensymbol"_ustr
);
227 vcl::font::PhysicalFontFamily
* pWingDingsFontFamily
228 = aFontCollection
.FindOrCreateFontFamily(u
"wingdings"_ustr
);
229 AddNormalFontFace(pWingDingsFontFamily
, u
"wingdings"_ustr
);
231 vcl::font::PhysicalFontFamily
* pStarsymbolFamily
= aFontCollection
.FindFontFamilyByAttributes(
232 ImplFontAttrs::Symbol
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
, u
"");
233 CPPUNIT_ASSERT_MESSAGE("family not found", pStarsymbolFamily
);
234 CPPUNIT_ASSERT_EQUAL_MESSAGE("opensymbol family not found", u
"opensymbol"_ustr
,
235 pStarsymbolFamily
->GetSearchName());
238 void VclPhysicalFontCollectionTest::testShouldFindSymboltypeFamily()
240 vcl::font::PhysicalFontCollection aFontCollection
;
241 vcl::font::PhysicalFontFamily
* pFontFamily
242 = aFontCollection
.FindOrCreateFontFamily(u
"testsymbol"_ustr
);
244 AddNormalFontFace(pFontFamily
, u
"testsymbol"_ustr
);
246 vcl::font::PhysicalFontFamily
* pSymbolFamily
= aFontCollection
.FindFontFamilyByAttributes(
247 ImplFontAttrs::Symbol
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
, u
"");
248 CPPUNIT_ASSERT_MESSAGE("family not found", pSymbolFamily
);
249 CPPUNIT_ASSERT_EQUAL_MESSAGE("test symbol family not found", u
"testsymbol"_ustr
,
250 pSymbolFamily
->GetSearchName());
253 void VclPhysicalFontCollectionTest::testShouldFindSymbolFamilyByMatchType()
255 // TODO: figure out how to test matchtype with ImplFontAttrs::Full
257 vcl::font::PhysicalFontCollection aFontCollection
;
258 vcl::font::PhysicalFontFamily
* pFontFamily
259 = aFontCollection
.FindOrCreateFontFamily(u
"symbols"_ustr
);
261 FontAttributes aFontAttr
;
262 aFontAttr
.SetFamilyName(u
"symbols"_ustr
);
263 aFontAttr
.SetMicrosoftSymbolEncoded(true);
264 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
265 pFontFamily
->AddFontFace(new TestFontFace(aFontAttr
, FONTID
));
267 vcl::font::PhysicalFontFamily
* pSymbolFamily
= aFontCollection
.FindFontFamilyByAttributes(
268 ImplFontAttrs::Symbol
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
, u
"");
269 CPPUNIT_ASSERT_MESSAGE("family not found", pSymbolFamily
);
270 CPPUNIT_ASSERT_EQUAL_MESSAGE("test symbol family not found", u
"symbols"_ustr
,
271 pSymbolFamily
->GetSearchName());
274 void VclPhysicalFontCollectionTest::testImpossibleSymbolFamily()
276 vcl::font::PhysicalFontCollection aFontCollection
;
277 vcl::font::PhysicalFontFamily
* pFontFamily
278 = aFontCollection
.FindOrCreateFontFamily(u
"testsymbolfamily"_ustr
);
280 FontAttributes aFontAttr
;
281 aFontAttr
.SetFamilyName(u
"testsymbolfamily"_ustr
);
282 aFontAttr
.SetMicrosoftSymbolEncoded(true);
283 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
284 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
285 pFontFamily
->AddFontFace(pFontFace
);
287 CPPUNIT_ASSERT_MESSAGE("match for family not possible, but was found anyway",
288 !aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::Normal
,
289 WEIGHT_NORMAL
, WIDTH_NORMAL
,
290 ITALIC_NORMAL
, u
""));
293 void VclPhysicalFontCollectionTest::testShouldNotFindSymbolFamily()
295 vcl::font::PhysicalFontCollection aFontCollection
;
296 vcl::font::PhysicalFontFamily
* pFontFamily
297 = aFontCollection
.FindOrCreateFontFamily(u
"symbol"_ustr
);
298 AddNormalFontFace(pFontFamily
, u
"symbol"_ustr
);
300 CPPUNIT_ASSERT_MESSAGE(
301 "Family found", !aFontCollection
.FindFontFamilyByAttributes(
302 ImplFontAttrs::Normal
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NONE
, u
""));
305 void VclPhysicalFontCollectionTest::testShouldMatchFamilyName()
307 vcl::font::PhysicalFontCollection aFontCollection
;
309 // note that for this test, it is irrelevant what the search name is for PhysicalFontFamily,
310 // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
311 vcl::font::PhysicalFontFamily
* pFontFamily
312 = aFontCollection
.FindOrCreateFontFamily(u
"Matching family name"_ustr
);
313 AddNormalFontFace(pFontFamily
, GetEnglishSearchFontName(u
"Matching family name"));
315 CPPUNIT_ASSERT_MESSAGE("No family found",
316 aFontCollection
.FindFontFamilyByAttributes(
317 ImplFontAttrs::Normal
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NONE
,
318 u
"Matching family name"));
321 void VclPhysicalFontCollectionTest::testShouldMatchBrushScriptFamily()
323 vcl::font::PhysicalFontCollection aFontCollection
;
324 vcl::font::PhysicalFontFamily
* pFontFamily
325 = aFontCollection
.FindOrCreateFontFamily(u
"script"_ustr
);
326 AddNormalFontFace(pFontFamily
, u
"script"_ustr
);
328 CPPUNIT_ASSERT_MESSAGE("Brush script family not found",
329 aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::BrushScript
,
330 WEIGHT_NORMAL
, WIDTH_NORMAL
,
334 void VclPhysicalFontCollectionTest::testShouldNotMatchBrushScriptFamily()
336 vcl::font::PhysicalFontCollection aFontCollection
;
337 vcl::font::PhysicalFontFamily
* pFontFamily
338 = aFontCollection
.FindOrCreateFontFamily(u
"testfamily"_ustr
);
339 AddNormalFontFace(pFontFamily
, u
"testfamily"_ustr
);
341 CPPUNIT_ASSERT_MESSAGE("Brush script family found",
342 !aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::BrushScript
,
343 WEIGHT_NORMAL
, WIDTH_NORMAL
,
347 void VclPhysicalFontCollectionTest::testShouldMatchFixedFamily()
349 vcl::font::PhysicalFontCollection aFontCollection
;
351 // note that for this test, it is irrelevant what the search name is for PhysicalFontFamily,
352 // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
353 vcl::font::PhysicalFontFamily
* pFontFamily
354 = aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Matching family name"));
356 FontAttributes aFontAttr
;
357 aFontAttr
.SetFamilyName(GetEnglishSearchFontName(u
"Matching family name"));
358 aFontAttr
.SetFamilyType(FAMILY_MODERN
);
359 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
360 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
361 pFontFamily
->AddFontFace(pFontFace
);
363 CPPUNIT_ASSERT_MESSAGE("No fixed family found",
364 aFontCollection
.FindFontFamilyByAttributes(
365 ImplFontAttrs::Fixed
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NONE
,
366 GetEnglishSearchFontName(u
"Matching family name")));
369 void VclPhysicalFontCollectionTest::testShouldNotMatchFixedFamily()
371 vcl::font::PhysicalFontCollection aFontCollection
;
373 // note that for this test, it is irrelevant what the search name is for PhysicalFontFamily,
374 // the font searches the family name and uses the search parameter of FindFontFamilyByAttributes()
375 vcl::font::PhysicalFontFamily
* pFontFamily
376 = aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Matching family name"));
378 FontAttributes aFontAttr
;
379 aFontAttr
.SetFamilyName(GetEnglishSearchFontName(u
"Matching family name"));
380 aFontAttr
.SetFamilyType(FAMILY_SWISS
);
381 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
382 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
383 pFontFamily
->AddFontFace(pFontFace
);
385 CPPUNIT_ASSERT_MESSAGE("Fixed family found",
386 aFontCollection
.FindFontFamilyByAttributes(
387 ImplFontAttrs::Fixed
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NONE
,
388 GetEnglishSearchFontName(u
"Matching family name")));
391 void VclPhysicalFontCollectionTest::testShouldMatchSerifFamily()
393 vcl::font::PhysicalFontCollection aFontCollection
;
394 vcl::font::PhysicalFontFamily
* pFontFamily
395 = aFontCollection
.FindOrCreateFontFamily(u
"serif"_ustr
);
397 FontAttributes aFontAttr
;
398 aFontAttr
.SetFamilyName(u
"serif"_ustr
);
399 aFontAttr
.SetFamilyType(FAMILY_ROMAN
);
400 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
401 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
402 pFontFamily
->AddFontFace(pFontFace
);
404 CPPUNIT_ASSERT_MESSAGE("Serif family not found", aFontCollection
.FindFontFamilyByAttributes(
405 ImplFontAttrs::Serif
, WEIGHT_NORMAL
,
406 WIDTH_NORMAL
, ITALIC_NONE
, u
""));
409 void VclPhysicalFontCollectionTest::testShouldNotMatchSerifFamily()
411 vcl::font::PhysicalFontCollection aFontCollection
;
412 vcl::font::PhysicalFontFamily
* pFontFamily
413 = aFontCollection
.FindOrCreateFontFamily(u
"sansseriftest"_ustr
);
415 FontAttributes aFontAttr
;
416 aFontAttr
.SetFamilyName(u
"sansseriftest"_ustr
);
417 aFontAttr
.SetFamilyType(FAMILY_SWISS
);
418 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
419 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
420 pFontFamily
->AddFontFace(pFontFace
);
422 CPPUNIT_ASSERT_MESSAGE("Serif family found", !aFontCollection
.FindFontFamilyByAttributes(
423 ImplFontAttrs::Serif
, WEIGHT_NORMAL
,
424 WIDTH_NORMAL
, ITALIC_NONE
, u
""));
427 void VclPhysicalFontCollectionTest::testShouldMatchSansSerifFamily()
429 vcl::font::PhysicalFontCollection aFontCollection
;
430 vcl::font::PhysicalFontFamily
* pFontFamily
431 = aFontCollection
.FindOrCreateFontFamily(u
"sansserif"_ustr
);
433 FontAttributes aFontAttr
;
434 aFontAttr
.SetFamilyName(u
"sansserif"_ustr
);
435 aFontAttr
.SetFamilyType(FAMILY_SWISS
);
436 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
437 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
438 pFontFamily
->AddFontFace(pFontFace
);
440 CPPUNIT_ASSERT_MESSAGE("SansSerif family not found",
441 aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::SansSerif
,
442 WEIGHT_NORMAL
, WIDTH_NORMAL
,
446 void VclPhysicalFontCollectionTest::testShouldNotMatchSansSerifFamily()
448 vcl::font::PhysicalFontCollection aFontCollection
;
449 vcl::font::PhysicalFontFamily
* pFontFamily
450 = aFontCollection
.FindOrCreateFontFamily(u
"serif"_ustr
);
452 FontAttributes aFontAttr
;
453 aFontAttr
.SetFamilyName(u
"serif"_ustr
);
454 aFontAttr
.SetFamilyType(FAMILY_ROMAN
);
455 aFontAttr
.SetWeight(WEIGHT_NORMAL
);
456 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
457 pFontFamily
->AddFontFace(pFontFace
);
459 CPPUNIT_ASSERT_MESSAGE("SansSerif family found", !aFontCollection
.FindFontFamilyByAttributes(
460 ImplFontAttrs::SansSerif
, WEIGHT_NORMAL
,
461 WIDTH_NORMAL
, ITALIC_NONE
, u
""));
464 void VclPhysicalFontCollectionTest::testShouldMatchDecorativeFamily()
466 vcl::font::PhysicalFontCollection aFontCollection
;
467 vcl::font::PhysicalFontFamily
* pFontFamily
468 = aFontCollection
.FindOrCreateFontFamily(u
"decorative"_ustr
);
470 FontAttributes aFontAttr
;
471 aFontAttr
.SetFamilyName(u
"decorative"_ustr
);
472 aFontAttr
.SetFamilyType(FAMILY_DECORATIVE
);
473 aFontAttr
.SetWeight(WEIGHT_MEDIUM
);
474 TestFontFace
* pFontFace
= new TestFontFace(aFontAttr
, FONTID
);
475 pFontFamily
->AddFontFace(pFontFace
);
477 CPPUNIT_ASSERT_MESSAGE("Decorative family not found",
478 aFontCollection
.FindFontFamilyByAttributes(ImplFontAttrs::Decorative
,
479 WEIGHT_NORMAL
, WIDTH_NORMAL
,
480 ITALIC_NORMAL
, u
""));
483 void VclPhysicalFontCollectionTest::testShouldFindTitlingFamily()
485 vcl::font::PhysicalFontCollection aFontCollection
;
486 vcl::font::PhysicalFontFamily
* pFontFamily
487 = aFontCollection
.FindOrCreateFontFamily(u
"testtitling"_ustr
);
488 AddNormalFontFace(pFontFamily
, u
"testtitling"_ustr
);
490 CPPUNIT_ASSERT_MESSAGE("Titling family not found", aFontCollection
.FindFontFamilyByAttributes(
491 ImplFontAttrs::Titling
, WEIGHT_NORMAL
,
492 WIDTH_NORMAL
, ITALIC_NORMAL
, u
""));
495 void VclPhysicalFontCollectionTest::testShouldFindCapitalsFamily()
497 vcl::font::PhysicalFontCollection aFontCollection
;
498 vcl::font::PhysicalFontFamily
* pFontFamily
499 = aFontCollection
.FindOrCreateFontFamily(u
"testcaps"_ustr
);
500 AddNormalFontFace(pFontFamily
, u
"testcaps"_ustr
);
502 CPPUNIT_ASSERT_MESSAGE("All-caps family not found", aFontCollection
.FindFontFamilyByAttributes(
503 ImplFontAttrs::Capitals
, WEIGHT_NORMAL
,
504 WIDTH_NORMAL
, ITALIC_NORMAL
, u
""));
507 void VclPhysicalFontCollectionTest::testShouldFindFamilyName()
509 vcl::font::PhysicalFontCollection aFontCollection
;
510 vcl::font::PhysicalFontFamily
* pFontFamily
511 = aFontCollection
.FindOrCreateFontFamily(GetEnglishSearchFontName(u
"Test font name"));
512 AddNormalFontFace(pFontFamily
, GetEnglishSearchFontName(u
"Test font name"));
514 CPPUNIT_ASSERT_MESSAGE("Cannot find font name",
515 aFontCollection
.FindFontFamilyByAttributes(
516 ImplFontAttrs::Capitals
, WEIGHT_NORMAL
, WIDTH_NORMAL
, ITALIC_NORMAL
,
517 GetEnglishSearchFontName(u
"Test font name")));
520 void VclPhysicalFontCollectionTest::testShouldFindOtherStyleFamily()
522 vcl::font::PhysicalFontCollection aFontCollection
;
523 vcl::font::PhysicalFontFamily
* pFontFamily
524 = aFontCollection
.FindOrCreateFontFamily(u
"testoldstyle"_ustr
);
525 AddNormalFontFace(pFontFamily
, u
"testoldstyle"_ustr
);
527 CPPUNIT_ASSERT_MESSAGE("Did not find font name", aFontCollection
.FindFontFamilyByAttributes(
528 ImplFontAttrs::OtherStyle
, WEIGHT_NORMAL
,
529 WIDTH_NORMAL
, ITALIC_NORMAL
, u
""));
532 void VclPhysicalFontCollectionTest::testShouldNotFindOtherStyleFamily()
534 vcl::font::PhysicalFontCollection aFontCollection
;
535 vcl::font::PhysicalFontFamily
* pFontFamily
536 = aFontCollection
.FindOrCreateFontFamily(u
"monotype"_ustr
);
537 AddNormalFontFace(pFontFamily
, u
"monotype"_ustr
);
539 CPPUNIT_ASSERT_MESSAGE("Found font name", !aFontCollection
.FindFontFamilyByAttributes(
540 ImplFontAttrs::OtherStyle
, WEIGHT_NORMAL
,
541 WIDTH_NORMAL
, ITALIC_NORMAL
, u
""));
544 void VclPhysicalFontCollectionTest::testShouldFindSchoolbookFamily()
546 vcl::font::PhysicalFontCollection aFontCollection
;
547 vcl::font::PhysicalFontFamily
* pFontFamily
548 = aFontCollection
.FindOrCreateFontFamily(u
"testschoolbook"_ustr
);
549 AddNormalFontFace(pFontFamily
, u
"testschoolbook"_ustr
);
551 CPPUNIT_ASSERT_MESSAGE("Did not find font name", aFontCollection
.FindFontFamilyByAttributes(
552 ImplFontAttrs::Schoolbook
, WEIGHT_NORMAL
,
553 WIDTH_NORMAL
, ITALIC_NORMAL
, u
""));
556 CPPUNIT_TEST_SUITE_REGISTRATION(VclPhysicalFontCollectionTest
);
558 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */