0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / PlotMgt / PlotMgt_TextManager.cxx
CommitLineData
b311480e 1// Created by: DCB
2// Copyright (c) 1993-1999 Matra Datavision
3// Copyright (c) 1999-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <PlotMgt_TextManager.ixx>
22#include <Aspect_Units.hxx>
23
24#ifdef WNT
25#pragma warning (disable : 4244)
26#endif
27
28//#define TRACE
29#define MAXPATHPOINTS 800
30#define MAXCHARPATHS 20
31#define MAXCHARPOINTS MAXPATHPOINTS*MAXCHARPATHS
32
33#define CONVERT(v) (v)*72./(0.0254005 METER)
34
35#define TRANSFORM(X,Y) \
36 { Standard_Real x = (X), y = (Y); \
37 X = x*theCosAngle - y*theSinAngle; \
38 Y = x*theSinAngle + y*theCosAngle; \
39 }
40
41#define ADD_POINT(X,Y,aX,aY) \
42 { theXPath[thePoint] = myDriver->MapX((X)+(aX)); \
43 theYPath[thePoint] = myDriver->MapY((Y)+(aY)); \
44 thePoint++; \
45 }
46
47//static Standard_Integer thePaintType, theNchar, theNpoly, theNpath;
48static Standard_Integer thePaintType, theNchar;
49static Standard_ShortReal theX, theY, thePX, thePY;
50static Standard_ShortReal theXmin, theXmax, theSinAngle, theCosAngle;
51static Standard_Real theOrientation, theSlant, theWidth, theHeight;
52static Standard_Integer theTextColor;
53static Standard_Integer theTypeOfText;
54static Quantity_Length theUnderlinePos;
55static Standard_ShortReal theXPath [MAXCHARPOINTS];
56static Standard_ShortReal theYPath [MAXCHARPOINTS];
57static Standard_Integer theCPath [MAXCHARPATHS ];
58static Standard_Integer thePoint = 0;
59static Standard_Integer thePathCount = 0;
60// Driver's graphic attributes
61static Standard_Integer lci, lti, lwi, pci, pti;
62static Standard_Boolean pef;
63
64//==========================================================
65PlotMgt_TextManager::PlotMgt_TextManager (const Handle(PlotMgt_PlotterDriver)& aDriver)
66{
67 myDriver = aDriver.operator->();
68 theTypeOfText = Aspect_TOT_OUTLINE;
69 theUnderlinePos = 0.;
70 theTextColor = 0;
71}
72
73//==========================================================
74Standard_Boolean PlotMgt_TextManager::SetCharBoundingBox (const Quantity_Length X1,
75 const Quantity_Length Y1,
76 const Quantity_Length X2,
77 const Quantity_Length Y2,
78 const Quantity_Length X3,
79 const Quantity_Length Y3,
80 const Quantity_Length X4,
81 const Quantity_Length Y4)
82{
83#ifdef TRACE
84 cout << " PlotMgt_TextManager::SetCharBoundingBox(" << X1 << "," << Y1
85 << "," << X2 << "," << Y2 << "," << X3 << "," << Y3 << "," << X4
86 << "," << Y4 << ")" << endl << flush;
87#endif
88 if (theUnderlinePos > 0.) {
89 if (!theNchar)
90 theXmin = Standard_ShortReal (X1);
91 theXmax = Sqrt(X2*X2 + Y2*Y2);
92 }
93 return Standard_True;
94}
95
96//==========================================================
97Standard_Boolean PlotMgt_TextManager::SetCharEncoding (const Standard_CString anEncoding)
98{
99#ifdef TRACE
100 cout << " PlotMgt_TextManager::SetCharEncoding('" << anEncoding << "')" << endl;
101#endif
102 return Standard_True;
103}
104
105//==========================================================
106void PlotMgt_TextManager::BeginString (const Quantity_Length X,
107 const Quantity_Length Y,
108 const Quantity_PlaneAngle anOrientation,
109 const Quantity_Length aWidth,
110 const Quantity_Length aHeight,
111 const Quantity_PlaneAngle aSlant,
112 const Standard_Integer aPaintType)
113{
114#ifdef TRACE
115 cout << " PlotMgt_TextManager::BeginString(" << X << "," << Y
116 << "," << anOrientation << "," << aWidth << "," << aHeight
117 << "," << aSlant << "," << aPaintType << ")" << endl;
118#endif
119 thePaintType = aPaintType;
120 theOrientation = (float) anOrientation;
121 // Force to OUTLINE if required
122 if (!thePaintType && (theTypeOfText == Aspect_TOT_OUTLINE))
123 thePaintType = 2;
124 theX = X; theY = Y;
125 theXmin = theXmax = 0.;
126 theNchar = 0;
127 theSlant = aSlant;
128 theWidth = aWidth;
129 theHeight = aHeight;
130 // Remember the old attributes and set new ones
131 myDriver -> LineAttrib (lci, lti, lwi);
132 myDriver -> PolyAttrib (pci, pti, pef);
133 myDriver -> SetLineAttrib (theTextColor, 0, 0);
134 myDriver -> SetPolyAttrib (theTextColor,
135 (theTypeOfText == Aspect_TOT_OUTLINE ? -1 : 0), Standard_False);
136 // Force plotting of graphic attributes at the begin of a string
137 myDriver -> PlotLineAttrib (theTextColor, 0, 0);
138 myDriver -> PlotPolyAttrib (theTextColor,
139 (theTypeOfText == Aspect_TOT_OUTLINE ? -1 : 0), Standard_False);
140}
141
142//==========================================================
143Standard_Boolean PlotMgt_TextManager::BeginChar (const Standard_Integer aCharCode,
144 const Quantity_Length X,
145 const Quantity_Length Y)
146{
147#ifdef TRACE
148 cout << " PlotMgt_TextManager::BeginChar(" << aCharCode << ","
149 << X << "," << Y << ")" << endl << flush;
150#endif
151 thePoint = 0;
152 thePathCount = 0;
153 theCPath[0] = 0;
154 thePX = X;
155 thePY = Y;
156 return Standard_True;
157}
158
159//==========================================================
160Standard_Boolean PlotMgt_TextManager::Moveto (const Quantity_Length X,
161 const Quantity_Length Y)
162{
163#ifdef TRACE
164 cout << " PlotMgt_TextManager::Moveto(" << X << "," << Y << ")" << endl << flush;
165#endif
166 if (theCPath[thePathCount] > 1)
167 thePathCount++;
168 else if (theCPath[thePathCount] > 0)
169 --thePoint;
170 theCPath[thePathCount] = 1;
171 thePX = X; thePY = Y;
172 ADD_POINT (theX, theY, X, Y);
173 return Standard_True;
174}
175
176//==========================================================
177Standard_Boolean PlotMgt_TextManager::Lineto (const Quantity_Length X,
178 const Quantity_Length Y)
179{
180#ifdef TRACE
181 cout << " PlotMgt_TextManager::Lineto(" << X << "," << Y << ")" << endl << flush;
182#endif
183 theCPath[thePathCount]++;
184 ADD_POINT (theX, theY, X, Y);
185 return Standard_True;
186}
187
188//==========================================================
189Standard_Boolean PlotMgt_TextManager::Curveto (const Quantity_Length X1,
190 const Quantity_Length Y1,
191 const Quantity_Length X2,
192 const Quantity_Length Y2,
193 const Quantity_Length X3,
194 const Quantity_Length Y3,
195 const Quantity_Length X4,
196 const Quantity_Length Y4)
197{
198#ifdef TRACE
199 cout << " PlotMgt_TextManager::Curveto(" << X1 << "," << Y1 << ","
200 << X2 << "," << Y2 << "," << X3 << "," << Y3 << "," << X4
201 << "," << Y4 << ")" << endl << flush;
202#endif
203 if (myDriver -> DrawCurveCapable()) {
204 if (theCPath[thePathCount] > 0)
205 thePathCount++;
206 theCPath[thePathCount] = -1;
207 ADD_POINT (theX, theY, X2, Y2);
208 ADD_POINT (theX, theY, X3, Y3);
209 ADD_POINT (theX, theY, X4, Y4);
210 thePathCount++;
211 theCPath[thePathCount] = 0;
212 return Standard_True;
213 }
214 return Standard_False;
215}
216
217//==========================================================
218void PlotMgt_TextManager::ClosePath ()
219{
220#ifdef TRACE
221 cout << " PlotMgt_TextManager::ClosePath()" << endl << flush;
222#endif
223 if (thePaintType == 2)
224 Lineto (thePX, thePY);
225 thePathCount++;
226 theCPath[thePathCount] = 0;
227}
228
229//==========================================================
230Standard_Boolean PlotMgt_TextManager::EndChar (const Quantity_Length X,
231 const Quantity_Length Y)
232{
233#ifdef TRACE
234 cout << "PlotMgt_TextManager::EndChar(" << X << "," << Y << ")\n"
235 << "Paths: " << thePathCount << ", PaintType: " << thePaintType << endl << flush;
236 for (int j = 0; j < thePathCount; j++)
237 cout << "Path[" << j << "] is: " << theCPath[j] << endl << flush;
238#endif
239 int N = 0, i;
240 theNchar++;
241 switch (thePaintType) {
242 /////////////////////////////////////////// Euclid3 font
243 case 1:
244 for (i = 0; i <= thePathCount; i++) {
245 myDriver -> PlotPolyline (&theXPath[N], &theYPath[N], &theCPath[i], 1);
246 N += theCPath [i];
247 }
248 break;
249 /////////////////////////////////////////// Outlined font
250 case 2:
251 myDriver -> PlotPolyline (theXPath, theYPath, theCPath, thePathCount);
252 break;
253 /////////////////////////////////////////// Solid font
254 default:
255 myDriver -> PlotPolygon (theXPath, theYPath, theCPath, thePathCount);
256 break;
257 }
258 thePathCount = 0;
259 memset (theCPath, 0, sizeof(theCPath));
260 return Standard_True;
261}
262
263//==========================================================
264void PlotMgt_TextManager::EndString ()
265{
266#ifdef TRACE
267 cout << " PlotMgt_TextManager::EndString()" << endl << flush;
268#endif
269 if (theUnderlinePos > 0.) {
270 Standard_ShortReal theX1 = theXmin;
271 Standard_ShortReal theY1 = (float)-theUnderlinePos;
272 Standard_ShortReal theX2 = theXmax;
273 Standard_ShortReal theY2 = theY1;
274 theSinAngle = (float)Sin(theOrientation);
275 theCosAngle = (float)Cos(theOrientation);
276 TRANSFORM(theX1, theY1);
277 TRANSFORM(theX2, theY2);
278 myDriver -> PlotSegment (
279 myDriver->MapX(theX+theX1), myDriver->MapY(theY+theY1),
280 myDriver->MapX(theX+theX2), myDriver->MapY(theY+theY2)
281 );
282 }
283 // Restore old attributes
284 myDriver -> SetLineAttrib (lci, lti, lwi);
285 myDriver -> SetPolyAttrib (pci, pti, pef);
286}
287
288//==========================================================
289void PlotMgt_TextManager::SetTextAttribs (const Standard_Integer aTextColor,
290 const Aspect_TypeOfText aTypeOfText,
291 const Quantity_Length anUnderlinePosition)
292{
293 theTextColor = aTextColor;
294 theTypeOfText = aTypeOfText;
295 theUnderlinePos = anUnderlinePosition;
296}