MantisBT - Open CASCADE
View Issue Details
0030537Open CASCADE[OCCT] OCCT:Visualizationpublic2019-03-04 20:072019-09-04 16:17
nds 
nds 
normalfeature 
assignedopen 
 
[OCCT] 7.5.0* 
0030537: Visualization - wrapping text in font text formatter
Provide a possibility to wrap the text given into Font_TextFormatter.
No tags attached.
related to 0030857verified apn Visualization - using one implementation of Text in graphic group 
Issue History
2019-03-04 20:07ndsNew Issue
2019-03-04 20:07ndsAssigned To => nds
2019-03-04 20:09gitNote Added: 0082596
2019-03-05 06:43gitNote Added: 0082600
2019-03-05 14:04gitNote Added: 0082695
2019-03-05 18:56gitNote Added: 0082700
2019-03-05 19:14gitNote Added: 0082702
2019-03-05 20:04gitNote Added: 0082704
2019-07-18 11:09gitNote Added: 0085741
2019-07-18 11:47ndsNote Added: 0085751
2019-07-18 17:34kgvNote Added: 0085769
2019-08-02 07:16gitNote Added: 0085973
2019-08-02 07:38gitNote Added: 0085975
2019-08-02 08:40ndsRelationship addedrelated to 0030857
2019-08-02 15:24ndsNote Added: 0085989
2019-08-02 15:24ndsAssigned Tonds => kgv
2019-08-02 15:24ndsStatusnew => resolved
2019-08-02 15:30kgvNote Added: 0085990
2019-08-02 15:30kgvAssigned Tokgv => nds
2019-08-02 15:30kgvStatusresolved => assigned
2019-08-02 16:32ndsNote Added: 0086002
2019-08-02 16:32ndsAssigned Tonds => kgv
2019-08-07 15:25gitNote Added: 0086067
2019-08-23 09:25gitNote Added: 0086427
2019-09-04 16:17kgvAssigned Tokgv => nds
2019-09-04 16:17kgvSeverityminor => feature
2019-09-04 16:17kgvTarget Version7.4.0 => 7.5.0*

Notes
(0082596)
git   
2019-03-04 20:09   
Branch CR30537 has been created by nds.

SHA-1: 858c86bc219d831d4baf2bb6506991761949c5bd


Detailed log of new commits:

Author: nds
Date: Mon Mar 4 20:04:26 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
(0082600)
git   
2019-03-05 06:43   
Branch CR30537 has been updated by nds.

SHA-1: 217d9b95df29d8d34807608d8738719e48304529


Detailed log of new commits:

Author: nds
Date: Tue Mar 5 06:38:12 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    #compilation correction

(0082695)
git   
2019-03-05 14:04   
Branch CR30537 has been updated by nds.

SHA-1: 85092818767d50c34928ff76619d24dc5377a40c


Detailed log of new commits:

Author: nds
Date: Tue Mar 5 13:52:37 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    #LineWidth public method, correction to compute line width in Format()

(0082700)
git   
2019-03-05 18:56   
Branch CR30537 has been updated by nds.

SHA-1: 3ae32a0a4e0fea48e00947c1761f60a0e123e45e


Detailed log of new commits:

Author: nds
Date: Tue Mar 5 18:51:12 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    #corners should be arranged around (0,0) point, example of the first point if rect width is 100, symbol has an empty width:
    # - left alignment: (-50, 0)
    # - center alignment: (0, 0)
    # - right alignment: (50, 0)

(0082702)
git   
2019-03-05 19:14   
Branch CR30537 has been updated by nds.

SHA-1: f3a4b8369495a2c2723cb19d91cdd9cff4401df3


Detailed log of new commits:

Author: nds
Date: Tue Mar 5 18:54:28 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    #corners should be arranged around (0,0) point, example of the first point if rect width is 100, symbol has an empty width:
    # - left alignment: (-50, 0)
    # - center alignment: (0, 0)
    # - right alignment: (50, 0)
    
    (cherry picked from commit 783914e968375a3165dffc83ae66c285a8c8dcbc)

