--- tkCanvImg.c.org Tue Sep 15 03:23:05 1998 +++ tkCanvImg.c Tue Mar 16 14:37:56 1999 @@ -68,6 +68,8 @@ Tk_Item *itemPtr, double *rectPtr)); static double ImageToPoint _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item *itemPtr, double *coordPtr)); +static int ImageToPostscript _ANSI_ARGS_((Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); static void ComputeImageBbox _ANSI_ARGS_((Tk_Canvas canvas, ImageItem *imgPtr)); static int ConfigureImage _ANSI_ARGS_((Tcl_Interp *interp, @@ -104,7 +106,7 @@ 0, /* alwaysRedraw */ ImageToPoint, /* pointProc */ ImageToArea, /* areaProc */ - (Tk_ItemPostscriptProc *) NULL, /* postscriptProc */ + ImageToPostscript, /* postscriptProc */ ScaleImage, /* scaleProc */ TranslateImage, /* translateProc */ (Tk_ItemIndexProc *) NULL, /* indexProc */ @@ -674,4 +676,131 @@ Tk_CanvasEventuallyRedraw(imgPtr->canvas, imgPtr->header.x1 + x, imgPtr->header.y1 + y, (int) (imgPtr->header.x1 + x + width), (int) (imgPtr->header.y1 + y + height)); +} + +/* + *-------------------------------------------------------------- + * + * ImageToPostscript -- + * + * This procedure is called to generate Postscript for + * image items. + * + * Results: + * The return value is a standard Tcl result. If an error + * occurs in generating Postscript then an error message is + * left in interp->result, replacing whatever used + * to be there. If no error occurs, then Postscript for the + * item is appended to the result. + * + * Side effects: + * None. + * + *-------------------------------------------------------------- + */ + +static int +ImageToPostscript(interp, canvas, itemPtr, prepass) + Tcl_Interp *interp; /* Leave Postscript or error message + * here. */ + Tk_Canvas canvas; /* Information about overall canvas. */ + Tk_Item *itemPtr; /* Item for which Postscript is + * wanted. */ + int prepass; /* 1 means this is a prepass to + * collect font information; 0 means + * final Postscript is being created. */ +{ + ImageItem *imgPtr = (ImageItem *) itemPtr; + Tk_PhotoHandle sp; + Tk_PhotoImageBlock sb; + int width, height; + double x, y; + unsigned char* pixelp; + int xp, yp; + char buffer[500]; + + sp = Tk_FindPhoto(interp, imgPtr->imageString); + Tk_PhotoGetImage(sp, &sb); + if (prepass != 0) { + return TCL_OK; + } + + x=imgPtr->x; + y=imgPtr->y; + Tk_SizeOfImage(imgPtr->image, &width, &height); + switch (imgPtr->anchor) { + case TK_ANCHOR_N: + x -= width/2; + break; + case TK_ANCHOR_NE: + x -= width; + break; + case TK_ANCHOR_E: + x -= width; + y -= height/2; + break; + case TK_ANCHOR_SE: + x -= width; + y -= height; + break; + case TK_ANCHOR_S: + x -= width/2; + y -= height; + break; + case TK_ANCHOR_SW: + y -= height; + break; + case TK_ANCHOR_W: + y -= height/2; + break; + case TK_ANCHOR_NW: + break; + case TK_ANCHOR_CENTER: + x -= width/2; + y -= height/2; + break; + } + sprintf(buffer, + "1 dict begin\ngsave\n" + "\%.15g %.15g translate\n" + "%d %d scale\n" + "%d %d 8\n[%d 0 0 %d 0 0]\n" + "{%d string currentfile exch readhexstring pop}\n" + "{%d string currentfile exch readhexstring pop}\n" + "{%d string currentfile exch readhexstring pop}\n" + "true 3\n" + "colorimage\n", + x, Tk_CanvasPsY(canvas, y), + sb.width, sb.height, + sb.width, sb.height, + sb.width, -sb.height, + sb.width, sb.width, sb.width); + Tcl_AppendResult(interp, buffer, (char *) NULL); + for (yp=0; yp<(sb.height); yp++) { + for (xp=0; xp<(sb.width); xp++) { + pixelp=(sb.pixelPtr) + yp * (sb.pitch) + xp * (sb.pixelSize); + sprintf(buffer, "%02x", + ((unsigned int)*(pixelp+(sb.offset[0])))); + Tcl_AppendResult(interp, buffer, (char *) NULL); + } + Tcl_AppendResult(interp, "\n", (char *) NULL); + for (xp=0; xp<(sb.width); xp++) { + pixelp=(sb.pixelPtr) + yp * (sb.pitch) + xp * (sb.pixelSize); + sprintf(buffer, "%02x", + ((unsigned int)*(pixelp+(sb.offset[1])))); + Tcl_AppendResult(interp, buffer, (char *) NULL); + } + Tcl_AppendResult(interp, "\n", (char *) NULL); + for (xp=0; xp<(sb.width); xp++) { + pixelp=(sb.pixelPtr) + yp * (sb.pitch) + xp * (sb.pixelSize); + sprintf(buffer, "%02x", + ((unsigned int)*(pixelp+(sb.offset[2])))); + Tcl_AppendResult(interp, buffer, (char *) NULL); + } + Tcl_AppendResult(interp, "\n", (char *) NULL); + } + sprintf(buffer, "grestore\nend\n"); + Tcl_AppendResult(interp, buffer, (char *) NULL); + + return TCL_OK; }