| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#define NEED_REAL_STDIO |
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkPort.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
typedef struct BitmapMaster { |
| 25 |
Tk_ImageMaster tkMaster; |
| 26 |
|
| 27 |
Tcl_Interp *interp; |
| 28 |
|
| 29 |
Tcl_Command imageCmd; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
int width, height; |
| 34 |
char *data; |
| 35 |
|
| 36 |
|
| 37 |
char *maskData; |
| 38 |
|
| 39 |
|
| 40 |
Tk_Uid fgUid; |
| 41 |
Tk_Uid bgUid; |
| 42 |
char *fileString; |
| 43 |
char *dataString; |
| 44 |
char *maskFileString; |
| 45 |
char *maskDataString; |
| 46 |
struct BitmapInstance *instancePtr; |
| 47 |
|
| 48 |
|
| 49 |
} BitmapMaster; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
typedef struct BitmapInstance { |
| 57 |
int refCount; |
| 58 |
|
| 59 |
BitmapMaster *masterPtr; |
| 60 |
Tk_Window tkwin; |
| 61 |
|
| 62 |
XColor *fg; |
| 63 |
XColor *bg; |
| 64 |
Pixmap bitmap; |
| 65 |
Pixmap mask; |
| 66 |
|
| 67 |
GC gc; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
struct BitmapInstance *nextPtr; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
} BitmapInstance; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
static int GetByte _ANSI_ARGS_((Tcl_Channel chan)); |
| 82 |
static int ImgBmapCreate _ANSI_ARGS_((Tcl_Interp *interp, |
| 83 |
char *name, int argc, Tcl_Obj *CONST objv[], |
| 84 |
Tk_ImageType *typePtr, Tk_ImageMaster master, |
| 85 |
ClientData *clientDataPtr)); |
| 86 |
static ClientData ImgBmapGet _ANSI_ARGS_((Tk_Window tkwin, |
| 87 |
ClientData clientData)); |
| 88 |
static void ImgBmapDisplay _ANSI_ARGS_((ClientData clientData, |
| 89 |
Display *display, Drawable drawable, |
| 90 |
int imageX, int imageY, int width, int height, |
| 91 |
int drawableX, int drawableY)); |
| 92 |
static void ImgBmapFree _ANSI_ARGS_((ClientData clientData, |
| 93 |
Display *display)); |
| 94 |
static void ImgBmapDelete _ANSI_ARGS_((ClientData clientData)); |
| 95 |
static int ImgBmapPostscript _ANSI_ARGS_((ClientData clientData, |
| 96 |
Tcl_Interp *interp, Tk_Window tkwin, |
| 97 |
Tk_PostscriptInfo psinfo, int x, int y, |
| 98 |
int width, int height, int prepass)); |
| 99 |
|
| 100 |
Tk_ImageType tkBitmapImageType = { |
| 101 |
"bitmap", |
| 102 |
ImgBmapCreate, |
| 103 |
ImgBmapGet, |
| 104 |
ImgBmapDisplay, |
| 105 |
ImgBmapFree, |
| 106 |
ImgBmapDelete, |
| 107 |
ImgBmapPostscript, |
| 108 |
(Tk_ImageType *) NULL |
| 109 |
}; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
static Tk_ConfigSpec configSpecs[] = { |
| 116 |
{TK_CONFIG_UID, "-background", (char *) NULL, (char *) NULL, |
| 117 |
"", Tk_Offset(BitmapMaster, bgUid), TK_CONFIG_NULL_OK}, |
| 118 |
{TK_CONFIG_STRING, "-data", (char *) NULL, (char *) NULL, |
| 119 |
(char *) NULL, Tk_Offset(BitmapMaster, dataString), TK_CONFIG_NULL_OK}, |
| 120 |
{TK_CONFIG_STRING, "-file", (char *) NULL, (char *) NULL, |
| 121 |
(char *) NULL, Tk_Offset(BitmapMaster, fileString), TK_CONFIG_NULL_OK}, |
| 122 |
{TK_CONFIG_UID, "-foreground", (char *) NULL, (char *) NULL, |
| 123 |
"#000000", Tk_Offset(BitmapMaster, fgUid), 0}, |
| 124 |
{TK_CONFIG_STRING, "-maskdata", (char *) NULL, (char *) NULL, |
| 125 |
(char *) NULL, Tk_Offset(BitmapMaster, maskDataString), |
| 126 |
TK_CONFIG_NULL_OK}, |
| 127 |
{TK_CONFIG_STRING, "-maskfile", (char *) NULL, (char *) NULL, |
| 128 |
(char *) NULL, Tk_Offset(BitmapMaster, maskFileString), |
| 129 |
TK_CONFIG_NULL_OK}, |
| 130 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 131 |
(char *) NULL, 0, 0} |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
#define MAX_WORD_LENGTH 100 |
| 141 |
typedef struct ParseInfo { |
| 142 |
char *string; |
| 143 |
|
| 144 |
|
| 145 |
Tcl_Channel chan; |
| 146 |
|
| 147 |
char word[MAX_WORD_LENGTH+1]; |
| 148 |
|
| 149 |
|
| 150 |
int wordLength; |
| 151 |
} ParseInfo; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static int ImgBmapCmd _ANSI_ARGS_((ClientData clientData, |
| 158 |
Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])); |
| 159 |
static void ImgBmapCmdDeletedProc _ANSI_ARGS_(( |
| 160 |
ClientData clientData)); |
| 161 |
static void ImgBmapConfigureInstance _ANSI_ARGS_(( |
| 162 |
BitmapInstance *instancePtr)); |
| 163 |
static int ImgBmapConfigureMaster _ANSI_ARGS_(( |
| 164 |
BitmapMaster *masterPtr, int argc, Tcl_Obj *CONST objv[], |
| 165 |
int flags)); |
| 166 |
static int NextBitmapWord _ANSI_ARGS_((ParseInfo *parseInfoPtr)); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static int |
| 187 |
ImgBmapCreate(interp, name, argc, objv, typePtr, master, clientDataPtr) |
| 188 |
Tcl_Interp *interp; |
| 189 |
|
| 190 |
char *name; |
| 191 |
int argc; |
| 192 |
Tcl_Obj *CONST objv[]; |
| 193 |
|
| 194 |
Tk_ImageType *typePtr; |
| 195 |
Tk_ImageMaster master; |
| 196 |
|
| 197 |
ClientData *clientDataPtr; |
| 198 |
|
| 199 |
{ |
| 200 |
BitmapMaster *masterPtr; |
| 201 |
|
| 202 |
masterPtr = (BitmapMaster *) ckalloc(sizeof(BitmapMaster)); |
| 203 |
masterPtr->tkMaster = master; |
| 204 |
masterPtr->interp = interp; |
| 205 |
masterPtr->imageCmd = Lang_CreateImage(interp, name, ImgBmapCmd, |
| 206 |
(ClientData) masterPtr, ImgBmapCmdDeletedProc, typePtr); |
| 207 |
masterPtr->width = masterPtr->height = 0; |
| 208 |
masterPtr->data = NULL; |
| 209 |
masterPtr->maskData = NULL; |
| 210 |
masterPtr->fgUid = NULL; |
| 211 |
masterPtr->bgUid = NULL; |
| 212 |
masterPtr->fileString = NULL; |
| 213 |
masterPtr->dataString = NULL; |
| 214 |
masterPtr->maskFileString = NULL; |
| 215 |
masterPtr->maskDataString = NULL; |
| 216 |
masterPtr->instancePtr = NULL; |
| 217 |
if (ImgBmapConfigureMaster(masterPtr, argc, objv, 0) != TCL_OK) { |
| 218 |
ImgBmapDelete((ClientData) masterPtr); |
| 219 |
return TCL_ERROR; |
| 220 |
} |
| 221 |
*clientDataPtr = (ClientData) masterPtr; |
| 222 |
return TCL_OK; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
static int |
| 246 |
ImgBmapConfigureMaster(masterPtr, objc, objv, flags) |
| 247 |
BitmapMaster *masterPtr; |
| 248 |
|
| 249 |
int objc; |
| 250 |
Tcl_Obj *CONST objv[]; |
| 251 |
int flags; |
| 252 |
|
| 253 |
{ |
| 254 |
BitmapInstance *instancePtr; |
| 255 |
int maskWidth, maskHeight, dummy1, dummy2; |
| 256 |
|
| 257 |
if (Tk_ConfigureWidget(masterPtr->interp, Tk_MainWindow(masterPtr->interp), |
| 258 |
configSpecs, objc, objv, (char *) masterPtr, flags) |
| 259 |
!= TCL_OK) { |
| 260 |
return TCL_ERROR; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
if (masterPtr->data != NULL) { |
| 269 |
ckfree(masterPtr->data); |
| 270 |
masterPtr->data = NULL; |
| 271 |
} |
| 272 |
if ((masterPtr->fileString != NULL) || (masterPtr->dataString != NULL)) { |
| 273 |
masterPtr->data = TkGetBitmapData(masterPtr->interp, |
| 274 |
masterPtr->dataString, masterPtr->fileString, |
| 275 |
&masterPtr->width, &masterPtr->height, &dummy1, &dummy2); |
| 276 |
if (masterPtr->data == NULL) { |
| 277 |
return TCL_ERROR; |
| 278 |
} |
| 279 |
} |
| 280 |
if (masterPtr->maskData != NULL) { |
| 281 |
ckfree(masterPtr->maskData); |
| 282 |
masterPtr->maskData = NULL; |
| 283 |
} |
| 284 |
if ((masterPtr->maskFileString != NULL) |
| 285 |
|| (masterPtr->maskDataString != NULL)) { |
| 286 |
if (masterPtr->data == NULL) { |
| 287 |
Tcl_SetResult(masterPtr->interp, "can't have mask without bitmap", |
| 288 |
TCL_STATIC); |
| 289 |
return TCL_ERROR; |
| 290 |
} |
| 291 |
masterPtr->maskData = TkGetBitmapData(masterPtr->interp, |
| 292 |
masterPtr->maskDataString, masterPtr->maskFileString, |
| 293 |
&maskWidth, &maskHeight, &dummy1, &dummy2); |
| 294 |
if (masterPtr->maskData == NULL) { |
| 295 |
return TCL_ERROR; |
| 296 |
} |
| 297 |
if ((maskWidth != masterPtr->width) |
| 298 |
|| (maskHeight != masterPtr->height)) { |
| 299 |
ckfree(masterPtr->maskData); |
| 300 |
masterPtr->maskData = NULL; |
| 301 |
Tcl_SetResult(masterPtr->interp, |
| 302 |
"bitmap and mask have different sizes", TCL_STATIC); |
| 303 |
return TCL_ERROR; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; |
| 314 |
instancePtr = instancePtr->nextPtr) { |
| 315 |
ImgBmapConfigureInstance(instancePtr); |
| 316 |
} |
| 317 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, masterPtr->width, |
| 318 |
masterPtr->height, masterPtr->width, masterPtr->height); |
| 319 |
return TCL_OK; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
static void |
| 343 |
ImgBmapConfigureInstance(instancePtr) |
| 344 |
BitmapInstance *instancePtr; |
| 345 |
{ |
| 346 |
BitmapMaster *masterPtr = instancePtr->masterPtr; |
| 347 |
XColor *colorPtr; |
| 348 |
XGCValues gcValues; |
| 349 |
GC gc; |
| 350 |
unsigned int mask; |
| 351 |
Pixmap oldMask; |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
if ((masterPtr->bgUid != NULL) && (masterPtr->bgUid[0] != '\0')) { |
| 359 |
colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin, |
| 360 |
masterPtr->bgUid); |
| 361 |
if (colorPtr == NULL) { |
| 362 |
goto error; |
| 363 |
} |
| 364 |
} else { |
| 365 |
colorPtr = NULL; |
| 366 |
} |
| 367 |
if (instancePtr->bg != NULL) { |
| 368 |
Tk_FreeColor(instancePtr->bg); |
| 369 |
} |
| 370 |
instancePtr->bg = colorPtr; |
| 371 |
|
| 372 |
colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin, |
| 373 |
masterPtr->fgUid); |
| 374 |
if (colorPtr == NULL) { |
| 375 |
goto error; |
| 376 |
} |
| 377 |
if (instancePtr->fg != NULL) { |
| 378 |
Tk_FreeColor(instancePtr->fg); |
| 379 |
} |
| 380 |
instancePtr->fg = colorPtr; |
| 381 |
|
| 382 |
if (instancePtr->bitmap != None) { |
| 383 |
Tk_FreePixmap(Tk_Display(instancePtr->tkwin), instancePtr->bitmap); |
| 384 |
instancePtr->bitmap = None; |
| 385 |
} |
| 386 |
if (masterPtr->data != NULL) { |
| 387 |
instancePtr->bitmap = XCreateBitmapFromData( |
| 388 |
Tk_Display(instancePtr->tkwin), |
| 389 |
RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)), |
| 390 |
masterPtr->data, (unsigned) masterPtr->width, |
| 391 |
(unsigned) masterPtr->height); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
oldMask = instancePtr->mask; |
| 401 |
instancePtr->mask = None; |
| 402 |
if (masterPtr->maskData != NULL) { |
| 403 |
instancePtr->mask = XCreateBitmapFromData( |
| 404 |
Tk_Display(instancePtr->tkwin), |
| 405 |
RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)), |
| 406 |
masterPtr->maskData, (unsigned) masterPtr->width, |
| 407 |
(unsigned) masterPtr->height); |
| 408 |
} |
| 409 |
if (oldMask != None) { |
| 410 |
Tk_FreePixmap(Tk_Display(instancePtr->tkwin), oldMask); |
| 411 |
} |
| 412 |
|
| 413 |
if (masterPtr->data != NULL) { |
| 414 |
gcValues.foreground = instancePtr->fg->pixel; |
| 415 |
gcValues.graphics_exposures = False; |
| 416 |
mask = GCForeground|GCGraphicsExposures; |
| 417 |
if (instancePtr->bg != NULL) { |
| 418 |
gcValues.background = instancePtr->bg->pixel; |
| 419 |
mask |= GCBackground; |
| 420 |
if (instancePtr->mask != None) { |
| 421 |
gcValues.clip_mask = instancePtr->mask; |
| 422 |
mask |= GCClipMask; |
| 423 |
} |
| 424 |
} else { |
| 425 |
gcValues.clip_mask = instancePtr->bitmap; |
| 426 |
mask |= GCClipMask; |
| 427 |
} |
| 428 |
gc = Tk_GetGC(instancePtr->tkwin, mask, &gcValues); |
| 429 |
} else { |
| 430 |
gc = None; |
| 431 |
} |
| 432 |
if (instancePtr->gc != None) { |
| 433 |
Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc); |
| 434 |
} |
| 435 |
instancePtr->gc = gc; |
| 436 |
return; |
| 437 |
|
| 438 |
error: |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
if (instancePtr->gc != None) { |
| 446 |
Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc); |
| 447 |
} |
| 448 |
instancePtr->gc = None; |
| 449 |
Tcl_AddErrorInfo(masterPtr->interp, "\n (while configuring image \""); |
| 450 |
Tcl_AddErrorInfo(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster)); |
| 451 |
Tcl_AddErrorInfo(masterPtr->interp, "\")"); |
| 452 |
Tcl_BackgroundError(masterPtr->interp); |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
char * |
| 479 |
TkGetBitmapData(interp, string, fileName, widthPtr, heightPtr, |
| 480 |
hotXPtr, hotYPtr) |
| 481 |
Tcl_Interp *interp; |
| 482 |
char *string; |
| 483 |
|
| 484 |
char *fileName; |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
int *widthPtr, *heightPtr; |
| 489 |
|
| 490 |
int *hotXPtr, *hotYPtr; |
| 491 |
{ |
| 492 |
int width, height, numBytes, hotX, hotY; |
| 493 |
CONST char *expandedFileName; |
| 494 |
char *p, *end; |
| 495 |
ParseInfo pi; |
| 496 |
char *data = NULL; |
| 497 |
Tcl_DString buffer; |
| 498 |
|
| 499 |
pi.string = string; |
| 500 |
if (string == NULL) { |
| 501 |
if ((interp != NULL) && Tcl_IsSafe(interp)) { |
| 502 |
Tcl_AppendResult(interp, "can't get bitmap data from a file in a", |
| 503 |
" safe interpreter", (char *) NULL); |
| 504 |
return NULL; |
| 505 |
} |
| 506 |
expandedFileName = Tcl_TranslateFileName(interp, fileName, &buffer); |
| 507 |
if (expandedFileName == NULL) { |
| 508 |
return NULL; |
| 509 |
} |
| 510 |
pi.chan = Tcl_OpenFileChannel(interp, expandedFileName, "r", 0); |
| 511 |
Tcl_DStringFree(&buffer); |
| 512 |
if (pi.chan == NULL) { |
| 513 |
if (interp != NULL) { |
| 514 |
Tcl_ResetResult(interp); |
| 515 |
Tcl_AppendResult(interp, "couldn't read bitmap file \"", |
| 516 |
fileName, "\": ", Tcl_PosixError(interp), |
| 517 |
(char *) NULL); |
| 518 |
} |
| 519 |
return NULL; |
| 520 |
} |
| 521 |
|
| 522 |
if (Tcl_SetChannelOption(interp, pi.chan, "-translation", "binary") |
| 523 |
!= TCL_OK) { |
| 524 |
return NULL; |
| 525 |
} |
| 526 |
if (Tcl_SetChannelOption(interp, pi.chan, "-encoding", "binary") |
| 527 |
!= TCL_OK) { |
| 528 |
return NULL; |
| 529 |
} |
| 530 |
} else { |
| 531 |
pi.chan = NULL; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
width = 0; |
| 552 |
height = 0; |
| 553 |
hotX = -1; |
| 554 |
hotY = -1; |
| 555 |
while (1) { |
| 556 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 557 |
goto error; |
| 558 |
} |
| 559 |
if ((pi.wordLength >= 6) && (pi.word[pi.wordLength-6] == '_') |
| 560 |
&& (strcmp(pi.word+pi.wordLength-6, "_width") == 0)) { |
| 561 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 562 |
goto error; |
| 563 |
} |
| 564 |
width = strtol(pi.word, &end, 0); |
| 565 |
if ((end == pi.word) || (*end != 0)) { |
| 566 |
goto error; |
| 567 |
} |
| 568 |
} else if ((pi.wordLength >= 7) && (pi.word[pi.wordLength-7] == '_') |
| 569 |
&& (strcmp(pi.word+pi.wordLength-7, "_height") == 0)) { |
| 570 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 571 |
goto error; |
| 572 |
} |
| 573 |
height = strtol(pi.word, &end, 0); |
| 574 |
if ((end == pi.word) || (*end != 0)) { |
| 575 |
goto error; |
| 576 |
} |
| 577 |
} else if ((pi.wordLength >= 6) && (pi.word[pi.wordLength-6] == '_') |
| 578 |
&& (strcmp(pi.word+pi.wordLength-6, "_x_hot") == 0)) { |
| 579 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 580 |
goto error; |
| 581 |
} |
| 582 |
hotX = strtol(pi.word, &end, 0); |
| 583 |
if ((end == pi.word) || (*end != 0)) { |
| 584 |
goto error; |
| 585 |
} |
| 586 |
} else if ((pi.wordLength >= 6) && (pi.word[pi.wordLength-6] == '_') |
| 587 |
&& (strcmp(pi.word+pi.wordLength-6, "_y_hot") == 0)) { |
| 588 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 589 |
goto error; |
| 590 |
} |
| 591 |
hotY = strtol(pi.word, &end, 0); |
| 592 |
if ((end == pi.word) || (*end != 0)) { |
| 593 |
goto error; |
| 594 |
} |
| 595 |
} else if ((pi.word[0] == 'c') && (strcmp(pi.word, "char") == 0)) { |
| 596 |
while (1) { |
| 597 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 598 |
goto error; |
| 599 |
} |
| 600 |
if ((pi.word[0] == '{') && (pi.word[1] == 0)) { |
| 601 |
goto getData; |
| 602 |
} |
| 603 |
} |
| 604 |
} else if ((pi.word[0] == '{') && (pi.word[1] == 0)) { |
| 605 |
if (interp != NULL) { |
| 606 |
Tcl_AppendResult(interp, "format error in bitmap data; ", |
| 607 |
"looks like it's an obsolete X10 bitmap file", |
| 608 |
(char *) NULL); |
| 609 |
} |
| 610 |
goto errorCleanup; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
getData: |
| 620 |
if ((width <= 0) || (height <= 0)) { |
| 621 |
goto error; |
| 622 |
} |
| 623 |
numBytes = ((width+7)/8) * height; |
| 624 |
data = (char *) ckalloc((unsigned) numBytes); |
| 625 |
for (p = data; numBytes > 0; p++, numBytes--) { |
| 626 |
if (NextBitmapWord(&pi) != TCL_OK) { |
| 627 |
goto error; |
| 628 |
} |
| 629 |
*p = (char) strtol(pi.word, &end, 0); |
| 630 |
if (end == pi.word) { |
| 631 |
goto error; |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
if (pi.chan != NULL) { |
| 640 |
Tcl_Close(NULL, pi.chan); |
| 641 |
} |
| 642 |
*widthPtr = width; |
| 643 |
*heightPtr = height; |
| 644 |
*hotXPtr = hotX; |
| 645 |
*hotYPtr = hotY; |
| 646 |
return data; |
| 647 |
|
| 648 |
error: |
| 649 |
if (interp != NULL) { |
| 650 |
Tcl_SetResult(interp, "format error in bitmap data", TCL_STATIC); |
| 651 |
} |
| 652 |
|
| 653 |
errorCleanup: |
| 654 |
if (data != NULL) { |
| 655 |
ckfree(data); |
| 656 |
} |
| 657 |
if (pi.chan != NULL) { |
| 658 |
Tcl_Close(NULL, pi.chan); |
| 659 |
} |
| 660 |
return NULL; |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
static int |
| 683 |
NextBitmapWord(parseInfoPtr) |
| 684 |
ParseInfo *parseInfoPtr; |
| 685 |
|
| 686 |
{ |
| 687 |
char *src, *dst; |
| 688 |
int c; |
| 689 |
|
| 690 |
parseInfoPtr->wordLength = 0; |
| 691 |
dst = parseInfoPtr->word; |
| 692 |
if (parseInfoPtr->string != NULL) { |
| 693 |
for (src = parseInfoPtr->string; isspace(UCHAR(*src)) || (*src == ','); |
| 694 |
src++) { |
| 695 |
if (*src == 0) { |
| 696 |
return TCL_ERROR; |
| 697 |
} |
| 698 |
} |
| 699 |
for ( ; !isspace(UCHAR(*src)) && (*src != ',') && (*src != 0); src++) { |
| 700 |
*dst = *src; |
| 701 |
dst++; |
| 702 |
parseInfoPtr->wordLength++; |
| 703 |
if (parseInfoPtr->wordLength > MAX_WORD_LENGTH) { |
| 704 |
return TCL_ERROR; |
| 705 |
} |
| 706 |
} |
| 707 |
parseInfoPtr->string = src; |
| 708 |
} else { |
| 709 |
for (c = GetByte(parseInfoPtr->chan); isspace(UCHAR(c)) || (c == ','); |
| 710 |
c = GetByte(parseInfoPtr->chan)) { |
| 711 |
if (c == EOF) { |
| 712 |
return TCL_ERROR; |
| 713 |
} |
| 714 |
} |
| 715 |
for ( ; !isspace(UCHAR(c)) && (c != ',') && (c != EOF); |
| 716 |
c = GetByte(parseInfoPtr->chan)) { |
| 717 |
*dst = c; |
| 718 |
dst++; |
| 719 |
parseInfoPtr->wordLength++; |
| 720 |
if (parseInfoPtr->wordLength > MAX_WORD_LENGTH) { |
| 721 |
return TCL_ERROR; |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
if (parseInfoPtr->wordLength == 0) { |
| 726 |
return TCL_ERROR; |
| 727 |
} |
| 728 |
parseInfoPtr->word[parseInfoPtr->wordLength] = 0; |
| 729 |
return TCL_OK; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
static int |
| 751 |
ImgBmapCmd(clientData, interp, objc, objv) |
| 752 |
ClientData clientData; |
| 753 |
Tcl_Interp *interp; |
| 754 |
int objc; |
| 755 |
Tcl_Obj *CONST objv[]; |
| 756 |
{ |
| 757 |
static CONST char *bmapOptions[] = {"cget", "configure", (char *) NULL}; |
| 758 |
BitmapMaster *masterPtr = (BitmapMaster *) clientData; |
| 759 |
int code, index; |
| 760 |
|
| 761 |
if (objc < 2) { |
| 762 |
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); |
| 763 |
return TCL_ERROR; |
| 764 |
} |
| 765 |
if (Tcl_GetIndexFromObj(interp, objv[1], bmapOptions, "option", 0, |
| 766 |
&index) != TCL_OK) { |
| 767 |
return TCL_ERROR; |
| 768 |
} |
| 769 |
switch (index) { |
| 770 |
case 0: { |
| 771 |
if (objc != 3) { |
| 772 |
Tcl_WrongNumArgs(interp, 2, objv, "option"); |
| 773 |
return TCL_ERROR; |
| 774 |
} |
| 775 |
return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs, |
| 776 |
(char *) masterPtr, Tcl_GetString(objv[2]), 0); |
| 777 |
} |
| 778 |
case 1: { |
| 779 |
if (objc == 2) { |
| 780 |
code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), |
| 781 |
configSpecs, (char *) masterPtr, (char *) NULL, 0); |
| 782 |
} else if (objc == 3) { |
| 783 |
code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp), |
| 784 |
configSpecs, (char *) masterPtr, |
| 785 |
Tcl_GetString(objv[2]), 0); |
| 786 |
} else { |
| 787 |
code = ImgBmapConfigureMaster(masterPtr, objc-2, objv+2, |
| 788 |
TK_CONFIG_ARGV_ONLY); |
| 789 |
} |
| 790 |
return code; |
| 791 |
} |
| 792 |
default: { |
| 793 |
panic("bad const entries to bmapOptions in ImgBmapCmd"); |
| 794 |
} |
| 795 |
} |
| 796 |
return TCL_OK; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
static ClientData |
| 819 |
ImgBmapGet(tkwin, masterData) |
| 820 |
Tk_Window tkwin; |
| 821 |
|
| 822 |
ClientData masterData; |
| 823 |
|
| 824 |
{ |
| 825 |
BitmapMaster *masterPtr = (BitmapMaster *) masterData; |
| 826 |
BitmapInstance *instancePtr; |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; |
| 834 |
instancePtr = instancePtr->nextPtr) { |
| 835 |
if (instancePtr->tkwin == tkwin) { |
| 836 |
instancePtr->refCount++; |
| 837 |
return (ClientData) instancePtr; |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
instancePtr = (BitmapInstance *) ckalloc(sizeof(BitmapInstance)); |
| 847 |
instancePtr->refCount = 1; |
| 848 |
instancePtr->masterPtr = masterPtr; |
| 849 |
instancePtr->tkwin = tkwin; |
| 850 |
instancePtr->fg = NULL; |
| 851 |
instancePtr->bg = NULL; |
| 852 |
instancePtr->bitmap = None; |
| 853 |
instancePtr->mask = None; |
| 854 |
instancePtr->gc = None; |
| 855 |
instancePtr->nextPtr = masterPtr->instancePtr; |
| 856 |
masterPtr->instancePtr = instancePtr; |
| 857 |
ImgBmapConfigureInstance(instancePtr); |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
if (instancePtr->nextPtr == NULL) { |
| 864 |
Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, masterPtr->width, |
| 865 |
masterPtr->height); |
| 866 |
} |
| 867 |
|
| 868 |
return (ClientData) instancePtr; |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
static void |
| 888 |
ImgBmapDisplay(clientData, display, drawable, imageX, imageY, width, |
| 889 |
height, drawableX, drawableY) |
| 890 |
ClientData clientData; |
| 891 |
|
| 892 |
Display *display; |
| 893 |
Drawable drawable; |
| 894 |
int imageX, imageY; |
| 895 |
|
| 896 |
int width, height; |
| 897 |
int drawableX, drawableY; |
| 898 |
|
| 899 |
{ |
| 900 |
BitmapInstance *instancePtr = (BitmapInstance *) clientData; |
| 901 |
int masking; |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
if (instancePtr->gc == None) { |
| 909 |
return; |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
masking = (instancePtr->mask != None) || (instancePtr->bg == NULL); |
| 920 |
if (masking) { |
| 921 |
XSetClipOrigin(display, instancePtr->gc, drawableX - imageX, |
| 922 |
drawableY - imageY); |
| 923 |
} |
| 924 |
XCopyPlane(display, instancePtr->bitmap, drawable, instancePtr->gc, |
| 925 |
imageX, imageY, (unsigned) width, (unsigned) height, |
| 926 |
drawableX, drawableY, 1); |
| 927 |
if (masking) { |
| 928 |
XSetClipOrigin(display, instancePtr->gc, 0, 0); |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
static void |
| 950 |
ImgBmapFree(clientData, display) |
| 951 |
ClientData clientData; |
| 952 |
|
| 953 |
Display *display; |
| 954 |
{ |
| 955 |
BitmapInstance *instancePtr = (BitmapInstance *) clientData; |
| 956 |
BitmapInstance *prevPtr; |
| 957 |
|
| 958 |
instancePtr->refCount--; |
| 959 |
if (instancePtr->refCount > 0) { |
| 960 |
return; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
if (instancePtr->fg != NULL) { |
| 969 |
Tk_FreeColor(instancePtr->fg); |
| 970 |
} |
| 971 |
if (instancePtr->bg != NULL) { |
| 972 |
Tk_FreeColor(instancePtr->bg); |
| 973 |
} |
| 974 |
if (instancePtr->bitmap != None) { |
| 975 |
Tk_FreePixmap(display, instancePtr->bitmap); |
| 976 |
} |
| 977 |
if (instancePtr->mask != None) { |
| 978 |
Tk_FreePixmap(display, instancePtr->mask); |
| 979 |
} |
| 980 |
if (instancePtr->gc != None) { |
| 981 |
Tk_FreeGC(display, instancePtr->gc); |
| 982 |
} |
| 983 |
if (instancePtr->masterPtr->instancePtr == instancePtr) { |
| 984 |
instancePtr->masterPtr->instancePtr = instancePtr->nextPtr; |
| 985 |
} else { |
| 986 |
for (prevPtr = instancePtr->masterPtr->instancePtr; |
| 987 |
prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) { |
| 988 |
|
| 989 |
} |
| 990 |
prevPtr->nextPtr = instancePtr->nextPtr; |
| 991 |
} |
| 992 |
ckfree((char *) instancePtr); |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
static void |
| 1013 |
ImgBmapDelete(masterData) |
| 1014 |
ClientData masterData; |
| 1015 |
|
| 1016 |
{ |
| 1017 |
BitmapMaster *masterPtr = (BitmapMaster *) masterData; |
| 1018 |
|
| 1019 |
if (masterPtr->instancePtr != NULL) { |
| 1020 |
panic("tried to delete bitmap image when instances still exist"); |
| 1021 |
} |
| 1022 |
masterPtr->tkMaster = NULL; |
| 1023 |
if (masterPtr->imageCmd != NULL) { |
| 1024 |
Tcl_DeleteCommandFromToken(masterPtr->interp, masterPtr->imageCmd); |
| 1025 |
} |
| 1026 |
if (masterPtr->data != NULL) { |
| 1027 |
ckfree(masterPtr->data); |
| 1028 |
} |
| 1029 |
if (masterPtr->maskData != NULL) { |
| 1030 |
ckfree(masterPtr->maskData); |
| 1031 |
} |
| 1032 |
Tk_FreeOptions(configSpecs, (char *) masterPtr, (Display *) NULL, 0); |
| 1033 |
ckfree((char *) masterPtr); |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
static void |
| 1054 |
ImgBmapCmdDeletedProc(clientData) |
| 1055 |
ClientData clientData; |
| 1056 |
|
| 1057 |
{ |
| 1058 |
BitmapMaster *masterPtr = (BitmapMaster *) clientData; |
| 1059 |
|
| 1060 |
masterPtr->imageCmd = NULL; |
| 1061 |
if (masterPtr->tkMaster != NULL) { |
| 1062 |
Tk_DeleteImage(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster)); |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
static int |
| 1083 |
GetByte(chan) |
| 1084 |
Tcl_Channel chan; |
| 1085 |
{ |
| 1086 |
char buffer; |
| 1087 |
int size; |
| 1088 |
|
| 1089 |
size = Tcl_Read(chan, &buffer, 1); |
| 1090 |
if (size <= 0) { |
| 1091 |
return EOF; |
| 1092 |
} else { |
| 1093 |
return buffer; |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
static int |
| 1135 |
ImgBmapPsImagemask(interp, width, height, data) |
| 1136 |
Tcl_Interp *interp; |
| 1137 |
int width, height; |
| 1138 |
char *data; |
| 1139 |
{ |
| 1140 |
int i, j, nBytePerRow; |
| 1141 |
char buffer[200]; |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
static unsigned char bit_reverse[] = { |
| 1151 |
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, |
| 1152 |
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, |
| 1153 |
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, |
| 1154 |
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, |
| 1155 |
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, |
| 1156 |
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, |
| 1157 |
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, |
| 1158 |
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, |
| 1159 |
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, |
| 1160 |
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, |
| 1161 |
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, |
| 1162 |
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, |
| 1163 |
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, |
| 1164 |
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, |
| 1165 |
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, |
| 1166 |
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255, |
| 1167 |
}; |
| 1168 |
|
| 1169 |
if (width*height > 60000) { |
| 1170 |
Tcl_ResetResult(interp); |
| 1171 |
Tcl_AppendResult(interp, "unable to generate postscript for bitmaps " |
| 1172 |
"larger than 60000 pixels", 0); |
| 1173 |
return TCL_ERROR; |
| 1174 |
} |
| 1175 |
sprintf(buffer, "0 0 moveto %d %d true [%d 0 0 %d 0 %d] {<\n", |
| 1176 |
width, height, width, -height, height); |
| 1177 |
Tcl_AppendResult(interp, buffer, 0); |
| 1178 |
nBytePerRow = (width+7)/8; |
| 1179 |
for(i=0; i<height; i++){ |
| 1180 |
for(j=0; j<nBytePerRow; j++){ |
| 1181 |
sprintf(buffer, " %02x", bit_reverse[0xff & data[i*nBytePerRow + j]]); |
| 1182 |
Tcl_AppendResult(interp, buffer, 0); |
| 1183 |
} |
| 1184 |
Tcl_AppendResult(interp, "\n", 0); |
| 1185 |
} |
| 1186 |
Tcl_AppendResult(interp, ">} imagemask \n", 0); |
| 1187 |
return TCL_OK; |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
static int |
| 1209 |
ImgBmapPostscript(clientData, interp, tkwin, psinfo, x, y, width, height, |
| 1210 |
prepass) |
| 1211 |
ClientData clientData; |
| 1212 |
Tcl_Interp *interp; |
| 1213 |
Tk_Window tkwin; |
| 1214 |
Tk_PostscriptInfo psinfo; |
| 1215 |
int x, y, width, height, prepass; |
| 1216 |
{ |
| 1217 |
BitmapMaster *masterPtr = (BitmapMaster *) clientData; |
| 1218 |
char buffer[200]; |
| 1219 |
|
| 1220 |
if (prepass) { |
| 1221 |
return TCL_OK; |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
if( width<=0 || height<=0 || masterPtr->width<=0 || masterPtr->height<=0 ){ |
| 1228 |
return TCL_OK; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
if( x!=0 || y!=0 ){ |
| 1240 |
sprintf(buffer, "%d %d moveto\n", x, y); |
| 1241 |
Tcl_AppendResult(interp, buffer, 0); |
| 1242 |
} |
| 1243 |
if( width!=1 || height!=1 ){ |
| 1244 |
sprintf(buffer, "%d %d scale\n", width, height); |
| 1245 |
Tcl_AppendResult(interp, buffer, 0); |
| 1246 |
} |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
if ((masterPtr->bgUid != NULL) && (masterPtr->bgUid[0] != '\0')) { |
| 1256 |
XColor color; |
| 1257 |
XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->bgUid, |
| 1258 |
&color); |
| 1259 |
if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) { |
| 1260 |
return TCL_ERROR; |
| 1261 |
} |
| 1262 |
if (masterPtr->maskData == NULL) { |
| 1263 |
Tcl_AppendResult(interp, |
| 1264 |
"0 0 moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto " |
| 1265 |
"closepath fill\n", 0 |
| 1266 |
); |
| 1267 |
} else if (ImgBmapPsImagemask(interp, masterPtr->width, |
| 1268 |
masterPtr->height, masterPtr->maskData) != TCL_OK) { |
| 1269 |
return TCL_ERROR; |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
if ( (masterPtr->fgUid != NULL) && (masterPtr->data != NULL) ) { |
| 1277 |
XColor color; |
| 1278 |
XParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin), masterPtr->fgUid, |
| 1279 |
&color); |
| 1280 |
if (Tk_PostscriptColor(interp, psinfo, &color) != TCL_OK) { |
| 1281 |
return TCL_ERROR; |
| 1282 |
} |
| 1283 |
if (ImgBmapPsImagemask(interp, masterPtr->width, masterPtr->height, |
| 1284 |
masterPtr->data) != TCL_OK) { |
| 1285 |
return TCL_ERROR; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
return TCL_OK; |
| 1289 |
} |
| 1290 |
|