The Trunk: ST80-nice.157.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: ST80-nice.157.mcz

commits-2
Nicolas Cellier uploaded a new version of ST80 to project The Trunk:
http://source.squeak.org/trunk/ST80-nice.157.mcz

==================== Summary ====================

Name: ST80-nice.157
Author: nice
Time: 6 October 2013, 11:38:34.779 pm
UUID: 43ab6d32-044c-4ed9-ad39-77695f385eca
Ancestors: ST80-nice.156

TextPrinter is designed for MVC, give it back to ST80.

=============== Diff against ST80-nice.156 ===============

Item was changed:
  CharacterBlockScanner subclass: #CharacterBlockScannerForMVC
  instanceVariableNames: ''
  classVariableNames: ''
  poolDictionaries: ''
  category: 'ST80-Support'!
+
+ !CharacterBlockScannerForMVC commentStamp: 'nice 10/6/2013 22:09' prior: 0!
+ A CharacterBlockScannerForMVC is specialization of a CharacterBlockScanner used for compatibility with Smalltalk-80 Model View Controller framework.
+ !

Item was added:
+ Object subclass: #TextPrinter
+ instanceVariableNames: 'form para paperSize landscape resolution depth offset columns docTitle noHeader noFooter'
+ classVariableNames: 'DefaultPaperSize DefaultTextPrinter'
+ poolDictionaries: ''
+ category: 'ST80-Support'!

Item was added:
+ ----- Method: TextPrinter class>>defaultPaperSize (in category 'accessing') -----
+ defaultPaperSize
+ ^DefaultPaperSize!

Item was added:
+ ----- Method: TextPrinter class>>defaultPaperSize: (in category 'accessing') -----
+ defaultPaperSize: aPoint
+ DefaultPaperSize := aPoint!

Item was added:
+ ----- Method: TextPrinter class>>defaultTextPrinter (in category 'accessing') -----
+ defaultTextPrinter
+ "This is the global default TextPrinter instance."
+ DefaultTextPrinter isNil ifTrue: [DefaultTextPrinter := self new].
+ ^DefaultTextPrinter!

Item was added:
+ ----- Method: TextPrinter class>>initialize (in category 'class initialization') -----
+ initialize
+ "TextPrinter initialize"
+ self defaultPaperSize: self paperSizeA4.!

Item was added:
+ ----- Method: TextPrinter class>>mm2in: (in category 'paper sizes') -----
+ mm2in: aPoint
+ "Convert aPoint from millimeters to inches"
+ ^aPoint / 25.4!

Item was added:
+ ----- Method: TextPrinter class>>paperSize10x14 (in category 'paper sizes') -----
+ paperSize10x14
+ ^10.0@14.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSize11x17 (in category 'paper sizes') -----
+ paperSize11x17
+ ^11.0@17.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeA3 (in category 'paper sizes') -----
+ paperSizeA3
+ ^self mm2in: 297@420!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeA4 (in category 'paper sizes') -----
+ paperSizeA4
+ ^self mm2in: 210@297!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeA5 (in category 'paper sizes') -----
+ paperSizeA5
+ ^self mm2in: 148@210!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeB4 (in category 'paper sizes') -----
+ paperSizeB4
+ ^self mm2in: 250@354!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeB5 (in category 'paper sizes') -----
+ paperSizeB5
+ ^self mm2in: 182@257!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeCSheet (in category 'paper sizes') -----
+ paperSizeCSheet
+ ^17.0@22.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeDSheet (in category 'paper sizes') -----
+ paperSizeDSheet
+ ^22.0@34.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeESheet (in category 'paper sizes') -----
+ paperSizeESheet
+ ^34.0@44.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelope10 (in category 'paper sizes') -----
+ paperSizeEnvelope10
+ ^4.125@9.5
+ !

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelope11 (in category 'paper sizes') -----
+ paperSizeEnvelope11
+ ^4.5@10.375!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelope12 (in category 'paper sizes') -----
+ paperSizeEnvelope12
+ ^4.75@11!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelope14 (in category 'paper sizes') -----
+ paperSizeEnvelope14
+ ^5.0@11.5!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelope9 (in category 'paper sizes') -----
+ paperSizeEnvelope9
+ ^3.875@8.875!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeB4 (in category 'paper sizes') -----
+ paperSizeEnvelopeB4
+ ^self mm2in: 250@353!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeB5 (in category 'paper sizes') -----
+ paperSizeEnvelopeB5
+ ^self mm2in: 176@250!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeB6 (in category 'paper sizes') -----
+ paperSizeEnvelopeB6
+ ^self mm2in: 176@125!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeC3 (in category 'paper sizes') -----
+ paperSizeEnvelopeC3
+ ^self mm2in: 324@458!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeC4 (in category 'paper sizes') -----
+ paperSizeEnvelopeC4
+ ^self mm2in: 229@324!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeC5 (in category 'paper sizes') -----
+ paperSizeEnvelopeC5
+ ^self mm2in: 162@229!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeC6 (in category 'paper sizes') -----
+ paperSizeEnvelopeC6
+ ^self mm2in: 114@162!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeEnvelopeC65 (in category 'paper sizes') -----
+ paperSizeEnvelopeC65
+ ^self mm2in: 114@229!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeFanfoldGerman (in category 'paper sizes') -----
+ paperSizeFanfoldGerman
+ "German standard fanfold"
+ ^8.5@12.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeFanfoldLegalGerman (in category 'paper sizes') -----
+ paperSizeFanfoldLegalGerman
+ "German legal fanfold"
+ ^8.5@13.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeFanfoldUS (in category 'paper sizes') -----
+ paperSizeFanfoldUS
+ "US standard fanfold"
+ ^14.875@11.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeFolio (in category 'paper sizes') -----
+ paperSizeFolio
+ ^8.5@13.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeLegal (in category 'paper sizes') -----
+ paperSizeLegal
+ ^8.5@14.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeLetter (in category 'paper sizes') -----
+ paperSizeLetter
+ ^8.5@11.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeNote (in category 'paper sizes') -----
+ paperSizeNote
+ ^8.5@11.0!

