Import Tk 8.6.10

This commit is contained in:
Steve Dower
2020-09-24 22:55:34 +01:00
parent 5ba5cbc9af
commit 42c69189d9
365 changed files with 24323 additions and 12832 deletions

View File

@@ -37,8 +37,8 @@ static const char *const encodingList[] = {
#define FONTMAP_SHIFT 10
#define FONTMAP_PAGES (1 << (sizeof(Tcl_UniChar)*8 - FONTMAP_SHIFT))
#define FONTMAP_BITSPERPAGE (1 << FONTMAP_SHIFT)
#define FONTMAP_PAGES (0x30000 / FONTMAP_BITSPERPAGE)
typedef struct FontFamily {
struct FontFamily *nextPtr; /* Next in list of all known font families. */
@@ -153,7 +153,7 @@ typedef struct FontAttributes {
TkXLFDAttributes xa;
} FontAttributes;
typedef struct ThreadSpecificData {
typedef struct {
FontFamily *fontFamilyList; /* The list of font families that are
* currently loaded. As screen fonts are
* loaded, this list grows to hold information
@@ -171,7 +171,7 @@ static Tcl_ThreadDataKey dataKey;
* encodings into the names expected by the Tcl encoding package.
*/
static EncodingAlias encodingAliases[] = {
static const EncodingAlias encodingAliases[] = {
{"gb2312-raw", "gb2312*"},
{"big5", "big5*"},
{"cns11643-1", "cns11643*-1"},
@@ -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,18 +311,13 @@ 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";
type.toUtfProc = ControlUtfProc;
type.fromUtfProc = ControlUtfProc;
type.freeProc = NULL;
type.clientData = NULL;
type.nullSize = 0;
Tcl_EncodingType type = {"X11ControlChars", ControlUtfProc, ControlUtfProc, NULL, NULL, 0};
tsdPtr->controlFamily.refCount = 2;
tsdPtr->controlFamily.encoding = Tcl_CreateEncoding(&type);
tsdPtr->controlFamily.isTwoByteFont = 0;
@@ -343,20 +329,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 ucs2type = {"ucs-2be", Ucs2beToUtfProc, UtfToUcs2beProc, NULL, NULL, 2};
Tcl_CreateEncoding(&ucs2type);
} else {
Tcl_FreeEncoding(ucs2);
}
Tcl_CreateThreadExitHandler(FontPkgCleanup, NULL);
}
}
@@ -428,15 +412,15 @@ ControlUtfProc(
}
src += TkUtfToUniChar(src, &ch);
dst[0] = '\\';
if (((size_t) ch < sizeof(mapChars)) && (mapChars[ch] != 0)) {
if (((size_t)ch < sizeof(mapChars)) && (mapChars[ch] != 0)) {
dst[1] = mapChars[ch];
dst += 2;
} else if (ch < 256) {
} else if ((size_t)ch < 256) {
dst[1] = 'x';
dst[2] = hexChars[(ch >> 4) & 0xf];
dst[3] = hexChars[ch & 0xf];
dst += 4;
} else if (ch < 0x10000) {
} else if ((size_t)ch < 0x10000) {
dst[1] = 'u';
dst[2] = hexChars[(ch >> 12) & 0xf];
dst[3] = hexChars[(ch >> 8) & 0xf];
@@ -459,14 +443,12 @@ ControlUtfProc(
return result;
}
#ifndef WORDS_BIGENDIAN
/*
*-------------------------------------------------------------------------
*
* Ucs2beToUtfProc --
*
* Convert from UCS-2BE (big-endian 16-bit Unicode) to UTF-8.
* This is only defined on LE machines.
*
* Results:
* Returns TCL_OK if conversion was successful.
@@ -515,6 +497,11 @@ Ucs2beToUtfProc(
result = TCL_CONVERT_MULTIBYTE;
srcLen--;
}
/* If last code point is a high surrogate, we cannot handle that yet */
if ((srcLen >= 2) && ((src[srcLen - 2] & 0xFC) == 0xD8)) {
result = TCL_CONVERT_MULTIBYTE;
srcLen -= 2;
}
srcStart = src;
srcEnd = src + srcLen;
@@ -533,7 +520,7 @@ Ucs2beToUtfProc(
* UCS-2BE. We know this is an LE->BE swap.
*/
dst += Tcl_UniCharToUtf(htons(*((short *)src)), dst);
dst += TkUniCharToUtf(htons(*((short *)src)), dst);
src += 2 /* sizeof(UCS-2) */;
}
@@ -589,7 +576,11 @@ UtfToUcs2beProc(
{
const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
int result, numChars;
Tcl_UniChar ch;
Tcl_UniChar *chPtr = (Tcl_UniChar *)statePtr;
if (flags & TCL_ENCODING_START) {
*statePtr = 0;
}
srcStart = src;
srcEnd = src + srcLen;
@@ -608,15 +599,14 @@ UtfToUcs2beProc(
* 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 (dst > dstEnd) {
result = TCL_CONVERT_NOSPACE;
break;
}
src += Tcl_UtfToUniChar(src, &ch);
}
src += Tcl_UtfToUniChar(src, chPtr);
/*
* Ensure big-endianness (store big bits first).
@@ -624,15 +614,15 @@ UtfToUcs2beProc(
* sure to work in char* for Tcl_UtfToUniChar alignment. [Bug 1122671]
*/
*dst++ = (ch >> 8);
*dst++ = (ch & 0xFF);
*dst++ = (char)(*chPtr >> 8);
*dst++ = (char)*chPtr;
}
*srcReadPtr = src - srcStart;
*dstWrotePtr = dst - dstStart;
*dstCharsPtr = numChars;
return result;
}
#endif /* WORDS_BIGENDIAN */
/*
*---------------------------------------------------------------------------
@@ -1986,11 +1976,11 @@ FindSubFontForChar(
SubFont *subFontPtr;
Tcl_DString ds;
if (FontMapLookup(&fontPtr->subFontArray[0], ch)) {
return &fontPtr->subFontArray[0];
if (ch < 0 || ch > 0x30000) {
ch = 0xfffd;
}
for (i = 1; i < fontPtr->numSubFonts; i++) {
for (i = 0; i < fontPtr->numSubFonts; i++) {
if (FontMapLookup(&fontPtr->subFontArray[i], ch)) {
return &fontPtr->subFontArray[i];
}
@@ -2140,6 +2130,9 @@ FontMapLookup(
{
int row, bitOffset;
if (ch < 0 || ch >= 0x30000) {
return 0;
}
row = ch >> FONTMAP_SHIFT;
if (subFontPtr->fontMap[row] == NULL) {
FontMapLoadPage(subFontPtr, row);
@@ -2180,12 +2173,14 @@ FontMapInsert(
{
int row, bitOffset;
row = ch >> FONTMAP_SHIFT;
if (subFontPtr->fontMap[row] == NULL) {
FontMapLoadPage(subFontPtr, row);
if (ch >= 0 && ch < 0x30000) {
row = ch >> FONTMAP_SHIFT;
if (subFontPtr->fontMap[row] == NULL) {
FontMapLoadPage(subFontPtr, row);
}
bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
}
bitOffset = ch & (FONTMAP_BITSPERPAGE - 1);
subFontPtr->fontMap[row][bitOffset >> 3] |= 1 << (bitOffset & 7);
}
/*
@@ -3015,10 +3010,10 @@ static const char *
GetEncodingAlias(
const char *name) /* The name to look up. */
{
EncodingAlias *aliasPtr;
const EncodingAlias *aliasPtr;
for (aliasPtr = encodingAliases; aliasPtr->aliasPattern != NULL; ) {
if (Tcl_StringMatch(name, aliasPtr->aliasPattern)) {
if (Tcl_StringCaseMatch(name, aliasPtr->aliasPattern, 0)) {
return aliasPtr->realName;
}
aliasPtr++;