Debian Codegraph @

sw/qa/writerfilter/dmapper/FontTable.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10 #include <test/unoapi_test.hxx>
11
12 #include <com/sun/star/awt/FontFamily.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/text/XTextDocument.hpp>
15
16 #include <vcl/embeddedfontsmanager.hxx>
17
18 using namespace com::sun::star;
19
20 namespace
21 {
22 /// Tests for sw/source/writerfilter/dmapper/FontTable.cxx.
23 class Test : public UnoApiTest
24 {
25 public:
26 Test()
27 : UnoApiTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr)
28 {
29 }
30 };
31
32 CPPUNIT_TEST_FIXTURE(Test, testSubsettedEmbeddedFont)
33 {
34 // Given a document with a subsetted embedded font, loaded for editing:
35 loadFromFile(u"subsetted-embedded-font.docx");
36
37 // When checking if the font is available:
38 OUString aUrl = EmbeddedFontsManager::fontFileUrl(
39 u"IBM Plex Serif Light", FAMILY_ROMAN, ITALIC_NONE, WEIGHT_NORMAL, PITCH_VARIABLE,
40 EmbeddedFontsManager::FontRights::ViewingAllowed);
41
42 // Then make sure the subsetted font is not available, given that the newly inserted characters
43 // during editing may be missing from the subsetted font:
44 CPPUNIT_ASSERT(aUrl.isEmpty());
45 }
46
47 CPPUNIT_TEST_FIXTURE(Test, testSubsettedFullEmbeddedFont)
48 {
49 #if !defined(MACOSX) // FIXME fails on macOS
50 // Given a document with an embedded font (marked as subsetted, but otherwise full in practice),
51 // loaded for editing:
52 loadFromFile(u"subsetted-full-embedded-font.docx");
53
54 // When checking if the font is available:
55 OUString aUrl = EmbeddedFontsManager::fontFileUrl(
56 u"IBM Plex Serif Light", FAMILY_ROMAN, ITALIC_NONE, WEIGHT_NORMAL, PITCH_VARIABLE,
57 EmbeddedFontsManager::FontRights::ViewingAllowed);
58
59 // Then make sure the subsetted font is available, given that it has the reasonable amount of
60 // glyphs:
61 CPPUNIT_ASSERT(!aUrl.isEmpty());
62 #endif
63 }
64
65 CPPUNIT_TEST_FIXTURE(Test, testFontFamily)
66 {
67 // Given a document with 2 paragraphs, first is sans, second is serif:
68 // When loading that document:
69 loadFromFile(u"font-family.docx");
70
71 // Then make sure we import <w:family w:val="...">:
72 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
73 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
74 uno::UNO_QUERY);
75 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
76 // First paragraph: sans.
77 uno::Reference<container::XEnumerationAccess> xPortionEnumAccess(xParaEnum->nextElement(),
78 uno::UNO_QUERY);
79 uno::Reference<container::XEnumeration> xPortionEnum = xPortionEnumAccess->createEnumeration();
80 uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY);
81 sal_Int16 nFontFamily = awt::FontFamily::DONTKNOW;
82 xPortion->getPropertyValue(u"CharFontFamily"_ustr) >>= nFontFamily;
83 // Without the accompanying fix in place, this test would have failed with:
84 // - Expected: 5 (SWISS)
85 // - Actual : 3 (ROMAN)
86 // i.e. the font family was not imported, all font family was roman.
87 CPPUNIT_ASSERT_EQUAL(awt::FontFamily::SWISS, nFontFamily);
88 // Second paragraph: serif.
89 xPortionEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
90 xPortionEnum = xPortionEnumAccess->createEnumeration();
91 xPortion.set(xPortionEnum->nextElement(), uno::UNO_QUERY);
92 nFontFamily = awt::FontFamily::DONTKNOW;
93 xPortion->getPropertyValue(u"CharFontFamily"_ustr) >>= nFontFamily;
94 CPPUNIT_ASSERT_EQUAL(awt::FontFamily::ROMAN, nFontFamily);
95 }
96 }
97
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */