Corrected integration.
[occt.git] / src / OpenGl / OpenGl_FontMgr.hxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #ifndef OPENGL_FONT_MGR_H
19 #define OPENGL_FONT_MGR_H
20
21 #ifdef WNT
22 # include <windows.h>
23 # include <stdlib.h>
24 #endif
25
26 #ifdef HAVE_FTGL_UPPERCASE
27 #include <FTGL.h>
28 #else
29 #include <FTGL/ftgl.h>
30 #endif
31
32 #include <InterfaceGraphic.hxx>
33 #include <TCollection_HAsciiString.hxx>
34 #include <NCollection_List.hxx>
35 #include <NCollection_DataMap.hxx>
36 #include <Graphic3d_NListOfHAsciiString.hxx>
37 #include <OSD_FontMgr.hxx>
38
39 void dump_texture();
40
41 class OpenGl_FontMgr
42 {
43  public:
44   static OpenGl_FontMgr*  instance();
45
46   int request_font( const Handle(TCollection_HAsciiString)& fontName,
47                     const OSD_FontAspect                    fontAspect,
48                     const Standard_Integer                  fontHeight );
49
50   void render_text( const Standard_Integer id,
51     const wchar_t* text,
52     const Standard_Boolean is2d = Standard_False );
53
54   //render text by last requested font
55   void render_text( const wchar_t* text,
56     const Standard_Boolean is2d = Standard_False );
57
58   //returns direct access to FTGL font
59   //Warning: don't change font pointer.
60   const FTFont*   fontById( const Standard_Integer id );
61
62   //returns width of string
63   Standard_ShortReal computeWidth( const Standard_Integer id, const wchar_t *str );
64
65   bool requestFontList( Graphic3d_NListOfHAsciiString& );
66
67   void setCurrentScale( const Standard_ShortReal xScale = 1.f,
68                         const Standard_ShortReal yScale = 1.f);
69
70 private:
71   OpenGl_FontMgr();
72   OpenGl_FontMgr( const OpenGl_FontMgr& ){};
73   OpenGl_FontMgr& operator = ( const OpenGl_FontMgr&){ return *this;};
74   ~OpenGl_FontMgr(){};
75
76   void                          _initializeFontDB();
77
78   typedef NCollection_List<Standard_Integer> IDList;
79
80   struct OGLFont_SysInfo {
81     Handle(OSD_SystemFont)            SysFont;
82     IDList                            GeneratedFonts;
83   };
84
85   struct OGLFont_Cache {
86     FTFont*            Font;
87     Standard_Integer   FontHeight;
88     GLCONTEXT          GlContext;
89   };
90
91   typedef NCollection_List<OGLFont_SysInfo*> FontDataBase;
92   typedef FontDataBase::Iterator             FontDBIt;
93   typedef NCollection_DataMap<Standard_Integer,OGLFont_Cache> FontCache;
94   typedef FontCache::Iterator                                 FCacheIt;
95
96   FontDataBase            _FontDB;
97   FontCache               _FontCache;
98
99   Standard_Integer        _CurrentFontId;
100
101   Standard_ShortReal      _XCurrentScale,
102                           _YCurrentScale;
103 };
104
105 #endif //OPENGL_FONT_MGR_H