checkin from browser
authorClaus Gittinger <cg@exept.de>
Sat, 04 Jan 1997 13:43:25 +0100
changeset 1154 07bc33341696
parent 1153 9a10a934c137
child 1155 e8b6f0e8484e
checkin from browser
BitmapFont.st
--- a/BitmapFont.st	Fri Jan 03 15:24:11 1997 +0100
+++ b/BitmapFont.st	Sat Jan 04 13:43:25 1997 +0100
@@ -74,13 +74,19 @@
     'characterBitmaps'.
     Some sample glyphs can be created with the class' sampleGlyphs method.
     The required protocol is found in drawing and accessing.
+
+    [author:]
+        Claus Gittinger
+
+    [see also:]
+        Font GraphicsContext
 "
 !
 
 examples
 "
   a label showing characters in this new bitmap font:
-
+                                                                [exBegin]
     |font l|
 
     font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
@@ -90,10 +96,11 @@
     l font:font.
     l label:'aazzazaz'.
     l open.
+                                                                [exEnd]
 
 
   a label showing characters in a new smily font:
-
+                                                                [exBegin]
     |font l|
 
     font := (BitmapFont new glyphs:(BitmapFont smilyGlyhps)).
@@ -103,11 +110,12 @@
     l font:font.
     l label:'aabbaaa'.
     l open.
+                                                                [exEnd]
 
 
   demonstrate, that this font can be used in textViews just as any other font:
   (well, missing character glyphs are blanked)
-
+                                                                [exBegin]
     |font top list|
 
     font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
@@ -118,10 +126,12 @@
     list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz').
     top extent:200@200.
     top open.
+                                                                [exEnd]
+
 
   demonstrate, that this font can be used in textViews just as any other font:
   (well, missing character glyphs are blanked)
-
+                                                                [exBegin]
     |font top list|
 
     font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
@@ -132,6 +142,7 @@
     list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz').
     top extent:200@200.
     top open.
+                                                                [exEnd]
 "
 ! !
 
@@ -333,68 +344,91 @@
 !BitmapFont methodsFor:'accessing'!
 
 glyphs:aGlyphArray
+    "set the glyphs array; that is the collection of
+     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
+    "set the fonts ascent; that is the number of pixels
+     above the fonts baseline"
+
     ascent := aNumber.
 !
 
 setDescent:aNumber
+    "set the fonts ascent; that is the number of pixels
+     below the fonts baseline"
+
     descent := aNumber.
 ! !
 
 !BitmapFont methodsFor:'drawing'!
 
 displayOpaqueString:aString from:index1 to:index2 x:x0 y:y in:aGC
+    "required protocol for new fonts:
+     - display part of a string, drawing both fore- and background pixels"
+
     |x|
 
     x := x0.
     index1 to:index2 do:[:index |
-	self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y opaque:true.
-	x := x + (self widthOfCharacter:(aString at:index) asciiValue)
+        self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y opaque:true.
+        x := x + (self widthOfCharacter:(aString at:index) asciiValue)
     ]
 !
 
 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)
+        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"
+
     |x|
 
     x := x0.
     index1 to:index2 do:[:index |
-	self drawCharacter:(aString at:index) asciiValue in:aGC x:x y:y opaque:false.
-	x := x + (self widthOfCharacter:(aString at:index) asciiValue)
+        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)
+        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|
@@ -414,6 +448,36 @@
     aGC displayForm:glyph x:x y:y-ascent
 ! !
 
+!BitmapFont methodsFor:'private - queries'!
+
+heightOfCharacter:ascii
+    "return the height of a specific character"
+
+    |glyph|
+
+    (ascii between:0 and:255) ifFalse:[^ 0].
+    glyph := characterBitmaps at:(ascii + 1).
+    glyph isNil ifTrue:[
+	glyph := characterBitmaps at:(Character space asciiValue + 1).
+    ].
+    glyph isNil ifTrue:[^ 0].
+    ^ glyph height
+!
+
+widthOfCharacter:ascii
+    "return the width of a specific character"
+
+    |glyph|
+
+    (ascii between:0 and:255) ifFalse:[^ 0].
+    glyph := characterBitmaps at:(ascii + 1).
+    glyph isNil ifTrue:[
+	glyph := characterBitmaps at:(Character space asciiValue + 1).
+    ].
+    glyph isNil ifTrue:[^ 0].
+    ^ glyph width
+! !
+
 !BitmapFont methodsFor:'queries'!
 
 ascent
@@ -458,20 +522,6 @@
     ^ descent + ascent.
 !
 
-heightOfCharacter:ascii
-    "return the height of a specific character"
-
-    |glyph|
-
-    (ascii between:0 and:255) ifFalse:[^ 0].
-    glyph := characterBitmaps at:(ascii + 1).
-    glyph isNil ifTrue:[
-	glyph := characterBitmaps at:(Character space asciiValue + 1).
-    ].
-    glyph isNil ifTrue:[^ 0].
-    ^ glyph height
-!
-
 heightOn:aDevice
     "return the height - the height in pixels of the highest character"
 
@@ -486,13 +536,32 @@
 !
 
 maxAscent
+    "return the maximum ascent; thats the ascent of the highest
+     character"
+
     ^ ascent.
 !
 
+maxDescent
+    "return the maximum descent; thats the descent of the highest
+     character"
+
+    ^ descent.
+!
+
 maxHeight
+    "return the maximum height; thats the height of the highest
+     character"
+
     ^ descent + ascent.
 !
 
+maxWidth 
+    "return the maximum width - the width of the widest character in pixels"
+
+    ^ width
+!
+
 on:aDevice
     "return a device representation of the receiver"
 
@@ -530,18 +599,10 @@
     ^ sumW
 !
 
-widthOfCharacter:ascii
-    "return the width of a specific character"
-
-    |glyph|
+widthOf:aString from:startIndex to:endIndex on:aDevice
+    "return the width of a substring"
 
-    (ascii between:0 and:255) ifFalse:[^ 0].
-    glyph := characterBitmaps at:(ascii + 1).
-    glyph isNil ifTrue:[
-	glyph := characterBitmaps at:(Character space asciiValue + 1).
-    ].
-    glyph isNil ifTrue:[^ 0].
-    ^ glyph width
+    ^ self widthOf:aString from:startIndex to:endIndex
 !
 
 widthOn:aDevice
@@ -553,5 +614,5 @@
 !BitmapFont class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.1 1996-10-22 21:47:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/BitmapFont.st,v 1.2 1997-01-04 12:43:25 cg Exp $'
 ! !