summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tkCanvText.c10
-rw-r--r--generic/tkEntry.c12
-rw-r--r--generic/tkFont.c12
-rw-r--r--generic/tkInt.h2
-rw-r--r--generic/tkSelect.c4
-rw-r--r--generic/tkUtil.c30
-rw-r--r--generic/ttk/ttkEntry.c18
-rw-r--r--macosx/tkMacOSXBitmap.c1
-rw-r--r--macosx/tkMacOSXFont.c33
-rw-r--r--macosx/tkMacOSXPrivate.h2
-rw-r--r--unix/tkUnixMenu.c6
-rw-r--r--win/tkWinMenu.c10
12 files changed, 79 insertions, 61 deletions
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index 1e58ce9..9a27efc 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -1025,7 +1025,7 @@ TextInsert(
if (index > textPtr->numChars) {
index = textPtr->numChars;
}
- byteIndex = Tcl_UtfAtIndex(text, index) - text;
+ byteIndex = TkUtfAtIndex(text, index) - text;
byteCount = strlen(string);
if (byteCount == 0) {
return;
@@ -1108,8 +1108,8 @@ TextDeleteChars(
}
charsRemoved = last + 1 - first;
- byteIndex = Tcl_UtfAtIndex(text, first) - text;
- byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
+ byteIndex = TkUtfAtIndex(text, first) - text;
+ byteCount = TkUtfAtIndex(text + byteIndex, charsRemoved)
- (text + byteIndex);
newStr = ckalloc(textPtr->numBytes + 1 - byteCount);
@@ -1497,8 +1497,8 @@ GetSelText(
return 0;
}
text = textPtr->text;
- selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(text, textInfoPtr->selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index 9c53769..fc5ba63 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -2049,7 +2049,7 @@ InsertChars(
char *newStr;
string = entryPtr->string;
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
+ byteIndex = TkUtfAtIndex(string, index) - string;
byteCount = strlen(value);
if (byteCount == 0) {
return TCL_OK;
@@ -2073,6 +2073,8 @@ InsertChars(
entryPtr->string = newStr;
/*
+ * ??? Is this construction still needed with Tcl_NumUtfChars ???
+ *
* The following construction is used because inserting improperly formed
* UTF-8 sequences between other improperly formed UTF-8 sequences could
* result in actually forming valid UTF-8 sequences; the number of
@@ -2153,8 +2155,8 @@ DeleteChars(
}
string = entryPtr->string;
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
- byteCount = Tcl_UtfAtIndex(string + byteIndex, count) - (string+byteIndex);
+ byteIndex = TkUtfAtIndex(string, index) - string;
+ byteCount = TkUtfAtIndex(string + byteIndex, count) - (string+byteIndex);
newByteCount = entryPtr->numBytes + 1 - byteCount;
newStr = ckalloc(newByteCount);
@@ -2815,8 +2817,8 @@ EntryFetchSelection(
return -1;
}
string = entryPtr->displayString;
- selStart = Tcl_UtfAtIndex(string, entryPtr->selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(string, entryPtr->selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
entryPtr->selectLast - entryPtr->selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
diff --git a/generic/tkFont.c b/generic/tkFont.c
index bf35626..53855ac 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -2021,7 +2021,7 @@ Tk_ComputeTextLayout(
curX = 0;
- end = Tcl_UtfAtIndex(string, numChars);
+ end = TkUtfAtIndex(string, numChars);
special = string;
flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
@@ -2325,14 +2325,14 @@ Tk_DrawTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
- firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ firstByte = TkUtfAtIndex(chunkPtr->start, firstChar);
Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
firstByte - chunkPtr->start, -1, 0, &drawX);
}
if (lastChar < numDisplayChars) {
numDisplayChars = lastChar;
}
- lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+ lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont, firstByte,
lastByte - firstByte, x+chunkPtr->x+drawX, y+chunkPtr->y);
}
@@ -2387,14 +2387,14 @@ TkDrawAngledTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
- firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ firstByte = TkUtfAtIndex(chunkPtr->start, firstChar);
Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
firstByte - chunkPtr->start, -1, 0, &drawX);
}
if (lastChar < numDisplayChars) {
numDisplayChars = lastChar;
}
- lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+ lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
dx = cosA * (chunkPtr->x + drawX) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x + drawX) + cosA * (chunkPtr->y);
if (angle == 0.0) {
@@ -2736,7 +2736,7 @@ Tk_CharBbox(
goto check;
}
} else if (index < chunkPtr->numChars) {
- end = Tcl_UtfAtIndex(chunkPtr->start, index);
+ end = TkUtfAtIndex(chunkPtr->start, index);
if (xPtr != NULL) {
Tk_MeasureChars(tkfont, chunkPtr->start,
end - chunkPtr->start, -1, 0, &x);
diff --git a/generic/tkInt.h b/generic/tkInt.h
index c63748a..3a8328f 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1291,10 +1291,12 @@ MODULE_SCOPE void TkUnixSetXftClipRegion(TkRegion clipRegion);
# define TkUtfToUniChar Tcl_UtfToUniChar
# define TkUniCharToUtf Tcl_UniCharToUtf
# define TkUtfPrev Tcl_UtfPrev
+# define TkUtfAtIndex Tcl_UtfAtIndex
#else
MODULE_SCOPE int TkUtfToUniChar(const char *, int *);
MODULE_SCOPE int TkUniCharToUtf(int, char *);
MODULE_SCOPE const char *TkUtfPrev(const char *, const char *);
+ MODULE_SCOPE const char *TkUtfAtIndex(const char *src, int index);
#endif
/*
diff --git a/generic/tkSelect.c b/generic/tkSelect.c
index 5c71465..ef16ff5 100644
--- a/generic/tkSelect.c
+++ b/generic/tkSelect.c
@@ -1400,12 +1400,12 @@ HandleTclCommand(
cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, -1);
cmdInfoPtr->buffer[0] = '\0';
} else {
- Tcl_UniChar ch = 0;
+ int ch;
p = string;
string += count;
numChars = 0;
while (p < string) {
- p += Tcl_UtfToUniChar(p, &ch);
+ p += TkUtfToUniChar(p, &ch);
numChars++;
}
cmdInfoPtr->charOffset += numChars;
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index 805a47c..17ba443 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -1302,6 +1302,36 @@ TkUtfPrev(
return (first + TkUtfToUniChar(first, &ch) >= src) ? first : p ;
}
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TkUtfAtIndex --
+ *
+ * Returns a pointer to the specified character (not byte) position in
+ * a CESU-8 string. This will never point at a low surrogate.
+ *
+ * Results:
+ * As above.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+const char *
+TkUtfAtIndex(
+ const char *src, /* The UTF-8 string. */
+ int index) /* The position of the desired character. */
+{
+ int ch;
+ const char *p = Tcl_UtfAtIndex(src, index);
+ if ((p > src) && (UCHAR(p[-1]) >= 0xF0)) {
+ --p;
+ return p + TkUtfToUniChar(p, &ch);
+ }
+ return p;
+}
#endif
/*
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index 96f3cf2..29f69a1 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -339,8 +339,8 @@ EntryFetchSelection(
}
string = entryPtr->entry.displayString;
- selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst);
- selEnd = Tcl_UtfAtIndex(selStart,
+ selStart = TkUtfAtIndex(string, entryPtr->entry.selectFirst);
+ selEnd = TkUtfAtIndex(selStart,
entryPtr->entry.selectLast - entryPtr->entry.selectFirst);
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
@@ -458,11 +458,11 @@ ExpandPercents(
break;
case 'S': /* string to be inserted/deleted, if any */
if (reason == VALIDATE_INSERT) {
- string = Tcl_UtfAtIndex(new, index);
- stringLength = Tcl_UtfAtIndex(string, count) - string;
+ string = TkUtfAtIndex(new, index);
+ stringLength = TkUtfAtIndex(string, count) - string;
} else if (reason == VALIDATE_DELETE) {
- string = Tcl_UtfAtIndex(entryPtr->entry.string, index);
- stringLength = Tcl_UtfAtIndex(string, count) - string;
+ string = TkUtfAtIndex(entryPtr->entry.string, index);
+ stringLength = TkUtfAtIndex(string, count) - string;
} else {
string = "";
stringLength = 0;
@@ -812,7 +812,7 @@ InsertChars(
const char *value) /* New characters to add */
{
char *string = entryPtr->entry.string;
- size_t byteIndex = Tcl_UtfAtIndex(string, index) - string;
+ size_t byteIndex = TkUtfAtIndex(string, index) - string;
size_t byteCount = strlen(value);
int charsAdded = Tcl_NumUtfChars(value, byteCount);
size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1;
@@ -866,8 +866,8 @@ DeleteChars(
return TCL_OK;
}
- byteIndex = Tcl_UtfAtIndex(string, index) - string;
- byteCount = Tcl_UtfAtIndex(string+byteIndex, count) - (string+byteIndex);
+ byteIndex = TkUtfAtIndex(string, index) - string;
+ byteCount = TkUtfAtIndex(string+byteIndex, count) - (string+byteIndex);
newByteCount = entryPtr->entry.numBytes + 1 - byteCount;
new = ckalloc(newByteCount);
diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c
index 615192b..2b08235 100644
--- a/macosx/tkMacOSXBitmap.c
+++ b/macosx/tkMacOSXBitmap.c
@@ -317,7 +317,6 @@ TkpGetNativeAppBitmap(
OSType iconType;
if (OSTypeFromString(name, &iconType) == TCL_OK) {
NSString *iconUTI = OSTYPE_TO_UTI(iconType);
- printf("Found image for UTI %s\n", iconUTI.UTF8String);
NSImage *iconImage = [[NSWorkspace sharedWorkspace]
iconForFileType: iconUTI];
pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 7fc0113..d704184 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -105,7 +105,7 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
* To avoid an extra copy, a TKNSString object wraps a Tcl_DString with an
* NSString that uses the DString's buffer as its character buffer. It can be
* constructed from a Tcl_DString and it has a DString property that handles
- * converting from an NSString to a Tcl_DString
+ * converting from an NSString to a Tcl_DString.
*/
@implementation TKNSString
@@ -133,7 +133,6 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
_string = [[NSString alloc] initWithString:aString];
self.UTF8String = _string.UTF8String;
}
- printf("Initialized with string %s\n", self.UTF8String);
return self;
}
@@ -166,32 +165,16 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
* The DString has not been initialized. Construct it from
* our string's unicode characters.
*/
-
- char buffer[2*TCL_UTF_MAX];
- unsigned int index, length, ch;
+ char *p;
+ int index;
Tcl_DStringInit(&_ds);
-#if TCL_UTF_MAX == 3
- for (index = 0; index < [_string length]; index++) {
- UniChar uni = [_string characterAtIndex: index];
-
- if (CFStringIsSurrogateHighCharacter(uni)) {
- UniChar low = [_string characterAtIndex: ++index];
- ch = CFStringGetLongCharacterForSurrogatePair(uni, low);
- } else {
- ch = uni;
- }
- length = TkUniCharToUtf(ch, buffer);
- Tcl_DStringAppend(&_ds, buffer, length);
- }
-#else
+ Tcl_DStringSetLength(&_ds, 3 * [_string length]);
+ p = Tcl_DStringValue(&_ds);
for (index = 0; index < [_string length]; index++) {
- ch = (int) [_string characterAtIndex: index];
- length = Tcl_UniCharToUtf(ch, buffer);
- Tcl_DStringAppend(&_ds, buffer, length);
+ p += Tcl_UniCharToUtf([_string characterAtIndex: index], p);
}
-
-#endif
+ Tcl_DStringSetLength(&_ds, p - Tcl_DStringValue(&_ds));
}
return _ds;
}
@@ -1056,7 +1039,7 @@ TkpMeasureCharsInContext(
[attributedString release];
[string release];
length = ceil(width - offset);
- fit = (Tcl_UtfAtIndex(source, index) - source) - rangeStart;
+ fit = (TkUtfAtIndex(source, index) - source) - rangeStart;
done:
#ifdef TK_MAC_DEBUG_FONTS
TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index a0645f7..be69fcd 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -527,7 +527,7 @@ VISIBILITY_HIDDEN
* byte sequence as initial data. So we add a new class which does provide
* such a constructor. It also has a DString property which is a DString whose
* string pointer is a byte sequence encoding the NSString with the current Tk
- * encoding, namely UTF-8 if TCL_MAX >= 4 or CESU-8 if TCL_MAX = 3.
+ * encoding, namely UTF-8 if TCL_UTF_MAX >= 4 or CESU-8 if TCL_UTF_MAX = 3.
*
*---------------------------------------------------------------------------
*/
diff --git a/unix/tkUnixMenu.c b/unix/tkUnixMenu.c
index f7e1860..aa54897 100644
--- a/unix/tkUnixMenu.c
+++ b/unix/tkUnixMenu.c
@@ -859,12 +859,12 @@ DrawMenuUnderline(
len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
- int activeBorderWidth, leftEdge;
+ int activeBorderWidth, leftEdge, ch;
const char *label, *start, *end;
label = Tcl_GetString(mePtr->labelPtr);
- start = Tcl_UtfAtIndex(label, mePtr->underline);
- end = Tcl_UtfNext(start);
+ start = TkUtfAtIndex(label, mePtr->underline);
+ end = start + TkUtfToUniChar(start, &ch);
Tk_GetPixelsFromObj(NULL, menuPtr->tkwin,
menuPtr->activeBorderWidthPtr, &activeBorderWidth);
diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c
index 18ef441..6c55164 100644
--- a/win/tkWinMenu.c
+++ b/win/tkWinMenu.c
@@ -511,6 +511,7 @@ GetEntryText(
: Tcl_GetString(mePtr->accelPtr);
const char *p, *next;
Tcl_DString itemString;
+ int ch;
/*
* We have to construct the string with an ampersand preceeding the
@@ -527,7 +528,7 @@ GetEntryText(
if (*p == '&') {
Tcl_DStringAppend(&itemString, "&", 1);
}
- next = Tcl_UtfNext(p);
+ next = p + TkUtfToUniChar(p, &ch);
Tcl_DStringAppend(&itemString, p, (int) (next - p));
}
if (mePtr->accelLength > 0) {
@@ -536,7 +537,7 @@ GetEntryText(
if (*p == '&') {
Tcl_DStringAppend(&itemString, "&", 1);
}
- next = Tcl_UtfNext(p);
+ next = p + TkUtfToUniChar(p, &ch);
Tcl_DStringAppend(&itemString, p, (int) (next - p));
}
}
@@ -2134,10 +2135,11 @@ DrawMenuUnderline(
len = Tcl_GetCharLength(mePtr->labelPtr);
if (mePtr->underline < len) {
const char *label, *start, *end;
+ int ch;
label = Tcl_GetString(mePtr->labelPtr);
- start = Tcl_UtfAtIndex(label, mePtr->underline);
- end = Tcl_UtfNext(start);
+ start = TkUtfAtIndex(label, mePtr->underline);
+ end = start + TkUtfToUniChar(start, &ch);
Tk_UnderlineChars(menuPtr->display, d,
gc, tkfont, label, x + mePtr->indicatorSpace,
y + (height + fmPtr->ascent - fmPtr->descent) / 2,