summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tkEntry.c8
-rw-r--r--generic/tkFont.c6
-rw-r--r--generic/tkInt.h6
-rw-r--r--generic/tkText.c6
-rw-r--r--generic/tkTextDisp.c2
-rw-r--r--generic/tkTextIndex.c4
-rw-r--r--generic/tkUtil.c37
-rw-r--r--generic/ttk/ttkEntry.c14
8 files changed, 59 insertions, 24 deletions
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index a66cf18..34f11d2 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -1926,8 +1926,8 @@ EntryComputeGeometry(
*/
if (entryPtr->showChar != NULL) {
- Tcl_UniChar ch;
- char buf[4];
+ int ch;
+ char buf[6];
int size;
/*
@@ -1937,8 +1937,8 @@ EntryComputeGeometry(
* resulting string.
*/
- Tcl_UtfToUniChar(entryPtr->showChar, &ch);
- size = Tcl_UniCharToUtf(ch, buf);
+ TkUtfToUniChar(entryPtr->showChar, &ch);
+ size = TkUniCharToUtf(ch, buf);
entryPtr->numDisplayBytes = entryPtr->numChars * size;
p = ckalloc(entryPtr->numDisplayBytes + 1);
diff --git a/generic/tkFont.c b/generic/tkFont.c
index 4a45691..1947666 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -563,7 +563,7 @@ Tk_FontObjCmd(
if (charPtr != NULL) {
const char *string = Tcl_GetString(charPtr);
- int len = TkUtfToUniChar2(string, &uniChar);
+ int len = TkUtfToUniChar(string, &uniChar);
if (len != charPtr->length) {
resultPtr = Tcl_NewStringObj(
@@ -1714,7 +1714,7 @@ Tk_PostscriptFontName(
src++;
upper = 1;
}
- src += TkUtfToUniChar2(src, &ch);
+ src += TkUtfToUniChar(src, &ch);
if (upper) {
ch = (Tcl_UniChar) Tcl_UniCharToUpper(ch);
upper = 0;
@@ -3274,7 +3274,7 @@ Tk_TextLayoutToPostscript(
* international postscript fonts.
*/
- p += TkUtfToUniChar2(p, &ch);
+ p += TkUtfToUniChar(p, &ch);
if ((ch == '(') || (ch == ')') || (ch == '\\') || (ch < 0x20)) {
/*
* Tricky point: the "03" is necessary in the sprintf below,
diff --git a/generic/tkInt.h b/generic/tkInt.h
index 6d86e08..1615a81 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -1233,9 +1233,11 @@ MODULE_SCOPE void TkUnixSetXftClipRegion(TkRegion clipRegion);
#endif
#if TCL_UTF_MAX > 4
-# define TkUtfToUniChar2 Tcl_UtfToUniChar
+# define TkUtfToUniChar Tcl_UtfToUniChar
+# define TkUniCharToUtf Tcl_UniCharToUtf
#else
- MODULE_SCOPE int TkUtfToUniChar2(const char *src, int *chPtr);
+ MODULE_SCOPE int TkUtfToUniChar(const char *, int *);
+ MODULE_SCOPE int TkUniCharToUtf(int, char *);
#endif
/*
diff --git a/generic/tkText.c b/generic/tkText.c
index dacadbe..8ae17a5 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -4615,7 +4615,7 @@ TkTextGetTabs(
* There may be a more efficient way of getting this.
*/
- TkUtfToUniChar2(Tcl_GetString(objv[i+1]), &ch);
+ TkUtfToUniChar(Tcl_GetString(objv[i+1]), &ch);
if (!Tcl_UniCharIsAlpha(ch)) {
continue;
}
@@ -5966,7 +5966,7 @@ SearchCore(
CLANG_ASSERT(pattern);
do {
- Tcl_UniChar ch;
+ int ch;
const char *p;
int lastFullLine = lastOffset;
@@ -6196,7 +6196,7 @@ SearchCore(
}
} else {
firstOffset = p - startOfLine +
- Tcl_UtfToUniChar(startOfLine+matchOffset,&ch);
+ TkUtfToUniChar(startOfLine+matchOffset,&ch);
}
}
} while (searchSpecPtr->all);
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 026023e..eb917cf 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -7582,7 +7582,7 @@ TkTextCharLayoutProc(
if (bytesThatFit < maxBytes) {
if ((bytesThatFit == 0) && noCharsYet) {
int ch;
- int chLen = TkUtfToUniChar2(p, &ch);
+ int chLen = TkUtfToUniChar(p, &ch);
#if TK_LAYOUT_WITH_BASE_CHUNKS
bytesThatFit = CharChunkMeasureChars(chunkPtr, line,
diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c
index b794cdb..7aebc84 100644
--- a/generic/tkTextIndex.c
+++ b/generic/tkTextIndex.c
@@ -2300,7 +2300,7 @@ StartEnd(
if (segPtr->typePtr == &tkTextCharType) {
int ch;
- chSize = TkUtfToUniChar2(segPtr->body.chars + offset, &ch);
+ chSize = TkUtfToUniChar(segPtr->body.chars + offset, &ch);
if (!Tcl_UniCharIsWordChar(ch)) {
break;
}
@@ -2345,7 +2345,7 @@ StartEnd(
if (segPtr->typePtr == &tkTextCharType) {
int ch;
- TkUtfToUniChar2(segPtr->body.chars + offset, &ch);
+ TkUtfToUniChar(segPtr->body.chars + offset, &ch);
if (!Tcl_UniCharIsWordChar(ch)) {
break;
}
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index a266cb3..19b343e 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -1197,7 +1197,7 @@ TkSendVirtualEvent(
/*
*---------------------------------------------------------------------------
*
- * TkUtfToUniChar2 --
+ * TkUtfToUniChar --
*
* Almost the same as Tcl_UtfToUniChar but using int instead of Tcl_UniChar.
* This function is capable of collapsing a upper/lower pair to a single
@@ -1214,7 +1214,7 @@ TkSendVirtualEvent(
*/
int
-TkUtfToUniChar2(
+TkUtfToUniChar(
const char *src, /* The UTF-8 string. */
int *chPtr) /* Filled with the Tcl_UniChar represented by
* the UTF-8 string. */
@@ -1238,6 +1238,39 @@ TkUtfToUniChar2(
}
return len;
}
+
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TkUniCharToUtf --
+ *
+ * Almost the same as Tcl_UniCharToUtf but producing surrogates if
+ * TCL_UTF_MAX==3.
+ *
+ * Results:
+ * *buf is filled with the UTF-8 string, and the return value is the
+ * number of bytes produced.
+ *
+ * Side effects:
+ * None.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+int TkUniCharToUtf(int ch, char *buf)
+{
+ int size = Tcl_UniCharToUtf(ch, buf);
+ if ((ch > 0xffff) && (size < 4)) {
+ /* Hey, this is wrong, we must be running TCL_UTF_MAX==3
+ * The best thing we can do is spit out 2 surrogates */
+ ch -= 0x10000;
+ size = Tcl_UniCharToUtf(((ch >> 10) | 0xd800), buf);
+ size += Tcl_UniCharToUtf(((ch & 0x3ff) | 0xdc00), buf+size);
+ }
+ return size;
+}
+
+
#endif
/*
* Local Variables:
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index d80e1fd..a25574a 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -282,11 +282,11 @@ static char *EntryDisplayString(const char *showChar, int numChars)
{
char *displayString, *p;
int size;
- Tcl_UniChar ch;
- char buf[4];
+ int ch;
+ char buf[6];
- Tcl_UtfToUniChar(showChar, &ch);
- size = Tcl_UniCharToUtf(ch, buf);
+ TkUtfToUniChar(showChar, &ch);
+ size = TkUniCharToUtf(ch, buf);
p = displayString = ckalloc(numChars * size + 1);
while (numChars--) {
@@ -406,7 +406,7 @@ ExpandPercents(
int number, length;
const char *string;
int stringLength;
- Tcl_UniChar ch;
+ int ch;
char numStorage[2*TCL_INTEGER_SPACE];
while (*template) {
@@ -430,7 +430,7 @@ ExpandPercents(
*/
++template; /* skip over % */
if (*template != '\0') {
- template += Tcl_UtfToUniChar(template, &ch);
+ template += TkUtfToUniChar(template, &ch);
} else {
ch = '%';
}
@@ -480,7 +480,7 @@ ExpandPercents(
string = Tk_PathName(entryPtr->core.tkwin);
break;
default:
- length = Tcl_UniCharToUtf(ch, numStorage);
+ length = TkUniCharToUtf(ch, numStorage);
numStorage[length] = '\0';
string = numStorage;
break;