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