NCBI C++ ToolKit
gltexturefont.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: gltexturefont.cpp 47485 2023-05-02 14:46:59Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Bob Falk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 #include <gui/opengl/glutils.hpp>
37 #include <gui/opengl/irender.hpp>
38 
39 #include <corelib/ncbifile.hpp>
40 
41 #include <math.h>
42 #include <stdio.h>
43 #include <sstream>
44 
45 #include <FTGL/ftgl.h>
46 
47 
49 
50 
51 
53  "NimbusSanL-Regu.ttf", // Helvetica
54  "NimbusSanL-Bold.ttf",
55  "NimbusSanL-ReguItal.ttf",
56  "NimbusSanL-BoldItal.ttf",
57  "LucidaBrightRegular.ttf", // Lucida
58  "LucidaBrightDemiBold.ttf",
59  "LucidaBrightItalic.ttf",
60  "LucidaBrightDemiItalic.ttf",
61  "NimbusMonL-Regu.ttf", //Courier
62  "NimbusMonL-Bold.ttf",
63  "NimbusMonL-ReguObli.ttf",
64  "NimbusMonL-BoldObli.ttf",
65  "dark-courier.ttf", //Fixed
66  "dark-courier-bold.ttf",
67  "dark-courier-italic.ttf",
68  "dark-courier-bold-italic.ttf",
69  "NimbusRomanNo9-Reg.ttf", // Times-Roman
70  "NimbusRomanNo9-Med.ttf",
71  "NimbusRomanNo9-Ita.ttf",
72  "NimbusRomanNo9-MedIta.ttf",
73  "BPmono.ttf", // BPMono - free monospaced bold font by: http://www.1001fonts.com/users/steffmann/
74  "BPmonoBold.ttf",
75  "BPmonoItalics.ttf",
76  "BPmonoBoldStencil.ttf",
77  "LastFontDummy.NotAFile",
78  "Helvetica6.ttf", // Bitmap
79  "Helvetica8.ttf", // Bitmap
80  "Helvetica10.ttf" // Bitmap
81 };
82 
83 string CGlTextureFont::s_FontNames[] = {
84  "Helvetica", // Helvetica
85  "Helvetica Bold",
86  "Helvetica Oblique",
87  "Helvetica Bold Oblique",
88  "Lucida", // Lucida
89  "Lucida Bold",
90  "Lucida Italic",
91  "Lucida Bold Italic",
92  "Courier", //Courier
93  "Courier Bold",
94  "Courier Oblique",
95  "Courier Bold Oblique",
96  "Fixed", //Fixed
97  "Fixed Bold",
98  "Fixed Oblique",
99  "Fixed Bold Oblique",
100  "Times-Roman", // Times-Roman
101  "Times-Roman Bold",
102  "Times-Roman Italic",
103  "Times-Roman Bold Italic",
104  "BPMono", // BPMono (monospaced font)
105  "BPMono Bold",
106  "BPMono Italic",
107  "BPMono Bold Stencil",
108  "Last Font Dummy",
109  "Helvetica Bitmap 6", // Bitmap
110  "Helvetica Bitmap 8", // Bitmap
111  "Helvetica Bitmap 10" // Bitmap
112 };
113 
115 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 21, 24, 36, 48, 60, 72, 0
116 };
117 
118 
120 : m_Font(NULL)
121 , m_FontFace(eFontFace_LastFont)
122 , m_FontSize(12)
123 , m_Rotate(fFontRotateBase)
124 , m_SnapToPixelX(true)
125 , m_SnapToPixelY(true)
126 , m_PrevShader(0)
127 {
129 }
130 
131 CGlTextureFont::CGlTextureFont(const string& font_file_name,
132  unsigned int font_size)
133 : m_Font(NULL)
134 , m_FontFace(eFontFace_LastFont)
135 , m_FontSize(font_size)
136 , m_Rotate(fFontRotateBase)
137 , m_SnapToPixelX(true)
138 , m_SnapToPixelY(true)
139 , m_PrevShader(0)
140 {
141  SetFont(font_file_name, font_size);
142 }
143 
145  unsigned int font_size)
146 : m_Font(NULL)
147 , m_FontFace(face)
148 , m_FontSize(font_size)
149 , m_Rotate(fFontRotateBase)
150 , m_SnapToPixelX(true)
151 , m_SnapToPixelY(true)
152 , m_PrevShader(0)
153 {
154  SetFontFace(face);
155 }
156 
157 void CGlTextureFont::SetFontFace(EFontFace face, bool use_bitmap_overrides)
158 {
159  string font_file = x_GetFontFile(face, m_FontFile, m_FontSize, use_bitmap_overrides);
160  m_FontFace = face;
161 
162  if (font_file != m_FontFile)
163  SetFont(font_file, m_FontSize, use_bitmap_overrides);
164 }
165 
167 {
168  return m_FontFace;
169 }
170 
172 {
173  m_FontSize = size;
174 
175  string font_file = m_FontFile;
176 
177  if (font_file != "")
178  SetFont(font_file, m_FontSize);
179 }
180 
181 unsigned int CGlTextureFont::GetFontSize() const
182 {
183  return m_FontSize;
184 }
185 
186 
187 bool CGlTextureFont::SetFont(string font_file_name,
188  unsigned int font_size,
189  bool use_bitmap_overrides)
190 {
192 
193  font_file_name = x_GetFontFile(m_FontFace, font_file_name, font_size, use_bitmap_overrides);
194 
195  FTFont* font = fm.GetFont(font_file_name.c_str(), font_size);
196 
197  /// Error loading - don't change current font selection
198  if (font==NULL || font->Error())
199  return false;
200 
201  m_FontFile = font_file_name;
202  m_Font = font;
203  m_FontSize = font_size;
204 
206 
207  return true;
208 }
209 
211 {
212  return s_FontFileNames[face];
213 }
214 
215 // This function mirrors x_GetFontFile and what files it chooses to return.
217 {
220  (m_FontSize == 6 || m_FontSize == 8 || m_FontSize == 10)) {
221  return true;
222  }
223 
224  return false;
225 }
226 
227 
228 void CGlTextureFont::SetSnapToPixel(bool xpix, bool ypix)
229 {
230  m_SnapToPixelX = xpix;
231  m_SnapToPixelY = ypix;
232 }
233 
235 {
236  /// Get viewport from OpenGL
239  m_Viewport[1],
240  m_Viewport[2],
241  m_Viewport[3]));
242 }
243 
244 void CGlTextureFont::BeginText(const TVPRect& viewport) const
245 {
246  // avoid pusattrib if possible since it can be very slow
247  //glPushAttrib(GL_ALL_ATTRIB_BITS);
248  IRender& gl = GetGl();
249 
250  // Copy viewport passed in (we can't get it from OpenGL always because
251  // this library also supports some pdf rendering functions and in pdf
252  // output the maximum viewing area generally exceeds the maximum
253  // supported by OpenGL)
254  m_Viewport[0] = GLint(viewport.Left());
255  m_Viewport[1] = GLint(viewport.Bottom());
256  m_Viewport[2] = GLint(viewport.Right());
257  m_Viewport[3] = GLint(viewport.Top());
258 
259  // Get modelview and projection matrices that will be used for
260  // unprojection (getting window coordinates) of text draw location
263 
264  // Set projection matrix to pixel coordinates
265  gl.MatrixMode(GL_PROJECTION);
266  gl.PushMatrix();
267  gl.LoadIdentity();
268  gl.Ortho(m_Viewport[0],
269  m_Viewport[0] + m_Viewport[2],
270  m_Viewport[1],
271  m_Viewport[1] + m_Viewport[3], -1.0, 1.0);
272  gl.MatrixMode(GL_MODELVIEW);
273 
274  // set up the ogl state for text
275  gl.Disable(GL_LIGHTING);
276  gl.Disable(GL_DEPTH_TEST);
277  gl.Disable(GL_CULL_FACE);
278  gl.Enable(GL_TEXTURE_2D);
279  gl.TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
280  //gl.Enable(GL_BLEND);
281  //gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
282  gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
283 
284  if (gl.GetApi() == eOpenGL20)
285  glGetIntegerv(GL_CURRENT_PROGRAM, &m_PrevShader);
286  gl.UseProgram(0);
288 }
289 
290 void CGlTextureFont::BeginText(const TVPRect& viewport,
291  GLdouble* mview, GLdouble* proj ) const
292 {
293  // avoid pusattrib if possible since it can be very slow
294  //glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
295  IRender& gl = GetGl();
296 
297  // Copy viewport passed in (we can't get it from OpenGL always because
298  // this library also supports some pdf rendering functions and in pdf
299  // output the maximum viewing area generally exceeds the maximum
300  // supported by OpenGL)
301  m_Viewport[0] = GLint(viewport.Left());
302  m_Viewport[1] = GLint(viewport.Bottom());
303  m_Viewport[2] = GLint(viewport.Right());
304  m_Viewport[3] = GLint(viewport.Top());
305 
306  // Get modelview and projection matrices that will be used for
307  // unprojection (getting window coordinates) of text draw location
308  memcpy(m_ModelviewMatrix, mview, sizeof(GLdouble)*16);
309  memcpy(m_ProjectionMatrix, proj, sizeof(GLdouble)*16);
310 
311 
312  //glGetDoublev(GL_MODELVIEW_MATRIX, m_ModelviewMatrix);
313  //glGetDoublev(GL_PROJECTION_MATRIX, m_ProjectionMatrix);
314  //glGetIntegerv(GL_VIEWPORT, m_Viewport);
315 
316  // Set projection matrix to pixel coordinates
317  gl.MatrixMode(GL_PROJECTION);
318  gl.PushMatrix();
319  gl.LoadIdentity();
320  gl.Ortho(m_Viewport[0],
321  m_Viewport[0] + m_Viewport[2],
322  m_Viewport[1],
323  m_Viewport[1] + m_Viewport[3], -1.0, 1.0);
324  gl.MatrixMode(GL_MODELVIEW);
325 
326  // set up the ogl state for text
327  gl.Disable(GL_LIGHTING);
328  gl.Disable(GL_DEPTH_TEST);
329  gl.Disable(GL_CULL_FACE);
330  gl.Enable(GL_TEXTURE_2D);
331  gl.TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
332  //glEnable(GL_BLEND);
333  //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
334  gl.PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
335 
336  glGetIntegerv(GL_CURRENT_PROGRAM, &m_PrevShader);
337  gl.UseProgram(0);
339 }
340 
342 {
343  // restore OpenGL state (push/pop all is expensive)
344  //glPopAttrib();
345  IRender& gl = GetGl();
346 
347  gl.MatrixMode(GL_PROJECTION);
348  gl.PopMatrix();
349  gl.MatrixMode(GL_MODELVIEW);
350 
351  // set most reasonable options (rather than push/pop attrib)
352  gl.Disable(GL_TEXTURE_2D);
353  gl.Enable(GL_BLEND);
354  gl.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
355  glListBase(0);
356  gl.UseProgram((GLuint)m_PrevShader);
358 }
359 
361  const char* text,
362  const float* color,
363  TModelUnit rotate_degrees) const
364 {
365  GetGl().Color4fv(color);
366  WriteText(x, y, text, rotate_degrees);
367 }
368 
370  TModelUnit width, TModelUnit height,
371  const char* text,
372  const float* color,
373  TAlign align,
375  TModelUnit rotate_degrees) const
376 {
377  GetGl().Color4fv(color);
378  WriteText(x, y, width, height, text, align, trunc, rotate_degrees);
379 }
380 
382  TModelUnit y,
383  const char* text,
384  TModelUnit rotate_degrees) const
385 {
386  // If rotation is between 90 and 270, the text will be backwards and upside down
387  // unless we re-orient. Check if user provided reorient flag.
388  bool reorient_text = false;
389  if (rotate_degrees != TModelUnit(0)) {
390  TModelUnit rads = rotate_degrees*(TModelUnit(3.141592653589732)/TModelUnit(180));
391  bool backwards = cos(double(rads)) < TModelUnit(0);
392  if ((m_Rotate & fReorientText) && backwards) {
393  reorient_text = true;
394  }
395  }
396 
397  IRender& gl = GetGl();
398 
399  // Get the window (projection) coordinates of the drawing position (x,y)
400  GLdouble wx, wy, wz;
401  gluProjectX(x, y, 0.0,
403  &wx, &wy, &wz);
404 
405  gl.MatrixMode(GL_MODELVIEW);
406  gl.PushMatrix();
407  gl.LoadIdentity();
408 
409  // Round the drawing coordinates to nearest integer pixel coordinate
410  // (drawing textured fonts on pixel boundries improves visual appearance)
411  // unless user has turned option off
412  double xi = wx;
413  double yi = wy;
414 
415  if (m_SnapToPixelX)
416  xi = floor(wx + 0.5);
417  if (m_SnapToPixelY)
418  yi = floor(wy + 0.5);
419 
420  TModelUnit rcenterx = (TModelUnit)0.0;
421  TModelUnit rcentery = (TModelUnit)0.0;
422 
423  if (m_Rotate & fFontRotateMid) {
424  rcentery = TextHeight()/(TModelUnit)2.0;
425  }
426  else if (m_Rotate & fFontRotateCap) {
427  rcentery = TextHeight();
428  }
429  // fFontRotateBase is default
430 
431  gl.Translated(xi, yi, 0.0);
432 
433  // rotate if desired
434  if (rotate_degrees != TModelUnit(0.0)) {
435  gl.Translated((GLdouble)rcenterx, (GLdouble)rcentery, 0.0);
436  gl.Rotated(rotate_degrees, 0.0, 0.0, 1.0);
437  gl.Translated((GLdouble)-rcenterx, (GLdouble)-rcentery, 0.0);
438 
439  // If we have rotated text to be upside-down and backwards, flip it
440  // across the x and y axes
441  if (reorient_text) {
442  gl.Translatef(0.0f, float(TextHeight()), 0.0f);
443  gl.Scalef(1.0f, -1.0f, 1.0f);
444  gl.Translatef(float(TextWidth(text)), 0.0f, 0.0f);
445  gl.Scalef(-1.0f, 1.0f, 1.0f);
446  }
447  }
448 
449  TextOut(text);
450 
451  gl.MatrixMode(GL_MODELVIEW);
452  gl.PopMatrix();
453 }
454 
456  TModelUnit width, TModelUnit height,
457  const char* text,
458  TAlign align,
460  TModelUnit rotate_degrees) const
461 {
462  string output_str(text);
463  x_WriteText(x, y, width, height, output_str, align, trunc, rotate_degrees, true);
464 }
465 
467  TModelUnit width, TModelUnit height,
468  string& text,
469  TAlign align,
471  TModelUnit rotate_degrees) const
472 {
473  return x_WriteText(x, y, width, height, text, align, trunc, rotate_degrees, false);
474 }
475 
477 {
478  double px, py;
479  double dummyz;
480 
481  gluProjectX(vertex.X(), vertex.Y(), 0.0, m_ModelviewMatrix, m_ProjectionMatrix, m_Viewport, &px, &py, &dummyz);
482  vertex.Set(float(px), float(py));
483 }
484 
486  TModelUnit width, TModelUnit height,
487  string& text,
488  TAlign align,
490  TModelUnit rotate_degrees,
491  bool write_text) const
492 {
493  TModelUnit w = width;
494  TModelUnit h = height;
495 
496  // If rotation is between 90 and 270, the text will be backwards and upside down
497  // unless we re-orient. Check if user provided reorient flag.
498  bool reorient_text = false;
499  if (rotate_degrees != TModelUnit(0)) {
500  TModelUnit rads = rotate_degrees*(TModelUnit(3.141592653589732)/TModelUnit(180));
501  bool backwards = cos(double(rads)) < TModelUnit(0);
502  if ((m_Rotate & fReorientText) && backwards) {
503  reorient_text = true;
504  }
505  }
506 
507  /// truncate as appropriate
508  string str;
509  switch (trunc) {
510  case eTruncate_None:
511  str = text;
512  break;
513 
514  case eTruncate_Empty:
515  case eTruncate_Ellipsis:
516  {
517  if (reorient_text) {
518  string rtext = text;
519 
520  // Reverse text so that it is truncated on the
521  // correct side
522  std::reverse(rtext.begin(), rtext.end());
523  x_Truncate(rtext.c_str(), w, trunc, &str);
524  std::reverse(str.begin(), str.end());
525  }
526  else {
527  x_Truncate(text.c_str(), w, trunc, &str);
528  }
529  }
530  break;
531  }
532 
533  // update parameter to return (possibly truncated) text
534  text = str;
535 
536  ///
537  /// determine where our text starts
538  ///
539  TModelUnit tx = 0;
540  TModelUnit ty = 0;
541 
542  // scale is the ratio of the visible width/height divided by the
543  // viewport width/height (same as in CGLPane). Assumes of course
544  // user is using orthographic projection matrix (e.g. glOrtho())
549 
550  // eAlign_Right or eAlign_Center are applied to horz position only if
551  // eAlign_Left is not specifed
552  if ((align & eAlign_HorizMask) == eAlign_Left) {
553  tx = x;
554  } else if ((align & eAlign_HorizMask) == eAlign_Right) {
555  // right justify
556  TModelUnit text_wid = TextWidth(str.c_str())*scale_x;
557  tx = x + (w - text_wid);
558  } else { // center
559  TModelUnit text_wid = TextWidth(str.c_str())*scale_x;
560  tx = x + (w - text_wid) * TModelUnit(0.5);
561  }
562 
563  if ((align & eAlign_VertMask) == eAlign_Bottom) {
564  ty = y;
565  } else if ((align & eAlign_VertMask) == eAlign_Top) {
566  // skip down enough to keep our text inside
567  TModelUnit text_ht = TextHeight()*scale_y;
568  ty = y + (h - text_ht);
569  } else {
570  // if nothing given or eAlign_Center is specified - center
571  // vertically
572  TModelUnit text_ht = TextHeight()*scale_y;
573  ty = y + (h - text_ht) * TModelUnit(0.5);
574  }
575 
576  IRender& gl = GetGl();
577 
578  //
579  // Set the matrices to pixel-coordinates and then render
580  //
581 
582  // Get window projection coordnates for (x,y)
583  GLdouble wx, wy, wz;
584  gluProjectX(tx, ty, 0.0,
586  &wx, &wy, &wz);
587 
588  gl.MatrixMode(GL_MODELVIEW);
589  gl.PushMatrix();
590  gl.LoadIdentity();
591 
592  // Round the drawing coordinates to nearest integer pixel coordinate
593  // (drawing textured fonts on pixel boundries improves visual appearance)
594  // unless user has turned option off
595  double xi = wx;
596  double yi = wy;
597 
598  if (m_SnapToPixelX)
599  xi = floor(wx + 0.5);
600  if (m_SnapToPixelY)
601  yi = floor(wy + 0.5);
602 
603  // If a rotation angle is specified, we want to rotate from the base
604  // of the box, not the text. So rotate the text around the bottom
605  // middle, or top of the base side of the box as appropriate.
606  if (rotate_degrees != TModelUnit(0.0)) {
607  TModelUnit rcenterx = (TModelUnit)0.0;
608  TModelUnit rcentery = (TModelUnit)0.0;
609 
610  // Get screen coordinates to which (x,y) (box base position) projects
611  GLdouble xproj, yproj, zproj;
612  gluProjectX(x, y, 0.0,
614  &xproj, &yproj, &zproj);
615 
616  // Get offset of box needed for rotation center
617  if (m_Rotate & fFontRotateMid) {
618  rcentery = height/(TModelUnit)2.0;
619  }
620  else if (m_Rotate & fFontRotateCap) {
621  rcentery = height;
622  }
623 
624  double xoff = xi-xproj;
625  double yoff = yi-yproj;
626 
627  gl.Translated(xi, yi, 0.0);
628  gl.Translated((GLdouble)rcenterx-xoff, (GLdouble)rcentery-yoff, 0.0);
629  gl.Rotated(rotate_degrees, 0.0, 0.0, 1.0);
630  gl.Translated((GLdouble)-rcenterx+xoff, (GLdouble)-rcentery+yoff, 0.0);
631 
632  // If we have rotated text to be upside-down and backwards, flip it
633  // across the x and y axes
634  if (reorient_text) {
635  gl.Translatef(0.0f, float(TextHeight()), 0.0f);
636  gl.Scalef(1.0f, -1.0f, 1.0f);
637  gl.Translatef(float(TextWidth(str.c_str())), 0.0f, 0.0f);
638  gl.Scalef(-1.0f, 1.0f, 1.0f);
639  }
640 
641  ///
642  /// Debugging code to draw the bounding box for the text
643  ///
644  /*
645  glMatrixMode(GL_MODELVIEW);
646  glPushMatrix();
647  glLoadIdentity();
648 
649  double wx2, wy2, wz2;
650  gluProjectX(x+width, y+height, 0.0,
651  m_ModelviewMatrix, m_ProjectionMatrix, m_Viewport,
652  &wx2, &wy2, &wz2);
653 
654  glTranslated((GLdouble)xproj+rcenterx, (GLdouble)yproj+rcentery, 0.0);
655  glRotated(rotate_degrees, 0.0, 0.0, 1.0);
656  glTranslated((GLdouble)-(xproj+rcenterx), (GLdouble)-(yproj+rcentery), 0.0);
657 
658  glDisable(GL_TEXTURE_2D);
659  glDisable(GL_BLEND);
660  glColor3f(0.0f, 0.0f, 1.0f);
661  glBegin(GL_LINE_LOOP);
662  glVertex3d(xproj, yproj, 0.0f);
663  glVertex3d(wx2, yproj, 0.0f);
664  glVertex3d(wx2, wy2, 0.0f);
665  glVertex3d(xproj, wy2, 0.0f);
666  glEnd();
667  glEnable(GL_TEXTURE_2D);
668  glEnable(GL_BLEND);
669  glMatrixMode(GL_MODELVIEW);
670  glPopMatrix();
671  */
672  }
673  else {
674  gl.Translated(xi, yi, 0.0);
675  }
676 
677  CMatrix4<double> xform;
678  xform.Identity();
679 
680  // If we write text matrix will be invalid (only do one or the other
681  // since both can slow down performance)
682  if (write_text) {
683  TextOut(str.c_str());
684  }
685  else {
686  gl.GetModelViewMatrix(xform.GetData());
687  xform.Transpose();
688  }
689 
690  gl.MatrixMode(GL_MODELVIEW);
691  gl.PopMatrix();
692 
693  return xform;
694 }
695 
696 void CGlTextureFont::TextOut(const char* text) const
697 {
698  if (m_Font != NULL && !m_Font->Error())
699  m_Font->Render(text);
700 }
701 
703  TModelUnit y,
704  const char* text) const
705 {
706  BeginText();
707  WriteText(x, y, text);
708  EndText();
709 }
710 
712  TModelUnit x2, TModelUnit y2,
713  const char* text,
714  TAlign align,
716  TModelUnit scale_x,
717  TModelUnit scale_y) const
718 {
719  // Handle alignment and truncation and scaling (scaling seems be used by the ruler class - maybe not much else
720  if(x2 < x1) {
721  swap(x1, x2);
722  }
723  if(y2 < y1) {
724  swap(y1, y2);
725  }
726 
727  TModelUnit x = x1;
728  TModelUnit y = y1;
729  TModelUnit w = x2 - x1;
730  TModelUnit h = y2 - y1;
731 
732  /// truncate as appropriate
733  string str;
734  switch (trunc) {
735  case eTruncate_None:
736  str = text;
737  break;
738 
739  case eTruncate_Empty:
740  case eTruncate_Ellipsis:
741  {
742  x_Truncate(text, w, trunc, &str);
743  }
744  break;
745  }
746 
747  BeginText();
748  WriteText(x, y, text);
749  EndText();
750 }
751 
752 string CGlTextureFont::Truncate(const char* text,
753  TModelUnit w,
754  ETruncate trunc) const
755 {
756  string res;
757  x_Truncate2(text, w, trunc, &res);
758  return res;
759 }
760 
761 string CGlTextureFont::Truncate(const string& text,
762  TModelUnit w,
763  ETruncate trunc) const
764 {
765  string res;
766  x_Truncate2(text.c_str(), w, trunc, &res);
767  return res;
768 }
769 
771  TModelUnit dx, TModelUnit dy,
772  const char* text,
773  const vector<CRgbaColor*>* colors,
774  TModelUnit scale_x,
775  TModelUnit scale_y) const
776 {
777  TModelUnit k_x = scale_x / 2;
778  TModelUnit k_y = scale_y / 2;
779 
780  TModelUnit ch = TextHeight();
781 
782  BeginText();
783  for (const char* p = text; p && *p; ++p) {
784  //if (*p < m_FontPtr->first ||
785  // *p >= m_FontPtr->first + m_FontPtr->num_chars) {
786  // continue;
787  //}
788  //const BitmapCharRec *ch = m_FontPtr->ch[*p - m_FontPtr->first];
789  string text_char(p, 1);
790  TModelUnit cw = TextWidth(text_char.c_str());
791 
792  int ind = (int)(p - text);
793  TModelUnit pos_x = x + ind * dx;
794  TModelUnit pos_y = y + ind * dy;
795  TModelUnit off_x;
796 
797  off_x = cw * k_x; // to current coord system
798 
799  if(colors) {
800  CRgbaColor& c = *(*colors)[ind];
801  GetGl().ColorC(c);
802  }
803 
804  WriteText(pos_x-off_x, pos_y, text_char.c_str(), 0.0f);
806  }
807 
808  EndText();
809 }
810 
812 {
813  if (m_Font != NULL && !m_Font->Error()) {
814  FTBBox bounding;
815  bounding = m_Font->BBox(text);
816  return (TModelUnit)(bounding.Upper().X() - bounding.Lower().X());
817  }
818 
819  return TModelUnit(0.0);
820 }
821 
823 {
824  // This returns the height of the fonts without descenders - so it's a little
825  // less that the full height. This does not use any OpenGL (so it can be called
826  // before window creation unlike some of the functions in GetMetric())
827  if (m_Font != NULL && !m_Font->Error()) {
828  TModelUnit fs = (TModelUnit)m_Font->FaceSize();
829 
830  // bitmap fonts are reporting slightly incorrect sizes
831  // which leads to misalignment in some glyphs
832  if (IsBitmapFont()) {
833  if (m_FontSize == 6 || m_FontSize == 8)
834  fs += 1;
835  else if (m_FontSize == 10)
836  fs -= 1;
837  }
838 
839  // descender is given as a negative number
840  TModelUnit desc = (TModelUnit)m_Font->Descender();
841  return fs + desc;
842  }
843 
844  return TModelUnit(m_FontSize);
845 }
846 
848 {
849  if (m_Font != NULL && !m_Font->Error())
850  return (TModelUnit)m_Font->Descender();
851 
852  return TModelUnit(0.0);
853 }
854 
856 {
857  if (m_Font != NULL && !m_Font->Error()) {
858  char str[] = {c, '\0'}; // FTGL code accesses the next char
859  return m_Font->Advance(str, 1);
860  }
861 
862  return TModelUnit(0.0f);
863 }
864 
866 {
867  double max_dig_w = 0;
868 
869  for( char c = '0'; c <= '9'; c++) {
870  double char_w = GetAdvance(c);
871  max_dig_w = max(max_dig_w, char_w);
872  }
873  double comma_w = GetAdvance(',');
874 
875  double mod = abs(max_num);
876  int digits_count = (int) ceil(log10(mod));
877  int commas_count = (digits_count - 1) / 3;
878 
879  // length of the longest possible label in pixels (add 2 for separation)
880  double w = digits_count * max_dig_w + commas_count * comma_w;
881  if(max_num < 0) {
882  w += GetAdvance('-');
883  }
884  return w;
885 }
886 
887 
889  const char* text,
890  int len) const
891 {
892  FTBBox bounding;
893 
894  // Standard characters (could also iterate over ascii codes).
895  static const char* sc_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`~!@#$%^&*()_-+={}|[]\\:\";'<,>.?/";
896  // just the caps
897  static const char* sc_caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
898 
899  float w = 0.0f;
900 
901  // Note -some of these use OpenGL and should not be called before window creation
902  if (m_Font != NULL && !m_Font->Error()) {
903  switch(metric) {
904  case eMetric_CharHeight:
905  if (m_MetricCharHeight < TModelUnit(0.0)) {
906  bounding = m_Font->BBox(sc_caps);
907  m_MetricCharHeight = bounding.Upper().Y() - bounding.Lower().Y();
908  }
909  return m_MetricCharHeight;
910  break;
912  return m_MetricFullCharHeight;
913  break;
915  if (m_MetricAvgCharWidth < 0.0f) {
916  w = m_Font->Advance(sc_chars);
917  m_MetricAvgCharWidth = (TModelUnit(w)/TModelUnit(strlen(sc_chars)));
918  }
919  return m_MetricAvgCharWidth;
920  break;
922  if ( m_MetricMaxCharWidth < TModelUnit(0.0) ) {
923  for (size_t i=0; i<strlen(sc_chars); ++i) {
924  w = m_Font->Advance(&sc_chars[i], 1);
925  if (w > m_MetricMaxCharWidth)
927  }
928  }
929  return m_MetricMaxCharWidth;
930  break;
931  case eMetric_TextWidth: // Does not include the final advance
932  if (text != NULL) {
933  bounding = m_Font->BBox(text);
934  return (TModelUnit)(bounding.Upper().X() - bounding.Lower().X());
935  }
936  break;
937  case eMetric_FullTextWidth: // Includes the final advance
938  if (text != NULL)
939  return (TModelUnit)m_Font->Advance(text);
940  break;
941  case eMetric_Descender:
942  return m_MetricDescender;
943  }
944  }
945 
946  return TModelUnit(0.0);
947 }
948 
950 {
951  FTBBox bounding;
952 
953  // Note -some of these use OpenGL and should not be called before window creation
954  if (m_Font != NULL && !m_Font->Error()) {
955 
956  // this should not be called before window is created so do it in
957  // get function
958  //bounding = m_Font->BBox(sc_caps);
959  //m_MetricCharHeight = bounding.Upper().Y() - bounding.Lower().Y();
961 
962  m_MetricFullCharHeight = (TModelUnit)m_Font->FaceSize();
963 
964  //w = m_Font->Advance(sc_chars);
965  //m_MetricAvgCharWidth = (TModelUnit(w)/TModelUnit(strlen(sc_chars)));
967 
968 
970 
971  m_MetricDescender = (TModelUnit)m_Font->Descender();
972  }
973 }
974 
976 {
977  return s_FontNames[face];
978 }
979 
981 {
982  vector<string> arr;
983  NStr::Split(str, " \t", arr);
984 
985  // If all tokens (such as Courier, bold, oblique occur in
986  // a string return the enum for that string, otherwise return
987  // eFontFace_LastFont
988  for (size_t i=0; i<(size_t)eFontFace_LastFont; ++i) {
989  //string str = s_FontNames[i];
990  bool match = true;
991 
992  for (size_t j=0; j<arr.size(); ++j) {
993  size_t pos = NStr::Find(s_FontNames[i], arr[j], NStr::eNocase);
994  if (pos == NPOS)
995  match = false;
996  }
997 
998  if (match)
999  return (EFontFace)i;
1000  }
1001 
1002  return eFontFace_LastFont;
1003 }
1004 
1006 {
1007  // These are all the base-font names defined by PDF (these fonts can be
1008  // embedded into pdf files, but do not have to be).
1009  /*
1010  Times-Roman
1011  Times-Bold
1012  Times-Italic
1013  Times-BoldItalic
1014  Helvetica
1015  Helvetica-Bold
1016  Helvetica-Oblique
1017  Helvetica-BoldOblique
1018  Courier
1019  Courier-Bold
1020  Courier-Oblique
1021  Courier-BoldOblique
1022  Symbol
1023  ZapfDingbats
1024  */
1025 
1026  // This is the best mapping to built in pdf font names. Some are only
1027  // approximations. PDF does also allow fonts to be embedded, if the pdf
1028  // rendering were to support it.
1029  switch (face) {
1030  case eFontFace_Helvetica:
1031  pdf_face = eFontFace_Helvetica;
1032  return "Helvetica";
1034  pdf_face = eFontFace_Helvetica_Bold;
1035  return "Helvetica-Bold";
1037  pdf_face = eFontFace_Helvetica_Italic;
1038  return "Helvetica-Oblique";
1040  pdf_face = eFontFace_Helvetica_BoldItalic;
1041  return "Helvetica-BoldOblique";
1042  case eFontFace_Lucida:
1043  pdf_face = eFontFace_TimesRoman;
1044  return "Times-Roman";
1045  case eFontFace_Lucida_Bold:
1046  pdf_face = eFontFace_TimesRoman_Bold;
1047  return "Times-Bold";
1049  pdf_face = eFontFace_TimesRoman_Italic;
1050  return "Times-Italic";
1053  return "Times-BoldItalic";
1054  case eFontFace_Courier:
1055  pdf_face = eFontFace_Courier;
1056  return "Courier";
1058  pdf_face = eFontFace_Courier_Bold;
1059  return "Courier-Bold";
1061  pdf_face = eFontFace_Courier_Italic;
1062  return "Courier-Oblique";
1064  pdf_face = eFontFace_Courier_BoldItalic;
1065  return "Courier-BoldOblique";
1066  case eFontFace_Fixed:
1067  pdf_face = eFontFace_Courier;
1068  return "Courier";
1069  case eFontFace_Fixed_Bold:
1070  pdf_face = eFontFace_Courier_Bold;
1071  return "Courier-Bold";
1073  pdf_face = eFontFace_Courier_Italic;
1074  return "Courier-Oblique";
1076  pdf_face = eFontFace_Courier_BoldItalic;
1077  return "Courier-BoldOblique";
1078  case eFontFace_TimesRoman:
1079  pdf_face = eFontFace_TimesRoman;
1080  return "Times-Roman";
1082  pdf_face = eFontFace_TimesRoman_Bold;
1083  return "Times-Bold";
1085  pdf_face = eFontFace_TimesRoman_Italic;
1086  return "Times-Italic";
1089  return "Times-BoldItalic";
1090  case eFontFace_BPMono:
1091  pdf_face = eFontFace_Courier;
1092  return "Courier";
1093  case eFontFace_BPMono_Bold:
1094  pdf_face = eFontFace_Courier_Bold;
1095  return "Courier-Bold";
1097  pdf_face = eFontFace_Courier_Italic;
1098  return "Courier-Oblique";
1100  pdf_face = eFontFace_Courier_Bold;
1101  return "Courier-Bold";
1102  default:
1103  pdf_face = eFontFace_LastFont;
1104  return "";
1105  }
1106 
1107  return "";
1108 }
1109 
1110 // saves and restores font face and size in(from) a string
1112 {
1113  string size_str = NStr::NumericToString(m_FontSize);
1114  string font_string = m_FontFile + " " + size_str;
1115 
1116  return font_string;
1117 }
1119 {
1120  string font_size_str;
1121  NStr::SplitInTwo(value, ",", m_FontFile, font_size_str);
1122  NStr::StringToNumeric(font_size_str, &m_FontSize);
1123 
1124  if (m_FontSize >= 4 && m_FontFile != "") {
1126 
1127  /// Set face name if we recognize the font file:
1128  for (size_t i=0; i<(size_t)eFontFace_LastFont; ++i) {
1129  if (s_FontFileNames[i] == m_FontFile) {
1130  m_FontFace = (EFontFace)i;
1131  break;
1132  }
1133  }
1134 
1135  // If it was a bitmap font, we call it Helvetica (but it
1136  // could also be Fixed).
1137  for (size_t i=(size_t)eFontFace_LastFont;
1138  i<(size_t)eFontFace_LastBitmapFont; ++i) {
1139  if (s_FontFileNames[i] == m_FontFile) {
1141  break;
1142  }
1143  }
1144 
1145  return SetFont(m_FontFile, m_FontSize);
1146  }
1147 
1148  return false;
1149 }
1150 
1151 void CGlTextureFont::GetAllFaces(vector<string>& faces)
1152 {
1153  faces.clear();
1154 
1155  for (size_t i=0; i<(size_t)eFontFace_LastFont; ++i) {
1156  faces.push_back(s_FontNames[i]);
1157  }
1158 }
1159 void CGlTextureFont::GetAllSizes(vector<string>& sizes)
1160 {
1161  sizes.clear();
1162 
1163  size_t idx = 0;
1164  while (s_FontSizes[idx] != 0) {
1165  sizes.push_back(NStr::NumericToString(s_FontSizes[idx++]));
1166  }
1167 }
1168 
1170  TModelUnit w,
1171  ETruncate trunc,
1172  string* str) const
1173 {
1174  if (m_Font == nullptr || m_Font->Error())
1175  return 0;
1176 
1177  string original_text{ text };
1178  string short_text{ text };
1179  size_t active_index = short_text.length();
1180 
1181  if (eTruncate_None == trunc)
1182  return (int)short_text.length();
1183 
1184  FTBBox text_bbox = m_Font->BBox(short_text.c_str());
1185  TModelUnit text_width = TModelUnit(text_bbox.Upper().X() - text_bbox.Lower().X());
1186 
1187  FTBBox ellipsis_bbox = m_Font->BBox("...");
1188  TModelUnit ellipsis_width = TModelUnit(ellipsis_bbox.Upper().X() - ellipsis_bbox.Lower().X());
1189 
1190  if (w < ellipsis_width) {
1191  return 0;
1192  }
1193 
1194  while (text_width > w) {
1195  short_text = original_text.substr(0, --active_index);
1196  if (eTruncate_Ellipsis == trunc) {
1197  short_text += "...";
1198  }
1199  text_bbox = m_Font->BBox(short_text.c_str());
1200  text_width = TModelUnit(text_bbox.Upper().X() - text_bbox.Lower().X());
1201  }
1202 
1203  if (nullptr != str) {
1204  if (active_index != original_text.length())
1205  *str = short_text;
1206  else
1207  *str = text;
1208  }
1209 
1210  return (int)active_index;
1211 
1212 }
1213 
1214 
1216  TModelUnit w,
1217  ETruncate trunc,
1218  string* str) const
1219 {
1220  if (m_Font == NULL || m_Font->Error())
1221  return 0;
1222 
1223  static const char* sc_ellipsis = "...";
1224  static const FTBBox sc_ebbox = m_Font->BBox(sc_ellipsis);
1225  static const TModelUnit sc_ewid = TModelUnit(sc_ebbox.Upper().X() -
1226  sc_ebbox.Lower().X());
1227 
1228  const char* ellip = NULL;
1229 
1230  const char* end_pos = text;
1231  switch (trunc) {
1232  case eTruncate_None:
1233  end_pos = text + strlen(text);
1234  break;
1235 
1236  case eTruncate_Ellipsis: {
1237  // first, do a blunt cut
1238  int pos = x_Truncate(text, w, eTruncate_Empty);
1239  end_pos = text + pos;
1240  if ( !*end_pos ) {
1241  // we can fit the whole thing
1242  break;
1243  }
1244 
1245  // adjust for the ellipsis
1246  TModelUnit e_wid = sc_ewid;
1247  while (e_wid > 0) {
1248  ellip = sc_ellipsis;
1249  FTBBox b = m_Font->BBox(end_pos, 1);
1250  e_wid -= TModelUnit(b.Upper().X() - b.Lower().X());
1251  if (end_pos > text) {
1252  --end_pos;
1253  } else {
1254  break;
1255  }
1256  }
1257  }
1258  break;
1259 
1260  case eTruncate_Empty:
1261  for ( ; end_pos && *end_pos && w >= 0; ++end_pos) {
1262  TModelUnit wid = (TModelUnit)m_Font->Advance(end_pos, 1);
1263  if (w - wid < 0) {
1264  FTBBox b = m_Font->BBox(end_pos, 1);
1265  wid = TModelUnit(b.Upper().X() - b.Lower().X());
1266  }
1267 
1268  w -= wid;
1269  }
1270 
1271  if (w < 0) {
1272  --end_pos;
1273  }
1274  break;
1275  }
1276 
1277  if (end_pos < text) {
1278  end_pos = text;
1279  }
1280 
1281  if (str) {
1282  str->assign(text, end_pos);
1283  if (ellip) {
1284  *str += ellip;
1285  }
1286  }
1287  return (int)(end_pos - text);
1288 }
1289 
1291  string font_file_name,
1292  unsigned int font_size,
1293  bool use_bitmap_overrides) const
1294 {
1295  // This function returns bitmap fonts for small sized Helvetica or Fixed fonts. Currently
1296  // just hardcoded, but if we had more bitmap fonts we could have an array of font file names for
1297  // each font face. Note that fixed and helvetica use the same bitmap fonts and it Only
1298  // applies to sizes 6, 8, and 10 (since you have to find/create fonts for each size).
1299  if (use_bitmap_overrides && (face == eFontFace_Helvetica ||
1300  face == eFontFace_Fixed) &&
1301  (font_size == 6 || font_size == 8 || font_size == 10)) {
1302 
1303  if (font_size == 6) {
1305  }
1306  else if (font_size == 8) {
1308  }
1309  else {
1311  }
1312  }
1313  else {
1314  // If the file was loaded directly, there may not be a face name, so
1315  // just return the file (which the calller will have to set correctly).
1316  if (face != eFontFace_LastFont)
1317  return s_FontFileNames[(int)face];
1318  else
1319  return font_file_name;
1320  }
1321 }
1322 
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static const Colors colors
Definition: cn3d_colors.cpp:50
#define true
Definition: bool.h:35
static int trunc
Definition: array_out.c:8
static const char * str(char *buf, int n)
Definition: stats.c:84
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define NULL
Definition: ncbistd.hpp:225
void Set(T x, T y)
Definition: vect2.hpp:260
void Transpose()
Definition: matrix4.hpp:347
T & X()
Definition: vect2.hpp:107
void Identity()
Definition: matrix4.hpp:373
const T * GetData() const
Definition: matrix4.hpp:103
T & Y()
Definition: vect2.hpp:109
virtual void Translated(GLdouble x, GLdouble y, GLdouble z)=0
void SetSnapToPixel(bool xpix, bool ypix)
If true (the default) text output position is rounded to nearest pixel coordinate,...
GLdouble TModelUnit
Definition: gltypes.hpp:48
int gluProjectX(GLdouble objx, GLdouble objy, GLdouble objz, const GLdouble modelMatrix[16], const GLdouble projMatrix[16], const GLint viewport[4], GLdouble *winx, GLdouble *winy, GLdouble *winz)
Definition: glutils.hpp:223
void Color4fv(const GLfloat *v)
Definition: irender.hpp:98
virtual void Scalef(GLfloat x, GLfloat y, GLfloat z)=0
TFontRotateFlags m_Rotate
flags for center of rotation and how to handle direction and orientation
string ToString() const
saves and restores font face and size to/from a string
virtual void Translatef(GLfloat x, GLfloat y, GLfloat z)=0
virtual CMatrix4< float > GetProjectionMatrix() const =0
virtual void Enable(GLenum glstate)=0
virtual void UseProgram(GLuint program)=0
For shaders. Only works with OpenGL 2.0+.
T Top() const
Definition: glrect.hpp:84
virtual bool IsBitmapFont() const
Returns true if the currently loaded font is from a bitmap.
GLint m_Viewport[4]
Temporary variables initialized by the BeginText() function and used by the Draw() functions.
virtual void BlendFunc(GLenum sfactor, GLenum dfactor)=0
Options to be used when GL_BLEND is enabled.
T Bottom() const
Definition: glrect.hpp:82
int x_Truncate(const char *text, TModelUnit w, ETruncate trunc, string *str=NULL) const
Truncate a string for display.
string x_GetFontFile(EFontFace face, string font_file_name, unsigned int font_size, bool use_bitmap_overrides=true) const
Return the font file for a font face - some fonts may use bitmap files for smaller sizes,...
virtual CMatrix4< float > GetModelViewMatrix() const =0
virtual void MatrixMode(GLenum mode)=0
static void GetAllFaces(vector< string > &faces)
GetAllFaces() and GetAllSizes() fills containers with strings repesenting all available enumerated (p...
bool m_SnapToPixelX
Normally, when text is written to the screen the position is synched to the nearest pixel.
IRender & GetGl()
convenience function for getting current render manager
void WriteText(TModelUnit x, TModelUnit y, const char *text, TModelUnit rotate_degrees=0.0) const
Write text at specified model coords.
T Right() const
Definition: glrect.hpp:83
CGlRect< TVPUnit > TVPRect
Definition: gltypes.hpp:53
GLdouble m_ModelviewMatrix[16]
TModelUnit m_MetricFullCharHeight
void ArrayTextOut(TModelUnit x, TModelUnit y, TModelUnit dx, TModelUnit dy, const char *text, const vector< CRgbaColor * > *colors=NULL, TModelUnit scale_x=1.0f, TModelUnit scale_y=1.0f) const
prints array of characters in positions (x + i*dx, y + i*dy) where "i" is index of a character in the...
CMatrix4< double > GetTextXform(TModelUnit x, TModelUnit y, TModelUnit width, TModelUnit height, string &text, TAlign align=eAlign_Center, ETruncate trunc=eTruncate_Ellipsis, TModelUnit rotate_degrees=0.0f) const
Get the transformation that will be applied to the text to write it within the box (x,...
virtual TModelUnit GetFontDescender() const
virtual void LoadIdentity()=0
void x_ComputeMetrics()
Compute metrics for the font upon creation (for performance)
TModelUnit m_MetricMaxCharWidth
static string s_FontFileNames[]
This maps EFontFace enums to font file names for loading.
CMatrix4< double > x_WriteText(TModelUnit x, TModelUnit y, TModelUnit width, TModelUnit height, string &text, TAlign align, ETruncate trunc, TModelUnit rotate_degrees, bool write_text) const
Called by both writetext and gettexttransform to compute transformation matrix or write the text.
FTFont * m_Font
The current font for writing. These are owned by CFtglFontManager class.
static string GetFontFileForFace(EFontFace face)
Get font file for given face.
string m_FontFile
File from which current font was loaded.
virtual void PopMatrix()=0
static string PdfBaseFontName(EFontFace face, EFontFace &pdf_face)
Name of basefont for PDF purposes, or "" if not available.
static CFtglFontManager & Instance()
Get an instance of the manager so you can retrieve fonts.
GLint m_PrevShader
Switch back to previous shader after writing text.
static string FaceToString(EFontFace face)
funtions below provide conversion of font parameters to strings and back.
T Left() const
Definition: glrect.hpp:81
EFontFace m_FontFace
Current font face held by m_Font.
void SetFontFace(EFontFace face, bool use_bitmap_overrides=true)
virtual void Rotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z)=0
void BeginText() const
WriteText interface The WriteText functions produce the same results as TextOut but they are more eff...
TModelUnit m_MetricDescender
TModelUnit GetMaxWidth(int max_num) const
returns minimal space sufficient to render any number in [0, max_num].
EFontFace GetFontFace() const
virtual void TexEnvi(GLenum target, GLenum pname, GLint param)=0
static bool CheckGlError()
Check if there are any OpenGL errors.
Definition: glutils.cpp:166
virtual ERenderTarget GetApi()=0
virtual void PolygonMode(GLenum face, GLenum mode)=0
Set the polygon rasterization mode.
unsigned int m_FontSize
Size of current font.
GLdouble m_ProjectionMatrix[16]
void ProjectVertex(CVect2< float > &vertex) const
void EndText() const
Pops matrices and attributes after writing text.
virtual TModelUnit GetMetric(EMetric metric, const char *text=NULL, int len=-1) const
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
CGlTextureFont()
default constructor.
virtual TModelUnit TextWidth(const char *text) const
Compute and return font metrics.
virtual TModelUnit TextHeight(void) const
static void GetAllSizes(vector< string > &sizes)
virtual void TextOut(const char *text) const
TextOut interface Write the specified text and set up state and transformation as needed.
void SetFontSize(unsigned int size)
Set/get font size in points.
static string s_FontNames[]
Maps EFontFace enums to a readable strings for selection lists.
int x_Truncate2(const char *text, TModelUnit w, ETruncate trunc, string *str=NULL) const
virtual void Disable(GLenum glstate)=0
glDisable()
virtual void Ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)=0
TModelUnit m_MetricCharHeight
Pre-computed metrics (may be computed first time accessed)
FTFont * GetFont(const char *filename, unsigned int size, EFtglFontType ft=eTextureFont)
static EFontFace FaceFromString(const string &str)
Selects a font face given a string or eFontFace_LastFont on failure.
static int s_FontSizes[]
Font sizes used as a standard set for user selection - last element in array is set to 0 as a marker.
bool SetFont(string font_file_name, unsigned int font_size, bool use_bitmap_overrides=true)
Load font from file explicitly. Returns true on success, false otherwise.
unsigned int GetFontSize() const
virtual void ColorC(const CRgbaColor &c)=0
Set current color (glColor{3,4}{f,d}{v,})
TModelUnit m_MetricAvgCharWidth
ETruncate
Definition: glfont.hpp:62
bool FromString(const string &value)
virtual void PushMatrix()=0
string Truncate(const char *text, TModelUnit w, ETruncate trunc=eTruncate_Ellipsis) const
Truncate text to the secified width.
int TAlign
Definition: glfont.hpp:113
TModelUnit GetAdvance(char c) const
virtual void GetViewport(GLint *params)=0
@ 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_HorizMask
Definition: glfont.hpp:101
@ eAlign_VertMask
Definition: glfont.hpp:106
@ fFontRotateMid
Rotate around mid-left of unrotated text box.
@ fReorientText
Ensure rotated text reads L to R and is rightside-up.
@ fFontRotateCap
Rotate around upper-left corner of unrotated text box.
@ eOpenGL20
Definition: glstate.hpp:61
@ 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
@ eFontFace_Helvetica_BoldItalic
@ eFontFace_TimesRoman_BoldItalic
@ 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
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
#define NPOS
Definition: ncbistr.hpp:133
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
Definition: ncbistr.hpp:330
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2891
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3554
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
n background color
int i
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define abs(a)
Definition: ncbi_heapmgr.c:130
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
T max(T x_, T y_)
T log10(T x_)
Int mod(Int i, Int j)
Definition: njn_integer.hpp:67
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
Modified on Mon May 20 05:04:45 2024 by modify_doxy.py rev. 669887