Item was added:
+ ----- Method: TextPrinter class>>paperSizeTabloid (in category 'paper sizes') -----
+ paperSizeTabloid
+ ^11.0@17.0!

Item was added:
+ ----- Method: TextPrinter>>bestColor (in category 'accessing') -----
+ bestColor
+ "Set the reproduction quality to true color"
+ depth := 32.!

Item was added:
+ ----- Method: TextPrinter>>blackAndWhite (in category 'accessing') -----
+ blackAndWhite
+ "Set the reproduction quality to black and white"
+ depth := 1.!

Item was added:
+ ----- Method: TextPrinter>>columnRect: (in category 'formatting') -----
+ columnRect: n
+ "Return a rectangle describing the n-th column"
+ | area left right |
+ area := self textArea.
+ left := area left + ((n-1) * self columnWidth).
+ left := left + ((n-1) * self columnSkip).
+ right := left + self columnWidth.
+ ^(self in2pix: left @ area top) corner:
+ (self in2pix: right @ area bottom)!

Item was added:
+ ----- Method: TextPrinter>>columnSkip (in category 'formatting') -----
+ columnSkip
+ "Return the separating space between two columns in inches"
+ ^0.2!

Item was added:
+ ----- Method: TextPrinter>>columnWidth (in category 'formatting') -----
+ columnWidth
+ ^(self textWidth - ((self columns-1) * self columnSkip)) / self columns!

Item was added:
+ ----- Method: TextPrinter>>columns (in category 'accessing') -----
+ columns
+ ^columns!

Item was added:
+ ----- Method: TextPrinter>>columns: (in category 'accessing') -----
+ columns: aNumber
+ columns := aNumber asInteger max: 1.!

Item was added:
+ ----- Method: TextPrinter>>defaultPaperSize (in category 'initialize') -----
+ defaultPaperSize
+ "Return the default paper size (inches) for printing"
+ ^self class defaultPaperSize!

Item was added:
+ ----- Method: TextPrinter>>defaultResolution (in category 'initialize') -----
+ defaultResolution
+ "Return the default resolution (DPI) for printing"
+ ^TextStyle pixelsPerInch asPoint!

Item was added:
+ ----- Method: TextPrinter>>documentTitle (in category 'accessing') -----
+ documentTitle
+ ^docTitle!

Item was added:
+ ----- Method: TextPrinter>>documentTitle: (in category 'accessing') -----
+ documentTitle: aString
+ docTitle := aString!

Item was added:
+ ----- Method: TextPrinter>>flushPage (in category 'printing') -----
+ flushPage
+ "The current page has been set up. Send it to the printer."
+ form primPrintHScale: self resolution x vScale: self resolution y landscape: self landscape.
+ "Uncomment the following for testing"
+ "form displayOn: Display. (Delay forSeconds: 5) wait."
+ !

Item was added:
+ ----- Method: TextPrinter>>footerHeight (in category 'footer') -----
+ footerHeight
+ "Return the (additional) height of the footer in inches."
+ self noFooter ifTrue:[^0.0].
+ ^(self pix2in: 0@TextStyle default lineGrid) y * 2!

