XftFontDescription.st
changeset 8794 2bd67fbc05b5
parent 8704 2b8ec91506ba
--- a/XftFontDescription.st	Fri Aug 30 11:18:00 2019 +0200
+++ b/XftFontDescription.st	Sat Aug 31 14:36:41 2019 +0200
@@ -18,7 +18,7 @@
 
 FontDescription subclass:#XftFontDescription
 	instanceVariableNames:'device fontId width minCode maxCode ascent descent height
-		fixedWidth'
+		fixedWidth dataValid'
 	classVariableNames:'FC_FAMILY FC_STYLE FC_SLANT FC_WEIGHT FC_SIZE FC_ASPECT
 		FC_PIXEL_SIZE FC_SPACING FC_FOUNDRY FC_ANTIALIAS FC_HINTING
 		FC_HINT_STYLE FC_VERTICAL_LAYOUT FC_AUTOHINT FC_WIDTH FC_FILE
@@ -583,9 +583,9 @@
 
     lc_CTYPE := OperatingSystem getEnvironment:'LC_CTYPE'.
     (lc_CTYPE isNil or:[lc_CTYPE = 'UTF-8']) ifTrue:[
-        ^ Smalltalk language
-          ,'_',Smalltalk languageTerritory asUppercase
-          ,'.UTF-8'.
+	^ Smalltalk language
+	  ,'_',Smalltalk languageTerritory asUppercase
+	  ,'.UTF-8'.
     ].
     ^ lc_CTYPE
 
@@ -715,12 +715,12 @@
     |newFont|
 
     newFont := Font
-                    family:family
-                    face:face
-                    style:style
-                    size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size])
-                    sizeUnit:sizeUnit
-                    encoding:encoding.
+		    family:family
+		    face:face
+		    style:style
+		    size:(sizeUnit == #px ifTrue:[pixelSize] ifFalse:[size])
+		    sizeUnit:sizeUnit
+		    encoding:encoding.
     newFont isForceNonXFTFont:true.
     ^ newFont
 
@@ -750,11 +750,11 @@
 
     prevFont := aGC font.
     fontId notNil ifTrue:[
-        thisContext isRecursive ifTrue:[self halt].
-        aGC basicFont:self.
-        aGC displayString:aString from:index1 to:index2 x:x y:y opaque:opaque.
+	thisContext isRecursive ifTrue:[self halt].
+	aGC basicFont:self.
+	aGC displayString:aString from:index1 to:index2 x:x y:y opaque:opaque.
     ] ifFalse:[
-        'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
+	'Font: [warning]: no replacementFont. should not happen' errorPrintCR.
     ].
     aGC basicFont:prevFont.
 
@@ -813,72 +813,72 @@
     |displayId myPatternHandle closestPatternHandle newFontId computedWeight deviceFont|
 
     (device == aGraphicsDevice) ifTrue:[
-        "I am already assigned to that device ..."
-        ^ self
+	"I am already assigned to that device ..."
+	^ self
     ].
     aGraphicsDevice isNil ifTrue:[
-        ^ self
+	^ self
     ].
     aGraphicsDevice supportsXftFonts ifFalse:[
-        ^ self asNonXftFont onDevice:aGraphicsDevice.
+	^ self asNonXftFont onDevice:aGraphicsDevice.
     ].
 
     deviceFont := aGraphicsDevice deviceFonts detect:[:eachFont | self sameDeviceFontAs:eachFont] ifNone:[].
     deviceFont notNil ifTrue:[
-        ^ deviceFont.
+	^ deviceFont.
     ].
 
     computedWeight := weight.
     computedWeight isNil ifTrue:[
-        computedWeight := StXFace2FCWeightMap at:(face ? '') asLowercase ifAbsent:[FC_WEIGHT_REGULAR].
+	computedWeight := StXFace2FCWeightMap at:(face ? '') asLowercase ifAbsent:[FC_WEIGHT_REGULAR].
     ].
 
     (OperatingSystem isOSXlike and:[FirstTimeCalled ~~ false]) ifTrue:[
-        "Slow font matching is a MAC-only feature"
-        Logger info:'XFT: matching font (this may take a long time, if the system''s font cache needs to be filled first. Be patient...'.
-        FirstTimeCalled := false.
+	"Slow font matching is a MAC-only feature"
+	Logger info:'XFT: matching font (this may take a long time, if the system''s font cache needs to be filled first. Be patient...'.
+	FirstTimeCalled := false.
     ].
 
     OperatingSystem setEnvironment:'LC_CTYPE' to:(self class fixedLC_CTYPE).
 
     [
-        myPatternHandle := FCPatternHandle create.
-        myPatternHandle
-            add:FC_FOUNDRY value:manufacturer;
-            add:FC_FAMILY value:family;
-            add:FC_WEIGHT value:computedWeight;
-            add:FC_SLANT  value:(StXStyle2FCSlantMap at:(style ? '') asLowercase 
-                                                     ifAbsent:[FC_SLANT_ROMAN]).
-        sizeUnit = #px ifTrue:[
-            myPatternHandle add:FC_PIXEL_SIZE value:(pixelSize isNil ifTrue:[nil] ifFalse:[pixelSize rounded]).
-        ] ifFalse:[
-            myPatternHandle add:FC_SIZE value:(size isNil ifTrue:[nil] ifFalse:[size rounded]).
-        ].
+	myPatternHandle := FCPatternHandle create.
+	myPatternHandle
+	    add:FC_FOUNDRY value:manufacturer;
+	    add:FC_FAMILY value:family;
+	    add:FC_WEIGHT value:computedWeight;
+	    add:FC_SLANT  value:(StXStyle2FCSlantMap at:(style ? '') asLowercase
+						     ifAbsent:[FC_SLANT_ROMAN]).
+	sizeUnit = #px ifTrue:[
+	    myPatternHandle add:FC_PIXEL_SIZE value:(pixelSize isNil ifTrue:[nil] ifFalse:[pixelSize rounded]).
+	] ifFalse:[
+	    myPatternHandle add:FC_SIZE value:(size isNil ifTrue:[nil] ifFalse:[size rounded]).
+	].
 
