Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions
StdPrs_BRepFont Class Reference

This tool provides basic services for rendering of vectorized text glyphs as BRep shapes. Single instance initialize single font for sequential glyphs rendering with implicit caching of already rendered glyphs. Thus position of each glyph in the text is specified by shape location. More...

#include <StdPrs_BRepFont.hxx>

Inheritance diagram for StdPrs_BRepFont:
Inheritance graph
[legend]

Public Member Functions

 StdPrs_BRepFont ()
 Empty constructor.
 
 StdPrs_BRepFont (const NCollection_String &theFontPath, const double theSize, const int theFaceId=0)
 Constructor with initialization.
 
 StdPrs_BRepFont (const NCollection_String &theFontName, const Font_FontAspect theFontAspect, const double theSize, const Font_StrictLevel theStrictLevel=Font_StrictLevel_Any)
 Constructor with initialization.
 
virtual void Release ()
 Release currently loaded font.
 
bool Init (const NCollection_String &theFontPath, const double theSize, const int theFaceId)
 Initialize the font.
 
bool FindAndInit (const TCollection_AsciiString &theFontName, const Font_FontAspect theFontAspect, const double theSize, const Font_StrictLevel theStrictLevel=Font_StrictLevel_Any)
 Find (using Font_FontMgr) and initialize the font from the given name. Please take into account that size is specified NOT in typography points (pt.). If you need to specify size in points, value should be converted. Formula for pt. -> m conversion: aSizeMeters = 0.0254 * theSizePt / 72.0.
 
const occ::handle< Font_FTFont > & FTFont () const
 Return wrapper over FreeType font.
 
TopoDS_Shape RenderGlyph (const char32_t &theChar)
 Render single glyph as TopoDS_Shape.
 
void SetCompositeCurveMode (const bool theToConcatenate)
 Setup glyph geometry construction mode. By default algorithm creates independent TopoDS_Edge for each original curve in the glyph (line segment or Bezie curve). Algorithm might optionally create composite BSpline curve for each contour which reduces memory footprint but limits curve class to C0. Notice that altering this flag clears currently accumulated cache!
 
void SetWidthScaling (const float theScaleFactor)
 Setup glyph scaling along X-axis. By default glyphs are not scaled (scaling factor = 1.0)
 
double Ascender () const
 
double Descender () const
 
double LineSpacing () const
 
double PointSize () const
 Configured point size.
 
double AdvanceX (const char32_t theUCharNext)
 Compute advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.
 
double AdvanceX (const char32_t theUChar, const char32_t theUCharNext)
 Compute advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.
 
double AdvanceY (const char32_t theUCharNext)
 Compute advance to the next character with kerning applied when applicable. Assuming text rendered vertically.
 
double AdvanceY (const char32_t theUChar, const char32_t theUCharNext)
 Compute advance to the next character with kerning applied when applicable. Assuming text rendered vertically.
 
double Scale () const
 Returns scaling factor for current font size.
 
std::mutex & Mutex ()
 Returns mutex.
 
bool Init (const NCollection_String &theFontName, const Font_FontAspect theFontAspect, const double theSize)
 Find (using Font_FontMgr) and initialize the font from the given name. Alias for FindAndInit() for backward compatibility.
 
- 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 ()=default
 Destructor must be virtual.
 
virtual const opencascade::handle< Standard_Type > & DynamicType () const
 Returns a type descriptor about this object.
 
bool IsInstance (const opencascade::handle< Standard_Type > &theType) const
 Returns a true value if this is an instance of Type.
 
bool IsInstance (const char *const theTypeName) const
 Returns a true value if this is an instance of TypeName.
 
bool 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.
 
