FontRegistry.h
1/* Copyright (C) 2024 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 02110-1301 USA
27*/
28
29#ifndef PT_GFX_FONTREGISTRY_H
30#define PT_GFX_FONTREGISTRY_H
31
32#include <Pt/Gfx/Api.h>
33#include <Pt/System/Path.h>
34
35#include <vector>
36
37namespace Pt {
38
39namespace Gfx {
40
41class FontProvider;
42
51class PT_GFX_API FontRegistry
52{
53 friend class FontProvider;
54
55 public:
56 struct Init
57 {
58 Init()
59 { FontRegistry::instance(); }
60 };
61
62 static FontRegistry& instance();
63
64 ~FontRegistry();
65
66 void addFonts(const System::Path& path);
67
68 bool addFont(const System::Path& path);
69
70 bool removeFont(const System::Path& path);
71
72 const std::vector<System::Path>& fontFiles() const;
73
74 private:
75 FontRegistry();
76
77 FontRegistry(const FontRegistry&) = delete;
78
79 FontRegistry& operator=(const FontRegistry&) = delete;
80
81 void registerProvider(FontProvider& provider);
82
83 void unregisterProvider(FontProvider& provider);
84
85 private:
86 std::vector<System::Path> _fontFiles;
87 std::vector<FontProvider*> _providers;
88};
89
90static FontRegistry::Init initFontRegistry;
91
92} // namespace
93
94} // namespace
95
96#endif
Backend that loads font files.
Definition FontProvider.h:53
Represents a path in the file-system.
Definition Path.h:48
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33