author | Claus Gittinger <cg@exept.de> |
Sun, 18 Sep 2016 18:16:59 +0200 | |
changeset 7571 | ba05e480c941 |
parent 7570 | b05dae395ad5 |
child 7572 | aca0c43e3ae2 |
child 7575 | 151c445c946c |
--- a/XftFontDescription.st Thu Sep 15 21:35:55 2016 +0200 +++ b/XftFontDescription.st Sun Sep 18 18:16:59 2016 +0200 @@ -303,6 +303,48 @@ !XftFontDescription class methodsFor:'instance creation'! +family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding + "returns a font for given family, face, style, size and the specified encoding. + The returned font is not associated to a specific device" + + |proto| + + RecentlyUsedFonts notNil ifTrue:[ + proto := RecentlyUsedFonts + detect:[:fn | + |fnStyle| + + fn family = familyString + and:[ fn size = size and:[fn sizeUnit = sizeUnit + and:[ fn face = faceString + and:[ ((fnStyle := fn style) = styleString + or:[ (fnStyle = 'oblique' and:[styleString = 'italic']) + or:[ (fnStyle = '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 + ]. + ]. + ^ super + family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding +! + for:aFontOrFontDescription ^ self family:aFontOrFontDescription family @@ -880,12 +922,36 @@ aGraphicsDevice supportsXftFonts ifFalse:[ ^ self asNonXftFont onDevice:aGraphicsDevice. ]. - - deviceFont := aGraphicsDevice deviceFonts detect:[:eachFont | self sameDeviceFontAs:eachFont] ifNone:[]. - deviceFont notNil ifTrue:[ - ^ deviceFont. + RecentlyUsedFonts isNil ifTrue:[ + RecentlyUsedFonts := OrderedCollection new:20. ]. + RecentlyUsedFonts keysAndValuesDo:[:index :aFont | + ((aFont class == self class) + and:[(self sameDeviceFontAs:aFont) + and:[device == aGraphicsDevice + and:[aFont getXftFontId notNil]]]) ifTrue:[ + "/ Transcript showCR:'hit'. + RecentlyUsedFonts + removeIndex:index; + addFirst:aFont. + ^ aFont + ] + ]. + + RecentlyUsedFonts size >= 20 ifTrue:[ + RecentlyUsedFonts removeLast. + ]. + + aGraphicsDevice deviceFonts do:[:aFont | + (self sameDeviceFontAs:aFont) ifTrue:[ + RecentlyUsedFonts addFirst:aFont. + ^ aFont + ]. + ]. + +"/ ^ self asNonXftFont onDevice:aGraphicsDevice. + computedWeight := weight. computedWeight isNil ifTrue:[ computedWeight := StXFace2FCWeightMap at:(face ? '') asLowercase ifAbsent:[FC_WEIGHT_REGULAR]. @@ -924,6 +990,7 @@ closestPatternHandle := nil. deviceFont setDevice:aGraphicsDevice patternId:nil fontId:newFontId. aGraphicsDevice registerFont:deviceFont. + RecentlyUsedFonts addFirst:deviceFont. ^ deviceFont. ]. ]. @@ -939,6 +1006,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'!