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