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