Font.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "../Rendering/Texture.hpp"
5 #include <unordered_map>
6 
7 namespace iv
8 {
9 
12 class Font
13 {
14 public:
16 
17  enum class Type
18  {
19  Hinted,
20  Msdf,
21  };
22 
23  struct Info
24  {
25  float line_height;
26  float ascender;
27  float descender;
28  float max_advance;
29 
30  std::unordered_map< uint32_t, float > advances;
31  std::unordered_map< uint32_t, float > widths;
32 
33  Info() : line_height( 0 ), ascender( 0 ), descender( 0 ), max_advance( 0 ){}
34  };
35 
36  struct Glyph
37  {
38  uint32_t code;
39  unsigned pos_x;
40  unsigned pos_y;
41  unsigned width;
42  unsigned height;
43  float bearing_x;
44  float bearing_y;
45 
46  Glyph() : code( 0 ){}
47  };
48 
49  struct Variant
50  {
51  Texture const * texture;
53  unsigned size;
54 
55  std::unordered_map< uint32_t, Glyph > glyphs;
56 
57  Variant() : texture( nullptr ), type( Type::Hinted ){}
58  };
59 
60  Font( Instance * inst );
61  Instance * instance() const;
62 
65  Info const & GetInfo() const;
66 
70  Variant const & SelectVariant( unsigned font_size ) const;
71 
74  Variant const & SelectVariantMsdf() const;
75 
76 protected:
78  std::unordered_map< unsigned, Variant > _variant_fixed;
80 
81 private:
82  Instance * inst;
83 };
84 
85 
86 class Font_Resource : public SingularResource< Font >
87 {
88 public:
91  SingularResource< Font >( inst, path ),
92  cm( inst, this, "Font_Resource" )
93  {
94  this->cm.inherits( this->SingularResource< Font >::cm );
95  }
96 };
97 
98 
99 }