]> OCCT Git - occt-copy.git/commitdiff
0026361: Visualization - move OpenGl_TextFormatter to Font_TextFormatter
authorisk <isk@opencascade.com>
Tue, 23 Jun 2015 19:43:45 +0000 (22:43 +0300)
committerisk <isk@opencascade.com>
Tue, 23 Jun 2015 19:43:45 +0000 (22:43 +0300)
for usage without OpenGL.
Split OpenGl_TextFormatter on Font_TextFormatter and OpenGl_TextBuilder.
Font_TextFormatter can format a text independetly of OpenGl now.
OpenGl_TextBuilder generates primitive array required for rendering text
using OpenGl_Font instance.

14 files changed:
src/Font/FILES
src/Font/Font_FTFont.cxx
src/Font/Font_FTFont.hxx
src/Font/Font_TextFormatter.cxx [new file with mode: 0644]
src/Font/Font_TextFormatter.hxx [new file with mode: 0644]
src/OpenGl/FILES
src/OpenGl/OpenGl_Font.cxx
src/OpenGl/OpenGl_Font.hxx
src/OpenGl/OpenGl_Text.cxx
src/OpenGl/OpenGl_Text.hxx
src/OpenGl/OpenGl_TextBuilder.cxx [new file with mode: 0644]
src/OpenGl/OpenGl_TextBuilder.hxx [new file with mode: 0644]
src/OpenGl/OpenGl_TextFormatter.cxx [deleted file]
src/OpenGl/OpenGl_TextFormatter.hxx [deleted file]

index ad2c3280a2ef505ae341e25152cdbbab813fd487..2aa2c0b149435a4b4918e4df6d05b9d39618c780 100644 (file)
@@ -7,3 +7,5 @@ Font_FTLibrary.hxx
 Font_FTLibrary.cxx
 Font_NListOfSystemFont.hxx
 Font_NameOfFont.hxx
+Font_TextFormatter.hxx
+Font_TextFormatter.cxx
\ No newline at end of file
index 684a831185b96c81ef52512f09cf6f32818257a6..b0f422ccbe38bde167f074944aa7e37dafdf819f 100755 (executable)
@@ -15,6 +15,8 @@
 
 #include <Font_FTFont.hxx>
 #include <Font_FontMgr.hxx>
+#include <Font_TextFormatter.hxx>
+
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
 
@@ -257,3 +259,25 @@ float Font_FTFont::AdvanceY (const Standard_Utf32Char theUCharNext)
   }
   return fromFTPoints<float> (myKernAdvance.y + myFTFace->glyph->advance.y);
 }
+
+// =======================================================================
+// function : BoundingBox
+// purpose  :
+// =======================================================================
+Font_FTFont::Rect Font_FTFont::BoundingBox (const NCollection_String&               theString,
+                                            const Graphic3d_HorizontalTextAlignment theAlignX,
+                                            const Graphic3d_VerticalTextAlignment   theAlignY)
+{
+  Font_TextFormatter aFormatter;
+  aFormatter.SetupAlignment (theAlignX, theAlignY);
+  aFormatter.Reset();
+
+  aFormatter.Append (theString, *this);
+  aFormatter.Format();
+
+  Rect aBndBox;
+
+  aFormatter.BndBox (aBndBox);
+
+  return aBndBox;
+}
index f4ba85ca8afddb5a6a790aaddd947a64f564a3ee..eb4c03ff361f85eb7e171c40bb6c0cb9a678066d 100755 (executable)
 #ifndef _Font_FTFont_H__
 #define _Font_FTFont_H__
 
-#include <NCollection_Vec2.hxx>
-#include <NCollection_String.hxx>
+#include <Font_FontAspect.hxx>
 #include <Font_FTLibrary.hxx>
+#include <Graphic3d_HorizontalTextAlignment.hxx>
+#include <Graphic3d_VerticalTextAlignment.hxx>
 #include <Image_PixMap.hxx>
-#include <Font_FontAspect.hxx>
+#include <NCollection_String.hxx>
+#include <NCollection_Vec2.hxx>
 
 //! Wrapper over FreeType font.
 //! Notice that this class uses internal buffers for loaded glyphs
@@ -178,6 +180,15 @@ public:
     theRect.Bottom = float(myFTFace->glyph->bitmap_top  - (int )aBitmap.rows);
   }
 
+  //! Computes bounding box of the given text using plain-text formatter (Font_TextFormatter).
+  //! Note that bounding box takes into account text alignments. It can have negative coordinates.
+  //! The width and height easy to get by the following formulas:
+  //! Width = Rect.Right - Rect.Left;
+  //! Height = Rect.Top - Rect.Bottom;
+  Standard_EXPORT Rect BoundingBox (const NCollection_String&               theString,
+                                    const Graphic3d_HorizontalTextAlignment theAlignX,
+                                    const Graphic3d_VerticalTextAlignment   theAlignY);
+
 protected:
 
   //! Convert value to 26.6 fixed-point format for FT library API.
