Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/font/PhysicalFontCollection.hxx
Line
Count
Source
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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <sal/config.h>
23
24
#include <vcl/dllapi.h>
25
26
#include <font/LogicalFontInstance.hxx>
27
28
#include "PhysicalFontFamily.hxx"
29
30
#include <array>
31
#include <string_view>
32
33
0
#define MAX_GLYPHFALLBACK 16
34
35
namespace vcl::font
36
{
37
class GlyphFallbackFontSubstitution;
38
class PreMatchFontSubstitution;
39
}
40
41
// TODO: merge with ImplFontCache
42
// TODO: rename to LogicalFontManager
43
44
namespace vcl::font
45
{
46
47
class VCL_PLUGIN_PUBLIC PhysicalFontCollection final
48
{
49
public:
50
    typedef std::unordered_map<OUString, OUString> FontFamilyAliases;
51
52
    explicit                PhysicalFontCollection();
53
                            ~PhysicalFontCollection();
54
55
    // fill the list with device font faces
56
    void                    Add( vcl::font::PhysicalFontFace* );
57
    SAL_DLLPRIVATE void     Clear();
58
35.2M
    int                     Count() const { return maPhysicalFontFamilies.size(); }
59
60
    // find the device font family
61
    vcl::font::PhysicalFontFamily* FindFontFamily( std::u16string_view rFontName ) const;
62
    std::tuple<vcl::font::PhysicalFontFamily*, bool> FindOrCreateFontFamily( const OUString &rFamilyName );
63
    SAL_DLLPRIVATE vcl::font::PhysicalFontFamily* FindFontFamily( vcl::font::FontSelectPattern& ) const;
64
    vcl::font::PhysicalFontFamily* FindFontFamilyByTokenNames(std::u16string_view rTokenStr) const;
65
    vcl::font::PhysicalFontFamily* FindFontFamilyByAttributes(ImplFontAttrs nSearchType, FontWeight, FontWidth,
66
                                             FontItalic, std::u16string_view rSearchFamily) const;
67
    void AddFontFamilyAlias(const OUString& rAlias, const OUString& rFamilyName);
68
    const FontFamilyAliases& GetFontFamilyNameAliases() const;
69
70
    // suggest fonts for glyph fallback
71
    SAL_DLLPRIVATE vcl::font::PhysicalFontFamily* GetGlyphFallbackFont( vcl::font::FontSelectPattern&,
72
                                                  LogicalFontInstance* pLogicalFont,
73
                                                  OUString& rMissingCodes, int nFallbackLevel ) const;
74
75
    // prepare platform specific font substitutions
76
    SAL_DLLPRIVATE void SetPreMatchHook( vcl::font::PreMatchFontSubstitution* );
77
    void SetFallbackHook( vcl::font::GlyphFallbackFontSubstitution* );
78
79
    // misc utilities
80
    SAL_DLLPRIVATE std::shared_ptr<PhysicalFontCollection> Clone() const;
81
    SAL_DLLPRIVATE std::unique_ptr<vcl::font::PhysicalFontFaceCollection> GetFontFaceCollection() const;
82
83
private:
84
    mutable bool            mbMatchData;    // true if matching attributes are initialized
85
86
    typedef std::unordered_map<OUString, std::unique_ptr<vcl::font::PhysicalFontFamily>> PhysicalFontFamilies;
87
    PhysicalFontFamilies    maPhysicalFontFamilies;
88
89
    FontFamilyAliases maFontLookupAliases; // maps normalized localized names
90
    FontFamilyAliases maFontFamilyNameAliases; // maps verbatim localized names
91
92
    vcl::font::PreMatchFontSubstitution* mpPreMatchHook;       // device specific prematch substitution
93
    vcl::font::GlyphFallbackFontSubstitution* mpFallbackHook;  // device specific glyph fallback substitution
94
95
    mutable std::unique_ptr<std::array<vcl::font::PhysicalFontFamily*,MAX_GLYPHFALLBACK>> mpFallbackList;
96
    mutable int             mnFallbackCount;
97
98
    SAL_DLLPRIVATE void ImplInitMatchData() const;
99
    SAL_DLLPRIVATE void ImplInitGenericGlyphFallback() const;
100
101
    SAL_DLLPRIVATE vcl::font::PhysicalFontFamily* ImplFindFontFamilyBySearchName( const OUString& ) const;
102
    SAL_DLLPRIVATE vcl::font::PhysicalFontFamily* ImplFindFontFamilyBySubstFontAttr( const utl::FontNameAttr& ) const;
103
104
    SAL_DLLPRIVATE vcl::font::PhysicalFontFamily* ImplFindFontFamilyOfDefaultFont() const;
105
106
};
107
108
}
109
110
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */