Antkeeper  0.0.1
ft-typeface.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code 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  * Antkeeper source code 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 Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_TYPE_FT_TYPEFACE_HPP
21 #define ANTKEEPER_TYPE_FT_TYPEFACE_HPP
22 
23 #include <engine/type/typeface.hpp>
24 #include <ft2build.h>
25 #include FT_FREETYPE_H
26 #include <vector>
27 #include <memory>
28 
29 namespace type {
30 
36 class ft_typeface: public typeface
37 {
38 public:
46  ft_typeface(FT_Library library, FT_Face face, std::unique_ptr<std::vector<FT_Byte>> file_buffer);
47 
49  virtual ~ft_typeface();
50 
51  virtual bool has_kerning() const;
52  virtual bool get_metrics(float height, font_metrics& metrics) const;
53  virtual bool get_metrics(float height, char32_t code, glyph_metrics& metrics) const;
54  virtual bool get_bitmap(float height, char32_t code, std::vector<std::byte>& bitmap, std::uint32_t& bitmap_width, std::uint32_t& bitmap_height) const;
55  virtual bool get_kerning(float height, char32_t first, char32_t second, math::fvec2& offset) const;
56 
57 private:
58  void set_face_pixel_size(float height) const;
59 
60  FT_Library library;
61  FT_Face face;
62  std::unique_ptr<std::vector<FT_Byte>> file_buffer;
63  mutable float height;
64 };
65 
66 } // namespace type
67 
68 #endif // ANTKEEPER_TYPE_FT_TYPEFACE_HPP
Typeface implementation using the FreeType library.
Definition: ft-typeface.hpp:37
virtual ~ft_typeface()
Destroys a FreeType typeface.
Definition: ft-typeface.cpp:42
ft_typeface(FT_Library library, FT_Face face, std::unique_ptr< std::vector< FT_Byte >> file_buffer)
Creates a FreeType typeface.
Definition: ft-typeface.cpp:26
virtual bool get_metrics(float height, font_metrics &metrics) const
Gets metrics for a font of the specified size.
Definition: ft-typeface.cpp:53
virtual bool get_kerning(float height, char32_t first, char32_t second, math::fvec2 &offset) const
Gets the kerning offset for a pair of glyphs.
virtual bool has_kerning() const
Returns true if the typeface contains kerning information, false otherwise.
Definition: ft-typeface.cpp:48
virtual bool get_bitmap(float height, char32_t code, std::vector< std::byte > &bitmap, std::uint32_t &bitmap_width, std::uint32_t &bitmap_height) const
Gets a bitmap of a glyph in a font of the specified size.
Definition: ft-typeface.cpp:99
Abstract base class for a typeface, which corresponds to a single digital font file.
Definition: typeface.hpp:50
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38
Text and typography.
Definition: bitmap-font.cpp:24
n-dimensional vector.
Definition: vector.hpp:44
Metrics describing properties of a font.
Metrics describing properties of a glyph.