author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 15:28:14 +0200 | |
changeset 9038 | dd177fea6408 |
parent 9035 | f07b260cf6b5 |
permissions | -rw-r--r-- |
9035 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1088 | 3 |
" |
4 |
COPYRIGHT (c) 1994 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 |
" |
|
3659 | 28 |
"{ Package: 'stx:libview' }" |
29 |
||
6931 | 30 |
"{ NameSpace: Smalltalk }" |
31 |
||
1088 | 32 |
FontDescription subclass:#BitmapFont |
3672 | 33 |
instanceVariableNames:'characterBitmaps ascent descent maxWidth maxHeight' |
1088 | 34 |
classVariableNames:'' |
35 |
poolDictionaries:'' |
|
36 |
category:'Graphics-Support' |
|
37 |
! |
|
38 |
||
39 |
!BitmapFont class methodsFor:'documentation'! |
|
40 |
||
41 |
copyright |
|
42 |
" |
|
43 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
44 |
All Rights Reserved |
|
45 |
||
46 |
This software is furnished under a license and may be used |
|
47 |
only in accordance with the terms of that license and with the |
|
48 |
inclusion of the above copyright notice. This software may not |
|
49 |
be provided or otherwise made available to, or used by, any |
|
50 |
other person. No title to or ownership of the software is |
|
51 |
hereby transferred. |
|
52 |
||
53 |
This is a demo example: |
|
54 |
||
55 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND |
|
56 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
57 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
58 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE |
|
59 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
60 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
61 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
62 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
63 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
64 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
65 |
SUCH DAMAGE. |
|
66 |
" |
|
67 |
! |
|
68 |
||
69 |
documentation |
|
70 |
" |
|
71 |
This class demonstrates, that it is possible to define your own |
|
72 |
renderers for fonts - you could even write a class which reads |
|
73 |
a truetype font from a ttf file and display those |
|
74 |
(maybe someone finds the time to do this |
|
75 |
and provides the code to the public domain ?) |
|
76 |
||
77 |
Here is a simple & sample implementation of private bitmap fonts; |
|
78 |
Glyphs for each character are stored in the instance variable |
|
79 |
'characterBitmaps'. |
|
80 |
Some sample glyphs can be created with the class' sampleGlyphs method. |
|
81 |
The required protocol is found in drawing and accessing. |
|
1154 | 82 |
|
83 |
[author:] |
|
84 |
Claus Gittinger |
|
85 |
||
86 |
[see also:] |
|
87 |
Font GraphicsContext |
|
1088 | 88 |
" |
89 |
! |
|
90 |
||
91 |
examples |
|
92 |
" |
|
2545 | 93 |
a label showing characters in a new bitmap font: |
1154 | 94 |
[exBegin] |
1088 | 95 |
|font l| |
96 |
||
97 |
font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)). |
|
98 |
font setAscent:13; setDescent:3. |
|
99 |
||
100 |
l := Label new. |
|
101 |
l font:font. |
|
102 |
l label:'aazzazaz'. |
|
103 |
l open. |
|
1154 | 104 |
[exEnd] |
1088 | 105 |
|
106 |
||
107 |
a label showing characters in a new smily font: |
|
1154 | 108 |
[exBegin] |
1088 | 109 |
|font l| |
110 |
||
111 |
font := (BitmapFont new glyphs:(BitmapFont smilyGlyhps)). |
|
112 |
font setAscent:16; setDescent:0. |
|
113 |
||
114 |
l := Label new. |
|
115 |
l font:font. |
|
116 |
l label:'aabbaaa'. |
|
117 |
l open. |
|
1154 | 118 |
[exEnd] |
1088 | 119 |
|
120 |
||
2545 | 121 |
demonstrate, that this font can be used in listViews just as any other font: |
1088 | 122 |
(well, missing character glyphs are blanked) |
1154 | 123 |
[exBegin] |
1088 | 124 |
|font top list| |
125 |
||
126 |
font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)). |
|
127 |
font setAscent:13; setDescent:3. |
|
128 |
||
129 |
top := ScrollableView forView:(list := SelectionInListView new). |
|
130 |
list font:font. |
|
131 |
list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz'). |
|
132 |
top extent:200@200. |
|
133 |
top open. |
|
1154 | 134 |
[exEnd] |
135 |
||
1088 | 136 |
|
137 |
demonstrate, that this font can be used in textViews just as any other font: |
|
138 |
(well, missing character glyphs are blanked) |
|
1154 | 139 |
[exBegin] |
1088 | 140 |
|font top list| |
141 |
||
142 |
font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)). |
|
143 |
font setAscent:13; setDescent:3. |
|
144 |
||
145 |
top := ScrollableView forView:(list := EditTextView new). |
|
146 |
list font:font. |
|
147 |
list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz'). |
|
148 |
top extent:200@200. |
|
149 |
top open. |
|
1154 | 150 |
[exEnd] |
4039 | 151 |
|
152 |
another clock display: |
|
6931 | 153 |
defines a font with the 7-segment led bitmaps as glyphs for 0-9, |
154 |
then simply displays the time as a string in that font. |
|
4039 | 155 |
[exBegin] |
156 |
|glyphs f label| |
|
157 |
||
158 |
glyphs := Array new:256. |
|
159 |
glyphs |
|
160 |
at:($0 asciiValue + 1) |
|
161 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led0.xpm'). |
|
162 |
glyphs |
|
163 |
at:($1 asciiValue + 1) |
|
164 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led1.xpm'). |
|
165 |
glyphs |
|
166 |
at:($2 asciiValue + 1) |
|
167 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led2.xpm'). |
|
168 |
glyphs |
|
169 |
at:($3 asciiValue + 1) |
|
170 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led3.xpm'). |
|
171 |
glyphs |
|
172 |
at:($4 asciiValue + 1) |
|
173 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led4.xpm'). |
|
174 |
glyphs |
|
175 |
at:($5 asciiValue + 1) |
|
176 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led5.xpm'). |
|
177 |
glyphs |
|
178 |
at:($6 asciiValue + 1) |
|
179 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led6.xpm'). |
|
180 |
glyphs |
|
181 |
at:($7 asciiValue + 1) |
|
182 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led7.xpm'). |
|
183 |
glyphs |
|
184 |
at:($8 asciiValue + 1) |
|
185 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led8.xpm'). |
|
186 |
glyphs |
|
187 |
at:($9 asciiValue + 1) |
|
188 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led9.xpm'). |
|
189 |
glyphs |
|
190 |
at:($: asciiValue + 1) |
|
191 |
put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/ledCol.xpm'). |
|
192 |
||
193 |
f := BitmapFont new glyphs:glyphs. |
|
194 |
||
195 |
label := Label new label:(Time now printString). |
|
196 |
label font:f. |
|
197 |
label open |
|
198 |
[exEnd] |
|
199 |
||
1088 | 200 |
" |
201 |
! ! |
|
202 |
||
203 |
!BitmapFont class methodsFor:'instance creation'! |
|
204 |
||
205 |
new |
|
206 |
|newFont| |
|
207 |
||
208 |
newFont := super new |
|
9035 | 209 |
family:'private' |
210 |
face:nil |
|
211 |
style:nil |
|
212 |
size:nil |
|
213 |
sizeUnit:#pt |
|
214 |
encoding:nil. |
|
1088 | 215 |
|
216 |
^ newFont |
|
217 |
||
218 |
" |
|
219 |
BitmapFont new glyphs:(self sampleGlyhps). |
|
220 |
" |
|
9035 | 221 |
|
222 |
"Modified: / 28-04-2020 / 15:09:48 / stefan" |
|
1088 | 223 |
! ! |
224 |
||
225 |
!BitmapFont class methodsFor:'private'! |
|
226 |
||
227 |
sampleGlyhps |
|
228 |
"return the bitmap array for a sample font |
|
229 |
(only contains glyphs for $a and $z)" |
|
230 |
||
231 |
|characters| |
|
232 |
||
233 |
characters := Array new:256. |
|
234 |
characters |
|
6080 | 235 |
at:(Character space codePoint + 1) |
2545 | 236 |
put:(Form |
237 |
width:16 |
|
238 |
height:16 |
|
239 |
fromArray:#[2r00000000 2r00000000 |
|
240 |
2r00000000 2r00000000 |
|
241 |
2r00000000 2r00000000 |
|
242 |
2r00000000 2r00000000 |
|
243 |
2r00000000 2r00000000 |
|
244 |
2r00000000 2r00000000 |
|
245 |
2r00000000 2r00000000 |
|
246 |
2r00000000 2r00000000 |
|
247 |
2r00000000 2r00000000 |
|
248 |
2r00000000 2r00000000 |
|
249 |
2r00000000 2r00000000 |
|
250 |
2r00000000 2r00000000 |
|
251 |
2r00000000 2r00000000 |
|
252 |
2r00000000 2r00000000 |
|
253 |
2r00000000 2r00000000 |
|
254 |
2r00000000 2r00000000]). |
|
1088 | 255 |
|
256 |
characters |
|
6080 | 257 |
at:($a codePoint + 1) |
258 |
put:(Form |
|
259 |
width:16 |
|
260 |
height:16 |
|
261 |
fromArray:#[2r00000000 2r00000000 |
|
262 |
2r00000000 2r00000000 |
|
263 |
2r00000000 2r00000000 |
|
264 |
2r00011111 2r11111000 |
|
265 |
2r00011111 2r11111000 |
|
266 |
2r00011000 2r00011000 |
|
267 |
2r00011000 2r00011000 |
|
268 |
2r00011000 2r00011000 |
|
269 |
2r00011000 2r00011000 |
|
270 |
2r00011000 2r00011000 |
|
271 |
2r00011000 2r00011000 |
|
272 |
2r00011111 2r11111110 |
|
273 |
2r00011111 2r11111110 |
|
274 |
2r00000000 2r00000000 |
|
275 |
2r00000000 2r00000000 |
|
276 |
2r00000000 2r00000000]). |
|
277 |
||
278 |
characters |
|
279 |
at:($z codePoint + 1) |
|
280 |
put:(Form |
|
281 |
width:16 |
|
282 |
height:16 |
|
283 |
fromArray:#[2r00000000 2r00000000 |
|
284 |
2r00000000 2r00000000 |
|
285 |
2r00000000 2r00000000 |
|
286 |
2r00011111 2r11111000 |
|
287 |
2r00011111 2r11111000 |
|
288 |
2r00000000 2r00110000 |
|
289 |
2r00000000 2r01100000 |
|
290 |
2r00011111 2r11111000 |
|
291 |
2r00011111 2r11111000 |
|
292 |
2r00000110 2r00000000 |
|
293 |
2r00001100 2r00000000 |
|
294 |
2r00011111 2r11111000 |
|
295 |
2r00011111 2r11111000 |
|
296 |
2r00000000 2r00000000 |
|
297 |
2r00000000 2r00000000 |
|
298 |
2r00000000 2r00000000]). |
|
299 |
||
300 |
^ characters |
|
301 |
! |
|
302 |
||
303 |
smilyGlyhps |
|
304 |
"return the bitmap array for a smily font |
|
305 |
(only contains glyphs for $a, $b and $c)" |
|
306 |
||
307 |
|characters| |
|
308 |
||
309 |
characters := Array new:256. |
|
310 |
characters |
|
311 |
at:(Character space codePoint + 1) |
|
312 |
put:(Form |
|
313 |
width:16 |
|
314 |
height:16 |
|
315 |
fromArray:#[2r00000000 2r00000000 |
|
316 |
2r00000000 2r00000000 |
|
317 |
2r00000000 2r00000000 |
|
318 |
2r00000000 2r00000000 |
|
319 |
2r00000000 2r00000000 |
|
320 |
2r00000000 2r00000000 |
|
321 |
2r00000000 2r00000000 |
|
322 |
2r00000000 2r00000000 |
|
323 |
2r00000000 2r00000000 |
|
324 |
2r00000000 2r00000000 |
|
325 |
2r00000000 2r00000000 |
|
326 |
2r00000000 2r00000000 |
|
327 |
2r00000000 2r00000000 |
|
328 |
2r00000000 2r00000000 |
|
329 |
2r00000000 2r00000000 |
|
330 |
2r00000000 2r00000000]). |
|
331 |
||
332 |
characters |
|
333 |
at:($a codePoint + 1) |
|
2545 | 334 |
put:(Form |
335 |
width:16 |
|
336 |
height:16 |
|
337 |
fromArray:#[2r00000001 2r10000000 |
|
338 |
2r00001110 2r01110000 |
|
339 |
2r00011000 2r00011000 |
|
340 |
2r00100000 2r00000100 |
|
341 |
2r01100110 2r01100110 |
|
342 |
2r01000110 2r01100010 |
|
343 |
2r01000000 2r00000010 |
|
344 |
2r10000001 2r00000001 |
|
345 |
2r10000001 2r00000001 |
|
346 |
2r01001000 2r00010010 |
|
347 |
2r01001100 2r00110010 |
|
348 |
2r01100111 2r11100110 |
|
349 |
2r00100001 2r10000100 |
|
350 |
2r00011000 2r00011000 |
|
351 |
2r00001110 2r01110000 |
|
352 |
2r00000001 2r10000000]). |
|
1088 | 353 |
|
354 |
characters |
|
6080 | 355 |
at:($b codePoint + 1) |
2545 | 356 |
put:(Form |
357 |
width:16 |
|
358 |
height:16 |
|
359 |
fromArray:#[2r00000001 2r10000000 |
|
360 |
2r00001110 2r01110000 |
|
361 |
2r00011000 2r00011000 |
|
362 |
2r00100000 2r00000100 |
|
363 |
2r01100110 2r01100110 |
|
364 |
2r01000110 2r01100010 |
|
365 |
2r01000000 2r00000010 |
|
366 |
2r10000001 2r00000001 |
|
367 |
2r10000001 2r00000001 |
|
368 |
2r01000000 2r00000010 |
|
369 |
2r01000001 2r10000010 |
|
370 |
2r01100010 2r01000110 |
|
371 |
2r00100010 2r01000100 |
|
372 |
2r00011000 2r00011000 |
|
373 |
2r00001110 2r01110000 |
|
374 |
2r00000001 2r10000000]). |
|
1088 | 375 |
|
376 |
characters |
|
6080 | 377 |
at:($c codePoint + 1) |
2545 | 378 |
put:(Form |
379 |
width:16 |
|
380 |
height:16 |
|
381 |
fromArray:#[2r00000001 2r10000000 |
|
382 |
2r00001110 2r01110000 |
|
383 |
2r00011000 2r00011000 |
|
384 |
2r00100000 2r00000100 |
|
385 |
2r01100110 2r01100110 |
|
386 |
2r01000110 2r01100010 |
|
387 |
2r01000000 2r00000010 |
|
388 |
2r10000001 2r00000001 |
|
389 |
2r10000001 2r00000001 |
|
390 |
2r01000000 2r00000010 |
|
391 |
2r01000001 2r10000010 |
|
392 |
2r01100011 2r11000110 |
|
393 |
2r00100011 2r11000100 |
|
394 |
2r00011001 2r10011000 |
|
395 |
2r00001110 2r01110000 |
|
396 |
2r00000001 2r10000000]). |
|
1088 | 397 |
|
398 |
^ characters |
|
399 |
! ! |
|
400 |
||
401 |
!BitmapFont methodsFor:'accessing'! |
|
402 |
||
403 |
glyphs:aGlyphArray |
|
1154 | 404 |
"set the glyphs array; that is the collection of |
405 |
bitmaps - one for each character" |
|
406 |
||
1088 | 407 |
characterBitmaps := aGlyphArray. |
2545 | 408 |
|
3672 | 409 |
maxWidth := maxHeight := 0. |
410 |
aGlyphArray do:[:glyph | glyph notNil ifTrue:[ |
|
4039 | 411 |
maxWidth := maxWidth max:(glyph width). |
412 |
maxHeight := maxHeight max:(glyph height). |
|
3672 | 413 |
] |
4039 | 414 |
]. |
415 |
ascent isNil ifTrue:[ascent := maxHeight]. |
|
416 |
descent isNil ifTrue:[descent := 0]. |
|
1088 | 417 |
! |
418 |
||
419 |
setAscent:aNumber |
|
7347 | 420 |
"set the font's ascent; that is the number of pixels |
421 |
above the baseline" |
|
1154 | 422 |
|
1088 | 423 |
ascent := aNumber. |
3672 | 424 |
maxHeight := self maxAscent + (self maxDescent max:0) |
1088 | 425 |
! |
426 |
||
427 |
setDescent:aNumber |
|
7347 | 428 |
"set the font's ascent; that is the number of pixels |
429 |
below the baseline" |
|
1154 | 430 |
|
1088 | 431 |
descent := aNumber. |
3672 | 432 |
maxHeight := self maxAscent + (self maxDescent max:0). |
1088 | 433 |
! ! |
434 |
||
435 |
!BitmapFont methodsFor:'drawing'! |
|
436 |
||
3663 | 437 |
displayString:aString from:index1 to:index2 x:x0 y:y in:aGC opaque:opaque |
1154 | 438 |
"required protocol for new fonts: |
439 |
- display part of a string, drawing foreground pixels only" |
|
440 |
||
1088 | 441 |
|x| |
442 |
||
443 |
x := x0. |
|
444 |
index1 to:index2 do:[:index | |
|
4077
ab3991c6a6b0
Use the ANSI-blessed #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
4039
diff
changeset
|
445 |
self drawCharacter:(aString at:index) codePoint in:aGC x:x y:y opaque:opaque. |
ab3991c6a6b0
Use the ANSI-blessed #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
4039
diff
changeset
|
446 |
x := x + (self widthOfCharacter:(aString at:index) codePoint) |
1088 | 447 |
] |
1154 | 448 |
! ! |
449 |
||
450 |
!BitmapFont methodsFor:'private - drawing'! |
|
1088 | 451 |
|
452 |
drawCharacter:ascii in:aGC x:x y:y opaque:opaque |
|
453 |
|glyph| |
|
454 |
||
2545 | 455 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil. |
1088 | 456 |
glyph isNil ifTrue:[^ self]. |
3673 | 457 |
aGC displayForm:glyph x:x y:y-glyph height+descent opaque:opaque |
1088 | 458 |
! ! |
459 |
||
1154 | 460 |
!BitmapFont methodsFor:'private - queries'! |
461 |
||
3672 | 462 |
glyphOfCharacter:ascii |
1154 | 463 |
"return the height of a specific character" |
464 |
||
465 |
|glyph| |
|
466 |
||
2545 | 467 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil. |
1154 | 468 |
glyph isNil ifTrue:[ |
6080 | 469 |
glyph := characterBitmaps at:(Character space codePoint + 1). |
1154 | 470 |
]. |
3672 | 471 |
^ glyph |
472 |
! |
|
473 |
||
474 |
heightOfCharacter:ascii |
|
475 |
"return the height of a specific character" |
|
476 |
||
477 |
|glyph| |
|
478 |
||
479 |
glyph := self glyphOfCharacter:ascii. |
|
1154 | 480 |
glyph isNil ifTrue:[^ 0]. |
481 |
^ glyph height |
|
482 |
! |
|
483 |
||
484 |
widthOfCharacter:ascii |
|
485 |
"return the width of a specific character" |
|
486 |
||
487 |
|glyph| |
|
488 |
||
3672 | 489 |
glyph := self glyphOfCharacter:ascii. |
1154 | 490 |
glyph isNil ifTrue:[^ 0]. |
491 |
^ glyph width |
|
492 |
! ! |
|
493 |
||
1088 | 494 |
!BitmapFont methodsFor:'queries'! |
495 |
||
496 |
ascent |
|
497 |
"return the ascent - the number of pixels above the baseLine" |
|
498 |
||
499 |
^ ascent |
|
500 |
! |
|
501 |
||
502 |
ascentOn:aDevice |
|
2545 | 503 |
"return the descent - the number of pixels below the baseLine. |
504 |
Since I am not device dependent, return my pixel ascent." |
|
1088 | 505 |
|
2545 | 506 |
^ descent |
1088 | 507 |
! |
508 |
||
509 |
descent |
|
510 |
"return the descent - the number of pixels below the baseLine" |
|
511 |
||
4039 | 512 |
^ descent ? 0 |
1088 | 513 |
! |
514 |
||
515 |
descentOn:aDevice |
|
2545 | 516 |
"return the descent - the number of pixels below the baseLine. |
517 |
Since I am not device dependent, return my pixel descent." |
|
1088 | 518 |
|
519 |
^ descent |
|
520 |
! |
|
521 |
||
522 |
height |
|
523 |
"return the height - the height in pixels of the highest character" |
|
524 |
||
3672 | 525 |
^ self maxHeight |
1088 | 526 |
! |
527 |
||
528 |
heightOf:aString |
|
529 |
"return the height - the height in pixels of the highest character" |
|
530 |
||
3672 | 531 |
^ self maxHeight. |
1088 | 532 |
! |
533 |
||
534 |
heightOn:aDevice |
|
535 |
"return the height - the height in pixels of the highest character" |
|
536 |
||
3672 | 537 |
^ self maxHeight. |
1088 | 538 |
! |
539 |
||
540 |
isFixedWidth |
|
7347 | 541 |
"return true if all of the font's characters are equal in |
1088 | 542 |
width." |
543 |
||
3664 | 544 |
|w| |
545 |
||
546 |
characterBitmaps do:[:glyph | |wHere| |
|
547 |
glyph notNil ifTrue:[ |
|
548 |
wHere := glyph width. |
|
549 |
w isNil |
|
550 |
ifTrue:[ w := wHere ] |
|
551 |
ifFalse:[ w ~~ wHere ifTrue:[^ false]] |
|
552 |
] |
|
553 |
]. |
|
1088 | 554 |
^ true |
555 |
! |
|
556 |
||
557 |
maxAscent |
|
7579 | 558 |
"return the maximum ascent; |
559 |
that's the ascent of the highest character" |
|
1154 | 560 |
|
3672 | 561 |
ascent isNil ifTrue:[ |
4039 | 562 |
ascent := (self maxHeight - self descent) max:0 |
3672 | 563 |
]. |
1088 | 564 |
^ ascent. |
565 |
! |
|
566 |
||
1154 | 567 |
maxDescent |
7579 | 568 |
"return the maximum descent; |
569 |
that's the descent of the highest character" |
|
1154 | 570 |
|
3672 | 571 |
descent isNil ifTrue:[ |
572 |
descent := (self maxHeight - ascent) max:0 |
|
573 |
]. |
|
1154 | 574 |
^ descent. |
575 |
! |
|
576 |
||
1088 | 577 |
maxHeight |
7579 | 578 |
"return the maximum height; |
579 |
that's the height of the highest character" |
|
1154 | 580 |
|
4039 | 581 |
^ maxHeight ? 0 |
1088 | 582 |
! |
583 |
||
1154 | 584 |
maxWidth |
585 |
"return the maximum width - the width of the widest character in pixels" |
|
586 |
||
3672 | 587 |
^ maxWidth |
1154 | 588 |
! |
589 |
||
2545 | 590 |
onDevice:aDevice |
591 |
"return a device representation of the receiver. |
|
592 |
Since I am device independent, return the receiver." |
|
1088 | 593 |
|
594 |
^ self |
|
595 |
! |
|
596 |
||
597 |
width |
|
598 |
"return the width - the average width in pixels" |
|
599 |
||
3672 | 600 |
^ self maxWidth |
1088 | 601 |
! |
602 |
||
603 |
widthOf:aString from:start to:stop |
|
604 |
"return the width of a substring" |
|
605 |
||
606 |
|sumW| |
|
607 |
||
608 |
(stop < start) ifTrue:[^ 0]. |
|
609 |
sumW := 0. |
|
610 |
start to:stop do:[:index | |
|
4077
ab3991c6a6b0
Use the ANSI-blessed #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
4039
diff
changeset
|
611 |
sumW := sumW + (self widthOfCharacter:(aString at:index) codePoint) |
1088 | 612 |
]. |
613 |
^ sumW |
|
614 |
! |
|
615 |
||
1154 | 616 |
widthOf:aString from:startIndex to:endIndex on:aDevice |
617 |
"return the width of a substring" |
|
1088 | 618 |
|
1154 | 619 |
^ self widthOf:aString from:startIndex to:endIndex |
1088 | 620 |
! |
621 |
||
622 |
widthOn:aDevice |
|
623 |
"return the width - the average width in pixels" |
|
624 |
||
3672 | 625 |
^ self maxWidth |
1088 | 626 |
! ! |
627 |
||
628 |
!BitmapFont class methodsFor:'documentation'! |
|
629 |
||
630 |
version |
|
6931 | 631 |
^ '$Header$' |
1088 | 632 |
! ! |
6080 | 633 |