1 // Created by: CHABROVSKY Dmitry
2 // Copyright (c) 1998-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 #define MFT // Study S3553
28 #include "WNT_MFTDraw.hxx"
29 #include "W32_Allocator.hxx"
30 #include "W95_Allocator.hxx"
31 #include "WNT_Allocator.hxx"
32 #include <WNT_WDriver.hxx>
33 #include <WNT_DDriver.hxx>
34 #include <WNT_TextManager.hxx>
40 #include <MFT_FontManager.hxx>
41 #include <TCollection_ExtendedString.hxx>
43 #define ROUNDL( d ) ( ( long )( ( d ) + ( ( d ) > 0 ? 0.5 : -0.5 ) ) )
44 #define TRANSFORM(i,X,Y,f95) \
46 Standard_Real x = (X),y = (Y); \
47 pts[(i)].x = P( ROUNDL((double)myPT.x + x*Ca - y*Sa) );\
48 if (f95) pts[(i)].y = sz.cy - P( ROUNDL((double)myPT.y + x*Sa + y*Ca) );\
49 else pts[(i)].y = P( ROUNDL((double)myPT.y + x*Sa + y*Ca) );\
51 #define SET_DRAW_DATA(aData,aDC,aSZ) \
52 { aData.theHDC = aDC; \
53 aData.theDevWidth = aSZ.cx; \
54 aData.theDevHeight = aSZ.cy; }
56 void __cdecl _Do_MFTDrawText_ (PW32_FCALLPARAM lpParam)
58 // Declare all needed variables
59 PMFT_DRAWTEXT lpDraw = (PMFT_DRAWTEXT) lpParam;
60 PW32_Allocator lpW32 = (PW32_Allocator) lpDraw->theParam.pAllocator;
61 WNT_WDriver* lpWDrv = (WNT_WDriver*) lpDraw->theParam.pDriver;
62 WNT_DDriver* lpDDrv = (WNT_DDriver*) lpDraw->theParam.pDriver;
63 int aFont = (int)lpW32->myTextFont;
64 double myPixelToUnit = lpDraw->theP2U;
67 HPEN hTextPen, hOldPen, hPolyPen;
68 HBRUSH hTextBrush, hOldBrush, hPolyBrush;
69 float Ca = (float)Cos(lpW32->myAngle),
70 Sa = (float)Sin(lpW32->myAngle);
72 // Starting point to draw
76 Ca*lpW32->myScaleX * (lpDraw->theXPos - float( U(lpW32->myPivot.x)) ) -
77 Sa*lpW32->myScaleY * (lpDraw->theYPos - float( U(lpW32->myPivot.y)) ) +
78 float( U( (lpW32->myPivot.x + lpW32->myMove.x) ) )
83 Sa*lpW32->myScaleX * (lpDraw->theXPos - float( U(lpW32->myPivot.x)) ) +
84 Ca*lpW32->myScaleY * (lpDraw->theYPos - float( U(lpW32->myPivot.y)) ) +
85 float( U( (lpW32->myPivot.y + lpW32->myMove.y) ) )
90 Handle(WNT_TextManager) theTextManager;
91 Handle(MFT_FontManager) theFontManager;
92 Standard_ShortReal theTextSize;
93 //============ Use driver to get some data ============
94 if (lpW32->myFlags & W32F_DVDRV) {
95 // theTextManager = lpDDrv->TextManager ();
96 // theFontManager = lpDDrv->MFT_Font (aFont);
97 // theTextSize = lpDDrv->MFT_Size (aFont);
99 theTextManager = lpWDrv->TextManager ();
100 theFontManager = lpWDrv->MFT_Font (aFont);
101 theTextSize = lpWDrv->MFT_Size (aFont);
103 //============== Set FontManager and TextManager attributes =============
104 theFontManager->SetFontAttribs (
105 Abs(theTextSize)*lpW32->myTextHScale*lpW32->myScaleX,
106 Abs(theTextSize)*lpW32->myTextVScale*lpW32->myScaleY,
107 lpW32->myTextSlant, 0.,
108 ((theTextSize > 0.) ? Standard_False : Standard_True)
110 uPos = (lpW32->myFlags & W32F_TULIN ?
111 theFontManager->UnderlinePosition() : 0.);
112 theTextManager->SetTextAttribs (
113 0, Aspect_TypeOfText(lpDraw->theTextType), uPos
115 //=============== Calculate UpdateRect ================
116 Ca = (float)Cos(lpDraw->theAngle + lpW32->myAngle);
117 Sa = (float)Sin(lpDraw->theAngle + lpW32->myAngle);
118 Standard_ShortReal theHeight, theWidth, theXoffset, theYoffset;
119 if (lpW32->myFlags & W32F_DVDRV) {
120 if (!lpDraw->isTextWide)
121 lpDDrv->TextSize ((char*)lpDraw->theText, theWidth, theHeight, theXoffset,
124 lpDDrv->TextSize ((short*)lpDraw->theText, theWidth, theHeight, theXoffset,
127 if (!lpDraw->isTextWide)
128 lpWDrv->TextSize ((char*)lpDraw->theText, theWidth, theHeight, theXoffset,
131 lpWDrv->TextSize ((short*)lpDraw->theText, theWidth, theHeight, theXoffset,
134 //================= Get some attributes ===============
135 int uWidth = P(theHeight/32.);
136 MFT_TEXTMAN_DATA aData = { 0, TRUE, 0, 0, uWidth, lpW32->myFlags & W32F_MONO };
137 if (lpW32->myFlags & W32F_WIN95) {
138 // Get necessary attributes from WIN95 Allocator
139 PW95_Allocator lpW95 = (PW95_Allocator)lpW32;
140 lpW95->myHDC.Extent(&sz);
141 MY_HDC = lpW95->myHDC.Hdc ();
142 SET_DRAW_DATA (aData, MY_HDC, sz);
143 theTextManager->SetDrawAttribs ( (Standard_Address)&aData );
144 hTextPen = CreatePen ( PS_SOLID, 1, lpW95->myTextColor );
145 hTextBrush = CreateSolidBrush ( lpW95->myTextColor );
146 hPolyPen = ((lpW32->myFlags & W32F_POUTL) ?
147 CreatePen (PS_SOLID, lpW95->myLinePenWidth,
148 lpW95->myLineBrush.lbColor):
149 (HPEN) GetStockObject (NULL_PEN));
150 hPolyBrush = ((lpW32->myFlags & W32F_NOFIL) ?
151 (HBRUSH) GetStockObject (NULL_BRUSH):
152 CreateBrushIndirect (&lpW95->myPolyBrush));
154 // Get necessary attributes from WINNT Allocator
155 PWNT_Allocator lpWNT = (PWNT_Allocator)lpW32;
156 lpWNT->GetExtent(&sz);
157 MY_HDC = lpWNT->myHDC;
158 aData.theWin95 = FALSE;
159 SET_DRAW_DATA (aData, MY_HDC, sz);
160 theTextManager->SetDrawAttribs ( (Standard_Address)&aData );
161 GetWorldTransform ( MY_HDC, &xf );
162 ModifyWorldTransform ( MY_HDC, NULL, MWT_IDENTITY );
163 hTextPen = lpWNT->myTextPen;
164 hTextBrush = lpWNT->myTextBrush;
165 hPolyPen = ((lpW32->myFlags & W32F_POUTL) ?
167 (HPEN) GetStockObject (NULL_PEN) );
168 hPolyBrush = ((lpW32->myFlags & W32F_NOFIL) ?
169 (HBRUSH) GetStockObject (NULL_BRUSH):
172 ////////////////////////////////////////////////////////
173 Standard_ShortReal marge =
174 Standard_ShortReal(theHeight * lpDraw->theMargin);
175 theWidth += 2.F*marge; theHeight += 2.F*marge;
176 theXoffset -= marge; theYoffset += marge;
177 ////////////////////////////////////////////////////////
178 BOOL fWin95 = lpW32->myFlags & W32F_WIN95;
180 TRANSFORM (0, theXoffset, - theYoffset, fWin95);
181 TRANSFORM (1, theXoffset + theWidth, - theYoffset, fWin95);
182 TRANSFORM (2, theXoffset + theWidth, theHeight - theYoffset, fWin95);
183 TRANSFORM (3, theXoffset, theHeight - theYoffset, fWin95);
184 //============ Draw POLYGON around the text ===========
185 if (lpDraw->isTextPoly) {
186 hOldPen = SelectPen (MY_HDC, hPolyPen );
187 hOldBrush = SelectBrush (MY_HDC, hPolyBrush);
188 Polygon (MY_HDC, pts, 4);
189 SelectBrush (MY_HDC, hOldBrush);
190 SelectPen (MY_HDC, hOldPen );
192 //================= Draw text itself ==================
193 hOldPen = SelectPen (MY_HDC, hTextPen);
194 hOldBrush = SelectBrush (MY_HDC, hTextBrush);
195 if (lpDraw->isTextWide) {
196 theFontManager->DrawText (
197 theTextManager, (short*)lpDraw->theText,
198 myPT.x, myPT.y, (lpDraw->theAngle + lpW32->myAngle)
201 theFontManager->DrawText (
202 theTextManager, (char*)lpDraw->theText,
203 myPT.x, myPT.y, (lpDraw->theAngle + lpW32->myAngle)
206 SelectBrush (MY_HDC, hOldBrush);
207 SelectPen (MY_HDC, hOldPen );
208 //========= Register points as an UpdatedRect =========
209 if (lpW32->myFlags & W32F_WIN95) {
210 PW95_Allocator lpW95 = (PW95_Allocator)lpW32;
211 lpW95->myHDC.Register ( pts, 4 );
212 DeletePen ( hTextPen );
213 DeleteBrush ( hTextBrush );
214 DeletePen ( hPolyPen );
215 DeleteBrush ( hPolyBrush );
217 PWNT_Allocator lpWNT = (PWNT_Allocator)lpW32;
218 lpWNT->Register ( pts, 4 );
219 SetWorldTransform ( MY_HDC, &xf );
221 //=====================================================
223 TCollection_ExtendedString extText;
224 if (lpDraw->isTextWide) {
225 extText = TCollection_ExtendedString((short*)lpDraw->theText);
227 extText = TCollection_AsciiString ((char*) lpDraw->theText);
229 cout << "DRAW_TEXT: " << (int)lpW32->myTextFont << ", "
230 << lpDraw->theXPos << ", " << lpDraw->theYPos << "), A="
231 << lpDraw->theAngle << ", M=" << lpDraw->theMargin << ", T="
232 << lpDraw->theTextType << ","
233 << (lpDraw->isTextPoly ? "'Poly'" : "'Simple'") << ","
234 << (lpDraw->isTextWide ? "'WCHAR'" : "'CHAR'")
235 << ", L=" << lpDraw->theTextLength << ", ('" << extText
236 << "'), SZ: " << theTextSize << ", VS=" << lpW32->myTextVScale
237 << ", HS=" << lpW32->myTextHScale << ", SL=" << lpW32->myTextSlant