XftFontDescription.st
changeset 6974 21d7c77069a1
parent 6963 26d226d61d32
child 6993 6eea4e9ccc2d
--- a/XftFontDescription.st	Mon Oct 05 14:28:59 2015 +0200
+++ b/XftFontDescription.st	Mon Oct 05 14:39:01 2015 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "{ Package: 'stx:libview' }"
 
 "{ NameSpace: Smalltalk }"
@@ -870,101 +868,103 @@
     (device == aGraphicsDevice) ifTrue:[^ self].
 
     (aGraphicsDevice isNil and:[device notNil]) ifTrue:[
-	^ self
+        ^ self
     ].
     aGraphicsDevice supportsXFTFonts ifFalse:[
-	^ super onDevice:aGraphicsDevice
+        ^ super onDevice:aGraphicsDevice
     ].
 
     (closestFont notNil and:[closestFont graphicsDevice == aGraphicsDevice]) ifTrue:[
-	^ closestFont onDevice: aGraphicsDevice.
+        ^ closestFont onDevice: aGraphicsDevice.
     ].
 
     RecentlyUsedFonts isNil ifTrue:[
-	RecentlyUsedFonts := OrderedCollection new:10.
+        RecentlyUsedFonts := OrderedCollection new:20.
     ].
 
     RecentlyUsedFonts keysAndValuesDo:[:index :aFont |
-	((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getFontId notNil]]) ifTrue:[
-	    "/ Transcript showCR:'hit'.
-	    RecentlyUsedFonts removeIndex:index.
-	    RecentlyUsedFonts addFirst:aFont.
-	    ^ aFont
-	]
+        ((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getFontId notNil]]) ifTrue:[
+            "/ Transcript showCR:'hit'.
+            RecentlyUsedFonts 
+                removeIndex:index;
+                addFirst:aFont.
+            ^ aFont
+        ]
     ].
 
-    RecentlyUsedFonts size > 20 ifTrue:[
-	RecentlyUsedFonts removeLast.
+    RecentlyUsedFonts size >= 20 ifTrue:[
+        RecentlyUsedFonts removeLast.
     ].
 
     aGraphicsDevice deviceFonts do:[:aFont |
-	((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
-	    RecentlyUsedFonts addFirst:aFont.
-	    ^ aFont
-	].
+        ((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
+            RecentlyUsedFonts addFirst:aFont.
+            ^ aFont
+        ].
     ].
 
     [
-	Error handle:[:ex |
-	    ^ self asNonXftFont onDevice:aGraphicsDevice
-	] do:[
-	    myPatternId := self xftPatternCreate.
-	].
-	self xftPatternAdd: myPatternId attribute: FC_FAMILY  value: family.
-	pixelSize notNil ifTrue:[
-	    self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: pixelSize.
-	] ifFalse:[
-	    self xftPatternAdd: myPatternId attribute: FC_SIZE value: (size isNil ifTrue:[nil] ifFalse:[size rounded]).
-	].
-	self xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular')).
-	self xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]).
+        Error handle:[:ex |
+            ^ self asNonXftFont onDevice:aGraphicsDevice
+        ] do:[
+            myPatternId := self xftPatternCreate.
+        ].
+        self xftPatternAdd: myPatternId attribute: FC_FAMILY  value: family.
+        sizeUnit = #px ifTrue:[
+            self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: (pixelSize isNil ifTrue:[nil] ifFalse:[pixelSize rounded]).
+        ] ifFalse:[
+            self xftPatternAdd: myPatternId attribute: FC_SIZE value: (size isNil ifTrue:[nil] ifFalse:[size rounded]).
+        ].
+        self 
+            xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular'));
+            xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]).
 
-	newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.
-	newFontId notNil ifTrue:[
-	    "/ Good, this font exists!!
-	    fontId := newFontId.
-	    device := aGraphicsDevice.
-	    aGraphicsDevice registerFont:self.
-	    RecentlyUsedFonts addFirst:self.
-	    ^ self.
-	] ifFalse:[
-	    closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId.
-	    closestPatternId1 isNil ifTrue:[
-		self error: 'No font matches'.
-	    ].
-	    "
-	    self xftPatternGet: closestPatternId attribute: 'family' index: 0.
-	    self xftPatternGet: closestPatternId attribute: 'size' index: 0.
-	    "
-	    closestPatternId2 := self xftPatternDuplicate: closestPatternId1.
-	    newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1.
-	    "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
-	    closestPatternId1 :=  nil.
-	    newFontId isNil ifTrue:[
-		self error: 'Pattern matched, but font could not be opened (should not happen)'.
-	    ].
+        newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.
+        newFontId notNil ifTrue:[
+            "/ Good, this font exists!!
+            fontId := newFontId.
+            device := aGraphicsDevice.
+            aGraphicsDevice registerFont:self.
+            RecentlyUsedFonts addFirst:self.
+            ^ self.
+        ] ifFalse:[
+            closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId.
+            closestPatternId1 isNil ifTrue:[
+                self error: 'No font matches'.
+            ].
+            "
+            self xftPatternGet: closestPatternId attribute: 'family' index: 0.
+            self xftPatternGet: closestPatternId attribute: 'size' index: 0.
+            "
+            closestPatternId2 := self xftPatternDuplicate: closestPatternId1.
+            newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1.
+            "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
+            closestPatternId1 :=  nil.
+            newFontId isNil ifTrue:[
+                self error: 'Pattern matched, but font could not be opened (should not happen)'.
+            ].
 
-	    "/ Search for existing registered font. Note, that XftFont instances
-	    "/ are shared (and refcounted) so newFontId = aFont getFontId is enough
-	    "/ to check whether some other font instance represents the same font...
-	    aGraphicsDevice deviceFonts do:[:aFont |
-		((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[
-		    closestFont := aFont.
-		    ^ closestFont
-		].
-	    ].
+            "/ Search for existing registered font. Note, that XftFont instances
+            "/ are shared (and refcounted) so newFontId = aFont getFontId is enough
+            "/ to check whether some other font instance represents the same font...
+            aGraphicsDevice deviceFonts do:[:aFont |
+                ((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[
+                    closestFont := aFont.
+                    ^ closestFont
+                ].
+            ].
 
-	    closestFont := self shallowCopy
-				setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
-				yourself.
-	    aGraphicsDevice registerFont: closestFont.
-	    RecentlyUsedFonts addFirst:closestFont.
-	    ^ closestFont
-	].
+            closestFont := self shallowCopy
+                                setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
+                                yourself.
+            aGraphicsDevice registerFont: closestFont.
+            RecentlyUsedFonts addFirst:closestFont.
+            ^ closestFont
+        ].
     ] ensure:[
-	myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId].
-	closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1].
-	closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2].
+        myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId].
+        closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1].
+        closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2].
     ].
 
     "