author | tz |
Sat, 07 Feb 1998 16:57:39 +0100 | |
changeset 834 | ac1655bd31bb |
parent 370 | 587c6dfc87d8 |
child 1580 | 84e53294af20 |
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 |
|
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 |
|x y dy| |
|
470 |
||
471 |
dy := f heightOn:aView device. |
|
472 |
aView clear. |
|
473 |
x := 100. y := dy. |
|
474 |
32 to:47 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
475 |
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
|
476 |
x := x + 30 |
0 | 477 |
]. |
478 |
||
479 |
x := 100. y := y + dy. |
|
480 |
48 to:57 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
481 |
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
|
482 |
x := x + 30 |
0 | 483 |
]. |
484 |
||
485 |
x := 100. y := y + dy. |
|
486 |
58 to:64 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
487 |
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
|
488 |
x := x + 30 |
0 | 489 |
]. |
490 |
||
491 |
x := 100. y := y + dy. |
|
492 |
65 to:90 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
493 |
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
|
494 |
x := x + 30 |
0 | 495 |
]. |
496 |
||
497 |
x := 100. y := y + dy. |
|
498 |
91 to:96 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
499 |
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
|
500 |
x := x + 30 |
0 | 501 |
]. |
502 |
||
503 |
x := 100. y := y + dy. |
|
504 |
97 to:122 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
505 |
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
|
506 |
x := x + 30 |
0 | 507 |
]. |
508 |
||
509 |
x := 100. y := y + dy. |
|
510 |
123 to:127 do:[:i | |
|
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
511 |
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
|
512 |
x := x + 30 |
0 | 513 |
] |
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
514 |
|
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
515 |
"Modified: 16.1.1997 / 18:27:15 / cg" |
0 | 516 |
! ! |
517 |
||
369 | 518 |
!HersheyFont class methodsFor:'private'! |
519 |
||
520 |
hersheyFontPath |
|
521 |
"the directory, where the glyph data is found; |
|
522 |
you may have to modify this a bit ..." |
|
523 |
||
524 |
^ '/usr/local/fonts/hershey/data/hersh.oc' |
|
525 |
||
526 |
"Modified: 16.1.1997 / 18:24:35 / cg" |
|
527 |
! |
|
528 |
||
529 |
name:aFileName family:family face:face style:style size:sz |
|
530 |
"return a font with glyph-data from aFileName" |
|
531 |
||
532 |
|newFont| |
|
533 |
||
534 |
newFont := self basicNew readGlyphsFrom:aFileName. |
|
535 |
newFont family:family face:face style:style size:sz. |
|
536 |
^ newFont |
|
537 |
||
538 |
"HersheyFont name:'gothger'" |
|
539 |
! |
|
540 |
||
541 |
readDataFile |
|
542 |
|inStream b5 b3 chars moves glyphNo nPairs char1 char2 index| |
|
543 |
||
544 |
inStream := FileStream readonlyFileNamed:(self hersheyFontPath). |
|
545 |
inStream isNil ifTrue:[ |
|
546 |
self error:'no glyph data file ''' , self hersheyFontPath , ''' found.'. |
|
547 |
^ self |
|
548 |
]. |
|
549 |
||
550 |
GlyphData isNil ifTrue:[ |
|
551 |
Transcript showCR:'reading hershey glyphs ...'. |
|
552 |
||
553 |
GlyphData := OrderedCollection new:4000; grow:4000. |
|
554 |
b5 := String new:5. |
|
555 |
b3 := String new:3. |
|
556 |
[inStream atEnd] whileFalse:[ |
|
557 |
chars := inStream nextBytes:5 into:b5. |
|
558 |
glyphNo := Number readFromString:b5. |
|
559 |
chars := inStream nextBytes:3 into:b3. |
|
560 |
nPairs := Number readFromString:b3. |
|
561 |
moves := String new:(nPairs * 2). |
|
562 |
index := 1. |
|
563 |
1 to:nPairs do:[:i | |
|
564 |
char1 := inStream next. |
|
565 |
char1 == Character nl ifTrue:[ |
|
566 |
char1 := inStream next |
|
567 |
]. |
|
568 |
char2 := inStream next. |
|
569 |
char2 == Character nl ifTrue:[ |
|
570 |
char2 := inStream next |
|
571 |
]. |
|
572 |
moves at:index put:char1. |
|
573 |
index := index + 1. |
|
574 |
moves at:index put:char2. |
|
575 |
index := index + 1 |
|
576 |
]. |
|
577 |
GlyphData at:glyphNo put:moves. |
|
578 |
[inStream peek == Character nl] whileTrue:[inStream next] |
|
579 |
]. |
|
580 |
inStream close |
|
581 |
] |
|
582 |
||
583 |
"HersheyFont readDataFile" |
|
584 |
||
585 |
"Modified: 16.1.1997 / 18:24:15 / cg" |
|
586 |
! ! |
|
587 |
||
588 |
!HersheyFont methodsFor:'drawing'! |
|
589 |
||
590 |
displayString:aString from:index1 to:index2 x:x0 y:y in:aGC |
|
591 |
|x| |
|
592 |
||
593 |
x := x0. |
|
594 |
index1 to:index2 do:[:index | |
|
595 |
self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y. |
|
596 |
x := x + (self widthOfCharacter:(aString at:index) asciiValue) |
|
597 |
] |
|
598 |
! |
|
599 |
||
600 |
displayString:aString x:x0 y:y in:aGC |
|
601 |
|x| |
|
602 |
||
603 |
x := x0. |
|
604 |
aString do:[:character | |
|
605 |
self drawCharacter:character asciiValue in:aGC x:x y:y. |
|
606 |
x := x + (self widthOfCharacter:character asciiValue) |
|
607 |
] |
|
608 |
! |
|
609 |
||
610 |
drawCharacter:ascii in:aGC x:x y:y |
|
611 |
|glyphNo| |
|
612 |
||
613 |
(ascii between:32 and:127) ifFalse:[^ self]. |
|
614 |
glyphNo := glyphs at:(ascii - 32 + 1). |
|
615 |
glyphNo isNil ifTrue:[^ self]. |
|
616 |
self class drawGlyph:glyphNo in:aGC x:x y:y scale:scale |
|
617 |
! ! |
|
618 |
||
0 | 619 |
!HersheyFont methodsFor:'private'! |
620 |
||
369 | 621 |
family:fam face:fac style:st size:sz |
622 |
family := fam. |
|
623 |
face := fac. |
|
624 |
style := st. |
|
625 |
size := sz. |
|
626 |
scale := sz / 24 |
|
627 |
! |
|
628 |
||
0 | 629 |
readGlyphsFrom:aFileName |
630 |
"read glyph definitions from aFileName" |
|
631 |
||
632 |
|inStream ascii index1 index2| |
|
633 |
||
634 |
self class readDataFile. |
|
635 |
glyphs := Array new:(256 - 32). |
|
636 |
inStream := FileStream readonlyFileNamed:('/LocalLibrary/Fonts/hershey/fonts/',aFileName,'.hmp'). |
|
637 |
ascii := 32. |
|
638 |
[inStream atEnd] whileFalse:[ |
|
86 | 639 |
index1 := Number readFrom:inStream. |
640 |
index2 := Number readFrom:inStream. |
|
641 |
index2 == 0 ifTrue:[ |
|
642 |
index2 := index1 |
|
643 |
]. |
|
644 |
index1 to:index2 do:[:pos | |
|
645 |
glyphs at:(ascii - 32 + 1) put:pos. |
|
646 |
ascii := ascii + 1 |
|
647 |
]. |
|
648 |
inStream skipSeparators |
|
0 | 649 |
]. |
650 |
inStream close. |
|
651 |
^ self |
|
652 |
! |
|
653 |
||
654 |
scale:aScale |
|
655 |
scale := aScale |
|
656 |
! ! |
|
657 |
||
658 |
!HersheyFont methodsFor:'queries'! |
|
659 |
||
660 |
ascentOn:aDevice |
|
661 |
^ 0 |
|
662 |
! |
|
663 |
||
664 |
descentOn:aDevice |
|
665 |
^ self heightOn:aDevice |
|
666 |
! |
|
667 |
||
668 |
heightOfCharacter:ascii |
|
669 |
|glyphNo| |
|
670 |
||
671 |
(ascii between:32 and:127) ifFalse:[^ 0]. |
|
672 |
glyphNo := glyphs at:(ascii - 32 + 1). |
|
673 |
glyphNo isNil ifTrue:[^ 0]. |
|
674 |
^ self class heightOfGlyph:glyphNo scale:scale |
|
675 |
! |
|
676 |
||
369 | 677 |
heightOn:aDevice |
678 |
^ scale * (24 + 12) |
|
679 |
! |
|
680 |
||
681 |
on:aDevice |
|
682 |
^ self |
|
683 |
! |
|
684 |
||
685 |
widthOf:aString |
|
686 |
|sumW| |
|
687 |
||
688 |
sumW := 0. |
|
689 |
aString do:[:character | |
|
690 |
sumW := sumW + (self widthOfCharacter:character asciiValue) |
|
691 |
]. |
|
692 |
^ sumW |
|
693 |
! |
|
694 |
||
0 | 695 |
widthOf:aString from:start to:stop |
696 |
"return the width of a substring" |
|
697 |
||
698 |
|sumW| |
|
699 |
||
700 |
(stop < start) ifTrue:[^ 0]. |
|
701 |
sumW := 0. |
|
702 |
start to:stop do:[:index | |
|
86 | 703 |
sumW := sumW + (self widthOfCharacter:(aString at:index) asciiValue) |
0 | 704 |
]. |
705 |
^ sumW |
|
706 |
! |
|
707 |
||
369 | 708 |
widthOfCharacter:ascii |
0 | 709 |
|glyphNo| |
710 |
||
369 | 711 |
(ascii between:32 and:127) ifFalse:[^ 0]. |
0 | 712 |
glyphNo := glyphs at:(ascii - 32 + 1). |
369 | 713 |
glyphNo isNil ifTrue:[^ 0]. |
714 |
^ self class widthOfGlyph:glyphNo scale:scale |
|
715 |
! ! |
|
0 | 716 |
|
369 | 717 |
!HersheyFont class methodsFor:'documentation'! |
0 | 718 |
|
369 | 719 |
version |
370
587c6dfc87d8
forced checkin / source container change from HersheyFont.st
Claus Gittinger <cg@exept.de>
parents:
369
diff
changeset
|
720 |
^ '$Header: /cvs/stx/stx/libview2/HersheyFont.st,v 1.6 1997-01-16 17:27:36 cg Exp $' |
0 | 721 |
! ! |