summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-14 10:33:56 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-14 10:33:56 (GMT)
commit8a2f66101bb61555e247c13cd0e6717121c07c49 (patch)
treeb8f356a9d8222392f1a8bb46df120b3c5235f89a /generic
parent886c564929235ae0172e8f74c1f13b2f4677edf9 (diff)
parent7cfd623dc5324f153717a00faa7c3e080811bcbb (diff)
downloadtk-8a2f66101bb61555e247c13cd0e6717121c07c49.zip
tk-8a2f66101bb61555e247c13cd0e6717121c07c49.tar.gz
tk-8a2f66101bb61555e247c13cd0e6717121c07c49.tar.bz2
Merge 8.7. Add testcases
Diffstat (limited to 'generic')
-rw-r--r--generic/tkButton.c8
-rw-r--r--generic/tkImgGIF.c15
-rw-r--r--generic/tkImgPNG.c74
-rw-r--r--generic/tkMessage.c70
-rw-r--r--generic/tkText.h9
5 files changed, 103 insertions, 73 deletions
diff --git a/generic/tkButton.c b/generic/tkButton.c
index 68af116..77a3fdc 100644
--- a/generic/tkButton.c
+++ b/generic/tkButton.c
@@ -1097,6 +1097,14 @@ ConfigureButton(
} else {
Tk_SetBackgroundFromBorder(butPtr->tkwin, butPtr->normalBorder);
}
+ if (butPtr->wrapLength < 0) {
+ butPtr->wrapLength = 0;
+ if (butPtr->wrapLengthPtr) {
+ Tcl_DecrRefCount(butPtr->wrapLengthPtr);
+ }
+ butPtr->wrapLengthPtr = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(butPtr->wrapLengthPtr);
+ }
if (butPtr->borderWidth < 0) {
butPtr->borderWidth = 0;
if (butPtr->borderWidthPtr) {
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c
index 9b70344..6368972 100644
--- a/generic/tkImgGIF.c
+++ b/generic/tkImgGIF.c
@@ -704,6 +704,7 @@ FileReadGIF(
}
if ((width > 0) && (height > 0)) {
+ unsigned char* pixelPtr;
Tk_PhotoImageBlock block;
int transparent = -1;
if (gifGraphicControlExtensionBlock.blockPresent) {
@@ -729,23 +730,25 @@ FileReadGIF(
goto error;
}
nBytes = block.pitch * imageHeight;
- block.pixelPtr = (unsigned char *)ckalloc(nBytes);
- if (block.pixelPtr) {
- memset(block.pixelPtr, 0, nBytes);
+ pixelPtr = (unsigned char*)ckalloc(nBytes);
+ if (pixelPtr) {
+ memset(pixelPtr, 0, nBytes);
}
+ block.pixelPtr = pixelPtr;
if (ReadImage(gifConfPtr, interp, block.pixelPtr, chan, imageWidth,
imageHeight, colorMap, srcX, srcY, BitSet(buf[8], INTERLACE),
transparent) != TCL_OK) {
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
goto error;
}
+ block.pixelPtr += srcX * block.pixelSize + srcY * block.pitch;
if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
goto error;
}
- ckfree(block.pixelPtr);
+ ckfree(pixelPtr);
}
/*
diff --git a/generic/tkImgPNG.c b/generic/tkImgPNG.c
index 5eb85a7..2879ae2 100644
--- a/generic/tkImgPNG.c
+++ b/generic/tkImgPNG.c
@@ -205,7 +205,8 @@ static void CleanupPNGImage(PNGImage *pngPtr);
static int DecodeLine(Tcl_Interp *interp, PNGImage *pngPtr);
static int DecodePNG(Tcl_Interp *interp, PNGImage *pngPtr,
Tcl_Obj *fmtObj, Tk_PhotoHandle imageHandle,
- int destX, int destY);
+ int destX, int destY, int width, int height,
+ int srcX, int srcY);
static int EncodePNG(Tcl_Interp *interp,
Tk_PhotoImageBlock *blockPtr, PNGImage *pngPtr,
Tcl_Obj *metadataInObj);
@@ -2476,14 +2477,19 @@ ParseFormat(
static int
DecodePNG(
- Tcl_Interp *interp,
- PNGImage *pngPtr,
- Tcl_Obj *fmtObj,
- Tk_PhotoHandle imageHandle,
- int destX,
- int destY)
+ Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
+ PNGImage *pngPtr, /* PNG image information record. */
+ Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
+ Tk_PhotoHandle imageHandle, /* The photo image to write into. */
+ int destX, int destY, /* Coordinates of top-left pixel in photo
+ * image to be written to. */
+ int width, int height, /* Dimensions of block of photo image to be
+ * written to. */
+ int srcX, int srcY) /* Coordinates of top-left pixel to be used in
+ * image being read. */
{
unsigned long chunkType;
+ int result;
Tcl_Size chunkSz;
unsigned long crc;
@@ -2631,8 +2637,8 @@ DecodePNG(
* to negative here: Tk will not shrink the image.
*/
- if (Tk_PhotoExpand(interp, imageHandle, destX + pngPtr->block.width,
- destY + pngPtr->block.height) == TCL_ERROR) {
+ if (Tk_PhotoExpand(interp, imageHandle, destX + width,
+ destY + height) == TCL_ERROR) {
return TCL_ERROR;
}
@@ -2786,13 +2792,12 @@ DecodePNG(
* Copy the decoded image block into the Tk photo image.
*/
- if (Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY,
- pngPtr->block.width, pngPtr->block.height,
- TK_PHOTO_COMPOSITE_SET) == TCL_ERROR) {
- return TCL_ERROR;
- }
+ pngPtr->block.pixelPtr += srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch;
+ result = Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY,
+ width, height, TK_PHOTO_COMPOSITE_SET);
+ pngPtr->block.pixelPtr -= srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch;
- return TCL_OK;
+ return result;
}
/*
@@ -2862,21 +2867,19 @@ FileMatchPNG(
static int
FileReadPNG(
- Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
Tcl_Channel chan, /* The image file, open for reading. */
- TCL_UNUSED(const char *), /* The name of the image file. */
+ TCL_UNUSED(const char*), /* The name of the image file. */
Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be NULL */
Tk_PhotoHandle imageHandle, /* The photo image to write into. */
int destX, int destY, /* Coordinates of top-left pixel in photo
* image to be written to. */
- TCL_UNUSED(int), /* Dimensions of block of photo image to be
+ int width, int height, /* Dimensions of block of photo image to be
* written to. */
- TCL_UNUSED(int),
- TCL_UNUSED(int), /* Coordinates of top-left pixel to be used in
+ int srcX, int srcY, /* Coordinates of top-left pixel to be used in
* image being read. */
- TCL_UNUSED(int),
- Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
+ Tcl_Obj* metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
int result = TCL_ERROR;
@@ -2884,7 +2887,7 @@ FileReadPNG(
result = InitPNGImage(interp, &png, chan, NULL, TCL_ZLIB_STREAM_INFLATE);
if (TCL_OK == result) {
- result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
+ result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
@@ -2968,16 +2971,17 @@ StringMatchPNG(
static int
StringReadPNG(
- Tcl_Interp *interp, /* interpreter for reporting errors in */
- Tcl_Obj *pObjData, /* object containing the image */
- Tcl_Obj *fmtObj, /* format object, or NULL */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
- Tk_PhotoHandle imageHandle, /* the image to write this data into */
- int destX, int destY, /* The rectangular region of the */
- TCL_UNUSED(int), /* image to copy */
- TCL_UNUSED(int),
- TCL_UNUSED(int),
- TCL_UNUSED(int),
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
+ Tcl_Obj *pObjData,
+ Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be NULL */
+ Tk_PhotoHandle imageHandle, /* The photo image to write into. */
+ int destX, int destY, /* Coordinates of top-left pixel in photo
+ * image to be written to. */
+ int width, int height, /* Dimensions of block of photo image to be
+ * written to. */
+ int srcX, int srcY, /* Coordinates of top-left pixel to be used in
+ * image being read. */
Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
@@ -2987,7 +2991,7 @@ StringReadPNG(
TCL_ZLIB_STREAM_INFLATE);
if (TCL_OK == result) {
- result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY);
+ result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
diff --git a/generic/tkMessage.c b/generic/tkMessage.c
index 0ed430f..b89500e 100644
--- a/generic/tkMessage.c
+++ b/generic/tkMessage.c
@@ -448,7 +448,7 @@ ConfigureMessage(
TCL_UNUSED(int)) /* Flags to pass to Tk_ConfigureWidget. */
{
Tk_SavedOptions savedOptions;
- int highlightWidth;
+ int width, borderWidth, highlightWidth, padX, padY;
/*
* Eliminate any existing trace on a variable monitored by the message.
@@ -498,6 +498,22 @@ ConfigureMessage(
msgPtr->numChars = TkNumUtfChars(msgPtr->string, TCL_INDEX_NONE);
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->widthObj, &width);
+ if (width < 0) {
+ if (msgPtr->widthObj) {
+ Tcl_DecrRefCount(msgPtr->widthObj);
+ }
+ msgPtr->widthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->widthObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->borderWidthObj, &borderWidth);
+ if (borderWidth < 0) {
+ if (msgPtr->borderWidthObj) {
+ Tcl_DecrRefCount(msgPtr->borderWidthObj);
+ }
+ msgPtr->borderWidthObj = Tcl_NewIntObj(0);
+ Tcl_IncrRefCount(msgPtr->borderWidthObj);
+ }
Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->highlightWidthObj, &highlightWidth);
if (highlightWidth < 0) {
if (msgPtr->highlightWidthObj) {
@@ -506,6 +522,30 @@ ConfigureMessage(
msgPtr->highlightWidthObj = Tcl_NewIntObj(0);
Tcl_IncrRefCount(msgPtr->highlightWidthObj);
}
+ if (!msgPtr->padXObj) {
+ msgPtr->padXObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padXObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
+ if (padX < 0) {
+ if (strcmp(Tcl_GetString(msgPtr->padXObj), "-1")) {
+ Tcl_DecrRefCount(msgPtr->padXObj);
+ msgPtr->padXObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padXObj);
+ }
+ }
+ if (!msgPtr->padYObj) {
+ msgPtr->padYObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padYObj);
+ }
+ Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
+ if (padY < 0) {
+ if (strcmp(Tcl_GetString(msgPtr->padYObj), "-1")) {
+ Tcl_DecrRefCount(msgPtr->padYObj);
+ msgPtr->padYObj = Tcl_NewIntObj(-1);
+ Tcl_IncrRefCount(msgPtr->padYObj);
+ }
+ }
Tk_FreeSavedOptions(&savedOptions);
MessageWorldChanged(msgPtr);
@@ -536,9 +576,7 @@ MessageWorldChanged(
{
XGCValues gcValues;
GC gc = NULL;
- Tk_FontMetrics fm;
Message *msgPtr = (Message *)instanceData;
- int padX, padY;
if (msgPtr->border != NULL) {
Tk_SetBackgroundFromBorder(msgPtr->tkwin, msgPtr->border);
@@ -552,32 +590,6 @@ MessageWorldChanged(
}
msgPtr->textGC = gc;
- Tk_GetFontMetrics(msgPtr->tkfont, &fm);
- if (!msgPtr->padXObj) {
- msgPtr->padXObj = Tcl_NewIntObj(-1);
- Tcl_IncrRefCount(msgPtr->padXObj);
- }
- Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padXObj, &padX);
- if (padX < 0) {
- if (strcmp(Tcl_GetString(msgPtr->padXObj), "-1")) {
- Tcl_DecrRefCount(msgPtr->padXObj);
- msgPtr->padXObj = Tcl_NewIntObj(-1);
- Tcl_IncrRefCount(msgPtr->padXObj);
- }
- }
- if (!msgPtr->padYObj) {
- msgPtr->padYObj = Tcl_NewIntObj(-1);
- Tcl_IncrRefCount(msgPtr->padYObj);
- }
- Tk_GetPixelsFromObj(NULL, msgPtr->tkwin, msgPtr->padYObj, &padY);
- if (padY < 0) {
- if (strcmp(Tcl_GetString(msgPtr->padYObj), "-1")) {
- Tcl_DecrRefCount(msgPtr->padYObj);
- msgPtr->padYObj = Tcl_NewIntObj(-1);
- Tcl_IncrRefCount(msgPtr->padYObj);
- }
- }
-
/*
* Recompute the desired geometry for the window, and arrange for the
* window to be redisplayed.
diff --git a/generic/tkText.h b/generic/tkText.h
index 90cc607..a2d8240 100644
--- a/generic/tkText.h
+++ b/generic/tkText.h
@@ -172,9 +172,12 @@ typedef struct TkTextSegment {
Tcl_Size size; /* Size of this segment (# of bytes of index
* space it occupies). */
union {
- char chars[TCL_UTF_MAX]; /* Characters that make up character info.
- * Actual length varies to hold as many
- * characters as needed.*/
+ /* The TKFLEXARRAY macro - unfortunately - doesn't work inside a union. */
+#if defined(__GNUC__) && (__GNUC__ > 2)
+ char chars[0]; /* Characters that make up character info. */
+#else /* Actual length varies to hold as many */
+ char chars[1]; /* characters as needed. See [dacd18294b] */
+#endif
TkTextToggle toggle; /* Information about tag toggle. */
TkTextMark mark; /* Information about mark. */
TkTextEmbWindow ew; /* Information about embedded window. */