Item was added:
+ ----- Method: TextPrinter>>footerParagraph (in category 'footer') -----
+ footerParagraph
+ "Return a paragraph for the footer"
+ | fPara rect paragraphClass |
+ paragraphClass := Smalltalk at: #Paragraph
+ ifAbsent: [^ self notify: 'MVC class Paragraph not present'].
+ fPara := paragraphClass new.
+ fPara destinationForm: form.
+ rect := (self in2pix: self textArea bottomLeft) corner:
+ (self in2pix: self textArea bottomRight + (0.0@self footerHeight)).
+ fPara clippingRectangle: rect.
+ fPara compositionRectangle: rect.
+ ^fPara!

Item was added:
+ ----- Method: TextPrinter>>formatColumn:startingWith: (in category 'formatting') -----
+ formatColumn: columnNum startingWith: anIndex
+ "Format a new column starting at the given string index. Return the string index indicating the start of the next column or nil if no more columns need printing."
+ | colRect blk |
+ colRect := self columnRect: columnNum.
+ anIndex > 1 ifTrue:[para text: (para text copyFrom: anIndex to: para text size)].
+ para compositionRectangle: colRect.
+ para clippingRectangle: colRect.
+ para composeAll.
+ para displayOn: form.
+ para visibleRectangle corner y <= colRect extent y ifTrue:[^nil].
+ "More columns -- find the character block of the last line and adjust clip rect"
+ blk := para characterBlockAtPoint: para visibleRectangle bottomLeft.
+ para clearVisibleRectangle. "Make sure that the background is clean"
+ para clippingRectangle: (colRect topLeft corner: colRect right@blk top).
+ para displayOn: form.
+ ^blk stringIndex.!

Item was added:
+ ----- Method: TextPrinter>>formatPage:startingWith: (in category 'formatting') -----
+ formatPage: pageNum startingWith: anIndex
+ "Format a new page starting at the given string index. Return the string index indicating the start of the next page or nil if no more pages need printing."
+ | nextIndex |
+ nextIndex := anIndex.
+ 1 to: self columns do:[:i|
+ nextIndex := self formatColumn: i startingWith: nextIndex.
+ nextIndex isNil ifTrue:[^nil].
+ ].
+ ^nextIndex!

Item was added:
+ ----- Method: TextPrinter>>goodColor (in category 'accessing') -----
+ goodColor
+ "Set the reproduction quality to 8 bit color depth"
+ depth := 8.!

Item was added:
+ ----- Method: TextPrinter>>headerHeight (in category 'header') -----
+ headerHeight
+ "Return the (additional) height of the header in inches."
+ self noHeader ifTrue:[^0.0].
+ ^(self pix2in: 0@TextStyle default lineGrid) y * 2!

Item was added:
+ ----- Method: TextPrinter>>headerParagraph (in category 'header') -----
+ headerParagraph
+ "Return a paragraph for the footer"
+ | hPara rect paragraphClass |
+ paragraphClass := Smalltalk at: #Paragraph
+ ifAbsent: [^ self notify: 'MVC class Paragraph not present'].
+ hPara := paragraphClass new.
+ hPara destinationForm: form.
+ rect := (self in2pix: self textArea topLeft - (0.0@self headerHeight)) corner:
+ (self in2pix: self textArea topRight).
+ hPara clippingRectangle: rect.
+ hPara compositionRectangle: rect.
+ ^hPara!

Item was added:
+ ----- Method: TextPrinter>>in2mm: (in category 'other') -----
+ in2mm: aPoint
+ "Convert aPoint from millimeters to inches"
+ ^aPoint * 25.4!

Item was added:
+ ----- Method: TextPrinter>>in2pix: (in category 'other') -----
+ in2pix: aPoint
+ "Convert aPoint from inches to actual pixels"
+ ^(aPoint * self resolution) rounded!

Item was added:
+ ----- Method: TextPrinter>>initialize (in category 'initialize') -----
+ initialize
+ self paperSize: self defaultPaperSize.
+ self resolution: self defaultResolution.
+ self blackAndWhite.
+ self landscape: false.
+ self offsetRect: (1.0@1.0 corner: 1.0@1.0).
+ self columns: 1.
+ self noHeader: false.
+ self noFooter: false.
+ self documentTitle: 'Squeak Document (from ', Date today printString,')'.!

Item was added:
+ ----- Method: TextPrinter>>landscape (in category 'accessing') -----
+ landscape
+ ^landscape!

Item was added:
+ ----- Method: TextPrinter>>landscape: (in category 'accessing') -----
+ landscape: aBoolean
+ landscape := aBoolean!

Item was added:
+ ----- Method: TextPrinter>>mm2in: (in category 'other') -----
+ mm2in: aPoint
+ "Convert aPoint from millimeters to inches"
+ ^aPoint / 25.4!

Item was added:
+ ----- Method: TextPrinter>>mm2pix: (in category 'other') -----
+ mm2pix: aPoint
+ "Convert aPoint from millimeters to actual pixels"
+ ^self in2pix: (self mm2in: aPoint)!

