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