073a78b09e31657d9aa23c3d39f1e8068e855a16
[occt.git] / src / OpenGl / OpenGl_FontMgr.hxx
1 #ifndef OPENGL_FONT_MGR_H
2 #define OPENGL_FONT_MGR_H
3
4
5 #ifdef WNT
6 # include <windows.h>
7 # include <stdlib.h>
8 #endif
9
10 #include <FTFont.h>
11
12 #include <InterfaceGraphic.hxx>
13 #include <TCollection_HAsciiString.hxx>
14 #include <NCollection_List.hxx>
15 #include <NCollection_DataMap.hxx>
16 #include <Graphic3d_NListOfHAsciiString.hxx>
17 #include <OSD_FontMgr.hxx>
18
19 void dump_texture();
20
21 class OpenGl_FontMgr
22 {
23 public:
24   static OpenGl_FontMgr*  instance();
25
26   int request_font( const Handle(TCollection_HAsciiString)& fontName,
27     const OSD_FontAspect                   fontAspect,
28     const Standard_Integer                 fontHeight );
29
30   void render_text( const Standard_Integer id,
31     const char* text,
32     const Standard_Boolean is2d = 0 );
33
34   //render text by last requested font
35   void render_text( const char* text, const Standard_Boolean is2d = 0 );
36
37   //returns direct access to FTGL font
38   //Warning: don't change font pointer.
39   const FTFont*   fontById( const Standard_Integer id );
40
41   //returns width of string
42   Standard_ShortReal computeWidth( const Standard_Integer id, const char* str );
43
44   bool requestFontList( Graphic3d_NListOfHAsciiString& );
45
46   void setCurrentScale( const Standard_ShortReal xScale = 1.f,
47                         const Standard_ShortReal yScale = 1.f);
48
49 private:
50   OpenGl_FontMgr();
51   OpenGl_FontMgr( const OpenGl_FontMgr& ){};
52   OpenGl_FontMgr& operator = ( const OpenGl_FontMgr&){ return *this;};
53   ~OpenGl_FontMgr(){};
54
55   void                          _initializeFontDB();
56
57   typedef NCollection_List<Standard_Integer> IDList;
58
59   struct OGLFont_SysInfo {
60     Handle(OSD_SystemFont)            SysFont;
61     IDList                            GeneratedFonts;
62   };
63
64   struct OGLFont_Cache {
65     FTFont*            Font;
66     Standard_Integer   FontHeight;
67     GLCONTEXT          GlContext;
68   };
69
70   typedef NCollection_List<OGLFont_SysInfo*> FontDataBase;
71   typedef FontDataBase::Iterator             FontDBIt;
72   typedef NCollection_DataMap<Standard_Integer,OGLFont_Cache> FontCache;
73   typedef FontCache::Iterator                                 FCacheIt;
74
75   FontDataBase            _FontDB;
76   FontCache               _FontCache;
77
78   Standard_Integer        _CurrentFontId;
79
80   Standard_ShortReal      _XCurrentScale,
81                           _YCurrentScale;
82 };
83
84 #endif //OPENGL_FONT_MGR_H