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.13 date: 2023/08/02 11:47:58
user: cg
file: CompoundFont.st directory: libview
module: stx stc-classLibrary: libview

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:]

copyright

COPYRIGHT (c) 1999 by Claus Gittinger / eXept Software AG 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  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
define an individual character to be drawn in another font

o  glyphsFrom: start to: stop putFont: aFont
define a range of characters to be drawn in another font

o  graphicsDevice
return the device I am on

converting
o  asSize: anotherPointSize
(comment from inherited method)
return another font corresponding to the receiver's family,
face and style but with another (point-) size

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
(comment from inherited method)
return a user-friendly printed representation of the receiver

private
o  computeMaxBounds

o  fontFor: aCharacter

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.

Usage example(s):

     |f|

     f := self new.
     f baseFont:#baseFont.
     f fontAt:$$ put:#font2.
     f substringPartsOf:'ae$a' from:1 to:8 
       do:[:s :i1 :i2 :f |
             Transcript 
                     show:i1; space;
                     show:i2; space;
                     showCR:f
          ]

queries
o  ascent
(comment from inherited method)
return the ascent - the number of pixels above the baseLine.

o  descent
(comment from inherited method)
return the descent - the number of pixels below the baseLine.

o  height
(comment from inherited method)
return the height - the number of pixels above plus below the baseLine.

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

o  maxAscent
(comment from inherited method)
return the font's maximum-ascent (i.e. the maximum of all characters);
That is the number of units (usually pixels) above the baseline.

o  maxDescent
(comment from inherited method)
return the font's maximum-descent (i.e. the maximum of all characters);
That is the number of units (usually pixels) below the baseline.

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

o  size
(comment from inherited method)
return the size, a number

o  widthOf: aString from: index1 to: index2
(comment from inherited method)
return the width of a sub string


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.
mix courier with a font which has emojis
|baseFont emojiFont mixedFont mixedFont2 top list|

baseFont := Font family:'courier' size:14.
baseFont := baseFont onDevice:Display.

emojiFont := Font family:'symbola' size:14.

mixedFont := CompoundFont basedOn:baseFont.
mixedFont glyphsFrom:0x1F600 to:0x1F6FF putFont:emojiFont.

top := ScrollableView forView:(list := EditTextView new).
list font:mixedFont.
list list:{ 'Hello Emoji',#(0x1f600) asUnicodeString}.
top extent:200@200.
top open.

mixedFont2 := mixedFont asSize:20.

top := ScrollableView forView:(list := EditTextView new).
list font:mixedFont2.
list list:{ 'Hello Emoji',#(0x1f600) asUnicodeString}.
top extent:200@200.
top open.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:19:18 GMT