-        displayId := aGraphicsDevice displayId.
-        displayId isNil ifTrue:[
-            self error:'nil displayId'.
-        ].
-        closestPatternHandle := myPatternHandle matchFontOnDisplayId:displayId screen:aGraphicsDevice screen.
-        closestPatternHandle notNil ifTrue:[
-            newFontId := closestPatternHandle getFontOnDisplayId:displayId.
-            newFontId notNil ifTrue:[
-                "/ Good, this font exists!!
-                device isNil ifTrue:[
-                    "not assigned to a device..."
-                    deviceFont := self.
-                ] ifFalse:[
-                    deviceFont := self copy.
-                ].
-                closestPatternHandle := nil.
-                deviceFont setDevice:aGraphicsDevice patternId:nil fontId:newFontId.
-                aGraphicsDevice registerFont:deviceFont.
-                ^ deviceFont.
-            ].
-        ].
+	displayId := aGraphicsDevice displayId.
+	displayId isNil ifTrue:[
+	    self error:'nil displayId'.
+	].
+	closestPatternHandle := myPatternHandle matchFontOnDisplayId:displayId screen:aGraphicsDevice screen.
+	closestPatternHandle notNil ifTrue:[
+	    newFontId := closestPatternHandle getFontOnDisplayId:displayId.
+	    newFontId notNil ifTrue:[
+		"/ Good, this font exists!!
+		device isNil ifTrue:[
+		    "not assigned to a device..."
+		    deviceFont := self.
+		] ifFalse:[
+		    deviceFont := self copy.
+		].
+		closestPatternHandle := nil.
+		deviceFont setDevice:aGraphicsDevice patternId:nil fontId:newFontId.
+		aGraphicsDevice registerFont:deviceFont.
+		^ deviceFont.
+	    ].
+	].
     ] ensure:[
-        myPatternHandle notNil ifTrue:[myPatternHandle destroy].
-        closestPatternHandle notNil ifTrue:[closestPatternHandle destroy].
+	myPatternHandle notNil ifTrue:[myPatternHandle destroy].
+	closestPatternHandle notNil ifTrue:[closestPatternHandle destroy].
     ].
     ^ aBlock value
 
