XftFontDescription.st
changeset 6957 5493f1a1b259
parent 6947 130ebce204d3
child 6963 26d226d61d32
equal deleted inserted replaced
6956:96f7888403e5 6957:5493f1a1b259
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "{ Package: 'stx:libview' }"
     3 "{ Package: 'stx:libview' }"
     2 
     4 
     3 "{ NameSpace: Smalltalk }"
     5 "{ NameSpace: Smalltalk }"
     4 
     6 
     5 FontDescription subclass:#XftFontDescription
     7 FontDescription subclass:#XftFontDescription
   312      The returned font is not associated to a specific device"
   314      The returned font is not associated to a specific device"
   313 
   315 
   314     |proto|
   316     |proto|
   315 
   317 
   316     RecentlyUsedFonts notNil ifTrue:[
   318     RecentlyUsedFonts notNil ifTrue:[
   317 	proto := RecentlyUsedFonts
   319         proto := RecentlyUsedFonts
   318 		detect:[:fn |
   320                 detect:[:fn |
   319 		    fn family = familyString
   321                     fn family = familyString
   320 		    and:[ fn size = size and:[fn sizeUnit = sizeUnit
   322                     and:[ fn size = size and:[fn sizeUnit = sizeUnit
   321 		    and:[ fn face = faceString
   323                     and:[ fn face = faceString
   322 		    and:[ (fn style = styleString
   324                     and:[ (fn style = styleString
   323 			  or:[ (fn style = 'oblique' and:[styleString = 'italic'])
   325                           or:[ (fn style = 'oblique' and:[styleString = 'italic'])
   324 			  or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]]]
   326                           or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]]]
   325 		ifNone:nil.
   327                 ifNone:nil.
   326 	proto notNil ifTrue:[
   328         proto notNil ifTrue:[
   327 	    ^ proto
   329             ^ proto
   328 	].
   330         ].
   329     ].
   331     ].
   330 
   332 
   331     CachedFontList notNil ifTrue:[
   333     CachedFontList notNil ifTrue:[
   332 	proto := CachedFontList
   334         proto := CachedFontList
   333 		detect:[:fn |
   335                 detect:[:fn |
   334 		    fn family = familyString
   336                     fn family = familyString
   335 		    and:[ fn face = faceString
   337                     and:[ fn face = faceString
   336 		    and:[ (fn style = styleString
   338                     and:[ (fn style = styleString
   337 			  or:[ (fn style = 'oblique' and:[styleString = 'italic'])
   339                           or:[ (fn style = 'oblique' and:[styleString = 'italic'])
   338 			  or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]
   340                           or:[ (fn style = 'italic' and:[styleString = 'oblique']) ]]) ]]]
   339 		ifNone:nil.
   341                 ifNone:nil.
   340 	proto notNil ifTrue:[
   342         proto notNil ifTrue:[
   341 	    ^ (proto shallowCopy)
   343             ^ (proto shallowCopy)
   342 		setDevice: nil patternId: nil fontId: nil;
   344                 setDevice: nil patternId: nil fontId: nil;
   343 		family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
   345                 family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
   344 	].
   346         ].
   345     ].
   347     ].
   346     ^ super
   348     ^ super
   347 	family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
   349         family:familyString face:faceString style:styleString size:size sizeUnit:sizeUnit encoding:encoding
   348 !
   350 !
   349 
   351 
   350 new
   352 new
   351 "/    self halt.
   353 "/    self halt.
   352     ^ super new.
   354     ^ super new.
       
   355 ! !
       
   356 
       
   357 !XftFontDescription class methodsFor:'change & update'!
       
   358 
       
   359 aboutToDestroyViewWithDevice:aDevice id:aWindowId
       
   360     "a view is going to be destroyed.
       
   361      Have to disassociate the XftDrawId from  the drawableId aWindowId"
       
   362 
       
   363     Lobby do:[:eachXftFont|
       
   364         eachXftFont graphicsDevice == aDevice ifTrue:[
       
   365             eachXftFont disassociateXftDrawableFrom:aWindowId.
       
   366         ].
       
   367     ].
   353 ! !
   368 ! !
   354 
   369 
   355 !XftFontDescription class methodsFor:'examples'!
   370 !XftFontDescription class methodsFor:'examples'!
   356 
   371 
   357 example1
   372 example1
   482     ^ minCode ? 0
   497     ^ minCode ? 0
   483 !
   498 !
   484 
   499 
   485 minCode:something
   500 minCode:something
   486     minCode := something.
   501     minCode := something.
   487 !
       
   488 
       
   489 size
       
   490     ^ size ? 0
       
   491 !
   502 !
   492 
   503 
   493 style
   504 style
   494     ^ style ? ''
   505     ^ style ? ''
   495 !
   506 !
   813 #endif
   824 #endif
   814 %}.
   825 %}.
   815     error notNil ifTrue:[
   826     error notNil ifTrue:[
   816         self primitiveFailed: error.
   827         self primitiveFailed: error.
   817     ].
   828     ].
   818     newDrawableAssociation notNil ifTrue:[
   829     newXftDrawId notNil ifTrue:[
   819         newXftDrawId notNil ifTrue:[
   830         Lobby register:self.
   820             Lobby register:self.
       
   821         ].
       
   822         aGC addDependent:self.      "I need to be informed, when the GC is destroyed"
       
   823     ].
   831     ].
   824     "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   832     "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   825     "Modified: / 10-01-2014 / 11:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   833     "Modified: / 10-01-2014 / 11:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   826 ! !
   834 ! !
   827 
   835 
   987 
   995 
   988 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg
   996 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg
   989     device := deviceArg.
   997     device := deviceArg.
   990     fontId := fontIdArg.
   998     fontId := fontIdArg.
   991     patternIdArg notNil ifTrue:[
   999     patternIdArg notNil ifTrue:[
   992 	family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
  1000         family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
   993 	size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
  1001         size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
   994 	face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
  1002         face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
   995 	face    := StXFace2FCWeightMap keyAtValue: face.
  1003         face    := StXFace2FCWeightMap keyAtValue: face.
   996 	style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
  1004         style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
   997 	style   := StXStyle2FCSlantMap keyAtValue: style.
  1005         style   := StXStyle2FCSlantMap keyAtValue: style.
   998 
  1006 
   999 	name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
  1007         name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
  1000 
  1008 
  1001 	encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
  1009         encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
       
  1010     ].
       
  1011     size isNil ifTrue:[
       
  1012         size := 0.
  1002     ].
  1013     ].
  1003 
  1014 
  1004     "Created: / 21-12-2013 / 00:46:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1015     "Created: / 21-12-2013 / 00:46:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1005     "Modified: / 30-12-2013 / 12:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1016     "Modified: / 30-12-2013 / 12:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1006 ! !
  1017 ! !
  1875     closestFont := nil.
  1886     closestFont := nil.
  1876 ! !
  1887 ! !
  1877 
  1888 
  1878 !XftFontDescription methodsFor:'testing'!
  1889 !XftFontDescription methodsFor:'testing'!
  1879 
  1890 
  1880 isScaledFont
       
  1881     "Xft fonts are always scaled"
       
  1882 
       
  1883     ^ true
       
  1884 !
       
  1885 
       
  1886 isUsed
  1891 isUsed
  1887     ^ sharedDrawId notNil
  1892     ^ sharedDrawId notNil
  1888 !
  1893 !
  1889 
  1894 
  1890 isXftFont
  1895 isXftFont
  1915     |readEntry list l fcListProg|
  1920     |readEntry list l fcListProg|
  1916 
  1921 
  1917     list := OrderedCollection new.
  1922     list := OrderedCollection new.
  1918 
  1923 
  1919     readEntry :=
  1924     readEntry :=
  1920 	[
  1925         [
  1921 	    |key|
  1926             |key|
  1922 
  1927 
  1923 	    [l startsWith:'Pattern has'] whileFalse:[
  1928             [l startsWith:'Pattern has'] whileFalse:[
  1924 	      l := pipeStream nextLine. Transcript showCR:l.
  1929               l := pipeStream nextLine. Transcript showCR:l.
  1925 	    ].
  1930             ].
  1926 
  1931 
  1927 	    currentDescription := XftFontDescription new.
  1932             currentDescription := XftFontDescription new.
  1928 	    [ l := pipeStream nextLine. l notEmptyOrNil ] whileTrue:[
  1933             [ l := pipeStream nextLine. l notEmptyOrNil ] whileTrue:[
  1929 		"/ Transcript showCR:l.
  1934                 "/ Transcript showCR:l.
  1930 		lineStream := l readStream. lineStream skipSeparators.
  1935                 lineStream := l readStream. lineStream skipSeparators.
  1931 		key := lineStream upToSeparator.
  1936                 key := lineStream upToSeparator.
  1932 		(
  1937                 (
  1933 		    #('family:' 'style:' 'slant:' 'weight:' 'width:'
  1938                     #('family:' 'style:' 'slant:' 'weight:' 'width:'
  1934 		      'pixelsize:' 'spacing:' 'foundry:' 'antialias:'
  1939                       'pixelsize:' 'spacing:' 'foundry:' 'antialias:'
  1935 		      'file:' 'outline' 'scalable:' 'charset:' 'lang:'
  1940                       'file:' 'outline' 'scalable:' 'charset:' 'lang:'
  1936 		      'fontversion:' 'fontformat:' 'decorative:' 'index:'
  1941                       'fontversion:' 'fontformat:' 'decorative:' 'index:'
  1937 		      'outline:' 'familylang:' 'stylelang:' 'fullname:'
  1942                       'outline:' 'familylang:' 'stylelang:' 'fullname:'
  1938 		      'fullnamelang:' 'capability:' 'hash:' 'postscriptname:'
  1943                       'fullnamelang:' 'capability:' 'hash:' 'postscriptname:'
  1939 		    ) includes:key
  1944                     ) includes:key
  1940 		) ifTrue:[
  1945                 ) ifTrue:[
  1941 		    self perform:('fc_',(key allButLast)) asSymbol
  1946                     self perform:('fc_', (key allButLast)) asSymbol
  1942 		] ifFalse:[
  1947                 ] ifFalse:[
  1943 		    Transcript show:'Xft ignored line: '; showCR:l.
  1948                     Transcript show:'Xft ignored line: '; showCR:l.
  1944 		    self breakPoint:#cg.
  1949                     self breakPoint:#cg.
  1945 		].
  1950                 ].
  1946 	    ].
  1951             ].
  1947 	    list add:currentDescription
  1952             list add:currentDescription
  1948 	].
  1953         ].
  1949 
  1954 
  1950     fcListProg := #('/usr/bin/fc-list' '/usr/X11/bin/fc-list') detect:[:eachProg|
  1955     fcListProg := #('/usr/bin/fc-list' '/usr/X11/bin/fc-list') detect:[:eachProg|
  1951 			eachProg asFilename isExecutableProgram
  1956                         eachProg asFilename isExecutableProgram
  1952 		    ] ifNone:[
  1957                     ] ifNone:[
  1953 			'XftFontDescription [warning]: fc-list program not found - no XFT fonts' errorPrintCR.
  1958                         'XftFontDescription [warning]: fc-list program not found - no XFT fonts' errorPrintCR.
  1954 			^ list.
  1959                         ^ list.
  1955 		    ].
  1960                     ].
  1956 
  1961 
  1957     pipeStream := PipeStream readingFrom:fcListProg, ' -v'.
  1962     pipeStream := PipeStream readingFrom:fcListProg, ' -v'.
  1958     [
  1963     [
  1959 	[pipeStream atEnd] whileFalse:[
  1964         [pipeStream atEnd] whileFalse:[
  1960 	    l := pipeStream nextLine.
  1965             l := pipeStream nextLine.
  1961 	    readEntry value.
  1966             readEntry value.
  1962 	]
  1967         ]
  1963     ] ensure:[
  1968     ] ensure:[
  1964 	pipeStream close
  1969         pipeStream close
  1965     ].
  1970     ].
  1966     ^ list
  1971     ^ list
  1967 
  1972 
  1968     "
  1973     "
  1969      FCFontListParser new listOfAvailableFonts
  1974      FCFontListParser new listOfAvailableFonts
  2115 !
  2120 !
  2116 
  2121 
  2117 fc_scalable
  2122 fc_scalable
  2118     "helper for font listing"
  2123     "helper for font listing"
  2119 
  2124 
  2120     currentDescription isScalableFont:(self getBoolean).
  2125     currentDescription isScalableFont:self getBoolean.
  2121 !
  2126 !
  2122 
  2127 
  2123 fc_slant
  2128 fc_slant
  2124     "helper for font listing"
  2129     "helper for font listing"
  2125 
  2130 
  2183 
  2188 
  2184     |s|
  2189     |s|
  2185 
  2190 
  2186     lineStream skipSeparators.
  2191     lineStream skipSeparators.
  2187     s := lineStream nextAlphaNumericWord.
  2192     s := lineStream nextAlphaNumericWord.
  2188     ^ s = 'FcTrue'.
  2193     ^ (s indexOfSubCollection:'True') ~~ 0.     "/ match at least 'True' and 'FCTrue'
  2189 !
  2194 !
  2190 
  2195 
  2191 getInteger
  2196 getInteger
  2192     "helper for font listing"
  2197     "helper for font listing"
  2193 
  2198