GL Studio Safety Critical Embedded C++ Runtime Library
gls_font_base.h
Go to the documentation of this file.
1#ifndef _GLS_FONT_BASE_H
2#define _GLS_FONT_BASE_H
3
4/*! \file gls_font_base.h
5
6\brief This header defines the GlsFontBase class
7 in the GL Studio DO-178B Runtime Library.
8
9\par Copyright Information
10Copyright (C) 1999-2012 The DiSTI Corporation<br>
11Orlando, FL USA<br>
12All rights reserved.<br>
13
14 This file is copyrighted software and contains proprietary trade secrets of
15DiSTI, and embodies substantial creative efforts as well as confidential
16information, ideas, and expressions.
17
18 Permission to use, and copy this software and its documentation for any
19purpose is hereby granted per the Distribution Agreement and/or the Licensing
20Agreement signed with DiSTI. This permission is granted provided that:
21 1. The above copyright notice appears in all copies.
22 2. That both the copyright notice and this permission notice appear in
23 the supporting documentation.
24 3. That the names DiSTI and GL Studio not be used in advertising or
25 publicity pertaining to distribution of the software without specific,
26 written prior permission of DiSTI.
27
28 Permission to modify the software is granted, but not the right to
29distribute the source code whether modified, or non-modified. Modifying the
30software might invalidate the DO-178B certification package.
31
32 Permission to distribute binaries produced by compiling source code, or
33modified source code is granted, provided you:
34 1. Provide your name and address as the primary contact for the support
35 of your modified version.
36 2. Retain our contact information in regard to use of the base software.
37
38 DiSTI does not provide warranty for this software or guarantee that it
39satisfies any specification or requirement unless otherwise stated in a
40specific contractual arrangement between the customer and DiSTI.
41
42*/
43
44#include "gls_include.h"
45#include "gls_types.h"
46#include "gls_vertex.h"
47#include "gls_color.h"
48#include "gls_image.h"
49#include "gls_class_invariant.h"
50
51/** This class serves as the base class for all fonts
52 * \invariant _fontAttributes.IsValid(), _numGlyphAttributes > 0,
53 * _glyphAttributes != GLS_NULL and array contains valid elements,
54 * _fontImage invariant holds
55 */
57{
58public:
60
61 /** code associated with a character in the font */
63
64 /** tab character constant */
65 static const GlsChar TAB_CHAR;
66
67 /** describes basic attributes for the font */
69 {
70 const CharCode firstChar; /**< First character code in the character set */
71 const CharCode lastChar; /**< Last character code in the character set */
72 const GlsUInt32 maxCharHeight; /**< Maximum character height in pixels */
73 const GlsUInt32 maxCharWidth; /**< Maximum character width in pixels */
74 const GlsUInt32 underlinePos; /**< Position of the underline for underlined text */
75 const GlsUInt32 underlineSize; /**< thickness of the underline */
76
77 #if defined( GLS_DEBUG )
78 /** Determine if the attributes are valid ( GLS_DEBUG only )
79 * \return GLS_TRUE if valid else GLS_FALSE
80 * \pre none
81 * \post none
82 */
83 GlsBool IsValid( void ) const;
84 #endif // GLS_DEBUG
85 };
86
87 /** describes attributes for one glyph in the font */
89 {
90 GlsFloat32 width; /**< Glyph width in pixels */
91 GlsFloat32 varTexX1; /**< Left most x position in the texture for variable width font spacing.
92 * (in texture coordinates) */
93 GlsFloat32 varTexX2; /**< Right most x position in the texture for variable width font spacing.
94 * (in texture coordinates) */
95 GlsFloat32 fixedTexX1; /**< Left most x position in the texture for fixed width font spacing.
96 * (in texture coordinates) */
97 GlsFloat32 fixedTexX2; /**< Right most x position in the texture for fixed width font spacing.
98 * (in texture coordinates) */
99 GlsFloat32 texY1; /**< Lowest y position in the texture (in texture coordinates) */
100 GlsFloat32 texY2; /**< Upper most y position in the texture (in texture coordinates) */
101 // Glyph metrics for placement
102 GlsFloat32 horiBearingX; /**< Distance from pen position to the left edge of the glyph (varTexX1) for horizontal strings. */
103 GlsFloat32 horiAdvance; /**< Distance to advance the pen position after drawing this glyph for horizontal strings. */
104
105 #if defined( GLS_DEBUG )
106 /** Determine if the attributes are valid ( GLS_DEBUG only )
107 * \return GLS_TRUE if valid else GLS_FALSE
108 * \pre none
109 * \post none
110 */
111 GlsBool IsValid( void ) const;
112 #endif // GLS_DEBUG
113 };
114
115 /** attributes describing how a character will be rendered */
117 {
118 GlsVector2D startPosition; /**< position where rendering will begin */
119 GlsVector2D cellSize; /**< size of character cell to render */
120 GlsFloat32 baselineShift; /**< amount of character height to shift the character baseline,
121 * ( -1.0f <= baselineShift <= 1.0f ) */
122 GlsFloat32 scale; /**< amount of character height to scale the char,
123 * ( 0.0f < scale <= 1.0f ) */
124 GlsFloat32 spacing; /**< amount of character width to space the char, spacing >= 0.0f */
125 GlsBool emphasize; /**< GLS_TRUE if char is drawn with emphasis ( bold ) else GLS_FALSE */
126 GlsBool haloEffect; /**< GLS_TRUE if char is drawn with a halo effect else GLS_FALSE */
127 GlsBool inverse; /**< GLS_TRUE if char is rendered with inverse video effect else GLS_FALSE */
128 GlsBool shadow; /**< GLS_TRUE if char is rendered with a shadow */
129 GlsFloat32 shadowDistance; /**< amount of cell width to offset shadow if shadow == GLS_TRUE,
130 * ( -1.0f <= shadowDistance <= 1.0f ) */
131 GlsColor fgColor; /**< foreground color (actual character color) */
132 GlsColor bgColor; /**< background color */
133 GlsColor haloColor; /**< color of halo around text if haloEffect == GLS_TRUE */
134 GlsColor shadowColor; /**< color of shadow behind text if shadow == GLS_TRUE */
135 GlsBool uppercase; /**< GLS_TRUE to render characters all in uppercase else GLS_FALSE */
136 GlsBool proportional; /**< GLS_TRUE to render characters with proportional spacing else
137 * GLS_FALSE for fixed width spacing */
138 GlsBool expandTabs; /**< GLS_TRUE to expand tab characters width by multiplying by tabSpacing
139 * else GLS_FALSE */
140 GlsFloat32 tabSpacing; /**< number of tab widths to use when expanding tabs */
141
142 #if defined( GLS_DEBUG )
143 /** Determine if the render attributes are valid ( GLS_DEBUG only )
144 * \return GLS_TRUE if valid else GLS_FALSE
145 * \pre none
146 * \post none
147 */
148 GlsBool IsValid( void ) const;
149 #endif // GLS_DEBUG
150 };
151
152 /** initialization parameters for GlsFontBase */
154 {
155 const FontAttributes fontAttributes; /**< font attributes */
156 const GlsUInt32 numGlyphAttributes; /**< number of glyph attribues
157 * in glyphAttributes array (>0)*/
158 const GlyphAttribute* const glyphAttributes; /**< array of glyph attributes */
159 const GlsImage::InlineImage fontInlineImage; /**< font inline image */
160
161 #if defined( GLS_DEBUG )
162 /** Determine if the initialization parameteres are valid ( GLS_DEBUG only )
163 * \return GLS_TRUE if valid else GLS_FALSE
164 * \pre none
165 * \post none
166 */
167 GlsBool IsValid( void ) const;
168 #endif // GLS_DEBUG
169 };
170
171 /** Initializes the font to begin rendering characters. This will
172 * bind the font's texture. This must be called once before
173 * invoking RenderString to draw characters.
174 * \param gl state manager for OpenGL
175 * \pre none
176 * \post 2D texturing is enabled in GL and
177 * the font texture is bound to OpenGL with
178 * the GL_MODULATE texture env mode
179 */
181
182 /** Renders the specified character string with the given render attributes.
183 * \param gl State Manager for OpenGL where character will be drawn
184 * \param str string to render ( must contain at least numChars characters )
185 * \param numChars number of characters in str to render (>0)
186 * \param renderAttributes desired render attributes for character
187 * \pre str != GLS_NULL, numChars > 0, renderAttributues.IsValid(),
188 * font texture is bound to GL using BindFontTexture() and setup with
189 * the desired texture filter modes
190 * \post string is drawn to OpenGL
191 */
192 void RenderString( GlsStateManager &gl, const GlsChar* const str, const GlsUInt32 numChars,
193 const RenderAttributes &renderAttributes ) const;
194
195 /** Get the font attributes for this font
196 * \return font attributes for this font
197 * \pre none
198 * \post none
199 */
200 const FontAttributes& GetFontAttributes( void ) const;
201
202 /** Get the glyph attributes for a given char
203 * \param c char in question
204 * \param uppercase GLS_TRUE to use uppercase version of char else GLS_FALSE
205 * \return glyph attributes for c else glyph attributes for first character
206 * in font if c is not in range for this font
207 * \pre none
208 * \post none
209 */
210 const GlyphAttribute& GetGlyphAttribute( const GlsChar c, const GlsBool uppercase ) const;
211
212protected:
213 /** Constructor - called by derived font classes
214 * \param initParameters initialization parameters
215 * \pre initParameters.IsValid(), a GlsStateManager instance does not yet exist
216 * \post object is constructed
217 */
218 GlsFontBase( const InitParameters &initParameters );
219
220 /** Issue the GL vertex and texture coordinates for the quad described by the given points
221 * and texture coordinates
222 * \param p1 first corner of quad
223 * \param p2 opposite corner of quad
224 * \param t1 texture coord for first corner
225 * \param t2 texture coord for opposite corner
226 * \pre p1.IsValid(), p2.IsValid(), t1.IsValid(), t2.IsValid()
227 * \post GL vertex and texture coordinates for the quad are issued to GL
228 */
229 void DrawMappedQuad( const GlsVector2D &p1, const GlsVector2D &p2, const GlsVector2D &t1, const GlsVector2D &t2 ) const;
230
231 /** Destructor - shall never be called
232 * \pre none
233 * \post none
234 */
235 virtual ~GlsFontBase();
236
237 const FontAttributes _fontAttributes; /**< font attributes */
238 const GlsUInt32 _numGlyphAttributes; /**< number of glyph attribues in glyphAttributes array */
239 GlyphAttribute* const _glyphAttributes; /**< array of glyph attributes */
240 const GlsImage* const _fontImage; /**< font texture */
241
242private:
243 // Disable implicit generated Members
244 GlsFontBase& operator=( const GlsFontBase &rhs );
245 GlsFontBase( const GlsFontBase &src );
246};
247
248#endif // _GLS_FONT_BASE_H
Definition: gls_font_base.h:57
GlyphAttribute *const _glyphAttributes
Definition: gls_font_base.h:239
static const GlsChar TAB_CHAR
Definition: gls_font_base.h:65
const GlsImage *const _fontImage
Definition: gls_font_base.h:240
const FontAttributes _fontAttributes
Definition: gls_font_base.h:237
void RenderString(GlsStateManager &gl, const GlsChar *const str, const GlsUInt32 numChars, const RenderAttributes &renderAttributes) const
const GlyphAttribute & GetGlyphAttribute(const GlsChar c, const GlsBool uppercase) const
virtual ~GlsFontBase()
const GlsUInt32 _numGlyphAttributes
Definition: gls_font_base.h:238
const FontAttributes & GetFontAttributes(void) const
void DrawMappedQuad(const GlsVector2D &p1, const GlsVector2D &p2, const GlsVector2D &t1, const GlsVector2D &t2) const
void BindFontTexture(GlsStateManager &gl) const
GlsFontBase(const InitParameters &initParameters)
GlsUInt32 CharCode
Definition: gls_font_base.h:62
Definition: gls_image.h:60
Definition: gls_state_manager.h:64
This header defines a GLS_DEBUG only macro for facilitating evaluating class invariants in the GL Stu...
#define GLS_CLASS_INVARIANT_DECLARATION(ClassName)
Definition: gls_class_invariant.h:80
This header defines a 4 component RGBA color for use in the GL Studio DO-178B Runtime Library.
This header defines the GlsImage class which encapsulates textures in the GL Studio DO-178B Runtime L...
This header defines any preprocessor defines needed to configure the GL Studio DO-178B Runtime Librar...
This header defines the basic types used by the GL Studio DO-178B Runtime Library.
bool GlsBool
Definition: gls_types.h:96
char GlsChar
Definition: gls_types.h:54
unsigned int GlsUInt32
Definition: gls_types.h:73
float GlsFloat32
Definition: gls_types.h:78
This header defines classes for working with 2D and 3D vectors, vertices and textured vertices in the...
Definition: gls_color.h:48
Definition: gls_font_base.h:69
const GlsUInt32 maxCharWidth
Definition: gls_font_base.h:73
const GlsUInt32 maxCharHeight
Definition: gls_font_base.h:72
const GlsUInt32 underlineSize
Definition: gls_font_base.h:75
const GlsUInt32 underlinePos
Definition: gls_font_base.h:74
const CharCode lastChar
Definition: gls_font_base.h:71
const CharCode firstChar
Definition: gls_font_base.h:70
Definition: gls_font_base.h:89
GlsFloat32 texY2
Definition: gls_font_base.h:100
GlsFloat32 fixedTexX2
Definition: gls_font_base.h:97
GlsFloat32 width
Definition: gls_font_base.h:90
GlsFloat32 horiAdvance
Definition: gls_font_base.h:103
GlsFloat32 varTexX2
Definition: gls_font_base.h:93
GlsFloat32 horiBearingX
Definition: gls_font_base.h:102
GlsFloat32 texY1
Definition: gls_font_base.h:99
GlsFloat32 varTexX1
Definition: gls_font_base.h:91
GlsFloat32 fixedTexX1
Definition: gls_font_base.h:95
Definition: gls_font_base.h:154
const FontAttributes fontAttributes
Definition: gls_font_base.h:155
const GlsUInt32 numGlyphAttributes
Definition: gls_font_base.h:156
const GlsImage::InlineImage fontInlineImage
Definition: gls_font_base.h:159
const GlyphAttribute *const glyphAttributes
Definition: gls_font_base.h:158
Definition: gls_font_base.h:117
GlsColor fgColor
Definition: gls_font_base.h:131
GlsVector2D cellSize
Definition: gls_font_base.h:119
GlsColor haloColor
Definition: gls_font_base.h:133
GlsFloat32 scale
Definition: gls_font_base.h:122
GlsBool emphasize
Definition: gls_font_base.h:125
GlsFloat32 spacing
Definition: gls_font_base.h:124
GlsColor bgColor
Definition: gls_font_base.h:132
GlsFloat32 baselineShift
Definition: gls_font_base.h:120
GlsFloat32 shadowDistance
Definition: gls_font_base.h:129
GlsColor shadowColor
Definition: gls_font_base.h:134
GlsBool expandTabs
Definition: gls_font_base.h:138
GlsBool proportional
Definition: gls_font_base.h:136
GlsBool shadow
Definition: gls_font_base.h:128
GlsFloat32 tabSpacing
Definition: gls_font_base.h:140
GlsBool haloEffect
Definition: gls_font_base.h:126
GlsBool uppercase
Definition: gls_font_base.h:135
GlsVector2D startPosition
Definition: gls_font_base.h:118
GlsBool inverse
Definition: gls_font_base.h:127
Definition: gls_image.h:91
Definition: gls_vertex.h:50