Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Font.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Font_INCLUDE_ONCE
33 #define Font_INCLUDE_ONCE
34 
36 #include <vlCore/Object.hpp>
37 #include <vlCore/Vector4.hpp>
38 #include <vlCore/String.hpp>
39 #include <map>
40 
41 //-----------------------------------------------------------------------------
42 struct FT_FaceRec_;
43 typedef struct FT_FaceRec_* FT_Face;
44 //-----------------------------------------------------------------------------
45 namespace vl
46 {
47  class Font;
48  class FontManager;
49  //-----------------------------------------------------------------------------
50  // Glyph
51  //-----------------------------------------------------------------------------
55  class Glyph: public Object
56  {
58 
59  private:
60  Glyph(const Glyph& other): Object(other)
61  {
62  VL_DEBUG_SET_OBJECT_NAME()
63  }
64  void operator=(const Glyph&){}
65 
66  public:
67  Glyph(): mFont(NULL), mS0(0), mT0(0), mS1(0), mT1(0), mGlyphIndex(0), mTextureHandle(0), mWidth(0), mHeight(0), mLeft(0), mTop(0) {}
68 
69  ~Glyph();
70 
71  unsigned int textureHandle() const { return mTextureHandle; }
72  void setTextureHandle(unsigned int handle) { mTextureHandle = handle; }
73 
74  int width() const { return mWidth; }
75  void setWidth(int width) { mWidth = width; }
76 
77  int height() const { return mHeight; }
78  void setHeight(int height) { mHeight = height; }
79 
80  int left() const { return mLeft; }
81  void setLeft(int left) { mLeft = left; }
82 
83  int top() const { return mTop; }
84  void setTop(int top) { mTop = top; }
85 
86  float s0() const { return mS0; }
87  void setS0(float s0) { mS0 = s0; }
88 
89  float t0() const { return mT0; }
90  void setT0(float t0) { mT0 = t0; }
91 
92  float s1() const { return mS1; }
93  void setS1(float s1) { mS1 = s1; }
94 
95  float t1() const { return mT1; }
96  void setT1(float t1) { mT1 = t1; }
97 
98  const fvec2& advance() const { return mAdvance; }
99  void setAdvance(const fvec2& advance) { mAdvance = advance; }
100 
101  unsigned int glyphIndex() const { return mGlyphIndex; }
102  void setGlyphIndex(unsigned int glyph_index) { mGlyphIndex = glyph_index; }
103 
104  const Font* font() const { return mFont; }
105  void setFont(Font* font) { mFont = font; }
106 
107  protected:
110  float mS0;
111  float mT0;
112  float mS1;
113  float mT1;
114  unsigned int mGlyphIndex;
115  unsigned int mTextureHandle;
116  int mWidth;
117  int mHeight;
118  int mLeft;
119  int mTop;
120  };
121  //-----------------------------------------------------------------------------
122  // Font
123  //-----------------------------------------------------------------------------
128  {
130 
131  friend class CoreText;
132  friend class Text;
133  friend class FontManager;
134 
136  void operator=(const Font&) { VL_TRAP() } // should never get used
137 
139  Font(const Font& other): Object(other) { VL_TRAP() } // should never get used
140 
142  Font(FontManager* fm = NULL);
143 
145  Font(FontManager* fm, const String& font_file, int size );
146 
147  public:
149  ~Font();
150 
152  bool operator<(const Font& other) const
153  {
154  if (filePath() != other.filePath())
155  return filePath() < other.filePath();
156  else
157  return size() < other.size();
158  }
159 
161  const String& filePath() const { return mFilePath; }
162 
164  void loadFont(const String& path);
165 
167  int size() const { return mSize; }
168 
170  void setSize(int size);
171 
173  Glyph* glyph(int character);
174 
176  void setSmooth(bool smooth);
177 
179  bool smooth() const { return mSmooth; }
180 
182  void releaseFreeTypeData();
183 
185  void setFontManager(FontManager* fm) { mFontManager = fm; }
186 
188  const FontManager* fontManager() const { return mFontManager; }
189 
191  FontManager* fontManager() { return mFontManager; }
192 
195  bool freeTypeLoadForceAutoHint() const { return mFreeTypeLoadForceAutoHint; }
196 
199  void setFreeTypLoadForceAutoHint(bool enable) { mFreeTypeLoadForceAutoHint = enable; }
200 
201  protected:
204  std::map< int, ref<Glyph> > mGlyphMap;
206  std::vector<char> mMemoryFile;
207  int mSize;
208  float mHeight;
209  bool mSmooth;
211  };
212  //-----------------------------------------------------------------------------
213 }
214 
215 #endif
void setS1(float s1)
Definition: Font.hpp:93
void setFreeTypLoadForceAutoHint(bool enable)
Whether FT_Load_Char() should be called with FT_LOAD_FORCE_AUTOHINT (default) or FT_LOAD_DEFAULT.
Definition: Font.hpp:199
The FontManager class keeps a map associating a font path, size and smoothing flag to a Font object...
Definition: FontManager.hpp:45
float s0() const
Definition: Font.hpp:86
Experimental.
Definition: CoreText.hpp:47
void setGlyphIndex(unsigned int glyph_index)
Definition: Font.hpp:102
int left() const
Definition: Font.hpp:80
void setFontManager(FontManager *fm)
The FontManager associated to this Font used to acquire/release FreeType resources.
Definition: Font.hpp:185
std::map< int, ref< Glyph > > mGlyphMap
Definition: Font.hpp:204
A Renderable that renders text with a given Font.
Definition: Text.hpp:50
fvec2 mAdvance
Definition: Font.hpp:109
int width() const
Definition: Font.hpp:74
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
A font to be used with a Text renderable.
Definition: Font.hpp:127
int top() const
Definition: Font.hpp:83
The Glyph associated to a character of a given Font.
Definition: Font.hpp:55
Object()
Constructor.
Definition: Object.hpp:164
float mT1
Definition: Font.hpp:113
void setFont(Font *font)
Definition: Font.hpp:105
String mFilePath
Definition: Font.hpp:203
unsigned int textureHandle() const
Definition: Font.hpp:71
Glyph()
Definition: Font.hpp:67
void setTop(int top)
Definition: Font.hpp:84
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
bool mFreeTypeLoadForceAutoHint
Definition: Font.hpp:210
bool mSmooth
Definition: Font.hpp:209
Visualization Library main namespace.
int size() const
The size of the font.
Definition: Font.hpp:167
FontManager * mFontManager
Definition: Font.hpp:202
void setT0(float t0)
Definition: Font.hpp:90
const fvec2 & advance() const
Definition: Font.hpp:98
float mHeight
Definition: Font.hpp:208
int mTop
Definition: Font.hpp:119
#define VL_TRAP()
Definition: checks.hpp:70
void setTextureHandle(unsigned int handle)
Definition: Font.hpp:72
float t0() const
Definition: Font.hpp:89
The base class for all the reference counted objects.
Definition: Object.hpp:158
void setS0(float s0)
Definition: Font.hpp:87
int height() const
Definition: Font.hpp:77
int mLeft
Definition: Font.hpp:118
void setHeight(int height)
Definition: Font.hpp:78
bool freeTypeLoadForceAutoHint() const
Whether FT_Load_Char() should be called with FT_LOAD_FORCE_AUTOHINT (default) or FT_LOAD_DEFAULT.
Definition: Font.hpp:195
const String & filePath() const
The font&#39;s file path.
Definition: Font.hpp:161
int mWidth
Definition: Font.hpp:116
bool operator<(const Font &other) const
Less-than operator.
Definition: Font.hpp:152
unsigned int glyphIndex() const
Definition: Font.hpp:101
const FontManager * fontManager() const
The FontManager associated to this Font used to acquire/release FreeType resources.
Definition: Font.hpp:188
#define NULL
Definition: OpenGLDefs.hpp:81
unsigned int mTextureHandle
Definition: Font.hpp:115
unsigned int mGlyphIndex
Definition: Font.hpp:114
void setLeft(int left)
Definition: Font.hpp:81
float mS1
Definition: Font.hpp:112
bool smooth() const
Whether the font rendering should use linear filtering or not.
Definition: Font.hpp:179
void setWidth(int width)
Definition: Font.hpp:75
void setT1(float t1)
Definition: Font.hpp:96
void setAdvance(const fvec2 &advance)
Definition: Font.hpp:99
float mS0
Definition: Font.hpp:110
int mHeight
Definition: Font.hpp:117
FT_Face mFT_Face
Definition: Font.hpp:205
float t1() const
Definition: Font.hpp:95
struct FT_FaceRec_ * FT_Face
Definition: Font.hpp:43
const Font * font() const
Definition: Font.hpp:104
float s1() const
Definition: Font.hpp:92
FontManager * fontManager()
The FontManager associated to this Font used to acquire/release FreeType resources.
Definition: Font.hpp:191
std::vector< char > mMemoryFile
Definition: Font.hpp:206
float mT0
Definition: Font.hpp:111
int mSize
Definition: Font.hpp:207
Font * mFont
Definition: Font.hpp:108