--- a/BitmapFont.st Wed Jul 24 20:04:33 2002 +0200
+++ b/BitmapFont.st Wed Jul 24 20:04:46 2002 +0200
@@ -27,7 +27,7 @@
"{ Package: 'stx:libview' }"
FontDescription subclass:#BitmapFont
- instanceVariableNames:'characterBitmaps ascent descent width'
+ instanceVariableNames:'characterBitmaps ascent descent maxWidth maxHeight'
classVariableNames:''
poolDictionaries:''
category:'Graphics-Support'
@@ -351,14 +351,12 @@
characterBitmaps := aGlyphArray.
- width := aGlyphArray
- inject:0
- into:[:max :glyph | glyph isNil ifTrue:[
- max
- ] ifFalse:[
- max max:glyph width
- ]
- ]
+ maxWidth := maxHeight := 0.
+ aGlyphArray do:[:glyph | glyph notNil ifTrue:[
+ maxWidth := maxWidth max:glyph width.
+ maxHeight := maxHeight max:glyph height.
+ ]
+ ]
!
setAscent:aNumber
@@ -366,6 +364,7 @@
above the fonts baseline"
ascent := aNumber.
+ maxHeight := self maxAscent + (self maxDescent max:0)
!
setDescent:aNumber
@@ -373,6 +372,8 @@
below the fonts baseline"
descent := aNumber.
+ maxHeight := self maxAscent + (self maxDescent max:0).
+
! !
!BitmapFont methodsFor:'drawing'!
@@ -397,12 +398,12 @@
glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
glyph isNil ifTrue:[^ self].
- aGC displayForm:glyph x:x y:y-ascent opaque:opaque
+ aGC displayForm:glyph x:x y:y-glyph height+1+descent opaque:opaque
! !
!BitmapFont methodsFor:'private - queries'!
-heightOfCharacter:ascii
+glyphOfCharacter:ascii
"return the height of a specific character"
|glyph|
@@ -411,6 +412,15 @@
glyph isNil ifTrue:[
glyph := characterBitmaps at:(Character space asciiValue + 1).
].
+ ^ glyph
+!
+
+heightOfCharacter:ascii
+ "return the height of a specific character"
+
+ |glyph|
+
+ glyph := self glyphOfCharacter:ascii.
glyph isNil ifTrue:[^ 0].
^ glyph height
!
@@ -420,10 +430,7 @@
|glyph|
- glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
- glyph isNil ifTrue:[
- glyph := characterBitmaps at:(Character space asciiValue + 1).
- ].
+ glyph := self glyphOfCharacter:ascii.
glyph isNil ifTrue:[^ 0].
^ glyph width
! !
@@ -459,19 +466,19 @@
height
"return the height - the height in pixels of the highest character"
- ^ descent + ascent.
+ ^ self maxHeight
!
heightOf:aString
"return the height - the height in pixels of the highest character"
- ^ descent + ascent.
+ ^ self maxHeight.
!
heightOn:aDevice
"return the height - the height in pixels of the highest character"
- ^ descent + ascent.
+ ^ self maxHeight.
!
isFixedWidth
@@ -495,6 +502,9 @@
"return the maximum ascent; thats the ascent of the highest
character"
+ ascent isNil ifTrue:[
+ ascent := (self maxHeight - descent) max:0
+ ].
^ ascent.
!
@@ -502,6 +512,9 @@
"return the maximum descent; thats the descent of the highest
character"
+ descent isNil ifTrue:[
+ descent := (self maxHeight - ascent) max:0
+ ].
^ descent.
!
@@ -509,13 +522,13 @@
"return the maximum height; thats the height of the highest
character"
- ^ descent + ascent.
+ ^ maxHeight
!
maxWidth
"return the maximum width - the width of the widest character in pixels"
- ^ width
+ ^ maxWidth
!
onDevice:aDevice
@@ -528,7 +541,7 @@
width
"return the width - the average width in pixels"
- ^ width
+ ^ self maxWidth
!
widthOf:aString from:start to:stop
@@ -553,11 +566,11 @@
widthOn:aDevice
"return the width - the average width in pixels"
- ^ width
+ ^ self maxWidth
! !
!BitmapFont class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.6 2002-07-24 13:43:28 mb Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.7 2002-07-24 18:04:46 mb Exp $'
! !