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