myFTFace (NULL),
myPointSize (0U),
myLoadFlags (FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL),
- myKernAdvance(new FT_Vector()),
myUChar (0U)
{
if (myFTLib.IsNull())
Font_FTFont::~Font_FTFont()
{
Release();
- delete myKernAdvance;
}
// =======================================================================
{
if (myUChar == theUChar)
{
- return true;
+ return myUChar != 0;
}
myGlyphImg.Clear();
// function : AdvanceX
// purpose :
// =======================================================================
-float Font_FTFont::AdvanceX (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext)
+float Font_FTFont::AdvanceX (Standard_Utf32Char theUChar,
+ Standard_Utf32Char theUCharNext)
{
loadGlyph (theUChar);
return AdvanceX (theUCharNext);
// function : AdvanceY
// purpose :
// =======================================================================
-float Font_FTFont::AdvanceY (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext)
+float Font_FTFont::AdvanceY (Standard_Utf32Char theUChar,
+ Standard_Utf32Char theUCharNext)
{
loadGlyph (theUChar);
return AdvanceY (theUCharNext);
}
+bool Font_FTFont::getKerning (FT_Vector& theKern,
+ Standard_Utf32Char theUCharCurr,
+ Standard_Utf32Char theUCharNext) const
+{
+ theKern.x = 0;
+ theKern.y = 0;
+ if (theUCharNext != 0 && FT_HAS_KERNING(myFTFace) != 0)
+ {
+ const FT_UInt aCharCurr = FT_Get_Char_Index (myFTFace, theUCharCurr);
+ const FT_UInt aCharNext = FT_Get_Char_Index (myFTFace, theUCharNext);
+ if (aCharCurr == 0 || aCharNext == 0
+ || FT_Get_Kerning (myFTFace, aCharCurr, aCharNext, FT_KERNING_UNFITTED, &theKern) != 0)
+ {
+ theKern.x = 0;
+ theKern.y = 0;
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
// =======================================================================
// function : AdvanceX
// purpose :
// =======================================================================
-float Font_FTFont::AdvanceX (const Standard_Utf32Char theUCharNext)
+float Font_FTFont::AdvanceX (Standard_Utf32Char theUCharNext) const
{
if (myUChar == 0)
{
return 0.0f;
}
- if (FT_HAS_KERNING (myFTFace) == 0 || theUCharNext == 0
- || FT_Get_Kerning (myFTFace, myUChar, theUCharNext, FT_KERNING_UNFITTED, myKernAdvance) != 0)
- {
- return fromFTPoints<float> (myFTFace->glyph->advance.x);
- }
- return fromFTPoints<float> (myKernAdvance->x + myFTFace->glyph->advance.x);
+ FT_Vector aKern;
+ getKerning (aKern, myUChar, theUCharNext);
+ return fromFTPoints<float> (myFTFace->glyph->advance.x + aKern.x);
}
// =======================================================================
// function : AdvanceY
// purpose :
// =======================================================================
-float Font_FTFont::AdvanceY (const Standard_Utf32Char theUCharNext)
+float Font_FTFont::AdvanceY (Standard_Utf32Char theUCharNext) const
{
if (myUChar == 0)
{
return 0.0f;
}
- if (FT_HAS_KERNING (myFTFace) == 0 || theUCharNext == 0
- || FT_Get_Kerning (myFTFace, myUChar, theUCharNext, FT_KERNING_UNFITTED, myKernAdvance) != 0)
- {
- return fromFTPoints<float> (myFTFace->glyph->advance.y);
- }
- return fromFTPoints<float> (myKernAdvance->y + myFTFace->glyph->advance.y);
+ FT_Vector aKern;
+ getKerning (aKern, myUChar, theUCharNext);
+ return fromFTPoints<float> (myFTFace->glyph->advance.y + aKern.y);
}
// =======================================================================
return myPointSize;
}
- //! Compute advance to the next character with kerning applied when applicable.
+ //! Compute horizontal advance to the next character with kerning applied when applicable.
//! Assuming text rendered horizontally.
- Standard_EXPORT float AdvanceX (const Standard_Utf32Char theUCharNext);
+ //! @param theUCharNext the next character to compute advance from current one
+ Standard_EXPORT float AdvanceX (Standard_Utf32Char theUCharNext) const;
- //! Compute advance to the next character with kerning applied when applicable.
+ //! Compute horizontal advance to the next character with kerning applied when applicable.
//! Assuming text rendered horizontally.
- Standard_EXPORT float AdvanceX (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext);
+ //! @param theUChar the character to be loaded as current one
+ //! @param theUCharNext the next character to compute advance from current one
+ Standard_EXPORT float AdvanceX (Standard_Utf32Char theUChar,
+ Standard_Utf32Char theUCharNext);
- //! Compute advance to the next character with kerning applied when applicable.
+ //! Compute vertical advance to the next character with kerning applied when applicable.
//! Assuming text rendered vertically.
- Standard_EXPORT float AdvanceY (const Standard_Utf32Char theUCharNext);
+ //! @param theUCharNext the next character to compute advance from current one
+ Standard_EXPORT float AdvanceY (Standard_Utf32Char theUCharNext) const;
- //! Compute advance to the next character with kerning applied when applicable.
+ //! Compute vertical advance to the next character with kerning applied when applicable.
//! Assuming text rendered vertically.
- Standard_EXPORT float AdvanceY (const Standard_Utf32Char theUChar,
- const Standard_Utf32Char theUCharNext);
+ //! @param theUChar the character to be loaded as current one
+ //! @param theUCharNext the next character to compute advance from current one
+ Standard_EXPORT float AdvanceY (Standard_Utf32Char theUChar,
+ Standard_Utf32Char theUCharNext);
//! @return glyphs number in this font.
Standard_EXPORT Standard_Integer GlyphsNumber() const;
//! Load glyph without rendering it.
Standard_EXPORT bool loadGlyph (const Standard_Utf32Char theUChar);
+ //! Wrapper for FT_Get_Kerning - retrieve kerning values.
+ Standard_EXPORT bool getKerning (FT_Vector& theKern,
+ Standard_Utf32Char theUCharCurr,
+ Standard_Utf32Char theUCharNext) const;
+
protected:
Handle(Font_FTLibrary) myFTLib; //!< handle to the FT library object
int32_t myLoadFlags; //!< default load flags
Image_PixMap myGlyphImg; //!< cached glyph plane
- FT_Vector* myKernAdvance; //!< buffer variable
Standard_Utf32Char myUChar; //!< currently loaded unicode character
public: