0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / Font / Font_BRepTextBuilder.cxx
1 // Created on: 2015-08-10
2 // Created by: Ilya SEVRIKOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Font_BRepTextBuilder.hxx>
17
18 // =======================================================================
19 // Function : Perfrom
20 // Purpose  :
21 // =======================================================================
22 TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont&            theFont,
23                                             const Font_TextFormatter& theFormatter,
24                                             const gp_Ax3&             thePenLoc)
25 {
26   gp_Trsf          aTrsf;
27   gp_XYZ           aPen;
28   TopoDS_Shape     aGlyphShape;
29   TopoDS_Compound  aResult;
30   Standard_Mutex::Sentry aSentry (theFont.Mutex());
31
32   myBuilder.MakeCompound (aResult);
33
34   Standard_Integer aSymbolCounter = 0;
35   Standard_Real    aScaleUnits    = theFont.Scale();
36   for (NCollection_Utf8Iter anIter = theFormatter.String().Iterator(); *anIter != 0; ++anIter)
37   {
38     const Standard_Utf32Char aCharCurr = *anIter;
39     if (aCharCurr == '\x0D' // CR  (carriage return)
40      || aCharCurr == '\a'   // BEL (alarm)
41      || aCharCurr == '\f'   // FF  (form feed) NP (new page)
42      || aCharCurr == '\b'   // BS  (backspace)
43      || aCharCurr == '\v'   // VT  (vertical tab)
44      || aCharCurr == ' '
45      || aCharCurr == '\t'
46      || aCharCurr == '\n')
47     {
48       continue; // skip unsupported carriage control codes
49     }
50
51     const NCollection_Vec2<Standard_ShortReal>& aCorner = theFormatter.TopLeft (aSymbolCounter);
52     aPen.SetCoord (aCorner.x() * aScaleUnits, aCorner.y() * aScaleUnits, 0.0);
53     aGlyphShape = theFont.RenderGlyph (aCharCurr);
54     if (!aGlyphShape.IsNull())
55     {
56       aTrsf.SetTranslation (gp_Vec (aPen));
57       aGlyphShape.Move (aTrsf);
58       myBuilder.Add (aResult, aGlyphShape);
59     }
60
61     ++aSymbolCounter;
62   }
63
64   aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY()));
65   aResult.Move (aTrsf);
66
67   return aResult;
68 }
69
70 // =======================================================================
71 // Function : Perform
72 // Purpose  :
73 // =======================================================================
74 TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont&                          theFont,
75                                             const NCollection_String&               theString,
76                                             const gp_Ax3&                           thePenLoc,
77                                             const Graphic3d_HorizontalTextAlignment theHAlign,
78                                             const Graphic3d_VerticalTextAlignment   theVAlign)
79 {
80   Font_TextFormatter aFormatter;
81
82   aFormatter.Reset();
83   aFormatter.SetupAlignment (theHAlign, theVAlign);
84
85   aFormatter.Append (theString, *(reinterpret_cast<Font_FTFont*> (&theFont)));
86   aFormatter.Format();
87
88   return Perform (theFont, aFormatter, thePenLoc);
89 }