#OTHER
authorStefan Vogel <sv@exept.de>
Sun, 04 Oct 2015 21:19:46 +0200
changeset 6957 5493f1a1b259
parent 6956 96f7888403e5
child 6958 5b5a6800adf4
#OTHER class: XftFontDescription added: #aboutToDestroyViewWithDevice:id: removed: #isScaledFont #size changed: #displayString:from:to:x:y:in:opaque: #family:face:style:size:sizeUnit:encoding: #setDevice:patternId:fontId: Fix scaled font detection No longer need to add dependent to view.
XftFontDescription.st
--- a/XftFontDescription.st	Sun Oct 04 19:19:26 2015 +0200
+++ b/XftFontDescription.st	Sun Oct 04 21:19:46 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'stx:libview' }"
 
 "{ NameSpace: Smalltalk }"
@@ -314,37 +316,37 @@
     |proto|
 
     RecentlyUsedFonts notNil ifTrue:[
-	proto := RecentlyUsedFonts
-		detect:[:fn |
-		    fn family = familyString
-		    and:[ fn size = size and:[fn sizeUnit = sizeUnit
-		    and:[ fn face = faceString
-		    and:[ (fn style = styleString
-			  or:[ (fn style = 'oblique' and:[styleString = 'italic'])
-			  or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]]]
-		ifNone:nil.
-	proto notNil ifTrue:[
-	    ^ proto
-	].
+        proto := RecentlyUsedFonts
+                detect:[:fn |
+                    fn family = familyString
+                    and:[ fn size = size and:[fn sizeUnit = sizeUnit
+                    and:[ fn face = faceString
+                    and:[ (fn style = styleString
+                          or:[ (fn style = 'oblique' and:[styleString = 'italic'])
+                          or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]]]
+                ifNone:nil.
+        proto notNil ifTrue:[
+            ^ proto
+        ].
     ].
 
     CachedFontList notNil ifTrue:[
-	proto := CachedFontList
-		detect:[:fn |
-		    fn family = familyString
-		    and:[ fn face = faceString
-		    and:[ (fn style = styleString
-			  or:[ (fn style = 'oblique' and:[styleString = 'italic'])
-			  or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]
-		ifNone:nil.
-	proto notNil ifTrue:[
-	    ^ (proto shallowCopy)
-		setDevice: nil patternId: nil fontId: nil;
-		family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
-	].
+        proto := CachedFontList
+                detect:[:fn |
+                    fn family = familyString
+                    and:[ fn face = faceString
+                    and:[ (fn style = styleString
+                          or:[ (fn style = 'oblique' and:[styleString = 'italic'])
+                          or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]
+                ifNone:nil.
+        proto notNil ifTrue:[
+            ^ (proto shallowCopy)
+                setDevice: nil patternId: nil fontId: nil;
+                family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
+        ].
     ].
     ^ super
-	family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
+        family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
 !
 
 new
@@ -352,6 +354,19 @@
     ^ super new.
 ! !
 
+!XftFontDescription class methodsFor:'change & update'!
+
+aboutToDestroyViewWithDevice:aDevice id:aWindowId
+    "a view is going to be destroyed.
+     Have to disassociate the XftDrawId from  the drawableId aWindowId"
+
+    Lobby do:[:eachXftFont|
+        eachXftFont graphicsDevice == aDevice ifTrue:[
+            eachXftFont disassociateXftDrawableFrom:aWindowId.
+        ].
+    ].
+! !
+
 !XftFontDescription class methodsFor:'examples'!
 
 example1
@@ -486,10 +501,6 @@
     minCode := something.
 !
 
-size
-    ^ size ? 0
-!
-
 style
     ^ style ? ''
 !
@@ -815,11 +826,8 @@
     error notNil ifTrue:[
         self primitiveFailed: error.
     ].
-    newDrawableAssociation notNil ifTrue:[
-        newXftDrawId notNil ifTrue:[
-            Lobby register:self.
-        ].
-        aGC addDependent:self.      "I need to be informed, when the GC is destroyed"
+    newXftDrawId notNil ifTrue:[
+        Lobby register:self.
     ].
     "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 10-01-2014 / 11:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -989,16 +997,19 @@
     device := deviceArg.
     fontId := fontIdArg.
     patternIdArg notNil ifTrue:[
-	family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
-	size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
-	face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
-	face    := StXFace2FCWeightMap keyAtValue: face.
-	style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
-	style   := StXStyle2FCSlantMap keyAtValue: style.
+        family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
+        size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
+        face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
+        face    := StXFace2FCWeightMap keyAtValue: face.
+        style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
+        style   := StXStyle2FCSlantMap keyAtValue: style.
 
-	name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
+        name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
 
-	encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
+        encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
+    ].
+    size isNil ifTrue:[
+        size := 0.
     ].
 
     "Created: / 21-12-2013 / 00:46:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1877,12 +1888,6 @@
 
 !XftFontDescription methodsFor:'testing'!
 
-isScaledFont
-    "Xft fonts are always scaled"
-
-    ^ true
-!
-
 isUsed
     ^ sharedDrawId notNil
 !
@@ -1917,51 +1922,51 @@
     list := OrderedCollection new.
 
     readEntry :=
-	[
-	    |key|
+        [
+            |key|
 
-	    [l startsWith:'Pattern has'] whileFalse:[
-	      l := pipeStream nextLine. Transcript showCR:l.
-	    ].
+            [l startsWith:'Pattern has'] whileFalse:[
+              l := pipeStream nextLine. Transcript showCR:l.
+            ].
 
-	    currentDescription := XftFontDescription new.
-	    [ l := pipeStream nextLine. l notEmptyOrNil ] whileTrue:[
-		"/ Transcript showCR:l.
-		lineStream := l readStream. lineStream skipSeparators.
-		key := lineStream upToSeparator.
-		(
-		    #('family:' 'style:' 'slant:' 'weight:' 'width:'
-		      'pixelsize:' 'spacing:' 'foundry:' 'antialias:'
-		      'file:' 'outline' 'scalable:' 'charset:' 'lang:'
-		      'fontversion:' 'fontformat:' 'decorative:' 'index:'
-		      'outline:' 'familylang:' 'stylelang:' 'fullname:'
-		      'fullnamelang:' 'capability:' 'hash:' 'postscriptname:'
-		    ) includes:key
-		) ifTrue:[
-		    self perform:('fc_',(key allButLast)) asSymbol
-		] ifFalse:[
-		    Transcript show:'Xft ignored line: '; showCR:l.
-		    self breakPoint:#cg.
-		].
-	    ].
-	    list add:currentDescription
-	].
+            currentDescription := XftFontDescription new.
+            [ l := pipeStream nextLine. l notEmptyOrNil ] whileTrue:[
+                "/ Transcript showCR:l.
+                lineStream := l readStream. lineStream skipSeparators.
+                key := lineStream upToSeparator.
+                (
+                    #('family:' 'style:' 'slant:' 'weight:' 'width:'
+                      'pixelsize:' 'spacing:' 'foundry:' 'antialias:'
+                      'file:' 'outline' 'scalable:' 'charset:' 'lang:'
+                      'fontversion:' 'fontformat:' 'decorative:' 'index:'
+                      'outline:' 'familylang:' 'stylelang:' 'fullname:'
+                      'fullnamelang:' 'capability:' 'hash:' 'postscriptname:'
+                    ) includes:key
+                ) ifTrue:[
+                    self perform:('fc_', (key allButLast)) asSymbol
+                ] ifFalse:[
+                    Transcript show:'Xft ignored line: '; showCR:l.
+                    self breakPoint:#cg.
+                ].
+            ].
+            list add:currentDescription
+        ].
 
     fcListProg := #('/usr/bin/fc-list' '/usr/X11/bin/fc-list') detect:[:eachProg|
-			eachProg asFilename isExecutableProgram
-		    ] ifNone:[
-			'XftFontDescription [warning]: fc-list program not found - no XFT fonts' errorPrintCR.
-			^ list.
-		    ].
+                        eachProg asFilename isExecutableProgram
+                    ] ifNone:[
+                        'XftFontDescription [warning]: fc-list program not found - no XFT fonts' errorPrintCR.
+                        ^ list.
+                    ].
 
     pipeStream := PipeStream readingFrom:fcListProg, ' -v'.
     [
-	[pipeStream atEnd] whileFalse:[
-	    l := pipeStream nextLine.
-	    readEntry value.
-	]
+        [pipeStream atEnd] whileFalse:[
+            l := pipeStream nextLine.
+            readEntry value.
+        ]
     ] ensure:[
-	pipeStream close
+        pipeStream close
     ].
     ^ list
 
@@ -2117,7 +2122,7 @@
 fc_scalable
     "helper for font listing"
 
-    currentDescription isScalableFont:(self getBoolean).
+    currentDescription isScalableFont:self getBoolean.
 !
 
 fc_slant
@@ -2185,7 +2190,7 @@
 
     lineStream skipSeparators.
     s := lineStream nextAlphaNumericWord.
-    ^ s = 'FcTrue'.
+    ^ (s indexOfSubCollection:'True') ~~ 0.     "/ match at least 'True' and 'FCTrue'
 !
 
 getInteger