@@ -1106,15 +1106,15 @@
      Also called monospaced fonts"
 
     fixedWidth isNil ifTrue:[
-        fontId isNil ifTrue:[
-            ^ false     "we don't know yet"
-        ].
-        fixedWidth := false.    "false until proven otherwise. Set to avoid recursion"
-        "/ take some obviously different chars
-        width := self widthOf:' '.
-        fixedWidth := (self widthOf:'i') == width
-                            and:[(self widthOf:'W') == width
-                            and:[(self widthOf:'.') == width]]
+	fontId isNil ifTrue:[
+	    ^ false     "we don't know yet"
+	].
+	fixedWidth := false.    "false until proven otherwise. Set to avoid recursion"
+	"/ take some obviously different chars
+	width := self widthOf:' '.
+	fixedWidth := (self widthOf:'i') == width
+			    and:[(self widthOf:'W') == width
+			    and:[(self widthOf:'.') == width]]
     ].
     ^ fixedWidth.
 
@@ -1192,19 +1192,19 @@
     "return the width of a sub string"
 
     (stop < start) ifTrue:[
-        ^ 0
+	^ 0
     ].
     fixedWidth isNil ifTrue:[
-        self isFixedWidth.  "/ initialize fixedWidth and width
+	self isFixedWidth.  "/ initialize fixedWidth and width
     ].
     fixedWidth == true ifTrue:[
-        ^ width * (stop - start + 1).
+	^ width * (stop - start + 1).
     ].
     device isNil ifTrue:[
-        self errorNoDevice.
+	self errorNoDevice.
     ].
     device isOpen not ifTrue:[
-        ^ 0.    "closed device, width does not matter"
+	^ 0.    "closed device, width does not matter"
     ].
 
     ^ self xftTextExtents:device displayId string:aString from:start to:stop into:nil.
@@ -1221,15 +1221,15 @@
     "I am no longer available on the device"
 
     |deviceID|
-    
+
     (device notNil and:[fontId notNil]) ifTrue:[
-        (deviceID := device displayId) notNil ifTrue:[
-            self class xftFontClose:fontId displayId:deviceID.
-        ].
-        device := nil.
-        fontId := nil.
-        width := nil.
-        fixedWidth := nil.
+	(deviceID := device displayId) notNil ifTrue:[
+	    self class xftFontClose:fontId displayId:deviceID.
+	].
+	device := nil.
+	fontId := nil.
+	width := nil.
+	fixedWidth := nil.
     ].
 
     "Modified: / 15-09-2017 / 12:42:25 / cg"
@@ -1300,62 +1300,62 @@
      and reads all known fonts from it"
 
     "self new listOfAvailableFonts"
