]> OCCT Git - occt-copy.git/commitdiff
0030537: Visualization - wrapping text in font text formatter - correction after...
authornds <nds@opencascade.com>
Fri, 2 Aug 2019 04:11:31 +0000 (07:11 +0300)
committernds <nds@opencascade.com>
Fri, 2 Aug 2019 04:11:31 +0000 (07:11 +0300)
src/Font/Font_BRepTextBuilder.cxx
src/Font/Font_FTFont.cxx
src/Font/Font_TextFormatter.cxx
src/Font/Font_TextFormatter.hxx
src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_Context.hxx
src/OpenGl/OpenGl_Text.cxx
src/OpenGl/OpenGl_TextBuilder.cxx

index dc476acf609df36e47544fe9406f372965c68c20..b1c979cfa38b86623e0eec5e4d97ff42d354e2a9 100644 (file)
@@ -34,7 +34,7 @@ TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont&            theFont,
   myBuilder.MakeCompound (aResult);
 
   Standard_Real aScaleUnits    = theFont.Scale();
-  for (Font_TextFormatter::Iterator aFormatterIt (theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
+  for (Font_TextFormatter::Iterator aFormatterIt (*theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
        aFormatterIt .More(); aFormatterIt .Next())
   {
     const NCollection_Vec2<Standard_ShortReal>& aCorner = theFormatter->BottomLeft (aFormatterIt.SymbolPosition());
index 5e91d4e10f6fd3721424df8cd98299f5056397e3..22a1297c4dd215109b51467f053a848ed35e5be8 100755 (executable)
@@ -406,14 +406,14 @@ Font_Rect Font_FTFont::BoundingBox (const NCollection_String&               theS
                                     const Graphic3d_HorizontalTextAlignment theAlignX,
                                     const Graphic3d_VerticalTextAlignment   theAlignY)
 {
-  Handle(Font_TextFormatter) aFormatter = new Font_TextFormatter();
-  aFormatter->SetupAlignment (theAlignX, theAlignY);
-  aFormatter->Reset();
+  Font_TextFormatter aFormatter;
+  aFormatter.SetupAlignment (theAlignX, theAlignY);
+  aFormatter.Reset();
 
-  aFormatter->Append (theString, *this);
-  aFormatter->Format();
+  aFormatter.Append (theString, *this);
+  aFormatter.Format();
 
   Font_Rect aBndBox;
-  aFormatter->BndBox (aBndBox);
+  aFormatter.BndBox (aBndBox);
   return aBndBox;
 }
index 7cbb083e19d94ffe0dd85874b994eda159ceec59..dfb764f4e89fb2344d5eb485f8ebf0c8cc0c8a95 100644 (file)
@@ -126,15 +126,14 @@ void Font_TextFormatter::Append (const NCollection_String& theString,
   int aSymbolsCounter = 0; // special counter to process tabulation symbols
 
   // first pass - render all symbols using associated font on single ZERO baseline
-  Handle(Font_TextFormatter) aFormatter (this);
   Standard_Utf32Char aCharThis;
-  for (Font_TextFormatter::Iterator aFormatterIt (aFormatter); aFormatterIt .More(); aFormatterIt .Next())
+  for (Font_TextFormatter::Iterator aFormatterIt (*this); aFormatterIt .More(); aFormatterIt .Next())
   {
     aCharThis = aFormatterIt.Symbol();
     const Standard_Utf32Char aCharNext = aFormatterIt.SymbolNext();
 
     Standard_ShortReal anAdvanceX = 0;
-    if (Font_TextFormatter::IsCommandSymbol (aCharThis))
+    if (IsCommandSymbol (aCharThis))
     {
       continue; // skip unsupported carriage control codes
     }
@@ -176,7 +175,7 @@ void Font_TextFormatter::newLine (const Standard_Integer theLastRect,
   Standard_Integer aFirstCornerId = myRectLineStart;
   Standard_Integer aLastCornerId = theLastRect;
 
-  if (aFirstCornerId >= getRectsNb())
+  if (aFirstCornerId >= myCorners.Length())
   {
     ++myLinesNb;
     myPenCurrLine -= myLineSpacing;
@@ -210,7 +209,7 @@ void Font_TextFormatter::newLine (const Standard_Integer theLastRect,
 // =======================================================================
 void Font_TextFormatter::Format()
 {
-  if (getRectsNb() == 0 || myIsFormatted)
+  if (myCorners.Length() == 0 || myIsFormatted)
   {
     return;
   }
@@ -243,8 +242,7 @@ void Font_TextFormatter::Format()
     }
   }
 
-  Handle(Font_TextFormatter) aFormatter (this);
-  for (Font_TextFormatter::Iterator aFormatterIt (aFormatter);
+  for (Font_TextFormatter::Iterator aFormatterIt (*this);
        aFormatterIt .More(); aFormatterIt .Next())
   {
     const Standard_Utf32Char aCharThis = aFormatterIt.Symbol();
@@ -275,7 +273,7 @@ void Font_TextFormatter::Format()
   myBndWidth = aMaxLineWidth;
 
   // move last line
-  newLine (getRectsNb() - 1, aMaxLineWidth);
+  newLine (myCorners.Length() - 1, aMaxLineWidth);
 
   // apply vertical alignment style
   if (myAlignY == Graphic3d_VTA_BOTTOM)
@@ -293,7 +291,7 @@ void Font_TextFormatter::Format()
 
   if (myAlignY != Graphic3d_VTA_TOP)
   {
-    moveY (myCorners, myBndTop, 0, getRectsNb() - 1);
+    moveY (myCorners, myBndTop, 0, myCorners.Length() - 1);
   }
 }
 
@@ -303,7 +301,7 @@ void Font_TextFormatter::Format()
 // =======================================================================
 Standard_Boolean Font_TextFormatter::BndBox (const Standard_Integer theIndex, Font_Rect& theBndBox) const
 {
-  if (theIndex < 0 || theIndex >= GetCorners().Size())
+  if (theIndex < 0 || theIndex >= Corners().Size())
     return Standard_False;
 
   const NCollection_Vec2<Standard_ShortReal>& aLeftCorner = BottomLeft (theIndex);
@@ -355,10 +353,10 @@ Standard_Boolean Font_TextFormatter::IsLFSymbol (const Standard_Integer theIndex
 }
 
 // =======================================================================
-// function : GetFirstPosition
+// function : FirstPosition
 // purpose  :
 // =======================================================================
-Standard_ShortReal Font_TextFormatter::GetFirstPosition() const
+Standard_ShortReal Font_TextFormatter::FirstPosition() const
 {
   switch (myAlignX)
   {
@@ -399,22 +397,6 @@ Standard_Integer Font_TextFormatter::LineIndex (const Standard_Integer theIndex)
   return (Standard_Integer)Abs((BottomLeft (theIndex).y() + myAscender) / myLineSpacing);
 }
 
-// =======================================================================
-// function : IsCommandSymbol
-// purpose  :
-// =======================================================================
-Standard_Boolean Font_TextFormatter::IsCommandSymbol (const Standard_Utf32Char& theSymbol)
-{
-  if (theSymbol == '\x0D' // CR  (carriage return)
-   || theSymbol == '\a'   // BEL (alarm)
-   || theSymbol == '\f'   // FF  (form feed) NP (new page)
-   || theSymbol == '\b'   // BS  (backspace)
-   || theSymbol == '\v')  // VT  (vertical tab)
-   return Standard_True;
-
-  return Standard_False;
-}
-
 // =======================================================================
 // function : LineWidth
 // purpose  :
index 40444078682148737323260cd434e02ccdda82f8..7a950091bf5f05413fdd7fad1f47bdda36150883 100755 (executable)
@@ -61,9 +61,9 @@ public:
   {
   public:
     //! Constructor with initialization.
-    Iterator (const Handle(Font_TextFormatter)& theFormatter,
+    Iterator (const Font_TextFormatter& theFormatter,
               IterationFilter theFilter = IterationFilter_None)
-    : myFormatter (theFormatter), myFilter (theFilter), myIter (theFormatter->myString.Iterator())
+    : myFilter (theFilter), myIter (theFormatter.myString.Iterator())
     {
       mySymbolPosition = readNextSymbol (-1, mySymbolChar);
       mySymbolNext = readNextSymbol (mySymbolPosition, mySymbolCharNext);
@@ -76,16 +76,16 @@ public:
     Standard_Boolean HasNext() const { return mySymbolNext >= 0; }
 
     //! Returns current symbol.
-    const Standard_Utf32Char& Symbol() const { return mySymbolChar; }
+    Standard_Utf32Char Symbol() const { return mySymbolChar; }
 
     //! Returns the next symbol if exists.
-    const Standard_Utf32Char& SymbolNext() const { return mySymbolCharNext; }
+    Standard_Utf32Char SymbolNext() const { return mySymbolCharNext; }
 
     //! Returns current symbol position.
-    const Standard_Integer& SymbolPosition() const { return mySymbolPosition; }
+    Standard_Integer SymbolPosition() const { return mySymbolPosition; }
 
     //! Returns the next symbol position.
-    const Standard_Integer& SymbolPositionNext() const { return mySymbolNext; }
+    Standard_Integer SymbolPositionNext() const { return mySymbolNext; }
 
     //! Moves to the next item.
     void Next()
@@ -122,7 +122,6 @@ public:
     }
 
   protected:
-    Handle(Font_TextFormatter) myFormatter; //!< source class for iterating
     IterationFilter myFilter; //!< possibility to filter not-necessary symbols
 
     NCollection_Utf8Iter myIter; //!< the next symbol iterator value over the text formatter string
@@ -170,7 +169,7 @@ public:
   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;
+  Standard_EXPORT Standard_ShortReal FirstPosition() const;
 
   //! Returns column index of the corner index in the current line
   Standard_EXPORT Standard_Integer LinePositionIndex (const Standard_Integer theIndex) const;
@@ -178,13 +177,6 @@ public:
   //! Returns row index of the corner index among text lines
   Standard_EXPORT Standard_Integer LineIndex (const Standard_Integer theIndex) const;
 
-  //! Returns current rendering string.
-  //! Obsolete method, please use Iterator to get the string characters
-  //inline const NCollection_String& String() const
-  //{
-  //  return myString;
-  //}
-
   //! Returns tab size.
   inline Standard_Integer TabSize() const
   {
@@ -242,12 +234,22 @@ public:
   }
 
   //!< Returns internal container of the top left corners of a formatted rectangles.
-  const NCollection_Vector < NCollection_Vec2<Standard_ShortReal> >& GetCorners() const { return myCorners; }
+  const NCollection_Vector < NCollection_Vec2<Standard_ShortReal> >& Corners() const { return myCorners; }
 
-  const NCollection_Vector<Standard_ShortReal>& GetNewLines() const { return myNewLines; }
+  const NCollection_Vector<Standard_ShortReal>& NewLines() const { return myNewLines; }
 
   //!< Returns true if the symbol is CR, BEL, FF, NP, BS or VT
-  Standard_EXPORT static Standard_Boolean IsCommandSymbol (const Standard_Utf32Char& theSymbol);
+  static inline Standard_Boolean IsCommandSymbol (const Standard_Utf32Char& theSymbol)
+  {
+    if (theSymbol == '\x0D' // CR  (carriage return)
+     || theSymbol == '\a'   // BEL (alarm)
+     || theSymbol == '\f'   // FF  (form feed) NP (new page)
+     || theSymbol == '\b'   // BS  (backspace)
+     || theSymbol == '\v')  // VT  (vertical tab)
+      return Standard_True;
+
+    return Standard_False;
+  }
 
   DEFINE_STANDARD_RTTIEXT (Font_TextFormatter, Standard_Transient)
 
@@ -257,9 +259,6 @@ protected: //! @name class auxiliary methods
   Standard_EXPORT void newLine (const Standard_Integer theLastRect,
                                 const Standard_ShortReal theMaxLineWidth);
 
-  //!< Returns rectangle number
-  Standard_Integer getRectsNb() { return myCorners.Length(); }
-
 protected: //! @name configuration
 
   Graphic3d_HorizontalTextAlignment myAlignX;  //!< horizontal alignment style
index ef2a608da6079dcd5d65529e55b5226768abf019..aa6d7b40bb718f2454c8db6e536dd80388e3bfd5 100644 (file)
@@ -36,6 +36,8 @@
 #include <Graphic3d_TransformUtils.hxx>
 #include <Graphic3d_RenderingParams.hxx>
 
+#include <Font_TextFormatter.hxx>
+
 #include <Message_Messenger.hxx>
 
 #include <NCollection_Vector.hxx>
@@ -248,6 +250,8 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
 
   memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions));
   myShaderManager = new OpenGl_ShaderManager (this);
+
+  myDefaultFormatter = new Font_TextFormatter();
 }
 
 // =======================================================================
index b4c5ca85f75078adcaec4ba7641c2b81f4dc0376..93c2e1694996fb3df06fb3ae53936d1ffa5af406 100644 (file)
@@ -136,6 +136,7 @@ template<typename theBaseClass_t> struct OpenGl_TmplCore45;
 typedef OpenGl_TmplCore45<OpenGl_GlCore44Back> OpenGl_GlCore45Back;
 typedef OpenGl_TmplCore45<OpenGl_GlCore44>     OpenGl_GlCore45;
 
+class Font_TextFormatter;
 class Graphic3d_PresentationAttributes;
 class OpenGl_Aspects;
 class OpenGl_FrameBuffer;
@@ -483,6 +484,9 @@ public:
   //! @return tool for management of shader programs within this context.
   inline const Handle(OpenGl_ShaderManager)& ShaderManager() const { return myShaderManager; }
 
+  //! @return default formatter of text withing this context
+  inline const Handle(Font_TextFormatter)& DefaultTextFormatter() const { return myDefaultFormatter; }
+
 public:
 
   //! Either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1).
@@ -984,6 +988,7 @@ private: // context info
   Standard_Boolean myHasRayTracingAdaptiveSamplingAtomic; //! indicates whether atomic adaptive screen sampling in ray tracing mode is supported
 
   Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
+  Handle(Font_TextFormatter) myDefaultFormatter;//!< default text formatter, an alternative to text params
 
 private: //! @name fields tracking current state
 
index 08caff903f29745f8d2263000b8b44be5e81acd3..be20067ee42f020639e7687cc58820876dcadb71 100644 (file)
@@ -702,7 +702,7 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
     Handle(Font_TextFormatter) aFormatter = myFormatter;
     if (myFormatter.IsNull())
     {
-      aFormatter = new Font_TextFormatter();
+      aFormatter = theCtx->DefaultTextFormatter();
       aFormatter->SetupAlignment (myParams.HAlign, myParams.VAlign);
       aFormatter->Reset();
 
index 338cec15feeda4be3abccbb2ca5848ed1db840b9..7c97ed045126db05b44706b12ac3e5622c3c5fcd 100644 (file)
@@ -59,7 +59,7 @@ void OpenGl_TextBuilder::createGlyphs (const Handle(Font_TextFormatter)&
   theTCrdsPerTexture.Clear();
 
   OpenGl_Font::Tile aTile = {Font_Rect(), Font_Rect(), 0u};
-  for (Font_TextFormatter::Iterator aFormatterIt (theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
+  for (Font_TextFormatter::Iterator aFormatterIt (*theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
        aFormatterIt .More(); aFormatterIt .Next())
   {
     theFont.RenderGlyph (theCtx, aFormatterIt.Symbol(), aTile);