diff options
author | hobbs <hobbs> | 2005-02-11 19:27:37 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2005-02-11 19:27:37 (GMT) |
commit | 1da4e50a6720393c4235a995f664b7bd6f6ed48e (patch) | |
tree | 070e9be4528227a17a13d9669abed1e606889764 /generic/tkCanvBmap.c | |
parent | 8954f5c96c1e3196fa11f124d0eb52687393afa8 (diff) | |
download | tk-1da4e50a6720393c4235a995f664b7bd6f6ed48e.zip tk-1da4e50a6720393c4235a995f664b7bd6f6ed48e.tar.gz tk-1da4e50a6720393c4235a995f664b7bd6f6ed48e.tar.bz2 |
* generic/tkCanvBmap.c (ConfigureBitmap, ComputeBitmapBbox): Fixed
possible crash with disabled bmap and bbox handling [Bug 1119460]
(BitmapToPostscript): made aware of various bitmap types
(DisplayBitmap): remove unused fg/bgColor refs
Diffstat (limited to 'generic/tkCanvBmap.c')
-rw-r--r-- | generic/tkCanvBmap.c | 108 |
1 files changed, 59 insertions, 49 deletions
diff --git a/generic/tkCanvBmap.c b/generic/tkCanvBmap.c index 6f979cf..5a74047 100644 --- a/generic/tkCanvBmap.c +++ b/generic/tkCanvBmap.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvBmap.c,v 1.7.2.1 2003/04/18 21:56:47 hobbs Exp $ + * RCS: @(#) $Id: tkCanvBmap.c,v 1.7.2.2 2005/02/11 19:27:52 hobbs Exp $ */ #include <stdio.h> @@ -180,7 +180,7 @@ TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) int i; if (objc == 0) { - panic("canvas did not pass any coords\n"); + Tcl_Panic("canvas did not pass any coords\n"); } /* @@ -352,12 +352,12 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } - if (state==TK_STATE_HIDDEN) { + if (state == TK_STATE_HIDDEN) { ComputeBitmapBbox(canvas, bmapPtr); - return TCL_OK; + return TCL_OK; } fgColor = bmapPtr->fgColor; bgColor = bmapPtr->bgColor; @@ -372,7 +372,7 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) if (bmapPtr->activeBitmap!=None) { bitmap = bmapPtr->activeBitmap; } - } else if (state==TK_STATE_DISABLED) { + } else if (state == TK_STATE_DISABLED) { if (bmapPtr->disabledFgColor!=NULL) { fgColor = bmapPtr->disabledFgColor; } @@ -384,23 +384,18 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) } } - if (state==TK_STATE_DISABLED || bitmap == None) { - ComputeBitmapBbox(canvas, bmapPtr); - return TCL_OK; - } - - gcValues.foreground = fgColor->pixel; - mask = GCForeground; - if (bgColor != NULL) { - gcValues.background = bgColor->pixel; - mask |= GCBackground; - } else { - gcValues.clip_mask = bitmap; - mask |= GCClipMask; - } if (bitmap == None) { newGC = None; } else { + gcValues.foreground = fgColor->pixel; + mask = GCForeground; + if (bgColor != NULL) { + gcValues.background = bgColor->pixel; + mask |= GCBackground; + } else { + gcValues.clip_mask = bitmap; + mask |= GCClipMask; + } newGC = Tk_GetGC(tkwin, mask, &gcValues); } if (bmapPtr->gc != None) { @@ -409,7 +404,6 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) bmapPtr->gc = newGC; ComputeBitmapBbox(canvas, bmapPtr); - return TCL_OK; } @@ -503,7 +497,7 @@ ComputeBitmapBbox(canvas, bmapPtr) Pixmap bitmap; Tk_State state = bmapPtr->header.state; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } bitmap = bmapPtr->bitmap; @@ -530,7 +524,7 @@ ComputeBitmapBbox(canvas, bmapPtr) * Compute location and size of bitmap, using anchor information. */ - Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bmapPtr->bitmap, + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { case TK_ANCHOR_N: @@ -606,8 +600,6 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) BitmapItem *bmapPtr = (BitmapItem *) itemPtr; int bmapX, bmapY, bmapWidth, bmapHeight; short drawableX, drawableY; - XColor *fgColor; - XColor *bgColor; Pixmap bitmap; Tk_State state = itemPtr->state; @@ -617,29 +609,15 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) * redisplay. */ - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } - fgColor = bmapPtr->fgColor; - bgColor = bmapPtr->bgColor; bitmap = bmapPtr->bitmap; if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (bmapPtr->activeFgColor!=NULL) { - fgColor = bmapPtr->activeFgColor; - } - if (bmapPtr->activeBgColor!=NULL) { - bgColor = bmapPtr->activeBgColor; - } if (bmapPtr->activeBitmap!=None) { bitmap = bmapPtr->activeBitmap; } - } else if (state==TK_STATE_DISABLED) { - if (bmapPtr->disabledFgColor!=NULL) { - fgColor = bmapPtr->disabledFgColor; - } - if (bmapPtr->disabledBgColor!=NULL) { - bgColor = bmapPtr->disabledBgColor; - } + } else if (state == TK_STATE_DISABLED) { if (bmapPtr->disabledBitmap!=None) { bitmap = bmapPtr->disabledBitmap; } @@ -678,7 +656,7 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) * to line up with the bitmap's origin (in order to make * bitmaps with "-background {}" work right). */ - + XSetClipOrigin(display, bmapPtr->gc, drawableX - bmapX, drawableY - bmapY); XCopyPlane(display, bitmap, drawable, @@ -897,8 +875,40 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) int width, height, rowsAtOnce, rowsThisTime; int curRow; char buffer[100 + TCL_DOUBLE_SPACE * 2 + TCL_INTEGER_SPACE * 4]; + XColor *fgColor; + XColor *bgColor; + Pixmap bitmap; + Tk_State state = itemPtr->state; + + if (state == TK_STATE_NULL) { + state = ((TkCanvas *)canvas)->canvas_state; + } + fgColor = bmapPtr->fgColor; + bgColor = bmapPtr->bgColor; + bitmap = bmapPtr->bitmap; + if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { + if (bmapPtr->activeFgColor!=NULL) { + fgColor = bmapPtr->activeFgColor; + } + if (bmapPtr->activeBgColor!=NULL) { + bgColor = bmapPtr->activeBgColor; + } + if (bmapPtr->activeBitmap!=None) { + bitmap = bmapPtr->activeBitmap; + } + } else if (state == TK_STATE_DISABLED) { + if (bmapPtr->disabledFgColor!=NULL) { + fgColor = bmapPtr->disabledFgColor; + } + if (bmapPtr->disabledBgColor!=NULL) { + bgColor = bmapPtr->disabledBgColor; + } + if (bmapPtr->disabledBitmap!=None) { + bitmap = bmapPtr->disabledBitmap; + } + } - if (bmapPtr->bitmap == None) { + if (bitmap == None) { return TCL_OK; } @@ -909,7 +919,7 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) x = bmapPtr->x; y = Tk_CanvasPsY(canvas, bmapPtr->y); - Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bmapPtr->bitmap, + Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { case TK_ANCHOR_NW: y -= height; break; @@ -927,12 +937,12 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) * Color the background, if there is one. */ - if (bmapPtr->bgColor != NULL) { + if (bgColor != NULL) { sprintf(buffer, "%.15g %.15g moveto %d 0 rlineto 0 %d rlineto %d %s\n", x, y, width, height, -width, "0 rlineto closepath"); Tcl_AppendResult(interp, buffer, (char *) NULL); - if (Tk_CanvasPsColor(interp, canvas, bmapPtr->bgColor) != TCL_OK) { + if (Tk_CanvasPsColor(interp, canvas, bgColor) != TCL_OK) { return TCL_ERROR; } Tcl_AppendResult(interp, "fill\n", (char *) NULL); @@ -945,8 +955,8 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) * can't handle single strings longer than 64 KBytes long. */ - if (bmapPtr->fgColor != NULL) { - if (Tk_CanvasPsColor(interp, canvas, bmapPtr->fgColor) != TCL_OK) { + if (fgColor != NULL) { + if (Tk_CanvasPsColor(interp, canvas, fgColor) != TCL_OK) { return TCL_ERROR; } if (width > 60000) { @@ -970,7 +980,7 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) sprintf(buffer, "0 -%.15g translate\n%d %d true matrix {\n", (double) rowsThisTime, width, rowsThisTime); Tcl_AppendResult(interp, buffer, (char *) NULL); - if (Tk_CanvasPsBitmap(interp, canvas, bmapPtr->bitmap, + if (Tk_CanvasPsBitmap(interp, canvas, bitmap, 0, curRow, width, rowsThisTime) != TCL_OK) { return TCL_ERROR; } |