diff --git a/src/Font/Font_TextFormatter.cxx b/src/Font/Font_TextFormatter.cxx
new file mode 100644 (file)
index 0000000..b4d6776
--- /dev/null
@@ -0,0 +1,341 @@
+// Created on: 2013-01-29
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2013-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Font_TextFormatter.hxx>
+
+namespace
+{
+
+  //! Auxiliary function to translate rectangle by the vector.
+  inline void move (Font_FTFont::Rect&                          theRect,
+                    const NCollection_Vec2<Standard_ShortReal>& theVec)
+  {
+    theRect.Left   += theVec.x();
+    theRect.Right  += theVec.x();
+    theRect.Top    += theVec.y();
+    theRect.Bottom += theVec.y();
+  }
+
+  //! Auxiliary function to translate rectangles by the vector.
+  inline void move (NCollection_Vector<Font_FTFont::Rect>&      theRects,
+                    const NCollection_Vec2<Standard_ShortReal>& theMoveVec,
+                    Standard_Integer                            theCharLower,
+                    const Standard_Integer                      theCharUpper)
+  {
+    for(; theCharLower <= theCharUpper; ++theCharLower)
+    {
+      Font_FTFont::Rect& aRect = theRects.ChangeValue (theCharLower);
+      move (aRect, theMoveVec);
+    }
+  }
+
+  //! Auxiliary function to translate rectangles in vertical direction.
+  inline void moveY (NCollection_Vector<Font_FTFont::Rect>& theRects,
+                     const Standard_ShortReal               theMoveVec,
+                     Standard_Integer                       theCharLower,
+                     const Standard_Integer                 theCharUpper)
+  {
+    for(; theCharLower <= theCharUpper; ++theCharLower)
+    {
+      Font_FTFont::Rect& aRect = theRects.ChangeValue (theCharLower);
+      aRect.Top    += theMoveVec;
+      aRect.Bottom += theMoveVec;
+    }
+  }
+
+  //! Apply floor to vector components.
+  //! @param  theVec - vector to change (by reference!)
+  //! @return modified vector
+  inline NCollection_Vec2<Standard_ShortReal>& floor (NCollection_Vec2<Standard_ShortReal>& theVec)
+  {
+    theVec.x() = std::floor (theVec.x());
+    theVec.y() = std::floor (theVec.y());
+    return theVec;
+  }
+
+}
+
+
+IMPLEMENT_STANDARD_HANDLE (Font_TextFormatter, Standard_Transient)
+IMPLEMENT_STANDARD_RTTIEXT(Font_TextFormatter, Standard_Transient)
+
+// =======================================================================
+// function : Font_TextFormatter
+// purpose  :
+// =======================================================================
+Font_TextFormatter::Font_TextFormatter()
+: myAlignX (Graphic3d_HTA_LEFT),
+  myAlignY (Graphic3d_VTA_TOP),
+  myTabSize (8),
+  //
+  myPen (0.0f, 0.0f),
+  myRectsNb (0),
+  myLineSpacing (0.0f),
+  myAscender (0.0f),
+  myIsFormatted (false),
+  //
+  myLinesNb (0),
+  myRectLineStart (0),
+  myRectWordStart (0),
+  myNewLineNb(0),
+  myPenCurrLine (0.0f),
+  myLineLeft (0.0f),
+  myLineTail (0.0f),
+  myBndTop   (0.0f),
+  myBndWidth (0.0f),
+  myMoveVec (0.0f, 0.0f)
+{
+  //
+}
+
+// =======================================================================
+// function : SetupAlignment
+// purpose  :
+// =======================================================================
+void Font_TextFormatter::SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
+                                         const Graphic3d_VerticalTextAlignment   theAlignY)
+{
+  myAlignX = theAlignX;
+  myAlignY = theAlignY;
+}
+
+// =======================================================================
+// function : Reset
+// purpose  :
+// =======================================================================
+void Font_TextFormatter::Reset()
+{
+  myIsFormatted = false;
+  myString.Clear();
+  myPen.x() = myPen.y() = 0.0f;
+  myRectsNb = 0;
+  myLineSpacing = myAscender = 0.0f;
+  myRects.Clear();
+  myNewLines.Clear();
+}
+
+// =======================================================================
+// function : Append
+// purpose  :
+// =======================================================================
+void Font_TextFormatter::Append (const NCollection_String& theString,
+                                   Font_FTFont&              theFont)
+{
+  if (theString.IsEmpty())
+  {
+    return;
+  }
+
+  myAscender    = Max (myAscender,    theFont.Ascender());
+  myLineSpacing = Max (myLineSpacing, theFont.LineSpacing());
+  myString     += theString;
+
+  int aSymbolsCounter = 0; // special counter to process tabulation symbols
+
+  // first pass - render all symbols using associated font on single ZERO baseline
+  Font_FTFont::Rect aRect = {};
+  for (NCollection_Utf8Iter anIter = theString.Iterator(); *anIter != 0;)
+  {
+    const Standard_Utf32Char aCharThis =   *anIter;
+    const Standard_Utf32Char aCharNext = *++anIter;
+
+    if (aCharThis == '\x0D' // CR  (carriage return)
+     || aCharThis == '\a'   // BEL (alarm)
+     || aCharThis == '\f'   // FF  (form feed) NP (new page)
+     || aCharThis == '\b'   // BS  (backspace)
+     || aCharThis == '\v')  // VT  (vertical tab)
+    {
+      continue; // skip unsupported carriage control codes
+    }
+    else if (aCharThis == '\x0A') // LF (line feed, new line)
+    {
+      aSymbolsCounter = 0;
+      myNewLines.Append (myPen.x());
+      continue; // will be processed on second pass
+    }
+    else if (aCharThis == ' ')
+    {
+      ++aSymbolsCounter;
+      myPen.x() += theFont.AdvanceX (' ', aCharNext);
+      continue;
+    }
+    else if (aCharThis == '\t')
+    {
+      const Standard_Integer aSpacesNum = (myTabSize - (aSymbolsCounter - 1) % myTabSize);
+      myPen.x() += theFont.AdvanceX (' ', aCharNext) * Standard_ShortReal(aSpacesNum);
+      aSymbolsCounter += aSpacesNum;
+      continue;
+    }
+
+    ++aSymbolsCounter;
+
+    theFont.RenderGlyph (aCharThis);
+    theFont.GlyphRect   (aRect);
+
+    aRect.Top    += myPen.y();
+    aRect.Bottom += myPen.y();
+    aRect.Left   += myPen.x();
+    aRect.Right  += myPen.x();
+
+    myPen.x() += theFont.AdvanceX (aCharThis, aCharNext);
+
+    myRects.Append (aRect);
+
+    ++myRectsNb;
+  }
+}
+
+// =======================================================================
+// function : newLine
+// purpose  :
+// =======================================================================
+void Font_TextFormatter::newLine (const Standard_Integer theLastRect)
+{
+  if (myRectLineStart >= myRectsNb)
+  {
+    ++myLinesNb;
+    myPenCurrLine -= myLineSpacing;
+    return;
+  }
+
+  myMoveVec.y() = myPenCurrLine;
+  switch (myAlignX)
+  {
+    default:
+    case Graphic3d_HTA_LEFT:
+    {
+      myMoveVec.x() = (myNewLineNb > 0) ? -myNewLines.Value (myNewLineNb - 1) : 0.0f;
+      break;
+    }
+    case Graphic3d_HTA_RIGHT:
+    {
+      myMoveVec.x() = (myNewLineNb < myNewLines.Length())
+                    ? -myNewLines.Value (myNewLineNb)
+                    : -myPen.x();
+      break;
+    }
+    case Graphic3d_HTA_CENTER:
+    {
+      const Standard_ShortReal aFrom = (myNewLineNb > 0)
+                                     ? myNewLines.Value (myNewLineNb - 1)
+                                     : 0.0f;
+      const Standard_ShortReal aTo   = (myNewLineNb < myNewLines.Length())
+                                     ? myNewLines.Value (myNewLineNb)
+                                     : myPen.x();
+      myMoveVec.x() = -0.5f * (aFrom + aTo);
+      break;
+    }
+  }
+
+  move (myRects, myMoveVec, myRectLineStart, theLastRect);
+
+  ++myLinesNb;
+  myPenCurrLine -= myLineSpacing;
+  myRectLineStart = myRectWordStart = theLastRect + 1;
+  if (myRectLineStart < myRectsNb)
+  {
+    myLineLeft = myRects.Value (myRectLineStart).Left;
+  }
+}
+
+// =======================================================================
+// function : Format
+// purpose  :
+// =======================================================================
+void Font_TextFormatter::Format()
+{
+  if (myRectsNb == 0 || myIsFormatted)
+  {
+    return;
+  }
+
+  myIsFormatted = true;
+  myLinesNb = myRectLineStart = myRectWordStart = 0;
+  myLineLeft   = 0.0f;
+  myLineTail   = 0.0f;
+  myBndTop     = 0.0f;
+  myBndWidth   = 0.0f;
+  myMoveVec.x() = myMoveVec.y() = 0.0f;
+
+  // split text into lines and apply horizontal alignment
+  myPenCurrLine = -myAscender;
+  Standard_Integer aRectIter = 0;
+  myNewLineNb = 0;
+  Standard_ShortReal aMaxLineWidth = -1.0f;
+  for (NCollection_Utf8Iter anIter = myString.Iterator(); *anIter != 0; ++anIter)
+  {
+    const Standard_Utf32Char aCharThis = *anIter;
+    if (aCharThis == '\x0D' // CR  (carriage return)
+     || aCharThis == '\a'   // BEL (alarm)
+     || aCharThis == '\f'   // FF  (form feed) NP (new page)
+     || aCharThis == '\b'   // BS  (backspace)
+     || aCharThis == '\v')  // VT  (vertical tab)
+    {
+      continue; // skip unsupported carriage control codes
+    }
+    else if (aCharThis == '\x0A') // LF (line feed, new line)
+    {
+      // calculate max line width
+      if (myNewLineNb == 0)
+      {
+        aMaxLineWidth = myNewLines.Value(0);
+      }
+      else
+      {
+        aMaxLineWidth = Max (aMaxLineWidth, myNewLines.Value (myNewLineNb) - myNewLines.Value (myNewLineNb - 1));
+      }
+
+      const Standard_Integer aLastRect = aRectIter - 1; // last rect on current line
+      newLine (aLastRect);
+      ++myNewLineNb;
+      continue;
+    }
+    else if (aCharThis == ' '
+          || aCharThis == '\t')
+    {
+      myRectWordStart = aRectIter;
+      continue;
+    }
+
+    ++aRectIter;
+  }
+
+  // If only one line
+  if (aMaxLineWidth < 0.0f)
+  {
+    aMaxLineWidth = myPen.x();
+  }
+  else // Consider last line
+  {
+    aMaxLineWidth = Max (aMaxLineWidth, myPen.x() - myNewLines.Value (myNewLineNb - 1));
+  }
+
+  myBndWidth = aMaxLineWidth;
+
+  // move last line
+  newLine (myRectsNb - 1);
+
+  // apply vertical alignment style
+  if (myAlignY == Graphic3d_VTA_BOTTOM)
+  {
+    myBndTop = -myLineSpacing - myPenCurrLine;
+    moveY (myRects, myBndTop, 0, myRectsNb - 1);
+  }
+  else if (myAlignY == Graphic3d_VTA_CENTER)
+  {
+    myBndTop = 0.5f * (myLineSpacing * Standard_ShortReal(myLinesNb));
+    moveY (myRects, myBndTop, 0, myRectsNb - 1);
+  }
+}
diff --git a/src/Font/Font_TextFormatter.hxx b/src/Font/Font_TextFormatter.hxx
new file mode 100644 (file)
index 0000000..174db88
--- /dev/null
@@ -0,0 +1,143 @@
+// Created on: 2013-01-29
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2013-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef Font_TextFormatter_Header
+#define Font_TextFormatter_Header
+
+#include <Font_FTFont.hxx>
+#include <NCollection_Vector.hxx>
+
+//! This class intended to prepare formatted text.
+class Font_TextFormatter : public Standard_Transient
+{
+public:
+
+  //! Default constructor.
+  Standard_EXPORT Font_TextFormatter();
+
+  //! Setup alignment style.
+  Standard_EXPORT void SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
+                                       const Graphic3d_VerticalTextAlignment   theAlignY);
+
+  //! Reset current progress.
+  Standard_EXPORT void Reset();
+
+  //! Render specified text to inner buffer.
+  Standard_EXPORT void Append (const NCollection_String& theString,
+                               Font_FTFont&              theFont);
+
+  //! Perform formatting on the buffered text.
+  //! Should not be called more than once after initialization!
+  Standard_EXPORT void Format();
+
+  //! Returns specific glyph rectangle.
+  inline const Font_FTFont::Rect& Rect (const Standard_Integer theIndex) const
+  {
+    return myRects.Value (theIndex);
+  }
+
+  //! Returns current rendering string.
+  inline const NCollection_String& String() const
+  {
+    return myString;
+  }
+
+  //! Returns tab size.
+  inline Standard_Integer TabSize() const
+  {
+    return myTabSize;
+  }
+
+  //! @return width of formatted text.
+  inline Standard_ShortReal ResultWidth() const
+  {
+    return myBndWidth;
+  }
+
+  //! @return height of formatted text.
+  inline Standard_ShortReal ResultHeight() const
+  {
+    return myLineSpacing * Standard_ShortReal(myLinesNb);
+  }
+
+  //! @param bounding box.
+  inline void BndBox (Font_FTFont::Rect& theBndBox) const
+  {
+    theBndBox.Left = 0.0f;
+    switch (myAlignX)
+    {
+      default:
+      case Graphic3d_HTA_LEFT:  theBndBox.Right  =  myBndWidth; break;
+      case Graphic3d_HTA_RIGHT: theBndBox.Right  = -myBndWidth; break;
+      case Graphic3d_HTA_CENTER:
+      {
+        theBndBox.Left  = -0.5f * myBndWidth;
+        theBndBox.Right =  0.5f * myBndWidth;
+        break;
+      }
+    }
+    theBndBox.Top    = myBndTop;
+    theBndBox.Bottom = theBndBox.Top - myLineSpacing * Standard_ShortReal(myLinesNb);
+  }
+
+protected: //! @name class auxiliary methods
+
+  //! Move glyphs on the current line to correct position.
+  Standard_EXPORT void newLine (const Standard_Integer theLastRect);
+
+protected: //! @name configuration
+
+  Graphic3d_HorizontalTextAlignment myAlignX;  //!< horizontal alignment style
+  Graphic3d_VerticalTextAlignment   myAlignY;  //!< vertical   alignment style
+  Standard_Integer                  myTabSize; //!< horizontal tabulation width (number of space symbols)
+
+protected: //! @name input data
+
+  NCollection_String myString;        //!< currently rendered text
+  NCollection_Vec2<Standard_ShortReal>
+                     myPen;           //!< current pen position
+  NCollection_Vector<Font_FTFont::Rect>
+                     myRects;         //!< glyphs rectangles
+  Standard_Integer   myRectsNb;       //!< rectangles number
+  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;      //!<
+  bool               myIsFormatted;   //!< formatting state
+
+protected: //! @name temporary variables for formatting routines
+
+  Standard_Integer   myLinesNb;       //!< overall (new)lines number (including splitting by width limit)
+  Standard_Integer   myRectLineStart; //!< id of first rectangle on the current line
+  Standard_Integer   myRectWordStart; //!< id of first rectangle in the current word
+  Standard_Integer   myNewLineNb;
+
+  Standard_ShortReal myPenCurrLine;   //!< current baseline position
+  Standard_ShortReal myLineLeft;      //!< left x position of first glyph on line before formatting applied
+  Standard_ShortReal myLineTail;
+  Standard_ShortReal myBndTop;
+  Standard_ShortReal myBndWidth;
+  NCollection_Vec2<Standard_ShortReal>
+                     myMoveVec;       //!< local variable
+
+public:
+
+  DEFINE_STANDARD_RTTI(Font_TextFormatter) // Type definition
+
+};
+
+DEFINE_STANDARD_HANDLE(Font_TextFormatter, Standard_Transient)
+
+#endif // Font_TextFormatter_Header
index 37d3e63a1fd2aaaec51f6bd4477b84a861925e59..de9014dd12631371ce40272209a052e38ac455ba 100755 (executable)
@@ -26,8 +26,6 @@ OpenGl_Element.hxx
 OpenGl_Element.cxx
 OpenGl_Text.hxx
 OpenGl_Text.cxx
