0023426: Tool to compare two runs of tests on the same station
[occt.git] / src / WNT / WNT_WDriver.cxx
CommitLineData
b311480e 1// Created on: 1997-03-17
2// Created by: EugenyPLOTNIKOV
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21// Modified: MAR-98 (DCB) MFT
22// DCB: SEP-98 Avoid memory crash when color indices do not follow
23// each other or do not begin with '1'
7fd59977 24
25// include windows.h first to have all definitions available
26#include <windows.h>
27
28#define MFT // Study S3553
29
30#define PRO17334 //GG_060199
31// SetXxxAttrib() must raise when index is wrong
32// Idem for DrawMarker()
33
34#define PRO17381 //GG_080199
35// Protection : Do nothing when NULL string is found in TextSize
36
37#define PRO19042 //GG_261199
38// Don't clear buffer at begin draw .If not this clear
39// the current buffer attribs and the resulting buffer is black
40
41#include <WNT_WDriver.ixx>
42
43#include <WNT_GraphicDevice.hxx>
44#include <WNT_ImageManager.hxx>
45#include <WNT_Image.hxx>
46
47#include <Aspect_FontStyle.hxx>
48#include <Aspect_FontMapEntry.hxx>
49#include <Aspect_LineStyle.hxx>
50#include <Aspect_TypeMapEntry.hxx>
51#include <Aspect_TypeOfLine.hxx>
52#include <Aspect_WidthMapEntry.hxx>
53#include <Aspect_ColorMapEntry.hxx>
54#include <Aspect_MarkMapEntry.hxx>
55
56#include <TColStd_Array1OfBoolean.hxx>
57#include <TColQuantity_Array1OfLength.hxx>
58#include <Resource_Unicode.hxx>
59
60#include <windowsx.h>
61
62#include "W32_Allocator.hxx"
63
64#define A ( ( PW32_Allocator )myAllocator )
65#define SA ( !( A -> myFlags & W32F_MONO ) || \
b311480e 66( ( A -> myFlags & W32F_MONO ) && ( A -> myFlags & W32F_MINIT ) ) \
7fd59977 67 )
68
69/*====================== MFT ====================*/
70#ifdef MFT
71#include <Aspect_Units.hxx>
72#include "WNT_MFTDraw.hxx"
73#endif
74/*====================== MFT ====================*/
75
76typedef struct _m_param {
77
78 Aspect_MarkerStyle* s;
79 int w;
80 int h;
81
82 } MPARAM, *PMPARAM;
83
84typedef struct {
85
86 float r;
87 float g;
88 float b;
89
90 } PIXEL2D, *PPIXEL2D;
91
92extern double W32_TextFactor;
93static PW32_Allocator __fastcall _FindAllocator ( Standard_Address, Standard_Integer );
94static int __fastcall _GetROP2 ( Aspect_TypeOfDrawMode );
95static char* __fastcall _ConvertU2F ( const TCollection_ExtendedString& );
96
97static void WINAPI _SetPoint ( int, int, int, LPPOINT, int*, void* );
98
99WNT_WDriver :: WNT_WDriver ( const Handle( WNT_Window )& aWindow ) :
100 Aspect_WindowDriver ( aWindow ) {
101
102 WINDOW_DATA* wd;
103 Standard_Integer pXSize, pYSize;
104 Quantity_Length dXSize, dYSize;
105
106 Handle( WNT_GraphicDevice ) gDev = Handle ( WNT_GraphicDevice ) ::
107 DownCast ( MyWindow -> GraphicDevice () );
108
109 gDev -> DisplaySize ( pXSize, pYSize );
110 gDev -> DisplaySize ( dXSize, dYSize );
111
112 myWNTWindow = Handle( WNT_Window ) :: DownCast ( MyWindow );
113 myPixelToUnit = ( dXSize / pXSize + dYSize / pYSize ) / 2.0;
114 myAllocators = myAllocator = ( *W32_GetAllocator ) ( 0, NULL );
115 MyDrawMode = Aspect_TODM_REPLACE;
116
117/*====================== MFT ====================*/
118#ifdef MFT
119 myTextManager = new WNT_TextManager (myPixelToUnit);
120#endif
121/*====================== MFT ====================*/
122
123 wd = (WINDOW_DATA* )GetWindowLongPtr ((HWND )aWindow->HWindow(), GWLP_USERDATA);
124 wd->WNT_WDriver_Ptr = (void* )this;
125
126} // end constructor
127
128void WNT_WDriver :: Destroy () {
129
130 do {
131
132 myAllocator = ( ( PW32_Allocator )myAllocators ) -> myNext;
133
134 delete ( PW32_Allocator )myAllocators;
135
136 myAllocators = ( PW32_Allocator )myAllocator;
137
138 } while ( myAllocators != NULL );
139
140} // end WNT_WDriver :: Destroy
141
142Standard_Address WNT_WDriver :: SelectBuffer (
143 const Standard_Integer aRetainBuffer
144 ) const {
145
146 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
147
148 if ( a != NULL ) *( ( Standard_Address* )&myAllocator ) = ( Standard_Address )a;
149
150 return myAllocator;
151
152} // end WNT_WDriver :: SelectBuffer
153
154void WNT_WDriver :: BeginDraw (
155 const Standard_Boolean aDoubleBuffer,
156 const Standard_Integer aRetainBuffer
157 ) {
158
159 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
160
161 if ( a != NULL ) {
162
163 if ( aDoubleBuffer ) {
164
165 MyWindow -> SetDoubleBuffer ( aDoubleBuffer );
166 a -> myFlags |= W32F_DBUFF;
167
168 } else a -> myFlags &= ~W32F_DBUFF;
169
170#ifdef PRO19042
171 if( !aRetainBuffer )
172#endif
173 a -> ClearBlocks ();
174 a -> myFlags |= W32F_START;
175 a -> myFlags &= ~W32F_DVDRV;
176
177 SelectBuffer ( aRetainBuffer );
178
179 } // end if
180
181} // end WNT_WDriver :: BeginDraw
182
183void WNT_WDriver :: EndDraw ( const Standard_Boolean aSynchronize ) {
184
185 ( ( PW32_Allocator )myAllocator ) -> myFlags &= ~W32F_START;
186
187 DrawBuffer ( ( ( PW32_Allocator )myAllocator ) -> myID );
188
189} // end WNT_WDriver :: EndDraw
190
191Aspect_TypeOfResize WNT_WDriver :: ResizeSpace () {
192
193 return myWNTWindow -> DoResize ();
194
195} // end WNT_WDriver :: ResizeSpace
196
197Standard_Boolean WNT_WDriver :: SetHighlightColor (
198 const Standard_Integer aColorIdx
199 ) const {
200
201 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
202 DownCast ( MyWindow -> GraphicDevice () );
203
204 gDev -> SetColor (
205 ColorMap () -> Entry ( aColorIdx + 1 ).Color (), Standard_True
206 );
207
208 return Standard_True;
209
210} // end WNT_WDriver :: SetHighlightColor
211
212void WNT_WDriver :: SetDrawMode ( const Aspect_TypeOfDrawMode aMode ) {
213
214 MyDrawMode = aMode;
215
216} // end WNT_WDriver :: SetDrawMode
217
218void WNT_WDriver :: SetLineAttrib (
219 const Standard_Integer ColorIndex,
220 const Standard_Integer TypeIndex,
221 const Standard_Integer WidthIndex
222 )
223{
224#ifdef PRO17334
225 if( myColors.IsNull() ||
226 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
227 Aspect_DriverError::Raise ("Bad Color Index") ;
228 if( myTypeIdxs.IsNull() ||
229 TypeIndex < myTypeIdxs->Lower() || TypeIndex > myTypeIdxs->Upper() )
230 Aspect_DriverError::Raise ("Bad Type Index") ;
231 if( myWidthIdxs.IsNull() ||
232 WidthIndex < myWidthIdxs->Lower() || WidthIndex > myWidthIdxs->Upper() )
233 Aspect_DriverError::Raise ("Bad Width Index") ;
234
235 Aspect_LineStyle Entry = TypeMap () -> Entry ( myTypeIdxs -> Value(TypeIndex) ).Type ();
236#else
237 Standard_Integer theIndex = TypeIndex;
238 if (TypeIndex < myTypeIdxs->Lower() || TypeIndex > myTypeIdxs->Upper())
239 theIndex = myTypeIdxs->Lower();
240
241 Aspect_LineStyle Entry = TypeMap () -> Entry ( myTypeIdxs -> Value(theIndex) ).Type ();
242#endif
243 Standard_Integer type = ((Entry.Style() == Aspect_TOL_SOLID) ? 0 : PS_USERSTYLE);
244 double width = ( double )ProcessWidthIndex ( WidthIndex );
245 Standard_Boolean fUser = ( type & PS_USERSTYLE );
246 LOGBRUSH lb = { BS_SOLID, ProcessColorIndex ( ColorIndex ), 0 };
247 if ( fUser ) {
248 Standard_Integer Lower = Entry.Values ().Lower ();
249 Standard_Integer Count = Entry.Values ().Length ();
250 PDWORD dwStyle = ( PDWORD )HeapAlloc (
251 GetProcessHeap (),
252 HEAP_GENERATE_EXCEPTIONS,
253 Count * sizeof ( DWORD )
254 );
255 for ( Standard_Integer i = 0; i < Count; ++i ) {
256 dwStyle[ i ] = DWORD ( Entry.Values ().Value ( i + Lower ) / myPixelToUnit + 0.5 );
257 if ( dwStyle[ i ] == 0.0 ) dwStyle[ i ] = 1;
258 } // end for
259 A -> LineAttrib ( DWORD( width + 0.5 ), &lb, Count, dwStyle );
260 HeapFree ( GetProcessHeap (), 0, ( LPVOID )dwStyle );
261 } else A -> LineAttrib ( DWORD( width + 0.5 ), &lb );
262} // end WNT_WDriver :: SetLineAttrib
263
264void WNT_WDriver :: SetTextAttrib (
265 const Standard_Integer ColorIndex,
266 const Standard_Integer FontIndex
267 )
268{
269 SetTextAttrib ( ColorIndex, FontIndex, 0.0, 1.0, 0.0,Standard_False );
270} // end WNT_WDriver :: SetTextAttrib
271
272void WNT_WDriver :: SetTextAttrib (
273 const Standard_Integer ColorIndex,
274 const Standard_Integer FontIndex,
275 const Quantity_PlaneAngle aSlant,
276 const Quantity_Factor aHScale,
277 const Quantity_Factor aWScale,
278 const Standard_Boolean isUnderlined
279 )
280{
281#ifdef PRO17334
282 if( myColors.IsNull() ||
283 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
284 Aspect_DriverError::Raise ("Bad Color Index") ;
285 if( myFonts.IsNull() ||
286 FontIndex < myFonts->Lower() || FontIndex > myFonts->Upper() )
287 Aspect_DriverError::Raise ("Bad Font Index") ;
288#endif
289 HFONT hFont;
290 LOGFONT lf;
291 BOOL fFree = FALSE;
292 Handle( WNT_FontMapEntry ) fmEntry = myFonts -> Value ( FontIndex );
293 /*====================== MFT ====================*/
294#ifdef MFT
295 if ( UseMFT() ) {
296 //============== Set some font attributes =============
297 Handle(MFT_FontManager) theFontManager = MFT_Font(FontIndex);
298 Standard_ShortReal theTextSize = MFT_Size(FontIndex);
299 theFontManager->SetFontAttribs (
300 Abs(theTextSize)*(aWScale > 0.0 ? aWScale : aHScale)*A->myScaleX,
301 Abs(theTextSize)*aHScale *A->myScaleY,
302 aSlant, 0., ((theTextSize > 0.) ? Standard_False : Standard_True)
303 );
304 A -> TextAttrib (
305 (HFONT)FontIndex, ProcessColorIndex ( ColorIndex ), aSlant,
306 aHScale, ( aWScale > 0.0 ? aWScale : aHScale ),
307 isUnderlined, Standard_False, Standard_True
308 );
309 } else {
310#endif
311 /*====================== MFT ====================*/
312 GetObject (
313 hFont = ( HFONT )fmEntry-> HFont (),
314 sizeof ( LOGFONT ), &lf
315 );
316
317 if ( isUnderlined && !lf.lfUnderline ) {
318 FONT_DATA fd = { TRUE };
319 hFont = ( HFONT )fmEntry -> SetAttrib ( faUnderlined, &fd );
320 fFree = TRUE;
321 } // end if
322
323 A -> TextAttrib (
324 hFont, ProcessColorIndex ( ColorIndex ), aSlant,
325 aHScale / W32_TextFactor,
326 ( aWScale > 0.0 ? aWScale : aHScale ) / W32_TextFactor,
327 isUnderlined, fFree
328 );
329#if 0
330 char* str = (isUnderlined ? "UNDERLINED" : "GOD DAMN ");
331 HDC hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
332 HFONT hf = SelectFont ( hdc, hFont );
333 SetTextColor ( hdc, RGB (133, 211, 66) );
334 SetBkColor ( hdc, RGB (0, 0, 0) );
335 Rectangle ( hdc, 0, 0, 1220, 220 );
336 SetBkMode ( hdc, OPAQUE );
337 TextOut ( hdc, 0, 0, str, lstrlen(str) );
338 SelectFont ( hdc, hf );
339 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
340 MessageBox ( ( HWND )myWNTWindow -> HWindow (), str, "Son of a BITCH", MB_OK );
341#endif
342 /*====================== MFT ====================*/
343#ifdef MFT
344 }
345#endif
346 /*====================== MFT ====================*/
347} // end WNT_WDriver :: SetTextAttrib
348
349void WNT_WDriver :: SetPolyAttrib (
350 const Standard_Integer ColorIndex,
351 const Standard_Integer TileIndex,
352 const Standard_Boolean DrawEdgeFlag
353 )
354{
355#ifdef PRO17334
356 if( myColors.IsNull() ||
357 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
358 Aspect_DriverError::Raise ("Bad Color Index") ;
359#endif
360 if ( !SA ) return;
361 LOGBRUSH lb = { TileIndex < 0 ? BS_NULL : BS_SOLID, ProcessColorIndex ( ColorIndex ), 0 };
362 A -> PolyAttrib ( &lb, DrawEdgeFlag );
363} // end WNT_WDriver :: SetPolyAttrib
364
365void WNT_WDriver :: SetPolyAttrib (
366 const Standard_Integer ColorIndex,
367 const Standard_Integer TileIndex,
368 const Standard_Integer PolygonMode,
369 const Standard_Boolean DrawEdgeFlag
370 )
371{
372#ifdef PRO17334
373 if( myColors.IsNull() ||
374 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
375 Aspect_DriverError::Raise ("Bad Color Index") ;
376#endif
377 if ( !SA ) return;
378 LOGBRUSH lb = { BS_SOLID, ProcessColorIndex ( ColorIndex ), 0 };
379 A -> PolyAttrib ( &lb, DrawEdgeFlag, PolygonMode );
380} // end WNT_WDriver :: SetPolyAttrib
381
382void WNT_WDriver :: SetMarkerAttrib (
383 const Standard_Integer ColorIndex,
384 const Standard_Integer EdgeWidthIndex,
385 const Standard_Boolean FillMarker
386 )
387{
388#ifdef PRO17334
389 if( myColors.IsNull() ||
390 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
391 Aspect_DriverError::Raise ("Bad Color Index") ;
392 if( myWidthIdxs.IsNull() ||
393 EdgeWidthIndex < myWidthIdxs->Lower() || EdgeWidthIndex > myWidthIdxs->Upper() )
394 Aspect_DriverError::Raise ("Bad EdgeWidth Index") ;
395#endif
396 if ( SA )
397 A -> MarkerAttrib (
398 ProcessColorIndex ( ColorIndex ),
399 DWORD( ProcessWidthIndex ( EdgeWidthIndex ) + 0.5 ),
400 FillMarker
401 );
402} // end WNT_WDriver :: SetMarkerAttrib
403
404Standard_Boolean WNT_WDriver :: IsKnownImage (
405 const Handle( Standard_Transient )& anImage
ec6a1aa7
D
406 )
407{
408 return myWNTWindow -> myImages -> Index ( ::HashCode (anImage, IntegerLast())
7fd59977 409 ) ? Standard_True : Standard_False;
7fd59977 410} // end WNT_WDriver :: IsKnownImage
411
412Standard_Boolean WNT_WDriver :: SizeOfImageFile (
413 const Standard_CString anImageFile,
414 Standard_Integer& aWidth,
415 Standard_Integer& aHeight
416 ) const {
417#ifndef BUG //Sets the size to 0 when the image file is not found.
418 aWidth = 0; aHeight = 0;
419#endif
420
421 Standard_Integer i = myWNTWindow -> myImages -> Load ( anImageFile );
422
423 if ( i ) myWNTWindow -> myImages -> Dim ( i, aWidth, aHeight );
424
425 return i ? Standard_True : Standard_False;
426
427} // end WNT_WDriver :: SizeOfImageFile
428
429void WNT_WDriver :: ClearImage ( const Handle( Standard_Transient )& anImageId ) {
430
431 Standard_Integer i = myWNTWindow -> myImages -> Index (
ec6a1aa7 432 ::HashCode (anImageId, IntegerLast())
7fd59977 433 );
434
435 if ( i ) myWNTWindow -> myImages -> Discard ( i );
436
437} // end WNT_WDriver :: ClearImage
438
439void WNT_WDriver :: ClearImageFile ( const Standard_CString anImageFile ) {
440
441 Standard_Integer i = myWNTWindow -> myImages -> Load ( anImageFile );
442
443 if ( i ) myWNTWindow -> myImages -> Discard ( i );
444
445} // end WNT_WDriver :: ClearImageFile
446
447void WNT_WDriver :: DrawImage (
448 const Handle( Standard_Transient )& anImageId,
449 const Standard_ShortReal aX,
450 const Standard_ShortReal aY
451 ) {
452
453 Standard_Integer i = myWNTWindow -> myImages -> Index (
ec6a1aa7 454 ::HashCode (anImageId, IntegerLast())
7fd59977 455 );
456
457 if ( i ) A -> Image (
458 P( aX ), P( aY ),
459 ( PW32_Bitmap )myWNTWindow -> myImages -> Image ( i ) -> Image ()
460 );
461
462} // end WNT_WDriver :: DrawImage
463
464void WNT_WDriver :: DrawImageFile (
465 const Standard_CString anImageFile,
466 const Standard_ShortReal aX,
467 const Standard_ShortReal aY,
468 const Quantity_Factor aScale
469 ) {
470
471 int i = myWNTWindow -> myImages -> Load ( anImageFile );
472
473 if ( i ) {
474
475 PW32_Bitmap pBmp;
476
477 if (aScale != 1.0) {
478
479 pBmp = ( PW32_Bitmap )HeapAlloc (
480 GetProcessHeap (),
481 HEAP_GENERATE_EXCEPTIONS,
482 sizeof ( W32_Bitmap )
483 );
484 pBmp -> hBmp = ( HBITMAP )myWNTWindow -> myImages -> Scale ( i, aScale, aScale );
485 pBmp -> nUsed = 0;
486
487 } else
488
489 pBmp = ( PW32_Bitmap )myWNTWindow -> myImages -> Image ( i ) -> Image ();
490
491 A -> Image ( P( aX ), P( aY ), pBmp );
492
493 } // end if
494
495} // end WNT_WDriver :: DrawImageFile
496
497void WNT_WDriver :: FillAndDrawImage (
498 const Handle(Standard_Transient)& anImageId,
499 const Standard_ShortReal aX,
500 const Standard_ShortReal aY,
501 const Standard_Integer Width,
502 const Standard_Integer Height,
503 const Standard_Address anArrayOfPixels
504 ) {
505
506 HDC hdc, hdcMem;
507 HBITMAP hbo;
508 HPALETTE hpo = NULL;
509 Standard_Integer i, h;
510 Quantity_Color color;
511 PPIXEL2D p = ( PPIXEL2D )anArrayOfPixels;
512 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
513 DownCast ( MyWindow -> GraphicDevice () );
514
515 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
516 hdcMem = CreateCompatibleDC ( hdc );
517
518 if ( gDev -> IsPaletteDevice () )
519
520 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
521
522 i = myWNTWindow -> myImages -> Index (
ec6a1aa7 523 h = ::HashCode (anImageId, IntegerLast())
7fd59977 524 );
525
526 if ( i == 0 ) i = myWNTWindow -> myImages -> Open ( hdc, Width, Height, h );
527
528 if ( Width > 0 && Height > 0 ) {
529
530 Standard_Integer iX, iY;
531 Standard_Real sX, sY;
532
533 myWNTWindow -> myImages -> Dim ( i, iX, iY );
534
535 if ( iX != Width || iY != Height ) {
536
537 sX = Width / ( Standard_Real )iX;
538 sY = Height / ( Standard_Real )iY;
539
540 myWNTWindow -> myImages -> Scale ( i, sX, sY, Standard_True );
541
542 } // end if
543
544 hbo = SelectBitmap(
545 hdcMem, ( HBITMAP )myWNTWindow -> myImages -> ImageHandle ( i )
546 );
547
548 for ( int i = 0; i < Height; ++i )
549
550 for ( int j = 0; j < Width; ++j, ++p ) {
551
552 color.SetValues ( p -> r, p -> g, p -> b, Quantity_TOC_RGB );
553 SetPixel ( hdcMem, j, i, gDev -> SetColor ( color ) );
554
555 } // end for
556
557 SelectBitmap( hdcMem, hbo );
558
559 } // end if
560
561 if ( hpo != NULL ) SelectPalette ( hdcMem, hpo, FALSE );
562
563 DeleteDC ( hdcMem );
564 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
565
566 DrawImage ( anImageId, aX, aY );
567
568} // end WNT_WDriver :: FillAndDrawImage
569
570void WNT_WDriver :: FillAndDrawImage (
571 const Handle( Standard_Transient )& anImageId,
572 const Standard_ShortReal aX,
573 const Standard_ShortReal aY,
574 const Standard_Integer anIndexOfLine,
575 const Standard_Integer Width,
576 const Standard_Integer Height,
577 const Standard_Address anArrayOfPixels
578 ) {
579
580 HDC hdc, hdcMem;
581 HBITMAP hbo;
582 HPALETTE hpo = NULL;
583 Standard_Integer i, h;
584 Quantity_Color color;
585 PPIXEL2D p = ( PPIXEL2D )anArrayOfPixels;
586 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
587 DownCast ( MyWindow -> GraphicDevice () );
588
589 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
590 hdcMem = CreateCompatibleDC ( hdc );
591
592 if ( gDev -> IsPaletteDevice () )
593
594 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
595
596 i = myWNTWindow -> myImages -> Index (
ec6a1aa7 597 h = ::HashCode (anImageId, IntegerLast())
7fd59977 598 );
599
600 if ( i == 0 ) i = myWNTWindow -> myImages -> Open ( hdc, Width, Height, h );
601
602 if ( Width > 0 && Height > 0 ) {
603
604 Standard_Integer iX, iY;
605 Standard_Real sX, sY;
606
607 myWNTWindow -> myImages -> Dim ( i, iX, iY );
608
609 if ( iX != Width || iY != Height ) {
610
611 sX = Width / ( Standard_Real )iX;
612 sY = Height / ( Standard_Real )iY;
613
614 myWNTWindow -> myImages -> Scale ( i, sX, sY, Standard_True );
615
616 } // end if
617
618 hbo = SelectBitmap(
619 hdcMem, ( HBITMAP )myWNTWindow -> myImages -> ImageHandle ( i )
620 );
621
622 for ( int j = 0; j < Width; ++j, ++p ) {
623
624 color.SetValues ( p -> r, p -> g, p -> b, Quantity_TOC_RGB );
625 SetPixel ( hdcMem, j, anIndexOfLine, gDev -> SetColor ( color ) );
626
627 } // end for
628
629 SelectBitmap( hdcMem, hbo );
630
631 } // end if
632
633 if ( hpo != NULL ) SelectPalette ( hdcMem, hpo, FALSE );
634
635 DeleteDC ( hdcMem );
636 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
637
638 if ( anIndexOfLine == Height - 1 ) DrawImage ( anImageId, aX, aY );
639
640} // end WNT_WDriver :: FillAndDrawImage
641
642void WNT_WDriver :: DrawPolyline (
643 const TShort_Array1OfShortReal& ListX,
644 const TShort_Array1OfShortReal& ListY
645 ) {
646
647 Standard_Integer nPts = ListX.Length ();
648
649 if ( nPts != ListY.Length () )
650
651 Aspect_DriverError :: Raise ( "DrawPolyline: incorrect argument" );
652
653 if ( nPts > 0 ) {
654
655 Standard_Integer lX = ListX.Lower ();
656 Standard_Integer lY = ListY.Lower ();
657
658 if ( A -> myPrimitive != zzNone ) ClosePrimitive ();
659
660 W32_PolygonNote* p = ( W32_PolygonNote* )( A -> Polyline ( nPts ) );
661
662 for ( Standard_Integer i = 0; i < nPts; ++i )
663
664 p -> Add (
665 P( ListX.Value ( lX + i ) ),
666 P( ListY.Value ( lY + i ) )
667 );
668
669 } // end if
670
671} // end WNT_WDriver :: DrawPolyline
672
673void WNT_WDriver :: DrawPolygon (
674 const TShort_Array1OfShortReal& ListX,
675 const TShort_Array1OfShortReal& ListY
676 ) {
677
678 Standard_Integer nPts = ListX.Length ();
679
680 if ( nPts != ListY.Length () )
681
682 Aspect_DriverError :: Raise ( "DrawPolygon: incorrect argument" );
683
684 if ( nPts > 0 ) {
685
686 Standard_Integer lX = ListX.Lower ();
687 Standard_Integer lY = ListY.Lower ();
688
689 if ( A -> myPrimitive != zzNone ) ClosePrimitive ();
690
691 W32_PolygonNote* p = ( W32_PolygonNote* )( A -> Polygon ( nPts ) );
692
693 for ( Standard_Integer i = 0; i < nPts; ++i )
694
695 p -> Add (
696 P( ListX.Value ( lX + i ) ),
697 P( ListY.Value ( lY + i ) )
698 );
699
700 } // end if
701
702} // end WNT_WDriver :: DrawPolygon
703
704void WNT_WDriver :: DrawSegment (
705 const Standard_ShortReal X1,
706 const Standard_ShortReal Y1,
707 const Standard_ShortReal X2,
708 const Standard_ShortReal Y2
709 ) {
710
711 A -> Line ( P( X1 ), P( Y1 ), P( X2 ), P( Y2 ) );
712
713} // end WNT_WDriver :: DrawSegment
714
715
716void WNT_WDriver :: DrawText (
717 const TCollection_ExtendedString& Text,
718 const Standard_ShortReal Xpos,
719 const Standard_ShortReal Ypos,
720 const Standard_ShortReal anAngle,
721 const Aspect_TypeOfText aType
722 )
723{
724/*====================== MFT ====================*/
725#ifdef MFT
726 if ( UseMFT() ) {
727 MFT_DRAWTEXT dt = {
728 myAllocator, this, myPixelToUnit,
729 Xpos, Ypos, anAngle, 0., (int)aType,
730 FALSE, TRUE, Text.Length(), NULL
731 };
732 CopyMemory (dt.theText, Text.ToExtString(),
733 Text.Length()*sizeof(short));
734 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
735 PW32_FCALLPARAM(&dt) );
736 } else {
737#endif
738/*====================== MFT ====================*/
739 char* str = _ConvertU2F ( Text );
740 A -> Text (
741 P( Xpos ), P( Ypos ),
742 anAngle, str, FALSE,
743 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
744 );
745 HeapFree ( GetProcessHeap (), 0, str );
746/*====================== MFT ====================*/
747#ifdef MFT
748 }
749#endif
750/*====================== MFT ====================*/
751} // end WNT_WDriver :: DrawText
752
753
754void WNT_WDriver :: DrawText (
755 const Standard_CString Text,
756 const Standard_ShortReal Xpos,
757 const Standard_ShortReal Ypos,
758 const Standard_ShortReal anAngle,
759 const Aspect_TypeOfText aType
760 )
761{
762/*====================== MFT ====================*/
763#ifdef MFT
764 if ( UseMFT() ) {
765 MFT_DRAWTEXT dt = {
766 myAllocator, this, myPixelToUnit,
767 Xpos, Ypos, anAngle, 0., (int)aType,
768 FALSE, FALSE, lstrlen(Text), NULL
769 };
770 CopyMemory (dt.theText, Text, lstrlen(Text));
771 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
772 PW32_FCALLPARAM(&dt) );
773 } else
774#endif
775/*====================== MFT ====================*/
776 A -> Text (
777 P( Xpos ), P( Ypos ), anAngle, (Standard_Address)Text, FALSE,
778 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
779 );
780} // end WNT_WDriver :: DrawText
781
782void WNT_WDriver :: DrawPolyText (
783 const TCollection_ExtendedString& aText,
784 const Standard_ShortReal Xpos,
785 const Standard_ShortReal Ypos,
786 const Quantity_Ratio aMarge,
787 const Standard_ShortReal anAngle,
788 const Aspect_TypeOfText aType
789 )
790{
791/*====================== MFT ====================*/
792#ifdef MFT
793 if ( UseMFT() ) {
794 MFT_DRAWTEXT dt = {
795 myAllocator, this, myPixelToUnit,
796 Xpos, Ypos, anAngle, aMarge, (int)aType,
797 TRUE, TRUE, aText.Length(), NULL
798 };
799 CopyMemory (dt.theText, aText.ToExtString(),
800 aText.Length()*sizeof(short));
801 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
802 PW32_FCALLPARAM(&dt) );
803 } else {
804#endif
805/*====================== MFT ====================*/
806 char* str = _ConvertU2F ( aText );
807 A -> Polytext (
808 P( Xpos ), P( Ypos ), anAngle, aMarge, str, FALSE,
809 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
810 );
811 HeapFree ( GetProcessHeap (), 0, str );
812/*====================== MFT ====================*/
813#ifdef MFT
814 }
815#endif
816/*====================== MFT ====================*/
817} // end WNT_WDriver :: DrawPolyText
818
819void WNT_WDriver :: DrawPolyText (
820 const Standard_CString aText,
821 const Standard_ShortReal Xpos,
822 const Standard_ShortReal Ypos,
823 const Quantity_Ratio aMarge,
824 const Standard_ShortReal anAngle,
825 const Aspect_TypeOfText aType
826 )
827{
828/*====================== MFT ====================*/
829#ifdef MFT
830 if ( UseMFT() ) {
831 MFT_DRAWTEXT dt = {
832 myAllocator, this, myPixelToUnit,
833 Xpos, Ypos, anAngle, aMarge, (int)aType,
834 TRUE, FALSE, lstrlen(aText), NULL
835 };
836 CopyMemory (dt.theText, aText, lstrlen(aText));
837 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
838 PW32_FCALLPARAM(&dt) );
839 } else
840#endif
841/*====================== MFT ====================*/
842 A -> Polytext (
843 P( Xpos ), P( Ypos ), anAngle, aMarge, (Standard_Address)aText, FALSE,
844 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
845 );
846
847} // end WNT_WDriver :: DrawPolyText
848
849void WNT_WDriver :: DrawPoint (
850 const Standard_ShortReal X,
851 const Standard_ShortReal Y
852 )
853{
854 switch ( A -> myPrimitive ) {
855 case zzPolygon:
856 ( ( W32_PolygonNote* )( A -> myNote ) ) -> Add ( P( X ), P( Y ) );
857 break;
858 case zzPolyline:
859 ( ( W32_PolylineNote* )( A -> myNote ) ) -> Add ( P( X ), P( Y ) );
860 break;
861 default:
862 A -> Point ( P( X ), P( Y ) );
863 } // end switch
864} // end WNT_WDriver :: DrawPoint
865
866void WNT_WDriver :: DrawMarker (
867 const Standard_Integer aMarker,
868 const Standard_ShortReal Xpos,
869 const Standard_ShortReal Ypos,
870 const Standard_ShortReal Width,
871 const Standard_ShortReal Height,
872 const Standard_ShortReal Angle
873 ) {
874
875 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzMarker ) ClosePrimitive ();
876
877 int aWidth = P( Width );
878 int aHeight = P( Height );
879
880 Standard_Integer theIndex = -1;
881#ifdef PRO17334
882 if( !myMarkerIdxs.IsNull() &&
883 (aMarker >= myMarkerIdxs->Lower() && aMarker <= myMarkerIdxs->Upper()) )
884 theIndex = myMarkerIdxs->Value(aMarker);
885 if( theIndex < 0 ) Aspect_DriverError::Raise ("Bad Marker Index") ;
886
887 if ( aWidth && aHeight && (aMarker > 0) ) {
888#else
889 if (aMarker >= myMarkerIdxs->Lower() || aMarker <= myMarkerIdxs->Upper())
890 theIndex = myMarkerIdxs->Value(aMarker);
891
892 if ( aWidth && aHeight && (theIndex >= 0) ) {
893#endif
894
895
896 A -> BeginMarker ( P( Xpos ), P( Ypos ), aWidth, aHeight, Angle );
897
898 Aspect_MarkerStyle Style = MarkMap () -> Entry ( theIndex ).Style ();
899
900 int MarkerSize = Style.Length ();
901 int DrawCount = 0;
902 int PrevPoint = 0;
903 int i;
904 MPARAM mp = { &Style, aWidth, aHeight };
905
906 for ( i = 2; i <= MarkerSize; ++i ) {
907
908 if ( Style.SValues ().Value ( i ) ) {
909
910 if ( Style.SValues ().Value ( i - 1 ) )
911
912 ++DrawCount;
913
914 else {
915
916 PrevPoint = i - 1;
917 DrawCount = 2;
918
919 } // end else
920
921 } else {
922
923 if ( Style.SValues().Value ( i - 1 ) ) {
924
925 if ( ( Style.XValues ().Value ( i ) == Style.XValues ().Value ( PrevPoint ) ) &&
926 ( Style.YValues ().Value ( i ) == Style.YValues ().Value ( PrevPoint ) )
927 )
928
929 A -> PolyMarker2 ( DrawCount, &_SetPoint, PrevPoint, &mp );
930
931 else
932
933 A -> PolyMarker1 ( DrawCount, &_SetPoint, PrevPoint, &mp );
934
935 } // end if
936
937 DrawCount = 0;
938
939 } // end else
940
941 } // end for
942
943 --i;
944
945 if ( DrawCount ) {
946
947 if ( ( Style.XValues ().Value ( i ) == Style.XValues ().Value ( PrevPoint ) ) &&
948 ( Style.YValues ().Value ( i ) == Style.YValues ().Value ( PrevPoint ) )
949 )
950
951 A -> PolyMarker2 ( DrawCount, &_SetPoint, PrevPoint, &mp );
952
953 else
954
955 A -> PolyMarker1 ( DrawCount, &_SetPoint, PrevPoint, &mp );
956
957 } // end if
958
959 A -> EndMarker ();
960
961 } else A -> MarkerPoint ( P( Xpos ), P( Ypos ) );
962
963} // end WNT_WDriver :: DrawMarker
964
965Standard_Boolean WNT_WDriver :: DrawArc (
966 const Standard_ShortReal X,
967 const Standard_ShortReal Y,
968 const Standard_ShortReal aXradius,
969 const Standard_ShortReal aYradius,
970 const Standard_ShortReal aStartAngle,
971 const Standard_ShortReal anOpenAngle
972 ) {
973
974 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzArc )
975
976 ClosePrimitive ();
977
978 if ( anOpenAngle >= 6.28318 )
979
980 A -> Ellipse ( P( X ), P( Y ), P( aXradius ), P( aYradius ) );
981
982 else
983
984 A -> Arc (
985 P( X ), P( Y ), P( aXradius ), P( aYradius ),
986 aStartAngle, anOpenAngle
987 );
988
989 return Standard_True;
990
991} // end WNT_WDriver :: DrawArc
992
993Standard_Boolean WNT_WDriver :: DrawPolyArc (
994 const Standard_ShortReal X,
995 const Standard_ShortReal Y,
996 const Standard_ShortReal anXradius,
997 const Standard_ShortReal anYradius,
998 const Standard_ShortReal aStartAngle,
999 const Standard_ShortReal anOpenAngle
1000
1001 ) {
1002
1003 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzPolySector )
1004
1005 ClosePrimitive ();
1006
1007 if ( anOpenAngle >= 6.28318 )
1008
1009 A -> PolyEllipse ( P( X ), P( Y ), P( anXradius ), P( anYradius ) );
1010
1011 else
1012
1013 A -> PolySector (
1014 P( X ), P( Y ), P( anXradius ), P( anYradius ),
1015 aStartAngle, anOpenAngle
1016 );
1017
1018 return Standard_True;
1019
1020} // end WNT_WDriver :: DrawPolyArc
1021
1022void WNT_WDriver :: BeginPolyline ( const Standard_Integer aNumber ) {
1023
1024 A -> myPrimitive = zzPolyline;
1025 A -> myNote = A -> Polyline ( aNumber );
1026
1027} // end WNT_WDriver :: BeginPolyline
1028
1029void WNT_WDriver :: BeginPolygon ( const Standard_Integer aNumber ) {
1030
1031 A -> myPrimitive = zzPolygon;
1032 A -> myNote = A -> Polygon ( aNumber );
1033
1034} // end WNT_WDriver :: BeginPolygon
1035
1036void WNT_WDriver :: BeginSegments () {
1037
1038 A -> myPrimitive = zzLine;
1039 A -> myNote = NULL;
1040
1041} // end WNT_WDriver :: BeginSegments
1042
1043void WNT_WDriver :: BeginArcs () {
1044
1045 A -> myPrimitive = zzArc;
1046 A -> myNote = NULL;
1047
1048} // end WNT_WDriver :: BeginArcs
1049
1050void WNT_WDriver :: BeginPolyArcs () {
1051
1052 A -> myPrimitive = zzPolySector;
1053 A -> myNote = NULL;
1054
1055} // end WNT_WDriver :: BeginPolyArcs
1056
1057void WNT_WDriver :: BeginMarkers () {
1058
1059 A -> myPrimitive = zzMarker;
1060 A -> myNote = NULL;
1061
1062} // end WNT_WDriver :: BeginMarkers
1063
1064void WNT_WDriver :: BeginPoints () {
1065
1066 A -> myPrimitive = zzPoint;
1067 A -> myNote = NULL;
1068
1069} // end WNT_WDriver :: BeginPoints
1070
1071void WNT_WDriver :: ClosePrimitive () {
1072
1073 A -> myPrimitive = zzNone;
1074 A -> myNote = NULL;
1075
1076} // end WNT_WDriver :: ClosePrimitive
1077
1078void WNT_WDriver :: InitializeColorMap ( const Handle( Aspect_ColorMap) & Colormap )
1079{
1080 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
1081 DownCast ( MyWindow -> GraphicDevice () );
1082
1083 Aspect_ColorMapEntry entry;
1084 Standard_Integer i, minindex = IntegerLast(), maxindex = -minindex;
1085 for (i = 1; i <= Colormap->Size (); i++) {
1086 entry = Colormap->Entry (i);
1087 maxindex = Max(maxindex, entry.Index ());
1088 minindex = Min(minindex, entry.Index ());
1089 }
1090
1091 if ( myColors.IsNull () || myColors -> Length () != Colormap -> Size () )
1092 myColors = new WNT_HColorTable ( minindex, maxindex, (WNT_ColorRef)0x00000000 );
1093
1094 gDev -> MapColors ( Colormap, myColors );
1095} // end WNT_WDriver :: InitializeColorMap
1096
1097void WNT_WDriver :: InitializeTypeMap ( const Handle( Aspect_TypeMap )& Typemap )
1098{
1099 Aspect_TypeMapEntry entry;
1100 Standard_Integer i, minindex = IntegerLast(), maxindex = -minindex;
1101 for (i = 1; i <= Typemap->Size (); i++) {
1102 entry = Typemap->Entry (i);
1103 maxindex = Max(maxindex, entry.Index ());
1104 minindex = Min(minindex, entry.Index ());
1105 }
1106
1107 myTypeIdxs = new TColStd_HArray1OfInteger (minindex, maxindex, 1);
1108 for (i = 1; i <= Typemap->Size (); i++) {
1109 entry = Typemap->Entry (i);
1110 myTypeIdxs -> SetValue (entry.Index(), i);
1111 }
1112} // end WNT_WDriver :: InitializeTypeMap
1113
1114void WNT_WDriver :: InitializeWidthMap ( const Handle( Aspect_WidthMap )& Widthmap )
1115{
1116 Aspect_WidthMapEntry entry;
1117 Standard_Integer i, minindex = IntegerLast(), maxindex = -minindex;
1118 for (i = 1; i <= Widthmap->Size (); i++) {
1119 entry = Widthmap->Entry (i);
1120 maxindex = Max(maxindex, entry.Index ());
1121 minindex = Min(minindex, entry.Index ());
1122 }
1123
1124 myWidthIdxs = new TColStd_HArray1OfInteger (minindex, maxindex, 1);
1125 for (i = 1; i <= Widthmap->Size (); i++) {
1126 entry = Widthmap->Entry (i);
1127 myWidthIdxs -> SetValue (entry.Index(), i);
1128 }
1129} // end WNT_WDriver :: InitializeWidthMap
1130
1131void WNT_WDriver :: InitializeFontMap ( const Handle( Aspect_FontMap )& Fontmap )
1132{
1133 Aspect_FontStyle fontStyle;
1134 Handle( WNT_FontMapEntry ) fmEntry;
1135 Standard_Character left[ 260 ], right[ 250 ];
1136 Standard_PCharacter pSize;
1137 Standard_Integer height, mapSize = Fontmap -> Size ();
1138 HDC hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1139 HFONT hfo = SelectFont( hdc, GetStockObject ( DEFAULT_GUI_FONT ) );
1140 Standard_Integer i;
1141/*====================== MFT ====================*/
1142#ifdef MFT
1143 Aspect_FontMapEntry entry;
1144 Aspect_FontStyle style;
1145 Quantity_Length size;
1146 Quantity_PlaneAngle slant;
1147 TCollection_AsciiString aname;
1148 if ( UseMFT() ) {
1149 Handle(MFT_FontManager) theFontManager;
1150 myMFTFonts = new WNT_HListOfMFTFonts (0, mapSize, theFontManager);
1151 myMFTSizes = new TShort_HArray1OfShortReal (0, mapSize, 0.F);
1152 }
1153#endif
1154/*====================== MFT ====================*/
1155 myFonts = new WNT_HFontTable ( 0, mapSize - 1 );
1156 for ( i = 0; i < mapSize; ++i ) {
1157/*====================== MFT ====================*/
1158#ifdef MFT
1159 if ( UseMFT() ) {
1160 entry = Fontmap->Entry(i+1);
1161 style = entry.Type ();
1162 size = (Quantity_Length) TOMILLIMETER (style.Size());
1163 slant = style.Slant ();
1164 if (style.CapsHeight()) size = -size;
1165 aname = style.AliasName ();
1166 Standard_Boolean found = MFT_FontManager::IsKnown (aname.ToCString());
1167 if (!found) {
1168 cout << " WNT_WDriver::SetFontMap can't find the MFT font name '"
1169 << aname << "', using 'Defaultfont'" << endl << flush;
1170 aname = TCollection_AsciiString("Defaultfont");
1171 found = Standard_True;
1172 }
1173 if (found) {
1174 Handle(MFT_FontManager) theFontManager;
1175 Aspect_FontStyle theStyle = MFT_FontManager::Font (aname.ToCString());
1176 found = Standard_False;
1177 for (int k = 0; k < mapSize; k++) {
1178 theFontManager = myMFTFonts -> Value (k);
1179 if (!theFontManager.IsNull()) {
1180 if (theStyle == theFontManager->Font()) {
1181 found = Standard_True;
1182 break;
1183 }
1184 }
1185 }
1186 if (!found)
1187 theFontManager = new MFT_FontManager (aname.ToCString());
1188 theFontManager->SetFontAttribs (
1189 Abs(size), Abs(size), slant, 0., Standard_Boolean(size < 0.)
1190 );
1191 myMFTFonts->SetValue (i, theFontManager);
1192 myMFTSizes->SetValue (i, (Standard_ShortReal)size);
1193 }
1194 }
1195 if ( UseMFT() && !myMFTFonts->Value(i).IsNull())
1196 continue;
1197#endif
1198/*====================== MFT ====================*/
1199 fontStyle = Fontmap -> Entry ( i + 1 ).Type ();
1200 height = Standard_Integer ( fontStyle.Size () / myPixelToUnit );
1201 lstrcpyA ( right,"-*-*-*-*-*-*-*-*-*-*-*-*-" );
1202 switch ( fontStyle.Style () ) {
1203 case Aspect_TOF_HELVETICA:
1204 lstrcatA ( right,"Arial" );
1205 break;
1206 case Aspect_TOF_DEFAULT:
1207 case Aspect_TOF_COURIER:
1208 lstrcatA ( right, "Courier New" );
1209 break;
1210 case Aspect_TOF_TIMES:
1211 lstrcatA ( right,"Times New Roman" );
1212 break;
1213 case Aspect_TOF_USERDEFINED:
1214 lstrcpyA ( left, fontStyle.Value () );
1215 if ( strchr ( fontStyle.Value (), '-' ) ) {
1216 height = atol ( pSize = strtok ( left, "-" ) );
1217 if ( height == 0 )
1218 height = Standard_Integer ( atof ( pSize ) / myPixelToUnit );
1219 if ( height == 0 )
1220 height = Standard_Integer ( fontStyle.Size () / myPixelToUnit );
1221 pSize = left + lstrlenA ( left );
1222 *pSize = '-';
1223 lstrcpyA ( right, pSize );
1224 } else lstrcatA ( right,left );
1225 } // end switch
1226 height = Standard_Integer ( height * W32_TextFactor );
1227 ltoa ( height, left, 10 );
1228 lstrcatA ( left, right );
1229 fmEntry = new WNT_FontMapEntry ( left );
1230 if ( fontStyle.CapsHeight () ) {
1231 double r;
1232 TEXTMETRIC tm;
1233 SelectFont( hdc, fmEntry -> HFont () );
1234 GetTextMetrics ( hdc, &tm );
1235 r = tm.tmAscent * tm.tmHeight / ( tm.tmAscent - tm.tmInternalLeading );
1236 lstrcpy ( right, strchr ( left, '-' ) );
1237 ltoa ( LONG( r + 0.5 ), left, 10 );
1238 lstrcatA ( left, right );
1239 fmEntry = new WNT_FontMapEntry ( left );
1240 } // end if
1241 myFonts -> SetValue ( i, fmEntry );
1242 } // end for
1243 SelectFont( hdc, hfo );
1244 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1245} // end WNT_WDriver :: InitializeFontMap
1246
1247void WNT_WDriver :: InitializeMarkMap ( const Handle( Aspect_MarkMap )& Markmap )
1248{
1249 Aspect_MarkMapEntry entry;
1250 Standard_Integer i, minindex = IntegerLast(), maxindex = -minindex;
1251 for (i = 1; i <= Markmap->Size (); i++) {
1252 entry = Markmap->Entry (i);
1253 maxindex = Max(maxindex, entry.Index ());
1254 minindex = Min(minindex, entry.Index ());
1255 }
1256
1257 myMarkerIdxs = new TColStd_HArray1OfInteger (minindex, maxindex, -1);
1258 for (i = 1; i <= Markmap->Size (); i++) {
1259 entry = Markmap->Entry (i);
1260 myMarkerIdxs -> SetValue (entry.Index(), i);
1261 }
1262} // end WNT_WDriver :: InitializeMarkMap
1263
1264Standard_Address WNT_WDriver :: InternalOpenBuffer (
1265 const Standard_Integer aRetainBuffer,
1266 const Standard_Boolean aMono,
1267 const Standard_ShortReal aPivotX,
1268 const Standard_ShortReal aPivotY,
1269 const Standard_Integer aColorIndex,
1270 const Standard_Integer aWidthIndex,
1271 const Standard_Integer aTypeIndex,
1272 const Standard_Integer aFontIndex,
1273 const Aspect_TypeOfDrawMode aDrawMode
1274 ) {
1275
1276 PW32_Allocator aNew = NULL;
7fd59977 1277
1278 MyDrawMode = aDrawMode;
1279 aNew = _FindAllocator ( myAllocators, aRetainBuffer );
1280
1281 if ( aNew != NULL )
1282
1283 ClearBuffer ( aRetainBuffer );
1284
1285 else aNew = ( *W32_GetAllocator ) (
1286 aRetainBuffer, ( PW32_Allocator )myAllocators
1287 );
1288
1289 aNew -> myPivot.x = P( aPivotX );
1290 aNew -> myPivot.y = P( aPivotY );
1291
1292 if ( aRetainBuffer ) {
1293
1294 Standard_Address aSave = myAllocator;
1295 myAllocator = ( Standard_Address )aNew;
1296
1297 A -> myFlags |= ( W32F_MONO | W32F_MINIT );
1298 SetLineAttrib ( aColorIndex, aTypeIndex, aWidthIndex );
1299 SetTextAttrib ( aColorIndex, aFontIndex );
1300 SetPolyAttrib ( aColorIndex, -1, Standard_True );
1301 SetMarkerAttrib ( aColorIndex, aWidthIndex, Standard_False );
1302 A -> myFlags &= ~W32F_MINIT;
1303
1304 myAllocator = aSave;
1305
1306 } else A -> myFlags &= ~W32F_MONO;
1307
1308 return aNew;
1309
1310} // end WNT_WDriver :: InternalOpenBuffer
1311
1312Standard_Boolean WNT_WDriver :: OpenBuffer (
1313 const Standard_Integer aRetainBuffer,
1314 const Standard_ShortReal aPivotX,
1315 const Standard_ShortReal aPivotY,
1316 const Standard_Integer aWidthIndex,
1317 const Standard_Integer aColorIndex,
1318 const Standard_Integer aFontIndex,
1319 const Aspect_TypeOfDrawMode aDrawMode
1320 ) {
1321 return ( Standard_Boolean )InternalOpenBuffer (
1322 aRetainBuffer, Standard_True,
1323 aPivotX, aPivotY, aColorIndex, aWidthIndex,
1324 0, aFontIndex, aDrawMode
1325 );
1326
1327} // end WNT_WDriver :: OpenBuffer
1328
1329Standard_Boolean WNT_WDriver :: OpenColorBuffer (
1330 const Standard_Integer aRetainBuffer,
1331 const Standard_ShortReal aPivotX,
1332 const Standard_ShortReal aPivotY,
1333 const Standard_Integer aWidthIndex,
1334 const Standard_Integer aColorIndex,
1335 const Standard_Integer aFontIndex,
1336 const Aspect_TypeOfDrawMode aDrawMode
1337 ) {
1338
1339 return ( Standard_Boolean )InternalOpenBuffer (
1340 aRetainBuffer, Standard_False,
1341 aPivotX, aPivotY, aColorIndex, aWidthIndex,
1342 0, aFontIndex, aDrawMode
1343 );
1344
1345} // end WNT_WDriver :: OpenColorBuffer
1346
1347void WNT_WDriver :: CloseBuffer ( const Standard_Integer aRetainBuffer ) const {
1348
1349 if ( aRetainBuffer ) {
1350
1351 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1352
1353 if ( a != NULL ) {
1354
1355 PW32_Allocator b = ( PW32_Allocator )myAllocators;
1356
1357 while ( b -> myNext != a ) b = b -> myNext;
1358
1359 if ( a -> myFlags & W32F_DRAWN ) EraseBuffer ( aRetainBuffer );
1360
1361 b -> myNext = a -> myNext;
1362
1363 delete a;
1364
1365 } // end if
1366
1367 SelectBuffer ( 0 );
1368
1369 } // end if
1370
1371} // end WNT_WDriver :: CloseBuffer
1372
1373void WNT_WDriver :: ClearBuffer ( const Standard_Integer aRetainBuffer ) const {
1374
1375 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1376
1377 if ( a != NULL ) {
1378
1379 if ( a -> myFlags & W32F_DRAWN ) EraseBuffer ( aRetainBuffer );
1380
1381 a -> ClearBlocks ();
1382
1383 } // end if
1384
1385} // end WNT_WDriver :: ClearBuffer
1386
1387void WNT_WDriver :: DrawBuffer ( const Standard_Integer aRetainBuffer ) const {
1388
1389 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1390
1391 if ( a != NULL ) {
1392
1393 RECT r;
1394 SIZE sz;
1395 HPALETTE hpo = NULL;
1396 HDC hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1397
1398 Handle( WNT_GraphicDevice ) gDev = Handle ( WNT_GraphicDevice ) ::
1399 DownCast ( MyWindow -> GraphicDevice () );
1400
1401 if ( gDev -> IsPaletteDevice () )
1402
1403 hpo = SelectPalette ( hdc, ( HPALETTE )gDev -> HPalette (), FALSE );
1404
1405 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1406 sz.cx = r.right;
1407 sz.cy = r.bottom;
1408
1409 if ( a -> myFlags & W32F_DBUFF ) {
1410 HDC hdcMem = CreateCompatibleDC ( hdc );
1411 HBITMAP hbo = SelectBitmap( hdcMem, ( HBITMAP )myWNTWindow -> HPixmap () );
1412 HPALETTE hpo;
1413
1414 if ( gDev -> IsPaletteDevice () )
1415
1416 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
1417
1418 SetROP2 ( hdcMem, _GetROP2 ( MyDrawMode ) );
1419
1420 a -> Play ( hdcMem, &sz );
1421
1422 BitBlt (
1423 hdc, r.left, r.top, r.right + 1, r.bottom + 1,
1424 hdcMem, r.left, r.top, SRCCOPY
1425 );
1426
1427 if ( gDev -> IsPaletteDevice () ) SelectPalette ( hdcMem, hpo, FALSE );
1428
1429 SelectBitmap( hdcMem, hbo );
1430 DeleteDC ( hdcMem );
1431 } else {
1432 SetROP2 ( hdc, _GetROP2 ( MyDrawMode ) );
1433 a -> Play ( hdc, &sz );
1434 } // end else
1435
1436 if ( hpo != NULL ) SelectPalette( hdc, hpo, FALSE );
1437
1438 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1439
1440 a -> myFlags |= W32F_DRAWN;
1441
1442 } // end if
1443
1444} // end WNT_WDriver :: DrawBuffer
1445
1446void WNT_WDriver :: EraseBuffer ( const Standard_Integer aRetainBuffer ) const {
1447
1448 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1449
1450 if ( a != NULL && ( a -> myFlags & W32F_DRAWN ) ) {
1451
1452 RECT r;
1453
1454 a -> URect ( &r );
1455
1456 if ( !IsRectEmpty ( &r ) ) {
1457
1458 if ( a -> myID != 0 ) {
1459
1460 if ( MyWindow -> BackingStore () )
1461
1462 MyWindow -> RestoreArea (
1463 ( r.left + r.right ) / 2, ( r.top + r.bottom ) / 2,
1464 r.right - r.left + 2, r.bottom - r.top + 2
1465 );
1466
1467 else if ( ( ( PW32_Allocator )myAllocators ) -> myFlags & W32F_DRAWN )
1468
1469 DrawBuffer ( 0 );
1470
1471 else
1472clear:
1473 MyWindow -> ClearArea (
1474 ( r.left + r.right ) / 2, ( r.top + r.bottom ) / 2,
1475 r.right - r.left + 2, r.bottom - r.top + 2
1476 );
1477
1478 } else goto clear;
1479
1480 } // end if
1481
1482 a -> myFlags &= ~W32F_DRAWN;
1483
1484 } // end if
1485
1486} // end WNT_WDriver :: EraseBuffer
1487
1488void WNT_WDriver :: MoveBuffer (
1489 const Standard_Integer aRetainBuffer,
1490 const Standard_ShortReal aPivotX,
1491 const Standard_ShortReal aPivotY
1492 ) const {
1493
1494 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1495
1496 if ( a != NULL ) {
1497
1498 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1499
1500 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1501
1502 a -> myMove.x = P( aPivotX ) - a -> myPivot.x;
1503 a -> myMove.y = P( aPivotY ) - a -> myPivot.y;
1504
1505 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1506
1507 } // end if
1508
1509} // end WNT_WDriver :: MoveBuffer
1510
1511void WNT_WDriver :: ScaleBuffer (
1512 const Standard_Integer aRetainBuffer,
1513 const Quantity_Factor aScaleX,
1514 const Quantity_Factor aScaleY
1515 ) const {
1516
1517 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1518
1519 if ( a != NULL ) {
1520
1521 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1522
1523 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1524
1525 a -> myScaleX = aScaleX;
1526 a -> myScaleY = aScaleY;
1527
1528 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1529
1530 } // end if
1531
1532} // end WNT_WDriver :: ScaleBuffer
1533
1534void WNT_WDriver :: RotateBuffer (
1535 const Standard_Integer aRetainBuffer,
1536 const Quantity_PlaneAngle anAngle
1537 ) const {
1538
1539 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1540
1541 if ( a != NULL ) {
1542
1543 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1544
1545 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1546
1547 a -> myAngle = anAngle;
1548
1549 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1550
1551 } // end if
1552
1553} // end WNT_WDriver :: RotateBuffer
1554
1555void WNT_WDriver :: WorkSpace ( Quantity_Length& Width, Quantity_Length& Heigth ) const {
1556
1557 RECT r;
1558
1559 GetClientRect ( ( HWND )( myWNTWindow -> HWindow () ), &r );
1560
1561 Width = U( r.right );
1562 Heigth = U( r.bottom );
1563
1564} // end WNT_WDriver :: WorkSpace
1565
1566Quantity_Length WNT_WDriver :: Convert ( const Standard_Integer PV ) const {
1567
1568 return U( PV );
1569
1570} // end WNT_WDriver :: Convert
1571
1572Standard_Integer WNT_WDriver :: Convert ( const Quantity_Length DV ) const {
1573
1574 return P( DV );
1575
1576} // end WNT_WDriver :: Convert
1577
1578void WNT_WDriver :: Convert (
1579 const Standard_Integer PX,
1580 const Standard_Integer PY,
1581 Quantity_Length& DX,
1582 Quantity_Length& DY
1583 ) const {
1584
1585 RECT r;
1586 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1587
1588 DX = U( PX );
1589 DY = U( r.bottom - PY );
1590
1591} // end WNT_WDriver :: Convert
1592
1593void WNT_WDriver :: Convert (
1594 const Quantity_Length DX,
1595 const Quantity_Length DY,
1596 Standard_Integer& PX,
1597 Standard_Integer& PY
1598 ) const {
1599
1600 RECT r;
1601 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1602
1603 PX = P( DX );
1604 PY = r.bottom - P( DY );
1605
1606} // end WNT_WDriver :: Convert
1607
1608Standard_Integer WNT_WDriver :: ProcessColorIndex (
1609 const Standard_Integer ColorIndex
1610 ) const {
1611
1612 if ( !SA ) return A -> myPointColor;
1613
1614 if ( myColors.IsNull () ) return ( Standard_Integer )RGB( 0, 0, 0 );
1615
1616 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
1617 DownCast ( MyWindow -> GraphicDevice () );
1618
1619 if ( ColorIndex <= 0 ) {
1620
1621 if ((A -> myFlags & W32F_MONO) && (A -> myFlags & W32F_MINIT)) {
1622 return RGB(255, 255, 255);
1623 } else {
1624 LOGBRUSH lb;
1625 GetObject ( myWNTWindow -> HBackground(), sizeof ( LOGBRUSH ), &lb );
1626 return lb.lbColor;
1627 }
1628
1629 } else
1630
1631 switch ( MyDrawMode ) {
1632
1633 default :
1634 case Aspect_TODM_REPLACE :
1635
1636 if (ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper())
1637 return myColors -> Value ( myColors->Lower() );
1638 return myColors -> Value ( ColorIndex );
1639
1640 case Aspect_TODM_ERASE :
1641
1642 return gDev -> SetColor ( MyWindow -> Background ().Color () );
1643
1644 case Aspect_TODM_XORLIGHT :
1645 case Aspect_TODM_XOR :
1646
1647 return gDev -> HighlightColor ();
1648
1649 } // end switch
1650
1651} // end WNT_WDriver :: ProcessColorIndex
1652
1653Quantity_Length WNT_WDriver :: ProcessWidthIndex (
1654 const Standard_Integer WidthIndex
1655 ) const
1656{
1657 Standard_Integer theIndex = WidthIndex;
1658 if (WidthIndex < myWidthIdxs->Lower() || WidthIndex > myWidthIdxs->Upper())
1659 theIndex = myWidthIdxs->Lower();
1660
1661 Aspect_WidthMapEntry Entry = WidthMap () -> Entry ( myWidthIdxs -> Value(theIndex) );
1662 return ( Entry.Type () == Aspect_WOL_THIN ) ?
1663 ( Quantity_Length )0.0 : Entry.Width () / myPixelToUnit;
1664} // end WNT_WDriver :: ProcessWidthIndex
1665
1666Standard_Integer WNT_WDriver :: ProcessTypeIndex (
1667 const Standard_Integer TypeIndex
1668 ) const{
1669
1670 return ( TypeMap () -> Entry ( TypeIndex + 1 ).Type ().Style () == Aspect_TOL_SOLID ) ?
1671 0 : PS_USERSTYLE;
1672
1673} // end WNT_WDriver :: ProcessTypeIndex
1674
1675Standard_Boolean WNT_WDriver :: BufferIsOpen (
1676 const Standard_Integer aRetainBuffer
1677 ) const {
1678
1679 return ( _FindAllocator ( myAllocators, aRetainBuffer) != NULL ?
1680 Standard_True : Standard_False
1681 );
1682
1683} // end WNT_WDriver :: BufferIsOpen
1684
1685Standard_Boolean WNT_WDriver :: BufferIsEmpty (
1686 const Standard_Integer aRetainBuffer
1687 ) const {
1688
1689 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1690
1691 if ( a != NULL )
1692
1693 return ( a -> myFlags & W32F_EMPTY ) ? Standard_True : Standard_False;
1694
1695 return Standard_True;
1696
1697} // end WNT_WDriver :: BufferIsEmpty
1698
1699Standard_Boolean WNT_WDriver :: BufferIsDrawn (
1700 const Standard_Integer aRetainBuffer
1701 ) const {
1702
1703 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1704
1705 if ( a != NULL )
1706
1707 return ( a -> myFlags & W32F_DRAWN ) ? Standard_True : Standard_False;
1708
1709 return Standard_False;
1710
1711} // end WNT_WDriver :: BufferIsDrawn
1712
1713void WNT_WDriver :: AngleOfBuffer (
1714 const Standard_Integer aRetainBuffer,
1715 Quantity_PlaneAngle& anAngle
1716 ) const {
1717
1718 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1719
1720 if ( a != NULL ) anAngle = a -> myAngle;
1721
1722} // end WNT_WDriver :: AngleOfBuffer
1723
1724void WNT_WDriver :: ScaleOfBuffer (
1725 const Standard_Integer aRetainBuffer,
1726 Quantity_Factor& aScaleX,
1727 Quantity_Factor& aScaleY
1728 ) const {
1729
1730 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1731
1732 if ( a != NULL ) {
1733
1734 aScaleX = a -> myScaleX;
1735 aScaleY = a -> myScaleY;
1736
1737 } // end if
1738
1739} // end WNT_WDriver :: ScaleOfBuffer
1740
1741void WNT_WDriver :: PositionOfBuffer (
1742 const Standard_Integer aRetainBuffer,
1743 Standard_ShortReal& aPivotX,
1744 Standard_ShortReal& aPivotY
1745 ) const {
1746
1747 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1748
1749 if ( a != NULL ) {
1750
1751 aPivotX = Standard_ShortReal ( U( a -> myPivot.x + a -> myMove.x ) );
1752 aPivotY = Standard_ShortReal ( U( a -> myPivot.y + a -> myMove.y ) );
1753
1754 } // end if
1755
1756} // end WNT_WDriver :: PositionOfBuffer
1757
1758void WNT_WDriver :: TextSize (
1759 const TCollection_ExtendedString& aText,
1760 Standard_ShortReal& aWidth,
1761 Standard_ShortReal& aHeight,
1762 const Standard_Integer aFontIndex
1763 ) const {
1764#ifdef PRO17381
1765if( aText.Length() <= 0 ) {
1766 aWidth = aHeight = 0.;
1767 return;
1768}
1769#endif
1770
1771 Standard_ShortReal xoffset, yoffset;
1772/*====================== MFT ====================*/
1773#ifdef MFT
1774 if ( UseMFT() )
1775 TextSize (aText, aWidth, aHeight, xoffset, yoffset, aFontIndex);
1776 else {
1777#endif
1778/*====================== MFT ====================*/
1779
1780 char* str = _ConvertU2F ( aText );
1781
1782 TextSize ( str, aWidth, aHeight, xoffset, yoffset, aFontIndex );
1783
1784 HeapFree ( GetProcessHeap (), 0, str );
1785
1786/*====================== MFT ====================*/
1787#ifdef MFT
1788 }
1789#endif
1790/*====================== MFT ====================*/
1791} // end WNT_WDriver :: TextSize
1792
1793void WNT_WDriver :: TextSize (
1794 const TCollection_ExtendedString& aText,
1795 Standard_ShortReal& aWidth,
1796 Standard_ShortReal& aHeight,
1797 Standard_ShortReal& anXoffset,
1798 Standard_ShortReal& anYoffset,
1799 const Standard_Integer aFontIndex
1800 ) const {
1801#ifdef PRO17381
1802if( aText.Length() <= 0 ) {
1803 aWidth = aHeight = anXoffset = anYoffset = 0.;
1804 return;
1805}
1806#endif
1807
1808/*====================== MFT ====================*/
1809#ifdef MFT
1810 if ( UseMFT() ) {
1811 Standard_Integer aFont = (aFontIndex < 0 ?
1812 (int)A->myTextFont : aFontIndex);
1813 Handle(MFT_FontManager) theFontManager =
1814 ((WNT_WDriver *const)(this))->MFT_Font(aFont);
1815 Standard_Real theWidth = 0.,theAscent = 0.,
1816 theLbearing = 0.,theDescent = 0.;
1817 if (aText.IsAscii()) {
1818 TCollection_AsciiString ascii (aText,'?');
1819 theFontManager->TextSize(ascii.ToCString(), theWidth,
1820 theAscent, theLbearing, theDescent);
1821 } else if (theFontManager->IsComposite()) {
1822 theFontManager->TextSize(aText.ToExtString(), theWidth,
1823 theAscent, theLbearing, theDescent);
1824 }
1825 theDescent = Max(
1826 theDescent, (A->myFlags & W32F_TULIN ?
1827 theFontManager->UnderlinePosition() : 0.));
1828 aWidth = Standard_ShortReal (theWidth );
1829 aHeight = Standard_ShortReal (theAscent + theDescent);
1830 anXoffset = Standard_ShortReal (theLbearing );
1831 anYoffset = Standard_ShortReal (theDescent );
1832 } else {
1833#endif
1834 char* str = ( char* )_ConvertU2F ( aText );
1835
1836 HDC hdc;
1837 HFONT hfo;
1838 SIZE sz;
1839 int xo;
1840
1841 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1842 hfo = SelectFont(
1843 hdc,
1844 aFontIndex < 0 ? A -> myTextFont : ( HFONT )myFonts -> Value ( aFontIndex ) -> HFont ()
1845 );
1846
1847 xo = A -> TextSize ( hdc, str, &sz );
1848 aWidth = Standard_ShortReal ( U( sz.cx ) );
1849 aHeight = Standard_ShortReal ( U( sz.cy ) );
1850
1851 anXoffset = Standard_ShortReal ( U( xo ) );
1852 anYoffset = Standard_ShortReal ( 0.0 );
1853
1854 SelectFont( hdc, hfo );
1855 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1856
1857 HeapFree ( GetProcessHeap (), 0, str );
1858
1859/*====================== MFT ====================*/
1860#ifdef MFT
1861 }
1862#endif
1863/*====================== MFT ====================*/
1864} // end WNT_WDriver :: TextSize
1865
1866void WNT_WDriver :: TextSize (
1867 const Standard_CString aText,
1868 Standard_ShortReal& aWidth,
1869 Standard_ShortReal& aHeight,
1870 Standard_ShortReal& anXoffset,
1871 Standard_ShortReal& anYoffset,
1872 const Standard_Integer aFontIndex
1873 ) const {
1874#ifdef PRO17381
1875if( !aText || (strlen(aText) <= 0) ) {
1876 aWidth = aHeight = anXoffset = anYoffset = 0.;
1877 return;
1878}
1879#endif
1880
1881/*====================== MFT ====================*/
1882#ifdef MFT
1883 if ( UseMFT() ) {
1884 TCollection_ExtendedString extText (aText);
1885 TextSize (extText, aWidth, aHeight, anXoffset, anYoffset, aFontIndex);
1886 } else {
1887#endif
1888/*====================== MFT ====================*/
1889 HDC hdc;
1890 HFONT hfo;
1891 SIZE sz;
1892 int xo;
1893
1894 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1895 hfo = SelectFont(
1896 hdc,
1897 aFontIndex < 0 ? A -> myTextFont : ( HFONT )myFonts -> Value ( aFontIndex ) -> HFont ()
1898 );
1899
1900 xo = A -> TextSize ( hdc, (Standard_PCharacter)aText, &sz );
1901 aWidth = Standard_ShortReal ( U( sz.cx ) );
1902 aHeight = Standard_ShortReal ( U( sz.cy ) );
1903
1904 anXoffset = Standard_ShortReal ( U( xo ) );
1905 anYoffset = Standard_ShortReal ( 0.0 );
1906
1907 SelectFont( hdc, hfo );
1908 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1909/*====================== MFT ====================*/
1910#ifdef MFT
1911 }
1912#endif
1913/*====================== MFT ====================*/
1914} // end WNT_WDriver :: TextSize
1915
1916Standard_CString WNT_WDriver :: FontSize (
1917 Quantity_PlaneAngle& aSlant,
1918 Standard_ShortReal& aSize,
1919 Standard_ShortReal& aBheight,
1920 const Standard_Integer aFontIndex
1921 ) const {
1922
1923/*====================== MFT ====================*/
1924#ifdef MFT
1925 if ( UseMFT() ) {
1926 Standard_CString fstring;
1927 Standard_Integer aFont = (aFontIndex < 0 ?
1928 (int)A->myTextFont : aFontIndex);
1929 Handle(MFT_FontManager) theFontManager =
1930 myMFTFonts->Value (aFont);
1931 Quantity_Length theWidth, theHeight, theDescent;
1932 Quantity_PlaneAngle theSlant;
1933 Quantity_Factor thePrecision;
1934 Standard_Boolean theCapsHeight;
1935 fstring = theFontManager->FontAttribs (
1936 theWidth, theHeight, theDescent, theSlant, thePrecision, theCapsHeight
1937 );
1938 aSize = (Standard_ShortReal)theHeight;
1939 aBheight = (Standard_ShortReal)theDescent;
1940 aSlant = theSlant;
1941 return fstring;
1942 } else {
1943#endif
1944/*====================== MFT ====================*/
1945 if (aFontIndex < 0)
1946 aSize = Standard_ShortReal ( U(myFonts->Value(0)->myLogFont.lfHeight) );
1947 else
1948 aSize = Standard_ShortReal ( U(myFonts->Value(aFontIndex)->myLogFont.lfHeight) );
1949 aSize = Standard_ShortReal ( aSize / W32_TextFactor );
1950 aSlant = aFontIndex < 0 ? A -> myTextSlant : 0.0;
1951 aBheight = 0.0F;
1952
1953 return aFontIndex < 0 ? "" : myFonts->Value(aFontIndex)->myLogFont.lfFaceName;
1954/*====================== MFT ====================*/
1955#ifdef MFT
1956 }
1957#endif
1958/*====================== MFT ====================*/
1959} // end WNT_WDriver :: FontSize
1960
1961void WNT_WDriver :: ColorBoundIndexs (
1962 Standard_Integer& aMinIndex,
1963 Standard_Integer& aMaxIndex
1964 ) const {
1965
1966 if ( myColors.IsNull () ) {
1967
1968 aMinIndex =
1969 aMaxIndex = 0;
1970
1971 } else {
1972
1973 aMinIndex = 1;
1974 aMaxIndex = myColors -> Length ();
1975
1976 } // end else
1977
1978} // end WNT_WDriver :: ColorBoundIndexs
1979
1980Standard_Integer WNT_WDriver :: LocalColorIndex (
1981 const Standard_Integer anIndex
1982 ) const {
1983
1984 return ( anIndex < 1 || anIndex > myColors -> Length () ) ? -1 : anIndex;
1985
1986} // end WNT_WDriver :: LocalColorIndex
1987
1988void WNT_WDriver :: FontBoundIndexs (
1989 Standard_Integer& aMinIndex,
1990 Standard_Integer& aMaxIndex
1991 ) const {
1992
1993 if ( myFonts.IsNull () ) {
1994
1995 aMinIndex =
1996 aMaxIndex = 0;
1997
1998 } else {
1999
2000 aMinIndex = 1;
2001 aMaxIndex = myFonts -> Length ();
2002
2003 } // end else
2004
2005} // end WNT_WDriver :: FontBoundIndexs
2006
2007Standard_Integer WNT_WDriver :: LocalFontIndex (
2008 const Standard_Integer anIndex
2009 ) const {
2010
2011 return ( anIndex < 1 || anIndex > myFonts -> Length () ) ? -1 : anIndex;
2012
2013} // end WNT_WDriver :: LocalFontIndex
2014
2015void WNT_WDriver :: TypeBoundIndexs (
2016 Standard_Integer& aMinIndex,
2017 Standard_Integer& aMaxIndex
2018 ) const {
2019
2020 if ( TypeMap ().IsNull () ) {
2021
2022 aMinIndex =
2023 aMaxIndex = 0;
2024
2025 } else {
2026
2027 aMinIndex = 1;
2028 aMaxIndex = TypeMap () -> Size ();
2029
2030 } // end else
2031
2032} // end WNT_WDriver :: TypeBoundIndexs
2033
2034Standard_Integer WNT_WDriver :: LocalTypeIndex (
2035 const Standard_Integer anIndex
2036 ) const {
2037
2038 return ( anIndex < 1 || anIndex > TypeMap () -> Size () ) ? -1 : anIndex;
2039
2040} // end WNT_WDriver :: LocalTypeIndex
2041
2042void WNT_WDriver :: WidthBoundIndexs (
2043 Standard_Integer& aMinIndex,
2044 Standard_Integer& aMaxIndex
2045 ) const {
2046
2047 if ( WidthMap ().IsNull () ) {
2048
2049 aMinIndex =
2050 aMaxIndex = 0;
2051
2052 } else {
2053
2054 aMinIndex = 1;
2055 aMaxIndex = WidthMap () -> Size ();
2056
2057 } // end else
2058
2059} // end WNT_WDriver :: WidthBoundIndexs
2060
2061Standard_Integer WNT_WDriver :: LocalWidthIndex (
2062 const Standard_Integer anIndex
2063 ) const {
2064
2065 return ( anIndex < 1 || anIndex > WidthMap () -> Size () ) ? -1 : anIndex;
2066
2067} // end WNT_WDriver :: LocalWidthIndex
2068
2069void WNT_WDriver :: MarkBoundIndexs (
2070 Standard_Integer& aMinIndex,
2071 Standard_Integer& aMaxIndex
2072 ) const {
2073
2074 if ( MarkMap ().IsNull () ) {
2075
2076 aMinIndex =
2077 aMaxIndex = 0;
2078
2079 } else {
2080
2081 aMinIndex = 1;
2082 aMaxIndex = MarkMap () -> Size ();
2083
2084 } // end else
2085
2086} // end WNT_WDriver :: MarkBoundIndexs
2087
2088Standard_Integer WNT_WDriver :: LocalMarkIndex (
2089 const Standard_Integer anIndex
2090 ) const {
2091
2092 return ( anIndex < 1 || anIndex > MarkMap () -> Size () ) ? -1 : anIndex;
2093
2094} // end WNT_WDriver :: LocalMarkIndex
2095
2096const Handle(WNT_TextManager)& WNT_WDriver :: TextManager ()
2097{
2098 return (myTextManager);
2099} // end WNT_WDriver :: TextManager
2100
2101const Handle(MFT_FontManager)& WNT_WDriver :: MFT_Font
2102 (const Standard_Integer anIndex)
2103{
2104 return myMFTFonts->Value(anIndex);
2105} // end WNT_WDriver :: MFT_FontList
2106
2107Standard_ShortReal WNT_WDriver :: MFT_Size
2108 (const Standard_Integer anIndex)
2109{
2110 return myMFTSizes->Value(anIndex);
2111} // end WNT_WDriver :: MFT_SizeList
2112
2113static PW32_Allocator __fastcall _FindAllocator ( Standard_Address p, Standard_Integer id ) {
2114
2115 while ( p != NULL && ( ( PW32_Allocator )p ) -> myID != id )
2116
2117 p = ( ( PW32_Allocator )p ) -> myNext;
2118
2119 return ( PW32_Allocator )p;
2120
2121} // end _FindAllocator
2122
2123static int __fastcall _GetROP2 ( Aspect_TypeOfDrawMode tdm ) {
2124
2125 int retVal;
2126
2127 switch ( tdm ) {
2128
2129 case Aspect_TODM_ERASE:
2130 case Aspect_TODM_REPLACE:
2131 default:
2132
2133 retVal = R2_COPYPEN;
2134
2135 break;
2136
2137 case Aspect_TODM_XOR:
2138 case Aspect_TODM_XORLIGHT:
2139
2140 retVal = R2_XORPEN;
2141
2142 break;
2143
2144 } // end switch
2145
2146 return retVal;
2147
2148} // end _GetROP2
2149
2150static void WINAPI _SetPoint ( int s, int m, int set, LPPOINT p, int* n, void* param ) {
2151
2152 PMPARAM pmp = ( PMPARAM )param;
2153
2154 *n = 0;
2155
2156 for ( int i = 0; i < m; ++i, ++( *n ), ++s ) {
2157
2158 p[ i ].x = LONG ( pmp -> s -> XValues ().Value ( s ) * pmp -> w / 2.0 + 0.5 );
2159 p[ i ].y = LONG ( pmp -> s -> YValues ().Value ( s ) * pmp -> h / 2.0 + 0.5 );
2160
2161 } // end for
2162
2163} // end _SetPoint
2164
2165static char* __fastcall _ConvertU2F ( const TCollection_ExtendedString& str ) {
2166
2167 char* retVal;
2168 Standard_Integer szBuff = ( str.Length () << 2 );
2169
2170 retVal = ( char* )HeapAlloc (
2171 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS,
2172 szBuff
2173 );
2174
2175 while ( !Resource_Unicode :: ConvertUnicodeToFormat ( str, retVal, szBuff ) ) {
2176
2177 szBuff <<= 1;
2178 retVal = ( char* )HeapReAlloc (
2179 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS,
2180 retVal, szBuff
2181 );
2182
2183 } // end while
2184
2185 return retVal;
2186
2187} // end _ConvertU2F