WinPrinterContext.st
changeset 2356 a4128a41b721
parent 2354 8bfd1f8d2e08
child 2357 918859a27b27
--- a/WinPrinterContext.st	Thu Nov 15 16:31:02 2007 +0100
+++ b/WinPrinterContext.st	Wed Nov 21 17:40:19 2007 +0100
@@ -19,7 +19,8 @@
 !
 
 WinPrinterContext subclass:#WinPrinterGraphicContext
-	instanceVariableNames:'fontScale pageCounter needsEndOfPage'
+	instanceVariableNames:'fontScale printPageNumbers pageNumberFormat pageCounter
+		needsEndOfPage titleFont'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:WinPrinterContext
@@ -5572,6 +5573,20 @@
     ^ 50
 ! !
 
+!WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing-hooks'!
+
+pageNumberFormat:aFormatString
+    "set the pageNumber format - the default is 'page %1'"
+
+    pageNumberFormat := aFormatString ? ''
+!
+
+printPageNumbers:aBoolean
+    "enable/disable printing of page numbers - the default is on"
+
+    printPageNumbers := aBoolean.
+! !
+
 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing-transformation'!
 
 clippingRectangle:aRectangle
@@ -5772,6 +5787,14 @@
               registry:registry encoding:encoding
 !
 
+titleFont
+    titleFont isNil ifTrue:[
+        titleFont := Font family:'helvetica' face:'medium' style:'roman' size:10.
+        titleFont := titleFont onDevice:(self device).
+    ].
+    ^ titleFont
+!
+
 widthOf:aString from:index1 to:index2 inFont:aFontId
     "after retrieving the width, we have to scale the width"
 
@@ -5820,17 +5843,53 @@
 
     pageCounter    := 0.
     needsEndOfPage := false.
+    printPageNumbers := true.
+
+    Language == #de ifTrue:[ pageNumberFormat := 'Seite %1' ]
+                   ifFalse:[ pageNumberFormat := 'page %1'  ].
 ! !
 
 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'printing process'!
 
+displayTitleDo:aNoneArgAction
+    
+    |oldClip oldTrans oldFont|
+
+    oldClip  := clipRect.
+    oldTrans := self translation.
+    oldFont  := font.
+
+    self  font:(self titleFont).
+    self  translation:0.
+    super clippingRectangle:nil.
+
+    aNoneArgAction value.
+
+    self translation:oldTrans.
+    super clippingRectangle:oldClip.
+    oldFont notNil ifTrue:[ self font:oldFont ].
+!
+
 endPage
     "ends the current page
      if the current page is already closed by endPage, the request will be ignored"
 
-    needsEndOfPage ifFalse:[^ self].
-
+    |s|
+
+    needsEndOfPage ifFalse:[
+        ^ self
+    ].
     needsEndOfPage := false.
+
+    printPageNumbers == true ifTrue:[
+        self displayTitleDo:[
+            s := pageNumberFormat bindWith:pageCounter.
+
+            self displayString:s
+                             x:(self extent x - (font widthOf:s))
+                             y:(self extent y + (font ascent)).
+        ]
+    ].
     super endPage.
 !
 
@@ -5860,5 +5919,5 @@
 !WinPrinterContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.28 2007-11-14 09:53:14 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.29 2007-11-21 16:40:19 ca Exp $'
 ! !