GL Studio C++ Runtime API
gls_font_base.h
Go to the documentation of this file.
1/// \file gls_font_base.h
2/// \brief The disti::GlsFontBase class and related classes.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef DISTI_INCLUDED_GLS_FONT_BASE_H
40#define DISTI_INCLUDED_GLS_FONT_BASE_H
41
42#include "gls_gl.h"
43#include "vertex.h"
44#include <string>
45#include <vector>
46
47//---------------------------------------------------------------------------
48// MACROS FOR USE IN GENERATED SOURCE CODE
49//---------------------------------------------------------------------------
50/// \cond INTERNAL
51#define BEGIN_CHAR_ATTR AttrCont_t attr
52#define ADD_CHAR_ATTR( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 ) \
53 attr.push_back( CharAttr_t( a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16 ) )
54#define END_CHAR_ATTR return attr
55/// \endcond
56//===========================================================================
57// BEGIN NAMESPACE
58//===========================================================================
59namespace disti
60{
61//---------------------------------------------------------------------------
62// FORWARD REFERENCES
63//---------------------------------------------------------------------------
64class VertexNoColor;
65class GlsColor;
66class Image;
67
69
70//===========================================================================
71/**
72* The GlsFontBase class provides a specific font face for use within the GL
73* Studio. The font face is determined at construction time by the
74* parameters passed in by the creator of the GlsFontBase instance. Specific
75* instances should be wrapped in a singleton object wrapper, as there is
76* no reason to have more than one instance of the exact same face (meaning
77* font family, style, and point size.)
78*
79* Once instanced, a GlsFontRenderer object can be used to render characters in
80* Open GL at specific locations and with several different text effects.
81*
82* \sa GlsFontRenderer
83*/
84//===========================================================================
86{
87public:
88 typedef GLuint Char_t; ///< Define the character type to use.
89
90 //-----------------------------------------------------------------------
91 /// Attributes of the specific font
92 //-----------------------------------------------------------------------
94 {
95 std::string family; ///< Font family name. Eg. Arial.
96 std::string style; ///< Font style. Eg. Bold.
97 GLuint ptSize; ///< Font point size.
98 GLuint descender; ///< Font descender in positive pixels.
99 Char_t firstChar; ///< First character code in the character set.
100 Char_t lastChar; ///< Last character code in the character set.
101 GLuint maxCharHeight; ///< Maximum character height in pixels.
102 GLuint maxCharWidth; ///< Maximum character width in pixels.
103 GLint underlinePos; ///< Position of the underline for underlined text.
104 GLuint underlineSize; ///< thickness of the underline.
105
106 /** Default constructor to initialize font data to known values */
108 : ptSize( 0 )
109 , descender( 0 )
110 , firstChar( 32 )
111 , lastChar( 127 )
112 , maxCharHeight( 0 )
113 , maxCharWidth( 0 )
114 , underlinePos( 0 )
115 , underlineSize( 0 )
116 {
117 }
118 };
119
120 //-----------------------------------------------------------------------
121 /// Character attributes. One item for each character in the set.
122 //-----------------------------------------------------------------------
124 {
125 GLfloat width; ///< Character width in pixels/points.
126 GLfloat height; ///< Character height in pixels/points.
127 GLfloat varTexX1; ///< Left most x position in the texture for variable width font spacing. (in texture coordinates).
128 GLfloat varTexX2; ///< Right most x position in the texture for variable width font spacing. (in texture coordinates).
129 GLfloat fixedTexX1; ///< Left most x position in the texture for fixed width font spacing. (in texture coordinates).
130 GLfloat fixedTexX2; ///< Right most x position in the texture for fixed width font spacing. (in texture coordinates).
131 GLfloat varTexY1; ///< Lowest y position in the texture for variable height font spacing. (in texture coordinates).
132 GLfloat varTexY2; ///< Upper most y position in the texture for variable height font spacing. (in texture coordinates).
133 GLfloat fixedTexY1; ///< Lowest y position in the texture for fixed height font spacing. (in texture coordinates).
134 GLfloat fixedTexY2; ///< Upper most y position in the texture for fixed height font spacing. (in texture coordinates).
135
136 // Glyph metrics for character placement
137 // Additional information on the meaning of these parameters can
138 // be found in the freetype library documentation.
139 GLfloat horiBearingX; ///< Distance from pen position to the left edge of the character (varTexX1) for horizontal strings.
140 GLfloat horiBearingY; ///< Distance from pen position (ie the baseline) to the top edge of the character (varTexY2) for horizontal strings.
141 GLfloat horiAdvance; ///< Distance to advance the pen position after drawing this character for horizontal strings.
142 GLfloat vertBearingX; ///< Distance from pen position (ie the center line) to the left edge of the character (varTexX1) for vertical strings.
143 GLfloat vertBearingY; ///< Distance from pen position to the top edge of the character (varTexY2) for vertical strings.
144 GLfloat vertAdvance; ///< Distance to advance the pen position after drawing this character for vertical strings.
145
146 /// Default constructor to initialize character attribute data to known values
148 : width( 0 )
149 , height( 0 )
150 , varTexX1( 0 )
151 , varTexX2( 0 )
152 , fixedTexX1( 0 )
153 , fixedTexX2( 0 )
154 , varTexY1( 0 )
155 , varTexY2( 0 )
156 , fixedTexY1( 0 )
157 , fixedTexY2( 0 )
158 , horiBearingX( 0 )
159 , horiBearingY( 0 )
160 , horiAdvance( 0 )
161 , vertBearingX( 0 )
162 , vertBearingY( 0 )
163 , vertAdvance( 0 )
164 {
165 }
166
167 /// Constructor
168 /// \param w Character width in pixels/points.
169 /// \param h Character height in pixels/points.
170 /// \param vTexX1 Left most x position in the texture for variable width font spacing. (in texture coordinates)
171 /// \param vTexX2 Right most x position in the texture for variable width font spacing. (in texture coordinates)
172 /// \param fTexX1 Left most x position in the texture for fixed width font spacing. (in texture coordinates)
173 /// \param fTexX2 Right most x position in the texture for fixed width font spacing. (in texture coordinates)
174 /// \param vTexY1 Lowest y position in the texture for variable height font spacing. (in texture coordinates)
175 /// \param vTexY2 Upper most y position in the texture for variable height font spacing. (in texture coordinates)
176 /// \param fTexY1 Lowest y position in the texture for fixed height font spacing. (in texture coordinates)
177 /// \param fTexY2 Upper most y position in the texture for fixed height font spacing. (in texture coordinates)
178 /// \param horiBearingX_ Distance from pen position to the left edge of the character (varTexX1) for horizontal strings.
179 /// \param horiBearingY_ Distance from pen position (ie the baseline) to the top edge of the character (varTexY2) for horizontal strings.
180 /// \param horiAdvance_ Distance to advance the pen position after drawing this character for horizontal strings.
181 /// \param vertBearingX_ Distance from pen position (ie the center line) to the left edge of the character (varTexX1) for vertical strings.
182 /// \param vertBearingY_ Distance from pen position to the top edge of the character (varTexY2) for vertical strings.
183 /// \param vertAdvance_ Distance to advance the pen position after drawing this character for vertical strings.
184 CharAttr_t( GLfloat w,
185 GLfloat h,
186 GLfloat vTexX1,
187 GLfloat vTexX2,
188 GLfloat fTexX1,
189 GLfloat fTexX2,
190 GLfloat vTexY1,
191 GLfloat vTexY2,
192 GLfloat fTexY1,
193 GLfloat fTexY2,
194 GLfloat horiBearingX_,
195 GLfloat horiBearingY_,
196 GLfloat horiAdvance_,
197 GLfloat vertBearingX_,
198 GLfloat vertBearingY_,
199 GLfloat vertAdvance_ )
200 : width( w )
201 , height( h )
202 , varTexX1( vTexX1 )
203 , varTexX2( vTexX2 )
204 , fixedTexX1( fTexX1 )
205 , fixedTexX2( fTexX2 )
206 , varTexY1( vTexY1 )
207 , varTexY2( vTexY2 )
208 , fixedTexY1( fTexY1 )
209 , fixedTexY2( fTexY2 )
210 , horiBearingX( horiBearingX_ )
211 , horiBearingY( horiBearingY_ )
212 , horiAdvance( horiAdvance_ )
213 , vertBearingX( vertBearingX_ )
214 , vertBearingY( vertBearingY_ )
215 , vertAdvance( vertAdvance_ )
216 {
217 }
218 }; // end struct CharAttr_t
219
220 typedef std::vector<CharAttr_t> AttrCont_t; ///< Typedef for a list of character attributes.
221
222 /// Class Constructor.
223 /// \param fontAttr Font attributes for this font.
224 /// \param charAttributes Attributes for each glyph of this font.
225 /// \param texture The generated texture atlas associated with this font.
226 GLS_EXPORT GlsFontBase( const FontAttr_t& fontAttr, const AttrCont_t& charAttributes, Image* texture );
227
228 /**
229 * Access the attributes of the font.
230 * \return all the attributes of the font.
231 */
232 const FontAttr_t& Attributes() const
233 {
234 return _attr;
235 }
236
237 /**
238 * NOTE: This function will only return char attributes for pre-generated ASCII fonts.
239 * Users should call CharAttrUnicode for GlsUnicodeFontBase fonts or CharAttrRuntime for GlsRuntimeFontBase fonts.
240 * \param c The character to retrieve attributes for.
241 * \returns The attributes for the character.
242 */
243 const CharAttr_t& CharAttr( Char_t c ) const
244 {
245 return _charAttr[ CharAttrIndex( c ) ];
246 }
247
248 /**
249 * Calculates an index for the specified character depending on the set of characters the texture map was generated for.
250 * NOTE: This function will only return char attributes for pre-generated ASCII fonts.
251 * Users should call CharAttrUnicode for GlsUnicodeFontBase fonts or CharAttrRuntime for GlsRuntimeFontBase fonts.
252 * \param c specifies for which character the index is calculated for
253 * \return the index of the specified character
254 */
255 GLuint CharAttrIndex( Char_t c ) const
256 {
257 return ( _attr.firstChar <= c && c <= _attr.lastChar )
258 ? GLuint( c - _attr.firstChar )
259 : 0;
260 }
261
262 /**
263 * Access the character attributes of the font.
264 * \return the attributes of all the characters in the font.
265 */
267 {
268 return _charAttr;
269 }
270
271 /**
272 * \return The font family string
273 */
274 std::string Family() const
275 {
276 return _attr.family;
277 }
278
279 /**
280 * \return The unique lookup key for this font.
281 */
282 std::string Key() const
283 {
284 return _key;
285 }
286
287 /// Builds a unique lookup key for a specific font, style, and size.
288 /// \param name Name of the font.
289 /// \param style Style of the font.
290 /// \param ptSize Point size of the font.
291 /// \return The associated unique key for this combination.
292 static GLS_EXPORT std::string Key(
293 const std::string& name,
294 const std::string& style,
295 GLuint ptSize );
296
297 /**
298 * \return maximum height in pixels of the characters in the set
299 */
300 GLfloat MaxCharHeight() const
301 {
302 return GLfloat( _attr.maxCharHeight );
303 }
304
305 /**
306 * \return maximum width in pixels of the characters in the set
307 */
308 GLfloat MaxCharWidth() const
309 {
310 return GLfloat( _attr.maxCharWidth );
311 }
312
313 /**
314 * \return maximum height in pixels of the characters in the set
315 */
316 GLuint PtSize() const
317 {
318 return _attr.ptSize;
319 }
320
321 /// \return The style description for this font.
322 std::string Style() const
323 {
324 return _attr.style;
325 }
326
327 /**
328 * \return a pointer to the font's texture image.
329 */
330 Image* Texture() const
331 {
332 return _texture;
333 }
334
335protected:
336 /**
337 * Class Destructor. This is protected so that no one can delete a font
338 * except via the font manager GlsFontMan.
339 * It is not vitual because we want to avoid calling destructors on unloaded font code,
340 * and it is not needed.
341 */
343
344 friend class GlsFontMan;
345
346 /** Attributes of the font. */
348
349 /** Proportional character attributes used when proportional character spacing is turned on. */
351
352 /** Unique key used as a lookup key to find fonts within maps. */
353 std::string _key;
354
355 /** Texture of all characters in the set. */
357
358private:
359 //-----------------------------------------------------------------------
360 // Prevent copies
361 //-----------------------------------------------------------------------
362 GlsFontBase( const GlsFontBase& );
363 GlsFontBase& operator=( const GlsFontBase& );
364
365}; // end class GlsFontBase
366
367} // end namespace disti
368
369#endif
Definition: gls_font_base.h:86
const CharAttr_t & CharAttr(Char_t c) const
Definition: gls_font_base.h:243
Image * Texture() const
Definition: gls_font_base.h:330
std::string Family() const
Definition: gls_font_base.h:274
std::vector< CharAttr_t > AttrCont_t
Typedef for a list of character attributes.
Definition: gls_font_base.h:220
std::string _key
Definition: gls_font_base.h:353
const FontAttr_t & Attributes() const
Definition: gls_font_base.h:232
static std::string Key(const std::string &name, const std::string &style, GLuint ptSize)
GLfloat MaxCharWidth() const
Definition: gls_font_base.h:308
GLuint Char_t
Define the character type to use.
Definition: gls_font_base.h:88
std::string Key() const
Definition: gls_font_base.h:282
const AttrCont_t & CharAttributes() const
Definition: gls_font_base.h:266
GLuint CharAttrIndex(Char_t c) const
Definition: gls_font_base.h:255
GlsFontBase(const FontAttr_t &fontAttr, const AttrCont_t &charAttributes, Image *texture)
std::string Style() const
Definition: gls_font_base.h:322
AttrCont_t _charAttr
Definition: gls_font_base.h:350
Image * _texture
Definition: gls_font_base.h:356
FontAttr_t _attr
Definition: gls_font_base.h:347
GLuint PtSize() const
Definition: gls_font_base.h:316
GLfloat MaxCharHeight() const
Definition: gls_font_base.h:300
Definition: gls_font_man.h:59
Definition: image.h:176
Definition: vertex.h:84
The gls_gl.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
Definition: bmpimage.h:46
VertexNoColor Vector
Definition: gls_font_base.h:68
Character attributes. One item for each character in the set.
Definition: gls_font_base.h:124
GLfloat vertBearingX
Distance from pen position (ie the center line) to the left edge of the character (varTexX1) for vert...
Definition: gls_font_base.h:142
GLfloat vertAdvance
Distance to advance the pen position after drawing this character for vertical strings.
Definition: gls_font_base.h:144
GLfloat fixedTexY2
Upper most y position in the texture for fixed height font spacing. (in texture coordinates).
Definition: gls_font_base.h:134
CharAttr_t(GLfloat w, GLfloat h, GLfloat vTexX1, GLfloat vTexX2, GLfloat fTexX1, GLfloat fTexX2, GLfloat vTexY1, GLfloat vTexY2, GLfloat fTexY1, GLfloat fTexY2, GLfloat horiBearingX_, GLfloat horiBearingY_, GLfloat horiAdvance_, GLfloat vertBearingX_, GLfloat vertBearingY_, GLfloat vertAdvance_)
Definition: gls_font_base.h:184
GLfloat width
Character width in pixels/points.
Definition: gls_font_base.h:125
GLfloat horiBearingX
Distance from pen position to the left edge of the character (varTexX1) for horizontal strings.
Definition: gls_font_base.h:139
GLfloat varTexY1
Lowest y position in the texture for variable height font spacing. (in texture coordinates).
Definition: gls_font_base.h:131
GLfloat fixedTexX1
Left most x position in the texture for fixed width font spacing. (in texture coordinates).
Definition: gls_font_base.h:129
GLfloat horiAdvance
Distance to advance the pen position after drawing this character for horizontal strings.
Definition: gls_font_base.h:141
CharAttr_t()
Default constructor to initialize character attribute data to known values.
Definition: gls_font_base.h:147
GLfloat varTexX2
Right most x position in the texture for variable width font spacing. (in texture coordinates).
Definition: gls_font_base.h:128
GLfloat fixedTexY1
Lowest y position in the texture for fixed height font spacing. (in texture coordinates).
Definition: gls_font_base.h:133
GLfloat vertBearingY
Distance from pen position to the top edge of the character (varTexY2) for vertical strings.
Definition: gls_font_base.h:143
GLfloat horiBearingY
Distance from pen position (ie the baseline) to the top edge of the character (varTexY2) for horizont...
Definition: gls_font_base.h:140
GLfloat height
Character height in pixels/points.
Definition: gls_font_base.h:126
GLfloat fixedTexX2
Right most x position in the texture for fixed width font spacing. (in texture coordinates).
Definition: gls_font_base.h:130
GLfloat varTexX1
Left most x position in the texture for variable width font spacing. (in texture coordinates).
Definition: gls_font_base.h:127
GLfloat varTexY2
Upper most y position in the texture for variable height font spacing. (in texture coordinates).
Definition: gls_font_base.h:132
Attributes of the specific font.
Definition: gls_font_base.h:94
GLuint maxCharWidth
Maximum character width in pixels.
Definition: gls_font_base.h:102
GLuint descender
Font descender in positive pixels.
Definition: gls_font_base.h:98
GLint underlinePos
Position of the underline for underlined text.
Definition: gls_font_base.h:103
FontAttr_t()
Definition: gls_font_base.h:107
GLuint ptSize
Font point size.
Definition: gls_font_base.h:97
std::string family
Font family name. Eg. Arial.
Definition: gls_font_base.h:95
GLuint underlineSize
thickness of the underline.
Definition: gls_font_base.h:104
std::string style
Font style. Eg. Bold.
Definition: gls_font_base.h:96
Char_t lastChar
Last character code in the character set.
Definition: gls_font_base.h:100
Char_t firstChar
First character code in the character set.
Definition: gls_font_base.h:99
GLuint maxCharHeight
Maximum character height in pixels.
Definition: gls_font_base.h:101
The disti::Vertex class. A class for manipulating 3D vertices.