WinPrinterContext.st
branchjv
changeset 3720 f27814c1b52a
parent 3528 378efd6fd2f1
parent 3719 a36b0c184dcb
child 3722 6d604bcf36f3
equal deleted inserted replaced
3708:108b53ed090f 3720:f27814c1b52a
    12 "{ Package: 'stx:libview2' }"
    12 "{ Package: 'stx:libview2' }"
    13 
    13 
    14 "{ NameSpace: Smalltalk }"
    14 "{ NameSpace: Smalltalk }"
    15 
    15 
    16 PrinterContext subclass:#WinPrinterContext
    16 PrinterContext subclass:#WinPrinterContext
    17 	instanceVariableNames:'deviceFonts hatch supportsColor'
    17 	instanceVariableNames:'deviceFonts hatch supportsColor title'
    18 	classVariableNames:'PostScriptBlackWhite'
    18 	classVariableNames:'PostScriptBlackWhite'
    19 	poolDictionaries:''
    19 	poolDictionaries:''
    20 	category:'Interface-Printing'
    20 	category:'Interface-Printing'
    21 !
    21 !
    22 
    22 
    23 WinPrinterContext subclass:#WinPrinterGraphicContext
    23 WinPrinterContext subclass:#WinPrinterGraphicContext
    24 	instanceVariableNames:'fontScale printPageNumbers pageNumberFormat pageCounter
    24 	instanceVariableNames:'fontScale printPageNumbers pageNumberFormat pageCounter
    25 		needsEndOfPage titleFont'
    25 		needsEndOfPage titleFont width height'
    26 	classVariableNames:''
    26 	classVariableNames:''
    27 	poolDictionaries:''
    27 	poolDictionaries:''
    28 	privateIn:WinPrinterContext
    28 	privateIn:WinPrinterContext
    29 !
    29 !
    30 
    30 
   297     printerInfo := PrintingDialog getPrinterInfoWithoutDialog:withoutDialog.
   297     printerInfo := PrintingDialog getPrinterInfoWithoutDialog:withoutDialog.
   298     printerInfo isNil ifTrue:[^ nil].
   298     printerInfo isNil ifTrue:[^ nil].
   299     gc := WinPrinterGraphicContext fromPrinterInfo:printerInfo.
   299     gc := WinPrinterGraphicContext fromPrinterInfo:printerInfo.
   300 
   300 
   301     gc notNil ifTrue:[
   301     gc notNil ifTrue:[
   302         gc startPrintJob:jobName
   302 	gc startPrintJob:jobName
   303     ].
   303     ].
   304     ^ gc
   304     ^ gc
   305 ! !
   305 ! !
   306 
   306 
   307 !WinPrinterContext class methodsFor:'accessing'!
   307 !WinPrinterContext class methodsFor:'accessing'!
  5622 startPrintJob:aString fileName:aFileName
  5622 startPrintJob:aString fileName:aFileName
  5623     "Start a print job, using aString as the job title; everything
  5623     "Start a print job, using aString as the job title; everything
  5624      drawn between startPrintJob and endPrintJob will become
  5624      drawn between startPrintJob and endPrintJob will become
  5625      one entry in the print queue."
  5625      one entry in the print queue."
  5626 
  5626 
  5627     |docInfoStruct nameAddress title fileNameAddress|
  5627     |docInfoStruct nameAddress fileNameAddress|
  5628 
  5628 
  5629     self gcId isNil ifTrue:[
  5629     self gcId isNil ifTrue:[
  5630 	self buildPrinter
  5630         self buildPrinter
  5631     ].
  5631     ].
  5632     abort := false.
  5632     abort := false.
  5633     title := aString ? 'Smalltalk/X'.
  5633     title := aString ? 'Smalltalk/X'.
  5634     nameAddress := title asExternalBytes unprotectFromGC.
  5634     nameAddress := title asExternalBytes unprotectFromGC.
  5635     aFileName isNil ifFalse:[
  5635     aFileName isNil ifFalse:[
  5636 	fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
  5636         fileNameAddress := aFileName pathName asExternalBytes unprotectFromGC
  5637     ].
  5637     ].
  5638     docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
  5638     docInfoStruct := Win32OperatingSystem::DocInfoStructure new.
  5639     docInfoStruct
  5639     docInfoStruct
  5640 	cbSize:docInfoStruct sizeInBytes;
  5640         cbSize:docInfoStruct sizeInBytes;
  5641 	lpszDocName:nameAddress address.
  5641         lpszDocName:nameAddress address.
  5642     fileNameAddress isNil ifFalse:[
  5642     fileNameAddress isNil ifFalse:[
  5643 	docInfoStruct lpszOutput:fileNameAddress address
  5643         docInfoStruct lpszOutput:fileNameAddress address
  5644     ].
  5644     ].
  5645     jobid := OperatingSystem startDoc:self gcId docInfo:docInfoStruct.
  5645     jobid := OperatingSystem startDoc:self gcId docInfo:docInfoStruct.
  5646     jobid > 0 ifFalse:[
  5646     jobid > 0 ifFalse:[
  5647 	jobid = -1 ifTrue:[
  5647         jobid = -1 ifTrue:[
  5648 	    abort := true.
  5648             abort := true.
  5649 	    ^ nil
  5649             ^ nil
  5650 	].
  5650         ].
  5651 "/        ^ self error
  5651 "/        ^ self error
  5652 	OpenError raiseErrorString:'Cannot create printer job'.
  5652         OpenError raiseErrorString:'Cannot create printer job'.
  5653     ].
  5653     ].
  5654     self startPage
  5654     self startPage
  5655 
  5655 
  5656     "Created: / 27-07-2006 / 18:19:31 / fm"
  5656     "Created: / 27-07-2006 / 18:19:31 / fm"
  5657     "Modified: / 03-08-2006 / 15:11:19 / fm"
  5657     "Modified: / 03-08-2006 / 15:11:19 / fm"
  5754     "return the papers bottom margin measured in pixels"
  5754     "return the papers bottom margin measured in pixels"
  5755 
  5755 
  5756     ^ 50
  5756     ^ 50
  5757 !
  5757 !
  5758 
  5758 
       
  5759 extent
       
  5760     ^ width @ height
       
  5761 !
       
  5762 
       
  5763 height
       
  5764     ^ height
       
  5765 !
       
  5766 
  5759 leftMargin
  5767 leftMargin
  5760     "return the papers left margin measured in pixels"
  5768     "return the papers left margin measured in pixels"
  5761 
  5769 
  5762     ^ 50
  5770     ^ 50
  5763 !
  5771 !
  5770 
  5778 
  5771 topMargin
  5779 topMargin
  5772     "return the papers top margin measured in pixels"
  5780     "return the papers top margin measured in pixels"
  5773 
  5781 
  5774     ^ 50
  5782     ^ 50
       
  5783 !
       
  5784 
       
  5785 width
       
  5786     ^ width
  5775 ! !
  5787 ! !
  5776 
  5788 
  5777 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing-hooks'!
  5789 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'accessing-hooks'!
  5778 
  5790 
  5779 pageCounter
  5791 pageCounter
  5825 
  5837 
  5826 scale:aScale
  5838 scale:aScale
  5827     "set the scale and add the fontScale factor"
  5839     "set the scale and add the fontScale factor"
  5828 
  5840 
  5829     super scale:(fontScale * (aScale ? 1.0)).
  5841     super scale:(fontScale * (aScale ? 1.0)).
       
  5842 !
       
  5843 
       
  5844 scale:scale translation:aPoint
       
  5845     self
       
  5846         translation:aPoint;
       
  5847         scale:scale.
  5830 !
  5848 !
  5831 
  5849 
  5832 transformation
  5850 transformation
  5833     "answer the transformation excluding the fontScale factor"
  5851     "answer the transformation excluding the fontScale factor"
  5834 
  5852 
  6057 !
  6075 !
  6058 
  6076 
  6059 initialize
  6077 initialize
  6060     super initialize.
  6078     super initialize.
  6061 
  6079 
       
  6080     device := nil.      "super initialize did set it to Screen current"
       
  6081 
  6062     pageCounter    := 0.
  6082     pageCounter    := 0.
  6063     needsEndOfPage := false.
  6083     needsEndOfPage := false.
  6064     printPageNumbers := true.
  6084     printPageNumbers := true.
  6065 
  6085 
  6066     Language == #de ifTrue:[ pageNumberFormat := 'Seite %1' ]
  6086     Language == #de ifTrue:[ pageNumberFormat := 'Seite %1' ]
  6067 		   ifFalse:[ pageNumberFormat := 'page %1'  ].
  6087                    ifFalse:[ pageNumberFormat := 'page %1'  ].
  6068 ! !
  6088 ! !
  6069 
  6089 
  6070 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'printing process'!
  6090 !WinPrinterContext::WinPrinterGraphicContext methodsFor:'printing process'!
  6071 
  6091 
  6072 displayTitleDo:aNoneArgAction
  6092 displayTitleDo:aNoneArgAction
  6073 
  6093 
  6074     |oldClip oldTrans oldFont|
  6094     |oldClip oldTrans oldFont|
  6075 
  6095 
  6076     oldClip := gc clipingRectangleOrNil.
  6096     oldClip := gc clipingRectangleOrNil.
  6077     oldClip notNil ifTrue:[ self deviceClippingRectangle:nil ].
  6097     oldClip notNil ifTrue:[ self deviceClippingBounds:nil ].
  6078 
  6098 
  6079     oldTrans := self translation.
  6099     oldTrans := self translation.
  6080     oldFont  := self font.
  6100     oldFont  := self font.
  6081 
  6101 
  6082     self  font:(self titleFont).
  6102     self  font:(self titleFont).
  6084 
  6104 
  6085     aNoneArgAction value.
  6105     aNoneArgAction value.
  6086 
  6106 
  6087     self translation:oldTrans.
  6107     self translation:oldTrans.
  6088     oldFont notNil ifTrue:[ self font:oldFont ].
  6108     oldFont notNil ifTrue:[ self font:oldFont ].
  6089     oldClip notNil ifTrue:[ self deviceClippingRectangle:oldClip ].
  6109     oldClip notNil ifTrue:[ self deviceClippingBounds:oldClip ].
  6090 !
  6110 !
  6091 
  6111 
  6092 endPage
  6112 endPage
  6093     "ends the current page
  6113     "ends the current page
  6094      if the current page is already closed by endPage, the request will be ignored"
  6114      if the current page is already closed by endPage, the request will be ignored"
  6095 
  6115 
  6096     |s|
  6116     |s|
  6097 
  6117 
  6098     needsEndOfPage ifFalse:[
  6118     needsEndOfPage ifFalse:[
  6099 	^ self
  6119         ^ self
  6100     ].
  6120     ].
  6101     needsEndOfPage := false.
  6121     needsEndOfPage := false.
  6102 
  6122 
  6103     printPageNumbers == true ifTrue:[
  6123     printPageNumbers == true ifTrue:[
  6104 	self displayTitleDo:[
  6124         self displayTitleDo:[
  6105 	    s := pageNumberFormat bindWith:pageCounter.
  6125             self displayString:title
  6106 
  6126                  x:(self extent x - (self font widthOf:title)) // 2
  6107 	    self displayString:s
  6127                  y:(self extent y + (self font ascent)).
       
  6128 
       
  6129             s := pageNumberFormat bindWith:pageCounter.
       
  6130             self displayString:s
  6108 			     x:(self extent x - (self font widthOf:s))
  6131 			     x:(self extent x - (self font widthOf:s))
  6109 			     y:(self extent y + (self font ascent)).
  6132 			     y:(self extent y + (self font ascent)).
  6110 	]
  6133         ]
  6111     ].
  6134     ].
  6112     super endPage.
  6135     super endPage.
  6113 !
  6136 !
  6114 
  6137 
  6115 startPage
  6138 startPage