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]
|
1088
|
148 |
"
|
|
149 |
! !
|
|
150 |
|
|
151 |
!BitmapFont class methodsFor:'instance creation'!
|
|
152 |
|
|
153 |
new
|
|
154 |
|newFont|
|
|
155 |
|
|
156 |
newFont := super new
|
|
157 |
family:'private'
|
|
158 |
face:nil
|
|
159 |
style:nil
|
|
160 |
size:nil
|
|
161 |
encoding:nil.
|
|
162 |
|
|
163 |
^ newFont
|
|
164 |
|
|
165 |
"
|
|
166 |
BitmapFont new glyphs:(self sampleGlyhps).
|
|
167 |
"
|
|
168 |
! !
|
|
169 |
|
|
170 |
!BitmapFont class methodsFor:'private'!
|
|
171 |
|
|
172 |
sampleGlyhps
|
|
173 |
"return the bitmap array for a sample font
|
|
174 |
(only contains glyphs for $a and $z)"
|
|
175 |
|
|
176 |
|characters|
|
|
177 |
|
|
178 |
characters := Array new:256.
|
|
179 |
characters
|
|
180 |
at:(Character space asciiValue + 1)
|
|
181 |
put:(Form
|
|
182 |
width:16
|
|
183 |
height:16
|
|
184 |
fromArray:#[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 |
2r00000000 2r00000000
|
|
199 |
2r00000000 2r00000000]).
|
|
200 |
|
|
201 |
characters
|
|
202 |
at:($a asciiValue + 1)
|
|
203 |
put:(Form
|
|
204 |
width:16
|
|
205 |
height:16
|
|
206 |
fromArray:#[2r00000000 2r00000000
|
|
207 |
2r00000000 2r00000000
|
|
208 |
2r00000000 2r00000000
|
|
209 |
2r00011111 2r11111000
|
|
210 |
2r00011111 2r11111000
|
|
211 |
2r00011000 2r00011000
|
|
212 |
2r00011000 2r00011000
|
|
213 |
2r00011000 2r00011000
|
|
214 |
2r00011000 2r00011000
|
|
215 |
2r00011000 2r00011000
|
|
216 |
2r00011000 2r00011000
|
|
217 |
2r00011111 2r11111110
|
|
218 |
2r00011111 2r11111110
|
|
219 |
2r00000000 2r00000000
|
|
220 |
2r00000000 2r00000000
|
|
221 |
2r00000000 2r00000000]).
|
|
222 |
|
|
223 |
characters
|
|
224 |
at:($z asciiValue + 1)
|
|
225 |
put:(Form
|
|
226 |
width:16
|
|
227 |
height:16
|
|
228 |
fromArray:#[2r00000000 2r00000000
|
|
229 |
2r00000000 2r00000000
|
|
230 |
2r00000000 2r00000000
|
|
231 |
2r00011111 2r11111000
|
|
232 |
2r00011111 2r11111000
|
|
233 |
2r00000000 2r00110000
|
|
234 |
2r00000000 2r01100000
|
|
235 |
2r00011111 2r11111000
|
|
236 |
2r00011111 2r11111000
|
|
237 |
2r00000110 2r00000000
|
|
238 |
2r00001100 2r00000000
|
|
239 |
2r00011111 2r11111000
|
|
240 |
2r00011111 2r11111000
|
|
241 |
2r00000000 2r00000000
|
|
242 |
2r00000000 2r00000000
|
|
243 |
2r00000000 2r00000000]).
|
|
244 |
|
|
245 |
^ characters
|
|
246 |
!
|
|
247 |
|
|
248 |
smilyGlyhps
|
|
249 |
"return the bitmap array for a smily font
|
2545
|
250 |
(only contains glyphs for $a, $b and $c)"
|
1088
|
251 |
|
|
252 |
|characters|
|
|
253 |
|
|
254 |
characters := Array new:256.
|
|
255 |
characters
|
2545
|
256 |
at:(Character space asciiValue + 1)
|
|
257 |
put:(Form
|
|
258 |
width:16
|
|
259 |
height:16
|
|
260 |
fromArray:#[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 |
2r00000000 2r00000000
|
|
275 |
2r00000000 2r00000000]).
|
1088
|
276 |
|
|
277 |
characters
|
2545
|
278 |
at:($a asciiValue + 1)
|
|
279 |
put:(Form
|
|
280 |
width:16
|
|
281 |
height:16
|
|
282 |
fromArray:#[2r00000001 2r10000000
|
|
283 |
2r00001110 2r01110000
|
|
284 |
2r00011000 2r00011000
|
|
285 |
2r00100000 2r00000100
|
|
286 |
2r01100110 2r01100110
|
|
287 |
2r01000110 2r01100010
|
|
288 |
2r01000000 2r00000010
|
|
289 |
2r10000001 2r00000001
|
|
290 |
2r10000001 2r00000001
|
|
291 |
2r01001000 2r00010010
|
|
292 |
2r01001100 2r00110010
|
|
293 |
2r01100111 2r11100110
|
|
294 |
2r00100001 2r10000100
|
|
295 |
2r00011000 2r00011000
|
|
296 |
2r00001110 2r01110000
|
|
297 |
2r00000001 2r10000000]).
|
1088
|
298 |
|
|
299 |
characters
|
2545
|
300 |
at:($b asciiValue + 1)
|
|
301 |
put:(Form
|
|
302 |
width:16
|
|
303 |
height:16
|
|
304 |
fromArray:#[2r00000001 2r10000000
|
|
305 |
2r00001110 2r01110000
|
|
306 |
2r00011000 2r00011000
|
|
307 |
2r00100000 2r00000100
|
|
308 |
2r01100110 2r01100110
|
|
309 |
2r01000110 2r01100010
|
|
310 |
2r01000000 2r00000010
|
|
311 |
2r10000001 2r00000001
|
|
312 |
2r10000001 2r00000001
|
|
313 |
2r01000000 2r00000010
|
|
314 |
2r01000001 2r10000010
|
|
315 |
2r01100010 2r01000110
|
|
316 |
2r00100010 2r01000100
|
|
317 |
2r00011000 2r00011000
|
|
318 |
2r00001110 2r01110000
|
|
319 |
2r00000001 2r10000000]).
|
1088
|
320 |
|
|
321 |
characters
|
2545
|
322 |
at:($c asciiValue + 1)
|
|
323 |
put:(Form
|
|
324 |
width:16
|
|
325 |
height:16
|
|
326 |
fromArray:#[2r00000001 2r10000000
|
|
327 |
2r00001110 2r01110000
|
|
328 |
2r00011000 2r00011000
|
|
329 |
2r00100000 2r00000100
|
|
330 |
2r01100110 2r01100110
|
|
331 |
2r01000110 2r01100010
|
|
332 |
2r01000000 2r00000010
|
|
333 |
2r10000001 2r00000001
|
|
334 |
2r10000001 2r00000001
|
|
335 |
2r01000000 2r00000010
|
|
336 |
2r01000001 2r10000010
|
|
337 |
2r01100011 2r11000110
|
|
338 |
2r00100011 2r11000100
|
|
339 |
2r00011001 2r10011000
|
|
340 |
2r00001110 2r01110000
|
|
341 |
2r00000001 2r10000000]).
|
1088
|
342 |
|
|
343 |
^ characters
|
|
344 |
! !
|
|
345 |
|
|
346 |
!BitmapFont methodsFor:'accessing'!
|
|
347 |
|
|
348 |
glyphs:aGlyphArray
|
1154
|
349 |
"set the glyphs array; that is the collection of
|
|
350 |
bitmaps - one for each character"
|
|
351 |
|
1088
|
352 |
characterBitmaps := aGlyphArray.
|
2545
|
353 |
|
3672
|
354 |
maxWidth := maxHeight := 0.
|
|
355 |
aGlyphArray do:[:glyph | glyph notNil ifTrue:[
|
|
356 |
maxWidth := maxWidth max:glyph width.
|
|
357 |
maxHeight := maxHeight max:glyph height.
|
|
358 |
]
|
|
359 |
]
|
1088
|
360 |
!
|
|
361 |
|
|
362 |
setAscent:aNumber
|
1154
|
363 |
"set the fonts ascent; that is the number of pixels
|
|
364 |
above the fonts baseline"
|
|
365 |
|
1088
|
366 |
ascent := aNumber.
|
3672
|
367 |
maxHeight := self maxAscent + (self maxDescent max:0)
|
1088
|
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.
|
3672
|
375 |
maxHeight := self maxAscent + (self maxDescent max:0).
|
|
376 |
|
1088
|
377 |
! !
|
|
378 |
|
|
379 |
!BitmapFont methodsFor:'drawing'!
|
|
380 |
|
3663
|
381 |
displayString:aString from:index1 to:index2 x:x0 y:y in:aGC opaque:opaque
|
1154
|
382 |
"required protocol for new fonts:
|
|
383 |
- display part of a string, drawing foreground pixels only"
|
|
384 |
|
1088
|
385 |
|x|
|
|
386 |
|
|
387 |
x := x0.
|
|
388 |
index1 to:index2 do:[:index |
|
3663
|
389 |
self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y opaque:opaque.
|
1154
|
390 |
x := x + (self widthOfCharacter:(aString at:index) asciiValue)
|
1088
|
391 |
]
|
1154
|
392 |
! !
|
|
393 |
|
|
394 |
!BitmapFont methodsFor:'private - drawing'!
|
1088
|
395 |
|
|
396 |
drawCharacter:ascii in:aGC x:x y:y opaque:opaque
|
|
397 |
|glyph|
|
|
398 |
|
2545
|
399 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
|
1088
|
400 |
glyph isNil ifTrue:[^ self].
|
3672
|
401 |
aGC displayForm:glyph x:x y:y-glyph height+1+descent opaque:opaque
|
1088
|
402 |
! !
|
|
403 |
|
1154
|
404 |
!BitmapFont methodsFor:'private - queries'!
|
|
405 |
|
3672
|
406 |
glyphOfCharacter:ascii
|
1154
|
407 |
"return the height of a specific character"
|
|
408 |
|
|
409 |
|glyph|
|
|
410 |
|
2545
|
411 |
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
|
1154
|
412 |
glyph isNil ifTrue:[
|
2545
|
413 |
glyph := characterBitmaps at:(Character space asciiValue + 1).
|
1154
|
414 |
].
|
3672
|
415 |
^ glyph
|
|
416 |
!
|
|
417 |
|
|
418 |
heightOfCharacter:ascii
|
|
419 |
"return the height of a specific character"
|
|
420 |
|
|
421 |
|glyph|
|
|
422 |
|
|
423 |
glyph := self glyphOfCharacter:ascii.
|
1154
|
424 |
glyph isNil ifTrue:[^ 0].
|
|
425 |
^ glyph height
|
|
426 |
!
|
|
427 |
|
|
428 |
widthOfCharacter:ascii
|
|
429 |
"return the width of a specific character"
|
|
430 |
|
|
431 |
|glyph|
|
|
432 |
|
3672
|
433 |
glyph := self glyphOfCharacter:ascii.
|
1154
|
434 |
glyph isNil ifTrue:[^ 0].
|
|
435 |
^ glyph width
|
|
436 |
! !
|
|
437 |
|
1088
|
438 |
!BitmapFont methodsFor:'queries'!
|
|
439 |
|
|
440 |
ascent
|
|
441 |
"return the ascent - the number of pixels above the baseLine"
|
|
442 |
|
|
443 |
^ ascent
|
|
444 |
!
|
|
445 |
|
|
446 |
ascentOn:aDevice
|
2545
|
447 |
"return the descent - the number of pixels below the baseLine.
|
|
448 |
Since I am not device dependent, return my pixel ascent."
|
1088
|
449 |
|
2545
|
450 |
^ descent
|
1088
|
451 |
!
|
|
452 |
|
|
453 |
descent
|
|
454 |
"return the descent - the number of pixels below the baseLine"
|
|
455 |
|
|
456 |
^ descent
|
|
457 |
!
|
|
458 |
|
|
459 |
descentOn:aDevice
|
2545
|
460 |
"return the descent - the number of pixels below the baseLine.
|
|
461 |
Since I am not device dependent, return my pixel descent."
|
1088
|
462 |
|
|
463 |
^ descent
|
|
464 |
!
|
|
465 |
|
|
466 |
height
|
|
467 |
"return the height - the height in pixels of the highest character"
|
|
468 |
|
3672
|
469 |
^ self maxHeight
|
1088
|
470 |
!
|
|
471 |
|
|
472 |
heightOf:aString
|
|
473 |
"return the height - the height in pixels of the highest character"
|
|
474 |
|
3672
|
475 |
^ self maxHeight.
|
1088
|
476 |
!
|
|
477 |
|
|
478 |
heightOn:aDevice
|
|
479 |
"return the height - the height in pixels of the highest character"
|
|
480 |
|
3672
|
481 |
^ self maxHeight.
|
1088
|
482 |
!
|
|
483 |
|
|
484 |
isFixedWidth
|
|
485 |
"return true if all of the fonts characters are equal in
|
|
486 |
width."
|
|
487 |
|
3664
|
488 |
|w|
|
|
489 |
|
|
490 |
characterBitmaps do:[:glyph | |wHere|
|
|
491 |
glyph notNil ifTrue:[
|
|
492 |
wHere := glyph width.
|
|
493 |
w isNil
|
|
494 |
ifTrue:[ w := wHere ]
|
|
495 |
ifFalse:[ w ~~ wHere ifTrue:[^ false]]
|
|
496 |
]
|
|
497 |
].
|
1088
|
498 |
^ true
|
|
499 |
!
|
|
500 |
|
|
501 |
maxAscent
|
1154
|
502 |
"return the maximum ascent; thats the ascent of the highest
|
|
503 |
character"
|
|
504 |
|
3672
|
505 |
ascent isNil ifTrue:[
|
|
506 |
ascent := (self maxHeight - descent) max:0
|
|
507 |
].
|
1088
|
508 |
^ ascent.
|
|
509 |
!
|
|
510 |
|
1154
|
511 |
maxDescent
|
|
512 |
"return the maximum descent; thats the descent of the highest
|
|
513 |
character"
|
|
514 |
|
3672
|
515 |
descent isNil ifTrue:[
|
|
516 |
descent := (self maxHeight - ascent) max:0
|
|
517 |
].
|
1154
|
518 |
^ descent.
|
|
519 |
!
|
|
520 |
|
1088
|
521 |
maxHeight
|
1154
|
522 |
"return the maximum height; thats the height of the highest
|
|
523 |
character"
|
|
524 |
|
3672
|
525 |
^ maxHeight
|
1088
|
526 |
!
|
|
527 |
|
1154
|
528 |
maxWidth
|
|
529 |
"return the maximum width - the width of the widest character in pixels"
|
|
530 |
|
3672
|
531 |
^ maxWidth
|
1154
|
532 |
!
|
|
533 |
|
2545
|
534 |
onDevice:aDevice
|
|
535 |
"return a device representation of the receiver.
|
|
536 |
Since I am device independent, return the receiver."
|
1088
|
537 |
|
|
538 |
^ self
|
|
539 |
!
|
|
540 |
|
|
541 |
width
|
|
542 |
"return the width - the average width in pixels"
|
|
543 |
|
3672
|
544 |
^ self maxWidth
|
1088
|
545 |
!
|
|
546 |
|
|
547 |
widthOf:aString from:start to:stop
|
|
548 |
"return the width of a substring"
|
|
549 |
|
|
550 |
|sumW|
|
|
551 |
|
|
552 |
(stop < start) ifTrue:[^ 0].
|
|
553 |
sumW := 0.
|
|
554 |
start to:stop do:[:index |
|
|
555 |
sumW := sumW + (self widthOfCharacter:(aString at:index) asciiValue)
|
|
556 |
].
|
|
557 |
^ sumW
|
|
558 |
!
|
|
559 |
|
1154
|
560 |
widthOf:aString from:startIndex to:endIndex on:aDevice
|
|
561 |
"return the width of a substring"
|
1088
|
562 |
|
1154
|
563 |
^ self widthOf:aString from:startIndex to:endIndex
|
1088
|
564 |
!
|
|
565 |
|
|
566 |
widthOn:aDevice
|
|
567 |
"return the width - the average width in pixels"
|
|
568 |
|
3672
|
569 |
^ self maxWidth
|
1088
|
570 |
! !
|
|
571 |
|
|
572 |
!BitmapFont class methodsFor:'documentation'!
|
|
573 |
|
|
574 |
version
|
3672
|
575 |
^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.7 2002-07-24 18:04:46 mb Exp $'
|
1088
|
576 |
! !
|