pretty printing
authorClaus Gittinger <cg@exept.de>
Tue, 10 Oct 2006 18:22:07 +0200
changeset 2236 76291d984db9
parent 2235 0df6bda4b353
child 2237 950fb103a14e
pretty printing
PrinterContext.st
--- a/PrinterContext.st	Tue Oct 10 17:55:30 2006 +0200
+++ b/PrinterContext.st	Tue Oct 10 18:22:07 2006 +0200
@@ -394,61 +394,63 @@
 !PrinterContext methodsFor:'abort handling'!
 
 abortPrintJob
-        "Abort the current print job."  
-
+    "Abort the current print job."
+    
     abort := true.
     jobid := nil.
 
     "Modified: / 02-08-2006 / 15:40:26 / fm"
+    "Modified: / 10-10-2006 / 18:13:45 / cg"
 !
 
 aborted
-        "Answer whether the user aborted from PrintAbortDialog."
-    ^abort
+    "Answer whether the user aborted from PrintAbortDialog."
+    
+    ^ abort
 
     "Created: / 27-07-2006 / 10:20:10 / fm"
+    "Modified: / 10-10-2006 / 18:13:50 / cg"
 ! !
 
 !PrinterContext methodsFor:'accessing'!
 
 getCharHeight
-        "Private - answer the height of the font selected in the receiver's
-        device context."
+    "Private - answer the height of the font selected in the receiver's
+     device context."
+    
+    |textMetrics|
 
-    | textMetrics |
     textMetrics := Win32OperatingSystem::TextMetricsStructure new.
-    ( OperatingSystem 
-        getTextMetrics: gcId "deviceContext" 
-        lpMetrics: textMetrics "asParameter" )
-            ifFalse: [ ^self error ].
-    ^textMetrics tmHeight + textMetrics tmExternalLeading
+    (OperatingSystem getTextMetrics:gcId lpMetrics:textMetrics) ifFalse:[ ^ self error ].
+    ^ textMetrics tmHeight + textMetrics tmExternalLeading
 
     "Created: / 02-08-2006 / 17:47:20 / fm"
     "Modified: / 03-08-2006 / 10:09:01 / fm"
+    "Modified: / 10-10-2006 / 18:15:17 / cg"
 !
 
-name                                   
-        "Answer the receiver's name from the current printerInfo."
-
-    ^self printerInfo printerName
+name
+    "Answer the receiver's name from the current printerInfo."
+    
+    ^ self printerInfo printerName
 
     "Modified: / 02-08-2006 / 16:55:03 / fm"
+    "Modified: / 10-10-2006 / 18:15:33 / cg"
 !
 
-name: aName
-        "Set the receiver's printer name to aName."
+name:aName 
+    "Set the receiver's printer name to aName."
+    
+    self printerInfo:(self class getPrinterInformation:aName)
 
-    self printerInfo: (self class getPrinterInformation: aName)
-
-    "Created: / 27-07-2006 / 10:33:04 / fm"
-    "Modified: / 02-08-2006 / 16:54:46 / fm"
+    "Modified: / 10-10-2006 / 18:15:36 / cg"
 !
 
 numberOfColorBitsPerPixel
-
     ^ OperatingSystem getDeviceCaps:gcId index:12 "Bitspixel"
 
     "Created: / 03-08-2006 / 09:58:18 / fm"
+    "Modified: / 10-10-2006 / 18:15:40 / cg"
 !
 
 pixelsPerInchOfScreenHeight
@@ -464,77 +466,65 @@
 !
 
 printerInfo
-        "Answer the receiver's name from the current printerInfo."
-
-    ^printerInfo
+    "Answer the receiver's name from the current printerInfo."
+    
+    ^ printerInfo
 
     "Created: / 02-08-2006 / 16:55:17 / fm"
+    "Modified: / 10-10-2006 / 18:18:34 / cg"
 !
 
-printerInfo: aPrinterInfo
-        "Sets the receiver's printerInfo."
-
+printerInfo:aPrinterInfo 
+    "Sets the receiver's printerInfo."
+    
     printerInfo := aPrinterInfo
 
     "Created: / 02-08-2006 / 16:55:34 / fm"
     "Modified: / 03-08-2006 / 13:11:19 / fm"
+    "Modified: / 10-10-2006 / 18:18:37 / cg"
 !
 
-printerInfoWithName: aName
-        "Set the receiver's printer name to aName."
-
-    self printerInfo: (self class getPrinterInformation: aName).
-    ^self
+printerInfoWithName:aName 
+    "Set the receiver's printer name to aName."
+    
+    self printerInfo:(self class getPrinterInformation:aName).
+    ^ self
 
     "Created: / 02-08-2006 / 16:55:52 / fm"
+    "Modified: / 10-10-2006 / 18:18:41 / cg"
 !
 
 printerUserFriendlyName
-        "Answer the receiver's name from the current printerInfo."
-
-    ^self printerInfo userFriendlyName
+    "Answer the receiver's name from the current printerInfo."
+    
+    ^ self printerInfo userFriendlyName
 
     "Created: / 03-08-2006 / 12:55:57 / fm"
