Font.st
changeset 2545 829790f194cc
parent 2433 b2d7a24db748
child 2767 04fdb969488a
--- a/Font.st	Tue Mar 30 19:40:13 1999 +0200
+++ b/Font.st	Tue Mar 30 19:41:20 1999 +0200
@@ -73,12 +73,20 @@
         '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.
@@ -315,37 +323,23 @@
 
     |prevFont|
 
+    prevFont := aGC font.
     replacementFont isNil ifTrue:[
-        'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
-        ^ self
+        fontId notNil ifTrue:[
+            aGC basicFont:self.
+            aGC displayOpaqueString:aString from:index1 to:index2 x:x y:y.
+        ] ifFalse:[
+            'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
+        ].
+    ] ifFalse:[
+        aGC basicFont:replacementFont.
+        aGC displayOpaqueString:aString from:index1 to:index2 x:x y:y.
     ].
-    prevFont := aGC font.
-    aGC basicFont:replacementFont.
-    aGC displayOpaqueString:aString from:index1 to:index2 x:x y:y.
     aGC basicFont:prevFont
 
     "Modified: 10.1.1997 / 17:51:10 / cg"
 !
 
-displayOpaqueString:aString x:x y:y in:aGC
-    "this is only called for fonts which have a nil fontId,
-     and therefore use the replacementFont. Should never be called
-     for non-replacement fonts."
-
-    |prevFont|
-
-    replacementFont isNil ifTrue:[
-        'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
-        ^ self
-    ].
-    prevFont := aGC font.
-    aGC basicFont:replacementFont.
-    aGC displayOpaqueString:aString x:x y:y.
-    aGC basicFont:prevFont.
-
-    "Modified: 10.1.1997 / 17:51:14 / cg"
-!
-
 displayString:aString from:index1 to:index2 x:x y:y in:aGC
     "this is only called for fonts which have a nil fontId,
      and therefore use the replacementFont. Should never be called
@@ -353,35 +347,21 @@
 
     |prevFont|
 
+    prevFont := aGC font.
     replacementFont isNil ifTrue:[
-        'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
-        ^ self
+        fontId notNil ifTrue:[
+            aGC basicFont:self.
+            aGC displayString:aString from:index1 to:index2 x:x y:y.
+        ] ifFalse:[
+            'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
+        ].
+    ] ifFalse:[
+        aGC basicFont:replacementFont.
+        aGC displayString:aString from:index1 to:index2 x:x y:y.
     ].
-    prevFont := aGC font.
-    aGC basicFont:replacementFont.
-    aGC displayString:aString from:index1 to:index2 x:x y:y.
     aGC basicFont:prevFont.
 
     "Modified: 10.1.1997 / 17:51:17 / cg"
-!
-
-displayString:aString x:x y:y in:aGC
-    "this is only called for fonts which have a nil fontId,
-     and therefore use the replacementFont. Should never be called
-     for non-replacement fonts."
-
-    |prevFont|
-
-    replacementFont isNil ifTrue:[
-        'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
-        ^ self
-    ].
-    prevFont := aGC font.
-    aGC basicFont:replacementFont.
-    aGC displayString:aString x:x y:y.
-    aGC basicFont:prevFont.
-
-    "Modified: 10.1.1997 / 17:51:22 / cg"
 ! !
 
 !Font methodsFor:'getting a device font'!
@@ -688,7 +668,54 @@
     "Modified: 20.4.1996 / 23:27:16 / cg"
 ! !
 
-!Font methodsFor:'queries'!
+!Font methodsFor:'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"
+
+    device isNil ifTrue:[
+        ^ nil
+    ].
+    ^ device fullNameOf:fontId.
+
+    "
+     ((Font name:'6x10') on:Display) fullName  
+    "
+
+    "Modified: 30.4.1996 / 17:30:10 / cg"
+!
+
+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."
+
+    device isNil ifTrue:[
+	self errorNoDevice.
+    ].
+    replacementFont notNil ifTrue:[
+	^ replacementFont isFixedWidth
+    ].
+    ^ isFixedWidth
+! !
+
+!Font methodsFor:'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."
+
+    device isNil ifTrue:[
+	self errorNoDevice
+    ].
+    replacementFont notNil ifTrue:[
+	^ replacementFont ascent
+    ].
+    ^ ascent
+!
 
 ascentOn:aDevice
     "return the fonts ascent (average), if used on aDevice."
@@ -705,130 +732,6 @@
     "Modified: / 10.9.1998 / 12:09:06 / cg"
 !
 
