*** empty log message ***
authorfm
Wed, 16 Aug 2006 13:00:12 +0200
changeset 2147 10c893aa772a
parent 2146 61291b6cc0f7
child 2148 cfff8a04d2e6
*** empty log message ***
PrinterContext.st
--- a/PrinterContext.st	Wed Aug 09 14:46:19 2006 +0200
+++ b/PrinterContext.st	Wed Aug 16 13:00:12 2006 +0200
@@ -302,6 +302,37 @@
     "Created: / 07-08-2006 / 11:40:48 / fm"
 !
 
+printStrings: stringAndPositionsArray
+
+        "Opens a print dialog and prints the given strings"
+
+    | printerInfo printer |
+    printerInfo := PrintingDialog getPrinterInfo.
+    printerInfo isNil ifTrue:[^self].
+
+    printer := self fromPrinterInfo: printerInfo.
+    [ 
+    printer startPrintJob: 'Strings with Position'.
+    printer foreground:Color black background:Color white.
+    stringAndPositionsArray
+        do:[:pairOfPointsAndPosition |                 
+             printer displayString:(pairOfPointsAndPosition at: 1) 
+                        x:(pairOfPointsAndPosition at: 2) x
+                        y:(pairOfPointsAndPosition at: 2) y
+        ].
+    printer endPrintJob.
+    ] forkAt: 3
+
+"
+    PrinterContext printStrings:  
+        (Array with: (Array with:'Testing printing with standart method' with:10@10)
+               with: (Array with:'Another test string to print' with:80@200))
+"
+
+    "Created: / 07-08-2006 / 12:09:48 / fm"
+    "Modified: / 07-08-2006 / 14:11:17 / fm"
+!
+
 printingTestString
 
 ^'GetTextExtentPoint Note  
@@ -467,55 +498,6 @@
     "Created: / 03-08-2006 / 12:55:57 / fm"
 ! !
 
-!PrinterContext methodsFor:'displaying lines'!
-
-displayLines: 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 |
-        |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.
-    ].
-
-"/    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"
-!
-
-displayLines: anIndexedCollection in: aRectangle
-        "Private - display anIndexedCollection of Strings clipped within
-        the bounds of aRectangle."
-    self
-        displayLines: anIndexedCollection
-        from: 1
-        to: anIndexedCollection size
-        in: aRectangle
-
-    "Created: / 03-08-2006 / 16:03:07 / fm"
-! !
-
 !PrinterContext methodsFor:'initialization & release'!
 
 buildPrinter
@@ -597,10 +579,9 @@
     jobid isNil
         ifTrue: [ self startPrintJob: aTitle ].
     abortDialog := PrintAbortDialog new open: aTitle printer: self.
-    Delay forMilliseconds: 3000.
-    self setPrinterFont: aFont.
+    self font: aFont.
     marginsRect := self marginsRectangleFor: aMarginsRect.
-    lines := self asArrayOfLines: aString in: marginsRect wordWrap: wordWrapBoolean.
+    lines := self asArrayOfStringLines: aString in: marginsRect wordWrap: wordWrapBoolean.
     charHeight := self getCharHeight. 
     linesPerPage := marginsRect bottom - marginsRect top // charHeight.
     totalPage := lines size + linesPerPage - 1 // linesPerPage.
@@ -614,7 +595,7 @@
         firstPage ifFalse: [ self formFeed ].
         abortDialog updatePrintingPageInfo: 'Page ', page printString, '/', totalPage printString.
 "/      self device font: printerFont.
-        self setPrinterFont: aFont.
+        self font: aFont.
         self printPage: page in: marginsRect lines: lines linesPerPage: linesPerPage.
         firstPage := false ]. 
 
@@ -660,11 +641,11 @@
 
     | lines linesPerPage totalPage marginsRect firstPage charHeight  printerFont headerLines|
 
-    self setPrinterFont: aFont.
+    self font: aFont.
     charHeight := self getCharHeight.
     marginsRect := self marginsRectangleFor: aMarginsRect.
