neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
font_manager.hpp
Go to the documentation of this file.
1// font_manager.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <unordered_map>
24#include <set>
25#include <neolib/core/jar.hpp>
30
31typedef struct FT_LibraryRec_* FT_Library;
32
33namespace neogfx
34{
35 class native_font;
36
38 {
39 public:
40 fallback_font_info(std::vector<string> aFallbackFontFamilies);
41 public:
42 bool has_fallback_for(i_string const& aFontFamilyName) const override;
43 i_string const& fallback_for(i_string const& aFontFamilyName) const override;
44 private:
45 std::vector<string> iFallbackFontFamilies;
46 };
47
49 {
50 friend class native_font_face;
51 private:
52 typedef std::list<native_font> native_font_list;
53 typedef std::map<string, std::vector<native_font_list::iterator>, neolib::ci_less> font_family_list;
54 typedef font id_cache_entry;
55 typedef neolib::small_jar<id_cache_entry> id_cache;
56 friend neolib::small_cookie item_cookie(const id_cache_entry&);
57 public:
58 struct error_initializing_font_library : std::runtime_error { error_initializing_font_library() : std::runtime_error("neogfx::font_manager::error_initializing_font_library") {} };
59 struct no_matching_font_found : std::runtime_error { no_matching_font_found() : std::runtime_error("neogfx::font_manager::no_matching_font_found") {} };
60 struct failed_to_allocate_glyph_space : std::runtime_error { failed_to_allocate_glyph_space() : std::runtime_error("neogfx::font_manager::failed_to_allocate_glyph_space") {} };
61 public:
64 public:
65 void* font_library_handle() const override;
68 i_native_font_face& create_default_font(const i_device_resolution& aDevice) override;
69 bool has_fallback_font(const i_native_font_face& aExistingFont) const override;
70 i_native_font_face& create_fallback_font(const i_native_font_face& aExistingFont) override;
71 i_native_font_face& create_font(i_string const& aFamilyName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) override;
72 i_native_font_face& create_font(i_string const& aFamilyName, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) override;
73 i_native_font_face& create_font(const font_info& aInfo, const i_device_resolution& aDevice) override;
74 i_native_font_face& create_font(i_native_font& aFont, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) override;
75 i_native_font_face& create_font(i_native_font& aFont, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) override;
76 bool is_font_file(i_string const& aFileName) const override;
77 i_native_font_face& load_font_from_file(i_string const& aFileName, const i_device_resolution& aDevice) override;
78 i_native_font_face& load_font_from_file(i_string const& aFileName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) override;
79 i_native_font_face& load_font_from_file(i_string const& aFileName, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) override;
80 i_native_font_face& load_font_from_memory(const void* aData, std::size_t aSizeInBytes, const i_device_resolution& aDevice) override;
81 i_native_font_face& load_font_from_memory(const void* aData, std::size_t aSizeInBytes, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) override;
82 i_native_font_face& load_font_from_memory(const void* aData, std::size_t aSizeInBytes, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) override;
83 public:
84 uint32_t font_family_count() const override;
85 i_string const& font_family(uint32_t aFamilyIndex) const override;
86 uint32_t font_style_count(uint32_t aFamilyIndex) const override;
87 neogfx::font_style font_style(uint32_t aFamilyIndex, uint32_t aStyleIndex) const override;
88 i_string const& font_style_name(uint32_t aFamilyIndex, uint32_t aStyleIndex) const override;
89 private:
90 font_id allocate_font_id() override;
91 public:
92 const font& font_from_id(font_id aId) const override;
93 public:
95 public:
96 const i_texture_atlas& glyph_atlas() const override;
98 const i_emoji_atlas& emoji_atlas() const override;
100 protected:
101 void add_ref(font_id aId) override;
102 void release(font_id aId) override;
103 long use_count(font_id aId) const override;
104 private:
105 i_native_font& find_font(i_string const& aFamilyName, i_string const& aStyleName, font::point_size aSize);
106 i_native_font& find_best_font(i_string const& aFamilyName, neogfx::font_style aStyle, font::point_size aSize);
107 private:
108 i_native_font_face& add_font(const ref_ptr<i_native_font_face>& aNewFont);
109 void cleanup();
110 private:
111 mutable std::unordered_map<system_font_role, optional<font_info>> iDefaultSystemFontInfo;
112 mutable std::optional<fallback_font_info> iDefaultFallbackFontInfo;
113 FT_Library iFontLib;
114 native_font_list iNativeFonts;
115 font_family_list iFontFamilies;
116 private:
117 id_cache iIdCache;
118 std::unique_ptr<i_glyph_text_factory> iGlyphTextFactory;
119 texture_atlas iGlyphAtlas;
120 neogfx::emoji_atlas iEmojiAtlas;
121 };
122}
bool has_fallback_for(i_string const &aFontFamilyName) const override
fallback_font_info(std::vector< string > aFallbackFontFamilies)
i_string const & fallback_for(i_string const &aFontFamilyName) const override
i_texture_atlas & glyph_atlas() override
bool is_font_file(i_string const &aFileName) const override
i_native_font_face & create_fallback_font(const i_native_font_face &aExistingFont) override
i_native_font_face & load_font_from_memory(const void *aData, std::size_t aSizeInBytes, const i_device_resolution &aDevice) override
i_string const & font_family(uint32_t aFamilyIndex) const override
neogfx::font_style font_style(uint32_t aFamilyIndex, uint32_t aStyleIndex) const override
i_native_font_face & create_font(i_native_font &aFont, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice) override
const i_emoji_atlas & emoji_atlas() const override
uint32_t font_family_count() const override
friend class native_font_face
bool has_fallback_font(const i_native_font_face &aExistingFont) const override
i_emoji_atlas & emoji_atlas() override
void add_ref(font_id aId) override
i_string const & font_style_name(uint32_t aFamilyIndex, uint32_t aStyleIndex) const override
const font & font_from_id(font_id aId) const override
i_glyph_text_factory & glyph_text_factory() const override
i_native_font_face & load_font_from_memory(const void *aData, std::size_t aSizeInBytes, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice) override
const i_fallback_font_info & default_fallback_font_info() const override
i_native_font_face & load_font_from_file(i_string const &aFileName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice) override
void * font_library_handle() const override
uint32_t font_style_count(uint32_t aFamilyIndex) const override
i_native_font_face & create_default_font(const i_device_resolution &aDevice) override
i_native_font_face & create_font(i_string const &aFamilyName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice) override
i_optional< font_info > const & default_system_font_info(system_font_role aRole) const override
i_native_font_face & create_font(i_string const &aFamilyName, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice) override
const i_texture_atlas & glyph_atlas() const override
void release(font_id aId) override
i_native_font_face & create_font(i_native_font &aFont, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice) override
i_native_font_face & load_font_from_file(i_string const &aFileName, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice) override
i_native_font_face & load_font_from_memory(const void *aData, std::size_t aSizeInBytes, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice) override
long use_count(font_id aId) const override
friend neolib::small_cookie item_cookie(const id_cache_entry &)
i_native_font_face & create_font(const font_info &aInfo, const i_device_resolution &aDevice) override
i_native_font_face & load_font_from_file(i_string const &aFileName, const i_device_resolution &aDevice) override
struct FT_LibraryRec_ * FT_Library
font_style
Definition font.hpp:35
uint16_t small_cookie
Definition i_jar.hpp:45
basic_jar< T, vector< T >, small_cookie, MutexType > small_jar
Definition jar.hpp:738