Open CASCADE Technology 7.8.2.dev
Font_TextFormatter Class Reference

This class is intended to prepare formatted text by using:
More...

#include <Font_TextFormatter.hxx>

Inheritance diagram for Font_TextFormatter:

Data Structures

class  Iterator
 Iterator through formatted symbols. It's possible to filter returned symbols to have only significant ones. More...
 

Public Types

enum  IterationFilter { IterationFilter_None = 0x0000 , IterationFilter_ExcludeInvisible = 0x0002 }
 Iteration filter flags. Command symbols are skipped with any filter. More...
 
- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 

Public Member Functions

 Font_TextFormatter ()
 Default constructor.
 
void SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX, const Graphic3d_VerticalTextAlignment theAlignY)
 Setup alignment style.
 
void Reset ()
 Reset current progress.
 
void Append (const NCollection_String &theString, Font_FTFont &theFont)
 Render specified text to inner buffer.
 
void Format ()
 Perform formatting on the buffered text. Should not be called more than once after initialization!
 
const NCollection_Vec2< Standard_ShortReal > & TopLeft (const Standard_Integer theIndex) const
 
const NCollection_Vec2< Standard_ShortReal > & BottomLeft (const Standard_Integer theIndex) const
 Returns specific glyph rectangle.
 
const NCollection_StringString () const
 Returns current rendering string.
 
Standard_Boolean GlyphBoundingBox (const Standard_Integer theIndex, Font_Rect &theBndBox) const
 Returns symbol bounding box.
 
Standard_ShortReal LineHeight (const Standard_Integer theIndex) const
 Returns the line height.
 
Standard_ShortReal LineWidth (const Standard_Integer theIndex) const
 Returns width of a line.
 
Standard_Boolean IsLFSymbol (const Standard_Integer theIndex) const
 Returns true if the symbol by the index is '
'. The width of the symbol is zero.
 
Standard_ShortReal FirstPosition () const
 Returns position of the first symbol in a line using alignment.
 
Standard_Integer LinePositionIndex (const Standard_Integer theIndex) const
 Returns column index of the corner index in the current line.
 
Standard_Integer LineIndex (const Standard_Integer theIndex) const
 Returns row index of the corner index among text lines.
 
Standard_Integer TabSize () const
 Returns tab size.
 
Graphic3d_HorizontalTextAlignment HorizontalTextAlignment () const
 Returns horizontal alignment style.
 
Graphic3d_VerticalTextAlignment VerticalTextAlignment () const
 Returns vertical alignment style.
 
void SetWrapping (const Standard_ShortReal theWidth)
 Sets text wrapping width, zero means that the text is not bounded by width.
 
Standard_Boolean HasWrapping () const
 Returns text maximum width, zero means that the text is not bounded by width.
 
Standard_ShortReal Wrapping () const
 Returns text maximum width, zero means that the text is not bounded by width.
 
Standard_Boolean WordWrapping () const
 returns TRUE when trying not to break words when wrapping text
 
void SetWordWrapping (const Standard_Boolean theIsWordWrapping)
 returns TRUE when trying not to break words when wrapping text
 
Standard_ShortReal ResultWidth () const
 
Standard_ShortReal ResultHeight () const
 
Standard_ShortReal MaximumSymbolWidth () const
 
void BndBox (Font_Rect &theBndBox) const
 
const NCollection_Vector< NCollection_Vec2< Standard_ShortReal > > & Corners () const
 Returns internal container of the top left corners of a formatted rectangles.
 
const NCollection_Vector< Standard_ShortReal > & NewLines () const
 Returns container of each line position at LF in formatted text.
 
- Public Member Functions inherited from Standard_Transient
 Standard_Transient ()
 Empty constructor.
 
 Standard_Transient (const Standard_Transient &)
 Copy constructor – does nothing.
 
Standard_Transientoperator= (const Standard_Transient &)
 Assignment operator, needed to avoid copying reference counter.
 
