XftFontDescription.st
changeset 7416 bd3b9e9edd9e
parent 7342 bb5f94f9aae9
child 7443 e2d05b756727
--- a/XftFontDescription.st	Sat Jul 16 18:24:24 2016 +0200
+++ b/XftFontDescription.st	Tue Jul 19 21:44:36 2016 +0200
@@ -1,3 +1,5 @@
+'From Smalltalk/X, Version:7.1.0.0 on 18-07-2016 at 18:55:24'                   !
+
 "{ Package: 'stx:libview' }"
 
 "{ NameSpace: Smalltalk }"
@@ -89,8 +91,6 @@
 	    handle;                                  \
 	})
 
-
-
 # define DISPLAY(x)    __HANDLE_VAL(Display*, x)
 # define SCREEN(x)     ((int)(__intVal(x)))
 # define DRAWABLE(x)   __HANDLE_VAL(Drawable, x)
@@ -470,6 +470,10 @@
 
 !XftFontDescription methodsFor:'accessing'!
 
+encoding
+    ^ encoding ? #'iso10646-1'
+!
+
 face
     ^ face ? ''
 !
@@ -616,37 +620,45 @@
     "display a partial string at some position in aGC."
 
     |index2 bytesPerCharacter transformation
-     clipOrg clipCorn clipRect clipX clipY clipW clipH clipPnt
+     clipRect clipX clipY clipW clipH
      fg fgR fgG fgB fgA fgPixel bg bgR bgG bgB bgA bgPixel
-     drawX drawY drawPnt displayId screen drawableId error stringLen
-     newXftDrawId newDrawableAssociation pixmapDepth|
+     drawX drawY displayId screen drawableId error stringLen
+     newXftDrawId pixmapDepth|
 
     "limit the string len, otherwise bad output is generated"
     stringLen := index2Arg - index1 + 1.
     stringLen > 1000 "8000" ifTrue:[
-	index2 := index1 + 1000 "8000" - 1.
+        index2 := index1 + 1000 "8000" - 1.
     ]  ifFalse:[
-	stringLen <= 0 ifTrue:[^ self].
-	index2 := index2Arg.
+        stringLen <= 0 ifTrue:[^ self].
+        index2 := index2Arg.
     ].
     bytesPerCharacter := aString bitsPerCharacter // 8.
 
-    clipRect := aGC deviceClippingRectangle.
+    transformation := aGC transformation.
+
+    clipRect := aGC deviceClippingBoundsOrNil.
     clipRect notNil ifTrue:[
-	clipX := clipRect left.
-	clipY := clipRect top.
-	clipW := clipRect width.
-	clipH := clipRect height.
+        clipX := clipRect left.
+        clipY := clipRect top.
+        clipW := clipRect width.
+        clipH := clipRect height.
+"/clipW > 32767 ifTrue:['clipW > 32767: ' errorPrint. clipW errorPrintCR. clipW := 32767].
+"/(clipX > 16384 or:[clipX < -16384]) ifTrue:['clipX > 16384: ' errorPrint. clipX errorPrintCR.].
+        "/ YES YES YES: this MUST be transformed!!
+        "/ (see htmlView) fix the notebook, please.
+"/        transformation notNil ifTrue:[
+"/            clipX := (transformation applyToX:clipX) ceiling.
+"/            clipY := (transformation applyToY:clipY) ceiling.
+"/        ].
     ].
 
-    transformation := aGC transformation.
     transformation isNil ifTrue:[
-	drawX := xArg.
-	drawY := yArg.
+        drawX := xArg.
+        drawY := yArg.
     ] ifFalse:[
-	drawPnt := transformation transformPoint:(xArg @ yArg).
-	drawX := drawPnt x ceiling.
-	drawY := drawPnt y ceiling.
+        drawX := (transformation applyToX:xArg) ceiling.
+        drawY := (transformation applyToY:yArg) ceiling.
     ].
 
     fg  := aGC paint.
