neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_font_manager.hpp
Go to the documentation of this file.
1// i_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 <neolib/core/jar.hpp>
28
29namespace neogfx
30{
31 class i_native_font;
32 class i_native_font_face;
33
34 class i_texture_atlas;
35 class i_emoji_atlas;
36
37 enum class system_font_role : uint32_t
38 {
39 Caption,
40 Menu,
41 Toolbar,
43 Widget
44 };
45
47 {
48 public:
49 struct no_fallback : std::logic_error { no_fallback() : std::logic_error("neogfx::i_fallback_font_info::no_fallback") {} };
50 public:
51 virtual bool has_fallback_for(i_string const& aFontFamilyName) const = 0;
52 virtual i_string const& fallback_for(i_string const& aFontFamilyName) const = 0;
53 };
54
56 {
57 friend class native_font;
58 public:
59 struct bad_font_family_index : std::logic_error { bad_font_family_index() : std::logic_error("neogfx::i_font_manager::bad_font_family_index") {} };
60 struct bad_font_style_index : std::logic_error { bad_font_style_index() : std::logic_error("neogfx::i_font_manager::bad_font_style_index") {} };
61 struct no_fallback_font : std::logic_error { no_fallback_font() : std::logic_error("neogfx::i_font_manager::no_fallback_font") {} };
62 public:
63 virtual ~i_font_manager() = default;
64 public:
65 virtual void* font_library_handle() const = 0;
68 virtual i_native_font_face& create_default_font(const i_device_resolution& aDevice) = 0;
69 virtual bool has_fallback_font(i_native_font_face const& aExistingFont) const = 0;
70 virtual i_native_font_face& create_fallback_font(i_native_font_face const& aExistingFont) = 0;
71 virtual i_native_font_face& create_font(i_string const& aFamilyName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) = 0;
72 virtual i_native_font_face& create_font(i_string const& aFamilyName, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) = 0;
73 virtual i_native_font_face& create_font(const font_info& aInfo, const i_device_resolution& aDevice) = 0;
74 virtual i_native_font_face& create_font(i_native_font& aFont, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution& aDevice) = 0;
75 virtual i_native_font_face& create_font(i_native_font& aFont, i_string const& aStyleName, font::point_size aSize, const i_device_resolution& aDevice) = 0;
76 virtual bool is_font_file(i_string const& aFileName) const = 0;
77 virtual i_native_font_face& load_font_from_file(i_string const& aFileName, i_device_resolution const& aDevice) = 0;
78 virtual 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) = 0;
79 virtual 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) = 0;
80 virtual i_native_font_face& load_font_from_memory(const void* aData, std::size_t aSizeInBytes, i_device_resolution const& aDevice) = 0;
81 virtual 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) = 0;
82 virtual 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) = 0;
83 public:
84 virtual uint32_t font_family_count() const = 0;
85 virtual i_string const& font_family(uint32_t aFamilyIndex) const = 0;
86 virtual uint32_t font_style_count(uint32_t aFamilyIndex) const = 0;
87 virtual neogfx::font_style font_style(uint32_t aFamilyIndex, uint32_t aStyleIndex) const = 0;
88 virtual i_string const& font_style_name(uint32_t aFamilyIndex, uint32_t aStyleIndex) const = 0;
89 private:
90 virtual font_id allocate_font_id() = 0;
91 public:
92 virtual const font& font_from_id(font_id aId) const = 0;
93 public:
95 public:
96 virtual const i_texture_atlas& glyph_atlas() const = 0;
98 virtual const i_emoji_atlas& emoji_atlas() const = 0;
99 virtual i_emoji_atlas& emoji_atlas() = 0;
100 public:
101 bool has_font(std::string const& aFamily, std::string const& aStyle) const
102 {
103 for (uint32_t familyIndex = 0; familyIndex < font_family_count(); ++familyIndex)
104 if (font_family(familyIndex).to_std_string_view() == aFamily)
105 {
106 for (uint32_t styleIndex = 0; styleIndex < font_style_count(familyIndex); ++styleIndex)
107 if (font_style_name(familyIndex, styleIndex).to_std_string_view() == aStyle)
108 return true;
109 return false;
110 }
111 return false;
112 }
113 public:
114 static uuid const& iid() { static uuid const sIid{ 0x83bbaf78, 0x66a8, 0x4862, 0x9221, { 0x4c, 0xfd, 0x93, 0xfb, 0xf3, 0xe7 } }; return sIid; }
115 };
116}
virtual bool has_fallback_for(i_string const &aFontFamilyName) const =0
virtual i_string const & fallback_for(i_string const &aFontFamilyName) const =0
virtual i_native_font_face & create_font(i_native_font &aFont, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice)=0
virtual const i_fallback_font_info & default_fallback_font_info() const =0
virtual bool is_font_file(i_string const &aFileName) const =0
virtual i_glyph_text_factory & glyph_text_factory() const =0
virtual i_native_font_face & load_font_from_memory(const void *aData, std::size_t aSizeInBytes, i_device_resolution const &aDevice)=0
virtual neogfx::font_style font_style(uint32_t aFamilyIndex, uint32_t aStyleIndex) const =0
virtual ~i_font_manager()=default
virtual void * font_library_handle() const =0
virtual uint32_t font_family_count() const =0
virtual i_string const & font_style_name(uint32_t aFamilyIndex, uint32_t aStyleIndex) const =0
virtual i_string const & font_family(uint32_t aFamilyIndex) const =0
virtual 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)=0
virtual i_native_font_face & create_default_font(const i_device_resolution &aDevice)=0
static uuid const & iid()
virtual i_optional< font_info > const & default_system_font_info(system_font_role aRole) const =0
virtual i_native_font_face & create_font(i_string const &aFamilyName, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice)=0
virtual i_native_font_face & create_font(const font_info &aInfo, const i_device_resolution &aDevice)=0
bool has_font(std::string const &aFamily, std::string const &aStyle) const
virtual bool has_fallback_font(i_native_font_face const &aExistingFont) const =0
virtual i_native_font_face & create_font(i_string const &aFamilyName, i_string const &aStyleName, font::point_size aSize, const i_device_resolution &aDevice)=0
virtual uint32_t font_style_count(uint32_t aFamilyIndex) const =0
virtual 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)=0
virtual i_texture_atlas & glyph_atlas()=0
virtual const i_emoji_atlas & emoji_atlas() const =0
virtual 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)=0
virtual const font & font_from_id(font_id aId) const =0
virtual const i_texture_atlas & glyph_atlas() const =0
virtual i_native_font_face & load_font_from_file(i_string const &aFileName, i_device_resolution const &aDevice)=0
virtual 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)=0
virtual i_native_font_face & create_fallback_font(i_native_font_face const &aExistingFont)=0
virtual i_native_font_face & create_font(i_native_font &aFont, neogfx::font_style aStyle, font::point_size aSize, const i_device_resolution &aDevice)=0
virtual i_emoji_atlas & emoji_atlas()=0
std::string_view to_std_string_view() const noexcept
Definition i_string.hpp:76
font_style
Definition font.hpp:35