NAP
glyph.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <nap/numeric.h>
8 #include <rtti/typeinfo.h>
9 #include <utility/errorstate.h>
10 #include <glm/glm.hpp>
11 
12 namespace nap
13 {
14  class FontInstance;
15  class Core;
16 
24  class NAPAPI Glyph final
25  {
26  friend FontInstance;
27  RTTI_ENABLE()
28  public:
29 
30  // Default construction is not allowed
31  Glyph() = delete;
32 
36  ~Glyph();
37 
38  // Copy is not allowed
39  Glyph(const Glyph& other) = delete;
40  Glyph& operator=(const Glyph&) = delete;
41 
42  // Move is not allowed
43  Glyph(Glyph&& other) = delete;
44  Glyph& operator=(Glyph&& other) = delete;
45 
49  uint getIndex() const { return mIndex; }
50 
54  bool isValid();
55 
59  int getHorizontalAdvance() const { return mAdvance.x; }
60 
64  int getVerticalAdvance() const { return mAdvance.y; }
65 
69  inline void* getHandle() const { return mHandle; }
70 
71  protected:
77  Glyph(void* handle, uint index);
78 
79  private:
80  void* mHandle = nullptr;
81  uint mIndex = 0;
82  glm::ivec2 mAdvance = { -1, -1 };
83  };
84 
85 
87  // IGlyphRepresentation
89 
97  class NAPAPI IGlyphRepresentation
98  {
99  friend FontInstance;
100  RTTI_ENABLE()
101  public:
105  virtual ~IGlyphRepresentation() { }
106 
111 
112  // Copy is not allowed
113  IGlyphRepresentation(const IGlyphRepresentation& other) = delete;
114  IGlyphRepresentation& operator=(const IGlyphRepresentation&) = delete;
115 
116  // Move is not allowed
117  IGlyphRepresentation(IGlyphRepresentation&& other) = delete;
118  IGlyphRepresentation& operator=(IGlyphRepresentation&& other) = delete;
119 
120  protected:
128  bool init(const Glyph& glyph, utility::ErrorState& error) { return onInit(glyph, error); }
129 
137  virtual bool onInit(const Glyph& glyph, utility::ErrorState& error) = 0;
138 
140  };
141 }
142 
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::IGlyphRepresentation
Definition: glyph.h:97
nap::Glyph::getHandle
void * getHandle() const
Definition: glyph.h:69
nap::utility::ErrorState
Definition: errorstate.h:19
nap::Glyph::getIndex
uint getIndex() const
Definition: glyph.h:49
nap::IGlyphRepresentation::init
bool init(const Glyph &glyph, utility::ErrorState &error)
Definition: glyph.h:128
nap::Glyph
Definition: glyph.h:24
nap::Core
Definition: core.h:82
nap::Glyph::getHorizontalAdvance
int getHorizontalAdvance() const
Definition: glyph.h:59
nap
Definition: templateapp.h:17
nap::IGlyphRepresentation::mCore
nap::Core * mCore
Handle to core instance.
Definition: glyph.h:139
nap::IGlyphRepresentation::~IGlyphRepresentation
virtual ~IGlyphRepresentation()
Definition: glyph.h:105
nap::Glyph::getVerticalAdvance
int getVerticalAdvance() const
Definition: glyph.h:64
nap::FontInstance
Definition: font.h:121