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.14 date: 2016/09/22 13:02:18
user: cg
file: BitmapFont.st directory: libview
module: stx stc-classLibrary: libview
Author:
Claus Gittinger

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.


Related information:

    Font
    GraphicsContext

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.1.0.0; WebServer 1.663 at exept.de:8081; Wed, 19 Sep 2018 03:16:32 GMT