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

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___GLBITMAPFONT__HPP
2 #define GUI_OPENGL___GLBITMAPFONT__HPP
3 
4 /* $Id: glbitmapfont.hpp 42673 2019-04-01 19:18:57Z katargir $
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  *
33  */
34 
35 #include <gui/opengl/glfont.hpp>
36 
37 #include <set>
38 
39 /** @addtogroup GUI_OPENGL
40  *
41  * @{
42  */
43 
45 
46 //
47 // Stand-in for GLUT fonts. This uses glBitmap directly.
48 //
50 {
51 public:
52  enum EFontSize {
53  eFontSize_6 = 6,
54  eFontSize_8 = 8,
55  eFontSize_10 = 10,
56  eFontSize_12 = 12,
57  eFontSize_14 = 14,
58  eFontSize_18 = 18,
59  eFontSize_20 = 20,
60  eFontSize_24 = 24
61  };
62 
63  enum EFontFace {
64  eFontFace_Bitmap = 0x0100,
65  eFontFace_Helvetica = 0x0200,
66  eFontFace_Lucida = 0x0300,
67  eFontFace_Courier = 0x0400,
68  eFontFace_Clean = 0x0500,
69  eFontFace_Fixed = 0x0600,
70  eFontFace_TimesRoman = 0x0700
71  };
72 
73  enum EFontRotate {
75  eFontRotate_90_Cap, // new baseline along cap height
76  eFontRotate_90_Base, // original base line
81  eFontRotate_90 = eFontRotate_90_Cap,
82  eFontRotate_180 = eFontRotate_180_Cap,
83  eFontRotate_270 = eFontRotate_270_Base
84  };
85 
86  enum EFont {
87  // fixed size fonts
88  // here, size doesn't map 1:1
89  eBitmap5x7 = eFontFace_Bitmap | 8, //eFontSize_8,
90  eBitmap8x13 = eFontFace_Bitmap | 12, //eFontSize_12,
91  eBitmap9x15 = eFontFace_Bitmap | 14, //eFontSize_14,
92  eBitmap10x20 = eFontFace_Bitmap | 18, //eFontSize_18,
93  eBitmap12x24 = eFontFace_Bitmap | 24, //eFontSize_24,
94 
95  // helvetica
96  eHelvetica6 = eFontFace_Helvetica | 6, //eFontSize_6,
97  eHelvetica8 = eFontFace_Helvetica | 8, //eFontSize_8,
98  eHelvetica10 = eFontFace_Helvetica | 10, //eFontSize_10,
99  eHelvetica12 = eFontFace_Helvetica | 12, //eFontSize_12,
100  eHelvetica14 = eFontFace_Helvetica | 14, //eFontSize_14,
101  eHelvetica18 = eFontFace_Helvetica | 18, //eFontSize_18,
102  eHelvetica20 = eFontFace_Helvetica | 20, //eFontSize_20,
103  eHelvetica24 = eFontFace_Helvetica | 24, //eFontSize_24,
104 
105  // lucida
106  eLucida6 = eFontFace_Lucida | 6, //eFontSize_6,
107  eLucida8 = eFontFace_Lucida | 8, //eFontSize_8,
108  eLucida10 = eFontFace_Lucida | 10, //eFontSize_10,
109  eLucida12 = eFontFace_Lucida | 12, //eFontSize_12,
110  eLucida14 = eFontFace_Lucida | 14, //eFontSize_14,
111  eLucida18 = eFontFace_Lucida | 18, //eFontSize_18,
112  eLucida20 = eFontFace_Lucida | 20, //eFontSize_20,
113  eLucida24 = eFontFace_Lucida | 24, //eFontSize_24,
114 
115  // courier
116  eCourier6 = eFontFace_Courier | 6, //eFontSize_6,
117  eCourier8 = eFontFace_Courier | 8, //eFontSize_8,
118  eCourier10 = eFontFace_Courier | 10, //eFontSize_10,
119  eCourier12 = eFontFace_Courier | 12, //eFontSize_12,
120  eCourier14 = eFontFace_Courier | 14, //eFontSize_14,
121  eCourier18 = eFontFace_Courier | 18, //eFontSize_18,
122  eCourier20 = eFontFace_Courier | 20, //eFontSize_20,
123  eCourier24 = eFontFace_Courier | 24, //eFontSize_24,
124 
125  // clean
126  eClean6 = eFontFace_Clean | 6, //eFontSize_6,
127  eClean8 = eFontFace_Clean | 8, //eFontSize_8,
128  eClean10 = eFontFace_Clean | 10, //eFontSize_10,
129  eClean12 = eFontFace_Clean | 12, //eFontSize_12,
130  eClean14 = eFontFace_Clean | 14, //eFontSize_14,
131  eClean18 = eFontFace_Clean | 18, //eFontSize_18,
132  eClean20 = eFontFace_Clean | 20, //eFontSize_20,
133  eClean24 = eFontFace_Clean | 24, //eFontSize_24,
134 
135  // fixed
136  eFixed6 = eFontFace_Fixed | 6, //eFontSize_6,
137  eFixed8 = eFontFace_Fixed | 8, //eFontSize_8,
138  eFixed10 = eFontFace_Fixed | 10, //eFontSize_10,
139  eFixed12 = eFontFace_Fixed | 12, //eFontSize_12,
140  eFixed14 = eFontFace_Fixed | 14, //eFontSize_14,
141  eFixed18 = eFontFace_Fixed | 18, //eFontSize_18,
142  eFixed20 = eFontFace_Fixed | 20, //eFontSize_20,
143  eFixed24 = eFontFace_Fixed | 24, //eFontSize_24,
144 
145  // Times Roman
146  eTimesRoman6 = eFontFace_TimesRoman | 6, //eFontSize_6,
147  eTimesRoman8 = eFontFace_TimesRoman | 8, //eFontSize_8,
148  eTimesRoman10 = eFontFace_TimesRoman | 10, //eFontSize_10,
149  eTimesRoman12 = eFontFace_TimesRoman | 12, //eFontSize_12,
150  eTimesRoman14 = eFontFace_TimesRoman | 14, //eFontSize_14,
151  eTimesRoman18 = eFontFace_TimesRoman | 18, //eFontSize_18,
152  eTimesRoman20 = eFontFace_TimesRoman | 20, //eFontSize_20,
153  eTimesRoman24 = eFontFace_TimesRoman | 24 //eFontSize_24
154  };
155 
156  // default constructor. This creates a font for the 8x13 bitmap font
157  // face
158  CGlBitmapFont(void);
159 
160  // create a bitmap font with a particular face in mind
161  CGlBitmapFont(EFont font);
162 
163  //CGlBitmapFont(const CGlBitmapFont&);
165 
166  // destructor
167  ~CGlBitmapFont();
168 
169  // set the font to one of the predefined options
170  void SetFont(EFont font);
171  EFont GetFont() const;
172  void SetFontFace(EFontFace face);
173  EFontFace GetFontFace() const;
174  void SetFontSize(EFontSize size);
175  EFontSize GetFontSize() const;
176 
177  void SetFontRotate(EFontRotate rot);
178  EFontRotate GetFontRotate(void) const;
179 
180  void SetCondensed(bool condensed);
181  bool IsCondensed(void) const;
182 
183  // Dump some text somewhere
184  virtual void TextOut(const char* text) const;
185  virtual void TextOut(TModelUnit x, TModelUnit y, const char* text) const;
186 
187  // Output text into a given rectangle using a particular alignment.
188  // The alignment is a bitmask of FLTK's Fl_Align enums. The only
189  // distinction is that text is *always* inside. Alignment is specified
190  // reative to the text
191  void TextOut(TModelUnit x1, TModelUnit y1, TModelUnit x2, TModelUnit y2, const char* text,
192  TAlign align = eAlign_Center,
193  ETruncate trunc = eTruncate_Ellipsis,
194  TModelUnit scale_x = 1.0, TModelUnit scale_y = 1.0) const;
195 
196  string Truncate(const char*, TModelUnit w, ETruncate trunc = eTruncate_Ellipsis) const;
197  string Truncate(const string& str, TModelUnit w, ETruncate trunc = eTruncate_Ellipsis) const;
198 
199  /// prints array of characters in positions (x + i*dx, y + i*dy) where
200  /// "i" is index of a character in the given string
201  void ArrayTextOut(TModelUnit x, TModelUnit y, TModelUnit dx, TModelUnit dy,
202  const char* text,
203  const vector<CRgbaColor*>* colors = NULL,
204  TModelUnit scale_x = 1.0f,
205  TModelUnit scale_y = 1.0f) const;
206 
207  // Determine how much space a piece of text will occupy
208  virtual TModelUnit TextWidth (const char* text) const;
209  virtual TModelUnit TextWidth (const char* text, int n) const;
210  virtual TModelUnit TextHeight(void) const;
211  virtual TModelUnit GetFontDescender() const;
212  TModelUnit GetAdvance(char c) const;
213 
214  // generic metric retrieval
215  virtual TModelUnit GetMetric(EMetric metric, const char* text_start = NULL,
216  int len = -1) const;
217 
218  // funtions below provide conversion of font parameters to strings and
219  // back. This can be handy for representing them in GUI.
220  static string FaceToString(EFontFace face);
221  static EFontFace FaceFromString(const string& str);
222 
223  static string SizeToString(EFontSize size);
224  static EFontSize SizeFromString(const string& str);
225  static EFontSize SizeFromInt(int i);
226 
227  // saves and restores font face and size in(from) a string
228  string ToString() const;
229  void FromString(const string& value);
230 
231  // GetAllFaces() and GetAllSizes() fill given container with strings
232  // repesenting all faces/sizes available
233  static void GetAllFaces(vector<string>& faces);
234  static void GetAllSizes(vector<string>& sizes);
235 
236 protected:
237  const void* GetFontPtr(const CGlBitmapFont::EFontRotate rot) const;
238  const void* GetFontPtr() const;
239 
240 private:
241  // Truncate a string for display. This returns the maximum
242  // number of characters that can fit into the given width. If the
243  // parameter 'str' is not null, the string will be filled out with
244  // the truncated text.
245  int x_Truncate(const char* text, TModelUnit w, ETruncate trunc,
246  string* str = NULL) const;
247 
248 private:
249  EFont m_Font; /// The font - combination of face and size
250 
251  EFontRotate m_FontRotate; /// rotation state of the font
252 
253  bool m_Condensed; /// render condensed
254 };
255 
256 
257 /// temporary placed here, later should be moved to the appropriate location
259 {
260 public:
261  static string FormatSeparatedNumber(int number, bool b_postfix = false);
262 
263  /// returns number of characters in symbolic representation of the given
264  /// number including non-digit separators ( 1,234 or 1,234,567)
265  static int GetCharsCount(int number);
266 
267  /// returns minimal space sufficient to render any number
268  /// in the range [0, max_num]. It is assumed that text is symbolic
269  /// representation of a number is produced by FormatSeparatedNumber().
270  static TModelUnit GetMaxWidth(int max_num, const CGlBitmapFont& font);
271 
272  // Set raster position safely - normally if the raster position is outside
273  // of the window boundary it is invalid and no text is displayed - even
274  // subsequent text which should be in the window.
275  static void SetRasterPosSafe(TModelUnit x, TModelUnit y);
276 };
277 
278 
280 
281 /* @} */
282 
283 #endif // GUI_OPENGL___GLBITMAPFONT__HPP
static int trunc
Definition: array_out.c:8
temporary placed here, later should be moved to the appropriate location
static const Colors colors
Definition: cn3d_colors.cpp:50
char value[7]
Definition: config.c:431
#define NULL
Definition: ncbistd.hpp:225
GLdouble TModelUnit
Definition: gltypes.hpp:48
virtual TModelUnit TextWidth(const char *text) const =0
EFontRotate m_FontRotate
The font - combination of face and size.
virtual void TextOut(const char *text) const =0
bool m_Condensed
rotation state of the font
virtual TModelUnit TextHeight(void) const =0
virtual TModelUnit GetMetric(EMetric metric, const char *text=NULL, int len=-1) const =0
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CTime Truncate(const CTime &t)
Definition: ncbitime.hpp:2195
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
int i
yy_size_t n
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
static BOOL number
Definition: pcregrep.c:193
static const char * str(char *buf, int n)
Definition: stats.c:84
string ToString(const wxRect &rc)
Definition: wx_utils.cpp:773
Modified on Thu Feb 29 12:22:35 2024 by modify_doxy.py rev. 669887