]> OCCT Git - occt-copy.git/commitdiff
Wrapping functionality in Font_TextFormatter - extending interface.
authornds <nds@opencascade.com>
Mon, 4 Mar 2019 06:31:37 +0000 (09:31 +0300)
committernds <nds@opencascade.com>
Mon, 4 Mar 2019 06:31:37 +0000 (09:31 +0300)
src/Font/Font_TextFormatter.cxx
src/Font/Font_TextFormatter.hxx

index 6bcae4c472d87de7972f18881cfcaa42c056df5b..1474a46c4650c27a8b5a9fbb0f441c30892c306c 100644 (file)
@@ -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<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;
 }
 
 // =======================================================================
@@ -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);
 }
 
 // =======================================================================
index fdc2295d02b31dff4e7ae6070b853431e6f01054..79958ca8ef3209ef3735d144e55a6735b02cec36 100755 (executable)
@@ -152,16 +152,22 @@ public:
 
   //! 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;
@@ -274,7 +280,7 @@ protected: //! @name input data
   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