1 // File: WNT_TextManager.cxx
3 // Author: CHABROVSKY Dmitry
4 // Copyright: Matra Datavision 1998
6 // include windows.h first to have all definitions available
11 #include <WNT_TextManager.ixx>
12 #include <WNT_MFTDraw.hxx>
13 #include <Aspect_Units.hxx>
15 #define CHAR_DESC_LEN 30000
16 #define MY_HDC (HDC)myDevContext
17 #define U2P(v) LONG( (v)/myPixelToUnit + 0.5 )
18 #define TRANSFORM(X,Y) \
19 { Standard_Real x = X,y = Y; \
20 X = Standard_ShortReal(x*theCosAngle - y*theSinAngle); \
21 Y = Standard_ShortReal(x*theSinAngle + y*theCosAngle); \
25 TOP_MOVETO, TOP_LINETO, TOP_CURVETO
28 static Standard_Integer thePaintType;
29 static Standard_Integer theTextColor;
30 static Aspect_TypeOfText theTypeOfText;
31 static Standard_ShortReal theUnderlinePosition;
32 static Standard_ShortReal theXmin,theXmax;
33 static Standard_Integer theNchar;
34 static Standard_Real theSinAngle,theCosAngle;
35 static Standard_Real theOrientation;
36 //////////////// Character description ///////////////
37 static int myStrLen = 0;
38 static POINT myStrDesc [CHAR_DESC_LEN];
39 static TypeOfPoint myStrInfo [CHAR_DESC_LEN];
40 static double myBX, myBY;
41 static double myCX, myCY;
42 static int myCharWidth;
43 static int myCharHeight;
44 static BOOL myCharInside;
46 #define ADD_POINT(X,Y,aType) \
47 myStrDesc[myStrLen].x = U2P( (X)+myBX ); \
48 myStrDesc[myStrLen].y = ( myWin95 ? myDevHeight - U2P((Y)+myBY) : U2P((Y)+myBY) ); \
49 myStrInfo[myStrLen] = aType; myStrLen++;
51 #define CHECK_INSIDE(x,y) \
54 if ((x > -myCharWidth && x < (myDevWidth /*+ myCharWidth*/ )) && \
55 (y > -myCharHeight && y < (myDevHeight + myCharHeight))) \
56 myCharInside = TRUE; \
58 if ((x > -myCharWidth && x < (myDevWidth /*+ myCharWidth */)) && \
59 (y > -myCharHeight && y < (myDevHeight /*+ myCharHeight*/))) \
60 myCharInside = TRUE; \
63 #define CUR_X() myStrDesc[myStrLen-1].x
64 #define CUR_Y() myStrDesc[myStrLen-1].y
66 /*==================================================================*/
67 WNT_TextManager::WNT_TextManager(const Standard_Real aPixelToUnit)
69 myPixelToUnit = aPixelToUnit;
72 // Clear the memory for STRING description
73 ZeroMemory (myStrDesc, sizeof(myStrDesc));
74 ZeroMemory (myStrInfo, sizeof(myStrInfo));
78 /*==================================================================*/
79 void WNT_TextManager::BeginString(const Quantity_Length X,
80 const Quantity_Length Y,
81 const Quantity_PlaneAngle anOrientation,
82 const Quantity_Length aWidth,
83 const Quantity_Length aHeight,
84 const Quantity_PlaneAngle aSlant,
85 const Standard_Integer aPaintType)
88 myCharWidth = U2P(aWidth );
89 myCharHeight = U2P(aHeight);
91 thePaintType = aPaintType;
92 theOrientation = anOrientation;
96 theXmin = theXmax = 0.F;
98 if ((aHeight < (6. MILLIMETER)) ||
99 (theTypeOfText == Aspect_TOT_OUTLINE))
104 /*==================================================================*/
105 Standard_Boolean WNT_TextManager::BeginChar(const Standard_Integer aCharCode,
106 const Standard_Real X,
107 const Standard_Real Y)
109 myCharInside = FALSE;
110 return Standard_True;
113 /*==================================================================*/
114 Standard_Boolean WNT_TextManager::SetCharBoundingBox(const Quantity_Length X1,
115 const Quantity_Length Y1,
116 const Quantity_Length X2,
117 const Quantity_Length Y2,
118 const Quantity_Length X3,
119 const Quantity_Length Y3,
120 const Quantity_Length X4,
121 const Quantity_Length Y4)
123 if (theUnderlinePosition > 0.) {
125 theXmin = Standard_ShortReal (X1);
126 theXmax = Standard_ShortReal (Sqrt(X2*X2 + Y2*Y2));
128 return Standard_True;
131 /*==================================================================*/
132 Standard_Boolean WNT_TextManager::SetCharEncoding(const Standard_CString anEncoding)
134 return Standard_True;
137 /*==================================================================*/
138 Standard_Boolean WNT_TextManager::Moveto(const Standard_Real X,
139 const Standard_Real Y)
141 ADD_POINT (X,Y,TOP_MOVETO);
143 CHECK_INSIDE (CUR_X(),CUR_Y());
149 /*==================================================================*/
150 Standard_Boolean WNT_TextManager::Lineto(const Standard_Real X,
151 const Standard_Real Y)
153 ADD_POINT (X,Y,TOP_LINETO);
154 CHECK_INSIDE (CUR_X(),CUR_Y());
160 /*==================================================================*/
161 Standard_Boolean WNT_TextManager::Curveto(const Quantity_Length X1,
162 const Quantity_Length Y1,
163 const Quantity_Length X2,
164 const Quantity_Length Y2,
165 const Quantity_Length X3,
166 const Quantity_Length Y3,
167 const Quantity_Length X4,
168 const Quantity_Length Y4)
170 ADD_POINT (X2,Y2,TOP_CURVETO);
171 ADD_POINT (X3,Y3,TOP_CURVETO);
172 ADD_POINT (X4,Y4,TOP_CURVETO);
173 return Standard_True;
176 /*==================================================================*/
177 void WNT_TextManager::ClosePath()
179 ADD_POINT (myCX,myCY,TOP_LINETO);
180 CHECK_INSIDE (CUR_X(),CUR_Y());
185 /*==================================================================*/
186 Standard_Boolean WNT_TextManager::EndChar(const Standard_Real X,
187 const Standard_Real Y)
190 return Standard_True;
193 /*==================================================================*/
194 void WNT_TextManager::EndString()
202 switch (myStrInfo[i]) {
204 MoveToEx (MY_HDC, myStrDesc[i].x, myStrDesc[i].y, NULL);
208 while ((myStrInfo[j] == TOP_LINETO) && (j < myStrLen))
210 PolylineTo (MY_HDC, &myStrDesc[i], j-i);
214 PolyBezierTo (MY_HDC, &myStrDesc[i], 3);
220 } while (++i < myStrLen);
222 if (thePaintType == 0 && !myMonoBuf) FillPath (MY_HDC);
223 else StrokePath (MY_HDC);
225 // Draw underline if necessary
226 if (theUnderlinePosition > 0.) {
227 Standard_ShortReal theX1 = theXmin;
228 Standard_ShortReal theY1 = -theUnderlinePosition;
229 Standard_ShortReal theX2 = theXmax;
230 Standard_ShortReal theY2 = theY1;
231 theSinAngle = Sin (theOrientation);
232 theCosAngle = Cos (theOrientation);
233 TRANSFORM (theX1, theY1);
234 TRANSFORM (theX2, theY2);
237 MoveToEx (MY_HDC, U2P(theX1 + myBX), myDevHeight - U2P(theY1 + myBY), NULL);
238 LineTo (MY_HDC, U2P(theX2 + myBX), myDevHeight - U2P(theY2 + myBY) );
240 MoveToEx (MY_HDC, U2P(theX1 + myBX), U2P(theY1 + myBY), NULL);
241 LineTo (MY_HDC, U2P(theX2 + myBX), U2P(theY2 + myBY) );
246 /*==================================================================*/
247 void WNT_TextManager::SetTextAttribs(const Standard_Integer aTextColor,
248 const Aspect_TypeOfText aTypeOfText,
249 const Quantity_Length anUnderlinePosition)
251 theTextColor = aTextColor;
252 theTypeOfText = aTypeOfText;
253 theUnderlinePosition = (Standard_ShortReal)anUnderlinePosition;
256 /*==================================================================*/
257 void WNT_TextManager::SetDrawAttribs(const Standard_Address aDrawData)
259 PMFT_TEXTMAN_DATA aData = (PMFT_TEXTMAN_DATA)aDrawData;
260 myDevContext = (int)aData->theHDC;
261 myWin95 = aData->theWin95;
262 myDevWidth = aData->theDevWidth;
263 myDevHeight = aData->theDevHeight;
264 myUWidth = aData->theUWidth;
265 myMonoBuf = aData->theMonoBuffer;