XftFontDescription.st
changeset 6176 9d9d7b5c33f4
child 6179 b2af8f1be089
equal deleted inserted replaced
6175:f993cd235795 6176:9d9d7b5c33f4
       
     1 "{ Package: 'stx:libview' }"
       
     2 
       
     3 FontDescription subclass:#XftFontDescription
       
     4 	instanceVariableNames:'device fontId drawId'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'Graphics-Support'
       
     8 !
       
     9 
       
    10 !XftFontDescription primitiveDefinitions!
       
    11 %{
       
    12 
       
    13 /*
       
    14  * includes, defines, structure definitions
       
    15  * and typedefs come here.
       
    16  */
       
    17 
       
    18 #undef True
       
    19 #undef False
       
    20 #define Time XTime
       
    21 
       
    22 #ifdef XFT
       
    23 # include <X11/Xft/Xft.h>
       
    24 # include <X11/Xft/XftCompat.h>
       
    25 #endif
       
    26 
       
    27 %}
       
    28 ! !
       
    29 
       
    30 !XftFontDescription class methodsFor:'documentation'!
       
    31 
       
    32 documentation
       
    33 "
       
    34     WARNING: Unfinished.
       
    35 
       
    36     Experimental implementation of custom font rendered using
       
    37     Xft library (UNIX / X Window only), To actually use it,
       
    38     add following definitions to the end of stx/configurations/myConf
       
    39     (works on Ubuntu 12.10)
       
    40 
       
    41     --- snip ---
       
    42     XDEFS+=-DXFT
       
    43     XINCLUDE+=$(shell pkg-config --cflags xft)
       
    44     LIB_XFT=-l:libXft.so.2 -l:libfontconfig.so.1
       
    45     --- snip --
       
    46 
       
    47     NOTE: This class should be named XftFont, however then
       
    48     there would be a name clash with XftFont structure
       
    49     defined in Xft.h - therefore the class is named
       
    50     XftFontDescription to avoid that name clash.
       
    51 
       
    52 
       
    53     [author:]
       
    54         Jan Vrany <jan.vrany@fit.cvut.cz>
       
    55 
       
    56     [instance variables:]
       
    57 
       
    58     [class variables:]
       
    59 
       
    60     [see also:]
       
    61 
       
    62 "
       
    63 ! !
       
    64 
       
    65 !XftFontDescription class methodsFor:'examples'!
       
    66 
       
    67 example1
       
    68 
       
    69     "
       
    70     XftFontDescription example1
       
    71     "
       
    72     |top textView|
       
    73 
       
    74     top := StandardSystemView new.
       
    75     top extent:300@200.
       
    76 
       
    77     textView := EditTextView new.
       
    78     textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
       
    79     textView basicFont: (XftFontDescription family: 'helvetica' size: 30).     
       
    80 
       
    81     top addSubView:textView.
       
    82 
       
    83     textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
       
    84 
       
    85     top open.
       
    86 
       
    87     "Created: / 20-12-2013 / 00:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    88 ! !
       
    89 
       
    90 !XftFontDescription methodsFor:'getting a device font'!
       
    91 
       
    92 onDevice:aGraphicsDevice
       
    93     "Create a new XftFont representing the closes font as
       
    94      myself on aDevice; if one already exists, return the one."
       
    95 
       
    96     | newFont displayHandle screen|
       
    97 
       
    98     "if I am already assigned to that device ..."
       
    99     (device == aGraphicsDevice) ifTrue:[^ self].
       
   100 
       
   101     (aGraphicsDevice isNil and:[device notNil]) ifTrue:[
       
   102         ^ self
       
   103     ].
       
   104 
       
   105     aGraphicsDevice deviceFonts do:[:aFont |
       
   106         (self sameDeviceFontAs:aFont) ifTrue:[
       
   107             ^ aFont
       
   108         ].
       
   109     ].
       
   110 
       
   111     displayHandle := aGraphicsDevice displayId.
       
   112     "/ TODO: ensure displayHandle is an ExternalAddress
       
   113 
       
   114     screen := aGraphicsDevice screen.
       
   115     "/ TODO: ensure displayHandle is an SmallInteger
       
   116 %{
       
   117 #ifdef XFT
       
   118     XftPattern* pattern = XftPatternCreate();
       
   119     XftFont* font;
       
   120     XftResult result;
       
   121 
       
   122     if (__isStringLike(__INST(family))) {
       
   123         XftPatternAddString(pattern, XFT_FAMILY, __stringVal(__INST(family)));
       
   124     }
       
   125     if (__isSmallInteger(__INST(size))) {
       
   126         XftPatternAddDouble(pattern, XFT_SIZE, (double)__intVal(__INST(size)));
       
   127     } else {
       
   128         if (__isSmallInteger(__INST(size))) {
       
   129             XftPatternAddInteger(pattern, XFT_PIXEL_SIZE, __intVal(__INST(pixelSize)));
       
   130         }
       
   131     }
       
   132 
       
   133     pattern = XftFontMatch(__externalAddressVal(displayHandle), __intVal(screen), pattern, &result);
       
   134     __INST(fontId) = __MKEXTERNALADDRESS(XftFontOpenPattern(__externalAddressVal(displayHandle), pattern));
       
   135     XftPatternDestroy(pattern);
       
   136 #else
       
   137     RETURN ( nil )
       
   138 #endif
       
   139 %}.
       
   140     ^ self
       
   141 
       
   142     "
       
   143      (Font family:'fooXXXXXX' size:17) onDevice:Screen current
       
   144     "
       
   145 
       
   146     "Modified: / 14-04-1997 / 18:22:31 / cg"
       
   147     "Modified: / 20-12-2013 / 10:56:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   148 !
       
   149 
       
   150 onDevice:aDevice ifAbsent:exceptionBlock
       
   151     "Create a new XftFont representing the same font as
       
   152      myself on aDevice. This does NOT try to look for existing
       
   153      or replacement fonts (i.e. can be used to get physical fonts)."
       
   154 
       
   155     ^ self shouldImplement
       
   156 
       
   157     "Modified: / 20-12-2013 / 10:54:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   158 ! !
       
   159 
       
   160 !XftFontDescription class methodsFor:'documentation'!
       
   161 
       
   162 version
       
   163     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.1 2013-12-20 09:57:03 vrany Exp $'
       
   164 !
       
   165 
       
   166 version_CVS
       
   167     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.1 2013-12-20 09:57:03 vrany Exp $'
       
   168 ! !
       
   169