eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CompoundFont':

Home

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

Class: CompoundFont


Inheritance:

   Object
   |
   +--FontDescription
      |
      +--CompoundFont

Package:
stx:libview
Category:
Graphics-Support
Version:
rev: 1.11 date: 2017/02/22 20:20:15
user: cg
file: CompoundFont.st directory: libview
module: stx stc-classLibrary: libview
Author:
Claus Gittinger

Description:


a CompountFont is a font which consists of character glyphs from multiple
other (base-)fonts; for each character code, an individual font may be given.

This has been mostly added to allow for non-EURO fonts to be used with ST/X,
by defining a mixedFont, which has an EURO-glyph at the desired character
position.
Do not hardCode usage of MixedFonts into your application, since they
might disappear in the future (when Unicode support has been fully 
implemented in ST/X, and Unicode fonts are generally available under X).
I.e. to use these fonts, add appropriate setup to the styleSheet,
or private.rc and use those fonts transparently.

[Instance variables:]

  baseFont                  <Font>          fallback (default-) font
  characterToFontMapping    <Dictionary>    maps characters to a fonts

[class variables:]


Related information:

    Font
    BitmapFont
    DeviceDrawable
    GraphicsContext

Class protocol:

instance creation
o  basedOn: aRealFont


Instance protocol:

accessing
o  baseFont
return the value of the instance variable 'baseFont' (automatically generated)

o  baseFont: something
set the value of the instance variable 'baseFont' (automatically generated)

o  glyphAt: char putFont: aFont

o  graphicsDevice
return the device I am on

displaying
o  displayString: aString from: index1 to: index2 x: x0 y: y0 in: aGC opaque: opaque
this is only called for fonts which have a nil fontId,
and therefore use the replacementFont. Should never be called
for non-replacement fonts.

printing
o  userFriendlyName

private
o  computeMaxBounds

o  substringPartsOf: aString from: index1 to: index2 do: aBlock
helper - evaluate aBlock for parts of a string, which use the same font.
aBlock is invoked for consecutive substrings, passing the string,
the startIndex, endIndex and the font as arguments.

queries
o  ascent

o  descent

o  height

o  isFixedWidth
return true, if this is a fixed pitch font
(i.e. all characters are of the same width)

o  maxAscent

o  maxDescent

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

o  widthOf: aString from: index1 to: index2


Examples:


a mixed font; all vowels are displayed in times; the rest in helvetica.
|font top list|

font := CompoundFont basedOn:(Font family:'courier' size:18).
#($a $e $i $o $u) do:[:char |
    font glyphAt:char putFont:(Font family:'times' size:18).
].
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.
|font font2 top list|

font := CompoundFont basedOn:(Font family:'courier' size:18).
font2 := Font family:'times' size:24.

#($a $e $i $o $u $j) do:[:char |
    font glyphAt:char putFont:font2.
    font glyphAt:char asUppercase putFont:font2.
].
top := ScrollableView forView:(list := EditTextView new).
list font:font.
list list:#('hello' 'abcdefghijklmnopqrstuvwxyz' 'xyz'
            'HELLO' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'XYZ').
top extent:200@200.
top open.
a mixed font; the dollar character is replaced by the european EURO symbol; the rest is helvetica (this is a hack - we really need a resizable font for this):
|font baseFont euroGlyph glyphs euroFont top list|

baseFont := Font family:'helvetica' size:12.
baseFont := baseFont onDevice:Display.
glyphs := Array new:256.
euroGlyph := Form 
                width:12 
                height:16 
                fromArray:#( 
                            2r00000000 2r00000000
                            2r00000000 2r00000000
                            2r00000000 2r00000000
                            2r00000111 2r11000000
                            2r00001000 2r00100000
                            2r00010000 2r00000000
                            2r01111111 2r10000000
                            2r00010000 2r00000000
                            2r01111111 2r10000000
                            2r00010000 2r00000000
                            2r00001000 2r00100000
                            2r00000111 2r11000000
                            2r00000000 2r00000000
                            2r00000000 2r00000000
                            2r00000000 2r00000000
                            2r00000000 2r00000000
                           ).
glyphs at:($$ asciiValue+1) put:euroGlyph.

euroFont := BitmapFont new glyphs:glyphs.
euroFont setAscent:(baseFont ascent).
euroFont setDescent:(baseFont descent).

font := CompoundFont basedOn:baseFont.
font glyphAt:$$ putFont:euroFont.

top := ScrollableView forView:(list := EditTextView new).
list font:font.
list list:#('100 $' '193 DM').
top extent:200@200.
top open.


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 22 Sep 2018 07:36:26 GMT