-    
+
     |readEntry list fcListProg shellEnvironment|
 
     list := OrderedCollection new.
 
     readEntry := [
-            |key line|
+	    |key line|
 
-            [
-                line := pipeStream nextLine.
-            ] doUntil:[(line startsWith:'Pattern has') or:[Transcript showCR:line. false]].
+	    [
+		line := pipeStream nextLine.
+	    ] doUntil:[(line startsWith:'Pattern has') or:[Transcript showCR:line. false]].
 
-            currentDescription := XftFontDescription new.
-            [line := pipeStream nextLine. line notEmptyOrNil] whileTrue:[
-                "/ Transcript showCR:l.
-                lineStream := line readStream. lineStream skipSeparators.
-                key := ('fc_', (lineStream upTo:$:)) asSymbolIfInterned.
-                (
-                    #(fc_family fc_style fc_slant fc_weight fc_width
-                      fc_pixelsize fc_spacing fc_foundry fc_antialias
-                      fc_file fc_outline fc_scalable fc_charset fc_lang
-                      fc_fontversion fc_fontformat fc_decorative fc_index
-                      fc_outline fc_familylang fc_stylelang fc_fullname
-                      fc_fullnamelang fc_capability fc_hash fc_postscriptname
-                      fc_symbol fc_color
-                    ) includesIdentical:key
-                ) ifTrue:[
-                    self perform:key.
-                ] ifFalse:[
-                    Transcript show:'Xft ignored line: '; showCR:line.
-                ].
-            ].
-            list add:currentDescription
-        ].
+	    currentDescription := XftFontDescription new.
+	    [line := pipeStream nextLine. line notEmptyOrNil] whileTrue:[
+		"/ Transcript showCR:l.
+		lineStream := line readStream. lineStream skipSeparators.
+		key := ('fc_', (lineStream upTo:$:)) asSymbolIfInterned.
+		(
+		    #(fc_family fc_style fc_slant fc_weight fc_width
+		      fc_pixelsize fc_spacing fc_foundry fc_antialias
+		      fc_file fc_outline fc_scalable fc_charset fc_lang
+		      fc_fontversion fc_fontformat fc_decorative fc_index
+		      fc_outline fc_familylang fc_stylelang fc_fullname
+		      fc_fullnamelang fc_capability fc_hash fc_postscriptname
+		      fc_symbol fc_color
+		    ) includesIdentical:key
+		) ifTrue:[
+		    self perform:key.
+		] ifFalse:[
+		    Transcript show:'Xft ignored line: '; showCR:line.
+		].
+	    ].
+	    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.
+		    ].
 
     "/ to suppress the disturbing warning message
     "/ if LC_CTYPE is wrong (osx problem)
     shellEnvironment := Dictionary new.
     shellEnvironment at:'LC_CTYPE' put:XftFontDescription fixedLC_CTYPE.
 
-    pipeStream := PipeStream 
-                    readingFrom:fcListProg, ' -v'
-                    environment:shellEnvironment.
+    pipeStream := PipeStream
+		    readingFrom:fcListProg, ' -v'
+		    environment:shellEnvironment.
     [
-        [pipeStream atEnd] whileFalse:[
-            readEntry value.
-        ]
+	[pipeStream atEnd] whileFalse:[
+	    readEntry value.
+	]
     ] ensure:[
-        pipeStream close
+	pipeStream close
     ].
     ^ list
 
@@ -1751,34 +1751,34 @@
     XftResult r;
 
     if (__INST(address_) == 0) {
-        error = @symbol(NullReceiver);
-        goto err;
+	error = @symbol(NullReceiver);
+	goto err;
     }
     if ( ! __isStringLike ( attribute ) ) {
-        error = @symbol(BadArg1);
-        goto err;
+	error = @symbol(BadArg1);
+	goto err;
     }
     if ( ! __isSmallInteger( index ) ) {
-        error = @symbol(BadArg2);
-        goto err;
+	error = @symbol(BadArg2);
+	goto err;
     }
     r = XftPatternGet((XftPattern*)__INST(address_), __stringVal( attribute ), __intVal( index ), &v);
     if ( r != XftResultMatch) {
-        RETURN ( nil );
+	RETURN ( nil );
     }
     if ( v.type == XftTypeString) {
-        RETURN ( __MKSTRING(v.u.s) );
+	RETURN ( __MKSTRING(v.u.s) );
     } else if ( v.type == XftTypeInteger ) {
-        RETURN ( __MKINT (v.u.i) );
+	RETURN ( __MKINT (v.u.i) );
     } else if ( v.type == XftTypeBool ) {
-        RETURN ( v.u.b == True ? true : false );
+	RETURN ( v.u.b == True ? true : false );
     } else if ( v.type == XftTypeDouble ) {
-        RETURN ( __MKFLOAT (v.u.d) );
+	RETURN ( __MKFLOAT (v.u.d) );
     } else if ( v.type == XftTypeVoid ) {
-        RETURN ( nil );
+	RETURN ( nil );
     } else {
-        error = @symbol(UnsupportedTypeValue);
-        goto err;
+	error = @symbol(UnsupportedTypeValue);
+	goto err;
     }
     err:;
 #endif