#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepLib_MakeEdge.hxx>
+#include <Font_FTLibrary.hxx>
#include <Font_TextFormatter.hxx>
#include <GCE2d_MakeSegment.hxx>
#include <GC_MakeSegment.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Vertex.hxx>
+#include <ft2build.h>
+#include FT_FREETYPE_H
#include FT_OUTLINE_H
-
IMPLEMENT_STANDARD_RTTIEXT(Font_BRepFont,Font_FTFont)
namespace
return theSize / Standard_Real(THE_FONT_SIZE) * 72.0 / Standard_Real(THE_RESOLUTION_DPI);
}
+ //! Auxiliary method to convert FT_Vector to gp_XY
+ static gp_XY readFTVec (const FT_Vector& theVec,
+ const Standard_Real theScaleUnits)
+ {
+ return gp_XY (theScaleUnits * Standard_Real(theVec.x) / 64.0, theScaleUnits * Standard_Real(theVec.y) / 64.0);
+ }
+
}
// =======================================================================
BRepBuilderAPI_MakeWire aWireMaker;
gp_XY aPntPrev;
- gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1]);
- gp_XY aPntNext = readFTVec (aPntList[0]);
+ gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1], myScaleUnits);
+ gp_XY aPntNext = readFTVec (aPntList[0], myScaleUnits);
Standard_Integer aLinePnts = (FT_CURVE_TAG(aTags[aPntsNb - 1]) == FT_Curve_Tag_On) ? 1 : 0;
gp_XY aPntLine1 = aPntCurr;
{
aPntPrev = aPntCurr;
aPntCurr = aPntNext;
- aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb]);
+ aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb], myScaleUnits);
// process tags
if (FT_CURVE_TAG(aTags[aPntId]) == FT_Curve_Tag_On)
my4Poles.SetValue (1, aPntPrev);
my4Poles.SetValue (2, aPntCurr);
my4Poles.SetValue (3, aPntNext);
- my4Poles.SetValue (4, gp_Pnt2d(readFTVec (aPntList[(aPntId + 2) % aPntsNb])));
+ my4Poles.SetValue (4, gp_Pnt2d(readFTVec (aPntList[(aPntId + 2) % aPntsNb], myScaleUnits)));
Handle(Geom2d_BezierCurve) aBezier = new Geom2d_BezierCurve (my4Poles);
if (myIsCompositeCurve)
{
const GeomAbs_Shape theContinuity,
Handle(Geom_Curve)& theCurve3d);
- //! Auxiliary method to convert FT_Vector to gp_XY
- gp_XY readFTVec (const FT_Vector& theVec) const
- {
- return gp_XY (myScaleUnits * Standard_Real(theVec.x) / 64.0, myScaleUnits * Standard_Real(theVec.y) / 64.0);
- }
-
protected: //! @name Protected fields
NCollection_DataMap<Standard_Utf32Char, TopoDS_Shape>
// commercial license or contractual agreement.
#include <Font_FTFont.hxx>
+
+#include <Font_FTLibrary.hxx>
#include <Font_FontMgr.hxx>
#include <Font_TextFormatter.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_HAsciiString.hxx>
-
+#include <ft2build.h>
+#include FT_FREETYPE_H
IMPLEMENT_STANDARD_RTTIEXT(Font_FTFont,Standard_Transient)
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;
}
// =======================================================================
-// function : Font_FTFont
+// function : Release
// purpose :
// =======================================================================
void Font_FTFont::Release()
myGlyphImg.Clear();
myUChar = 0;
if (theUChar == 0
- || FT_Load_Char (myFTFace, theUChar, myLoadFlags) != 0
+ || FT_Load_Char (myFTFace, theUChar, FT_Int32(myLoadFlags)) != 0
|| myFTFace->glyph == NULL)
{
return false;
myGlyphImg.Clear();
myUChar = 0;
if (theUChar == 0
- || FT_Load_Char (myFTFace, theUChar, myLoadFlags | FT_LOAD_RENDER) != 0
+ || FT_Load_Char (myFTFace, theUChar, FT_Int32(myLoadFlags | FT_LOAD_RENDER)) != 0
|| myFTFace->glyph == NULL
|| myFTFace->glyph->format != FT_GLYPH_FORMAT_BITMAP)
{
return (unsigned int)(aHeight + 0.5f);
}
+// =======================================================================
+// function : Ascender
+// purpose :
+// =======================================================================
+float Font_FTFont::Ascender() const
+{
+ return float(myFTFace->ascender) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
+}
+
+// =======================================================================
+// function : Descender
+// purpose :
+// =======================================================================
+float Font_FTFont::Descender() const
+{
+ return float(myFTFace->descender) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
+}
+
+// =======================================================================
+// function : LineSpacing
+// purpose :
+// =======================================================================
+float Font_FTFont::LineSpacing() const
+{
+ return float(myFTFace->height) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
+}
+
// =======================================================================
// function : AdvanceX
// purpose :
}
if (FT_HAS_KERNING (myFTFace) == 0 || theUCharNext == 0
- || FT_Get_Kerning (myFTFace, myUChar, theUCharNext, FT_KERNING_UNFITTED, &myKernAdvance) != 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);
+ return fromFTPoints<float> (myKernAdvance->x + myFTFace->glyph->advance.x);
}
// =======================================================================
}
if (FT_HAS_KERNING (myFTFace) == 0 || theUCharNext == 0
- || FT_Get_Kerning (myFTFace, myUChar, theUCharNext, FT_KERNING_UNFITTED, &myKernAdvance) != 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);
+ return fromFTPoints<float> (myKernAdvance->y + myFTFace->glyph->advance.y);
+}
+
+// =======================================================================
+// function : GlyphsNumber
+// purpose :
+// =======================================================================
+Standard_Integer Font_FTFont::GlyphsNumber() const
+{
+ return myFTFace->num_glyphs;
+}
+
+// =======================================================================
+// function : theRect
+// purpose :
+// =======================================================================
+void Font_FTFont::GlyphRect (Font_Rect& theRect) const
+{
+ const FT_Bitmap& aBitmap = myFTFace->glyph->bitmap;
+ theRect.Left = float(myFTFace->glyph->bitmap_left);
+ theRect.Top = float(myFTFace->glyph->bitmap_top);
+ theRect.Right = float(myFTFace->glyph->bitmap_left + (int )aBitmap.width);
+ theRect.Bottom = float(myFTFace->glyph->bitmap_top - (int )aBitmap.rows);
}
// =======================================================================
#define _Font_FTFont_H__
#include <Font_FontAspect.hxx>
-#include <Font_FTLibrary.hxx>
#include <Font_Rect.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Image_PixMap.hxx>
#include <NCollection_String.hxx>
+// forward declarations to avoid including of FreeType headers
+typedef struct FT_FaceRec_* FT_Face;
+typedef struct FT_Vector_ FT_Vector;
+class Font_FTLibrary;
+
//! 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!
public:
//! Create uninitialized instance.
- Standard_EXPORT Font_FTFont (const Handle(Font_FTLibrary)& theFTLib = NULL);
+ Standard_EXPORT Font_FTFont (const Handle(Font_FTLibrary)& theFTLib = Handle(Font_FTLibrary)());
//! Destructor.
Standard_EXPORT virtual ~Font_FTFont();
Standard_EXPORT unsigned int GlyphMaxSizeY() const;
//! @return vertical distance from the horizontal baseline to the highest character coordinate.
- inline float Ascender() const
- {
- return float(myFTFace->ascender) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
- }
+ Standard_EXPORT float Ascender() const;
//! @return vertical distance from the horizontal baseline to the lowest character coordinate.
- inline float Descender() const
- {
- return float(myFTFace->descender) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
- }
+ Standard_EXPORT float Descender() const;
//! @return default line spacing (the baseline-to-baseline distance).
- inline float LineSpacing() const
- {
- return float(myFTFace->height) * (float(myFTFace->size->metrics.y_ppem) / float(myFTFace->units_per_EM));
- }
+ Standard_EXPORT float LineSpacing() const;
//! Configured point size
unsigned int PointSize() const
const Standard_Utf32Char theUCharNext);
//! @return glyphs number in this font.
- inline Standard_Integer GlyphsNumber() const
- {
- return myFTFace->num_glyphs;
- }
+ Standard_EXPORT Standard_Integer GlyphsNumber() const;
//! Retrieve glyph bitmap rectangle
- inline void GlyphRect (Font_Rect& theRect) const
- {
- const FT_Bitmap& aBitmap = myFTFace->glyph->bitmap;
- theRect.Left = float(myFTFace->glyph->bitmap_left);
- theRect.Top = float(myFTFace->glyph->bitmap_top);
- theRect.Right = float(myFTFace->glyph->bitmap_left + (int )aBitmap.width);
- theRect.Bottom = float(myFTFace->glyph->bitmap_top - (int )aBitmap.rows);
- }
+ Standard_EXPORT void GlyphRect (Font_Rect& theRect) const;
//! Computes bounding box of the given text using plain-text formatter (Font_TextFormatter).
//! Note that bounding box takes into account the text alignment options.
//! Convert value to 26.6 fixed-point format for FT library API.
template <typename theInput_t>
- inline FT_F26Dot6 toFTPoints (const theInput_t thePointSize) const
+ int32_t toFTPoints (const theInput_t thePointSize) const
{
- return (FT_F26Dot6)thePointSize * 64;
+ return (int32_t)thePointSize * 64;
}
//! Convert value from 26.6 fixed-point format for FT library API.
FT_Face myFTFace; //!< FT face object
NCollection_String myFontPath; //!< font path
unsigned int myPointSize; //!< point size set by FT_Set_Char_Size
- FT_Int32 myLoadFlags; //!< default load flags
+ int32_t myLoadFlags; //!< default load flags
Image_PixMap myGlyphImg; //!< cached glyph plane
- FT_Vector myKernAdvance; //!< buffer variable
+ FT_Vector* myKernAdvance; //!< buffer variable
Standard_Utf32Char myUChar; //!< currently loaded unicode character
public:
#include <Font_FTLibrary.hxx>
+#include <ft2build.h>
+#include FT_FREETYPE_H
IMPLEMENT_STANDARD_RTTIEXT(Font_FTLibrary,Standard_Transient)
#include <Standard_Type.hxx>
#include <Standard_Transient.hxx>
-// inclusion template for FreeType
-#include <ft2build.h>
-#include FT_FREETYPE_H
+// forward declarations to avoid including of FreeType headers
+typedef struct FT_LibraryRec_ *FT_Library;
//! Wrapper over FT_Library. Provides access to FreeType library.
class Font_FTLibrary : public Standard_Transient
Handle(Font_FTFont) aFontFt;
if (!aRequestedFont.IsNull())
{
- aFontFt = new Font_FTFont (NULL);
+ aFontFt = new Font_FTFont (Handle(Font_FTLibrary)());
if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, theResolution))
{