GL Studio C++ Runtime API
gls_text.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsText class.
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 
41 #ifndef _GLS_TEXT_H
42 #define _GLS_TEXT_H
43 
44 #include "unhide_globals.h"
45 
46 #include "gls_gl.h"
47 #include <string>
48 
49 #include "glpolygon.h"
50 #include "gls_color.h"
51 #include "gls_cpp_lang_support.h"
52 #include "gls_font_base.h"
53 #include "gls_font_man.h"
55 #include "gls_runtime_font_base.h"
56 #include "gls_unicode_font_base.h"
57 #include "scoped_ptr.h"
58 
59 //===========================================================================
60 // MACROS
61 //===========================================================================
62 #ifdef GLES
63 # define GLS_TEXT_SET_GEOMETRY_REFRESH GeometryRefresh();
64 #else
65 # define GLS_TEXT_SET_GEOMETRY_REFRESH
66 #endif
67 
68 #define SET_ALL_CHARS( attribute, value ) \
69  { \
70  for( CharAttrCont_t::iterator i = _chars.begin(); i != _chars.end(); ++i ) \
71  { \
72  i->attribute = value; \
73  } \
74  GLS_TEXT_SET_GEOMETRY_REFRESH \
75  }
76 
77 //===========================================================================
78 // BEGIN NAMESPACE
79 //===========================================================================
80 namespace disti
81 {
82 #ifdef GLES
83 // Forward Declaration
84 class GlsGloFileAttribute;
85 #endif
86 
87 // Forward Declaration
88 class RuntimeGlyphGenerationText;
89 
90 // Initializers for text
91 typedef enum
92 {
93  GLS_TEXT_BORDER = GLS_LAST_INITIALIZER + 1,
94  GLS_TEXT_CELL_HEIGHT,
95  GLS_TEXT_CELL_WIDTH,
96  GLS_TEXT_CONSTRAIN_CELL_RATIO,
97  GLS_TEXT_CONTROL_CELL_SIZE,
98  GLS_TEXT_FONT,
99  GLS_TEXT_HALO,
100  GLS_TEXT_LINESPACING,
101  GLS_TEXT_LOCK_CELL_SIZE,
102  GLS_TEXT_JUSTIFY,
103  GLS_TEXT_SHADOW,
104  GLS_TEXT_STRING,
105  GLS_TEXT_UPPERCASE,
106  GLS_TEXT_WRAP,
107  GLS_LAST_TEXT_INITIALIZER = GLS_TEXT_WRAP
108 } GlsTextInitializers_t;
109 
110 /** helper method for safely getting a runtime font base from a font base (if possible)
111  * \param font font in question
112  * \return runtime font else NULL
113  */
115 {
116  GlsRuntimeFontBase* rtf = NULL;
117  if( font )
118  {
119  // determine if font can be safely cast to a runtime font by inspecting the family name
120  if( 0 == font->Family().find( GLS_RUNTIME_FONT_NAME_PREFIX ) )
121  {
122  rtf = static_cast<GlsRuntimeFontBase*>( (GlsFontBase*)font );
123  }
124  }
125  return ( rtf );
126 }
127 
128 /** helper method for safely getting a unicode font base from a font base (if possible)
129  * \param font font in question
130  * \return unicode font else NULL
131  */
133 {
134  const GlsUnicodeFontBase* unf = NULL;
135  if( font )
136  {
137  // determine if font can be safely cast to a unicode font by inspecting the family name
138  if( 0 == font->Family().find( GLS_UNICODE_FONT_NAME_PREFIX ) )
139  {
140  unf = static_cast<const GlsUnicodeFontBase*>( font );
141  }
142  }
143  return ( unf );
144 }
145 
146 //===========================================================================
147 /**
148 * The GlsText class provides a base class for all GLStudio text components.
149 */
150 //===========================================================================
151 class GlsText : public GLPolygon
152 {
153 public:
154  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
155  typedef GLPolygon _BaseClass;
156  typedef GLPolygon BaseClass;
157 
158  typedef GlsFontBase::Char_t Char_t;
159 
160  // Carriage return (end of line) character
161  static GLS_EXPORT const Char_t EOL;
162 
163  enum
164  {
165  NUM_VERTICES = 4
166  };
167 
168  /// Different text justifications.
170  {
171  LEFT,
172  CENTER,
173  RIGHT
174  };
175 
176  /// Attributes for each character position in the grid.
177  struct CharAttr_t
178  {
179  Char_t code;
180  float baselineShift;
181  GlsColor bgColor;
182  GlsColor fgColor;
183  bool fauxBold;
184  bool inverse;
185  float scale;
186  float spacing;
187  bool strikeThru;
188  bool underline;
189 
190  //----------------------------------------------------------------------
191  GLS_EXPORT CharAttr_t();
192 
193  //----------------------------------------------------------------------
194  GLS_EXPORT CharAttr_t( const CharAttr_t& r );
195 
196  //----------------------------------------------------------------------
197  GLS_EXPORT void Clear();
198 
199  //----------------------------------------------------------------------
200  GLS_EXPORT CharAttr_t& operator=( const CharAttr_t& r );
201  };
202 
203  /** Class Constructor. */
204  GLS_EXPORT GlsText();
205  GLS_EXPORT GlsText( const GlsText& that, const bool generateNames );
206 
207  /** Class Constructor. */
208  GLS_EXPORT virtual ~GlsText();
209 
210  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
211 
212  /** Sets the baseline shift for all characters.
213  * \param baselineShift multiplier used to shift the baseline. This will
214  * be multiplied by the character height to
215  * determine how much to shift. A value of 0 does
216  * not shift at all, a value of 1 will shift up
217  * by the height of 1 character.
218  */
219  GLS_EXPORT void Baseline( const float& baselineShift );
220 
221  /** Gets the baseline shift for the first character
222  */
223  GLS_EXPORT float Baseline();
224 
225  /** Sets the background color for all characters
226  * \param color The background color to set
227  */
228  GLS_EXPORT void BgColor( const GlsColor& color );
229 
230  /** Gets the background color for the first character
231  */
232  GLS_EXPORT GlsColor BgColor();
233 
234  /** Sets the spacing between the box outline and the text in logical units.
235  * \param units Border offset value in logical units
236  */
237  GLS_EXPORT void Border( const float& units );
238 
239  /** Sets the spacing between the box outline and the text in logical units.
240  */
241  float Border() const
242  {
243  return _border;
244  }
245 
246  /** Sets the height of a character cell of the grid in logical units
247  * when stretch to fit mode is in effect. When stretch to fit mode
248  * is not in effect, this call will not affect the grid since the
249  * font determines the cell size.
250  * \param height the new character cell height.
251  */
252  GLS_EXPORT void CellHeight( float height );
253 
254  /** \return the height of a char cell of the grid in logical units.
255  */
256  float CellHeight() const
257  {
258  return _cellHeight;
259  }
260 
261  /** Sets the width of a character cell of the grid in logical units
262  * when stretch to fit mode is in effect. When stretch to fit mode
263  * is not in effect, this call will not affect the grid since the
264  * font determines the cell size.
265  * \param width the new character cell width.
266  */
267  GLS_EXPORT void CellWidth( float width );
268 
269  /** \return the width of a char cell of the grid in logical units. */
270  float CellWidth() const
271  {
272  return _cellWidth;
273  }
274 
275  /** Sets the character code for all cell positions in the text grid
276  * \param code The Unicode character code to set
277  */
278  GLS_EXPORT void Char( Char_t code );
279 
280  /** Accessor method used by metadata to read and write the character attributes
281  * for this object. Currently only allows you to load and save attributes for the
282  * entire object, not on a per character basis.
283  * \return The character attribute for the first character in the object and therefore
284  * for every character in the object
285  */
287  {
288  return _chars[ 0 ];
289  }
290 
291  /** \return a particular cell's character attributes. */
292  CharAttr_t CharAttr( unsigned int index ) const
293  {
294  return _chars[ index < _chars.size() ? index : 0 ];
295  }
296 
297  /** Sets the scale factor of all characters NOTE: This is the size of the character in its
298  * cell not the overall scale of the entire object
299  * \param newScale The new scale factor of the characters (0.0 < newScale <= 1.0)
300  */
301  GLS_EXPORT void CharScaling( const float& newScale );
302 
303  /** Gets the scale factor of the first character
304  */
305  GLS_EXPORT float CharScaling();
306 
307  /** Sets the horizontal character spacing for all characters (spacing
308  * from the start of one character to the start of the next character.
309  * 1.0 is the default spacing 2.0 would be twice the normal spacing
310  * \param horizontalSpacing The horizontalSpacing value
311  */
312  GLS_EXPORT void CharSpacing( const float& horizontalSpacing );
313 
314  /** Gets the horizontal character spacing for the first character
315  */
316  GLS_EXPORT float CharSpacing();
317 
318  /** Sets whether to constrain cell width and height proportions when
319  * in stretch to fit mode and changing the size of character cells.
320  * \param constrain true to constrain proportions.
321  */
322  GLS_EXPORT void ConstrainCellRatio( bool constrain );
323 
324  /** \return whether to constrain cell width and height proportions when
325  * in stretch to fit mode and changing the size of character cells.
326  */
327  bool ConstrainCellRatio() const
328  {
329  return _constrainRatio;
330  }
331 
332  /** Sets whether or not the character cell size will stretch to fit
333  * this object's bounding box or if it is based on its font and font.
334  * \param control True if stretch to fit will be enabled
335  */
336  GLS_EXPORT void ControlCellSize( bool control );
337 
338  /** \return whether or not the character cell size will stretch to fit
339  * this object's bounding box or if it is based on its font and font
340  */
341  bool ControlCellSize() const
342  {
343  return _controlCellSize;
344  }
345 
346  /* See base class */
347  GLS_EXPORT virtual void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
348 
349  /* See base class */
350  GLS_EXPORT virtual void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
351 
352  /** Erase all characters. */
353  GLS_EXPORT void Erase();
354 
355  /** Set the bold state on or off for all characters
356  * \param bold Bold state
357  */
358  GLS_EXPORT void FauxBold( const bool& bold );
359 
360  /** Gets the bold state on or off for the first character
361  */
362  GLS_EXPORT bool FauxBold();
363 
364  /** \return The font currently being used to render this text.
365  */
366  GlsFontBase* Font() const
367  {
368  return _font;
369  }
370 
371  /** Set the font used to render this text.
372  * \param font Pointer to a font instance to set
373  */
374  GLS_EXPORT void Font( GlsFontBase* font );
375 
376 #ifndef GLES
377  /* See base class */
378  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
379 
380  /* See base class */
381  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
382 #endif
383 
384  /** Set the halo state to on or off for the text
385  * \param halo halo state
386  */
387  GLS_EXPORT void Halo( bool halo );
388 
389  bool Halo() const
390  {
391  return _halo;
392  }
393 
394  /** Set the color of the halo around the text
395  * \param color halo color
396  */
397  GLS_EXPORT void HaloColor( const GlsColor& color );
398 
399  GlsColor HaloColor() const
400  {
401  return _haloColor;
402  }
403 
404  /** Invalidates the font for this object. If the font is invalidated, this object will
405  * draw using the default font. This is used in the editor and should not need to
406  * be called by any user code at run-time.
407  */
408  GLS_EXPORT void InvalidateFont();
409 
410  /** Set the inverse video state on or off for all characters
411  * \param inverse inverse video state
412  */
413  GLS_EXPORT void Inverse( const bool& inverse );
414 
415  /** Gets the inverse video state on or off for the first character
416  */
417  GLS_EXPORT bool Inverse();
418 
419  /** Set the justification mode for this text object
420  * \param justification The justification mode (LEFT, RIGHT, CENTER)
421  */
422  GLS_EXPORT void Justify( Justify_t justification );
423 
424  /** \return the justification mode (LEFT, RIGHT, CENTER)*/
426  {
427  return _justify;
428  }
429 
430  /** Sets the linespacing for the text object. A line spacing of 1.0 indicates normal
431  * "single spaced" text. 2.0 would be double spaced, etc.
432  * \param spacing The new linespacing value
433  */
434  GLS_EXPORT void LineSpacing( float spacing );
435 
436  /** \return the linespacing for the text object. */
437  float LineSpacing() const
438  {
439  return _lineSpacing;
440  }
441 
442  /** Sets whether or not the cell size is locked while in stretch to fit
443  * mode. If locked, changing other attributes will not affect the
444  * cell size, but the box size instead. If not locked, changing
445  * certain attributes, eg. border, will affect the cell size.
446  * \param lock true to lock cell size, false otherwise
447  */
448  GLS_EXPORT void LockCellSize( bool lock );
449 
450  /** \return the setting of lock cell size. */
451  bool LockCellSize() const
452  {
453  return _lockCellSize;
454  }
455 
456 #if !defined( GCC_2_95 )
457  /* Unhides base class implementation. */
458  using BaseClass::Rotate;
459 #endif
460 
461  /* See base class */
462  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
463 
464  /* See base class */
465  virtual GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
466 
467 #ifdef GLES
468  /** Set a single attribute from the GLO file.
469  * \param data The attribute to set and its associated data.
470  */
471  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
472 #endif
473 
474  /** Set the shadow state to on or off for the text
475  * \param shadow shadow state
476  */
477  GLS_EXPORT void Shadow( bool shadow );
478 
479  bool Shadow() const
480  {
481  return _shadow;
482  }
483 
484  /** Set the color of the shadow behind the text
485  * \param color shadow color
486  */
487  GLS_EXPORT void ShadowColor( const GlsColor& color );
488 
489  GlsColor ShadowColor() const
490  {
491  return _shadowColor;
492  }
493 
494  /** Set the distance of the shadow from the text. Distance represent a percentage of the character
495  * width. Negative values are up and to the left. Positive values are down and to the right. Note that the
496  * corresponding getter was removed because ShadowDistance is deprecated in favor of ShadowOffset.
497  * \param dist shadow distance
498  */
499  void ShadowDistance( const float& dist )
500  {
501  ShadowOffset( Vector( dist, -dist, 0.0f ) );
502  }
503 
504  /** Set the Cartesian offset of the shadow from the text. Offset represent a percentage of the character
505  * width. Negative values are down and to the left. Positive values are up and to the right.
506  * Z component is ignored.
507  * \param offset shadow offset
508  */
509  GLS_EXPORT void ShadowOffset( const Vector& offset );
510 
511  Vector ShadowOffset()
512  {
513  return _shadowOffset;
514  }
515 
516  /** Sets the strikethru state for all characters
517  * \param strike Whether or not set strikethru
518  */
519  GLS_EXPORT void StrikeThru( const bool& strike );
520 
521  /** Gets the strikethru state for the first character
522  */
523  GLS_EXPORT bool StrikeThru();
524 
525  /** Sets the Unicode string to be displayed for this object
526  * \param s STD Template Library String
527  */
528  virtual GLS_EXPORT void String( const std::string& s );
529 
530  /** Sets the Unicode string to be displayed for this object
531  * \param s C Style string
532  */
533  virtual void String( const char* s )
534  {
535  String( std::string( s ) );
536  }
537 
538  /** \return The string currently stored in this object.
539  * NOTE: This can contain extra characters not being displayed
540  * in the grid if the string size is greater than will
541  * fit within the grid.
542  */
543  std::string String() const
544  {
545  return _text;
546  }
547 
548  /** Sets the foreground color for all characters in the text grid.
549  * \param color The foreground color to set
550  */
551  GLS_EXPORT void TextColor( const GlsColor& color );
552 
553  /** Gets the foreground color for the first character in the text grid.
554  */
555  GLS_EXPORT GlsColor TextColor();
556 
557  /** Turns on/off underlines for all characters
558  * \param underline Whether or not to enable underline
559  */
560  GLS_EXPORT void Underline( const bool& underline );
561 
562  /** Gets the on/off state of underline for the first character
563  */
564  GLS_EXPORT bool Underline();
565 
566  /** Makes all characters uppercase when rendered.
567  * \param uppercase Whether or not to enable uppercase
568  */
569  GLS_EXPORT void Uppercase( bool uppercase );
570  bool Uppercase() const
571  {
572  return _uppercase;
573  }
574 
575  /** Enable/disable word wrap behavior for this object
576  * \param wrap Whether or not to enable word wrap
577  */
578  GLS_EXPORT void WrapText( bool wrap );
579 
580  /** \return current word wrap behavior for this object */
581  bool WrapText() const
582  {
583  return _wrapText;
584  }
585 
586  /** Sets the rebuild flag, which forces the text object to rebuild itself on the next call to Calculate, PreDraw, or Draw. */
587  void SetRebuild()
588  {
589  _needToRebuild = true;
591  }
592 
593  /** whether or not this text object requires a font file to work. If this returns true, the text object may not work with the generated ASCII / UNICODE font types */
594  virtual bool RequiresFontFile() const
595  {
596  return false;
597  }
598 
599 public: // protected is prefered, but VC 7.0 has issues with it.
600  /** Line Segment_t */
602  {
603  public:
604  float x1;
605  float x2;
606  float y;
607  float thickness;
608  float shadowOffsetX;
609  float shadowOffsetY;
610  GlsColor color;
611 
612  LineSegment_t()
613  : x1( 0.0f )
614  , x2( 0.0f )
615  , y( 0.0f )
616  , thickness( 0.0f )
617  , shadowOffsetX( 0.0f )
618  , shadowOffsetY( 0.0f )
619  {
620  }
621 
623  const float segmentX1,
624  const float segmentX2,
625  const float segmentY,
626  const float segmentThickness,
627  const float segmentShadowOffsetX,
628  const float segmentShadowOffsetY,
629  const GlsColor& segmentColor )
630  : x1( segmentX1 )
631  , x2( segmentX2 )
632  , y( segmentY )
633  , thickness( segmentThickness )
634  , shadowOffsetX( segmentShadowOffsetX )
635  , shadowOffsetY( segmentShadowOffsetY )
636  , color( segmentColor )
637  {
638  }
639  };
640 
641 protected:
642  typedef std::vector<CharAttr_t> CharAttrCont_t;
643 
644  static GLS_EXPORT const Vector XAXIS;
645  static GLS_EXPORT const Vector YAXIS;
646 
647  static GLS_EXPORT Vertex INITIAL_VERTICES[ NUM_VERTICES ];
648 
649  /** The border offset in logical units for this object.
650  * Defines the size of the empty space between the outline of the box
651  * and its text
652  */
653  float _border;
654 
655  /** Container of character attributes */
656  CharAttrCont_t _chars;
657 
658  Vertex _currentVertices[ NUM_VERTICES ];
659 
660  /** Height of each character cell in the grid in logical units */
661  float _cellHeight;
662 
663  /** Width of each character cell in the grid in logical units */
664  float _cellWidth;
665 
666  /** Only effective when _controlCellSize is true. Whether or not to
667  * constrain cell size ratio when changing cell height or width.
668  */
670 
671  /** If true, font size does not control cell size */
673 
674  /** Current font being used for the text */
676 
677  /* Whether or not the halo effect is on. */
678  bool _halo;
679 
680  /** Color of the halo effect behind the characters */
682 
683  /** Justification setting (LEFT, RIGHT, CENTER) */
685 
686  /** Line spacing between grid rows as a percentage */
688 
689  /** Only effective when _controlCellSize is true. If true, changes to
690  * rows, columns, border, line spacing, column spacing, etc. will
691  * not change the cell size. Normally, when _controlCellSize is true
692  * these attributes affect the cell size.
693  */
695 
696  /** This is set to true whenever an attribute changes that will affect
697  * the size of the grid or its cells.
698  */
700 
701  /* Whether or not the shadow effect is on. */
702  bool _shadow;
703 
704  /** Color of the shadow effect behind the characters */
706 
707  /** Offset of the shadow effect from the characters. Z component is ignored. */
709 
710  /** String of text to be displayed. */
711  std::string _text;
712 
713  /** If true, all characters will be displayed in uppercase */
715 
716  /** Direction vector indicating direction of horizontal travel for rendering */
718 
719  /** Direction vector indicating direction of vertical travel for rendering */
721 
722  /** Normal to the Vx Vy plane */
724 
725  /** Whether or not to word wrap text */
726  bool _wrapText;
727 
728  //-----------------------------------------------------------------------
729  /**
730  * Draw a line by rendering a filled polygon with a line around it so that
731  * the thickness scales and anti-aliasing will work if enabled.
732  */
733  //-----------------------------------------------------------------------
734 public: // protected is preferred, but VC 7.0 has issues with it.
735 #ifndef GLES
736  static void DrawScalableLine(
737  GLfloat x1, // Left point
738  GLfloat y1, // Top point
739  GLfloat x2, // Right Point
740  GLfloat y2 ) // Bottom Point
741  {
742  // APR: The Text Objects send x1,y1 as TOP-RIGHT. Rewrote glVertex calls to support CCW drawing.
743  glBegin( GL_POLYGON );
744  glVertex2f( x1, y1 );
745  glVertex2f( x1, y2 );
746  glVertex2f( x2, y2 );
747  glVertex2f( x2, y1 );
748  glEnd();
749  /*
750  glBegin(GL_LINE_LOOP);
751  glVertex2f(x1, y1);
752  glVertex2f(x2, y1);
753  glVertex2f(x2, y2);
754  glVertex2f(x1, y2);
755  glEnd();
756  */
757  }
758 #endif
759 protected:
760  /**
761  * Allocate a text buffer of the appropriate size for this grid and output snprintf style format
762  * into the buffer
763  * \param format snprintf style format spec
764  * \param args arguments for sprintf style formatting
765  * \param initialBufferLength the length of the initial character buffer
766  * \return formatted textbuffer ( must be deleted by caller )
767  */
768  GLS_EXPORT char* FormatVarArgList( const int initialBufferLength, const char* format, va_list args );
769 
770  //-----------------------------------------------------------------------
771  /**
772  */
773  //-----------------------------------------------------------------------
774  GLS_EXPORT void RecalcDirectionVectors();
775 
776  /** Pointer to the internal data needed for runtime glyph generation. */
778 
779 private:
780  // Allow derived classes to perform a custom action when cell height/width changes.
781  virtual GLS_EXPORT void OnCellDimensionChanged()
782  {}
783 
784  // Disable copying.
785  GlsText( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
786  void operator=( const GlsText& ) DISTI_SPECIAL_MEM_FUN_DELETE;
787 };
788 
789 //---------------------------------------------------------------------------
790 // Stream operators for text enumeration types
791 //---------------------------------------------------------------------------
792 inline std::istream& operator>>(
793  std::istream& instr, disti::GlsText::Justify_t& j )
794 {
795  std::string str;
796  instr >> str;
797 
798  if( str == "LEFT" )
799  {
800  j = disti::GlsText::LEFT;
801  }
802  else if( str == "CENTER" )
803  {
804  j = disti::GlsText::CENTER;
805  }
806  else if( str == "RIGHT" )
807  {
808  j = disti::GlsText::RIGHT;
809  }
810  return instr;
811 }
812 
813 //---------------------------------------------------------------------------
814 inline std::ostream& operator<<( std::ostream& outstr, disti::GlsText::Justify_t j )
815 {
816  switch( j )
817  {
818  case disti::GlsText::LEFT:
819  outstr << "LEFT";
820  break;
821  case disti::GlsText::CENTER:
822  outstr << "CENTER";
823  break;
824  case disti::GlsText::RIGHT:
825  outstr << "RIGHT";
826  break;
827  }
828  return outstr;
829 }
830 
831 //===========================================================================
832 /**
833 * Attributes of a text character.
834 * NOTE: Use of this attribute is deprecated.
835 * Instead use individual top-level attributes such as ("FauxBold" and "TextColor").
836 */
837 //===========================================================================
839 {
840 public:
841  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
842  typedef DistiAttributeDictionaryAttribute _BaseClass;
843  typedef DistiAttributeDictionaryAttribute BaseClass;
844 
845  GlsTextCharAttr( const AttributeName& name, GlsText* text );
846 
847  virtual ~GlsTextCharAttr()
848  {
849  delete _dict;
850  }
851 
852  // Do not write out, because this interface is only for backward
853  // compatability
854  virtual bool OkToWrite() const
855  {
856  return false;
857  }
858 
859  virtual std::ostream& WriteValue( std::ostream& outstr )
860  {
861  _charAttr = _text->CharAttr( 0 );
862  return BaseClass::WriteValue( outstr );
863  }
864  virtual std::istream& ReadValue( std::istream& instr )
865  {
866  // First get _charAttr to the current value.
867  // This is because the instr may not contain
868  // new values for all the attributes.
869  _charAttr = _text->CharAttr( 0 );
870 
871  BaseClass::ReadValue( instr );
872 
873  _text->Baseline( _charAttr.baselineShift );
874  _text->BgColor( _charAttr.bgColor );
875  _text->CharSpacing( _charAttr.spacing );
876  _text->TextColor( _charAttr.fgColor );
877  _text->FauxBold( _charAttr.fauxBold );
878  _text->Inverse( _charAttr.inverse );
879  _text->CharScaling( _charAttr.scale );
880  _text->StrikeThru( _charAttr.strikeThru );
881  _text->Underline( _charAttr.underline );
882 
883  return instr;
884  }
885 
886 protected:
887  GlsText* _text;
888  GlsText::CharAttr_t _charAttr;
889 };
890 
891 } // namespace disti
892 
893 DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const disti::GlsText::CharAttr_t& c );
894 DISTI_EXPORT std::istream& operator>>( std::istream& instr, disti::GlsText::CharAttr_t& c );
895 
896 #endif
The DistiUnhideGlobalsDummyClass class.
Vector _vX
Definition: gls_text.h:717
float Baseline()
void InvalidateFont()
void ShadowOffset(const Vector &offset)
Definition: vertex.h:409
bool _uppercase
Definition: gls_text.h:714
virtual void CopyProperties(DisplayObject *src) override
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
virtual bool OkToWrite() const
Definition: gls_text.h:854
bool ConstrainCellRatio() const
Definition: gls_text.h:327
#define GLS_UNICODE_FONT_NAME_PREFIX
Definition: gls_font_man.h:50
Definition: dynamic_array.h:66
virtual std::istream & ReadValue(std::istream &instr)
Definition: gls_text.h:864
virtual void SetValue(int spec, va_list &args) override
char * FormatVarArgList(const int initialBufferLength, const char *format, va_list args)
The disti::GlsFontBase class and related classes.
The Polygon class. Implements Polygons.
Definition: glpolygon.h:55
bool _constrainRatio
Definition: gls_text.h:669
Attributes for each character position in the grid.
Definition: gls_text.h:177
Justify_t _justify
Definition: gls_text.h:684
virtual bool RequiresFontFile() const
Definition: gls_text.h:594
float LineSpacing() const
Definition: gls_text.h:437
GlsColor TextColor()
Definition: display.h:98
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) override
Definition: gls_text.h:838
void ShadowDistance(const float &dist)
Definition: gls_text.h:499
The disti::GLPolygon class. Implements Polygons.
float _cellHeight
Definition: gls_text.h:661
Definition: gls_text.h:151
std::string _text
Definition: gls_text.h:711
CharAttrCont_t _chars
Definition: gls_text.h:656
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
GlsColor BgColor()
The Color class: Implements a 4 component RGBA color.
Justify_t
Different text justifications.
Definition: gls_text.h:169
float _lineSpacing
Definition: gls_text.h:687
void Char(Char_t code)
Definition: gls_glo_file.h:988
Definition: gls_unicode_font_base.h:65
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
Defines the stream out operator.
Justify_t Justify() const
Definition: gls_text.h:425
ScopedPtr< RuntimeGlyphGenerationText > _runtimeGlyphGenerationText
Definition: gls_text.h:777
GlsRuntimeFontBase * GetGlsRuntimeFontBase(const GlsFontBase *font)
Definition: gls_text.h:114
float CellWidth() const
Definition: gls_text.h:270
bool LockCellSize() const
Definition: gls_text.h:451
The disti::GlsFontMan class.
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
VertexNoColor Vector
Definition: gls_font_base.h:66
bool _lockCellSize
Definition: gls_text.h:694
bool _controlCellSize
Definition: gls_text.h:672
float _border
Definition: gls_text.h:653
bool ControlCellSize() const
Definition: gls_text.h:341
CharAttr_t CharAttribs() const
Definition: gls_text.h:286
GlsColor _haloColor
Definition: gls_text.h:681
Definition: gls_runtime_font_base.h:66
static void DrawScalableLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
Definition: gls_text.h:736
bool WrapText() const
Definition: gls_text.h:581
Definition: gls_color.h:53
virtual void Rotate(float angle, int axis=Z_AXIS)
GlsFontBase * Font() const
Definition: gls_text.h:366
Vector _vZ
Definition: gls_text.h:723
float _cellWidth
Definition: gls_text.h:664
virtual std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_text.h:859
float CharScaling()
CharAttr_t CharAttr(unsigned int index) const
Definition: gls_text.h:292
float CharSpacing()
Vector _vY
Definition: gls_text.h:720
Defines templated metadata classes for DisplayObjects and other uses.
GlsFontBase * _font
Definition: gls_text.h:675
Definition: gls_metadata_attributes.h:617
The disti::GlsUnicodeFontBase class and related classes.
std::string String() const
Definition: gls_text.h:543
Definition: vertex.h:84
void SetRebuild()
Definition: gls_text.h:587
A smart pointer with unique ownership – poor man's std::unique_ptr.
virtual void CopyGeometry(DisplayObject *src) override
bool _wrapText
Definition: gls_text.h:726
const GlsUnicodeFontBase * GetGlsUnicodeFontBase(const GlsFontBase *font)
Definition: gls_text.h:132
virtual void SetAvailableAttributes(unsigned int value) override
std::string Family() const
Definition: gls_font_base.h:258
Vector _shadowOffset
Definition: gls_text.h:708
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual void String(const char *s)
Definition: gls_text.h:533
Definition: disti_metadata.h:85
bool _needToRebuild
Definition: gls_text.h:699
Definition: bmpimage.h:46
float Border() const
Definition: gls_text.h:241
virtual ~GlsText()
Definition: gls_text.h:601
The disti::GlsRuntimeFontBase class and related classes.
float CellHeight() const
Definition: gls_text.h:256
GlsColor _shadowColor
Definition: gls_text.h:705
Definition: gls_font_base.h:85
The gls_gl.
#define GLS_RUNTIME_FONT_NAME_PREFIX
Definition: gls_font_man.h:53