#TUNING by stefan
authorStefan Vogel <sv@exept.de>
Tue, 13 Sep 2016 15:06:59 +0200
changeset 7563 3555a447b0aa
parent 7562 217cc7ec5656
child 7564 5330f64092a5
#TUNING by stefan class: XftFontDescription added: #xftTextExtents:string:from:to:into: removed: #xftTextExtents:font:string:from:to: changed: #widthOf:from:to:
XftFontDescription.st
--- a/XftFontDescription.st	Tue Sep 13 14:44:08 2016 +0200
+++ b/XftFontDescription.st	Tue Sep 13 15:06:59 2016 +0200
@@ -1177,65 +1177,84 @@
     "Created: / 21-12-2013 / 00:55:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-xftTextExtents: displayIdArg font: fontIdArg string: text from: start to: stop
-    | error extents bitsPerCharacter |
-
-    extents :=  Array new: 6.
-    bitsPerCharacter := text bitsPerCharacter.
+xftTextExtents:displayIdArg string:aString from:start to:stop into:extentsArrayOrNil
+    "get the extents of aString.
+     Answer thr width of aString (in reality the xOff).
+     If extentArrayOrNil is an Array, fill is with the extent info:
+        #(width height x y xOff yOff)."
+
+    |error bytesPerCharacter|
+
+    bytesPerCharacter := aString bytesPerCharacter.
 
 %{ /* STACK: 64000 */
 #ifdef XFT
     XGlyphInfo info;
     char *string;
     int len;
-    int bytesPerCharacter = __intVal(bitsPerCharacter) / 8;
+    int __bytesPerCharacter = __intVal(bytesPerCharacter);
 
     if ( ! __isExternalAddressLike(displayIdArg) ) {
-	error = @symbol(BadArg1);
-	goto err;
-    }
-    if ( ! __isExternalAddressLike(fontIdArg) ) {
-	error = @symbol(BadArg2);
-	goto err;
+        error = @symbol(BadArg1);
+        goto err;
     }
     if ( ! __isSmallInteger(start) ) {
-	error = @symbol(BadArg4);
-	goto err;
+        error = @symbol(BadArg3);
+        goto err;
     }
     if ( ! __isSmallInteger(stop) ) {
-	error = @symbol(BadArg5);
-	goto err;
+        error = @symbol(BadArg4);
+        goto err;
     }
-
-    string = __stringVal( text ) + (( __intVal(start) - 1 ) * bytesPerCharacter);
+    if ( ! __isExternalAddressLike(__INST(fontId)) ) {
+        error = @symbol(BadFontId);
+        goto err;
+    }
+
+    string = __stringVal(aString) + ((__intVal(start) - 1) * __bytesPerCharacter);
     len = __intVal(stop) - __intVal(start) + 1;
 
-    switch (bytesPerCharacter) {
+    switch (__bytesPerCharacter) {
     case 1:
-	XftTextExtents8(DISPLAY(displayIdArg), XFT_FONT(fontIdArg), (FcChar8*)string, len, &info);
-	break;
+        XftTextExtents8(DISPLAY(displayIdArg), XFT_FONT(__INST(fontId)), (FcChar8*)string, len, &info);
+        break;
     case 2:
-	XftTextExtents16(DISPLAY(displayIdArg), XFT_FONT(fontIdArg), (FcChar16*)string, len, &info);
-	break;
+        XftTextExtents16(DISPLAY(displayIdArg), XFT_FONT(__INST(fontId)), (FcChar16*)string, len, &info);
+        break;
     case 4:
-	XftTextExtents32(DISPLAY(displayIdArg), XFT_FONT(fontIdArg), (FcChar32*)string, len, &info);
-	break;
+        XftTextExtents32(DISPLAY(displayIdArg), XFT_FONT(__INST(fontId)), (FcChar32*)string, len, &info);
+        break;
+    default:
+        error = @symbol(BadArg2);
+        goto err;
     }
-    __ArrayInstPtr(extents)->a_element[0] = __MKSMALLINT(info.width);
-    __ArrayInstPtr(extents)->a_element[1] = __MKSMALLINT(info.height);
-    __ArrayInstPtr(extents)->a_element[2] = __MKSMALLINT(info.x);
-    __ArrayInstPtr(extents)->a_element[3] = __MKSMALLINT(info.y);
-    __ArrayInstPtr(extents)->a_element[4] = __MKSMALLINT(info.xOff);
-    __ArrayInstPtr(extents)->a_element[5] = __MKSMALLINT(info.yOff);
-    error = nil;
+
+    if (extentsArrayOrNil != nil && __isArray(extentsArrayOrNil)) {
+        switch (__arraySize(extentsArrayOrNil)) {
+        case 6:
+            __arrayVal(extentsArrayOrNil)[5] = __MKSMALLINT(info.yOff);
+        case 5:
+            __arrayVal(extentsArrayOrNil)[4] = __MKSMALLINT(info.xOff);
+        case 4:
+            __arrayVal(extentsArrayOrNil)[3] = __MKSMALLINT(info.y);
+        case 3:
+            __arrayVal(extentsArrayOrNil)[2] = __MKSMALLINT(info.x);
+        case 2:
+            __arrayVal(extentsArrayOrNil)[1] = __MKSMALLINT(info.height);
+        case 1:
+            __arrayVal(extentsArrayOrNil)[0] = __MKSMALLINT(info.width);
+        }
+    }
+
+    RETURN(__MKSMALLINT(info.xOff));
+
     err:;
 #endif
 %}.
     error notNil ifTrue:[
-	self primitiveFailed: error.
-	^ nil.
+        self primitiveFailed: error.
+        ^ nil.
     ].
-    ^ extents
 
     "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 30-12-2013 / 20:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1412,16 +1431,11 @@
 widthOf:aString from:start to:stop
     "return the width of a sub string"
 
-    | extents |
-
     (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 ?!!
-    ^ extents fifth.
+    ^ self xftTextExtents:device displayId string:aString from:start to:stop into:nil.
 
     "Created: / 21-12-2013 / 10:42:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 29-12-2013 / 21:16:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"