OCCT3D OCCT 8.0.1
OCCT documentation

Search guides and API reference

Enter at least two characters.

    Open CASCADE Technology Reference Manual 8.0.1
    Font_FTFont Class Reference

    Wrapper over FreeType font. Notice that this class uses internal buffers for loaded glyphs and it is absolutely UNSAFE to load/read glyph from concurrent threads! More...

    #include <Font_FTFont.hxx>

    Inheritance diagram for Font_FTFont:

    Public Member Functions

     Font_FTFont (const occ::handle< Font_FTLibrary > &theFTLib=occ::handle< Font_FTLibrary >())
     Create uninitialized instance.
     ~Font_FTFont () override
     Destructor.
    bool IsValid () const
    const Image_PixMapGlyphImage () const
    bool Init (const TCollection_AsciiString &theFontPath, const Font_FTFontParams &theParams, const int theFaceId=0)
     Initialize the font from the given file path.
    bool Init (const occ::handle< NCollection_Buffer > &theData, const TCollection_AsciiString &theFileName, const Font_FTFontParams &theParams, const int theFaceId=0)
     Initialize the font from the given file path or memory buffer.
    bool FindAndInit (const TCollection_AsciiString &theFontName, Font_FontAspect theFontAspect, const Font_FTFontParams &theParams, Font_StrictLevel theStrictLevel=Font_StrictLevel_Any)
     Find (using Font_FontMgr) and initialize the font from the given name.
    bool ToUseUnicodeSubsetFallback () const
     Return flag to use fallback fonts in case if used font does not include symbols from specific Unicode subset; TRUE by default.
    void SetUseUnicodeSubsetFallback (bool theToFallback)
     Set if fallback fonts should be used in case if used font does not include symbols from specific Unicode subset.
    bool IsSingleStrokeFont () const
     Return TRUE if this is single-stroke (one-line) font, FALSE by default. Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.
    void SetSingleStrokeFont (bool theIsSingleLine)
     Set if this font should be rendered as single-stroke (one-line).
    bool ToSynthesizeItalic () const
     Return TRUE if italic style should be synthesized; FALSE by default.
    virtual void Release ()
     Release currently loaded font.
    bool RenderGlyph (const char32_t theChar)
     Render specified glyph into internal buffer (bitmap).
    unsigned int GlyphMaxSizeX (bool theToIncludeFallback=false) const
    unsigned int GlyphMaxSizeY (bool theToIncludeFallback=false) const
    float Ascender () const
    float Descender () const
    float LineSpacing () const
    unsigned int PointSize () const
     Configured point size.
    float WidthScaling () const
     Return glyph scaling along X-axis.
    void SetWidthScaling (const float theScaleFactor)
     Setup glyph scaling along X-axis. By default glyphs are not scaled (scaling factor = 1.0).
    bool HasSymbol (char32_t theUChar) const
     Return TRUE if font contains specified symbol (excluding fallback list).
    float AdvanceX (char32_t theUCharNext) const
     Compute horizontal advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.
    float AdvanceX (char32_t theUChar, char32_t theUCharNext)
     Compute horizontal advance to the next character with kerning applied when applicable. Assuming text rendered horizontally.
    float AdvanceY (char32_t theUCharNext) const
     Compute vertical advance to the next character with kerning applied when applicable. Assuming text rendered vertically.
    float AdvanceY (char32_t theUChar, char32_t theUCharNext)
     Compute vertical advance to the next character with kerning applied when applicable. Assuming text rendered vertically.
    int GlyphsNumber (bool theToIncludeFallback=false) const
     Return glyphs number in this font.
    void GlyphRect (Font_Rect &theRect) const
     Retrieve glyph bitmap rectangle.
    Font_Rect BoundingBox (const NCollection_String &theString, const Graphic3d_HorizontalTextAlignment theAlignX, const Graphic3d_VerticalTextAlignment theAlignY)
     Computes bounding box of the given text using plain-text formatter (Font_TextFormatter). Note that bounding box takes into account the text alignment options. Its corners are relative to the text alignment anchor point, their coordinates can be negative.
    const FT_OutlinerenderGlyphOutline (const char32_t theChar)
     Computes outline contour for the symbol.
    parameters bool Init (const NCollection_String &theFontPath, unsigned int thePointSize, unsigned int theResolution)
     Initialize the font.
    parameters bool Init (const NCollection_String &theFontName, Font_FontAspect theFontAspect, unsigned int thePointSize, unsigned int theResolution)
     Initialize the font.
    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< Font_FTFontFindAndCreate (const TCollection_AsciiString &theFontName, const Font_FontAspect theFontAspect, const Font_FTFontParams &theParams, const Font_StrictLevel theStrictLevel=Font_StrictLevel_Any)
     Find the font Initialize the font.
    static bool IsCharFromCJK (char32_t theUChar)
     Return TRUE if specified character is within subset of modern CJK characters.
    static bool IsCharFromHiragana (char32_t theUChar)
     Return TRUE if specified character is within subset of Hiragana (Japanese).
    static bool IsCharFromKatakana (char32_t theUChar)
     Return TRUE if specified character is within subset of Katakana (Japanese).
    static bool IsCharFromKorean (char32_t theUChar)
     Return TRUE if specified character is within subset of modern Korean characters (Hangul).
    static bool IsCharFromArabic (char32_t theUChar)
     Return TRUE if specified character is within subset of Arabic characters.
    static bool IsCharRightToLeft (char32_t theUChar)
     Return TRUE if specified character should be displayed in Right-to-Left order.
    static Font_UnicodeSubset CharSubset (char32_t theUChar)
     Determine Unicode subset for specified character.
    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

    template<typename theInput_t>
    int32_t toFTPoints (const theInput_t thePointSize) const
     Convert value to 26.6 fixed-point format for FT library API.
    template<typename theReturn_t, typename theFTUnits_t>
    theReturn_t fromFTPoints (const theFTUnits_t theFTUnits) const
     Convert value from 26.6 fixed-point format for FT library API.
    bool loadGlyph (const char32_t theUChar)
     Load glyph without rendering it.
    bool getKerning (FT_Vector &theKern, char32_t theUCharCurr, char32_t theUCharNext) const
     Wrapper for FT_Get_Kerning - retrieve kerning values.
    bool findAndInitFallback (Font_UnicodeSubset theSubset)
     Initialize fallback font.
    void setLoadFlag (int32_t theFlag, bool theToEnable)
     Enable/disable load flag.

    Protected Attributes

    occ::handle< Font_FTLibrarymyFTLib
     handle to the FT library object
    occ::handle< NCollection_BuffermyBuffer
     memory buffer
    occ::handle< Font_FTFontmyFallbackFaces [Font_UnicodeSubset_NB]
     fallback fonts
    FT_Face myFTFace
     FT face object.
    FT_Face myActiveFTFace
     active FT face object (the main of fallback)
    TCollection_AsciiString myFontPath
     font path
    Font_FTFontParams myFontParams
     font initialization parameters
    Font_FontAspect myFontAspect
     font initialization aspect
    float myWidthScaling
     scale glyphs along X-axis
    int32_t myLoadFlags
     default load flags
    Image_PixMap myGlyphImg
     cached glyph plane
    char32_t myUChar
     currently loaded unicode character
    bool myToUseUnicodeSubsetFallback
     use default fallback fonts for extended Unicode sub-sets (Korean, CJK, etc.)

    Additional Inherited Members

    typedef void base_type
     Returns a type descriptor about this object.

    Detailed Description

    Wrapper over FreeType font. Notice that this class uses internal buffers for loaded glyphs and it is absolutely UNSAFE to load/read glyph from concurrent threads!

    Constructor & Destructor Documentation

    ◆ Font_FTFont()

    Font_FTFont::Font_FTFont ( const occ::handle< Font_FTLibrary > & theFTLib = occ::handleFont_FTLibrary >())

    Create uninitialized instance.

    ◆ ~Font_FTFont()

    Font_FTFont::~Font_FTFont ( )
    override

    Destructor.

    Member Function Documentation

    ◆ AdvanceX() [1/2]

    float Font_FTFont::AdvanceX ( char32_t theUChar,
    char32_t theUCharNext )

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

    Parameters
    theUCharthe character to be loaded as current one
    theUCharNextthe next character to compute advance from current one

    ◆ AdvanceX() [2/2]

    float Font_FTFont::AdvanceX ( char32_t theUCharNext) const

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

    Parameters
    theUCharNextthe next character to compute advance from current one

    ◆ AdvanceY() [1/2]

    float Font_FTFont::AdvanceY ( char32_t theUChar,
    char32_t theUCharNext )

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

    Parameters
    theUCharthe character to be loaded as current one
    theUCharNextthe next character to compute advance from current one

    ◆ AdvanceY() [2/2]

    float Font_FTFont::AdvanceY ( char32_t theUCharNext) const

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

    Parameters
    theUCharNextthe next character to compute advance from current one

    ◆ Ascender()

    float Font_FTFont::Ascender ( ) const
    Returns
    vertical distance from the horizontal baseline to the highest character coordinate.

    ◆ BoundingBox()

    Font_Rect Font_FTFont::BoundingBox ( const NCollection_String & theString,
    const Graphic3d_HorizontalTextAlignment theAlignX,
    const Graphic3d_VerticalTextAlignment theAlignY )

    Computes bounding box of the given text using plain-text formatter (Font_TextFormatter). Note that bounding box takes into account the text alignment options. Its corners are relative to the text alignment anchor point, their coordinates can be negative.

    ◆ CharSubset()

    Font_UnicodeSubset Font_FTFont::CharSubset ( char32_t theUChar)
    inlinestatic

    Determine Unicode subset for specified character.

    ◆ Descender()

    float Font_FTFont::Descender ( ) const
    Returns
    vertical distance from the horizontal baseline to the lowest character coordinate.

    ◆ FindAndCreate()

    occ::handle< Font_FTFont > Font_FTFont::FindAndCreate ( const TCollection_AsciiString & theFontName,
    const Font_FontAspect theFontAspect,
    const Font_FTFontParams & theParams,
    const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any )
    static

    Find the font Initialize the font.

    Parameters
    theFontNamethe font name
    theFontAspectthe font style
    theParamsinitialization parameters
    theStrictLevelsearch strict level for using aliases and fallback
    Returns
    true on success

    ◆ FindAndInit()

    bool Font_FTFont::FindAndInit ( const TCollection_AsciiString & theFontName,
    Font_FontAspect theFontAspect,
    const Font_FTFontParams & theParams,
    Font_StrictLevel theStrictLevel = Font_StrictLevel_Any )

    Find (using Font_FontMgr) and initialize the font from the given name.

    Parameters
    theFontNamethe font name
    theFontAspectthe font style
    theParamsinitialization parameters
    theStrictLevelsearch strict level for using aliases and fallback
    Returns
    true on success

    ◆ findAndInitFallback()

    bool Font_FTFont::findAndInitFallback ( Font_UnicodeSubset theSubset)
    protected

    Initialize fallback font.

    ◆ fromFTPoints()

    template<typename theReturn_t, typename theFTUnits_t>
    theReturn_t Font_FTFont::fromFTPoints ( const theFTUnits_t theFTUnits) const
    inlineprotected

    Convert value from 26.6 fixed-point format for FT library API.

    ◆ getKerning()

    bool Font_FTFont::getKerning ( FT_Vector & theKern,
    char32_t theUCharCurr,
    char32_t theUCharNext ) const
    protected

    Wrapper for FT_Get_Kerning - retrieve kerning values.

    ◆ GlyphImage()

    const Image_PixMap & Font_FTFont::GlyphImage ( ) const
    inline
    Returns
    image plane for currently rendered glyph

    ◆ GlyphMaxSizeX()

    unsigned int Font_FTFont::GlyphMaxSizeX ( bool theToIncludeFallback = false) const
    Returns
    maximal glyph width in pixels (rendered to bitmap).

    ◆ GlyphMaxSizeY()

    unsigned int Font_FTFont::GlyphMaxSizeY ( bool theToIncludeFallback = false) const
    Returns
    maximal glyph height in pixels (rendered to bitmap).

    ◆ GlyphRect()

    void Font_FTFont::GlyphRect ( Font_Rect & theRect) const

    Retrieve glyph bitmap rectangle.

    ◆ GlyphsNumber()

    int Font_FTFont::GlyphsNumber ( bool theToIncludeFallback = false) const

    Return glyphs number in this font.

    Parameters
    theToIncludeFallbackif TRUE then the number will include fallback list

    ◆ HasSymbol()

    bool Font_FTFont::HasSymbol ( char32_t theUChar) const

    Return TRUE if font contains specified symbol (excluding fallback list).

    ◆ Init() [1/4]

    parameters bool Font_FTFont::Init ( const NCollection_String & theFontName,
    Font_FontAspect theFontAspect,
    unsigned int thePointSize,
    unsigned int theResolution )
    inline

    Initialize the font.

    Parameters
    theFontNamethe font name
    theFontAspectthe font style
    thePointSizethe face size in points (1/72 inch)
    theResolutionthe resolution of the target device in dpi
    Returns
    true on success
    Deprecated
    ("Deprecated method, Font_FTFontParams should be used for passing "

    ◆ Init() [2/4]

    parameters bool Font_FTFont::Init ( const NCollection_String & theFontPath,
    unsigned int thePointSize,
    unsigned int theResolution )
    inline

    Initialize the font.

    Parameters
    theFontPathpath to the font
    thePointSizethe face size in points (1/72 inch)
    theResolutionthe resolution of the target device in dpi
    Returns
    true on success
    Deprecated
    ("Deprecated method, Font_FTFontParams should be used for passing "

    ◆ Init() [3/4]

    bool Font_FTFont::Init ( const occ::handle< NCollection_Buffer > & theData,
    const TCollection_AsciiString & theFileName,
    const Font_FTFontParams & theParams,
    const int theFaceId = 0 )

    Initialize the font from the given file path or memory buffer.

    Parameters
    theDatamemory to read from, should NOT be freed after initialization! when NULL, function will attempt to open theFileName file
    theFileNameoptional path to the font
    theParamsinitialization parameters
    theFaceIdface id within the file (0 by default)
    Returns
    true on success

    ◆ Init() [4/4]

    bool Font_FTFont::Init ( const TCollection_AsciiString & theFontPath,
    const Font_FTFontParams & theParams,
    const int theFaceId = 0 )
    inline

    Initialize the font from the given file path.

    Parameters
    theFontPathpath to the font
    theParamsinitialization parameters
    theFaceIdface id within the file (0 by default)
    Returns
    true on success

    ◆ IsCharFromArabic()

    bool Font_FTFont::IsCharFromArabic ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character is within subset of Arabic characters.

    ◆ IsCharFromCJK()

    bool Font_FTFont::IsCharFromCJK ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character is within subset of modern CJK characters.

    ◆ IsCharFromHiragana()

    bool Font_FTFont::IsCharFromHiragana ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character is within subset of Hiragana (Japanese).

    ◆ IsCharFromKatakana()

    bool Font_FTFont::IsCharFromKatakana ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character is within subset of Katakana (Japanese).

    ◆ IsCharFromKorean()

    bool Font_FTFont::IsCharFromKorean ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character is within subset of modern Korean characters (Hangul).

    ◆ IsCharRightToLeft()

    bool Font_FTFont::IsCharRightToLeft ( char32_t theUChar)
    inlinestatic

    Return TRUE if specified character should be displayed in Right-to-Left order.

    ◆ IsSingleStrokeFont()

    bool Font_FTFont::IsSingleStrokeFont ( ) const
    inline

    Return TRUE if this is single-stroke (one-line) font, FALSE by default. Such fonts define single-line glyphs instead of closed contours, so that they are rendered incorrectly by normal software.

    ◆ IsValid()

    bool Font_FTFont::IsValid ( ) const
    inline
    Returns
    true if font is loaded

    ◆ LineSpacing()

    float Font_FTFont::LineSpacing ( ) const
    Returns
    default line spacing (the baseline-to-baseline distance).

    ◆ loadGlyph()

    bool Font_FTFont::loadGlyph ( const char32_t theUChar)
    protected

    Load glyph without rendering it.

    ◆ PointSize()

    unsigned int Font_FTFont::PointSize ( ) const
    inline

    Configured point size.

    ◆ Release()

    virtual void Font_FTFont::Release ( )
    virtual

    Release currently loaded font.

    ◆ RenderGlyph()

    bool Font_FTFont::RenderGlyph ( const char32_t theChar)

    Render specified glyph into internal buffer (bitmap).

    ◆ renderGlyphOutline()

    const FT_Outline * Font_FTFont::renderGlyphOutline ( const char32_t theChar)

    Computes outline contour for the symbol.

    Parameters
    [in]theUCharthe character to be loaded as current one
    [out]theOutlineoutline contour
    Returns
    true on success

    ◆ setLoadFlag()

    void Font_FTFont::setLoadFlag ( int32_t theFlag,
    bool theToEnable )
    inlineprotected

    Enable/disable load flag.

    ◆ SetSingleStrokeFont()

    void Font_FTFont::SetSingleStrokeFont ( bool theIsSingleLine)
    inline

    Set if this font should be rendered as single-stroke (one-line).

    ◆ SetUseUnicodeSubsetFallback()

    void Font_FTFont::SetUseUnicodeSubsetFallback ( bool theToFallback)
    inline

    Set if fallback fonts should be used in case if used font does not include symbols from specific Unicode subset.

    ◆ SetWidthScaling()

    void Font_FTFont::SetWidthScaling ( const float theScaleFactor)
    inline

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

    ◆ toFTPoints()

    template<typename theInput_t>
    int32_t Font_FTFont::toFTPoints ( const theInput_t thePointSize) const
    inlineprotected

    Convert value to 26.6 fixed-point format for FT library API.

    ◆ ToSynthesizeItalic()

    bool Font_FTFont::ToSynthesizeItalic ( ) const
    inline

    Return TRUE if italic style should be synthesized; FALSE by default.

    ◆ ToUseUnicodeSubsetFallback()

    bool Font_FTFont::ToUseUnicodeSubsetFallback ( ) const
    inline

    Return flag to use fallback fonts in case if used font does not include symbols from specific Unicode subset; TRUE by default.

    See also
    Font_FontMgr::ToUseUnicodeSubsetFallback()

    ◆ WidthScaling()

    float Font_FTFont::WidthScaling ( ) const
    inline

    Return glyph scaling along X-axis.

    Field Documentation

    ◆ myActiveFTFace

    FT_Face Font_FTFont::myActiveFTFace
    protected

    active FT face object (the main of fallback)

    ◆ myBuffer

    occ::handle<NCollection_Buffer> Font_FTFont::myBuffer
    protected

    memory buffer

    ◆ myFallbackFaces

    occ::handle<Font_FTFont> Font_FTFont::myFallbackFaces[Font_UnicodeSubset_NB]
    protected

    fallback fonts

    ◆ myFontAspect

    Font_FontAspect Font_FTFont::myFontAspect
    protected

    font initialization aspect

    ◆ myFontParams

    Font_FTFontParams Font_FTFont::myFontParams
    protected

    font initialization parameters

    ◆ myFontPath

    TCollection_AsciiString Font_FTFont::myFontPath
    protected

    font path

    ◆ myFTFace

    FT_Face Font_FTFont::myFTFace
    protected

    FT face object.

    ◆ myFTLib

    occ::handle<Font_FTLibrary> Font_FTFont::myFTLib
    protected

    handle to the FT library object

    ◆ myGlyphImg

    Image_PixMap Font_FTFont::myGlyphImg
    protected

    cached glyph plane

    ◆ myLoadFlags

    int32_t Font_FTFont::myLoadFlags
    protected

    default load flags

    ◆ myToUseUnicodeSubsetFallback

    bool Font_FTFont::myToUseUnicodeSubsetFallback
    protected

    use default fallback fonts for extended Unicode sub-sets (Korean, CJK, etc.)

    ◆ myUChar

    char32_t Font_FTFont::myUChar
    protected

    currently loaded unicode character

    ◆ myWidthScaling

    float Font_FTFont::myWidthScaling
    protected

    scale glyphs along X-axis


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