lxgui
Loading...
Searching...
No Matches
gui_gl_font.hpp
1#ifndef LXGUI_GUI_GL_FONT_HPP
2#define LXGUI_GUI_GL_FONT_HPP
3
4#include "lxgui/gui_font.hpp"
5#include "lxgui/impl/gui_gl_material.hpp"
6#include "lxgui/utils.hpp"
7
8#include <ft2build.h>
9#include <vector>
10#include FT_FREETYPE_H
11
12namespace lxgui::gui::gl {
13
20class font final : public gui::font {
21public:
31 const std::string& font_file,
32 std::size_t size,
33 std::size_t outline,
34 const std::vector<code_point_range>& code_points,
35 char32_t default_code_point);
36
38 ~font() override;
39
44 std::size_t get_size() const override;
45
53 bounds2f get_character_uvs(char32_t c) const override;
54
60 bounds2f get_character_bounds(char32_t c) const override;
61
67 float get_character_width(char32_t c) const override;
68
74 float get_character_height(char32_t c) const override;
75
86 float get_character_kerning(char32_t c1, char32_t c2) const override;
87
92 std::weak_ptr<gui::material> get_texture() const override;
93
98 void update_texture(std::shared_ptr<gui::material> mat) override;
99
100private:
101 struct character_info {
102 char32_t code_point = 0;
103 bounds2f uvs;
104 bounds2f rect;
105 float advance = 0.0f;
106 };
107
108 struct range_info {
109 code_point_range range;
110 std::vector<character_info> data;
111 };
112
113 const character_info* get_character_(char32_t c) const;
114
115 FT_Face face_ = nullptr;
116 std::size_t size_ = 0u;
117 bool kerning_ = false;
118 char32_t default_code_point_ = 0u;
119
120 std::shared_ptr<gl::material> texture_;
121 std::vector<range_info> range_list_;
122};
123
124} // namespace lxgui::gui::gl
125
126#endif
A texture containing characters.
Definition gui_font.hpp:22
A texture containing characters This is the OpenGL implementation of the gui::font....
float get_character_width(char32_t c) const override
Returns the width of a character in pixels.
std::weak_ptr< gui::material > get_texture() const override
Returns the underlying material to use for rendering.
bounds2f get_character_uvs(char32_t c) const override
Returns the uv coordinates of a character on the texture.
font(const std::string &font_file, std::size_t size, std::size_t outline, const std::vector< code_point_range > &code_points, char32_t default_code_point)
Constructor.
void update_texture(std::shared_ptr< gui::material > mat) override
Update the material to use for rendering.
float get_character_kerning(char32_t c1, char32_t c2) const override
Return the kerning amount between two characters.
float get_character_height(char32_t c) const override
Returns the height of a character in pixels.
std::size_t get_size() const override
Get the size of the font in pixels.
bounds2f get_character_bounds(char32_t c) const override
Returns the rect coordinates of a character as it should be drawn relative to the baseline.
~font() override
Destructor.
Represents a contiguous range of unicode code points.