author | Claus Gittinger <cg@exept.de> |
Thu, 01 Oct 2015 11:12:19 +0200 | |
changeset 6931 | babe431ab64c |
parent 6080 | a754f2b9a9ef |
child 7347 | 43a15e3e23c4 |
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 |
|
1154 | 415 |
"set the fonts ascent; that is the number of pixels |
416 |
above the fonts baseline" |
|
417 |
||
1088 | 418 |
ascent := aNumber. |
3672 | 419 |
maxHeight := self maxAscent + (self maxDescent max:0) |
1088 | 420 |
! |
421 |
||
422 |
setDescent:aNumber |
|
1154 | 423 |
"set the fonts ascent; that is the number of pixels |
424 |
below the fonts baseline" |
|
425 |
||
1088 | 426 |
descent := aNumber. |
3672 | 427 |
maxHeight := self maxAscent + (self maxDescent max:0). |
428 |
||
1088 | 429 |
! ! |
430 |
||
431 |
!BitmapFont methodsFor:'drawing'! |
|
432 |
||
3663 | 433 |
displayString:aString from:index1 to:index2 x:x0 y:y in:aGC opaque:opaque |
1154 | 434 |
"required protocol for new fonts: |
435 |
- display part of a string, drawing foreground pixels only" |
|
436 |
||
1088 | 437 |
|x| |
438 |
||
439 |
x := x0. |
|
440 |
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
|
441 |
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
|
442 |
x := x + (self widthOfCharacter:(aString at:index) codePoint) |
1088 | 443 |
] |
1154 | 444 |
! ! |
445 |
||
446 |
!BitmapFont methodsFor:'private - drawing'! |
|
1088 | 447 |
|
448 |
drawCharacter:ascii in:aGC x:x y:y opaque:opaque |
|
449 |
|glyph| |
|
450 |
||
2545 | 451 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil. |
1088 | 452 |
glyph isNil ifTrue:[^ self]. |
3673 | 453 |
aGC displayForm:glyph x:x y:y-glyph height+descent opaque:opaque |
1088 | 454 |
! ! |
455 |
||
1154 | 456 |
!BitmapFont methodsFor:'private - queries'! |
457 |
||
3672 | 458 |
glyphOfCharacter:ascii |
1154 | 459 |
"return the height of a specific character" |
460 |
||
461 |
|glyph| |
|
462 |
||
2545 | 463 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil. |
1154 | 464 |
glyph isNil ifTrue:[ |
6080 | 465 |
glyph := characterBitmaps at:(Character space codePoint + 1). |
1154 | 466 |
]. |
3672 | 467 |
^ glyph |
468 |
! |
|
469 |
||
470 |
heightOfCharacter:ascii |
|
471 |
"return the height of a specific character" |
|
472 |
||
473 |
|glyph| |
|
474 |
||
475 |
glyph := self glyphOfCharacter:ascii. |
|
1154 | 476 |
glyph isNil ifTrue:[^ 0]. |
477 |
^ glyph height |
|
478 |
! |
|
479 |
||
480 |
widthOfCharacter:ascii |
|
481 |
"return the width of a specific character" |
|
482 |
||
483 |
|glyph| |
|
484 |
||
3672 | 485 |
glyph := self glyphOfCharacter:ascii. |
1154 | 486 |
glyph isNil ifTrue:[^ 0]. |
487 |
^ glyph width |
|
488 |
! ! |
|
489 |
||
1088 | 490 |
!BitmapFont methodsFor:'queries'! |
491 |
||
492 |
ascent |
|
493 |
"return the ascent - the number of pixels above the baseLine" |
|
494 |
||
495 |
^ ascent |
|
496 |
! |
|
497 |
||
498 |
ascentOn:aDevice |
|
2545 | 499 |
"return the descent - the number of pixels below the baseLine. |
500 |
Since I am not device dependent, return my pixel ascent." |
|
1088 | 501 |
|
2545 | 502 |
^ descent |
1088 | 503 |
! |
504 |
||
505 |
descent |
|
506 |
"return the descent - the number of pixels below the baseLine" |
|
507 |
||
4039 | 508 |
^ descent ? 0 |
1088 | 509 |
! |
510 |
||
511 |
descentOn:aDevice |
|
2545 | 512 |
"return the descent - the number of pixels below the baseLine. |
513 |
Since I am not device dependent, return my pixel descent." |
|
1088 | 514 |
|
515 |
^ descent |
|
516 |
! |
|
517 |
||
518 |
height |
|
519 |
"return the height - the height in pixels of the highest character" |
|
520 |
||
3672 | 521 |
^ self maxHeight |
1088 | 522 |
! |
523 |
||
524 |
heightOf:aString |
|
525 |
"return the height - the height in pixels of the highest character" |
|
526 |
||
3672 | 527 |
^ self maxHeight. |
1088 | 528 |
! |
529 |
||
530 |
heightOn:aDevice |
|
531 |
"return the height - the height in pixels of the highest character" |
|
532 |
||
3672 | 533 |
^ self maxHeight. |
1088 | 534 |
! |
535 |
||
536 |
isFixedWidth |
|
537 |
"return true if all of the fonts characters are equal in |
|
538 |
width." |
|
539 |
||
3664 | 540 |
|w| |
541 |
||
542 |
characterBitmaps do:[:glyph | |wHere| |
|
543 |
glyph notNil ifTrue:[ |
|
544 |
wHere := glyph width. |
|
545 |
w isNil |
|
546 |
ifTrue:[ w := wHere ] |
|
547 |
ifFalse:[ w ~~ wHere ifTrue:[^ false]] |
|
548 |
] |
|
549 |
]. |
|
1088 | 550 |
^ true |
551 |
! |
|
552 |
||
553 |
maxAscent |
|
1154 | 554 |
"return the maximum ascent; thats the ascent of the highest |
555 |
character" |
|
556 |
||
3672 | 557 |
ascent isNil ifTrue:[ |
4039 | 558 |
ascent := (self maxHeight - self descent) max:0 |
3672 | 559 |
]. |
1088 | 560 |
^ ascent. |
561 |
! |
|
562 |
||
1154 | 563 |
maxDescent |
564 |
"return the maximum descent; thats the descent of the highest |
|
565 |
character" |
|
566 |
||
3672 | 567 |
descent isNil ifTrue:[ |
568 |
descent := (self maxHeight - ascent) max:0 |
|
569 |
]. |
|
1154 | 570 |
^ descent. |
571 |
! |
|
572 |
||
1088 | 573 |
maxHeight |
1154 | 574 |
"return the maximum height; thats the height of the highest |
575 |
character" |
|
576 |
||
4039 | 577 |
^ maxHeight ? 0 |
1088 | 578 |
! |
579 |
||
1154 | 580 |
maxWidth |
581 |
"return the maximum width - the width of the widest character in pixels" |
|
582 |
||
3672 | 583 |
^ maxWidth |
1154 | 584 |
! |
585 |
||
2545 | 586 |
onDevice:aDevice |
587 |
"return a device representation of the receiver. |
|
588 |
Since I am device independent, return the receiver." |
|
1088 | 589 |
|
590 |
^ self |
|
591 |
! |
|
592 |
||
593 |
width |
|
594 |
"return the width - the average width in pixels" |
|
595 |
||
3672 | 596 |
^ self maxWidth |
1088 | 597 |
! |
598 |
||
599 |
widthOf:aString from:start to:stop |
|
600 |
"return the width of a substring" |
|
601 |
||
602 |
|sumW| |
|
603 |
||
604 |
(stop < start) ifTrue:[^ 0]. |
|
605 |
sumW := 0. |
|
606 |
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
|
607 |
sumW := sumW + (self widthOfCharacter:(aString at:index) codePoint) |
1088 | 608 |
]. |
609 |
^ sumW |
|
610 |
! |
|
611 |
||
1154 | 612 |
widthOf:aString from:startIndex to:endIndex on:aDevice |
613 |
"return the width of a substring" |
|
1088 | 614 |
|
1154 | 615 |
^ self widthOf:aString from:startIndex to:endIndex |
1088 | 616 |
! |
617 |
||
618 |
widthOn:aDevice |
|
619 |
"return the width - the average width in pixels" |
|
620 |
||
3672 | 621 |
^ self maxWidth |
1088 | 622 |
! ! |
623 |
||
624 |
!BitmapFont class methodsFor:'documentation'! |
|
625 |
||
626 |
version |
|
6931 | 627 |
^ '$Header$' |
1088 | 628 |
! ! |
6080 | 629 |