-OpenGl_TextFormatter.hxx
-OpenGl_TextFormatter.cxx
 OpenGl_PointSprite.hxx
 OpenGl_PointSprite.cxx
 Handle_OpenGl_PointSprite.hxx
@@ -169,3 +167,5 @@ OpenGl_Sphere.hxx
 OpenGl_Sphere.cxx
 OpenGl_BackgroundArray.hxx
 OpenGl_BackgroundArray.cxx
+OpenGl_TextBuilder.hxx
+OpenGl_TextBuilder.cxx
index 1a17c604ab2d6ff483ec7fff71fb6a252ff6dc2c..54e9db700c3ac87cbe7566fe3ab28dc94daa2d53 100755 (executable)
@@ -234,3 +234,33 @@ void OpenGl_Font::RenderGlyph (const Handle(OpenGl_Context)& theCtx,
 
   thePen.x() += myFont->AdvanceX (theUChar, theUCharNext);
 }
+
+// =======================================================================
+// function : RenderGlyph
+// purpose  :
+// =======================================================================
+bool OpenGl_Font::RenderGlyph (const Handle(OpenGl_Context)& theCtx,
+                               const Standard_Utf32Char      theUChar,
+                               Tile&                         theGlyph)
+{
+  Standard_Integer aTileId = 0;
+  if (!myGlyphMap.Find (theUChar,aTileId))
+  {
+    if (renderGlyph (theCtx, theUChar))
+    {
+      aTileId = myLastTileId;
+    }
+    else
+    {
+      return false;
+    }
+
+    myGlyphMap.Bind (theUChar, aTileId);
+  }
+
+  const OpenGl_Font::Tile& aTile = myTiles.Value (aTileId);
+  theGlyph.uv      = aTile.uv;
+  theGlyph.texture = aTile.texture;
+
+  return true;
+}
index fd95912d1dd9392c4b36970ac8e7ee9edd40ae40..4ba8d3a588d5e169b922103534dd4c13d3cb4e11 100755 (executable)
@@ -128,6 +128,11 @@ public:
                                     Tile&                         theGlyph,
                                     OpenGl_Vec2&                  thePen);
 