@@ -656,45 +668,45 @@
     fgA := fg scaledAlpha.
 
     fgR isNil ifTrue:[
-	"/ when drawing into a pixmap...
-	fgPixel := fg colorId.
-	fgPixel == 0 ifTrue:[
-	    fgR := fgG := fgB := 0.
-	] ifFalse:[
-	    fgR := fgG := fgB := 16rFFFF.
-	]
+        "/ when drawing into a pixmap...
+        fgPixel := fg colorId.
+        fgPixel == 0 ifTrue:[
+            fgR := fgG := fgB := 0.
+        ] ifFalse:[
+            fgR := fgG := fgB := 16rFFFF.
+        ]
     ].
 
     opaque ifTrue:[
-	bg := aGC backgroundPaint.
-	bg isColor ifTrue:[
-	    bgR := bg scaledRed.
-	    bgG := bg scaledGreen.
-	    bgB := bg scaledBlue.
-	    bgA := bg scaledAlpha.
-	] ifFalse:[
-	    "images are not yet implemented"
-	    "/ #todo: fill background rectangle
-	    bgR := bgG := bgB := bgA := 16rFFFF.
-	].
-	bgR isNil ifTrue:[
-	    "/ when drawing into a pixmap...
-	    bgPixel := bg colorId.
-	    bgPixel == 0 ifTrue:[
-		bgR := bgG := bgB := 0.
-	    ] ifFalse:[
-		bgR := bgG := bgB := 16rFFFF.
-	    ]
-	].
+        bg := aGC backgroundPaint.
+        bg isColor ifTrue:[
+            bgR := bg scaledRed.
+            bgG := bg scaledGreen.
+            bgB := bg scaledBlue.
+            bgA := bg scaledAlpha.
+        ] ifFalse:[
+            "images are not yet implemented"
+            "/ #todo: fill background rectangle
+            bgR := bgG := bgB := bgA := 16rFFFF.
+        ].
+        bgR isNil ifTrue:[
+            "/ when drawing into a pixmap...
+            bgPixel := bg colorId.
+            bgPixel == 0 ifTrue:[
+                bgR := bgG := bgB := 0.
+            ] ifFalse:[
+                bgR := bgG := bgB := 16rFFFF.
+            ]
+        ].
     ].
     displayId := device displayIdOrErrorIfBroken.
     displayId isNil ifTrue:[
-	^ self.
+        ^ self.
     ].
     screen := device screen.
     drawableId := aGC drawableId.