(0082704)
git   
2019-03-05 20:04   
Branch CR30537 has been updated by nds.

SHA-1: 1bbbcca13bc8d1edb782c51793c73c453dd2ef92


Detailed log of new commits:

Author: nds
Date: Tue Mar 5 19:57:36 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    # last row length correction
    
    (cherry picked from commit 7dab09204f899fc54dbd5379bcd76e7d23af831d)

(0085741)
git   
2019-07-18 11:09   
Branch CR30537_1 has been created by nds.

SHA-1: 7ba0c7dc49b4de17aa99908ceea25cc9bdff8909


Detailed log of new commits:

Author: nds
Date: Thu Mar 7 16:28:20 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    (cherry picked from commit 8016b09836d484f061a75ac303953f9d80c05109)
    
    # Conflicts:
    # src/Graphic3d/Graphic3d_Group.hxx
    # src/OpenGl/OpenGl_Text.hxx
    (cherry picked from commit c0a38f3a5294cc0f168bc592f17f4ec9837d5a48)
    (cherry picked from commit ba793f42f8cc07e041f448e2685dca63ecde547f)
(0085751)
nds   
2019-07-18 11:47   
Jenkins job:
http://jenkins-test-12.nnov.opencascade.com/view/CR30537_1-CR30537_1-NDS/ [^]
(0085769)
kgv   
2019-07-18 17:34   
+  //! Iterator through light sources.
+  class Iterator
+  {
+  public:
+    //! Constructor with initialization.
+    Iterator (const Handle(Font_TextFormatter)& theFormatter,
+              IterationFilter theFilter = IterationFilter_None)

It looks redundant passing/requiring handle in iterator - usually iterators hold a reference (pointer) to the collection.

+    //! Returns current symbol.
+    const Standard_Utf32Char& Symbol() const { return mySymbolChar; }
+
+    //! Returns the next symbol if exists.
+    const Standard_Utf32Char& SymbolNext() const { return mySymbolCharNext; }
+
+    //! Returns current symbol position.
+    const Standard_Integer& SymbolPosition() const { return mySymbolPosition; }
+
+    //! Returns the next symbol position.
+    const Standard_Integer& SymbolPositionNext() const { return mySymbolNext; }

Please avoid returning/passing primitive types like Standard_Integer, Standard_Utf32Char via reference.

-  Font_TextFormatter aFormatter;
-  aFormatter.SetupAlignment (theAlignX, theAlignY);
-  aFormatter.Reset();
+  Handle(Font_TextFormatter) aFormatter = new Font_TextFormatter();

I would suggest avoiding creation of handle where it is not actually needed.

+  //!< Returns true if the symbol is CR, BEL, FF, NP, BS or VT
+  Standard_EXPORT static Standard_Boolean IsCommandSymbol (const Standard_Utf32Char& theSymbol);


This expected to be inline.

+void Graphic3d_Group::Text (const Handle(Font_TextFormatter)&       theTextFormatter,
+                            const gp_Ax2&                           theOrientation,
+                            const Standard_Real                     theHeight,

The expansion of Text() methods should last.
Consider defining a common structure for passing auxiliary parameters and Text representation modes,
and replacing all Text() methods with single one (existing methods to be preserved for a while as deprecated redirections to new method).

-    Font_TextFormatter aFormatter;
-    aFormatter.SetupAlignment (myParams.HAlign, myParams.VAlign);
-    aFormatter.Reset();
+    Handle(Font_TextFormatter) aFormatter = myFormatter;
+    if (myFormatter.IsNull())

It is preferred putting shared temporary instance of Font_TextFormatter inside OpenGl_Context.

+  //!< 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<Standard_ShortReal>& GetNewLines() const { return myNewLines; }

...
+  //! Returns position of the first symbol in a line using alignment
+  Standard_EXPORT Standard_ShortReal GetFirstPosition() const;

"Get" is unexpected prefix.

+  if (aFirstCornerId >= getRectsNb())

Usage of trivial getter within the class implementation looks dubious.
(0085973)
git   
2019-08-02 07:16   
Branch CR30537_2 has been created by nds.

SHA-1: 25a41791e3c93a47596bb768b3aaaa192abced10


Detailed log of new commits:

Author: nds
Date: Fri Aug 2 07:11:31 2019 +0300

    0030537: Visualization - wrapping text in font text formatter - correction after review
    
    (cherry picked from commit 9e7172d37227121ae550f7e4f10fc59725622ed3)

Author: nds
Date: Thu Mar 7 16:28:20 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    (cherry picked from commit 8016b09836d484f061a75ac303953f9d80c05109)
    
    # Conflicts:
    # src/Graphic3d/Graphic3d_Group.hxx
    # src/OpenGl/OpenGl_Text.hxx
    (cherry picked from commit c0a38f3a5294cc0f168bc592f17f4ec9837d5a48)
    (cherry picked from commit ba793f42f8cc07e041f448e2685dca63ecde547f)
    (cherry picked from commit 7ba0c7dc49b4de17aa99908ceea25cc9bdff8909)
(0085975)
git   
2019-08-02 07:38   
Branch CR30537_3 has been created by nds.

SHA-1: 0d9c24acb9d1ef06c1f4212c00b90d50475a3fa1


Detailed log of new commits:

Author: nds
Date: Thu Mar 7 16:28:20 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
(0085989)
nds   
2019-08-02 15:24   
Dear Kirill,

please review the branch.

Some remarks are corrected as you recommended.
Remarks NOT corrected:
1. The expansion of Text() methods should last.
   -> I propose to implement it in another issue 0030857, if possible (to do not make this integration too thick).
2. It is preferred putting shared temporary instance of Font_TextFormatter inside OpenGl_Context.
  -> I'm not sure that correctly understand this recomendation. Do you mean having one instance as default one? If yes, the fix contains it.
On the other hand, I would expect that each text have own text formatter (as it caches calculated positions/sizes) and avoid recompute formatting on each render() call. It seems that it improves performance.

Best regards, Natalia
(0085990)
kgv   
2019-08-02 15:30   
> 1. The expansion of Text() methods should last.
> -> I propose to implement it in another issue 0030857, if possible (to do not make this integration too thick).
Then please process the referred issue first.

> 2. It is preferred putting shared temporary instance of Font_TextFormatter inside OpenGl_Context.
> -> I'm not sure that correctly understand this recomendation. Do you mean having one instance as default one? If yes, the fix contains it.
In context of implicitly created formatter, this formatter is created temporarily.
The idea is to create this temporary formatter once and reuse it to avoid extra memory flactuations/keep memory buffers allocated.
(0086002)
nds   
2019-08-02 16:32   
Dear Kirill,

thank you for explanation.
1. Ok
2. If several text presentations are shown in the viewer, each one has long text(for example) with own formatter. Don't you think that render() for each will require much time to recompute it? Anyway, it is possible do not use SetTextFormatter for text group, then the default formatter(from Context) will be used(acoording to current implementation) and your case works here.

Best regards, Natalia
(0086067)
git   
2019-08-07 15:25   
Branch CR30537_4 has been created by nds.

SHA-1: fe7b06965a80e25b4d07a214d7a6e2d3eefcdd1c


Detailed log of new commits:

Author: nds
Date: Wed Aug 7 15:23:18 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
(0086427)
git   
2019-08-23 09:25   
Branch CR30537_5 has been created by nds.

SHA-1: 91ba6d212b5b3398191212a4922c7a3f0ccdc730


Detailed log of new commits:

Author: nds
Date: Fri Aug 23 09:22:27 2019 +0300

    0030537: Visualization - wrapping text in font text formatter
    
    Font_TextFormatter inherits Standard_Transient, now it is given as a handle in functions.
    Graphic3d_Text - extended with Font_TextFormatter to be able to have it filled out of text render. If it is not defined here, the default text formatter of context is used.
    OpenGl_Context - has default Font_TextFormatter for rendering OpenGl_Text.