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