NCBI C++ ToolKit
glfont.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GL_FONT__HPP
2 #define GUI_OPENGL___GL_FONT__HPP
3 
4 /* $Id: glfont.hpp 44930 2020-04-21 17:07:30Z evgeniev $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  * CGlFont -- base class for OpenGL fonts
33  * CGlutFont -- GLUT based bitmap fonts
34  */
35 
36 
37 #include <corelib/ncbiobj.hpp>
38 
39 #include <gui/opengl.h>
40 #include <gui/opengl/gltypes.hpp>
41 #include <gui/utils/rgba_color.hpp>
42 
43 #include <map>
44 
45 
46 /** @addtogroup GUI_OPENGL
47  *
48  * @{
49  */
50 
52 
53 
54 //
55 // Interface class for all OpenGL fonts.
56 //
57 
58 class IGlFont : public CObject
59 {
60 public:
61  // text truncation types
62  enum ETruncate {
63  // do not attempt any kind of truncation
65 
66  // simply chop the string without providing any details
68 
69  // truncate and append an ellipsis
71  };
72 
73  // metric types
74  enum EMetric {
75  // return the height of a capital letter
77 
78  // return the height of all possible character, including
79  // ascents and descents
81 
82  // return the widths of all characters
84 
85  // return the maximum width of all characters
87 
88  // return the length of a given string without the final advance
89  // (this is the entire space taken up by only this string)
91 
92  // return the length of a given string with the final advance
94 
95  // return the font descener for a given string
97  };
98 
99  /// alignment modes
100  enum EAlignMode {
102  eAlign_Left = 0x0001,
103  eAlign_HCenter = 0x0002,
104  eAlign_Right = 0x0004,
105 
106  eAlign_VertMask = 0x00f0,
107  eAlign_Top = 0x0010,
108  eAlign_VCenter = 0x0020,
109  eAlign_Bottom = 0x0040,
110 
112  };
113  typedef int TAlign;
114 
115  // must provide default ctor - copy ctor is private
116  IGlFont(void) {}
117 
118  // destructor
119  virtual ~IGlFont(void) {}
120 
121  // Print the appropriate text on the screen. This function uses the
122  // current raster position.
123  virtual void TextOut(const char* text) const = 0;
124 
125  // Print some text on the screen. This function uses a specified
126  // raster position.
127  virtual void TextOut(TModelUnit x, TModelUnit y, const char* text) const = 0;
128 
129  // Output text into a given rectangle using a particular alignment.
131  const char* text,
132  TAlign align = eAlign_Center,
134  TModelUnit scale_x = 1.0,
135  TModelUnit scale_y = 1.0) const = 0;
136 
137  /// This is needed by pdf but really on for gltexture font subclass since those
138  /// may be either texture or (for clarity at small screen size) bitmap
139  virtual bool IsBitmapFont() const { return true; }
140 
141  // Determine how much space a piece of text will occupy. This
142  // is intended *not* to include the final advance!
143  virtual TModelUnit TextWidth(const char* text) const = 0;
144 
145  // determine the text height
146  virtual TModelUnit TextHeight(void) const = 0;
147 
148  // query the font for certain metrics
149  virtual TModelUnit GetMetric(EMetric metric,
150  const char* text = NULL,
151  int len = -1) const = 0;
152 };
153 
154 
155 //
156 // Utility class for managing font encoding / interception in feedback mode
157 //
158 
160 {
161 public:
162 
163  enum
164  {
165  eBeginText = 0xBAAB,
166  eEndText = 0xCBBC,
167  ePosition = 0xFCEB,
168  eColor = 0xEFBA
169  };
170 
171  union FPackChar
172  {
173  float f;
174  char c[4];
175  };
176 
177  static vector<float> EncodeText(GLfloat pos[4],
178  const CRgbaColor& color,
179  const char* text,
180  size_t length);
181 
182  static vector<float> EncodeText(GLfloat pos[4],
183  const CRgbaColor& color,
184  const string& text);
185 
186  static void DecodeText(const vector<float>& textbuf,
187  GLfloat* pos,
188  GLfloat* color,
189  string& text);
190 };
191 
192 
194 
195 /* @} */
196 
197 #endif // GUI_OPENGL___GL_FONT__HPP
CObject –.
Definition: ncbiobj.hpp:180
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static int trunc
Definition: array_out.c:8
#define NULL
Definition: ncbistd.hpp:225
GLdouble TModelUnit
Definition: gltypes.hpp:48
EAlignMode
alignment modes
Definition: glfont.hpp:100
virtual TModelUnit TextWidth(const char *text) const =0
static vector< float > EncodeText(GLfloat pos[4], const CRgbaColor &color, const char *text, size_t length)
Definition: glfont.cpp:57
virtual void TextOut(const char *text) const =0
static void DecodeText(const vector< float > &textbuf, GLfloat *pos, GLfloat *color, string &text)
Definition: glfont.cpp:104
virtual bool IsBitmapFont() const
This is needed by pdf but really on for gltexture font subclass since those may be either texture or ...
Definition: glfont.hpp:139
virtual TModelUnit TextHeight(void) const =0
virtual void TextOut(TModelUnit x, TModelUnit y, const char *text) const =0
IGlFont(void)
Definition: glfont.hpp:116
virtual TModelUnit GetMetric(EMetric metric, const char *text=NULL, int len=-1) const =0
virtual ~IGlFont(void)
Definition: glfont.hpp:119
virtual void TextOut(TModelUnit x, TModelUnit y, TModelUnit w, TModelUnit h, const char *text, TAlign align=eAlign_Center, ETruncate trunc=eTruncate_Ellipsis, TModelUnit scale_x=1.0, TModelUnit scale_y=1.0) const =0
ETruncate
Definition: glfont.hpp:62
int TAlign
Definition: glfont.hpp:113
@ eAlign_Center
Definition: glfont.hpp:111
@ eAlign_Right
Definition: glfont.hpp:104
@ eAlign_Top
Definition: glfont.hpp:107
@ eAlign_Bottom
Definition: glfont.hpp:109
@ eAlign_Left
Definition: glfont.hpp:102
@ eAlign_VCenter
Definition: glfont.hpp:108
@ eAlign_HorizMask
Definition: glfont.hpp:101
@ eAlign_HCenter
Definition: glfont.hpp:103
@ eAlign_VertMask
Definition: glfont.hpp:106
@ eMetric_FullCharHeight
Definition: glfont.hpp:80
@ eMetric_AvgCharWidth
Definition: glfont.hpp:83
@ eMetric_FullTextWidth
Definition: glfont.hpp:93
@ eMetric_Descender
Definition: glfont.hpp:96
@ eMetric_TextWidth
Definition: glfont.hpp:90
@ eMetric_CharHeight
Definition: glfont.hpp:76
@ eMetric_MaxCharWidth
Definition: glfont.hpp:86
@ eTruncate_Empty
Definition: glfont.hpp:67
@ eTruncate_None
Definition: glfont.hpp:64
@ eTruncate_Ellipsis
Definition: glfont.hpp:70
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
n background color
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Standard mechanism to include OpenGL headers for all platforms.
Modified on Tue Jul 16 13:20:17 2024 by modify_doxy.py rev. 669887