+    "Modified: / 10-10-2006 / 18:18:55 / cg"
 ! !
 
 !PrinterContext methodsFor:'initialization & release'!
 
 buildPrinter
-        "Private - create all the operating system resources needed."
-    self 
-        createDC;       
+    "Private - create all the operating system resources needed."
+    
+    self
+        createDC;
         initExtent
 
     "Created: / 27-07-2006 / 10:20:36 / fm"
     "Modified: / 01-08-2006 / 15:57:49 / fm"
+    "Modified: / 10-10-2006 / 18:14:04 / cg"
 !
 
 createDC
-        "Private - Create a device context for the receiver"
-
- gcId := printerInfo createDC
-
-"/    | printerInfo driverNm mediumNm deviceNm hPrinter driverData|
-"/    printerInfo := self class getPrinterInformation: self name.
-"/     driverNm := printerInfo driverName.
-"/     mediumNm := printerInfo medium.
-"/     deviceNm := printerInfo printerName.
-"/
-"/     hPrinter := OperatingSystem openPrinter:deviceNm.
-"/     driverData := OperatingSystem getDocumentProperties:nil hPrinter:hPrinter pDeviceName:deviceNm.
-"/     Win32OperatingSystem primClosePrinter:hPrinter.
-"/
-"/     "deviceContext" gcId := OperatingSystem createPrinterDC:driverNm device:deviceNm output:mediumNm initData:driverData.
-
-"/    ( deviceContext := GDILibrary
-"/        createDC: driverName asParameter
-"/        deviceName: deviceName asParameter
-"/        output: printerPort asParameter
-"/        initData: nil ) = 0
-"/            ifTrue: [ ^self osError ].
+    "Private - Create a device context for the receiver"
+    
+    gcId := printerInfo createDC
 
     "Created: / 27-07-2006 / 10:21:05 / fm"
     "Modified: / 02-08-2006 / 17:30:47 / fm"
+    "Modified: / 10-10-2006 / 18:14:28 / cg"
 !
 
 initExtent
@@ -548,9 +538,9 @@
 !
 
 printerHeightArea
-    ^ (OperatingSystem getDeviceCaps:gcId index:10 "Vertres")
+    ^ (OperatingSystem getDeviceCaps:gcId index:10)
 
-    "Created: / 01-08-2006 / 16:14:49 / fm"
+    "Modified: / 10-10-2006 / 18:18:31 / cg"
 !
 
 printerWidthArea
@@ -561,43 +551,58 @@
 
 !PrinterContext methodsFor:'printing'!
 
-print: aString
-    font: aFont
-    title: aTitle  
-    wordWrap: wordWrapBoolean
-    marginsRect: aMarginsRect
-        "Answer the receiver.  Output the receiver string to
-        the printer using aFont.  A Print abort dialog box will be opened
-        with aTitle.  If collateBoolean is true, collate output, otherwise
-        do not.  Print copiesInteger copies of the specified string.  If
-        wordWrapBoolean is true, word wrap the lines, otherwise do not.
-        Left, top, right & bottom margins are specified in inches in
-        aMarginsRect."
-    | lines linesPerPage totalPage marginsRect firstPage charHeight abortDialog |
+print:aString font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect 
+    "Answer the receiver.  Output the receiver string to
+     the printer using aFont.  A Print abort dialog box will be opened
+     with aTitle.  If collateBoolean is true, collate output, otherwise
+     do not.  Print copiesInteger copies of the specified string.  If
+     wordWrapBoolean is true, word wrap the lines, otherwise do not.
+     Left, top, right & bottom margins are specified in inches in
+     aMarginsRect."
+    
+    |lines linesPerPage totalPage marginsRect firstPage charHeight abortDialog|
 
-    jobid isNil
-        ifTrue: [ self startPrintJob: aTitle ].
-    abortDialog := PrintAbortDialog new open: aTitle printer: self.
-    self font: aFont.
-    marginsRect := self marginsRectangleFor: aMarginsRect.
-    lines := self asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean.
-    charHeight := self getCharHeight. 
-    linesPerPage := marginsRect bottom - marginsRect top // charHeight.
-    totalPage := lines size + linesPerPage - 1 // linesPerPage.
+    jobid isNil ifTrue:[
+        self startPrintJob:aTitle
+    ].
+    abortDialog := PrintAbortDialog new open:aTitle printer:self.
+    self font:aFont.
+    marginsRect := self marginsRectangleFor:aMarginsRect.
+    lines := self 
+                asArrayOfStringLines:aString
+                in:marginsRect
+                wordWrap:wordWrapBoolean.
+    charHeight := self getCharHeight.
+    linesPerPage := (marginsRect bottom - marginsRect top) // charHeight.
+    totalPage := (lines size + linesPerPage - 1) // linesPerPage.
     firstPage := true.