virtual ~Standard_Transient ()
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
Standard_Boolean IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
Standard_Boolean IsInstance (const Standard_CString theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
Standard_Boolean IsKind (const opencascade::handle< Standard_Type > &theType) const
 Returns true if this is an instance of Type or an instance of any class that inherits from Type. Note that multiple inheritance is not supported by OCCT RTTI mechanism.
 
Standard_Boolean IsKind (const Standard_CString theTypeName) const
 Returns true if this is an instance of TypeName or an instance of any class that inherits from TypeName. Note that multiple inheritance is not supported by OCCT RTTI mechanism.
 
Standard_TransientThis () const
 Returns non-const pointer to this object (like const_cast). For protection against creating handle to objects allocated in stack or call from constructor, it will raise exception Standard_ProgramError if reference counter is zero.
 
Standard_Integer GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object.
 
Standard_Integer DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Static Public Member Functions

static Standard_Boolean IsCommandSymbol (const Standard_Utf32Char &theSymbol)
 Returns true if the symbol is CR, BEL, FF, NP, BS or VT.
 
static Standard_Boolean IsSeparatorSymbol (const Standard_Utf32Char &theSymbol)
 Returns true if the symbol separates words when wrapping is enabled.
 
- Static Public Member Functions inherited from Standard_Transient
static constexpr const char * get_type_name ()
 Returns a type descriptor about this object.
 
static const opencascade::handle< Standard_Type > & get_type_descriptor ()
 Returns type descriptor of Standard_Transient class.
 

Protected Member Functions

class auxiliary methods
void newLine (const Standard_Integer theLastRect, const Standard_ShortReal theMaxLineWidth)
 Move glyphs on the current line to correct position.
 

Protected Attributes

configuration
Graphic3d_HorizontalTextAlignment myAlignX
 horizontal alignment style
 
Graphic3d_VerticalTextAlignment myAlignY
 vertical alignment style
 
Standard_Integer myTabSize
 horizontal tabulation width (number of space symbols)
 
Standard_ShortReal myWrappingWidth
 text is wrapped by the width if defined (more 0)
 
Standard_Boolean myIsWordWrapping
 if TRUE try not to break words when wrapping text (true by default)
 
Standard_ShortReal myLastSymbolWidth
 width of the last symbol
 
Standard_ShortReal myMaxSymbolWidth
 maximum symbol width of the formatter string
 
input data
NCollection_String myString
 currently rendered text
 
NCollection_Vec2< Standard_ShortRealmyPen
 current pen position
 
NCollection_Vector< NCollection_Vec2< Standard_ShortReal > > myCorners
 The bottom left corners of a formatted rectangles.
 
NCollection_Vector< Standard_ShortRealmyNewLines
 position at LF
 
Standard_ShortReal myLineSpacing
 line spacing (computed as maximum of all fonts involved in text formatting)
 
Standard_ShortReal myAscender
 line spacing for the first line
 
bool myIsFormatted
 formatting state
 
temporary variables for formatting routines
Standard_Integer myLinesNb
 overall (new)lines number (including splitting by width limit)
 
Standard_Integer myRectLineStart
 id of first rectangle on the current line
 
Standard_Integer myNewLineNb
 overall (new)lines number (including splitting by width limit)
 
Standard_ShortReal myPenCurrLine
 current baseline position
 
Standard_ShortReal myBndTop
 overall (new)lines number (including splitting by width limit)
 
Standard_ShortReal myBndWidth
 overall (new)lines number (including splitting by width limit)
 
NCollection_Vec2< Standard_ShortRealmyMoveVec
 local variable
 

Detailed Description

This class is intended to prepare formatted text by using:

  • font to string combination,
  • alignment,
  • wrapping.

After text formatting, each symbol of formatted text is placed in some position. Further work with the formatter is using an iterator. The iterator gives an access to each symbol inside the initial row. Also it's possible to get only significant/writable symbols of the text.
Formatter gives an access to geometrical position of a symbol by the symbol index in the text.
Example of correspondence of some text symbol to an index in "row_1\n\nrow_2\n":
"row_1\n" - 0-5 indices;
"\n" - 6 index;
"\n" - 7 index;
"row_2\n" - 8-13 indices.
Pay attention that fonts should have the same LineSpacing value for correct formatting.
Example of the formatter using:

aFormatter->Append(text_1, aFont1);
aFormatter->Append(text_2, aFont2);
// setting of additional properties such as wrapping or alignment
aFormatter->Format();
#define Handle(Class)
Define Handle() macro.
Definition Standard_Handle.hxx:399
This class is intended to prepare formatted text by using:
Definition Font_TextFormatter.hxx:55
Font_TextFormatter()
Default constructor.

Member Enumeration Documentation

◆ IterationFilter

Iteration filter flags. Command symbols are skipped with any filter.

Enumerator
IterationFilter_None 

no filter

IterationFilter_ExcludeInvisible 

exclude ' ', '\t', '
'

Constructor & Destructor Documentation

◆ Font_TextFormatter()

Font_TextFormatter::Font_TextFormatter ( )

Default constructor.

Member Function Documentation

◆ Append()

void Font_TextFormatter::Append ( const NCollection_String & theString,
Font_FTFont & theFont )

Render specified text to inner buffer.

◆ BndBox()

void Font_TextFormatter::BndBox ( Font_Rect & theBndBox) const
inline
Parameters
boundingbox.

◆ BottomLeft()

const NCollection_Vec2< Standard_ShortReal > & Font_TextFormatter::BottomLeft ( const Standard_Integer theIndex) const
inline

Returns specific glyph rectangle.

◆ Corners()

const NCollection_Vector< NCollection_Vec2< Standard_ShortReal > > & Font_TextFormatter::Corners ( ) const
inline

Returns internal container of the top left corners of a formatted rectangles.

◆ FirstPosition()

Standard_ShortReal Font_TextFormatter::FirstPosition ( ) const

Returns position of the first symbol in a line using alignment.

◆ Format()

void Font_TextFormatter::Format ( )

Perform formatting on the buffered text. Should not be called more than once after initialization!

◆ GlyphBoundingBox()

Standard_Boolean Font_TextFormatter::GlyphBoundingBox ( const Standard_Integer theIndex,
Font_Rect & theBndBox ) const

Returns symbol bounding box.

Parameters
boundingbox.

◆ HasWrapping()

Standard_Boolean Font_TextFormatter::HasWrapping ( ) const
inline

Returns text maximum width, zero means that the text is not bounded by width.

◆ HorizontalTextAlignment()

Graphic3d_HorizontalTextAlignment Font_TextFormatter::HorizontalTextAlignment ( ) const
inline

Returns horizontal alignment style.

◆ IsCommandSymbol()

static Standard_Boolean Font_TextFormatter::IsCommandSymbol ( const Standard_Utf32Char & theSymbol)
inlinestatic

Returns true if the symbol is CR, BEL, FF, NP, BS or VT.

◆ IsLFSymbol()

Standard_Boolean Font_TextFormatter::IsLFSymbol ( const Standard_Integer theIndex) const

Returns true if the symbol by the index is '
'. The width of the symbol is zero.

◆ IsSeparatorSymbol()

static Standard_Boolean Font_TextFormatter::IsSeparatorSymbol ( const Standard_Utf32Char & theSymbol)
inlinestatic

Returns true if the symbol separates words when wrapping is enabled.

◆ LineHeight()

Standard_ShortReal Font_TextFormatter::LineHeight ( const Standard_Integer theIndex) const
inline

Returns the line height.

Parameters
theIndexa line index, obtained by LineIndex()

◆ LineIndex()

Standard_Integer Font_TextFormatter::LineIndex ( const Standard_Integer theIndex) const

Returns row index of the corner index among text lines.

◆ LinePositionIndex()

Standard_Integer Font_TextFormatter::LinePositionIndex ( const Standard_Integer theIndex) const

Returns column index of the corner index in the current line.

◆ LineWidth()

Standard_ShortReal Font_TextFormatter::LineWidth ( const Standard_Integer theIndex) const

Returns width of a line.

◆ MaximumSymbolWidth()

Standard_ShortReal Font_TextFormatter::MaximumSymbolWidth ( ) const
inline
Returns
maximum width of the text symbol

◆ newLine()

void Font_TextFormatter::newLine ( const Standard_Integer theLastRect,
const Standard_ShortReal theMaxLineWidth )
protected

Move glyphs on the current line to correct position.

◆ NewLines()

const NCollection_Vector< Standard_ShortReal > & Font_TextFormatter::NewLines ( ) const
inline

Returns container of each line position at LF in formatted text.

◆ Reset()

void Font_TextFormatter::Reset ( )

Reset current progress.

◆ ResultHeight()

Standard_ShortReal Font_TextFormatter::ResultHeight ( ) const
inline
Returns
height of formatted text.

◆ ResultWidth()

Standard_ShortReal Font_TextFormatter::ResultWidth ( ) const
inline
Returns
width of formatted text.

◆ SetupAlignment()

void Font_TextFormatter::SetupAlignment ( const Graphic3d_HorizontalTextAlignment theAlignX,
const Graphic3d_VerticalTextAlignment theAlignY )

Setup alignment style.

◆ SetWordWrapping()

void Font_TextFormatter::SetWordWrapping ( const Standard_Boolean theIsWordWrapping)
inline

returns TRUE when trying not to break words when wrapping text

◆ SetWrapping()

void Font_TextFormatter::SetWrapping ( const Standard_ShortReal theWidth)
inline

Sets text wrapping width, zero means that the text is not bounded by width.

◆ String()

const NCollection_String & Font_TextFormatter::String ( ) const
inline

Returns current rendering string.

◆ TabSize()

Standard_Integer Font_TextFormatter::TabSize ( ) const
inline

Returns tab size.

◆ TopLeft()

const NCollection_Vec2< Standard_ShortReal > & Font_TextFormatter::TopLeft ( const Standard_Integer theIndex) const
inline
Deprecated
("BottomLeft should be used instead")

◆ VerticalTextAlignment()

Graphic3d_VerticalTextAlignment Font_TextFormatter::VerticalTextAlignment ( ) const
inline

Returns vertical alignment style.

◆ WordWrapping()

Standard_Boolean Font_TextFormatter::WordWrapping ( ) const
inline

returns TRUE when trying not to break words when wrapping text

◆ Wrapping()

Standard_ShortReal Font_TextFormatter::Wrapping ( ) const
inline

Returns text maximum width, zero means that the text is not bounded by width.

Field Documentation

◆ myAlignX

Graphic3d_HorizontalTextAlignment Font_TextFormatter::myAlignX
protected

horizontal alignment style

◆ myAlignY

Graphic3d_VerticalTextAlignment Font_TextFormatter::myAlignY
protected

vertical alignment style

◆ myAscender

Standard_ShortReal Font_TextFormatter::myAscender
protected

line spacing for the first line

◆ myBndTop

Standard_ShortReal Font_TextFormatter::myBndTop
protected

overall (new)lines number (including splitting by width limit)

◆ myBndWidth

Standard_ShortReal Font_TextFormatter::myBndWidth
protected

overall (new)lines number (including splitting by width limit)

◆ myCorners

NCollection_Vector< NCollection_Vec2<Standard_ShortReal> > Font_TextFormatter::myCorners
protected

The bottom left corners of a formatted rectangles.

◆ myIsFormatted

bool Font_TextFormatter::myIsFormatted
protected

formatting state

◆ myIsWordWrapping

Standard_Boolean Font_TextFormatter::myIsWordWrapping
protected

if TRUE try not to break words when wrapping text (true by default)

◆ myLastSymbolWidth

Standard_ShortReal Font_TextFormatter::myLastSymbolWidth
protected

width of the last symbol

◆ myLinesNb

Standard_Integer Font_TextFormatter::myLinesNb
protected

overall (new)lines number (including splitting by width limit)

◆ myLineSpacing

Standard_ShortReal Font_TextFormatter::myLineSpacing
protected

line spacing (computed as maximum of all fonts involved in text formatting)

◆ myMaxSymbolWidth

Standard_ShortReal Font_TextFormatter::myMaxSymbolWidth
protected

maximum symbol width of the formatter string

◆ myMoveVec

NCollection_Vec2<Standard_ShortReal> Font_TextFormatter::myMoveVec
protected

local variable

◆ myNewLineNb

Standard_Integer Font_TextFormatter::myNewLineNb
protected

overall (new)lines number (including splitting by width limit)

◆ myNewLines

NCollection_Vector<Standard_ShortReal> Font_TextFormatter::myNewLines
protected

position at LF

◆ myPen

NCollection_Vec2<Standard_ShortReal> Font_TextFormatter::myPen
protected

current pen position

◆ myPenCurrLine

Standard_ShortReal Font_TextFormatter::myPenCurrLine
protected

current baseline position

◆ myRectLineStart

Standard_Integer Font_TextFormatter::myRectLineStart
protected

id of first rectangle on the current line

◆ myString

NCollection_String Font_TextFormatter::myString
protected

currently rendered text

◆ myTabSize

Standard_Integer Font_TextFormatter::myTabSize
protected

horizontal tabulation width (number of space symbols)

◆ myWrappingWidth

Standard_ShortReal Font_TextFormatter::myWrappingWidth
protected

text is wrapped by the width if defined (more 0)


The documentation for this class was generated from the following file: