aFormatter.BndBox (aBndBox);
return aBndBox;
}
+
+// =======================================================================
+// function : renderGlyphOutline
+// purpose :
+// =======================================================================
+const FT_Outline* Font_FTFont::renderGlyphOutline (const Standard_Utf32Char theChar)
+{
+ if (!loadGlyph (theChar)
+ || myActiveFTFace->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
+ {
+ return 0;
+ }
+ return &myActiveFTFace->glyph->outline;
+}
// forward declarations to avoid including of FreeType headers
typedef struct FT_FaceRec_* FT_Face;
typedef struct FT_Vector_ FT_Vector;
+typedef struct FT_Outline_ FT_Outline;
class Font_FTLibrary;
//! Font initialization parameters.
return myFontParams.PointSize;
}
+ //! Return glyph scaling along X-axis.
+ float WidthScaling() const
+ {
+ return myWidthScaling;
+ }
+
//! Setup glyph scaling along X-axis.
//! By default glyphs are not scaled (scaling factor = 1.0)
void SetWidthScaling (const float theScaleFactor)
const Graphic3d_HorizontalTextAlignment theAlignX,
const Graphic3d_VerticalTextAlignment theAlignY);
+public:
+
+ //! Computes outline contour for the symbol.
+ //! @param theUChar [in] the character to be loaded as current one
+ //! @param theOutline [out] outline contour
+ //! @return true on success
+ Standard_EXPORT const FT_Outline* renderGlyphOutline(const Standard_Utf32Char theChar);
+
public:
//! Initialize the font.
#include FT_FREETYPE_H
#include FT_OUTLINE_H
-IMPLEMENT_STANDARD_RTTIEXT(StdPrs_BRepFont, Font_FTFont)
+IMPLEMENT_STANDARD_RTTIEXT(StdPrs_BRepFont, Standard_Transient)
namespace
{
my3Poles (1, 3),
my4Poles (1, 4)
{
+ myFTFont = new Font_FTFont();
init();
}
}
myScaleUnits = getScale (theSize);
- Font_FTFont::Init (theFontPath.ToCString(), THE_FONT_PARAMS, theFaceId);
+ myFTFont = new Font_FTFont();
+ myFTFont->Init (theFontPath.ToCString(), THE_FONT_PARAMS, theFaceId);
}
// =======================================================================
}
myScaleUnits = getScale (theSize);
- Font_FTFont::FindAndInit (theFontName.ToCString(), theFontAspect, THE_FONT_PARAMS, theStrictLevel);
+ myFTFont = new Font_FTFont();
+ myFTFont->FindAndInit (theFontName.ToCString(), theFontAspect, THE_FONT_PARAMS, theStrictLevel);
}
// =======================================================================
void StdPrs_BRepFont::Release()
{
myCache.Clear();
- Font_FTFont::Release();
+ myFTFont->Release();
+}
+
+// =======================================================================
+// function : FindAndCreate
+// purpose :
+// =======================================================================
+Handle(StdPrs_BRepFont) StdPrs_BRepFont::FindAndCreate (const TCollection_AsciiString& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Real theSize,
+ const Font_StrictLevel theStrictLevel)
+{
+ Handle(StdPrs_BRepFont) aFont = new StdPrs_BRepFont();
+
+ if (aFont->FindAndInit (theFontName, theFontAspect, theSize, theStrictLevel))
+ return aFont;
+
+ return Handle(StdPrs_BRepFont)();
}
// =======================================================================
}
myScaleUnits = getScale (theSize);
- return Font_FTFont::Init (theFontPath.ToCString(), THE_FONT_PARAMS, theFaceId);
+ myCache.Clear();
+ return myFTFont->Init (theFontPath.ToCString(), THE_FONT_PARAMS, theFaceId);
}
// =======================================================================
}
myScaleUnits = getScale (theSize);
- return Font_FTFont::FindAndInit (theFontName.ToCString(), theFontAspect, THE_FONT_PARAMS, theStrictLevel);
+ myCache.Clear();
+ return myFTFont->FindAndInit (theFontName.ToCString(), theFontAspect, THE_FONT_PARAMS, theStrictLevel);
}
// =======================================================================
TopoDS_Shape& theShape)
{
theShape.Nullify();
- if (!loadGlyph (theChar)
- || myActiveFTFace->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
+
+ const FT_Outline* anOutline = myFTFont->renderGlyphOutline (theChar);
+ if (!anOutline)
{
return Standard_False;
}
return !theShape.IsNull();
}
- const FT_Outline& anOutline = myActiveFTFace->glyph->outline;
- if (!anOutline.n_contours)
+ if (!anOutline->n_contours)
return Standard_False;
TopLoc_Location aLoc;
// Get orientation is useless since it doesn't retrieve any in-font information and just computes orientation.
// Because it fails in some cases - leave this to ShapeFix.
//const FT_Orientation anOrient = FT_Outline_Get_Orientation (&anOutline);
- for (short aContour = 0, aStartIndex = 0; aContour < anOutline.n_contours; ++aContour)
+ for (short aContour = 0, aStartIndex = 0; aContour < anOutline->n_contours; ++aContour)
{
- const FT_Vector* aPntList = &anOutline.points[aStartIndex];
- const char* aTags = &anOutline.tags[aStartIndex];
- const short anEndIndex = anOutline.contours[aContour];
+ const FT_Vector* aPntList = &anOutline->points[aStartIndex];
+ const char* aTags = &anOutline->tags[aStartIndex];
+ const short anEndIndex = anOutline->contours[aContour];
const short aPntsNb = (anEndIndex - aStartIndex) + 1;
aStartIndex = anEndIndex + 1;
- if (aPntsNb < 3 && !myFontParams.IsSingleStrokeFont)
+ if (aPntsNb < 3 && !myFTFont->IsSingleStrokeFont())
{
// closed contour can not be constructed from < 3 points
continue;
BRepBuilderAPI_MakeWire aWireMaker;
gp_XY aPntPrev;
- gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1], myScaleUnits, myWidthScaling);
- gp_XY aPntNext = readFTVec (aPntList[0], myScaleUnits, myWidthScaling);
+ gp_XY aPntCurr = readFTVec (aPntList[aPntsNb - 1], myScaleUnits, myFTFont->WidthScaling());
+ gp_XY aPntNext = readFTVec (aPntList[0], myScaleUnits, myFTFont->WidthScaling());
- bool isLineSeg = !myFontParams.IsSingleStrokeFont
+ bool isLineSeg = !myFTFont->IsSingleStrokeFont()
&& FT_CURVE_TAG(aTags[aPntsNb - 1]) == FT_Curve_Tag_On;
gp_XY aPntLine1 = aPntCurr;
{
aPntPrev = aPntCurr;
aPntCurr = aPntNext;
- aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb], myScaleUnits, myWidthScaling);
+ aPntNext = readFTVec (aPntList[(aPntId + 1) % aPntsNb], myScaleUnits, myFTFont->WidthScaling());
// 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], myScaleUnits, myWidthScaling)));
+ my4Poles.SetValue (4, gp_Pnt2d(readFTVec (aPntList[(aPntId + 2) % aPntsNb], myScaleUnits, myFTFont->WidthScaling())));
Handle(Geom2d_BezierCurve) aBezier = new Geom2d_BezierCurve (my4Poles);
if (myIsCompositeCurve)
{
const gp_Pnt2d aFirstPnt = aDraft2d->StartPoint();
const gp_Pnt2d aLastPnt = aDraft2d->EndPoint();
- if (!myFontParams.IsSingleStrokeFont
+ if (!myFTFont->IsSingleStrokeFont()
&& !aFirstPnt.IsEqual (aLastPnt, myPrecision))
{
Handle(Geom2d_TrimmedCurve) aLine = GCE2d_MakeSegment (aLastPnt, aFirstPnt);
TopExp::Vertices (aWireMaker.Wire(), aFirstV, aLastV);
gp_Pnt aFirstPoint = BRep_Tool::Pnt (aFirstV);
gp_Pnt aLastPoint = BRep_Tool::Pnt (aLastV);
- if (!myFontParams.IsSingleStrokeFont
+ if (!myFTFont->IsSingleStrokeFont()
&& !aFirstPoint.IsEqual (aLastPoint, myPrecision))
{
aWireMaker.Add (BRepLib_MakeEdge (aFirstV, aLastV));
}
TopoDS_Wire aWireDraft = aWireMaker.Wire();
- if (!myFontParams.IsSingleStrokeFont)
+ if (!myFTFont->IsSingleStrokeFont())
{
// collect all wires and set CCW orientation
TopoDS_Face aFace;
#include <TopoDS_Face.hxx>
#include <TopTools_SequenceOfShape.hxx>
-DEFINE_STANDARD_HANDLE(StdPrs_BRepFont, Font_FTFont)
+DEFINE_STANDARD_HANDLE(StdPrs_BRepFont, Standard_Transient)
//! 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.
//! 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.
-class StdPrs_BRepFont : protected Font_FTFont
+class StdPrs_BRepFont : public Standard_Transient
{
- DEFINE_STANDARD_RTTIEXT(StdPrs_BRepFont, Font_FTFont)
+ DEFINE_STANDARD_RTTIEXT(StdPrs_BRepFont, Standard_Transient)
public:
+ //! Find the font Initialize the font.
+ //! @param theFontName the font name
+ //! @param theFontAspect the font style
+ //! @param theSize the face size in model units
+ //! @param theStrictLevel search strict level for using aliases and fallback
+ //! @return true on success
+ Standard_EXPORT static Handle(StdPrs_BRepFont) FindAndCreate (const TCollection_AsciiString& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Real theSize,
+ const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any);
+
//! Empty constructor
Standard_EXPORT StdPrs_BRepFont();
const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any);
//! Release currently loaded font.
- Standard_EXPORT virtual void Release() Standard_OVERRIDE;
+ Standard_EXPORT virtual void Release();
//! Initialize the font.
//! @param theFontPath FULL path to the font
const Standard_Real theSize,
const Font_StrictLevel theStrictLevel = Font_StrictLevel_Any);
+ //! Return wrapper over FreeType font.
+ const Handle(Font_FTFont)& FTFont() const { return myFTFont; }
+
//! Render single glyph as TopoDS_Shape.
//! @param theChar glyph identifier
//! @return rendered glyph within cache, might be NULL shape
//! By default glyphs are not scaled (scaling factor = 1.0)
void SetWidthScaling (const float theScaleFactor)
{
- myWidthScaling = theScaleFactor;
+ myFTFont->SetWidthScaling (theScaleFactor);
}
public:
//! @return vertical distance from the horizontal baseline to the highest character coordinate.
Standard_Real Ascender() const
{
- return myScaleUnits * Standard_Real(Font_FTFont::Ascender());
+ return myScaleUnits * Standard_Real(myFTFont->Ascender());
}
//! @return vertical distance from the horizontal baseline to the lowest character coordinate.
Standard_Real Descender() const
{
- return myScaleUnits * Standard_Real(Font_FTFont::Descender());
+ return myScaleUnits * Standard_Real(myFTFont->Descender());
}
//! @return default line spacing (the baseline-to-baseline distance).
Standard_Real LineSpacing() const
{
- return myScaleUnits * Standard_Real(Font_FTFont::LineSpacing());
+ return myScaleUnits * Standard_Real(myFTFont->LineSpacing());
}
//! Configured point size
Standard_Real PointSize() const
{
- return myScaleUnits * Standard_Real(Font_FTFont::PointSize());
+ return myScaleUnits * Standard_Real(myFTFont->PointSize());
}
//! Compute advance to the next character with kerning applied when applicable.
//! Assuming text rendered horizontally.
Standard_Real AdvanceX (const Standard_Utf32Char theUCharNext)
{
- return myScaleUnits * Standard_Real(Font_FTFont::AdvanceX (theUCharNext));
+ return myScaleUnits * Standard_Real(myFTFont->AdvanceX (theUCharNext));
}
//! Compute advance to the next character with kerning applied when applicable.
Standard_Real AdvanceX (const Standard_Utf32Char theUChar,
const Standard_Utf32Char theUCharNext)
{
- return myScaleUnits * Standard_Real(Font_FTFont::AdvanceX (theUChar, theUCharNext));
+ return myScaleUnits * Standard_Real(myFTFont->AdvanceX (theUChar, theUCharNext));
}
//! Compute advance to the next character with kerning applied when applicable.
//! Assuming text rendered vertically.
Standard_Real AdvanceY (const Standard_Utf32Char theUCharNext)
{
- return myScaleUnits * Standard_Real(Font_FTFont::AdvanceY (theUCharNext));
+ return myScaleUnits * Standard_Real(myFTFont->AdvanceY (theUCharNext));
}
//! Compute advance to the next character with kerning applied when applicable.
Standard_Real AdvanceY (const Standard_Utf32Char theUChar,
const Standard_Utf32Char theUCharNext)
{
- return myScaleUnits * Standard_Real(Font_FTFont::AdvanceY (theUChar, theUCharNext));
+ return myScaleUnits * Standard_Real(myFTFont->AdvanceY (theUChar, theUCharNext));
}
//! Returns scaling factor for current font size.
Standard_Boolean buildFaces (const NCollection_Sequence<TopoDS_Wire>& theWires,
TopoDS_Shape& theRes);
- //! Hide visibility.
- using Font_FTFont::FindAndCreate;
-
protected: //! @name Protected fields
+ Handle(Font_FTFont) myFTFont; //!< wrapper over FreeType font
NCollection_DataMap<Standard_Utf32Char, TopoDS_Shape>
myCache; //!< glyphs cache
Standard_Mutex myMutex; //!< lock for thread-safety
aFormatter->Reset();
aFormatter->SetupAlignment (theHAlign, theVAlign);
- aFormatter->Append (theString, *(reinterpret_cast<Font_FTFont*> (&theFont)));
+ aFormatter->Append (theString, *theFont.FTFont());
aFormatter->Format();
return Perform (theFont, aFormatter, thePenLoc);