| 1 |
/* |
| 2 |
* bltCanvEps.c -- |
| 3 |
* |
| 4 |
* This file implements Encapsulated PostScript items for canvas widgets. |
| 5 |
* |
| 6 |
* Copyright 1991-1998 Lucent Technologies, Inc. |
| 7 |
* |
| 8 |
* Permission to use, copy, modify, and distribute this software and |
| 9 |
* its documentation for any purpose and without fee is hereby |
| 10 |
* granted, provided that the above copyright notice appear in all |
| 11 |
* copies and that both that the copyright notice and warranty |
| 12 |
* disclaimer appear in supporting documentation, and that the names |
| 13 |
* of Lucent Technologies any of their entities not be used in |
| 14 |
* advertising or publicity pertaining to distribution of the software |
| 15 |
* without specific, written prior permission. |
| 16 |
* |
| 17 |
* Lucent Technologies disclaims all warranties with regard to this |
| 18 |
* software, including all implied warranties of merchantability and |
| 19 |
* fitness. In no event shall Lucent Technologies be liable for any |
| 20 |
* special, indirect or consequential damages or any damages |
| 21 |
* whatsoever resulting from loss of use, data or profits, whether in |
| 22 |
* an action of contract, negligence or other tortuous action, arising |
| 23 |
* out of or in connection with the use or performance of this |
| 24 |
* software. |
| 25 |
* |
| 26 |
* EPS canvas item created by George Howlett. |
| 27 |
*/ |
| 28 |
|
| 29 |
/* |
| 30 |
* To do: |
| 31 |
* |
| 32 |
* 1. Add -rotate option. Allow arbitrary rotation of image and EPS. |
| 33 |
* 2. Draw color images instead of photos. This will eliminate the need |
| 34 |
* to create hidden photo images. |
| 35 |
* 3. Create a spiffy demo that lets you edit your page description. |
| 36 |
*/ |
| 37 |
#include "bltInt.h" |
| 38 |
#include "bltPs.h" |
| 39 |
#include "bltImage.h" |
| 40 |
|
| 41 |
#ifdef HAVE_TIFF_H |
| 42 |
#include "tiff.h" |
| 43 |
#endif |
| 44 |
#include <fcntl.h> |
| 45 |
|
| 46 |
#if defined(_MSC_VER) || defined(__BORLANDC__) |
| 47 |
#include <io.h> |
| 48 |
#define open _open |
| 49 |
#define close _close |
| 50 |
#define write _write |
| 51 |
#define unlink _unlink |
| 52 |
#define lseek _lseek |
| 53 |
#define fdopen _fdopen |
| 54 |
#define fcntl _fcntl |
| 55 |
#ifdef _MSC_VER |
| 56 |
#define O_RDWR _O_RDWR |
| 57 |
#define O_CREAT _O_CREAT |
| 58 |
#define O_TRUNC _O_TRUNC |
| 59 |
#define O_EXCL _O_EXCL |
| 60 |
#endif /* _MSC_VER */ |
| 61 |
#endif /* _MSC_VER || __BORLANDC__ */ |
| 62 |
|
| 63 |
#define DEBUG_READER 0 |
| 64 |
#ifndef WIN32 |
| 65 |
#define PurifyPrintf printf |
| 66 |
#endif |
| 67 |
#define PS_PREVIEW_EPSI 0 |
| 68 |
#define PS_PREVIEW_WMF 1 |
| 69 |
#define PS_PREVIEW_TIFF 2 |
| 70 |
|
| 71 |
#define xLeft header.x1 |
| 72 |
#define xRight header.x2 |
| 73 |
#define yTop header.y1 |
| 74 |
#define yBottom header.y2 |
| 75 |
|
| 76 |
|
| 77 |
#define MAX_EPS_LINE_LENGTH 255 /* Maximum line length for a EPS file */ |
| 78 |
|
| 79 |
/* |
| 80 |
* ParseInfo -- |
| 81 |
* |
| 82 |
* This structure is used to pass PostScript file information |
| 83 |
* around to various routines while parsing the EPS file. |
| 84 |
*/ |
| 85 |
typedef struct { |
| 86 |
int maxBytes; /* Maximum length of PostScript code. */ |
| 87 |
int lineNumber; /* Current line number of EPS file */ |
| 88 |
char line[MAX_EPS_LINE_LENGTH + 1]; |
| 89 |
/* Buffer to contain a single line from |
| 90 |
* the PostScript file. */ |
| 91 |
char hexTable[256]; /* Table for converting ASCII hex digits to |
| 92 |
* values */ |
| 93 |
|
| 94 |
char *nextPtr; /* Pointer to the next character to process on |
| 95 |
* the current line. If NULL (or if nextPtr |
| 96 |
* points a NULL byte), this indicates the |
| 97 |
* the next line needs to be read. */ |
| 98 |
FILE *f; /* */ |
| 99 |
} ParseInfo; |
| 100 |
|
| 101 |
#define DEF_EPS_ANCHOR "nw" |
| 102 |
#define DEF_EPS_OUTLINE_COLOR RGB_BLACK |
| 103 |
#define DEF_EPS_OUTLINE_MONO RGB_BLACK |
| 104 |
#define DEF_EPS_BORDERWIDTH STD_BORDERWIDTH |
| 105 |
#define DEF_EPS_FILE_NAME (char *)NULL |
| 106 |
#define DEF_EPS_FONT STD_FONT |
| 107 |
#define DEF_EPS_FILL_COLOR STD_NORMAL_FOREGROUND |
| 108 |
#define DEF_EPS_FILL_MONO STD_NORMAL_FG_MONO |
| 109 |
#define DEF_EPS_HEIGHT "0" |
| 110 |
#define DEF_EPS_IMAGE_NAME (char *)NULL |
| 111 |
#define DEF_EPS_JUSTIFY "center" |
| 112 |
#define DEF_EPS_QUICK_RESIZE "no" |
| 113 |
#define DEF_EPS_RELIEF "sunken" |
| 114 |
#define DEF_EPS_SHADOW_COLOR (char *)NULL |
| 115 |
#define DEF_EPS_SHADOW_MONO (char *)NULL |
| 116 |
#define DEF_EPS_SHOW_IMAGE "yes" |
| 117 |
#define DEF_EPS_STIPPLE (char *)NULL |
| 118 |
#define DEF_EPS_TAGS (char *)NULL |
| 119 |
#define DEF_EPS_TITLE (char *)NULL |
| 120 |
#define DEF_EPS_TITLE_ANCHOR "center" |
| 121 |
#define DEF_EPS_TITLE_COLOR RGB_BLACK |
| 122 |
#define DEF_EPS_TITLE_ROTATE "0" |
| 123 |
#define DEF_EPS_WIDTH "0" |
| 124 |
|
| 125 |
/* |
| 126 |
* Information used for parsing configuration specs: |
| 127 |
*/ |
| 128 |
|
| 129 |
static Tk_CustomOption tagsOption; |
| 130 |
|
| 131 |
extern Tk_CustomOption bltDistanceOption; |
| 132 |
extern Tk_CustomOption bltShadowOption; |
| 133 |
|
| 134 |
/* |
| 135 |
* The structure below defines the record for each EPS item. |
| 136 |
*/ |
| 137 |
typedef struct { |
| 138 |
Tk_Item header; /* Generic stuff that's the same for all |
| 139 |
* types. MUST BE FIRST IN STRUCTURE. */ |
| 140 |
Tk_Canvas canvas; /* Canvas containing the EPS item. */ |
| 141 |
|
| 142 |
int canvasX, canvasY; /* Translated (by the anchor) canvas |
| 143 |
* coordinates of the EPS item. */ |
| 144 |
|
| 145 |
int lastWidth, lastHeight; /* Last known dimensions of the EPS item. |
| 146 |
* This is used to know if the color image |
| 147 |
* preview needs to be resized. */ |
| 148 |
|
| 149 |
Tcl_Interp *interp; |
| 150 |
|
| 151 |
FILE *psFile; /* File pointer to Encapsulated |
| 152 |
* PostScript file. We'll hold this as |
| 153 |
* long as the EPS item is using this |
| 154 |
* file. */ |
| 155 |
size_t psStart; /* File offset of PostScript code. */ |
| 156 |
size_t psLength; /* Length of PostScript code. If zero, |
| 157 |
* indicates to read to EOF. */ |
| 158 |
size_t wmfStart; /* File offset of Windows Metafile preview. */ |
| 159 |
size_t wmfLength; /* Length of WMF portion in bytes. If zero, |
| 160 |
* indicates there is no WMF preview. */ |
| 161 |
size_t tiffStart; /* File offset of TIFF preview. */ |
| 162 |
size_t tiffLength; /* Length of TIFF portion in bytes. If zero, |
| 163 |
* indicates there is no TIFF preview. */ |
| 164 |
char *previewName; |
| 165 |
int previewFormat; |
| 166 |
|
| 167 |
Tk_Image preview; /* A Tk photo image provided as a |
| 168 |
* preview of the EPS contents. This |
| 169 |
* image supersedes any EPS preview |
| 170 |
* embedded PostScript preview (EPSI). */ |
| 171 |
|
| 172 |
Tk_Image tmpImage; /* Used to display the resized preview image. |
| 173 |
* Created and deleted internally. */ |
| 174 |
|
| 175 |
|
| 176 |
Pixmap pixmap; /* Pixmap representing scaled preview. This |
| 177 |
* isn't currently used. For now we're |
| 178 |
* overwriting the Tk image everytime the |
| 179 |
* EPS item is resized. In the future |
| 180 |
* we'll use our own image routines. */ |
| 181 |
|
| 182 |
ColorTable colorTable; /* Pointer to color table */ |
| 183 |
|
| 184 |
Blt_ColorImage colorImage; /* The original photo or PostScript |
| 185 |
* preview image converted to a color |
| 186 |
* image. This is kept around for |
| 187 |
* resampling or resizing the image. */ |
| 188 |
|
| 189 |
int firstLine, lastLine; |
| 190 |
/* First and last line numbers of the |
| 191 |
* PostScript preview. They are used |
| 192 |
* to skip over the preview when |
| 193 |
* encapsulating PostScript for the |
| 194 |
* canvas item. */ |
| 195 |
|
| 196 |
GC fillGC; /* Graphics context to fill background |
| 197 |
* of image outline if no preview image |
| 198 |
* was present. */ |
| 199 |
|
| 200 |
int llx, lly, urx, ury; /* Lower left and upper right coordinates |
| 201 |
* of PostScript bounding box, retrieved |
| 202 |
* from file's "BoundingBox:" field. */ |
| 203 |
|
| 204 |
char *title; /* Title, retrieved from the file's "Title:" |
| 205 |
* field, to be displayed over the top of |
| 206 |
* the EPS preview (malloc-ed). */ |
| 207 |
|
| 208 |
Tcl_DString dString; /* Contains the encapsulate PostScript. */ |
| 209 |
|
| 210 |
/* User configurable fields */ |
| 211 |
|
| 212 |
double x, y; /* Canvas coordinates of the item */ |
| 213 |
Tk_Anchor anchor; |
| 214 |
|
| 215 |
char *fileName; /* Name of the encapsulated PostScript file. |
| 216 |
* If NULL, indicates that no EPS file |
| 217 |
* has be successfully loaded yet. */ |
| 218 |
|
| 219 |
char *reqTitle; /* Title to be displayed in the EPS item. |
| 220 |
* Supersedes the title found in the EPS |
| 221 |
* file. If NULL, indicates that the title |
| 222 |
* found in the EPS file should be used. */ |
| 223 |
|
| 224 |
int width, height; /* Dimensions of EPS item. If set to zero, |
| 225 |
* the dimension found in the "%%BoundingBox:" |
| 226 |
* specification from the EPS file are |
| 227 |
* used. */ |
| 228 |
|
| 229 |
int showImage; /* Indicates if the image or the outline |
| 230 |
* rectangle should be displayed */ |
| 231 |
|
| 232 |
int quick; |
| 233 |
|
| 234 |
XColor *fillColor; /* Fill color of the image outline. */ |
| 235 |
|
| 236 |
Tk_3DBorder border; /* Outline color */ |
| 237 |
|
| 238 |
int borderWidth; |
| 239 |
int relief; |
| 240 |
|
| 241 |
TextStyle titleStyle; /* Font, color, etc. for title */ |
| 242 |
|
| 243 |
Pixmap stipple; /* Stipple for image fill */ |
| 244 |
|
| 245 |
ClientData tiffPtr; |
| 246 |
#ifdef WIN32 |
| 247 |
HENHMETAFILE *hMetaFile; /* Windows metafile. */ |
| 248 |
#endif |
| 249 |
} EpsItem; |
| 250 |
|
| 251 |
static Tk_ConfigSpec configSpecs[] = |
| 252 |
{ |
| 253 |
{TK_CONFIG_ANCHOR, "-anchor", (char *)NULL, (char *)NULL, |
| 254 |
DEF_EPS_ANCHOR, Tk_Offset(EpsItem, anchor), |
| 255 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 256 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0}, |
| 257 |
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", (char *)NULL, |
| 258 |
DEF_EPS_BORDERWIDTH, Tk_Offset(EpsItem, borderWidth), |
| 259 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 260 |
{TK_CONFIG_STRING, "-file", (char *)NULL, (char *)NULL, |
| 261 |
DEF_EPS_FILE_NAME, Tk_Offset(EpsItem, fileName), TK_CONFIG_NULL_OK}, |
| 262 |
{TK_CONFIG_FONT, "-font", "font", "Font", |
| 263 |
DEF_EPS_FONT, Tk_Offset(EpsItem, titleStyle.font), 0}, |
| 264 |
{TK_CONFIG_COLOR, "-fill", "fill", (char *)NULL, |
| 265 |
DEF_EPS_FILL_COLOR, Tk_Offset(EpsItem, fillColor), TK_CONFIG_COLOR_ONLY}, |
| 266 |
{TK_CONFIG_COLOR, "-fill", "fill", (char *)NULL, |
| 267 |
DEF_EPS_FILL_MONO, Tk_Offset(EpsItem, fillColor), TK_CONFIG_MONO_ONLY}, |
| 268 |
{TK_CONFIG_CUSTOM, "-height", (char *)NULL, (char *)NULL, |
| 269 |
DEF_EPS_HEIGHT, Tk_Offset(EpsItem, height), |
| 270 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 271 |
{TK_CONFIG_STRING, "-image", (char *)NULL, (char *)NULL, |
| 272 |
DEF_EPS_IMAGE_NAME, Tk_Offset(EpsItem, previewName), |
| 273 |
TK_CONFIG_NULL_OK}, |
| 274 |
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", |
| 275 |
DEF_EPS_JUSTIFY, Tk_Offset(EpsItem, titleStyle.justify), |
| 276 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 277 |
{TK_CONFIG_BORDER, "-outline", "outline", (char *)NULL, |
| 278 |
DEF_EPS_OUTLINE_COLOR, Tk_Offset(EpsItem, border), |
| 279 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 280 |
{TK_CONFIG_BORDER, "-outline", "outline", (char *)NULL, |
| 281 |
DEF_EPS_OUTLINE_MONO, Tk_Offset(EpsItem, border), |
| 282 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 283 |
{TK_CONFIG_BOOLEAN, "-quick", "quick", "Quick", |
| 284 |
DEF_EPS_QUICK_RESIZE, Tk_Offset(EpsItem, quick), |
| 285 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 286 |
{TK_CONFIG_RELIEF, "-relief", (char *)NULL, (char *)NULL, |
| 287 |
DEF_EPS_RELIEF, Tk_Offset(EpsItem, relief), |
| 288 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 289 |
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow", |
| 290 |
DEF_EPS_SHADOW_COLOR, Tk_Offset(EpsItem, titleStyle.shadow), |
| 291 |
TK_CONFIG_COLOR_ONLY, &bltShadowOption}, |
| 292 |
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow", |
| 293 |
DEF_EPS_SHADOW_MONO, Tk_Offset(EpsItem, titleStyle.shadow), |
| 294 |
TK_CONFIG_MONO_ONLY, &bltShadowOption}, |
| 295 |
{TK_CONFIG_BOOLEAN, "-showimage", "showImage", "ShowImage", |
| 296 |
DEF_EPS_SHOW_IMAGE, Tk_Offset(EpsItem, showImage), |
| 297 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 298 |
{TK_CONFIG_BITMAP, "-stipple", (char *)NULL, (char *)NULL, |
| 299 |
DEF_EPS_STIPPLE, Tk_Offset(EpsItem, stipple), TK_CONFIG_NULL_OK}, |
| 300 |
{TK_CONFIG_CUSTOM, "-tags", (char *)NULL, (char *)NULL, |
| 301 |
DEF_EPS_TAGS, 0, TK_CONFIG_NULL_OK, &tagsOption}, |
| 302 |
{TK_CONFIG_STRING, "-title", (char *)NULL, (char *)NULL, |
| 303 |
DEF_EPS_TITLE, Tk_Offset(EpsItem, reqTitle), TK_CONFIG_NULL_OK}, |
| 304 |
{TK_CONFIG_ANCHOR, "-titleanchor", (char *)NULL, (char *)NULL, |
| 305 |
DEF_EPS_TITLE_ANCHOR, Tk_Offset(EpsItem, titleStyle.anchor), 0}, |
| 306 |
{TK_CONFIG_COLOR, "-titlecolor", (char *)NULL, (char *)NULL, |
| 307 |
DEF_EPS_TITLE_COLOR, Tk_Offset(EpsItem, titleStyle.color), |
| 308 |
TK_CONFIG_COLOR_ONLY}, |
| 309 |
{TK_CONFIG_DOUBLE, "-titlerotate", "titleRotate", "TitleRotate", |
| 310 |
DEF_EPS_TITLE_ROTATE, Tk_Offset(EpsItem, titleStyle.theta), |
| 311 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 312 |
{TK_CONFIG_CUSTOM, "-width", (char *)NULL, (char *)NULL, |
| 313 |
DEF_EPS_WIDTH, Tk_Offset(EpsItem, width), |
| 314 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 315 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 316 |
(char *)NULL, 0, 0} |
| 317 |
}; |
| 318 |
|
| 319 |
/* |
| 320 |
* Prototypes for procedures defined in this file: |
| 321 |
*/ |
| 322 |
|
| 323 |
static void ImageChangedProc _ANSI_ARGS_((ClientData clientData, int x, int y, |
| 324 |
int width, int height, int imgWidth, int imgHeight)); |
| 325 |
static int EpsToArea _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 326 |
double *rectPtr)); |
| 327 |
static double EpsToPoint _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 328 |
double *coordPtr)); |
| 329 |
static void ComputeEpsBbox _ANSI_ARGS_((Tk_Canvas canvas, EpsItem *imgPtr)); |
| 330 |
#ifdef USE_OLD_CANVAS |
| 331 |
static int ConfigureEps _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 332 |
Tk_Item * itemPtr, int argc, char **argv, int flags)); |
| 333 |
static int CreateEps _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 334 |
Tk_Item * itemPtr, int argc, char **argv)); |
| 335 |
static int EpsCoords _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 336 |
Tk_Item * itemPtr, int argc, char **argv)); |
| 337 |
#else |
| 338 |
static int ConfigureEps _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 339 |
Tk_Item * itemPtr, int argc, Tcl_Obj *CONST *objv, int flags)); |
| 340 |
static int CreateEps _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 341 |
Tk_Item * itemPtr, int argc, Tcl_Obj *CONST *objv)); |
| 342 |
static int EpsCoords _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 343 |
Tk_Item * itemPtr, int argc, Tcl_Obj *CONST *objv)); |
| 344 |
#endif |
| 345 |
static void DeleteEps _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 346 |
Display *display)); |
| 347 |
static void DisplayEps _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 348 |
Display *display, Drawable dst, int x, int y, int width, int height)); |
| 349 |
static void ScaleEps _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 350 |
double originX, double originY, double scaleX, double scaleY)); |
| 351 |
static void TranslateEps _ANSI_ARGS_((Tk_Canvas canvas, Tk_Item * itemPtr, |
| 352 |
double deltaX, double deltaY)); |
| 353 |
static int EpsToPostScript _ANSI_ARGS_((Tcl_Interp *interp, Tk_Canvas canvas, |
| 354 |
Tk_Item * itemPtr, int prepass)); |
| 355 |
static int ReadPostScript _ANSI_ARGS_((Tcl_Interp *interp, EpsItem *epsPtr)); |
| 356 |
|
| 357 |
|
| 358 |
static char * |
| 359 |
SkipBlanks(piPtr) |
| 360 |
ParseInfo *piPtr; |
| 361 |
{ |
| 362 |
char *s; |
| 363 |
|
| 364 |
for (s = piPtr->line; isspace(UCHAR(*s)); s++) { |
| 365 |
/*empty*/ |
| 366 |
} |
| 367 |
return s; |
| 368 |
} |
| 369 |
|
| 370 |
static int |
| 371 |
ReadPsLine(piPtr) |
| 372 |
ParseInfo *piPtr; |
| 373 |
{ |
| 374 |
if (ftell(piPtr->f) < piPtr->maxBytes) { |
| 375 |
if (fgets(piPtr->line, MAX_EPS_LINE_LENGTH, piPtr->f) != NULL) { |
| 376 |
piPtr->lineNumber++; |
| 377 |
#if DEBUG_READER |
| 378 |
PurifyPrintf("%d: %s\n", piPtr->lineNumber, piPtr->line); |
| 379 |
#endif |
| 380 |
return TRUE; |
| 381 |
} |
| 382 |
} |
| 383 |
return FALSE; |
| 384 |
} |
| 385 |
|
| 386 |
/* |
| 387 |
*---------------------------------------------------------------------- |
| 388 |
* |
| 389 |
* ReverseBits -- |
| 390 |
* |
| 391 |
* Convert a byte from a X image into PostScript image order. |
| 392 |
* This requires not only the nybbles to be reversed but also |
| 393 |
* their bit values. |
| 394 |
* |
| 395 |
* Results: |
| 396 |
* The converted byte is returned. |
| 397 |
* |
| 398 |
*---------------------------------------------------------------------- |
| 399 |
*/ |
| 400 |
INLINE static unsigned char |
| 401 |
ReverseBits(byte) |
| 402 |
register unsigned char byte; |
| 403 |
{ |
| 404 |
byte = ((byte >> 1) & 0x55) | ((byte << 1) & 0xaa); |
| 405 |
byte = ((byte >> 2) & 0x33) | ((byte << 2) & 0xcc); |
| 406 |
byte = ((byte >> 4) & 0x0f) | ((byte << 4) & 0xf0); |
| 407 |
return byte; |
| 408 |
} |
| 409 |
|
| 410 |
/* |
| 411 |
*---------------------------------------------------------------------- |
| 412 |
* |
| 413 |
* GetHexValue -- |
| 414 |
* |
| 415 |
* Reads the next ASCII hex value from EPS preview image and |
| 416 |
* converts it. |
| 417 |
* |
| 418 |
* Results: |
| 419 |
* One of three Tcl return values is possible. |
| 420 |
* |
| 421 |
* TCL_OK the next byte was successfully parsed. |
| 422 |
* TCL_ERROR an error occurred processing the next hex value. |
| 423 |
* TCL_RETURN "%%EndPreview" line was detected. |
| 424 |
* |
| 425 |
* The converted hex value is returned via "bytePtr". |
| 426 |
* |
| 427 |
*---------------------------------------------------------------------- |
| 428 |
*/ |
| 429 |
static int |
| 430 |
GetHexValue(piPtr, bytePtr) |
| 431 |
ParseInfo *piPtr; |
| 432 |
unsigned char *bytePtr; |
| 433 |
{ |
| 434 |
register char *p; |
| 435 |
unsigned int byte; |
| 436 |
|
| 437 |
p = piPtr->nextPtr; |
| 438 |
if (p == NULL) { |
| 439 |
nextLine: |
| 440 |
if (!ReadPsLine(piPtr)) { |
| 441 |
#if DEBUG_READER |
| 442 |
PurifyPrintf("short file\n"); |
| 443 |
#endif |
| 444 |
return TCL_ERROR; /* Short file */ |
| 445 |
} |
| 446 |
if (piPtr->line[0] != '%') { |
| 447 |
#if DEBUG_READER |
| 448 |
PurifyPrintf("line doesn't start with %% (%s)\n", piPtr->line); |
| 449 |
#endif |
| 450 |
return TCL_ERROR; |
| 451 |
} |
| 452 |
if ((piPtr->line[1] == '%') && |
| 453 |
(strncmp(piPtr->line + 2, "EndPreview", 10) == 0)) { |
| 454 |
#if DEBUG_READER |
| 455 |
PurifyPrintf("end of preview (%s)\n", piPtr->line); |
| 456 |
#endif |
| 457 |
return TCL_RETURN; |
| 458 |
} |
| 459 |
p = piPtr->line + 1; |
| 460 |
} |
| 461 |
while (isspace((int)*p)) { |
| 462 |
p++; /* Skip spaces */ |
| 463 |
} |
| 464 |
if (*p == '\0') { |
| 465 |
goto nextLine; |
| 466 |
} |
| 467 |
if ((!isxdigit((int)p[0])) || (!isxdigit((int)p[1]))) { |
| 468 |
#if DEBUG_READER |
| 469 |
PurifyPrintf("not a hex digit (%s)\n", piPtr->line); |
| 470 |
#endif |
| 471 |
return TCL_ERROR; |
| 472 |
} |
| 473 |
byte = (piPtr->hexTable[(int)p[0]] << 4) | piPtr->hexTable[(int)p[1]]; |
| 474 |
p += 2; |
| 475 |
piPtr->nextPtr = p; |
| 476 |
*bytePtr = byte; |
| 477 |
return TCL_OK; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
/* |
| 482 |
*---------------------------------------------------------------------- |
| 483 |
* |
| 484 |
* ReadEPSI -- |
| 485 |
* |
| 486 |
* Reads the EPS preview image from the PostScript file, converting |
| 487 |
* the image into a Blt_ColorImage. If an error occurs when parsing |
| 488 |
* the preview, the preview is silently ignored. |
| 489 |
* |
| 490 |
* Results: |
| 491 |
* None. |
| 492 |
* |
| 493 |
*---------------------------------------------------------------------- |
| 494 |
*/ |
| 495 |
static void |
| 496 |
ReadEPSI(epsPtr, piPtr) |
| 497 |
EpsItem *epsPtr; |
| 498 |
ParseInfo *piPtr; |
| 499 |
{ |
| 500 |
Blt_ColorImage image; |
| 501 |
int width, height, bitsPerPixel, nLines; |
| 502 |
char *dscBeginPreview; |
| 503 |
|
| 504 |
dscBeginPreview = piPtr->line + 16; |
| 505 |
if (sscanf(dscBeginPreview, "%d %d %d %d", &width, &height, &bitsPerPixel, |
| 506 |
&nLines) != 4) { |
| 507 |
#if DEBUG_READER |
| 508 |
PurifyPrintf("bad %%BeginPreview (%s) format\n", dscBeginPreview); |
| 509 |
#endif |
| 510 |
return; |
| 511 |
} |
| 512 |
if (((bitsPerPixel != 1) && (bitsPerPixel != 8)) || (width < 1) || |
| 513 |
(width > SHRT_MAX) || (height < 1) || (height > SHRT_MAX)) { |
| 514 |
#if DEBUG_READER |
| 515 |
PurifyPrintf("Bad %%BeginPreview (%s) values\n", dscBeginPreview); |
| 516 |
#endif |
| 517 |
return; /* Bad "%%BeginPreview:" information */ |
| 518 |
} |
| 519 |
epsPtr->firstLine = piPtr->lineNumber; |
| 520 |
Blt_InitHexTable(piPtr->hexTable); |
| 521 |
piPtr->nextPtr = NULL; |
| 522 |
image = Blt_CreateColorImage(width, height); |
| 523 |
|
| 524 |
if (bitsPerPixel == 8) { |
| 525 |
int result; |
| 526 |
register Pix32 *destPtr; |
| 527 |
register int x, y; |
| 528 |
unsigned char byte; |
| 529 |
|
| 530 |
for (y = height - 1; y >= 0; y--) { |
| 531 |
destPtr = Blt_ColorImageBits(image) + (y * width); |
| 532 |
for (x = 0; x < width; x++, destPtr++) { |
| 533 |
result = GetHexValue(piPtr, &byte); |
| 534 |
if (result == TCL_ERROR) { |
| 535 |
goto error; |
| 536 |
} |
| 537 |
if (result == TCL_RETURN) { |
| 538 |
goto done; |
| 539 |
} |
| 540 |
destPtr->Red = destPtr->Green = destPtr->Blue = ~byte; |
| 541 |
destPtr->Alpha = 0xFF; |
| 542 |
} |
| 543 |
} |
| 544 |
} else if (bitsPerPixel == 1) { |
| 545 |
int result; |
| 546 |
register Pix32 *destPtr; |
| 547 |
register int x, y; |
| 548 |
unsigned char byte; |
| 549 |
register int bit; |
| 550 |
|
| 551 |
destPtr = Blt_ColorImageBits(image); |
| 552 |
for (y = 0; y < height; y++) { |
| 553 |
bit = 8; |
| 554 |
for (x = 0; x < width; x++, destPtr++) { |
| 555 |
if (bit == 8) { |
| 556 |
result = GetHexValue(piPtr, &byte); |
| 557 |
if (result == TCL_ERROR) { |
| 558 |
goto error; |
| 559 |
} |
| 560 |
if (result == TCL_RETURN) { |
| 561 |
goto done; |
| 562 |
} |
| 563 |
byte = ReverseBits(byte); |
| 564 |
bit = 0; |
| 565 |
} |
| 566 |
if (((byte >> bit) & 0x01) == 0) { |
| 567 |
destPtr->value = 0xFFFFFFFF; |
| 568 |
} |
| 569 |
bit++; |
| 570 |
} |
| 571 |
} |
| 572 |
} else { |
| 573 |
fprintf(stderr, "unknown EPSI bitsPerPixel (%d)\n", bitsPerPixel); |
| 574 |
} |
| 575 |
done: |
| 576 |
epsPtr->colorImage = image; |
| 577 |
epsPtr->lastLine = piPtr->lineNumber + 1; |
| 578 |
return; |
| 579 |
|
| 580 |
error: |
| 581 |
epsPtr->firstLine = epsPtr->lastLine = -1; |
| 582 |
if (image != NULL) { |
| 583 |
Blt_FreeColorImage(image); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
/* |
| 588 |
*---------------------------------------------------------------------- |
| 589 |
* |
| 590 |
* ReadPostScript -- |
| 591 |
* |
| 592 |
* This routine reads and parses the few fields we need out |
| 593 |
* of an EPS file. |
| 594 |
* |
| 595 |
* The EPS standards are outlined from Appendix H of the |
| 596 |
* "PostScript Language Reference Manual" pp. 709-736. |
| 597 |
* |
| 598 |
* Mandatory fields: |
| 599 |
* |
| 600 |
* - Starts with "%!PS*" |
| 601 |
* - Contains "%%BoundingBox: llx lly urx ury" |
| 602 |
* |
| 603 |
* Optional fields for EPS item: |
| 604 |
* - "%%BeginPreview: w h bpp #lines" |
| 605 |
* Preview is in hexadecimal. Each line must start with "%" |
| 606 |
* - "%%EndPreview" |
| 607 |
* - "%%Title: (string)" |
| 608 |
* |
| 609 |
*---------------------------------------------------------------------- |
| 610 |
*/ |
| 611 |
static int |
| 612 |
ReadPostScript(interp, epsPtr) |
| 613 |
Tcl_Interp *interp; |
| 614 |
EpsItem *epsPtr; |
| 615 |
{ |
| 616 |
char *field; |
| 617 |
char *dscTitle, *dscBoundingBox; |
| 618 |
char *dscEndComments; |
| 619 |
ParseInfo pi; |
| 620 |
|
| 621 |
pi.line[0] = '\0'; |
| 622 |
pi.maxBytes = epsPtr->psLength; |
| 623 |
pi.lineNumber = 0; |
| 624 |
pi.f = epsPtr->psFile; |
| 625 |
|
| 626 |
Tcl_DStringInit(&epsPtr->dString); |
| 627 |
if (pi.maxBytes == 0) { |
| 628 |
pi.maxBytes = INT_MAX; |
| 629 |
} |
| 630 |
if (epsPtr->psStart > 0) { |
| 631 |
if (fseek(epsPtr->psFile, epsPtr->psStart, 0) != 0) { |
| 632 |
Tcl_AppendResult(interp, |
| 633 |
"can't seek to start of PostScript code in \"", |
| 634 |
epsPtr->fileName, "\"", (char *)NULL); |
| 635 |
return TCL_ERROR; |
| 636 |
} |
| 637 |
} |
| 638 |
if (!ReadPsLine(&pi)) { |
| 639 |
Tcl_AppendResult(interp, "file \"", epsPtr->fileName, "\" is empty?", |
| 640 |
(char *)NULL); |
| 641 |
return TCL_ERROR; |
| 642 |
} |
| 643 |
if (strncmp(pi.line, "%!PS", 4) != 0) { |
| 644 |
Tcl_AppendResult(interp, "file \"", epsPtr->fileName, |
| 645 |
"\" doesn't start with \"%!PS\"", (char *)NULL); |
| 646 |
return TCL_ERROR; |
| 647 |
} |
| 648 |
|
| 649 |
/* |
| 650 |
* Initialize field flags to NULL. We want to look only at the |
| 651 |
* first appearance of these comment fields. The file itself may |
| 652 |
* have another EPS file embedded into it. |
| 653 |
*/ |
| 654 |
dscBoundingBox = dscTitle = dscEndComments = NULL; |
| 655 |
pi.lineNumber = 1; |
| 656 |
while (ReadPsLine(&pi)) { |
| 657 |
pi.lineNumber++; |
| 658 |
if ((pi.line[0] == '%') && (pi.line[1] == '%')) { /* Header comment */ |
| 659 |
field = pi.line + 2; |
| 660 |
if (field[0] == 'B') { |
| 661 |
if (strncmp(field, "BeginSetup", 8) == 0) { |
| 662 |
break; /* Done */ |
| 663 |
} |
| 664 |
if (strncmp(field, "BeginProlog", 8) == 0) { |
| 665 |
break; /* Done */ |
| 666 |
} |
| 667 |
if ((strncmp(field, "BoundingBox:", 12) == 0) && |
| 668 |
(dscBoundingBox == NULL)) { |
| 669 |
int nFields; |
| 670 |
|
| 671 |
dscBoundingBox = field + 12; |
| 672 |
nFields = sscanf(dscBoundingBox, "%d %d %d %d", |
| 673 |
&(epsPtr->llx), &(epsPtr->lly), |
| 674 |
&(epsPtr->urx), &(epsPtr->ury)); |
| 675 |
if (nFields != 4) { |
| 676 |
Tcl_AppendResult(interp, |
| 677 |
"bad \"%%BoundingBox\" values: \"", |
| 678 |
dscBoundingBox, "\"", (char *)NULL); |
| 679 |
goto error; |
| 680 |
} |
| 681 |
} |
| 682 |
} else if ((field[0] == 'T') && |
| 683 |
(strncmp(field, "Title:", 6) == 0)) { |
| 684 |
if (dscTitle == NULL) { |
| 685 |
dscTitle = Blt_Strdup(field + 6); |
| 686 |
} |
| 687 |
} else if (field[0] == 'E') { |
| 688 |
if (strncmp(field, "EndComments", 11) == 0) { |
| 689 |
dscEndComments = field; |
| 690 |
break; /* Done */ |
| 691 |
} |
| 692 |
} |
| 693 |
} /* %% */ |
| 694 |
} |
| 695 |
if (dscBoundingBox == NULL) { |
| 696 |
Tcl_AppendResult(interp, "no \"%%BoundingBox:\" found in \"", |
| 697 |
epsPtr->fileName, "\"", (char *)NULL); |
| 698 |
goto error; |
| 699 |
} |
| 700 |
if (dscEndComments != NULL) { |
| 701 |
/* Check if a "%%BeginPreview" immediately follows */ |
| 702 |
while (ReadPsLine(&pi)) { |
| 703 |
field = SkipBlanks(&pi); |
| 704 |
if (field[0] != '\0') { |
| 705 |
break; |
| 706 |
} |
| 707 |
} |
| 708 |
if (strncmp(pi.line, "%%BeginPreview:", 15) == 0) { |
| 709 |
ReadEPSI(epsPtr, &pi); |
| 710 |
} |
| 711 |
} |
| 712 |
if (dscTitle != NULL) { |
| 713 |
epsPtr->title = dscTitle; |
| 714 |
} |
| 715 |
/* Finally save the PostScript into a dynamic string. */ |
| 716 |
while (ReadPsLine(&pi)) { |
| 717 |
Tcl_DStringAppend(&epsPtr->dString, pi.line, -1); |
| 718 |
Tcl_DStringAppend(&epsPtr->dString, "\n", 1); |
| 719 |
} |
| 720 |
return TCL_OK; |
| 721 |
error: |
| 722 |
if (dscTitle != NULL) { |
| 723 |
Blt_Free(dscTitle); |
| 724 |
} |
| 725 |
return TCL_ERROR; /* BoundingBox: is required. */ |
| 726 |
} |
| 727 |
|
| 728 |
static int |
| 729 |
OpenEpsFile(interp, epsPtr) |
| 730 |
Tcl_Interp *interp; |
| 731 |
EpsItem *epsPtr; |
| 732 |
{ |
| 733 |
FILE *f; |
| 734 |
#ifdef WIN32 |
| 735 |
DOSEPSHEADER dosHeader; |
| 736 |
int nBytes; |
| 737 |
#endif |
| 738 |
|
| 739 |
f = fopen(epsPtr->fileName, "rb"); |
| 740 |
if (f == NULL) { |
| 741 |
Tcl_AppendResult(epsPtr->interp, "can't open \"", epsPtr->fileName, |
| 742 |
"\": ", Tcl_PosixError(epsPtr->interp), (char *)NULL); |
| 743 |
return TCL_ERROR; |
| 744 |
} |
| 745 |
epsPtr->psFile = f; |
| 746 |
epsPtr->psStart = epsPtr->psLength = 0L; |
| 747 |
epsPtr->wmfStart = epsPtr->wmfLength = 0L; |
| 748 |
epsPtr->tiffStart = epsPtr->tiffLength = 0L; |
| 749 |
|
| 750 |
#ifdef WIN32 |
| 751 |
nBytes = fread(&dosHeader, sizeof(DOSEPSHEADER), 1, f); |
| 752 |
if ((nBytes == sizeof(DOSEPSHEADER)) && |
| 753 |
(dosHeader.magic[0] == 0xC5) && (dosHeader.magic[1] == 0xD0) && |
| 754 |
(dosHeader.magic[2] == 0xD3) && (dosHeader.magic[3] == 0xC6)) { |
| 755 |
|
| 756 |
/* DOS EPS file */ |
| 757 |
epsPtr->psStart = dosHeader.psStart; |
| 758 |
epsPtr->wmfStart = dosHeader.wmfStart; |
| 759 |
epsPtr->wmfLength = dosHeader.wmfLength; |
| 760 |
epsPtr->tiffStart = dosHeader.tiffStart; |
| 761 |
epsPtr->tiffLength = dosHeader.tiffLength; |
| 762 |
epsPtr->previewFormat = PS_PREVIEW_EPSI; |
| 763 |
#ifdef HAVE_TIFF_H |
| 764 |
if (epsPtr->tiffLength > 0) { |
| 765 |
epsPtr->previewFormat = PS_PREVIEW_TIFF; |
| 766 |
} |
| 767 |
#endif /* HAVE_TIFF_H */ |
| 768 |
if (epsPtr->wmfLength > 0) { |
| 769 |
epsPtr->previewFormat = PS_PREVIEW_WMF; |
| 770 |
} |
| 771 |
} |
| 772 |
fseek(f, 0, 0); |
| 773 |
#endif /* WIN32 */ |
| 774 |
return ReadPostScript(interp, epsPtr); |
| 775 |
} |
| 776 |
|
| 777 |
static void |
| 778 |
CloseEpsFile(epsPtr) |
| 779 |
EpsItem *epsPtr; |
| 780 |
{ |
| 781 |
if (epsPtr->psFile != NULL) { |
| 782 |
fclose(epsPtr->psFile); |
| 783 |
epsPtr->psFile = NULL; |
| 784 |
} |
| 785 |
} |
| 786 |
|
| 787 |
#ifdef HAVE_TIFF_H |
| 788 |
static void |
| 789 |
ReadTiffPreview(epsPtr) |
| 790 |
EpsItem *epsPtr; |
| 791 |
{ |
| 792 |
unsigned int width, height; |
| 793 |
Blt_ColorImage image; |
| 794 |
Pix32 *dataPtr; |
| 795 |
FILE *f; |
| 796 |
int n; |
| 797 |
|
| 798 |
TIFFGetField(epsPtr->tiffPtr, TIFFTAG_IMAGEWIDTH, &width); |
| 799 |
TIFFGetField(epsPtr->tiffPtr, TIFFTAG_IMAGELENGTH, &height); |
| 800 |
image = Blt_CreateColorImage(width, height); |
| 801 |
dataPtr = Blt_ColorImageBits(image); |
| 802 |
if (!TIFFReadRGBAImage(epsPtr->tiffPtr, width, height, dataPtr, 0)) { |
| 803 |
Blt_FreeColorImage(image); |
| 804 |
return; |
| 805 |
} |
| 806 |
/* Reverse the order of the components for each pixel. */ |
| 807 |
/* ... */ |
| 808 |
epsPtr->colorImage = image; |
| 809 |
} |
| 810 |
#endif |
| 811 |
|
| 812 |
#ifdef notdef |
| 813 |
ReadWMF(f, epsPtr, headerPtr) |
| 814 |
FILE *f; |
| 815 |
{ |
| 816 |
HANDLE hMem; |
| 817 |
Tk_Window tkwin; |
| 818 |
|
| 819 |
if (fseek(f, headerPtr->wmfStart, 0) != 0) { |
| 820 |
Tcl_AppendResult(interp, "can't seek in \"", epsPtr->fileName, |
| 821 |
"\"", (char *)NULL); |
| 822 |
return TCL_ERROR; |
| 823 |
} |
| 824 |
hMem = GlobalAlloc(GHND, size); |
| 825 |
if (hMem == NULL) { |
| 826 |
Tcl_AppendResult(graphPtr->interp, "can't allocate global memory:", |
| 827 |
Blt_LastError(), (char *)NULL); |
| 828 |
return TCL_ERROR; |
| 829 |
} |
| 830 |
buffer = (LPVOID)GlobalLock(hMem); |
| 831 |
/* Read the header and see what kind of meta file it is. */ |
| 832 |
fread(buffer, sizeof(unsigned char), headerPtr->wmfLength, f); |
| 833 |
mfp.mm = 0; |
| 834 |
mfp.xExt = epsPtr->width; |
| 835 |
mfp.yExt = epsPtr->height; |
| 836 |
mfp.hMF = hMetaFile; |
| 837 |
tkwin = Tk_CanvasTkwin(epsPtr->canvas); |
| 838 |
hRefDC = TkWinGetDrawableDC(Tk_Display(tkwin), Tk_WindowId(tkwin), &state); |
| 839 |
hDC = CreateEnhMetaFile(hRefDC, NULL, NULL, NULL); |
| 840 |
mfp.hMF = CloseEnhMetaFile(hDC); |
| 841 |
hMetaFile = SetWinMetaFileBits(size, buffer, MM_ANISOTROPIC, &pict); |
| 842 |
Tcl_AppendResult(graphPtr->interp, "can't get metafile data:", |
| 843 |
Blt_LastError(), (char *)NULL); |
| 844 |
goto error; |
| 845 |
} |
| 846 |
#endif |
| 847 |
|
| 848 |
/* |
| 849 |
*---------------------------------------------------------------------- |
| 850 |
* |
| 851 |
* DeleteEps -- |
| 852 |
* |
| 853 |
* This procedure is called to clean up the data structure |
| 854 |
* associated with a EPS item. |
| 855 |
* |
| 856 |
* Results: |
| 857 |
* None. |
| 858 |
* |
| 859 |
* Side effects: |
| 860 |
* Resources associated with itemPtr are released. |
| 861 |
* |
| 862 |
*---------------------------------------------------------------------- |
| 863 |
*/ |
| 864 |
/*ARGSUSED*/ |
| 865 |
static void |
| 866 |
DeleteEps(canvas, itemPtr, display) |
| 867 |
Tk_Canvas canvas; /* Info about overall canvas widget. */ |
| 868 |
Tk_Item *itemPtr; /* Item that is being deleted. */ |
| 869 |
Display *display; /* Display containing window for |
| 870 |
* canvas. */ |
| 871 |
{ |
| 872 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 873 |
|
| 874 |
Tk_FreeOptions(configSpecs, (char *)epsPtr, display, 0); |
| 875 |
CloseEpsFile(epsPtr); |
| 876 |
if (epsPtr->colorImage != NULL) { |
| 877 |
Blt_FreeColorImage(epsPtr->colorImage); |
| 878 |
} |
| 879 |
if (epsPtr->preview != NULL) { |
| 880 |
Tk_FreeImage(epsPtr->preview); |
| 881 |
} |
| 882 |
if (epsPtr->previewName != NULL) { |
| 883 |
Blt_Free(epsPtr->previewName); |
| 884 |
} |
| 885 |
if (epsPtr->tmpImage != NULL) { |
| 886 |
Blt_DestroyTemporaryImage(epsPtr->interp, epsPtr->tmpImage); |
| 887 |
} |
| 888 |
if (epsPtr->pixmap != None) { |
| 889 |
#ifdef notyet |
| 890 |
Blt_FreeColorTable(epsPtr->colorTable); |
| 891 |
#endif |
| 892 |
Tk_FreePixmap(display, epsPtr->pixmap); |
| 893 |
} |
| 894 |
if (epsPtr->stipple != None) { |
| 895 |
Tk_FreePixmap(display, epsPtr->stipple); |
| 896 |
} |
| 897 |
if (epsPtr->fillGC != NULL) { |
| 898 |
Tk_FreeGC(display, epsPtr->fillGC); |
| 899 |
} |
| 900 |
Blt_FreeTextStyle(display, &(epsPtr->titleStyle)); |
| 901 |
|
| 902 |
if (epsPtr->title != NULL) { |
| 903 |
Blt_Free(epsPtr->title); |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
/* |
| 909 |
*---------------------------------------------------------------------- |
| 910 |
* |
| 911 |
* CreateEps -- |
| 912 |
* |
| 913 |
* This procedure is invoked to create a new EPS item |
| 914 |
* in a canvas. |
| 915 |
* |
| 916 |
* Results: |
| 917 |
* A standard Tcl return value. If an error occurred in |
| 918 |
* creating the item, then an error message is left in |
| 919 |
* interp->result; in this case itemPtr is left uninitialized, |
| 920 |
* so it can be safely freed by the caller. |
| 921 |
* |
| 922 |
* Side effects: |
| 923 |
* A new EPS item is created. |
| 924 |
* |
| 925 |
*---------------------------------------------------------------------- |
| 926 |
*/ |
| 927 |
#ifdef USE_OLD_CANVAS |
| 928 |
static int |
| 929 |
CreateEps(interp, canvas, itemPtr, argc, argv) |
| 930 |
Tcl_Interp *interp; /* Interpreter for error reporting. */ |
| 931 |
Tk_Canvas canvas; /* Canvas to hold new item. */ |
| 932 |
Tk_Item *itemPtr; /* Record to hold new item; header |
| 933 |
* has been initialized by caller. */ |
| 934 |
int argc; /* Number of arguments in argv. */ |
| 935 |
char **argv; /* Arguments describing rectangle. */ |
| 936 |
{ |
| 937 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 938 |
Tk_Window tkwin; |
| 939 |
|
| 940 |
tkwin = Tk_CanvasTkwin(canvas); |
| 941 |
if (argc < 2) { |
| 942 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 943 |
Tk_PathName(tkwin), " create ", itemPtr->typePtr->name, |
| 944 |
" x1 y1 ?options?\"", (char *)NULL); |
| 945 |
return TCL_ERROR; |
| 946 |
} |
| 947 |
/* |
| 948 |
* Initialize the item's record by hand (bleah). |
| 949 |
*/ |
| 950 |
epsPtr->anchor = TK_ANCHOR_NW; |
| 951 |
epsPtr->border = NULL; |
| 952 |
epsPtr->borderWidth = 2; |
| 953 |
epsPtr->canvas = canvas; |
| 954 |
epsPtr->fileName = NULL; |
| 955 |
epsPtr->psFile = NULL; |
| 956 |
epsPtr->fillGC = NULL; |
| 957 |
epsPtr->fillColor = NULL; |
| 958 |
epsPtr->colorImage = NULL; |
| 959 |
epsPtr->previewName = NULL; |
| 960 |
epsPtr->preview = NULL; |
| 961 |
epsPtr->interp = interp; |
| 962 |
epsPtr->tmpImage = NULL; |
| 963 |
epsPtr->pixmap = None; |
| 964 |
epsPtr->firstLine = epsPtr->lastLine = -1; |
| 965 |
epsPtr->relief = TK_RELIEF_SUNKEN; |
| 966 |
epsPtr->reqTitle = NULL; |
| 967 |
epsPtr->stipple = None; |
| 968 |
epsPtr->showImage = TRUE; |
| 969 |
epsPtr->quick = FALSE; |
| 970 |
epsPtr->title = NULL; |
| 971 |
epsPtr->lastWidth = epsPtr->lastHeight = 0; |
| 972 |
epsPtr->width = epsPtr->height = 0; |
| 973 |
epsPtr->x = epsPtr->y = 0.0; |
| 974 |
epsPtr->llx = epsPtr->lly = epsPtr->urx = epsPtr->ury = 0; |
| 975 |
epsPtr->canvasX = epsPtr->canvasY = 0; |
| 976 |
Tcl_DStringInit(&epsPtr->dString); |
| 977 |
memset(&(epsPtr->titleStyle), 0, sizeof(TextStyle)); |
| 978 |
#define PAD 8 |
| 979 |
epsPtr->titleStyle.padLeft = epsPtr->titleStyle.padRight = PAD; |
| 980 |
epsPtr->titleStyle.padTop = epsPtr->titleStyle.padBottom = PAD; |
| 981 |
|
| 982 |
/* |
| 983 |
* Process the arguments to fill in the item record. |
| 984 |
*/ |
| 985 |
|
| 986 |
if ((Tk_CanvasGetCoord(interp, canvas, argv[0], &(epsPtr->x)) != TCL_OK) || |
| 987 |
(Tk_CanvasGetCoord(interp, canvas, argv[1], &(epsPtr->y)) != TCL_OK)) { |
| 988 |
return TCL_ERROR; |
| 989 |
} |
| 990 |
if (ConfigureEps(interp, canvas, itemPtr, argc - 2, argv + 2, 0) |
| 991 |
!= TCL_OK) { |
| 992 |
DeleteEps(canvas, itemPtr, Tk_Display(tkwin)); |
| 993 |
return TCL_ERROR; |
| 994 |
} |
| 995 |
return TCL_OK; |
| 996 |
} |
| 997 |
#else |
| 998 |
static int |
| 999 |
CreateEps(interp, canvas, itemPtr, argc, objv) |
| 1000 |
Tcl_Interp *interp; /* Interpreter for error reporting. */ |
| 1001 |
Tk_Canvas canvas; /* Canvas to hold new item. */ |
| 1002 |
Tk_Item *itemPtr; /* Record to hold new item; header |
| 1003 |
* has been initialized by caller. */ |
| 1004 |
int argc; /* Number of arguments in argv. */ |
| 1005 |
Tcl_Obj *CONST *objv; /* Arguments describing rectangle. */ |
| 1006 |
{ |
| 1007 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1008 |
Tk_Window tkwin; |
| 1009 |
int i; |
| 1010 |
|
| 1011 |
tkwin = Tk_CanvasTkwin(canvas); |
| 1012 |
if (argc < 1) { |
| 1013 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1014 |
Tk_PathName(tkwin), " create ", itemPtr->typePtr->name, |
| 1015 |
" coords ?options?\"", (char *)NULL); |
| 1016 |
return TCL_ERROR; |
| 1017 |
} |
| 1018 |
/* |
| 1019 |
* Initialize the item's record by hand (bleah). |
| 1020 |
*/ |
| 1021 |
epsPtr->anchor = TK_ANCHOR_NW; |
| 1022 |
epsPtr->border = NULL; |
| 1023 |
epsPtr->borderWidth = 2; |
| 1024 |
epsPtr->canvas = canvas; |
| 1025 |
epsPtr->fileName = NULL; |
| 1026 |
epsPtr->psFile = NULL; |
| 1027 |
epsPtr->fillGC = NULL; |
| 1028 |
epsPtr->fillColor = NULL; |
| 1029 |
epsPtr->colorImage = NULL; |
| 1030 |
epsPtr->previewName = NULL; |
| 1031 |
epsPtr->preview = NULL; |
| 1032 |
epsPtr->interp = interp; |
| 1033 |
epsPtr->tmpImage = NULL; |
| 1034 |
epsPtr->pixmap = None; |
| 1035 |
epsPtr->firstLine = epsPtr->lastLine = -1; |
| 1036 |
epsPtr->relief = TK_RELIEF_SUNKEN; |
| 1037 |
epsPtr->reqTitle = NULL; |
| 1038 |
epsPtr->stipple = None; |
| 1039 |
epsPtr->showImage = TRUE; |
| 1040 |
epsPtr->quick = FALSE; |
| 1041 |
epsPtr->title = NULL; |
| 1042 |
epsPtr->lastWidth = epsPtr->lastHeight = 0; |
| 1043 |
epsPtr->width = epsPtr->height = 0; |
| 1044 |
epsPtr->x = epsPtr->y = 0.0; |
| 1045 |
epsPtr->llx = epsPtr->lly = epsPtr->urx = epsPtr->ury = 0; |
| 1046 |
epsPtr->canvasX = epsPtr->canvasY = 0; |
| 1047 |
Tcl_DStringInit(&epsPtr->dString); |
| 1048 |
memset(&(epsPtr->titleStyle), 0, sizeof(TextStyle)); |
| 1049 |
#define PAD 8 |
| 1050 |
epsPtr->titleStyle.padLeft = epsPtr->titleStyle.padRight = PAD; |
| 1051 |
epsPtr->titleStyle.padTop = epsPtr->titleStyle.padBottom = PAD; |
| 1052 |
|
| 1053 |
/* |
| 1054 |
* Process the arguments to fill in the item record. |
| 1055 |
*/ |
| 1056 |
|
| 1057 |
if (argc == 1) { |
| 1058 |
i = 1; |
| 1059 |
} else { |
| 1060 |
char *arg = Tcl_GetString(objv[1]); |
| 1061 |
i = 2; |
| 1062 |
if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { |
| 1063 |
i = 1; |
| 1064 |
} |
| 1065 |
} |
| 1066 |
if ((EpsCoords(interp, canvas, itemPtr, i, objv) != TCL_OK)) { |
| 1067 |
return TCL_ERROR; |
| 1068 |
} |
| 1069 |
|
| 1070 |
if (ConfigureEps(interp, canvas, itemPtr, argc - i, objv + i, 0) |
| 1071 |
!= TCL_OK) { |
| 1072 |
DeleteEps(canvas, itemPtr, Tk_Display(tkwin)); |
| 1073 |
return TCL_ERROR; |
| 1074 |
} |
| 1075 |
return TCL_OK; |
| 1076 |
} |
| 1077 |
#endif |
| 1078 |
|
| 1079 |
/* |
| 1080 |
*---------------------------------------------------------------------- |
| 1081 |
* |
| 1082 |
* ImageChangedProc |
| 1083 |
* |
| 1084 |
* The image is over-written each time the EPS item is resized. |
| 1085 |
* So we only worry if the image is deleted. |
| 1086 |
* |
| 1087 |
* We always resample from the color image we saved when the |
| 1088 |
* photo image was specified (-image option). |
| 1089 |
* |
| 1090 |
* Results: |
| 1091 |
* None. |
| 1092 |
* |
| 1093 |
*---------------------------------------------------------------------- |
| 1094 |
*/ |
| 1095 |
/* ARGSUSED */ |
| 1096 |
static void |
| 1097 |
ImageChangedProc(clientData, x, y, width, height, imageWidth, imageHeight) |
| 1098 |
ClientData clientData; |
| 1099 |
int x, y, width, height; /* Not used. */ |
| 1100 |
int imageWidth, imageHeight;/* Not used. */ |
| 1101 |
{ |
| 1102 |
EpsItem *epsPtr = clientData; |
| 1103 |
|
| 1104 |
if ((epsPtr->preview == NULL) || (Tk_ImageIsDeleted(epsPtr->preview))) { |
| 1105 |
epsPtr->preview = NULL; |
| 1106 |
if (epsPtr->previewName != NULL) { |
| 1107 |
Blt_Free(epsPtr->previewName); |
| 1108 |
epsPtr->previewName = NULL; |
| 1109 |
} |
| 1110 |
Tk_CanvasEventuallyRedraw(epsPtr->canvas, epsPtr->xLeft, epsPtr->yTop, |
| 1111 |
epsPtr->xRight, epsPtr->yBottom); |
| 1112 |
} |
| 1113 |
} |
| 1114 |
|
| 1115 |
/* |
| 1116 |
*---------------------------------------------------------------------- |
| 1117 |
* |
| 1118 |
* ConfigureEps -- |
| 1119 |
* |
| 1120 |
* This procedure is invoked to configure various aspects |
| 1121 |
* of an EPS item, such as its background color. |
| 1122 |
* |
| 1123 |
* Results: |
| 1124 |
* A standard Tcl result code. If an error occurs, then |
| 1125 |
* an error message is left in interp->result. |
| 1126 |
* |
| 1127 |
* Side effects: |
| 1128 |
* Configuration information may be set for itemPtr. |
| 1129 |
* |
| 1130 |
*---------------------------------------------------------------------- |
| 1131 |
*/ |
| 1132 |
#ifdef USE_OLD_CANVAS |
| 1133 |
static int |
| 1134 |
ConfigureEps(interp, canvas, itemPtr, argc, argv, flags) |
| 1135 |
Tcl_Interp *interp; /* Used for error reporting. */ |
| 1136 |
Tk_Canvas canvas; /* Canvas containing itemPtr. */ |
| 1137 |
Tk_Item *itemPtr; /* EPS item to reconfigure. */ |
| 1138 |
int argc; /* Number of elements in argv. */ |
| 1139 |
char **argv; /* Arguments describing things to configure. */ |
| 1140 |
int flags; /* Flags to pass to Tk_ConfigureWidget. */ |
| 1141 |
{ |
| 1142 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1143 |
Tk_Window tkwin; |
| 1144 |
XGCValues gcValues; |
| 1145 |
unsigned long gcMask; |
| 1146 |
GC newGC; |
| 1147 |
int width, height; |
| 1148 |
|
| 1149 |
tkwin = Tk_CanvasTkwin(canvas); |
| 1150 |
if (Blt_ConfigureWidget(interp, tkwin, configSpecs, argc, |
| 1151 |
argv, (char *)epsPtr, flags) != TCL_OK) { |
| 1152 |
return TCL_ERROR; |
| 1153 |
} |
| 1154 |
/* Determine the size of the EPS item */ |
| 1155 |
width = height = 0; |
| 1156 |
/* |
| 1157 |
* Check for a "-image" option specifying an image to be displayed |
| 1158 |
* representing the EPS canvas item. |
| 1159 |
*/ |
| 1160 |
if (Blt_ConfigModified(configSpecs, interp, "-image", (char *)NULL)) { |
| 1161 |
if (epsPtr->preview != NULL) { |
| 1162 |
Tk_FreeImage(epsPtr->preview); /* Release old Tk image */ |
| 1163 |
Blt_FreeColorImage(epsPtr->colorImage); |
| 1164 |
epsPtr->preview = NULL; |
| 1165 |
epsPtr->colorImage = NULL; |
| 1166 |
} |
| 1167 |
if (epsPtr->previewName != NULL) { |
| 1168 |
Tk_PhotoHandle photo; /* Photo handle to Tk image. */ |
| 1169 |
/* |
| 1170 |
* Allocate a new image, if one was named. |
| 1171 |
*/ |
| 1172 |
photo = Blt_FindPhoto(interp, epsPtr->previewName); |
| 1173 |
if (photo == NULL) { |
| 1174 |
Tcl_AppendResult(interp, "image \"", epsPtr->previewName, |
| 1175 |
"\" doesn't exist or is not a photo image", |
| 1176 |
(char *)NULL); |
| 1177 |
return TCL_ERROR; |
| 1178 |
} |
| 1179 |
epsPtr->preview = Tk_GetImage(interp, tkwin, epsPtr->previewName, |
| 1180 |
ImageChangedProc, epsPtr); |
| 1181 |
if (epsPtr->preview == NULL) { |
| 1182 |
Tcl_AppendResult(interp, "can't find an image \"", |
| 1183 |
epsPtr->previewName, "\"", (char *)NULL); |
| 1184 |
Blt_Free(epsPtr->previewName); |
| 1185 |
epsPtr->previewName = NULL; |
| 1186 |
return TCL_ERROR; |
| 1187 |
} |
| 1188 |
epsPtr->colorImage = Blt_PhotoToColorImage(photo); |
| 1189 |
width = Blt_ColorImageWidth(epsPtr->colorImage); |
| 1190 |
height = Blt_ColorImageHeight(epsPtr->colorImage); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
if (Blt_ConfigModified(configSpecs, interp, "-file", (char *)NULL)) { |
| 1194 |
CloseEpsFile(epsPtr); |
| 1195 |
if (epsPtr->pixmap != None) { |
| 1196 |
#ifdef notyet |
| 1197 |
Blt_FreeColorTable(epsPtr->colorTable); |
| 1198 |
#endif |
| 1199 |
Tk_FreePixmap(Tk_Display(tkwin), epsPtr->pixmap); |
| 1200 |
epsPtr->pixmap = None; |
| 1201 |
} |
| 1202 |
if (epsPtr->colorImage != NULL) { |
| 1203 |
Blt_FreeColorImage(epsPtr->colorImage); |
| 1204 |
epsPtr->colorImage = NULL; |
| 1205 |
} |
| 1206 |
epsPtr->firstLine = epsPtr->lastLine = -1; |
| 1207 |
if (epsPtr->fileName != NULL) { |
| 1208 |
if (OpenEpsFile(interp, epsPtr) != TCL_OK) { |
| 1209 |
return TCL_ERROR; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
} |
| 1213 |
if ((epsPtr->colorImage != NULL) && (epsPtr->tmpImage == NULL)) { |
| 1214 |
epsPtr->tmpImage = Blt_CreateTemporaryImage(interp, tkwin, epsPtr); |
| 1215 |
if (epsPtr->tmpImage == NULL) { |
| 1216 |
return TCL_ERROR; |
| 1217 |
} |
| 1218 |
} else if ((epsPtr->colorImage == NULL) && (epsPtr->tmpImage != NULL)) { |
| 1219 |
Blt_DestroyTemporaryImage(epsPtr->interp, epsPtr->tmpImage); |
| 1220 |
} |
| 1221 |
if (epsPtr->preview != NULL) { |
| 1222 |
Tk_SizeOfImage(epsPtr->preview, &width, &height); |
| 1223 |
} |
| 1224 |
if (epsPtr->width == 0) { |
| 1225 |
if (epsPtr->fileName != NULL) { |
| 1226 |
width = (epsPtr->urx - epsPtr->llx); |
| 1227 |
} |
| 1228 |
epsPtr->width = width; |
| 1229 |
} |
| 1230 |
if (epsPtr->height == 0) { |
| 1231 |
if (epsPtr->fileName != NULL) { |
| 1232 |
height = (epsPtr->ury - epsPtr->lly); |
| 1233 |
} |
| 1234 |
epsPtr->height = height; |
| 1235 |
} |
| 1236 |
Blt_ResetTextStyle(tkwin, &(epsPtr->titleStyle)); |
| 1237 |
|
| 1238 |
if (Blt_ConfigModified(configSpecs, interp, "-quick", (char *)NULL)) { |
| 1239 |
epsPtr->lastWidth = epsPtr->lastHeight = 0; |
| 1240 |
} |
| 1241 |
/* Fill color GC */ |
| 1242 |
|
| 1243 |
newGC = NULL; |
| 1244 |
if (epsPtr->fillColor != NULL) { |
| 1245 |
gcMask = GCForeground; |
| 1246 |
gcValues.foreground = epsPtr->fillColor->pixel; |
| 1247 |
if (epsPtr->stipple != None) { |
| 1248 |
gcMask |= (GCStipple | GCFillStyle); |
| 1249 |
gcValues.stipple = epsPtr->stipple; |
| 1250 |
if (epsPtr->border != NULL) { |
| 1251 |
gcValues.foreground = Tk_3DBorderColor(epsPtr->border)->pixel; |
| 1252 |
gcValues.background = epsPtr->fillColor->pixel; |
| 1253 |
gcMask |= GCBackground; |
| 1254 |
gcValues.fill_style = FillOpaqueStippled; |
| 1255 |
} else { |
| 1256 |
gcValues.fill_style = FillStippled; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
newGC = Tk_GetGC(tkwin, gcMask, &gcValues); |
| 1260 |
} |
| 1261 |
if (epsPtr->fillGC != NULL) { |
| 1262 |
Tk_FreeGC(Tk_Display(tkwin), epsPtr->fillGC); |
| 1263 |
} |
| 1264 |
epsPtr->fillGC = newGC; |
| 1265 |
CloseEpsFile(epsPtr); |
| 1266 |
ComputeEpsBbox(canvas, epsPtr); |
| 1267 |
return TCL_OK; |
| 1268 |
} |
| 1269 |
#else |
| 1270 |
static int |
| 1271 |
ConfigureEps(interp, canvas, itemPtr, argc, objv, flags) |
| 1272 |
Tcl_Interp *interp; /* Used for error reporting. */ |
| 1273 |
Tk_Canvas canvas; /* Canvas containing itemPtr. */ |
| 1274 |
Tk_Item *itemPtr; /* EPS item to reconfigure. */ |
| 1275 |
int argc; /* Number of elements in argv. */ |
| 1276 |
Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ |
| 1277 |
int flags; /* Flags to pass to Tk_ConfigureWidget. */ |
| 1278 |
{ |
| 1279 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1280 |
Tk_Window tkwin; |
| 1281 |
XGCValues gcValues; |
| 1282 |
unsigned long gcMask; |
| 1283 |
GC newGC; |
| 1284 |
int width, height, i; |
| 1285 |
char **argv; |
| 1286 |
|
| 1287 |
tkwin = Tk_CanvasTkwin(canvas); |
| 1288 |
argv = (char**)ckalloc((argc+1)*sizeof(char*)); |
| 1289 |
for (i=0; i<argc; i++) { |
| 1290 |
argv[i] = Tcl_GetString(objv[i]); |
| 1291 |
} |
| 1292 |
argv[i] = 0; |
| 1293 |
if (Tk_ConfigureWidget(interp, tkwin, configSpecs, argc, |
| 1294 |
argv, (char *)epsPtr, flags) != TCL_OK) { |
| 1295 |
ckfree((char*)argv); |
| 1296 |
return TCL_ERROR; |
| 1297 |
} |
| 1298 |
ckfree((char*)argv); |
| 1299 |
/* Determine the size of the EPS item */ |
| 1300 |
width = height = 0; |
| 1301 |
/* |
| 1302 |
* Check for a "-image" option specifying an image to be displayed |
| 1303 |
* representing the EPS canvas item. |
| 1304 |
*/ |
| 1305 |
if (Blt_ConfigModified(configSpecs, interp, "-image", (char *)NULL)) { |
| 1306 |
if (epsPtr->preview != NULL) { |
| 1307 |
Tk_FreeImage(epsPtr->preview); /* Release old Tk image */ |
| 1308 |
Blt_FreeColorImage(epsPtr->colorImage); |
| 1309 |
epsPtr->preview = NULL; |
| 1310 |
epsPtr->colorImage = NULL; |
| 1311 |
} |
| 1312 |
if (epsPtr->previewName != NULL) { |
| 1313 |
Tk_PhotoHandle photo; /* Photo handle to Tk image. */ |
| 1314 |
/* |
| 1315 |
* Allocate a new image, if one was named. |
| 1316 |
*/ |
| 1317 |
photo = Blt_FindPhoto(interp, epsPtr->previewName); |
| 1318 |
if (photo == NULL) { |
| 1319 |
Tcl_AppendResult(interp, "image \"", epsPtr->previewName, |
| 1320 |
"\" doesn't exist or is not a photo image", |
| 1321 |
(char *)NULL); |
| 1322 |
return TCL_ERROR; |
| 1323 |
} |
| 1324 |
epsPtr->preview = Tk_GetImage(interp, tkwin, epsPtr->previewName, |
| 1325 |
ImageChangedProc, epsPtr); |
| 1326 |
if (epsPtr->preview == NULL) { |
| 1327 |
Tcl_AppendResult(interp, "can't find an image \"", |
| 1328 |
epsPtr->previewName, "\"", (char *)NULL); |
| 1329 |
Blt_Free(epsPtr->previewName); |
| 1330 |
epsPtr->previewName = NULL; |
| 1331 |
return TCL_ERROR; |
| 1332 |
} |
| 1333 |
epsPtr->colorImage = Blt_PhotoToColorImage(photo); |
| 1334 |
width = Blt_ColorImageWidth(epsPtr->colorImage); |
| 1335 |
height = Blt_ColorImageHeight(epsPtr->colorImage); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
if (Blt_ConfigModified(configSpecs, interp, "-file", (char *)NULL)) { |
| 1339 |
CloseEpsFile(epsPtr); |
| 1340 |
if (epsPtr->pixmap != None) { |
| 1341 |
#ifdef notyet |
| 1342 |
Blt_FreeColorTable(epsPtr->colorTable); |
| 1343 |
#endif |
| 1344 |
Tk_FreePixmap(Tk_Display(tkwin), epsPtr->pixmap); |
| 1345 |
epsPtr->pixmap = None; |
| 1346 |
} |
| 1347 |
if (epsPtr->colorImage != NULL) { |
| 1348 |
Blt_FreeColorImage(epsPtr->colorImage); |
| 1349 |
epsPtr->colorImage = NULL; |
| 1350 |
} |
| 1351 |
epsPtr->firstLine = epsPtr->lastLine = -1; |
| 1352 |
if (epsPtr->fileName != NULL) { |
| 1353 |
if (OpenEpsFile(interp, epsPtr) != TCL_OK) { |
| 1354 |
return TCL_ERROR; |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
if ((epsPtr->colorImage != NULL) && (epsPtr->tmpImage == NULL)) { |
| 1359 |
epsPtr->tmpImage = Blt_CreateTemporaryImage(interp, tkwin, epsPtr); |
| 1360 |
if (epsPtr->tmpImage == NULL) { |
| 1361 |
return TCL_ERROR; |
| 1362 |
} |
| 1363 |
} else if ((epsPtr->colorImage == NULL) && (epsPtr->tmpImage != NULL)) { |
| 1364 |
Blt_DestroyTemporaryImage(epsPtr->interp, epsPtr->tmpImage); |
| 1365 |
} |
| 1366 |
if (epsPtr->preview != NULL) { |
| 1367 |
Tk_SizeOfImage(epsPtr->preview, &width, &height); |
| 1368 |
} |
| 1369 |
if (epsPtr->width == 0) { |
| 1370 |
if (epsPtr->fileName != NULL) { |
| 1371 |
width = (epsPtr->urx - epsPtr->llx); |
| 1372 |
} |
| 1373 |
epsPtr->width = width; |
| 1374 |
} |
| 1375 |
if (epsPtr->height == 0) { |
| 1376 |
if (epsPtr->fileName != NULL) { |
| 1377 |
height = (epsPtr->ury - epsPtr->lly); |
| 1378 |
} |
| 1379 |
epsPtr->height = height; |
| 1380 |
} |
| 1381 |
Blt_ResetTextStyle(tkwin, &(epsPtr->titleStyle)); |
| 1382 |
|
| 1383 |
if (Blt_ConfigModified(configSpecs, interp, "-quick", (char *)NULL)) { |
| 1384 |
epsPtr->lastWidth = epsPtr->lastHeight = 0; |
| 1385 |
} |
| 1386 |
/* Fill color GC */ |
| 1387 |
|
| 1388 |
newGC = NULL; |
| 1389 |
if (epsPtr->fillColor != NULL) { |
| 1390 |
gcMask = GCForeground; |
| 1391 |
gcValues.foreground = epsPtr->fillColor->pixel; |
| 1392 |
if (epsPtr->stipple != None) { |
| 1393 |
gcMask |= (GCStipple | GCFillStyle); |
| 1394 |
gcValues.stipple = epsPtr->stipple; |
| 1395 |
if (epsPtr->border != NULL) { |
| 1396 |
gcValues.foreground = Tk_3DBorderColor(epsPtr->border)->pixel; |
| 1397 |
gcValues.background = epsPtr->fillColor->pixel; |
| 1398 |
gcMask |= GCBackground; |
| 1399 |
gcValues.fill_style = FillOpaqueStippled; |
| 1400 |
} else { |
| 1401 |
gcValues.fill_style = FillStippled; |
| 1402 |
} |
| 1403 |
} |
| 1404 |
newGC = Tk_GetGC(tkwin, gcMask, &gcValues); |
| 1405 |
} |
| 1406 |
if (epsPtr->fillGC != NULL) { |
| 1407 |
Tk_FreeGC(Tk_Display(tkwin), epsPtr->fillGC); |
| 1408 |
} |
| 1409 |
epsPtr->fillGC = newGC; |
| 1410 |
CloseEpsFile(epsPtr); |
| 1411 |
ComputeEpsBbox(canvas, epsPtr); |
| 1412 |
return TCL_OK; |
| 1413 |
} |
| 1414 |
#endif |
| 1415 |
/* |
| 1416 |
*---------------------------------------------------------------------- |
| 1417 |
* |
| 1418 |
* EpsCoords -- |
| 1419 |
* |
| 1420 |
* This procedure is invoked to process the "coords" widget |
| 1421 |
* command on EPS items. See the user documentation for |
| 1422 |
* details on what it does. |
| 1423 |
* |
| 1424 |
* Results: |
| 1425 |
* Returns TCL_OK or TCL_ERROR, and sets interp->result. |
| 1426 |
* |
| 1427 |
* Side effects: |
| 1428 |
* The coordinates for the given item may be changed. |
| 1429 |
* |
| 1430 |
*---------------------------------------------------------------------- |
| 1431 |
*/ |
| 1432 |
#ifdef USE_OLD_CANVAS |
| 1433 |
static int |
| 1434 |
EpsCoords(interp, canvas, itemPtr, argc, argv) |
| 1435 |
Tcl_Interp *interp; /* Used for error reporting. */ |
| 1436 |
Tk_Canvas canvas; /* Canvas containing item. */ |
| 1437 |
Tk_Item *itemPtr; /* Item whose coordinates are to be |
| 1438 |
* read or modified. */ |
| 1439 |
int argc; /* Number of coordinates supplied in |
| 1440 |
* argv. */ |
| 1441 |
char **argv; /* Array of coordinates: x1, y1, |
| 1442 |
* x2, y2, ... */ |
| 1443 |
{ |
| 1444 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1445 |
|
| 1446 |
if ((argc != 0) && (argc != 2)) { |
| 1447 |
Tcl_AppendResult(interp, "wrong # coordinates: expected 0 or 2, got ", |
| 1448 |
Blt_Itoa(argc), (char *)NULL); |
| 1449 |
return TCL_ERROR; |
| 1450 |
} |
| 1451 |
|
| 1452 |
if (argc == 2) { |
| 1453 |
double x, y; /* Don't overwrite old coordinates on errors */ |
| 1454 |
|
| 1455 |
if ((Tk_CanvasGetCoord(interp, canvas, argv[0], &x) != TCL_OK) || |
| 1456 |
(Tk_CanvasGetCoord(interp, canvas, argv[1], &y) != TCL_OK)) { |
| 1457 |
return TCL_ERROR; |
| 1458 |
} |
| 1459 |
epsPtr->x = x; |
| 1460 |
epsPtr->y = y; |
| 1461 |
ComputeEpsBbox(canvas, epsPtr); |
| 1462 |
return TCL_OK; |
| 1463 |
} |
| 1464 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, epsPtr->x)); |
| 1465 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, epsPtr->y)); |
| 1466 |
return TCL_OK; |
| 1467 |
} |
| 1468 |
#else |
| 1469 |
static int |
| 1470 |
EpsCoords(interp, canvas, itemPtr, argc, objv) |
| 1471 |
Tcl_Interp *interp; /* Used for error reporting. */ |
| 1472 |
Tk_Canvas canvas; /* Canvas containing item. */ |
| 1473 |
Tk_Item *itemPtr; /* Item whose coordinates are to be |
| 1474 |
* read or modified. */ |
| 1475 |
int argc; /* Number of coordinates supplied in |
| 1476 |
* argv. */ |
| 1477 |
Tcl_Obj *CONST objv[]; /* Array of coordinates: x1, y1, |
| 1478 |
* x2, y2, ... */ |
| 1479 |
{ |
| 1480 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1481 |
|
| 1482 |
if (argc > 2) { |
| 1483 |
Tcl_AppendResult(interp, "wrong # coordinates: expected 0, 1, or 2, got ", |
| 1484 |
Blt_Itoa(argc), (char *)NULL); |
| 1485 |
return TCL_ERROR; |
| 1486 |
} |
| 1487 |
if (argc==1) { |
| 1488 |
if (Tcl_ListObjGetElements(interp, objv[0], &argc, |
| 1489 |
(Tcl_Obj ***) &objv) != TCL_OK) { |
| 1490 |
return TCL_ERROR; |
| 1491 |
} else if (argc != 2) { |
| 1492 |
char buf[64]; |
| 1493 |
|
| 1494 |
sprintf(buf, "wrong # coordinates: expected 2, got %d", argc); |
| 1495 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 1496 |
return TCL_ERROR; |
| 1497 |
} |
| 1498 |
} |
| 1499 |
if (argc == 2) { |
| 1500 |
double x, y; /* Don't overwrite old coordinates on errors */ |
| 1501 |
|
| 1502 |
if ((Tk_CanvasGetCoord(interp, canvas, Tcl_GetString(objv[0]), &x) != TCL_OK) || |
| 1503 |
(Tk_CanvasGetCoord(interp, canvas, Tcl_GetString(objv[1]), &y) != TCL_OK)) { |
| 1504 |
return TCL_ERROR; |
| 1505 |
} |
| 1506 |
epsPtr->x = x; |
| 1507 |
epsPtr->y = y; |
| 1508 |
ComputeEpsBbox(canvas, epsPtr); |
| 1509 |
return TCL_OK; |
| 1510 |
} |
| 1511 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, epsPtr->x)); |
| 1512 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, epsPtr->y)); |
| 1513 |
return TCL_OK; |
| 1514 |
} |
| 1515 |
#endif |
| 1516 |
|
| 1517 |
/* |
| 1518 |
*---------------------------------------------------------------------- |
| 1519 |
* |
| 1520 |
* ComputeEpsBbox -- |
| 1521 |
* |
| 1522 |
* This procedure is invoked to compute the bounding box of |
| 1523 |
* all the pixels that may be drawn as part of a EPS item. |
| 1524 |
* This procedure is where the preview image's placement is |
| 1525 |
* computed. |
| 1526 |
* |
| 1527 |
* Results: |
| 1528 |
* None. |
| 1529 |
* |
| 1530 |
* Side effects: |
| 1531 |
* The fields x1, y1, x2, and y2 are updated in the header |
| 1532 |
* for itemPtr. |
| 1533 |
* |
| 1534 |
*---------------------------------------------------------------------- |
| 1535 |
*/ |
| 1536 |
/* ARGSUSED */ |
| 1537 |
static void |
| 1538 |
ComputeEpsBbox(canvas, epsPtr) |
| 1539 |
Tk_Canvas canvas; /* Canvas that contains item. */ |
| 1540 |
EpsItem *epsPtr; /* Item whose bbox is to be recomputed. */ |
| 1541 |
{ |
| 1542 |
int x, y; |
| 1543 |
|
| 1544 |
x = ROUND(epsPtr->x), y = ROUND(epsPtr->y); |
| 1545 |
Blt_TranslateAnchor(x, y, epsPtr->width, epsPtr->height, epsPtr->anchor, |
| 1546 |
&x, &y); |
| 1547 |
epsPtr->xLeft = epsPtr->canvasX = x; |
| 1548 |
epsPtr->yTop = epsPtr->canvasY = y; |
| 1549 |
|
| 1550 |
/* |
| 1551 |
* The right and bottom are (weirdly) exterior to the item. Can't |
| 1552 |
* complain much since it's documented in the Tk_CreateItemType |
| 1553 |
* manual page. |
| 1554 |
* |
| 1555 |
* "These fields give a bounding box for the items using integer |
| 1556 |
* canvas coordinates: the item should not cover any pixels with |
| 1557 |
* x-coordinate lower than x1 or y-coordinate lower than y1, nor |
| 1558 |
* should it cover any pixels with x-coordinate greater than or |
| 1559 |
* equal to x2 or y-coordinate greater than or equal to y2." |
| 1560 |
*/ |
| 1561 |
epsPtr->xRight = x + epsPtr->width; |
| 1562 |
epsPtr->yBottom = y + epsPtr->height; |
| 1563 |
} |
| 1564 |
|
| 1565 |
/* |
| 1566 |
*---------------------------------------------------------------------- |
| 1567 |
* |
| 1568 |
* DisplayEps -- |
| 1569 |
* |
| 1570 |
* This procedure is invoked to draw the EPS item in a |
| 1571 |
* given drawable. The EPS item may be drawn as either |
| 1572 |
* a solid rectangle or a pixmap of the preview image. |
| 1573 |
* |
| 1574 |
* Results: |
| 1575 |
* None. |
| 1576 |
* |
| 1577 |
* Side effects: |
| 1578 |
* ItemPtr is drawn in drawable using the transformation |
| 1579 |
* information in canvas. |
| 1580 |
* |
| 1581 |
*---------------------------------------------------------------------- |
| 1582 |
*/ |
| 1583 |
static void |
| 1584 |
DisplayEps(canvas, itemPtr, display, drawable, x, y, width, height) |
| 1585 |
Tk_Canvas canvas; /* Canvas that contains item. */ |
| 1586 |
Tk_Item *itemPtr; /* Item to be displayed. */ |
| 1587 |
Display *display; /* Display on which to draw item. */ |
| 1588 |
Drawable drawable; /* Pixmap or window in which to draw |
| 1589 |
* item. */ |
| 1590 |
int x, y, width, height; /* Describes region of canvas that |
| 1591 |
* must be redisplayed (not used). */ |
| 1592 |
{ |
| 1593 |
Tk_Window tkwin; |
| 1594 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1595 |
short int drawableX, drawableY; |
| 1596 |
char *title; |
| 1597 |
int twiceBW; |
| 1598 |
int noImage; |
| 1599 |
|
| 1600 |
if ((epsPtr->width < 1) || (epsPtr->height < 1)) { |
| 1601 |
return; |
| 1602 |
} |
| 1603 |
tkwin = Tk_CanvasTkwin(canvas); |
| 1604 |
epsPtr->showImage = TRUE; |
| 1605 |
if ((epsPtr->showImage) && (epsPtr->colorImage != NULL) && |
| 1606 |
((epsPtr->lastWidth != epsPtr->width) || |
| 1607 |
(epsPtr->lastHeight != epsPtr->height))) { |
| 1608 |
Blt_ColorImage image; |
| 1609 |
|
| 1610 |
if (epsPtr->quick) { |
| 1611 |
image = Blt_ResizeColorImage(epsPtr->colorImage, 0, 0, |
| 1612 |
Blt_ColorImageWidth(epsPtr->colorImage), |
| 1613 |
Blt_ColorImageHeight(epsPtr->colorImage), |
| 1614 |
epsPtr->width, epsPtr->height); |
| 1615 |
} else { |
| 1616 |
image = Blt_ResampleColorImage(epsPtr->colorImage, epsPtr->width, |
| 1617 |
epsPtr->height, bltBoxFilterPtr, bltBoxFilterPtr); |
| 1618 |
} |
| 1619 |
if (epsPtr->tmpImage != NULL) { |
| 1620 |
Tk_PhotoHandle photo; |
| 1621 |
/* |
| 1622 |
* Resize the Tk photo image used to represent the EPS item. |
| 1623 |
* We will over-write the temporary image with a resampled one. |
| 1624 |
*/ |
| 1625 |
photo = Blt_FindPhoto(epsPtr->interp, |
| 1626 |
Blt_NameOfImage(epsPtr->tmpImage)); |
| 1627 |
Blt_ColorImageToPhoto(image, photo); |
| 1628 |
} else { |
| 1629 |
#ifdef notyet |
| 1630 |
epsPtr->pixmap = Blt_ColorImageToPixmap(epsPtr->interp, tkwin, |
| 1631 |
image, &(epsPtr->colorTable)); |
| 1632 |
#endif |
| 1633 |
} |
| 1634 |
epsPtr->lastHeight = epsPtr->height; |
| 1635 |
epsPtr->lastWidth = epsPtr->width; |
| 1636 |
Blt_FreeColorImage(image); |
| 1637 |
} |
| 1638 |
/* |
| 1639 |
* Translate the coordinates to those of the EPS item, then redisplay it. |
| 1640 |
*/ |
| 1641 |
Tk_CanvasDrawableCoords(canvas, (double)epsPtr->canvasX, |
| 1642 |
(double)epsPtr->canvasY, &drawableX, &drawableY); |
| 1643 |
x = (int)drawableX; |
| 1644 |
y = (int)drawableY; |
| 1645 |
|
| 1646 |
twiceBW = epsPtr->borderWidth * 2; |
| 1647 |
title = epsPtr->title; |
| 1648 |
|
| 1649 |
if (epsPtr->reqTitle != NULL) { |
| 1650 |
title = epsPtr->reqTitle; |
| 1651 |
} |
| 1652 |
width = epsPtr->width; |
| 1653 |
height = epsPtr->height; |
| 1654 |
noImage = ((!epsPtr->showImage) || ((epsPtr->tmpImage == NULL) && |
| 1655 |
(epsPtr->pixmap == None))); |
| 1656 |
if (noImage) { |
| 1657 |
if ((twiceBW >= width) || (twiceBW >= height)) { |
| 1658 |
return; |
| 1659 |
} |
| 1660 |
width -= twiceBW; |
| 1661 |
height -= twiceBW; |
| 1662 |
if (epsPtr->fillGC != NULL) { |
| 1663 |
XSetTSOrigin(display, epsPtr->fillGC, x, y); |
| 1664 |
XFillRectangle(display, drawable, epsPtr->fillGC, x, y, |
| 1665 |
epsPtr->width, epsPtr->height); |
| 1666 |
XSetTSOrigin(display, epsPtr->fillGC, 0, 0); |
| 1667 |
} |
| 1668 |
} else { |
| 1669 |
if (epsPtr->pixmap != None) { |
| 1670 |
XCopyArea(Tk_Display(tkwin), epsPtr->pixmap, drawable, |
| 1671 |
epsPtr->fillGC, 0, 0, width, height, x, y); |
| 1672 |
} else { |
| 1673 |
Tk_RedrawImage(epsPtr->tmpImage, 0, 0, width, height, drawable, |
| 1674 |
x, y); |
| 1675 |
} |
| 1676 |
} |
| 1677 |
|
| 1678 |
if (title != NULL) { |
| 1679 |
TextLayout *textPtr; |
| 1680 |
double rotWidth, rotHeight; |
| 1681 |
int destWidth, destHeight; |
| 1682 |
|
| 1683 |
/* Translate the title to an anchor position within the EPS item */ |
| 1684 |
textPtr = Blt_GetTextLayout(title, &(epsPtr->titleStyle)); |
| 1685 |
Blt_GetBoundingBox(textPtr->width, textPtr->height, |
| 1686 |
epsPtr->titleStyle.theta, &rotWidth, &rotHeight, (Point2D *)NULL); |
| 1687 |
destWidth = (int)ceil(rotWidth); |
| 1688 |
destHeight = (int)ceil(rotHeight); |
| 1689 |
if ((destWidth <= width) && (destHeight <= height)) { |
| 1690 |
int titleX, titleY; |
| 1691 |
|
| 1692 |
Blt_TranslateAnchor(x, y, width, height, epsPtr->titleStyle.anchor, |
| 1693 |
&titleX, &titleY); |
| 1694 |
if (noImage) { |
| 1695 |
titleX += epsPtr->borderWidth; |
| 1696 |
titleY += epsPtr->borderWidth; |
| 1697 |
} |
| 1698 |
Blt_DrawTextLayout(tkwin, drawable, textPtr, &(epsPtr->titleStyle), |
| 1699 |
titleX, titleY); |
| 1700 |
} |
| 1701 |
Blt_Free(textPtr); |
| 1702 |
} |
| 1703 |
if ((noImage) && (epsPtr->border != NULL)) { |
| 1704 |
Blt_Draw3DRectangle(tkwin, drawable, epsPtr->border, x, y, |
| 1705 |
epsPtr->width, epsPtr->height, epsPtr->borderWidth, epsPtr->relief); |
| 1706 |
} |
| 1707 |
} |
| 1708 |
|
| 1709 |
/* |
| 1710 |
*---------------------------------------------------------------------- |
| 1711 |
* |
| 1712 |
* EpsToPoint -- |
| 1713 |
* |
| 1714 |
* Computes the distance from a given point to a given |
| 1715 |
* rectangle, in canvas units. |
| 1716 |
* |
| 1717 |
* Results: |
| 1718 |
* The return value is 0 if the point whose x and y coordinates |
| 1719 |
* are coordPtr[0] and coordPtr[1] is inside the EPS item. If the |
| 1720 |
* point isn't inside the item then the return value is the |
| 1721 |
* distance from the point to the EPS item. |
| 1722 |
* |
| 1723 |
* Side effects: |
| 1724 |
* None. |
| 1725 |
* |
| 1726 |
*---------------------------------------------------------------------- |
| 1727 |
*/ |
| 1728 |
/*ARGSUSED*/ |
| 1729 |
static double |
| 1730 |
EpsToPoint(canvas, itemPtr, coordArr) |
| 1731 |
Tk_Canvas canvas; /* Canvas containing item. */ |
| 1732 |
Tk_Item *itemPtr; /* Item to check against point. */ |
| 1733 |
double *coordArr; /* Pointer to x and y coordinates. */ |
| 1734 |
{ |
| 1735 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1736 |
double dx, dy; |
| 1737 |
|
| 1738 |
/* |
| 1739 |
* Point is outside rectangle. |
| 1740 |
*/ |
| 1741 |
if (coordArr[0] < epsPtr->xLeft) { |
| 1742 |
dx = epsPtr->xLeft - coordArr[0]; |
| 1743 |
} else if (coordArr[0] > epsPtr->xRight) { |
| 1744 |
dx = coordArr[0] - epsPtr->xRight; |
| 1745 |
} else { |
| 1746 |
dx = 0; |
| 1747 |
} |
| 1748 |
if (coordArr[1] < epsPtr->yTop) { |
| 1749 |
dy = epsPtr->yTop - coordArr[1]; |
| 1750 |
} else if (coordArr[1] > epsPtr->yBottom) { |
| 1751 |
dy = coordArr[1] - epsPtr->yBottom; |
| 1752 |
} else { |
| 1753 |
dy = 0; |
| 1754 |
} |
| 1755 |
return hypot(dx, dy); |
| 1756 |
} |
| 1757 |
|
| 1758 |
/* |
| 1759 |
*---------------------------------------------------------------------- |
| 1760 |
* |
| 1761 |
* EpsToArea -- |
| 1762 |
* |
| 1763 |
* This procedure is called to determine whether an item |
| 1764 |
* lies entirely inside, entirely outside, or overlapping |
| 1765 |
* a given rectangle. |
| 1766 |
* |
| 1767 |
* Results: |
| 1768 |
* -1 is returned if the item is entirely outside the area |
| 1769 |
* given by rectPtr, 0 if it overlaps, and 1 if it is entirely |
| 1770 |
* inside the given area. |
| 1771 |
* |
| 1772 |
* Side effects: |
| 1773 |
* None. |
| 1774 |
* |
| 1775 |
*---------------------------------------------------------------------- |
| 1776 |
*/ |
| 1777 |
/*ARGSUSED*/ |
| 1778 |
static int |
| 1779 |
EpsToArea(canvas, itemPtr, area) |
| 1780 |
Tk_Canvas canvas; /* Canvas containing item. */ |
| 1781 |
Tk_Item *itemPtr; /* Item to check against rectangle. */ |
| 1782 |
double area[]; /* Pointer to array of four coordinates |
| 1783 |
* (x1, y1, x2, y2) describing rectangular |
| 1784 |
* area. */ |
| 1785 |
{ |
| 1786 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1787 |
|
| 1788 |
if ((area[2] <= epsPtr->xLeft) || (area[0] >= epsPtr->xRight) || |
| 1789 |
(area[3] <= epsPtr->yTop) || (area[1] >= epsPtr->yBottom)) { |
| 1790 |
return -1; |
| 1791 |
} |
| 1792 |
if ((area[0] <= epsPtr->xLeft) && (area[1] <= epsPtr->yTop) && |
| 1793 |
(area[2] >= epsPtr->xRight) && (area[3] >= epsPtr->yBottom)) { |
| 1794 |
return 1; |
| 1795 |
} |
| 1796 |
return 0; |
| 1797 |
} |
| 1798 |
|
| 1799 |
/* |
| 1800 |
*---------------------------------------------------------------------- |
| 1801 |
* |
| 1802 |
* ScaleEps -- |
| 1803 |
* |
| 1804 |
* This procedure is invoked to rescale an item. |
| 1805 |
* |
| 1806 |
* Results: |
| 1807 |
* None. |
| 1808 |
* |
| 1809 |
* Side effects: |
| 1810 |
* The item referred to by itemPtr is rescaled so that the |
| 1811 |
* following transformation is applied to all point coordinates: |
| 1812 |
* x' = originX + scaleX*(x-originX) |
| 1813 |
* y' = originY + scaleY*(y-originY) |
| 1814 |
* |
| 1815 |
*---------------------------------------------------------------------- |
| 1816 |
*/ |
| 1817 |
static void |
| 1818 |
ScaleEps(canvas, itemPtr, originX, originY, scaleX, scaleY) |
| 1819 |
Tk_Canvas canvas; /* Canvas containing rectangle. */ |
| 1820 |
Tk_Item *itemPtr; /* Rectangle to be scaled. */ |
| 1821 |
double originX, originY; /* Origin about which to scale rect. */ |
| 1822 |
double scaleX; /* Amount to scale in X direction. */ |
| 1823 |
double scaleY; /* Amount to scale in Y direction. */ |
| 1824 |
{ |
| 1825 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1826 |
|
| 1827 |
epsPtr->x = originX + scaleX * (epsPtr->x - originX); |
| 1828 |
epsPtr->y = originY + scaleY * (epsPtr->y - originY); |
| 1829 |
ComputeEpsBbox(canvas, epsPtr); |
| 1830 |
} |
| 1831 |
|
| 1832 |
/* |
| 1833 |
*---------------------------------------------------------------------- |
| 1834 |
* |
| 1835 |
* TranslateEps -- |
| 1836 |
* |
| 1837 |
* This procedure is called to move an item by a given amount. |
| 1838 |
* |
| 1839 |
* Results: |
| 1840 |
* None. |
| 1841 |
* |
| 1842 |
* Side effects: |
| 1843 |
* The position of the item is offset by (xDelta, yDelta), and |
| 1844 |
* the bounding box is updated in the generic part of the item |
| 1845 |
* structure. |
| 1846 |
* |
| 1847 |
*---------------------------------------------------------------------- |
| 1848 |
*/ |
| 1849 |
static void |
| 1850 |
TranslateEps(canvas, itemPtr, deltaX, deltaY) |
| 1851 |
Tk_Canvas canvas; /* Canvas containing item. */ |
| 1852 |
Tk_Item *itemPtr; /* Item that is being moved. */ |
| 1853 |
double deltaX, deltaY; /* Amount by which item is to be |
| 1854 |
* moved. */ |
| 1855 |
{ |
| 1856 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1857 |
|
| 1858 |
epsPtr->x += deltaX; |
| 1859 |
epsPtr->y += deltaY; |
| 1860 |
ComputeEpsBbox(canvas, epsPtr); |
| 1861 |
} |
| 1862 |
|
| 1863 |
/* |
| 1864 |
*---------------------------------------------------------------------- |
| 1865 |
* |
| 1866 |
* EpsToPostscript -- |
| 1867 |
* |
| 1868 |
* This procedure is called to generate Postscript for EPS |
| 1869 |
* canvas items. |
| 1870 |
* |
| 1871 |
* Results: |
| 1872 |
* The return value is a standard Tcl result. If an error |
| 1873 |
* occurs in generating Postscript then an error message is |
| 1874 |
* left in interp->result, replacing whatever used |
| 1875 |
* to be there. If no error occurs, then Postscript for the |
| 1876 |
* item is appended to the result. |
| 1877 |
* |
| 1878 |
* Side effects: |
| 1879 |
* None. |
| 1880 |
* |
| 1881 |
*---------------------------------------------------------------------- |
| 1882 |
*/ |
| 1883 |
static int |
| 1884 |
EpsToPostScript(interp, canvas, itemPtr, prepass) |
| 1885 |
Tcl_Interp *interp; /* Leave Postscript or error message |
| 1886 |
* here. */ |
| 1887 |
Tk_Canvas canvas; /* Information about overall canvas. */ |
| 1888 |
Tk_Item *itemPtr; /* Item for which Postscript is |
| 1889 |
* wanted. */ |
| 1890 |
int prepass; /* 1 means this is a prepass to |
| 1891 |
* collect font information; 0 means |
| 1892 |
* final Postscript is being created. */ |
| 1893 |
{ |
| 1894 |
EpsItem *epsPtr = (EpsItem *)itemPtr; |
| 1895 |
PsToken psToken; |
| 1896 |
Tk_Window tkwin; |
| 1897 |
double xScale, yScale; |
| 1898 |
int x, y, width, height; |
| 1899 |
|
| 1900 |
if (prepass) { |
| 1901 |
return TCL_OK; |
| 1902 |
} |
| 1903 |
tkwin = Tk_CanvasTkwin(epsPtr->canvas); |
| 1904 |
psToken = Blt_GetPsToken(interp, tkwin); |
| 1905 |
x = epsPtr->canvasX; |
| 1906 |
y = (int)Tk_CanvasPsY(canvas, (double)epsPtr->canvasY + epsPtr->height); |
| 1907 |
|
| 1908 |
if (epsPtr->fileName == NULL) { |
| 1909 |
/* No PostScript file, generate PostScript of resized image instead. */ |
| 1910 |
if (epsPtr->tmpImage != NULL) { |
| 1911 |
Tk_PhotoHandle photo; |
| 1912 |
|
| 1913 |
Blt_FormatToPostScript(psToken, "gsave\n"); |
| 1914 |
/* |
| 1915 |
* First flip the PostScript y-coordinate axis so that the |
| 1916 |
* origin is the upper-left corner like our color image. |
| 1917 |
*/ |
| 1918 |
Blt_FormatToPostScript(psToken, " %d %d translate\n", |
| 1919 |
x, y + epsPtr->height); |
| 1920 |
Blt_FormatToPostScript(psToken, " 1 -1 scale\n"); |
| 1921 |
|
| 1922 |
photo = Blt_FindPhoto(epsPtr->interp, |
| 1923 |
Blt_NameOfImage(epsPtr->tmpImage)); |
| 1924 |
Blt_PhotoToPostScript(psToken, photo, 0.0, 0.0); |
| 1925 |
Blt_FormatToPostScript(psToken, "grestore\n"); |
| 1926 |
|
| 1927 |
Tcl_AppendResult(interp, Blt_PostScriptFromToken(psToken), |
| 1928 |
(char *)NULL); |
| 1929 |
Blt_ReleasePsToken(psToken); |
| 1930 |
} |
| 1931 |
return TCL_OK; |
| 1932 |
} |
| 1933 |
|
| 1934 |
/* Copy in the PostScript prolog for EPS encapsulation. */ |
| 1935 |
|
| 1936 |
if (Blt_FileToPostScript(psToken, "bltCanvEps.pro") != TCL_OK) { |
| 1937 |
goto error; |
| 1938 |
} |
| 1939 |
Blt_AppendToPostScript(psToken, "BeginEPSF\n", (char *)NULL); |
| 1940 |
|
| 1941 |
width = epsPtr->width; |
| 1942 |
height = epsPtr->height; |
| 1943 |
xScale = (double)width / (double)(epsPtr->urx - epsPtr->llx); |
| 1944 |
yScale = (double)height / (double)(epsPtr->ury - epsPtr->lly); |
| 1945 |
|
| 1946 |
/* Set up scaling and translation transformations for the EPS item */ |
| 1947 |
|
| 1948 |
Blt_FormatToPostScript(psToken, "%d %d translate\n", x, y); |
| 1949 |
Blt_FormatToPostScript(psToken, "%g %g scale\n", xScale, yScale); |
| 1950 |
Blt_FormatToPostScript(psToken, "%d %d translate\n", -(epsPtr->llx), |
| 1951 |
-(epsPtr->lly)); |
| 1952 |
Blt_FormatToPostScript(psToken, "%d %d %d %d SetClipRegion\n", |
| 1953 |
epsPtr->llx, epsPtr->lly, epsPtr->urx, epsPtr->ury); |
| 1954 |
Blt_AppendToPostScript(psToken, "%% including \"", epsPtr->fileName, |
| 1955 |
"\"\n\n", (char *)NULL); |
| 1956 |
|
| 1957 |
Blt_AppendToPostScript(psToken, Tcl_DStringValue(&epsPtr->dString), |
| 1958 |
(char *)NULL); |
| 1959 |
Blt_AppendToPostScript(psToken, "EndEPSF\n", (char *)NULL); |
| 1960 |
Tcl_AppendResult(interp, Blt_PostScriptFromToken(psToken), (char *)NULL); |
| 1961 |
Blt_ReleasePsToken(psToken); |
| 1962 |
return TCL_OK; |
| 1963 |
|
| 1964 |
error: |
| 1965 |
Blt_ReleasePsToken(psToken); |
| 1966 |
return TCL_ERROR; |
| 1967 |
} |
| 1968 |
|
| 1969 |
/* |
| 1970 |
* The structures below defines the EPS item type in terms of |
| 1971 |
* procedures that can be invoked by generic item code. |
| 1972 |
*/ |
| 1973 |
static Tk_ItemType epsItemType = |
| 1974 |
{ |
| 1975 |
"eps", /* name */ |
| 1976 |
sizeof(EpsItem), /* itemSize */ |
| 1977 |
(Tk_ItemCreateProc *)CreateEps, /* createProc */ |
| 1978 |
configSpecs, /* configSpecs */ |
| 1979 |
(Tk_ItemConfigureProc *)ConfigureEps, /* configureProc */ |
| 1980 |
(Tk_ItemCoordProc *)EpsCoords, /* coordProc */ |
| 1981 |
DeleteEps, /* deleteProc */ |
| 1982 |
DisplayEps, /* displayProc */ |
| 1983 |
#ifdef USE_OLD_CANVAS |
| 1984 |
0, |
| 1985 |
#else |
| 1986 |
TK_CONFIG_OBJS, /* alwaysRedraw */ |
| 1987 |
#endif |
| 1988 |
EpsToPoint, /* pointProc */ |
| 1989 |
EpsToArea, /* areaProc */ |
| 1990 |
EpsToPostScript, /* postscriptProc */ |
| 1991 |
ScaleEps, /* scaleProc */ |
| 1992 |
TranslateEps, /* translateProc */ |
| 1993 |
(Tk_ItemIndexProc *) NULL, /* indexProc */ |
| 1994 |
(Tk_ItemCursorProc *) NULL, /* icursorProc */ |
| 1995 |
(Tk_ItemSelectionProc *) NULL, /* selectionProc */ |
| 1996 |
(Tk_ItemInsertProc *) NULL, /* insertProc */ |
| 1997 |
(Tk_ItemDCharsProc *) NULL, /* dTextProc */ |
| 1998 |
(Tk_ItemType *) NULL /* nextPtr */ |
| 1999 |
}; |
| 2000 |
|
| 2001 |
/*ARGSUSED*/ |
| 2002 |
void |
| 2003 |
Blt_InitEpsCanvasItem(interp) |
| 2004 |
Tcl_Interp *interp; /* Not used. */ |
| 2005 |
{ |
| 2006 |
Tk_CreateItemType(&epsItemType); |
| 2007 |
/* Initialize custom canvas option routines. */ |
| 2008 |
tagsOption.parseProc = (Tk_OptionParseProc *)Tk_CanvasTagsParseProc; |
| 2009 |
tagsOption.printProc = (Tk_OptionPrintProc *)Tk_CanvasTagsPrintProc; |
| 2010 |
} |