0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / Xw / Xw_TextManager.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#define S3593 //GG_130398
19// OPTIMISATION MFT
7fd59977 20#define PRO14351//GG_180698
21// OPTIMISATION MFT
7fd59977 22
23#include <Xw_TextManager.ixx>
24#include <Aspect_Units.hxx>
25#define TRACE 0
26
27#define MAXCHARPOINTS 512
28#define MAXCHARPATHS 8
29#define TRANSFORM(X,Y) \
b311480e 30{ Standard_Real x = X,y = Y; \
7fd59977 31 X = x*theCosAngle - y*theSinAngle; \
32 Y = x*theSinAngle + y*theCosAngle; \
33 }
34
35// Routines C a declarer en extern
36//extern "C" {
37#include <Xw_Cextern.hxx>
38//}
39
40static XW_ATTRIB thePolyCode,theLineCode;
41static Standard_Integer thePaintType,theNchar,theNpoly,theNpath;
42static Standard_Integer theTextColor,theLineColor,theLineType,theLineWidth;
43static Standard_Integer thePolyColor,thePolyType,thePolyTile;
44static XW_DRAWMODE theLineMode,thePolyMode;
45static Aspect_TypeOfText theTypeOfText;
46static Standard_ShortReal theUnderlinePosition;
47static Standard_ShortReal theX,theY,thePX,thePY;
48static Standard_ShortReal theXmin,theXmax,theSinAngle,theCosAngle;
49static Standard_ShortReal theSlant,theWidth,theHeight;
50static Standard_Real theOrientation;
51static Standard_Boolean theClippingFlag;
52
53Xw_TextManager::Xw_TextManager(const Standard_Address aDrawable, const Standard_Address aWidthMap) : myDrawable(aDrawable),myWidthMap(aWidthMap) {
54}
55
56void Xw_TextManager::BeginString( const Quantity_Length X, const Quantity_Length Y, const Quantity_PlaneAngle anOrientation, const Quantity_Length aWidth, const Quantity_Length aHeight, const Quantity_PlaneAngle aSlant, const Standard_Integer aPaintType) {
57#if TRACE > 0
58 cout << " Xw_TextManager::BeginString(" <<
59 X << "," << Y << "," << anOrientation << ","
60 << aWidth << "," << aHeight << "," aSlant << ","
61 << aPaintType << ")" << endl;
62#endif
63
64 thePaintType = aPaintType;
65 theOrientation = anOrientation;
66 theX = X; theY = Y;
67 theXmin = theXmax = 0.;
68 theNchar = 0;
69 theSlant = aSlant;
70 theWidth = aWidth;
71 theHeight = aHeight;
72 theNpoly = theNpath = 0;
73
74#ifdef S3593
75 // Set clipping off
76 theClippingFlag = Xw_get_clipping(myDrawable);
77 Xw_set_clipping(myDrawable,Standard_False);
78#endif
79 // Save line attribs
80 thePolyCode = Xw_get_poly_attrib(myDrawable,
81 &thePolyColor,&thePolyType,&thePolyTile,&thePolyMode);
82 theLineCode = Xw_get_line_attrib(myDrawable,
83 &theLineColor,&theLineType,&theLineWidth,&theLineMode);
84
85 Standard_ShortReal thickness = theHeight/32.;
86 Standard_Integer windex;
87 Xw_get_width_index(myWidthMap,thickness,&windex) ;
88 // Force to OUTLINE if required
89 if( !thePaintType ) {
90 if( (theHeight < (4. MILLIMETER)) ||
91 (theTypeOfText == Aspect_TOT_OUTLINE) ) thePaintType = 2;
92 }
93 // Sets the MFT text attribs
94 switch (thePaintType) {
95 case 0:
96 Xw_set_poly_attrib(myDrawable,
97 theTextColor,Standard_False,0,XW_REPLACE);
98 Xw_set_line_attrib(myDrawable,
99 theTextColor,0,windex,XW_REPLACE);
100 break;
101 case 2:
102 Xw_set_poly_attrib(myDrawable,
103 theTextColor,Standard_True,-1,XW_REPLACE);
104 Xw_set_line_attrib(myDrawable,
105 theTextColor,0,windex,XW_REPLACE);
106 break;
107 case 1:
108 Xw_set_line_attrib(myDrawable,
109 theTextColor,0,windex,XW_REPLACE);
110#ifndef PRO14351
111 Xw_begin_segments(myDrawable, 0);
112#endif
113 break;
114 }
115
116}
117
118Standard_Boolean Xw_TextManager::BeginChar(const Standard_Integer aCharCode, const Standard_Real X, const Standard_Real Y) {
119#if TRACE > 0
120 cout << " Xw_TextManager::BeginChar(" << aCharCode << "," <<
121 X << "," << Y << ")" << endl;
122#endif
123
124 thePX = X; thePY = Y;
125#ifndef PRO14351
126 if( thePaintType != 1 )
127#endif
128 theNpoly = theNpath = 0;
129 return Standard_True;
130}
131
132Standard_Boolean Xw_TextManager::SetCharBoundingBox(const Quantity_Length X1, const Quantity_Length Y1, const Quantity_Length X2, const Quantity_Length Y2, const Quantity_Length X3, const Quantity_Length Y3, const Quantity_Length X4, const Quantity_Length Y4) {
133
134#if TRACE > 0
135 cout << " Xw_TextManager::SetCharBoundingBox(" << X1 << "," << Y1 << "," <<
136 X2 << "," << Y2 << "," << X3 << "," << Y3 << "," <<
137 X4 << "," << Y4 << ")" << endl;
138#endif
139
140 if( theUnderlinePosition > 0. ) {
141 if( !theNchar ) {
142 theXmin = Standard_ShortReal (X1);
143 }
144 theXmax = Sqrt(X2*X2 + Y2*Y2);
145 }
146 return Standard_True;
147}
148
149Standard_Boolean Xw_TextManager::SetCharEncoding(const Standard_CString anEncoding) {
150
151#if TRACE > 0
152 cout << " Xw_TextManager::SetCharEncoding('" << anEncoding << "')" << endl;
153#endif
154
155 return Standard_True;
156}
157
158Standard_Boolean Xw_TextManager::Moveto(const Standard_Real X, const Standard_Real Y) {
159#if TRACE > 1
160 cout << " Xw_TextManager::Moveto(" << X << "," << Y << ")" << endl;
161#endif
162
163#ifndef PRO14351
164 if( thePaintType != 1 )
165#endif
166 this->ClosePath();
167 thePX = X; thePY = Y;
168
169 return Standard_True;
170}
171
172Standard_Boolean Xw_TextManager::Lineto(const Standard_Real X, const Standard_Real Y) {
173#if TRACE > 1
174 cout << " Xw_TextManager::Lineto(" << X << "," << Y << ")" << endl;
175#endif
176 switch (thePaintType) {
177 case 0:
178 case 2:
179 if( theNpoly == 0 ) {
180 Xw_begin_poly(myDrawable,MAXCHARPOINTS,MAXCHARPATHS);
181 }
182 if( theNpath == 0 ) {
183 Xw_poly_point(myDrawable, theX+thePX, theY+thePY);
184 }
185 Xw_poly_point(myDrawable, theX+Standard_ShortReal(X),
186 theY+Standard_ShortReal(Y));
187 theNpath++; theNpoly++;
188 break;
189 case 1:
190#ifndef PRO14351
191 Xw_draw_segment(myDrawable, theX+thePX, theY+thePY,
192 theX+Standard_ShortReal(X),
193 theY+Standard_ShortReal(Y));
194#else
195 if( theNpoly == 0 ) {
196 Xw_begin_line(myDrawable,MAXCHARPOINTS);
197 Xw_line_point(myDrawable, theX+thePX, theY+thePY);
198 }
199 Xw_line_point(myDrawable, theX+Standard_ShortReal(X),
200 theY+Standard_ShortReal(Y));
201#endif
202 thePX = X; thePY = Y;
203 theNpoly++;
204 }
205
206 return Standard_True;
207}
208
209Standard_Boolean Xw_TextManager::Curveto(const Quantity_Length X1, const Quantity_Length Y1, const Quantity_Length X2, const Quantity_Length Y2, const Quantity_Length X3, const Quantity_Length Y3, const Quantity_Length X4, const Quantity_Length Y4) {
210
211#if TRACE > 0
212 cout << " Xw_TextManager::Curveto(" << X1 << "," << Y1 << "," <<
213 X2 << "," << Y2 << "," << X3 << "," << Y3 << "," <<
214 X4 << "," << Y4 << ")" << endl;
215#endif
216
217 return Standard_False;
218}
219
220void Xw_TextManager::ClosePath() {
221#if TRACE > 0
222 cout << " Xw_TextManager::ClosePath()" << endl;
223#endif
224 switch (thePaintType) {
225 case 0:
226 case 2:
227 if( theNpath > 0 ) Xw_close_path(myDrawable);
228 theNpath = 0;
229 break;
230 case 1:
231#ifdef PRO14351
232 if( theNpoly > 0 ) Xw_close_line(myDrawable);
233 theNpoly = 0;
234#endif
235 break;
236 }
237}
238
239Standard_Boolean Xw_TextManager::EndChar(const Standard_Real X, const Standard_Real Y) {
240#if TRACE > 0
241 cout << " Xw_TextManager::EndChar(" << X << "," << Y << ")" << endl;
242#endif
243 switch (thePaintType) {
244 case 0:
245 case 2:
246 Xw_close_poly(myDrawable);
247 break;
248 case 1:
249#ifdef PRO14351
250 Xw_close_line(myDrawable);
251 theNpoly = theNpath = 0;
252#endif
253 break;
254 }
255 theNchar++;
256
257 return Standard_True;
258}
259
260void Xw_TextManager::EndString() {
261#if TRACE > 0
262 cout << " Xw_TextManager::EndString()" << endl;
263#endif
264
265 if( theUnderlinePosition > 0. ) {
266 Standard_ShortReal theX1 = theXmin;
267 Standard_ShortReal theY1 = -theUnderlinePosition;
268 Standard_ShortReal theX2 = theXmax;
269 Standard_ShortReal theY2 = theY1;
270 theSinAngle = Sin(theOrientation);
271 theCosAngle = Cos(theOrientation);
272 TRANSFORM(theX1,theY1);
273 TRANSFORM(theX2,theY2);
274#ifndef PRO14351
275 Xw_draw_segment(myDrawable, theX+theX1, theY+theY1,
276 theX+theX2, theY+theY2);
277#else
278 Xw_begin_line(myDrawable,2);
279 Xw_line_point(myDrawable, theX+theX1, theY+theY1);
280 Xw_line_point(myDrawable, theX+theX2, theY+theY2);
281 Xw_close_line(myDrawable);
282#endif
283 }
284 // Restore line attribs
285 switch (thePaintType) {
286 case 0:
287 case 2:
288 if( thePolyCode != ~0 ) Xw_set_poly_attrib(myDrawable,
289 thePolyColor,thePolyType,thePolyTile,thePolyMode);
290 case 1:
291#ifndef PRO14351
292 Xw_close_segments(myDrawable);
293 theNpoly = 0;
294#endif
295 if( theLineCode != ~0 ) Xw_set_line_attrib(myDrawable,
296 theLineColor,theLineType,theLineWidth,theLineMode);
297 break;
298 }
299#ifdef S3593
300 // Restore clipping
301 Xw_set_clipping(myDrawable,theClippingFlag);
302#endif
303}
304
305void Xw_TextManager::SetTextAttribs( const Standard_Integer aTextColor, const Aspect_TypeOfText aTypeOfText, const Quantity_Length anUnderlinePosition) {
306
307 theTextColor = aTextColor;
308 theTypeOfText = aTypeOfText;
309 theUnderlinePosition = anUnderlinePosition;
310}