7fd59977 |
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 | |
33 | //render text by last requested font |
34 | void render_text( const char* text ); |
35 | |
36 | //returns direct access to FTGL font |
37 | //Warning: don't change font pointer. |
38 | const FTFont* fontById( const Standard_Integer id ); |
39 | |
40 | //returns width of string |
41 | Standard_ShortReal computeWidth( const Standard_Integer id, const char* str ); |
42 | |
43 | bool requestFontList( Graphic3d_NListOfHAsciiString& ); |
44 | |
45 | void setCurrentScale( const Standard_ShortReal xScale = 1.f, |
46 | const Standard_ShortReal yScale = 1.f); |
47 | |
48 | private: |
49 | OpenGl_FontMgr(); |
50 | OpenGl_FontMgr( const OpenGl_FontMgr& ){}; |
51 | OpenGl_FontMgr& operator = ( const OpenGl_FontMgr&){ return *this;}; |
52 | ~OpenGl_FontMgr(){}; |
53 | |
54 | void _initializeFontDB(); |
55 | |
56 | typedef NCollection_List<Standard_Integer> IDList; |
57 | |
58 | struct OGLFont_SysInfo { |
59 | Handle(OSD_SystemFont) SysFont; |
60 | IDList GeneratedFonts; |
61 | }; |
62 | |
63 | struct OGLFont_Cache { |
64 | FTFont* Font; |
65 | Standard_Integer FontHeight; |
66 | GLCONTEXT GlContext; |
67 | }; |
68 | |
69 | typedef NCollection_List<OGLFont_SysInfo*> FontDataBase; |
70 | typedef FontDataBase::Iterator FontDBIt; |
71 | typedef NCollection_DataMap<Standard_Integer,OGLFont_Cache> FontCache; |
72 | typedef FontCache::Iterator FCacheIt; |
73 | |
74 | FontDataBase _FontDB; |
75 | FontCache _FontCache; |
76 | |
77 | Standard_Integer _CurrentFontId; |
78 | |
79 | Standard_ShortReal _XCurrentScale, |
80 | _YCurrentScale; |
81 | }; |
82 | |
83 | #endif //OPENGL_FONT_MGR_H |