2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <PlotMgt_TextManager.ixx>
22 #include <Aspect_Units.hxx>
25 #pragma warning (disable : 4244)
29 #define MAXPATHPOINTS 800
30 #define MAXCHARPATHS 20
31 #define MAXCHARPOINTS MAXPATHPOINTS*MAXCHARPATHS
33 #define CONVERT(v) (v)*72./(0.0254005 METER)
35 #define TRANSFORM(X,Y) \
36 { Standard_Real x = (X), y = (Y); \
37 X = x*theCosAngle - y*theSinAngle; \
38 Y = x*theSinAngle + y*theCosAngle; \
41 #define ADD_POINT(X,Y,aX,aY) \
42 { theXPath[thePoint] = myDriver->MapX((X)+(aX)); \
43 theYPath[thePoint] = myDriver->MapY((Y)+(aY)); \
47 //static Standard_Integer thePaintType, theNchar, theNpoly, theNpath;
48 static Standard_Integer thePaintType, theNchar;
49 static Standard_ShortReal theX, theY, thePX, thePY;
50 static Standard_ShortReal theXmin, theXmax, theSinAngle, theCosAngle;
51 static Standard_Real theOrientation, theSlant, theWidth, theHeight;
52 static Standard_Integer theTextColor;
53 static Standard_Integer theTypeOfText;
54 static Quantity_Length theUnderlinePos;
55 static Standard_ShortReal theXPath [MAXCHARPOINTS];
56 static Standard_ShortReal theYPath [MAXCHARPOINTS];
57 static Standard_Integer theCPath [MAXCHARPATHS ];
58 static Standard_Integer thePoint = 0;
59 static Standard_Integer thePathCount = 0;
60 // Driver's graphic attributes
61 static Standard_Integer lci, lti, lwi, pci, pti;
62 static Standard_Boolean pef;
64 //==========================================================
65 PlotMgt_TextManager::PlotMgt_TextManager (const Handle(PlotMgt_PlotterDriver)& aDriver)
67 myDriver = aDriver.operator->();
68 theTypeOfText = Aspect_TOT_OUTLINE;
73 //==========================================================
74 Standard_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)
84 cout << " PlotMgt_TextManager::SetCharBoundingBox(" << X1 << "," << Y1
85 << "," << X2 << "," << Y2 << "," << X3 << "," << Y3 << "," << X4
86 << "," << Y4 << ")" << endl << flush;
88 if (theUnderlinePos > 0.) {
90 theXmin = Standard_ShortReal (X1);
91 theXmax = Sqrt(X2*X2 + Y2*Y2);
96 //==========================================================
97 Standard_Boolean PlotMgt_TextManager::SetCharEncoding (const Standard_CString anEncoding)
100 cout << " PlotMgt_TextManager::SetCharEncoding('" << anEncoding << "')" << endl;
102 return Standard_True;
105 //==========================================================
106 void 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)
115 cout << " PlotMgt_TextManager::BeginString(" << X << "," << Y
116 << "," << anOrientation << "," << aWidth << "," << aHeight
117 << "," << aSlant << "," << aPaintType << ")" << endl;
119 thePaintType = aPaintType;
120 theOrientation = (float) anOrientation;
121 // Force to OUTLINE if required
122 if (!thePaintType && (theTypeOfText == Aspect_TOT_OUTLINE))
125 theXmin = theXmax = 0.;
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);
142 //==========================================================
143 Standard_Boolean PlotMgt_TextManager::BeginChar (const Standard_Integer aCharCode,
144 const Quantity_Length X,
145 const Quantity_Length Y)
148 cout << " PlotMgt_TextManager::BeginChar(" << aCharCode << ","
149 << X << "," << Y << ")" << endl << flush;
156 return Standard_True;
159 //==========================================================
160 Standard_Boolean PlotMgt_TextManager::Moveto (const Quantity_Length X,
161 const Quantity_Length Y)
164 cout << " PlotMgt_TextManager::Moveto(" << X << "," << Y << ")" << endl << flush;
166 if (theCPath[thePathCount] > 1)
168 else if (theCPath[thePathCount] > 0)
170 theCPath[thePathCount] = 1;
171 thePX = X; thePY = Y;
172 ADD_POINT (theX, theY, X, Y);
173 return Standard_True;
176 //==========================================================
177 Standard_Boolean PlotMgt_TextManager::Lineto (const Quantity_Length X,
178 const Quantity_Length Y)
181 cout << " PlotMgt_TextManager::Lineto(" << X << "," << Y << ")" << endl << flush;
183 theCPath[thePathCount]++;
184 ADD_POINT (theX, theY, X, Y);
185 return Standard_True;
188 //==========================================================
189 Standard_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)
199 cout << " PlotMgt_TextManager::Curveto(" << X1 << "," << Y1 << ","
200 << X2 << "," << Y2 << "," << X3 << "," << Y3 << "," << X4
201 << "," << Y4 << ")" << endl << flush;
203 if (myDriver -> DrawCurveCapable()) {
204 if (theCPath[thePathCount] > 0)
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);
211 theCPath[thePathCount] = 0;
212 return Standard_True;
214 return Standard_False;
217 //==========================================================
218 void PlotMgt_TextManager::ClosePath ()
221 cout << " PlotMgt_TextManager::ClosePath()" << endl << flush;
223 if (thePaintType == 2)
224 Lineto (thePX, thePY);
226 theCPath[thePathCount] = 0;
229 //==========================================================
230 Standard_Boolean PlotMgt_TextManager::EndChar (const Quantity_Length X,
231 const Quantity_Length Y)
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;
241 switch (thePaintType) {
242 /////////////////////////////////////////// Euclid3 font
244 for (i = 0; i <= thePathCount; i++) {
245 myDriver -> PlotPolyline (&theXPath[N], &theYPath[N], &theCPath[i], 1);
249 /////////////////////////////////////////// Outlined font
251 myDriver -> PlotPolyline (theXPath, theYPath, theCPath, thePathCount);
253 /////////////////////////////////////////// Solid font
255 myDriver -> PlotPolygon (theXPath, theYPath, theCPath, thePathCount);
259 memset (theCPath, 0, sizeof(theCPath));
260 return Standard_True;
263 //==========================================================
264 void PlotMgt_TextManager::EndString ()
267 cout << " PlotMgt_TextManager::EndString()" << endl << flush;
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)
283 // Restore old attributes
284 myDriver -> SetLineAttrib (lci, lti, lwi);
285 myDriver -> SetPolyAttrib (pci, pti, pef);
288 //==========================================================
289 void PlotMgt_TextManager::SetTextAttribs (const Standard_Integer aTextColor,
290 const Aspect_TypeOfText aTypeOfText,
291 const Quantity_Length anUnderlinePosition)
293 theTextColor = aTextColor;
294 theTypeOfText = aTypeOfText;
295 theUnderlinePos = anUnderlinePosition;