BitmapFont.st
changeset 2545 829790f194cc
parent 1154 07bc33341696
child 3659 26bd2ef5f0ed
--- a/BitmapFont.st	Tue Mar 30 19:40:13 1999 +0200
+++ b/BitmapFont.st	Tue Mar 30 19:41:20 1999 +0200
@@ -85,7 +85,7 @@
 
 examples
 "
-  a label showing characters in this new bitmap font:
+  a label showing characters in a new bitmap font:
                                                                 [exBegin]
     |font l|
 
@@ -113,7 +113,7 @@
                                                                 [exEnd]
 
 
-  demonstrate, that this font can be used in textViews just as any other font:
+  demonstrate, that this font can be used in listViews just as any other font:
   (well, missing character glyphs are blanked)
                                                                 [exBegin]
     |font top list|
@@ -245,98 +245,98 @@
 
 smilyGlyhps
     "return the bitmap array for a smily font
-     (only contains glyphs for $a and $b)"
+     (only contains glyphs for $a, $b and $c)"
 
     |characters|
 
     characters := Array new:256.
     characters 
-	at:(Character space asciiValue + 1) 
-	put:(Form 
-		width:16 
-		height:16 
-		fromArray:#[2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000
-			    2r00000000 2r00000000]).
+        at:(Character space asciiValue + 1) 
+        put:(Form 
+                width:16 
+                height:16 
+                fromArray:#[2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000
+                            2r00000000 2r00000000]).
 
     characters 
-	at:($a asciiValue + 1) 
-	put:(Form 
-		width:16 
-		height:16 
-		fromArray:#[2r00000001 2r10000000
-			    2r00001110 2r01110000
-			    2r00011000 2r00011000
-			    2r00100000 2r00000100
-			    2r01100110 2r01100110
-			    2r01000110 2r01100010
-			    2r01000000 2r00000010
-			    2r10000001 2r00000001
-			    2r10000001 2r00000001
-			    2r01001000 2r00010010
-			    2r01001100 2r00110010
-			    2r01100111 2r11100110
-			    2r00100001 2r10000100
-			    2r00011000 2r00011000
-			    2r00001110 2r01110000
-			    2r00000001 2r10000000]).
+        at:($a asciiValue + 1) 
+        put:(Form 
+                width:16 
+                height:16 
+                fromArray:#[2r00000001 2r10000000
+                            2r00001110 2r01110000
+                            2r00011000 2r00011000
+                            2r00100000 2r00000100
+                            2r01100110 2r01100110
+                            2r01000110 2r01100010
+                            2r01000000 2r00000010
+                            2r10000001 2r00000001
+                            2r10000001 2r00000001
+                            2r01001000 2r00010010
+                            2r01001100 2r00110010
+                            2r01100111 2r11100110
+                            2r00100001 2r10000100
+                            2r00011000 2r00011000
+                            2r00001110 2r01110000
+                            2r00000001 2r10000000]).
 
     characters 
-	at:($b asciiValue + 1) 
-	put:(Form 
-		width:16 
-		height:16 
-		fromArray:#[2r00000001 2r10000000
-			    2r00001110 2r01110000
-			    2r00011000 2r00011000
-			    2r00100000 2r00000100
-			    2r01100110 2r01100110
-			    2r01000110 2r01100010
-			    2r01000000 2r00000010
-			    2r10000001 2r00000001
-			    2r10000001 2r00000001
-			    2r01000000 2r00000010
-			    2r01000001 2r10000010
-			    2r01100010 2r01000110
-			    2r00100010 2r01000100
-			    2r00011000 2r00011000
-			    2r00001110 2r01110000
-			    2r00000001 2r10000000]).
+        at:($b asciiValue + 1) 
+        put:(Form 
+                width:16 
+                height:16 
+                fromArray:#[2r00000001 2r10000000
+                            2r00001110 2r01110000
+                            2r00011000 2r00011000
+                            2r00100000 2r00000100
+                            2r01100110 2r01100110
+                            2r01000110 2r01100010
+                            2r01000000 2r00000010
+                            2r10000001 2r00000001
+                            2r10000001 2r00000001
+                            2r01000000 2r00000010
+                            2r01000001 2r10000010
+                            2r01100010 2r01000110
+                            2r00100010 2r01000100
+                            2r00011000 2r00011000
+                            2r00001110 2r01110000
+                            2r00000001 2r10000000]).
 
     characters 
-	at:($c asciiValue + 1) 
-	put:(Form 
-		width:16 
-		height:16 
-		fromArray:#[2r00000001 2r10000000
-			    2r00001110 2r01110000
-			    2r00011000 2r00011000
-			    2r00100000 2r00000100
-			    2r01100110 2r01100110
-			    2r01000110 2r01100010
-			    2r01000000 2r00000010
-			    2r10000001 2r00000001
-			    2r10000001 2r00000001
-			    2r01000000 2r00000010
-			    2r01000001 2r10000010
-			    2r01100011 2r11000110
-			    2r00100011 2r11000100
-			    2r00011001 2r10011000
-			    2r00001110 2r01110000
-			    2r00000001 2r10000000]).
+        at:($c asciiValue + 1) 
+        put:(Form 
+                width:16 
+                height:16 
+                fromArray:#[2r00000001 2r10000000
+                            2r00001110 2r01110000
+                            2r00011000 2r00011000
+                            2r00100000 2r00000100
+                            2r01100110 2r01100110
+                            2r01000110 2r01100010
+                            2r01000000 2r00000010
+                            2r10000001 2r00000001
+                            2r10000001 2r00000001
+                            2r01000000 2r00000010
+                            2r01000001 2r10000010
+                            2r01100011 2r11000110
+                            2r00100011 2r11000100
+                            2r00011001 2r10011000
+                            2r00001110 2r01110000
+                            2r00000001 2r10000000]).
 
     ^ characters
 ! !
