summaryrefslogtreecommitdiff
path: root/inc/OpenGl_TextRender.hxx
blob: 574417ea5836c81d5c26bc7013e85db1a8281d7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <OSD_FontAspect.hxx>
#include <InterfaceGraphic_tgl_all.hxx>
#include <OpenGl_tgl_all.hxx>
#include <InterfaceGraphic_telem.hxx>
#include <NCollection_DataMap.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_HAsciiString.hxx>
#include <OpenGl_FontMgr.hxx>  // For FTFont

#define NUM_FONT_SIZES 40
#define NUM_CHAR_FONT 1024
#define CACHE_SIZE 30

class OpenGl_TextRender
{
 public:

  static OpenGl_TextRender* instance();
  Tint FindFont ( Tchar*, OSD_FontAspect, Tfloat, Tfloat = 1. , Tfloat = 1.);

  void StringSize( const wchar_t *text, GLint *width, GLint *ascent, GLint *descent);
  void RenderText( const wchar_t*, GLuint, int, GLfloat, GLfloat, GLfloat );
  void ExportText( const wchar_t* text, char* fontname, GLfloat height, GLfloat angle, GLint alingment, GLfloat x, GLfloat y, GLfloat z, GLboolean is2d );
#ifdef HAVE_GL2PS
  static void getGL2PSFontName(char *src_font, char *ps_font);
#endif

 private:

  static int curFont  ;
  static int curSize  ;
  static int curScale ;
  static int curTexFont ; 
#ifdef HAVE_GL2PS
  int alignmentforgl2ps(int Hmode, int Vmode);
#endif

  struct FontMapNode 
  {
    const char*     enumName;
    const char*     FontName;
    OSD_FontAspect  fontAspect;
  };

  struct FontEntry
  {
    const char*     name;
    const char*     xlfd;
    float     xsizes[NUM_FONT_SIZES];
    int       count;
  };

  FontMapNode searchFontInMap( Handle(TCollection_HAsciiString)& fontName );

  static FontMapNode  fontMap[];
  static FontEntry    fontEntry[];

  OpenGl_TextRender();
  OpenGl_TextRender( const OpenGl_TextRender& ){};
  OpenGl_TextRender& operator = ( const OpenGl_TextRender&){ return *this;};
 ~OpenGl_TextRender(){};


  struct OGLFont_Cache 
  {
    FTFont*            Font;
    Standard_Integer   FontHeight;
    GLCONTEXT          GlContext;
  };

  typedef NCollection_DataMap<Standard_Integer,OGLFont_Cache> FontCache;
  FontCache               _FontCache;
  Standard_Integer        _CurrentFontId;
  Standard_ShortReal      _XCurrentScale,
                          _YCurrentScale; 

};