Item was added:
+ ----- Method: TextPrinter>>noFooter (in category 'accessing') -----
+ noFooter
+ ^noFooter!

Item was added:
+ ----- Method: TextPrinter>>noFooter: (in category 'accessing') -----
+ noFooter: aBoolean
+ "Turn off footer printing"
+ noFooter := aBoolean.!

Item was added:
+ ----- Method: TextPrinter>>noHeader (in category 'accessing') -----
+ noHeader
+ ^noHeader!

Item was added:
+ ----- Method: TextPrinter>>noHeader: (in category 'accessing') -----
+ noHeader: aBoolean
+ "Turn off header printing"
+ noHeader := aBoolean.!

Item was added:
+ ----- Method: TextPrinter>>offsetRect (in category 'accessing') -----
+ offsetRect
+ ^offset!

Item was added:
+ ----- Method: TextPrinter>>offsetRect: (in category 'accessing') -----
+ offsetRect: aRectangle
+ "Set the offset rectangle"
+ offset := aRectangle!

Item was added:
+ ----- Method: TextPrinter>>paperSize (in category 'accessing') -----
+ paperSize
+ ^paperSize!

Item was added:
+ ----- Method: TextPrinter>>paperSize: (in category 'accessing') -----
+ paperSize: aPoint
+ paperSize := aPoint!

Item was added:
+ ----- Method: TextPrinter>>pix2in: (in category 'other') -----
+ pix2in: aPoint
+ "Convert aPoint from a pixel value to inches"
+ ^aPoint / self resolution!

Item was added:
+ ----- Method: TextPrinter>>pix2mm: (in category 'other') -----
+ pix2mm: aPoint
+ "Convert aPoint from a pixel value to millimeters"
+ ^self in2mm: (self pix2in: aPoint)!

Item was added:
+ ----- Method: TextPrinter>>pixelSize (in category 'private') -----
+ pixelSize
+ "Return the size of the page in pixels"
+ ^self in2pix: (self realPaperSize)!

Item was added:
+ ----- Method: TextPrinter>>printFooter: (in category 'footer') -----
+ printFooter: pageNumber
+ "Print the footer for the given page number"
+ | fPara |
+ self noFooter ifTrue:[^self].
+ fPara := self footerParagraph.
+ fPara centered.
+ fPara text: ('Page ', pageNumber printString) asText.
+ fPara displayOn: form.!

Item was added:
+ ----- Method: TextPrinter>>printHeader: (in category 'header') -----
+ printHeader: pageNumber
+ "Print the header for the given page number"
+ | fPara |
+ self noHeader ifTrue:[^self].
+ fPara := self headerParagraph.
+ fPara centered.
+ fPara text: self documentTitle asText.
+ fPara displayOn: form.!

Item was added:
+ ----- Method: TextPrinter>>printParagraph (in category 'printing') -----
+ printParagraph
+ | pageNum nextIndex |
+ para destinationForm: form.
+ pageNum := 1.
+ nextIndex := 1.
+ [form fillColor: Color white.
+ self printHeader: pageNum.
+ self printFooter: pageNum.
+ nextIndex := self formatPage: pageNum startingWith: nextIndex.
+ self flushPage.
+ nextIndex isNil] whileFalse:[pageNum := pageNum + 1].!

Item was added:
+ ----- Method: TextPrinter>>printText: (in category 'printing') -----
+ printText: aText
+ "Print aText"
+ | paragraphClass |
+ form isNil ifTrue:[
+ form := Form extent: self pixelSize depth: depth.
+ ].
+ paragraphClass := Smalltalk at: #Paragraph
+ ifAbsent: [^ self notify: 'MVC class Paragraph not present'].
+ para := paragraphClass withText: aText asText.
+ Cursor wait showWhile:[
+ self printParagraph.
+ ].!

Item was added:
+ ----- Method: TextPrinter>>realPaperSize (in category 'private') -----
+ realPaperSize
+ ^self landscape
+ ifTrue:[self paperSize y @ self paperSize x]
+ ifFalse:[self paperSize]!

Item was added:
+ ----- Method: TextPrinter>>resolution (in category 'accessing') -----
+ resolution
+ ^resolution!

Item was added:
+ ----- Method: TextPrinter>>resolution: (in category 'accessing') -----
+ resolution: aPoint
+ resolution := aPoint!

Item was added:
+ ----- Method: TextPrinter>>textArea (in category 'formatting') -----
+ textArea
+ ^(self offsetRect origin + (0.0@self headerHeight)) corner:
+ (self realPaperSize - self offsetRect corner - (0.0@self footerHeight))!

Item was added:
+ ----- Method: TextPrinter>>textWidth (in category 'formatting') -----
+ textWidth
+ ^self textArea extent x!