-
+    
 "/    collateBoolean
 "/        ifTrue: [
 "/            copiesInteger timesRepeat: [
-    1 to: totalPage do: [ :page |
-        abort ifTrue: [^self].
-        firstPage ifFalse: [ self formFeed ].
-        abortDialog updatePrintingPageInfo: 'Page ', page printString, '/', totalPage printString.
+    
+    1 to:totalPage do:[:page | 
+        abort ifTrue:[ ^ self ].
+        firstPage ifFalse:[
+            self formFeed
+        ].
+        abortDialog 
+            updatePrintingPageInfo:(self class classResources
+                                    string:'Page %1/%2'
+                                    with:page printString
+                                    with:totalPage printString).
+        
 "/      self device font: printerFont.
-        self font: aFont.
-        self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage.
-        firstPage := false ]. 
-
+        
+        self font:aFont.
+        self 
+            printPage:page
+            in:marginsRect
+            lines:lines
+            linesPerPage:linesPerPage.
+        firstPage := false
+    ].
+    
 "/            ] 
 "/        ] ifFalse: [
 "/            1 to: totalPage do: [ :page |
@@ -610,205 +615,208 @@
 "/                 ] 
 "/            ]   
 "/        ].
+    
+    jobid notNil ifTrue:[
+        self endPrintJob.
+        abortDialog close.
+    ].
 
-    jobid notNil
-        ifTrue: [ self endPrintJob.
-                  abortDialog close.].
-
-"/    abort ifFalse: [ abortDialog close ]
+    "/    abort ifFalse: [ abortDialog close ]
 
     "Created: / 03-08-2006 / 16:13:33 / fm"
     "Modified: / 04-08-2006 / 13:40:02 / fm"
+    "Modified: / 10-10-2006 / 18:16:54 / cg"
 !
 
-print: aString
-    pageHeader: aString2
-    font: aFont
-    title: aTitle 
-    wordWrap: wordWrapBoolean
-    marginsRect: aMarginsRect
-
-        "Private - Answer the receiver.  Output the receiver string to
-        the printer using aFont.  A Print abort dialog box will be opened
-        with aTitle.  If collateBoolean is true, collate output, otherwise
-        do not.  Print copiesInteger copies of the specified string.  If
-        wordWrapBoolean is true, word wrap the lines, otherwise do not.
-        Left, top, right & bottom margins are specified in inches in
-        aMarginsRect.
-        Mg: Erweitert um pageHeader"
-       "Changed by K3/EES5-Mg, 08.01.96"
+print:aString pageHeader:aString2 font:aFont title:aTitle wordWrap:wordWrapBoolean marginsRect:aMarginsRect 
+    "Private - Answer the receiver.  Output the receiver string to
+     the printer using aFont.  A Print abort dialog box will be opened
+     with aTitle.  If collateBoolean is true, collate output, otherwise
+     do not.  Print copiesInteger copies of the specified string.  If
+     wordWrapBoolean is true, word wrap the lines, otherwise do not.
+     Left, top, right & bottom margins are specified in inches in
+     aMarginsRect."
+    
+    |lines linesPerPage totalPage marginsRect firstPage charHeight printerFont headerLines|
 
-    | lines linesPerPage totalPage marginsRect firstPage charHeight  printerFont headerLines|
-
-    self font: aFont.
+    self font:aFont.
     charHeight := self getCharHeight.
-    marginsRect := self marginsRectangleFor: aMarginsRect.
-    lines := self asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean.
-    headerLines := self asArrayOfStringLines: aString2 in: marginsRect wordWrap: wordWrapBoolean.
-    linesPerPage := marginsRect bottom - marginsRect top // charHeight.
-
-    linesPerPage > headerLines size
-        ifFalse:
-          [Dialog information: 'Der Dokumentenkopf ist zu groß; wird ignoriert!!'.
-           headerLines := #().
-          ]
-        ifTrue: [linesPerPage := linesPerPage - headerLines size].
-    totalPage := lines size + linesPerPage - 1 // linesPerPage.
+    marginsRect := self marginsRectangleFor:aMarginsRect.
+    lines := self 
+                asArrayOfStringLines:aString
+                in:marginsRect
+                wordWrap:wordWrapBoolean.
+    headerLines := self 
+                asArrayOfStringLines:aString2
+                in:marginsRect
+                wordWrap:wordWrapBoolean.
+    linesPerPage := (marginsRect bottom - marginsRect top) // charHeight.
+    linesPerPage > headerLines size ifFalse:[
+        Dialog information:(self class classResources 
+                                string:'The header is too large - ignored!!').
+        headerLines := #().
+    ] ifTrue:[
+        linesPerPage := linesPerPage - headerLines size
+    ].
+    totalPage := (lines size + linesPerPage - 1) // linesPerPage.
     firstPage := true.
-
+    
 "/    collateBoolean
 "/        ifTrue: [
 "/            copiesInteger timesRepeat: [
