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 //===========================================================================
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
81  texture */
82 
83  /** Default constructor to initialize font data to known values */
85  : numberOfTextures( 1 )
86  , glyphCount( 0 )
87  , maxNumberOfGlyphsPerTexture( 1 )
88  {
89  }
90  };
91 
92  //-----------------------------------------------------------------------
93  /// Character attributes. One item for each character in the set.
94  //-----------------------------------------------------------------------
95  struct CharAttrUnicode_t : public CharAttr_t
96  {
97  unsigned int textureIndex; /**< Index of the texture that contains the glyph */
98  unsigned int glyphIndex; /**< Index of the glyph. This is needed since glyphs are not assumed to be contiguous */
99 
100  /** Default constructor to initialize character attribute data to known values */
102  : textureIndex( 0 )
103  , glyphIndex( 0 )
104  {
105  }
106 
108  GLfloat w,
109  GLfloat h,
110  GLfloat vTexX1,
111  GLfloat vTexX2,
112  GLfloat fTexX1,
113  GLfloat fTexX2,
114  GLfloat vTexY1,
115  GLfloat vTexY2,
116  GLfloat fTexY1,
117  GLfloat fTexY2,
118  GLfloat horiBearingX_,
119  GLfloat horiBearingY_,
120  GLfloat horiAdvance_,
121  GLfloat vertBearingX_,
122  GLfloat vertBearingY_,
123  GLfloat vertAdvance_,
124  unsigned int textureIndex_,
125  unsigned int glyphIndex_ )
126  : CharAttr_t( w, h, vTexX1, vTexX2, fTexX1, fTexX2, vTexY1, vTexY2, fTexY1, fTexY2,
127  horiBearingX_, horiBearingY_, horiAdvance_, vertBearingX_, vertBearingY_, vertAdvance_ )
128  , textureIndex( textureIndex_ )
129  , glyphIndex( glyphIndex_ )
130  {
131  }
132  };
133 
134  typedef std::vector<CharAttrUnicode_t> AttrContUnicode_t;
135 
136  typedef std::vector<Image*> ImageVector_t;
137 
138  /** Class Constructor
139  * \param dbufReader reader to read BUF data from
140  */
141  GLS_EXPORT GlsUnicodeFontBase( GlsUnicodeFontDBUFReader& dbufReader );
142 
143  /** Determine if font was instantiated correctly
144  * \return true if valid else false
145  */
146  GLS_EXPORT bool IsValid( void ) const;
147 
148  /** get the font textures associated with the unicode font
149  * \return the font textures associated with the unicode font
150  */
151  GLS_EXPORT ImageVector_t FontTextures( void ) const;
152 
153  /** get the unicode character attribute for the given char
154  * \param c The character to retrieve attributes for.
155  * \returns The attributes for the character else char attributes for first character
156  * in font if char is not in range for this font
157  */
158  GLS_EXPORT const CharAttrUnicode_t& CharAttrUnicode( Char_t c ) const;
159 
160  /** Get the font texture for the font texture containing the given glyph
161  * \param c The character to retrieve attributes for.
162  * \return the font texture for the font texture containing the given glyph,
163  * else font texture for first glyph in font if glyph is not in the font
164  */
165  GLS_EXPORT Image* FontTextureForChar( Char_t c ) const;
166 
167 protected:
168  /**
169  * Class Destructor. This is protected so that no one can delete a font
170  * except via the font manager GlsFontMan.
171  * It is not vitual because we want to avoid calling destructors on unloaded font code,
172  * and it is not needed.
173  */
174  GLS_EXPORT ~GlsUnicodeFontBase();
175 
176  friend class GlsFontMan;
177 
178  FontAttrUnicode_t _fontAttrUnicode; /**< unicode font attributes */
179  AttrContUnicode_t _charAttrUnicode; /**< unicode char attributes */
180  ImageVector_t _fontTextures; /**< font textures */
181  bool _isValid; /**< true if font is valid else false */
182 
183  unsigned int _charAttributeIndexLUTSize; /**< number of entries in the _charAttributeIndexLUT = ( lastChar - firstChar ) + 1 ) */
184  unsigned short* _charAttributeIndexLUT; /**< look up table from glyph index ( minus _fontAttributes.firstChar )
185  * to _charAttrUnicode array index else entry has NO_GLYPH to indicate that the given
186  * glyph is not in the font ( NOTE : array is _charAttributeIndexLUT long ) */
187 
188 private:
189  //-----------------------------------------------------------------------
190  // Prevent copies
191  //-----------------------------------------------------------------------
193  GlsUnicodeFontBase& operator=( const GlsUnicodeFontBase& );
194 
195 }; // end class GlsUnicodeFontBase
196 
197 /** helper class for reading a binary unicode font (DBUF) */
199 {
200 public:
201  /** ctor -- construct from inline data (optionally compressed)
202  * \param inlineDBUFData inline DBUF data to read
203  * \param lineLength length of lines in inline data
204  * \param totalInlineSize total number of bytes (not including NULL terminators) of inline data
205  * \param isCompressed true if dbuf data is zlib compressed else false
206  * \param uncompressedSize uncompressed size of data if isCompressed else ignored
207  */
208  GLS_EXPORT GlsUnicodeFontDBUFReader( const unsigned char* const* inlineDBUFData, const unsigned int lineLength,
209  const unsigned int totalInlineSize, const bool isCompressed, unsigned long uncompressedSize );
210 
211  /** ctor -- construct from noninline data (not compressed)
212  * \param dbufData DBUF data to read
213  * \param dbufDataLength number of bytes of data in dbufData
214  */
215  GLS_EXPORT GlsUnicodeFontDBUFReader( const unsigned char* const dbufData, const unsigned int dbufDataLength );
216 
217  /** dtor */
218  GLS_EXPORT ~GlsUnicodeFontDBUFReader();
219 
220  /** Get the GlsFontBase::FontAttr_t associated with the unicode font
221  * \return the GlsFontBase::FontAttr_t associated with the unicode font
222  */
224 
225  /** Get the GlsFontBase::AttrCont_t associated with the unicode font
226  * \return the GlsFontBase::AttrCont_t associated with the unicode font
227  */
228  GLS_EXPORT GlsFontBase::AttrCont_t GetGlsFontBaseCharAttributes( void );
229 
230  /** Get the first image associated with the unicode font (suitable for use by GlsFontBase)
231  * \return the first image associated with the unicode font (suitable for use by GlsFontBase)
232  * \note will increase usage count on texture by one so caller should call DeleteUsage when texture is no longer needed
233  */
234  GLS_EXPORT Image* GetGlsFontBaseTexture( void );
235 
236  /** Get the GlsUnicodeFontBase::FontAttrUnicode_t associated with the unicode font
237  * \return the GlsFontBase::FontAttrUnicode_t associated with the unicode font
238  */
240 
241  /** Get the GlsUnicodeFontBase::AttrContUnicode_t associated with the unicode font
242  * \return the GlsFontBase::AttrContUnicode_t associated with the unicode font
243  */
244  GLS_EXPORT GlsUnicodeFontBase::AttrContUnicode_t GetGlsUnicodeFontBaseCharAttributes( void );
245 
246  /** Get the textures associated with the unicode font
247  * \return the textures associated with the unicode font
248  * \note each texture will have its usage count increased by one so caller should call DeleteUsage on each texture
249  * when they are no longer needed
250  */
251  GLS_EXPORT std::vector<Image*> GetGlsUnicodeFontBaseTextures( void );
252 
253  /** Determine if a valid DBUF was read
254  * \return true if a valid DBUF was read else false
255  */
256  GLS_EXPORT bool IsValid( void ) const;
257 
258  /** Get an error message if !IsValid()
259  * \return an error message if !IsValid()
260  */
261  GLS_EXPORT std::string GetErrorMsg( void ) const;
262 
263 protected:
264  /** initialize the reader from the given DBUF data
265  * \param dbufData DBUF data to read
266  * \param dbufDataLength number of bytes of data in dbufData
267  */
268  GLS_EXPORT void InitializeFromDBUF( const unsigned char* const dbufData, const unsigned int dbufDataLength );
269 
270  bool _isValid; /**< true if a valid DBUF was read else false */
271  std::string _errMsg; /**< error message if !IsValid() */
272 
273  GlsUnicodeFontBase::FontAttrUnicode_t _fontAttrUnicode; /**< unicode font attributes read from DBUF data */
274  GlsUnicodeFontBase::AttrContUnicode_t _charAttrUnicode; /**< unicode char attributes read from DBUF data */
275  std::vector<Image*> _fontTextures; /**< font textures read from DBUF data */
276 
277 private:
278  //-----------------------------------------------------------------------
279  // Prevent copies
280  //-----------------------------------------------------------------------
281  GlsUnicodeFontDBUFReader( const GlsUnicodeFontDBUFReader& src );
282  GlsUnicodeFontDBUFReader& operator=( const GlsUnicodeFontDBUFReader& ths );
283 };
284 
285 } // end namespace disti
286 
287 #endif
ImageVector_t _fontTextures
Definition: gls_unicode_font_base.h:180
Definition: image.h:162
unsigned int glyphCount
Definition: gls_unicode_font_base.h:77
ImageVector_t FontTextures(void) const
const CharAttrUnicode_t & CharAttrUnicode(Char_t c) const
FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:178
std::vector< Image * > _fontTextures
Definition: gls_unicode_font_base.h:275
bool _isValid
Definition: gls_unicode_font_base.h:181
The disti::GlsFontBase class and related classes.
unsigned int textureIndex
Definition: gls_unicode_font_base.h:97
static const unsigned short NO_GLYPH
Definition: gls_unicode_font_base.h:69
GlsFontBase::AttrCont_t GetGlsFontBaseCharAttributes(void)
std::vector< Image * > GetGlsUnicodeFontBaseTextures(void)
GlsUnicodeFontBase::AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:274
unsigned short * _charAttributeIndexLUT
Definition: gls_unicode_font_base.h:184
FontAttrUnicode_t()
Definition: gls_unicode_font_base.h:84
CharAttrUnicode_t()
Definition: gls_unicode_font_base.h:101
GlsUnicodeFontBase(GlsUnicodeFontDBUFReader &dbufReader)
GlsFontBase::FontAttr_t GetGlsFontBaseFontAttributes(void)
Image * FontTextureForChar(Char_t c) const
unsigned int maxNumberOfGlyphsPerTexture
Definition: gls_unicode_font_base.h:78
Definition: gls_unicode_font_base.h:65
std::string _errMsg
Definition: gls_unicode_font_base.h:271
AttrContUnicode_t _charAttrUnicode
Definition: gls_unicode_font_base.h:179
unsigned int glyphIndex
Definition: gls_unicode_font_base.h:98
bool IsValid(void) const
Attributes of the specific font.
Definition: gls_unicode_font_base.h:74
Attributes of the specific font.
Definition: gls_font_base.h:94
void InitializeFromDBUF(const unsigned char *const dbufData, const unsigned int dbufDataLength)
Character attributes. One item for each character in the set.
Definition: gls_unicode_font_base.h:95
Definition: gls_unicode_font_base.h:198
GlsUnicodeFontBase::AttrContUnicode_t GetGlsUnicodeFontBaseCharAttributes(void)
GlsUnicodeFontBase::FontAttrUnicode_t _fontAttrUnicode
Definition: gls_unicode_font_base.h:273
bool _isValid
Definition: gls_unicode_font_base.h:270
GlsUnicodeFontBase::FontAttrUnicode_t GetGlsUnicodeFontBaseFontAttributes(void)
Character attributes. One item for each character in the set.
Definition: gls_font_base.h:124
GlsUnicodeFontDBUFReader(const unsigned char *const *inlineDBUFData, const unsigned int lineLength, const unsigned int totalInlineSize, const bool isCompressed, unsigned long uncompressedSize)
Definition: bmpimage.h:46
unsigned int _charAttributeIndexLUTSize
Definition: gls_unicode_font_base.h:183
std::string GetErrorMsg(void) const
Definition: gls_font_base.h:85