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