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