Attachment "TkDrawChars.patch" to
ticket [552509ff]
added by
petasis
2002-05-05 19:03:41.
diff -urN tk/unix/tkUnixFont.c tkFixed/unix/tkUnixFont.c
--- tk/unix/tkUnixFont.c Thu Apr 25 07:40:06 2002
+++ tkFixed/unix/tkUnixFont.c Sun May 5 14:22:11 2002
@@ -1177,18 +1177,16 @@
}
end = source + numBytes;
- needWidth = fontPtr->font.fa.underline + fontPtr->font.fa.overstrike;
for (p = source; p < end; ) {
next = p + Tcl_UtfToUniChar(p, &ch);
thisSubFontPtr = FindSubFontForChar(fontPtr, ch);
- if ((thisSubFontPtr != lastSubFontPtr)
- || (p == end-1) || (p-source > 200)) {
- if (p == end-1) {
- p++;
- }
+ /*
+ * Do not draw large string ranges that share the shame encoding at
+ * once. Break this drawing in smaller steps, each one of 200 bytes
+ * long...
+ */
+ if (thisSubFontPtr != lastSubFontPtr || (p-source > 200)) {
if (p > source) {
- int do_width = (needWidth || (p != end-1)) ? 1 : 0;
-
familyPtr = lastSubFontPtr->familyPtr;
Tcl_UtfToExternalDString(familyPtr->encoding, source,
p - source, &runString);
@@ -1196,20 +1194,16 @@
XDrawString16(display, drawable, gc, x, y,
(XChar2b *) Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString) / 2);
- if (do_width) {
- x += XTextWidth16(lastSubFontPtr->fontStructPtr,
- (XChar2b *) Tcl_DStringValue(&runString),
- Tcl_DStringLength(&runString) / 2);
- }
+ x += XTextWidth16(lastSubFontPtr->fontStructPtr,
+ (XChar2b *) Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString) / 2);
} else {
XDrawString(display, drawable, gc, x, y,
Tcl_DStringValue(&runString),
Tcl_DStringLength(&runString));
- if (do_width) {
- x += XTextWidth(lastSubFontPtr->fontStructPtr,
- Tcl_DStringValue(&runString),
- Tcl_DStringLength(&runString));
- }
+ x += XTextWidth(lastSubFontPtr->fontStructPtr,
+ Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString));
}
Tcl_DStringFree(&runString);
}
@@ -1223,6 +1217,43 @@
p = next;
}
+ /*
+ * The following code draws only the last character of the string.
+ * Although it seems tempting to merge this with the loop above that draws
+ * all the rest characters (as was done with patch #541999) it is not
+ * worth the efford as a check has to be done again regarding the font
+ * encoding, as the last character can be in a different encoding than the
+ * previous character...
+ */
+ if (x <= window_width) {
+ needWidth = fontPtr->font.fa.underline + fontPtr->font.fa.overstrike;
+ if (p > source) {
+ familyPtr = lastSubFontPtr->familyPtr;
+ Tcl_UtfToExternalDString(familyPtr->encoding, source, p - source,
+ &runString);
+ if (familyPtr->isTwoByteFont) {
+ XDrawString16(display, drawable, gc, x, y,
+ (XChar2b *) Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString) >> 1);
+ if (needWidth) {
+ x += XTextWidth16(lastSubFontPtr->fontStructPtr,
+ (XChar2b *) Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString) >> 1);
+ }
+ } else {
+ XDrawString(display, drawable, gc, x, y,
+ Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString));
+ if (needWidth) {
+ x += XTextWidth(lastSubFontPtr->fontStructPtr,
+ Tcl_DStringValue(&runString),
+ Tcl_DStringLength(&runString));
+ }
+ }
+ Tcl_DStringFree(&runString);
+ }
+ }
+
if (lastSubFontPtr != &fontPtr->subFontArray[0]) {
XSetFont(display, gc, fontPtr->subFontArray[0].fontStructPtr->fid);
}