eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Font':

Home

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

Class: Font


Inheritance:

   Object
   |
   +--FontDescription
      |
      +--Font

Package:
stx:libview
Category:
Graphics-Support
Version:
rev: 1.153 date: 2019/07/25 11:01:10
user: cg
file: Font.st directory: libview
module: stx stc-classLibrary: libview
Author:
Claus Gittinger

Description:


Font represents fonts in a device independent manner; after being
created using 'Font family:family face:face style:style size:size',
the returned font is not associated to a specific device.
(therefore, those fonts can be used to draw on any GC)

To get a device font, any font can be sent the message
'aFont onDevice:aDevice' which returns an instance of Font which is
associated to a device (it returns the receiver, if that is already
associated to that device).

For proper operation, each graphics operation working with fonts
must get a device font before doing the draw.
Most draw methods in DeviceDrawable do that automatically for you,
before doing the draw; so you do not have to care.

However, some operations require explicit conversion to a device font
before being allowed. For example, a query for a font's height (in device
units) can only be done if the font being asked is associated to
a device (which should be clear, since a 'courier-roman-12' font may
have a different number of pixels on a 75dpi vs. a 120dpi display. And
a totally different number of device units on a 600dpi laser printer.
Thus, to query a font for its height (or ascent, or descent, or width),
use something like:

    myFont := Font family:'courier' ... size:12.
        ...

    'want to know its height on the Display'

    h := (myFont on:Display) height.

    'want to know its height on a printer'

    h := (myFont on:aPrinter) height.

there are alternative shortcuts for these operations:

    h := myFont heightOn:Display.
    h := myFont heightOn:Printer.

    or:

    a := myFont ascentOn:Display.

Keep in mind, that each device is free to think in whatever units it
likes - a display may return units of pixels, a postscript printer may
think in (fractions of) inches, a dot matrix printer may think in dots.
Also, notice that currently only graphic displays are really supported;
printer devices are being developed and may or may not be in the current
system.

If a font cannot be represented on a device, a replacement
font is chosen and kept in the replacementFont instance variable.
This is done to preserve the original font information, in case the image
is restarted later on another display which has that font available.


[Instance variables:]

  family          <String>        the font's family ('courier', 'helvetica' etc)
  face            <String>        the font's face ('bold', 'medium' etc)
  style           <String>        the font's style ('roman', 'italic', 'oblique')
  size            <String>        the font's size (not in pixels)
  encoding        <Symbol>        the font's encoding (usually #iso8859)

  device          <Object>        the device the font is associated to, or nil
  fontId          <Object>        the id of the font on that device, or nil
  replacement     <Font>          the replacement font or nil

  ascent          <Integer>       the font's ascent in device units on device
  descent         <Integer>       the font's descent in device units on device
  width           <Integer>       the character width in device units on device
                                  (for variable fonts, its the width of a space)
  isFixedWidth    <Boolean>       true if font is a fixed width font
  minWidth        <Integer>       width of the smallest-width character in
                                  in device units on device
  maxWidth        <Integer>       width of the largest-width character in
                                  in device units on device

[class variables:]

  Replacements    <Dictionary>    replacement fonts


Related information:

    DeviceWorkstation
    DeviceDrawable
    GraphicsContext
    Cursor
    Color
    [introduction to view programming]

Class protocol:

initialization
o  initialize
initialize the font tracking array

instance creation
o  family: familyString face: faceString style: styleString size: sizeArgOrNil sizeUnit: sizeUnitArg encoding: encodingSym
returns a font for given family, face, style, size and encoding.
The returned font is not associated to a specific device.


Instance protocol:

accessing
o  device
return the device I am on.
Obsolete - use #graphicsDevice

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  fontId
return the device-dependent font-id

copying
o  deepCopyUsing: aDictionary postCopySelector: postCopySelector

displaying
o  displayString: aString from: index1 to: index2 x: x y: y 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.

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

getting a device font
o  onDevice: aDevice
create a new Font representing the same font as
myself on aDevice; if one already exists, return the one.

usage example(s):

     (Font family:'fooXXXXXX' size:17) onDevice:Screen current

o  onDevice: aDevice xFontsOnly: xFontsOnly xftFontsOnly: xftFontsOnly ifAbsent: exceptionBlock
create a new Font representing the same font as myself on aDevice.
The xFontsOnly/xftFontsOnly are only relevant for XWindow devices;
xFontsOnly will suppress xft fonts, whereas xftFontsOnly will suppress x fonts
(the first is useful if ST/X has a slow remote X connection for display,
on which xft fonts are very slow. Yes, this is actually a reasonable setup
in use at one of our customers)
This does NOT try to look for existing
or replacement fonts (i.e. can be used to get physical fonts).

o  replacementFontOnDevice: aDevice
return a replacement font for the receiver - this is needed, if
an image is restored on another type of display, or one which has
a different set of fonts.

instance release
o  executor
redefined to return a lightweight copy
- all we need is the device handle

object persistency
o  elementDescriptorFor: aspect
support for persistency:
answer the elements to be made persistent with an ObjectCoder

printing & storing
o  printOn: aStream
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.
Redefined to print more about the font's name

private
o  getFontInfos
ask the device about all of my actual attributes

o  getFontMetrics
ask the device about all of my actual attributes

usage example(s):

         (View defaultFont onDevice:Screen current) getFontMetrics

o  getFontResolution
ask the device about all of my actual attributes

o  installInDeviceForGCId: aGCId
install the font for aGCId

o  releaseFromDevice
I am no longer available on the device

o  restored
flush device handles when restored

o  setDevice: aDevice
set the device handle

o  setDevice: aDevice fontId: aFontId
set the device and font handles

o  setFamily: familyString face: faceString style: styleString size: sizeNum encoding: encodingSym device: aDevice

o  setFamily: familyString face: faceString style: styleString size: sizeArg sizeUnit: sizeUnitArg encoding: encodingSym device: aDevice
set my instance attributes

o  setFontId: aFontId
set my font handle

o  setReplacementFont: aFont
set my replacement font

queries-deviceFonts
o  fullName
return the full (device specific) name of the receiver.
This is query only valid if the receiver is associated to a device

usage example(s):

     ((Font name:'6x10') on:Display) fullName  

o  isFixedWidth
return true, if all characters have same width (as in courier).
The receiver must be associated to a device,
for this query to be legal.

o  maxWidth
return the width of the widest character;
if the receiver is a fixed width font its the width of every character.
The receiver must be associated to a device,
for this query to be legal.

queries-dimensions
o  ascent
return the font-ascent (i.e. the normal average of all characters);
That is the number of units (usually pixels) above the baseline.
The receiver must be associated to a device,
for this query to be legal.

o  ascentOn: aDevice
return the font's ascent (average), if used on aDevice.

o  descent
return the font-descent (i.e. the normal average of all characters);
That is the number of units (usually pixels) below the baseline.
The receiver must be associated to a device,
for this query to be legal.

o  descentOn: aDevice
return the font's descent (average), if used on aDevice.

o  height
return the font's characters normal (average) height;
That is the number of units (usually pixels) on the device.
The receiver must be associated to a device,
for this query to be legal.

o  heightOf: textOrString
return the height (device specific) of the argument;
the argument must be a String.
CAVEAT:
currently only constant height fonts are supported.

o  heightOf: aString on: aDevice
return the height of aString, if displayed on aDevice.
The argument must be a string-like object.

o  heightOn: aDevice
return the font's height (average), if used on aDevice.

o  maxAscent
return the font's maximum-ascent (i.e. the maximum of all characters);
That is the number of units (usually pixels) above the baseline.
The receiver must be associated to a device,
for this query to be legal.

o  maxDescent
return the font-descent (i.e. the maximum of all characters);
That is the number of units (usually pixels) below the baseline.
The receiver must be associated to a device,
for this query to be legal.

o  maxHeight
return the font's characters maximum height;
That is the number of units (usually pixels) on the device.
The receiver must be associated to a device,
for this query to be legal.

o  minWidth
return the width of the smallest character;
if the receiver is a fixed width font its the width of every character.
The receiver must be associated to a device,
for this query to be legal.

o  width
return the font's characters width;
That is the number of units (usually pixels) on the device.
For variable pitch fonts, the width of the space character is returned.
For fixed fonts, this is the same as minWidth or maxWidth (or any character).
The receiver must be associated to a device, for this query to be legal.

o  widthOf: textOrString
return the width (device specific) of the argument;
the argument may be a Character, String or some Text;
in the last case the width of the longest line in the text is returned.
The receiver must be associated to a device,
for this query to be legal.

o  widthOf: aString from: start to: stop
return the width of a substring.
The receiver must be associated to a device,
for this query to be legal.

o  widthOf: aString from: startIndex to: endIndex on: aDevice
return the width of substring, if displayed on aDevice.
The argument may be a Character, String or some Text;
in the last case the width of the longest line in the text is returned.

o  widthOf: aString on: aDevice
return the width of aString, if displayed on aDevice.
The argument may be a Character, String or some Text;
in the last case the width of the longest line in the text is returned.

o  widthOn: aDevice
return the font's width, if used on aDevice.
For variable pitch fonts, the width of the space character is returned.
For fixed fonts, this is the same as minWidth or maxWidth (or any character).

queries-misc
o  direction

o  graphicsDevice
same as #device, for ST-80 compatibility naming.
Return the device I am associated with.

o  maxAscii
squeak compatibility

o  maxCode

o  minAscii
squeak compatibility

o  minCode

st-80 queries
o  fixedWidth
return true, if this font is a fixed width font -
for st-80 compatibility

o  pixelSize
return the height of the font in pixels -
for st-80 compatibility

testing
o  isAlienFont
answer true, if this is an alien font which does not have a device representation.
Alien fonts are eg. Hershey or Bitmap fonts, which are drawn by st/x itself.


Private classes:

    DeviceFontHandle

Examples:


standard fonts: Font family:'courier' size:12 Font family:'helvetica' face:'roman' style:'bold' size:16 Font family:'helvetica' pixelSize:20 special (non-portable displayType specific) fonts (typically: old X11 fonts): Font name:'6x10' Font name:'k14' setting the font of a button:
    |b|

    b := Button new.
    b label:'hello'.
    b font:(Font family:'helvetica' 
                 face:'medium' 
                 style:'roman' 
                 size:16).
    b open
asking a font about a strings size in pixels, if it was used on some device: aFont widthOf:'hello' on:Display asking about the ascent, if used on some device: aFont ascentOn:Display if the font has been associated to a device, the following are a bit faster: |aFont| ... aFont := aFont onDevice:aDevice. ... aFont widthOf:'hello' ... aFont ascent ...

ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 20 Apr 2024 03:13:17 GMT