-    aGC isForm ifTrue:[
-	pixmapDepth := aGC depth.
+    aGC isPixmap ifTrue:[
+        pixmapDepth := aGC depth.
     ].
 
 %{ /* STACK: 64000 */
@@ -709,76 +721,78 @@
     XftFont *__xftFont = XFT_FONT(__INST(fontId));
 
     if (!(__bothSmallInteger(drawX, drawY)
-	  && __bothSmallInteger(index1, index2)
-	  && __isSmallInteger(bytesPerCharacter)
-	  && (__isSmallInteger(fgPixel) || (__bothSmallInteger(fgR, fgG) && __bothSmallInteger(fgB, fgA)))
-	  && (opaque == false || __isSmallInteger(bgPixel) || (__bothSmallInteger(bgR, bgG) && __bothSmallInteger(bgB, bgA)))
-	  && __isNonNilObject(aString)
+          && __bothSmallInteger(index1, index2)
+          && __isSmallInteger(bytesPerCharacter)
+          && (__isSmallInteger(fgPixel) || (__bothSmallInteger(fgR, fgG) && __bothSmallInteger(fgB, fgA)))
+          && (opaque == false || __isSmallInteger(bgPixel) || (__bothSmallInteger(bgR, bgG) && __bothSmallInteger(bgB, bgA)))
+          && __isNonNilObject(aString)
     )) {
-	error = @symbol(badArgument);
-	goto out;
+        error = @symbol(badArgument);
+        goto out;
     }
 
     __bytesPerCharacter = __intVal(bytesPerCharacter);
 
     if (pixmapDepth != nil) {
-	int __pixmapDepth = __intVal(pixmapDepth);
+        int __pixmapDepth = __intVal(pixmapDepth);
 
-	if (__pixmapDepth == 1) {
-	    __sharedDrawId = XftDrawCreateBitmap(DISPLAY(displayId), DRAWABLE(drawableId));
-	} else {
-	    __sharedDrawId = XftDrawCreateAlpha(DISPLAY(displayId), DRAWABLE(drawableId), __pixmapDepth);
-	}
+        if (__pixmapDepth == 1) {
+            __sharedDrawId = XftDrawCreateBitmap(DISPLAY(displayId), DRAWABLE(drawableId));
+        } else {
+            __sharedDrawId = XftDrawCreateAlpha(DISPLAY(displayId), DRAWABLE(drawableId), __pixmapDepth);
+        }
     } else {
-	if (__INST(sharedDrawId) == nil) {
-	    __sharedDrawId = XftDrawCreate(DISPLAY(displayId),
-					   DRAWABLE(drawableId),
-					   DefaultVisual(DISPLAY(displayId), SCREEN(screen)),
-					   DefaultColormap(DISPLAY(displayId), SCREEN(screen)));
-	    __INST(sharedDrawId) = newXftDrawId = XFT_DRAW_HANDLE_NEW(__sharedDrawId);
-	    __STORE(self, __INST(sharedDrawId));
-	} else if (XftDrawDrawable(__sharedDrawId = XFT_DRAW(__INST(sharedDrawId))) != DRAWABLE(drawableId)) {
-	    XftDrawChange(__sharedDrawId, DRAWABLE(drawableId));
-	}
+        if (__INST(sharedDrawId) == nil) {
+            __sharedDrawId = XftDrawCreate(DISPLAY(displayId),
+                                           DRAWABLE(drawableId),
+                                           DefaultVisual(DISPLAY(displayId), SCREEN(screen)),
+                                           DefaultColormap(DISPLAY(displayId), SCREEN(screen)));
+            __INST(sharedDrawId) = newXftDrawId = XFT_DRAW_HANDLE_NEW(__sharedDrawId);
+            __STORE(self, newXftDrawId);
+        } else if (XftDrawDrawable(__sharedDrawId = XFT_DRAW(__INST(sharedDrawId))) != DRAWABLE(drawableId)) {
+            XftDrawChange(__sharedDrawId, DRAWABLE(drawableId));
+        }
     }
 
     string = __stringVal(aString) + ((__intVal(index1) - 1 ) * __bytesPerCharacter);
     len = __intVal(index2) - __intVal(index1) + 1;
 
-    if (clipRect != nil) {
-	clipRX.x = __intVal(clipX);
-	clipRX.y = __intVal(clipY);
-	clipRX.width = __intVal(clipW);
-	clipRX.height = __intVal(clipH);
-	XftDrawSetClipRectangles(__sharedDrawId, 0, 0, &clipRX, 1);
+    if (clipX != nil) {
+        clipRX.x = __intVal(clipX);
+        clipRX.y = __intVal(clipY);
+        clipRX.width = __intVal(clipW);
+        clipRX.height = __intVal(clipH);
+        XftDrawSetClipRectangles(__sharedDrawId, 0, 0, &clipRX, 1);
     } else {
-	XftDrawSetClip(__sharedDrawId, 0);
+        XftDrawSetClip(__sharedDrawId, 0);
     }
 
     if (opaque == true) {
-	if (bgPixel != nil) {
-	    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);
+        if (bgPixel != nil) {
+            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);
 
-	switch (__bytesPerCharacter) {
-	case 1:
-	    XftTextExtents8(DISPLAY(displayId), __xftFont, (FcChar8*)string, len, &extents);
-	    break;
-	case 2:
-	    XftTextExtents16(DISPLAY(displayId), __xftFont, (FcChar16*)string, len, &extents);
-	    break;
-	case 4:
-	    XftTextExtents32(DISPLAY(displayId), __xftFont, (FcChar32*)string, len, &extents);
-	    break;
-	}
-	XftDrawRect(__sharedDrawId, &color, __intVal(drawX) - extents.x, __intVal(drawY) - __xftFont->ascent, extents.width, __xftFont->height);
+        switch (__bytesPerCharacter) {
+        case 1:
+            XftTextExtents8(DISPLAY(displayId), __xftFont, (FcChar8*)string, len, &extents);
+            break;
+        case 2:
+            XftTextExtents16(DISPLAY(displayId), __xftFont, (FcChar16*)string, len, &extents);
+            break;
+        case 4:
+            XftTextExtents32(DISPLAY(displayId), __xftFont, (FcChar32*)string, len, &extents);
+            break;
+        }
+if (extents.width < 0) printf("width: %d  < 0\n", extents.width);
+
+        XftDrawRect(__sharedDrawId, &color, __intVal(drawX) - extents.x, __intVal(drawY) - __xftFont->ascent, extents.width, __xftFont->height);
     }
     if (fgPixel != nil) {
-	color.pixel = (unsigned long)__intVal(fgPixel);
+        color.pixel = (unsigned long)__intVal(fgPixel);
     }
     color.color.red = __intVal(fgR);
     color.color.green = __intVal(fgG);
@@ -787,36 +801,36 @@
 
     switch (__bytesPerCharacter) {
     case 1:
-	XftDrawString8(__sharedDrawId, &color,__xftFont,
-			__intVal(drawX),
-			__intVal(drawY),
-			(FcChar8*)string,
-			len);
-	break;
+        XftDrawString8(__sharedDrawId, &color,__xftFont,
+                        __intVal(drawX),
+                        __intVal(drawY),
+                        (FcChar8*)string,
+                        len);
+        break;
 
     case 2:
-	XftDrawString16(__sharedDrawId, &color, __xftFont,
-			__intVal(drawX),
-			__intVal(drawY),
-			(FcChar16*)string,
-			len);
-	break;
+        XftDrawString16(__sharedDrawId, &color, __xftFont,
+                        __intVal(drawX),
+                        __intVal(drawY),
+                        (FcChar16*)string,
+                        len);
+        break;
 
     case 4:
-	XftDrawString32(__sharedDrawId, &color, __xftFont,
-			__intVal(drawX),
-			__intVal(drawY),
-			(FcChar32*)string,
-			len);
-	break;
+        XftDrawString32(__sharedDrawId, &color, __xftFont,
+                        __intVal(drawX),
+                        __intVal(drawY),
+                        (FcChar32*)string,
+                        len);
+        break;
 
     default:
-	error = @symbol(invalidStringSize);
-	goto out;
+        error = @symbol(invalidStringSize);
+        goto out;
     }
 
     if (pixmapDepth != nil) {
-	XftDrawDestroy(__sharedDrawId);
+        XftDrawDestroy(__sharedDrawId);
     }
 
 # if 0 // this has been superseeded by receiving change messages on view destroy
@@ -828,10 +842,10 @@
 #endif
 %}.
     error notNil ifTrue:[
-	self primitiveFailed: error.
+        self primitiveFailed: error.
     ].
     newXftDrawId notNil ifTrue:[
-	Lobby register:self.
+        Lobby register:self.
     ].
     "Created: / 21-12-2013 / 21:11:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 10-01-2014 / 11:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1324,8 +1338,8 @@
      That is a number of units (usually pixels)."
 
     (fixedWidth class == SmallInteger) ifTrue:[
-        ^ fixedWidth
-    ].    
+	^ fixedWidth
+    ].
     ^ self xftFontGetMaxAdvanceWidth: fontId
 
     "Created: / 30-12-2013 / 20:02:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1362,8 +1376,8 @@
      The receiver must be associated to a device, for this query to be legal."
 
     fixedWidth class == SmallInteger ifTrue:[
-        ^ fixedWidth
-    ].    
+	^ fixedWidth
+    ].
     ^ self widthOf:' '
 
     "Modified: 30.4.1996 / 16:43:45 / cg"
@@ -1376,8 +1390,8 @@
 
     (stop < start) ifTrue:[^ 0].
     (fixedWidth class == SmallInteger) ifTrue:[
-        ^ fixedWidth * (stop - start + 1) 
-    ].    
+	^ fixedWidth * (stop - start + 1)
+    ].
     extents := self xftTextExtents: device displayId font: fontId string: aString from: start to: stop.
     "/ extents --> #(width height x y xOff yOff)
     "/ cg: shouln't this be first ?!!
@@ -1441,6 +1455,12 @@
 
 !XftFontDescription methodsFor:'testing'!
 
+isAlienFont
+    "my GraphicsContext knows how to disply strings in my font"
+
+    ^ false
+!
+
 isUsed
     ^ sharedDrawId notNil
 !