-    lines := self asArrayOfLines: aString in: marginsRect wordWrap: wordWrapBoolean.
-    headerLines := self asArrayOfLines: aString2 in: marginsRect wordWrap: wordWrapBoolean.
+    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
@@ -702,100 +683,9 @@
 "/        ].
 
     "Created: / 03-08-2006 / 16:14:10 / fm"
-!
-
-printPage: pageIndex in: aRectangle lines: lines headerLines: headerLines linesPerPage: linesPerPage
-
-        "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.
-
-    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 displayLines: hLines in: aRectangle.
-    self displayLines: lines from: firstLine to: lastLine in: rect.
-
-    "Created: / 27-07-2006 / 18:28:00 / fm"
-    "Modified: / 03-08-2006 / 16:03:15 / fm"
-!
-
-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 displayLines: lines from: firstLine to: lastLine in: aRectangle
-
-    "Created: / 27-07-2006 / 18:24:59 / fm"
-    "Modified: / 03-08-2006 / 12:47:24 / fm"
 ! !
 
-!PrinterContext methodsFor:'processing'!
-
-asArrayOfLines: 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: [
-        leftMargin := aRectangle left.
-        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 
-                        ].
-                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
-
-    "Created: / 02-08-2006 / 17:56:51 / fm"
-    "Modified: / 04-08-2006 / 13:39:50 / fm"
-!
+!PrinterContext methodsFor:'printing process'!
 
 endPage
         "Informs device that we are finished writing to a page."
@@ -834,52 +724,6 @@
     "Created: / 27-07-2006 / 18:25:40 / fm"
 !
 
-marginsRectangleFor:aRectangle 
-    "Private - Answer a Rectangle defining margins based on aRectangle.
-     Units for aRectangle are in inches, returned margins rectangle is
-     in device units (pixels)."
-    
-    |left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle|
-    pixelsPerInchX := self pixelsPerInchOfScreenWidth.
-    pixelsPerInchY := self pixelsPerInchOfScreenHeight.
-    aRectangle isNil ifTrue:[
-        horzRes := self printerWidthArea.
-        vertRes := self printerHeightArea.
-        inset := self class defaultMargins.
-        left := (inset x * pixelsPerInchX) asInteger.
-        top := (inset y * pixelsPerInchY) asInteger.
-        right := horzRes - (inset x * pixelsPerInchX) asInteger.
-        bottom := vertRes - (inset y * pixelsPerInchY) asInteger
-    ] ifFalse:[
-        left := (aRectangle left * pixelsPerInchX) asInteger.
-        top := (aRectangle top * pixelsPerInchY) asInteger.
-        right := (aRectangle right * pixelsPerInchX) asInteger.
-        bottom := (aRectangle bottom * pixelsPerInchY) asInteger
-    ].
-    rectangle := left @ top extent: right @ bottom.
-    ^ rectangle
-
-    "Created: / 27-07-2006 / 18:22:57 / fm"
-    "Modified: / 04-08-2006 / 13:39:45 / fm"
-!
-
-setPrinterFont: aFont
-        "Private - set a font in the receiver's medium whose characteristics
-        (pointSize, etc.) match those of aFont."
-    | printerFont |
-    aFont notNil ifTrue: [
-        self basicFont: aFont.
-"/        printerFont := Font fromLogicalFont: aFont logicalFont graphicsMedium: self.
-"/        printerFont pointSize: aFont pointSize graphicsMedium: self.
-"/        printerFont makeFont.
-"/        self device font: printerFont 
-    ].
-    ^aFont
-
-    "Created: / 27-07-2006 / 18:21:59 / fm"
-    "Modified: / 03-08-2006 / 16:29:16 / fm"
-!
-
 startPage
         "Starts a page."
     ( OperatingSystem startPage: gcId ) > 0
@@ -957,6 +801,211 @@
 
     "Created: / 27-07-2006 / 18:19:31 / fm"
     "Modified: / 03-08-2006 / 15:11:19 / fm"
