| 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 <vcl/font.hxx> |
| 13 |
#include <vcl/vclptr.hxx> |
| 14 |
#include <vcl/wintypes.hxx> |
| 15 |
#include <vcl/window.hxx> |
| 16 |
#include <vcl/glyphitemcache.hxx> |
| 17 |
|
| 18 |
#include <font/FontSelectPattern.hxx> |
| 19 |
#include <unx/fontmanager.hxx> |
| 20 |
|
| 21 |
using namespace ::com::sun::star; |
| 22 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
/// Covers vcl/unx/generic/ fixes. |
| 26 |
class Test : public UnoApiTest |
| 27 |
{ |
| 28 |
public: |
| 29 |
Test() |
| 30 |
: UnoApiTest(u"/vcl/qa/unx/generic/data/"_ustr) |
| 31 |
{ |
| 32 |
} |
| 33 |
static OUString GetFallbackFont(const vcl::Font& rFont) |
| 34 |
{ |
| 35 |
Size aSize(0, 3840); |
| 36 |
float fExactHeight = 3840; |
| 37 |
bool bNonAntialias = false; |
| 38 |
vcl::font::FontSelectPattern aPattern(rFont, rFont.GetFamilyName(), aSize, fExactHeight, |
| 39 |
bNonAntialias); |
| 40 |
aPattern.maTargetName = rFont.GetFamilyName(); |
| 41 |
psp::PrintFontManager& rMgr = psp::PrintFontManager::get(); |
| 42 |
OUString aMissingCodes; |
| 43 |
|
| 44 |
rMgr.Substitute(aPattern, aMissingCodes); |
| 45 |
|
| 46 |
return aPattern.maSearchName; |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
CPPUNIT_TEST_FIXTURE(Test, testFontFallbackSerif) |
| 51 |
{ |
| 52 |
OUString sResolvedSerif = GetFallbackFont(vcl::Font("serif", Size(12, 12))); |
| 53 |
|
| 54 |
// Given a font select pattern with a font name we don't bundle and with a serif family: |
| 55 |
vcl::Font aFont; |
| 56 |
aFont.SetFamilyName("IBM Plex Serif"); |
| 57 |
aFont.SetFamily(FAMILY_ROMAN); |
| 58 |
|
| 59 |
OUString sPlexFallback = GetFallbackFont(aFont); |
| 60 |
|
| 61 |
// Then make sure we get a serif fallback: |
| 62 |
// Without the accompanying fix in place, this test would have failed with: |
| 63 |
// - Expected: Noto Serif (or DejaVu Serif) |
| 64 |
// - Actual : Noto Kufi Arabic |
| 65 |
// i.e. we got a sans fallback for a serif pattern, which is clearly poor. |
| 66 |
CPPUNIT_ASSERT_EQUAL(sResolvedSerif, sPlexFallback); |
| 67 |
} |
| 68 |
|
| 69 |
CPPUNIT_TEST_FIXTURE(Test, testFontFallbackCaching) |
| 70 |
{ |
| 71 |
// Given a vcl-level text layout, created for the serif Verdana: |
| 72 |
ScopedVclPtrInstance<vcl::Window> pWindow(nullptr, WB_APP | WB_STDWORK); |
| 73 |
VclPtr<OutputDevice> pOutDev = pWindow->GetOutDev(); |
| 74 |
vcl::Font aFont; |
| 75 |
aFont.SetFamilyName("Verdana"); |
| 76 |
aFont.SetFamily(FAMILY_ROMAN); |
| 77 |
pOutDev->SetFont(aFont); |
| 78 |
OUString aText = u"1-1-2017"_ustr; |
| 79 |
sal_Int32 nIndex = 0; |
| 80 |
sal_Int32 nLength = aText.getLength(); |
| 81 |
tools::Long nLogicWidth = 0; |
| 82 |
SalLayoutGlyphsCache::CachedGlyphsKey aKey1(pOutDev, aText, nIndex, nLength, nLogicWidth); |
| 83 |
|
| 84 |
// When creating a layout for the sans Verdana: |
| 85 |
aFont.SetFamily(FAMILY_SWISS); |
| 86 |
pOutDev->SetFont(aFont); |
| 87 |
SalLayoutGlyphsCache::CachedGlyphsKey aKey2(pOutDev, aText, nIndex, nLength, nLogicWidth); |
| 88 |
|
| 89 |
// Then make sure these two layouts don't match: |
| 90 |
// Without the accompanying fix in place, this test would have failed, the Noto Serif layout was |
| 91 |
// reused for the Noto Sans layout if those were selected as fallbacks. |
| 92 |
CPPUNIT_ASSERT(aKey1 != aKey2); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 97 |
|
| 98 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |