1 // Created on: 2015-08-10
2 // Created by: Ilya SEVRIKOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Font_BRepTextBuilder.hxx>
18 // =======================================================================
21 // =======================================================================
22 TopoDS_Shape Font_BRepTextBuilder::Perform (Font_BRepFont& theFont,
23 const Font_TextFormatter& theFormatter,
24 const gp_Ax3& thePenLoc)
28 TopoDS_Shape aGlyphShape;
29 TopoDS_Compound aResult;
30 Standard_Mutex::Sentry aSentry (theFont.Mutex());
32 myBuilder.MakeCompound (aResult);
34 Standard_Integer aSymbolCounter = 0;
35 Standard_Real aScaleUnits = theFont.Scale();
36 for (NCollection_Utf8Iter anIter = theFormatter.String().Iterator(); *anIter != 0; ++anIter)
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)
48 continue; // skip unsupported carriage control codes
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())
56 aTrsf.SetTranslation (gp_Vec (aPen));
57 aGlyphShape.Move (aTrsf);
58 myBuilder.Add (aResult, aGlyphShape);
64 aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY()));
70 // =======================================================================
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)
80 Font_TextFormatter aFormatter;
83 aFormatter.SetupAlignment (theHAlign, theVAlign);
85 aFormatter.Append (theString, *(reinterpret_cast<Font_FTFont*> (&theFont)));
88 return Perform (theFont, aFormatter, thePenLoc);