class: Font stable
authorStefan Vogel <sv@exept.de>
Fri, 26 Jul 2013 17:53:54 +0200
changeset 6109 e35961f7892a
parent 6108 6ecfb89408d2
child 6110 28bccabea00a
class: Font changed:6 methods fix replacement font handling
Font.st
--- a/Font.st	Fri Jul 26 17:38:47 2013 +0200
+++ b/Font.st	Fri Jul 26 17:53:54 2013 +0200
@@ -216,20 +216,21 @@
             at:'monospace'              put:#('courier new' 'courier' 'andale mono' 'lucidatypewriter' 'fixed').
 
         Replacements 
-            at:'clean'                  put:#('courier');
-            at:'fixed'                  put:#('courier');
-            at:'new century schoolbook' put:#('times');
+            at:'clean'                  put:#('courier new' 'courier');
+            at:'fixed'                  put:#('courier new' 'courier');
+            at:'new century schoolbook' put:#('times' 'times new roman');
             at:'arial'                  put:#('helvetica' 'lucida');
             at:'lucida'                 put:#('arial' 'helvetica');
             at:'lucidabright'           put:#('arial' 'helvetica');
             at:'lucidatypewriter'       put:#('courier' 'courier new');
             at:'courier'                put:#('courier new');
+            at:'courier new'            put:#('courier');
             at:'charter'                put:#('times' 'times new roman');
             at:'times new roman'        put:#('times');
-            at:'times'                  put:#('times');
+            at:'times'                  put:#('times new roman');
             at:'terminal'               put:#('courier' 'courier new');
             at:'helvetica'              put:#('arial' 'lucida').
-    ]
+    ].
 ! !
 
 !Font class methodsFor:'instance creation'!
@@ -278,13 +279,16 @@
      Obsolete - use #graphicsDevice"
 
     <resource:#obsolete>
-
+    self obsoleteMethodWarning:'2013-07-25'.
     ^ device
 !
 
 fontId
     "return the device-dependent font-id"
 
+    replacementFont notNil ifTrue:[
+        ^ replacementFont fontId
+    ].
     ^ fontId
 !
 
@@ -366,41 +370,39 @@
     newFont := self onDevice:aDevice ifAbsent:nil.
     newFont isNil ifTrue:[
         "oops did not work - (device has no such font)"
-
         aDevice isOpen ifFalse:[
             "/ the display device is not connected
             "/ (or has a broken connection).
             aDevice class drawingOnClosedDeviceSignal raiseRequestWith:aDevice.
             ^ self.
         ].
+
         "/ look for a replacement font
-
         rep := self replacementFontOnDevice:aDevice.
         device isNil ifTrue:[
             device := aDevice.
             replacementFont := rep.
-            aDevice registerFont:self.
-            ^ self
+            newFont := self.
+        ] ifFalse:[
+            newFont := self class basicNew.
+            newFont
+                setFamily:family 
+                face:face 
+                style:style 
+                size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size]) 
+                sizeUnit:sizeUnit 
+                encoding:encoding 
+                device:aDevice;
+                isGenericFont:self isGenericFont;
+                setReplacementFont:rep.
         ].
-
-        newFont := (self class basicNew)
-                        setFamily:family 
-                        face:face 
-                        style:style 
-                        size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size]) 
-                        sizeUnit:sizeUnit 
-                        encoding:encoding 
-                        device:aDevice.
-        newFont isGenericFont:self isGenericFont.
-        newFont setReplacementFont:rep.
         aDevice registerFont:newFont.
-        ^ newFont
     ].
 
     ^ newFont
 
     "
-     Font family:'foo' size:17
+     (Font family:'fooXXXXXX' size:17) onDevice:Screen current
     "
 
     "Modified: 14.4.1997 / 18:22:31 / cg"
@@ -453,13 +455,13 @@
 
     alternateFamilyName := family.
     self isGenericFont ifFalse:[
-        trySize := size ? 0.
+        trySize := (sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size]) ? 0.
         [id isNil and:[trySize := trySize - 1. trySize > 4]] whileTrue:[
             id := aDevice 
                     getFontWithFamily:family
                     face:face
                     style:style 
-                    size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[trySize])  
+                    size:trySize  
                     sizeUnit:sizeUnit  
                     encoding:encoding.
         ].
@@ -471,13 +473,13 @@
         alternatives := Replacements at:family asLowercase ifAbsent:nil.
         alternatives notNil ifTrue:[
             alternatives detect:[:eachAlternateFamilyName|
-                trySize := size ? 0.
+                trySize := (sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size]) ? 0.
                 [
                     id := aDevice 
                             getFontWithFamily:eachAlternateFamilyName
                             face:face
                             style:style 
-                            size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[trySize])  
+                            size:trySize  
                             sizeUnit:sizeUnit  
                             encoding:encoding.
                 ] doWhile:[id isNil and:[trySize := trySize - 1. trySize > 4. false]].
@@ -522,10 +524,11 @@
     ].
 
     f := self class basicNew.
+    f 
+        setFamily:alternateFamilyName face:face style:style size:trySize sizeUnit:sizeUnit encoding:encoding device:aDevice;
+        setDevice:aDevice fontId:id;
+        getFontInfos.
 
-    f setFamily:alternateFamilyName face:face style:style size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[trySize]) sizeUnit:sizeUnit encoding:encoding device:aDevice.
-    f setDevice:aDevice fontId:id.
-    f getFontInfos.
     aDevice registerFont:f.
     ^ f
 
@@ -723,6 +726,7 @@
 
 setFamily:familyString face:faceString style:styleString size:sizeNum encoding:encodingSym device:aDevice
     <resource: #obsolete>
+    self obsoleteMethodWarning:'2013-07-25'.
 
     self 
         setFamily:familyString 
@@ -1284,11 +1288,11 @@
 !Font class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.132 2013-07-26 14:30:57 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.133 2013-07-26 15:53:54 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.132 2013-07-26 14:30:57 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Font.st,v 1.133 2013-07-26 15:53:54 stefan Exp $'
 ! !