@@ -348,16 +348,15 @@
      bitmaps - one for each character"
 
     characterBitmaps := aGlyphArray.
-    width isNil ifTrue:[
-        width := aGlyphArray 
-                        inject:0 
-                        into:[:max :glyph | glyph isNil ifTrue:[
-                                                max
-                                            ] ifFalse:[
-                                                max max:glyph width
-                                            ]
-                             ]
-    ].
+
+    width := aGlyphArray 
+                    inject:0 
+                    into:[:max :glyph | glyph isNil ifTrue:[
+                                            max
+                                        ] ifFalse:[
+                                            max max:glyph width
+                                        ]
+                         ]
 !
 
 setAscent:aNumber
@@ -389,19 +388,6 @@
     ]
 !
 
-displayOpaqueString:aString x:x0 y:y in:aGC
-    "required protocol for new fonts:
-     - display a string, drawing both fore- and background pixels"
-
-    |x|
-
-    x := x0.
-    aString do:[:character |
-        self drawCharacter:character asciiValue in:aGC x:x y:y opaque:true.
-        x := x + (self widthOfCharacter:character asciiValue)
-    ]
-!
-
 displayString:aString from:index1 to:index2 x:x0 y:y in:aGC
     "required protocol for new fonts:
      - display part of a string, drawing foreground pixels only"
@@ -413,39 +399,20 @@
         self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y opaque:false.
         x := x + (self widthOfCharacter:(aString at:index) asciiValue)
     ]
-!
-
-displayString:aString x:x0 y:y in:aGC
-    "required protocol for new fonts:
-     - display a string, drawing foreground pixels only"
-
-    |x|
-
-    x := x0.
-    aString do:[:character |
-        self drawCharacter:character asciiValue in:aGC x:x y:y opaque:false.
-        x := x + (self widthOfCharacter:character asciiValue)
-    ]
 ! !
 
 !BitmapFont methodsFor:'private - drawing'!
 
-drawCharacter:ascii in:aGC x:x y:y
-    |glyph|
-
-    (ascii between:0 and:255) ifFalse:[^ self].
-    glyph := characterBitmaps at:(ascii + 1).
-    glyph isNil ifTrue:[^ self].
-    aGC displayForm:glyph x:x y:y-ascent
-!
-
 drawCharacter:ascii in:aGC x:x y:y opaque:opaque
     |glyph|
 
-    (ascii between:0 and:255) ifFalse:[^ self].
-    glyph := characterBitmaps at:(ascii + 1).
+    glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
     glyph isNil ifTrue:[^ self].
-    aGC displayForm:glyph x:x y:y-ascent
+    opaque ifTrue:[
+        aGC displayOpaqueForm:glyph x:x y:y-ascent
+    ] ifFalse:[
+        aGC displayForm:glyph x:x y:y-ascent
+    ]
 ! !
 
 !BitmapFont methodsFor:'private - queries'!
@@ -455,10 +422,9 @@
 
     |glyph|
 
-    (ascii between:0 and:255) ifFalse:[^ 0].
-    glyph := characterBitmaps at:(ascii + 1).
+    glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
     glyph isNil ifTrue:[
-	glyph := characterBitmaps at:(Character space asciiValue + 1).
+        glyph := characterBitmaps at:(Character space asciiValue + 1).
     ].
     glyph isNil ifTrue:[^ 0].
     ^ glyph height
@@ -469,10 +435,9 @@
 
     |glyph|
 
-    (ascii between:0 and:255) ifFalse:[^ 0].
-    glyph := characterBitmaps at:(ascii + 1).
+    glyph := characterBitmaps at:(ascii + 1) ifAbsent:nil.
     glyph isNil ifTrue:[
-	glyph := characterBitmaps at:(Character space asciiValue + 1).
+        glyph := characterBitmaps at:(Character space asciiValue + 1).
     ].
     glyph isNil ifTrue:[^ 0].
     ^ glyph width
@@ -487,9 +452,10 @@
 !
 
 ascentOn:aDevice
-    "return the ascent - the number of pixels above the baseLine"
+    "return the descent - the number of pixels below the baseLine.
+     Since I am not device dependent, return my pixel ascent."
 
-    ^ ascent
+    ^ descent
 !
 
 descent
@@ -499,17 +465,12 @@
 !
 
 descentOn:aDevice
-    "return the descent - the number of pixels below the baseLine"
+    "return the descent - the number of pixels below the baseLine.
+     Since I am not device dependent, return my pixel descent."
 
     ^ descent
 !
 
-fontId
-    "return the fonts device ID - here, there is none"
-
-    ^ nil
-!
-
 height
     "return the height - the height in pixels of the highest character"
 
@@ -563,7 +524,15 @@
 !
 
 on:aDevice
-    "return a device representation of the receiver"
+    "return a device representation of the receiver.
+     Since I am device independent, return the receiver."
+
+    ^ self
+!
+
+onDevice:aDevice
+    "return a device representation of the receiver.
+     Since I am device independent, return the receiver."
 
     ^ self
 !
@@ -574,18 +543,6 @@
     ^ width
 !
 
-widthOf:aString
-    "return the width of a string"
-
-    |sumW|
-
-    sumW := 0.
-    aString do:[:character |
-	sumW := sumW + (self widthOfCharacter:character asciiValue) 
-    ].
-    ^ sumW
-!
-
 widthOf:aString from:start to:stop
     "return the width of a substring"
 
@@ -614,5 +571,5 @@
 !BitmapFont class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.2 1997-01-04 12:43:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.3 1999-03-30 17:41:20 cg Exp $'
 ! !