dont attempt to draw strings with zero size
authorClaus Gittinger <cg@exept.de>
Wed, 28 May 2014 20:06:01 +0200
changeset 6486 4bd177a046f1
parent 6484 5d1889e556a7
child 6487 07daeb3f1bec
dont attempt to draw strings with zero size
WinWorkstation.st
--- a/WinWorkstation.st	Fri May 23 20:50:28 2014 +0200
+++ b/WinWorkstation.st	Wed May 28 20:06:01 2014 +0200
@@ -10598,11 +10598,19 @@
      && __bothSmallInteger(index1, index2)
      && __bothSmallInteger(x, y))
     {
-	struct gcData *gcData = _GCDATA(aGCId);
+	struct gcData *gcData;
 	int pX, pY;
-	HDC hDC = _getDC(gcData);
+	HDC hDC;
 	HFONT hOldFont;
 
+	i1 = __intVal(index1) - 1;
+	i2 = __intVal(index2) - 1;
+	if ((i1 < 0) || (i2 < i1)) {
+	    RETURN (self);
+	}
+
+	gcData = _GCDATA(aGCId);
+	hDC = _getDC(gcData);
 	pX = __intVal(x);
 	pY = __intVal(y);
 	pY -= gcData->fontAscent;
@@ -10632,52 +10640,48 @@
 
 	cls = __qClass(aString);
 
-	i1 = __intVal(index1) - 1;
-	i2 = __intVal(index2) - 1;
-	if (i1 >= 0 && i2 >= i1) {
-	    cp = __stringVal(aString);
-	    l = i2 - i1 + 1;
-	    if (l > 32758) {
-		/* Windows (as in XP) limits the string size for TextOut* to 32758 */
-		l = 32758;
-	    }
-
-	    if (__isStringLike(aString)) {
-		n = __stringSize(aString);
+	cp = __stringVal(aString);
+	l = i2 - i1 + 1;
+	if (l > 32758) {
+	    /* Windows (as in XP) limits the string size for TextOut* to 32758 */
+	    l = 32758;
+	}
+
+	if (__isStringLike(aString)) {
+	    n = __stringSize(aString);
 commonOutChars:
-		if (i2 < n) {
-		    cp += i1;
-		    CPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
-		    if (! TextOutA(hDC, pX, pY, (char *)cp, l)) {
-			PRINTF(("WinWorkstation [warning]: TextOutA failed. [%d]\n", __LINE__));
-			PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d\n", GetLastError(), pX, pY, l));
-			goto error;
-		    }
+	    if (i2 < n) {
+		cp += i1;
+		CPRINTF(("string1: %s pos=%d/%d l=%d hDC=%x\n", cp, pX, pY,l,hDC));
+		if (! TextOutA(hDC, pX, pY, (char *)cp, l)) {
+		    PRINTF(("WinWorkstation [warning]: TextOutA failed. [%d]\n", __LINE__));
+		    PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d\n", GetLastError(), pX, pY, l));
+		    goto error;
+		}
+	    }
+	    goto ret;
+	}
+
+	nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+	cp += nInstBytes;
+	n = __byteArraySize(aString) - nInstBytes;
+
+	if (__isBytes(aString)) {
+	    goto commonOutChars;
+	}
+
+	/* Unicode */
+	if (__isWords(aString)) {
+	    n = n / 2;
+	    if (i2 < n) {
+		WIDECHAR *w_cp = (WIDECHAR *)cp;
+		w_cp += i1;
+		if (! TextOutW(hDC, pX, pY, w_cp, l)) {
+		    PRINTF(("WinWorkstation [warning]: TextOutW failed. [%d]\n", __LINE__));
+		    PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d\n", GetLastError(), pX, pY, l));
 		}
 		goto ret;
 	    }
-
-	    nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    cp += nInstBytes;
-	    n = __byteArraySize(aString) - nInstBytes;
-
-	    if (__isBytes(aString)) {
-		goto commonOutChars;
-	    }
-
-	    /* Unicode */
-	    if (__isWords(aString)) {
-		n = n / 2;
-		if (i2 < n) {
-		    WIDECHAR *w_cp = (WIDECHAR *)cp;
-		    w_cp += i1;
-		    if (! TextOutW(hDC, pX, pY, w_cp, l)) {
-			PRINTF(("WinWorkstation [warning]: TextOutW failed. [%d]\n", __LINE__));
-			PRINTF(("WinWorkstation [warning]: lastError=%d x:%d y:%d len:%d\n", GetLastError(), pX, pY, l));
-		    }
-		    goto ret;
-		}
-	    }
 	}
 ret:;
 #if 0
@@ -19335,11 +19339,11 @@
 !WinWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.482 2014-04-03 21:21:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.483 2014-05-28 18:06:01 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.482 2014-04-03 21:21:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.483 2014-05-28 18:06:01 cg Exp $'
 ! !