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 <StdPrs_BRepTextBuilder.hxx>
18 #include <Font_TextFormatter.hxx>
20 // =======================================================================
23 // =======================================================================
24 TopoDS_Shape StdPrs_BRepTextBuilder::Perform (StdPrs_BRepFont& theFont,
25 const Handle(Font_TextFormatter)& theFormatter,
26 const gp_Ax3& thePenLoc)
30 TopoDS_Shape aGlyphShape;
31 TopoDS_Compound aResult;
32 Standard_Mutex::Sentry aSentry (theFont.Mutex());
34 myBuilder.MakeCompound (aResult);
36 Standard_Real aScaleUnits = theFont.Scale();
37 for (Font_TextFormatter::Iterator aFormatterIt (*theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
38 aFormatterIt.More(); aFormatterIt.Next())
40 const NCollection_Vec2<Standard_ShortReal>& aCorner = theFormatter->BottomLeft (aFormatterIt.SymbolPosition());
42 aPen.SetCoord (aCorner.x() * aScaleUnits, aCorner.y() * aScaleUnits, 0.0);
43 aGlyphShape = theFont.RenderGlyph (aFormatterIt.Symbol());
44 if (!aGlyphShape.IsNull())
46 aTrsf.SetTranslation (gp_Vec (aPen));
47 aGlyphShape.Move (aTrsf);
48 myBuilder.Add (aResult, aGlyphShape);
52 aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY()));
58 // =======================================================================
61 // =======================================================================
62 TopoDS_Shape StdPrs_BRepTextBuilder::Perform (StdPrs_BRepFont& theFont,
63 const NCollection_String& theString,
64 const gp_Ax3& thePenLoc,
65 const Graphic3d_HorizontalTextAlignment theHAlign,
66 const Graphic3d_VerticalTextAlignment theVAlign)
68 Handle(Font_TextFormatter) aFormatter = new Font_TextFormatter();
71 aFormatter->SetupAlignment (theHAlign, theVAlign);
73 aFormatter->Append (theString, *(reinterpret_cast<Font_FTFont*> (&theFont)));
76 return Perform (theFont, aFormatter, thePenLoc);