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