Import Tk 8.6.11

This commit is contained in:
Steve Dower
2021-03-30 00:54:10 +01:00
parent 42c69189d9
commit 070b8750b0
403 changed files with 21608 additions and 16269 deletions

View File

@@ -14,8 +14,9 @@
#include "tkInt.h"
#include "tkFont.h"
#if defined(MAC_OSX_TK)
#include "tkMacOSXInt.h"
#include "tkMacOSXInt.h" /* Defines TK_DRAW_IN_CONTEXT */
#endif
/*
* The following structure is used to keep track of all the fonts that exist
* in the current application. It must be stored in the TkMainInfo for the
@@ -95,7 +96,7 @@ typedef struct TextLayout {
* layout. */
int numChunks; /* Number of chunks actually used in following
* array. */
LayoutChunk chunks[1]; /* Array of chunks. The actual size will be
LayoutChunk chunks[TKFLEXARRAY];/* Array of chunks. The actual size will be
* maxChunks. THIS FIELD MUST BE THE LAST IN
* THE STRUCTURE. */
} TextLayout;
@@ -379,7 +380,7 @@ void
TkFontPkgInit(
TkMainInfo *mainPtr) /* The application being created. */
{
TkFontInfo *fiPtr = ckalloc(sizeof(TkFontInfo));
TkFontInfo *fiPtr = (TkFontInfo *)ckalloc(sizeof(TkFontInfo));
Tcl_InitHashTable(&fiPtr->fontCache, TCL_STRING_KEYS);
Tcl_InitHashTable(&fiPtr->namedTable, TCL_STRING_KEYS);
@@ -472,7 +473,7 @@ Tk_FontObjCmd(
Tcl_Obj *const objv[]) /* Argument objects. */
{
int index;
Tk_Window tkwin = clientData;
Tk_Window tkwin = (Tk_Window)clientData;
TkFontInfo *fiPtr = ((TkWindow *) tkwin)->mainPtr->fontInfoPtr;
static const char *const optionStrings[] = {
"actual", "configure", "create", "delete",
@@ -616,9 +617,9 @@ Tk_FontObjCmd(
}
string = Tcl_GetString(objv[2]);
namedHashPtr = Tcl_FindHashEntry(&fiPtr->namedTable, string);
nfPtr = NULL; /* lint. */
nfPtr = NULL;
if (namedHashPtr != NULL) {
nfPtr = Tcl_GetHashValue(namedHashPtr);
nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
}
if ((namedHashPtr == NULL) || nfPtr->deletePending) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -739,7 +740,7 @@ Tk_FontObjCmd(
}
case FONT_METRICS: {
Tk_Font tkfont;
int skip, index, i;
int skip, i;
const TkFontMetrics *fmPtr;
static const char *const switches[] = {
"-ascent", "-descent", "-linespace", "-fixed", NULL
@@ -796,10 +797,10 @@ Tk_FontObjCmd(
resultPtr = Tcl_NewObj();
namedHashPtr = Tcl_FirstHashEntry(&fiPtr->namedTable, &search);
while (namedHashPtr != NULL) {
NamedFont *nfPtr = Tcl_GetHashValue(namedHashPtr);
NamedFont *nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
if (!nfPtr->deletePending) {
char *string = Tcl_GetHashKey(&fiPtr->namedTable,
char *string = (char *)Tcl_GetHashKey(&fiPtr->namedTable,
namedHashPtr);
Tcl_ListObjAppendElement(NULL, resultPtr,
@@ -842,7 +843,7 @@ UpdateDependentFonts(
Tcl_HashEntry *cacheHashPtr;
Tcl_HashSearch search;
TkFont *fontPtr;
NamedFont *nfPtr = Tcl_GetHashValue(namedHashPtr);
NamedFont *nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
if (nfPtr->refCount == 0) {
/*
@@ -855,7 +856,7 @@ UpdateDependentFonts(
cacheHashPtr = Tcl_FirstHashEntry(&fiPtr->fontCache, &search);
while (cacheHashPtr != NULL) {
for (fontPtr = Tcl_GetHashValue(cacheHashPtr);
for (fontPtr = (TkFont *)Tcl_GetHashValue(cacheHashPtr);
fontPtr != NULL; fontPtr = fontPtr->nextPtr) {
if (fontPtr->namedHashPtr == namedHashPtr) {
TkpGetFontFromAttributes(fontPtr, tkwin, &nfPtr->fa);
@@ -873,19 +874,19 @@ static void
TheWorldHasChanged(
ClientData clientData) /* Info about application's fonts. */
{
TkFontInfo *fiPtr = clientData;
#if defined(MAC_OSX_TK)
TkFontInfo *fiPtr = (TkFontInfo *)clientData;
/*
* On macOS it is catastrophic to recompute all widgets while the
* [NSView drawRect] method is drawing. The best that we can do in
* that situation is to abort the recomputation and hope for the best.
* This is ignored on other platforms.
*/
if (TkpAppIsDrawing()) {
if (TkpWillDrawWidget(NULL)) {
return;
}
#endif
fiPtr->updatePending = 0;
RecomputeWidgets(fiPtr->mainPtr->winPtr);
}
@@ -963,7 +964,7 @@ TkCreateNamedFont(
namedHashPtr = Tcl_CreateHashEntry(&fiPtr->namedTable, name, &isNew);
if (!isNew) {
nfPtr = Tcl_GetHashValue(namedHashPtr);
nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
if (!nfPtr->deletePending) {
if (interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -985,7 +986,7 @@ TkCreateNamedFont(
return TCL_OK;
}
nfPtr = ckalloc(sizeof(NamedFont));
nfPtr = (NamedFont *)ckalloc(sizeof(NamedFont));
nfPtr->deletePending = 0;
Tcl_SetHashValue(namedHashPtr, nfPtr);
nfPtr->fa = *faPtr;
@@ -1024,7 +1025,7 @@ TkDeleteNamedFont(
}
return TCL_ERROR;
}
nfPtr = Tcl_GetHashValue(namedHashPtr);
nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
if (nfPtr->refCount != 0) {
nfPtr->deletePending = 1;
} else {
@@ -1113,7 +1114,7 @@ Tk_AllocFontFromObj(
SetFontFromAny(interp, objPtr);
}
oldFontPtr = objPtr->internalRep.twoPtrValue.ptr1;
oldFontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
if (oldFontPtr != NULL) {
if (oldFontPtr->resourceRefCount == 0) {
/*
@@ -1142,7 +1143,7 @@ Tk_AllocFontFromObj(
cacheHashPtr = Tcl_CreateHashEntry(&fiPtr->fontCache,
Tcl_GetString(objPtr), &isNew);
}
firstFontPtr = Tcl_GetHashValue(cacheHashPtr);
firstFontPtr = (TkFont *)Tcl_GetHashValue(cacheHashPtr);
for (fontPtr = firstFontPtr; (fontPtr != NULL);
fontPtr = fontPtr->nextPtr) {
if (Tk_Screen(tkwin) == fontPtr->screen) {
@@ -1165,7 +1166,7 @@ Tk_AllocFontFromObj(
* Construct a font based on a named font.
*/
nfPtr = Tcl_GetHashValue(namedHashPtr);
nfPtr = (NamedFont *)Tcl_GetHashValue(namedHashPtr);
nfPtr->refCount++;
fontPtr = TkpGetFontFromAttributes(NULL, tkwin, &nfPtr->fa);
@@ -1298,7 +1299,7 @@ Tk_GetFontFromObj(
SetFontFromAny(NULL, objPtr);
}
fontPtr = objPtr->internalRep.twoPtrValue.ptr1;
fontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
if (fontPtr != NULL) {
if (fontPtr->resourceRefCount == 0) {
/*
@@ -1325,7 +1326,7 @@ Tk_GetFontFromObj(
hashPtr = Tcl_FindHashEntry(&fiPtr->fontCache, Tcl_GetString(objPtr));
}
if (hashPtr != NULL) {
for (fontPtr = Tcl_GetHashValue(hashPtr); fontPtr != NULL;
for (fontPtr = (TkFont *)Tcl_GetHashValue(hashPtr); fontPtr != NULL;
fontPtr = fontPtr->nextPtr) {
if (Tk_Screen(tkwin) == fontPtr->screen) {
fontPtr->objRefCount++;
@@ -1360,7 +1361,7 @@ Tk_GetFontFromObj(
static int
SetFontFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
TCL_UNUSED(Tcl_Interp *), /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
const Tcl_ObjType *typePtr;
@@ -1436,8 +1437,7 @@ Tk_FreeFont(
if (fontPtr == NULL) {
return;
}
fontPtr->resourceRefCount--;
if (fontPtr->resourceRefCount > 0) {
if (fontPtr->resourceRefCount-- > 1) {
return;
}
if (fontPtr->namedHashPtr != NULL) {
@@ -1446,7 +1446,7 @@ Tk_FreeFont(
* the named font and free it if no-one else is using it.
*/
nfPtr = Tcl_GetHashValue(fontPtr->namedHashPtr);
nfPtr = (NamedFont *)Tcl_GetHashValue(fontPtr->namedHashPtr);
nfPtr->refCount--;
if ((nfPtr->refCount == 0) && nfPtr->deletePending) {
Tcl_DeleteHashEntry(fontPtr->namedHashPtr);
@@ -1454,7 +1454,7 @@ Tk_FreeFont(
}
}
prevPtr = Tcl_GetHashValue(fontPtr->cacheHashPtr);
prevPtr = (TkFont *)Tcl_GetHashValue(fontPtr->cacheHashPtr);
if (prevPtr == fontPtr) {
if (fontPtr->nextPtr == NULL) {
Tcl_DeleteHashEntry(fontPtr->cacheHashPtr);
@@ -1532,7 +1532,7 @@ static void
FreeFontObj(
Tcl_Obj *objPtr) /* The object we are releasing. */
{
TkFont *fontPtr = objPtr->internalRep.twoPtrValue.ptr1;
TkFont *fontPtr = (TkFont *)objPtr->internalRep.twoPtrValue.ptr1;
if (fontPtr != NULL) {
fontPtr->objRefCount--;
@@ -1567,7 +1567,7 @@ DupFontObjProc(
Tcl_Obj *srcObjPtr, /* The object we are copying from. */
Tcl_Obj *dupObjPtr) /* The object we are copying to. */
{
TkFont *fontPtr = srcObjPtr->internalRep.twoPtrValue.ptr1;
TkFont *fontPtr = (TkFont *)srcObjPtr->internalRep.twoPtrValue.ptr1;
dupObjPtr->typePtr = srcObjPtr->typePtr;
dupObjPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
@@ -1973,7 +1973,7 @@ Tk_ComputeTextLayout(
int *heightPtr) /* Filled with height of string. */
{
TkFont *fontPtr = (TkFont *) tkfont;
const char *start, *end, *special;
const char *start, *endp, *special;
int n, y, bytesThisChunk, maxChunks, curLine, layoutHeight;
int baseline, height, curX, newX, maxWidth, *lineLengths;
TextLayout *layoutPtr;
@@ -2006,8 +2006,8 @@ Tk_ComputeTextLayout(
maxChunks = 1;
layoutPtr = ckalloc(sizeof(TextLayout)
+ (maxChunks-1) * sizeof(LayoutChunk));
layoutPtr = (TextLayout *)ckalloc(Tk_Offset(TextLayout, chunks)
+ maxChunks * sizeof(LayoutChunk));
layoutPtr->tkfont = tkfont;
layoutPtr->string = string;
layoutPtr->numChunks = 0;
@@ -2021,12 +2021,12 @@ Tk_ComputeTextLayout(
curX = 0;
end = Tcl_UtfAtIndex(string, numChars);
endp = TkUtfAtIndex(string, numChars);
special = string;
flags &= TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
flags |= TK_WHOLE_WORDS | TK_AT_LEAST_ONE;
for (start = string; start < end; ) {
for (start = string; start < endp; ) {
if (start >= special) {
/*
* Find the next special character in the string.
@@ -2037,7 +2037,7 @@ Tk_ComputeTextLayout(
* whitespace set.
*/
for (special = start; special < end; special++) {
for (special = start; special < endp; special++) {
if (!(flags & TK_IGNORE_NEWLINES)) {
if ((*special == '\n') || (*special == '\r')) {
break;
@@ -2071,7 +2071,7 @@ Tk_ComputeTextLayout(
}
}
if ((start == special) && (special < end)) {
if ((start == special) && (special < endp)) {
/*
* Handle the special character.
*
@@ -2088,7 +2088,7 @@ Tk_ComputeTextLayout(
start++;
curX = newX;
flags &= ~TK_AT_LEAST_ONE;
if ((start < end) &&
if ((start < endp) &&
((wrapLength <= 0) || (newX <= wrapLength))) {
/*
* More chars can still fit on this line.
@@ -2110,7 +2110,7 @@ Tk_ComputeTextLayout(
* Consume all extra spaces at end of line.
*/
while ((start < end) && isspace(UCHAR(*start))) { /* INTL: ISO space */
while ((start < endp) && isspace(UCHAR(*start))) { /* INTL: ISO space */
if (!(flags & TK_IGNORE_NEWLINES)) {
if ((*start == '\n') || (*start == '\r')) {
break;
@@ -2298,12 +2298,16 @@ Tk_DrawTextLayout(
int x, int y, /* Upper-left hand corner of rectangle in
* which to draw (pixels). */
int firstChar, /* The index of the first character to draw
* from the given text item. 0 specfies the
* from the given text item. 0 specifies the
* beginning. */
int lastChar) /* The index just after the last character to
* draw from the given text item. A number < 0
* means to draw all characters. */
{
#if 0
/* Use TkDrawAngledTextLayout() implementation - testing purposes at this point */
TkDrawAngledTextLayout(display, drawable, gc, layout, x, y, 0.0, firstChar, lastChar);
#else
TextLayout *layoutPtr = (TextLayout *) layout;
int i, numDisplayChars, drawX;
const char *firstByte, *lastByte;
@@ -2325,16 +2329,23 @@ Tk_DrawTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
firstByte = TkUtfAtIndex(chunkPtr->start, firstChar);
Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
firstByte - chunkPtr->start, -1, 0, &drawX);
}
if (lastChar < numDisplayChars) {
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
#if TK_DRAW_IN_CONTEXT
TkpDrawCharsInContext(display, drawable, gc, layoutPtr->tkfont,
chunkPtr->start, chunkPtr->numBytes,
firstByte - chunkPtr->start, lastByte - firstByte,
x+chunkPtr->x, y+chunkPtr->y);
#else /* !TK_DRAW_IN_CONTEXT */
Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont, firstByte,
lastByte - firstByte, x+chunkPtr->x+drawX, y+chunkPtr->y);
#endif /* TK_DRAW_IN_CONTEXT */
}
firstChar -= chunkPtr->numChars;
lastChar -= chunkPtr->numChars;
@@ -2343,6 +2354,7 @@ Tk_DrawTextLayout(
}
chunkPtr++;
}
#endif /* Use TkDrawAngledTextLayout() implementation */
}
void
@@ -2357,7 +2369,7 @@ TkDrawAngledTextLayout(
* which to draw (pixels). */
double angle,
int firstChar, /* The index of the first character to draw
* from the given text item. 0 specfies the
* from the given text item. 0 specifies the
* beginning. */
int lastChar) /* The index just after the last character to
* draw from the given text item. A number < 0
@@ -2387,14 +2399,29 @@ TkDrawAngledTextLayout(
firstChar = 0;
firstByte = chunkPtr->start;
} else {
firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
firstByte = TkUtfAtIndex(chunkPtr->start, firstChar);
Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
firstByte - chunkPtr->start, -1, 0, &drawX);
}
if (lastChar < numDisplayChars) {
numDisplayChars = lastChar;
}
lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
lastByte = TkUtfAtIndex(chunkPtr->start, numDisplayChars);
#if TK_DRAW_IN_CONTEXT
dx = cosA * (chunkPtr->x) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x) + cosA * (chunkPtr->y);
if (angle == 0.0) {
TkpDrawCharsInContext(display, drawable, gc,
layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
firstByte - chunkPtr->start, lastByte - firstByte,
(int)(x + dx), (int)(y + dy));
} else {
TkpDrawAngledCharsInContext(display, drawable, gc,
layoutPtr->tkfont, chunkPtr->start, chunkPtr->numBytes,
firstByte - chunkPtr->start, lastByte - firstByte,
x+dx, y+dy, angle);
}
#else /* !TK_DRAW_IN_CONTEXT */
dx = cosA * (chunkPtr->x + drawX) + sinA * (chunkPtr->y);
dy = -sinA * (chunkPtr->x + drawX) + cosA * (chunkPtr->y);
if (angle == 0.0) {
@@ -2405,6 +2432,7 @@ TkDrawAngledTextLayout(
TkDrawAngledChars(display, drawable, gc, layoutPtr->tkfont,
firstByte, lastByte - firstByte, x+dx, y+dy, angle);
}
#endif /* TK_DRAW_IN_CONTEXT */
}
firstChar -= chunkPtr->numChars;
lastChar -= chunkPtr->numChars;
@@ -2736,15 +2764,15 @@ Tk_CharBbox(
goto check;
}
} else if (index < chunkPtr->numChars) {
end = Tcl_UtfAtIndex(chunkPtr->start, index);
end = TkUtfAtIndex(chunkPtr->start, index);
if (xPtr != NULL) {
Tk_MeasureChars(tkfont, chunkPtr->start,
end - chunkPtr->start, -1, 0, &x);
x += chunkPtr->x;
}
if (widthPtr != NULL) {
Tk_MeasureChars(tkfont, end, Tcl_UtfNext(end) - end,
-1, 0, &w);
int ch;
Tk_MeasureChars(tkfont, end, TkUtfToUniChar(end, &ch), -1, 0, &w);
}
goto check;
}
@@ -3376,7 +3404,7 @@ noMapping: ;
static int
ConfigAttributesObj(
Tcl_Interp *interp, /* Interp for error return. */
Tk_Window tkwin, /* For display on which font will be used. */
TCL_UNUSED(Tk_Window), /* For display on which font will be used. */
int objc, /* Number of elements in argv. */
Tcl_Obj *const objv[], /* Command line options. */
TkFontAttributes *faPtr) /* Font attributes structure whose fields are
@@ -3583,7 +3611,7 @@ ParseFontNameObj(
* specified in font name are filled with
* default values. */
{
char *dash;
const char *dash;
int objc, result, i, n;
Tcl_Obj **objv;
const char *string;
@@ -3751,7 +3779,7 @@ NewChunk(
maxChunks = *maxPtr;
if (layoutPtr->numChunks == maxChunks) {
maxChunks *= 2;
s = sizeof(TextLayout) + ((maxChunks - 1) * sizeof(LayoutChunk));
s = Tk_Offset(TextLayout, chunks) + (maxChunks * sizeof(LayoutChunk));
layoutPtr = ckrealloc(layoutPtr, s);
*layoutPtrPtr = layoutPtr;
@@ -4215,7 +4243,7 @@ TkDebugFont(
hashPtr = Tcl_FindHashEntry(
&((TkWindow *) tkwin)->mainPtr->fontInfoPtr->fontCache, name);
if (hashPtr != NULL) {
fontPtr = Tcl_GetHashValue(hashPtr);
fontPtr = (TkFont *)Tcl_GetHashValue(hashPtr);
if (fontPtr == NULL) {
Tcl_Panic("TkDebugFont found empty hash table entry");
}
@@ -4268,7 +4296,7 @@ TkFontGetFirstTextLayout(
}
chunkPtr = layoutPtr->chunks;
numBytesInChunk = chunkPtr->numBytes;
strncpy(dst, chunkPtr->start, (size_t) numBytesInChunk);
strncpy(dst, chunkPtr->start, numBytesInChunk);
*font = layoutPtr->tkfont;
return numBytesInChunk;
}