From 763193957592f8927e228b6932b238b97bd5e7d2 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 4 Mar 2019 09:31:37 +0300 Subject: [PATCH] Wrapping functionality in Font_TextFormatter - extending interface. --- src/Font/Font_TextFormatter.cxx | 31 +++++++++++++++++++------------ src/Font/Font_TextFormatter.hxx | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Font/Font_TextFormatter.cxx b/src/Font/Font_TextFormatter.cxx index 6bcae4c472..1474a46c46 100644 --- a/src/Font/Font_TextFormatter.cxx +++ b/src/Font/Font_TextFormatter.cxx @@ -312,7 +312,7 @@ Standard_Boolean Font_TextFormatter::BndBox (const Standard_Integer theIndex, Fo theBndBox.Left = aLeftCorner.x(); theBndBox.Bottom = aLeftCorner.y(); theBndBox.Top = theBndBox.Bottom + myLineSpacing; - if (Abs (aLeftCorner.y() - aNextLeftCorner.y()) < Precision::Confusion()) + if (Abs (aLeftCorner.y() - aNextLeftCorner.y()) < Precision::Confusion()) // in the same row { theBndBox.Right = aNextLeftCorner.x(); } @@ -339,26 +339,33 @@ Standard_Boolean Font_TextFormatter::BndBox (const Standard_Integer theIndex, Fo return Standard_True; } + // ======================================================================= -// function : LastLFBndBox +// function : IsLFSymbol // purpose : // ======================================================================= -Standard_Boolean Font_TextFormatter::LastLFBndBox (Font_Rect& theBndBox) const +Standard_Boolean Font_TextFormatter::IsLFSymbol (const Standard_Integer theIndex) const { - if (GetCorners().Length() == 0 || myLastSymbolWidth > 0.0f) + Font_Rect aBndBox; + if (!BndBox (theIndex, aBndBox)) return Standard_False; - const NCollection_Vec2& aLastCorner = BottomLeft (GetCorners().Length() -1); + return Abs (aBndBox.Right - aBndBox.Left) < Precision::Confusion(); +} - theBndBox.Top = aLastCorner.y(); - theBndBox.Bottom = theBndBox.Top - myLineSpacing; +// ======================================================================= +// function : GetFirstPosition +// purpose : +// ======================================================================= +Standard_ShortReal Font_TextFormatter::GetFirstPosition() const +{ switch (myAlignX) { - case Graphic3d_HTA_LEFT: theBndBox.Left = theBndBox.Right = 0; break; - case Graphic3d_HTA_RIGHT: theBndBox.Left = theBndBox.Right = myBndWidth; break; - case Graphic3d_HTA_CENTER: theBndBox.Left = theBndBox.Right = 0.5f * myBndWidth; break; + default: + case Graphic3d_HTA_LEFT: return 0; break; + case Graphic3d_HTA_RIGHT: return myBndWidth; break; + case Graphic3d_HTA_CENTER: return 0.5f * myBndWidth; break; } - return Standard_True; } // ======================================================================= @@ -388,7 +395,7 @@ Standard_Integer Font_TextFormatter::LineIndex (const Standard_Integer theIndex) if (myLineSpacing < 0.0f) return 0; - return (Standard_Integer)Abs((BottomLeft (theIndex).y() + myLineSpacing) / myLineSpacing); + return (Standard_Integer)Abs((BottomLeft (theIndex).y() + myAscender) / myLineSpacing); } // ======================================================================= diff --git a/src/Font/Font_TextFormatter.hxx b/src/Font/Font_TextFormatter.hxx index fdc2295d02..79958ca8ef 100755 --- a/src/Font/Font_TextFormatter.hxx +++ b/src/Font/Font_TextFormatter.hxx @@ -152,16 +152,22 @@ public: //! Returns specific glyph rectangle. inline const NCollection_Vec2& BottomLeft (const Standard_Integer theIndex) const - { - return myCorners.Value (theIndex); - } + { return myCorners.Value (theIndex); } //! Returns symbol bounding box //! @param bounding box. Standard_EXPORT Standard_Boolean BndBox (const Standard_Integer theIndex, Font_Rect& theBndBox) const; - //! Returns true if the last symbol is caret. Creates bounding box of the next row symbol position - Standard_EXPORT Standard_Boolean LastLFBndBox (Font_Rect& theBndBox) const; + //! Returns the line height + //! \param theIndex a line index, obtained by LineIndex() + Standard_ShortReal LineHeight (const Standard_Integer theIndex) const + { return theIndex == 0 ? myAscender : myLineSpacing; } + + //! Returns true if the symbol by the index is '\n'. The width of the symbol is zero. + Standard_EXPORT Standard_Boolean IsLFSymbol (const Standard_Integer theIndex) const; + + //! Returns position of the first symbol in a line using alignment + Standard_EXPORT Standard_ShortReal GetFirstPosition() const; //! Returns column index of the corner index in the current line Standard_EXPORT Standard_Integer LinePositionIndex (const Standard_Integer theIndex) const; @@ -274,7 +280,7 @@ protected: //! @name input data NCollection_Vector myNewLines; //!< position at LF Standard_ShortReal myLineSpacing; //!< line spacing (computed as maximum of all fonts involved in text formatting) - Standard_ShortReal myAscender; //!< + Standard_ShortReal myAscender; //!< line spacing for the first line bool myIsFormatted; //!< formatting state protected: //! @name temporary variables for formatting routines -- 2.39.5