-
-     1 to: totalPage do: [ :page |
-                    abort ifTrue: [ ^self].
-                    firstPage ifFalse: [ self formFeed ].
-                    self font: printerFont.
-                    self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
-                    firstPage := false 
-     ] 
+    
+    1 to:totalPage do:[:page | 
+        abort ifTrue:[ ^ self ].
+        firstPage ifFalse:[
+            self formFeed
+        ].
+        self font:printerFont.
+        self 
+            printPage:page
+            in:marginsRect
+            lines:lines
+            headerLines:headerLines
+            linesPerPage:linesPerPage.
+        firstPage := false
+    ]
 
-"/            ] 
-"/        ] ifFalse: [
-"/            1 to: totalPage do: [ :page |
-"/                copiesInteger timesRepeat: [
-"/                    abort ifTrue: [ ^self endPrintJob ].
-"/                    firstPage ifFalse: [ self formFeed ].
-"/                    self device font: printerFont.
-"/                    self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
-"/                    firstPage := false 
-"/                ] 
-"/            ] 
-"/        ].
+    "/            ] 
+    "/        ] ifFalse: [
+    "/            1 to: totalPage do: [ :page |
+    "/                copiesInteger timesRepeat: [
+    "/                    abort ifTrue: [ ^self endPrintJob ].
+    "/                    firstPage ifFalse: [ self formFeed ].
+    "/                    self device font: printerFont.
+    "/                    self printPage: page in: marginsRect lines: lines headerLines: headerLines linesPerPage: linesPerPage.
+    "/                    firstPage := false 
+    "/                ] 
+    "/            ] 
+    "/        ].
 
     "Created: / 03-08-2006 / 16:14:10 / fm"
+    "Modified: / 10-10-2006 / 18:18:03 / cg"
 ! !
 
 !PrinterContext methodsFor:'printing process'!
 
 endPage
-        "Informs device that we are finished writing to a page."
-    ( OperatingSystem endPage: gcId ) > 0
-        ifFalse: [ self error ]
+    "Informs device that we are finished writing to a page."
+    
+    (OperatingSystem endPage:gcId) > 0 ifFalse:[
+        self error
+    ]
 
     "Created: / 27-07-2006 / 18:20:48 / fm"
     "Modified: / 01-08-2006 / 16:01:34 / fm"
+    "Modified: / 10-10-2006 / 18:14:44 / cg"
 !
 
 endPrintJob
+    "End the print job.  Everything drawn between startPrintJob
+     and endPrintJob will become one entry in the print queue."
+    
+    |result|
 
-        "End the print job.  Everything drawn between startPrintJob
-         and endPrintJob will become one entry in the print queue."
-       "Changed by K3EES5-Mg, 19.09.97"
-
-    | result |
     self endPage.
-    result := OperatingSystem endDoc: gcId "deviceContext".
-    "graphicsTool" device close "deleteDC".
-    "deviceContext" gcId := nil.
+    result := OperatingSystem endDoc:gcId.
+    device close.
+    gcId := nil.
     jobid := nil.
-    result  >= 0        "> geändert in >=: Mg 22.6.95"
-        ifFalse: [ ^self error "osError" ]
+    result >= 0 ifFalse:[
+        ^ self error
+    ]
 
     "Created: / 27-07-2006 / 18:21:04 / fm"
     "Modified: / 01-08-2006 / 16:01:38 / fm"
+    "Modified: / 10-10-2006 / 18:15:02 / cg"
 !
 
 formFeed
-        "Send a form feed to the printer."
+    "Send a form feed to the printer."
+    
     self
         endPage;
         startPage
 
     "Created: / 27-07-2006 / 18:25:40 / fm"
+    "Modified: / 10-10-2006 / 18:15:07 / cg"
 !
 
 startPage
-        "Starts a page."
-    ( OperatingSystem startPage: gcId ) > 0
-        ifFalse: [ ^self error "osError" ].
+    "Starts a page."
+    
+    (OperatingSystem startPage:gcId) > 0 ifFalse:[
+        ^ self error
+    ].
 
     "Created: / 27-07-2006 / 18:25:55 / fm"
     "Modified: / 28-07-2006 / 18:19:04 / fm"
+    "Modified: / 10-10-2006 / 18:19:02 / cg"
 !
 
 startPrintJob
-        "Start a print job.  Everything drawn between startPrintJob
-         and endPrintJob will become one entry in the print queue."
-    self startPrintJob: nil
+    "Start a print job.  Everything drawn between startPrintJob
+     and endPrintJob will become one entry in the print queue."
+    
+    self startPrintJob:nil
 
     "Created: / 27-07-2006 / 18:18:52 / fm"
+    "Modified: / 10-10-2006 / 18:19:05 / cg"
 !
 
