Font.hpp
1// Copyright 2019 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4
5#ifndef SMK_FONT_HPP
6#define SMK_FONT_HPP
7
8#include <glm/glm.hpp>
9#include <map>
10#include <memory>
11#include <smk/OpenGL.hpp>
12#include <smk/Texture.hpp>
13#include <string>
14#include <vector>
15
16namespace smk {
17
18class Font {
19 public:
20 Font() = default; // Empty font.
21 Font(std::string filename, float line_height);
22
23 float line_height() const { return line_height_; }
24 float baseline_position() const { return baseline_position_; }
25
26 struct Glyph {
27 smk::Texture texture;
28 glm::ivec2 bearing = {0, 0}; // Offset from baseline to left/top of glyph
29 float advance = 0; // Offset to advance to next glyph
30 };
31 Glyph* FetchGlyph(wchar_t in);
32
33 // --- Move only resource ----------------------------------------------------
34 Font(Font&&) = default;
35 Font(const Font&) = delete;
36 Font& operator=(Font&&) noexcept;
37 Font& operator=(const Font&) = delete;
38 // ---------------------------------------------------------------------------
39
40 private:
41 void LoadGlyphs(const std::vector<wchar_t>& chars);
42
43 std::map<wchar_t, std::unique_ptr<Glyph>> glyphs_;
44 std::string filename_;
45 float line_height_ = 0.f;
46 float baseline_position_ = 0.f;
47};
48
49} // namespace smk
50
51#endif /* end of include guard: SMK_FONT_HPP */