GL Studio C++ Runtime API
gls_unicode_font_base.h
Go to the documentation of this file.
1/// \file gls_unicode_font_base.h
2/// \brief The disti::GlsUnicodeFontBase 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_UNICODE_FONT_BASE_H
40#define DISTI_INCLUDED_GLS_UNICODE_FONT_BASE_H
41
42#include "gls_font_base.h"
43
44namespace disti
45{
46// forward ref
47class GlsUnicodeFontDBUFReader;
48
49//===========================================================================
50/**
51* The GlsUnicodeFontBase class provides a specific unicode font face for use within the GL
52* Studio. The font face is determined at construction time by the
53* parameters passed in by the creator of the GlsFontBase instance. Specific
54* instances should be wrapped in a singelton object wrapper, as there is
55* no reason to have more than one instance of the exact same face (meaning
56* font family, style, and point size.)
57*
58* Once instanced, a GlsFontRenderer object can be used to render characters in
59* Open GL at specific locations and with several different text effects.
60*
61* \sa GlsFontRenderer
62*/
63//===========================================================================
65{
66public:
67 /** char index associated with absent glyph */
68 static const unsigned short NO_GLYPH;
69
70 //-----------------------------------------------------------------------
71 /// Attributes of the specific font
72 //-----------------------------------------------------------------------
74 {
75 unsigned int numberOfTextures; ///< The number of textures used to generate font.
76 unsigned int glyphCount; ///< The number of glyphs rendered for the font.
77 unsigned int maxNumberOfGlyphsPerTexture; ///< The maximum number of glyphs per texture for the first n textures.
78 ///< This does not take into consideration the last texture which
79 ///< may contain less than the standard number of glyphs per texture.
80
81 /** Default constructor to initialize font data to known values */
83 : numberOfTextures( 1 )
84 , glyphCount( 0 )
86 {
87 }
88 };
89
90 //-----------------------------------------------------------------------
91 /// Character attributes. One item for each character in the set.
92 //-----------------------------------------------------------------------
94 {
95 unsigned int textureIndex; /**< Index of the texture that contains the glyph */
96 unsigned int glyphIndex; /**< Index of the glyph. This is needed since glyphs are not assumed to be contiguous */
97
98 /** Default constructor to initialize character attribute data to known values */
100 : textureIndex( 0 )
101 , glyphIndex( 0 )
102 {
103 }
104
105 /// Constructor
106 /// \param w Character width in pixels/points.
107 /// \param h Character height in pixels/points.
108 /// \param vTexX1 Left most x position in the texture for variable width font spacing. (in texture coordinates)
109 /// \param vTexX2 Right most x position in the texture for variable width font spacing. (in texture coordinates)
110 /// \param fTexX1 Left most x position in the texture for fixed width font spacing. (in texture coordinates)
111 /// \param fTexX2 Right most x position in the texture for fixed width font spacing. (in texture coordinates)
112 /// \param vTexY1 Lowest y position in the texture for variable height font spacing. (in texture coordinates)
113 /// \param vTexY2 Upper most y position in the texture for variable height font spacing. (in texture coordinates)
114 /// \param fTexY1 Lowest y position in the texture for fixed height font spacing. (in texture coordinates)
115 /// \param fTexY2 Upper most y position in the texture for fixed height font spacing. (in texture coordinates)
116 /// \param horiBearingX_ Distance from pen position to the left edge of the character (varTexX1) for horizontal strings.
117 /// \param horiBearingY_ Distance from pen position (ie the baseline) to the top edge of the character (varTexY2) for horizontal strings.
118 /// \param horiAdvance_ Distance to advance the pen position after drawing this character for horizontal strings.
119 /// \param vertBearingX_ Distance from pen position (ie the center line) to the left edge of the character (varTexX1) for vertical strings.
120 /// \param vertBearingY_ Distance from pen position to the top edge of the character (varTexY2) for vertical strings.
121 /// \param vertAdvance_ Distance to advance the pen position after drawing this character for vertical strings.
122 /// \param textureIndex_ The texture index to use for this character.
123 /// \param glyphIndex_ The glyph index of this character.
125 GLfloat w,
126 GLfloat h,
127 GLfloat vTexX1,
128 GLfloat vTexX2,
129 GLfloat fTexX1,
130 GLfloat fTexX2,
131 GLfloat vTexY1,
132 GLfloat vTexY2,
133 GLfloat fTexY1,
134 GLfloat fTexY2,
135 GLfloat horiBearingX_,
136 GLfloat horiBearingY_,
137 GLfloat horiAdvance_,
138 GLfloat vertBearingX_,
139 GLfloat vertBearingY_,
140 GLfloat vertAdvance_,
141 unsigned int textureIndex_,
142 unsigned int glyphIndex_ )
143 : CharAttr_t( w, h, vTexX1, vTexX2, fTexX1, fTexX2, vTexY1, vTexY2, fTexY1, fTexY2,
144 horiBearingX_, horiBearingY_, horiAdvance_, vertBearingX_, vertBearingY_, vertAdvance_ )
145 , textureIndex( textureIndex_ )
146 , glyphIndex( glyphIndex_ )
147 {
148 }
149 };
150
151 typedef std::vector<CharAttrUnicode_t> AttrContUnicode_t; ///< Typedef for a list of character attributes.
152
153 typedef std::vector<Image*> ImageVector_t; ///< Typedef for a list of glyph images.
154
155 /** Class Constructor
156 * \param dbufReader reader to read BUF data from
157 */
159
160 /** Determine if font was instantiated correctly
161 * \return true if valid else false
162 */
163 GLS_EXPORT bool IsValid() const;
164
165 /** get the font textures associated with the unicode font
166 * \return the font textures associated with the unicode font
167 */
169
170 /** get the unicode character attribute for the given char
171 * \param c The character to retrieve attributes for.
172 * \returns The attributes for the character else char attributes for first character
173 * in font if char is not in range for this font
174 */
176
177 /** Get the font texture for the font texture containing the given glyph
178 * \param c The character to retrieve attributes for.
179 * \return the font texture for the font texture containing the given glyph,
180 * else font texture for first glyph in font if glyph is not in the font
181 */
183
184protected:
185 /**
186 * Class Destructor. This is protected so that no one can delete a font
187 * except via the font manager GlsFontMan.
188 * It is not vitual because we want to avoid calling destructors on unloaded font code,
189 * and it is not needed.
190 */
192
193 friend class GlsFontMan;
194
195 FontAttrUnicode_t _fontAttrUnicode; /**< unicode font attributes */
196 AttrContUnicode_t _charAttrUnicode; /**< unicode char attributes */
197 ImageVector_t _fontTextures; /**< font textures */
198 bool _isValid; /**< true if font is valid else false */
199
200 unsigned int _charAttributeIndexLUTSize; /**< number of entries in the _charAttributeIndexLUT = ( lastChar - firstChar ) + 1 ) */
201 unsigned short* _charAttributeIndexLUT; /**< look up table from glyph index ( minus _fontAttributes.firstChar )
202 * to _charAttrUnicode array index else entry has NO_GLYPH to indicate that the given
203 * glyph is not in the font ( NOTE : array is _charAttributeIndexLUT long ) */
204
205private:
206 //-----------------------------------------------------------------------
207 // Prevent copies
208 //-----------------------------------------------------------------------
210 GlsUnicodeFontBase& operator=( const GlsUnicodeFontBase& );
211
212}; // end class GlsUnicodeFontBase
213
214/** helper class for reading a binary unicode font (DBUF) */
216{
217public:
218 /** ctor -- construct from inline data (optionally compressed)
219 * \param inlineDBUFData DBUF data to read
220 * \param lineLength length of lines in data
221 * \param totalInlineSize total number of bytes (not including NULL terminators) of data
222 * \param isCompressed true if dbuf data is zlib compressed else false
223 * \param uncompressedSize uncompressed size of data if isCompressed else ignored
224 */
225 GLS_EXPORT GlsUnicodeFontDBUFReader( const unsigned char* const* inlineDBUFData, const unsigned int lineLength,
226 const unsigned int totalInlineSize, const bool isCompressed, unsigned long uncompressedSize );
227
228 /** ctor -- construct from noninline data (not compressed)
229 * \param dbufData DBUF data to read
230 * \param dbufDataLength number of bytes of data in dbufData
231 */
232 GLS_EXPORT GlsUnicodeFontDBUFReader( const unsigned char* const dbufData, const unsigned int dbufDataLength );
233
234 /** dtor */
236
237 /** Get the GlsFontBase::FontAttr_t associated with the unicode font
238 * \return the GlsFontBase::FontAttr_t associated with the unicode font
239 */
241
242 /** Get the GlsFontBase::AttrCont_t associated with the unicode font
243 * \return the GlsFontBase::AttrCont_t associated with the unicode font
244 */
246
247 /** Get the first image associated with the unicode font (suitable for use by GlsFontBase)
248 * \return the first image associated with the unicode font (suitable for use by GlsFontBase)
249 * \note will increase usage count on texture by one so caller should call DeleteUsage when texture is no longer needed
250 */
252
253 /** Get the GlsUnicodeFontBase::FontAttrUnicode_t associated with the unicode font
254 * \return the GlsFontBase::FontAttrUnicode_t associated with the unicode font
255 */
257
258 /** Get the GlsUnicodeFontBase::AttrContUnicode_t associated with the unicode font
259 * \return the GlsFontBase::AttrContUnicode_t associated with the unicode font
260 */
262
263 /** Get the textures associated with the unicode font
264 * \return the textures associated with the unicode font
265 * \note each texture will have its usage count increased by one so caller should call DeleteUsage on each texture
266 * when they are no longer needed
267 */
269
270 /** Determine if a valid DBUF was read
271 * \return true if a valid DBUF was read else false
272 */
273 GLS_EXPORT bool IsValid() const;
274
275 /** Get an error message if !IsValid()
276 * \return an error message if !IsValid()
277 */
278 GLS_EXPORT std::string GetErrorMsg() const;
279
280protected:
281 /** initialize the reader from the given DBUF data
282 * \param dbufData DBUF data to read
283 * \param dbufDataLength number of bytes of data in dbufData
284 */
285 GLS_EXPORT void InitializeFromDBUF( const unsigned char* const dbufData, const unsigned int dbufDataLength );
286
287 bool _isValid; /**< true if a valid DBUF was read else false */
288 std::string _errMsg; /**< error message if !IsValid() */
289
290 GlsUnicodeFontBase::FontAttrUnicode_t _fontAttrUnicode; /**< unicode font attributes read from DBUF data */
291 GlsUnicodeFontBase::AttrContUnicode_t _charAttrUnicode; /**< unicode char attributes read from DBUF data */
292 std::vector<Image*> _fontTextures; /**< font textures read from DBUF data */
293
294private:
295 //-----------------------------------------------------------------------
296 // Prevent copies
297 //-----------------------------------------------------------------------
299 GlsUnicodeFontDBUFReader& operator=( const GlsUnicodeFontDBUFReader& ths );
300};
301
302} // end namespace disti
303
304#endif
Definition: gls_font_base.h:86
std::vector< CharAttr_t > AttrCont_t
Typedef for a list of character attributes.
Definition: gls_font_base.h:220
GLuint Char_t
Define the character type to use.
Definition: gls_font_base.h:88
Definition: gls_font_man.h:59
Definition: gls_unicode_font_base.h:65
std::vector< Image * > ImageVector_t
Typedef for a list of glyph images.
Definition: gls_unicode_font_base.h:153
ImageVector_t _fontTextures
Definition: gls_unicode_font_base.h:197
unsigned short * _charAttributeIndexLUT
Definition: gls_unicode_font_base.h:201
GlsUnicodeFontBase(GlsUnicodeFontDBUFReader &dbufReader)
const CharAttrUnicode_t & CharAttrUnicode(Char_t c) const
ImageVector_t FontTextures() const
Image * FontTextureForChar(Char_t c) const
AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:196
unsigned int _charAttributeIndexLUTSize
Definition: gls_unicode_font_base.h:200
FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:195
bool _isValid
Definition: gls_unicode_font_base.h:198
static const unsigned short NO_GLYPH
Definition: gls_unicode_font_base.h:68
std::vector< CharAttrUnicode_t > AttrContUnicode_t
Typedef for a list of character attributes.
Definition: gls_unicode_font_base.h:151
Definition: gls_unicode_font_base.h:216
std::vector< Image * > GetGlsUnicodeFontBaseTextures()
GlsUnicodeFontBase::FontAttrUnicode_t GetGlsUnicodeFontBaseFontAttributes()
GlsUnicodeFontDBUFReader(const unsigned char *const dbufData, const unsigned int dbufDataLength)
std::vector< Image * > _fontTextures
Definition: gls_unicode_font_base.h:292
GlsUnicodeFontBase::FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:290
void InitializeFromDBUF(const unsigned char *const dbufData, const unsigned int dbufDataLength)
std::string GetErrorMsg() const
bool _isValid
Definition: gls_unicode_font_base.h:287
std::string _errMsg
Definition: gls_unicode_font_base.h:288
GlsUnicodeFontBase::AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:291
GlsUnicodeFontDBUFReader(const unsigned char *const *inlineDBUFData, const unsigned int lineLength, const unsigned int totalInlineSize, const bool isCompressed, unsigned long uncompressedSize)
GlsUnicodeFontBase::AttrContUnicode_t GetGlsUnicodeFontBaseCharAttributes()
GlsFontBase::AttrCont_t GetGlsFontBaseCharAttributes()
GlsFontBase::FontAttr_t GetGlsFontBaseFontAttributes()
Definition: image.h:176
The disti::GlsFontBase class and related classes.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
Definition: bmpimage.h:46
Character attributes. One item for each character in the set.
Definition: gls_font_base.h:124
Attributes of the specific font.
Definition: gls_font_base.h:94
Character attributes. One item for each character in the set.
Definition: gls_unicode_font_base.h:94
CharAttrUnicode_t()
Definition: gls_unicode_font_base.h:99
unsigned int glyphIndex
Definition: gls_unicode_font_base.h:96
unsigned int textureIndex
Definition: gls_unicode_font_base.h:95
CharAttrUnicode_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_, unsigned int textureIndex_, unsigned int glyphIndex_)
Definition: gls_unicode_font_base.h:124
Attributes of the specific font.
Definition: gls_unicode_font_base.h:74
unsigned int numberOfTextures
The number of textures used to generate font.
Definition: gls_unicode_font_base.h:75
unsigned int maxNumberOfGlyphsPerTexture
Definition: gls_unicode_font_base.h:77
FontAttrUnicode_t()
Definition: gls_unicode_font_base.h:82
unsigned int glyphCount
The number of glyphs rendered for the font.
Definition: gls_unicode_font_base.h:76