-startPrintJob: aString
-
-        "Start a print job, using aString as the job title; everything
-         drawn between startPrintJob and endPrintJob will become
-         one entry in the print queue.
-
-         Mg: Bei SpUserabort (bei Drucken in Datei) wird abort auf true gesetzt
-         und SpUserabort zurückgegeben.
-        "
-       "Changed by K3/EES5-Mg, 21.07.97"
-       "Changed by K3EES5-Mg, 19.09.97"
-
-    ^self startPrintJob: aString fileName: nil
+startPrintJob:aString 
+    "Start a print job, using aString as the job title; everything
+     drawn between startPrintJob and endPrintJob will become
+     one entry in the print queue."
+    
+    ^ self startPrintJob:aString fileName:nil
 
     "Created: / 27-07-2006 / 18:19:09 / fm"
+    "Modified: / 10-10-2006 / 18:19:12 / cg"
 !
 
-startPrintJob: aString fileName: aFileName
+startPrintJob:aString fileName:aFileName 
+    "Start a print job, using aString as the job title; everything
+     drawn between startPrintJob and endPrintJob will become
+     one entry in the print queue."
+    
+    |docInfoStruct nameAddress title fileNameAddress|
 
-        "Start a print job, using aString as the job title; everything
-         drawn between startPrintJob and endPrintJob will become
-         one entry in the print queue."
-       "Changed by K3/EES5-Mg, 21.07.97"
-       "Changed by K3EES5-Mg, 19.09.97"
-       "Changed by GS/EEZ3-Vr, 15.03.02"
-
-    | docInfoStruct nameAddress title fileNameAddress |
-
-    gcId "deviceContext" isNil ifTrue: [ self buildPrinter ].
+    gcId isNil ifTrue:[
+        self buildPrinter
+    ].
     abort := false.
-    "self setAbortProc."
-    title := aString isNil ifTrue: [ 'Smalltalk/X' "WindowLabelPrefix" ] ifFalse: [ aString ].
-
+    title := aString ? 'Smalltalk/X'.
     nameAddress := title asExternalBytes unprotectFromGC.
-"/    nameAddress := ExternalAddress copyToNonSmalltalkMemory: title.
-    aFileName isNil ifFalse: [fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC].
-"/    aFileName isNil ifFalse: [fileNameAddress := ExternalAddress copyToNonSmalltalkMemory: aFileName].
-
-    docInfoStruct := Win32OperatingSystem::DocInfoStructure new "some value". 
-    docInfoStruct cbSize: docInfoStruct sizeInBytes;
-                  lpszDocName: nameAddress address.
-"/    ( docInfoStruct := SelfDefinedStructure named: 'DOCINFO' )
-"/        cbSize: docInfoStruct sizeInBytes;
-"/        lpszDocName: nameAddress "asParameter".
-
-    fileNameAddress isNil ifFalse:[docInfoStruct lpszOutput: fileNameAddress address"asParameter"].
-
-    jobid := OperatingSystem startDoc: gcId "deviceContext"  
-                             docInfo: docInfoStruct "asParameter".
-"/    nameAddress free.
-"/    fileNameAddress isNil ifFalse: [fileNameAddress free].
-
-    jobid  > 0 
-        ifFalse: [jobid = -1 
-                    ifTrue: [abort := true. ^nil]. 
-                  ^self error "osError" ].
+    aFileName isNil ifFalse:[
+        fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
+    ].
+    docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
+    docInfoStruct
+        cbSize:docInfoStruct sizeInBytes;
+        lpszDocName:nameAddress address.
+    fileNameAddress isNil ifFalse:[
+        docInfoStruct lpszOutput:fileNameAddress address
+    ].
+    jobid := OperatingSystem startDoc:gcId docInfo:docInfoStruct.
+    jobid > 0 ifFalse:[
+        jobid = -1 ifTrue:[
+            abort := true.
+            ^ nil
+        ].
+        ^ self error
+    ].
     self startPage
 
     "Created: / 27-07-2006 / 18:19:31 / fm"
     "Modified: / 03-08-2006 / 15:11:19 / fm"
+    "Modified: / 10-10-2006 / 18:20:01 / cg"
 ! !
 
 !PrinterContext methodsFor:'queries'!
 
 supportsColor
 
-       "Changed by K3/EES5-Vo, 11.03.98"
-       "Changed by GS-EC/EES3-Vo, 06.10.05"
-
 "/    | retVal info |
 "/
 "/    info := (self class getPrinterInformation: self name) asUppercase.
@@ -824,115 +832,125 @@
 "/
 "/    ^retVal
 
+    ^ false.
+
     "Created: / 03-08-2006 / 09:55:26 / fm"
     "Modified: / 04-08-2006 / 13:20:40 / fm"
+    "Modified: / 10-10-2006 / 18:21:07 / cg"
 !
 
 supportsGraphics
-
-       "Private & DEFAULT!!."
-       "Changed by K3/EES5-Mg, 26.01.96"
-
     ^(OperatingSystem getDeviceCaps: gcId asParameter index: 2 "Technology") ~= 4
 
     "Created: / 03-08-2006 / 10:07:43 / fm"
+    "Modified: / 10-10-2006 / 18:21:14 / cg"
 ! !
 
 !PrinterContext methodsFor:'text printing'!
 
