From 65b0ae26bc6431cbb6fa5ef0ba4e2908b4f274aa Mon Sep 17 00:00:00 2001 From: hobbs Date: Thu, 5 Apr 2001 22:02:20 +0000 Subject: * unix/tkUnixFont.c: Corrected support for iso10646 (X11 Unicode) fonts on Unix. This adds a ucs-2be (UCS-2 Big Endian) encoding in Tk on Unix that is used for those fonts (X11 requires big-endianness). (welch) [Patch #406411; Bug #220890 #220899] Added alias for jisx0201* fonts to jis0201 encoding. [Bug #414033] --- ChangeLog | 16 ++++ unix/tk.spec | 6 +- unix/tkUnixFont.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 234 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f06caf0..aacd2fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2001-04-05 Jeff Hobbs + + * unix/tkUnixFont.c: Corrected support for iso10646 (X11 Unicode) + fonts on Unix. This adds a ucs-2be (UCS-2 Big Endian) encoding in + Tk on Unix that is used for those fonts (X11 requires + big-endianness). (welch) [Patch #406411; Bug #220890 #220899] + Added alias for jisx0201* fonts to jis0201 encoding. [Bug #414033] + + * mac/tkMacProjects.sea.hqx: this was accidently swapped with the + tcl project files. + + * tests/listbox.test: labelled listbox-27.1 knownBug as it isn't + really fixed. + * generic/tkListbox.c: reverted listbox back to 8.3.2 version + because the fixes weren't 100% correct for the problem. + 2001-04-04 Jeff Hobbs ** Start changes for improved mac build (steffen) ** diff --git a/unix/tk.spec b/unix/tk.spec index 23cec99..316ab99 100644 --- a/unix/tk.spec +++ b/unix/tk.spec @@ -1,4 +1,4 @@ -# $Id: tk.spec,v 1.3.2.2 2001/04/04 07:57:18 hobbs Exp $ +# $Id: tk.spec,v 1.3.2.3 2001/04/05 22:02:20 hobbs Exp $ # This file is the basis for a binary Tk Linux RPM. %define version 8.3.3 @@ -11,8 +11,8 @@ Release: 1 Copyright: BSD Group: Development/Languages Source: ftp://ftp.scriptics.com/pub/tcl/tcl8_3/tk%{version}.tar.gz -URL: http://dev.scriptics.com/ -Packager: Scriptics Corporation +URL: http://tcl.activestate.com/ +Packager: ActiveState Tool Corporation Buildroot: /var/tmp/%{name}%{version} Requires: XFree86-libs >= 3.3.3, XFree86-devel >= 3.3.3, tcl = 8.3.3 diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 59826c2..e2a717a 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -9,18 +9,19 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixFont.c,v 1.8 1999/12/21 23:56:34 hobbs Exp $ + * RCS: @(#) $Id: tkUnixFont.c,v 1.8.2.1 2001/04/05 22:02:20 hobbs Exp $ */ #include "tkUnixInt.h" #include "tkFont.h" +#include /* for htons() prototype */ /* * The preferred font encodings. */ static CONST char *encodingList[] = { - "iso8859-1", "jis0208", "jis0212", NULL + "ucs-2be", "iso8859-1", "jis0208", "jis0212", NULL }; /* @@ -180,6 +181,7 @@ static EncodingAlias encodingAliases[] = { {"cns11643-1", "cns11643*.1-0"}, {"cns11643-2", "cns11643*-2"}, {"cns11643-2", "cns11643*.2-0"}, + {"jis0201", "jisx0201*"}, {"jis0201", "jisx0202*"}, {"jis0208", "jisc6226*"}, {"jis0208", "jisx0208*"}, @@ -187,6 +189,7 @@ static EncodingAlias encodingAliases[] = { {"tis620", "tis620*"}, {"ksc5601", "ksc5601*"}, {"dingbats", "*dingbats"}, + {"ucs-2be", "iso10646*"}, {NULL, NULL} }; @@ -243,6 +246,16 @@ static void ReleaseSubFont _ANSI_ARGS_((Display *display, SubFont *subFontPtr)); static int SeenName _ANSI_ARGS_((CONST char *name, Tcl_DString *dsPtr)); +static int Ucs2beToUtfProc _ANSI_ARGS_((ClientData clientData, + CONST char *src, int srcLen, int flags, + Tcl_EncodingState *statePtr, char *dst, int dstLen, + int *srcReadPtr, int *dstWrotePtr, + int *dstCharsPtr)); +static int UtfToUcs2beProc _ANSI_ARGS_((ClientData clientData, + CONST char *src, int srcLen, int flags, + Tcl_EncodingState *statePtr, char *dst, int dstLen, + int *srcReadPtr, int *dstWrotePtr, + int *dstCharsPtr)); /* @@ -274,12 +287,12 @@ TkpFontPkgInit(mainPtr) int i; if (tsdPtr->controlFamily.encoding == NULL) { - type.encodingName = "X11ControlChars"; - type.toUtfProc = ControlUtfProc; - type.fromUtfProc = ControlUtfProc; - type.freeProc = NULL; - type.clientData = NULL; - type.nullSize = 0; + type.encodingName = "X11ControlChars"; + type.toUtfProc = ControlUtfProc; + type.fromUtfProc = ControlUtfProc; + type.freeProc = NULL; + type.clientData = NULL; + type.nullSize = 0; tsdPtr->controlFamily.refCount = 2; tsdPtr->controlFamily.encoding = Tcl_CreateEncoding(&type); @@ -291,6 +304,19 @@ TkpFontPkgInit(mainPtr) FontMapInsert(&dummy, i); FontMapInsert(&dummy, i + 0x80); } + + /* + * UCS2BE is unicode in big-endian format. + * 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); } } @@ -387,6 +413,176 @@ ControlUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen, } /* + *------------------------------------------------------------------------- + * + * Ucs2beToUtfProc -- + * + * Convert from UCS-2BE (big-endian 16-bit Unicode) to UTF-8. + * + * Results: + * Returns TCL_OK if conversion was successful. + * + * Side effects: + * None. + * + *------------------------------------------------------------------------- + */ + +static int +Ucs2beToUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen, + srcReadPtr, dstWrotePtr, dstCharsPtr) + ClientData clientData; /* Not used. */ + CONST char *src; /* Source string in Unicode. */ + int srcLen; /* Source string length in bytes. */ + int flags; /* Conversion control flags. */ + Tcl_EncodingState *statePtr;/* Place for conversion routine to store + * state information used during a piecewise + * conversion. Contents of statePtr are + * initialized and/or reset by conversion + * routine under control of flags argument. */ + char *dst; /* Output buffer in which converted string + * is stored. */ + int dstLen; /* The maximum length of output buffer in + * bytes. */ + int *srcReadPtr; /* Filled with the number of bytes from the + * source string that were converted. This + * may be less than the original source length + * if there was a problem converting some + * source characters. */ + int *dstWrotePtr; /* Filled with the number of bytes that were + * stored in the output buffer as a result of + * the conversion. */ + int *dstCharsPtr; /* Filled with the number of characters that + * correspond to the bytes stored in the + * output buffer. */ +{ + CONST Tcl_UniChar *wSrc, *wSrcStart, *wSrcEnd; + char *dstEnd, *dstStart; + int result, numChars; + + result = TCL_OK; + if ((srcLen % sizeof(Tcl_UniChar)) != 0) { + result = TCL_CONVERT_MULTIBYTE; + srcLen /= sizeof(Tcl_UniChar); + srcLen *= sizeof(Tcl_UniChar); + } + + wSrc = (Tcl_UniChar *) src; + + wSrcStart = (Tcl_UniChar *) src; + wSrcEnd = (Tcl_UniChar *) (src + srcLen); + + dstStart = dst; + dstEnd = dst + dstLen - TCL_UTF_MAX; + + for (numChars = 0; wSrc < wSrcEnd; numChars++) { + if (dst > dstEnd) { + result = TCL_CONVERT_NOSPACE; + break; + } + /* + * On a little-endian machine (Intel) the UCS-2BE is in the + * wrong byte-order in comparison to "unicode", which is + * in native host order. + */ + dst += Tcl_UniCharToUtf(htons(*wSrc), dst); + wSrc++; + } + + *srcReadPtr = (char *) wSrc - (char *) wSrcStart; + *dstWrotePtr = dst - dstStart; + *dstCharsPtr = numChars; + return result; +} + +/* + *------------------------------------------------------------------------- + * + * UtfToUcs2beProc -- + * + * Convert from UTF-8 to UCS-2BE. + * + * Results: + * Returns TCL_OK if conversion was successful. + * + * Side effects: + * None. + * + *------------------------------------------------------------------------- + */ + +static int +UtfToUcs2beProc(clientData, src, srcLen, flags, statePtr, dst, dstLen, + srcReadPtr, dstWrotePtr, dstCharsPtr) + ClientData clientData; /* TableEncodingData that specifies encoding. */ + CONST char *src; /* Source string in UTF-8. */ + int srcLen; /* Source string length in bytes. */ + int flags; /* Conversion control flags. */ + Tcl_EncodingState *statePtr;/* Place for conversion routine to store + * state information used during a piecewise + * conversion. Contents of statePtr are + * initialized and/or reset by conversion + * routine under control of flags argument. */ + char *dst; /* Output buffer in which converted string + * is stored. */ + int dstLen; /* The maximum length of output buffer in + * bytes. */ + int *srcReadPtr; /* Filled with the number of bytes from the + * source string that were converted. This + * may be less than the original source length + * if there was a problem converting some + * source characters. */ + int *dstWrotePtr; /* Filled with the number of bytes that were + * stored in the output buffer as a result of + * the conversion. */ + int *dstCharsPtr; /* Filled with the number of characters that + * correspond to the bytes stored in the + * output buffer. */ +{ + CONST char *srcStart, *srcEnd, *srcClose; + Tcl_UniChar *wDst, *wDstStart, *wDstEnd; + int result, numChars; + + srcStart = src; + srcEnd = src + srcLen; + srcClose = srcEnd; + if ((flags & TCL_ENCODING_END) == 0) { + srcClose -= TCL_UTF_MAX; + } + + wDst = (Tcl_UniChar *) dst; + wDstStart = (Tcl_UniChar *) dst; + wDstEnd = (Tcl_UniChar *) (dst + dstLen - sizeof(Tcl_UniChar)); + + result = TCL_OK; + for (numChars = 0; src < srcEnd; numChars++) { + if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) { + /* + * If there is more string to follow, this will ensure that the + * last UTF-8 character in the source buffer hasn't been cut off. + */ + + result = TCL_CONVERT_MULTIBYTE; + break; + } + if (wDst > wDstEnd) { + result = TCL_CONVERT_NOSPACE; + break; + } + src += Tcl_UtfToUniChar(src, wDst); + /* + * Byte swap for little-endian machines. + */ + *wDst = htons(*wDst); + wDst++; + } + *srcReadPtr = src - srcStart; + *dstWrotePtr = (char *) wDst - (char *) wDstStart; + *dstCharsPtr = numChars; + return result; +} + +/* *--------------------------------------------------------------------------- * * TkpGetNativeFont -- @@ -1460,7 +1656,17 @@ AllocFontFamily(display, fontStructPtr, base) */ familyPtr->refCount = 2; - familyPtr->isTwoByteFont = (fontStructPtr->min_byte1 > 0); + + /* + * One byte/character fonts have both min_byte1 and max_byte1 0, + * and max_char_or_byte2 <= 255. + * Anything else specifies a two byte/character font. + */ + + familyPtr->isTwoByteFont = !( + (fontStructPtr->min_byte1 == 0) && + (fontStructPtr->max_byte1 == 0) && + (fontStructPtr->max_char_or_byte2 < 256)); return familyPtr; } -- cgit v0.12