Antkeeper  0.0.1
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_TYPEFACE_HPP
21 #define ANTKEEPER_TYPE_TYPEFACE_HPP
22 
25 #include <engine/math/vector.hpp>
26 #include <vector>
27 #include <unordered_set>
28 
29 namespace type {
30 
32 enum class typeface_style
33 {
35  normal,
36 
38  italic,
39 
41  oblique
42 };
43 
49 class typeface
50 {
51 public:
58  typeface(typeface_style style, int weight);
59 
61  typeface();
62 
64  virtual ~typeface() = default;
65 
71  void set_style(typeface_style style);
72 
78  void set_weight(int weight);
79 
81  [[nodiscard]] inline typeface_style get_style() const noexcept
82  {
83  return style;
84  }
85 
87  [[nodiscard]] inline int get_weight() const noexcept
88  {
89  return weight;
90  }
91 
93  virtual bool has_kerning() const = 0;
94 
102  virtual bool get_metrics(float height, font_metrics& metrics) const = 0;
103 
112  virtual bool get_metrics(float height, char32_t code, glyph_metrics& metrics) const = 0;
113 
122  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 = 0;
123 
133  virtual bool get_kerning(float height, char32_t first, char32_t second, math::fvec2& offset) const = 0;
134 
136  [[nodiscard]] inline const std::unordered_set<char32_t>& get_charset() const noexcept
137  {
138  return charset;
139  }
140 
141 protected:
142  std::unordered_set<char32_t> charset;
143 
144 private:
145  typeface_style style;
146  int weight;
147 };
148 
149 } // namespace type
150 
151 #endif // ANTKEEPER_TYPE_TYPEFACE_HPP
Abstract base class for a typeface, which corresponds to a single digital font file.
Definition: typeface.hpp:50
virtual bool get_metrics(float height, font_metrics &metrics) const =0
Gets metrics for a font of the specified size.
virtual bool get_kerning(float height, char32_t first, char32_t second, math::fvec2 &offset) const =0
Gets the kerning offset for a pair of glyphs.
void set_weight(int weight)
Sets the weight of the typeface.
Definition: typeface.cpp:45
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 =0
Gets a bitmap of a glyph in a font of the specified size.
virtual bool get_metrics(float height, char32_t code, glyph_metrics &metrics) const =0
Gets metrics for a glyph in a font of the specified size.
void set_style(typeface_style style)
Sets the style of the typeface.
Definition: typeface.cpp:40
typeface_style get_style() const noexcept
Returns the style of the typeface.
Definition: typeface.hpp:81
int get_weight() const noexcept
Returns the weight of the typeface.
Definition: typeface.hpp:87
virtual ~typeface()=default
Destroys a typeface.
std::unordered_set< char32_t > charset
Definition: typeface.hpp:142
virtual bool has_kerning() const =0
Returns true if the typeface contains kerning information, false otherwise.
typeface()
Creates an empty typeface.
Definition: typeface.cpp:35
const std::unordered_set< char32_t > & get_charset() const noexcept
Returns the set of characters supported by the typeface.
Definition: typeface.hpp:136
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38
Text and typography.
Definition: bitmap-font.cpp:24
typeface_style
Emumerates typeface styles.
Definition: typeface.hpp:33
@ italic
Italic typeface style.
@ oblique
Oblique typeface style.
@ normal
Normal typeface style.
n-dimensional vector.
Definition: vector.hpp:44
Metrics describing properties of a font.
Metrics describing properties of a glyph.