| 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
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*/
40#ifndef _GLS_UNICODE_FONT_BASE_H
41#define _GLS_UNICODE_FONT_BASE_H
42
43#include "gls_font_base.h"
44
45 namespace disti
46{
47// forward ref
48 class 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//===========================================================================
65 class GlsUnicodeFontBase : public GlsFontBase
66{
67 public:
68 /** char index associated with absent glyph */
69 static const unsigned short NO_GLYPH;
70
71 //-----------------------------------------------------------------------
72 /// Attributes of the specific font
73 //-----------------------------------------------------------------------
74 struct FontAttrUnicode_t : public FontAttr_t
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 */
83 FontAttrUnicode_t()
84 : numberOfTextures( 1 )
85 , glyphCount( 0 )
86 , maxNumberOfGlyphsPerTexture( 1 )
87 {
88 }
89 };
90
91 //-----------------------------------------------------------------------
92 /// Character attributes. One item for each character in the set.
93 //-----------------------------------------------------------------------
94 struct CharAttrUnicode_t : public CharAttr_t
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 */
100 CharAttrUnicode_t()
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.
125 CharAttrUnicode_t(
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 */
159 GLS_EXPORT GlsUnicodeFontBase( GlsUnicodeFontDBUFReader& dbufReader );
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 */
169 GLS_EXPORT ImageVector_t FontTextures() const;
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 */
176 GLS_EXPORT const CharAttrUnicode_t& CharAttrUnicode( Char_t c ) const;
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 */
183 GLS_EXPORT Image* FontTextureForChar( Char_t c ) const;
184
185 protected:
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 */
192 GLS_EXPORT ~GlsUnicodeFontBase();
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
206 private:
207 //-----------------------------------------------------------------------
208 // Prevent copies
209 //-----------------------------------------------------------------------
210 GlsUnicodeFontBase( const GlsUnicodeFontBase& );
211 GlsUnicodeFontBase& operator=( const GlsUnicodeFontBase& );
212
213}; // end class GlsUnicodeFontBase
214
215/** helper class for reading a binary unicode font (DBUF) */
216 class GlsUnicodeFontDBUFReader
217{
218 public:
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 */
236 GLS_EXPORT ~GlsUnicodeFontDBUFReader();
237
238 /** Get the GlsFontBase::FontAttr_t associated with the unicode font
239 * \return the GlsFontBase::FontAttr_t associated with the unicode font
240 */
241 GLS_EXPORT GlsFontBase::FontAttr_t GetGlsFontBaseFontAttributes();
242
243 /** Get the GlsFontBase::AttrCont_t associated with the unicode font
244 * \return the GlsFontBase::AttrCont_t associated with the unicode font
245 */
246 GLS_EXPORT GlsFontBase::AttrCont_t GetGlsFontBaseCharAttributes();
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 */
252 GLS_EXPORT Image* GetGlsFontBaseTexture();
253
254 /** Get the GlsUnicodeFontBase::FontAttrUnicode_t associated with the unicode font
255 * \return the GlsFontBase::FontAttrUnicode_t associated with the unicode font
256 */
257 GLS_EXPORT GlsUnicodeFontBase::FontAttrUnicode_t GetGlsUnicodeFontBaseFontAttributes();
258
259 /** Get the GlsUnicodeFontBase::AttrContUnicode_t associated with the unicode font
260 * \return the GlsFontBase::AttrContUnicode_t associated with the unicode font
261 */
262 GLS_EXPORT GlsUnicodeFontBase::AttrContUnicode_t GetGlsUnicodeFontBaseCharAttributes();
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 */
269 GLS_EXPORT std::vector<Image*> GetGlsUnicodeFontBaseTextures();
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
281 protected:
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
295 private:
296 //-----------------------------------------------------------------------
297 // Prevent copies
298 //-----------------------------------------------------------------------
299 GlsUnicodeFontDBUFReader( const GlsUnicodeFontDBUFReader& src );
300 GlsUnicodeFontDBUFReader& operator=( const GlsUnicodeFontDBUFReader& ths );
301};
302
303} // end namespace disti
304
305#endif
disti::GlsFontBase
Definition: gls_font_base.h:87
disti::GlsFontBase::AttrCont_t
std::vector< CharAttr_t > AttrCont_t
Typedef for a list of character attributes.
Definition: gls_font_base.h:221
disti::GlsFontBase::Char_t
GLuint Char_t
Define the character type to use.
Definition: gls_font_base.h:89
disti::GlsFontMan
Definition: gls_font_man.h:60
disti::GlsUnicodeFontBase
Definition: gls_unicode_font_base.h:66
disti::GlsUnicodeFontBase::ImageVector_t
std::vector< Image * > ImageVector_t
Typedef for a list of glyph images.
Definition: gls_unicode_font_base.h:154
disti::GlsUnicodeFontBase::_fontTextures
ImageVector_t _fontTextures
Definition: gls_unicode_font_base.h:198
disti::GlsUnicodeFontBase::_charAttributeIndexLUT
unsigned short * _charAttributeIndexLUT
Definition: gls_unicode_font_base.h:202
disti::GlsUnicodeFontBase::GlsUnicodeFontBase
GlsUnicodeFontBase(GlsUnicodeFontDBUFReader &dbufReader)
disti::GlsUnicodeFontBase::CharAttrUnicode
const CharAttrUnicode_t & CharAttrUnicode(Char_t c) const
disti::GlsUnicodeFontBase::FontTextures
ImageVector_t FontTextures() const
disti::GlsUnicodeFontBase::FontTextureForChar
Image * FontTextureForChar(Char_t c) const
disti::GlsUnicodeFontBase::_charAttrUnicode
AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:197
disti::GlsUnicodeFontBase::_charAttributeIndexLUTSize
unsigned int _charAttributeIndexLUTSize
Definition: gls_unicode_font_base.h:201
disti::GlsUnicodeFontBase::_fontAttrUnicode
FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:196
disti::GlsUnicodeFontBase::_isValid
bool _isValid
Definition: gls_unicode_font_base.h:199
disti::GlsUnicodeFontBase::NO_GLYPH
static const unsigned short NO_GLYPH
Definition: gls_unicode_font_base.h:69
disti::GlsUnicodeFontBase::IsValid
bool IsValid() const
disti::GlsUnicodeFontBase::~GlsUnicodeFontBase
~GlsUnicodeFontBase()
disti::GlsUnicodeFontBase::AttrContUnicode_t
std::vector< CharAttrUnicode_t > AttrContUnicode_t
Typedef for a list of character attributes.
Definition: gls_unicode_font_base.h:152
disti::GlsUnicodeFontDBUFReader
Definition: gls_unicode_font_base.h:217
disti::GlsUnicodeFontDBUFReader::GetGlsUnicodeFontBaseTextures
std::vector< Image * > GetGlsUnicodeFontBaseTextures()
disti::GlsUnicodeFontDBUFReader::GetGlsUnicodeFontBaseFontAttributes
GlsUnicodeFontBase::FontAttrUnicode_t GetGlsUnicodeFontBaseFontAttributes()
disti::GlsUnicodeFontDBUFReader::GlsUnicodeFontDBUFReader
GlsUnicodeFontDBUFReader(const unsigned char *const dbufData, const unsigned int dbufDataLength)
disti::GlsUnicodeFontDBUFReader::_fontTextures
std::vector< Image * > _fontTextures
Definition: gls_unicode_font_base.h:293
disti::GlsUnicodeFontDBUFReader::_fontAttrUnicode
GlsUnicodeFontBase::FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:291
disti::GlsUnicodeFontDBUFReader::InitializeFromDBUF
void InitializeFromDBUF(const unsigned char *const dbufData, const unsigned int dbufDataLength)
disti::GlsUnicodeFontDBUFReader::GetErrorMsg
std::string GetErrorMsg() const
disti::GlsUnicodeFontDBUFReader::_isValid
bool _isValid
Definition: gls_unicode_font_base.h:288
disti::GlsUnicodeFontDBUFReader::_errMsg
std::string _errMsg
Definition: gls_unicode_font_base.h:289
disti::GlsUnicodeFontDBUFReader::~GlsUnicodeFontDBUFReader
~GlsUnicodeFontDBUFReader()
disti::GlsUnicodeFontDBUFReader::_charAttrUnicode
GlsUnicodeFontBase::AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:292
disti::GlsUnicodeFontDBUFReader::GetGlsFontBaseTexture
Image * GetGlsFontBaseTexture()
disti::GlsUnicodeFontDBUFReader::IsValid
bool IsValid() const
disti::GlsUnicodeFontDBUFReader::GlsUnicodeFontDBUFReader
GlsUnicodeFontDBUFReader(const unsigned char *const *inlineDBUFData, const unsigned int lineLength, const unsigned int totalInlineSize, const bool isCompressed, unsigned long uncompressedSize)
disti::GlsUnicodeFontDBUFReader::GetGlsUnicodeFontBaseCharAttributes
GlsUnicodeFontBase::AttrContUnicode_t GetGlsUnicodeFontBaseCharAttributes()
disti::GlsUnicodeFontDBUFReader::GetGlsFontBaseCharAttributes
GlsFontBase::AttrCont_t GetGlsFontBaseCharAttributes()
disti::GlsUnicodeFontDBUFReader::GetGlsFontBaseFontAttributes
GlsFontBase::FontAttr_t GetGlsFontBaseFontAttributes()
disti::Image
Definition: image.h:178
gls_font_base.h
The disti::GlsFontBase class and related classes.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
disti
Definition: bmpimage.h:47
disti::GlsFontBase::CharAttr_t
Character attributes. One item for each character in the set.
Definition: gls_font_base.h:125
disti::GlsFontBase::FontAttr_t
Attributes of the specific font.
Definition: gls_font_base.h:95
disti::GlsUnicodeFontBase::CharAttrUnicode_t
Character attributes. One item for each character in the set.
Definition: gls_unicode_font_base.h:95
disti::GlsUnicodeFontBase::CharAttrUnicode_t::CharAttrUnicode_t
CharAttrUnicode_t()
Definition: gls_unicode_font_base.h:100
disti::GlsUnicodeFontBase::CharAttrUnicode_t::glyphIndex
unsigned int glyphIndex
Definition: gls_unicode_font_base.h:97
disti::GlsUnicodeFontBase::CharAttrUnicode_t::textureIndex
unsigned int textureIndex
Definition: gls_unicode_font_base.h:96
disti::GlsUnicodeFontBase::CharAttrUnicode_t::CharAttrUnicode_t
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
disti::GlsUnicodeFontBase::FontAttrUnicode_t
Attributes of the specific font.
Definition: gls_unicode_font_base.h:75
disti::GlsUnicodeFontBase::FontAttrUnicode_t::numberOfTextures
unsigned int numberOfTextures
The number of textures used to generate font.
Definition: gls_unicode_font_base.h:76
disti::GlsUnicodeFontBase::FontAttrUnicode_t::maxNumberOfGlyphsPerTexture
unsigned int maxNumberOfGlyphsPerTexture
Definition: gls_unicode_font_base.h:78
disti::GlsUnicodeFontBase::FontAttrUnicode_t::FontAttrUnicode_t
FontAttrUnicode_t()
Definition: gls_unicode_font_base.h:83
disti::GlsUnicodeFontBase::FontAttrUnicode_t::glyphCount
unsigned int glyphCount
The number of glyphs rendered for the font.
Definition: gls_unicode_font_base.h:77