From: kgv Date: Mon, 17 Jul 2017 08:12:48 +0000 (+0300) Subject: 0028915: Configuration, Font_BRepFont - do not include FreeType headers within OCCT... X-Git-Tag: V7_2_0_beta~35 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=f9801cf97ab753fb656cd72b243168ef6f72d3b5 0028915: Configuration, Font_BRepFont - do not include FreeType headers within OCCT headers --- diff --git a/src/Font/Font_BRepFont.cxx b/src/Font/Font_BRepFont.cxx index a1fcfb7ec9..ff3e47e62d 100755 --- a/src/Font/Font_BRepFont.cxx +++ b/src/Font/Font_BRepFont.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -45,9 +46,10 @@ #include #include +#include +#include FT_FREETYPE_H #include FT_OUTLINE_H - IMPLEMENT_STANDARD_RTTIEXT(Font_BRepFont,Font_FTFont) namespace @@ -62,6 +64,13 @@ 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); + } + } // ======================================================================= @@ -277,8 +286,8 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar, 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; @@ -289,7 +298,7 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar, { 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) @@ -373,7 +382,7 @@ Standard_Boolean Font_BRepFont::renderGlyph (const Standard_Utf32Char theChar, 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) { diff --git a/src/Font/Font_BRepFont.hxx b/src/Font/Font_BRepFont.hxx index 9ed0fa77b9..dbbf7d0c0d 100755 --- a/src/Font/Font_BRepFont.hxx +++ b/src/Font/Font_BRepFont.hxx @@ -183,12 +183,6 @@ private: 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 diff --git a/src/Font/Font_FTFont.cxx b/src/Font/Font_FTFont.cxx index 5c1498a29d..b51cac3f8c 100755 --- a/src/Font/Font_FTFont.cxx +++ b/src/Font/Font_FTFont.cxx @@ -14,12 +14,13 @@ // commercial license or contractual agreement. #include + +#include #include #include -#include -#include - +#include +#include FT_FREETYPE_H IMPLEMENT_STANDARD_RTTIEXT(Font_FTFont,Standard_Transient) @@ -32,6 +33,7 @@ Font_FTFont::Font_FTFont (const Handle(Font_FTLibrary)& theFTLib) myFTFace (NULL), myPointSize (0U), myLoadFlags (FT_LOAD_NO_HINTING | FT_LOAD_TARGET_NORMAL), + myKernAdvance(new FT_Vector()), myUChar (0U) { if (myFTLib.IsNull()) @@ -47,10 +49,11 @@ Font_FTFont::Font_FTFont (const Handle(Font_FTLibrary)& theFTLib) Font_FTFont::~Font_FTFont() { Release(); + delete myKernAdvance; } // ======================================================================= -// function : Font_FTFont +// function : Release // purpose : // ======================================================================= void Font_FTFont::Release() @@ -134,7 +137,7 @@ bool Font_FTFont::loadGlyph (const Standard_Utf32Char theUChar) 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; @@ -153,7 +156,7 @@ bool Font_FTFont::RenderGlyph (const Standard_Utf32Char theUChar) 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) { @@ -200,6 +203,33 @@ unsigned int Font_FTFont::GlyphMaxSizeY() const 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 : @@ -234,11 +264,11 @@ float Font_FTFont::AdvanceX (const Standard_Utf32Char theUCharNext) } 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 (myFTFace->glyph->advance.x); } - return fromFTPoints (myKernAdvance.x + myFTFace->glyph->advance.x); + return fromFTPoints (myKernAdvance->x + myFTFace->glyph->advance.x); } // ======================================================================= @@ -253,11 +283,33 @@ float Font_FTFont::AdvanceY (const Standard_Utf32Char theUCharNext) } 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 (myFTFace->glyph->advance.y); } - return fromFTPoints (myKernAdvance.y + myFTFace->glyph->advance.y); + return fromFTPoints (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); } // ======================================================================= diff --git a/src/Font/Font_FTFont.hxx b/src/Font/Font_FTFont.hxx index 13b3054567..4d500fe0b0 100755 --- a/src/Font/Font_FTFont.hxx +++ b/src/Font/Font_FTFont.hxx @@ -17,13 +17,17 @@ #define _Font_FTFont_H__ #include -#include #include #include #include #include #include +// 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! @@ -32,7 +36,7 @@ class Font_FTFont : public Standard_Transient 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(); @@ -82,22 +86,13 @@ public: 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 @@ -124,20 +119,10 @@ public: 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. @@ -150,9 +135,9 @@ protected: //! Convert value to 26.6 fixed-point format for FT library API. template - 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. @@ -173,10 +158,10 @@ protected: 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: diff --git a/src/Font/Font_FTLibrary.cxx b/src/Font/Font_FTLibrary.cxx index 1b9654238d..31976bffc3 100755 --- a/src/Font/Font_FTLibrary.cxx +++ b/src/Font/Font_FTLibrary.cxx @@ -15,6 +15,8 @@ #include +#include +#include FT_FREETYPE_H IMPLEMENT_STANDARD_RTTIEXT(Font_FTLibrary,Standard_Transient) diff --git a/src/Font/Font_FTLibrary.hxx b/src/Font/Font_FTLibrary.hxx index bd7e65ad95..48eb411975 100755 --- a/src/Font/Font_FTLibrary.hxx +++ b/src/Font/Font_FTLibrary.hxx @@ -19,9 +19,8 @@ #include #include -// inclusion template for FreeType -#include -#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 diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 69a1ec6b1e..1219a76807 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -658,7 +658,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx, 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)) {