-asArrayOfStringLines: aString in: aRectangle wordWrap: wordWrapBoolean
-        "Private - convert aString into an array of lines; if wordWrapBoolean
-        is true, also perform word wrapping on the lines, within aRectangle."
-    | line lines stream x0 x1 partialLine leftMargin rightMargin partialLineWidth index |
-    stream := ReadStream on: aString.
+asArrayOfStringLines:aString in:aRectangle wordWrap:wordWrapBoolean 
+    "Private - convert aString into an array of lines; if wordWrapBoolean
+     is true, also perform word wrapping on the lines, within aRectangle."
+    
+    |line lines stream x0 x1 partialLine leftMargin rightMargin partialLineWidth index|
+
+    stream := ReadStream on:aString.
     lines := OrderedCollection new.
-    wordWrapBoolean ifTrue: [
+    wordWrapBoolean ifTrue:[
         leftMargin := aRectangle left.
-        rightMargin := aRectangle right ].
-    [ stream atEnd ] whileFalse: [
+        rightMargin := aRectangle right
+    ].
+    [ stream atEnd ] whileFalse:[
         line := stream nextLine.
-        wordWrapBoolean
-            ifFalse: [ lines add: line ]
-            ifTrue: [
-                x0 := x1 := 1.
-                1 to: line size do: [ :i | 
-                     ( ( line at: i ) = Character space "32"  and: [ (partialLine := line copyFrom: x0 to: i) trimBlanks notEmpty ] ) 
-                        ifTrue: [
-                            partialLineWidth := self stringWidthOf: partialLine.
-                            ( leftMargin + partialLineWidth ) > rightMargin
-                                ifTrue: [
-                                    partialLine := line copyFrom: x0 to: x1.
-                                    lines add: partialLine.
-                                    x0 := x1 + 1 ]
-                                ifFalse: [ x1 := i ] ].
-                            index := i 
+        wordWrapBoolean ifFalse:[
+            lines add:line
+        ] ifTrue:[
+            x0 := x1 := 1.
+            1 to:line size do:[:i | 
+                ((line at:i) = Character space "32" 
+                    and:[ (partialLine := line copyFrom:x0 to:i) trimBlanks notEmpty ]) 
+                        ifTrue:[
+                            partialLineWidth := self stringWidthOf:partialLine.
+                            (leftMargin + partialLineWidth) > rightMargin ifTrue:[
+                                partialLine := line copyFrom:x0 to:x1.
+                                lines add:partialLine.
+                                x0 := x1 + 1
+                            ] ifFalse:[ x1 := i ]
                         ].
-                line isEmpty
-                    ifTrue: [ lines add: line ]
-                    ifFalse: [
-                        partialLine := line copyFrom: x0 to: index.
-                        partialLineWidth := self stringWidthOf: partialLine.
-                        ( leftMargin + partialLineWidth ) > rightMargin 
-                                ifTrue: [
-                                    partialLine := line copyFrom: x0 to: x1.
-                                    lines add: partialLine.
-                                    partialLine := line copyFrom: x1 + 1 to: index 
-                                ].
-                        lines add: partialLine 
-                    ] 
-            ] 
+                index := i
+            ].
+            line isEmpty ifTrue:[
+                lines add:line
+            ] ifFalse:[
+                partialLine := line copyFrom:x0 to:index.
+                partialLineWidth := self stringWidthOf:partialLine.
+                (leftMargin + partialLineWidth) > rightMargin ifTrue:[
+                    partialLine := line copyFrom:x0 to:x1.
+                    lines add:partialLine.
+                    partialLine := line copyFrom:x1 + 1 to:index
+                ].
+                lines add:partialLine
+            ]
+        ]
     ].
-    ^lines asArray
+    ^ lines asArray
 
     "Created: / 02-08-2006 / 17:56:51 / fm"
     "Modified: / 04-08-2006 / 13:39:50 / fm"
+    "Modified: / 10-10-2006 / 18:14:00 / cg"
 !
 
-displayStringLines: anIndexedCollection from: startIndex to: endIndex in: aRectangle
-        "Private - display Strings in anIndexedCollection starting at startIndex and
-        ending at endIndex, clipped within the bounds of aRectangle."
-    | charHeight ta region ascent|
+displayStringLines:anIndexedCollection from:startIndex to:endIndex in:aRectangle 
+    "Private - display Strings in anIndexedCollection starting at startIndex and
+     ending at endIndex, clipped within the bounds of aRectangle."
+    
+    |charHeight ta region ascent|
+
     charHeight := self getCharHeight.
-    ascent := self font ascentOn: self device.
-    startIndex to: endIndex do: [ :i |
+    ascent := self font ascentOn:self device.
+    startIndex to:endIndex do:[:i | 
         |lineToPrint|
-        lineToPrint := ( anIndexedCollection at: i ).
-        self device
-            displayString: lineToPrint 
-            from:1 
-            to: lineToPrint size 
-            x: aRectangle left 
-            y: (aRectangle top + ( i - startIndex * charHeight ) )
-            in:nil 
-            with: gcId 
-            opaque:false 
-            fontAscent: ascent.
+
+        lineToPrint := (anIndexedCollection at:i).
+        self device 
+            displayString:lineToPrint
+            from:1
+            to:lineToPrint size
+            x:aRectangle left
+            y:(aRectangle top + ((i - startIndex) * charHeight))
+            in:nil
+            with:gcId
+            opaque:false
+            fontAscent:ascent.
     ].
 
-"/    region := self setClipRect: aRectangle.
-"/    ta := self getTextAlign.
-"/    self setTextAlign: TaTop.
-"/    startIndex to: endIndex do: [ :i |
-"/        self
-"/            displayText: ( anIndexedCollection at: i )
-"/            at: aRectangle left @ ( aRectangle top + ( i - startIndex * charHeight ) ) ].
-"/    self setTextAlign: ta.
-"/    self destroyRegion: region
+    "/    region := self setClipRect: aRectangle.
+    "/    ta := self getTextAlign.
+    "/    self setTextAlign: TaTop.
+    "/    startIndex to: endIndex do: [ :i |
+    "/        self
+    "/            displayText: ( anIndexedCollection at: i )
+    "/            at: aRectangle left @ ( aRectangle top + ( i - startIndex * charHeight ) ) ].
+    "/    self setTextAlign: ta.
+    "/    self destroyRegion: region
 
     "Created: / 03-08-2006 / 11:37:52 / fm"
     "Modified: / 03-08-2006 / 12:38:43 / fm"
+    "Modified: / 10-10-2006 / 18:14:36 / cg"
 !
 
-displayStringLines: anIndexedCollection in: aRectangle
-        "Private - display anIndexedCollection of Strings clipped within
-        the bounds of aRectangle."
-    self
-        displayStringLines: anIndexedCollection
-        from: 1
-        to: anIndexedCollection size
-        in: aRectangle
+displayStringLines:anIndexedCollection in:aRectangle 
+    "Private - display anIndexedCollection of Strings clipped within
+     the bounds of aRectangle."
+    
+    self 
+        displayStringLines:anIndexedCollection
+        from:1
+        to:anIndexedCollection size
+        in:aRectangle
 
     "Created: / 03-08-2006 / 16:03:07 / fm"
+    "Modified: / 10-10-2006 / 18:14:40 / cg"
 !
 
 marginsRectangleFor:aRectangle 
@@ -941,6 +959,7 @@
      in device units (pixels)."
     
     |left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle|
+
     pixelsPerInchX := self pixelsPerInchOfScreenWidth.
     pixelsPerInchY := self pixelsPerInchOfScreenHeight.
     aRectangle isNil ifTrue:[
@@ -957,98 +976,110 @@
         right := (aRectangle right * pixelsPerInchX) asInteger.
         bottom := (aRectangle bottom * pixelsPerInchY) asInteger
     ].
-    rectangle := left @ top extent: right @ bottom.
+    rectangle := left @ top extent:right @ bottom.
     ^ rectangle
 
     "Created: / 27-07-2006 / 18:22:57 / fm"
     "Modified: / 04-08-2006 / 13:39:45 / fm"
+    "Modified: / 10-10-2006 / 18:15:26 / cg"
 !
 
-printPage: pageIndex in: aRectangle lines: lines headerLines: headerLines linesPerPage: linesPerPage
+printPage:pageIndex in:aRectangle lines:lines headerLines:headerLines linesPerPage:linesPerPage 
+    "Private - print page # pageIndex from lines, assuming
+     the given number of linesPerPage."
+    
+    |firstLine lastLine l indexString p cHeight rect hLines|
 
-        "Private - print page # pageIndex from lines, assuming
-        the given number of linesPerPage."
-       "Changed by K3/EES5-Mg, 30.07.97"
-
-    | firstLine lastLine l indexString p cHeight rect hLines|
-    firstLine := ( pageIndex - 1 ) * linesPerPage + 1.
-    lastLine := ( firstLine + linesPerPage - 1 ) min: lines size.
-
+    firstLine := (pageIndex - 1) * linesPerPage + 1.
+    lastLine := (firstLine + linesPerPage - 1) min:lines size.
     rect := aRectangle deepCopy.
     hLines := headerLines deepCopy.
-    headerLines size > 0 ifTrue:
-      [l := hLines first.
-       (p := l indexOfString: '#P') = 0 ifFalse:
-          [indexString := pageIndex printString,' '.
-           "l replaceFrom: p to: p + indexString size - 1 with: indexString startingAt: 1."
-           l := (l copyFrom: 1 to: p - 1),indexString,(l copyFrom: p + 2 to: l size).
-           hLines at: 1 put: l.
-          ].
-       cHeight := self getCharHeight.
-       rect top: rect top + (hLines size * cHeight).
-      ].
-
-    self displayStringLines: hLines in: aRectangle.
-    self displayStringLines: lines from: firstLine to: lastLine in: rect.
+    headerLines size > 0 ifTrue:[
+        l := hLines first.
+        (p := l indexOfString:'#P') = 0 ifFalse:[
+            indexString := pageIndex printString , ' '.
+            l := (l copyFrom:1 to:p - 1) , indexString , (l copyFrom:p + 2 to:l size).
+            hLines at:1 put:l.
+        ].
+        cHeight := self getCharHeight.
+        rect top:rect top + (hLines size * cHeight).
+    ].
+    self displayStringLines:hLines in:aRectangle.
+    self 
+        displayStringLines:lines
+        from:firstLine
+        to:lastLine
+        in:rect.
 
     "Created: / 27-07-2006 / 18:28:00 / fm"
     "Modified: / 03-08-2006 / 16:03:15 / fm"
+    "Modified: / 10-10-2006 / 18:18:15 / cg"
 !
 
-printPage: pageIndex in: aRectangle lines: lines linesPerPage: linesPerPage
-        "Private - print page # pageIndex from lines, assuming
-        the given number of linesPerPage."
-    | firstLine lastLine |
-    firstLine := ( pageIndex - 1 ) * linesPerPage + 1.
-    lastLine := ( firstLine + linesPerPage - 1 ) min: lines size.
-    self displayStringLines: lines from: firstLine to: lastLine in: aRectangle
+printPage:pageIndex in:aRectangle lines:lines linesPerPage:linesPerPage 
+    "Private - print page # pageIndex from lines, assuming
+     the given number of linesPerPage."
+    
+    |firstLine lastLine|
+
+    firstLine := (pageIndex - 1) * linesPerPage + 1.
+    lastLine := (firstLine + linesPerPage - 1) min:lines size.
+    self 
+        displayStringLines:lines
+        from:firstLine
+        to:lastLine
+        in:aRectangle
 
     "Created: / 27-07-2006 / 18:24:59 / fm"
     "Modified: / 03-08-2006 / 12:47:24 / fm"
+    "Modified: / 10-10-2006 / 18:18:22 / cg"
 !
 
-stringWidthOf: aString
-        "Return the width of aString
-         when written using the current font."
-    ^self
-        stringWidthOf: aString
-        at: aString size.
+stringWidthOf:aString 
+    "Return the width of aString
+     when written using the current font."
+    
+    ^ self stringWidthOf:aString at:aString size.
 
     "Modified: / 03-08-2006 / 10:18:23 / fm"
+    "Modified: / 10-10-2006 / 18:20:08 / cg"
 !
 
-stringWidthOf: aString at: index
-        "Return the width of aString up to index
-         when written using the current font; expand tabs out
-         to 4 spaces for calculations"
-    | answer str size spaceWidth|
-    index <= 0 ifTrue: [^0].
-    str :=  index >= aString size
-        ifTrue:[aString]
-        ifFalse:[aString copyFrom: 1 to: index].
-    true "self font isNil"
-        ifTrue: [  "if font not set yet, calculate based on default font"
-"/            extString := str asExternalString.
-            size := Win32OperatingSystem::WinPointStructure new.
-            ( OperatingSystem
-                getTextExtentPoint: gcId "self handle"
-                string: str 
-                size: size)                  
-                    ifFalse: [ ^self error ].
-            answer := size x.
-#TODO.
-        ] ifFalse: [ answer := self font widthOf: str on: self device "self handle" ].
-    index > aString size ifTrue: [
-        spaceWidth:=  self font widthOf: Character space on: self device. 
-        answer := answer + (index - aString size * spaceWidth)].
-    ^answer.
+stringWidthOf:aString at:index 
+    "Return the width of aString up to index
+     when written using the current font; expand tabs out
+     to 4 spaces for calculations"
+    
+    |answer str size spaceWidth|
+
+    index <= 0 ifTrue:[ ^ 0 ].
+    str := index >= aString size ifTrue:[ aString ] ifFalse:[ aString copyFrom:1 to:index ].
+    true "self font isNil" ifTrue:[
+        "if font not set yet, calculate based on default font"
+        "/            extString := str asExternalString.
+        size := Win32OperatingSystem::WinPointStructure new.
+        (OperatingSystem 
+            getTextExtentPoint:gcId
+            string:str
+            size:size) ifFalse:[ ^ self error ].
+        answer := size x.
+        #TODO.
+    ] ifFalse:[
+        answer := self font widthOf:str on:self device
+    ].
+    index > aString size ifTrue:[
+        spaceWidth := self font widthOf:Character space on:self device.
+        answer := answer + ((index - aString size) * spaceWidth)
+    ].
+    ^ answer.
 
     "Created: / 03-08-2006 / 10:27:20 / fm"
     "Modified: / 04-08-2006 / 12:27:26 / fm"
+    "Modified: / 10-10-2006 / 18:20:43 / cg"
 ! !
 
 !PrinterContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.5 2006-10-10 15:55:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.6 2006-10-10 16:22:07 cg Exp $'
 ! !