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