WinPrinterContext.st
changeset 3041 e0211b174c0e
parent 3002 a6acab3dbdea
child 3190 437b1425507e
equal deleted inserted replaced
3040:4b9f600b4057 3041:e0211b174c0e
    62 #define Process WIN_Process
    62 #define Process WIN_Process
    63 #undef Processor
    63 #undef Processor
    64 #define Processor WIN_Processor
    64 #define Processor WIN_Processor
    65 #undef Message
    65 #undef Message
    66 #define Message WIN_Message
    66 #define Message WIN_Message
       
    67 #undef String
       
    68 #define String WIN_String
       
    69 #undef Character
       
    70 #define Character WIN_Character
    67 
    71 
    68 #include <stdio.h>
    72 #include <stdio.h>
    69 #include <errno.h>
    73 #include <errno.h>
    70 
    74 
    71 #ifdef __BORLANDC__
    75 #ifdef __BORLANDC__
   165 # endif
   169 # endif
   166 # ifdef __DEF_Message
   170 # ifdef __DEF_Message
   167 #  undef Message
   171 #  undef Message
   168 #  define Message __DEF_Message
   172 #  define Message __DEF_Message
   169 # endif
   173 # endif
       
   174 # ifdef __DEF_String
       
   175 #  undef String
       
   176 #  define String __DEF_String
       
   177 # endif
       
   178 # ifdef __DEF_Character
       
   179 #  undef Character
       
   180 #  define Character __DEF_Character
       
   181 # endif
   170 
   182 
   171 #undef INT
   183 #undef INT
   172 #define INT int
   184 #define INT STX_INT
       
   185 #undef UINT
       
   186 #define UINT STX_UINT
   173 
   187 
   174 /*
   188 /*
   175  * some defines - tired of typing ...
   189  * some defines - tired of typing ...
   176  */
   190  */
   177 #define _HANDLEVal(o)        (HANDLE)(__MKCP(o))
   191 #define _HANDLEVal(o)        (HANDLE)(__MKCP(o))
   194 # define DPRINTF(x)              /* */
   208 # define DPRINTF(x)              /* */
   195 # define DFPRINTF(x)             /* */
   209 # define DFPRINTF(x)             /* */
   196 #endif
   210 #endif
   197 
   211 
   198 typedef int (*intf)(int);
   212 typedef int (*intf)(int);
       
   213 typedef INT (*INTF)(INT);
   199 %}
   214 %}
   200 ! !
   215 ! !
   201 
   216 
   202 !WinPrinterContext class methodsFor:'documentation'!
   217 !WinPrinterContext class methodsFor:'documentation'!
   203 
   218 
   271     printerInfo := PrintingDialog getPrinterInfoWithoutDialog:withoutDialog.
   286     printerInfo := PrintingDialog getPrinterInfoWithoutDialog:withoutDialog.
   272     printerInfo isNil ifTrue:[^ nil].
   287     printerInfo isNil ifTrue:[^ nil].
   273     gc := WinPrinterGraphicContext fromPrinterInfo:printerInfo.
   288     gc := WinPrinterGraphicContext fromPrinterInfo:printerInfo.
   274 
   289 
   275     gc notNil ifTrue:[
   290     gc notNil ifTrue:[
   276         gc startPrintJob
   291 	gc startPrintJob
   277     ].
   292     ].
   278     ^ gc
   293     ^ gc
   279 ! !
   294 ! !
   280 
   295 
   281 !WinPrinterContext class methodsFor:'accessing'!
   296 !WinPrinterContext class methodsFor:'accessing'!
   296     "Modified: / 01-08-2006 / 16:01:44 / fm"
   311     "Modified: / 01-08-2006 / 16:01:44 / fm"
   297     "Modified: / 10-10-2006 / 18:57:45 / cg"
   312     "Modified: / 10-10-2006 / 18:57:45 / cg"
   298 !
   313 !
   299 
   314 
   300 getPrinterInformationString: printerNameString
   315 getPrinterInformationString: printerNameString
   301         " Answer the printer information string from the WIN.INI file
   316 	" Answer the printer information string from the WIN.INI file
   302         for the printer named printerNameString.  If no name is specified,
   317 	for the printer named printerNameString.  If no name is specified,
   303         answer the information for the default printer. "
   318 	answer the information for the default printer. "
   304     | printerInfo result |
   319     | printerInfo result |
   305     printerInfo := ( String new: 80 ).
   320     printerInfo := ( String new: 80 ).
   306     result := OperatingSystem primGetProfileString: 'windows' 
   321     result := OperatingSystem primGetProfileString: 'windows'
   307         keyName:  'device'
   322 	keyName:  'device'
   308         default: ( printerNameString isNil ifTrue: [ '' ] ifFalse: [ printerNameString ] )
   323 	default: ( printerNameString isNil ifTrue: [ '' ] ifFalse: [ printerNameString ] )
   309         returnedString: printerInfo
   324 	returnedString: printerInfo
   310         size: printerInfo size.
   325 	size: printerInfo size.
   311     ^result > 0
   326     ^result > 0
   312         ifTrue: [printerInfo copyFrom: 1 to: result]
   327 	ifTrue: [printerInfo copyFrom: 1 to: result]
   313         ifFalse: ['']
   328 	ifFalse: ['']
   314 !
   329 !
   315 
   330 
   316 named: aName
   331 named: aName
   317     "Answer a new instance of Printer which represents
   332     "Answer a new instance of Printer which represents
   318      the printer named aName as specified in the host
   333      the printer named aName as specified in the host
   383 
   398 
   384 !WinPrinterContext class methodsFor:'testing'!
   399 !WinPrinterContext class methodsFor:'testing'!
   385 
   400 
   386 computeScaleForPrinter:aPrinter
   401 computeScaleForPrinter:aPrinter
   387     ^ Point x:(aPrinter pixelsPerInchOfScreenWidth / Screen current horizontalPixelPerInch)
   402     ^ Point x:(aPrinter pixelsPerInchOfScreenWidth / Screen current horizontalPixelPerInch)
   388             y:(aPrinter pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch)
   403 	    y:(aPrinter pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch)
   389 !
   404 !
   390 
   405 
   391 testPrintingDo:anOneArgBlock
   406 testPrintingDo:anOneArgBlock
   392 
   407 
   393     "Opens a print dialog and invokes the action with the printer"
   408     "Opens a print dialog and invokes the action with the printer"
   477     printerInfo := PrintingDialog getPrinterInfo.
   492     printerInfo := PrintingDialog getPrinterInfo.
   478     printerInfo isNil ifTrue:[^self].
   493     printerInfo isNil ifTrue:[^self].
   479 
   494 
   480     printer := self fromPrinterInfo: printerInfo.
   495     printer := self fromPrinterInfo: printerInfo.
   481     [
   496     [
   482         printer startPrintJob: 'Fill Hatch Circles'.
   497 	printer startPrintJob: 'Fill Hatch Circles'.
   483         arrayOfPointsAndRadiusWithContextArray
   498 	arrayOfPointsAndRadiusWithContextArray
   484             do:[:pointsAndRadiusWithContextArray |
   499 	    do:[:pointsAndRadiusWithContextArray |
   485                 | point radius color hatch|
   500 		| point radius color hatch|
   486                 point := (pointsAndRadiusWithContextArray at:1).
   501 		point := (pointsAndRadiusWithContextArray at:1).
   487                 radius := (pointsAndRadiusWithContextArray at:2).
   502 		radius := (pointsAndRadiusWithContextArray at:2).
   488                 color := (pointsAndRadiusWithContextArray at:3).
   503 		color := (pointsAndRadiusWithContextArray at:3).
   489                 hatch := (pointsAndRadiusWithContextArray at:4).
   504 		hatch := (pointsAndRadiusWithContextArray at:4).
   490                 printer foreground: color;
   505 		printer foreground: color;
   491                         hatch: hatch.
   506 			hatch: hatch.
   492                 printer fillCircle:point
   507 		printer fillCircle:point
   493                         radius:radius.
   508 			radius:radius.
   494             ].
   509 	    ].
   495         printer endPrintJob.
   510 	printer endPrintJob.
   496     ] forkAt: 3
   511     ] forkAt: 3
   497 
   512 
   498     "
   513     "
   499      WinPrinterContext fillHatchCircles:
   514      WinPrinterContext fillHatchCircles:
   500         (Array with: (Array with: 800@800 with: 600 with:Color red with: #diagonalCross)
   515 	(Array with: (Array with: 800@800 with: 600 with:Color red with: #diagonalCross)
   501                with: (Array with: 1500@1500 with: 1000 with:Color blue with: #vertical)
   516 	       with: (Array with: 1500@1500 with: 1000 with:Color blue with: #vertical)
   502                with: (Array with: 4000@2500 with: 2000 with:Color gray with: #bDiagonal))
   517 	       with: (Array with: 4000@2500 with: 2000 with:Color gray with: #bDiagonal))
   503     "
   518     "
   504 
   519 
   505     "Created: / 07-08-2006 / 11:46:52 / fm"
   520     "Created: / 07-08-2006 / 11:46:52 / fm"
   506     "Modified: / 16-04-2007 / 15:37:34 / cg"
   521     "Modified: / 16-04-2007 / 15:37:34 / cg"
   507 !
   522 !
   514     printerInfo := PrintingDialog getPrinterInfo.
   529     printerInfo := PrintingDialog getPrinterInfo.
   515     printerInfo isNil ifTrue:[^self].
   530     printerInfo isNil ifTrue:[^self].
   516 
   531 
   517     printer := self fromPrinterInfo: printerInfo.
   532     printer := self fromPrinterInfo: printerInfo.
   518     [
   533     [
   519         printer startPrintJob: 'Fill Hatch Polygons'.
   534 	printer startPrintJob: 'Fill Hatch Polygons'.
   520         polygonsWithContextArray
   535 	polygonsWithContextArray
   521             do:[:polygonWithContextArray |
   536 	    do:[:polygonWithContextArray |
   522                  |aPolygon color hatch|
   537 		 |aPolygon color hatch|
   523                  aPolygon := polygonWithContextArray at: 1.
   538 		 aPolygon := polygonWithContextArray at: 1.
   524                  color := (polygonWithContextArray at: 2).
   539 		 color := (polygonWithContextArray at: 2).
   525                  hatch := (polygonWithContextArray at: 3).
   540 		 hatch := (polygonWithContextArray at: 3).
   526                  printer foreground: color;
   541 		 printer foreground: color;
   527                          hatch: hatch.
   542 			 hatch: hatch.
   528                  aPolygon displayFilledOn: printer.
   543 		 aPolygon displayFilledOn: printer.
   529             ].
   544 	    ].
   530         printer endPrintJob.
   545 	printer endPrintJob.
   531     ] forkAt: 3
   546     ] forkAt: 3
   532 
   547 
   533     "
   548     "
   534      WinPrinterContext fillHatchPolygons:
   549      WinPrinterContext fillHatchPolygons:
   535         (Array with: (Array with: (Polygon vertices:(
   550 	(Array with: (Array with: (Polygon vertices:(
   536                                 Array
   551 				Array
   537                                     with:100@100
   552 				    with:100@100
   538                                     with:600@1000
   553 				    with:600@1000
   539                                     with:3500@4000
   554 				    with:3500@4000
   540                                     with:100@4000
   555 				    with:100@4000
   541                                     with:100@100))
   556 				    with:100@100))
   542                             with: Color red
   557 			    with: Color red
   543                             with: #cross)
   558 			    with: #cross)
   544                 with: (Array with: (Polygon vertices:(
   559 		with: (Array with: (Polygon vertices:(
   545                                 Array
   560 				Array
   546                                     with:1000@1000
   561 				    with:1000@1000
   547                                     with:1000@2000
   562 				    with:1000@2000
   548                                     with:2000@1000))
   563 				    with:2000@1000))
   549                              with: Color blue
   564 			     with: Color blue
   550                              with: #none)
   565 			     with: #none)
   551     )
   566     )
   552     "
   567     "
   553 
   568 
   554     "Created: / 07-08-2006 / 12:09:48 / fm"
   569     "Created: / 07-08-2006 / 12:09:48 / fm"
   555     "Modified: / 07-08-2006 / 14:11:17 / fm"
   570     "Modified: / 07-08-2006 / 14:11:17 / fm"
   564     printerInfo := PrintingDialog getPrinterInfo.
   579     printerInfo := PrintingDialog getPrinterInfo.
   565     printerInfo isNil ifTrue:[^self].
   580     printerInfo isNil ifTrue:[^self].
   566 
   581 
   567     printer := self fromPrinterInfo: printerInfo.
   582     printer := self fromPrinterInfo: printerInfo.
   568     [
   583     [
   569         printer startPrintJob: 'Fill Hatch Rectangles'.
   584 	printer startPrintJob: 'Fill Hatch Rectangles'.
   570         printer foreground:Color blue background:Color white.
   585 	printer foreground:Color blue background:Color white.
   571         rectanglesWithHatch
   586 	rectanglesWithHatch
   572             do:[:rectangleWithHatch |
   587 	    do:[:rectangleWithHatch |
   573                 |rectangle hatch|
   588 		|rectangle hatch|
   574                 rectangle := rectangleWithHatch at: 1.
   589 		rectangle := rectangleWithHatch at: 1.
   575                 hatch := rectangleWithHatch at: 2.
   590 		hatch := rectangleWithHatch at: 2.
   576                 printer hatch: hatch.
   591 		printer hatch: hatch.
   577                 printer fillRectangleX: rectangle origin x
   592 		printer fillRectangleX: rectangle origin x
   578                         y: rectangle origin y
   593 			y: rectangle origin y
   579                         width: rectangle width
   594 			width: rectangle width
   580                         height: rectangle height.
   595 			height: rectangle height.
   581             ].
   596 	    ].
   582         printer endPrintJob.
   597 	printer endPrintJob.
   583     ] forkAt: 3
   598     ] forkAt: 3
   584 
   599 
   585     "
   600     "
   586      WinPrinterContext fillHatchRectangles:
   601      WinPrinterContext fillHatchRectangles:
   587         (Array with: (Array with: (Rectangle left:20 top:20 width:400 height:600) with: #horizontal)
   602 	(Array with: (Array with: (Rectangle left:20 top:20 width:400 height:600) with: #horizontal)
   588                with: (Array with: (Rectangle left:500 top:700 width:600 height:400) with: #vertical)
   603 	       with: (Array with: (Rectangle left:500 top:700 width:600 height:400) with: #vertical)
   589                with: (Array with: (Rectangle left:800 top:1000 width:1600 height:2000) with: #cross)
   604 	       with: (Array with: (Rectangle left:800 top:1000 width:1600 height:2000) with: #cross)
   590                with: (Array with: (Rectangle left:1040 top:1240 width:3000 height:3000) with: #bDiagonal)
   605 	       with: (Array with: (Rectangle left:1040 top:1240 width:3000 height:3000) with: #bDiagonal)
   591         )
   606 	)
   592     "
   607     "
   593 
   608 
   594     "Created: / 07-08-2006 / 11:40:48 / fm"
   609     "Created: / 07-08-2006 / 11:40:48 / fm"
   595     "Modified: / 16-04-2007 / 15:37:46 / cg"
   610     "Modified: / 16-04-2007 / 15:37:46 / cg"
   596 !
   611 !
   701     printerInfo := PrintingDialog getPrinterInfo.
   716     printerInfo := PrintingDialog getPrinterInfo.
   702     printerInfo isNil ifTrue:[^self].
   717     printerInfo isNil ifTrue:[^self].
   703 
   718 
   704     printer := self fromPrinterInfo: printerInfo.
   719     printer := self fromPrinterInfo: printerInfo.
   705     [
   720     [
   706         printer
   721 	printer
   707             print: aString
   722 	    print: aString
   708             font: aFont
   723 	    font: aFont
   709             title: aTitle
   724 	    title: aTitle
   710             wordWrap: wordWrap
   725 	    wordWrap: wordWrap
   711             marginsRect: nil
   726 	    marginsRect: nil
   712     ] forkAt: 3
   727     ] forkAt: 3
   713 
   728 
   714     "
   729     "
   715      WinPrinterContext print: 'Holaaaa!! (from:  PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' wordWrap: true
   730      WinPrinterContext print: 'Holaaaa!! (from:  PrinterContext>>print:aString font:aFont title:aTitle)' font: nil title: 'Printing Test' wordWrap: true
   716      WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font:nil title:'Printing Test String' wordWrap:true
   731      WinPrinterContext print: (WinPrinterContext class sourceCodeAt:#'print:font:title:wordWrap:') font:nil title:'Printing Test String' wordWrap:true
   806     printerInfo := PrintingDialog getPrinterInfo.
   821     printerInfo := PrintingDialog getPrinterInfo.
   807     printerInfo isNil ifTrue:[^self].
   822     printerInfo isNil ifTrue:[^self].
   808 
   823 
   809     printer := self fromPrinterInfo: printerInfo.
   824     printer := self fromPrinterInfo: printerInfo.
   810     [
   825     [
   811         printer startPrintJob: 'Image'.
   826 	printer startPrintJob: 'Image'.
   812         printer background:Color white.
   827 	printer background:Color white.
   813         (anImage magnifiedBy:factor) displayOn:printer x:0 y:0.
   828 	(anImage magnifiedBy:factor) displayOn:printer x:0 y:0.
   814         printer endPrintJob.
   829 	printer endPrintJob.
   815     ] forkAt: 3
   830     ] forkAt: 3
   816 
   831 
   817     "
   832     "
   818      WinPrinterContext printImage: (Image fromFile:'C:\vsw311\pavheadr.gif').
   833      WinPrinterContext printImage: (Image fromFile:'C:\vsw311\pavheadr.gif').
   819      WinPrinterContext printImage: XPToolbarIconLibrary help32x32Icon.
   834      WinPrinterContext printImage: XPToolbarIconLibrary help32x32Icon.
  1011     printerInfo := PrintingDialog getPrinterInfo.
  1026     printerInfo := PrintingDialog getPrinterInfo.
  1012     printerInfo isNil ifTrue:[^self].
  1027     printerInfo isNil ifTrue:[^self].
  1013 
  1028 
  1014     printer := self fromPrinterInfo: printerInfo.
  1029     printer := self fromPrinterInfo: printerInfo.
  1015     [
  1030     [
  1016         printer startPrintJob: 'Strings with Position'.
  1031 	printer startPrintJob: 'Strings with Position'.
  1017         printer foreground:Color black background:Color white.
  1032 	printer foreground:Color black background:Color white.
  1018         stringAndPositionsArray
  1033 	stringAndPositionsArray
  1019             do:[:pairOfPointsAndPosition |
  1034 	    do:[:pairOfPointsAndPosition |
  1020                  printer displayString:(pairOfPointsAndPosition at: 1)
  1035 		 printer displayString:(pairOfPointsAndPosition at: 1)
  1021                             x:(pairOfPointsAndPosition at: 2) x
  1036 			    x:(pairOfPointsAndPosition at: 2) x
  1022                             y:(pairOfPointsAndPosition at: 2) y
  1037 			    y:(pairOfPointsAndPosition at: 2) y
  1023             ].
  1038 	    ].
  1024         printer endPrintJob.
  1039 	printer endPrintJob.
  1025     ] forkAt: 3
  1040     ] forkAt: 3
  1026 
  1041 
  1027     "
  1042     "
  1028      WinPrinterContext printStrings:
  1043      WinPrinterContext printStrings:
  1029         (Array with: (Array with:'Testing printing with standard method' with:10@10)
  1044 	(Array with: (Array with:'Testing printing with standard method' with:10@10)
  1030                with: (Array with:'Another test string to print' with:80@200))
  1045 	       with: (Array with:'Another test string to print' with:80@200))
  1031     "
  1046     "
  1032 
  1047 
  1033     "Created: / 07-08-2006 / 12:09:48 / fm"
  1048     "Created: / 07-08-2006 / 12:09:48 / fm"
  1034     "Modified: / 07-08-2006 / 14:11:17 / fm"
  1049     "Modified: / 07-08-2006 / 14:11:17 / fm"
  1035     "Modified: / 16-04-2007 / 15:37:49 / cg"
  1050     "Modified: / 16-04-2007 / 15:37:49 / cg"
  1316 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1331 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1317 	COLORREF fgColor;
  1332 	COLORREF fgColor;
  1318 	HANDLE hPen, prevPen;
  1333 	HANDLE hPen, prevPen;
  1319 	int lineStyleInt, capStyleInt, joinStyleInt, lineWidth;
  1334 	int lineStyleInt, capStyleInt, joinStyleInt, lineWidth;
  1320 
  1335 
  1321 	lineWidth= __INST(lineWidth);
  1336 	lineWidth= __intVal(__INST(lineWidth));
  1322 
  1337 
  1323 	if (__INST(lineStyle) == @symbol(solid)) {
  1338 	if (__INST(lineStyle) == @symbol(solid)) {
  1324 	    lineStyleInt= PS_SOLID;
  1339 	    lineStyleInt= PS_SOLID;
  1325 	} else if (__INST(lineStyle) == @symbol(dashed)) {
  1340 	} else if (__INST(lineStyle) == @symbol(dashed)) {
  1326 	    lineStyleInt= PS_DASH;
  1341 	    lineStyleInt= PS_DASH;
  1420     self primitiveFailed
  1435     self primitiveFailed
  1421 !
  1436 !
  1422 
  1437 
  1423 hatch
  1438 hatch
  1424 
  1439 
  1425     "The hatch style will define a hatched brush between these patterns:   
  1440     "The hatch style will define a hatched brush between these patterns:
  1426 
  1441 
  1427        #none                                     
  1442        #none
  1428        #horizontal              -----       HS_HORIZONTAL = 0       
  1443        #horizontal              -----       HS_HORIZONTAL = 0
  1429        #vertical                |||||       HS_VERTICAL = 1
  1444        #vertical                |||||       HS_VERTICAL = 1
  1430        #fDiagonal               \\\\\       HS_FDIAGONAL = 2
  1445        #fDiagonal               \\\\\       HS_FDIAGONAL = 2
  1431        #bDiagonal               /////       HS_BDIAGONAL = 3
  1446        #bDiagonal               /////       HS_BDIAGONAL = 3
  1432        #cross                   +++++       HS_CROSS = 4
  1447        #cross                   +++++       HS_CROSS = 4
  1433        #diagonalCross           xxxxx       HS_DIAGCROSS = 5
  1448        #diagonalCross           xxxxx       HS_DIAGCROSS = 5
  1437     ^ hatch
  1452     ^ hatch
  1438 !
  1453 !
  1439 
  1454 
  1440 hatch: aSymbol
  1455 hatch: aSymbol
  1441 
  1456 
  1442     "The hatch style will define a hatched brush between these patterns:   
  1457     "The hatch style will define a hatched brush between these patterns:
  1443 
  1458 
  1444        #none                                     
  1459        #none
  1445        #horizontal              -----       HS_HORIZONTAL = 0       
  1460        #horizontal              -----       HS_HORIZONTAL = 0
  1446        #vertical                |||||       HS_VERTICAL = 1
  1461        #vertical                |||||       HS_VERTICAL = 1
  1447        #fDiagonal               \\\\\       HS_FDIAGONAL = 2
  1462        #fDiagonal               \\\\\       HS_FDIAGONAL = 2
  1448        #bDiagonal               /////       HS_BDIAGONAL = 3
  1463        #bDiagonal               /////       HS_BDIAGONAL = 3
  1449        #cross                   +++++       HS_CROSS = 4
  1464        #cross                   +++++       HS_CROSS = 4
  1450        #diagonalCross           xxxxx       HS_DIAGCROSS = 5
  1465        #diagonalCross           xxxxx       HS_DIAGCROSS = 5
  1467 %}
  1482 %}
  1468 !
  1483 !
  1469 
  1484 
  1470 platformName
  1485 platformName
  1471     "used by #fillRoundRectangleX ...."
  1486     "used by #fillRoundRectangleX ...."
  1472     ^ Smalltalk platformName asUppercase      
  1487     ^ Smalltalk platformName asUppercase
  1473 !
  1488 !
  1474 
  1489 
  1475 setBitmapMask:aBitmapId in:aDC
  1490 setBitmapMask:aBitmapId in:aDC
  1476     "set or clear the drawing mask - a bitmap mask using current fg/bg"
  1491     "set or clear the drawing mask - a bitmap mask using current fg/bg"
  1477 
  1492 
  1683 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1698 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1684 	DWORD clr = 0 /* 0xFFFFFFFF */;
  1699 	DWORD clr = 0 /* 0xFFFFFFFF */;
  1685 	HANDLE prevPen, hPen;
  1700 	HANDLE prevPen, hPen;
  1686 	double xB, yB, xE, yE, xR, yR;
  1701 	double xB, yB, xE, yE, xR, yR;
  1687 	COLORREF fgColor;
  1702 	COLORREF fgColor;
  1688 	int lStyleSymbol, lStyleInt;
  1703 	OBJ lStyleSymbol;
       
  1704 	int lStyleInt;
  1689 	int lw;
  1705 	int lw;
  1690 
  1706 
  1691 	lw= __intVal(__INST(lineWidth));
  1707 	lw= __intVal(__INST(lineWidth));
  1692 	lStyleSymbol= __INST(lineStyle);
  1708 	lStyleSymbol= __INST(lineStyle);
  1693 
  1709 
  1769 
  1785 
  1770 %{  /* NOCONTEXT */
  1786 %{  /* NOCONTEXT */
  1771     if (__isExternalAddressLike(aDC)
  1787     if (__isExternalAddressLike(aDC)
  1772      && __bothSmallInteger(x0, y0)
  1788      && __bothSmallInteger(x0, y0)
  1773      && __bothSmallInteger(x1, y1)) {
  1789      && __bothSmallInteger(x1, y1)) {
  1774         HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1790 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1775         COLORREF fgColor;
  1791 	COLORREF fgColor;
  1776         HANDLE prevPen, hPen;
  1792 	HANDLE prevPen, hPen;
  1777         int __x1 = __intVal(x1), __y1 = __intVal(y1);
  1793 	int __x1 = __intVal(x1), __y1 = __intVal(y1);
  1778         int lStyleSymbol, lStyleInt;
  1794 	OBJ lStyleSymbol;
  1779         int lw;
  1795 	int lStyleInt;
       
  1796 	int lw;
  1780 
  1797 
  1781 /*      DPRINTF(("displayLine: %d/%d -> %d/%d\n",
  1798 /*      DPRINTF(("displayLine: %d/%d -> %d/%d\n",
  1782                     __intVal(x0), __intVal(y0),
  1799 		    __intVal(x0), __intVal(y0),
  1783                     __x1, __y1));
  1800 		    __x1, __y1));
  1784 */
  1801 */
  1785 
  1802 
  1786         lw= __intVal(__INST(lineWidth));
  1803 	lw= __intVal(__INST(lineWidth));
  1787         lStyleSymbol= __INST(lineStyle);
  1804 	lStyleSymbol= __INST(lineStyle);
  1788 
  1805 
  1789         /*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  1806 	/*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  1790             only works with lineWidth = 1  */
  1807 	    only works with lineWidth = 1  */
  1791 
  1808 
  1792         if (lStyleSymbol == @symbol(solid)) {
  1809 	if (lStyleSymbol == @symbol(solid)) {
  1793             lStyleInt= PS_SOLID;
  1810 	    lStyleInt= PS_SOLID;
  1794         } else if (lStyleSymbol == @symbol(dashed)) {
  1811 	} else if (lStyleSymbol == @symbol(dashed)) {
  1795             lStyleInt= PS_DASH;
  1812 	    lStyleInt= PS_DASH;
  1796         } else if (lStyleSymbol == @symbol(dotted)) {
  1813 	} else if (lStyleSymbol == @symbol(dotted)) {
  1797             lStyleInt= PS_DOT;
  1814 	    lStyleInt= PS_DOT;
  1798         } else if (lStyleSymbol == @symbol(dashDot)) {
  1815 	} else if (lStyleSymbol == @symbol(dashDot)) {
  1799             lStyleInt= PS_DASHDOT;
  1816 	    lStyleInt= PS_DASHDOT;
  1800         } else if (lStyleSymbol == @symbol(dashDotDot)) {
  1817 	} else if (lStyleSymbol == @symbol(dashDotDot)) {
  1801             lStyleInt= PS_DASHDOTDOT;
  1818 	    lStyleInt= PS_DASHDOTDOT;
  1802         } else if (lStyleSymbol == @symbol(insideFrame)) {
  1819 	} else if (lStyleSymbol == @symbol(insideFrame)) {
  1803             lStyleInt= PS_INSIDEFRAME;
  1820 	    lStyleInt= PS_INSIDEFRAME;
  1804         } else
  1821 	} else
  1805             lStyleInt= PS_SOLID;
  1822 	    lStyleInt= PS_SOLID;
  1806 
  1823 
  1807         fgColor = GetTextColor(hDC);
  1824 	fgColor = GetTextColor(hDC);
  1808         hPen = CreatePen(lStyleInt, lw, fgColor);
  1825 	hPen = CreatePen(lStyleInt, lw, fgColor);
  1809         prevPen = SelectObject(hDC, hPen);
  1826 	prevPen = SelectObject(hDC, hPen);
  1810         MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL);
  1827 	MoveToEx(hDC, __intVal(x0), __intVal(y0), NULL);
  1811         LineTo(hDC, __x1, __y1);
  1828 	LineTo(hDC, __x1, __y1);
  1812         /*
  1829 	/*
  1813          * end-point ...
  1830 	 * end-point ...
  1814          */
  1831 	 */
  1815         // LineTo(hDC, __x1+1, __y1);
  1832 	// LineTo(hDC, __x1+1, __y1);
  1816 
  1833 
  1817         SelectObject(hDC, prevPen);
  1834 	SelectObject(hDC, prevPen);
  1818         DeleteObject(hPen);
  1835 	DeleteObject(hPen);
  1819 
  1836 
  1820         RETURN ( self );
  1837 	RETURN ( self );
  1821     }
  1838     }
  1822 %}
  1839 %}
  1823 !
  1840 !
  1824 
  1841 
  1825 displayPointX:px y:py in:ignoredDrawableId with:aDC
  1842 displayPointX:px y:py in:ignoredDrawableId with:aDC
  1861 	POINT p;
  1878 	POINT p;
  1862 	DWORD clr = 0 /* 0xFFFFFFFF */;
  1879 	DWORD clr = 0 /* 0xFFFFFFFF */;
  1863 	HANDLE prevPen, hPen;
  1880 	HANDLE prevPen, hPen;
  1864 	int lw;
  1881 	int lw;
  1865 	COLORREF fgColor;
  1882 	COLORREF fgColor;
  1866 	int lStyleSymbol, lStyleInt;
  1883 	OBJ lStyleSymbol;
       
  1884 	int lStyleInt;
  1867 
  1885 
  1868 	lw= __intVal(__INST(lineWidth));
  1886 	lw= __intVal(__INST(lineWidth));
  1869 	lStyleSymbol= __INST(lineStyle);
  1887 	lStyleSymbol= __INST(lineStyle);
  1870 
  1888 
  1871 	/*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  1889 	/*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  1961 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1979 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  1962 	POINT p;
  1980 	POINT p;
  1963 	HANDLE prevPen, hPen;
  1981 	HANDLE prevPen, hPen;
  1964 	COLORREF fgColor;
  1982 	COLORREF fgColor;
  1965 	int lw;
  1983 	int lw;
  1966 	int lStyleSymbol, lStyleInt;
  1984 	OBJ lStyleSymbol;
  1967 
  1985 	int lStyleInt;
  1968 
  1986 
  1969 	lw= __intVal(__INST(lineWidth));
  1987 	lw= __intVal(__INST(lineWidth));
  1970 	lStyleSymbol= __INST(lineStyle);
  1988 	lStyleSymbol= __INST(lineStyle);
  1971 
  1989 
  1972 	/*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  1990 	/*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  2039     int xL, yT;
  2057     int xL, yT;
  2040     if (__isExternalAddressLike(aDC)
  2058     if (__isExternalAddressLike(aDC)
  2041      && __bothSmallInteger(x, y)
  2059      && __bothSmallInteger(x, y)
  2042      && __bothSmallInteger(width, height)) {
  2060      && __bothSmallInteger(width, height)) {
  2043 
  2061 
  2044         xL = __intVal(x);
  2062 	xL = __intVal(x);
  2045         yT = __intVal(y);
  2063 	yT = __intVal(y);
  2046         w = __intVal(width);
  2064 	w = __intVal(width);
  2047         h = __intVal(height);
  2065 	h = __intVal(height);
  2048 
  2066 
  2049         DPRINTF(("displayRectangle: %d/%d -> %d/%d\n", xL, yT, w, h));
  2067 	DPRINTF(("displayRectangle: %d/%d -> %d/%d\n", xL, yT, w, h));
  2050 
  2068 
  2051         if ((w >= 0) && (h >= 0)) {
  2069 	if ((w >= 0) && (h >= 0)) {
  2052             HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2070 	    HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2053             COLORREF fgColor;
  2071 	    COLORREF fgColor;
  2054             HANDLE prevPen, hPen;
  2072 	    HANDLE prevPen, hPen;
  2055             int lStyleSymbol, lStyleInt;
  2073 	    OBJ lStyleSymbol;
  2056 
  2074 	    int lStyleInt;
  2057             int lw;
  2075 	    int lw;
  2058 
  2076 
  2059             lw= __intVal(__INST(lineWidth));
  2077 	    lw= __intVal(__INST(lineWidth));
  2060             lStyleSymbol= __INST(lineStyle);
  2078 	    lStyleSymbol= __INST(lineStyle);
  2061 
  2079 
  2062             /*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  2080 	    /*  PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT
  2063                 only works with lineWidth = 1  */
  2081 		only works with lineWidth = 1  */
  2064 
  2082 
  2065             if (lStyleSymbol == @symbol(solid)) {
  2083 	    if (lStyleSymbol == @symbol(solid)) {
  2066                 lStyleInt= PS_SOLID;
  2084 		lStyleInt= PS_SOLID;
  2067             } else if (lStyleSymbol == @symbol(dashed)) {
  2085 	    } else if (lStyleSymbol == @symbol(dashed)) {
  2068                 lStyleInt= PS_DASH;
  2086 		lStyleInt= PS_DASH;
  2069             } else if (lStyleSymbol == @symbol(dotted)) {
  2087 	    } else if (lStyleSymbol == @symbol(dotted)) {
  2070                 lStyleInt= PS_DOT;
  2088 		lStyleInt= PS_DOT;
  2071             } else if (lStyleSymbol == @symbol(dashDot)) {
  2089 	    } else if (lStyleSymbol == @symbol(dashDot)) {
  2072                 lStyleInt= PS_DASHDOT;
  2090 		lStyleInt= PS_DASHDOT;
  2073             } else if (lStyleSymbol == @symbol(dashDotDot)) {
  2091 	    } else if (lStyleSymbol == @symbol(dashDotDot)) {
  2074                 lStyleInt= PS_DASHDOTDOT;
  2092 		lStyleInt= PS_DASHDOTDOT;
  2075             } else if (lStyleSymbol == @symbol(insideFrame)) {
  2093 	    } else if (lStyleSymbol == @symbol(insideFrame)) {
  2076                 lStyleInt= PS_INSIDEFRAME;
  2094 		lStyleInt= PS_INSIDEFRAME;
  2077             } else
  2095 	    } else
  2078                 lStyleInt= PS_SOLID;
  2096 		lStyleInt= PS_SOLID;
  2079 
  2097 
  2080             fgColor = GetTextColor(hDC);
  2098 	    fgColor = GetTextColor(hDC);
  2081             hPen = CreatePen(lStyleInt, lw, fgColor);
  2099 	    hPen = CreatePen(lStyleInt, lw, fgColor);
  2082 
  2100 
  2083             prevPen = SelectObject(hDC, hPen);
  2101 	    prevPen = SelectObject(hDC, hPen);
  2084             MoveToEx(hDC, xL, yT, NULL);
  2102 	    MoveToEx(hDC, xL, yT, NULL);
  2085             LineTo(hDC, xL+w, yT);       // to top-right
  2103 	    LineTo(hDC, xL+w, yT);       // to top-right
  2086             LineTo(hDC, xL+w, yT+h);     // to bot-right
  2104 	    LineTo(hDC, xL+w, yT+h);     // to bot-right
  2087             MoveToEx(hDC, xL, yT, NULL); // back to top-left
  2105 	    MoveToEx(hDC, xL, yT, NULL); // back to top-left
  2088             LineTo(hDC, xL, yT+h);       // to bot-left
  2106 	    LineTo(hDC, xL, yT+h);       // to bot-left
  2089             // LineTo(hDC, xL+w+1, yT+h);   // move pen one pixel more
  2107 	    // LineTo(hDC, xL+w+1, yT+h);   // move pen one pixel more
  2090             LineTo(hDC, xL+w,   yT+h);   // move pen one pixel more
  2108 	    LineTo(hDC, xL+w,   yT+h);   // move pen one pixel more
  2091 
  2109 
  2092             SelectObject(hDC, prevPen);
  2110 	    SelectObject(hDC, prevPen);
  2093             DeleteObject(hPen);
  2111 	    DeleteObject(hPen);
  2094 
  2112 
  2095         }
  2113 	}
  2096         RETURN ( self );
  2114 	RETURN ( self );
  2097     }
  2115     }
  2098 %}.
  2116 %}.
  2099     self primitiveFailed
  2117     self primitiveFailed
  2100 
  2118 
  2101     "Created: / 28-07-2006 / 20:18:25 / fm"
  2119     "Created: / 28-07-2006 / 20:18:25 / fm"
  2109 
  2127 
  2110     wC := wCorn.
  2128     wC := wCorn.
  2111     hC := hCorn.
  2129     hC := hCorn.
  2112 
  2130 
  2113     self scale = 1 ifTrue:[
  2131     self scale = 1 ifTrue:[
  2114         wHalf := wC // 2.
  2132 	wHalf := wC // 2.
  2115         hHalf := hC // 2.
  2133 	hHalf := hC // 2.
  2116     ] ifFalse:[
  2134     ] ifFalse:[
  2117         wHalf := wC / 2.
  2135 	wHalf := wC / 2.
  2118         hHalf := hC / 2.
  2136 	hHalf := hC / 2.
  2119     ].
  2137     ].
  2120 
  2138 
  2121     "top left arc"
  2139     "top left arc"
  2122     self displayArcX:left y:top width:wC height:hC from:90 angle:90.
  2140     self displayArcX:left y:top width:wC height:hC from:90 angle:90.
  2123 
  2141 
  2136     "left line"
  2154     "left line"
  2137     self displayLineFromX:left y:(top + hHalf - 1) toX:left y:(bottom - hHalf).
  2155     self displayLineFromX:left y:(top + hHalf - 1) toX:left y:(bottom - hHalf).
  2138 
  2156 
  2139     "bottom line"
  2157     "bottom line"
  2140     self displayLineFromX:(left + wHalf-1) y:bottom
  2158     self displayLineFromX:(left + wHalf-1) y:bottom
  2141                       toX:(right - wHalf ) y:bottom.
  2159 		      toX:(right - wHalf ) y:bottom.
  2142 
  2160 
  2143     "right line"
  2161     "right line"
  2144     self displayLineFromX:right y:(top + hHalf) toX:right y:(bottom - hHalf).
  2162     self displayLineFromX:right y:(top + hHalf) toX:right y:(bottom - hHalf).
  2145 
  2163 
  2146 
  2164 
  2181     if (__isExternalAddressLike(aDC)
  2199     if (__isExternalAddressLike(aDC)
  2182      && __isNonNilObject(aString)
  2200      && __isNonNilObject(aString)
  2183      && __bothSmallInteger(index1, index2)
  2201      && __bothSmallInteger(index1, index2)
  2184      && __bothSmallInteger(x, y))
  2202      && __bothSmallInteger(x, y))
  2185     {
  2203     {
  2186         HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2204 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2187         int pX, pY;
  2205 	int pX, pY;
  2188         COLORREF fgColor;
  2206 	COLORREF fgColor;
  2189 
  2207 
  2190         pX = __intVal(x);
  2208 	pX = __intVal(x);
  2191         pY = __intVal(y);
  2209 	pY = __intVal(y);
  2192 
  2210 
  2193         if (opaque == true) {
  2211 	if (opaque == true) {
  2194             SetBkMode(hDC, OPAQUE);
  2212 	    SetBkMode(hDC, OPAQUE);
  2195         } else {
  2213 	} else {
  2196             SetBkMode(hDC, TRANSPARENT);
  2214 	    SetBkMode(hDC, TRANSPARENT);
  2197         }
  2215 	}
  2198         fgColor = GetTextColor(hDC);
  2216 	fgColor = GetTextColor(hDC);
  2199         SetTextColor(hDC, fgColor);
  2217 	SetTextColor(hDC, fgColor);
  2200         SetBkColor(hDC, 0xFFFFFFFF);
  2218 	SetBkColor(hDC, 0xFFFFFFFF);
  2201 
  2219 
  2202         cls = __qClass(aString);
  2220 	cls = __qClass(aString);
  2203 
  2221 
  2204         i1 = __intVal(index1) - 1;
  2222 	i1 = __intVal(index1) - 1;
  2205         if (i1 >= 0) {
  2223 	if (i1 >= 0) {
  2206             i2 = __intVal(index2) - 1;
  2224 	    i2 = __intVal(index2) - 1;
  2207             if (i2 < i1) {
  2225 	    if (i2 < i1) {
  2208                 goto ret;
  2226 		goto ret;
  2209             }
  2227 	    }
  2210 
  2228 
  2211             cp = _stringVal(aString);
  2229 	    cp = _stringVal(aString);
  2212             l = i2 - i1 + 1;
  2230 	    l = i2 - i1 + 1;
  2213 
  2231 
  2214             if ((cls == @global(String)) || (cls == @global(Symbol))) {
  2232 	    if ((cls == @global(String)) || (cls == @global(Symbol))) {
  2215                 n = _stringSize(aString);
  2233 		n = _stringSize(aString);
  2216                 if (i2 < n) {
  2234 		if (i2 < n) {
  2217                     cp += i1;
  2235 		    cp += i1;
  2218                     DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
  2236 		    DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
  2219 
  2237 
  2220                     if (l > 32767) {
  2238 		    if (l > 32767) {
  2221                         l = 32767;
  2239 			l = 32767;
  2222                     }
  2240 		    }
  2223                     if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2241 		    if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2224                         DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2242 			DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2225                     }
  2243 		    }
  2226                     goto ret;
  2244 		    goto ret;
  2227                 }
  2245 		}
  2228             }
  2246 	    }
  2229 
  2247 
  2230             nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  2248 	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  2231             cp += nInstBytes;
  2249 	    cp += nInstBytes;
  2232             n = __byteArraySize(aString) - nInstBytes;
  2250 	    n = __byteArraySize(aString) - nInstBytes;
  2233 
  2251 
  2234             if (__isBytes(aString)) {
  2252 	    if (__isBytes(aString)) {
  2235                 if (i2 < n) {
  2253 		if (i2 < n) {
  2236                     cp += i1;
  2254 		    cp += i1;
  2237                     DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
  2255 		    DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
  2238                     if (l > 32767) {
  2256 		    if (l > 32767) {
  2239                         l = 32767;
  2257 			l = 32767;
  2240                     }
  2258 		    }
  2241                     if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2259 		    if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2242                         DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2260 			DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2243                     }
  2261 		    }
  2244                     goto ret;
  2262 		    goto ret;
  2245                 }
  2263 		}
  2246             }
  2264 	    }
  2247 
  2265 
  2248             /* Unicode */
  2266 	    /* Unicode */
  2249             if (__isWords(aString)) {
  2267 	    if (__isWords(aString)) {
  2250                 n = n / 2;
  2268 		n = n / 2;
  2251                 if (i2 < n) {
  2269 		if (i2 < n) {
  2252                     WIDECHAR *w_cp = (WIDECHAR *)cp;
  2270 		    WIDECHAR *w_cp = (WIDECHAR *)cp;
  2253 
  2271 
  2254                     w_cp += i1;
  2272 		    w_cp += i1;
  2255 
  2273 
  2256                     if (! TextOutW(hDC, pX, pY, w_cp, l)) {
  2274 		    if (! TextOutW(hDC, pX, pY, w_cp, l)) {
  2257                         DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError()));
  2275 			DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError()));
  2258                     }
  2276 		    }
  2259                     goto ret;
  2277 		    goto ret;
  2260                 }
  2278 		}
  2261             }
  2279 	    }
  2262         }
  2280 	}
  2263 ret:
  2281 ret:
  2264         RETURN ( self );
  2282 	RETURN ( self );
  2265     }
  2283     }
  2266 %}.
  2284 %}.
  2267     self primitiveFailed
  2285     self primitiveFailed
  2268 
  2286 
  2269     "Created: / 28-07-2006 / 20:35:19 / fm"
  2287     "Created: / 28-07-2006 / 20:35:19 / fm"
  2283     if (__isExternalAddressLike(aDC)
  2301     if (__isExternalAddressLike(aDC)
  2284      && __isNonNilObject(aString)
  2302      && __isNonNilObject(aString)
  2285      && __bothSmallInteger(index1, index2)
  2303      && __bothSmallInteger(index1, index2)
  2286      && __bothSmallInteger(x, y))
  2304      && __bothSmallInteger(x, y))
  2287     {
  2305     {
  2288         HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2306 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2289         int pX, pY;
  2307 	int pX, pY;
  2290         COLORREF fgColor;
  2308 	COLORREF fgColor;
  2291 
  2309 
  2292         pX = __intVal(x);
  2310 	pX = __intVal(x);
  2293         pY = __intVal(y);
  2311 	pY = __intVal(y);
  2294         pY -= __intVal(fontAscent);
  2312 	pY -= __intVal(fontAscent);
  2295 
  2313 
  2296         if (opaque == true) {
  2314 	if (opaque == true) {
  2297             SetBkMode(hDC, OPAQUE);
  2315 	    SetBkMode(hDC, OPAQUE);
  2298         } else {
  2316 	} else {
  2299             SetBkMode(hDC, TRANSPARENT);
  2317 	    SetBkMode(hDC, TRANSPARENT);
  2300         }
  2318 	}
  2301         fgColor = GetTextColor(hDC);
  2319 	fgColor = GetTextColor(hDC);
  2302         SetTextColor(hDC, fgColor);
  2320 	SetTextColor(hDC, fgColor);
  2303         SetBkColor(hDC, 0xFFFFFFFF);
  2321 	SetBkColor(hDC, 0xFFFFFFFF);
  2304 
  2322 
  2305         cls = __qClass(aString);
  2323 	cls = __qClass(aString);
  2306 
  2324 
  2307         i1 = __intVal(index1) - 1;
  2325 	i1 = __intVal(index1) - 1;
  2308         if (i1 >= 0) {
  2326 	if (i1 >= 0) {
  2309             i2 = __intVal(index2) - 1;
  2327 	    i2 = __intVal(index2) - 1;
  2310             if (i2 < i1) {
  2328 	    if (i2 < i1) {
  2311                 goto ret;
  2329 		goto ret;
  2312             }
  2330 	    }
  2313 
  2331 
  2314             cp = _stringVal(aString);
  2332 	    cp = _stringVal(aString);
  2315             l = i2 - i1 + 1;
  2333 	    l = i2 - i1 + 1;
  2316 
  2334 
  2317             if ((cls == @global(String)) || (cls == @global(Symbol))) {
  2335 	    if ((cls == @global(String)) || (cls == @global(Symbol))) {
  2318                 n = _stringSize(aString);
  2336 		n = _stringSize(aString);
  2319                 if (i2 < n) {
  2337 		if (i2 < n) {
  2320                     cp += i1;
  2338 		    cp += i1;
  2321                     DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
  2339 		    DPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
  2322 
  2340 
  2323                     if (l > 32767) {
  2341 		    if (l > 32767) {
  2324                         l = 32767;
  2342 			l = 32767;
  2325                     }
  2343 		    }
  2326                     if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2344 		    if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2327                         DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2345 			DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2328                     }
  2346 		    }
  2329                     goto ret;
  2347 		    goto ret;
  2330                 }
  2348 		}
  2331             }
  2349 	    }
  2332 
  2350 
  2333             nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  2351 	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
  2334             cp += nInstBytes;
  2352 	    cp += nInstBytes;
  2335             n = __byteArraySize(aString) - nInstBytes;
  2353 	    n = __byteArraySize(aString) - nInstBytes;
  2336 
  2354 
  2337             if (__isBytes(aString)) {
  2355 	    if (__isBytes(aString)) {
  2338                 if (i2 < n) {
  2356 		if (i2 < n) {
  2339                     cp += i1;
  2357 		    cp += i1;
  2340                     DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
  2358 		    DPRINTF(("string: %s pos=%d/%d\n", cp, pX, pY));
  2341                     if (l > 32767) {
  2359 		    if (l > 32767) {
  2342                         l = 32767;
  2360 			l = 32767;
  2343                     }
  2361 		    }
  2344                     if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2362 		    if (! TextOut(hDC, pX, pY, (char *)cp, l)) {
  2345                         DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2363 			DFPRINTF((stderr, "WinPrinter [warning]: Textout failed. %d\n", GetLastError()));
  2346                     }
  2364 		    }
  2347                     goto ret;
  2365 		    goto ret;
  2348                 }
  2366 		}
  2349             }
  2367 	    }
  2350 
  2368 
  2351             /* Unicode */
  2369 	    /* Unicode */
  2352             if (__isWords(aString)) {
  2370 	    if (__isWords(aString)) {
  2353                 n = n / 2;
  2371 		n = n / 2;
  2354                 if (i2 < n) {
  2372 		if (i2 < n) {
  2355                     WIDECHAR *w_cp = (WIDECHAR *)cp;
  2373 		    WIDECHAR *w_cp = (WIDECHAR *)cp;
  2356 
  2374 
  2357                     w_cp += i1;
  2375 		    w_cp += i1;
  2358 
  2376 
  2359                     if (! TextOutW(hDC, pX, pY, w_cp, l)) {
  2377 		    if (! TextOutW(hDC, pX, pY, w_cp, l)) {
  2360                         DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError()));
  2378 			DFPRINTF((stderr, "WinPrinter [warning]: TextoutW failed. %d\n", GetLastError()));
  2361                     }
  2379 		    }
  2362                     goto ret;
  2380 		    goto ret;
  2363                 }
  2381 		}
  2364             }
  2382 	    }
  2365         }
  2383 	}
  2366 ret:
  2384 ret:
  2367         RETURN ( self );
  2385 	RETURN ( self );
  2368     }
  2386     }
  2369 %}.
  2387 %}.
  2370     self primitiveFailed
  2388     self primitiveFailed
  2371 
  2389 
  2372     "Created: / 28-07-2006 / 20:35:19 / fm"
  2390     "Created: / 28-07-2006 / 20:35:19 / fm"
  2397 		     with:aDC
  2415 		     with:aDC
  2398 		     opaque:opaque
  2416 		     opaque:opaque
  2399 !
  2417 !
  2400 
  2418 
  2401 fillArcX:x y:y width:width height:height from:startAngle angle:angle
  2419 fillArcX:x y:y width:width height:height from:startAngle angle:angle
  2402                in:ignoredDrawableId with:aDC
  2420 	       in:ignoredDrawableId with:aDC
  2403     "fill an arc. If any coordinate is not integer, an error is triggered.
  2421     "fill an arc. If any coordinate is not integer, an error is triggered.
  2404      The angles may be floats or integer - they are given in degrees."
  2422      The angles may be floats or integer - they are given in degrees."
  2405 
  2423 
  2406     | hatchSymbol |
  2424     | hatchSymbol |
  2407 
  2425 
  2410 %{
  2428 %{
  2411     int __x, __y, w, h;
  2429     int __x, __y, w, h;
  2412     float angle1, angle2;
  2430     float angle1, angle2;
  2413 
  2431 
  2414     if (__isSmallInteger(startAngle))
  2432     if (__isSmallInteger(startAngle))
  2415         angle1 = (float)(__intVal(startAngle));
  2433 	angle1 = (float)(__intVal(startAngle));
  2416     else if (__isFloat(startAngle)) {
  2434     else if (__isFloat(startAngle)) {
  2417         angle1 = __floatVal(startAngle);
  2435 	angle1 = __floatVal(startAngle);
  2418     } else if (__isShortFloat(startAngle)) {
  2436     } else if (__isShortFloat(startAngle)) {
  2419         angle1 = __shortFloatVal(startAngle);
  2437 	angle1 = __shortFloatVal(startAngle);
  2420     } else goto bad;
  2438     } else goto bad;
  2421 
  2439 
  2422     if (__isSmallInteger(angle))
  2440     if (__isSmallInteger(angle))
  2423         angle2 = (float)(__intVal(angle));
  2441 	angle2 = (float)(__intVal(angle));
  2424     else if (__isFloat(angle)) {
  2442     else if (__isFloat(angle)) {
  2425         angle2 = __floatVal(angle);
  2443 	angle2 = __floatVal(angle);
  2426     } else if (__isShortFloat(angle)) {
  2444     } else if (__isShortFloat(angle)) {
  2427         angle2 = __shortFloatVal(angle);
  2445 	angle2 = __shortFloatVal(angle);
  2428     } else goto bad;
  2446     } else goto bad;
  2429 
  2447 
  2430     if (angle2 <= 0) {
  2448     if (angle2 <= 0) {
  2431         RETURN (self);
  2449 	RETURN (self);
  2432     }
  2450     }
  2433 
  2451 
  2434     if (__isExternalAddressLike(aDC)
  2452     if (__isExternalAddressLike(aDC)
  2435      && __bothSmallInteger(x, y)
  2453      && __bothSmallInteger(x, y)
  2436      && __bothSmallInteger(width, height))
  2454      && __bothSmallInteger(width, height))
  2437      {
  2455      {
  2438         HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2456 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2439         HBRUSH hBrush, prevBrush;
  2457 	HBRUSH hBrush, prevBrush;
  2440         HPEN prevPen = 0;
  2458 	HPEN prevPen = 0;
  2441         COLORREF fgColor;
  2459 	COLORREF fgColor;
  2442         int hatch, hasHatch;
  2460 	int hatch, hasHatch;
  2443 
  2461 
  2444         w = __intVal(width);
  2462 	w = __intVal(width);
  2445         h = __intVal(height);
  2463 	h = __intVal(height);
  2446         __x = __intVal(x);
  2464 	__x = __intVal(x);
  2447         __y = __intVal(y);
  2465 	__y = __intVal(y);
  2448 
  2466 
  2449         fgColor = GetTextColor(hDC);
  2467 	fgColor = GetTextColor(hDC);
  2450 
  2468 
  2451         hasHatch= 1;
  2469 	hasHatch= 1;
  2452 
  2470 
  2453         if (hatchSymbol == @symbol(none)) {
  2471 	if (hatchSymbol == @symbol(none)) {
  2454             hasHatch= 0;
  2472 	    hasHatch= 0;
  2455         } else if (hatchSymbol == @symbol(horizontal)) {
  2473 	} else if (hatchSymbol == @symbol(horizontal)) {
  2456             hatch= HS_HORIZONTAL;
  2474 	    hatch= HS_HORIZONTAL;
  2457         } else if (hatchSymbol == @symbol(vertical)) {
  2475 	} else if (hatchSymbol == @symbol(vertical)) {
  2458             hatch= HS_VERTICAL;
  2476 	    hatch= HS_VERTICAL;
  2459         } else if (hatchSymbol == @symbol(cross)) {
  2477 	} else if (hatchSymbol == @symbol(cross)) {
  2460             hatch= HS_CROSS;
  2478 	    hatch= HS_CROSS;
  2461         } else if (hatchSymbol == @symbol(bDiagonal)) {
  2479 	} else if (hatchSymbol == @symbol(bDiagonal)) {
  2462             hatch= HS_BDIAGONAL;
  2480 	    hatch= HS_BDIAGONAL;
  2463         } else if (hatchSymbol == @symbol(fDiagonal)) {
  2481 	} else if (hatchSymbol == @symbol(fDiagonal)) {
  2464             hatch= HS_FDIAGONAL;
  2482 	    hatch= HS_FDIAGONAL;
  2465         } else if (hatchSymbol == @symbol(diagonalCross)) {
  2483 	} else if (hatchSymbol == @symbol(diagonalCross)) {
  2466             hatch= HS_DIAGCROSS;
  2484 	    hatch= HS_DIAGCROSS;
  2467         } else
  2485 	} else
  2468             hasHatch= 0;
  2486 	    hasHatch= 0;
  2469 
  2487 
  2470         if (hasHatch) {
  2488 	if (hasHatch) {
  2471             hBrush = CreateHatchBrush(hatch, fgColor);
  2489 	    hBrush = CreateHatchBrush(hatch, fgColor);
  2472         } else {
  2490 	} else {
  2473             hBrush = CreateSolidBrush(fgColor); 
  2491 	    hBrush = CreateSolidBrush(fgColor);
  2474         }
  2492 	}
  2475 
  2493 
  2476         prevBrush = SelectObject(hDC, hBrush);
  2494 	prevBrush = SelectObject(hDC, hBrush);
  2477         if (hBrush == 0) {
  2495 	if (hBrush == 0) {
  2478             DPRINTF(("fillArc: no brush\n"));
  2496 	    DPRINTF(("fillArc: no brush\n"));
  2479         } else {
  2497 	} else {
  2480             HPEN hPen = 0;
  2498 	    HPEN hPen = 0;
  2481 
  2499 
  2482             if (0 /* __isWinNT */) {
  2500 	    if (0 /* __isWinNT */) {
  2483                 fgColor = GetTextColor(hDC);
  2501 		fgColor = GetTextColor(hDC);
  2484                 hPen = CreatePen(PS_SOLID, 1, fgColor);
  2502 		hPen = CreatePen(PS_SOLID, 1, fgColor);
  2485                 prevPen = SelectObject(hDC, hPen);
  2503 		prevPen = SelectObject(hDC, hPen);
  2486                 if (hPen == 0) {
  2504 		if (hPen == 0) {
  2487                     DPRINTF(("fillArc: no pen\n"));
  2505 		    DPRINTF(("fillArc: no pen\n"));
  2488                     goto failpen;
  2506 		    goto failpen;
  2489                 }
  2507 		}
  2490             } else {
  2508 	    } else {
  2491                 prevPen = SelectObject(hDC, GetStockObject(NULL_PEN));
  2509 		prevPen = SelectObject(hDC, GetStockObject(NULL_PEN));
  2492                 w++;
  2510 		w++;
  2493                 h++;
  2511 		h++;
  2494             }
  2512 	    }
  2495 
  2513 
  2496             {
  2514 	    {
  2497                 double xB, yB, xE, yE, xR, yR;
  2515 		double xB, yB, xE, yE, xR, yR;
  2498 
  2516 
  2499                 xR = w / 2;
  2517 		xR = w / 2;
  2500                 yR = h / 2;
  2518 		yR = h / 2;
  2501                 if (angle2 - angle1 >= 360) {
  2519 		if (angle2 - angle1 >= 360) {
  2502                     xB = xE = __x + xR + 0.5;
  2520 		    xB = xE = __x + xR + 0.5;
  2503                     yB = yE = __y /*+ yR + 0.5*/;
  2521 		    yB = yE = __y /*+ yR + 0.5*/;
  2504                 } else {
  2522 		} else {
  2505                     double sin(), cos();
  2523 		    double sin(), cos();
  2506                     float rad1, rad2;
  2524 		    float rad1, rad2;
  2507 
  2525 
  2508                     if (angle1 <= 180)
  2526 		    if (angle1 <= 180)
  2509                         angle1 = 180 - angle1;
  2527 			angle1 = 180 - angle1;
  2510                     else
  2528 		    else
  2511                         angle1 = 360 + 180 - angle1;
  2529 			angle1 = 360 + 180 - angle1;
  2512                     angle2 = angle1 - angle2;
  2530 		    angle2 = angle1 - angle2;
  2513                     /* sigh - compute the intersections ... */
  2531 		    /* sigh - compute the intersections ... */
  2514                     rad1 = (angle1 * 3.14159265359) / 180.0;
  2532 		    rad1 = (angle1 * 3.14159265359) / 180.0;
  2515                     rad2 = (angle2 * 3.14159265359) / 180.0;
  2533 		    rad2 = (angle2 * 3.14159265359) / 180.0;
  2516                     xB = cos(rad1) * xR;
  2534 		    xB = cos(rad1) * xR;
  2517                     yB = sin(rad1) * yR;
  2535 		    yB = sin(rad1) * yR;
  2518                     xE = cos(rad2) * xR;
  2536 		    xE = cos(rad2) * xR;
  2519                     yE = sin(rad2) * yR;
  2537 		    yE = sin(rad2) * yR;
  2520                     xB = __x + xR - xB + 0.5;
  2538 		    xB = __x + xR - xB + 0.5;
  2521                     yB = __y + yR - yB + 0.5;
  2539 		    yB = __y + yR - yB + 0.5;
  2522                     xE = __x + xR - xE + 0.5;
  2540 		    xE = __x + xR - xE + 0.5;
  2523                     yE = __y + yR - yE + 0.5;
  2541 		    yE = __y + yR - yE + 0.5;
  2524                 }
  2542 		}
  2525                 DPRINTF(("fillArc x=%d y=%d w=%d h=%d xB=%d xE=%d yB=%d yE=%d a1=%f a2=%f\n",__x,__y,w,h,(int)xB,(int)xE,(int)yB,(int)yE,angle1,angle2));
  2543 		DPRINTF(("fillArc x=%d y=%d w=%d h=%d xB=%d xE=%d yB=%d yE=%d a1=%f a2=%f\n",__x,__y,w,h,(int)xB,(int)xE,(int)yB,(int)yE,angle1,angle2));
  2526 
  2544 
  2527                 Pie(hDC,
  2545 		Pie(hDC,
  2528                     __x, __y,
  2546 		    __x, __y,
  2529                     __x + w + 1, __y + h + 1,
  2547 		    __x + w + 1, __y + h + 1,
  2530                     (int)xB, (int)yB,
  2548 		    (int)xB, (int)yB,
  2531                     (int)xE, (int)yE);
  2549 		    (int)xE, (int)yE);
  2532 
  2550 
  2533                 if (hPen) {
  2551 		if (hPen) {
  2534                     DeleteObject(hPen);
  2552 		    DeleteObject(hPen);
  2535                 }
  2553 		}
  2536             }
  2554 	    }
  2537 failpen:
  2555 failpen:
  2538             if (prevPen) SelectObject(hDC, prevPen);
  2556 	    if (prevPen) SelectObject(hDC, prevPen);
  2539             DeleteObject(hPen);
  2557 	    DeleteObject(hPen);
  2540 
  2558 
  2541             SelectObject(hDC, prevBrush);
  2559 	    SelectObject(hDC, prevBrush);
  2542             DeleteObject(hBrush);
  2560 	    DeleteObject(hBrush);
  2543         }
  2561 	}
  2544         RETURN ( self );
  2562 	RETURN ( self );
  2545     }
  2563     }
  2546     bad: ;
  2564     bad: ;
  2547 %}.
  2565 %}.
  2548     self primitiveFailed
  2566     self primitiveFailed
  2549 !
  2567 !
  2571 
  2589 
  2572     int w, h;
  2590     int w, h;
  2573     if (__isExternalAddressLike(aDC)
  2591     if (__isExternalAddressLike(aDC)
  2574      && __bothSmallInteger(x, y)
  2592      && __bothSmallInteger(x, y)
  2575      && __bothSmallInteger(width, height)) {
  2593      && __bothSmallInteger(width, height)) {
  2576         w = __intVal(width);
  2594 	w = __intVal(width);
  2577         h = __intVal(height);
  2595 	h = __intVal(height);
  2578 
  2596 
  2579         if ((w >= 0) && (h >= 0)) {
  2597 	if ((w >= 0) && (h >= 0)) {
  2580             HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2598 	    HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2581             HBRUSH hBrush, prevBrush;
  2599 	    HBRUSH hBrush, prevBrush;
  2582             RECT rct;
  2600 	    RECT rct;
  2583             COLORREF fgColor;
  2601 	    COLORREF fgColor;
  2584             int hatch, hasHatch;
  2602 	    int hatch, hasHatch;
  2585 
  2603 
  2586             fgColor = GetTextColor(hDC);
  2604 	    fgColor = GetTextColor(hDC);
  2587             hasHatch= 1;
  2605 	    hasHatch= 1;
  2588 
  2606 
  2589             if (hatchSymbol == @symbol(none)) {
  2607 	    if (hatchSymbol == @symbol(none)) {
  2590                 hasHatch= 0;
  2608 		hasHatch= 0;
  2591             } else if (hatchSymbol == @symbol(horizontal)) {
  2609 	    } else if (hatchSymbol == @symbol(horizontal)) {
  2592                 hatch= HS_HORIZONTAL;
  2610 		hatch= HS_HORIZONTAL;
  2593             } else if (hatchSymbol == @symbol(vertical)) {
  2611 	    } else if (hatchSymbol == @symbol(vertical)) {
  2594                 hatch= HS_VERTICAL;
  2612 		hatch= HS_VERTICAL;
  2595             } else if (hatchSymbol == @symbol(cross)) {
  2613 	    } else if (hatchSymbol == @symbol(cross)) {
  2596                 hatch= HS_CROSS;
  2614 		hatch= HS_CROSS;
  2597             } else if (hatchSymbol == @symbol(bDiagonal)) {
  2615 	    } else if (hatchSymbol == @symbol(bDiagonal)) {
  2598                 hatch= HS_BDIAGONAL;
  2616 		hatch= HS_BDIAGONAL;
  2599             } else if (hatchSymbol == @symbol(fDiagonal)) {
  2617 	    } else if (hatchSymbol == @symbol(fDiagonal)) {
  2600                 hatch= HS_FDIAGONAL;
  2618 		hatch= HS_FDIAGONAL;
  2601             } else if (hatchSymbol == @symbol(diagonalCross)) {
  2619 	    } else if (hatchSymbol == @symbol(diagonalCross)) {
  2602                 hatch= HS_DIAGCROSS;
  2620 		hatch= HS_DIAGCROSS;
  2603             } else
  2621 	    } else
  2604                 hasHatch= 0;
  2622 		hasHatch= 0;
  2605 
  2623 
  2606             if (hasHatch) {
  2624 	    if (hasHatch) {
  2607                 hBrush = CreateHatchBrush(hatch, fgColor);
  2625 		hBrush = CreateHatchBrush(hatch, fgColor);
  2608             } else {
  2626 	    } else {
  2609                 hBrush = CreateSolidBrush(fgColor); 
  2627 		hBrush = CreateSolidBrush(fgColor);
  2610             }
  2628 	    }
  2611 
  2629 
  2612             rct.left = __intVal(x);
  2630 	    rct.left = __intVal(x);
  2613             rct.top  = __intVal(y);
  2631 	    rct.top  = __intVal(y);
  2614             rct.right  = rct.left + w; // + 1;
  2632 	    rct.right  = rct.left + w; // + 1;
  2615             rct.bottom = rct.top  + h; // + 1;
  2633 	    rct.bottom = rct.top  + h; // + 1;
  2616 
  2634 
  2617            prevBrush = SelectObject(hDC, hBrush);
  2635 	   prevBrush = SelectObject(hDC, hBrush);
  2618            FillRect(hDC, &rct, hBrush);
  2636 	   FillRect(hDC, &rct, hBrush);
  2619            SelectObject(hDC, prevBrush);
  2637 	   SelectObject(hDC, prevBrush);
  2620            DeleteObject(hBrush);
  2638 	   DeleteObject(hBrush);
  2621 
  2639 
  2622         }
  2640 	}
  2623     }
  2641     }
  2624     RETURN ( self );
  2642     RETURN ( self );
  2625 
  2643 
  2626 
  2644 
  2627 %}
  2645 %}
  2637     OBJ point, px, py;
  2655     OBJ point, px, py;
  2638     int i, num;
  2656     int i, num;
  2639 
  2657 
  2640     if (__isExternalAddressLike(aDC)
  2658     if (__isExternalAddressLike(aDC)
  2641      && __isSmallInteger(numberOfPoints)) {
  2659      && __isSmallInteger(numberOfPoints)) {
  2642         HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2660 	HANDLE hDC = (HANDLE)(__externalAddressVal(aDC));
  2643         POINT p;
  2661 	POINT p;
  2644         HBRUSH hBrush, prevBrush;
  2662 	HBRUSH hBrush, prevBrush;
  2645         COLORREF fgColor;
  2663 	COLORREF fgColor;
  2646         int hatch, hasHatch;
  2664 	int hatch, hasHatch;
  2647 
  2665 
  2648         num = __intVal(numberOfPoints);
  2666 	num = __intVal(numberOfPoints);
  2649         if (num < 3) {
  2667 	if (num < 3) {
  2650             RETURN ( self );
  2668 	    RETURN ( self );
  2651         }
  2669 	}
  2652         for (i=0; i<num; i++) {
  2670 	for (i=0; i<num; i++) {
  2653             point = __AT_(aPolygon, __MKSMALLINT(i+1));
  2671 	    point = __AT_(aPolygon, __MKSMALLINT(i+1));
  2654             if (! __isPoint(point)) goto fail;
  2672 	    if (! __isPoint(point)) goto fail;
  2655             px = _point_X(point);
  2673 	    px = _point_X(point);
  2656             py = _point_Y(point);
  2674 	    py = _point_Y(point);
  2657             if (! __bothSmallInteger(px, py))
  2675 	    if (! __bothSmallInteger(px, py))
  2658                 goto fail;
  2676 		goto fail;
  2659         }
  2677 	}
  2660 
  2678 
  2661         fgColor = GetTextColor(hDC);
  2679 	fgColor = GetTextColor(hDC);
  2662         hasHatch= 1;
  2680 	hasHatch= 1;
  2663 
  2681 
  2664         if (hatchSymbol == @symbol(none)) {
  2682 	if (hatchSymbol == @symbol(none)) {
  2665             hasHatch= 0;
  2683 	    hasHatch= 0;
  2666         } else if (hatchSymbol == @symbol(horizontal)) {
  2684 	} else if (hatchSymbol == @symbol(horizontal)) {
  2667             hatch= HS_HORIZONTAL;
  2685 	    hatch= HS_HORIZONTAL;
  2668         } else if (hatchSymbol == @symbol(vertical)) {
  2686 	} else if (hatchSymbol == @symbol(vertical)) {
  2669             hatch= HS_VERTICAL;
  2687 	    hatch= HS_VERTICAL;
  2670         } else if (hatchSymbol == @symbol(cross)) {
  2688 	} else if (hatchSymbol == @symbol(cross)) {
  2671             hatch= HS_CROSS;
  2689 	    hatch= HS_CROSS;
  2672         } else if (hatchSymbol == @symbol(bDiagonal)) {
  2690 	} else if (hatchSymbol == @symbol(bDiagonal)) {
  2673             hatch= HS_BDIAGONAL;
  2691 	    hatch= HS_BDIAGONAL;
  2674         } else if (hatchSymbol == @symbol(fDiagonal)) {
  2692 	} else if (hatchSymbol == @symbol(fDiagonal)) {
  2675             hatch= HS_FDIAGONAL;
  2693 	    hatch= HS_FDIAGONAL;
  2676         } else if (hatchSymbol == @symbol(diagonalCross)) {
  2694 	} else if (hatchSymbol == @symbol(diagonalCross)) {
  2677             hatch= HS_DIAGCROSS;
  2695 	    hatch= HS_DIAGCROSS;
  2678         } else
  2696 	} else
  2679             hasHatch= 0;
  2697 	    hasHatch= 0;
  2680 
  2698 
  2681         if (hasHatch) {
  2699 	if (hasHatch) {
  2682             hBrush = CreateHatchBrush(hatch, fgColor);
  2700 	    hBrush = CreateHatchBrush(hatch, fgColor);
  2683         } else {
  2701 	} else {
  2684             hBrush = CreateSolidBrush(fgColor); 
  2702 	    hBrush = CreateSolidBrush(fgColor);
  2685         }
  2703 	}
  2686 
  2704 
  2687         if (hBrush == 0) {
  2705 	if (hBrush == 0) {
  2688             DPRINTF(("fillPolygon: no brush\n"));
  2706 	    DPRINTF(("fillPolygon: no brush\n"));
  2689         } else {
  2707 	} else {
  2690             HPEN prevPen;
  2708 	    HPEN prevPen;
  2691 
  2709 
  2692             prevBrush = SelectObject(hDC, hBrush);
  2710 	    prevBrush = SelectObject(hDC, hBrush);
  2693             prevPen = SelectObject(hDC, GetStockObject(NULL_PEN));
  2711 	    prevPen = SelectObject(hDC, GetStockObject(NULL_PEN));
  2694 
  2712 
  2695             BeginPath(hDC);
  2713 	    BeginPath(hDC);
  2696 
  2714 
  2697             for (i=0; i<num; i++) {
  2715 	    for (i=0; i<num; i++) {
  2698                 point = __AT_(aPolygon, __MKSMALLINT(i+1));
  2716 		point = __AT_(aPolygon, __MKSMALLINT(i+1));
  2699                 px = _point_X(point);
  2717 		px = _point_X(point);
  2700                 py = _point_Y(point);
  2718 		py = _point_Y(point);
  2701                 if (i == 0) {
  2719 		if (i == 0) {
  2702                     MoveToEx(hDC, __intVal(px), __intVal(py), NULL);
  2720 		    MoveToEx(hDC, __intVal(px), __intVal(py), NULL);
  2703                 } else {
  2721 		} else {
  2704                     if (i == (num-1)) {
  2722 		    if (i == (num-1)) {
  2705                         p.x = __intVal(px);
  2723 			p.x = __intVal(px);
  2706                         p.y = __intVal(py);
  2724 			p.y = __intVal(py);
  2707                         PolylineTo(hDC, &p, 1);
  2725 			PolylineTo(hDC, &p, 1);
  2708                     } else {
  2726 		    } else {
  2709                         LineTo(hDC, __intVal(px), __intVal(py));
  2727 			LineTo(hDC, __intVal(px), __intVal(py));
  2710                     }
  2728 		    }
  2711                 }
  2729 		}
  2712             }
  2730 	    }
  2713 
  2731 
  2714             EndPath(hDC);
  2732 	    EndPath(hDC);
  2715             FillPath(hDC);
  2733 	    FillPath(hDC);
  2716             SelectObject(hDC, prevPen);
  2734 	    SelectObject(hDC, prevPen);
  2717             SelectObject(hDC, prevBrush);
  2735 	    SelectObject(hDC, prevBrush);
  2718             DeleteObject(hBrush);
  2736 	    DeleteObject(hBrush);
  2719         }
  2737 	}
  2720         RETURN ( self );
  2738 	RETURN ( self );
  2721 
  2739 
  2722 fail: ;
  2740 fail: ;
  2723     }
  2741     }
  2724 %}
  2742 %}
  2725 !
  2743 !
  2726 
  2744 
  2727 scaleTest_displayString:aString x:x y:y
  2745 scaleTest_displayString:aString x:x y:y
  2728     "draw a string at the coordinate x/y - 
  2746     "draw a string at the coordinate x/y -
  2729      draw foreground-pixels only (in current paint-color), 
  2747      draw foreground-pixels only (in current paint-color),
  2730      leaving background as-is. If the transformation involves scaling, 
  2748      leaving background as-is. If the transformation involves scaling,
  2731      the fonts point-size is scaled as appropriate."
  2749      the fonts point-size is scaled as appropriate."
  2732 
  2750 
  2733     |id pX pY fontUsed sz s fontsEncoding|
  2751     |id pX pY fontUsed sz s fontsEncoding|
  2734 
  2752 
  2735     "hook for non-strings (i.e. attributed text)"
  2753     "hook for non-strings (i.e. attributed text)"
  2736     (aString isString not
  2754     (aString isString not
  2737     or:[aString isText]) ifTrue:[
  2755     or:[aString isText]) ifTrue:[
  2738         ^ aString displayOn:self x:x y:y
  2756 	^ aString displayOn:self x:x y:y
  2739     ].
  2757     ].
  2740 
  2758 
  2741     gcId isNil ifTrue:[
  2759     gcId isNil ifTrue:[
  2742         self initGC
  2760 	self initGC
  2743     ].
  2761     ].
  2744 
  2762 
  2745     fontUsed := font.
  2763     fontUsed := font.
  2746     transformation notNil ifTrue:[
  2764     transformation notNil ifTrue:[
  2747         pX := transformation applyToX:x.
  2765 	pX := transformation applyToX:x.
  2748         pY := transformation applyToY:y.
  2766 	pY := transformation applyToY:y.
  2749         transformation noScale ifFalse:[
  2767 	transformation noScale ifFalse:[
  2750             sz := font size.
  2768 	    sz := font size.
  2751             sz isNil ifTrue:[
  2769 	    sz isNil ifTrue:[
  2752                 "/ oops - not a real font; use original font
  2770 		"/ oops - not a real font; use original font
  2753                 fontUsed := font
  2771 		fontUsed := font
  2754             ] ifFalse:[ |yS|
  2772 	    ] ifFalse:[ |yS|
  2755                 yS := self pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch.
  2773 		yS := self pixelsPerInchOfScreenHeight / Screen current verticalPixelPerInch.
  2756                 yS := self scale y / yS.
  2774 		yS := self scale y / yS.
  2757                 fontUsed := font size:(sz * yS) rounded.
  2775 		fontUsed := font size:(sz * yS) rounded.
  2758             ]
  2776 	    ]
  2759         ]
  2777 	]
  2760     ] ifFalse:[
  2778     ] ifFalse:[
  2761         pX := x.
  2779 	pX := x.
  2762         pY := y.
  2780 	pY := y.
  2763     ].
  2781     ].
  2764     pX := pX rounded.
  2782     pX := pX rounded.
  2765     pY := pY rounded.
  2783     pY := pY rounded.
  2766 
  2784 
  2767     s := aString.
  2785     s := aString.
  2768     fontUsed := fontUsed onDevice:device.
  2786     fontUsed := fontUsed onDevice:device.
  2769     fontsEncoding := fontUsed encoding.
  2787     fontsEncoding := fontUsed encoding.
  2770     (characterEncoding ~~ fontsEncoding) ifTrue:[
  2788     (characterEncoding ~~ fontsEncoding) ifTrue:[
  2771         [
  2789 	[
  2772             s := CharacterEncoder encodeString:s from:characterEncoding into:fontsEncoding.
  2790 	    s := CharacterEncoder encodeString:s from:characterEncoding into:fontsEncoding.
  2773         ] on:CharacterEncoderError do:[:ex|
  2791 	] on:CharacterEncoderError do:[:ex|
  2774             "substitute a default value for codes that cannot be represented
  2792 	    "substitute a default value for codes that cannot be represented
  2775              in the new character set"
  2793 	     in the new character set"
  2776             ex proceedWith:ex defaultValue.
  2794 	    ex proceedWith:ex defaultValue.
  2777         ].
  2795 	].
  2778     ].
  2796     ].
  2779 
  2797 
  2780     id := fontUsed fontId.
  2798     id := fontUsed fontId.
  2781     id isNil ifTrue:[
  2799     id isNil ifTrue:[
  2782         "hook for alien fonts"
  2800 	"hook for alien fonts"
  2783         fontUsed displayString:s x:x y:y in:self
  2801 	fontUsed displayString:s x:x y:y in:self
  2784     ] ifFalse:[
  2802     ] ifFalse:[
  2785         deviceFont ~~ fontUsed ifTrue:[
  2803 	deviceFont ~~ fontUsed ifTrue:[
  2786             device setFont:id in:gcId.
  2804 	    device setFont:id in:gcId.
  2787             deviceFont := fontUsed
  2805 	    deviceFont := fontUsed
  2788         ].
  2806 	].
  2789         device displayString:s x:pX y:pY in:drawableId with:gcId
  2807 	device displayString:s x:pX y:pY in:drawableId with:gcId
  2790     ]
  2808     ]
  2791 
  2809 
  2792     "Modified: 1.7.1997 / 17:08:35 / cg"
  2810     "Modified: 1.7.1997 / 17:08:35 / cg"
  2793 ! !
  2811 ! !
  2794 
  2812 
  2831 !
  2849 !
  2832 
  2850 
  2833 compressColorMapImage: image
  2851 compressColorMapImage: image
  2834     "calculates a new color map for the image, using only used colors"
  2852     "calculates a new color map for the image, using only used colors"
  2835 
  2853 
  2836     |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| 
  2854     |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits|
  2837 
  2855 
  2838     oldImage := image.
  2856     oldImage := image.
  2839     depth := oldImage depth.
  2857     depth := oldImage depth.
  2840 
  2858 
  2841     oldImage photometric ~~ #palette ifTrue:[
  2859     oldImage photometric ~~ #palette ifTrue:[
  2842         Transcript showCR:'Compress colorMap: Only palette images have colormaps.'.
  2860 	Transcript showCR:'Compress colorMap: Only palette images have colormaps.'.
  2843         ^ image
  2861 	^ image
  2844     ].
  2862     ].
  2845 
  2863 
  2846     usedColors := oldImage realUsedColors.
  2864     usedColors := oldImage realUsedColors.
  2847     usedColors size == (1 bitShift:depth) ifTrue:[
  2865     usedColors size == (1 bitShift:depth) ifTrue:[
  2848         Transcript showCR:'Compress colorMap: All colors are used - no compression.'.
  2866 	Transcript showCR:'Compress colorMap: All colors are used - no compression.'.
  2849         ^ image
  2867 	^ image
  2850     ].
  2868     ].
  2851     usedColors size == oldImage colorMap size ifTrue:[
  2869     usedColors size == oldImage colorMap size ifTrue:[
  2852         Transcript showCR:'Compress colorMap: Colormap already compressed - no compression.'.
  2870 	Transcript showCR:'Compress colorMap: Colormap already compressed - no compression.'.
  2853         ^ image
  2871 	^ image
  2854     ].
  2872     ].
  2855 
  2873 
  2856         "/ translation table
  2874 	"/ translation table
  2857         oldToNew := ByteArray new:(1 bitShift:depth).
  2875 	oldToNew := ByteArray new:(1 bitShift:depth).
  2858         newColorMap := usedColors asArray.
  2876 	newColorMap := usedColors asArray.
  2859         newColorMap sort:self sortBlockForColors.
  2877 	newColorMap sort:self sortBlockForColors.
  2860 
  2878 
  2861         oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
  2879 	oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
  2862             |newPixel|
  2880 	    |newPixel|
  2863 
  2881 
  2864             (usedColors includes:clr) ifTrue:[
  2882 	    (usedColors includes:clr) ifTrue:[
  2865                 newPixel := newColorMap indexOf:clr.
  2883 		newPixel := newColorMap indexOf:clr.
  2866                 oldToNew at:oldIdx put:newPixel-1.
  2884 		oldToNew at:oldIdx put:newPixel-1.
  2867             ]
  2885 	    ]
  2868         ].
  2886 	].
  2869 
  2887 
  2870         oldBits := oldImage bits.
  2888 	oldBits := oldImage bits.
  2871         newBits := ByteArray new:(oldBits size).
  2889 	newBits := ByteArray new:(oldBits size).
  2872         depth ~~ 8 ifTrue:[
  2890 	depth ~~ 8 ifTrue:[
  2873             "/ expand/compress can only handle 8bits
  2891 	    "/ expand/compress can only handle 8bits
  2874             tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
  2892 	    tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
  2875             oldBits
  2893 	    oldBits
  2876                 expandPixels:depth
  2894 		expandPixels:depth
  2877                 width:oldImage width
  2895 		width:oldImage width
  2878                 height:oldImage height 
  2896 		height:oldImage height
  2879                 into:tmpBits
  2897 		into:tmpBits
  2880                 mapping:oldToNew.
  2898 		mapping:oldToNew.
  2881             tmpBits
  2899 	    tmpBits
  2882                 compressPixels:depth 
  2900 		compressPixels:depth
  2883                 width:oldImage width 
  2901 		width:oldImage width
  2884                 height:oldImage height 
  2902 		height:oldImage height
  2885                 into:newBits 
  2903 		into:newBits
  2886                 mapping:nil
  2904 		mapping:nil
  2887         ] ifFalse:[
  2905 	] ifFalse:[
  2888             oldBits
  2906 	    oldBits
  2889                 expandPixels:depth
  2907 		expandPixels:depth
  2890                 width:oldImage width
  2908 		width:oldImage width
  2891                 height:oldImage height 
  2909 		height:oldImage height
  2892                 into:newBits
  2910 		into:newBits
  2893                 mapping:oldToNew.
  2911 		mapping:oldToNew.
  2894         ].
  2912 	].
  2895 
  2913 
  2896         newImage := oldImage species new
  2914 	newImage := oldImage species new
  2897                         width:oldImage width
  2915 			width:oldImage width
  2898                         height:oldImage height
  2916 			height:oldImage height
  2899                         depth:depth
  2917 			depth:depth
  2900                         fromArray:newBits.
  2918 			fromArray:newBits.
  2901 
  2919 
  2902         newImage colorMap:newColorMap.  
  2920 	newImage colorMap:newColorMap.
  2903         newImage fileName:oldImage fileName.
  2921 	newImage fileName:oldImage fileName.
  2904         newImage mask:(oldImage mask copy).
  2922 	newImage mask:(oldImage mask copy).
  2905 
  2923 
  2906         ^ newImage
  2924 	^ newImage
  2907 
  2925 
  2908     "Created: / 28.7.1998 / 20:03:11 / cg"
  2926     "Created: / 28.7.1998 / 20:03:11 / cg"
  2909     "Modified: / 15.9.1998 / 17:53:32 / cg"
  2927     "Modified: / 15.9.1998 / 17:53:32 / cg"
  2910 !
  2928 !
  2911 
  2929 
  2912 copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId
  2930 copyFromId:sourceId x:srcX y:srcY gc:srcGCId to:destId x:dstX y:dstY gc:dstGCId
  2913                 width:w height:h
  2931 		width:w height:h
  2914     "do a bit-blt; copy bits from the rectangle defined by
  2932     "do a bit-blt; copy bits from the rectangle defined by
  2915      srcX/srcY and w/h from the sourceId drawable to the rectangle
  2933      srcX/srcY and w/h from the sourceId drawable to the rectangle
  2916      below dstX/dstY in the destId drawable. Trigger an error if any
  2934      below dstX/dstY in the destId drawable. Trigger an error if any
  2917      argument is not integer."
  2935      argument is not integer."
  2918 
  2936 
  2921     HWND    dstGcHWIN;
  2939     HWND    dstGcHWIN;
  2922     HBITMAP dstGcHBITMAP;
  2940     HBITMAP dstGcHBITMAP;
  2923 
  2941 
  2924     if (! __isExternalAddressLike(srcGCId)
  2942     if (! __isExternalAddressLike(srcGCId)
  2925      || ! __isExternalAddressLike(dstGCId)) {
  2943      || ! __isExternalAddressLike(dstGCId)) {
  2926         goto fail;
  2944 	goto fail;
  2927     }
  2945     }
  2928 
  2946 
  2929     if (__bothSmallInteger(w, h)
  2947     if (__bothSmallInteger(w, h)
  2930      && __bothSmallInteger(srcX, srcY)
  2948      && __bothSmallInteger(srcX, srcY)
  2931      && __bothSmallInteger(dstX, dstY)) {
  2949      && __bothSmallInteger(dstX, dstY)) {
  2932         HANDLE srcDC = (HANDLE)(__externalAddressVal(srcGCId));
  2950 	HANDLE srcDC = (HANDLE)(__externalAddressVal(srcGCId));
  2933         HANDLE dstDC = (HANDLE)(__externalAddressVal(dstGCId));
  2951 	HANDLE dstDC = (HANDLE)(__externalAddressVal(dstGCId));
  2934 
  2952 
  2935         int fun, aFunctionSymbol;
  2953 	int fun;
  2936         int src_fg, src_bg, dst_fg, dst_bg;
  2954 	OBJ aFunctionSymbol;
  2937         char buf[5];
  2955 	int src_fg, src_bg, dst_fg, dst_bg;
       
  2956 	char buf[5];
  2938 
  2957 
  2939 //          fun = dstGcData->bitbltrop2;
  2958 //          fun = dstGcData->bitbltrop2;
  2940 
  2959 
  2941         aFunctionSymbol= __INST(function);
  2960 	aFunctionSymbol= __INST(function);
  2942 
  2961 
  2943         if (aFunctionSymbol == @symbol(copy)) {
  2962 	if (aFunctionSymbol == @symbol(copy)) {
  2944             fun = SRCCOPY /* R2_COPYPEN */ ;
  2963 	    fun = SRCCOPY /* R2_COPYPEN */ ;
  2945 /*            bfun = BITBLT_COPY;                                          */
  2964 /*            bfun = BITBLT_COPY;                                          */
  2946         } else if (aFunctionSymbol == @symbol(copyInverted)) {
  2965 	} else if (aFunctionSymbol == @symbol(copyInverted)) {
  2947             fun = NOTSRCCOPY /* R2_NOTCOPYPEN */;
  2966 	    fun = NOTSRCCOPY /* R2_NOTCOPYPEN */;
  2948 /*            bfun = BITBLT_COPYINVERTED;                                  */
  2967 /*            bfun = BITBLT_COPYINVERTED;                                  */
  2949         } else if (aFunctionSymbol == @symbol(xor)) {
  2968 	} else if (aFunctionSymbol == @symbol(xor)) {
  2950             fun = SRCINVERT /* R2_XORPEN */;
  2969 	    fun = SRCINVERT /* R2_XORPEN */;
  2951 /*            bfun = BITBLT_XOR;                                           */
  2970 /*            bfun = BITBLT_XOR;                                           */
  2952         } else if (aFunctionSymbol == @symbol(and)) {
  2971 	} else if (aFunctionSymbol == @symbol(and)) {
  2953             fun = SRCAND /* R2_MASKPEN */ ;
  2972 	    fun = SRCAND /* R2_MASKPEN */ ;
  2954 /*            bfun = BITBLT_AND;                                           */
  2973 /*            bfun = BITBLT_AND;                                           */
  2955         } else if (aFunctionSymbol == @symbol(or)) {
  2974 	} else if (aFunctionSymbol == @symbol(or)) {
  2956             fun = MERGECOPY /* R2_MERGEPEN */ ;
  2975 	    fun = MERGECOPY /* R2_MERGEPEN */ ;
  2957 /*            bfun = BITBLT_OR;                                            */
  2976 /*            bfun = BITBLT_OR;                                            */
  2958         }
  2977 	}
  2959 
  2978 
  2960     // convert 123 to string [buf]
  2979     // convert 123 to string [buf]
  2961     // itoa(fun, buf, 10);
  2980     // itoa(fun, buf, 10);
  2962 
  2981 
  2963     //        console_printf(" ", buf);
  2982     //        console_printf(" ", buf);
  2964 
  2983 
  2965 /*
  2984 /*
  2966 #if 0
  2985 #if 0
  2967         switch (fun) {
  2986 	switch (fun) {
  2968           case BITBLT_COPY:
  2987 	  case BITBLT_COPY:
  2969             console_printf("BITBLT_COPY\n");
  2988 	    console_printf("BITBLT_COPY\n");
  2970             break;
  2989 	    break;
  2971           case BITBLT_COPYINVERTED:
  2990 	  case BITBLT_COPYINVERTED:
  2972             console_printf("BITBLT_COPYINVERTED\n");
  2991 	    console_printf("BITBLT_COPYINVERTED\n");
  2973             break;
  2992 	    break;
  2974           case BITBLT_XOR:
  2993 	  case BITBLT_XOR:
  2975             console_printf("BITBLT_XOR\n");
  2994 	    console_printf("BITBLT_XOR\n");
  2976             break;
  2995 	    break;
  2977           case BITBLT_AND:
  2996 	  case BITBLT_AND:
  2978             console_printf("BITBLT_AND\n");
  2997 	    console_printf("BITBLT_AND\n");
  2979             break;
  2998 	    break;
  2980           case BITBLT_OR:
  2999 	  case BITBLT_OR:
  2981             console_printf("BITBLT_OR\n");
  3000 	    console_printf("BITBLT_OR\n");
  2982             break;
  3001 	    break;
  2983         }
  3002 	}
  2984 #endif
  3003 #endif
  2985 */
  3004 */
  2986 
  3005 
  2987 //          fun = dstGcData->bitbltrop2;
  3006 //          fun = dstGcData->bitbltrop2;
  2988 
  3007 
  2989         if (0 /* fun == BITBLT_COPY */) {
  3008 	if (0 /* fun == BITBLT_COPY */) {
  2990             src_fg = dst_fg = 0xFFFFFF;
  3009 	    src_fg = dst_fg = 0xFFFFFF;
  2991             src_bg = dst_bg = 0x000000;
  3010 	    src_bg = dst_bg = 0x000000;
  2992         } else {
  3011 	} else {
  2993             src_fg = GetTextColor(srcDC) /* srcGcData->fgColor */;
  3012 	    src_fg = GetTextColor(srcDC) /* srcGcData->fgColor */;
  2994             src_bg = GetBkColor(dstDC) /* srcGcData->bgColor */;
  3013 	    src_bg = GetBkColor(dstDC) /* srcGcData->bgColor */;
  2995             dst_fg = GetTextColor(srcDC) /* dstGcData->fgColor */;
  3014 	    dst_fg = GetTextColor(srcDC) /* dstGcData->fgColor */;
  2996             dst_bg = GetBkColor(dstDC) /* dstGcData->bgColor */;
  3015 	    dst_bg = GetBkColor(dstDC) /* dstGcData->bgColor */;
  2997         }
  3016 	}
  2998 
  3017 
  2999         SetBkColor(dstDC, dst_fg);
  3018 	SetBkColor(dstDC, dst_fg);
  3000         SetTextColor(dstDC, dst_bg);
  3019 	SetTextColor(dstDC, dst_bg);
  3001 
  3020 
  3002         SetBkColor(srcDC, src_fg);
  3021 	SetBkColor(srcDC, src_fg);
  3003         SetTextColor(srcDC, src_bg);
  3022 	SetTextColor(srcDC, src_bg);
  3004 
  3023 
  3005 /*
  3024 /*
  3006         CPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC)));
  3025 	CPRINTF(("bitblt src f:%x b:%x",GetTextColor(srcDC),GetBkColor(srcDC)));
  3007         CPRINTF(("dst f:%x b:%x\n",GetTextColor(dstDC),GetBkColor(dstDC)));
  3026 	CPRINTF(("dst f:%x b:%x\n",GetTextColor(dstDC),GetBkColor(dstDC)));
  3008 */
  3027 */
  3009         if (BitBlt(dstDC,
  3028 	if (BitBlt(dstDC,
  3010              __intVal(dstX), __intVal(dstY),
  3029 	     __intVal(dstX), __intVal(dstY),
  3011              __intVal(w), __intVal(h),
  3030 	     __intVal(w), __intVal(h),
  3012              srcDC,
  3031 	     srcDC,
  3013              __intVal(srcX), __intVal(srcY),
  3032 	     __intVal(srcX), __intVal(srcY),
  3014              fun)
  3033 	     fun)
  3015            == 0
  3034 	   == 0
  3016           ) {
  3035 	  ) {
  3017             console_fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n");
  3036 	    console_fprintf(stderr, "WinWorkstation [info]: ERROR in BitBlt\n");
  3018         }
  3037 	}
  3019 
  3038 
  3020 /*
  3039 /*
  3021         if (dstGcData != srcGcData) {
  3040 	if (dstGcData != srcGcData) {
  3022             SetBkColor(dstDC, dstGcData->bgColor);
  3041 	    SetBkColor(dstDC, dstGcData->bgColor);
  3023             SetTextColor(dstDC, dstGcData->fgColor);
  3042 	    SetTextColor(dstDC, dstGcData->fgColor);
  3024         }
  3043 	}
  3025         SetBkColor(srcDC, srcGcData->bgColor);
  3044 	SetBkColor(srcDC, srcGcData->bgColor);
  3026         SetTextColor(srcDC, srcGcData->fgColor);
  3045 	SetTextColor(srcDC, srcGcData->fgColor);
  3027 */
  3046 */
  3028 
  3047 
  3029 /*
  3048 /*
  3030         if (srcGcData != dstGcData) {
  3049 	if (srcGcData != dstGcData) {
  3031             _releaseDC(srcGcData);
  3050 	    _releaseDC(srcGcData);
  3032         }
  3051 	}
  3033         _releaseDC(dstGcData);
  3052 	_releaseDC(dstGcData);
  3034 */
  3053 */
  3035         RETURN ( self );
  3054 	RETURN ( self );
  3036     }
  3055     }
  3037 
  3056 
  3038  fail: ;
  3057  fail: ;
  3039 %}.
  3058 %}.
  3040     self primitiveFailed.
  3059     self primitiveFailed.
  3092     HANDLE newBitmapHandle;
  3111     HANDLE newBitmapHandle;
  3093     HANDLE rootDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  3112     HANDLE rootDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  3094 
  3113 
  3095     /*console_printf("CreateBitmap Color\n");*/
  3114     /*console_printf("CreateBitmap Color\n");*/
  3096     if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) {
  3115     if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) {
  3097         if (__intVal(d) == 1) {
  3116 	if (__intVal(d) == 1) {
  3098             newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
  3117 	    newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
  3099         } else {
  3118 	} else {
  3100 #if 0
  3119 #if 0
  3101             if (__intVal(d) != __depth) {
  3120 	    if (__intVal(d) != __depth) {
  3102                 console_printf("invalid depth\n");
  3121 		console_printf("invalid depth\n");
  3103                 RETURN (nil);
  3122 		RETURN (nil);
  3104             }
  3123 	    }
  3105 #endif
  3124 #endif
  3106             newBitmapHandle = CreateCompatibleBitmap(rootDC, __intVal(w), __intVal(h) );
  3125 	    newBitmapHandle = CreateCompatibleBitmap(rootDC, __intVal(w), __intVal(h) );
  3107         }
  3126 	}
  3108 
  3127 
  3109         if (newBitmapHandle) {
  3128 	if (newBitmapHandle) {
  3110             RETURN ( __MKEXTERNALADDRESS(newBitmapHandle));
  3129 	    RETURN ( __MKEXTERNALADDRESS(newBitmapHandle));
  3111         }
  3130 	}
  3112 /*
  3131 /*
  3113         DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle));
  3132 	DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle));
  3114 */
  3133 */
  3115     }
  3134     }
  3116     RETURN (nil);
  3135     RETURN (nil);
  3117 %}
  3136 %}
  3118 !
  3137 !
  3137 
  3156 
  3138     sortedImage := aForm.
  3157     sortedImage := aForm.
  3139 
  3158 
  3140     "Image 16 bits"
  3159     "Image 16 bits"
  3141     aForm depth = 16 ifTrue:[
  3160     aForm depth = 16 ifTrue:[
  3142         bitsWithTransparency := aForm bits.  
  3161 	bitsWithTransparency := aForm bits.
  3143     ].
  3162     ].
  3144     "Image 24 and 32 bits"
  3163     "Image 24 and 32 bits"
  3145     aForm depth >= 24 ifTrue:[
  3164     aForm depth >= 24 ifTrue:[
  3146         |bestFormat|
  3165 	|bestFormat|
  3147         bestFormat := aForm bestSupportedImageFormatFor: Display.
  3166 	bestFormat := aForm bestSupportedImageFormatFor: Display.
  3148         bitsWithTransparency := aForm rgbImageBitsOn: Display bestFormat: bestFormat.
  3167 	bitsWithTransparency := aForm rgbImageBitsOn: Display bestFormat: bestFormat.
  3149     ].
  3168     ].
  3150     "Image up to 8 bits"
  3169     "Image up to 8 bits"
  3151     aForm depth <= 8 ifTrue:[
  3170     aForm depth <= 8 ifTrue:[
  3152         aForm depth < 8 ifTrue:[
  3171 	aForm depth < 8 ifTrue:[
  3153             sortedImage := aForm asImageWithDepth: 8.
  3172 	    sortedImage := aForm asImageWithDepth: 8.
  3154         ].
  3173 	].
  3155 "/        sortedImage := self sortColorMapImage: aForm.
  3174 "/        sortedImage := self sortColorMapImage: aForm.
  3156         sortedImage := self compressColorMapImage: sortedImage.
  3175 	sortedImage := self compressColorMapImage: sortedImage.
  3157 
  3176 
  3158         formMask := sortedImage mask.
  3177 	formMask := sortedImage mask.
  3159         formMask isNil 
  3178 	formMask isNil
  3160             ifTrue:[bitsWithTransparency := sortedImage bits ]
  3179 	    ifTrue:[bitsWithTransparency := sortedImage bits ]
  3161             ifFalse:[
  3180 	    ifFalse:[
  3162                 |bitsWithTransparencySize|
  3181 		|bitsWithTransparencySize|
  3163                 formMask := formMask asImageWithDepth: sortedImage depth.
  3182 		formMask := formMask asImageWithDepth: sortedImage depth.
  3164                 bitsWithTransparency := sortedImage bits copy.
  3183 		bitsWithTransparency := sortedImage bits copy.
  3165                 bitsWithTransparencySize := bitsWithTransparency size.
  3184 		bitsWithTransparencySize := bitsWithTransparency size.
  3166                 formMask bits doWithIndex:[:maskBit :index |
  3185 		formMask bits doWithIndex:[:maskBit :index |
  3167                     bitsWithTransparencySize >= index ifTrue:[
  3186 		    bitsWithTransparencySize >= index ifTrue:[
  3168                         maskBit == 0 ifTrue:[bitsWithTransparency at: index put: 255 "60" "bitClearAt: index"].
  3187 			maskBit == 0 ifTrue:[bitsWithTransparency at: index put: 255 "60" "bitClearAt: index"].
  3169 "/                    maskBit == 1 ifTrue:[bitsWithTransparency at: index put: (bitsWithTransparency at: index)].
  3188 "/                    maskBit == 1 ifTrue:[bitsWithTransparency at: index put: (bitsWithTransparency at: index)].
  3170                     ].
  3189 		    ].
  3171                 ].
  3190 		].
  3172         ].
  3191 	].
  3173 
  3192 
  3174         redVector := sortedImage colorMap redVector.
  3193 	redVector := sortedImage colorMap redVector.
  3175         greenVector := sortedImage colorMap greenVector.
  3194 	greenVector := sortedImage colorMap greenVector.
  3176         blueVector := sortedImage colorMap blueVector.
  3195 	blueVector := sortedImage colorMap blueVector.
  3177     ].
  3196     ].
  3178 
  3197 
  3179     self 
  3198     self
  3180          drawBits: bitsWithTransparency
  3199 	 drawBits: bitsWithTransparency
  3181         redVector: redVector
  3200 	redVector: redVector
  3182       greenVector: greenVector
  3201       greenVector: greenVector
  3183        blueVector: blueVector
  3202        blueVector: blueVector
  3184      bitsPerPixel: sortedImage bitsPerPixel
  3203      bitsPerPixel: sortedImage bitsPerPixel
  3185             depth: sortedImage depth
  3204 	    depth: sortedImage depth
  3186             width: sortedImage width 
  3205 	    width: sortedImage width
  3187            height: sortedImage height
  3206 	   height: sortedImage height
  3188              into: self id
  3207 	     into: self id
  3189                 x: x 
  3208 		x: x
  3190                 y: y
  3209 		y: y
  3191             width: sortedImage width 
  3210 	    width: sortedImage width
  3192            height: sortedImage height
  3211 	   height: sortedImage height
  3193              with: gcId.
  3212 	     with: gcId.
  3194 !
  3213 !
  3195 
  3214 
  3196 drawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3215 drawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3197                           width:imageWidth height:imageHeight
  3216 			  width:imageWidth height:imageHeight
  3198                               x:srcx y:srcy
  3217 			      x:srcx y:srcy
  3199                            into:ignoredDrawableId
  3218 			   into:ignoredDrawableId
  3200                               x:dstx y:dsty
  3219 			      x:dstx y:dsty
  3201                           width:w height:h
  3220 			  width:w height:h
  3202                            with:aGCId
  3221 			   with:aGCId
  3203 
  3222 
  3204     "draw a bitImage which has depth id, width iw and height ih into
  3223     "draw a bitImage which has depth id, width iw and height ih into
  3205      the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty.
  3224      the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty.
  3206      Individual source pixels have bitsPerPixel bits, allowing to draw
  3225      Individual source pixels have bitsPerPixel bits, allowing to draw
  3207      depth and pixel-units to be different.
  3226      depth and pixel-units to be different.
  3213     "
  3232     "
  3214      sorry; I had to separate it into 2 methods, since XPutImage needs
  3233      sorry; I had to separate it into 2 methods, since XPutImage needs
  3215      an unlimited stack, and thus cannot send primitiveFailed
  3234      an unlimited stack, and thus cannot send primitiveFailed
  3216     "
  3235     "
  3217     (self primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3236     (self primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3218                                         width:imageWidth height:imageHeight
  3237 					width:imageWidth height:imageHeight
  3219                                              x:srcx y:srcy
  3238 					     x:srcx y:srcy
  3220                                           into:ignoredDrawableId
  3239 					  into:ignoredDrawableId
  3221                                              x:(dstx rounded) y:(dsty rounded)
  3240 					     x:(dstx rounded) y:(dsty rounded)
  3222                                          width:w height:h
  3241 					 width:w height:h
  3223                                           with:aGCId)
  3242 					  with:aGCId)
  3224     ifFalse:[
  3243     ifFalse:[
  3225         "
  3244 	"
  3226          also happens, if a segmentation violation occurs in the
  3245 	 also happens, if a segmentation violation occurs in the
  3227          XPutImage ...
  3246 	 XPutImage ...
  3228         "
  3247 	"
  3229         self primitiveFailed
  3248 	self primitiveFailed
  3230     ].
  3249     ].
  3231 !
  3250 !
  3232 
  3251 
  3233 drawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth 
  3252 drawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth
  3234                               width:imageWidth height:imageHeight
  3253 			      width:imageWidth height:imageHeight
  3235                                into:ignoredDrawableId
  3254 			       into:ignoredDrawableId
  3236                                   x:dstx y:dsty
  3255 				  x:dstx y:dsty
  3237                               width:w height:h
  3256 			      width:w height:h
  3238                                with:aGCId
  3257 			       with:aGCId
  3239 
  3258 
  3240     "draw a bitImage which has depth id, width iw and height ih into
  3259     "draw a bitImage which has depth id, width iw and height ih into
  3241      the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty.
  3260      the drawable. draw a region of w/h pixels from srcx/srcy to dstx/dsty.
  3242      Individual source pixels have bitsPerPixel bits, allowing to draw
  3261      Individual source pixels have bitsPerPixel bits, allowing to draw
  3243      depth and pixel-units to be different.
  3262      depth and pixel-units to be different.
  3248 
  3267 
  3249     "
  3268     "
  3250      sorry; I had to separate it into 2 methods, since XPutImage needs
  3269      sorry; I had to separate it into 2 methods, since XPutImage needs
  3251      an unlimited stack, and thus cannot send primitiveFailed
  3270      an unlimited stack, and thus cannot send primitiveFailed
  3252     "
  3271     "
  3253     (self primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth 
  3272     (self primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth
  3254                               width:imageWidth height:imageHeight
  3273 			      width:imageWidth height:imageHeight
  3255                                into:ignoredDrawableId
  3274 			       into:ignoredDrawableId
  3256                                   x:(dstx rounded) y:(dsty rounded)
  3275 				  x:(dstx rounded) y:(dsty rounded)
  3257                               width:w height:h
  3276 			      width:w height:h
  3258                                with:aGCId)
  3277 			       with:aGCId)
  3259     ifFalse:[
  3278     ifFalse:[
  3260         self primitiveFailed
  3279 	self primitiveFailed
  3261     ].
  3280     ].
  3262 !
  3281 !
  3263 
  3282 
  3264 primCreateBitmapFromArray:anArray width:w height:h
  3283 primCreateBitmapFromArray:anArray width:w height:h
  3265 %{
  3284 %{
  3274     unsigned char *allocatedBits = 0;
  3293     unsigned char *allocatedBits = 0;
  3275     unsigned char fastBits[10000];
  3294     unsigned char fastBits[10000];
  3276 
  3295 
  3277     if (__bothSmallInteger(w, h)
  3296     if (__bothSmallInteger(w, h)
  3278      && __isNonNilObject(anArray)) {
  3297      && __isNonNilObject(anArray)) {
  3279         OBJ cls = __qClass(anArray);
  3298 	OBJ cls = __qClass(anArray);
  3280 
  3299 
  3281         b_width = __intVal(w);
  3300 	b_width = __intVal(w);
  3282         b_height = __intVal(h);
  3301 	b_height = __intVal(h);
  3283         bytesPerRowST = (b_width + 7) / 8;
  3302 	bytesPerRowST = (b_width + 7) / 8;
  3284         bytesPerRowWN = ((b_width + 15) / 16) * 2;
  3303 	bytesPerRowWN = ((b_width + 15) / 16) * 2;
  3285         padding = bytesPerRowWN - bytesPerRowST;
  3304 	padding = bytesPerRowWN - bytesPerRowST;
  3286 
  3305 
  3287         if ((padding == 0) && (cls == @global(ByteArray))) {
  3306 	if ((padding == 0) && (cls == @global(ByteArray))) {
  3288             b_bits = __ByteArrayInstPtr(anArray)->ba_element;
  3307 	    b_bits = __ByteArrayInstPtr(anArray)->ba_element;
  3289             cp = 0;
  3308 	    cp = 0;
  3290         } else {
  3309 	} else {
  3291             int nBytes = b_height * bytesPerRowWN;
  3310 	    int nBytes = b_height * bytesPerRowWN;
  3292 
  3311 
  3293             if (nBytes < sizeof(fastBits)) {
  3312 	    if (nBytes < sizeof(fastBits)) {
  3294                 cp = b_bits = fastBits;
  3313 		cp = b_bits = fastBits;
  3295             } else {
  3314 	    } else {
  3296                 cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3315 		cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3297                 if (! cp) goto fail;
  3316 		if (! cp) goto fail;
  3298             }
  3317 	    }
  3299         }
  3318 	}
  3300         if (cp) {
  3319 	if (cp) {
  3301             if (__qIsArrayLike(anArray)) {
  3320 	    if (__qIsArrayLike(anArray)) {
  3302                 OBJ *op;
  3321 		OBJ *op;
  3303 
  3322 
  3304                 index = 1;
  3323 		index = 1;
  3305                 op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
  3324 		op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
  3306                 for (row = b_height; row; row--) {
  3325 		for (row = b_height; row; row--) {
  3307                     for (col = bytesPerRowST; col; col--) {
  3326 		    for (col = bytesPerRowST; col; col--) {
  3308                         num = *op++;
  3327 			num = *op++;
  3309                         if (! __isSmallInteger(num))
  3328 			if (! __isSmallInteger(num))
  3310                             goto fail;
  3329 			    goto fail;
  3311                         *cp++ = __intVal(num);
  3330 			*cp++ = __intVal(num);
  3312                     }
  3331 		    }
  3313                     cp += padding;
  3332 		    cp += padding;
  3314                 }
  3333 		}
  3315             } else if (__qIsByteArrayLike(anArray)) {
  3334 	    } else if (__qIsByteArrayLike(anArray)) {
  3316                 unsigned char *pBits;
  3335 		unsigned char *pBits;
  3317 
  3336 
  3318                 pBits = __ByteArrayInstPtr(anArray)->ba_element;
  3337 		pBits = __ByteArrayInstPtr(anArray)->ba_element;
  3319                 for (row = b_height; row; row--) {
  3338 		for (row = b_height; row; row--) {
  3320                     for (col = bytesPerRowST; col; col--) {
  3339 		    for (col = bytesPerRowST; col; col--) {
  3321                         *cp++ = ( *pBits++ /*^ 0xFF*/ );
  3340 			*cp++ = ( *pBits++ /*^ 0xFF*/ );
  3322                     }
  3341 		    }
  3323                     cp += padding;
  3342 		    cp += padding;
  3324                 }
  3343 		}
  3325             } else {
  3344 	    } else {
  3326                 goto fail;
  3345 		goto fail;
  3327             }
  3346 	    }
  3328         }
  3347 	}
  3329 /*
  3348 /*
  3330         CPRINTF(("create bitmap ...\n"));
  3349 	CPRINTF(("create bitmap ...\n"));
  3331 */
  3350 */
  3332         newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
  3351 	newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
  3333 
  3352 
  3334         if (newBitmapHandle ) {
  3353 	if (newBitmapHandle ) {
  3335 /*
  3354 /*
  3336             DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle));
  3355 	    DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle));
  3337 */
  3356 */
  3338             if (allocatedBits) {
  3357 	    if (allocatedBits) {
  3339                 free(allocatedBits);
  3358 		free(allocatedBits);
  3340             }
  3359 	    }
  3341             RETURN ( __MKEXTERNALADDRESS(newBitmapHandle));
  3360 	    RETURN ( __MKEXTERNALADDRESS(newBitmapHandle));
  3342         }
  3361 	}
  3343     }
  3362     }
  3344 fail: ;
  3363 fail: ;
  3345 /*
  3364 /*
  3346     DDPRINTF(("create bitmap FAILED!!!\n"));
  3365     DDPRINTF(("create bitmap FAILED!!!\n"));
  3347 */
  3366 */
  3348     if (allocatedBits) {
  3367     if (allocatedBits) {
  3349 /*
  3368 /*
  3350         CPRINTF(("freeing up bitmap bits ...\n"));
  3369 	CPRINTF(("freeing up bitmap bits ...\n"));
  3351 */
  3370 */
  3352         free(allocatedBits);
  3371 	free(allocatedBits);
  3353     }
  3372     }
  3354 /*
  3373 /*
  3355     CPRINTF(("returning nil ...\n"));
  3374     CPRINTF(("returning nil ...\n"));
  3356 */
  3375 */
  3357     RETURN ( nil );
  3376     RETURN ( nil );
  3358 %}
  3377 %}
  3359 !
  3378 !
  3360 
  3379 
  3361 primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3380 primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
  3362                               width:imageWidth height:imageHeight
  3381 			      width:imageWidth height:imageHeight
  3363                                   x:srcx y:srcy
  3382 				  x:srcx y:srcy
  3364                                into:ignoredDrawableId
  3383 			       into:ignoredDrawableId
  3365                                   x:dstx y:dsty
  3384 				  x:dstx y:dsty
  3366                               width:w height:h
  3385 			      width:w height:h
  3367                                with:aGCId
  3386 			       with:aGCId
  3368 
  3387 
  3369     "since XPutImage may allocate huge amount of stack space
  3388     "since XPutImage may allocate huge amount of stack space
  3370      (some implementations use alloca), this must run with unlimited stack."
  3389      (some implementations use alloca), this must run with unlimited stack."
  3371 
  3390 
  3372 %{
  3391 %{
  3374     unsigned char *b_bits = 0;
  3393     unsigned char *b_bits = 0;
  3375     unsigned char *allocatedBits = 0;
  3394     unsigned char *allocatedBits = 0;
  3376     unsigned char *__imageBits = 0;
  3395     unsigned char *__imageBits = 0;
  3377 
  3396 
  3378     if (__isByteArray(imageBits)) {
  3397     if (__isByteArray(imageBits)) {
  3379         __imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3398 	__imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3380     } else if (__isExternalBytesLike(imageBits)) {
  3399     } else if (__isExternalBytesLike(imageBits)) {
  3381         __imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3400 	__imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3382     }
  3401     }
  3383 
  3402 
  3384     if (/* ISCONNECTED
  3403     if (/* ISCONNECTED
  3385      && */ __isExternalAddressLike(aGCId)
  3404      && */ __isExternalAddressLike(aGCId)
  3386      && __bothSmallInteger(srcx, srcy)
  3405      && __bothSmallInteger(srcx, srcy)
  3389      && __bothSmallInteger(imageWidth, imageHeight)
  3408      && __bothSmallInteger(imageWidth, imageHeight)
  3390      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3409      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3391      && __isSmallInteger(padd)
  3410      && __isSmallInteger(padd)
  3392      && __imageBits)
  3411      && __imageBits)
  3393      {
  3412      {
  3394         struct
  3413 	struct
  3395         {
  3414 	{
  3396           BITMAPINFOHEADER bmiHeader;
  3415 	  BITMAPINFOHEADER bmiHeader;
  3397           DWORD r;
  3416 	  DWORD r;
  3398           DWORD g;
  3417 	  DWORD g;
  3399           DWORD b;
  3418 	  DWORD b;
  3400         } bitmap;
  3419 	} bitmap;
  3401 
  3420 
  3402         HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3421 	HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3403         HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3422 	HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3404 
  3423 
  3405 /*
  3424 /*
  3406         DDPRINTF(("hDC = %x\n", hDC));
  3425 	DDPRINTF(("hDC = %x\n", hDC));
  3407 */
  3426 */
  3408         if (__intVal(padd) != WIN32PADDING) {
  3427 	if (__intVal(padd) != WIN32PADDING) {
  3409             int row, col;
  3428 	    int row, col;
  3410             unsigned char *cp;
  3429 	    unsigned char *cp;
  3411             unsigned char *pBits;
  3430 	    unsigned char *pBits;
  3412             int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3431 	    int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3413             int bi = __intVal(bitsPerPixel);
  3432 	    int bi = __intVal(bitsPerPixel);
  3414 
  3433 
  3415             b_width = __intVal(w);
  3434 	    b_width = __intVal(w);
  3416             b_height = __intVal(h);
  3435 	    b_height = __intVal(h);
  3417             bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd);
  3436 	    bytesPerRowST = (b_width * bi + (__intVal(padd)-1)) / __intVal(padd);
  3418             bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3437 	    bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3419             padding = bytesPerRowWN - bytesPerRowST;
  3438 	    padding = bytesPerRowWN - bytesPerRowST;
  3420             nBytes = b_height * bytesPerRowWN;
  3439 	    nBytes = b_height * bytesPerRowWN;
  3421             /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3440 	    /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3422             if (padding) {
  3441 	    if (padding) {
  3423                 if (nBytes < sizeof(fastBits)) {
  3442 		if (nBytes < sizeof(fastBits)) {
  3424                     cp = b_bits = fastBits;
  3443 		    cp = b_bits = fastBits;
  3425                 } else {
  3444 		} else {
  3426                     cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3445 		    cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3427                 }
  3446 		}
  3428                 if (cp) {
  3447 		if (cp) {
  3429                     pBits = __imageBits;
  3448 		    pBits = __imageBits;
  3430                     for (row = b_height; row; row--) {
  3449 		    for (row = b_height; row; row--) {
  3431                         for (col = bytesPerRowST; col; col--) {
  3450 			for (col = bytesPerRowST; col; col--) {
  3432                             *cp++ = *pBits++;
  3451 			    *cp++ = *pBits++;
  3433                         }
  3452 			}
  3434                         cp += padding;
  3453 			cp += padding;
  3435                     }
  3454 		    }
  3436                 } else
  3455 		} else
  3437                     goto fail;
  3456 		    goto fail;
  3438             }
  3457 	    }
  3439         }
  3458 	}
  3440 
  3459 
  3441         if (b_bits == 0) {
  3460 	if (b_bits == 0) {
  3442             b_bits = __imageBits;
  3461 	    b_bits = __imageBits;
  3443         }
  3462 	}
  3444 
  3463 
  3445         bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  3464 	bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  3446         bitmap.bmiHeader.biPlanes = 1;
  3465 	bitmap.bmiHeader.biPlanes = 1;
  3447         if (__intVal(imageDepth) == 24) {
  3466 	if (__intVal(imageDepth) == 24) {
  3448             /*bitmap.bmiHeader.biCompression = BI_BITFIELDS;
  3467 	    /*bitmap.bmiHeader.biCompression = BI_BITFIELDS;
  3449             bitmap.r = 0xff0000;
  3468 	    bitmap.r = 0xff0000;
  3450             bitmap.g = 0x00ff00;
  3469 	    bitmap.g = 0x00ff00;
  3451             bitmap.b = 0x0000ff;*/
  3470 	    bitmap.b = 0x0000ff;*/
  3452             bitmap.bmiHeader.biCompression = BI_RGB;
  3471 	    bitmap.bmiHeader.biCompression = BI_RGB;
  3453         } else if (__intVal(imageDepth) == 16) {
  3472 	} else if (__intVal(imageDepth) == 16) {
  3454             /*bitmap.bmiHeader.biCompression = BI_RGB;
  3473 	    /*bitmap.bmiHeader.biCompression = BI_RGB;
  3455             bitmap.bmiHeader.biCompression = BI_BITFIELDS;
  3474 	    bitmap.bmiHeader.biCompression = BI_BITFIELDS;
  3456             bitmap.b = 0x001f;
  3475 	    bitmap.b = 0x001f;
  3457             bitmap.g = 0x07e0;
  3476 	    bitmap.g = 0x07e0;
  3458             bitmap.r = 0xf800;*/
  3477 	    bitmap.r = 0xf800;*/
  3459             bitmap.b = 0;
  3478 	    bitmap.b = 0;
  3460             bitmap.g = 0;
  3479 	    bitmap.g = 0;
  3461             bitmap.r = 0;
  3480 	    bitmap.r = 0;
  3462             bitmap.bmiHeader.biCompression = BI_RGB;
  3481 	    bitmap.bmiHeader.biCompression = BI_RGB;
  3463         }
  3482 	}
  3464         bitmap.bmiHeader.biSizeImage = 0;
  3483 	bitmap.bmiHeader.biSizeImage = 0;
  3465         bitmap.bmiHeader.biXPelsPerMeter = 0;
  3484 	bitmap.bmiHeader.biXPelsPerMeter = 0;
  3466         bitmap.bmiHeader.biYPelsPerMeter = 0;
  3485 	bitmap.bmiHeader.biYPelsPerMeter = 0;
  3467         bitmap.bmiHeader.biClrUsed = 0;
  3486 	bitmap.bmiHeader.biClrUsed = 0;
  3468         bitmap.bmiHeader.biClrImportant = 0;
  3487 	bitmap.bmiHeader.biClrImportant = 0;
  3469         bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  3488 	bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  3470         bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  3489 	bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  3471         bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  3490 	bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  3472         /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  3491 	/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  3473 
  3492 
  3474         SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  3493 	SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  3475                               __intVal(w), __intVal(h),
  3494 			      __intVal(w), __intVal(h),
  3476                               __intVal(srcx), __intVal(srcy),
  3495 			      __intVal(srcx), __intVal(srcy),
  3477                               0,__intVal(h),
  3496 			      0,__intVal(h),
  3478                               (void *)b_bits,
  3497 			      (void *)b_bits,
  3479                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3498 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3480 
  3499 
  3481 /*
  3500 /*
  3482         SetDIBits(hDC,hBitmap,
  3501 	SetDIBits(hDC,hBitmap,
  3483                               0,__intVal(h),
  3502 			      0,__intVal(h),
  3484                               (void *)b_bits,
  3503 			      (void *)b_bits,
  3485                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3504 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3486 */
  3505 */
  3487 /*
  3506 /*
  3488         StretchDIBits(hDC,
  3507 	StretchDIBits(hDC,
  3489                       __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  3508 		      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  3490                       __intVal(w), __intVal(h),                 // width & height of destination rectangle
  3509 		      __intVal(w), __intVal(h),                 // width & height of destination rectangle
  3491                       __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  3510 		      __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  3492                       __intVal(w), __intVal(h),                 // width & height of source rectangle
  3511 		      __intVal(w), __intVal(h),                 // width & height of source rectangle
  3493                       (void *)b_bits,                           // bitmap bits
  3512 		      (void *)b_bits,                           // bitmap bits
  3494                       (BITMAPINFO*)&bitmap,                     // bitmap data
  3513 		      (BITMAPINFO*)&bitmap,                     // bitmap data
  3495                       DIB_RGB_COLORS,                           // usage options
  3514 		      DIB_RGB_COLORS,                           // usage options
  3496                       SRCCOPY                                   // raster operation code
  3515 		      SRCCOPY                                   // raster operation code
  3497         );
  3516 	);
  3498 */
  3517 */
  3499         if (allocatedBits) {
  3518 	if (allocatedBits) {
  3500             free(allocatedBits);
  3519 	    free(allocatedBits);
  3501         }
  3520 	}
  3502 /*
  3521 /*
  3503 #ifndef CACHE_LAST_DC
  3522 #ifndef CACHE_LAST_DC
  3504         _releaseDC(gcData);
  3523 	_releaseDC(gcData);
  3505 #endif
  3524 #endif
  3506 */
  3525 */
  3507         RETURN ( true );
  3526 	RETURN ( true );
  3508     }
  3527     }
  3509 
  3528 
  3510 fail: ;
  3529 fail: ;
  3511 /*
  3530 /*
  3512     PRINTF(("create temp bitmap FAILED!!!\n"));
  3531     PRINTF(("create temp bitmap FAILED!!!\n"));
  3513 */
  3532 */
  3514     if (allocatedBits) {
  3533     if (allocatedBits) {
  3515 /*
  3534 /*
  3516         PRINTF(("freeing up temp bitmap bits ...\n"));
  3535 	PRINTF(("freeing up temp bitmap bits ...\n"));
  3517 */
  3536 */
  3518         free(allocatedBits);
  3537 	free(allocatedBits);
  3519     }
  3538     }
  3520 /*
  3539 /*
  3521 #ifndef CACHE_LAST_DC
  3540 #ifndef CACHE_LAST_DC
  3522     if (hDC) {
  3541     if (hDC) {
  3523         _releaseDC(gcData);
  3542 	_releaseDC(gcData);
  3524     }
  3543     }
  3525 #endif
  3544 #endif
  3526 */
  3545 */
  3527 %}
  3546 %}
  3528 .
  3547 .
  3529     ^ false
  3548     ^ false
  3530 !
  3549 !
  3531 
  3550 
  3532 primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth 
  3551 primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth
  3533                               width:imageWidth height:imageHeight
  3552 			      width:imageWidth height:imageHeight
  3534                                into:ignoredDrawableId
  3553 			       into:ignoredDrawableId
  3535                                   x:dstx y:dsty
  3554 				  x:dstx y:dsty
  3536                               width:w height:h
  3555 			      width:w height:h
  3537                                with:aGCId
  3556 			       with:aGCId
  3538 
  3557 
  3539     "since XPutImage may allocate huge amount of stack space
  3558     "since XPutImage may allocate huge amount of stack space
  3540      (some implementations use alloca), this must run with unlimited stack."
  3559      (some implementations use alloca), this must run with unlimited stack."
  3541 
  3560 
  3542 %{
  3561 %{
  3548     unsigned char *__greenVector = 0;
  3567     unsigned char *__greenVector = 0;
  3549     unsigned char *__blueVector = 0;
  3568     unsigned char *__blueVector = 0;
  3550     int padd = 8;
  3569     int padd = 8;
  3551 
  3570 
  3552     if (__isByteArray(imageBits)) {
  3571     if (__isByteArray(imageBits)) {
  3553         __imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3572 	__imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3554     } else if (__isExternalBytesLike(imageBits)) {
  3573     } else if (__isExternalBytesLike(imageBits)) {
  3555         __imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3574 	__imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3556     }
  3575     }
  3557 
  3576 
  3558     if (__isByteArray(redVector)) {
  3577     if (__isByteArray(redVector)) {
  3559         __redVector = __ByteArrayInstPtr(redVector)->ba_element;
  3578 	__redVector = __ByteArrayInstPtr(redVector)->ba_element;
  3560     } else if (__isExternalBytesLike(redVector)) {
  3579     } else if (__isExternalBytesLike(redVector)) {
  3561         __redVector = (unsigned char *)(__externalBytesAddress(redVector));
  3580 	__redVector = (unsigned char *)(__externalBytesAddress(redVector));
  3562     }
  3581     }
  3563 
  3582 
  3564     if (__isByteArray(greenVector)) {
  3583     if (__isByteArray(greenVector)) {
  3565         __greenVector = __ByteArrayInstPtr(greenVector)->ba_element;
  3584 	__greenVector = __ByteArrayInstPtr(greenVector)->ba_element;
  3566     } else if (__isExternalBytesLike(greenVector)) {
  3585     } else if (__isExternalBytesLike(greenVector)) {
  3567         __greenVector = (unsigned char *)(__externalBytesAddress(greenVector));
  3586 	__greenVector = (unsigned char *)(__externalBytesAddress(greenVector));
  3568     }
  3587     }
  3569 
  3588 
  3570     if (__isByteArray(blueVector)) {
  3589     if (__isByteArray(blueVector)) {
  3571         __blueVector = __ByteArrayInstPtr(blueVector)->ba_element;
  3590 	__blueVector = __ByteArrayInstPtr(blueVector)->ba_element;
  3572     } else if (__isExternalBytesLike(blueVector)) {
  3591     } else if (__isExternalBytesLike(blueVector)) {
  3573         __blueVector = (unsigned char *)(__externalBytesAddress(blueVector));
  3592 	__blueVector = (unsigned char *)(__externalBytesAddress(blueVector));
  3574     }
  3593     }
  3575 
  3594 
  3576     if (/* ISCONNECTED
  3595     if (/* ISCONNECTED
  3577      && */ __isExternalAddressLike(aGCId)
  3596      && */ __isExternalAddressLike(aGCId)
  3578 //     && __bothSmallInteger(srcx, srcy)
  3597 //     && __bothSmallInteger(srcx, srcy)
  3580      && __bothSmallInteger(w, h)
  3599      && __bothSmallInteger(w, h)
  3581      && __bothSmallInteger(imageWidth, imageHeight)
  3600      && __bothSmallInteger(imageWidth, imageHeight)
  3582      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3601      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3583      && __imageBits)
  3602      && __imageBits)
  3584      {
  3603      {
  3585         struct
  3604 	struct
  3586         {
  3605 	{
  3587           BITMAPINFOHEADER bmiHeader;
  3606 	  BITMAPINFOHEADER bmiHeader;
  3588           RGBQUAD bmiColors[256];
  3607 	  RGBQUAD bmiColors[256];
  3589         } bitmap;
  3608 	} bitmap;
  3590 
  3609 
  3591         HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3610 	HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3592         HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3611 	HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3593         int col;
  3612 	int col;
  3594 /*
  3613 /*
  3595         DDPRINTF(("hDC = %x\n", hDC));
  3614 	DDPRINTF(("hDC = %x\n", hDC));
  3596 */
  3615 */
  3597 
  3616 
  3598         if (padd != WIN32PADDING) {
  3617 	if (padd != WIN32PADDING) {
  3599 
  3618 
  3600             int row, col;
  3619 	    int row, col;
  3601             unsigned char *cp;
  3620 	    unsigned char *cp;
  3602             unsigned char *pBits;
  3621 	    unsigned char *pBits;
  3603             int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3622 	    int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3604             int bi = __intVal(bitsPerPixel);
  3623 	    int bi = __intVal(bitsPerPixel);
  3605 
  3624 
  3606 //            console_fprintf(stderr, "Non WIN32PADDING");
  3625 //            console_fprintf(stderr, "Non WIN32PADDING");
  3607 
  3626 
  3608             b_width = __intVal(w);
  3627 	    b_width = __intVal(w);
  3609             b_height = __intVal(h);
  3628 	    b_height = __intVal(h);
  3610             bytesPerRowST = (b_width * bi + (padd - 1 )) / padd;
  3629 	    bytesPerRowST = (b_width * bi + (padd - 1 )) / padd;
  3611             bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3630 	    bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3612             padding = bytesPerRowWN - bytesPerRowST;
  3631 	    padding = bytesPerRowWN - bytesPerRowST;
  3613             nBytes = b_height * bytesPerRowWN;
  3632 	    nBytes = b_height * bytesPerRowWN;
  3614             /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3633 	    /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3615             if (padding) {
  3634 	    if (padding) {
  3616                 if (nBytes < sizeof(fastBits)) {
  3635 		if (nBytes < sizeof(fastBits)) {
  3617                     cp = b_bits = fastBits;
  3636 		    cp = b_bits = fastBits;
  3618                 } else {
  3637 		} else {
  3619                     cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3638 		    cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3620                 }
  3639 		}
  3621                 if (cp) {
  3640 		if (cp) {
  3622                     pBits = __imageBits;
  3641 		    pBits = __imageBits;
  3623                     for (row = b_height; row; row--) {
  3642 		    for (row = b_height; row; row--) {
  3624                         for (col = bytesPerRowST; col; col--) {
  3643 			for (col = bytesPerRowST; col; col--) {
  3625                             *cp++ = *pBits++;
  3644 			    *cp++ = *pBits++;
  3626                         }
  3645 			}
  3627                         cp += padding;
  3646 			cp += padding;
  3628                     }
  3647 		    }
  3629                 } else
  3648 		} else
  3630                     goto fail;
  3649 		    goto fail;
  3631             }
  3650 	    }
  3632         }
  3651 	}
  3633 
  3652 
  3634         if (b_bits == 0) {
  3653 	if (b_bits == 0) {
  3635             b_bits = __imageBits;
  3654 	    b_bits = __imageBits;
  3636         }
  3655 	}
  3637 
  3656 
  3638         bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  3657 	bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  3639         bitmap.bmiHeader.biPlanes = 1;
  3658 	bitmap.bmiHeader.biPlanes = 1;
  3640         bitmap.bmiHeader.biCompression = BI_RGB;
  3659 	bitmap.bmiHeader.biCompression = BI_RGB;
  3641         bitmap.bmiHeader.biSizeImage = 0;
  3660 	bitmap.bmiHeader.biSizeImage = 0;
  3642         bitmap.bmiHeader.biXPelsPerMeter = 0;
  3661 	bitmap.bmiHeader.biXPelsPerMeter = 0;
  3643         bitmap.bmiHeader.biYPelsPerMeter = 0;
  3662 	bitmap.bmiHeader.biYPelsPerMeter = 0;
  3644         bitmap.bmiHeader.biClrUsed = 0;
  3663 	bitmap.bmiHeader.biClrUsed = 0;
  3645         bitmap.bmiHeader.biClrImportant = 0;
  3664 	bitmap.bmiHeader.biClrImportant = 0;
  3646         bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  3665 	bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  3647         bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  3666 	bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  3648         bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  3667 	bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  3649         /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  3668 	/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  3650 
  3669 
  3651         if (__intVal(imageDepth) <= 8) {
  3670 	if (__intVal(imageDepth) <= 8) {
  3652             for(col=0;col<256;col++)
  3671 	    for(col=0;col<256;col++)
  3653              {
  3672 	     {
  3654               bitmap.bmiColors[col].rgbBlue = __blueVector[col];    // Microsoft idea: change rgbBlue to rgbRed
  3673 	      bitmap.bmiColors[col].rgbBlue = __blueVector[col];    // Microsoft idea: change rgbBlue to rgbRed
  3655               bitmap.bmiColors[col].rgbGreen = __greenVector[col];
  3674 	      bitmap.bmiColors[col].rgbGreen = __greenVector[col];
  3656               bitmap.bmiColors[col].rgbRed = __redVector[col];         // Microsoft idea: change rgbRed to rgbBlue
  3675 	      bitmap.bmiColors[col].rgbRed = __redVector[col];         // Microsoft idea: change rgbRed to rgbBlue
  3657               bitmap.bmiColors[col].rgbReserved = 0;
  3676 	      bitmap.bmiColors[col].rgbReserved = 0;
  3658 
  3677 
  3659             }
  3678 	    }
  3660         }
  3679 	}
  3661 
  3680 
  3662         bitmap.bmiColors[255].rgbBlue=255;
  3681 	bitmap.bmiColors[255].rgbBlue=255;
  3663         bitmap.bmiColors[255].rgbGreen=255;
  3682 	bitmap.bmiColors[255].rgbGreen=255;
  3664         bitmap.bmiColors[255].rgbRed =255;
  3683 	bitmap.bmiColors[255].rgbRed =255;
  3665 
  3684 
  3666         SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  3685 	SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  3667                               __intVal(w), __intVal(h),
  3686 			      __intVal(w), __intVal(h),
  3668                               0, 0, /* __intVal(srcx), __intVal(srcy),    */
  3687 			      0, 0, /* __intVal(srcx), __intVal(srcy),    */
  3669                               0,__intVal(h),
  3688 			      0,__intVal(h),
  3670                               (void *)b_bits,
  3689 			      (void *)b_bits,
  3671                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3690 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3672 /*
  3691 /*
  3673         SetDIBits(hDC,hBitmap,
  3692 	SetDIBits(hDC,hBitmap,
  3674                               0,__intVal(h),
  3693 			      0,__intVal(h),
  3675                               (void *)b_bits,
  3694 			      (void *)b_bits,
  3676                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3695 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  3677 */
  3696 */
  3678 /*
  3697 /*
  3679         StretchDIBits(hDC,
  3698 	StretchDIBits(hDC,
  3680                       __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  3699 		      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  3681                       __intVal(w), __intVal(h),                 // width & height of destination rectangle
  3700 		      __intVal(w), __intVal(h),                 // width & height of destination rectangle
  3682                       __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  3701 		      __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  3683                       __intVal(w), __intVal(h),                 // width & height of source rectangle
  3702 		      __intVal(w), __intVal(h),                 // width & height of source rectangle
  3684                       (void *)b_bits,                           // bitmap bits
  3703 		      (void *)b_bits,                           // bitmap bits
  3685                       (BITMAPINFO*)&bitmap,                     // bitmap data
  3704 		      (BITMAPINFO*)&bitmap,                     // bitmap data
  3686                       DIB_RGB_COLORS,                           // usage options
  3705 		      DIB_RGB_COLORS,                           // usage options
  3687                       SRCCOPY                                   // raster operation code
  3706 		      SRCCOPY                                   // raster operation code
  3688         );
  3707 	);
  3689 */
  3708 */
  3690         if (allocatedBits) {
  3709 	if (allocatedBits) {
  3691             free(allocatedBits);
  3710 	    free(allocatedBits);
  3692         }
  3711 	}
  3693 /*
  3712 /*
  3694 #ifndef CACHE_LAST_DC
  3713 #ifndef CACHE_LAST_DC
  3695         _releaseDC(gcData);
  3714 	_releaseDC(gcData);
  3696 #endif
  3715 #endif
  3697 */
  3716 */
  3698         RETURN ( true );
  3717 	RETURN ( true );
  3699     }
  3718     }
  3700 
  3719 
  3701 fail: ;
  3720 fail: ;
  3702 /*
  3721 /*
  3703     PRINTF(("create temp bitmap FAILED!!!\n"));
  3722     PRINTF(("create temp bitmap FAILED!!!\n"));
  3704 */
  3723 */
  3705     if (allocatedBits) {
  3724     if (allocatedBits) {
  3706 /*
  3725 /*
  3707         PRINTF(("freeing up temp bitmap bits ...\n"));
  3726 	PRINTF(("freeing up temp bitmap bits ...\n"));
  3708 */
  3727 */
  3709         free(allocatedBits);
  3728 	free(allocatedBits);
  3710     }
  3729     }
  3711 /*
  3730 /*
  3712 #ifndef CACHE_LAST_DC
  3731 #ifndef CACHE_LAST_DC
  3713     if (hDC) {
  3732     if (hDC) {
  3714         _releaseDC(gcData);
  3733 	_releaseDC(gcData);
  3715     }
  3734     }
  3716 #endif
  3735 #endif
  3717 */
  3736 */
  3718 %}
  3737 %}
  3719 .
  3738 .
  3794 !
  3813 !
  3795 
  3814 
  3796 sortBlockForColors
  3815 sortBlockForColors
  3797 
  3816 
  3798     ^ [:a :b |
  3817     ^ [:a :b |
  3799             a redByte == b redByte ifTrue:[
  3818 	    a redByte == b redByte ifTrue:[
  3800                 a greenByte == b greenByte ifTrue:[
  3819 		a greenByte == b greenByte ifTrue:[
  3801                     a blueByte < b blueByte
  3820 		    a blueByte < b blueByte
  3802                 ] ifFalse:[
  3821 		] ifFalse:[
  3803                     a greenByte < b greenByte 
  3822 		    a greenByte < b greenByte
  3804                 ]
  3823 		]
  3805             ] ifFalse:[
  3824 	    ] ifFalse:[
  3806                 a redByte < b redByte 
  3825 		a redByte < b redByte
  3807             ]
  3826 	    ]
  3808       ].
  3827       ].
  3809 !
  3828 !
  3810 
  3829 
  3811 sortColorMapImage: image
  3830 sortColorMapImage: image
  3812     "calculates a new color map for the image, sorting colors"
  3831     "calculates a new color map for the image, sorting colors"
  3813 
  3832 
  3814     |sortBlock depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| 
  3833     |sortBlock depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits|
  3815 
  3834 
  3816     sortBlock := self sortBlockForColors.
  3835     sortBlock := self sortBlockForColors.
  3817     oldImage := image.
  3836     oldImage := image.
  3818     depth := oldImage depth.
  3837     depth := oldImage depth.
  3819 
  3838 
  3820     oldImage photometric ~~ #palette ifTrue:[
  3839     oldImage photometric ~~ #palette ifTrue:[
  3821         Transcript showCR:'Compress colorMap: Only palette images have colormaps.'.
  3840 	Transcript showCR:'Compress colorMap: Only palette images have colormaps.'.
  3822         ^ image
  3841 	^ image
  3823     ].
  3842     ].
  3824 
  3843 
  3825     usedColors := oldImage realColorMap.
  3844     usedColors := oldImage realColorMap.
  3826 
  3845 
  3827 
  3846 
  3828         "/ translation table
  3847 	"/ translation table
  3829         oldToNew := ByteArray new:(1 bitShift:depth).
  3848 	oldToNew := ByteArray new:(1 bitShift:depth).
  3830         newColorMap := usedColors asArray.
  3849 	newColorMap := usedColors asArray.
  3831         newColorMap sort:sortBlock.
  3850 	newColorMap sort:sortBlock.
  3832 
  3851 
  3833         oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
  3852 	oldImage colorMap asArray keysAndValuesDo:[:oldIdx :clr |
  3834             |newPixel|
  3853 	    |newPixel|
  3835 
  3854 
  3836             (usedColors includes:clr) ifTrue:[
  3855 	    (usedColors includes:clr) ifTrue:[
  3837                 newPixel := newColorMap indexOf:clr.
  3856 		newPixel := newColorMap indexOf:clr.
  3838                 oldToNew at:oldIdx put:newPixel-1.
  3857 		oldToNew at:oldIdx put:newPixel-1.
  3839             ]
  3858 	    ]
  3840         ].
  3859 	].
  3841 
  3860 
  3842         oldBits := oldImage bits.
  3861 	oldBits := oldImage bits.
  3843         newBits := ByteArray new:(oldBits size).
  3862 	newBits := ByteArray new:(oldBits size).
  3844         depth ~~ 8 ifTrue:[
  3863 	depth ~~ 8 ifTrue:[
  3845             "/ expand/compress can only handle 8bits
  3864 	    "/ expand/compress can only handle 8bits
  3846             tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
  3865 	    tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height).
  3847             oldBits
  3866 	    oldBits
  3848                 expandPixels:depth
  3867 		expandPixels:depth
  3849                 width:oldImage width
  3868 		width:oldImage width
  3850                 height:oldImage height 
  3869 		height:oldImage height
  3851                 into:tmpBits
  3870 		into:tmpBits
  3852                 mapping:oldToNew.
  3871 		mapping:oldToNew.
  3853             tmpBits
  3872 	    tmpBits
  3854                 compressPixels:depth 
  3873 		compressPixels:depth
  3855                 width:oldImage width 
  3874 		width:oldImage width
  3856                 height:oldImage height 
  3875 		height:oldImage height
  3857                 into:newBits 
  3876 		into:newBits
  3858                 mapping:nil
  3877 		mapping:nil
  3859         ] ifFalse:[
  3878 	] ifFalse:[
  3860             oldBits
  3879 	    oldBits
  3861                 expandPixels:depth
  3880 		expandPixels:depth
  3862                 width:oldImage width
  3881 		width:oldImage width
  3863                 height:oldImage height 
  3882 		height:oldImage height
  3864                 into:newBits
  3883 		into:newBits
  3865                 mapping:oldToNew.
  3884 		mapping:oldToNew.
  3866         ].
  3885 	].
  3867 
  3886 
  3868         newImage := oldImage species new
  3887 	newImage := oldImage species new
  3869                         width:oldImage width
  3888 			width:oldImage width
  3870                         height:oldImage height
  3889 			height:oldImage height
  3871                         depth:depth
  3890 			depth:depth
  3872                         fromArray:newBits.
  3891 			fromArray:newBits.
  3873 
  3892 
  3874         newImage colorMap:newColorMap.  
  3893 	newImage colorMap:newColorMap.
  3875         newImage fileName:oldImage fileName.
  3894 	newImage fileName:oldImage fileName.
  3876         newImage mask:(oldImage mask copy).
  3895 	newImage mask:(oldImage mask copy).
  3877 
  3896 
  3878         ^newImage
  3897 	^newImage
  3879 !
  3898 !
  3880 
  3899 
  3881 transparencyTest_primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth 
  3900 transparencyTest_primDrawBits:imageBits redVector:redVector greenVector:greenVector blueVector:blueVector bitsPerPixel:bitsPerPixel depth:imageDepth
  3882                               width:imageWidth height:imageHeight
  3901 			      width:imageWidth height:imageHeight
  3883                                into:ignoredDrawableId
  3902 			       into:ignoredDrawableId
  3884                                   x:dstx y:dsty
  3903 				  x:dstx y:dsty
  3885                               width:w height:h
  3904 			      width:w height:h
  3886                                with:aGCId
  3905 			       with:aGCId
  3887 
  3906 
  3888     "since XPutImage may allocate huge amount of stack space
  3907     "since XPutImage may allocate huge amount of stack space
  3889      (some implementations use alloca), this must run with unlimited stack."
  3908      (some implementations use alloca), this must run with unlimited stack."
  3890 
  3909 
  3891 %{
  3910 %{
  3897     unsigned char *__greenVector = 0;
  3916     unsigned char *__greenVector = 0;
  3898     unsigned char *__blueVector = 0;
  3917     unsigned char *__blueVector = 0;
  3899     int padd = 8;
  3918     int padd = 8;
  3900 
  3919 
  3901     if (__isByteArray(imageBits)) {
  3920     if (__isByteArray(imageBits)) {
  3902         __imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3921 	__imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
  3903     } else if (__isExternalBytesLike(imageBits)) {
  3922     } else if (__isExternalBytesLike(imageBits)) {
  3904         __imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3923 	__imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
  3905     }
  3924     }
  3906 
  3925 
  3907     if (__isByteArray(redVector)) {
  3926     if (__isByteArray(redVector)) {
  3908         __redVector = __ByteArrayInstPtr(redVector)->ba_element;
  3927 	__redVector = __ByteArrayInstPtr(redVector)->ba_element;
  3909     } else if (__isExternalBytesLike(redVector)) {
  3928     } else if (__isExternalBytesLike(redVector)) {
  3910         __redVector = (unsigned char *)(__externalBytesAddress(redVector));
  3929 	__redVector = (unsigned char *)(__externalBytesAddress(redVector));
  3911     }
  3930     }
  3912 
  3931 
  3913     if (__isByteArray(greenVector)) {
  3932     if (__isByteArray(greenVector)) {
  3914         __greenVector = __ByteArrayInstPtr(greenVector)->ba_element;
  3933 	__greenVector = __ByteArrayInstPtr(greenVector)->ba_element;
  3915     } else if (__isExternalBytesLike(greenVector)) {
  3934     } else if (__isExternalBytesLike(greenVector)) {
  3916         __greenVector = (unsigned char *)(__externalBytesAddress(greenVector));
  3935 	__greenVector = (unsigned char *)(__externalBytesAddress(greenVector));
  3917     }
  3936     }
  3918 
  3937 
  3919     if (__isByteArray(blueVector)) {
  3938     if (__isByteArray(blueVector)) {
  3920         __blueVector = __ByteArrayInstPtr(blueVector)->ba_element;
  3939 	__blueVector = __ByteArrayInstPtr(blueVector)->ba_element;
  3921     } else if (__isExternalBytesLike(blueVector)) {
  3940     } else if (__isExternalBytesLike(blueVector)) {
  3922         __blueVector = (unsigned char *)(__externalBytesAddress(blueVector));
  3941 	__blueVector = (unsigned char *)(__externalBytesAddress(blueVector));
  3923     }
  3942     }
  3924 
  3943 
  3925     if (/* ISCONNECTED
  3944     if (/* ISCONNECTED
  3926      && */ __isExternalAddressLike(aGCId)
  3945      && */ __isExternalAddressLike(aGCId)
  3927 //     && __bothSmallInteger(srcx, srcy)
  3946 //     && __bothSmallInteger(srcx, srcy)
  3929      && __bothSmallInteger(w, h)
  3948      && __bothSmallInteger(w, h)
  3930      && __bothSmallInteger(imageWidth, imageHeight)
  3949      && __bothSmallInteger(imageWidth, imageHeight)
  3931      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3950      && __bothSmallInteger(imageDepth, bitsPerPixel)
  3932      && __imageBits)
  3951      && __imageBits)
  3933      {
  3952      {
  3934         struct
  3953 	struct
  3935         {
  3954 	{
  3936           BITMAPINFOHEADER bmiHeader;
  3955 	  BITMAPINFOHEADER bmiHeader;
  3937           RGBQUAD bmiColors[256];
  3956 	  RGBQUAD bmiColors[256];
  3938         } bitmap;
  3957 	} bitmap;
  3939 
  3958 
  3940         HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3959 	HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));
  3941         HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3960 	HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));
  3942         int col;
  3961 	int col;
  3943 /*
  3962 /*
  3944         DDPRINTF(("hDC = %x\n", hDC));
  3963 	DDPRINTF(("hDC = %x\n", hDC));
  3945 */
  3964 */
  3946 
  3965 
  3947         if (padd != WIN32PADDING) {
  3966 	if (padd != WIN32PADDING) {
  3948 
  3967 
  3949             int row, col;
  3968 	    int row, col;
  3950             unsigned char *cp;
  3969 	    unsigned char *cp;
  3951             unsigned char *pBits;
  3970 	    unsigned char *pBits;
  3952             int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3971 	    int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding, nBytes;
  3953             int bi = __intVal(bitsPerPixel);
  3972 	    int bi = __intVal(bitsPerPixel);
  3954 
  3973 
  3955 //            console_fprintf(stderr, "Non WIN32PADDING");
  3974 //            console_fprintf(stderr, "Non WIN32PADDING");
  3956 
  3975 
  3957             b_width = __intVal(w);
  3976 	    b_width = __intVal(w);
  3958             b_height = __intVal(h);
  3977 	    b_height = __intVal(h);
  3959             bytesPerRowST = (b_width * bi + (padd - 1 )) / padd;
  3978 	    bytesPerRowST = (b_width * bi + (padd - 1 )) / padd;
  3960             bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3979 	    bytesPerRowWN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
  3961             padding = bytesPerRowWN - bytesPerRowST;
  3980 	    padding = bytesPerRowWN - bytesPerRowST;
  3962             nBytes = b_height * bytesPerRowWN;
  3981 	    nBytes = b_height * bytesPerRowWN;
  3963             /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3982 	    /*console_printf("padd %d bs %d bw %d p %d\n",__intVal(padd),bytesPerRowST,bytesPerRowWN,padding);*/
  3964             if (padding) {
  3983 	    if (padding) {
  3965                 if (nBytes < sizeof(fastBits)) {
  3984 		if (nBytes < sizeof(fastBits)) {
  3966                     cp = b_bits = fastBits;
  3985 		    cp = b_bits = fastBits;
  3967                 } else {
  3986 		} else {
  3968                     cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3987 		    cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
  3969                 }
  3988 		}
  3970                 if (cp) {
  3989 		if (cp) {
  3971                     pBits = __imageBits;
  3990 		    pBits = __imageBits;
  3972                     for (row = b_height; row; row--) {
  3991 		    for (row = b_height; row; row--) {
  3973                         for (col = bytesPerRowST; col; col--) {
  3992 			for (col = bytesPerRowST; col; col--) {
  3974                             *cp++ = *pBits++;
  3993 			    *cp++ = *pBits++;
  3975                         }
  3994 			}
  3976                         cp += padding;
  3995 			cp += padding;
  3977                     }
  3996 		    }
  3978                 } else
  3997 		} else
  3979                     goto fail;
  3998 		    goto fail;
  3980             }
  3999 	    }
  3981         }
  4000 	}
  3982 
  4001 
  3983         if (b_bits == 0) {
  4002 	if (b_bits == 0) {
  3984             b_bits = __imageBits;
  4003 	    b_bits = __imageBits;
  3985         }
  4004 	}
  3986 
  4005 
  3987         bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  4006 	bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  3988         bitmap.bmiHeader.biPlanes = 1;
  4007 	bitmap.bmiHeader.biPlanes = 1;
  3989         bitmap.bmiHeader.biCompression = BI_RGB;
  4008 	bitmap.bmiHeader.biCompression = BI_RGB;
  3990         bitmap.bmiHeader.biSizeImage = 0;
  4009 	bitmap.bmiHeader.biSizeImage = 0;
  3991         bitmap.bmiHeader.biXPelsPerMeter = 0;
  4010 	bitmap.bmiHeader.biXPelsPerMeter = 0;
  3992         bitmap.bmiHeader.biYPelsPerMeter = 0;
  4011 	bitmap.bmiHeader.biYPelsPerMeter = 0;
  3993         bitmap.bmiHeader.biClrUsed = 0;
  4012 	bitmap.bmiHeader.biClrUsed = 0;
  3994         bitmap.bmiHeader.biClrImportant = 0;
  4013 	bitmap.bmiHeader.biClrImportant = 0;
  3995         bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  4014 	bitmap.bmiHeader.biWidth = __intVal(imageWidth);
  3996         bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  4015 	bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
  3997         bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  4016 	bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
  3998         /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  4017 	/*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
  3999 
  4018 
  4000         if (__intVal(imageDepth) <= 8) {
  4019 	if (__intVal(imageDepth) <= 8) {
  4001             for(col=0;col<256;col++)
  4020 	    for(col=0;col<256;col++)
  4002              {
  4021 	     {
  4003               bitmap.bmiColors[col].rgbBlue = 0;    
  4022 	      bitmap.bmiColors[col].rgbBlue = 0;
  4004               bitmap.bmiColors[col].rgbGreen = 0;
  4023 	      bitmap.bmiColors[col].rgbGreen = 0;
  4005               bitmap.bmiColors[col].rgbRed = 0;     
  4024 	      bitmap.bmiColors[col].rgbRed = 0;
  4006               bitmap.bmiColors[col].rgbReserved = 0;
  4025 	      bitmap.bmiColors[col].rgbReserved = 0;
  4007 
  4026 
  4008             }
  4027 	    }
  4009         }
  4028 	}
  4010 
  4029 
  4011         bitmap.bmiColors[255].rgbBlue=255;
  4030 	bitmap.bmiColors[255].rgbBlue=255;
  4012         bitmap.bmiColors[255].rgbGreen=255;
  4031 	bitmap.bmiColors[255].rgbGreen=255;
  4013         bitmap.bmiColors[255].rgbRed =255;
  4032 	bitmap.bmiColors[255].rgbRed =255;
  4014         bitmap.bmiColors[255].rgbReserved = 0;
  4033 	bitmap.bmiColors[255].rgbReserved = 0;
  4015         StretchDIBits(hDC,
  4034 	StretchDIBits(hDC,
  4016                       __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4035 		      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4017                       __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4036 		      __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4018                       0, 0,  /* __intVal(srcx), __intVal(srcy),    */   // x & y coord of source upper-left corner
  4037 		      0, 0,  /* __intVal(srcx), __intVal(srcy),    */   // x & y coord of source upper-left corner
  4019                       __intVal(w), __intVal(h),                 // width & height of source rectangle
  4038 		      __intVal(w), __intVal(h),                 // width & height of source rectangle
  4020                       (void *)b_bits,                           // bitmap bits
  4039 		      (void *)b_bits,                           // bitmap bits
  4021                       (BITMAPINFO*)&bitmap,                     // bitmap data
  4040 		      (BITMAPINFO*)&bitmap,                     // bitmap data
  4022                       DIB_RGB_COLORS,                           // usage options
  4041 		      DIB_RGB_COLORS,                           // usage options
  4023                       SRCAND                                   // raster operation code
  4042 		      SRCAND                                   // raster operation code
  4024         );
  4043 	);
  4025 /*
  4044 /*
  4026         if (__intVal(imageDepth) <= 8) {
  4045 	if (__intVal(imageDepth) <= 8) {
  4027             for(col=0;col<256;col++)
  4046 	    for(col=0;col<256;col++)
  4028              {
  4047 	     {
  4029               bitmap.bmiColors[col].rgbBlue = __blueVector[col];    // Microsoft idea: change rgbBlue to rgbRed
  4048 	      bitmap.bmiColors[col].rgbBlue = __blueVector[col];    // Microsoft idea: change rgbBlue to rgbRed
  4030               bitmap.bmiColors[col].rgbGreen = __greenVector[col];
  4049 	      bitmap.bmiColors[col].rgbGreen = __greenVector[col];
  4031               bitmap.bmiColors[col].rgbRed = __redVector[col];         // Microsoft idea: change rgbRed to rgbBlue
  4050 	      bitmap.bmiColors[col].rgbRed = __redVector[col];         // Microsoft idea: change rgbRed to rgbBlue
  4032               bitmap.bmiColors[col].rgbReserved = 0;
  4051 	      bitmap.bmiColors[col].rgbReserved = 0;
  4033 
  4052 
  4034             }
  4053 	    }
  4035         }
  4054 	}
  4036 
  4055 
  4037         bitmap.bmiColors[255].rgbBlue=0;
  4056 	bitmap.bmiColors[255].rgbBlue=0;
  4038         bitmap.bmiColors[255].rgbGreen=0;
  4057 	bitmap.bmiColors[255].rgbGreen=0;
  4039         bitmap.bmiColors[255].rgbRed =0;
  4058 	bitmap.bmiColors[255].rgbRed =0;
  4040         bitmap.bmiColors[255].rgbReserved = 0;
  4059 	bitmap.bmiColors[255].rgbReserved = 0;
  4041         StretchDIBits(hDC,
  4060 	StretchDIBits(hDC,
  4042                       __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4061 		      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4043                       __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4062 		      __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4044                       0, 0,                                     // x & y coord of source upper-left corner
  4063 		      0, 0,                                     // x & y coord of source upper-left corner
  4045                       __intVal(w), __intVal(h),                 // width & height of source rectangle
  4064 		      __intVal(w), __intVal(h),                 // width & height of source rectangle
  4046                       (void *)b_bits,                           // bitmap bits
  4065 		      (void *)b_bits,                           // bitmap bits
  4047                       (BITMAPINFO*)&bitmap,                     // bitmap data
  4066 		      (BITMAPINFO*)&bitmap,                     // bitmap data
  4048                       DIB_RGB_COLORS,                           // usage options
  4067 		      DIB_RGB_COLORS,                           // usage options
  4049                       SRCPAINT                                  // raster operation code
  4068 		      SRCPAINT                                  // raster operation code
  4050         );
  4069 	);
  4051  */
  4070  */
  4052 /*
  4071 /*
  4053         SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  4072 	SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
  4054                               __intVal(w), __intVal(h),
  4073 			      __intVal(w), __intVal(h),
  4055                               0, 0,
  4074 			      0, 0,
  4056                               0,__intVal(h),
  4075 			      0,__intVal(h),
  4057                               (void *)b_bits,
  4076 			      (void *)b_bits,
  4058                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  4077 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  4059 */
  4078 */
  4060 /*
  4079 /*
  4061         SetDIBits(hDC,hBitmap,
  4080 	SetDIBits(hDC,hBitmap,
  4062                               0,__intVal(h),
  4081 			      0,__intVal(h),
  4063                               (void *)b_bits,
  4082 			      (void *)b_bits,
  4064                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  4083 			      (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
  4065 */
  4084 */
  4066 /*
  4085 /*
  4067         StretchDIBits(hDC,
  4086 	StretchDIBits(hDC,
  4068                       __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4087 		      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
  4069                       __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4088 		      __intVal(w), __intVal(h),                 // width & height of destination rectangle
  4070                       __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  4089 		      __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
  4071                       __intVal(w), __intVal(h),                 // width & height of source rectangle
  4090 		      __intVal(w), __intVal(h),                 // width & height of source rectangle
  4072                       (void *)b_bits,                           // bitmap bits
  4091 		      (void *)b_bits,                           // bitmap bits
  4073                       (BITMAPINFO*)&bitmap,                     // bitmap data
  4092 		      (BITMAPINFO*)&bitmap,                     // bitmap data
  4074                       DIB_RGB_COLORS,                           // usage options
  4093 		      DIB_RGB_COLORS,                           // usage options
  4075                       SRCCOPY                                   // raster operation code
  4094 		      SRCCOPY                                   // raster operation code
  4076         );
  4095 	);
  4077 */
  4096 */
  4078         if (allocatedBits) {
  4097 	if (allocatedBits) {
  4079             free(allocatedBits);
  4098 	    free(allocatedBits);
  4080         }
  4099 	}
  4081 /*
  4100 /*
  4082 #ifndef CACHE_LAST_DC
  4101 #ifndef CACHE_LAST_DC
  4083         _releaseDC(gcData);
  4102 	_releaseDC(gcData);
  4084 #endif
  4103 #endif
  4085 */
  4104 */
  4086         RETURN ( true );
  4105 	RETURN ( true );
  4087     }
  4106     }
  4088 
  4107 
  4089 fail: ;
  4108 fail: ;
  4090 /*
  4109 /*
  4091     PRINTF(("create temp bitmap FAILED!!!\n"));
  4110     PRINTF(("create temp bitmap FAILED!!!\n"));
  4092 */
  4111 */
  4093     if (allocatedBits) {
  4112     if (allocatedBits) {
  4094 /*
  4113 /*
  4095         PRINTF(("freeing up temp bitmap bits ...\n"));
  4114 	PRINTF(("freeing up temp bitmap bits ...\n"));
  4096 */
  4115 */
  4097         free(allocatedBits);
  4116 	free(allocatedBits);
  4098     }
  4117     }
  4099 /*
  4118 /*
  4100 #ifndef CACHE_LAST_DC
  4119 #ifndef CACHE_LAST_DC
  4101     if (hDC) {
  4120     if (hDC) {
  4102         _releaseDC(gcData);
  4121 	_releaseDC(gcData);
  4103     }
  4122     }
  4104 #endif
  4123 #endif
  4105 */
  4124 */
  4106 %}
  4125 %}
  4107 .
  4126 .
  4118 %{
  4137 %{
  4119     HGDIOBJ hFont;
  4138     HGDIOBJ hFont;
  4120     char *fn;
  4139     char *fn;
  4121 
  4140 
  4122     if (__isStringLike(aFontName)) {
  4141     if (__isStringLike(aFontName)) {
  4123         fn = __stringVal(aFontName);
  4142 	fn = __stringVal(aFontName);
  4124         if ((strcmp(fn, "fixed") == 0) || (strcmp(fn, "ANSI_FIXED_FONT") == 0)) {
  4143 	if ((strcmp(fn, "fixed") == 0) || (strcmp(fn, "ANSI_FIXED_FONT") == 0)) {
  4125             hFont = GetStockObject(ANSI_FIXED_FONT);
  4144 	    hFont = GetStockObject(ANSI_FIXED_FONT);
  4126         } else if ((strcmp(fn, "variable") == 0) || (strcmp(fn, "ANSI_VAR_FONT") == 0)) {
  4145 	} else if ((strcmp(fn, "variable") == 0) || (strcmp(fn, "ANSI_VAR_FONT") == 0)) {
  4127             hFont = GetStockObject(ANSI_VAR_FONT);
  4146 	    hFont = GetStockObject(ANSI_VAR_FONT);
  4128         } else if ((strcmp(fn, "system") == 0) || (strcmp(fn, "SYSTEM_FONT") == 0)) {
  4147 	} else if ((strcmp(fn, "system") == 0) || (strcmp(fn, "SYSTEM_FONT") == 0)) {
  4129             hFont = GetStockObject(SYSTEM_FONT);
  4148 	    hFont = GetStockObject(SYSTEM_FONT);
  4130         } else if ((strcmp(fn, "systemFixed") == 0) || (strcmp(fn, "SYSTEM_FIXED_FONT") == 0)) {
  4149 	} else if ((strcmp(fn, "systemFixed") == 0) || (strcmp(fn, "SYSTEM_FIXED_FONT") == 0)) {
  4131             hFont = GetStockObject(SYSTEM_FIXED_FONT);
  4150 	    hFont = GetStockObject(SYSTEM_FIXED_FONT);
  4132         } else if ((strcmp(fn, "deviceDefault") == 0) || (strcmp(fn, "DEVICE_DEFAULT_FONT") == 0)) {
  4151 	} else if ((strcmp(fn, "deviceDefault") == 0) || (strcmp(fn, "DEVICE_DEFAULT_FONT") == 0)) {
  4133             hFont = GetStockObject(DEVICE_DEFAULT_FONT);
  4152 	    hFont = GetStockObject(DEVICE_DEFAULT_FONT);
  4134         } else {
  4153 	} else {
  4135             hFont = GetStockObject(ANSI_FIXED_FONT);
  4154 	    hFont = GetStockObject(ANSI_FIXED_FONT);
  4136         }
  4155 	}
  4137         if (hFont) {
  4156 	if (hFont) {
  4138             DPRINTF(("createFontFor:%s -> %x\n", fn, hFont));
  4157 	    DPRINTF(("createFontFor:%s -> %x\n", fn, hFont));
  4139             RETURN ( __MKEXTERNALADDRESS(hFont) );
  4158 	    RETURN ( __MKEXTERNALADDRESS(hFont) );
  4140         }
  4159 	}
  4141     }
  4160     }
  4142 %}.
  4161 %}.
  4143     ^ nil
  4162     ^ nil
  4144 !
  4163 !
  4145 
  4164 
  4184 getFontWithFamily:familyString face:faceString style:styleString size:sizeArg encoding:encodingSym
  4203 getFontWithFamily:familyString face:faceString style:styleString size:sizeArg encoding:encodingSym
  4185     "try to get the specified font, return id.
  4204     "try to get the specified font, return id.
  4186      If not available, try next smaller font.
  4205      If not available, try next smaller font.
  4187      If no font fits, return nil"
  4206      If no font fits, return nil"
  4188 
  4207 
  4189     ^ self 
  4208     ^ self
  4190         getFontWithFamily:familyString 
  4209 	getFontWithFamily:familyString
  4191         face:faceString 
  4210 	face:faceString
  4192         style:styleString 
  4211 	style:styleString
  4193         size:sizeArg  
  4212 	size:sizeArg
  4194         sizeUnit:#pt  
  4213 	sizeUnit:#pt
  4195         encoding:encodingSym
  4214 	encoding:encodingSym
  4196 !
  4215 !
  4197 
  4216 
  4198 getFontWithFamily:familyString face:faceString
  4217 getFontWithFamily:familyString face:faceString
  4199             style:styleArgString size:sizeArgOrNil sizeUnit:sizeUnit encoding:encodingSym
  4218 	    style:styleArgString size:sizeArgOrNil sizeUnit:sizeUnit encoding:encodingSym
  4200 
  4219 
  4201     "try to get the specified font, if not available, try the next smaller
  4220     "try to get the specified font, if not available, try the next smaller
  4202      font."
  4221      font."
  4203 
  4222 
  4204     |styleString theName theId xlatedStyle id spacing|
  4223     |styleString theName theId xlatedStyle id spacing|
  4207 
  4226 
  4208     styleString := styleArgString.
  4227     styleString := styleArgString.
  4209 
  4228 
  4210     "special: if face is nil, allow access to X-fonts"
  4229     "special: if face is nil, allow access to X-fonts"
  4211     faceString isNil ifTrue:[
  4230     faceString isNil ifTrue:[
  4212         sizeArgOrNil notNil ifTrue:[
  4231 	sizeArgOrNil notNil ifTrue:[
  4213             theName := familyString , '-' , sizeArgOrNil printString
  4232 	    theName := familyString , '-' , sizeArgOrNil printString
  4214         ] ifFalse:[
  4233 	] ifFalse:[
  4215             theName := familyString
  4234 	    theName := familyString
  4216         ].
  4235 	].
  4217         theName notNil ifTrue:[
  4236 	theName notNil ifTrue:[
  4218             theId := self createFontFor:theName.
  4237 	    theId := self createFontFor:theName.
  4219         ].
  4238 	].
  4220         theId isNil ifTrue:[
  4239 	theId isNil ifTrue:[
  4221             theId := self getDefaultFontWithEncoding:encodingSym
  4240 	    theId := self getDefaultFontWithEncoding:encodingSym
  4222         ].
  4241 	].
  4223         ^ theId
  4242 	^ theId
  4224     ].
  4243     ].
  4225 
  4244 
  4226     "/ spacing other than 'normal' is contained as last component
  4245     "/ spacing other than 'normal' is contained as last component
  4227     "/ in style
  4246     "/ in style
  4228     styleString notNil ifTrue:[
  4247     styleString notNil ifTrue:[
  4229         ((styleString endsWith:'-narrow')
  4248 	((styleString endsWith:'-narrow')
  4230          or:[styleString endsWith:'-semicondensed']) ifTrue:[
  4249 	 or:[styleString endsWith:'-semicondensed']) ifTrue:[
  4231             |i|
  4250 	    |i|
  4232             i := styleString lastIndexOf:$-.
  4251 	    i := styleString lastIndexOf:$-.
  4233             spacing := styleString copyFrom:(i+1).
  4252 	    spacing := styleString copyFrom:(i+1).
  4234             styleString := styleString copyTo:(i-1).
  4253 	    styleString := styleString copyTo:(i-1).
  4235         ] ifFalse:[
  4254 	] ifFalse:[
  4236             spacing := 'normal'.
  4255 	    spacing := 'normal'.
  4237         ].
  4256 	].
  4238     ].
  4257     ].
  4239 
  4258 
  4240     xlatedStyle := styleString.
  4259     xlatedStyle := styleString.
  4241     xlatedStyle notNil ifTrue:[
  4260     xlatedStyle notNil ifTrue:[
  4242         xlatedStyle := xlatedStyle first asString
  4261 	xlatedStyle := xlatedStyle first asString
  4243     ].
  4262     ].
  4244 
  4263 
  4245     id := self
  4264     id := self
  4246             getFontWithFoundry:'*'
  4265 	    getFontWithFoundry:'*'
  4247             family:familyString asLowercase
  4266 	    family:familyString asLowercase
  4248             weight:faceString
  4267 	    weight:faceString
  4249             slant:styleString "/ xlatedStyle
  4268 	    slant:styleString "/ xlatedStyle
  4250             spacing:spacing
  4269 	    spacing:spacing
  4251             pixelSize:nil
  4270 	    pixelSize:nil
  4252             size:sizeArgOrNil
  4271 	    size:sizeArgOrNil
  4253             registry:'*'
  4272 	    registry:'*'
  4254             encoding:encodingSym.
  4273 	    encoding:encodingSym.
  4255 
  4274 
  4256     id isNil ifTrue:[
  4275     id isNil ifTrue:[
  4257         (encodingSym notNil and:[encodingSym ~= '*']) ifTrue:[
  4276 	(encodingSym notNil and:[encodingSym ~= '*']) ifTrue:[
  4258             "/ too stupid: encodings come in both cases
  4277 	    "/ too stupid: encodings come in both cases
  4259             "/
  4278 	    "/
  4260             id := self
  4279 	    id := self
  4261                     getFontWithFoundry:'*'
  4280 		    getFontWithFoundry:'*'
  4262                     family:familyString asLowercase
  4281 		    family:familyString asLowercase
  4263                     weight:faceString
  4282 		    weight:faceString
  4264                     slant:styleString "/ xlatedStyle
  4283 		    slant:styleString "/ xlatedStyle
  4265                     spacing:spacing
  4284 		    spacing:spacing
  4266                     pixelSize:nil
  4285 		    pixelSize:nil
  4267                     size:sizeArgOrNil
  4286 		    size:sizeArgOrNil
  4268                     registry:'*'
  4287 		    registry:'*'
  4269                     encoding:encodingSym asUppercase.
  4288 		    encoding:encodingSym asUppercase.
  4270             id isNil ifTrue:[
  4289 	    id isNil ifTrue:[
  4271                 id := self
  4290 		id := self
  4272                         getFontWithFoundry:'*'
  4291 			getFontWithFoundry:'*'
  4273                         family:familyString asLowercase
  4292 			family:familyString asLowercase
  4274                         weight:faceString
  4293 			weight:faceString
  4275                         slant:styleString "/ xlatedStyle
  4294 			slant:styleString "/ xlatedStyle
  4276                         spacing:spacing
  4295 			spacing:spacing
  4277                         pixelSize:nil
  4296 			pixelSize:nil
  4278                         size:sizeArgOrNil
  4297 			size:sizeArgOrNil
  4279                         registry:'*'
  4298 			registry:'*'
  4280                         encoding:encodingSym asLowercase.
  4299 			encoding:encodingSym asLowercase.
  4281 
  4300 
  4282                 id isNil ifTrue:[
  4301 		id isNil ifTrue:[
  4283                     id := self
  4302 		    id := self
  4284                             getFontWithFoundry:'*'
  4303 			    getFontWithFoundry:'*'
  4285                             family:familyString asLowercase
  4304 			    family:familyString asLowercase
  4286                             weight:faceString asLowercase
  4305 			    weight:faceString asLowercase
  4287                             slant:styleString asLowercase
  4306 			    slant:styleString asLowercase
  4288                             spacing:spacing
  4307 			    spacing:spacing
  4289                             pixelSize:nil
  4308 			    pixelSize:nil
  4290                             size:sizeArgOrNil
  4309 			    size:sizeArgOrNil
  4291                             registry:'*'
  4310 			    registry:'*'
  4292                             encoding:encodingSym asLowercase.
  4311 			    encoding:encodingSym asLowercase.
  4293                 ]
  4312 		]
  4294             ]
  4313 	    ]
  4295         ]
  4314 	]
  4296     ].
  4315     ].
  4297     ^ id
  4316     ^ id
  4298 
  4317 
  4299     "Modified: 24.2.1996 / 22:37:24 / cg"
  4318     "Modified: 24.2.1996 / 22:37:24 / cg"
  4300     "Modified: 4.7.1996 / 11:38:47 / stefan"
  4319     "Modified: 4.7.1996 / 11:38:47 / stefan"
  4301 !
  4320 !
  4302 
  4321 
  4303 getFontWithFoundry:foundry family:family weight:weight
  4322 getFontWithFoundry:foundry family:family weight:weight
  4304               slant:slant spacing:spc pixelSize:pixelSize size:pointSize
  4323 	      slant:slant spacing:spc pixelSize:pixelSize size:pointSize
  4305               registry:registry encoding:encodingArg
  4324 	      registry:registry encoding:encodingArg
  4306 
  4325 
  4307     "get the specified font, if not available, return nil.
  4326     "get the specified font, if not available, return nil.
  4308      For now, this is a poor (incomplete) emulation of the X code ...
  4327      For now, this is a poor (incomplete) emulation of the X code ...
  4309      Individual attributes can be left empty (i.e. '') or nil to match any.
  4328      Individual attributes can be left empty (i.e. '') or nil to match any.
  4310 
  4329 
  4320     "
  4339     "
  4321 
  4340 
  4322     "
  4341     "
  4323      Windows-NT/95 allows the creation of a font with the following parameters
  4342      Windows-NT/95 allows the creation of a font with the following parameters
  4324 
  4343 
  4325         nHeight
  4344 	nHeight
  4326         nWidth
  4345 	nWidth
  4327         nEscapement
  4346 	nEscapement
  4328         nOrientation
  4347 	nOrientation
  4329         fnWeight        FW_DONTCARE, FW_NORMAL, FW_MEDIUM, FW_BOLD, ...
  4348 	fnWeight        FW_DONTCARE, FW_NORMAL, FW_MEDIUM, FW_BOLD, ...
  4330         fdwItalic       TRUE or FALSE
  4349 	fdwItalic       TRUE or FALSE
  4331         fdwUnderline    TRUE or FALSE
  4350 	fdwUnderline    TRUE or FALSE
  4332         fdwStrikeOut    TRUE or FALSE
  4351 	fdwStrikeOut    TRUE or FALSE
  4333         fdwCharSet      ANSI_CHARSET, UNICODE_, SYMBOL_, SHIFTJIS_,...
  4352 	fdwCharSet      ANSI_CHARSET, UNICODE_, SYMBOL_, SHIFTJIS_,...
  4334         fdwOutputPrecision      DEFAULT, STRING, CHAR, ...
  4353 	fdwOutputPrecision      DEFAULT, STRING, CHAR, ...
  4335         fdwClipPrecision        DEFAULT, CHAR, STROKE, MASK, ...
  4354 	fdwClipPrecision        DEFAULT, CHAR, STROKE, MASK, ...
  4336         fdwQuality      DEFAULT, DRAFT, or PROOF.
  4355 	fdwQuality      DEFAULT, DRAFT, or PROOF.
  4337         fdwPitchAndFamily
  4356 	fdwPitchAndFamily
  4338                 DEFAULT, FIXED or VARIABLE pitch
  4357 		DEFAULT, FIXED or VARIABLE pitch
  4339                 DECORATIVE, DONTCASE, MODERN, ROMAN, SCRIPT, or SWISS.
  4358 		DECORATIVE, DONTCASE, MODERN, ROMAN, SCRIPT, or SWISS.
  4340         lpszFace
  4359 	lpszFace
  4341                 Typeface Name
  4360 		Typeface Name
  4342 
  4361 
  4343       These two above descriptions will be matched as follows:
  4362       These two above descriptions will be matched as follows:
  4344 
  4363 
  4345         foundry   - ignored
  4364 	foundry   - ignored
  4346         family    - mapped to type face name.
  4365 	family    - mapped to type face name.
  4347         weight    - mapped to fnWeight
  4366 	weight    - mapped to fnWeight
  4348         slant     - used for style
  4367 	slant     - used for style
  4349         spacing   - NOT USED INITIALLY
  4368 	spacing   - NOT USED INITIALLY
  4350         pixelSize - NOT USED INITIALLY
  4369 	pixelSize - NOT USED INITIALLY
  4351         size      - mapped to nHeight
  4370 	size      - mapped to nHeight
  4352         registry  - NOT USED INITIALLY
  4371 	registry  - NOT USED INITIALLY
  4353         encoding  - mapped to fdwCharSet
  4372 	encoding  - mapped to fdwCharSet
  4354      "
  4373      "
  4355 
  4374 
  4356     |logSize encoding|
  4375     |logSize encoding|
  4357 
  4376 
  4358     encoding := encodingArg asSymbol.
  4377     encoding := encodingArg asSymbol.
  4359 
  4378 
  4360     pixelSize notNil ifTrue:[
  4379     pixelSize notNil ifTrue:[
  4361         logSize := pixelSize
  4380 	logSize := pixelSize
  4362     ] ifFalse:[
  4381     ] ifFalse:[
  4363         logSize := (pointSize * (self getLogicalPixelSizeY) / 72.0) rounded.
  4382 	logSize := (pointSize * (self getLogicalPixelSizeY) / 72.0) rounded.
  4364     ].
  4383     ].
  4365 %{
  4384 %{
  4366     HGDIOBJ hFont;
  4385     HGDIOBJ hFont;
  4367     int  pointSize, nHeight, nWidth, nEscapement, nOrientation;
  4386     int  nHeight, nWidth, nEscapement, nOrientation;
  4368     char* work;
  4387     char* work;
  4369     char* work2;
  4388     char* work2;
  4370     DWORD fnWeight;
  4389     DWORD fnWeight;
  4371     DWORD fdwItalic;
  4390     DWORD fdwItalic;
  4372     DWORD fdwUnderline;
  4391     DWORD fdwUnderline;
  4393     fdwQuality         = DEFAULT_QUALITY;
  4412     fdwQuality         = DEFAULT_QUALITY;
  4394     fdwPitchAndFamily  = FF_DONTCARE;
  4413     fdwPitchAndFamily  = FF_DONTCARE;
  4395 
  4414 
  4396     fdwCharSet   = ANSI_CHARSET;
  4415     fdwCharSet   = ANSI_CHARSET;
  4397     if ((encoding == @symbol('ms-ansi'))) {
  4416     if ((encoding == @symbol('ms-ansi'))) {
  4398         fdwCharSet   = ANSI_CHARSET;
  4417 	fdwCharSet   = ANSI_CHARSET;
  4399     } else if (encoding == @symbol('ms-default')
  4418     } else if (encoding == @symbol('ms-default')
  4400                || encoding == @symbol(*)) {
  4419 	       || encoding == @symbol(*)) {
  4401         fdwCharSet   = DEFAULT_CHARSET;
  4420 	fdwCharSet   = DEFAULT_CHARSET;
  4402     } else if ((encoding == @symbol('ms-symbol'))
  4421     } else if ((encoding == @symbol('ms-symbol'))
  4403             || (encoding == @symbol('misc-fontspecific'))) {
  4422 	    || (encoding == @symbol('misc-fontspecific'))) {
  4404         fdwCharSet   = SYMBOL_CHARSET;
  4423 	fdwCharSet   = SYMBOL_CHARSET;
  4405     } else if ((encoding == @symbol('ms-shiftjis'))
  4424     } else if ((encoding == @symbol('ms-shiftjis'))
  4406             || (encoding == @symbol('jisx0208.1983-0'))){
  4425 	    || (encoding == @symbol('jisx0208.1983-0'))){
  4407         fdwCharSet   = SHIFTJIS_CHARSET;
  4426 	fdwCharSet   = SHIFTJIS_CHARSET;
  4408     } else if ((encoding == @symbol('ms-gb2312'))
  4427     } else if ((encoding == @symbol('ms-gb2312'))
  4409             || (encoding == @symbol('gb2312.1980-0'))) {
  4428 	    || (encoding == @symbol('gb2312.1980-0'))) {
  4410         fdwCharSet   = GB2312_CHARSET;
  4429 	fdwCharSet   = GB2312_CHARSET;
  4411     } else if ((encoding == @symbol('ms-hangeul'))
  4430     } else if ((encoding == @symbol('ms-hangeul'))
  4412             || (encoding == @symbol('ksc5601.1987-0'))) {
  4431 	    || (encoding == @symbol('ksc5601.1987-0'))) {
  4413         fdwCharSet   = HANGEUL_CHARSET;
  4432 	fdwCharSet   = HANGEUL_CHARSET;
  4414     } else if ((encoding == @symbol('ms-chinesebig5'))
  4433     } else if ((encoding == @symbol('ms-chinesebig5'))
  4415             || (encoding == @symbol('big5'))) {
  4434 	    || (encoding == @symbol('big5'))) {
  4416         fdwCharSet   = CHINESEBIG5_CHARSET;
  4435 	fdwCharSet   = CHINESEBIG5_CHARSET;
  4417     } else if (encoding == @symbol('ms-oem')) {
  4436     } else if (encoding == @symbol('ms-oem')) {
  4418         fdwCharSet   = OEM_CHARSET;
  4437 	fdwCharSet   = OEM_CHARSET;
  4419     } else if (encoding == @symbol('ms-johab')) {
  4438     } else if (encoding == @symbol('ms-johab')) {
  4420         fdwCharSet   = JOHAB_CHARSET;
  4439 	fdwCharSet   = JOHAB_CHARSET;
  4421     } else if ((encoding == @symbol('ms-hebrew'))
  4440     } else if ((encoding == @symbol('ms-hebrew'))
  4422             || (encoding == @symbol('ms-cp1255'))) {
  4441 	    || (encoding == @symbol('ms-cp1255'))) {
  4423         fdwCharSet   = HEBREW_CHARSET;
  4442 	fdwCharSet   = HEBREW_CHARSET;
  4424     } else if ((encoding == @symbol('ms-arabic'))
  4443     } else if ((encoding == @symbol('ms-arabic'))
  4425             || (encoding == @symbol('ms-cp1256'))) {
  4444 	    || (encoding == @symbol('ms-cp1256'))) {
  4426         fdwCharSet   = ARABIC_CHARSET;
  4445 	fdwCharSet   = ARABIC_CHARSET;
  4427     } else if ((encoding == @symbol('ms-greek'))
  4446     } else if ((encoding == @symbol('ms-greek'))
  4428             || (encoding == @symbol('ms-cp1253'))) {
  4447 	    || (encoding == @symbol('ms-cp1253'))) {
  4429         fdwCharSet   = GREEK_CHARSET;
  4448 	fdwCharSet   = GREEK_CHARSET;
  4430     } else if ((encoding == @symbol('ms-turkish'))
  4449     } else if ((encoding == @symbol('ms-turkish'))
  4431             || (encoding == @symbol('ms-cp1254'))) {
  4450 	    || (encoding == @symbol('ms-cp1254'))) {
  4432         fdwCharSet   = TURKISH_CHARSET;
  4451 	fdwCharSet   = TURKISH_CHARSET;
  4433     } else if ((encoding == @symbol('ms-russian'))
  4452     } else if ((encoding == @symbol('ms-russian'))
  4434             || (encoding == @symbol('ms-cp1251'))) {
  4453 	    || (encoding == @symbol('ms-cp1251'))) {
  4435         fdwCharSet   = RUSSIAN_CHARSET;
  4454 	fdwCharSet   = RUSSIAN_CHARSET;
  4436     } else if ((encoding == @symbol('ms-easteurope'))
  4455     } else if ((encoding == @symbol('ms-easteurope'))
  4437             || (encoding == @symbol('ms-cp1250'))) {
  4456 	    || (encoding == @symbol('ms-cp1250'))) {
  4438         fdwCharSet   = EASTEUROPE_CHARSET;
  4457 	fdwCharSet   = EASTEUROPE_CHARSET;
  4439     } else if ((encoding == @symbol('ms-baltic'))
  4458     } else if ((encoding == @symbol('ms-baltic'))
  4440             || (encoding == @symbol('ms-cp1257'))) {
  4459 	    || (encoding == @symbol('ms-cp1257'))) {
  4441         fdwCharSet   = BALTIC_CHARSET;
  4460 	fdwCharSet   = BALTIC_CHARSET;
  4442     } else if ((encoding == @symbol('ms-vietnamese'))) {
  4461     } else if ((encoding == @symbol('ms-vietnamese'))) {
  4443         fdwCharSet   = VIETNAMESE_CHARSET;
  4462 	fdwCharSet   = VIETNAMESE_CHARSET;
  4444     } else if ((encoding == @symbol('ms-thai'))) {
  4463     } else if ((encoding == @symbol('ms-thai'))) {
  4445         fdwCharSet   = THAI_CHARSET;
  4464 	fdwCharSet   = THAI_CHARSET;
  4446     } else if ((encoding == @symbol('ms-mac'))) {
  4465     } else if ((encoding == @symbol('ms-mac'))) {
  4447         fdwCharSet   = MAC_CHARSET;
  4466 	fdwCharSet   = MAC_CHARSET;
  4448 #ifdef UNICODE_CHARSET
  4467 #ifdef UNICODE_CHARSET
  4449     } else if ((encoding == @symbol('ms-unicode'))) {
  4468     } else if ((encoding == @symbol('ms-unicode'))) {
  4450         fdwCharSet   = UNICODE_CHARSET;
  4469 	fdwCharSet   = UNICODE_CHARSET;
  4451 #endif
  4470 #endif
  4452     }
  4471     }
  4453 
  4472 
  4454     if ( __isString( family ) ) {
  4473     if ( __isString( family ) ) {
  4455         work = __stringVal( family );
  4474 	work = __stringVal( family );
  4456         if (strcmp( work, "nil" ) != 0 ) {
  4475 	if (strcmp( work, "nil" ) != 0 ) {
  4457             strncpy( faceName, work, sizeof(faceName)-1 );
  4476 	    strncpy( faceName, work, sizeof(faceName)-1 );
  4458         }
  4477 	}
  4459     }
  4478     }
  4460 
  4479 
  4461     /* Q: should we allow those ? (they make ST/X programs less portable to X */
  4480     /* Q: should we allow those ? (they make ST/X programs less portable to X */
  4462     if( __isString( weight ) ) {
  4481     if( __isString( weight ) ) {
  4463         work = __stringVal( weight );
  4482 	work = __stringVal( weight );
  4464         if (strcmp( work, "bold" ) == 0 ) {
  4483 	if (strcmp( work, "bold" ) == 0 ) {
  4465             fnWeight = FW_BOLD;
  4484 	    fnWeight = FW_BOLD;
  4466         } else if (strcmp( work, "medium" ) == 0 ) {
  4485 	} else if (strcmp( work, "medium" ) == 0 ) {
  4467             fnWeight = FW_MEDIUM;
  4486 	    fnWeight = FW_MEDIUM;
  4468         } else if (strcmp( work, "normal" ) == 0 ) {
  4487 	} else if (strcmp( work, "normal" ) == 0 ) {
  4469             fnWeight = FW_NORMAL;
  4488 	    fnWeight = FW_NORMAL;
  4470         } else if (strcmp( work, "light" ) == 0 ) {
  4489 	} else if (strcmp( work, "light" ) == 0 ) {
  4471             fnWeight = FW_LIGHT;
  4490 	    fnWeight = FW_LIGHT;
  4472         } else if (strcmp( work, "demi" ) == 0 ) {
  4491 	} else if (strcmp( work, "demi" ) == 0 ) {
  4473             fnWeight = FW_LIGHT;
  4492 	    fnWeight = FW_LIGHT;
  4474         } else if (strcmp( work, "heavy" ) == 0 ) {
  4493 	} else if (strcmp( work, "heavy" ) == 0 ) {
  4475             fnWeight = FW_HEAVY;
  4494 	    fnWeight = FW_HEAVY;
  4476         } else if (strcmp( work, "extraBold" ) == 0 ) {
  4495 	} else if (strcmp( work, "extraBold" ) == 0 ) {
  4477             fnWeight = FW_EXTRABOLD;
  4496 	    fnWeight = FW_EXTRABOLD;
  4478         } else if (strcmp( work, "semiBold" ) == 0 ) {
  4497 	} else if (strcmp( work, "semiBold" ) == 0 ) {
  4479             fnWeight = FW_SEMIBOLD;
  4498 	    fnWeight = FW_SEMIBOLD;
  4480         } else if (strcmp( work, "thin" ) == 0 ) {
  4499 	} else if (strcmp( work, "thin" ) == 0 ) {
  4481             fnWeight = FW_THIN;
  4500 	    fnWeight = FW_THIN;
  4482         } else if (strcmp( work, "extraLight" ) == 0 ) {
  4501 	} else if (strcmp( work, "extraLight" ) == 0 ) {
  4483             fnWeight = FW_EXTRALIGHT;
  4502 	    fnWeight = FW_EXTRALIGHT;
  4484         }
  4503 	}
  4485     } else if (__isSmallInteger(weight)) {
  4504     } else if (__isSmallInteger(weight)) {
  4486         fnWeight = __intVal(weight);
  4505 	fnWeight = __intVal(weight);
  4487     }
  4506     }
  4488 
  4507 
  4489     if(__isSmallInteger( logSize )) {
  4508     if(__isSmallInteger( logSize )) {
  4490         nHeight = __intVal( logSize );
  4509 	nHeight = __intVal( logSize );
  4491     }
  4510     }
  4492 
  4511 
  4493     if (__isString(slant)) {
  4512     if (__isString(slant)) {
  4494         work2 = __stringVal( slant );
  4513 	work2 = __stringVal( slant );
  4495         work  = __stringVal( slant );
  4514 	work  = __stringVal( slant );
  4496 
  4515 
  4497         if (strncmp(work2, "italic", 6) == 0)  {
  4516 	if (strncmp(work2, "italic", 6) == 0)  {
  4498             fdwItalic = TRUE;
  4517 	    fdwItalic = TRUE;
  4499             if ( work2[6] == '-' )
  4518 	    if ( work2[6] == '-' )
  4500                 strncpy( work, &work2[7], ( strlen( work2) - 7) );
  4519 		strncpy( work, &work2[7], ( strlen( work2) - 7) );
  4501         } else {
  4520 	} else {
  4502             if (strncmp(work2, "oblique", 7) == 0)  {
  4521 	    if (strncmp(work2, "oblique", 7) == 0)  {
  4503                 fdwItalic = TRUE;
  4522 		fdwItalic = TRUE;
  4504                 if ( work2[7] == '-' )
  4523 		if ( work2[7] == '-' )
  4505                     strncpy( work, &work2[8], ( strlen( work2) - 8) );
  4524 		    strncpy( work, &work2[8], ( strlen( work2) - 8) );
  4506             }
  4525 	    }
  4507         }
  4526 	}
  4508         if (strncmp( work, "underline", 9 ) == 0 ) {
  4527 	if (strncmp( work, "underline", 9 ) == 0 ) {
  4509             fdwUnderline = TRUE;
  4528 	    fdwUnderline = TRUE;
  4510             if( work[10] == '-' )
  4529 	    if( work[10] == '-' )
  4511                 strncpy( work2, &work[11], ( strlen( work ) - 10 ) );
  4530 		strncpy( work2, &work[11], ( strlen( work ) - 10 ) );
  4512         }
  4531 	}
  4513         if (strncmp( work2, "strikeOut", 9 ) == 0 ) {
  4532 	if (strncmp( work2, "strikeOut", 9 ) == 0 ) {
  4514             fdwStrikeOut = TRUE;
  4533 	    fdwStrikeOut = TRUE;
  4515         }
  4534 	}
  4516     }
  4535     }
  4517 
  4536 
  4518     DPRINTF(("CreateFont face:%s h=%d w=%d wght=%d\n",
  4537     DPRINTF(("CreateFont face:%s h=%d w=%d wght=%d\n",
  4519                 faceName, nHeight, nWidth, fnWeight));
  4538 		faceName, nHeight, nWidth, fnWeight));
  4520 
  4539 
  4521     hFont = CreateFont( -nHeight,   /* character height - not cell height */
  4540     hFont = CreateFont( -nHeight,   /* character height - not cell height */
  4522                         nWidth,
  4541 			nWidth,
  4523                         nEscapement,
  4542 			nEscapement,
  4524                         nOrientation,
  4543 			nOrientation,
  4525                         fnWeight,
  4544 			fnWeight,
  4526                         fdwItalic,
  4545 			fdwItalic,
  4527                         fdwUnderline,
  4546 			fdwUnderline,
  4528                         fdwStrikeOut,
  4547 			fdwStrikeOut,
  4529                         fdwCharSet,
  4548 			fdwCharSet,
  4530                         fdwOutputPrecision,
  4549 			fdwOutputPrecision,
  4531                         fdwClipPrecision,
  4550 			fdwClipPrecision,
  4532                         fdwQuality,
  4551 			fdwQuality,
  4533                         fdwPitchAndFamily,
  4552 			fdwPitchAndFamily,
  4534                         faceName );
  4553 			faceName );
  4535 
  4554 
  4536     if (hFont != NULL) {
  4555     if (hFont != NULL) {
  4537         DPRINTF(("createFont: %x\n", hFont));
  4556 	DPRINTF(("createFont: %x\n", hFont));
  4538 /*
  4557 /*
  4539     #ifdef COUNT_RESOURCES
  4558     #ifdef COUNT_RESOURCES
  4540         __cnt_font++;
  4559 	__cnt_font++;
  4541         RES1PRINTF(("CreateFont %d\n", __cnt_font));
  4560 	RES1PRINTF(("CreateFont %d\n", __cnt_font));
  4542     #endif
  4561     #endif
  4543 */
  4562 */
  4544         RETURN ( __MKEXTERNALADDRESS(hFont) );
  4563 	RETURN ( __MKEXTERNALADDRESS(hFont) );
  4545     }
  4564     }
  4546 
  4565 
  4547     DPRINTF(("***** ERROR createFontWithFoundry failed ERROR *****\n" ));
  4566     DPRINTF(("***** ERROR createFontWithFoundry failed ERROR *****\n" ));
  4548 %}.
  4567 %}.
  4549     ^ nil
  4568     ^ nil
  4550 
  4569 
  4551     "
  4570     "
  4552      Display getFontWithFoundry:'*'
  4571      Display getFontWithFoundry:'*'
  4553                          family:'courier'
  4572 			 family:'courier'
  4554                          weight:'medium'
  4573 			 weight:'medium'
  4555                           slant:'r'
  4574 			  slant:'r'
  4556                         spacing:nil
  4575 			spacing:nil
  4557                       pixelSize:nil
  4576 		      pixelSize:nil
  4558                            size:13
  4577 			   size:13
  4559                        registry:'iso8859'
  4578 		       registry:'iso8859'
  4560                        encoding:'*'
  4579 		       encoding:'*'
  4561     "
  4580     "
  4562 
  4581 
  4563     "new NT Version: 20.2.1997 / 22:33:29 / dq"
  4582     "new NT Version: 20.2.1997 / 22:33:29 / dq"
  4564 !
  4583 !
  4565 
  4584 
  5026 gcForBitmap:aDrawableId
  5045 gcForBitmap:aDrawableId
  5027 
  5046 
  5028 %{  /* NOCONTEXT */
  5047 %{  /* NOCONTEXT */
  5029 
  5048 
  5030     if (__isExternalAddress(aDrawableId)){
  5049     if (__isExternalAddress(aDrawableId)){
  5031         BITMAP bitmap;
  5050 	BITMAP bitmap;
  5032         HBITMAP hBitmap = _HBITMAPVAL(aDrawableId);
  5051 	HBITMAP hBitmap = _HBITMAPVAL(aDrawableId);
  5033         HBITMAP memBM;
  5052 	HBITMAP memBM;
  5034         HANDLE compatibleDC, rootDC, hdcScreen;
  5053 	HANDLE compatibleDC, rootDC, hdcScreen;
  5035    //     HANDLE printerDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
  5054    //     HANDLE printerDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
  5036 
  5055 
  5037         if (! hBitmap) {
  5056 	if (! hBitmap) {
  5038             RETURN (nil);
  5057 	    RETURN (nil);
  5039         }
  5058 	}
  5040 
  5059 
  5041         if (GetObject(hBitmap, sizeof(bitmap), &bitmap)) {
  5060 	if (GetObject(hBitmap, sizeof(bitmap), &bitmap)) {
  5042 /*
  5061 /*
  5043             DDPRINTF(("bitmap info:%d\n", bitmap.bmBitsPixel));
  5062 	    DDPRINTF(("bitmap info:%d\n", bitmap.bmBitsPixel));
  5044 */
  5063 */
  5045         } else {
  5064 	} else {
  5046 /*
  5065 /*
  5047             DPRINTF(("noinfo returned for bitmap\n"));
  5066 	    DPRINTF(("noinfo returned for bitmap\n"));
  5048 */
  5067 */
  5049             /* mhmh - can this happen ? */
  5068 	    /* mhmh - can this happen ? */
  5050             bitmap.bmBitsPixel = 1;
  5069 	    bitmap.bmBitsPixel = 1;
  5051         }
  5070 	}
  5052 /*
  5071 /*
  5053         gcData->hBitmap = hBitmap;
  5072 	gcData->hBitmap = hBitmap;
  5054         gcData->bitmapColorBitCount = bitmap.bmBitsPixel;
  5073 	gcData->bitmapColorBitCount = bitmap.bmBitsPixel;
  5055 */
  5074 */
  5056 
  5075 
  5057         rootDC  = CreateDC("DISPLAY", NULL, NULL, NULL);
  5076 	rootDC  = CreateDC("DISPLAY", NULL, NULL, NULL);
  5058         compatibleDC = CreateCompatibleDC(rootDC);
  5077 	compatibleDC = CreateCompatibleDC(rootDC);
  5059         SelectObject(compatibleDC, hBitmap);
  5078 	SelectObject(compatibleDC, hBitmap);
  5060 
  5079 
  5061    //     hdcScreen= CreateDC("NULL", NULL, NULL, NULL);
  5080    //     hdcScreen= CreateDC("NULL", NULL, NULL, NULL);
  5062    //       compatibleDC =  rootDC;
  5081    //       compatibleDC =  rootDC;
  5063    //     compatibleDC = CreateCompatibleDC(printerDC);
  5082    //     compatibleDC = CreateCompatibleDC(printerDC);
  5064    //     compatibleDC = CreateCompatibleDC(0);
  5083    //     compatibleDC = CreateCompatibleDC(0);
  5065 
  5084 
  5066    //     memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight );
  5085    //     memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight );
  5067    //     SelectObject ( compatibleDC, memBM );
  5086    //     SelectObject ( compatibleDC, memBM );
  5068 
  5087 
  5069         RETURN (__MKEXTERNALADDRESS(compatibleDC));
  5088 	RETURN (__MKEXTERNALADDRESS(compatibleDC));
  5070 
  5089 
  5071 /*
  5090 /*
  5072         RETURN ( __MKEXTERNALADDRESS(gcData) );
  5091 	RETURN ( __MKEXTERNALADDRESS(gcData) );
  5073 */
  5092 */
  5074     }
  5093     }
  5075     RETURN (nil);
  5094     RETURN (nil);
  5076 %}
  5095 %}
  5077 !
  5096 !
  5091     HPEN prevPen;
  5110     HPEN prevPen;
  5092     LOGBRUSH Brush;
  5111     LOGBRUSH Brush;
  5093     COLORREF fgColor;
  5112     COLORREF fgColor;
  5094     HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
  5113     HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
  5095     int lStyle, bkMode, hMask, maskOrgX, maskOrgY;
  5114     int lStyle, bkMode, hMask, maskOrgX, maskOrgY;
  5096     int style, lineStyle, capStyle, joinStyle;
  5115     OBJ lineStyle, capStyle, joinStyle;
       
  5116     int style;
  5097     int lw;
  5117     int lw;
  5098     int BK_TRANSPARENT;
  5118     int BK_TRANSPARENT;
  5099 
  5119 
  5100     BK_TRANSPARENT = 1;
  5120     BK_TRANSPARENT = 1;
  5101 
  5121 
  5102     lw= __INST(lineWidth);
  5122     lw= __intVal(__INST(lineWidth));
  5103 /*    fgColor = __intVal(__INST(foreground)) & 0xffffff;     */
  5123 /*    fgColor = __intVal(__INST(foreground)) & 0xffffff;     */
  5104 
  5124 
  5105     fgColor = GetTextColor(hDC);
  5125     fgColor = GetTextColor(hDC);
  5106     lineStyle=__INST(lineStyle);
  5126     lineStyle=__INST(lineStyle);
  5107     capStyle=__INST(capStyle);
  5127     capStyle=__INST(capStyle);
  5108     joinStyle=__INST(joinStyle);
  5128     joinStyle=__INST(joinStyle);
  5109     hMask= __INST(mask);
  5129     hMask= __intVal(__INST(mask));
  5110     maskOrgX=__intVal(maskOriginX);
  5130     maskOrgX=__intVal(maskOriginX);
  5111     maskOrgY=__intVal(maskOriginY);
  5131     maskOrgY=__intVal(maskOriginY);
  5112 
  5132 
  5113     if (lineStyle == @symbol(solid)) {
  5133     if (lineStyle == @symbol(solid)) {
  5114 	style = PS_SOLID;
  5134 	style = PS_SOLID;
  5153      && (hMask == 0)
  5173      && (hMask == 0)
  5154      && (lw /* lineWidth */ <= 1)) {
  5174      && (lw /* lineWidth */ <= 1)) {
  5155 	if (fgColor == 0 /* BlackPixel */ ) {
  5175 	if (fgColor == 0 /* BlackPixel */ ) {
  5156 	    hPen = GetStockObject(BLACK_PEN);
  5176 	    hPen = GetStockObject(BLACK_PEN);
  5157 	    prevPen = SelectObject(hDC, hPen);
  5177 	    prevPen = SelectObject(hDC, hPen);
  5158 	    RETURN( hPen );
  5178 	    RETURN( __MKEXTERNALADDRESS(hPen) );
  5159 	}
  5179 	}
  5160 	if (fgColor == 1 /* WhitePixel */) {
  5180 	if (fgColor == 1 /* WhitePixel */) {
  5161 	    hPen = GetStockObject(WHITE_PEN);
  5181 	    hPen = GetStockObject(WHITE_PEN);
  5162 	    prevPen = SelectObject(hDC, hPen);
  5182 	    prevPen = SelectObject(hDC, hPen);
  5163 	    RETURN( hPen );
  5183 	    RETURN( __MKEXTERNALADDRESS(hPen) );
  5164 	}
  5184 	}
  5165     }
  5185     }
  5166 
  5186 
  5167     hPen = (HPEN) 0;
  5187     hPen = (HPEN) 0;
  5168 
  5188 
  5278 	    bkMode = BK_TRANSPARENT;
  5298 	    bkMode = BK_TRANSPARENT;
  5279 	}
  5299 	}
  5280     }
  5300     }
  5281 
  5301 
  5282     prevPen = SelectObject(hDC, hPen);
  5302     prevPen = SelectObject(hDC, hPen);
  5283 
  5303     RETURN (__MKEXTERNALADDRESS(hPen));
  5284     RETURN (hPen);
       
  5285 
  5304 
  5286 %}
  5305 %}
  5287 !
  5306 !
  5288 
  5307 
  5289 xprimDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd width:imageWidth height:imageHeight
  5308 xprimDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd width:imageWidth height:imageHeight
  5422 xxxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC
  5441 xxxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC
  5423     "draw a line. If the coordinates are not integers, an error is triggered."
  5442     "draw a line. If the coordinates are not integers, an error is triggered."
  5424 
  5443 
  5425     |penHandle|
  5444     |penHandle|
  5426 
  5445 
  5427     penHandle := ExternalBytes address: self getPenForMyContext.
  5446     penHandle := self getPenForMyContext.
  5428 
  5447 
  5429 %{  /* NOCONTEXT */
  5448 %{  /* NOCONTEXT */
  5430     if (__isExternalAddressLike(aDC)
  5449     if (__isExternalAddressLike(aDC)
  5431      && __isExternalAddressLike(penHandle)
  5450      && __isExternalAddressLike(penHandle)
  5432      && __bothSmallInteger(x0, y0)
  5451      && __bothSmallInteger(x0, y0)
  5500 
  5519 
  5501     | retVal info |
  5520     | retVal info |
  5502 
  5521 
  5503     info := (self class getPrinterInformationString: self name) asUppercase.
  5522     info := (self class getPrinterInformationString: self name) asUppercase.
  5504     (info includesSubString: ',PSCRIPT,')
  5523     (info includesSubString: ',PSCRIPT,')
  5505         ifTrue: [
  5524 	ifTrue: [
  5506             retVal := self class postScriptBlackWhite not.
  5525 	    retVal := self class postScriptBlackWhite not.
  5507 "/            retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not.
  5526 "/            retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not.
  5508         ]
  5527 	]
  5509         ifFalse: [
  5528 	ifFalse: [
  5510             retVal := (info includesSubString: 'PDF')
  5529 	    retVal := (info includesSubString: 'PDF')
  5511                 ifTrue: [true]
  5530 		ifTrue: [true]
  5512                 ifFalse: [self numberOfColorBitsPerPixel > 1].
  5531 		ifFalse: [self numberOfColorBitsPerPixel > 1].
  5513     ].
  5532     ].
  5514 
  5533 
  5515     ^retVal
  5534     ^retVal
  5516 !
  5535 !
  5517 
  5536 
  5533      one entry in the print queue."
  5552      one entry in the print queue."
  5534 
  5553 
  5535     |docInfoStruct nameAddress title fileNameAddress|
  5554     |docInfoStruct nameAddress title fileNameAddress|
  5536 
  5555 
  5537     gcId isNil ifTrue:[
  5556     gcId isNil ifTrue:[
  5538         self buildPrinter
  5557 	self buildPrinter
  5539     ].
  5558     ].
  5540     abort := false.
  5559     abort := false.
  5541     title := aString ? 'Smalltalk/X'.
  5560     title := aString ? 'Smalltalk/X'.
  5542     nameAddress := title asExternalBytes unprotectFromGC.
  5561     nameAddress := title asExternalBytes unprotectFromGC.
  5543     aFileName isNil ifFalse:[
  5562     aFileName isNil ifFalse:[
  5544         fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
  5563 	fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
  5545     ].
  5564     ].
  5546     docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
  5565     docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
  5547     docInfoStruct
  5566     docInfoStruct
  5548         cbSize:docInfoStruct sizeInBytes;
  5567 	cbSize:docInfoStruct sizeInBytes;
  5549         lpszDocName:nameAddress address.
  5568 	lpszDocName:nameAddress address.
  5550     fileNameAddress isNil ifFalse:[
  5569     fileNameAddress isNil ifFalse:[
  5551         docInfoStruct lpszOutput:fileNameAddress address
  5570 	docInfoStruct lpszOutput:fileNameAddress address
  5552     ].
  5571     ].
  5553     jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct.
  5572     jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct.
  5554     jobid > 0 ifFalse:[
  5573     jobid > 0 ifFalse:[
  5555         jobid = -1 ifTrue:[
  5574 	jobid = -1 ifTrue:[
  5556             abort := true.
  5575 	    abort := true.
  5557             ^ nil
  5576 	    ^ nil
  5558         ].
  5577 	].
  5559 "/        ^ self error
  5578 "/        ^ self error
  5560         OpenError raiseErrorString:'Cannot create printer job'.
  5579 	OpenError raiseErrorString:'Cannot create printer job'.
  5561     ].
  5580     ].
  5562     self startPage
  5581     self startPage
  5563 
  5582 
  5564     "Created: / 27-07-2006 / 18:19:31 / fm"
  5583     "Created: / 27-07-2006 / 18:19:31 / fm"
  5565     "Modified: / 03-08-2006 / 15:11:19 / fm"
  5584     "Modified: / 03-08-2006 / 15:11:19 / fm"
  5623 "
  5642 "
  5624 !
  5643 !
  5625 
  5644 
  5626 examples
  5645 examples
  5627 "
  5646 "
  5628                                                                                 [exBegin]
  5647 										[exBegin]
  5629     |gc font|
  5648     |gc font|
  5630 
  5649 
  5631     gc := WinPrinterContext openGraphicContext.
  5650     gc := WinPrinterContext openGraphicContext.
  5632     gc isNil ifTrue:[^ self ].
  5651     gc isNil ifTrue:[^ self ].
  5633 
  5652 
  5634     [
  5653     [
  5635         gc startPrintJob:'Test'.
  5654 	gc startPrintJob:'Test'.
  5636         gc paint:(Color black).
  5655 	gc paint:(Color black).
  5637         gc displayLineFromX:10 y:40 toX:100 y:40.
  5656 	gc displayLineFromX:10 y:40 toX:100 y:40.
  5638         font := (Font family:'helvetica' face:'roman' style:'bold' size:16) onDevice:(gc device).
  5657 	font := (Font family:'helvetica' face:'roman' style:'bold' size:16) onDevice:(gc device).
  5639 
  5658 
  5640         gc font:font.
  5659 	gc font:font.
  5641         gc paint:(Color red).
  5660 	gc paint:(Color red).
  5642         gc displayString:'hallo' x:10 y:(40 + font ascent).
  5661 	gc displayString:'hallo' x:10 y:(40 + font ascent).
  5643 
  5662 
  5644         gc paint:(Color black).
  5663 	gc paint:(Color black).
  5645         gc displayLineFromX:10 y:(40 + font height) toX:100 y:(40 + font height).
  5664 	gc displayLineFromX:10 y:(40 + font height) toX:100 y:(40 + font height).
  5646     ] ensure:[
  5665     ] ensure:[
  5647         gc close.
  5666 	gc close.
  5648     ].
  5667     ].
  5649                                                                                 [exEnd]
  5668 										[exEnd]
  5650 
  5669 
  5651 "
  5670 "
  5652 ! !
  5671 ! !
  5653 
  5672 
  5654 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing dimensions'!
  5673 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing dimensions'!
  5710     top := tranlate y.
  5729     top := tranlate y.
  5711     rgt := lft + extent x.
  5730     rgt := lft + extent x.
  5712     bot := top + extent y.
  5731     bot := top + extent y.
  5713 
  5732 
  5714     aRectangle notNil ifTrue:[
  5733     aRectangle notNil ifTrue:[
  5715         lft := lft max:aRectangle left.
  5734 	lft := lft max:aRectangle left.
  5716         top := top max:aRectangle top.
  5735 	top := top max:aRectangle top.
  5717         rgt := rgt min:aRectangle right.
  5736 	rgt := rgt min:aRectangle right.
  5718         bot := bot min:aRectangle bottom.
  5737 	bot := bot min:aRectangle bottom.
  5719     ].
  5738     ].
  5720     super clippingRectangle:(Rectangle left:lft top:top right:rgt bottom:bot).
  5739     super clippingRectangle:(Rectangle left:lft top:top right:rgt bottom:bot).
  5721 !
  5740 !
  5722 
  5741 
  5723 scale
  5742 scale
  5734 
  5753 
  5735 transformation
  5754 transformation
  5736     "answer the transformation excluding the fontScale factor"
  5755     "answer the transformation excluding the fontScale factor"
  5737 
  5756 
  5738     ^ WindowingTransformation scale:(self scale)
  5757     ^ WindowingTransformation scale:(self scale)
  5739                         translation:(self translation).
  5758 			translation:(self translation).
  5740 !
  5759 !
  5741 
  5760 
  5742 transformation:aTransformation
  5761 transformation:aTransformation
  5743     "set the transformation and add the fontScale factor"
  5762     "set the transformation and add the fontScale factor"
  5744 
  5763 
  5745     |s t|
  5764     |s t|
  5746 
  5765 
  5747     aTransformation notNil ifTrue:[
  5766     aTransformation notNil ifTrue:[
  5748         s := aTransformation scale.
  5767 	s := aTransformation scale.
  5749         t := aTransformation translation.
  5768 	t := aTransformation translation.
  5750     ].
  5769     ].
  5751     self scale:s.
  5770     self scale:s.
  5752     self translation:t.
  5771     self translation:t.
  5753 !
  5772 !
  5754 
  5773 
  5776     |trans|
  5795     |trans|
  5777 
  5796 
  5778     trans := Point x:(self leftMargin) y:(self topMargin).
  5797     trans := Point x:(self leftMargin) y:(self topMargin).
  5779 
  5798 
  5780     aTranslation notNil ifTrue:[
  5799     aTranslation notNil ifTrue:[
  5781         trans := trans + aTranslation.
  5800 	trans := trans + aTranslation.
  5782     ].
  5801     ].
  5783 
  5802 
  5784     super translation:((trans * fontScale) rounded).
  5803     super translation:((trans * fontScale) rounded).
  5785 ! !
  5804 ! !
  5786 
  5805 
  5794     |end|
  5813     |end|
  5795 
  5814 
  5796     end := aString size.
  5815     end := aString size.
  5797 
  5816 
  5798     end ~~ 0 ifTrue:[
  5817     end ~~ 0 ifTrue:[
  5799         self displayOpaqueString:aString from:1 to:end x:x y:y.
  5818 	self displayOpaqueString:aString from:1 to:end x:x y:y.
  5800     ].
  5819     ].
  5801 !
  5820 !
  5802 
  5821 
  5803 displayString:aString from:index1 to:index2 x:x y:y
  5822 displayString:aString from:index1 to:index2 x:x y:y
  5804     "setup the special scale for strings before drawing"
  5823     "setup the special scale for strings before drawing"
  5806     |tscale fscale yFont xFont|
  5825     |tscale fscale yFont xFont|
  5807 
  5826 
  5808     index2 < index1 ifTrue:[^ self].
  5827     index2 < index1 ifTrue:[^ self].
  5809 
  5828 
  5810     transformation isNil ifTrue:[
  5829     transformation isNil ifTrue:[
  5811         self initTransformation.
  5830 	self initTransformation.
  5812     ].
  5831     ].
  5813     tscale := transformation scale.
  5832     tscale := transformation scale.
  5814     fscale := tscale / fontScale.
  5833     fscale := tscale / fontScale.
  5815 
  5834 
  5816     xFont := x * fontScale x.
  5835     xFont := x * fontScale x.
  5817     yFont := (y - font ascent) * fontScale y.    "/ MM_TEXT - Ursprung liegt oben links
  5836     yFont := (y - font ascent) * fontScale y.    "/ MM_TEXT - Ursprung liegt oben links
  5818 
  5837 
  5819     transformation scale:fscale.
  5838     transformation scale:fscale.
  5820 
  5839 
  5821     super displayString:aString from:index1 to:index2
  5840     super displayString:aString from:index1 to:index2
  5822                 x:xFont truncated
  5841 		x:xFont truncated
  5823                 y:yFont truncated.
  5842 		y:yFont truncated.
  5824 
  5843 
  5825     transformation scale:tscale.
  5844     transformation scale:tscale.
  5826 !
  5845 !
  5827 
  5846 
  5828 displayString:aString x:x y:y
  5847 displayString:aString x:x y:y
  5829     |end|
  5848     |end|
  5830 
  5849 
  5831     end := aString size.
  5850     end := aString size.
  5832 
  5851 
  5833     end ~~ 0 ifTrue:[
  5852     end ~~ 0 ifTrue:[
  5834         self displayString:aString from:1 to:end x:x y:y.
  5853 	self displayString:aString from:1 to:end x:x y:y.
  5835     ].
  5854     ].
  5836 !
  5855 !
  5837 
  5856 
  5838 displayString:aString x:x y:y angle:drawAngle opaque:opaque
  5857 displayString:aString x:x y:y angle:drawAngle opaque:opaque
  5839     "angles other than 0 is not yet supported"
  5858     "angles other than 0 is not yet supported"
  5841     |angle|
  5860     |angle|
  5842 
  5861 
  5843     angle := drawAngle.
  5862     angle := drawAngle.
  5844 
  5863 
  5845     angle >= 360 ifTrue:[
  5864     angle >= 360 ifTrue:[
  5846         angle := angle - (((angle // 360)) * 360)
  5865 	angle := angle - (((angle // 360)) * 360)
  5847     ] ifFalse:[
  5866     ] ifFalse:[
  5848         angle < 0 ifTrue:[
  5867 	angle < 0 ifTrue:[
  5849             angle := angle - (((angle // 360)) * 360).
  5868 	    angle := angle - (((angle // 360)) * 360).
  5850             angle := angle + 360.
  5869 	    angle := angle + 360.
  5851             angle >= 360 ifTrue:[
  5870 	    angle >= 360 ifTrue:[
  5852                 angle := angle - (((angle // 360)) * 360)
  5871 		angle := angle - (((angle // 360)) * 360)
  5853             ]
  5872 	    ]
  5854         ].
  5873 	].
  5855     ].
  5874     ].
  5856     angle == 0 ifTrue:[
  5875     angle == 0 ifTrue:[
  5857         super displayString:aString x:x y:y angle:drawAngle opaque:opaque.
  5876 	super displayString:aString x:x y:y angle:drawAngle opaque:opaque.
  5858     ].
  5877     ].
  5859 ! !
  5878 ! !
  5860 
  5879 
  5861 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'font stuff'!
  5880 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'font stuff'!
  5862 
  5881 
  5867 
  5886 
  5868     metrics := super fontMetricsOf:fontId.
  5887     metrics := super fontMetricsOf:fontId.
  5869     metrics isNil ifTrue:[^ nil ].
  5888     metrics isNil ifTrue:[^ nil ].
  5870 
  5889 
  5871     metrics ascent:((metrics ascent / fontScale y) rounded)
  5890     metrics ascent:((metrics ascent / fontScale y) rounded)
  5872             descent:((metrics descent / fontScale y) rounded + 1)
  5891 	    descent:((metrics descent / fontScale y) rounded + 1)
  5873             maxAscent:((metrics maxAscent / fontScale y) rounded)
  5892 	    maxAscent:((metrics maxAscent / fontScale y) rounded)
  5874             maxDescent:((metrics maxDescent / fontScale y) rounded + 1)
  5893 	    maxDescent:((metrics maxDescent / fontScale y) rounded + 1)
  5875             minWidth:((metrics minWidth / fontScale x) rounded)
  5894 	    minWidth:((metrics minWidth / fontScale x) rounded)
  5876             maxWidth:((metrics maxWidth / fontScale x) rounded)
  5895 	    maxWidth:((metrics maxWidth / fontScale x) rounded)
  5877             avgWidth:((metrics averageWidth / fontScale x) rounded).
  5896 	    avgWidth:((metrics averageWidth / fontScale x) rounded).
  5878 
  5897 
  5879     ^ metrics
  5898     ^ metrics
  5880 !
  5899 !
  5881 
  5900 
  5882 getFontWithFoundry:foundry family:family weight:weight
  5901 getFontWithFoundry:foundry family:family weight:weight
  5883               slant:slant spacing:spc pixelSize:pixelSize size:pointSize
  5902 	      slant:slant spacing:spc pixelSize:pixelSize size:pointSize
  5884               registry:registry encoding:encoding
  5903 	      registry:registry encoding:encoding
  5885 
  5904 
  5886     "compute the pixels dependent on the Screen current resolution"
  5905     "compute the pixels dependent on the Screen current resolution"
  5887 
  5906 
  5888     |psize|
  5907     |psize|
  5889 
  5908 
  5890     psize := pixelSize.
  5909     psize := pixelSize.
  5891 
  5910 
  5892     psize isNil ifTrue:[ 
  5911     psize isNil ifTrue:[
  5893         psize := (pointSize * (self getLogicalPixelSizeY) / (Screen current getLogicalPixelSizeY)) rounded.
  5912 	psize := (pointSize * (self getLogicalPixelSizeY) / (Screen current getLogicalPixelSizeY)) rounded.
  5894     ].
  5913     ].
  5895 
  5914 
  5896     ^ super getFontWithFoundry:foundry family:family weight:weight
  5915     ^ super getFontWithFoundry:foundry family:family weight:weight
  5897               slant:slant spacing:spc pixelSize:psize size:pointSize
  5916 	      slant:slant spacing:spc pixelSize:psize size:pointSize
  5898               registry:registry encoding:encoding
  5917 	      registry:registry encoding:encoding
  5899 !
  5918 !
  5900 
  5919 
  5901 titleFont
  5920 titleFont
  5902     "answer the font used for displaying page numbers..."
  5921     "answer the font used for displaying page numbers..."
  5903 
  5922 
  5904     titleFont isNil ifTrue:[
  5923     titleFont isNil ifTrue:[
  5905         titleFont := Font family:'helvetica' face:'medium' style:'roman' size:10.
  5924 	titleFont := Font family:'helvetica' face:'medium' style:'roman' size:10.
  5906         titleFont := titleFont onDevice:(self device).
  5925 	titleFont := titleFont onDevice:(self device).
  5907     ].
  5926     ].
  5908     ^ titleFont
  5927     ^ titleFont
  5909 !
  5928 !
  5910 
  5929 
  5911 titleFont:aFont
  5930 titleFont:aFont
  5912     "set the font used for displaying page numbers..."
  5931     "set the font used for displaying page numbers..."
  5913 
  5932 
  5914     (aFont notNil and:[aFont ~= titleFont]) ifTrue:[
  5933     (aFont notNil and:[aFont ~= titleFont]) ifTrue:[
  5915         titleFont := aFont onDevice:(self device).
  5934 	titleFont := aFont onDevice:(self device).
  5916     ].
  5935     ].
  5917 !
  5936 !
  5918 
  5937 
  5919 widthOf:aString from:index1 to:index2 inFont:aFontId
  5938 widthOf:aString from:index1 to:index2 inFont:aFontId
  5920     "after retrieving the width, we have to scale the width"
  5939     "after retrieving the width, we have to scale the width"
  5950 
  5969 
  5951 initTransformation
  5970 initTransformation
  5952     |margin|
  5971     |margin|
  5953 
  5972 
  5954     transformation isNil ifTrue:[
  5973     transformation isNil ifTrue:[
  5955         margin := Point x:(self leftMargin) y:(self topMargin).
  5974 	margin := Point x:(self leftMargin) y:(self topMargin).
  5956 
  5975 
  5957         transformation := WindowingTransformation scale:fontScale
  5976 	transformation := WindowingTransformation scale:fontScale
  5958                                             translation:(margin * fontScale).
  5977 					    translation:(margin * fontScale).
  5959     ].
  5978     ].
  5960 !
  5979 !
  5961 
  5980 
  5962 initialize
  5981 initialize
  5963     super initialize.
  5982     super initialize.
  5965     pageCounter    := 0.
  5984     pageCounter    := 0.
  5966     needsEndOfPage := false.
  5985     needsEndOfPage := false.
  5967     printPageNumbers := true.
  5986     printPageNumbers := true.
  5968 
  5987 
  5969     Language == #de ifTrue:[ pageNumberFormat := 'Seite %1' ]
  5988     Language == #de ifTrue:[ pageNumberFormat := 'Seite %1' ]
  5970                    ifFalse:[ pageNumberFormat := 'page %1'  ].
  5989 		   ifFalse:[ pageNumberFormat := 'page %1'  ].
  5971 ! !
  5990 ! !
  5972 
  5991 
  5973 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'printing process'!
  5992 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'printing process'!
  5974 
  5993 
  5975 displayTitleDo:aNoneArgAction
  5994 displayTitleDo:aNoneArgAction
  5976     
  5995 
  5977     |oldClip oldTrans oldFont|
  5996     |oldClip oldTrans oldFont|
  5978 
  5997 
  5979     oldClip := clipRect.
  5998     oldClip := clipRect.
  5980     oldClip notNil ifTrue:[ self deviceClippingRectangle:nil ].
  5999     oldClip notNil ifTrue:[ self deviceClippingRectangle:nil ].
  5981 
  6000 
  5997      if the current page is already closed by endPage, the request will be ignored"
  6016      if the current page is already closed by endPage, the request will be ignored"
  5998 
  6017 
  5999     |s|
  6018     |s|
  6000 
  6019 
  6001     needsEndOfPage ifFalse:[
  6020     needsEndOfPage ifFalse:[
  6002         ^ self
  6021 	^ self
  6003     ].
  6022     ].
  6004     needsEndOfPage := false.
  6023     needsEndOfPage := false.
  6005 
  6024 
  6006     printPageNumbers == true ifTrue:[
  6025     printPageNumbers == true ifTrue:[
  6007         self displayTitleDo:[
  6026 	self displayTitleDo:[
  6008             s := pageNumberFormat bindWith:pageCounter.
  6027 	    s := pageNumberFormat bindWith:pageCounter.
  6009 
  6028 
  6010             self displayString:s
  6029 	    self displayString:s
  6011                              x:(self extent x - (font widthOf:s))
  6030 			     x:(self extent x - (font widthOf:s))
  6012                              y:(self extent y + (font ascent)).
  6031 			     y:(self extent y + (font ascent)).
  6013         ]
  6032 	]
  6014     ].
  6033     ].
  6015     super endPage.
  6034     super endPage.
  6016 !
  6035 !
  6017 
  6036 
  6018 startPage
  6037 startPage
  6019     "starts a new page
  6038     "starts a new page
  6020      if the current page is not closed by endPage, a endPage is forward to the device"
  6039      if the current page is not closed by endPage, a endPage is forward to the device"
  6021 
  6040 
  6022     needsEndOfPage ifTrue:[
  6041     needsEndOfPage ifTrue:[
  6023         self endPage.
  6042 	self endPage.
  6024     ].
  6043     ].
  6025     super startPage.
  6044     super startPage.
  6026     needsEndOfPage := true.
  6045     needsEndOfPage := true.
  6027     pageCounter := pageCounter + 1.
  6046     pageCounter := pageCounter + 1.
  6028 ! !
  6047 ! !
  6029 
  6048 
  6030 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'queries'!
  6049 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'queries'!
  6031 
  6050 
  6032 pixelPerInch
  6051 pixelPerInch
  6033     ^ Point x:(self pixelsPerInchOfScreenWidth)
  6052     ^ Point x:(self pixelsPerInchOfScreenWidth)
  6034             y:(self pixelsPerInchOfScreenHeight).
  6053 	    y:(self pixelsPerInchOfScreenHeight).
  6035 !
  6054 !
  6036 
  6055 
  6037 resolution
  6056 resolution
  6038     ^ self pixelPerInch
  6057     ^ self pixelPerInch
  6039 ! !
  6058 ! !
  6040 
  6059 
  6041 !WinPrinterContext class methodsFor:'documentation'!
  6060 !WinPrinterContext class methodsFor:'documentation'!
  6042 
  6061 
  6043 version
  6062 version
  6044     ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.42 2012-04-25 19:46:59 stefan Exp $'
  6063     ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.43 2013-01-11 15:09:26 cg Exp $'
  6045 !
  6064 !
  6046 
  6065 
  6047 version_CVS
  6066 version_CVS
  6048     ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.42 2012-04-25 19:46:59 stefan Exp $'
  6067     ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.43 2013-01-11 15:09:26 cg Exp $'
  6049 ! !
  6068 ! !