eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'BitmapFont':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: BitmapFont


Inheritance:

   Object
   |
   +--FontDescription
      |
      +--BitmapFont

Package:
stx:libview
Category:
Graphics-Support
Version:
rev: 1.17 date: 2023/05/26 11:45:09
user: cg
file: BitmapFont.st directory: libview
module: stx stc-classLibrary: libview

Description:


This class demonstrates, that it is possible to define your own
renderers for fonts - you could even write a class which reads 
a truetype font from a ttf file and display those 
(maybe someone finds the time to do this 
 and provides the code to the public domain ?)

Here is a simple & sample implementation of private bitmap fonts;
Glyphs for each character are stored in the instance variable
'characterBitmaps'.
Some sample glyphs can be created with the class' sampleGlyphs method.
The required protocol is found in drawing and accessing.

copyright

COPYRIGHT (c) 1994 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred. This is a demo example: THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Class protocol:

instance creation
o  new
BitmapFont new glyphs:(self sampleGlyhps).

private
o  sampleGlyhps
return the bitmap array for a sample font
(only contains glyphs for $a and $z)

o  smilyGlyhps
return the bitmap array for a smily font
(only contains glyphs for $a, $b and $c)


Instance protocol:

accessing
o  glyphs: aGlyphArray
set the glyphs array; that is the collection of
bitmaps - one for each character

o  setAscent: aNumber
set the font's ascent; that is the number of pixels
above the baseline

o  setDescent: aNumber
set the font's ascent; that is the number of pixels
below the baseline

drawing
o  displayString: aString from: index1 to: index2 x: x0 y: y in: aGC opaque: opaque
required protocol for new fonts:
- display part of a string, drawing foreground pixels only

private - drawing
o  drawCharacter: ascii in: aGC x: x y: y opaque: opaque

private - queries
o  glyphOfCharacter: ascii
return the height of a specific character

o  heightOfCharacter: ascii
return the height of a specific character

o  widthOfCharacter: ascii
return the width of a specific character

queries
o  ascent
return the ascent - the number of pixels above the baseLine

o  ascentOn: aDevice
return the descent - the number of pixels below the baseLine.
Since I am not device dependent, return my pixel ascent.

o  descent
return the descent - the number of pixels below the baseLine

o  descentOn: aDevice
return the descent - the number of pixels below the baseLine.
Since I am not device dependent, return my pixel descent.

o  height
return the height - the height in pixels of the highest character

o  heightOf: aString
return the height - the height in pixels of the highest character

o  heightOn: aDevice
return the height - the height in pixels of the highest character

o  isFixedWidth
return true if all of the font's characters are equal in
width.

o  maxAscent
return the maximum ascent;
that's the ascent of the highest character

o  maxDescent
return the maximum descent;
that's the descent of the highest character

o  maxHeight
return the maximum height;
that's the height of the highest character

o  maxWidth
return the maximum width - the width of the widest character in pixels

o  onDevice: aDevice
return a device representation of the receiver.
Since I am device independent, return the receiver.

o  width
return the width - the average width in pixels

o  widthOf: aString from: start to: stop
return the width of a substring

o  widthOf: aString from: startIndex to: endIndex on: aDevice
return the width of a substring

o  widthOn: aDevice
return the width - the average width in pixels


Examples:


a label showing characters in a new bitmap font:
  |font l|

  font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
  font setAscent:13; setDescent:3.

  l := Label new.
  l font:font.
  l label:'aazzazaz'.
  l open.
a label showing characters in a new smily font:
  |font l|

  font := (BitmapFont new glyphs:(BitmapFont smilyGlyhps)).
  font setAscent:16; setDescent:0.

  l := Label new.
  l font:font.
  l label:'aabbaaa'.
  l open.
demonstrate, that this font can be used in listViews just as any other font: (well, missing character glyphs are blanked)
  |font top list|

  font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
  font setAscent:13; setDescent:3.

  top := ScrollableView forView:(list := SelectionInListView new).
  list font:font.
  list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz').
  top extent:200@200.
  top open.
demonstrate, that this font can be used in textViews just as any other font: (well, missing character glyphs are blanked)
  |font top list|

  font := (BitmapFont new glyphs:(BitmapFont sampleGlyhps)).
  font setAscent:13; setDescent:3.

  top := ScrollableView forView:(list := EditTextView new).
  list font:font.
  list list:#('a' 'z' 'aaa' 'zzz' 'azaz' 'zaza' 'aa' 'az' 'za' 'hello' 'abcdef' 'xyz').
  top extent:200@200.
  top open.
another clock display: defines a font with the 7-segment led bitmaps as glyphs for 0-9, then simply displays the time as a string in that font.
  |glyphs f label|

  glyphs := Array new:256.
  glyphs 
      at:($0 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led0.xpm').
  glyphs 
      at:($1 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led1.xpm').
  glyphs 
      at:($2 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led2.xpm').
  glyphs 
      at:($3 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led3.xpm').
  glyphs 
      at:($4 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led4.xpm').
  glyphs 
      at:($5 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led5.xpm').
  glyphs 
      at:($6 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led6.xpm').
  glyphs 
      at:($7 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led7.xpm').
  glyphs 
      at:($8 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led8.xpm').
  glyphs 
      at:($9 asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/led9.xpm').
  glyphs 
      at:($: asciiValue + 1) 
      put:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/misc_numbers/ledCol.xpm').

  f := BitmapFont new glyphs:glyphs.

  label := Label new label:(Time now printString).
  label font:f.
  label open


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 13:14:17 GMT