XftFontDescription.st
changeset 7559 90328370ce0e
parent 7526 d0199171a370
child 7563 3555a447b0aa
--- a/XftFontDescription.st	Mon Sep 12 15:00:52 2016 +0200
+++ b/XftFontDescription.st	Mon Sep 12 15:01:15 2016 +0200
@@ -905,10 +905,10 @@
 !
 
 onDevice:aGraphicsDevice ifAbsent:aBlock
-    "Create a new XftFont representing the closes font as
+    "Create a new XftFont representing the closest font as
      myself on aDevice; if one already exists, return the one."
 
-    |displayId myPatternHandle closestPatternHandle newFontId computedWeight|
+    |displayId myPatternHandle closestPatternHandle newFontId computedWeight deviceFont|
 
     (device == aGraphicsDevice) ifTrue:[
         "I am already assigned to that device ..."
@@ -920,13 +920,15 @@
     aGraphicsDevice supportsXftFonts ifFalse:[
         ^ self asNonXftFont onDevice:aGraphicsDevice.
     ].
-
     RecentlyUsedFonts isNil ifTrue:[
         RecentlyUsedFonts := OrderedCollection new:20.
     ].
 
     RecentlyUsedFonts keysAndValuesDo:[:index :aFont |
-        ((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getXftFontId notNil]]) ifTrue:[
+        ((aFont class == self class) 
+         and:[(self sameDeviceFontAs:aFont) 
+         and:[device == aGraphicsDevice
+         and:[aFont getXftFontId notNil]]]) ifTrue:[
             "/ Transcript showCR:'hit'.
             RecentlyUsedFonts
                 removeIndex:index;
@@ -940,7 +942,7 @@
     ].
 
     aGraphicsDevice deviceFonts do:[:aFont |
-        ((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
+        (self sameDeviceFontAs:aFont) ifTrue:[
             RecentlyUsedFonts addFirst:aFont.
             ^ aFont
         ].
@@ -953,6 +955,12 @@
         computedWeight := StXFace2FCWeightMap at:(face ? '') asLowercase ifAbsent:[FC_WEIGHT_REGULAR].
     ].
 
+
+    FirstTimeCalled ~~ false ifTrue:[
+        'XftFont: matching font (this may take a long time, if the system''s font cache needs to be filled first. Be patient...' infoPrintCR.
+        FirstTimeCalled := false.
+    ].
+
     [
         myPatternHandle := FCPatternHandle create.
         myPatternHandle
@@ -967,22 +975,21 @@
         ].
 
         displayId := aGraphicsDevice displayId.
-
-        FirstTimeCalled ~~ false ifTrue:[
-            'XftFont: matching font (this may take a long time, if the system''s font cache needs to be filled first. Be patient...' infoPrintCR.
-            FirstTimeCalled := false.
-        ].
         closestPatternHandle := myPatternHandle matchFontOnDisplayId:displayId screen:aGraphicsDevice screen.
         closestPatternHandle notNil ifTrue:[
             newFontId := closestPatternHandle getFontOnDisplayId:displayId.
             newFontId notNil ifTrue:[
                 "/ Good, this font exists!!
+                device isNil ifTrue:[
+                    deviceFont := self.
+                ] ifFalse:[
+                    deviceFont := self copy.
+                ].
                 closestPatternHandle := nil.
-                fontId := newFontId.
-                device := aGraphicsDevice.
-                aGraphicsDevice registerFont:self.
-                RecentlyUsedFonts addFirst:self.
-                ^ self.
+                deviceFont setDevice:aGraphicsDevice patternId:nil fontId:newFontId.
+                aGraphicsDevice registerFont:deviceFont.
+                RecentlyUsedFonts addFirst:deviceFont.
+                ^ deviceFont.
             ].
         ].
     ] ensure:[
@@ -997,6 +1004,10 @@
 
     "Modified: / 14-04-1997 / 18:22:31 / cg"
     "Modified: / 02-01-2014 / 23:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sameDeviceFontAs:aFont
+    ^ (super sameDeviceFontAs:aFont) and:[device == aFont graphicsDevice]
 ! !
 
 !XftFontDescription methodsFor:'initialization'!