bool IsKind (const char *const 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.
 
int GetRefCount () const noexcept
 Get the reference counter of this object.
 
void IncrementRefCounter () noexcept
 Increments the reference counter of this object. Uses relaxed memory ordering since incrementing only requires atomicity, not synchronization with other memory operations.
 
int DecrementRefCounter () noexcept
 Decrements the reference counter of this object; returns the decremented value. Uses release ordering for the decrement to ensure all writes to the object are visible before the count reaches zero. An acquire fence is added only when the count reaches zero, ensuring proper synchronization before deletion. This is more efficient than using acq_rel for every decrement.
 
virtual void Delete () const
 Memory deallocator for transient classes.
 

Static Public Member Functions

static occ::handle< StdPrs_BRepFontFindAndCreate (const TCollection_AsciiString &theFontName, const Font_FontAspect theFontAspect, const double theSize, const Font_StrictLevel theStrictLevel=Font_StrictLevel_Any)
 Find the font Initialize the font.
 
- Static Public Member Functions inherited from Standard_Transient
static constexpr const charget_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

bool renderGlyph (const char32_t theChar, TopoDS_Shape &theShape)
 Render single glyph as TopoDS_Shape. This method does not lock the mutex.
 

Protected Attributes

Protected fields
occ::handle< Font_FTFontmyFTFont
 wrapper over FreeType font
 
NCollection_DataMap< char32_t, TopoDS_ShapemyCache
 glyphs cache
 
std::mutex myMutex
 lock for thread-safety
 
occ::handle< Geom_SurfacemySurface
 surface to place glyphs on to
 
double myPrecision
 algorithm precision
 
double myScaleUnits
 scale font rendering units into model units
 
bool myIsCompositeCurve
 flag to merge C1 curves of each contour into single C0 curve, OFF by default
 
Shared temporary variables for glyph construction
Adaptor3d_CurveOnSurface myCurvOnSurf
 
occ::handle< Geom2dAdaptor_CurvemyCurve2dAdaptor
 
Geom2dConvert_CompCurveToBSplineCurve myConcatMaker
 
NCollection_Array1< gp_Pnt2dmy3Poles
 
NCollection_Array1< gp_Pnt2dmy4Poles
 
BRep_Builder myBuilder
 

Additional Inherited Members

- Public Types inherited from Standard_Transient
typedef void base_type
 Returns a type descriptor about this object.
 

Detailed Description

This tool provides basic services for rendering of vectorized text glyphs as BRep shapes. Single instance initialize single font for sequential glyphs rendering with implicit caching of already rendered glyphs. Thus position of each glyph in the text is specified by shape location.

Please notice that this implementation uses mutex for thread-safety access, thus may lead to performance penalties in case of concurrent access. Although caching should eliminate this issue after rendering of sufficient number of glyphs.

Constructor & Destructor Documentation

◆ StdPrs_BRepFont() [1/3]

StdPrs_BRepFont::StdPrs_BRepFont ( )

Empty constructor.

◆ StdPrs_BRepFont() [2/3]

StdPrs_BRepFont::StdPrs_BRepFont ( const NCollection_String & theFontPath,
const double theSize,
const int theFaceId = 0 )

Constructor with initialization.

Parameters
theFontPathFULL path to the font
theSizethe face size in model units
theFaceIdface id within the file (0 by default)

◆ StdPrs_BRepFont() [3/3]

StdPrs_BRepFont::StdPrs_BRepFont ( const NCollection_String & theFontName,
const Font_FontAspect theFontAspect,
const double theSize,
const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any )

Constructor with initialization.

Parameters
theFontNamethe font name
theFontAspectthe font style
theSizethe face size in model units
theStrictLevelsearch strict level for using aliases and fallback

Member Function Documentation

◆ AdvanceX() [1/2]

double StdPrs_BRepFont::AdvanceX ( const char32_t theUChar,
const char32_t theUCharNext )
inline

Compute advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.

◆ AdvanceX() [2/2]

double StdPrs_BRepFont::AdvanceX ( const char32_t theUCharNext)
inline

Compute advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.

◆ AdvanceY() [1/2]

double StdPrs_BRepFont::AdvanceY ( const char32_t theUChar,
const char32_t theUCharNext )
inline

Compute advance to the next character with kerning applied when applicable. Assuming text rendered vertically.

◆ AdvanceY() [2/2]

double StdPrs_BRepFont::AdvanceY ( const char32_t theUCharNext)
inline

Compute advance to the next character with kerning applied when applicable. Assuming text rendered vertically.

◆ Ascender()

double StdPrs_BRepFont::Ascender ( ) const
inline
Returns
vertical distance from the horizontal baseline to the highest character coordinate.

◆ Descender()

double StdPrs_BRepFont::Descender ( ) const
inline
Returns
vertical distance from the horizontal baseline to the lowest character coordinate.

◆ FindAndCreate()

static occ::handle< StdPrs_BRepFont > StdPrs_BRepFont::FindAndCreate ( const TCollection_AsciiString & theFontName,
const Font_FontAspect theFontAspect,
const double theSize,
const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any )
static

Find the font Initialize the font.

Parameters
theFontNamethe font name
theFontAspectthe font style
theSizethe face size in model units
theStrictLevelsearch strict level for using aliases and fallback
Returns
true on success

◆ FindAndInit()

bool StdPrs_BRepFont::FindAndInit ( const TCollection_AsciiString & theFontName,
const Font_FontAspect theFontAspect,
const double theSize,
const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any )

Find (using Font_FontMgr) and initialize the font from the given name. Please take into account that size is specified NOT in typography points (pt.). If you need to specify size in points, value should be converted. Formula for pt. -> m conversion: aSizeMeters = 0.0254 * theSizePt / 72.0.

Parameters
theFontNamethe font name
theFontAspectthe font style
theSizethe face size in model units
theStrictLevelsearch strict level for using aliases and fallback
Returns
true on success

◆ FTFont()

const occ::handle< Font_FTFont > & StdPrs_BRepFont::FTFont ( ) const
inline

Return wrapper over FreeType font.

◆ Init() [1/2]

bool StdPrs_BRepFont::Init ( const NCollection_String & theFontName,
const Font_FontAspect theFontAspect,
const double theSize )
inline

Find (using Font_FontMgr) and initialize the font from the given name. Alias for FindAndInit() for backward compatibility.

◆ Init() [2/2]

bool StdPrs_BRepFont::Init ( const NCollection_String & theFontPath,
const double theSize,
const int theFaceId )

Initialize the font.

Parameters
theFontPathFULL path to the font
theSizethe face size in model units
theFaceIdface id within the file (0 by default)
Returns
true on success

◆ LineSpacing()

double StdPrs_BRepFont::LineSpacing ( ) const
inline
Returns
default line spacing (the baseline-to-baseline distance).

◆ Mutex()

std::mutex & StdPrs_BRepFont::Mutex ( )
inline

Returns mutex.

◆ PointSize()

double StdPrs_BRepFont::PointSize ( ) const
inline

Configured point size.

◆ Release()

virtual void StdPrs_BRepFont::Release ( )
virtual

Release currently loaded font.

◆ RenderGlyph()

TopoDS_Shape StdPrs_BRepFont::RenderGlyph ( const char32_t & theChar)

Render single glyph as TopoDS_Shape.

Parameters
theCharglyph identifier
Returns
rendered glyph within cache, might be NULL shape

◆ renderGlyph()

bool StdPrs_BRepFont::renderGlyph ( const char32_t theChar,
TopoDS_Shape & theShape )
protected

Render single glyph as TopoDS_Shape. This method does not lock the mutex.

Parameters
theCharglyph identifier
theShaperendered glyph within cache, might be NULL shape
Returns
true if glyph's geometry is available

◆ Scale()

double StdPrs_BRepFont::Scale ( ) const
inline

Returns scaling factor for current font size.

◆ SetCompositeCurveMode()

void StdPrs_BRepFont::SetCompositeCurveMode ( const bool theToConcatenate)

Setup glyph geometry construction mode. By default algorithm creates independent TopoDS_Edge for each original curve in the glyph (line segment or Bezie curve). Algorithm might optionally create composite BSpline curve for each contour which reduces memory footprint but limits curve class to C0. Notice that altering this flag clears currently accumulated cache!

◆ SetWidthScaling()

void StdPrs_BRepFont::SetWidthScaling ( const float theScaleFactor)
inline

Setup glyph scaling along X-axis. By default glyphs are not scaled (scaling factor = 1.0)

Field Documentation

◆ my3Poles

NCollection_Array1<gp_Pnt2d> StdPrs_BRepFont::my3Poles
protected

◆ my4Poles

NCollection_Array1<gp_Pnt2d> StdPrs_BRepFont::my4Poles
protected

◆ myBuilder

BRep_Builder StdPrs_BRepFont::myBuilder
protected

◆ myCache

NCollection_DataMap<char32_t, TopoDS_Shape> StdPrs_BRepFont::myCache
protected

glyphs cache

◆ myConcatMaker

Geom2dConvert_CompCurveToBSplineCurve StdPrs_BRepFont::myConcatMaker
protected

◆ myCurve2dAdaptor

occ::handle<Geom2dAdaptor_Curve> StdPrs_BRepFont::myCurve2dAdaptor
protected

◆ myCurvOnSurf

Adaptor3d_CurveOnSurface StdPrs_BRepFont::myCurvOnSurf
protected

◆ myFTFont

occ::handle<Font_FTFont> StdPrs_BRepFont::myFTFont
protected

wrapper over FreeType font

◆ myIsCompositeCurve

bool StdPrs_BRepFont::myIsCompositeCurve
protected

flag to merge C1 curves of each contour into single C0 curve, OFF by default

◆ myMutex

std::mutex StdPrs_BRepFont::myMutex
protected

lock for thread-safety

◆ myPrecision

double StdPrs_BRepFont::myPrecision
protected

algorithm precision

◆ myScaleUnits

double StdPrs_BRepFont::myScaleUnits
protected

scale font rendering units into model units

◆ mySurface

occ::handle<Geom_Surface> StdPrs_BRepFont::mySurface
protected

surface to place glyphs on to


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