diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-17 08:51:55 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-09-17 08:51:55 (GMT) |
commit | af123e3f03048a5013a6802a06321f1386efe71d (patch) | |
tree | 8aaef324a6bcd923c54628b876709f11fe0fabc8 | |
parent | 9b2958c5803abffb4174f28adac63058409ded8e (diff) | |
parent | 862f1a276482cc4ca6bf3d1f03709ab1e270c349 (diff) | |
download | tk-af123e3f03048a5013a6802a06321f1386efe71d.zip tk-af123e3f03048a5013a6802a06321f1386efe71d.tar.gz tk-af123e3f03048a5013a6802a06321f1386efe71d.tar.bz2 |
Merge 8.6
-rw-r--r-- | unix/tkUnixFont.c | 63 | ||||
-rw-r--r-- | unix/tkUnixSelect.c | 4 | ||||
-rw-r--r-- | win/tkWinFont.c | 38 |
3 files changed, 70 insertions, 35 deletions
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 908deeb..3c1ce65 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -35,10 +35,10 @@ static const char encodingList[][10] = { * family": the foundry, face name, and charset. */ -#define FONTMAP_SHIFT 12 +#define FONTMAP_SHIFT 10 -#define FONTMAP_PAGES (1 << (21 - 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. */ @@ -391,7 +391,7 @@ ControlUtfProc( const char *srcStart, *srcEnd; char *dstStart, *dstEnd; int ch, result; - static const char hexChars[] = "0123456789abcdef"; + static const char hexChars[] = "0123456789ABCDEF"; static const char mapChars[] = { 0, 0, 0, 0, 0, 0, 0, 'a', 'b', 't', 'n', 'v', 'f', 'r' @@ -412,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]; @@ -430,10 +430,10 @@ ControlUtfProc( } else { /* TODO we can do better here */ dst[1] = 'u'; - dst[2] = 'f'; - dst[3] = 'f'; - dst[4] = 'f'; - dst[5] = 'd'; + dst[2] = 'F'; + dst[3] = 'F'; + dst[4] = 'F'; + dst[5] = 'D'; dst += 6; } } @@ -449,7 +449,6 @@ ControlUtfProc( * 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. @@ -498,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; @@ -572,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; @@ -591,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). @@ -607,8 +614,9 @@ 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; @@ -1967,11 +1975,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]; } @@ -2121,6 +2129,9 @@ FontMapLookup( { int row, bitOffset; + if (ch < 0 || ch >= 0x30000) { + return 0; + } row = ch >> FONTMAP_SHIFT; if (subFontPtr->fontMap[row] == NULL) { FontMapLoadPage(subFontPtr, row); @@ -2161,12 +2172,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); } /* diff --git a/unix/tkUnixSelect.c b/unix/tkUnixSelect.c index b6e980e..11161b7 100644 --- a/unix/tkUnixSelect.c +++ b/unix/tkUnixSelect.c @@ -21,7 +21,7 @@ typedef struct ConvertInfo { * offset of the next chunk of data to * transfer. */ Tcl_EncodingState state; /* The encoding state needed across chunks. */ - char buffer[4]; /* A buffer to hold part of a UTF character + char buffer[4]; /* A buffer to hold part of a UTF character * that is split across chunks.*/ } ConvertInfo; @@ -446,7 +446,7 @@ TkSelPropProc( * Preserve any left-over bytes. */ - if (srcLen > 4) { + if (srcLen > 3) { Tcl_Panic("selection conversion left too many bytes unconverted"); } memcpy(incrPtr->converts[i].buffer, src, srcLen + 1); diff --git a/win/tkWinFont.c b/win/tkWinFont.c index 948ca10..35a9941 100644 --- a/win/tkWinFont.c +++ b/win/tkWinFont.c @@ -26,10 +26,10 @@ * Under Windows, a "font family" is uniquely identified by its face name. */ -#define FONTMAP_SHIFT 12 +#define FONTMAP_SHIFT 10 -#define FONTMAP_PAGES (1 << (21 - 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. */ @@ -1943,7 +1943,7 @@ FindSubFontForChar( SubFont *subFontPtr; Tcl_DString ds; - if (ch < BASE_CHARS) { + if ((ch < BASE_CHARS) || (ch >= 0x30000)) { return &fontPtr->subFontArray[0]; } @@ -2115,6 +2115,10 @@ FontMapLookup( { int row, bitOffset; + if (ch < 0 || ch >= 0x30000) { + return 0; + } + row = ch >> FONTMAP_SHIFT; if (subFontPtr->fontMap[row] == NULL) { FontMapLoadPage(subFontPtr, row); @@ -2155,12 +2159,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); } /* @@ -2528,6 +2534,22 @@ FamilyExists( int result; Tcl_DString faceString; + /* + * Just immediately rule out the following fonts, because they look so + * ugly on windows. The caller's fallback mechanism will cause the + * corresponding appropriate TrueType fonts to be selected. + */ + + if (strcasecmp(faceName, "Courier") == 0) { + return 0; + } + if (strcasecmp(faceName, "Times") == 0) { + return 0; + } + if (strcasecmp(faceName, "Helvetica") == 0) { + return 0; + } + Tcl_UtfToExternalDString(systemEncoding, faceName, -1, &faceString); /* |