*** empty log message ***
authorfm
Wed, 18 Apr 2007 13:20:46 +0200
changeset 2316 1660bcf17d63
parent 2315 026d4d8cfb1b
child 2317 c9bf3bf3c014
*** empty log message ***
WinPrinterContext.st
--- a/WinPrinterContext.st	Tue Apr 17 13:07:58 2007 +0200
+++ b/WinPrinterContext.st	Wed Apr 18 13:20:46 2007 +0200
@@ -50,16 +50,19 @@
 !WinPrinterContext class methodsFor:'instance creation'!
 
 fromPrinterInfo: aPrinterInfo
-    | aPrinter hDC|     
+    | printerContext printerDevice hDC|     
 
     hDC := aPrinterInfo createDC.
     hDC = 0 ifTrue: [ ^self error: 'Error while opening printer.' ].
 
-    aPrinter := self new.
-    aPrinter printerInfo: aPrinterInfo.
-    aPrinter setDevice:(WinPrinter on: aPrinterInfo) id:nil gcId:hDC.
-    aPrinter initExtent.
-    ^aPrinter
+    printerDevice := WinPrinter on: aPrinterInfo.
+    printerDevice printerDC:hDC.
+
+    printerContext := self new.
+    printerContext printerInfo: aPrinterInfo.
+    printerContext setDevice:printerDevice id:nil gcId:hDC.
+    printerContext initExtent.
+    ^printerContext
 
     "Created: / 03-08-2006 / 12:53:52 / fm"
     "Modified: / 04-08-2006 / 12:55:01 / fm"
@@ -100,6 +103,41 @@
 
 !WinPrinterContext class methodsFor:'testing & examples'!
 
+fillRectangles: rectangles
+    "Opens a print dialog and prints the given rectangles"
+
+    | printerInfo printer |
+
+    printerInfo := PrintingDialog getPrinterInfo.
+    printerInfo isNil ifTrue:[^self].
+
+    printer := self fromPrinterInfo: printerInfo.
+    [ 
+        printer startPrintJob: 'Fill Rectangles'.
+        printer foreground:Color blue background:Color white.
+        rectangles 
+            do:[:rectangle |
+                printer fillRectangleX: rectangle origin x 
+                        y: rectangle origin y 
+                        width: rectangle width 
+                        height: rectangle height.
+            ].
+        printer endPrintJob.
+    ] forkAt: 3
+
+    "
+     WinPrinterContext fillRectangles:  
+        (Array with: (Rectangle left:20 top:20 width:400 height:600)
+               with: (Rectangle left:500 top:700 width:600 height:400)    
+               with: (Rectangle left:800 top:1000 width:1600 height:2000)    
+               with: (Rectangle left:1040 top:1240 width:3000 height:3000)    
+        )
+    "
+
+    "Created: / 07-08-2006 / 11:40:48 / fm"
+    "Modified: / 16-04-2007 / 15:37:46 / cg"
+!
+
 print: aString font: aFont title: aTitle
     "Open a print dialog to allow printing of the given string
      using the given title & font."
@@ -157,6 +195,7 @@
     printer := self fromPrinterInfo: printerInfo.
     [ 
         printer startPrintJob: 'Circles'.
+        printer foreground:Color green background:Color white.
         arrayOfPointsAndRadius
             do:[:pointAndRadius |
                 printer displayCircle:(pointAndRadius at:1) 
@@ -216,7 +255,7 @@
     printer := self fromPrinterInfo: printerInfo.
     [ 
         printer startPrintJob: 'Lines'.
-        printer foreground:Color black background:Color white.
+        printer foreground:Color red background:Color white.
         pairOfPointsArray
             do:[:pairOfPoints |                 
                  printer displayLineFrom: (pairOfPoints at:1)  to: (pairOfPoints at:2).
@@ -226,8 +265,8 @@
 
     "
      WinPrinterContext printLines:  
-        (Array with: (Array with:10@10 with:100@10)
-               with: (Array with:10@10 with:35@200))
+        (Array with: (Array with:10@10 with:1000@5000)
+               with: (Array with:10@10 with:3500@2000))
     "
 
     "Created: / 07-08-2006 / 12:09:48 / fm"
@@ -235,6 +274,35 @@
     "Modified: / 16-04-2007 / 15:37:41 / cg"
 !
 
+printPoints: aCollectionOfPoints
+    "Opens a print dialog and prints the given points"
+
+    | printerInfo printer |
+
+    printerInfo := PrintingDialog getPrinterInfo.
+    printerInfo isNil ifTrue:[^self].
+
+    printer := self fromPrinterInfo: printerInfo.
+    [ 
+        printer startPrintJob: 'Points'.
+        aCollectionOfPoints do:[:each |
+            printer displayPointX: each x y: each y.
+        ].
+        printer endPrintJob.
+    ] forkAt: 3
+
+    "
+     WinPrinterContext printPoints:  
+        (Array with: (10 @ 10)
+               with: (500 @ 700)    
+               with: (900 @ 1000)
+               with: (1500 @ 1700)   
+               with: (2100 @ 2000)
+               with: (2500 @ 2700)   
+        )
+    "
+!
+
 printPolygons: polygons
     "Opens a print dialog and prints the given polygons"
 
@@ -268,6 +336,36 @@
     "Modified: / 16-04-2007 / 15:37:43 / cg"
 !
 
+printPolylines: evenCollectionOfPoints
+    "Opens a print dialog and prints the given rectangles"
+
+    | printerInfo printer |
+
+    printerInfo := PrintingDialog getPrinterInfo.
+    printerInfo isNil ifTrue:[^self].
+
+    printer := self fromPrinterInfo: printerInfo.
+    [ 
+        printer startPrintJob: 'Polylines'.
+        printer displayPolylines:evenCollectionOfPoints.
+        printer endPrintJob.
+    ] forkAt: 3
+
+    "
+     WinPrinterContext printPolylines:  
+        (Array with: (10 @ 10)
+               with: (500 @ 700)    
+               with: (900 @ 1000)
+               with: (1500 @ 1700)   
+               with: (2100 @ 2000)
+               with: (2500 @ 2700)   
+        )
+    "
+
+    "Created: / 07-08-2006 / 11:40:48 / fm"
+    "Modified: / 16-04-2007 / 15:37:46 / cg"
+!
+
 printRectangles: rectangles
     "Opens a print dialog and prints the given rectangles"
 
@@ -279,6 +377,7 @@
     printer := self fromPrinterInfo: printerInfo.
     [ 
         printer startPrintJob: 'Rectangles'.
+        printer foreground:Color red background:Color white.
         rectangles 
             do:[:rectangle |
                 printer displayRectangleX: rectangle origin x 
@@ -422,6 +521,13 @@
     "Created: / 01-08-2006 / 16:14:08 / fm"
 ! !
 
+!WinPrinterContext methodsFor:'drawing'!
+
+displayPolylines:arrayOfPoints 
+
+    device displayPolylines:arrayOfPoints in:nil with:gcId
+! !
+
 !WinPrinterContext methodsFor:'initialization & release'!
 
 createDC
@@ -454,7 +560,7 @@
     "Private - Delete and clear the device context of the receiver."
 
     self deleteDC.
-    device close.
+"/    device close.
     gcId := nil
 ! !
 
@@ -611,5 +717,5 @@
 !WinPrinterContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.5 2007-04-17 11:07:58 fm Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.6 2007-04-18 11:20:46 fm Exp $'
 ! !