-descentOn:aDevice
-    "return the fonts descent (average), if used on aDevice."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont descentOn:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ descent
-    ].
-    ^ (self on:aDevice) descent
-
-    "Created: / 30.4.1996 / 16:41:43 / cg"
-    "Modified: / 10.9.1998 / 12:09:30 / 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
-!
-
-heightOf:aString on:aDevice
-    "return the height of aString, if displayed on aDevice.
-     The argument must be a string-like object."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont heightOf:aString on:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ self heightOf:aString
-    ].
-    ^ (self on:aDevice) heightOf:aString
-
-    "Created: / 30.4.1996 / 17:14:18 / cg"
-    "Modified: / 10.9.1998 / 12:09:47 / cg"
-!
-
-heightOn:aDevice
-    "return the fonts height (average), if used on aDevice."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont heightOn:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ descent + ascent
-    ].
-    ^ (self on:aDevice) height
-
-    "Created: / 30.4.1996 / 16:41:59 / cg"
-    "Modified: / 10.9.1998 / 12:08:18 / 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."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont widthOf:aString from:startIndex to:endIndex on:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ self widthOf:aString from:startIndex to:endIndex
-    ].
-    ^ (self on:aDevice) widthOf:aString from:startIndex to:endIndex
-
-    "Created: / 30.4.1996 / 17:15:20 / cg"
-    "Modified: / 10.9.1998 / 12:10:11 / 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."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont widthOf:aString on:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ self widthOf:aString
-    ].
-    ^ (self on:aDevice) widthOf:aString
-
-    "Created: / 30.4.1996 / 17:14:18 / cg"
-    "Modified: / 10.9.1998 / 12:10:26 / 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)."
-
-    replacementFont notNil ifTrue:[
-        ^ replacementFont widthOn:aDevice
-    ].
-    device == aDevice ifTrue:[
-        ^ self width
-    ].
-    ^ (self on:aDevice) width
-
-    "Created: / 30.4.1996 / 16:42:28 / cg"
-    "Modified: / 10.9.1998 / 12:11:33 / 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.
-     The receiver must be associated to a device,
-     for this query to be legal."
-
-    device isNil ifTrue:[
-	self errorNoDevice
-    ].
-    replacementFont notNil ifTrue:[
-	^ replacementFont ascent
-    ].
-    ^ ascent
-!
-
 descent
     "return the font-descent (i.e. the normal average of all characters);
      That is the number of units (usually pixels) below the baseline.
@@ -844,20 +747,19 @@
     ^ descent
 !
 
-fullName
-    "return the full (device specific) name of the receiver.
-     This is query only valid if the receiver is associated to a device"
+descentOn:aDevice
+    "return the fonts descent (average), if used on aDevice."
 
-    device isNil ifTrue:[
-        ^ nil
+    replacementFont notNil ifTrue:[
+        ^ replacementFont descentOn:aDevice
     ].
-    ^ device fullNameOf:fontId.
+    device == aDevice ifTrue:[
+        ^ descent
+    ].
+    ^ (self on:aDevice) descent
 
-    "
-     ((Font name:'6x10') on:Display) fullName  
-    "
-
-    "Modified: 30.4.1996 / 17:30:10 / cg"
+    "Created: / 30.4.1996 / 16:41:43 / cg"
+    "Modified: / 10.9.1998 / 12:09:30 / cg"
 !
 
 height
@@ -894,18 +796,35 @@
     "Created: 12.5.1996 / 11:05:00 / cg"
 !
 
-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."
+heightOf:aString on:aDevice
+    "return the height of aString, if displayed on aDevice.
+     The argument must be a string-like object."
+
+    replacementFont notNil ifTrue:[
+        ^ replacementFont heightOf:aString on:aDevice
+    ].
+    device == aDevice ifTrue:[
+        ^ self heightOf:aString
+    ].
+    ^ (self on:aDevice) heightOf:aString
 
-    device isNil ifTrue:[
-	self errorNoDevice.
-    ].
+    "Created: / 30.4.1996 / 17:14:18 / cg"
+    "Modified: / 10.9.1998 / 12:09:47 / cg"
+!
+
+heightOn:aDevice
+    "return the fonts height (average), if used on aDevice."
+
     replacementFont notNil ifTrue:[
-	^ replacementFont isFixedWidth
+        ^ replacementFont heightOn:aDevice
+    ].
+    device == aDevice ifTrue:[
+        ^ descent + ascent
     ].
-    ^ isFixedWidth
+    ^ (self on:aDevice) height
+
+    "Created: / 30.4.1996 / 16:41:59 / cg"
+    "Modified: / 10.9.1998 / 12:08:18 / cg"
 !
 
 maxAscent
@@ -988,8 +907,7 @@
      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."
+     The receiver must be associated to a device, for this query to be legal."
 
     device isNil ifTrue:[
         self errorNoDevice.
@@ -1069,6 +987,57 @@
 	^ device widthOf:aString from:start to:stop inFont:fontId
     ].
     ^ (stop - start + 1) * width
+!
+
+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."
+
+    replacementFont notNil ifTrue:[
+        ^ replacementFont widthOf:aString from:startIndex to:endIndex on:aDevice
+    ].
+    device == aDevice ifTrue:[
+        ^ self widthOf:aString from:startIndex to:endIndex
+    ].
+    ^ (self on:aDevice) widthOf:aString from:startIndex to:endIndex
+
+    "Created: / 30.4.1996 / 17:15:20 / cg"
+    "Modified: / 10.9.1998 / 12:10:11 / 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."
+
+    replacementFont notNil ifTrue:[
+        ^ replacementFont widthOf:aString on:aDevice
+    ].
+    device == aDevice ifTrue:[
+        ^ self widthOf:aString
+    ].
+    ^ (self on:aDevice) widthOf:aString
+
+    "Created: / 30.4.1996 / 17:14:18 / cg"
+    "Modified: / 10.9.1998 / 12:10:26 / 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)."
+
+    replacementFont notNil ifTrue:[
+        ^ replacementFont widthOn:aDevice
+    ].
+    device == aDevice ifTrue:[
+        ^ self width
+    ].
+    ^ (self on:aDevice) width
+
+    "Created: / 30.4.1996 / 16:42:28 / cg"
+    "Modified: / 10.9.1998 / 12:11:33 / cg"
 ! !
 
 !Font methodsFor:'st-80 queries'!
@@ -1134,6 +1103,6 @@
 !Font class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.65 1999-02-03 15:16:55 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.66 1999-03-30 17:40:54 cg Exp $'
 ! !
 Font initialize!