3816
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2016 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
PrinterStream subclass:#HTMLPrinterStream
|
3818
|
17 |
instanceVariableNames:'htmlBuilder buffer currentStyle bold italic fontName'
|
3816
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Printing'
|
|
21 |
!
|
|
22 |
|
|
23 |
!HTMLPrinterStream class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2016 by Claus Gittinger
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
A simple HTML generating printer stream.
|
|
42 |
Useful to generate indented listings, which need to be included in
|
|
43 |
an html document.
|
|
44 |
Currently only supports bold and normal printing;
|
|
45 |
needs more care & feeding for italic, underline and colors.
|
|
46 |
|
|
47 |
[see also:]
|
|
48 |
PSPrinterStream PrinterStream PDFPrinterStream
|
|
49 |
|
|
50 |
[author:]
|
|
51 |
Claus Gittinger
|
|
52 |
"
|
|
53 |
! !
|
|
54 |
|
|
55 |
!HTMLPrinterStream class methodsFor:'queries'!
|
|
56 |
|
|
57 |
isDrivenByCommand
|
|
58 |
^ false
|
|
59 |
!
|
|
60 |
|
|
61 |
printerTypeName
|
|
62 |
"return a descriptive name"
|
|
63 |
|
|
64 |
^ 'HTML Printer'
|
|
65 |
!
|
|
66 |
|
|
67 |
supportsMargins
|
|
68 |
^ false
|
|
69 |
!
|
|
70 |
|
|
71 |
supportsPageSizes
|
|
72 |
^ false
|
|
73 |
!
|
|
74 |
|
|
75 |
supportsPostscript
|
|
76 |
^ false
|
|
77 |
!
|
|
78 |
|
|
79 |
supportsPrintingToFile
|
|
80 |
^ true
|
|
81 |
! !
|
|
82 |
|
|
83 |
!HTMLPrinterStream methodsFor:'emphasis'!
|
|
84 |
|
3818
|
85 |
bold
|
|
86 |
"switch to bold emphasis"
|
|
87 |
|
|
88 |
bold ifFalse:[
|
|
89 |
self flushBuffer.
|
|
90 |
htmlBuilder bold.
|
|
91 |
bold := true.
|
|
92 |
].
|
|
93 |
!
|
|
94 |
|
3816
|
95 |
emphasis:anEmphasis
|
|
96 |
self flushBuffer.
|
|
97 |
super emphasis:anEmphasis.
|
|
98 |
|
3818
|
99 |
"/ self setupFontTypeEmphasis.
|
|
100 |
"/ self setupColorFromEmphasis:anEmphasis.
|
|
101 |
"/ self setupUnderlineFromEmphasis:anEmphasis.
|
|
102 |
!
|
|
103 |
|
|
104 |
normal
|
|
105 |
"back to normal (non-bold, non-italic) emphasis"
|
|
106 |
|
|
107 |
bold ifTrue:[
|
|
108 |
self flushBuffer.
|
|
109 |
htmlBuilder boldEnd.
|
|
110 |
bold := false.
|
|
111 |
].
|
|
112 |
! !
|
|
113 |
|
|
114 |
!HTMLPrinterStream methodsFor:'initialization'!
|
|
115 |
|
|
116 |
close
|
|
117 |
self flushBuffer.
|
|
118 |
bold ifTrue:[
|
|
119 |
htmlBuilder boldEnd.
|
|
120 |
].
|
|
121 |
htmlBuilder preEnd.
|
|
122 |
htmlBuilder bodyEnd.
|
|
123 |
htmlBuilder printHtmlOn:stream.
|
|
124 |
super close.
|
|
125 |
!
|
|
126 |
|
|
127 |
initialize
|
|
128 |
super initialize.
|
3898
|
129 |
|
|
130 |
HTML::TreeBuilder isNil ifTrue:[
|
|
131 |
Smalltalk loadPackage:#'stx:goodies/webServer/htmlTree'
|
|
132 |
].
|
3818
|
133 |
bold := italic := false.
|
|
134 |
htmlBuilder := HTML::TreeBuilder new.
|
|
135 |
htmlBuilder body.
|
|
136 |
htmlBuilder pre.
|
3816
|
137 |
! !
|
|
138 |
|
|
139 |
!HTMLPrinterStream methodsFor:'writing'!
|
|
140 |
|
|
141 |
cr
|
|
142 |
self flushBuffer.
|
3818
|
143 |
super cr.
|
3816
|
144 |
!
|
|
145 |
|
|
146 |
flushBuffer
|
3818
|
147 |
|style|
|
3816
|
148 |
|
|
149 |
buffer notNil ifTrue:[
|
3818
|
150 |
htmlBuilder text:buffer contents.
|
|
151 |
"/ bold ifTrue:[ style := self style:style with: htmlBuilder boldEnd ].
|
|
152 |
"/ italic ifTrue:[ htmlBuilder italicEnd ].
|
|
153 |
"/ underline ifTrue:[ htmlBuilder underlineEnd ].
|
|
154 |
"/ strikeout ifTrue:[ htmlBuilder strikeoutEnd ].
|
|
155 |
"/
|
|
156 |
"/ redefinedStyle := PdfStyle redefine.
|
|
157 |
"/ redefinedStyle color:currentFontColor.
|
|
158 |
"/ redefinedStyle setFont:currentFontTypeEmphasis.
|
|
159 |
"/ redefinedStyle underlinedColor:currentUnderlineColor.
|
|
160 |
"/
|
|
161 |
"/ currentUnderlineBool ifTrue:[
|
|
162 |
"/ redefinedStyle underlined.
|
|
163 |
"/ ].
|
|
164 |
"/
|
|
165 |
"/ pdfDocumentEditor
|
|
166 |
"/ text:buffer contents
|
|
167 |
"/ style:redefinedStyle.
|
3816
|
168 |
|
|
169 |
buffer := nil.
|
|
170 |
].
|
|
171 |
!
|
|
172 |
|
|
173 |
nextPut:aCharacter
|
|
174 |
buffer isNil ifTrue:[
|
|
175 |
buffer := CharacterWriteStream new.
|
|
176 |
].
|
|
177 |
buffer nextPut:aCharacter.
|
|
178 |
! !
|
|
179 |
|
|
180 |
!HTMLPrinterStream class methodsFor:'documentation'!
|
|
181 |
|
|
182 |
version
|
|
183 |
^ '$Header$'
|
|
184 |
!
|
|
185 |
|
|
186 |
version_CVS
|
|
187 |
^ '$Header$'
|
|
188 |
! !
|
|
189 |
|