+  //! Render glyph to texture if not already.
+  Standard_EXPORT bool RenderGlyph (const Handle(OpenGl_Context)& theCtx,
+                                    const Standard_Utf32Char      theUChar,
+                                    Tile&                         theGlyph);
+
 protected:
 
   //! Render new glyph to the texture.
index a67ea82ed6999a73b51b6be7cfb248dedfd14786..d98a62da768e3f27513c7958efee9bc69270f4f6 100644 (file)
@@ -146,6 +146,7 @@ OpenGl_Text::OpenGl_Text()
   myWinZ (0.0f),
   myScaleHeight (1.0f),
   myPoint  (0.0f, 0.0f, 0.0f),
+
   myIs2d   (false)
 {
   myParams.Height = 10;
@@ -174,6 +175,7 @@ OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText,
 }
 
 // =======================================================================
+
 // function : SetPosition
 // purpose  :
 // =======================================================================
@@ -464,8 +466,7 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
                                             anObjZ);
 
     OpenGl_Utils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
-    OpenGl_Utils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
-
+    OpenGl_Utils::Rotate<GLdouble>    (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
     if (!theTextAspect.IsZoomable())
     {
     #ifdef _WIN32
@@ -580,6 +581,7 @@ Handle(OpenGl_Font) OpenGl_Text::FindFont (const Handle(OpenGl_Context)& theCtx,
     if (!aRequestedFont.IsNull())
     {
       aFontFt = new Font_FTFont (NULL);
+
       if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight))
       {
         aFont = new OpenGl_Font (aFontFt, theKey);
@@ -655,13 +657,23 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
 
   if (myTextures.IsEmpty())
   {
-    OpenGl_TextFormatter aFormatter;
+
+    Font_TextFormatter aFormatter;
     aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
     aFormatter.Reset();
-    aFormatter.Append (theCtx, myString, *myFont.operator->());
+
+
+    aFormatter.Append (myString, *myFont->FTFont());
     aFormatter.Format();
 
-    aFormatter.Result (theCtx, myTextures, myVertsVbo, myTCrdsVbo);
+    OpenGl_TextBuilder aBuilder;
+    aBuilder.Perform (aFormatter,
+                      theCtx,
+                      *myFont.operator->(),
+                      myTextures,
+                      myVertsVbo,
+                      myTCrdsVbo);
+
     aFormatter.BndBox (myBndBox);
   }
 
index 68d8514a5100450da4bd59abafc5ce2a5ffe417e..71200ee30ac00700c41245ce12eddcced9439bc6 100755 (executable)
@@ -20,7 +20,7 @@
 
 #include <OpenGl_AspectText.hxx>
 #include <OpenGl_TextParam.hxx>
-#include <OpenGl_TextFormatter.hxx>
+#include <OpenGl_TextBuilder.hxx>
 
 #include <TCollection_ExtendedString.hxx>
 #include <Graphic3d_Vertex.hxx>
diff --git a/src/OpenGl/OpenGl_TextBuilder.cxx b/src/OpenGl/OpenGl_TextBuilder.cxx
new file mode 100644 (file)
index 0000000..216de4f
--- /dev/null
@@ -0,0 +1,217 @@
+// Created on: 2015-06-18
+// Created by: Ilya SEVRIKOV
+// Copyright (c) 2015 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_TextBuilder.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>
+
+namespace
+{
+  //! Apply floor to vector components.
+  //! @param  theVec - vector to change (by reference!)
+  //! @return modified vector
+  inline OpenGl_Vec2& floor (OpenGl_Vec2& theVec)
+  {
+    theVec.x() = std::floor (theVec.x());
+    theVec.y() = std::floor (theVec.y());
+    return theVec;
+  }
+};
+
+// =======================================================================
+// function : OpenGl_TextBuilder
+// purpose  :
+// =======================================================================
+OpenGl_TextBuilder::OpenGl_TextBuilder()
+{
+  //
+}
+
+// =======================================================================
+// function : createGlyphs
+// purpose  :
+// =======================================================================
+void OpenGl_TextBuilder::createGlyphs (const Font_TextFormatter&                                                  theFormatter,
+                                       const Handle(OpenGl_Context)&                                              theCtx,
+                                       OpenGl_Font&                                                               theFont,
+                                       NCollection_Vector<GLuint>&                                                theTextures,
+                                       NCollection_Vector<NCollection_Handle<NCollection_Vector<OpenGl_Vec2> > >& theVertsPerTexture,
+                                       NCollection_Vector<NCollection_Handle<NCollection_Vector<OpenGl_Vec2> > >& theTCrdsPerTexture)
+{
+  OpenGl_Vec2 aVec (0.0f, 0.0f);
+
+  theTextures.Clear();
+  theVertsPerTexture.Clear();
+  theTCrdsPerTexture.Clear();
+
+  OpenGl_Font::Tile aTile = {};
+  OpenGl_Vec2       aPen (0.0f, 0.0f);
+  Standard_Integer  aRectsNb = 0;
+  Standard_Integer  aSymbolsCounter = 0;
+
+  for (NCollection_Utf8Iter anIter = theFormatter.String().Iterator(); *anIter != 0;)
+  {
+    const Standard_Utf32Char aCharThis =   *anIter;
+    const Standard_Utf32Char aCharNext = *++anIter;
+
+    if (aCharThis == '\x0D' // CR  (carriage return)
+     || aCharThis == '\a'   // BEL (alarm)
+     || aCharThis == '\f'   // FF  (form feed) NP (new page)
+     || aCharThis == '\b'   // BS  (backspace)
+     || aCharThis == '\v')  // VT  (vertical tab)
+    {
+      continue; // skip unsupported carriage control codes
+    }
+    else if (aCharThis == '\x0A') // LF (line feed, new line)
+    {
+      aSymbolsCounter = 0;
+      continue; // will be processed on second pass
+    }
+    else if (aCharThis == ' ')
+    {
+      ++aSymbolsCounter;
+      aPen.x() += theFont.AdvanceX (' ', aCharNext);
+      continue;
+    }
+    else if (aCharThis == '\t')
+    {
+      const Standard_Integer aSpacesNum = (theFormatter.TabSize() - (aSymbolsCounter - 1) % theFormatter.TabSize());
+      aPen.x() += theFont.AdvanceX (' ', aCharNext) * Standard_ShortReal(aSpacesNum);
+      aSymbolsCounter += aSpacesNum;
+      continue;
+    }
+
+    ++aSymbolsCounter;
+
+    theFont.RenderGlyph (theCtx, aCharThis, aTile);
+
+    const Font_FTFont::Rect& aRect    = theFormatter.Rect (aRectsNb);
+    const Font_FTFont::Rect& aRectUV  = aTile.uv;
+    const GLuint             aTexture = aTile.texture;
+
+    Standard_Integer aListId = 0;
+    for (aListId = 0; aListId < theTextures.Length(); ++aListId)
+    {
+      if (theTextures.Value (aListId) == aTexture)
+      {
+        break;
+      }
+    }
+    if (aListId >= theTextures.Length())
+    {
+      theTextures.Append (aTexture);
+      theVertsPerTexture.Append (new NCollection_Vector<OpenGl_Vec2>());
+      theTCrdsPerTexture.Append (new NCollection_Vector<OpenGl_Vec2>());
+    }
+
+    NCollection_Vector<OpenGl_Vec2>& aVerts = *theVertsPerTexture.ChangeValue (aListId);
+    NCollection_Vector<OpenGl_Vec2>& aTCrds = *theTCrdsPerTexture.ChangeValue (aListId);
+
+    // apply floor on position to avoid blurring issues
+    // due to cross-pixel coordinates
+    aVerts.Append (floor(aRect.TopRight   (aVec)));
+    aVerts.Append (floor(aRect.TopLeft    (aVec)));
+    aVerts.Append (floor(aRect.BottomLeft (aVec)));
+    aTCrds.Append (aRectUV.TopRight   (aVec));
+    aTCrds.Append (aRectUV.TopLeft    (aVec));
+    aTCrds.Append (aRectUV.BottomLeft (aVec));
+
+    aVerts.Append (floor(aRect.BottomRight (aVec)));
+    aVerts.Append (floor(aRect.TopRight    (aVec)));
+    aVerts.Append (floor(aRect.BottomLeft  (aVec)));
+    aTCrds.Append (aRectUV.BottomRight (aVec));
+    aTCrds.Append (aRectUV.TopRight    (aVec));
+    aTCrds.Append (aRectUV.BottomLeft  (aVec));
+
+    ++aRectsNb;
+  }
+}
+
+// =======================================================================
+// function : CreateTextures
+// purpose  :
+// =======================================================================
+void OpenGl_TextBuilder::Perform (const Font_TextFormatter&                       theFormatter,
+                                  const Handle_OpenGl_Context&                    theCtx,
+                                  OpenGl_Font&                                    theFont,
+                                  NCollection_Vector<GLuint>&                     theTextures,
+                                  NCollection_Vector<Handle_OpenGl_VertexBuffer>& theVertsPerTexture,
+                                  NCollection_Vector<Handle_OpenGl_VertexBuffer>& theTCrdsPerTexture)
+{
+  NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > > aVertsPerTexture;
+  NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > > aTCrdsPerTexture;
+
+  createGlyphs (theFormatter, theCtx, theFont, theTextures, aVertsPerTexture, aTCrdsPerTexture);
+
+  if (theVertsPerTexture.Length() != theTextures.Length())
+  {
+    for (Standard_Integer aTextureIter = 0; aTextureIter < theVertsPerTexture.Length(); ++aTextureIter)
+    {
+      theVertsPerTexture.Value (aTextureIter)->Release (theCtx.operator->());
+      theTCrdsPerTexture.Value (aTextureIter)->Release (theCtx.operator->());
+    }
+    theVertsPerTexture.Clear();
+    theTCrdsPerTexture.Clear();
+
+    const bool isNormalMode = theCtx->ToUseVbo();
+    Handle(OpenGl_VertexBuffer) aVertsVbo, aTcrdsVbo;
+    while (theVertsPerTexture.Length() < theTextures.Length())
+    {
+      if (isNormalMode)
+      {
+        aVertsVbo = new OpenGl_VertexBuffer();
+        aTcrdsVbo = new OpenGl_VertexBuffer();
+      }
+      else
+      {
+        aVertsVbo = new OpenGl_VertexBufferCompat();
+        aTcrdsVbo = new OpenGl_VertexBufferCompat();
+      }
+      theVertsPerTexture.Append (aVertsVbo);
+      theTCrdsPerTexture.Append (aTcrdsVbo);
+      aVertsVbo->Create (theCtx);
+      aTcrdsVbo->Create (theCtx);
+    }
+  }
+
+  for (Standard_Integer aTextureIter = 0; aTextureIter < theTextures.Length(); ++aTextureIter)
+  {
+    const NCollection_Vector<OpenGl_Vec2>& aVerts = *aVertsPerTexture.Value (aTextureIter);
+    Handle(OpenGl_VertexBuffer)& aVertsVbo = theVertsPerTexture.ChangeValue (aTextureIter);
+    if (!aVertsVbo->Init (theCtx, 2, aVerts.Length(), (GLfloat* )NULL)
+     || !myVboEditor.Init (theCtx, aVertsVbo))
+    {
+      continue;
+    }
+    for (Standard_Integer aVertIter = 0; aVertIter < aVerts.Length(); ++aVertIter, myVboEditor.Next())
+    {
+      myVboEditor.Value() = aVerts.Value (aVertIter);
+    }
+    myVboEditor.Flush();
+
+    const NCollection_Vector<OpenGl_Vec2>& aTCrds = *aTCrdsPerTexture.Value (aTextureIter);
+    Handle(OpenGl_VertexBuffer)& aTCrdsVbo = theTCrdsPerTexture.ChangeValue (aTextureIter);
+    if (!aTCrdsVbo->Init (theCtx, 2, aVerts.Length(), (GLfloat* )NULL)
+     || !myVboEditor.Init (theCtx, aTCrdsVbo))
+    {
+      continue;
+    }
+    for (Standard_Integer aVertIter = 0; aVertIter < aVerts.Length(); ++aVertIter, myVboEditor.Next())
+    {
+      myVboEditor.Value() = aTCrds.Value (aVertIter);
+    }
+    myVboEditor.Flush();
+  }
+  myVboEditor.Init (NULL, NULL);
+}
diff --git a/src/OpenGl/OpenGl_TextBuilder.hxx b/src/OpenGl/OpenGl_TextBuilder.hxx
new file mode 100644 (file)
index 0000000..016e518
--- /dev/null
@@ -0,0 +1,62 @@
+// Created on: 2015-06-18
+// Created by: Ilya SEVRIKOV
+// Copyright (c) 2015 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef OpenGl_TextBuilder_Header
+#define OpenGl_TextBuilder_Header
+
+#include <Font_TextFormatter.hxx>
+
+#include <OpenGl_Context.hxx>
+#include <OpenGl_Font.hxx>
+#include <OpenGl_VertexBuffer.hxx>
+#include <OpenGl_VertexBufferEditor.hxx>
+#include <OpenGl_Vec.hxx>
+
+#include <NCollection_Vector.hxx>
+#include <NCollection_Handle.hxx>
+
+
+//! This class generates primitive array required for rendering textured text using OpenGl_Font instance.
+class OpenGl_TextBuilder
+{
+public:
+
+  //! Creates empty object.
+  OpenGl_TextBuilder();
+
+  //! Creates texture quads for the given text.
+  Standard_EXPORT void Perform (const Font_TextFormatter&                        theFormatter,
+                                const Handle(OpenGl_Context)&                    theContext,
+                                OpenGl_Font&                                     theFont,
+                                NCollection_Vector<GLuint>&                      theTextures,
+                                NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theVertsPerTexture,
+                                NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theTCrdsPerTexture);
+
+protected: //! @name class auxillary methods
+
+  Standard_EXPORT void createGlyphs (const Font_TextFormatter&                                                      theFormatter,
+                                     const Handle(OpenGl_Context)&                                                  theCtx,
+                                     OpenGl_Font&                                                                   theFont,
+                                     NCollection_Vector<GLuint>&                                                    theTextures,
+                                     NCollection_Vector< NCollection_Handle < NCollection_Vector <OpenGl_Vec2> > >& theVertsPerTexture,
+                                     NCollection_Vector< NCollection_Handle < NCollection_Vector <OpenGl_Vec2> > >& theTCrdsPerTexture);
+
+protected: //! @name class auxillary fields
+
+  NCollection_Vector<OpenGl_Font::Tile>  myTileRects;
+  OpenGl_VertexBufferEditor<OpenGl_Vec2> myVboEditor;
+};
+
+#endif // OpenGl_TextBuilder_Header
diff --git a/src/OpenGl/OpenGl_TextFormatter.cxx b/src/OpenGl/OpenGl_TextFormatter.cxx
deleted file mode 100755 (executable)
index 85d5153..0000000
+++ /dev/null
@@ -1,461 +0,0 @@
-// Created on: 2013-01-29
-// Created by: Kirill GAVRILOV
-// Copyright (c) 2013-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <OpenGl_TextFormatter.hxx>
-
-#include <OpenGl_VertexBufferCompat.hxx>
-
-#include <cmath>
-
-namespace
-{
-
-  //! Auxiliary function to translate rectangle by the vector.
-  inline void move (Font_FTFont::Rect& theRect,
-                    const OpenGl_Vec2& theVec)
-  {
-    theRect.Left   += theVec.x();
-    theRect.Right  += theVec.x();
-    theRect.Top    += theVec.y();
-    theRect.Bottom += theVec.y();
-  }
-
-  //! Auxiliary function to translate rectangles by the vector.
-  inline void move (NCollection_Vector<OpenGl_Font::Tile>& theRects,
-                    const OpenGl_Vec2&                     theMoveVec,
-                    Standard_Integer                       theCharLower,
-                    const Standard_Integer                 theCharUpper)
-  {
-    for(; theCharLower <= theCharUpper; ++theCharLower)
-    {
-      Font_FTFont::Rect& aRect = theRects.ChangeValue (theCharLower).px;
-      move (aRect, theMoveVec);
-    }
-  }
-
-  //! Auxiliary function to translate rectangles in horizontal direction.
-  /*inline void moveX (NCollection_Vector<OpenGl_Font::Tile>& theRects,
-                     const Standard_ShortReal               theMoveVec,
-                     Standard_Integer                       theCharLower,
-                     const Standard_Integer                 theCharUpper)
-  {
-    for (; theCharLower <= theCharUpper; ++theCharLower)
-    {
-      Font_FTFont::Rect& aRect = theRects.ChangeValue (theCharLower).px;
-      aRect.Left  += theMoveVec;
-      aRect.Right += theMoveVec;
-    }
-  }*/
-
-  //! Auxiliary function to translate rectangles in vertical direction.
-  inline void moveY (NCollection_Vector<OpenGl_Font::Tile>& theRects,
-                     const Standard_ShortReal               theMoveVec,
-                     Standard_Integer                       theCharLower,
-                     const Standard_Integer                 theCharUpper)
-  {
-    for(; theCharLower <= theCharUpper; ++theCharLower)
-    {
-      Font_FTFont::Rect& aRect = theRects.ChangeValue (theCharLower).px;
-      aRect.Top    += theMoveVec;
-      aRect.Bottom += theMoveVec;
-    }
-  }
-
-  //! Apply floor to vector components.
-  //! @param  theVec - vector to change (by reference!)
-  //! @return modified vector
-  inline OpenGl_Vec2& floor (OpenGl_Vec2& theVec)
-  {
-    theVec.x() = std::floor (theVec.x());
-    theVec.y() = std::floor (theVec.y());
-    return theVec;
-  }
-
-};
-
-IMPLEMENT_STANDARD_HANDLE (OpenGl_TextFormatter, Standard_Transient)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_TextFormatter, Standard_Transient)
-
-// =======================================================================
-// function : OpenGl_TextFormatter
-// purpose  :
-// =======================================================================
-OpenGl_TextFormatter::OpenGl_TextFormatter()
-: myAlignX (Graphic3d_HTA_LEFT),
-  myAlignY (Graphic3d_VTA_TOP),
-  myTabSize (8),
-  //
-  myPen (0.0f, 0.0f),
-  myRectsNb (0),
-  myLineSpacing (0.0f),
-  myAscender (0.0f),
-  myIsFormatted (false),
-  //
-  myLinesNb (0),
-  myRectLineStart (0),
-  myRectWordStart (0),
-  myNewLineNb(0),
-  myPenCurrLine (0.0f),
-  myLineLeft (0.0f),
-  myLineTail (0.0f),
-  myBndTop   (0.0f),
-  myBndWidth (0.0f),
-  myMoveVec (0.0f, 0.0f)
-{
-  //
-}
-
-// =======================================================================
-// function : SetupAlignment
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
-                                           const Graphic3d_VerticalTextAlignment   theAlignY)
-{
-  myAlignX = theAlignX;
-  myAlignY = theAlignY;
-}
-
-// =======================================================================
-// function : Reset
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::Reset()
-{
-  myIsFormatted = false;
-  myString.Clear();
-  myPen.x() = myPen.y() = 0.0f;
-  myRectsNb = 0;
-  myLineSpacing = myAscender = 0.0f;
-  myRects.Clear();
-  myNewLines.Clear();
-}
-
-// =======================================================================
-// function : Result
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::Result (NCollection_Vector<GLuint>& theTextures,
-                                   NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > >& theVertsPerTexture,
-                                   NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > >& theTCrdsPerTexture) const
-{
-  OpenGl_Vec2 aVec (0.0f, 0.0f);
-  theTextures.Clear();
-  theVertsPerTexture.Clear();
-  theTCrdsPerTexture.Clear();
-  for (Standard_Integer aRectIter = 0; aRectIter < myRectsNb; ++aRectIter)
-  {
-    const Font_FTFont::Rect& aRect    = myRects.Value (aRectIter).px;
-    const Font_FTFont::Rect& aRectUV  = myRects.Value (aRectIter).uv;
-    const GLuint             aTexture = myRects.Value (aRectIter).texture;
-
-    Standard_Integer aListId = 0;
-    for (aListId = 0; aListId < theTextures.Length(); ++aListId)
-    {
-      if (theTextures.Value (aListId) == aTexture)
-      {
-        break;
-      }
-    }
-    if (aListId >= theTextures.Length())
-    {
-      theTextures.Append (aTexture);
-      theVertsPerTexture.Append (new NCollection_Vector<OpenGl_Vec2>());
-      theTCrdsPerTexture.Append (new NCollection_Vector<OpenGl_Vec2>());
-    }
-
-    NCollection_Vector<OpenGl_Vec2>& aVerts = *theVertsPerTexture.ChangeValue (aListId);
-    NCollection_Vector<OpenGl_Vec2>& aTCrds = *theTCrdsPerTexture.ChangeValue (aListId);
-
-    // apply floor on position to avoid blurring issues
-    // due to cross-pixel coordinates
-    aVerts.Append (floor(aRect.TopRight   (aVec)));
-    aVerts.Append (floor(aRect.TopLeft    (aVec)));
-    aVerts.Append (floor(aRect.BottomLeft (aVec)));
-    aTCrds.Append (aRectUV.TopRight   (aVec));
-    aTCrds.Append (aRectUV.TopLeft    (aVec));
-    aTCrds.Append (aRectUV.BottomLeft (aVec));
-
-    aVerts.Append (floor(aRect.BottomRight (aVec)));
-    aVerts.Append (floor(aRect.TopRight    (aVec)));
-    aVerts.Append (floor(aRect.BottomLeft  (aVec)));
-    aTCrds.Append (aRectUV.BottomRight (aVec));
-    aTCrds.Append (aRectUV.TopRight    (aVec));
-    aTCrds.Append (aRectUV.BottomLeft  (aVec));
-  }
-}
-
-// =======================================================================
-// function : Result
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::Result (const Handle(OpenGl_Context)&                    theCtx,
-                                   NCollection_Vector<GLuint>&                      theTextures,
-                                   NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theVertsPerTexture,
-                                   NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theTCrdsPerTexture) const
-{
-  NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > > aVertsPerTexture;
-  NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > > aTCrdsPerTexture;
-  Result (theTextures, aVertsPerTexture, aTCrdsPerTexture);
-
-  if (theVertsPerTexture.Length() != theTextures.Length())
-  {
-    for (Standard_Integer aTextureIter = 0; aTextureIter < theVertsPerTexture.Length(); ++aTextureIter)
-    {
-      theVertsPerTexture.Value (aTextureIter)->Release (theCtx.operator->());
-      theTCrdsPerTexture.Value (aTextureIter)->Release (theCtx.operator->());
-    }
-    theVertsPerTexture.Clear();
-    theTCrdsPerTexture.Clear();
-
-    const bool isNormalMode = theCtx->ToUseVbo();
-    Handle(OpenGl_VertexBuffer) aVertsVbo, aTcrdsVbo;
-    while (theVertsPerTexture.Length() < theTextures.Length())
-    {
-      if (isNormalMode)
-      {
-        aVertsVbo = new OpenGl_VertexBuffer();
-        aTcrdsVbo = new OpenGl_VertexBuffer();
-      }
-      else
-      {
-        aVertsVbo = new OpenGl_VertexBufferCompat();
-        aTcrdsVbo = new OpenGl_VertexBufferCompat();
-      }
-      theVertsPerTexture.Append (aVertsVbo);
-      theTCrdsPerTexture.Append (aTcrdsVbo);
-      aVertsVbo->Create (theCtx);
-      aTcrdsVbo->Create (theCtx);
-    }
-  }
-
-  for (Standard_Integer aTextureIter = 0; aTextureIter < theTextures.Length(); ++aTextureIter)
-  {
-    const NCollection_Vector<OpenGl_Vec2>& aVerts = *aVertsPerTexture.Value (aTextureIter);
-    Handle(OpenGl_VertexBuffer)& aVertsVbo = theVertsPerTexture.ChangeValue (aTextureIter);
-    if (!aVertsVbo->Init (theCtx, 2, aVerts.Length(), (GLfloat* )NULL)
-     || !myVboEditor.Init (theCtx, aVertsVbo))
-    {
-      continue;
-    }
-    for (Standard_Integer aVertIter = 0; aVertIter < aVerts.Length(); ++aVertIter, myVboEditor.Next())
-    {
-      myVboEditor.Value() = aVerts.Value (aVertIter);
-    }
-    myVboEditor.Flush();
-
-    const NCollection_Vector<OpenGl_Vec2>& aTCrds = *aTCrdsPerTexture.Value (aTextureIter);
-    Handle(OpenGl_VertexBuffer)& aTCrdsVbo = theTCrdsPerTexture.ChangeValue (aTextureIter);
-    if (!aTCrdsVbo->Init (theCtx, 2, aVerts.Length(), (GLfloat* )NULL)
-     || !myVboEditor.Init (theCtx, aTCrdsVbo))
-    {
-      continue;
-    }
-    for (Standard_Integer aVertIter = 0; aVertIter < aVerts.Length(); ++aVertIter, myVboEditor.Next())
-    {
-      myVboEditor.Value() = aTCrds.Value (aVertIter);
-    }
-    myVboEditor.Flush();
-  }
-  myVboEditor.Init (NULL, NULL);
-}
-
-// =======================================================================
-// function : Append
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::Append (const Handle(OpenGl_Context)& theCtx,
-                                   const NCollection_String&     theString,
-                                   OpenGl_Font&                  theFont)
-{
-  if (theString.IsEmpty())
-  {
-    return;
-  }
-
-  myAscender    = Max (myAscender,    theFont.Ascender());
-  myLineSpacing = Max (myLineSpacing, theFont.LineSpacing());
-  myString     += theString;
-
-  int aSymbolsCounter = 0; // special counter to process tabulation symbols
-
-  // first pass - render all symbols using associated font on single ZERO baseline
-  OpenGl_Font::Tile aTile;
-  memset (&aTile, 0, sizeof(aTile));
-  for (NCollection_Utf8Iter anIter = theString.Iterator(); *anIter != 0;)
-  {
-    const Standard_Utf32Char aCharThis =   *anIter;
-    const Standard_Utf32Char aCharNext = *++anIter;
-
-    if (aCharThis == '\x0D' // CR  (carriage return)
-     || aCharThis == '\a'   // BEL (alarm)
-     || aCharThis == '\f'   // FF  (form feed) NP (new page)
-     || aCharThis == '\b'   // BS  (backspace)
-     || aCharThis == '\v')  // VT  (vertical tab)
-    {
-      continue; // skip unsupported carriage control codes
-    }
-    else if (aCharThis == '\x0A') // LF (line feed, new line)
-    {
-      aSymbolsCounter = 0;
-      myNewLines.Append (myPen.x());
-      continue; // will be processed on second pass
-    }
-    else if (aCharThis == ' ')
-    {
-      ++aSymbolsCounter;
-      myPen.x() += theFont.AdvanceX (' ', aCharNext);
-      continue;
-    }
-    else if (aCharThis == '\t')
-    {
-      const Standard_Integer aSpacesNum = (myTabSize - (aSymbolsCounter - 1) % myTabSize);
-      myPen.x() += theFont.AdvanceX (' ', aCharNext) * Standard_ShortReal(aSpacesNum);
-      aSymbolsCounter += aSpacesNum;
-      continue;
-    }
-
-    ++aSymbolsCounter;
-    theFont.RenderGlyph (theCtx,
-                         aCharThis, aCharNext,
-                         aTile, myPen);
-    myRects.Append (aTile);
-
-    ++myRectsNb;
-  }
-}
-
-// =======================================================================
-// function : newLine
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::newLine (const Standard_Integer theLastRect)
-{
-  if (myRectLineStart >= myRectsNb)
-  {
-    ++myLinesNb;
-    myPenCurrLine -= myLineSpacing;
-    return;
-  }
-
-  myMoveVec.y() = myPenCurrLine;
-  switch (myAlignX)
-  {
-    default:
-    case Graphic3d_HTA_LEFT:
-    {
-      myMoveVec.x() = (myNewLineNb > 0) ? -myNewLines.Value (myNewLineNb - 1) : 0.0f;
-      break;
-    }
-    case Graphic3d_HTA_RIGHT:
-    {
-      myMoveVec.x() = (myNewLineNb < myNewLines.Length())
-                    ? -myNewLines.Value (myNewLineNb)
-                    : -myPen.x();
-      break;
-    }
-    case Graphic3d_HTA_CENTER:
-    {
-      const Standard_ShortReal aFrom = (myNewLineNb > 0)
-                                     ? myNewLines.Value (myNewLineNb - 1)
-                                     : 0.0f;
-      const Standard_ShortReal aTo   = (myNewLineNb < myNewLines.Length())
-                                     ? myNewLines.Value (myNewLineNb)
-                                     : myPen.x();
-      myMoveVec.x() = -0.5f * (aFrom + aTo);
-      break;
-    }
-  }
-
-  move (myRects, myMoveVec, myRectLineStart, theLastRect);
-
-  ++myLinesNb;
-  myPenCurrLine -= myLineSpacing;
-  myRectLineStart = myRectWordStart = theLastRect + 1;
-  if (myRectLineStart < myRectsNb)
-  {
-    myLineLeft = myRects.Value (myRectLineStart).px.Left;
-  }
-}
-
-// =======================================================================
-// function : Format
-// purpose  :
-// =======================================================================
-void OpenGl_TextFormatter::Format()
-{
-  if (myRectsNb == 0 || myIsFormatted)
-  {
-    return;
-  }
-
-  myIsFormatted = true;
-  myLinesNb = myRectLineStart = myRectWordStart = 0;
-  myLineLeft   = 0.0f;
-  myLineTail   = 0.0f;
-  myBndTop     = 0.0f;
-  myBndWidth   = 0.0f;
-  myMoveVec.x() = myMoveVec.y() = 0.0f;
-
-  // split text into lines and apply horizontal alignment
-  myPenCurrLine = -myAscender;
-  Standard_Integer aRectIter = 0;
-  myNewLineNb = 0;
-  for (NCollection_Utf8Iter anIter = myString.Iterator(); *anIter != 0; ++anIter)
-  {
-    const Standard_Utf32Char aCharThis = *anIter;
-    if (aCharThis == '\x0D' // CR  (carriage return)
-     || aCharThis == '\a'   // BEL (alarm)
-     || aCharThis == '\f'   // FF  (form feed) NP (new page)
-     || aCharThis == '\b'   // BS  (backspace)
-     || aCharThis == '\v')  // VT  (vertical tab)
-    {
-      continue; // skip unsupported carriage control codes
-    }
-    else if (aCharThis == '\x0A') // LF (line feed, new line)
-    {
-      const Standard_Integer aLastRect = aRectIter - 1; // last rect on current line
-      newLine (aLastRect);
-      ++myNewLineNb;
-      continue;
-    }
-    else if (aCharThis == ' '
-          || aCharThis == '\t')
-    {
-      myRectWordStart = aRectIter;
-      continue;
-    }
-
-    Standard_ShortReal aWidth = myRects.Value (aRectIter).px.Right - myLineLeft;
-    myBndWidth = Max (myBndWidth, aWidth);
-
-    ++aRectIter;
-  }
-
-  // move last line
-  newLine (myRectsNb - 1);
-
-  // apply vertical alignment style
-  if (myAlignY == Graphic3d_VTA_BOTTOM)
-  {
-    myBndTop = -myLineSpacing - myPenCurrLine;
-    moveY (myRects, myBndTop, 0, myRectsNb - 1);
-  }
-  else if (myAlignY == Graphic3d_VTA_CENTER)
-  {
-    myBndTop = 0.5f * (myLineSpacing * Standard_ShortReal(myLinesNb));
-    moveY (myRects, myBndTop, 0, myRectsNb - 1);
-  }
-}
diff --git a/src/OpenGl/OpenGl_TextFormatter.hxx b/src/OpenGl/OpenGl_TextFormatter.hxx
deleted file mode 100755 (executable)
index adca108..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-// Created on: 2013-01-29
-// Created by: Kirill GAVRILOV
-// Copyright (c) 2013-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef _OpenGl_TextFormatter_H__
-#define _OpenGl_TextFormatter_H__
-
-#include <OpenGl_Font.hxx>
-#include <OpenGl_VertexBufferEditor.hxx>
-
-#include <Graphic3d_HorizontalTextAlignment.hxx>
-#include <Graphic3d_VerticalTextAlignment.hxx>
-
-#include <NCollection_String.hxx>
-
-//! This class intended to prepare formatted text.
-class OpenGl_TextFormatter : public Standard_Transient
-{
-
-public:
-
-  //! Default constructor.
-  Standard_EXPORT OpenGl_TextFormatter();
-
-  //! Setup alignment style.
-  Standard_EXPORT void SetupAlignment (const Graphic3d_HorizontalTextAlignment theAlignX,
-                                       const Graphic3d_VerticalTextAlignment   theAlignY);
-
-  //! Reset current progress.
-  Standard_EXPORT void Reset();
-
-  //! Render specified text to inner buffer.
-  Standard_EXPORT void Append (const Handle(OpenGl_Context)& theCtx,
-                               const NCollection_String&     theString,
-                               OpenGl_Font&                  theFont);
-
-  //! Perform formatting on the buffered text.
-  //! Should not be called more than once after initialization!
-  Standard_EXPORT void Format();
-
-  //! Retrieve formatting results.
-  Standard_EXPORT void Result (NCollection_Vector<GLuint>& theTextures,
-                               NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > >& theVertsPerTexture,
-                               NCollection_Vector< NCollection_Handle <NCollection_Vector <OpenGl_Vec2> > >& theTCrdsPerTexture) const;
-
-  //! Retrieve formatting results.
-  Standard_EXPORT void Result (const Handle(OpenGl_Context)&                    theCtx,
-                               NCollection_Vector<GLuint>&                      theTextures,
-                               NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theVertsPerTexture,
-                               NCollection_Vector<Handle(OpenGl_VertexBuffer)>& theTCrdsPerTexture) const;
-
-  //! @return width of formatted text.
-  inline Standard_ShortReal ResultWidth() const
-  {
-    return myBndWidth;
-  }
-
-  //! @return height of formatted text.
-  inline Standard_ShortReal ResultHeight() const
-  {
-    return myLineSpacing * Standard_ShortReal(myLinesNb);
-  }
-
-  //! @param bounding box.
-  inline void BndBox (Font_FTFont::Rect& theBndBox) const
-  {
-    theBndBox.Left = 0.0f;
-    switch (myAlignX)
-    {
-      default:
-      case Graphic3d_HTA_LEFT:  theBndBox.Right  =  myBndWidth; break;
-      case Graphic3d_HTA_RIGHT: theBndBox.Right  = -myBndWidth; break;
-      case Graphic3d_HTA_CENTER:
-      {
-        theBndBox.Left  = -0.5f * myBndWidth;
-        theBndBox.Right =  0.5f * myBndWidth;
-        break;
-      }
-    }
-    theBndBox.Top    = myBndTop;
-    theBndBox.Bottom = theBndBox.Top - myLineSpacing * Standard_ShortReal(myLinesNb);
-  }
-
-protected: //! @name class auxiliary methods
-
-  //! Move glyphs on the current line to correct position.
-  Standard_EXPORT void newLine (const Standard_Integer theLastRect);
-
-protected: //! @name configuration
-
-  Graphic3d_HorizontalTextAlignment myAlignX;  //!< horizontal alignment style
-  Graphic3d_VerticalTextAlignment   myAlignY;  //!< vertical   alignment style
-  Standard_Integer                  myTabSize; //!< horizontal tabulation width (number of space symbols)
-
-protected: //! @name input data
-
-  NCollection_String myString;        //!< currently rendered text
-  OpenGl_Vec2        myPen;           //!< current pen position
-  NCollection_Vector<OpenGl_Font::Tile>
-                     myRects;         //!< glyphs rectangles
-  Standard_Integer   myRectsNb;       //!< rectangles number
-  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;      //!<
-  bool               myIsFormatted;   //!< formatting state
-
-protected:
-
-  mutable OpenGl_VertexBufferEditor<OpenGl_Vec2> myVboEditor;
-
-protected: //! @name temporary variables for formatting routines
-
-  Standard_Integer   myLinesNb;       //!< overall (new)lines number (including splitting by width limit)
-  Standard_Integer   myRectLineStart; //!< id of first rectangle on the current line
-  Standard_Integer   myRectWordStart; //!< id of first rectangle in the current word
-  Standard_Integer   myNewLineNb;
-
-  Standard_ShortReal myPenCurrLine;   //!< current baseline position
-  Standard_ShortReal myLineLeft;      //!< left x position of first glyph on line before formatting applied
-  Standard_ShortReal myLineTail;
-  Standard_ShortReal myBndTop;
-  Standard_ShortReal myBndWidth;
-  OpenGl_Vec2        myMoveVec;       //!< local variable
-
-public:
-
-  DEFINE_STANDARD_RTTI(OpenGl_TextFormatter) // Type definition
-
-};
-
-DEFINE_STANDARD_HANDLE(OpenGl_TextFormatter, Standard_Transient)
-
-#endif // _OpenGl_TextFormatter_H__