0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Font / Font_TextFormatter.hxx
CommitLineData
a174a3c5 1// Created on: 2013-01-29
2// Created by: Kirill GAVRILOV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
a174a3c5 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
a174a3c5 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
a174a3c5 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
a174a3c5 15
317d68c9 16#ifndef Font_TextFormatter_Header
17#define Font_TextFormatter_Header
a174a3c5 18
d2eddacc 19#include <Font_Rect.hxx>
20#include <Graphic3d_HorizontalTextAlignment.hxx>
21#include <Graphic3d_VerticalTextAlignment.hxx>
317d68c9 22#include <NCollection_DataMap.hxx>
23#include <NCollection_Vector.hxx>
d2eddacc 24#include <NCollection_String.hxx>
25
26class Font_FTFont;
a174a3c5 27
a174a3c5 28//! This class intended to prepare formatted text.
317d68c9 29class Font_TextFormatter
a174a3c5 30{
a174a3c5 31public:
32
33 //! Default constructor.
317d68c9 34 Standard_EXPORT Font_TextFormatter();
a174a3c5 35
36 //! Setup alignment style.
37 Standard_EXPORT void SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
38 const Graphic3d_VerticalTextAlignment theAlignY);
39
40 //! Reset current progress.
41 Standard_EXPORT void Reset();
42
43 //! Render specified text to inner buffer.
317d68c9 44 Standard_EXPORT void Append (const NCollection_String& theString,
45 Font_FTFont& theFont);
a174a3c5 46
47 //! Perform formatting on the buffered text.
48 //! Should not be called more than once after initialization!
49 Standard_EXPORT void Format();
50
317d68c9 51 //! Returns specific glyph rectangle.
52 inline const NCollection_Vec2<Standard_ShortReal>& TopLeft (const Standard_Integer theIndex) const
53 {
54 return myCorners.Value (theIndex);
55 }
a174a3c5 56
317d68c9 57 //! Returns current rendering string.
58 inline const NCollection_String& String() const
59 {
60 return myString;
61 }
62
63 //! Returns tab size.
64 inline Standard_Integer TabSize() const
65 {
66 return myTabSize;
67 }
a174a3c5 68
a174a3c5 69 //! @return width of formatted text.
70 inline Standard_ShortReal ResultWidth() const
71 {
72 return myBndWidth;
73 }
74
75 //! @return height of formatted text.
76 inline Standard_ShortReal ResultHeight() const
77 {
78 return myLineSpacing * Standard_ShortReal(myLinesNb);
79 }
80
81 //! @param bounding box.
d2eddacc 82 inline void BndBox (Font_Rect& theBndBox) const
a174a3c5 83 {
84 theBndBox.Left = 0.0f;
85 switch (myAlignX)
86 {
87 default:
88 case Graphic3d_HTA_LEFT: theBndBox.Right = myBndWidth; break;
89 case Graphic3d_HTA_RIGHT: theBndBox.Right = -myBndWidth; break;
90 case Graphic3d_HTA_CENTER:
91 {
92 theBndBox.Left = -0.5f * myBndWidth;
93 theBndBox.Right = 0.5f * myBndWidth;
94 break;
95 }
96 }
97 theBndBox.Top = myBndTop;
98 theBndBox.Bottom = theBndBox.Top - myLineSpacing * Standard_ShortReal(myLinesNb);
99 }
100
101protected: //! @name class auxiliary methods
102
103 //! Move glyphs on the current line to correct position.
104 Standard_EXPORT void newLine (const Standard_Integer theLastRect);
105
106protected: //! @name configuration
107
108 Graphic3d_HorizontalTextAlignment myAlignX; //!< horizontal alignment style
109 Graphic3d_VerticalTextAlignment myAlignY; //!< vertical alignment style
110 Standard_Integer myTabSize; //!< horizontal tabulation width (number of space symbols)
111
112protected: //! @name input data
113
114 NCollection_String myString; //!< currently rendered text
317d68c9 115 NCollection_Vec2<Standard_ShortReal>
116 myPen; //!< current pen position
117 NCollection_Vector < NCollection_Vec2<Standard_ShortReal> >
118 myCorners; //!< The top left corners of a formatted rectangles.
a174a3c5 119 Standard_Integer myRectsNb; //!< rectangles number
120 NCollection_Vector<Standard_ShortReal>
121 myNewLines; //!< position at LF
122 Standard_ShortReal myLineSpacing; //!< line spacing (computed as maximum of all fonts involved in text formatting)
123 Standard_ShortReal myAscender; //!<
124 bool myIsFormatted; //!< formatting state
125
a174a3c5 126protected: //! @name temporary variables for formatting routines
127
128 Standard_Integer myLinesNb; //!< overall (new)lines number (including splitting by width limit)
129 Standard_Integer myRectLineStart; //!< id of first rectangle on the current line
130 Standard_Integer myRectWordStart; //!< id of first rectangle in the current word
131 Standard_Integer myNewLineNb;
132
133 Standard_ShortReal myPenCurrLine; //!< current baseline position
a174a3c5 134 Standard_ShortReal myBndTop;
135 Standard_ShortReal myBndWidth;
317d68c9 136 NCollection_Vec2<Standard_ShortReal>
137 myMoveVec; //!< local variable
a174a3c5 138};
139
317d68c9 140#endif // Font_TextFormatter_Header