369
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989 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 |
This is a demo example:
|
|
13 |
|
|
14 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
|
|
15 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
|
|
18 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
22 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
23 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
24 |
SUCH DAMAGE.
|
|
25 |
"
|
|
26 |
|
0
|
27 |
|
|
28 |
Font subclass:#HersheyFont
|
369
|
29 |
instanceVariableNames:'glyphs scale'
|
|
30 |
classVariableNames:'GlyphData'
|
|
31 |
poolDictionaries:''
|
|
32 |
category:'Graphics-Support'
|
0
|
33 |
!
|
|
34 |
|
86
|
35 |
HersheyFont comment:'
|
|
36 |
Support for hershey fonts is based on a freeware cd-rom distribution
|
0
|
37 |
by DEC. This disk contains the hershey outlines and glyph maps of
|
|
38 |
the following fonts:
|
|
39 |
|
|
40 |
Fonts:
|
86
|
41 |
Roman: Plain, Simplex, Duplex, Complex Small, Complex, Triplex
|
0
|
42 |
Italic: Complex Small, Complex, Triplex
|
|
43 |
Script: Simplex, Complex
|
|
44 |
Gothic: German, English, Italian
|
86
|
45 |
Greek: Plain, Simplex, Complex Small, Complex
|
0
|
46 |
Cyrillic: Complex
|
|
47 |
|
|
48 |
Symbols:
|
86
|
49 |
Mathematical
|
|
50 |
Daggers
|
|
51 |
Astronomical
|
|
52 |
Astrological
|
|
53 |
Musical
|
|
54 |
Typesetting (ffl,fl,fi sorts of things)
|
|
55 |
Miscellaneous:
|
|
56 |
- Playing card suits
|
|
57 |
- Meteorology
|
|
58 |
- Graphics (lines, curves)
|
|
59 |
- Electrical
|
|
60 |
- Geometric (shapes)
|
|
61 |
- Cartographic
|
|
62 |
- Naval
|
|
63 |
- Agricultural
|
|
64 |
- Highways
|
|
65 |
- Etc...
|
0
|
66 |
|
|
67 |
Legal notice:
|
86
|
68 |
This distribution of the Hershey Fonts may be used by anyone for
|
|
69 |
any purpose, commercial or otherwise, providing that:
|
|
70 |
|
|
71 |
1. The following acknowledgements must be distributed with
|
|
72 |
the font data:
|
|
73 |
- The Hershey Fonts were originally created by Dr.
|
|
74 |
A. V. Hershey while working at the U. S.
|
|
75 |
National Bureau of Standards.
|
|
76 |
- The format of the Font data in this distribution
|
|
77 |
was originally created by
|
|
78 |
James Hurt
|
|
79 |
Cognition, Inc.
|
|
80 |
900 Technology Park Drive
|
|
81 |
Billerica, MA 01821
|
|
82 |
(mit-eddie!!ci-dandelion!!hurt)
|
|
83 |
|
|
84 |
2. The font data in this distribution may be converted into
|
|
85 |
any other format *EXCEPT* the format distributed by
|
|
86 |
the U.S. NTIS (which organization holds the rights
|
|
87 |
to the distribution and use of the font data in that
|
|
88 |
particular format). Not that anybody would really
|
|
89 |
*want* to use their format... each point is described
|
|
90 |
in eight bytes as "xxx yyy:", where xxx and yyy are
|
|
91 |
the coordinate values as ASCII numbers.
|
0
|
92 |
'!
|
|
93 |
|
369
|
94 |
!HersheyFont class methodsFor:'documentation'!
|
|
95 |
|
|
96 |
copyright
|
|
97 |
"
|
|
98 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
99 |
All Rights Reserved
|
|
100 |
|
|
101 |
This software is furnished under a license and may be used
|
|
102 |
only in accordance with the terms of that license and with the
|
|
103 |
inclusion of the above copyright notice. This software may not
|
|
104 |
be provided or otherwise made available to, or used by, any
|
|
105 |
other person. No title to or ownership of the software is
|
|
106 |
hereby transferred.
|
|
107 |
|
|
108 |
This is a demo example:
|
|
109 |
|
|
110 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
|
|
111 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
112 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
113 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
|
|
114 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
115 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
116 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
117 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
118 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
119 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
120 |
SUCH DAMAGE.
|
|
121 |
"
|
|
122 |
|
|
123 |
!
|
|
124 |
|
|
125 |
documentation
|
|
126 |
"
|
|
127 |
HersheyFont provides (limited) support to draw characters
|
|
128 |
from the hershey font data file 'hersh.oc'
|
|
129 |
(which is available via ftp and must be aquired from elsewhere).
|
|
130 |
|
|
131 |
This is a demo class - not maintained or meant for productive use.
|
|
132 |
Notice: this is a very old demo - it should be rewritten to honor
|
|
133 |
the FontDescription protocol (see BitmapFont as a better example).
|
|
134 |
|
|
135 |
[see also:]
|
|
136 |
BitmapFont FontDescription Font
|
|
137 |
|
|
138 |
|
|
139 |
Support for hershey fonts is based on a freeware cd-rom distribution
|
|
140 |
by DEC. This disk contains the hershey outlines and glyph maps of
|
|
141 |
the following fonts:
|
0
|
142 |
|
369
|
143 |
Fonts:
|
|
144 |
Roman: Plain, Simplex, Duplex, Complex Small, Complex, Triplex
|
|
145 |
Italic: Complex Small, Complex, Triplex
|
|
146 |
Script: Simplex, Complex
|
|
147 |
Gothic: German, English, Italian
|
|
148 |
Greek: Plain, Simplex, Complex Small, Complex
|
|
149 |
Cyrillic: Complex
|
|
150 |
|
|
151 |
Symbols:
|
|
152 |
Mathematical
|
|
153 |
Daggers
|
|
154 |
Astronomical
|
|
155 |
Astrological
|
|
156 |
Musical
|
|
157 |
Typesetting (ffl,fl,fi sorts of things)
|
|
158 |
Miscellaneous:
|
|
159 |
- Playing card suits
|
|
160 |
- Meteorology
|
|
161 |
- Graphics (lines, curves)
|
|
162 |
- Electrical
|
|
163 |
- Geometric (shapes)
|
|
164 |
- Cartographic
|
|
165 |
- Naval
|
|
166 |
- Agricultural
|
|
167 |
- Highways
|
|
168 |
- Etc...
|
86
|
169 |
|
369
|
170 |
Legal notice:
|
|
171 |
This distribution of the Hershey Fonts may be used by anyone for
|
|
172 |
any purpose, commercial or otherwise, providing that:
|
|
173 |
|
|
174 |
1. The following acknowledgements must be distributed with
|
|
175 |
the font data:
|
|
176 |
- The Hershey Fonts were originally created by Dr.
|
|
177 |
A. V. Hershey while working at the U. S.
|
|
178 |
National Bureau of Standards.
|
|
179 |
- The format of the Font data in this distribution
|
|
180 |
was originally created by
|
|
181 |
James Hurt
|
|
182 |
Cognition, Inc.
|
|
183 |
900 Technology Park Drive
|
|
184 |
Billerica, MA 01821
|
|
185 |
(mit-eddie!!ci-dandelion!!hurt)
|
|
186 |
|
|
187 |
2. The font data in this distribution may be converted into
|
|
188 |
any other format *EXCEPT* the format distributed by
|
|
189 |
the U.S. NTIS (which organization holds the rights
|
|
190 |
to the distribution and use of the font data in that
|
|
191 |
particular format). Not that anybody would really
|
|
192 |
*want* to use their format... each point is described
|
|
193 |
in eight bytes as 'xxx yyy:', where xxx and yyy are
|
|
194 |
the coordinate values as ASCII numbers.
|
|
195 |
"
|
86
|
196 |
!
|
|
197 |
|
369
|
198 |
examples
|
|
199 |
"
|
|
200 |
|aView|
|
|
201 |
|
|
202 |
aView := View new extent:500@200.
|
|
203 |
aView openAndWait.
|
|
204 |
aView backingStore:true.
|
|
205 |
|
|
206 |
HersheyFont showFont:(HersheyFont family:'hershey-astrology'
|
|
207 |
face:'bold'
|
|
208 |
style:'roman'
|
|
209 |
size:24) in:aView
|
|
210 |
|
|
211 |
HersheyFont showFont:(HersheyFont family:'hershey-music'
|
|
212 |
face:'bold'
|
|
213 |
style:'roman'
|
|
214 |
size:24) in:aView
|
|
215 |
|
|
216 |
HersheyFont showFont:(HersheyFont family:'hershey-meteorology'
|
|
217 |
face:'medium'
|
|
218 |
style:'roman'
|
|
219 |
size:24) in:aView
|
|
220 |
|
|
221 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
|
222 |
face:'medium'
|
|
223 |
style:'roman'
|
|
224 |
size:10) in:aView
|
|
225 |
|
|
226 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
|
227 |
face:'medium'
|
|
228 |
style:'roman'
|
|
229 |
size:24) in:aView
|
|
230 |
|
|
231 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
|
232 |
face:'medium'
|
|
233 |
style:'roman'
|
|
234 |
size:48) in:aView
|
0
|
235 |
|
369
|
236 |
HersheyFont showFont:(HersheyFont family:'hershey-script'
|
|
237 |
face:'bold'
|
|
238 |
style:'roman'
|
|
239 |
size:24) in:aView
|
|
240 |
|
|
241 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
242 |
face:'medium'
|
|
243 |
style:'roman'
|
|
244 |
size:12) in:aView
|
|
245 |
|
|
246 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
247 |
face:'medium'
|
|
248 |
style:'roman'
|
|
249 |
size:24) in:aView
|
|
250 |
|
|
251 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
252 |
face:'medium'
|
|
253 |
style:'roman'
|
|
254 |
size:48) in:aView
|
|
255 |
|
|
256 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
257 |
face:'bold'
|
|
258 |
style:'roman'
|
|
259 |
size:24) in:aView
|
|
260 |
|
|
261 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
262 |
face:'medium'
|
|
263 |
style:'italic'
|
|
264 |
size:24) in:aView
|
|
265 |
|
|
266 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
|
267 |
face:'bold'
|
|
268 |
style:'italic'
|
|
269 |
size:24) in:aView
|
|
270 |
|
|
271 |
HersheyFont showFont:(HersheyFont family:'hershey-futura'
|
|
272 |
face:'medium'
|
|
273 |
style:'roman'
|
|
274 |
size:24) in:aView
|
|
275 |
|
|
276 |
HersheyFont showFont:(HersheyFont family:'hershey-futura'
|
|
277 |
face:'bold'
|
|
278 |
style:'roman'
|
|
279 |
size:24) in:aView
|
0
|
280 |
|
369
|
281 |
HersheyFont showFont:(HersheyFont family:'hershey-markers'
|
|
282 |
face:'medium'
|
|
283 |
style:'roman'
|
|
284 |
size:24) in:aView
|
|
285 |
|
|
286 |
HersheyFont showFont:(HersheyFont family:'hershey-math1'
|
|
287 |
face:'medium'
|
|
288 |
style:'roman'
|
|
289 |
size:24) in:aView
|
|
290 |
|
|
291 |
HersheyFont showFont:(HersheyFont family:'hershey-math2'
|
|
292 |
face:'medium'
|
|
293 |
style:'roman'
|
|
294 |
size:24) in:aView
|
|
295 |
|
|
296 |
HersheyFont showFont:(HersheyFont family:'hershey-symbol'
|
|
297 |
face:'medium'
|
|
298 |
style:'roman'
|
|
299 |
size:24) in:aView
|
|
300 |
|
|
301 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-italian'
|
|
302 |
face:'bold'
|
|
303 |
style:'roman'
|
|
304 |
size:24) in:aView
|
|
305 |
|
|
306 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-german'
|
|
307 |
face:'bold'
|
|
308 |
style:'roman'
|
|
309 |
size:24) in:aView
|
|
310 |
|
|
311 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-english'
|
|
312 |
face:'bold'
|
|
313 |
style:'roman'
|
|
314 |
size:24) in:aView
|
|
315 |
].
|
|
316 |
"
|
|
317 |
! !
|
|
318 |
|
|
319 |
!HersheyFont class methodsFor:'instance creation'!
|
|
320 |
|
|
321 |
family:family face:face style:style size:sz
|
|
322 |
"return a HersheyFont, given an ST/X-style fontName"
|
|
323 |
|
|
324 |
|fontNames|
|
0
|
325 |
|
369
|
326 |
fontNames := #(
|
|
327 |
('hershey-times' 'bold' 'roman' 'romant')
|
|
328 |
('hershey-times' 'medium' 'roman' 'romanc')
|
|
329 |
('hershey-times' 'medium' 'italic' 'italicc')
|
|
330 |
('hershey-times' 'bold' 'italic' 'italict')
|
|
331 |
('hershey-times' 'bold' 'greek' 'greekc')
|
|
332 |
|
|
333 |
('hershey-japan' 'bold' 'normal' 'japan')
|
0
|
334 |
|
369
|
335 |
('hershey-gothic-german' 'bold' 'roman' 'gothger')
|
|
336 |
('hershey-gothic-english' 'bold' 'roman' 'gotheng')
|
|
337 |
('hershey-gothic-italian' 'bold' 'roman' 'gothita')
|
|
338 |
|
|
339 |
('hershey-cursive' 'medium' 'roman' 'scripts')
|
|
340 |
('hershey-script' 'bold' 'roman' 'scriptc')
|
|
341 |
|
|
342 |
('hershey-futura' 'medium' 'roman' 'romans')
|
|
343 |
('hershey-futura' 'bold' 'roman' 'romand')
|
0
|
344 |
|
369
|
345 |
('hershey-markers' 'medium' 'roman' 'marker')
|
|
346 |
('hershey-math1' 'medium' 'roman' 'lowmat')
|
|
347 |
('hershey-math2' 'medium' 'roman' 'uppmat')
|
|
348 |
('hershey-symbol' 'medium' 'roman' 'symbol')
|
|
349 |
|
|
350 |
('hershey-astrology' 'bold' 'roman' 'astrol')
|
|
351 |
('hershey-meteorology' 'medium' 'roman' 'meteo')
|
|
352 |
('hershey-music' 'bold' 'roman' 'music')
|
|
353 |
).
|
0
|
354 |
|
369
|
355 |
fontNames do:[:entry |
|
|
356 |
(entry at:1) = family ifTrue:[
|
|
357 |
(entry at:2) = face ifTrue:[
|
|
358 |
(entry at:3) = style ifTrue:[
|
|
359 |
^ self name:(entry at:4) family:family face:face style:style size:sz
|
|
360 |
]
|
|
361 |
]
|
|
362 |
]
|
|
363 |
].
|
|
364 |
^ nil
|
0
|
365 |
|
369
|
366 |
"
|
|
367 |
HersheyFont family:'hershey-gothic-german' face:'medium' style:'roman' size:12
|
|
368 |
"
|
|
369 |
|
|
370 |
"Modified: 16.1.1997 / 18:19:47 / cg"
|
0
|
371 |
! !
|
|
372 |
|
|
373 |
!HersheyFont class methodsFor:'drawing'!
|
|
374 |
|
|
375 |
drawGlyph:glyphNo in:aGC x:x y:y scale:aScale
|
369
|
376 |
"draw a single character"
|
|
377 |
|
0
|
378 |
|moves c1 c2 xPos yPos nX nY draw w h savedLW|
|
|
379 |
|
86
|
380 |
moves := GlyphData at:glyphNo.
|
0
|
381 |
moves isNil ifTrue:[
|
369
|
382 |
Transcript showCR:('no glyph for ' , glyphNo printString).
|
|
383 |
^ self
|
0
|
384 |
].
|
|
385 |
savedLW := aGC lineWidth.
|
|
386 |
aGC lineWidth:(aScale * 2) rounded.
|
|
387 |
|
|
388 |
xPos := 0 "x".
|
|
389 |
yPos := 0 "y".
|
|
390 |
draw := false. "start with a skip"
|
|
391 |
w := ((moves at:1) asciiValue - $R asciiValue)" * aScale".
|
|
392 |
h := ($R asciiValue - (moves at:2) asciiValue)" negated * aScale".
|
|
393 |
w := w negated * aScale * 2.
|
|
394 |
h := h negated * aScale * 2.
|
|
395 |
|
|
396 |
3 to:(moves size) by:2 do:[:index |
|
369
|
397 |
c1 := moves at:index.
|
|
398 |
c2 := moves at:(index + 1).
|
|
399 |
c1 == Character space ifTrue:[
|
|
400 |
draw := false
|
|
401 |
] ifFalse:[
|
|
402 |
nX := "xPos +" ((c1 asciiValue - $R asciiValue) * aScale).
|
|
403 |
nY := "yPos +" (($R asciiValue - c2 asciiValue) negated * aScale).
|
|
404 |
draw ifTrue:[
|
|
405 |
aGC displayLineFromX:((x + xPos) truncated "rounded")
|
|
406 |
y:((y + yPos) truncated "rounded")
|
|
407 |
toX:((x + nX) truncated "rounded")
|
|
408 |
y:((y + nY) truncated "rounded").
|
|
409 |
].
|
|
410 |
xPos := nX.
|
|
411 |
yPos := nY.
|
|
412 |
draw := true
|
|
413 |
]
|
0
|
414 |
].
|
|
415 |
aGC lineWidth:savedLW
|
|
416 |
|
|
417 |
"Smalltalk at:#v put:nil.
|
|
418 |
Smalltalk at:#f put:nil.
|
|
419 |
v := View new realize.
|
|
420 |
|
|
421 |
v clear.
|
|
422 |
v font:(f := HersheyFont family:'hershey-times' face:'bold' style:'roman' size:12).
|
|
423 |
v displayString:'hello' x:50 y:50"
|
369
|
424 |
|
|
425 |
"Modified: 16.1.1997 / 18:22:10 / cg"
|
|
426 |
!
|
|
427 |
|
|
428 |
heightOfGlyph:glyphNo scale:aScale
|
|
429 |
"return the height of a single character"
|
|
430 |
|
|
431 |
|moves h|
|
|
432 |
|
|
433 |
moves := GlyphData at:glyphNo.
|
|
434 |
moves isNil ifTrue:[
|
|
435 |
Transcript showCR:('no glyph for ' , glyphNo printString).
|
|
436 |
^ 0
|
|
437 |
].
|
|
438 |
|
|
439 |
h := ($R asciiValue - (moves at:2) asciiValue)" negated * aScale".
|
|
440 |
h := h negated * aScale * 2.
|
|
441 |
^ h
|
|
442 |
|
|
443 |
"Modified: 16.1.1997 / 18:22:24 / cg"
|
0
|
444 |
!
|
|
445 |
|
|
446 |
widthOfGlyph:glyphNo scale:aScale
|
369
|
447 |
"return the width of a single character"
|
|
448 |
|
0
|
449 |
|moves w|
|
|
450 |
|
86
|
451 |
moves := GlyphData at:glyphNo.
|
0
|
452 |
moves isNil ifTrue:[
|
369
|
453 |
Transcript showCR:('no glyph for ' , glyphNo printString).
|
|
454 |
^ 0
|
0
|
455 |
].
|
|
456 |
|
|
457 |
w := ((moves at:1) asciiValue - $R asciiValue).
|
|
458 |
w := w negated * aScale * 2.
|
|
459 |
^ w
|
|
460 |
|
|
461 |
"HersheyFont widthOfGlyph:3401 scale:1"
|
|
462 |
|
369
|
463 |
"Modified: 16.1.1997 / 18:22:31 / cg"
|
0
|
464 |
! !
|
|
465 |
|
|
466 |
!HersheyFont class methodsFor:'examples'!
|
|
467 |
|
|
468 |
showFont:f in:aView
|
|
469 |
"
|
|
470 |
Smalltalk at:#aView put:(View new extent:500@200) realize.
|
|
471 |
aView backingStore:true.
|
|
472 |
HersheyFont showFont:(HersheyFont family:'hershey-astrology'
|
86
|
473 |
face:'bold'
|
|
474 |
style:'roman'
|
|
475 |
size:24) in:aView
|
0
|
476 |
|
|
477 |
HersheyFont showFont:(HersheyFont family:'hershey-music'
|
86
|
478 |
face:'bold'
|
|
479 |
style:'roman'
|
|
480 |
size:24) in:aView
|
0
|
481 |
|
|
482 |
HersheyFont showFont:(HersheyFont family:'hershey-meteorology'
|
86
|
483 |
face:'medium'
|
|
484 |
style:'roman'
|
|
485 |
size:24) in:aView
|
0
|
486 |
|
|
487 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
86
|
488 |
face:'medium'
|
|
489 |
style:'roman'
|
|
490 |
size:10) in:aView
|
0
|
491 |
|
|
492 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
86
|
493 |
face:'medium'
|
|
494 |
style:'roman'
|
|
495 |
size:24) in:aView
|
0
|
496 |
|
|
497 |
HersheyFont showFont:(HersheyFont family:'hershey-cursive'
|
86
|
498 |
face:'medium'
|
|
499 |
style:'roman'
|
|
500 |
size:48) in:aView
|
0
|
501 |
|
|
502 |
HersheyFont showFont:(HersheyFont family:'hershey-script'
|
86
|
503 |
face:'bold'
|
|
504 |
style:'roman'
|
|
505 |
size:24) in:aView
|
0
|
506 |
|
|
507 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
508 |
face:'medium'
|
|
509 |
style:'roman'
|
|
510 |
size:12) in:aView
|
0
|
511 |
|
|
512 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
513 |
face:'medium'
|
|
514 |
style:'roman'
|
|
515 |
size:24) in:aView
|
0
|
516 |
|
|
517 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
518 |
face:'medium'
|
|
519 |
style:'roman'
|
|
520 |
size:48) in:aView
|
0
|
521 |
|
|
522 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
523 |
face:'bold'
|
|
524 |
style:'roman'
|
|
525 |
size:24) in:aView
|
0
|
526 |
|
|
527 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
528 |
face:'medium'
|
|
529 |
style:'italic'
|
|
530 |
size:24) in:aView
|
0
|
531 |
|
|
532 |
HersheyFont showFont:(HersheyFont family:'hershey-times'
|
86
|
533 |
face:'bold'
|
|
534 |
style:'italic'
|
|
535 |
size:24) in:aView
|
0
|
536 |
|
|
537 |
HersheyFont showFont:(HersheyFont family:'hershey-futura'
|
86
|
538 |
face:'medium'
|
|
539 |
style:'roman'
|
|
540 |
size:24) in:aView
|
0
|
541 |
|
|
542 |
HersheyFont showFont:(HersheyFont family:'hershey-futura'
|
86
|
543 |
face:'bold'
|
|
544 |
style:'roman'
|
|
545 |
size:24) in:aView
|
0
|
546 |
|
|
547 |
HersheyFont showFont:(HersheyFont family:'hershey-markers'
|
86
|
548 |
face:'medium'
|
|
549 |
style:'roman'
|
|
550 |
size:24) in:aView
|
0
|
551 |
|
|
552 |
HersheyFont showFont:(HersheyFont family:'hershey-math1'
|
86
|
553 |
face:'medium'
|
|
554 |
style:'roman'
|
|
555 |
size:24) in:aView
|
0
|
556 |
|
|
557 |
HersheyFont showFont:(HersheyFont family:'hershey-math2'
|
86
|
558 |
face:'medium'
|
|
559 |
style:'roman'
|
|
560 |
size:24) in:aView
|
0
|
561 |
|
|
562 |
HersheyFont showFont:(HersheyFont family:'hershey-symbol'
|
86
|
563 |
face:'medium'
|
|
564 |
style:'roman'
|
|
565 |
size:24) in:aView
|
0
|
566 |
|
|
567 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-italian'
|
86
|
568 |
face:'bold'
|
|
569 |
style:'roman'
|
|
570 |
size:24) in:aView
|
0
|
571 |
|
|
572 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-german'
|
86
|
573 |
face:'bold'
|
|
574 |
style:'roman'
|
|
575 |
size:24) in:aView
|
0
|
576 |
|
|
577 |
HersheyFont showFont:(HersheyFont family:'hershey-gothic-english'
|
86
|
578 |
face:'bold'
|
|
579 |
style:'roman'
|
|
580 |
size:24) in:aView
|
0
|
581 |
"
|
|
582 |
|
|
583 |
|x y dy|
|
|
584 |
|
|
585 |
dy := f heightOn:aView device.
|
|
586 |
aView clear.
|
|
587 |
x := 100. y := dy.
|
|
588 |
32 to:47 do:[:i |
|
86
|
589 |
f drawCharacter:i in:aView x:x y:y.
|
|
590 |
x := x + 30
|
0
|
591 |
].
|
|
592 |
|
|
593 |
x := 100. y := y + dy.
|
|
594 |
48 to:57 do:[:i |
|
86
|
595 |
f drawCharacter:i in:aView x:x y:y.
|
|
596 |
x := x + 30
|
0
|
597 |
].
|
|
598 |
|
|
599 |
x := 100. y := y + dy.
|
|
600 |
58 to:64 do:[:i |
|
86
|
601 |
f drawCharacter:i in:aView x:x y:y.
|
|
602 |
x := x + 30
|
0
|
603 |
].
|
|
604 |
|
|
605 |
x := 100. y := y + dy.
|
|
606 |
65 to:90 do:[:i |
|
86
|
607 |
f drawCharacter:i in:aView x:x y:y.
|
|
608 |
x := x + 30
|
0
|
609 |
].
|
|
610 |
|
|
611 |
x := 100. y := y + dy.
|
|
612 |
91 to:96 do:[:i |
|
86
|
613 |
f drawCharacter:i in:aView x:x y:y.
|
|
614 |
x := x + 30
|
0
|
615 |
].
|
|
616 |
|
|
617 |
x := 100. y := y + dy.
|
|
618 |
97 to:122 do:[:i |
|
86
|
619 |
f drawCharacter:i in:aView x:x y:y.
|
|
620 |
x := x + 30
|
0
|
621 |
].
|
|
622 |
|
|
623 |
x := 100. y := y + dy.
|
|
624 |
123 to:127 do:[:i |
|
86
|
625 |
f drawCharacter:i in:aView x:x y:y.
|
|
626 |
x := x + 30
|
0
|
627 |
]
|
|
628 |
! !
|
|
629 |
|
369
|
630 |
!HersheyFont class methodsFor:'private'!
|
|
631 |
|
|
632 |
hersheyFontPath
|
|
633 |
"the directory, where the glyph data is found;
|
|
634 |
you may have to modify this a bit ..."
|
|
635 |
|
|
636 |
^ '/usr/local/fonts/hershey/data/hersh.oc'
|
|
637 |
|
|
638 |
"Modified: 16.1.1997 / 18:24:35 / cg"
|
|
639 |
!
|
|
640 |
|
|
641 |
name:aFileName family:family face:face style:style size:sz
|
|
642 |
"return a font with glyph-data from aFileName"
|
|
643 |
|
|
644 |
|newFont|
|
|
645 |
|
|
646 |
newFont := self basicNew readGlyphsFrom:aFileName.
|
|
647 |
newFont family:family face:face style:style size:sz.
|
|
648 |
^ newFont
|
|
649 |
|
|
650 |
"HersheyFont name:'gothger'"
|
|
651 |
!
|
|
652 |
|
|
653 |
readDataFile
|
|
654 |
|inStream b5 b3 chars moves glyphNo nPairs char1 char2 index|
|
|
655 |
|
|
656 |
inStream := FileStream readonlyFileNamed:(self hersheyFontPath).
|
|
657 |
inStream isNil ifTrue:[
|
|
658 |
self error:'no glyph data file ''' , self hersheyFontPath , ''' found.'.
|
|
659 |
^ self
|
|
660 |
].
|
|
661 |
|
|
662 |
GlyphData isNil ifTrue:[
|
|
663 |
Transcript showCR:'reading hershey glyphs ...'.
|
|
664 |
|
|
665 |
GlyphData := OrderedCollection new:4000; grow:4000.
|
|
666 |
b5 := String new:5.
|
|
667 |
b3 := String new:3.
|
|
668 |
[inStream atEnd] whileFalse:[
|
|
669 |
chars := inStream nextBytes:5 into:b5.
|
|
670 |
glyphNo := Number readFromString:b5.
|
|
671 |
chars := inStream nextBytes:3 into:b3.
|
|
672 |
nPairs := Number readFromString:b3.
|
|
673 |
moves := String new:(nPairs * 2).
|
|
674 |
index := 1.
|
|
675 |
1 to:nPairs do:[:i |
|
|
676 |
char1 := inStream next.
|
|
677 |
char1 == Character nl ifTrue:[
|
|
678 |
char1 := inStream next
|
|
679 |
].
|
|
680 |
char2 := inStream next.
|
|
681 |
char2 == Character nl ifTrue:[
|
|
682 |
char2 := inStream next
|
|
683 |
].
|
|
684 |
moves at:index put:char1.
|
|
685 |
index := index + 1.
|
|
686 |
moves at:index put:char2.
|
|
687 |
index := index + 1
|
|
688 |
].
|
|
689 |
GlyphData at:glyphNo put:moves.
|
|
690 |
[inStream peek == Character nl] whileTrue:[inStream next]
|
|
691 |
].
|
|
692 |
inStream close
|
|
693 |
]
|
|
694 |
|
|
695 |
"HersheyFont readDataFile"
|
|
696 |
|
|
697 |
"Modified: 16.1.1997 / 18:24:15 / cg"
|
|
698 |
! !
|
|
699 |
|
|
700 |
!HersheyFont methodsFor:'drawing'!
|
|
701 |
|
|
702 |
displayString:aString from:index1 to:index2 x:x0 y:y in:aGC
|
|
703 |
|x|
|
|
704 |
|
|
705 |
x := x0.
|
|
706 |
index1 to:index2 do:[:index |
|
|
707 |
self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y.
|
|
708 |
x := x + (self widthOfCharacter:(aString at:index) asciiValue)
|
|
709 |
]
|
|
710 |
!
|
|
711 |
|
|
712 |
displayString:aString x:x0 y:y in:aGC
|
|
713 |
|x|
|
|
714 |
|
|
715 |
x := x0.
|
|
716 |
aString do:[:character |
|
|
717 |
self drawCharacter:character asciiValue in:aGC x:x y:y.
|
|
718 |
x := x + (self widthOfCharacter:character asciiValue)
|
|
719 |
]
|
|
720 |
!
|
|
721 |
|
|
722 |
drawCharacter:ascii in:aGC x:x y:y
|
|
723 |
|glyphNo|
|
|
724 |
|
|
725 |
(ascii between:32 and:127) ifFalse:[^ self].
|
|
726 |
glyphNo := glyphs at:(ascii - 32 + 1).
|
|
727 |
glyphNo isNil ifTrue:[^ self].
|
|
728 |
self class drawGlyph:glyphNo in:aGC x:x y:y scale:scale
|
|
729 |
! !
|
|
730 |
|
0
|
731 |
!HersheyFont methodsFor:'private'!
|
|
732 |
|
369
|
733 |
family:fam face:fac style:st size:sz
|
|
734 |
family := fam.
|
|
735 |
face := fac.
|
|
736 |
style := st.
|
|
737 |
size := sz.
|
|
738 |
scale := sz / 24
|
|
739 |
!
|
|
740 |
|
0
|
741 |
readGlyphsFrom:aFileName
|
|
742 |
"read glyph definitions from aFileName"
|
|
743 |
|
|
744 |
|inStream ascii index1 index2|
|
|
745 |
|
|
746 |
self class readDataFile.
|
|
747 |
glyphs := Array new:(256 - 32).
|
|
748 |
inStream := FileStream readonlyFileNamed:('/LocalLibrary/Fonts/hershey/fonts/',aFileName,'.hmp').
|
|
749 |
ascii := 32.
|
|
750 |
[inStream atEnd] whileFalse:[
|
86
|
751 |
index1 := Number readFrom:inStream.
|
|
752 |
index2 := Number readFrom:inStream.
|
|
753 |
index2 == 0 ifTrue:[
|
|
754 |
index2 := index1
|
|
755 |
].
|
|
756 |
index1 to:index2 do:[:pos |
|
|
757 |
glyphs at:(ascii - 32 + 1) put:pos.
|
|
758 |
ascii := ascii + 1
|
|
759 |
].
|
|
760 |
inStream skipSeparators
|
0
|
761 |
].
|
|
762 |
inStream close.
|
|
763 |
^ self
|
|
764 |
!
|
|
765 |
|
|
766 |
scale:aScale
|
|
767 |
scale := aScale
|
|
768 |
! !
|
|
769 |
|
|
770 |
!HersheyFont methodsFor:'queries'!
|
|
771 |
|
|
772 |
ascentOn:aDevice
|
|
773 |
^ 0
|
|
774 |
!
|
|
775 |
|
|
776 |
descentOn:aDevice
|
|
777 |
^ self heightOn:aDevice
|
|
778 |
!
|
|
779 |
|
|
780 |
heightOfCharacter:ascii
|
|
781 |
|glyphNo|
|
|
782 |
|
|
783 |
(ascii between:32 and:127) ifFalse:[^ 0].
|
|
784 |
glyphNo := glyphs at:(ascii - 32 + 1).
|
|
785 |
glyphNo isNil ifTrue:[^ 0].
|
|
786 |
^ self class heightOfGlyph:glyphNo scale:scale
|
|
787 |
!
|
|
788 |
|
369
|
789 |
heightOn:aDevice
|
|
790 |
^ scale * (24 + 12)
|
|
791 |
!
|
|
792 |
|
|
793 |
on:aDevice
|
|
794 |
^ self
|
|
795 |
!
|
|
796 |
|
|
797 |
widthOf:aString
|
|
798 |
|sumW|
|
|
799 |
|
|
800 |
sumW := 0.
|
|
801 |
aString do:[:character |
|
|
802 |
sumW := sumW + (self widthOfCharacter:character asciiValue)
|
|
803 |
].
|
|
804 |
^ sumW
|
|
805 |
!
|
|
806 |
|
0
|
807 |
widthOf:aString from:start to:stop
|
|
808 |
"return the width of a substring"
|
|
809 |
|
|
810 |
|sumW|
|
|
811 |
|
|
812 |
(stop < start) ifTrue:[^ 0].
|
|
813 |
sumW := 0.
|
|
814 |
start to:stop do:[:index |
|
86
|
815 |
sumW := sumW + (self widthOfCharacter:(aString at:index) asciiValue)
|
0
|
816 |
].
|
|
817 |
^ sumW
|
|
818 |
!
|
|
819 |
|
369
|
820 |
widthOfCharacter:ascii
|
0
|
821 |
|glyphNo|
|
|
822 |
|
369
|
823 |
(ascii between:32 and:127) ifFalse:[^ 0].
|
0
|
824 |
glyphNo := glyphs at:(ascii - 32 + 1).
|
369
|
825 |
glyphNo isNil ifTrue:[^ 0].
|
|
826 |
^ self class widthOfGlyph:glyphNo scale:scale
|
|
827 |
! !
|
0
|
828 |
|
369
|
829 |
!HersheyFont class methodsFor:'documentation'!
|
0
|
830 |
|
369
|
831 |
version
|
|
832 |
^ '$Header: /cvs/stx/stx/libview2/HersheyFont.st,v 1.5 1997-01-16 17:26:21 cg Exp $'
|
0
|
833 |
! !
|