--- a/Font.st Tue Apr 30 16:12:35 1996 +0200
+++ b/Font.st Tue Apr 30 17:31:16 1996 +0200
@@ -120,12 +120,73 @@
[see also:]
DeviceWorkstation
- DeviceDrawable
+ DeviceDrawable GraphicsContext
Cursor Color
+ ( introduction to view programming :html: programming/viewintro.html#FONTS )
[author:]
Claus Gittinger
"
+!
+
+examples
+"
+ standard fonts:
+
+ aFont := Font family:'courier' size:12
+
+ aFont := Font
+ family:'helvetica'
+ face:'roman'
+ style:'bold'
+ size:16
+
+
+ special (non-portable displayType specific) fonts:
+
+ aFont := Font name:'6x10'
+
+ aFont := Font name:'k14'
+
+
+ setting the font of a button:
+ [exBegin]
+ |b|
+
+ b := Button new.
+ b label:'hello'.
+ b font:(Font family:'helvetica'
+ face:'medium'
+ style:'roman'
+ size:16).
+ b open
+ [exEnd]
+
+ 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 on:aDevice.
+ ...
+ aFont widthOf:'hello'
+ ...
+ aFont ascent
+ ...
+"
! !
!Font class methodsFor:'initialization'!
@@ -632,6 +693,96 @@
!Font methodsFor:'queries'!
+ascentOn:aDevice
+ "return the fonts ascent (average), if used on aDevice."
+
+ device == aDevice ifTrue:[
+ ^ ascent
+ ].
+ ^ (self on:aDevice) ascent
+
+ "Created: 30.4.1996 / 16:41:32 / cg"
+ "Modified: 30.4.1996 / 16:44:49 / cg"
+!
+
+descentOn:aDevice
+ "return the fonts descent (average), if used on aDevice."
+
+ device == aDevice ifTrue:[
+ ^ descent
+ ].
+ ^ (self on:aDevice) descent
+
+ "Created: 30.4.1996 / 16:41:43 / cg"
+ "Modified: 30.4.1996 / 16:45:02 / cg"
+!
+
+existsOn:aDevice
+ "return true, if the recevier is available on aDevice;
+ false otherwise. This is a kludge method; its better to
+ ask a device for its available fonts and use this info ...
+ Notice, that if you simply use a font by name, the system
+ will automatically take a replacement font."
+
+ ^ (self on:aDevice ifAbsent:nil) notNil
+!
+
+heightOn:aDevice
+ "return the fonts height (average), if used on aDevice."
+
+ device == aDevice ifTrue:[
+ ^ descent + ascent
+ ].
+ ^ (self on:aDevice) height
+
+ "Created: 30.4.1996 / 16:41:59 / cg"
+ "Modified: 30.4.1996 / 16:44:39 / cg"
+!
+
+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."
+
+ device == aDevice ifTrue:[
+ ^ self widthOf:aString from:startIndex to:endIndex
+ ].
+ ^ (self on:aDevice) widthOf:aString from:startIndex to:endIndex
+
+ "Modified: 30.4.1996 / 17:14:50 / cg"
+ "Created: 30.4.1996 / 17:15:20 / cg"
+!
+
+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."
+
+ device == aDevice ifTrue:[
+ ^ self widthOf:aString
+ ].
+ ^ (self on:aDevice) widthOf:aString
+
+ "Created: 30.4.1996 / 17:14:18 / cg"
+ "Modified: 30.4.1996 / 17:14:50 / cg"
+!
+
+widthOn:aDevice
+ "return the fonts 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)."
+
+ device == aDevice ifTrue:[
+ ^ descent + ascent
+ ].
+ ^ (self on:aDevice) width
+
+ "Created: 30.4.1996 / 16:42:28 / cg"
+ "Modified: 30.4.1996 / 16:43:50 / cg"
+! !
+
+!Font methodsFor:'queries-deviceFonts'!
+
ascent
"return the font-ascent (i.e. the normal average of all characters);
That is the number of units (usually pixels) above the baseline.
@@ -662,24 +813,20 @@
^ descent
!
-existsOn:aDevice
- "return true, if the recevier is available on aDevice;
- false otherwise. This is a kludge method; its better to
- ask a device for its available fonts and use this info ...
- Notice, that if you simply use a font by name, the system
- will automatically take a replacement font."
+fullName
+ "return the full (device specific) name of the receiver.
+ This is query only valid if the receiver is associated to a device"
- ^ (self on:aDevice ifAbsent:nil) notNil
-!
-
-fullName
device isNil ifTrue:[
^ nil
].
^ device fullNameOf:fontId.
- "Created: 23.2.1996 / 00:44:10 / cg"
- "Modified: 23.2.1996 / 00:46:44 / cg"
+ "
+ ((Font name:'6x10') on:Display) fullName
+ "
+
+ "Modified: 30.4.1996 / 17:30:10 / cg"
!
height
@@ -790,17 +937,19 @@
"return the fonts 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.
+ 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."
device isNil ifTrue:[
- self errorNoDevice.
+ self errorNoDevice.
].
replacementFont notNil ifTrue:[
- ^ replacementFont width
+ ^ replacementFont width
].
^ width
+
+ "Modified: 30.4.1996 / 16:43:45 / cg"
!
widthOf:textOrString
@@ -891,6 +1040,6 @@
!Font class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.40 1996-04-25 16:25:34 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.41 1996-04-30 15:31:16 cg Exp $'
! !
Font initialize!