0030537: Visualization - wrapping text in font text formatter
[occt.git] / src / StdPrs / StdPrs_BRepTextBuilder.cxx
CommitLineData
ac84fcf6 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
7f24b768 16#include <StdPrs_BRepTextBuilder.hxx>
ac84fcf6 17
60f7b225 18#include <Font_TextFormatter.hxx>
19
ac84fcf6 20// =======================================================================
21// Function : Perfrom
22// Purpose :
23// =======================================================================
7f24b768 24TopoDS_Shape StdPrs_BRepTextBuilder::Perform (StdPrs_BRepFont& theFont,
60f7b225 25 const Handle(Font_TextFormatter)& theFormatter,
7f24b768 26 const gp_Ax3& thePenLoc)
ac84fcf6 27{
28 gp_Trsf aTrsf;
29 gp_XYZ aPen;
30 TopoDS_Shape aGlyphShape;
31 TopoDS_Compound aResult;
32 Standard_Mutex::Sentry aSentry (theFont.Mutex());
33
34 myBuilder.MakeCompound (aResult);
35
60f7b225 36 Standard_Real aScaleUnits = theFont.Scale();
37 for (Font_TextFormatter::Iterator aFormatterIt (*theFormatter, Font_TextFormatter::IterationFilter_ExcludeInvisible);
38 aFormatterIt.More(); aFormatterIt.Next())
ac84fcf6 39 {
60f7b225 40 const NCollection_Vec2<Standard_ShortReal>& aCorner = theFormatter->BottomLeft (aFormatterIt.SymbolPosition());
ac84fcf6 41
ac84fcf6 42 aPen.SetCoord (aCorner.x() * aScaleUnits, aCorner.y() * aScaleUnits, 0.0);
60f7b225 43 aGlyphShape = theFont.RenderGlyph (aFormatterIt.Symbol());
ac84fcf6 44 if (!aGlyphShape.IsNull())
45 {
46 aTrsf.SetTranslation (gp_Vec (aPen));
47 aGlyphShape.Move (aTrsf);
48 myBuilder.Add (aResult, aGlyphShape);
49 }
ac84fcf6 50 }
51
52 aTrsf.SetTransformation (thePenLoc, gp_Ax3 (gp::XOY()));
53 aResult.Move (aTrsf);
54
55 return aResult;
56}
57
58// =======================================================================
59// Function : Perform
60// Purpose :
61// =======================================================================
7f24b768 62TopoDS_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)
ac84fcf6 67{
60f7b225 68 Handle(Font_TextFormatter) aFormatter = new Font_TextFormatter();
ac84fcf6 69
60f7b225 70 aFormatter->Reset();
71 aFormatter->SetupAlignment (theHAlign, theVAlign);
ac84fcf6 72
60f7b225 73 aFormatter->Append (theString, *(reinterpret_cast<Font_FTFont*> (&theFont)));
74 aFormatter->Format();
ac84fcf6 75
76 return Perform (theFont, aFormatter, thePenLoc);
77}