Antkeeper  0.0.1
font.cpp
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 #include <engine/type/font.hpp>
21 
22 namespace type {
23 
24 font::font(const font_metrics& metrics):
25  metrics(metrics)
26 {}
27 
29 {}
30 
32 {}
33 
34 void font::kern(char32_t first, char32_t second, const math::fvec2& offset)
35 {
36  kerning_table[first][second] = offset;
37 }
38 
40 {
41  this->metrics = metrics;
42 }
43 
44 const math::fvec2& font::get_kerning(char32_t first, char32_t second) const
45 {
46  if (auto it_first = kerning_table.find(first); it_first != kerning_table.end())
47  if (auto it_second = it_first->second.find(second); it_second != it_first->second.end())
48  return it_second->second;
49 
50  static const math::fvec2 no_kerning = {0.0f, 0.0f};
51  return no_kerning;
52 }
53 
54 } // namespace type
const math::fvec2 & get_kerning(char32_t first, char32_t second) const
Returns the kerning offset for a pair of glyphs.
Definition: font.cpp:44
font_metrics metrics
Definition: font.hpp:100
void set_font_metrics(const font_metrics &metrics)
Sets the font metrics.
Definition: font.cpp:39
font()
Creates an empty font.
Definition: font.cpp:28
void kern(char32_t first, char32_t second, const math::fvec2 &offset)
Sets the kerning offset for a pair of glyphs.
Definition: font.cpp:34
virtual ~font()
Destroys a font.
Definition: font.cpp:31
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38
Text and typography.
Definition: bitmap-font.cpp:24
std::unordered_map< char32_t, std::unordered_map< char32_t, math::fvec2 > > kerning_table
Table containing kerning offsets for pairs of glyphs.
n-dimensional vector.
Definition: vector.hpp:44
Metrics describing properties of a font.