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