0024890: Result of uniform scaling is invalid
[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
317d68c9 19#include <Font_FTFont.hxx>
20#include <NCollection_DataMap.hxx>
21#include <NCollection_Vector.hxx>
a174a3c5 22
a174a3c5 23//! This class intended to prepare formatted text.
317d68c9 24class Font_TextFormatter
a174a3c5 25{
a174a3c5 26public:
27
28 //! Default constructor.
317d68c9 29 Standard_EXPORT Font_TextFormatter();
a174a3c5 30
31 //! Setup alignment style.
32 Standard_EXPORT void SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
33 const Graphic3d_VerticalTextAlignment theAlignY);
34
35 //! Reset current progress.
36 Standard_EXPORT void Reset();
37
38 //! Render specified text to inner buffer.
317d68c9 39 Standard_EXPORT void Append (const NCollection_String& theString,
40 Font_FTFont& theFont);
a174a3c5 41
42 //! Perform formatting on the buffered text.
43 //! Should not be called more than once after initialization!
44 Standard_EXPORT void Format();
45
317d68c9 46 //! Returns specific glyph rectangle.
47 inline const NCollection_Vec2<Standard_ShortReal>& TopLeft (const Standard_Integer theIndex) const
48 {
49 return myCorners.Value (theIndex);
50 }
a174a3c5 51
317d68c9 52 //! Returns current rendering string.
53 inline const NCollection_String& String() const
54 {
55 return myString;
56 }
57
58 //! Returns tab size.
59 inline Standard_Integer TabSize() const
60 {
61 return myTabSize;
62 }
a174a3c5 63
a174a3c5 64 //! @return width of formatted text.
65 inline Standard_ShortReal ResultWidth() const
66 {
67 return myBndWidth;
68 }
69
70 //! @return height of formatted text.
71 inline Standard_ShortReal ResultHeight() const
72 {
73 return myLineSpacing * Standard_ShortReal(myLinesNb);
74 }
75
76 //! @param bounding box.
77 inline void BndBox (Font_FTFont::Rect& theBndBox) const
78 {
79 theBndBox.Left = 0.0f;
80 switch (myAlignX)
81 {
82 default:
83 case Graphic3d_HTA_LEFT: theBndBox.Right = myBndWidth; break;
84 case Graphic3d_HTA_RIGHT: theBndBox.Right = -myBndWidth; break;
85 case Graphic3d_HTA_CENTER:
86 {
87 theBndBox.Left = -0.5f * myBndWidth;
88 theBndBox.Right = 0.5f * myBndWidth;
89 break;
90 }
91 }
92 theBndBox.Top = myBndTop;
93 theBndBox.Bottom = theBndBox.Top - myLineSpacing * Standard_ShortReal(myLinesNb);
94 }
95
96protected: //! @name class auxiliary methods
97
98 //! Move glyphs on the current line to correct position.
99 Standard_EXPORT void newLine (const Standard_Integer theLastRect);
100
101protected: //! @name configuration
102
103 Graphic3d_HorizontalTextAlignment myAlignX; //!< horizontal alignment style
104 Graphic3d_VerticalTextAlignment myAlignY; //!< vertical alignment style
105 Standard_Integer myTabSize; //!< horizontal tabulation width (number of space symbols)
106
107protected: //! @name input data
108
109 NCollection_String myString; //!< currently rendered text
317d68c9 110 NCollection_Vec2<Standard_ShortReal>
111 myPen; //!< current pen position
112 NCollection_Vector < NCollection_Vec2<Standard_ShortReal> >
113 myCorners; //!< The top left corners of a formatted rectangles.
a174a3c5 114 Standard_Integer myRectsNb; //!< rectangles number
115 NCollection_Vector<Standard_ShortReal>
116 myNewLines; //!< position at LF
117 Standard_ShortReal myLineSpacing; //!< line spacing (computed as maximum of all fonts involved in text formatting)
118 Standard_ShortReal myAscender; //!<
119 bool myIsFormatted; //!< formatting state
120
a174a3c5 121protected: //! @name temporary variables for formatting routines
122
123 Standard_Integer myLinesNb; //!< overall (new)lines number (including splitting by width limit)
124 Standard_Integer myRectLineStart; //!< id of first rectangle on the current line
125 Standard_Integer myRectWordStart; //!< id of first rectangle in the current word
126 Standard_Integer myNewLineNb;
127
128 Standard_ShortReal myPenCurrLine; //!< current baseline position
a174a3c5 129 Standard_ShortReal myBndTop;
130 Standard_ShortReal myBndWidth;
317d68c9 131 NCollection_Vec2<Standard_ShortReal>
132 myMoveVec; //!< local variable
a174a3c5 133};
134
317d68c9 135#endif // Font_TextFormatter_Header