From 5f5dec875b76abf0a55e531de9d358ba5b34485f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 19 Jun 2019 14:08:44 +0000 Subject: Use available "ucs2-be" encoding on X11 and "utf-16" encoding on Win32, if provided by Tcl (TIP #547). If Tcl doesn't provide those encodings, proceed as usual. --- unix/tkUnixFont.c | 31 +++++++++---------------------- win/tkWinX.c | 5 ++++- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 96635b4..d00ff82 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -186,14 +186,7 @@ static EncodingAlias encodingAliases[] = { {"tis620", "tis620*"}, {"ksc5601", "ksc5601*"}, {"dingbats", "*dingbats"}, -#ifdef WORDS_BIGENDIAN - {"unicode", "iso10646-1"}, -#else - /* - * ucs-2be is needed if native order isn't BE. - */ {"ucs-2be", "iso10646-1"}, -#endif {NULL, NULL} }; @@ -246,7 +239,6 @@ static unsigned RankAttributes(FontAttributes *wantPtr, static void ReleaseFont(UnixFont *fontPtr); static void ReleaseSubFont(Display *display, SubFont *subFontPtr); static int SeenName(const char *name, Tcl_DString *dsPtr); -#ifndef WORDS_BIGENDIAN static int Ucs2beToUtfProc(ClientData clientData, const char*src, int srcLen, int flags, Tcl_EncodingState*statePtr, char *dst, int dstLen, int *srcReadPtr, @@ -255,7 +247,6 @@ static int UtfToUcs2beProc(ClientData clientData, const char*src, int srcLen, int flags, Tcl_EncodingState*statePtr, char *dst, int dstLen, int *srcReadPtr, int *dstWrotePtr, int *dstCharsPtr); -#endif /* *------------------------------------------------------------------------- @@ -320,9 +311,9 @@ TkpFontPkgInit( { ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); - Tcl_EncodingType type; SubFont dummy; int i; + Tcl_Encoding ucs2; if (tsdPtr->controlFamily.encoding == NULL) { type.encodingName = "X11ControlChars"; @@ -343,20 +334,18 @@ TkpFontPkgInit( FontMapInsert(&dummy, i + 0x80); } -#ifndef WORDS_BIGENDIAN /* * UCS-2BE is unicode (UCS-2) in big-endian format. Define this if - * native order isn't BE. It is used in iso10646 fonts. + * if it doesn't exist yet. It is used in iso10646 fonts. */ - type.encodingName = "ucs-2be"; - type.toUtfProc = Ucs2beToUtfProc; - type.fromUtfProc = UtfToUcs2beProc; - type.freeProc = NULL; - type.clientData = NULL; - type.nullSize = 2; - Tcl_CreateEncoding(&type); -#endif + ucs2 = Tcl_GetEncoding(NULL, "ucs-2be"); + if (ucs2 == NULL) { + Tcl_EncodingType type = {"ucs-2be", Ucs2beToUtfProc, UtfToUcs2beProc, NULL, NULL, 2}; + Tcl_CreateEncoding(&type); + } else { + Tcl_FreeEncoding(ucs2); + } Tcl_CreateThreadExitHandler(FontPkgCleanup, NULL); } } @@ -459,7 +448,6 @@ ControlUtfProc( return result; } -#ifndef WORDS_BIGENDIAN /* *------------------------------------------------------------------------- * @@ -632,7 +620,6 @@ UtfToUcs2beProc( *dstCharsPtr = numChars; return result; } -#endif /* WORDS_BIGENDIAN */ /* *--------------------------------------------------------------------------- diff --git a/win/tkWinX.c b/win/tkWinX.c index 75064b5..e7428e5 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1594,7 +1594,10 @@ Tcl_Encoding TkWinGetUnicodeEncoding(void) { if (unicodeEncoding == NULL) { - unicodeEncoding = Tcl_GetEncoding(NULL, "unicode"); + unicodeEncoding = Tcl_GetEncoding(NULL, "utf-16"); + if (unicodeEncoding == NULL) { + unicodeEncoding = Tcl_GetEncoding(NULL, "unicode"); + } } return unicodeEncoding; } -- cgit v0.12