XftFontDescription.st
changeset 6333 a39a5f90e4fd
parent 6327 332c152432eb
child 6337 9bf102dba190
equal deleted inserted replaced
6332:792a2b79c651 6333:a39a5f90e4fd
   442 
   442 
   443     bytesPerCharacter := aString bitsPerCharacter // 8.
   443     bytesPerCharacter := aString bitsPerCharacter // 8.
   444     transformation := aGC transformation.
   444     transformation := aGC transformation.
   445 
   445 
   446     transformation isNil ifTrue:[
   446     transformation isNil ifTrue:[
   447 	drawX := xArg.
   447         drawX := xArg.
   448 	drawY := yArg.
   448         drawY := yArg.
   449     ] ifFalse:[
   449     ] ifFalse:[
   450 	drawX := transformation applyToX: xArg.
   450         drawX := transformation applyToX: xArg.
   451 	drawY := transformation applyToY: yArg.
   451         drawY := transformation applyToY: yArg.
   452     ].
   452     ].
   453 
   453 
   454     clipR := aGC clippingBoundsOrNil.
   454     clipR := aGC clippingBoundsOrNil.
   455     clipR notNil ifTrue:[
   455     clipR notNil ifTrue:[
   456 	clipX := clipR left.
   456         clipX := clipR left.
   457 	clipY := clipR top.
   457         clipY := clipR top.
   458 	clipW := clipR width.
   458         clipW := clipR width.
   459 	clipH := clipR height.
   459         clipH := clipR height.
   460     ].
   460     ].
   461 
   461 
   462     fg  :=  aGC paint.
   462     fg  :=  aGC paint.
   463     fgPixel := fg colorId.
   463     fgPixel := fg colorId.
   464     "/ fgPixel notNil ifTrue:[
   464     "/ fgPixel notNil ifTrue:[
   465 	fgR := fg scaledRed.
   465         fgR := fg scaledRed.
   466 	fgG := fg scaledGreen.
   466         fgG := fg scaledGreen.
   467 	fgB := fg scaledBlue.
   467         fgB := fg scaledBlue.
   468 	fgA := (fg alpha * 65535) rounded.
   468         fgA := (fg alpha * 65535) rounded.
   469     "/].
   469     "/].
   470     fgR isNil ifTrue:[
   470     fgR isNil ifTrue:[
   471 	"/ when drawing into a pixmap...
   471         "/ when drawing into a pixmap...
   472 	fg colorId == 0 ifTrue:[
   472         fg colorId == 0 ifTrue:[
   473 	    fgR := fgG := fgB := 0.
   473             fgR := fgG := fgB := 0.
   474 	] ifFalse:[
   474         ] ifFalse:[
   475 	    fgR := fgG := fgB := 16rFFFF.
   475             fgR := fgG := fgB := 16rFFFF.
   476 	]
   476         ]
   477     ].
   477     ].
   478 
   478 
   479     opaque ifTrue:[
   479     opaque ifTrue:[
   480 	bg  := aGC backgroundPaint.
   480         bg  := aGC backgroundPaint.
   481 	bgPixel := bg colorId.
   481         bgPixel := bg colorId.
   482 	"/bgPixel notNil ifTrue:[
   482         "/bgPixel notNil ifTrue:[
   483 	    bgR := bg scaledRed.
   483             bgR := bg scaledRed.
   484 	    bgG := bg scaledGreen.
   484             bgG := bg scaledGreen.
   485 	    bgB := bg scaledBlue.
   485             bgB := bg scaledBlue.
   486 	    bgA := (bg alpha * 65535) rounded.
   486             bgA := (bg alpha * 65535) rounded.
   487 	"/].
   487         "/].
   488 	bgR isNil ifTrue:[
   488         bgR isNil ifTrue:[
   489 	    "/ when drawing into a pixmap...
   489             "/ when drawing into a pixmap...
   490 	    bg colorId == 0 ifTrue:[
   490             bg colorId == 0 ifTrue:[
   491 		bgR := bgG := bgB := 0.
   491                 bgR := bgG := bgB := 0.
   492 	    ] ifFalse:[
   492             ] ifFalse:[
   493 		bgR := bgG := bgB := 16rFFFF.
   493                 bgR := bgG := bgB := 16rFFFF.
   494 	    ]
   494             ]
   495 	].
   495         ].
   496     ].
   496     ].
   497     displayId := device displayId.
   497     displayId := device displayIdOrErrorIfBroken.
       
   498     displayId isNil ifTrue:[    
       
   499         ^ self.
       
   500     ].
   498     screen := device screen.
   501     screen := device screen.
   499     drawableId := aGC id.
   502     drawableId := aGC id.
   500 
   503 
   501 %{
   504 %{
   502 #ifdef XFT
   505 #ifdef XFT
   508     char* string;
   511     char* string;
   509     int len;
   512     int len;
   510     int __bytesPerCharacter;
   513     int __bytesPerCharacter;
   511 
   514 
   512     if (!(__bothSmallInteger(drawX, drawY)
   515     if (!(__bothSmallInteger(drawX, drawY)
   513 	  && __bothSmallInteger(index1, index2)
   516           && __bothSmallInteger(index1, index2)
   514 	  && __isSmallInteger(bytesPerCharacter)
   517           && __isSmallInteger(bytesPerCharacter)
   515 	  && (__isSmallInteger(fgPixel) || (__bothSmallInteger(fgR, fgG) && __bothSmallInteger(fgB, fgA)))
   518           && (__isSmallInteger(fgPixel) || (__bothSmallInteger(fgR, fgG) && __bothSmallInteger(fgB, fgA)))
   516 	  && (opaque == false || __isSmallInteger(bgPixel) || (__bothSmallInteger(bgR, bgG) && __bothSmallInteger(bgB, bgA)))
   519           && (opaque == false || __isSmallInteger(bgPixel) || (__bothSmallInteger(bgR, bgG) && __bothSmallInteger(bgB, bgA)))
   517 	  && __isNonNilObject(aString)
   520           && __isNonNilObject(aString)
   518     )) {
   521     )) {
   519 	goto err;
   522         goto err;
   520     }
   523     }
   521 
   524 
   522     __bytesPerCharacter = __intVal(bytesPerCharacter);
   525     __bytesPerCharacter = __intVal(bytesPerCharacter);
   523 
   526 
   524     if ( __INST(drawId) == nil ) {
   527     if ( __INST(drawId) == nil ) {
   525 	__INST(drawId) = XFT_DRAW_HANDLE_NEW ( XftDrawCreate ( DISPLAY( displayId ) ,
   528         __INST(drawId) = XFT_DRAW_HANDLE_NEW ( XftDrawCreate ( DISPLAY( displayId ) ,
   526 					       DRAWABLE( drawableId ) ,
   529                                                DRAWABLE( drawableId ) ,
   527 					       DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
   530                                                DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
   528 					       DefaultColormap( DISPLAY( displayId), SCREEN (screen) ) ) );
   531                                                DefaultColormap( DISPLAY( displayId), SCREEN (screen) ) ) );
   529 	__STORE(self, __INST(drawId));
   532         __STORE(self, __INST(drawId));
   530     }
   533     }
   531 
   534 
   532     if ( XftDrawDrawable ( XFT_DRAW ( __INST(drawId) ) ) != DRAWABLE( drawableId ) ) {
   535     if ( XftDrawDrawable ( XFT_DRAW ( __INST(drawId) ) ) != DRAWABLE( drawableId ) ) {
   533 	XftDrawChange( XFT_DRAW( __INST(drawId) ) , DRAWABLE( drawableId ) );
   536         XftDrawChange( XFT_DRAW( __INST(drawId) ) , DRAWABLE( drawableId ) );
   534     }
   537     }
   535 
   538 
   536     string = __stringVal( aString ) + (( __intVal(index1) - 1 ) * __bytesPerCharacter);
   539     string = __stringVal( aString ) + (( __intVal(index1) - 1 ) * __bytesPerCharacter);
   537     len = __intVal(index2) - __intVal(index1) + 1;
   540     len = __intVal(index2) - __intVal(index1) + 1;
   538 
   541 
   539     if (clipR != nil) {
   542     if (clipR != nil) {
   540 	clipRX.x = __intVal(clipX);
   543         clipRX.x = __intVal(clipX);
   541 	clipRX.y = __intVal(clipY);
   544         clipRX.y = __intVal(clipY);
   542 	clipRX.width = __intVal(clipW);
   545         clipRX.width = __intVal(clipW);
   543 	clipRX.height = __intVal(clipH);
   546         clipRX.height = __intVal(clipH);
   544 	XftDrawSetClipRectangles( XFT_DRAW( __INST( drawId ) ) , 0, 0, &clipRX, 1);
   547         XftDrawSetClipRectangles( XFT_DRAW( __INST( drawId ) ) , 0, 0, &clipRX, 1);
   545     } else {
   548     } else {
   546 	XftDrawSetClip( XFT_DRAW( __INST( drawId ) ) , 0);
   549         XftDrawSetClip( XFT_DRAW( __INST( drawId ) ) , 0);
   547     }
   550     }
   548 
   551 
   549     if (opaque == true) {
   552     if (opaque == true) {
   550 	if (bgPixel != nil) {
   553         if (bgPixel != nil) {
   551 	    color.pixel = (unsigned long)__intVal(bgPixel);
   554             color.pixel = (unsigned long)__intVal(bgPixel);
   552 	}
   555         }
   553 	// else {
   556         // else {
   554 	    color.color.red = __intVal(bgR);
   557             color.color.red = __intVal(bgR);
   555 	    color.color.green = __intVal(bgG);
   558             color.color.green = __intVal(bgG);
   556 	    color.color.blue = __intVal(bgB);
   559             color.color.blue = __intVal(bgB);
   557 	    color.color.alpha = __intVal(bgA);
   560             color.color.alpha = __intVal(bgA);
   558 	// }
   561         // }
   559 	switch (__bytesPerCharacter) {
   562         switch (__bytesPerCharacter) {
   560 	case 1:
   563         case 1:
   561 	    XftTextExtents8( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar8*)string, len, &extents);
   564             XftTextExtents8( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar8*)string, len, &extents);
   562 	    break;
   565             break;
   563 	case 2:
   566         case 2:
   564 	    XftTextExtents16( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar16*)string, len, &extents);
   567             XftTextExtents16( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar16*)string, len, &extents);
   565 	    break;
   568             break;
   566 	case 4:
   569         case 4:
   567 	    XftTextExtents32( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar32*)string, len, &extents);
   570             XftTextExtents32( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar32*)string, len, &extents);
   568 	    break;
   571             break;
   569 	}
   572         }
   570 	XftDrawRect( XFT_DRAW ( __INST( drawId ) ), &color, __intVal(drawX) - extents.x, __intVal(drawY) - XFT_FONT( __INST( fontId ) )->ascent, extents.width, XFT_FONT(__INST (fontId ) )->height);
   573         XftDrawRect( XFT_DRAW ( __INST( drawId ) ), &color, __intVal(drawX) - extents.x, __intVal(drawY) - XFT_FONT( __INST( fontId ) )->ascent, extents.width, XFT_FONT(__INST (fontId ) )->height);
   571     }
   574     }
   572     if (fgPixel != nil) {
   575     if (fgPixel != nil) {
   573 	color.pixel = (unsigned long)__intVal(fgPixel);
   576         color.pixel = (unsigned long)__intVal(fgPixel);
   574     }
   577     }
   575     // else {
   578     // else {
   576 	color.color.red = __intVal(fgR);
   579         color.color.red = __intVal(fgR);
   577 	color.color.green = __intVal(fgG);
   580         color.color.green = __intVal(fgG);
   578 	color.color.blue = __intVal(fgB);
   581         color.color.blue = __intVal(fgB);
   579 	color.color.alpha = __intVal(fgA);
   582         color.color.alpha = __intVal(fgA);
   580     // }
   583     // }
   581     switch (__bytesPerCharacter) {
   584     switch (__bytesPerCharacter) {
   582     case 1:
   585     case 1:
   583 	XftDrawString8( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   586         XftDrawString8( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   584 			__intVal(drawX),
   587                         __intVal(drawX),
   585 			__intVal(drawY),
   588                         __intVal(drawY),
   586 			(FcChar8*)string,
   589                         (FcChar8*)string,
   587 			len);
   590                         len);
   588 	RETURN ( self );
   591         RETURN ( self );
   589 	break;
   592         break;
   590     case 2:
   593     case 2:
   591 	XftDrawString16( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   594         XftDrawString16( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   592 			__intVal(drawX),
   595                         __intVal(drawX),
   593 			__intVal(drawY),
   596                         __intVal(drawY),
   594 			(FcChar16*)string,
   597                         (FcChar16*)string,
   595 			len);
   598                         len);
   596 	RETURN ( self );
   599         RETURN ( self );
   597 	break;
   600         break;
   598     case 4:
   601     case 4:
   599 	XftDrawString32( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   602         XftDrawString32( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
   600 			__intVal(drawX),
   603                         __intVal(drawX),
   601 			__intVal(drawY),
   604                         __intVal(drawY),
   602 			(FcChar32*)string,
   605                         (FcChar32*)string,
   603 			len);
   606                         len);
   604 	RETURN ( self );
   607         RETURN ( self );
   605 	break;
   608         break;
   606     }
   609     }
   607     err:;
   610     err:;
   608 #endif
   611 #endif
   609 %}.
   612 %}.
   610     self primitiveFailed: error.
   613     self primitiveFailed: error.
  1872 ! !
  1875 ! !
  1873 
  1876 
  1874 !XftFontDescription class methodsFor:'documentation'!
  1877 !XftFontDescription class methodsFor:'documentation'!
  1875 
  1878 
  1876 version
  1879 version
  1877     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.36 2014-03-17 09:20:57 cg Exp $'
  1880     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.37 2014-03-17 19:19:39 stefan Exp $'
  1878 !
  1881 !
  1879 
  1882 
  1880 version_CVS
  1883 version_CVS
  1881     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.36 2014-03-17 09:20:57 cg Exp $'
  1884     ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.37 2014-03-17 19:19:39 stefan Exp $'
  1882 ! !
  1885 ! !
  1883 
  1886 
  1884 
  1887 
  1885 XftFontDescription initialize!
  1888 XftFontDescription initialize!