0024271: Provide Boolean operations for NCollection_Map
[occt.git] / src / OpenGl / OpenGl_Text.hxx
1 // Created on: 2011-07-13
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 #ifndef OpenGl_Text_Header
21 #define OpenGl_Text_Header
22
23 #include <OpenGl_Element.hxx>
24
25 #include <OpenGl_AspectText.hxx>
26 #include <OpenGl_TextParam.hxx>
27 #include <OpenGl_TextFormatter.hxx>
28
29 #include <TCollection_ExtendedString.hxx>
30 #include <Graphic3d_Vertex.hxx>
31 #include <Graphic3d_HorizontalTextAlignment.hxx>
32 #include <Graphic3d_VerticalTextAlignment.hxx>
33
34 class Handle(OpenGl_PrinterContext);
35
36 //! Text rendering
37 class OpenGl_Text : public OpenGl_Element
38 {
39
40 public:
41
42   //! Main constructor
43   Standard_EXPORT OpenGl_Text (const TCollection_ExtendedString& theText,
44                                const OpenGl_Vec3&                thePoint,
45                                const OpenGl_TextParam&           theParams);
46
47   //! Setup new string and position
48   Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
49                              const Standard_Utf8Char*      theText,
50                              const OpenGl_Vec3&            thePoint);
51
52   //! Setup new string and parameters
53   Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
54                              const Standard_Utf8Char*      theText,
55                              const OpenGl_Vec3&            thePoint,
56                              const OpenGl_TextParam&       theParams);
57
58   //! Setup new position
59   Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
60
61   //! Setup new font size
62   Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
63                                     const Standard_Integer        theFontSize);
64
65   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
66   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)&   theContext);
67
68 public: //! @name methods for compatibility with layers
69
70   //! Empty constructor
71   OpenGl_Text();
72
73   //! Create key for shared resource
74   static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
75                                           const Standard_Integer   theHeight);
76
77   //! Find shared resource for specified font or initialize new one
78   static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
79                                        const OpenGl_AspectText&      theAspect,
80                                        const Standard_Integer        theHeight,
81                                        const TCollection_AsciiString theKey);
82
83   //! Compute text width
84   static void StringSize (const Handle(OpenGl_Context)& theCtx,
85                           const NCollection_String&     theText,
86                           const OpenGl_AspectText&      theTextAspect,
87                           const OpenGl_TextParam&       theParams,
88                           Standard_ShortReal&           theWidth,
89                           Standard_ShortReal&           theAscent,
90                           Standard_ShortReal&           theDescent);
91
92   //! Setup new string and parameters
93   void Init (const Handle(OpenGl_Context)&     theCtx,
94              const TCollection_ExtendedString& theText,
95              const OpenGl_Vec2&                thePoint,
96              const OpenGl_TextParam&           theParams);
97
98   //! Perform rendering
99   void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
100                const Handle(OpenGl_Context)&        theCtx,
101                const OpenGl_AspectText&             theTextAspect) const;
102
103 protected:
104
105   //! Destructor
106   Standard_EXPORT virtual ~OpenGl_Text();
107
108   friend class OpenGl_Trihedron;
109   friend class OpenGl_GraduatedTrihedron;
110
111 private:
112
113   //! Release cached VBO resources
114   void releaseVbos (const Handle(OpenGl_Context)& theCtx);
115
116   //! Setup matrix.
117   void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
118                     const Handle(OpenGl_Context)&        theCtx,
119                     const OpenGl_AspectText&             theTextAspect,
120                     const OpenGl_Vec3                    theDVec) const;
121
122   //! Draw arrays of vertices.
123   void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
124                  const Handle(OpenGl_Context)&        theCtx,
125                  const OpenGl_AspectText&             theTextAspect) const;
126
127   //! Main rendering code
128   void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
129                const Handle(OpenGl_Context)&        theCtx,
130                const OpenGl_AspectText&             theTextAspect,
131                const TEL_COLOUR&                    theColorText,
132                const TEL_COLOUR&                    theColorSubs) const;
133
134 protected:
135
136   mutable Handle(OpenGl_Font)                             myFont;
137   mutable NCollection_Vector<GLuint>                      myTextures;   //!< textures' IDs
138   mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo;   //!< VBOs of vertices
139   mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo;   //!< VBOs of texture coordinates
140   mutable NCollection_Vector<Handle(OpenGl_Vec2Array)>    myVertsArray; //!< arrays of vertices (for compatibility mode)
141   mutable NCollection_Vector<Handle(OpenGl_Vec2Array)>    myTCrdsArray; //!< arrays of vertices (for compatibility mode)
142   mutable Font_FTFont::Rect                               myBndBox;
143
144 protected:
145
146   mutable GLdouble myProjMatrix[16];
147   mutable GLdouble myModelMatrix[16];
148   mutable GLint    myViewport[4];
149   mutable GLdouble myWinX;
150   mutable GLdouble myWinY;
151   mutable GLdouble myWinZ;
152   mutable GLdouble myScaleHeight;
153   mutable GLdouble myExportHeight;
154
155 protected:
156
157   OpenGl_TextParam   myParams;
158   NCollection_String myString;
159   OpenGl_Vec3        myPoint;
160   bool               myIs2d;
161
162 public:
163
164   DEFINE_STANDARD_ALLOC
165
166 };
167
168 #endif //OpenGl_Text_Header