XftFontDescription.st
changeset 6182 8bf2372670d9
parent 6180 6034bf4c5022
child 6183 a21827076de1
equal deleted inserted replaced
6181:d90dd329fe6a 6182:8bf2372670d9
     1 "{ Package: 'stx:libview' }"
     1 "{ Package: 'stx:libview' }"
     2 
     2 
     3 FontDescription subclass:#XftFontDescription
     3 FontDescription subclass:#XftFontDescription
     4 	instanceVariableNames:'device fontId drawId'
     4 	instanceVariableNames:'device fontId drawId lasrFgColor lastFgColorId lastBgColor
       
     5 		lastBgColorId'
     5 	classVariableNames:''
     6 	classVariableNames:''
     6 	poolDictionaries:''
     7 	poolDictionaries:''
     7 	category:'Graphics-Support'
     8 	category:'Graphics-Support'
     8 !
     9 !
     9 
    10 
    18 #undef True
    19 #undef True
    19 #undef False
    20 #undef False
    20 #undef Time
    21 #undef Time
    21 #define Time XTime
    22 #define Time XTime
    22 
    23 
    23 #ifdef XFT
    24 
       
    25 #ifdef XFT
       
    26 # define __externalAddressValCasted(type, externalAddress) \
       
    27 	((type)__externalAddressVal(externalAddress))
       
    28 # define DISPLAY(x)    __externalAddressValCasted(Display*, x)
       
    29 # define SCREEN(x)     ((int)(__intVal(x)))
       
    30 # define DRAWABLE(x)   __externalAddressValCasted(Drawable, x)
       
    31 # define GC(x)         __externalAddressValCasted(GC, x)
       
    32 # define VISUAL(x)     __externalAddressValCasted(Visual*, x)
       
    33 # define COLORMAP(x)   __externalAddressValCasted(Colormap, x)
       
    34 # define XFT_FONT(x)      __externalAddressValCasted(XftFont*, x)
       
    35 # define XFT_PATTERN(x)   __externalAddressValCasted(XftPattern*, x)
       
    36 # define XFT_DRAW(x)      __externalAddressValCasted(XftDraw*, x)
       
    37 # define XFT_COLOR(x)     __externalAddressValCasted(XftColor*, x)
       
    38 
    24 # include <X11/Xft/Xft.h>
    39 # include <X11/Xft/Xft.h>
    25 # include <X11/Xft/XftCompat.h>
    40 # include <X11/Xft/XftCompat.h>
    26 # define __XftFontVal(handle) ((XftFont*)__externalAddressVal(handle))
    41 
    27 # define __XftPatternVal(handle) ((XftPattern*)__externalAddressVal(handle))
       
    28 # define __XftDrawVal(handle) ((XftDraw*)__externalAddressVal(handle))
       
    29 # define __XftColorVal(handle) ((XftColor*)__externalAddressVal(handle))
       
    30 #endif
    42 #endif
    31 
    43 
    32 %}
    44 %}
    33 ! !
    45 ! !
    34 
    46 
    79     top := StandardSystemView new.
    91     top := StandardSystemView new.
    80     top extent:300@200.
    92     top extent:300@200.
    81 
    93 
    82     textView := EditTextView new.
    94     textView := EditTextView new.
    83     textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
    95     textView origin:0.0 @ 0.0 corner:1.0 @ 1.0.
    84     textView basicFont: (XftFontDescription family: 'helvetica' size: 30).
    96     textView basicFont: (XftFontDescription family: 'helvetica' size: 16).
    85 
    97 
    86     top addSubView:textView.
    98     top addSubView:textView.
    87 
    99 
    88     textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
   100     textView contents:('/etc/hosts' asFilename contentsOfEntireFile).
    89 
   101 
    90     top open.
   102     top open.
    91 
   103 
    92     "Created: / 20-12-2013 / 00:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   104     "Created: / 20-12-2013 / 00:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   105     "Modified: / 29-12-2013 / 10:28:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   106 ! !
       
   107 
       
   108 !XftFontDescription methodsFor:'displaying'!
       
   109 
       
   110 displayString:aString from:index1 to:index2 x:x y:y in:aGC opaque:opaque
       
   111     "display a partial string at some position in aGC."
       
   112 
       
   113     | y0 extents |
       
   114 
       
   115     y0 := y - self ascent.
       
   116 
       
   117     drawId isNil ifTrue:[
       
   118         drawId := self xftDrawCreate: device displayId screen: device screen drawable: aGC id.
       
   119     ] ifFalse:[
       
   120         self xftDrawChange: drawId drawable: aGC id
       
   121     ].
       
   122     lasrFgColor ~= aGC paint ifTrue:[
       
   123         lastFgColorId notNil ifTrue:[
       
   124             self xftColorDestroy: device displayId screen: device screen color: lastFgColorId.
       
   125         ].
       
   126         lasrFgColor := aGC paint.
       
   127         lastFgColorId := self xftColorCreate: device displayId screen: device screen color: lasrFgColor.
       
   128     ].
       
   129     extents :=  self xftTextExtents: device displayId font: fontId string: aString from: index1 to: index2.
       
   130 
       
   131     opaque ifTrue:[
       
   132 
       
   133         lastBgColor ~= aGC backgroundPaint ifTrue:[
       
   134             lastBgColorId notNil ifTrue:[
       
   135                 self xftColorDestroy: device displayId screen: device screen color: lastBgColorId.
       
   136             ].
       
   137             lastBgColor := aGC backgroundPaint.
       
   138             lastBgColorId := self xftColorCreate: device displayId screen: device screen color: lastBgColor.
       
   139         ].
       
   140         self xftDrawRect: drawId color: lastBgColorId  x: x y:y0 width: extents first height: extents second
       
   141 
       
   142     ].
       
   143     "true"false ifTrue:[
       
   144         | w p |
       
   145 
       
   146         w := self widthOf: aString   from: index1 to: index2.
       
   147         p :=  aGC paint.
       
   148         aGC paint: Color red.
       
   149         aGC displayLineFromX: x  y: y toX: x + w y: y.
       
   150         aGC paint: Color blue.
       
   151         aGC displayLineFromX: x  y: y - self ascent toX: x + w y: y - self ascent.
       
   152         aGC paint: Color yellow.
       
   153         aGC displayLineFromX: x  y: y + self descent toX: x + w y: y + self descent.
       
   154 
       
   155 
       
   156         aGC paint: p.
       
   157 
       
   158 
       
   159     ].
       
   160     self xftDrawString: drawId color: lastFgColorId font: fontId x: x y: y  string: aString from: index1 to: index2
       
   161 
       
   162     "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   163     "Modified: / 29-12-2013 / 11:38:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    93 ! !
   164 ! !
    94 
   165 
    95 !XftFontDescription methodsFor:'error reporting'!
   166 !XftFontDescription methodsFor:'error reporting'!
    96 
   167 
    97 primitiveFailedIfNoXft
   168 primitiveFailedIfNoXft
   133         pixelSize notNil ifTrue:[
   204         pixelSize notNil ifTrue:[
   134             self xftPatternAdd: myPatternId attribute: 'pixelsize' value: pixelSize.
   205             self xftPatternAdd: myPatternId attribute: 'pixelsize' value: pixelSize.
   135         ] ifFalse:[
   206         ] ifFalse:[
   136             self xftPatternAdd: myPatternId attribute: 'size' value: size.
   207             self xftPatternAdd: myPatternId attribute: 'size' value: size.
   137         ].
   208         ].
   138         newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.  
   209         newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.
   139         newFontId notNil ifTrue:[
   210         newFontId notNil ifTrue:[
   140             "/ Good, this font exist!!
   211             "/ Good, this font exist!!
   141             fontId := newFontId.
   212             fontId := newFontId.
   142             device := aGraphicsDevice.
   213             device := aGraphicsDevice.
   143             self shouldImplement. "/ Register font...
   214             self shouldImplement. "/ Register font...
   157             "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
   228             "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
   158             closestPatternId1 :=  nil.
   229             closestPatternId1 :=  nil.
   159             newFontId isNil ifTrue:[
   230             newFontId isNil ifTrue:[
   160                 self error: 'Pattern matched, but font could be open (should not happen)'.
   231                 self error: 'Pattern matched, but font could be open (should not happen)'.
   161             ].
   232             ].
   162             ^ self class new                
   233             ^ self class new
   163                 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
   234                 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
   164                 yourself.
   235                 yourself.
   165         ].
   236         ].
   166     ] ensure:[
   237     ] ensure:[
   167         self xftPatternDestroy: myPatternId.
   238         self xftPatternDestroy: myPatternId.
   192 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg
   263 setDevice: deviceArg patternId: patternIdArg fontId: fontIdArg
   193 
   264 
   194     device := deviceArg.
   265     device := deviceArg.
   195     fontId := fontIdArg.
   266     fontId := fontIdArg.
   196 
   267 
   197     family  := self xftPatternGet: patternIdArg attribute: 'family' index: 0.  
   268     family  := self xftPatternGet: patternIdArg attribute: 'family' index: 0.
   198     size    := self xftPatternGet: patternIdArg attribute: 'size' index: 0.
   269     size    := self xftPatternGet: patternIdArg attribute: 'size' index: 0.
   199     face    := self xftPatternGet: patternIdArg attribute: 'slant' index: 0.
   270     face    := self xftPatternGet: patternIdArg attribute: 'slant' index: 0.
   200     face == 0 ifTrue:[ face := 'roman'].
   271     face == 0 ifTrue:[ face := 'roman'].
   201     face == 100 ifTrue:[ face := 'italic'].
   272     face == 100 ifTrue:[ face := 'italic'].
   202     face == 110 ifTrue:[ face := 'oblique'].
   273     face == 110 ifTrue:[ face := 'oblique'].
   217     ^ false
   288     ^ false
   218 
   289 
   219     "Created: / 20-12-2013 / 21:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   290     "Created: / 20-12-2013 / 21:10:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   220 !
   291 !
   221 
   292 
       
   293 xftColorCreate: displayId screen: screen color: color
       
   294 
       
   295     | error r g b a |
       
   296 
       
   297     self primitiveFailedIfNoXft.
       
   298 
       
   299     r := color scaledRed.
       
   300     g := color scaledGreen.
       
   301     b := color scaledBlue.
       
   302     a := color alpha * 65535.
       
   303 %{
       
   304 #ifdef XFT
       
   305     XRenderColor xrcolor;
       
   306     XftColor *xftcolor;
       
   307 
       
   308     if ( ! __isExternalAddressLike(displayId) ) {
       
   309         error = @symbol(BadArg1);
       
   310         goto err;
       
   311     }
       
   312     if ( ! __isSmallInteger(screen) ) {
       
   313         error = @symbol(BadArg2);
       
   314         goto err;
       
   315     }
       
   316     xrcolor.red   = __intVal(r);
       
   317     xrcolor.green = __intVal(g);
       
   318     xrcolor.blue  = __intVal(b);
       
   319     xrcolor.alpha = __intVal(a);
       
   320 
       
   321     xftcolor = (XftColor*) malloc( sizeof( XftColor ) );
       
   322     XftColorAllocValue ( DISPLAY( displayId ) ,
       
   323                          DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
       
   324                          DefaultColormap( DISPLAY( displayId), SCREEN (screen) ),
       
   325                          &xrcolor,
       
   326                          xftcolor );
       
   327     RETURN ( __MKEXTERNALADDRESS( xftcolor ) );
       
   328     err:;
       
   329 #endif
       
   330 %}.
       
   331     self primitiveFailed: error
       
   332 
       
   333     "Created: / 28-12-2013 / 11:55:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   334 !
       
   335 
       
   336 xftColorDestroy: displayId screen: screen color: xftColorId
       
   337 
       
   338     | error |
       
   339 
       
   340     self primitiveFailedIfNoXft.
       
   341 
       
   342 %{
       
   343 #ifdef XFT
       
   344     XRenderColor xrcolor;
       
   345     XftColor *xftcolor;
       
   346 
       
   347     if ( ! __isExternalAddressLike(displayId) ) {
       
   348         error = @symbol(BadArg1);
       
   349         goto err;
       
   350     }
       
   351     if ( ! __isSmallInteger(screen) ) {
       
   352         error = @symbol(BadArg2);
       
   353         goto err;
       
   354     }
       
   355     if ( ! __isExternalAddressLike(xftColorId) ) {
       
   356         error = @symbol(BadArg3);
       
   357         goto err;
       
   358     }
       
   359 
       
   360     XftColorFree ( DISPLAY( displayId ) ,
       
   361                    DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
       
   362                    DefaultColormap( DISPLAY( displayId), SCREEN (screen) ),
       
   363                    XFT_COLOR( xftColorId ) );
       
   364     free( __externalAddressVal( xftColorId ) );
       
   365     __externalAddressVal( xftColorId ) = NULL;
       
   366     RETURN ( self );
       
   367     err:;
       
   368 #endif
       
   369 %}.
       
   370     self primitiveFailed: error
       
   371 
       
   372     "Created: / 28-12-2013 / 12:21:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   373 !
       
   374 
       
   375 xftDrawChange: xftDrawId drawable: drawableId
       
   376 
       
   377     | error |
       
   378 
       
   379     self primitiveFailedIfNoXft.
       
   380 %{
       
   381 #ifdef XFT
       
   382     if ( ! __isExternalAddressLike(xftDrawId) ) {
       
   383         error = @symbol(BadArg1);
       
   384         goto err;
       
   385     }
       
   386     if ( ! __isExternalAddressLike(drawableId) ) {
       
   387         error = @symbol(BadArg2);
       
   388         goto err;
       
   389     }
       
   390     if (XftDrawDrawable( XFT_DRAW(xftDrawId) ) != DRAWABLE( drawableId ) ) {
       
   391         XftDrawChange( XFT_DRAW(xftDrawId) , DRAWABLE( drawableId ) );
       
   392     }
       
   393     RETURN ( self );
       
   394     err:;
       
   395 #endif
       
   396 %}.
       
   397     self primitiveFailed: error
       
   398 
       
   399     "Created: / 26-12-2013 / 12:17:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   400 !
       
   401 
       
   402 xftDrawCreate: displayId screen: screen drawable: drawableId
       
   403 
       
   404     | error |
       
   405 
       
   406     self primitiveFailedIfNoXft.
       
   407 %{
       
   408 #ifdef XFT
       
   409     if ( ! __isExternalAddressLike(displayId) ) {
       
   410         error = @symbol(BadArg1);
       
   411         goto err;
       
   412     }
       
   413     if ( ! __isSmallInteger(screen) ) {
       
   414         error = @symbol(BadArg2);
       
   415         goto err;
       
   416     }
       
   417     if ( ! __isExternalAddressLike(drawableId) ) {
       
   418         error = @symbol(BadArg3);
       
   419         goto err;
       
   420     }
       
   421     RETURN ( __MKEXTERNALADDRESS(  XftDrawCreate ( DISPLAY( displayId ) ,
       
   422                                                    DRAWABLE( drawableId ) ,
       
   423                                                    DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
       
   424                                                    DefaultColormap( DISPLAY( displayId), SCREEN (screen) ) ) ) );
       
   425     err:;
       
   426 #endif
       
   427 %}.
       
   428     self primitiveFailed: error
       
   429 
       
   430     "Created: / 21-12-2013 / 21:12:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   431 !
       
   432 
       
   433 xftDrawRect: drawIdArg color: colorIdArg x: x y: y width: w height: h
       
   434 
       
   435     | error extents |
       
   436 
       
   437     self primitiveFailedIfNoXft.
       
   438 %{
       
   439 #ifdef XFT
       
   440     if ( ! __isExternalAddressLike(drawIdArg) ) {
       
   441         error = @symbol(BadArg1);
       
   442         goto err;
       
   443     }
       
   444     if ( ! __isExternalAddressLike(colorIdArg) ) {
       
   445         error = @symbol(BadArg2);
       
   446         goto err;
       
   447     }
       
   448     if ( ! __isSmallInteger(x) ) {
       
   449         error = @symbol(BadArg3);
       
   450         goto err;
       
   451     }
       
   452     if ( ! __isSmallInteger(y) ) {
       
   453         error = @symbol(BadArg4);
       
   454         goto err;
       
   455     }
       
   456     if ( ! __isSmallInteger(w) ) {
       
   457         error = @symbol(BadArg5);
       
   458         goto err;
       
   459     }
       
   460     if ( ! __isSmallInteger(h) ) {
       
   461         error = @symbol(BadArg6);
       
   462         goto err;
       
   463     }
       
   464     XftDrawRect(XFT_DRAW(drawIdArg), XFT_COLOR(colorIdArg),
       
   465                         __intVal(x), __intVal(y), __intVal(w) ,__intVal(h));
       
   466 
       
   467     RETURN ( self );
       
   468     err:;
       
   469 #endif
       
   470 %}.
       
   471     self primitiveFailed: error.
       
   472 
       
   473     "Created: / 28-12-2013 / 23:35:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   474 !
       
   475 
       
   476 xftDrawString: drawIdArg color: colorIdArg font: fontIdArg x: x y: y string: text from: start to: stop
       
   477 
       
   478     | error extents |
       
   479 
       
   480     self primitiveFailedIfNoXft.
       
   481 %{
       
   482 #ifdef XFT
       
   483     int _start, _stop;
       
   484     int _x, _y;
       
   485     if ( ! __isExternalAddressLike(drawIdArg) ) {
       
   486         error = @symbol(BadArg1);
       
   487         goto err;
       
   488     }
       
   489     if ( ! __isExternalAddressLike(colorIdArg) ) {
       
   490         error = @symbol(BadArg2);
       
   491         goto err;
       
   492     }
       
   493     if ( ! __isExternalAddressLike(fontIdArg) ) {
       
   494         error = @symbol(BadArg3);
       
   495         goto err;
       
   496     }
       
   497     if ( ! __isSmallInteger(x) ) {
       
   498         error = @symbol(BadArg4);
       
   499         goto err;
       
   500     }
       
   501     _x = __intVal(x);
       
   502     if ( ! __isSmallInteger(y) ) {
       
   503         error = @symbol(BadArg5);
       
   504         goto err;
       
   505     }
       
   506     _y = __intVal(y);
       
   507 
       
   508 
       
   509     if ( ! __isSmallInteger(start) ) {
       
   510         error = @symbol(BadArg6);
       
   511         goto err;
       
   512     }
       
   513     _start = __intVal(start);
       
   514     if ( ! __isSmallInteger(stop) ) {
       
   515         error = @symbol(BadArg7);
       
   516         goto err;
       
   517     }
       
   518     _stop = __intVal(stop);
       
   519 
       
   520     if ( __isString(text) ) {
       
   521         XftDrawString8(XFT_DRAW(drawIdArg), XFT_COLOR(colorIdArg), XFT_FONT(fontIdArg),
       
   522                         _x, _y,
       
   523                         __stringVal(text) + (_start - 1), _stop - _start + 1);
       
   524         RETURN ( self );
       
   525     } else {
       
   526         error = @symbol(BadArg5);
       
   527         goto err;
       
   528     }
       
   529     err:;
       
   530 #endif
       
   531 %}.
       
   532     self primitiveFailed: error.
       
   533 
       
   534     "Created: / 28-12-2013 / 12:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   535     "Modified: / 29-12-2013 / 11:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   536 !
       
   537 
   222 xftFontGetAscent: fontIdArg
   538 xftFontGetAscent: fontIdArg
   223 
   539 
   224     | error |
   540     | error |
   225 
   541 
   226     self primitiveFailedIfNoXft.
   542     self primitiveFailedIfNoXft.
   229     int v;
   545     int v;
   230     if ( ! __isExternalAddressLike(fontIdArg) ) {
   546     if ( ! __isExternalAddressLike(fontIdArg) ) {
   231         error = @symbol(BadArg1);
   547         error = @symbol(BadArg1);
   232         goto err;
   548         goto err;
   233     }
   549     }
   234     v = ((XftFont*)__externalAddressVal(fontIdArg))->ascent;
   550     v = XFT_FONT(fontIdArg)->ascent;
   235     RETURN ( __MKINT( v ) );
   551     RETURN ( __MKINT( v ) );
   236     err:;
   552     err:;
   237 #endif
   553 #endif
   238 %}.
   554 %}.
   239     self primitiveFailed: error
   555     self primitiveFailed: error
   251     int v;
   567     int v;
   252     if ( ! __isExternalAddressLike(fontIdArg) ) {
   568     if ( ! __isExternalAddressLike(fontIdArg) ) {
   253         error = @symbol(BadArg1);
   569         error = @symbol(BadArg1);
   254         goto err;
   570         goto err;
   255     }
   571     }
   256     v = ((XftFont*)__externalAddressVal(fontIdArg))->descent;
   572     v = XFT_FONT(fontIdArg)->descent;
   257     RETURN ( __MKINT( v ) );
   573     RETURN ( __MKINT( v ) );
   258     err:;
   574     err:;
   259 #endif
   575 #endif
   260 %}.
   576 %}.
   261     self primitiveFailed: error
   577     self primitiveFailed: error
   273     int v;
   589     int v;
   274     if ( ! __isExternalAddressLike(fontIdArg) ) {
   590     if ( ! __isExternalAddressLike(fontIdArg) ) {
   275         error = @symbol(BadArg1);
   591         error = @symbol(BadArg1);
   276         goto err;
   592         goto err;
   277     }
   593     }
   278     v = ((XftFont*)__externalAddressVal(fontIdArg))->height;
   594     v = XFT_FONT(fontIdArg)->height;
   279     RETURN ( __MKINT( v ) );
   595     RETURN ( __MKINT( v ) );
   280     err:;
   596     err:;
   281 #endif
   597 #endif
   282 %}.
   598 %}.
   283     self primitiveFailed: error
   599     self primitiveFailed: error
   295     XftPattern* p;
   611     XftPattern* p;
   296     if ( ! __isExternalAddressLike(fontIdArg) ) {
   612     if ( ! __isExternalAddressLike(fontIdArg) ) {
   297         error = @symbol(BadArg1);
   613         error = @symbol(BadArg1);
   298         goto err;
   614         goto err;
   299     }
   615     }
   300     p = ((XftFont*)__externalAddressVal(fontIdArg))->pattern;
   616     p = XFT_FONT(fontIdArg)->pattern;
   301     if (p == NULL) {
   617     if (p == NULL) {
   302         RETURN ( nil );
   618         RETURN ( nil );
   303     } else {
   619     } else {
   304         RETURN ( __MKEXTERNALADDRESS ( p ) );
   620         RETURN ( __MKEXTERNALADDRESS ( p ) );
   305     }
   621     }
   332     if ( ! __isExternalAddressLike(patternId) ) {
   648     if ( ! __isExternalAddressLike(patternId) ) {
   333         error = @symbol(BadArg3);
   649         error = @symbol(BadArg3);
   334         goto err;
   650         goto err;
   335     }
   651     }
   336 
   652 
   337     p = XftFontMatch( __externalAddressVal(displayId) , __intVal( screen ), __externalAddressVal( patternId ), &r );
   653     p = XftFontMatch( DISPLAY(displayId) , SCREEN( screen ), XFT_PATTERN( patternId ), &r );
   338     if (r == XftResultMatch) {
   654     if (r == XftResultMatch) {
   339         RETURN ( __MKEXTERNALADDRESS ( p ) );
   655         RETURN ( __MKEXTERNALADDRESS ( p ) );
   340     } else {
   656     } else {
   341         if ( p ) {
   657         if ( p ) {
   342             XftPatternDestroy( p );
   658             XftPatternDestroy( p );
   366     if ( ! __isExternalAddressLike(patternId) ) {
   682     if ( ! __isExternalAddressLike(patternId) ) {
   367         error = @symbol(BadArg2);
   683         error = @symbol(BadArg2);
   368         goto err;
   684         goto err;
   369     }
   685     }
   370 
   686 
   371     f = XftFontOpenPattern( __externalAddressVal(displayId) , __externalAddressVal( patternId ) );
   687     f = XftFontOpenPattern( DISPLAY(displayId) , XFT_PATTERN( patternId ) );
   372     if (f == NULL) {
   688     if (f == NULL) {
   373         RETURN ( nil );
   689         RETURN ( nil );
   374     } else {
   690     } else {
   375         RETURN ( __MKEXTERNALADDRESS ( f ) );
   691         RETURN ( __MKEXTERNALADDRESS ( f ) );
   376     }
   692     }
   436     	v.u.f = NULL;
   752     	v.u.f = NULL;
   437     } else {
   753     } else {
   438     	error = @symbol(BadArg3);
   754     	error = @symbol(BadArg3);
   439     	goto err;
   755     	goto err;
   440     }
   756     }
   441     b = XftPatternAdd( __externalAddressVal(pattern), __stringVal(attribute), v, append == true ? True : False );
   757     b = XftPatternAdd( XFT_PATTERN(pattern), __stringVal(attribute), v, append == true ? True : False );
   442     RETURN ( b == True ? true : false );
   758     RETURN ( b == True ? true : false );
   443 
   759 
   444     err:;
   760     err:;
   445 #endif
   761 #endif
   446 %}.
   762 %}.
   475     }
   791     }
   476     if ( ! __isStringLike ( attribute ) ) {
   792     if ( ! __isStringLike ( attribute ) ) {
   477     	error = @symbol(BadArg2);
   793     	error = @symbol(BadArg2);
   478     	goto err;
   794     	goto err;
   479     }
   795     }
   480     XftPatternDel( __externalAddressVal(pattern), __stringVal ( attribute ) );
   796     XftPatternDel( XFT_PATTERN(pattern), __stringVal ( attribute ) );
   481     RETURN ( self );
   797     RETURN ( self );
   482 
   798 
   483     err:;
   799     err:;
   484 #endif
   800 #endif
   485 %}.
   801 %}.
   499 #ifdef XFT
   815 #ifdef XFT
   500     if ( ! __isExternalAddressLike(addr) ) {
   816     if ( ! __isExternalAddressLike(addr) ) {
   501         error = @symbol(BadArg1);
   817         error = @symbol(BadArg1);
   502         goto err;
   818         goto err;
   503     }
   819     }
   504     XftPatternDestroy( __externalAddressVal(addr) );
   820     XftPatternDestroy( XFT_PATTERN(addr) );
   505     RETURN ( self );
   821     RETURN ( self );
   506 
   822 
   507     err:;
   823     err:;
   508 #endif
   824 #endif
   509 %}.
   825 %}.
   524 #ifdef XFT
   840 #ifdef XFT
   525     if ( ! __isExternalAddressLike(addr) ) {
   841     if ( ! __isExternalAddressLike(addr) ) {
   526         error = @symbol(BadArg1);
   842         error = @symbol(BadArg1);
   527         goto err;
   843         goto err;
   528     }
   844     }
   529     RETURN ( __MKEXTERNALADDRESS ( XftPatternDuplicate( __externalAddressVal(addr) ) ) );
   845     RETURN ( __MKEXTERNALADDRESS ( XftPatternDuplicate( XFT_PATTERN(addr) ) ) );
   530     err:;
   846     err:;
   531 #endif
   847 #endif
   532 %}.
   848 %}.
   533     self primitiveFailed: error
   849     self primitiveFailed: error
   534 
   850 
   557     }
   873     }
   558     if ( ! __isSmallInteger( index ) ) {
   874     if ( ! __isSmallInteger( index ) ) {
   559         error = @symbol(BadArg3);
   875         error = @symbol(BadArg3);
   560         goto err;
   876         goto err;
   561     }
   877     }
   562     r = XftPatternGet(__externalAddressVal( pattern ), __stringVal( attribute ), __intVal( index ), &v);
   878     r = XftPatternGet(XFT_PATTERN(pattern), __stringVal( attribute ), __intVal( index ), &v);
   563     if ( r != XftResultMatch) {
   879     if ( r != XftResultMatch) {
   564         RETURN ( nil );
   880         RETURN ( nil );
   565     }
   881     }
   566     if ( v.type == XftTypeString) {
   882     if ( v.type == XftTypeString) {
   567         RETURN ( __MKSTRING(v.u.s) );
   883         RETURN ( __MKSTRING(v.u.s) );
   582 %}.
   898 %}.
   583     self primitiveFailed: error
   899     self primitiveFailed: error
   584 
   900 
   585     "Created: / 20-12-2013 / 21:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   901     "Created: / 20-12-2013 / 21:50:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   586     "Modified: / 21-12-2013 / 01:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   902     "Modified: / 21-12-2013 / 01:06:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   903 !
       
   904 
       
   905 xftTextExtents: displayIdArg font: fontIdArg string: text from: start to: stop
       
   906 
       
   907     | error extents |
       
   908 
       
   909     self primitiveFailedIfNoXft.
       
   910     extents :=  Array new: 6.
       
   911 %{
       
   912 #ifdef XFT
       
   913     XGlyphInfo info;
       
   914     int _start, _stop;
       
   915     if ( ! __isExternalAddressLike(displayIdArg) ) {
       
   916         error = @symbol(BadArg1);
       
   917         goto err;
       
   918     }
       
   919     if ( ! __isExternalAddressLike(fontIdArg) ) {
       
   920         error = @symbol(BadArg2);
       
   921         goto err;
       
   922     }
       
   923     if ( ! __isSmallInteger(start) ) {
       
   924         error = @symbol(BadArg4);
       
   925         goto err;
       
   926     }
       
   927     _start = __intVal(start);
       
   928     if ( ! __isSmallInteger(stop) ) {
       
   929         error = @symbol(BadArg5);
       
   930         goto err;
       
   931     }
       
   932     _stop = __intVal(stop);
       
   933     if ( __isString(text) ) {
       
   934         XftTextExtents8(DISPLAY(displayIdArg), XFT_FONT(fontIdArg),
       
   935                         __stringVal(text) + (_start - 1), _stop - _start + 1, &info);
       
   936     } else {
       
   937         error = @symbol(BadArg3);
       
   938         goto err;
       
   939     }
       
   940     __ArrayInstPtr(extents)->a_element[0] = __MKSMALLINT(info.width);
       
   941     __ArrayInstPtr(extents)->a_element[1] = __MKSMALLINT(info.height);
       
   942     __ArrayInstPtr(extents)->a_element[2] = __MKSMALLINT(info.x);
       
   943     __ArrayInstPtr(extents)->a_element[3] = __MKSMALLINT(info.y);
       
   944     __ArrayInstPtr(extents)->a_element[4] = __MKSMALLINT(info.xOff);
       
   945     __ArrayInstPtr(extents)->a_element[5] = __MKSMALLINT(info.yOff);
       
   946     error = nil;
       
   947     err:;
       
   948 #endif
       
   949 %}.
       
   950     error notNil ifTrue:[
       
   951         self primitiveFailed: error.
       
   952         ^ nil.
       
   953     ].
       
   954     ^ extents
       
   955 
       
   956     "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   957     "Modified: / 21-12-2013 / 20:53:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   587 ! !
   958 ! !
   588 
   959 
   589 !XftFontDescription methodsFor:'queries-dimensions'!
   960 !XftFontDescription methodsFor:'queries-dimensions'!
   590 
   961 
   591 ascent
   962 ascent
   608     "return the height - the number of pixels above plus below the baseLine."
   979     "return the height - the number of pixels above plus below the baseLine."
   609 
   980 
   610     ^ self xftFontGetHeight: fontId
   981     ^ self xftFontGetHeight: fontId
   611 
   982 
   612     "Created: / 21-12-2013 / 01:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   983     "Created: / 21-12-2013 / 01:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   984 !
       
   985 
       
   986 isFixedWidth
       
   987     "return true, if this is a fixed pitch font (i.e. all characters
       
   988      are of the same width)"
       
   989 
       
   990     ^ false "/ How to check?
       
   991 
       
   992     "Created: / 21-12-2013 / 10:38:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   993 !
       
   994 
       
   995 widthOf:aString from:start to:stop
       
   996     "return the width of a sub string"
       
   997 
       
   998     | extents |
       
   999 
       
  1000     extents := self xftTextExtents: device displayId font: fontId string: aString from: start to: stop.
       
  1001     "/ extents --> #(width height x y xOff yOff)
       
  1002     ^ extents first.
       
  1003 
       
  1004     "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   613 ! !
  1005 ! !
   614 
  1006 
   615 !XftFontDescription class methodsFor:'documentation'!
  1007 !XftFontDescription class methodsFor:'documentation'!
   616 
  1008 
   617 version
  1009 version
   618     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.3 2013-12-21 00:21:22 vrany Exp $'
  1010     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.4 2013-12-29 11:03:28 vrany Exp $'
   619 !
  1011 !
   620 
  1012 
   621 version_CVS
  1013 version_CVS
   622     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.3 2013-12-21 00:21:22 vrany Exp $'
  1014     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.4 2013-12-29 11:03:28 vrany Exp $'
   623 ! !
  1015 ! !
   624 
  1016