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();
}
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<Standard_ShortReal>& 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;
}
// =======================================================================
if (myLineSpacing < 0.0f)
return 0;
- return (Standard_Integer)Abs((BottomLeft (theIndex).y() + myLineSpacing) / myLineSpacing);
+ return (Standard_Integer)Abs((BottomLeft (theIndex).y() + myAscender) / myLineSpacing);
}
// =======================================================================
//! Returns specific glyph rectangle.
inline const NCollection_Vec2<Standard_ShortReal>& 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;
NCollection_Vector<Standard_ShortReal>
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