+! !
+
+!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.
+"/    (info includesSubstring: ',PSCRIPT,')
+"/    ifTrue: [
+"/        retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not.
+"/    ]
+"/    ifFalse: [
+"/        retVal := (info includesSubstring: 'PDF')
+"/            ifTrue: [true]
+"/            ifFalse: [self numberOfColorBitsPerPixel > 1].
+"/    ].
+"/
+"/    ^retVal
+
+    "Created: / 03-08-2006 / 09:55:26 / fm"
+    "Modified: / 04-08-2006 / 13:20:40 / fm"
+!
+
+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"
+! !
+
+!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.
+    lines := OrderedCollection new.
+    wordWrapBoolean ifTrue: [
+        leftMargin := aRectangle left.
+        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 
+                        ].
+                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
+
+    "Created: / 02-08-2006 / 17:56:51 / fm"
+    "Modified: / 04-08-2006 / 13:39:50 / fm"
+!
+
+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 |
+        |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.
+    ].
+
+"/    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"
+!
+
+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"
+!
+
+marginsRectangleFor:aRectangle 
+    "Private - Answer a Rectangle defining margins based on aRectangle.
+     Units for aRectangle are in inches, returned margins rectangle is
+     in device units (pixels)."
+    
+    |left top right bottom pixelsPerInchX pixelsPerInchY horzRes vertRes inset rectangle|
+    pixelsPerInchX := self pixelsPerInchOfScreenWidth.
+    pixelsPerInchY := self pixelsPerInchOfScreenHeight.
+    aRectangle isNil ifTrue:[
+        horzRes := self printerWidthArea.
+        vertRes := self printerHeightArea.
+        inset := self class defaultMargins.
+        left := (inset x * pixelsPerInchX) asInteger.
+        top := (inset y * pixelsPerInchY) asInteger.
+        right := horzRes - (inset x * pixelsPerInchX) asInteger.
+        bottom := vertRes - (inset y * pixelsPerInchY) asInteger
+    ] ifFalse:[
+        left := (aRectangle left * pixelsPerInchX) asInteger.
+        top := (aRectangle top * pixelsPerInchY) asInteger.
+        right := (aRectangle right * pixelsPerInchX) asInteger.
+        bottom := (aRectangle bottom * pixelsPerInchY) asInteger
+    ].
+    rectangle := left @ top extent: right @ bottom.
+    ^ rectangle
+
+    "Created: / 27-07-2006 / 18:22:57 / fm"
+    "Modified: / 04-08-2006 / 13:39:45 / fm"
+!
+
+printPage: pageIndex in: aRectangle lines: lines headerLines: headerLines linesPerPage: linesPerPage
+
+        "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.
+
+    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.
+
+    "Created: / 27-07-2006 / 18:28:00 / fm"
+    "Modified: / 03-08-2006 / 16:03:15 / fm"
+!
+
+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"
 !
 
 stringWidthOf: aString
@@ -999,44 +1048,8 @@
     "Modified: / 04-08-2006 / 12:27:26 / fm"
 ! !
 
-!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.
-"/    (info includesSubstring: ',PSCRIPT,')
-"/    ifTrue: [
-"/        retVal := (DAPASX::DapasSystemInfo getYesNoInfoApp: 'Printer' profile: 'PostScriptBlackWhite') not.
-"/    ]
-"/    ifFalse: [
-"/        retVal := (info includesSubstring: 'PDF')
-"/            ifTrue: [true]
-"/            ifFalse: [self numberOfColorBitsPerPixel > 1].
-"/    ].
-"/
-"/    ^retVal
-
-    "Created: / 03-08-2006 / 09:55:26 / fm"
-    "Modified: / 04-08-2006 / 13:20:40 / fm"
-!
-
-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"
-! !
-
 !PrinterContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.2 2006-08-09 12:46:19 fm Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/PrinterContext.st,v 1.3 2006-08-16 11:00:12 fm Exp $'
 ! !