0022149: Strings with Japanese characters can not be displayed in 3D viewer
[occt.git] / src / OpenGl / OpenGl_FontMgr.hxx
1 #ifndef OPENGL_FONT_MGR_H
2 #define OPENGL_FONT_MGR_H
3
4 #ifdef WNT
5 # include <windows.h>
6 # include <stdlib.h>
7 #endif
8
9 #include <FTFont.h>
10
11 #include <InterfaceGraphic.hxx>
12 #include <TCollection_HAsciiString.hxx>
13 #include <NCollection_List.hxx>
14 #include <NCollection_DataMap.hxx>
15 #include <Graphic3d_NListOfHAsciiString.hxx>
16 #include <OSD_FontMgr.hxx>
17
18 void dump_texture();
19
20 class OpenGl_FontMgr
21 {
22  public:
23   static OpenGl_FontMgr*  instance();
24
25   int request_font( const Handle(TCollection_HAsciiString)& fontName,
26                     const OSD_FontAspect                    fontAspect,
27                     const Standard_Integer                  fontHeight );
28
29   void render_text( const Standard_Integer id,
30     const wchar_t* text,
31     const Standard_Boolean is2d = Standard_False );
32
33   //render text by last requested font
34   void render_text( const wchar_t* text,
35     const Standard_Boolean is2d = Standard_False );
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 wchar_t *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