|
Class: Font
Object
|
+--FontDescription
|
+--Font
- Package:
- stx:libview
- Category:
- Graphics-Support
- Version:
- rev:
1.159
date: 2023/05/26 11:44:49
- user: cg
- file: Font.st directory: libview
- module: stx stc-classLibrary: libview
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
copyrightCOPYRIGHT (c) 1992 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.
initialization
-
initialize
-
initialize the font tracking array
instance creation
-
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.
accessing
-
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) **
-
fontId
-
return the device-dependent font-id
copying
-
deepCopyUsing: aDictionary postCopySelector: postCopySelector
-
displaying
-
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.
-
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
-
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
|
-
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).
-
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
-
executor
-
redefined to return a lightweight copy
- all we need is the device handle
-
releaseFromDevice
-
I am no longer available on the device
-
restored
-
private: instance has been restored (either from snapin or binary store);
flush device handles
object persistency
-
elementDescriptorFor: aspect
-
support for persistency:
answer the elements to be made persistent with an ObjectCoder
printing & storing
-
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
-
getFontInfos
-
ask the device about all of my actual attributes
-
getFontMetrics
-
ask the device about all of my actual attributes
Usage example(s):
(View defaultFont onDevice:Screen current) getFontMetrics
|
-
getFontResolution
-
ask the device about all of my actual attributes
-
installInDeviceForGCId: aGCId
-
install the font for aGCId
-
setDevice: aDevice
-
set the device handle
-
setDevice: aDevice fontId: aFontId
-
set the device and font handles
-
setFamily: familyString face: faceString style: styleString size: sizeNum encoding: encodingSym device: aDevice
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
setFamily: familyString face: faceString style: styleString size: sizeArg sizeUnit: sizeUnitArg encoding: encodingSym device: aDevice
-
set my instance attributes
-
setFontId: aFontId
-
set my font handle
-
setReplacementFont: aFont
-
set my replacement font
queries-deviceFonts
-
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
|
-
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.
-
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
-
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.
-
ascentOn: aDevice
-
return the font's ascent (average), if used on aDevice.
-
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.
-
descentOn: aDevice
-
return the font's descent (average), if used on aDevice.
-
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.
-
heightOf: textOrString
-
return the height (device specific) of the argument;
the argument must be a String.
CAVEAT:
currently only constant height fonts are supported.
-
heightOf: aString on: aDevice
-
return the height of aString, if displayed on aDevice.
The argument must be a string-like object.
-
heightOn: aDevice
-
return the font's height (average), if used on aDevice.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
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
-
direction
-
-
graphicsDevice
-
same as #device, for ST-80 compatibility naming.
Return the device I am associated with.
-
maxAscii
-
squeak compatibility
-
maxCode
-
(comment from inherited method)
return the biggest UCS code in font.
Dummy for now
-
minAscii
-
squeak compatibility
-
minCode
-
(comment from inherited method)
return the smallest UCS code in font.
Dummy for now
st-80 queries
-
fixedWidth
-
return true, if this font is a fixed width font -
for st-80 compatibility
-
pixelSize
-
return the height of the font in pixels -
for st-80 compatibility
testing
-
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.
DeviceFontHandle
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
...
|