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
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.
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.
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.
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'
25 // include windows.h first to have all definitions available
28 #define MFT // Study S3553
30 #define PRO17334 //GG_060199
31 // SetXxxAttrib() must raise when index is wrong
32 // Idem for DrawMarker()
34 #define PRO17381 //GG_080199
35 // Protection : Do nothing when NULL string is found in TextSize
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
41 #include <WNT_WDriver.ixx>
43 #include <WNT_GraphicDevice.hxx>
44 #include <WNT_ImageManager.hxx>
45 #include <WNT_Image.hxx>
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>
56 #include <TColStd_Array1OfBoolean.hxx>
57 #include <TColQuantity_Array1OfLength.hxx>
58 #include <Resource_Unicode.hxx>
62 #include "W32_Allocator.hxx"
64 #define A ( ( PW32_Allocator )myAllocator )
65 #define SA ( !( A -> myFlags & W32F_MONO ) || \
66 ( ( A -> myFlags & W32F_MONO ) && ( A -> myFlags & W32F_MINIT ) ) \
69 /*====================== MFT ====================*/
71 #include <Aspect_Units.hxx>
72 #include "WNT_MFTDraw.hxx"
74 /*====================== MFT ====================*/
76 typedef struct _m_param {
78 Aspect_MarkerStyle* s;
92 extern double W32_TextFactor;
93 static PW32_Allocator __fastcall _FindAllocator ( Standard_Address, Standard_Integer );
94 static int __fastcall _GetROP2 ( Aspect_TypeOfDrawMode );
95 static char* __fastcall _ConvertU2F ( const TCollection_ExtendedString& );
97 static void WINAPI _SetPoint ( int, int, int, LPPOINT, int*, void* );
99 WNT_WDriver :: WNT_WDriver ( const Handle( WNT_Window )& aWindow ) :
100 Aspect_WindowDriver ( aWindow ) {
103 Standard_Integer pXSize, pYSize;
104 Quantity_Length dXSize, dYSize;
106 Handle( WNT_GraphicDevice ) gDev = Handle ( WNT_GraphicDevice ) ::
107 DownCast ( MyWindow -> GraphicDevice () );
109 gDev -> DisplaySize ( pXSize, pYSize );
110 gDev -> DisplaySize ( dXSize, dYSize );
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;
117 /*====================== MFT ====================*/
119 myTextManager = new WNT_TextManager (myPixelToUnit);
121 /*====================== MFT ====================*/
123 wd = (WINDOW_DATA* )GetWindowLongPtr ((HWND )aWindow->HWindow(), GWLP_USERDATA);
124 wd->WNT_WDriver_Ptr = (void* )this;
128 void WNT_WDriver :: Destroy () {
132 myAllocator = ( ( PW32_Allocator )myAllocators ) -> myNext;
134 delete ( PW32_Allocator )myAllocators;
136 myAllocators = ( PW32_Allocator )myAllocator;
138 } while ( myAllocators != NULL );
140 } // end WNT_WDriver :: Destroy
142 Standard_Address WNT_WDriver :: SelectBuffer (
143 const Standard_Integer aRetainBuffer
146 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
148 if ( a != NULL ) *( ( Standard_Address* )&myAllocator ) = ( Standard_Address )a;
152 } // end WNT_WDriver :: SelectBuffer
154 void WNT_WDriver :: BeginDraw (
155 const Standard_Boolean aDoubleBuffer,
156 const Standard_Integer aRetainBuffer
159 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
163 if ( aDoubleBuffer ) {
165 MyWindow -> SetDoubleBuffer ( aDoubleBuffer );
166 a -> myFlags |= W32F_DBUFF;
168 } else a -> myFlags &= ~W32F_DBUFF;
174 a -> myFlags |= W32F_START;
175 a -> myFlags &= ~W32F_DVDRV;
177 SelectBuffer ( aRetainBuffer );
181 } // end WNT_WDriver :: BeginDraw
183 void WNT_WDriver :: EndDraw ( const Standard_Boolean aSynchronize ) {
185 ( ( PW32_Allocator )myAllocator ) -> myFlags &= ~W32F_START;
187 DrawBuffer ( ( ( PW32_Allocator )myAllocator ) -> myID );
189 } // end WNT_WDriver :: EndDraw
191 Aspect_TypeOfResize WNT_WDriver :: ResizeSpace () {
193 return myWNTWindow -> DoResize ();
195 } // end WNT_WDriver :: ResizeSpace
197 Standard_Boolean WNT_WDriver :: SetHighlightColor (
198 const Standard_Integer aColorIdx
201 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
202 DownCast ( MyWindow -> GraphicDevice () );
205 ColorMap () -> Entry ( aColorIdx + 1 ).Color (), Standard_True
208 return Standard_True;
210 } // end WNT_WDriver :: SetHighlightColor
212 void WNT_WDriver :: SetDrawMode ( const Aspect_TypeOfDrawMode aMode ) {
216 } // end WNT_WDriver :: SetDrawMode
218 void WNT_WDriver :: SetLineAttrib (
219 const Standard_Integer ColorIndex,
220 const Standard_Integer TypeIndex,
221 const Standard_Integer WidthIndex
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") ;
235 Aspect_LineStyle Entry = TypeMap () -> Entry ( myTypeIdxs -> Value(TypeIndex) ).Type ();
237 Standard_Integer theIndex = TypeIndex;
238 if (TypeIndex < myTypeIdxs->Lower() || TypeIndex > myTypeIdxs->Upper())
239 theIndex = myTypeIdxs->Lower();
241 Aspect_LineStyle Entry = TypeMap () -> Entry ( myTypeIdxs -> Value(theIndex) ).Type ();
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 };
248 Standard_Integer Lower = Entry.Values ().Lower ();
249 Standard_Integer Count = Entry.Values ().Length ();
250 PDWORD dwStyle = ( PDWORD )HeapAlloc (
252 HEAP_GENERATE_EXCEPTIONS,
253 Count * sizeof ( DWORD )
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;
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
264 void WNT_WDriver :: SetTextAttrib (
265 const Standard_Integer ColorIndex,
266 const Standard_Integer FontIndex
269 SetTextAttrib ( ColorIndex, FontIndex, 0.0, 1.0, 0.0,Standard_False );
270 } // end WNT_WDriver :: SetTextAttrib
272 void 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
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") ;
292 Handle( WNT_FontMapEntry ) fmEntry = myFonts -> Value ( FontIndex );
293 /*====================== MFT ====================*/
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)
305 (HFONT)FontIndex, ProcessColorIndex ( ColorIndex ), aSlant,
306 aHScale, ( aWScale > 0.0 ? aWScale : aHScale ),
307 isUnderlined, Standard_False, Standard_True
311 /*====================== MFT ====================*/
313 hFont = ( HFONT )fmEntry-> HFont (),
314 sizeof ( LOGFONT ), &lf
317 if ( isUnderlined && !lf.lfUnderline ) {
318 FONT_DATA fd = { TRUE };
319 hFont = ( HFONT )fmEntry -> SetAttrib ( faUnderlined, &fd );
324 hFont, ProcessColorIndex ( ColorIndex ), aSlant,
325 aHScale / W32_TextFactor,
326 ( aWScale > 0.0 ? aWScale : aHScale ) / W32_TextFactor,
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 );
342 /*====================== MFT ====================*/
346 /*====================== MFT ====================*/
347 } // end WNT_WDriver :: SetTextAttrib
349 void WNT_WDriver :: SetPolyAttrib (
350 const Standard_Integer ColorIndex,
351 const Standard_Integer TileIndex,
352 const Standard_Boolean DrawEdgeFlag
356 if( myColors.IsNull() ||
357 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
358 Aspect_DriverError::Raise ("Bad Color Index") ;
361 LOGBRUSH lb = { TileIndex < 0 ? BS_NULL : BS_SOLID, ProcessColorIndex ( ColorIndex ), 0 };
362 A -> PolyAttrib ( &lb, DrawEdgeFlag );
363 } // end WNT_WDriver :: SetPolyAttrib
365 void WNT_WDriver :: SetPolyAttrib (
366 const Standard_Integer ColorIndex,
367 const Standard_Integer TileIndex,
368 const Standard_Integer PolygonMode,
369 const Standard_Boolean DrawEdgeFlag
373 if( myColors.IsNull() ||
374 ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper() )
375 Aspect_DriverError::Raise ("Bad Color Index") ;
378 LOGBRUSH lb = { BS_SOLID, ProcessColorIndex ( ColorIndex ), 0 };
379 A -> PolyAttrib ( &lb, DrawEdgeFlag, PolygonMode );
380 } // end WNT_WDriver :: SetPolyAttrib
382 void WNT_WDriver :: SetMarkerAttrib (
383 const Standard_Integer ColorIndex,
384 const Standard_Integer EdgeWidthIndex,
385 const Standard_Boolean FillMarker
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") ;
398 ProcessColorIndex ( ColorIndex ),
399 DWORD( ProcessWidthIndex ( EdgeWidthIndex ) + 0.5 ),
402 } // end WNT_WDriver :: SetMarkerAttrib
404 Standard_Boolean WNT_WDriver :: IsKnownImage (
405 const Handle( Standard_Transient )& anImage
408 return myWNTWindow -> myImages -> Index ( ::HashCode (anImage, IntegerLast())
409 ) ? Standard_True : Standard_False;
410 } // end WNT_WDriver :: IsKnownImage
412 Standard_Boolean WNT_WDriver :: SizeOfImageFile (
413 const Standard_CString anImageFile,
414 Standard_Integer& aWidth,
415 Standard_Integer& aHeight
417 #ifndef BUG //Sets the size to 0 when the image file is not found.
418 aWidth = 0; aHeight = 0;
421 Standard_Integer i = myWNTWindow -> myImages -> Load ( anImageFile );
423 if ( i ) myWNTWindow -> myImages -> Dim ( i, aWidth, aHeight );
425 return i ? Standard_True : Standard_False;
427 } // end WNT_WDriver :: SizeOfImageFile
429 void WNT_WDriver :: ClearImage ( const Handle( Standard_Transient )& anImageId ) {
431 Standard_Integer i = myWNTWindow -> myImages -> Index (
432 ::HashCode (anImageId, IntegerLast())
435 if ( i ) myWNTWindow -> myImages -> Discard ( i );
437 } // end WNT_WDriver :: ClearImage
439 void WNT_WDriver :: ClearImageFile ( const Standard_CString anImageFile ) {
441 Standard_Integer i = myWNTWindow -> myImages -> Load ( anImageFile );
443 if ( i ) myWNTWindow -> myImages -> Discard ( i );
445 } // end WNT_WDriver :: ClearImageFile
447 void WNT_WDriver :: DrawImage (
448 const Handle( Standard_Transient )& anImageId,
449 const Standard_ShortReal aX,
450 const Standard_ShortReal aY
453 Standard_Integer i = myWNTWindow -> myImages -> Index (
454 ::HashCode (anImageId, IntegerLast())
457 if ( i ) A -> Image (
459 ( PW32_Bitmap )myWNTWindow -> myImages -> Image ( i ) -> Image ()
462 } // end WNT_WDriver :: DrawImage
464 void WNT_WDriver :: DrawImageFile (
465 const Standard_CString anImageFile,
466 const Standard_ShortReal aX,
467 const Standard_ShortReal aY,
468 const Quantity_Factor aScale
471 int i = myWNTWindow -> myImages -> Load ( anImageFile );
479 pBmp = ( PW32_Bitmap )HeapAlloc (
481 HEAP_GENERATE_EXCEPTIONS,
482 sizeof ( W32_Bitmap )
484 pBmp -> hBmp = ( HBITMAP )myWNTWindow -> myImages -> Scale ( i, aScale, aScale );
489 pBmp = ( PW32_Bitmap )myWNTWindow -> myImages -> Image ( i ) -> Image ();
491 A -> Image ( P( aX ), P( aY ), pBmp );
495 } // end WNT_WDriver :: DrawImageFile
497 void 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
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 () );
515 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
516 hdcMem = CreateCompatibleDC ( hdc );
518 if ( gDev -> IsPaletteDevice () )
520 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
522 i = myWNTWindow -> myImages -> Index (
523 h = ::HashCode (anImageId, IntegerLast())
526 if ( i == 0 ) i = myWNTWindow -> myImages -> Open ( hdc, Width, Height, h );
528 if ( Width > 0 && Height > 0 ) {
530 Standard_Integer iX, iY;
531 Standard_Real sX, sY;
533 myWNTWindow -> myImages -> Dim ( i, iX, iY );
535 if ( iX != Width || iY != Height ) {
537 sX = Width / ( Standard_Real )iX;
538 sY = Height / ( Standard_Real )iY;
540 myWNTWindow -> myImages -> Scale ( i, sX, sY, Standard_True );
545 hdcMem, ( HBITMAP )myWNTWindow -> myImages -> ImageHandle ( i )
548 for ( int i = 0; i < Height; ++i )
550 for ( int j = 0; j < Width; ++j, ++p ) {
552 color.SetValues ( p -> r, p -> g, p -> b, Quantity_TOC_RGB );
553 SetPixel ( hdcMem, j, i, gDev -> SetColor ( color ) );
557 SelectBitmap( hdcMem, hbo );
561 if ( hpo != NULL ) SelectPalette ( hdcMem, hpo, FALSE );
564 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
566 DrawImage ( anImageId, aX, aY );
568 } // end WNT_WDriver :: FillAndDrawImage
570 void 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
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 () );
589 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
590 hdcMem = CreateCompatibleDC ( hdc );
592 if ( gDev -> IsPaletteDevice () )
594 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
596 i = myWNTWindow -> myImages -> Index (
597 h = ::HashCode (anImageId, IntegerLast())
600 if ( i == 0 ) i = myWNTWindow -> myImages -> Open ( hdc, Width, Height, h );
602 if ( Width > 0 && Height > 0 ) {
604 Standard_Integer iX, iY;
605 Standard_Real sX, sY;
607 myWNTWindow -> myImages -> Dim ( i, iX, iY );
609 if ( iX != Width || iY != Height ) {
611 sX = Width / ( Standard_Real )iX;
612 sY = Height / ( Standard_Real )iY;
614 myWNTWindow -> myImages -> Scale ( i, sX, sY, Standard_True );
619 hdcMem, ( HBITMAP )myWNTWindow -> myImages -> ImageHandle ( i )
622 for ( int j = 0; j < Width; ++j, ++p ) {
624 color.SetValues ( p -> r, p -> g, p -> b, Quantity_TOC_RGB );
625 SetPixel ( hdcMem, j, anIndexOfLine, gDev -> SetColor ( color ) );
629 SelectBitmap( hdcMem, hbo );
633 if ( hpo != NULL ) SelectPalette ( hdcMem, hpo, FALSE );
636 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
638 if ( anIndexOfLine == Height - 1 ) DrawImage ( anImageId, aX, aY );
640 } // end WNT_WDriver :: FillAndDrawImage
642 void WNT_WDriver :: DrawPolyline (
643 const TShort_Array1OfShortReal& ListX,
644 const TShort_Array1OfShortReal& ListY
647 Standard_Integer nPts = ListX.Length ();
649 if ( nPts != ListY.Length () )
651 Aspect_DriverError :: Raise ( "DrawPolyline: incorrect argument" );
655 Standard_Integer lX = ListX.Lower ();
656 Standard_Integer lY = ListY.Lower ();
658 if ( A -> myPrimitive != zzNone ) ClosePrimitive ();
660 W32_PolygonNote* p = ( W32_PolygonNote* )( A -> Polyline ( nPts ) );
662 for ( Standard_Integer i = 0; i < nPts; ++i )
665 P( ListX.Value ( lX + i ) ),
666 P( ListY.Value ( lY + i ) )
671 } // end WNT_WDriver :: DrawPolyline
673 void WNT_WDriver :: DrawPolygon (
674 const TShort_Array1OfShortReal& ListX,
675 const TShort_Array1OfShortReal& ListY
678 Standard_Integer nPts = ListX.Length ();
680 if ( nPts != ListY.Length () )
682 Aspect_DriverError :: Raise ( "DrawPolygon: incorrect argument" );
686 Standard_Integer lX = ListX.Lower ();
687 Standard_Integer lY = ListY.Lower ();
689 if ( A -> myPrimitive != zzNone ) ClosePrimitive ();
691 W32_PolygonNote* p = ( W32_PolygonNote* )( A -> Polygon ( nPts ) );
693 for ( Standard_Integer i = 0; i < nPts; ++i )
696 P( ListX.Value ( lX + i ) ),
697 P( ListY.Value ( lY + i ) )
702 } // end WNT_WDriver :: DrawPolygon
704 void WNT_WDriver :: DrawSegment (
705 const Standard_ShortReal X1,
706 const Standard_ShortReal Y1,
707 const Standard_ShortReal X2,
708 const Standard_ShortReal Y2
711 A -> Line ( P( X1 ), P( Y1 ), P( X2 ), P( Y2 ) );
713 } // end WNT_WDriver :: DrawSegment
716 void 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
724 /*====================== MFT ====================*/
728 myAllocator, this, myPixelToUnit,
729 Xpos, Ypos, anAngle, 0., (int)aType,
730 FALSE, TRUE, Text.Length(), NULL
732 CopyMemory (dt.theText, Text.ToExtString(),
733 Text.Length()*sizeof(short));
734 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
735 PW32_FCALLPARAM(&dt) );
738 /*====================== MFT ====================*/
739 char* str = _ConvertU2F ( Text );
741 P( Xpos ), P( Ypos ),
743 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
745 HeapFree ( GetProcessHeap (), 0, str );
746 /*====================== MFT ====================*/
750 /*====================== MFT ====================*/
751 } // end WNT_WDriver :: DrawText
754 void 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
762 /*====================== MFT ====================*/
766 myAllocator, this, myPixelToUnit,
767 Xpos, Ypos, anAngle, 0., (int)aType,
768 FALSE, FALSE, lstrlen(Text), NULL
770 CopyMemory (dt.theText, Text, lstrlen(Text));
771 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
772 PW32_FCALLPARAM(&dt) );
775 /*====================== MFT ====================*/
777 P( Xpos ), P( Ypos ), anAngle, (Standard_Address)Text, FALSE,
778 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
780 } // end WNT_WDriver :: DrawText
782 void 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
791 /*====================== MFT ====================*/
795 myAllocator, this, myPixelToUnit,
796 Xpos, Ypos, anAngle, aMarge, (int)aType,
797 TRUE, TRUE, aText.Length(), NULL
799 CopyMemory (dt.theText, aText.ToExtString(),
800 aText.Length()*sizeof(short));
801 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
802 PW32_FCALLPARAM(&dt) );
805 /*====================== MFT ====================*/
806 char* str = _ConvertU2F ( aText );
808 P( Xpos ), P( Ypos ), anAngle, aMarge, str, FALSE,
809 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
811 HeapFree ( GetProcessHeap (), 0, str );
812 /*====================== MFT ====================*/
816 /*====================== MFT ====================*/
817 } // end WNT_WDriver :: DrawPolyText
819 void 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
828 /*====================== MFT ====================*/
832 myAllocator, this, myPixelToUnit,
833 Xpos, Ypos, anAngle, aMarge, (int)aType,
834 TRUE, FALSE, lstrlen(aText), NULL
836 CopyMemory (dt.theText, aText, lstrlen(aText));
837 A -> FunCall ( _Do_MFTDrawText_, sizeof(MFT_DRAWTEXT),
838 PW32_FCALLPARAM(&dt) );
841 /*====================== MFT ====================*/
843 P( Xpos ), P( Ypos ), anAngle, aMarge, (Standard_Address)aText, FALSE,
844 ( aType == Aspect_TOT_SOLID ) ? FALSE : TRUE
847 } // end WNT_WDriver :: DrawPolyText
849 void WNT_WDriver :: DrawPoint (
850 const Standard_ShortReal X,
851 const Standard_ShortReal Y
854 switch ( A -> myPrimitive ) {
856 ( ( W32_PolygonNote* )( A -> myNote ) ) -> Add ( P( X ), P( Y ) );
859 ( ( W32_PolylineNote* )( A -> myNote ) ) -> Add ( P( X ), P( Y ) );
862 A -> Point ( P( X ), P( Y ) );
864 } // end WNT_WDriver :: DrawPoint
866 void 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
875 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzMarker ) ClosePrimitive ();
877 int aWidth = P( Width );
878 int aHeight = P( Height );
880 Standard_Integer theIndex = -1;
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") ;
887 if ( aWidth && aHeight && (aMarker > 0) ) {
889 if (aMarker >= myMarkerIdxs->Lower() || aMarker <= myMarkerIdxs->Upper())
890 theIndex = myMarkerIdxs->Value(aMarker);
892 if ( aWidth && aHeight && (theIndex >= 0) ) {
896 A -> BeginMarker ( P( Xpos ), P( Ypos ), aWidth, aHeight, Angle );
898 Aspect_MarkerStyle Style = MarkMap () -> Entry ( theIndex ).Style ();
900 int MarkerSize = Style.Length ();
904 MPARAM mp = { &Style, aWidth, aHeight };
906 for ( i = 2; i <= MarkerSize; ++i ) {
908 if ( Style.SValues ().Value ( i ) ) {
910 if ( Style.SValues ().Value ( i - 1 ) )
923 if ( Style.SValues().Value ( i - 1 ) ) {
925 if ( ( Style.XValues ().Value ( i ) == Style.XValues ().Value ( PrevPoint ) ) &&
926 ( Style.YValues ().Value ( i ) == Style.YValues ().Value ( PrevPoint ) )
929 A -> PolyMarker2 ( DrawCount, &_SetPoint, PrevPoint, &mp );
933 A -> PolyMarker1 ( DrawCount, &_SetPoint, PrevPoint, &mp );
947 if ( ( Style.XValues ().Value ( i ) == Style.XValues ().Value ( PrevPoint ) ) &&
948 ( Style.YValues ().Value ( i ) == Style.YValues ().Value ( PrevPoint ) )
951 A -> PolyMarker2 ( DrawCount, &_SetPoint, PrevPoint, &mp );
955 A -> PolyMarker1 ( DrawCount, &_SetPoint, PrevPoint, &mp );
961 } else A -> MarkerPoint ( P( Xpos ), P( Ypos ) );
963 } // end WNT_WDriver :: DrawMarker
965 Standard_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
974 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzArc )
978 if ( anOpenAngle >= 6.28318 )
980 A -> Ellipse ( P( X ), P( Y ), P( aXradius ), P( aYradius ) );
985 P( X ), P( Y ), P( aXradius ), P( aYradius ),
986 aStartAngle, anOpenAngle
989 return Standard_True;
991 } // end WNT_WDriver :: DrawArc
993 Standard_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
1003 if ( A -> myPrimitive != zzNone && A -> myPrimitive != zzPolySector )
1007 if ( anOpenAngle >= 6.28318 )
1009 A -> PolyEllipse ( P( X ), P( Y ), P( anXradius ), P( anYradius ) );
1014 P( X ), P( Y ), P( anXradius ), P( anYradius ),
1015 aStartAngle, anOpenAngle
1018 return Standard_True;
1020 } // end WNT_WDriver :: DrawPolyArc
1022 void WNT_WDriver :: BeginPolyline ( const Standard_Integer aNumber ) {
1024 A -> myPrimitive = zzPolyline;
1025 A -> myNote = A -> Polyline ( aNumber );
1027 } // end WNT_WDriver :: BeginPolyline
1029 void WNT_WDriver :: BeginPolygon ( const Standard_Integer aNumber ) {
1031 A -> myPrimitive = zzPolygon;
1032 A -> myNote = A -> Polygon ( aNumber );
1034 } // end WNT_WDriver :: BeginPolygon
1036 void WNT_WDriver :: BeginSegments () {
1038 A -> myPrimitive = zzLine;
1041 } // end WNT_WDriver :: BeginSegments
1043 void WNT_WDriver :: BeginArcs () {
1045 A -> myPrimitive = zzArc;
1048 } // end WNT_WDriver :: BeginArcs
1050 void WNT_WDriver :: BeginPolyArcs () {
1052 A -> myPrimitive = zzPolySector;
1055 } // end WNT_WDriver :: BeginPolyArcs
1057 void WNT_WDriver :: BeginMarkers () {
1059 A -> myPrimitive = zzMarker;
1062 } // end WNT_WDriver :: BeginMarkers
1064 void WNT_WDriver :: BeginPoints () {
1066 A -> myPrimitive = zzPoint;
1069 } // end WNT_WDriver :: BeginPoints
1071 void WNT_WDriver :: ClosePrimitive () {
1073 A -> myPrimitive = zzNone;
1076 } // end WNT_WDriver :: ClosePrimitive
1078 void WNT_WDriver :: InitializeColorMap ( const Handle( Aspect_ColorMap) & Colormap )
1080 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
1081 DownCast ( MyWindow -> GraphicDevice () );
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 ());
1091 if ( myColors.IsNull () || myColors -> Length () != Colormap -> Size () )
1092 myColors = new WNT_HColorTable ( minindex, maxindex, (WNT_ColorRef)0x00000000 );
1094 gDev -> MapColors ( Colormap, myColors );
1095 } // end WNT_WDriver :: InitializeColorMap
1097 void WNT_WDriver :: InitializeTypeMap ( const Handle( Aspect_TypeMap )& Typemap )
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 ());
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);
1112 } // end WNT_WDriver :: InitializeTypeMap
1114 void WNT_WDriver :: InitializeWidthMap ( const Handle( Aspect_WidthMap )& Widthmap )
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 ());
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);
1129 } // end WNT_WDriver :: InitializeWidthMap
1131 void WNT_WDriver :: InitializeFontMap ( const Handle( Aspect_FontMap )& Fontmap )
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 ) );
1141 /*====================== MFT ====================*/
1143 Aspect_FontMapEntry entry;
1144 Aspect_FontStyle style;
1145 Quantity_Length size;
1146 Quantity_PlaneAngle slant;
1147 TCollection_AsciiString aname;
1149 Handle(MFT_FontManager) theFontManager;
1150 myMFTFonts = new WNT_HListOfMFTFonts (0, mapSize, theFontManager);
1151 myMFTSizes = new TShort_HArray1OfShortReal (0, mapSize, 0.F);
1154 /*====================== MFT ====================*/
1155 myFonts = new WNT_HFontTable ( 0, mapSize - 1 );
1156 for ( i = 0; i < mapSize; ++i ) {
1157 /*====================== MFT ====================*/
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());
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;
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;
1187 theFontManager = new MFT_FontManager (aname.ToCString());
1188 theFontManager->SetFontAttribs (
1189 Abs(size), Abs(size), slant, 0., Standard_Boolean(size < 0.)
1191 myMFTFonts->SetValue (i, theFontManager);
1192 myMFTSizes->SetValue (i, (Standard_ShortReal)size);
1195 if ( UseMFT() && !myMFTFonts->Value(i).IsNull())
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" );
1206 case Aspect_TOF_DEFAULT:
1207 case Aspect_TOF_COURIER:
1208 lstrcatA ( right, "Courier New" );
1210 case Aspect_TOF_TIMES:
1211 lstrcatA ( right,"Times New Roman" );
1213 case Aspect_TOF_USERDEFINED:
1214 lstrcpyA ( left, fontStyle.Value () );
1215 if ( strchr ( fontStyle.Value (), '-' ) ) {
1216 height = atol ( pSize = strtok ( left, "-" ) );
1218 height = Standard_Integer ( atof ( pSize ) / myPixelToUnit );
1220 height = Standard_Integer ( fontStyle.Size () / myPixelToUnit );
1221 pSize = left + lstrlenA ( left );
1223 lstrcpyA ( right, pSize );
1224 } else lstrcatA ( right,left );
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 () ) {
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 );
1241 myFonts -> SetValue ( i, fmEntry );
1243 SelectFont( hdc, hfo );
1244 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1245 } // end WNT_WDriver :: InitializeFontMap
1247 void WNT_WDriver :: InitializeMarkMap ( const Handle( Aspect_MarkMap )& Markmap )
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 ());
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);
1262 } // end WNT_WDriver :: InitializeMarkMap
1264 Standard_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
1276 PW32_Allocator aNew = NULL;
1278 MyDrawMode = aDrawMode;
1279 aNew = _FindAllocator ( myAllocators, aRetainBuffer );
1283 ClearBuffer ( aRetainBuffer );
1285 else aNew = ( *W32_GetAllocator ) (
1286 aRetainBuffer, ( PW32_Allocator )myAllocators
1289 aNew -> myPivot.x = P( aPivotX );
1290 aNew -> myPivot.y = P( aPivotY );
1292 if ( aRetainBuffer ) {
1294 Standard_Address aSave = myAllocator;
1295 myAllocator = ( Standard_Address )aNew;
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;
1304 myAllocator = aSave;
1306 } else A -> myFlags &= ~W32F_MONO;
1310 } // end WNT_WDriver :: InternalOpenBuffer
1312 Standard_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
1321 return ( Standard_Boolean )InternalOpenBuffer (
1322 aRetainBuffer, Standard_True,
1323 aPivotX, aPivotY, aColorIndex, aWidthIndex,
1324 0, aFontIndex, aDrawMode
1327 } // end WNT_WDriver :: OpenBuffer
1329 Standard_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
1339 return ( Standard_Boolean )InternalOpenBuffer (
1340 aRetainBuffer, Standard_False,
1341 aPivotX, aPivotY, aColorIndex, aWidthIndex,
1342 0, aFontIndex, aDrawMode
1345 } // end WNT_WDriver :: OpenColorBuffer
1347 void WNT_WDriver :: CloseBuffer ( const Standard_Integer aRetainBuffer ) const {
1349 if ( aRetainBuffer ) {
1351 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1355 PW32_Allocator b = ( PW32_Allocator )myAllocators;
1357 while ( b -> myNext != a ) b = b -> myNext;
1359 if ( a -> myFlags & W32F_DRAWN ) EraseBuffer ( aRetainBuffer );
1361 b -> myNext = a -> myNext;
1371 } // end WNT_WDriver :: CloseBuffer
1373 void WNT_WDriver :: ClearBuffer ( const Standard_Integer aRetainBuffer ) const {
1375 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1379 if ( a -> myFlags & W32F_DRAWN ) EraseBuffer ( aRetainBuffer );
1381 a -> ClearBlocks ();
1385 } // end WNT_WDriver :: ClearBuffer
1387 void WNT_WDriver :: DrawBuffer ( const Standard_Integer aRetainBuffer ) const {
1389 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1395 HPALETTE hpo = NULL;
1396 HDC hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1398 Handle( WNT_GraphicDevice ) gDev = Handle ( WNT_GraphicDevice ) ::
1399 DownCast ( MyWindow -> GraphicDevice () );
1401 if ( gDev -> IsPaletteDevice () )
1403 hpo = SelectPalette ( hdc, ( HPALETTE )gDev -> HPalette (), FALSE );
1405 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1409 if ( a -> myFlags & W32F_DBUFF ) {
1410 HDC hdcMem = CreateCompatibleDC ( hdc );
1411 HBITMAP hbo = SelectBitmap( hdcMem, ( HBITMAP )myWNTWindow -> HPixmap () );
1414 if ( gDev -> IsPaletteDevice () )
1416 hpo = SelectPalette ( hdcMem, ( HPALETTE )gDev -> HPalette (), FALSE );
1418 SetROP2 ( hdcMem, _GetROP2 ( MyDrawMode ) );
1420 a -> Play ( hdcMem, &sz );
1423 hdc, r.left, r.top, r.right + 1, r.bottom + 1,
1424 hdcMem, r.left, r.top, SRCCOPY
1427 if ( gDev -> IsPaletteDevice () ) SelectPalette ( hdcMem, hpo, FALSE );
1429 SelectBitmap( hdcMem, hbo );
1430 DeleteDC ( hdcMem );
1432 SetROP2 ( hdc, _GetROP2 ( MyDrawMode ) );
1433 a -> Play ( hdc, &sz );
1436 if ( hpo != NULL ) SelectPalette( hdc, hpo, FALSE );
1438 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1440 a -> myFlags |= W32F_DRAWN;
1444 } // end WNT_WDriver :: DrawBuffer
1446 void WNT_WDriver :: EraseBuffer ( const Standard_Integer aRetainBuffer ) const {
1448 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1450 if ( a != NULL && ( a -> myFlags & W32F_DRAWN ) ) {
1456 if ( !IsRectEmpty ( &r ) ) {
1458 if ( a -> myID != 0 ) {
1460 if ( MyWindow -> BackingStore () )
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
1467 else if ( ( ( PW32_Allocator )myAllocators ) -> myFlags & W32F_DRAWN )
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
1482 a -> myFlags &= ~W32F_DRAWN;
1486 } // end WNT_WDriver :: EraseBuffer
1488 void WNT_WDriver :: MoveBuffer (
1489 const Standard_Integer aRetainBuffer,
1490 const Standard_ShortReal aPivotX,
1491 const Standard_ShortReal aPivotY
1494 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1498 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1500 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1502 a -> myMove.x = P( aPivotX ) - a -> myPivot.x;
1503 a -> myMove.y = P( aPivotY ) - a -> myPivot.y;
1505 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1509 } // end WNT_WDriver :: MoveBuffer
1511 void WNT_WDriver :: ScaleBuffer (
1512 const Standard_Integer aRetainBuffer,
1513 const Quantity_Factor aScaleX,
1514 const Quantity_Factor aScaleY
1517 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1521 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1523 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1525 a -> myScaleX = aScaleX;
1526 a -> myScaleY = aScaleY;
1528 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1532 } // end WNT_WDriver :: ScaleBuffer
1534 void WNT_WDriver :: RotateBuffer (
1535 const Standard_Integer aRetainBuffer,
1536 const Quantity_PlaneAngle anAngle
1539 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1543 BOOL fDrawn = a -> myFlags & W32F_DRAWN;
1545 if ( fDrawn ) EraseBuffer ( aRetainBuffer );
1547 a -> myAngle = anAngle;
1549 if ( fDrawn ) DrawBuffer ( aRetainBuffer );
1553 } // end WNT_WDriver :: RotateBuffer
1555 void WNT_WDriver :: WorkSpace ( Quantity_Length& Width, Quantity_Length& Heigth ) const {
1559 GetClientRect ( ( HWND )( myWNTWindow -> HWindow () ), &r );
1561 Width = U( r.right );
1562 Heigth = U( r.bottom );
1564 } // end WNT_WDriver :: WorkSpace
1566 Quantity_Length WNT_WDriver :: Convert ( const Standard_Integer PV ) const {
1570 } // end WNT_WDriver :: Convert
1572 Standard_Integer WNT_WDriver :: Convert ( const Quantity_Length DV ) const {
1576 } // end WNT_WDriver :: Convert
1578 void WNT_WDriver :: Convert (
1579 const Standard_Integer PX,
1580 const Standard_Integer PY,
1581 Quantity_Length& DX,
1586 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1589 DY = U( r.bottom - PY );
1591 } // end WNT_WDriver :: Convert
1593 void WNT_WDriver :: Convert (
1594 const Quantity_Length DX,
1595 const Quantity_Length DY,
1596 Standard_Integer& PX,
1597 Standard_Integer& PY
1601 GetClientRect ( ( HWND )myWNTWindow -> HWindow (), &r );
1604 PY = r.bottom - P( DY );
1606 } // end WNT_WDriver :: Convert
1608 Standard_Integer WNT_WDriver :: ProcessColorIndex (
1609 const Standard_Integer ColorIndex
1612 if ( !SA ) return A -> myPointColor;
1614 if ( myColors.IsNull () ) return ( Standard_Integer )RGB( 0, 0, 0 );
1616 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
1617 DownCast ( MyWindow -> GraphicDevice () );
1619 if ( ColorIndex <= 0 ) {
1621 if ((A -> myFlags & W32F_MONO) && (A -> myFlags & W32F_MINIT)) {
1622 return RGB(255, 255, 255);
1625 GetObject ( myWNTWindow -> HBackground(), sizeof ( LOGBRUSH ), &lb );
1631 switch ( MyDrawMode ) {
1634 case Aspect_TODM_REPLACE :
1636 if (ColorIndex < myColors->Lower() || ColorIndex > myColors->Upper())
1637 return myColors -> Value ( myColors->Lower() );
1638 return myColors -> Value ( ColorIndex );
1640 case Aspect_TODM_ERASE :
1642 return gDev -> SetColor ( MyWindow -> Background ().Color () );
1644 case Aspect_TODM_XORLIGHT :
1645 case Aspect_TODM_XOR :
1647 return gDev -> HighlightColor ();
1651 } // end WNT_WDriver :: ProcessColorIndex
1653 Quantity_Length WNT_WDriver :: ProcessWidthIndex (
1654 const Standard_Integer WidthIndex
1657 Standard_Integer theIndex = WidthIndex;
1658 if (WidthIndex < myWidthIdxs->Lower() || WidthIndex > myWidthIdxs->Upper())
1659 theIndex = myWidthIdxs->Lower();
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
1666 Standard_Integer WNT_WDriver :: ProcessTypeIndex (
1667 const Standard_Integer TypeIndex
1670 return ( TypeMap () -> Entry ( TypeIndex + 1 ).Type ().Style () == Aspect_TOL_SOLID ) ?
1673 } // end WNT_WDriver :: ProcessTypeIndex
1675 Standard_Boolean WNT_WDriver :: BufferIsOpen (
1676 const Standard_Integer aRetainBuffer
1679 return ( _FindAllocator ( myAllocators, aRetainBuffer) != NULL ?
1680 Standard_True : Standard_False
1683 } // end WNT_WDriver :: BufferIsOpen
1685 Standard_Boolean WNT_WDriver :: BufferIsEmpty (
1686 const Standard_Integer aRetainBuffer
1689 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1693 return ( a -> myFlags & W32F_EMPTY ) ? Standard_True : Standard_False;
1695 return Standard_True;
1697 } // end WNT_WDriver :: BufferIsEmpty
1699 Standard_Boolean WNT_WDriver :: BufferIsDrawn (
1700 const Standard_Integer aRetainBuffer
1703 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1707 return ( a -> myFlags & W32F_DRAWN ) ? Standard_True : Standard_False;
1709 return Standard_False;
1711 } // end WNT_WDriver :: BufferIsDrawn
1713 void WNT_WDriver :: AngleOfBuffer (
1714 const Standard_Integer aRetainBuffer,
1715 Quantity_PlaneAngle& anAngle
1718 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1720 if ( a != NULL ) anAngle = a -> myAngle;
1722 } // end WNT_WDriver :: AngleOfBuffer
1724 void WNT_WDriver :: ScaleOfBuffer (
1725 const Standard_Integer aRetainBuffer,
1726 Quantity_Factor& aScaleX,
1727 Quantity_Factor& aScaleY
1730 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1734 aScaleX = a -> myScaleX;
1735 aScaleY = a -> myScaleY;
1739 } // end WNT_WDriver :: ScaleOfBuffer
1741 void WNT_WDriver :: PositionOfBuffer (
1742 const Standard_Integer aRetainBuffer,
1743 Standard_ShortReal& aPivotX,
1744 Standard_ShortReal& aPivotY
1747 PW32_Allocator a = _FindAllocator ( myAllocators, aRetainBuffer );
1751 aPivotX = Standard_ShortReal ( U( a -> myPivot.x + a -> myMove.x ) );
1752 aPivotY = Standard_ShortReal ( U( a -> myPivot.y + a -> myMove.y ) );
1756 } // end WNT_WDriver :: PositionOfBuffer
1758 void WNT_WDriver :: TextSize (
1759 const TCollection_ExtendedString& aText,
1760 Standard_ShortReal& aWidth,
1761 Standard_ShortReal& aHeight,
1762 const Standard_Integer aFontIndex
1765 if( aText.Length() <= 0 ) {
1766 aWidth = aHeight = 0.;
1771 Standard_ShortReal xoffset, yoffset;
1772 /*====================== MFT ====================*/
1775 TextSize (aText, aWidth, aHeight, xoffset, yoffset, aFontIndex);
1778 /*====================== MFT ====================*/
1780 char* str = _ConvertU2F ( aText );
1782 TextSize ( str, aWidth, aHeight, xoffset, yoffset, aFontIndex );
1784 HeapFree ( GetProcessHeap (), 0, str );
1786 /*====================== MFT ====================*/
1790 /*====================== MFT ====================*/
1791 } // end WNT_WDriver :: TextSize
1793 void 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
1802 if( aText.Length() <= 0 ) {
1803 aWidth = aHeight = anXoffset = anYoffset = 0.;
1808 /*====================== MFT ====================*/
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);
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 );
1834 char* str = ( char* )_ConvertU2F ( aText );
1841 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1844 aFontIndex < 0 ? A -> myTextFont : ( HFONT )myFonts -> Value ( aFontIndex ) -> HFont ()
1847 xo = A -> TextSize ( hdc, str, &sz );
1848 aWidth = Standard_ShortReal ( U( sz.cx ) );
1849 aHeight = Standard_ShortReal ( U( sz.cy ) );
1851 anXoffset = Standard_ShortReal ( U( xo ) );
1852 anYoffset = Standard_ShortReal ( 0.0 );
1854 SelectFont( hdc, hfo );
1855 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1857 HeapFree ( GetProcessHeap (), 0, str );
1859 /*====================== MFT ====================*/
1863 /*====================== MFT ====================*/
1864 } // end WNT_WDriver :: TextSize
1866 void 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
1875 if( !aText || (strlen(aText) <= 0) ) {
1876 aWidth = aHeight = anXoffset = anYoffset = 0.;
1881 /*====================== MFT ====================*/
1884 TCollection_ExtendedString extText (aText);
1885 TextSize (extText, aWidth, aHeight, anXoffset, anYoffset, aFontIndex);
1888 /*====================== MFT ====================*/
1894 hdc = GetDC ( ( HWND )myWNTWindow -> HWindow () );
1897 aFontIndex < 0 ? A -> myTextFont : ( HFONT )myFonts -> Value ( aFontIndex ) -> HFont ()
1900 xo = A -> TextSize ( hdc, (Standard_PCharacter)aText, &sz );
1901 aWidth = Standard_ShortReal ( U( sz.cx ) );
1902 aHeight = Standard_ShortReal ( U( sz.cy ) );
1904 anXoffset = Standard_ShortReal ( U( xo ) );
1905 anYoffset = Standard_ShortReal ( 0.0 );
1907 SelectFont( hdc, hfo );
1908 ReleaseDC ( ( HWND )myWNTWindow -> HWindow (), hdc );
1909 /*====================== MFT ====================*/
1913 /*====================== MFT ====================*/
1914 } // end WNT_WDriver :: TextSize
1916 Standard_CString WNT_WDriver :: FontSize (
1917 Quantity_PlaneAngle& aSlant,
1918 Standard_ShortReal& aSize,
1919 Standard_ShortReal& aBheight,
1920 const Standard_Integer aFontIndex
1923 /*====================== MFT ====================*/
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
1938 aSize = (Standard_ShortReal)theHeight;
1939 aBheight = (Standard_ShortReal)theDescent;
1944 /*====================== MFT ====================*/
1946 aSize = Standard_ShortReal ( U(myFonts->Value(0)->myLogFont.lfHeight) );
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;
1953 return aFontIndex < 0 ? "" : myFonts->Value(aFontIndex)->myLogFont.lfFaceName;
1954 /*====================== MFT ====================*/
1958 /*====================== MFT ====================*/
1959 } // end WNT_WDriver :: FontSize
1961 void WNT_WDriver :: ColorBoundIndexs (
1962 Standard_Integer& aMinIndex,
1963 Standard_Integer& aMaxIndex
1966 if ( myColors.IsNull () ) {
1974 aMaxIndex = myColors -> Length ();
1978 } // end WNT_WDriver :: ColorBoundIndexs
1980 Standard_Integer WNT_WDriver :: LocalColorIndex (
1981 const Standard_Integer anIndex
1984 return ( anIndex < 1 || anIndex > myColors -> Length () ) ? -1 : anIndex;
1986 } // end WNT_WDriver :: LocalColorIndex
1988 void WNT_WDriver :: FontBoundIndexs (
1989 Standard_Integer& aMinIndex,
1990 Standard_Integer& aMaxIndex
1993 if ( myFonts.IsNull () ) {
2001 aMaxIndex = myFonts -> Length ();
2005 } // end WNT_WDriver :: FontBoundIndexs
2007 Standard_Integer WNT_WDriver :: LocalFontIndex (
2008 const Standard_Integer anIndex
2011 return ( anIndex < 1 || anIndex > myFonts -> Length () ) ? -1 : anIndex;
2013 } // end WNT_WDriver :: LocalFontIndex
2015 void WNT_WDriver :: TypeBoundIndexs (
2016 Standard_Integer& aMinIndex,
2017 Standard_Integer& aMaxIndex
2020 if ( TypeMap ().IsNull () ) {
2028 aMaxIndex = TypeMap () -> Size ();
2032 } // end WNT_WDriver :: TypeBoundIndexs
2034 Standard_Integer WNT_WDriver :: LocalTypeIndex (
2035 const Standard_Integer anIndex
2038 return ( anIndex < 1 || anIndex > TypeMap () -> Size () ) ? -1 : anIndex;
2040 } // end WNT_WDriver :: LocalTypeIndex
2042 void WNT_WDriver :: WidthBoundIndexs (
2043 Standard_Integer& aMinIndex,
2044 Standard_Integer& aMaxIndex
2047 if ( WidthMap ().IsNull () ) {
2055 aMaxIndex = WidthMap () -> Size ();
2059 } // end WNT_WDriver :: WidthBoundIndexs
2061 Standard_Integer WNT_WDriver :: LocalWidthIndex (
2062 const Standard_Integer anIndex
2065 return ( anIndex < 1 || anIndex > WidthMap () -> Size () ) ? -1 : anIndex;
2067 } // end WNT_WDriver :: LocalWidthIndex
2069 void WNT_WDriver :: MarkBoundIndexs (
2070 Standard_Integer& aMinIndex,
2071 Standard_Integer& aMaxIndex
2074 if ( MarkMap ().IsNull () ) {
2082 aMaxIndex = MarkMap () -> Size ();
2086 } // end WNT_WDriver :: MarkBoundIndexs
2088 Standard_Integer WNT_WDriver :: LocalMarkIndex (
2089 const Standard_Integer anIndex
2092 return ( anIndex < 1 || anIndex > MarkMap () -> Size () ) ? -1 : anIndex;
2094 } // end WNT_WDriver :: LocalMarkIndex
2096 const Handle(WNT_TextManager)& WNT_WDriver :: TextManager ()
2098 return (myTextManager);
2099 } // end WNT_WDriver :: TextManager
2101 const Handle(MFT_FontManager)& WNT_WDriver :: MFT_Font
2102 (const Standard_Integer anIndex)
2104 return myMFTFonts->Value(anIndex);
2105 } // end WNT_WDriver :: MFT_FontList
2107 Standard_ShortReal WNT_WDriver :: MFT_Size
2108 (const Standard_Integer anIndex)
2110 return myMFTSizes->Value(anIndex);
2111 } // end WNT_WDriver :: MFT_SizeList
2113 static PW32_Allocator __fastcall _FindAllocator ( Standard_Address p, Standard_Integer id ) {
2115 while ( p != NULL && ( ( PW32_Allocator )p ) -> myID != id )
2117 p = ( ( PW32_Allocator )p ) -> myNext;
2119 return ( PW32_Allocator )p;
2121 } // end _FindAllocator
2123 static int __fastcall _GetROP2 ( Aspect_TypeOfDrawMode tdm ) {
2129 case Aspect_TODM_ERASE:
2130 case Aspect_TODM_REPLACE:
2133 retVal = R2_COPYPEN;
2137 case Aspect_TODM_XOR:
2138 case Aspect_TODM_XORLIGHT:
2150 static void WINAPI _SetPoint ( int s, int m, int set, LPPOINT p, int* n, void* param ) {
2152 PMPARAM pmp = ( PMPARAM )param;
2156 for ( int i = 0; i < m; ++i, ++( *n ), ++s ) {
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 );
2165 static char* __fastcall _ConvertU2F ( const TCollection_ExtendedString& str ) {
2168 Standard_Integer szBuff = ( str.Length () << 2 );
2170 retVal = ( char* )HeapAlloc (
2171 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS,
2175 while ( !Resource_Unicode :: ConvertUnicodeToFormat ( str, retVal, szBuff ) ) {
2178 retVal = ( char* )HeapReAlloc (
2179 GetProcessHeap (), HEAP_GENERATE_EXCEPTIONS,
2187 } // end _ConvertU2F