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