--- a/XftFontDescription.st Fri Jan 03 11:16:08 2014 +0100
+++ b/XftFontDescription.st Sat Jan 04 02:06:40 2014 +0100
@@ -69,15 +69,15 @@
extern OBJ __GLOBAL_GET_BY_NAME();
# define __HANDLE_VAL(type, externalAddress) \
- ((type)__externalAddressVal(externalAddress))
-#define __HANDLE_NEW(ptr, __cls) \
- ({ \
- OBJ handle; \
- handle = __MKEXTERNALADDRESS(ptr); \
- __InstPtr(handle)->o_class = \
- __GLOBAL_GET_BY_NAME(__cls); \
- handle; \
- })
+ ((type)__externalAddressVal(externalAddress))
+#define __HANDLE_NEW(ptr, __cls) \
+ ({ \
+ OBJ handle; \
+ handle = __MKEXTERNALADDRESS(ptr); \
+ __InstPtr(handle)->o_class = \
+ __GLOBAL_GET_BY_NAME(__cls); \
+ handle; \
+ })
@@ -92,15 +92,15 @@
/* FontConfig objects */
-# define FC_PATTERN(x) __HANDLE_VAL(XftPattern*, x)
-# define FC_PATTERN_HANDLE_NEW(x) __HANDLE_NEW(x, "XftFontDescription::FCPatternHandle")
+# define FC_PATTERN(x) __HANDLE_VAL(XftPattern*, x)
+# define FC_PATTERN_HANDLE_NEW(x) __HANDLE_NEW(x, "XftFontDescription::FCPatternHandle")
/* Xft Objects */
-# define XFT_FONT(x) __HANDLE_VAL(XftFont*, x)
+# define XFT_FONT(x) __HANDLE_VAL(XftFont*, x)
# define XFT_FONT_HANDLE_NEW(x) __HANDLE_NEW(x, "XftFontDescription::XftFontHandle")
-# define XFT_DRAW(x) __HANDLE_VAL(XftDraw*, x)
+# define XFT_DRAW(x) __HANDLE_VAL(XftDraw*, x)
# define XFT_DRAW_HANDLE_NEW(x) __HANDLE_NEW(x, "XftFontDescription::XftDrawHandle")
@@ -342,30 +342,106 @@
displayString:aString from:index1 to:index2 x:x y:y in:aGC opaque:opaque
"display a partial string at some position in aGC."
- | extents |
+ | clipR clipX clipY clipW clipH fg fgR fgG fgB fgA fgPixel bg bgR bgG bgB bgA bgPixel displayId screen drawableId error |
+
+ self primitiveFailedIfNoXft.
- drawId isNil ifTrue:[
- drawId := self xftDrawCreate: device displayId screen: device screen drawable: aGC id.
- ] ifFalse:[
- self xftDrawChange: drawId drawable: aGC id
+ clipR := aGC clippingBounds.
+ clipR notNil ifTrue:[
+ clipX := clipR left.
+ clipY := clipR top.
+ clipW := clipR width.
+ clipH := clipR height.
].
- self xftDrawSetClip: drawId rectangle: aGC clippingBounds.
- extents := self xftTextExtents: device displayId font: fontId string: aString from: index1 to: index2.
+ fg := aGC paint.
+ fgR := fg scaledRed.
+ fgG := fg scaledGreen.
+ fgB := fg scaledBlue.
+ fgA := fg alpha * 65535.
+ fgPixel := fg colorId.
opaque ifTrue:[
- "/ While following is technically correct
- "/
- "/ self xftDrawRect: drawId color: aGC backgroundPaint x: x - extents third y:y - extents fourth width: extents first height: extents second
- "/
- "/ We have to clear while ascent+descent because otherwise Text with background become
- "/ funny-looking. This is a bug in Text which has to be compensated here...
- self xftDrawRect: drawId color: aGC backgroundPaint x: x - extents third y:y - self ascent width: extents first height: self height
+ bg := aGC backgroundPaint.
+ bgR := bg scaledRed.
+ bgG := bg scaledGreen.
+ bgB := bg scaledBlue.
+ bgA := bg alpha * 65535.
+ bgPixel := bg colorId.
+ ].
+ displayId := device displayId.
+ screen := device screen.
+ drawableId := aGC id.
+%{
+#ifdef XFT
+ XftFont *font;
+ XftDraw *draw;
+ XftColor color;
+ XGlyphInfo extents;
+ XRectangle clipRX;
+ char* string;
+
+ int len;
+ if ( __INST(drawId) == nil ) {
+ __INST(drawId) = XFT_DRAW_HANDLE_NEW ( XftDrawCreate ( DISPLAY( displayId ) ,
+ DRAWABLE( drawableId ) ,
+ DefaultVisual( DISPLAY( displayId), SCREEN (screen) ) ,
+ DefaultColormap( DISPLAY( displayId), SCREEN (screen) ) ) );
+ __STORE(self, __INST(drawId));
+ } else {
+ if ( XftDrawDrawable ( XFT_DRAW ( __INST(drawId) ) ) != DRAWABLE( drawableId ) ) {
+ XftDrawChange( XFT_DRAW( __INST(drawId) ) , DRAWABLE( drawableId ) );
+ }
+ }
+
+
- ].
- self xftDrawString: drawId color: aGC paint font: fontId x: x y: y string: aString from: index1 to: index2
+ if ( __isStringLike( aString ) ) {
+ string = __stringVal( aString ) + ( __intVal(index1) - 1 );
+ len = __intVal(index2) - __intVal(index1) + 1;
+ } else {
+ error = @symbol(BadArg1);
+ goto err;
+ }
+
+ if (clipR != nil) {
+ clipRX.x = __intVal(clipX);
+ clipRX.y = __intVal(clipY);
+ clipRX.width = __intVal(clipW);
+ clipRX.height = __intVal(clipH);
+ XftDrawSetClipRectangles( XFT_DRAW( __INST( drawId ) ) , 0, 0, &clipRX, 1);
+ } else {
+ XftDrawSetClipRectangles( XFT_DRAW( __INST( drawId ) ) , 0, 0, (XRectangle*)NULL, 0);
+ }
+
+ if ( opaque == true ) {
+ color.pixel = (unsigned long)__intVal(bgPixel);
+ color.color.red = __intVal(bgR);
+ color.color.green = __intVal(bgG);
+ color.color.blue = __intVal(bgB);
+ color.color.alpha = __intVal(bgA);
+ XftTextExtents8( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), string, len, &extents);
+ XftDrawRect( XFT_DRAW ( __INST( drawId ) ), &color, __intVal(x) - extents.x, __intVal(y) - XFT_FONT( __INST( fontId ) )->ascent, extents.width, XFT_FONT(__INST (fontId ) )->height);
+ }
+ color.pixel = (unsigned long)__intVal(fgPixel);
+ color.color.red = __intVal(fgR);
+ color.color.green = __intVal(fgG);
+ color.color.blue = __intVal(fgB);
+ color.color.alpha = __intVal(fgA);
+ if ( __isStringLike( aString ) ) {
+ XftDrawString8( XFT_DRAW ( __INST( drawId ) ), &color, XFT_FONT( __INST( fontId ) ),
+ __intVal(x),
+ __intVal(y),
+ (FcChar8*)string,
+ len);
+ RETURN ( self );
+ }
+ err:;
+#endif
+%}.
+ self primitiveFailed: error.
"Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 31-12-2013 / 01:28:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-01-2014 / 01:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!XftFontDescription methodsFor:'error reporting'!
@@ -477,9 +553,11 @@
myself on aWorkstation. This does NOT try to look for existing
or replacement fonts (i.e. can be used to get physical fonts)."
+ "/ Apparently, this is not needed.
self shouldImplement
"Modified: / 02-01-2014 / 23:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 04-01-2014 / 02:06:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!XftFontDescription methodsFor:'initialization'!
@@ -1261,11 +1339,11 @@
!XftFontDescription class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.14 2014-01-03 10:16:08 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.15 2014-01-04 01:06:40 vrany Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.14 2014-01-03 10:16:08 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.15 2014-01-04 01:06:40 vrany Exp $'
! !