| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkCanvas.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
typedef struct TkColormapData { |
| 29 |
int separated; |
| 30 |
int color; |
| 31 |
int ncolors; |
| 32 |
XColor *colors; |
| 33 |
int red_mask, green_mask, blue_mask; |
| 34 |
int red_shift, green_shift, blue_shift; |
| 35 |
} TkColormapData; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
typedef struct TkPostscriptInfo { |
| 44 |
int x, y, width, height; |
| 45 |
|
| 46 |
int x2, y2; |
| 47 |
char *pageXString; |
| 48 |
char *pageYString; |
| 49 |
double pageX, pageY; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
char *pageWidthString; |
| 54 |
char *pageHeightString; |
| 55 |
double scale; |
| 56 |
|
| 57 |
Tk_Anchor pageAnchor; |
| 58 |
int rotate; |
| 59 |
|
| 60 |
Var fontVar; |
| 61 |
|
| 62 |
|
| 63 |
Var colorVar; |
| 64 |
|
| 65 |
|
| 66 |
char *colorMode; |
| 67 |
|
| 68 |
int colorLevel; |
| 69 |
|
| 70 |
char *fileName; |
| 71 |
|
| 72 |
|
| 73 |
char *channelName; |
| 74 |
|
| 75 |
Tcl_Channel chan; |
| 76 |
Tcl_HashTable fontTable; |
| 77 |
|
| 78 |
|
| 79 |
int prepass; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
int prolog; |
| 84 |
|
| 85 |
} TkPostscriptInfo; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
static Tk_ConfigSpec configSpecs[] = { |
| 94 |
{TK_CONFIG_HASHVAR, "-colormap", (char *) NULL, (char *) NULL, |
| 95 |
"", Tk_Offset(TkPostscriptInfo, colorVar), 0}, |
| 96 |
{TK_CONFIG_STRING, "-colormode", (char *) NULL, (char *) NULL, |
| 97 |
"", Tk_Offset(TkPostscriptInfo, colorMode), 0}, |
| 98 |
{TK_CONFIG_STRING, "-file", (char *) NULL, (char *) NULL, |
| 99 |
"", Tk_Offset(TkPostscriptInfo, fileName), 0}, |
| 100 |
{TK_CONFIG_STRING, "-channel", (char *) NULL, (char *) NULL, |
| 101 |
"", Tk_Offset(TkPostscriptInfo, channelName), 0}, |
| 102 |
{TK_CONFIG_HASHVAR, "-fontmap", (char *) NULL, (char *) NULL, |
| 103 |
"", Tk_Offset(TkPostscriptInfo, fontVar), 0}, |
| 104 |
{TK_CONFIG_PIXELS, "-height", (char *) NULL, (char *) NULL, |
| 105 |
"", Tk_Offset(TkPostscriptInfo, height), 0}, |
| 106 |
{TK_CONFIG_ANCHOR, "-pageanchor", (char *) NULL, (char *) NULL, |
| 107 |
"", Tk_Offset(TkPostscriptInfo, pageAnchor), 0}, |
| 108 |
{TK_CONFIG_STRING, "-pageheight", (char *) NULL, (char *) NULL, |
| 109 |
"", Tk_Offset(TkPostscriptInfo, pageHeightString), 0}, |
| 110 |
{TK_CONFIG_STRING, "-pagewidth", (char *) NULL, (char *) NULL, |
| 111 |
"", Tk_Offset(TkPostscriptInfo, pageWidthString), 0}, |
| 112 |
{TK_CONFIG_STRING, "-pagex", (char *) NULL, (char *) NULL, |
| 113 |
"", Tk_Offset(TkPostscriptInfo, pageXString), 0}, |
| 114 |
{TK_CONFIG_STRING, "-pagey", (char *) NULL, (char *) NULL, |
| 115 |
"", Tk_Offset(TkPostscriptInfo, pageYString), 0}, |
| 116 |
{TK_CONFIG_BOOLEAN, "-prolog", (char *) NULL, (char *) NULL, |
| 117 |
"", Tk_Offset(TkPostscriptInfo, prolog), 0}, |
| 118 |
{TK_CONFIG_BOOLEAN, "-rotate", (char *) NULL, (char *) NULL, |
| 119 |
"", Tk_Offset(TkPostscriptInfo, rotate), 0}, |
| 120 |
{TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL, |
| 121 |
"", Tk_Offset(TkPostscriptInfo, width), 0}, |
| 122 |
{TK_CONFIG_PIXELS, "-x", (char *) NULL, (char *) NULL, |
| 123 |
"", Tk_Offset(TkPostscriptInfo, x), 0}, |
| 124 |
{TK_CONFIG_PIXELS, "-y", (char *) NULL, (char *) NULL, |
| 125 |
"", Tk_Offset(TkPostscriptInfo, y), 0}, |
| 126 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 127 |
(char *) NULL, 0, 0} |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
static int GetPostscriptPoints _ANSI_ARGS_((Tcl_Interp *interp, |
| 135 |
char *string, double *doublePtr)); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
int |
| 157 |
TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) |
| 158 |
TkCanvas *canvasPtr; |
| 159 |
Tcl_Interp *interp; |
| 160 |
int argc; |
| 161 |
CONST84 Tcl_Obj *CONST *objv; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
{ |
| 166 |
TkPostscriptInfo psInfo; |
| 167 |
Tk_PostscriptInfo oldInfoPtr; |
| 168 |
int result; |
| 169 |
Tk_Item *itemPtr; |
| 170 |
#define STRING_LENGTH 400 |
| 171 |
char string[STRING_LENGTH+1]; |
| 172 |
CONST char *p; |
| 173 |
time_t now; |
| 174 |
size_t length; |
| 175 |
Tk_Window tkwin = canvasPtr->tkwin; |
| 176 |
int deltaX = 0, deltaY = 0; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
Tcl_HashSearch search; |
| 184 |
Tcl_HashEntry *hPtr; |
| 185 |
Tcl_DString buffer; |
| 186 |
#ifndef _LANG |
| 187 |
char psenccmd[]="::tk::ensure_psenc_is_loaded"; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
result = Tcl_EvalEx(interp,psenccmd,-1,TCL_EVAL_GLOBAL); |
| 196 |
if (result != TCL_OK) { |
| 197 |
return result; |
| 198 |
} |
| 199 |
#endif |
| 200 |
oldInfoPtr = canvasPtr->psInfo; |
| 201 |
canvasPtr->psInfo = (Tk_PostscriptInfo) &psInfo; |
| 202 |
psInfo.x = canvasPtr->xOrigin; |
| 203 |
psInfo.y = canvasPtr->yOrigin; |
| 204 |
psInfo.width = -1; |
| 205 |
psInfo.height = -1; |
| 206 |
psInfo.pageXString = NULL; |
| 207 |
psInfo.pageYString = NULL; |
| 208 |
psInfo.pageX = 72*4.25; |
| 209 |
psInfo.pageY = 72*5.5; |
| 210 |
psInfo.pageWidthString = NULL; |
| 211 |
psInfo.pageHeightString = NULL; |
| 212 |
psInfo.scale = 1.0; |
| 213 |
psInfo.pageAnchor = TK_ANCHOR_CENTER; |
| 214 |
psInfo.rotate = 0; |
| 215 |
psInfo.fontVar = NULL; |
| 216 |
psInfo.colorVar = NULL; |
| 217 |
psInfo.colorMode = NULL; |
| 218 |
psInfo.colorLevel = 0; |
| 219 |
psInfo.fileName = NULL; |
| 220 |
psInfo.channelName = NULL; |
| 221 |
psInfo.chan = NULL; |
| 222 |
psInfo.prepass = 0; |
| 223 |
psInfo.prolog = 1; |
| 224 |
Tcl_InitHashTable(&psInfo.fontTable, TCL_STRING_KEYS); |
| 225 |
result = Tk_ConfigureWidget(interp, tkwin, |
| 226 |
configSpecs, argc-2, argv+2, (char *) &psInfo, |
| 227 |
TK_CONFIG_ARGV_ONLY); |
| 228 |
if (result != TCL_OK) { |
| 229 |
goto cleanup; |
| 230 |
} |
| 231 |
|
| 232 |
if (psInfo.width == -1) { |
| 233 |
psInfo.width = Tk_Width(tkwin); |
| 234 |
} |
| 235 |
if (psInfo.height == -1) { |
| 236 |
psInfo.height = Tk_Height(tkwin); |
| 237 |
} |
| 238 |
psInfo.x2 = psInfo.x + psInfo.width; |
| 239 |
psInfo.y2 = psInfo.y + psInfo.height; |
| 240 |
|
| 241 |
if (psInfo.pageXString != NULL) { |
| 242 |
if (GetPostscriptPoints(interp, psInfo.pageXString, |
| 243 |
&psInfo.pageX) != TCL_OK) { |
| 244 |
goto cleanup; |
| 245 |
} |
| 246 |
} |
| 247 |
if (psInfo.pageYString != NULL) { |
| 248 |
if (GetPostscriptPoints(interp, psInfo.pageYString, |
| 249 |
&psInfo.pageY) != TCL_OK) { |
| 250 |
goto cleanup; |
| 251 |
} |
| 252 |
} |
| 253 |
if (psInfo.pageWidthString != NULL) { |
| 254 |
if (GetPostscriptPoints(interp, psInfo.pageWidthString, |
| 255 |
&psInfo.scale) != TCL_OK) { |
| 256 |
goto cleanup; |
| 257 |
} |
| 258 |
psInfo.scale /= psInfo.width; |
| 259 |
} else if (psInfo.pageHeightString != NULL) { |
| 260 |
if (GetPostscriptPoints(interp, psInfo.pageHeightString, |
| 261 |
&psInfo.scale) != TCL_OK) { |
| 262 |
goto cleanup; |
| 263 |
} |
| 264 |
psInfo.scale /= psInfo.height; |
| 265 |
} else { |
| 266 |
psInfo.scale = (72.0/25.4)*WidthMMOfScreen(Tk_Screen(tkwin)); |
| 267 |
psInfo.scale /= WidthOfScreen(Tk_Screen(tkwin)); |
| 268 |
} |
| 269 |
switch (psInfo.pageAnchor) { |
| 270 |
case TK_ANCHOR_NW: |
| 271 |
case TK_ANCHOR_W: |
| 272 |
case TK_ANCHOR_SW: |
| 273 |
deltaX = 0; |
| 274 |
break; |
| 275 |
case TK_ANCHOR_N: |
| 276 |
case TK_ANCHOR_CENTER: |
| 277 |
case TK_ANCHOR_S: |
| 278 |
deltaX = -psInfo.width/2; |
| 279 |
break; |
| 280 |
case TK_ANCHOR_NE: |
| 281 |
case TK_ANCHOR_E: |
| 282 |
case TK_ANCHOR_SE: |
| 283 |
deltaX = -psInfo.width; |
| 284 |
break; |
| 285 |
} |
| 286 |
switch (psInfo.pageAnchor) { |
| 287 |
case TK_ANCHOR_NW: |
| 288 |
case TK_ANCHOR_N: |
| 289 |
case TK_ANCHOR_NE: |
| 290 |
deltaY = - psInfo.height; |
| 291 |
break; |
| 292 |
case TK_ANCHOR_W: |
| 293 |
case TK_ANCHOR_CENTER: |
| 294 |
case TK_ANCHOR_E: |
| 295 |
deltaY = -psInfo.height/2; |
| 296 |
break; |
| 297 |
case TK_ANCHOR_SW: |
| 298 |
case TK_ANCHOR_S: |
| 299 |
case TK_ANCHOR_SE: |
| 300 |
deltaY = 0; |
| 301 |
break; |
| 302 |
} |
| 303 |
|
| 304 |
if (psInfo.colorMode == NULL) { |
| 305 |
psInfo.colorLevel = 2; |
| 306 |
} else { |
| 307 |
length = strlen(psInfo.colorMode); |
| 308 |
if (strncmp(psInfo.colorMode, "monochrome", length) == 0) { |
| 309 |
psInfo.colorLevel = 0; |
| 310 |
} else if (strncmp(psInfo.colorMode, "gray", length) == 0) { |
| 311 |
psInfo.colorLevel = 1; |
| 312 |
} else if (strncmp(psInfo.colorMode, "color", length) == 0) { |
| 313 |
psInfo.colorLevel = 2; |
| 314 |
} else { |
| 315 |
Tcl_AppendResult(interp, "bad color mode \"", |
| 316 |
psInfo.colorMode, "\": must be monochrome, ", |
| 317 |
"gray, or color", (char *) NULL); |
| 318 |
goto cleanup; |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
if (psInfo.fileName != NULL) { |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
if (psInfo.channelName != NULL) { |
| 329 |
Tcl_AppendResult(interp, "can't specify both -file", |
| 330 |
" and -channel", (char *) NULL); |
| 331 |
result = TCL_ERROR; |
| 332 |
goto cleanup; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
if (Tcl_IsSafe(interp)) { |
| 341 |
Tcl_AppendResult(interp, "can't specify -file in a", |
| 342 |
" safe interpreter", (char *) NULL); |
| 343 |
result = TCL_ERROR; |
| 344 |
goto cleanup; |
| 345 |
} |
| 346 |
|
| 347 |
p = Tcl_TranslateFileName(interp, psInfo.fileName, &buffer); |
| 348 |
if (p == NULL) { |
| 349 |
goto cleanup; |
| 350 |
} |
| 351 |
psInfo.chan = Tcl_OpenFileChannel(interp, p, "w", 0666); |
| 352 |
Tcl_DStringFree(&buffer); |
| 353 |
if (psInfo.chan == NULL) { |
| 354 |
goto cleanup; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
if (psInfo.channelName != NULL) { |
| 359 |
int mode; |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
psInfo.chan = Tcl_GetChannel(interp, psInfo.channelName, |
| 367 |
&mode); |
| 368 |
if (psInfo.chan == (Tcl_Channel) NULL) { |
| 369 |
result = TCL_ERROR; |
| 370 |
goto cleanup; |
| 371 |
} |
| 372 |
if ((mode & TCL_WRITABLE) == 0) { |
| 373 |
Tcl_AppendResult(interp, "channel \"", |
| 374 |
psInfo.channelName, "\" wasn't opened for writing", |
| 375 |
(char *) NULL); |
| 376 |
result = TCL_ERROR; |
| 377 |
goto cleanup; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
psInfo.prepass = 1; |
| 392 |
for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; |
| 393 |
itemPtr = itemPtr->nextPtr) { |
| 394 |
if ((itemPtr->x1 >= psInfo.x2) || (itemPtr->x2 < psInfo.x) |
| 395 |
|| (itemPtr->y1 >= psInfo.y2) || (itemPtr->y2 < psInfo.y)) { |
| 396 |
continue; |
| 397 |
} |
| 398 |
if (itemPtr->group != canvasPtr->activeGroup) { |
| 399 |
continue; |
| 400 |
} |
| 401 |
if (itemPtr->typePtr->postscriptProc == NULL) { |
| 402 |
continue; |
| 403 |
} |
| 404 |
result = (*itemPtr->typePtr->postscriptProc)(interp, |
| 405 |
(Tk_Canvas) canvasPtr, itemPtr, 1); |
| 406 |
Tcl_ResetResult(interp); |
| 407 |
if (result != TCL_OK) { |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
break; |
| 416 |
} |
| 417 |
} |
| 418 |
psInfo.prepass = 0; |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
if (psInfo.prolog) { |
| 427 |
Tcl_AppendResult(interp, "%!PS-Adobe-3.0 EPSF-3.0\n", |
| 428 |
"%%Creator: Tk Canvas Widget\n", (char *) NULL); |
| 429 |
#ifdef HAVE_PW_GECOS |
| 430 |
if (!Tcl_IsSafe(interp)) { |
| 431 |
struct passwd *pwPtr = getpwuid(getuid()); |
| 432 |
Tcl_AppendResult(interp, "%%For: ", |
| 433 |
(pwPtr != NULL) ? pwPtr->pw_gecos : "Unknown", "\n", |
| 434 |
(char *) NULL); |
| 435 |
endpwent(); |
| 436 |
} |
| 437 |
#endif |
| 438 |
Tcl_AppendResult(interp, "%%Title: Window ", |
| 439 |
Tk_PathName(tkwin), "\n", (char *) NULL); |
| 440 |
time(&now); |
| 441 |
Tcl_AppendResult(interp, "%%CreationDate: ", |
| 442 |
ctime(&now), (char *) NULL); |
| 443 |
if (!psInfo.rotate) { |
| 444 |
sprintf(string, "%d %d %d %d", |
| 445 |
(int) (psInfo.pageX + psInfo.scale*deltaX), |
| 446 |
(int) (psInfo.pageY + psInfo.scale*deltaY), |
| 447 |
(int) (psInfo.pageX + psInfo.scale*(deltaX + psInfo.width) |
| 448 |
+ 1.0), |
| 449 |
(int) (psInfo.pageY + psInfo.scale*(deltaY + psInfo.height) |
| 450 |
+ 1.0)); |
| 451 |
} else { |
| 452 |
sprintf(string, "%d %d %d %d", |
| 453 |
(int) (psInfo.pageX - psInfo.scale*(deltaY + psInfo.height)), |
| 454 |
(int) (psInfo.pageY + psInfo.scale*deltaX), |
| 455 |
(int) (psInfo.pageX - psInfo.scale*deltaY + 1.0), |
| 456 |
(int) (psInfo.pageY + psInfo.scale*(deltaX + psInfo.width) |
| 457 |
+ 1.0)); |
| 458 |
} |
| 459 |
Tcl_AppendResult(interp, "%%BoundingBox: ", string, |
| 460 |
"\n", (char *) NULL); |
| 461 |
Tcl_AppendResult(interp, "%%Pages: 1\n", |
| 462 |
"%%DocumentData: Clean7Bit\n", (char *) NULL); |
| 463 |
Tcl_AppendResult(interp, "%%Orientation: ", |
| 464 |
psInfo.rotate ? "Landscape\n" : "Portrait\n", (char *) NULL); |
| 465 |
p = "%%DocumentNeededResources: font "; |
| 466 |
for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); |
| 467 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 468 |
Tcl_AppendResult(interp, p, |
| 469 |
Tcl_GetHashKey(&psInfo.fontTable, hPtr), |
| 470 |
"\n", (char *) NULL); |
| 471 |
p = "%%+ font "; |
| 472 |
} |
| 473 |
Tcl_AppendResult(interp, "%%EndComments\n\n", (char *) NULL); |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
Tcl_AppendResult(interp, Tcl_GetVar(interp,"::tk::ps_preamable", |
| 479 |
TCL_GLOBAL_ONLY), (char *) NULL); |
| 480 |
|
| 481 |
if (psInfo.chan != NULL) { |
| 482 |
Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); |
| 483 |
Tcl_ResetResult(canvasPtr->interp); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
sprintf(string, "/CL %d def\n", psInfo.colorLevel); |
| 493 |
Tcl_AppendResult(interp, "%%BeginSetup\n", string, |
| 494 |
(char *) NULL); |
| 495 |
for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); |
| 496 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 497 |
Tcl_AppendResult(interp, "%%IncludeResource: font ", |
| 498 |
Tcl_GetHashKey(&psInfo.fontTable, hPtr), "\n", (char *) NULL); |
| 499 |
} |
| 500 |
Tcl_AppendResult(interp, "%%EndSetup\n\n", (char *) NULL); |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
Tcl_AppendResult(interp, "%%Page: 1 1\n", "save\n", |
| 511 |
(char *) NULL); |
| 512 |
sprintf(string, "%.1f %.1f translate\n", psInfo.pageX, psInfo.pageY); |
| 513 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 514 |
if (psInfo.rotate) { |
| 515 |
Tcl_AppendResult(interp, "90 rotate\n", (char *) NULL); |
| 516 |
} |
| 517 |
sprintf(string, "%.4g %.4g scale\n", psInfo.scale, psInfo.scale); |
| 518 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 519 |
sprintf(string, "%d %d translate\n", deltaX - psInfo.x, deltaY); |
| 520 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 521 |
sprintf(string, "%d %.15g moveto %d %.15g lineto %d %.15g lineto %d %.15g", |
| 522 |
psInfo.x, |
| 523 |
Tk_PostscriptY((double) psInfo.y, (Tk_PostscriptInfo) &psInfo), |
| 524 |
psInfo.x2, |
| 525 |
Tk_PostscriptY((double) psInfo.y, (Tk_PostscriptInfo) &psInfo), |
| 526 |
psInfo.x2, |
| 527 |
Tk_PostscriptY((double) psInfo.y2, (Tk_PostscriptInfo) &psInfo), |
| 528 |
psInfo.x, |
| 529 |
Tk_PostscriptY((double) psInfo.y2, (Tk_PostscriptInfo) &psInfo)); |
| 530 |
Tcl_AppendResult(interp, string, |
| 531 |
" lineto closepath clip newpath\n", (char *) NULL); |
| 532 |
} |
| 533 |
if (psInfo.chan != NULL) { |
| 534 |
Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); |
| 535 |
Tcl_ResetResult(canvasPtr->interp); |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
result = TCL_OK; |
| 546 |
for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; |
| 547 |
itemPtr = itemPtr->nextPtr) { |
| 548 |
if ((itemPtr->x1 >= psInfo.x2) || (itemPtr->x2 < psInfo.x) |
| 549 |
|| (itemPtr->y1 >= psInfo.y2) || (itemPtr->y2 < psInfo.y)) { |
| 550 |
continue; |
| 551 |
} |
| 552 |
if (itemPtr->group != canvasPtr->activeGroup) { |
| 553 |
continue; |
| 554 |
} |
| 555 |
if (itemPtr->typePtr->postscriptProc == NULL) { |
| 556 |
continue; |
| 557 |
} |
| 558 |
if (itemPtr->state == TK_STATE_HIDDEN) { |
| 559 |
continue; |
| 560 |
} |
| 561 |
Tcl_AppendResult(interp, "gsave\n", (char *) NULL); |
| 562 |
result = (*itemPtr->typePtr->postscriptProc)(interp, |
| 563 |
(Tk_Canvas) canvasPtr, itemPtr, 0); |
| 564 |
if (result != TCL_OK) { |
| 565 |
char msg[64 + TCL_INTEGER_SPACE]; |
| 566 |
|
| 567 |
sprintf(msg, "\n (generating Postscript for item %d)", |
| 568 |
itemPtr->id); |
| 569 |
Tcl_AddErrorInfo(interp, msg); |
| 570 |
goto cleanup; |
| 571 |
} |
| 572 |
Tcl_AppendResult(interp, "grestore\n", (char *) NULL); |
| 573 |
if (psInfo.chan != NULL) { |
| 574 |
Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); |
| 575 |
Tcl_ResetResult(interp); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
if (psInfo.prolog) { |
| 587 |
Tcl_AppendResult(interp, "restore showpage\n\n", |
| 588 |
"%%Trailer\nend\n%%EOF\n", (char *) NULL); |
| 589 |
} |
| 590 |
if (psInfo.chan != NULL) { |
| 591 |
Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); |
| 592 |
Tcl_ResetResult(canvasPtr->interp); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
cleanup: |
| 600 |
if (psInfo.pageXString != NULL) { |
| 601 |
ckfree(psInfo.pageXString); |
| 602 |
} |
| 603 |
if (psInfo.pageYString != NULL) { |
| 604 |
ckfree(psInfo.pageYString); |
| 605 |
} |
| 606 |
if (psInfo.pageWidthString != NULL) { |
| 607 |
ckfree(psInfo.pageWidthString); |
| 608 |
} |
| 609 |
if (psInfo.pageHeightString != NULL) { |
| 610 |
ckfree(psInfo.pageHeightString); |
| 611 |
} |
| 612 |
if (psInfo.fontVar != NULL) { |
| 613 |
LangFreeVar(psInfo.fontVar); |
| 614 |
} |
| 615 |
if (psInfo.colorVar != NULL) { |
| 616 |
LangFreeVar(psInfo.colorVar); |
| 617 |
} |
| 618 |
if (psInfo.colorMode != NULL) { |
| 619 |
ckfree(psInfo.colorMode); |
| 620 |
} |
| 621 |
if (psInfo.fileName != NULL) { |
| 622 |
ckfree(psInfo.fileName); |
| 623 |
} |
| 624 |
if ((psInfo.chan != NULL) && (psInfo.channelName == NULL)) { |
| 625 |
Tcl_Close(interp, psInfo.chan); |
| 626 |
} |
| 627 |
if (psInfo.channelName != NULL) { |
| 628 |
ckfree(psInfo.channelName); |
| 629 |
} |
| 630 |
Tcl_DeleteHashTable(&psInfo.fontTable); |
| 631 |
canvasPtr->psInfo = (Tk_PostscriptInfo) oldInfoPtr; |
| 632 |
return result; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
int |
| 658 |
Tk_PostscriptColor(interp, psInfo, colorPtr) |
| 659 |
Tcl_Interp *interp; |
| 660 |
Tk_PostscriptInfo psInfo; |
| 661 |
XColor *colorPtr; |
| 662 |
{ |
| 663 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 664 |
int tmp; |
| 665 |
double red, green, blue; |
| 666 |
char string[200]; |
| 667 |
|
| 668 |
if (psInfoPtr->prepass) { |
| 669 |
return TCL_OK; |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
if (psInfoPtr->colorVar != NULL) { |
| 679 |
Tcl_Obj * cmdString; |
| 680 |
Tcl_Obj *name = Tcl_NewStringObj(Tk_NameOfColor(colorPtr),-1); |
| 681 |
|
| 682 |
cmdString = Tcl_ObjGetVar2(interp, psInfoPtr->colorVar, name,0); |
| 683 |
Tcl_DecrRefCount(name); |
| 684 |
|
| 685 |
if (cmdString != NULL) { |
| 686 |
Tcl_AppendResult(interp, Tcl_GetString(cmdString), "\n", (char *) NULL); |
| 687 |
return TCL_OK; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
tmp = colorPtr->red; |
| 705 |
red = ((double) (tmp >> 8))/255.0; |
| 706 |
tmp = colorPtr->green; |
| 707 |
green = ((double) (tmp >> 8))/255.0; |
| 708 |
tmp = colorPtr->blue; |
| 709 |
blue = ((double) (tmp >> 8))/255.0; |
| 710 |
sprintf(string, "%.3f %.3f %.3f setrgbcolor AdjustColor\n", |
| 711 |
red, green, blue); |
| 712 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 713 |
return TCL_OK; |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
int |
| 740 |
Tk_PostscriptFont(interp, psInfo, tkfont) |
| 741 |
Tcl_Interp *interp; |
| 742 |
Tk_PostscriptInfo psInfo; |
| 743 |
Tk_Font tkfont; |
| 744 |
|
| 745 |
{ |
| 746 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 747 |
char *end; |
| 748 |
char pointString[TCL_INTEGER_SPACE]; |
| 749 |
Tcl_DString ds; |
| 750 |
int i, points; |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
Tcl_DStringInit(&ds); |
| 759 |
|
| 760 |
if (psInfoPtr->fontVar != NULL) { |
| 761 |
Tcl_Obj *list; |
| 762 |
int argc; |
| 763 |
double size; |
| 764 |
Tcl_Obj **objv; |
| 765 |
Tcl_Obj *name; |
| 766 |
|
| 767 |
name = Tcl_NewStringObj(Tk_NameOfFont(tkfont),-1); |
| 768 |
list = Tcl_ObjGetVar2(interp, psInfoPtr->fontVar, name, 0); |
| 769 |
Tcl_DecrRefCount(name); |
| 770 |
if (list != NULL) { |
| 771 |
if (Tcl_ListObjGetElements(interp, list, &argc, &argv) |
| 772 |
!= TCL_OK) { |
| 773 |
badMapEntry: |
| 774 |
Tcl_ResetResult(interp); |
| 775 |
Tcl_AppendResult(interp, "bad font map entry for \"", name, |
| 776 |
"\": \"", list, "\"", (char *) NULL); |
| 777 |
return TCL_ERROR; |
| 778 |
} |
| 779 |
if (argc != 2) { |
| 780 |
goto badMapEntry; |
| 781 |
} |
| 782 |
if (Tcl_GetDoubleFromObj(interp, objv[1], &size) != TCL_OK) { |
| 783 |
goto badMapEntry; |
| 784 |
} |
| 785 |
|
| 786 |
Tcl_DStringAppend(&ds, argv[0], -1); |
| 787 |
points = (int) size; |
| 788 |
#ifdef FIXME |
| 789 |
ckfree((char *) argv); |
| 790 |
#endif |
| 791 |
goto findfont; |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
points = Tk_PostscriptFontName(tkfont, &ds); |
| 796 |
|
| 797 |
findfont: |
| 798 |
sprintf(pointString, "%d", points); |
| 799 |
Tcl_AppendResult(interp, "/", Tcl_DStringValue(&ds), " findfont ", |
| 800 |
pointString, " scalefont ", (char *) NULL); |
| 801 |
if (strncasecmp(Tcl_DStringValue(&ds), "Symbol", 7) != 0) { |
| 802 |
Tcl_AppendResult(interp, "ISOEncode ", (char *) NULL); |
| 803 |
} |
| 804 |
Tcl_AppendResult(interp, "setfont\n", (char *) NULL); |
| 805 |
Tcl_CreateHashEntry(&psInfoPtr->fontTable, Tcl_DStringValue(&ds), &i); |
| 806 |
Tcl_DStringFree(&ds); |
| 807 |
|
| 808 |
return TCL_OK; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
#undef TkGetProlog |
| 834 |
int |
| 835 |
Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, |
| 836 |
height) |
| 837 |
Tcl_Interp *interp; |
| 838 |
Tk_Window tkwin; |
| 839 |
Tk_PostscriptInfo psInfo; |
| 840 |
Pixmap bitmap; |
| 841 |
|
| 842 |
int startX, startY; |
| 843 |
|
| 844 |
int width, height; |
| 845 |
{ |
| 846 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 847 |
XImage *imagePtr; |
| 848 |
int charsInLine, x, y, lastX, lastY, value, mask; |
| 849 |
unsigned int totalWidth, totalHeight; |
| 850 |
char string[100]; |
| 851 |
Window dummyRoot; |
| 852 |
int dummyX, dummyY; |
| 853 |
unsigned dummyBorderwidth, dummyDepth; |
| 854 |
|
| 855 |
if (psInfoPtr->prepass) { |
| 856 |
return TCL_OK; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot, |
| 868 |
(int *) &dummyX, (int *) &dummyY, (unsigned int *) &totalWidth, |
| 869 |
(unsigned int *) &totalHeight, &dummyBorderwidth, &dummyDepth); |
| 870 |
imagePtr = XGetImage(Tk_Display(tkwin), bitmap, 0, 0, |
| 871 |
totalWidth, totalHeight, 1, XYPixmap); |
| 872 |
Tcl_AppendResult(interp, "<", (char *) NULL); |
| 873 |
mask = 0x80; |
| 874 |
value = 0; |
| 875 |
charsInLine = 0; |
| 876 |
lastX = startX + width - 1; |
| 877 |
lastY = startY + height - 1; |
| 878 |
for (y = lastY; y >= startY; y--) { |
| 879 |
for (x = startX; x <= lastX; x++) { |
| 880 |
if (XGetPixel(imagePtr, x, y)) { |
| 881 |
value |= mask; |
| 882 |
} |
| 883 |
mask >>= 1; |
| 884 |
if (mask == 0) { |
| 885 |
sprintf(string, "%02x", value); |
| 886 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 887 |
mask = 0x80; |
| 888 |
value = 0; |
| 889 |
charsInLine += 2; |
| 890 |
if (charsInLine >= 60) { |
| 891 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 892 |
charsInLine = 0; |
| 893 |
} |
| 894 |
} |
| 895 |
} |
| 896 |
if (mask != 0x80) { |
| 897 |
sprintf(string, "%02x", value); |
| 898 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 899 |
mask = 0x80; |
| 900 |
value = 0; |
| 901 |
charsInLine += 2; |
| 902 |
} |
| 903 |
} |
| 904 |
Tcl_AppendResult(interp, ">", (char *) NULL); |
| 905 |
XDestroyImage(imagePtr); |
| 906 |
return TCL_OK; |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
int |
| 934 |
Tk_PostscriptStipple(interp, tkwin, psInfo, bitmap) |
| 935 |
Tcl_Interp *interp; |
| 936 |
Tk_Window tkwin; |
| 937 |
Tk_PostscriptInfo psInfo; |
| 938 |
|
| 939 |
Pixmap bitmap; |
| 940 |
{ |
| 941 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 942 |
int width, height; |
| 943 |
char string[TCL_INTEGER_SPACE * 2]; |
| 944 |
Window dummyRoot; |
| 945 |
int dummyX, dummyY; |
| 946 |
unsigned dummyBorderwidth, dummyDepth; |
| 947 |
|
| 948 |
if (psInfoPtr->prepass) { |
| 949 |
return TCL_OK; |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot, |
| 961 |
(int *) &dummyX, (int *) &dummyY, (unsigned *) &width, |
| 962 |
(unsigned *) &height, &dummyBorderwidth, &dummyDepth); |
| 963 |
sprintf(string, "%d %d ", width, height); |
| 964 |
Tcl_AppendResult(interp, string, (char *) NULL); |
| 965 |
if (Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, 0, 0, |
| 966 |
width, height) != TCL_OK) { |
| 967 |
return TCL_ERROR; |
| 968 |
} |
| 969 |
Tcl_AppendResult(interp, " StippleFill\n", (char *) NULL); |
| 970 |
return TCL_OK; |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
double |
| 992 |
Tk_PostscriptY(y, psInfo) |
| 993 |
double y; |
| 994 |
Tk_PostscriptInfo psInfo; |
| 995 |
{ |
| 996 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 997 |
|
| 998 |
return psInfoPtr->y2 - y; |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
void |
| 1019 |
Tk_PostscriptPath(interp, psInfo, coordPtr, numPoints) |
| 1020 |
Tcl_Interp *interp; |
| 1021 |
Tk_PostscriptInfo psInfo; |
| 1022 |
|
| 1023 |
double *coordPtr; |
| 1024 |
|
| 1025 |
|
| 1026 |
int numPoints; |
| 1027 |
{ |
| 1028 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 1029 |
char buffer[200]; |
| 1030 |
|
| 1031 |
if (psInfoPtr->prepass) { |
| 1032 |
return; |
| 1033 |
} |
| 1034 |
sprintf(buffer, "%.15g %.15g moveto\n", coordPtr[0], |
| 1035 |
Tk_PostscriptY(coordPtr[1], psInfo)); |
| 1036 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1037 |
for (numPoints--, coordPtr += 2; numPoints > 0; |
| 1038 |
numPoints--, coordPtr += 2) { |
| 1039 |
sprintf(buffer, "%.15g %.15g lineto\n", coordPtr[0], |
| 1040 |
Tk_PostscriptY(coordPtr[1], psInfo)); |
| 1041 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
static int |
| 1067 |
GetPostscriptPoints(interp, string, doublePtr) |
| 1068 |
Tcl_Interp *interp; |
| 1069 |
char *string; |
| 1070 |
double *doublePtr; |
| 1071 |
{ |
| 1072 |
char *end; |
| 1073 |
double d; |
| 1074 |
|
| 1075 |
d = strtod(string, &end); |
| 1076 |
if (end == string) { |
| 1077 |
error: |
| 1078 |
Tcl_AppendResult(interp, "bad distance \"", string, |
| 1079 |
"\"", (char *) NULL); |
| 1080 |
return TCL_ERROR; |
| 1081 |
} |
| 1082 |
while ((*end != '\0') && isspace(UCHAR(*end))) { |
| 1083 |
end++; |
| 1084 |
} |
| 1085 |
switch (*end) { |
| 1086 |
case 'c': |
| 1087 |
d *= 72.0/2.54; |
| 1088 |
end++; |
| 1089 |
break; |
| 1090 |
case 'i': |
| 1091 |
d *= 72.0; |
| 1092 |
end++; |
| 1093 |
break; |
| 1094 |
case 'm': |
| 1095 |
d *= 72.0/25.4; |
| 1096 |
end++; |
| 1097 |
break; |
| 1098 |
case 0: |
| 1099 |
break; |
| 1100 |
case 'p': |
| 1101 |
end++; |
| 1102 |
break; |
| 1103 |
default: |
| 1104 |
goto error; |
| 1105 |
} |
| 1106 |
while ((*end != '\0') && isspace(UCHAR(*end))) { |
| 1107 |
end++; |
| 1108 |
} |
| 1109 |
if (*end != 0) { |
| 1110 |
goto error; |
| 1111 |
} |
| 1112 |
*doublePtr = d; |
| 1113 |
return TCL_OK; |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
#ifdef WIN32 |
| 1143 |
#include <windows.h> |
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
static void |
| 1153 |
TkImageGetColor(cdata, pixel, red, green, blue) |
| 1154 |
TkColormapData *cdata; |
| 1155 |
unsigned long pixel; |
| 1156 |
double *red, *green, *blue; |
| 1157 |
{ |
| 1158 |
*red = (double) GetRValue(pixel) / 255.0; |
| 1159 |
*green = (double) GetGValue(pixel) / 255.0; |
| 1160 |
*blue = (double) GetBValue(pixel) / 255.0; |
| 1161 |
} |
| 1162 |
#else |
| 1163 |
static void |
| 1164 |
TkImageGetColor(cdata, pixel, red, green, blue) |
| 1165 |
TkColormapData *cdata; |
| 1166 |
unsigned long pixel; |
| 1167 |
double *red, *green, *blue; |
| 1168 |
{ |
| 1169 |
if (cdata->separated) { |
| 1170 |
int r = (pixel & cdata->red_mask) >> cdata->red_shift; |
| 1171 |
int g = (pixel & cdata->green_mask) >> cdata->green_shift; |
| 1172 |
int b = (pixel & cdata->blue_mask) >> cdata->blue_shift; |
| 1173 |
*red = cdata->colors[r].red / 65535.0; |
| 1174 |
*green = cdata->colors[g].green / 65535.0; |
| 1175 |
*blue = cdata->colors[b].blue / 65535.0; |
| 1176 |
} else { |
| 1177 |
*red = cdata->colors[pixel].red / 65535.0; |
| 1178 |
*green = cdata->colors[pixel].green / 65535.0; |
| 1179 |
*blue = cdata->colors[pixel].blue / 65535.0; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
#endif |
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
int |
| 1208 |
TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) |
| 1209 |
Tcl_Interp *interp; |
| 1210 |
Tk_Window tkwin; |
| 1211 |
Tk_PostscriptInfo psInfo; |
| 1212 |
XImage *ximage; |
| 1213 |
int x, y; |
| 1214 |
int width, height; |
| 1215 |
{ |
| 1216 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 1217 |
char buffer[256]; |
| 1218 |
int xx, yy, band, maxRows; |
| 1219 |
double red, green, blue; |
| 1220 |
int bytesPerLine=0, maxWidth=0; |
| 1221 |
int level = psInfoPtr->colorLevel; |
| 1222 |
Colormap cmap; |
| 1223 |
int i, ncolors; |
| 1224 |
Visual *visual; |
| 1225 |
TkColormapData cdata; |
| 1226 |
|
| 1227 |
if (psInfoPtr->prepass) { |
| 1228 |
return TCL_OK; |
| 1229 |
} |
| 1230 |
|
| 1231 |
cmap = Tk_Colormap(tkwin); |
| 1232 |
visual = Tk_Visual(tkwin); |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
ncolors = visual->map_entries; |
| 1241 |
cdata.colors = (XColor *) ckalloc(sizeof(XColor) * ncolors); |
| 1242 |
cdata.ncolors = ncolors; |
| 1243 |
|
| 1244 |
if (visual->class == DirectColor || visual->class == TrueColor) { |
| 1245 |
cdata.separated = 1; |
| 1246 |
cdata.red_mask = visual->red_mask; |
| 1247 |
cdata.green_mask = visual->green_mask; |
| 1248 |
cdata.blue_mask = visual->blue_mask; |
| 1249 |
cdata.red_shift = 0; |
| 1250 |
cdata.green_shift = 0; |
| 1251 |
cdata.blue_shift = 0; |
| 1252 |
while ((0x0001 & (cdata.red_mask >> cdata.red_shift)) == 0) |
| 1253 |
cdata.red_shift ++; |
| 1254 |
while ((0x0001 & (cdata.green_mask >> cdata.green_shift)) == 0) |
| 1255 |
cdata.green_shift ++; |
| 1256 |
while ((0x0001 & (cdata.blue_mask >> cdata.blue_shift)) == 0) |
| 1257 |
cdata.blue_shift ++; |
| 1258 |
for (i = 0; i < ncolors; i ++) |
| 1259 |
cdata.colors[i].pixel = |
| 1260 |
((i << cdata.red_shift) & cdata.red_mask) | |
| 1261 |
((i << cdata.green_shift) & cdata.green_mask) | |
| 1262 |
((i << cdata.blue_shift) & cdata.blue_mask); |
| 1263 |
} else { |
| 1264 |
cdata.separated=0; |
| 1265 |
for (i = 0; i < ncolors; i ++) |
| 1266 |
cdata.colors[i].pixel = i; |
| 1267 |
} |
| 1268 |
if (visual->class == StaticGray || visual->class == GrayScale) |
| 1269 |
cdata.color = 0; |
| 1270 |
else |
| 1271 |
cdata.color = 1; |
| 1272 |
|
| 1273 |
XQueryColors(Tk_Display(tkwin), cmap, cdata.colors, ncolors); |
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
if (!cdata.color && level == 2) { |
| 1282 |
level = 1; |
| 1283 |
} |
| 1284 |
|
| 1285 |
if (!cdata.color && cdata.ncolors == 2) { |
| 1286 |
level = 0; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
switch (level) { |
| 1296 |
case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; |
| 1297 |
case 1: bytesPerLine = width; maxWidth = 60000; break; |
| 1298 |
case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; |
| 1299 |
} |
| 1300 |
|
| 1301 |
if (bytesPerLine > 60000) { |
| 1302 |
Tcl_ResetResult(interp); |
| 1303 |
sprintf(buffer, |
| 1304 |
"Can't generate Postscript for images more than %d pixels wide", |
| 1305 |
maxWidth); |
| 1306 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1307 |
ckfree((char *) cdata.colors); |
| 1308 |
return TCL_ERROR; |
| 1309 |
} |
| 1310 |
|
| 1311 |
maxRows = 60000 / bytesPerLine; |
| 1312 |
|
| 1313 |
for (band = height-1; band >= 0; band -= maxRows) { |
| 1314 |
int rows = (band >= maxRows) ? maxRows : band + 1; |
| 1315 |
int lineLen = 0; |
| 1316 |
switch (level) { |
| 1317 |
case 0: |
| 1318 |
sprintf(buffer, "%d %d 1 matrix {\n<", width, rows); |
| 1319 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1320 |
break; |
| 1321 |
case 1: |
| 1322 |
sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); |
| 1323 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1324 |
break; |
| 1325 |
case 2: |
| 1326 |
sprintf(buffer, "%d %d 8 matrix {\n<", |
| 1327 |
width, rows); |
| 1328 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1329 |
break; |
| 1330 |
} |
| 1331 |
for (yy = band; yy > band - rows; yy--) { |
| 1332 |
switch (level) { |
| 1333 |
case 0: { |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
unsigned char mask=0x80; |
| 1340 |
unsigned char data=0x00; |
| 1341 |
for (xx = x; xx< x+width; xx++) { |
| 1342 |
TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), |
| 1343 |
&red, &green, &blue); |
| 1344 |
if (0.30 * red + 0.59 * green + 0.11 * blue > 0.5) |
| 1345 |
data |= mask; |
| 1346 |
mask >>= 1; |
| 1347 |
if (mask == 0) { |
| 1348 |
sprintf(buffer, "%02X", data); |
| 1349 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1350 |
lineLen += 2; |
| 1351 |
if (lineLen > 60) { |
| 1352 |
lineLen = 0; |
| 1353 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1354 |
} |
| 1355 |
mask=0x80; |
| 1356 |
data=0x00; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
if ((width % 8) != 0) { |
| 1360 |
sprintf(buffer, "%02X", data); |
| 1361 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1362 |
mask=0x80; |
| 1363 |
data=0x00; |
| 1364 |
} |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
case 1: { |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
for (xx = x; xx < x+width; xx ++) { |
| 1373 |
TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), |
| 1374 |
&red, &green, &blue); |
| 1375 |
sprintf(buffer, "%02X", (int) floor(0.5 + 255.0 * |
| 1376 |
(0.30 * red + 0.59 * green + 0.11 * blue))); |
| 1377 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1378 |
lineLen += 2; |
| 1379 |
if (lineLen > 60) { |
| 1380 |
lineLen = 0; |
| 1381 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1382 |
} |
| 1383 |
} |
| 1384 |
break; |
| 1385 |
} |
| 1386 |
case 2: { |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
for (xx = x; xx < x+width; xx++) { |
| 1392 |
TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), |
| 1393 |
&red, &green, &blue); |
| 1394 |
sprintf(buffer, "%02X%02X%02X", |
| 1395 |
(int) floor(0.5 + 255.0 * red), |
| 1396 |
(int) floor(0.5 + 255.0 * green), |
| 1397 |
(int) floor(0.5 + 255.0 * blue)); |
| 1398 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1399 |
lineLen += 6; |
| 1400 |
if (lineLen > 60) { |
| 1401 |
lineLen = 0; |
| 1402 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1403 |
} |
| 1404 |
} |
| 1405 |
break; |
| 1406 |
} |
| 1407 |
} |
| 1408 |
} |
| 1409 |
switch (level) { |
| 1410 |
case 0: sprintf(buffer, ">\n} image\n"); break; |
| 1411 |
case 1: sprintf(buffer, ">\n} image\n"); break; |
| 1412 |
case 2: sprintf(buffer, ">\n} false 3 colorimage\n"); break; |
| 1413 |
} |
| 1414 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1415 |
sprintf(buffer, "0 %d translate\n", rows); |
| 1416 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1417 |
} |
| 1418 |
ckfree((char *) cdata.colors); |
| 1419 |
return TCL_OK; |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
int |
| 1444 |
Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) |
| 1445 |
Tcl_Interp *interp; |
| 1446 |
Tk_PhotoImageBlock *blockPtr; |
| 1447 |
Tk_PostscriptInfo psInfo; |
| 1448 |
int width, height; |
| 1449 |
{ |
| 1450 |
TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; |
| 1451 |
int colorLevel = psInfoPtr->colorLevel; |
| 1452 |
static int codeIncluded = 0; |
| 1453 |
|
| 1454 |
unsigned char *pixelPtr; |
| 1455 |
char buffer[256], cspace[40], decode[40]; |
| 1456 |
int bpc; |
| 1457 |
int xx, yy, lineLen; |
| 1458 |
float red, green, blue; |
| 1459 |
int alpha; |
| 1460 |
int bytesPerLine=0, maxWidth=0; |
| 1461 |
|
| 1462 |
unsigned char opaque = 255; |
| 1463 |
unsigned char *alphaPtr; |
| 1464 |
int alphaOffset, alphaPitch, alphaIncr; |
| 1465 |
|
| 1466 |
if (psInfoPtr->prepass) { |
| 1467 |
codeIncluded = 0; |
| 1468 |
return TCL_OK; |
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
if( !codeIncluded && (colorLevel != 0) ) { |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
codeIncluded = !0; |
| 1485 |
Tcl_AppendResult( interp, |
| 1486 |
"/TkPhoto { \n", |
| 1487 |
" gsave \n", |
| 1488 |
" 32 dict begin \n", |
| 1489 |
" /tinteger exch def \n", |
| 1490 |
" /transparent 1 string def \n", |
| 1491 |
" transparent 0 tinteger put \n", |
| 1492 |
" /olddict exch def \n", |
| 1493 |
" olddict /DataSource get dup type /filetype ne { \n", |
| 1494 |
" olddict /DataSource 3 -1 roll \n", |
| 1495 |
" 0 () /SubFileDecode filter put \n", |
| 1496 |
" } { \n", |
| 1497 |
" pop \n", |
| 1498 |
" } ifelse \n", |
| 1499 |
" /newdict olddict maxlength dict def \n", |
| 1500 |
" olddict newdict copy pop \n", |
| 1501 |
" /w newdict /Width get def \n", |
| 1502 |
" /crpp newdict /Decode get length 2 idiv def \n", |
| 1503 |
" /str w string def \n", |
| 1504 |
" /pix w crpp mul string def \n", |
| 1505 |
" /substrlen 2 w log 2 log div floor exp cvi def \n", |
| 1506 |
" /substrs [ \n", |
| 1507 |
" { \n", |
| 1508 |
" substrlen string \n", |
| 1509 |
" 0 1 substrlen 1 sub { \n", |
| 1510 |
" 1 index exch tinteger put \n", |
| 1511 |
" } for \n", |
| 1512 |
" /substrlen substrlen 2 idiv def \n", |
| 1513 |
" substrlen 0 eq {exit} if \n", |
| 1514 |
" } loop \n", |
| 1515 |
" ] def \n", |
| 1516 |
" /h newdict /Height get def \n", |
| 1517 |
" 1 w div 1 h div matrix scale \n", |
| 1518 |
" olddict /ImageMatrix get exch matrix concatmatrix \n", |
| 1519 |
" matrix invertmatrix concat \n", |
| 1520 |
" newdict /Height 1 put \n", |
| 1521 |
" newdict /DataSource pix put \n", |
| 1522 |
" /mat [w 0 0 h 0 0] def \n", |
| 1523 |
" newdict /ImageMatrix mat put \n", |
| 1524 |
" 0 1 h 1 sub { \n", |
| 1525 |
" mat 5 3 -1 roll neg put \n", |
| 1526 |
" olddict /DataSource get str readstring pop pop \n", |
| 1527 |
" /tail str def \n", |
| 1528 |
" /x 0 def \n", |
| 1529 |
" olddict /DataSource get pix readstring pop pop \n", |
| 1530 |
" { \n", |
| 1531 |
" tail transparent search dup /done exch not def \n", |
| 1532 |
" {exch pop exch pop} if \n", |
| 1533 |
" /w1 exch length def \n", |
| 1534 |
" w1 0 ne { \n", |
| 1535 |
" newdict /DataSource ", |
| 1536 |
" pix x crpp mul w1 crpp mul getinterval put \n", |
| 1537 |
" newdict /Width w1 put \n", |
| 1538 |
" mat 4 x neg put \n", |
| 1539 |
" /x x w1 add def \n", |
| 1540 |
" newdict image \n", |
| 1541 |
" /tail tail w1 tail length w1 sub getinterval def \n", |
| 1542 |
" } if \n", |
| 1543 |
" done {exit} if \n", |
| 1544 |
" tail substrs { \n", |
| 1545 |
" anchorsearch {pop} if \n", |
| 1546 |
" } forall \n", |
| 1547 |
" /tail exch def \n", |
| 1548 |
" tail length 0 eq {exit} if \n", |
| 1549 |
" /x w tail length sub def \n", |
| 1550 |
" } loop \n", |
| 1551 |
" } for \n", |
| 1552 |
" end \n", |
| 1553 |
" grestore \n", |
| 1554 |
"} bind def \n\n\n", (char *) NULL); |
| 1555 |
} else if( !codeIncluded && (colorLevel == 0) ) { |
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
codeIncluded = !0; |
| 1561 |
Tcl_AppendResult( interp, |
| 1562 |
"/TkPhoto { \n", |
| 1563 |
" gsave \n", |
| 1564 |
" 32 dict begin \n", |
| 1565 |
" /dummyInteger exch def \n", |
| 1566 |
" /olddict exch def \n", |
| 1567 |
" olddict /DataSource get dup type /filetype ne { \n", |
| 1568 |
" olddict /DataSource 3 -1 roll \n", |
| 1569 |
" 0 () /SubFileDecode filter put \n", |
| 1570 |
" } { \n", |
| 1571 |
" pop \n", |
| 1572 |
" } ifelse \n", |
| 1573 |
" /newdict olddict maxlength dict def \n", |
| 1574 |
" olddict newdict copy pop \n", |
| 1575 |
" /w newdict /Width get def \n", |
| 1576 |
" /pix w 7 add 8 idiv string def \n", |
| 1577 |
" /h newdict /Height get def \n", |
| 1578 |
" 1 w div 1 h div matrix scale \n", |
| 1579 |
" olddict /ImageMatrix get exch matrix concatmatrix \n", |
| 1580 |
" matrix invertmatrix concat \n", |
| 1581 |
" newdict /Height 1 put \n", |
| 1582 |
" newdict /DataSource pix put \n", |
| 1583 |
" /mat [w 0 0 h 0 0] def \n", |
| 1584 |
" newdict /ImageMatrix mat put \n", |
| 1585 |
" 0 1 h 1 sub { \n", |
| 1586 |
" mat 5 3 -1 roll neg put \n", |
| 1587 |
" 0.000 0.000 0.000 setrgbcolor \n", |
| 1588 |
" olddict /DataSource get pix readstring pop pop \n", |
| 1589 |
" newdict /DataSource pix put \n", |
| 1590 |
" newdict imagemask \n", |
| 1591 |
" 1.000 1.000 1.000 setrgbcolor \n", |
| 1592 |
" olddict /DataSource get pix readstring pop pop \n", |
| 1593 |
" newdict /DataSource pix put \n", |
| 1594 |
" newdict imagemask \n", |
| 1595 |
" } for \n", |
| 1596 |
" end \n", |
| 1597 |
" grestore \n", |
| 1598 |
"} bind def \n\n\n", (char *) NULL); |
| 1599 |
} |
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
switch (colorLevel) |
| 1608 |
{ |
| 1609 |
case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; |
| 1610 |
case 1: bytesPerLine = width; maxWidth = 60000; break; |
| 1611 |
case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; |
| 1612 |
} |
| 1613 |
if (bytesPerLine > 60000) { |
| 1614 |
Tcl_ResetResult(interp); |
| 1615 |
sprintf(buffer, |
| 1616 |
"Can't generate Postscript for images more than %d pixels wide", |
| 1617 |
maxWidth); |
| 1618 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1619 |
return TCL_ERROR; |
| 1620 |
} |
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
switch (colorLevel) { |
| 1627 |
case 0: |
| 1628 |
strcpy( cspace, "/DeviceGray"); |
| 1629 |
strcpy( decode, "[1 0]"); |
| 1630 |
bpc = 1; |
| 1631 |
break; |
| 1632 |
case 1: |
| 1633 |
strcpy( cspace, "/DeviceGray"); |
| 1634 |
strcpy( decode, "[0 1]"); |
| 1635 |
bpc = 8; |
| 1636 |
break; |
| 1637 |
default: |
| 1638 |
strcpy( cspace, "/DeviceRGB"); |
| 1639 |
strcpy( decode, "[0 1 0 1 0 1]"); |
| 1640 |
bpc = 8; |
| 1641 |
break; |
| 1642 |
} |
| 1643 |
|
| 1644 |
|
| 1645 |
Tcl_AppendResult(interp, |
| 1646 |
cspace, " setcolorspace\n\n", (char *) NULL); |
| 1647 |
|
| 1648 |
sprintf(buffer, |
| 1649 |
" /Width %d\n /Height %d\n /BitsPerComponent %d\n", |
| 1650 |
width, height, bpc); |
| 1651 |
Tcl_AppendResult(interp, |
| 1652 |
"<<\n /ImageType 1\n", buffer, |
| 1653 |
" /DataSource currentfile", |
| 1654 |
" /ASCIIHexDecode filter\n", (char *) NULL); |
| 1655 |
|
| 1656 |
|
| 1657 |
sprintf(buffer, |
| 1658 |
" /ImageMatrix [1 0 0 -1 0 %d]\n", height); |
| 1659 |
Tcl_AppendResult(interp, buffer, |
| 1660 |
" /Decode ", decode, "\n>>\n1 TkPhoto\n", (char *) NULL); |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
if (blockPtr->pixelSize == 3) { |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
alphaPtr = &opaque; |
| 1676 |
alphaPitch = alphaIncr = alphaOffset = 0; |
| 1677 |
} else { |
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
alphaPtr = blockPtr->pixelPtr; |
| 1683 |
alphaPitch = blockPtr->pitch; |
| 1684 |
alphaIncr = blockPtr->pixelSize; |
| 1685 |
alphaOffset = blockPtr->offset[3]; |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
for (yy = 0, lineLen=0; yy < height; yy++) { |
| 1690 |
switch (colorLevel) { |
| 1691 |
case 0: { |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
unsigned char mask=0x80; |
| 1701 |
unsigned char data=0x00; |
| 1702 |
for (xx = 0; xx< width; xx ++) { |
| 1703 |
pixelPtr = blockPtr->pixelPtr |
| 1704 |
+ (yy * blockPtr->pitch) |
| 1705 |
+ (xx *blockPtr->pixelSize); |
| 1706 |
|
| 1707 |
red = pixelPtr[blockPtr->offset[0]]; |
| 1708 |
green = pixelPtr[blockPtr->offset[1]]; |
| 1709 |
blue = pixelPtr[blockPtr->offset[2]]; |
| 1710 |
|
| 1711 |
alpha = *(alphaPtr + (yy * alphaPitch) |
| 1712 |
+ (xx * alphaIncr) + alphaOffset); |
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
if ((alpha != 0) && |
| 1719 |
( 0.3086 * red |
| 1720 |
+ 0.6094 * green |
| 1721 |
+ 0.082 * blue < 128)) { |
| 1722 |
data |= mask; |
| 1723 |
} |
| 1724 |
mask >>= 1; |
| 1725 |
if (mask == 0) { |
| 1726 |
sprintf(buffer, "%02X", data); |
| 1727 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1728 |
lineLen += 2; |
| 1729 |
if (lineLen >= 60) { |
| 1730 |
lineLen = 0; |
| 1731 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1732 |
} |
| 1733 |
mask=0x80; |
| 1734 |
data=0x00; |
| 1735 |
} |
| 1736 |
} |
| 1737 |
if ((width % 8) != 0) { |
| 1738 |
sprintf(buffer, "%02X", data); |
| 1739 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1740 |
mask=0x80; |
| 1741 |
data=0x00; |
| 1742 |
} |
| 1743 |
|
| 1744 |
mask=0x80; |
| 1745 |
data=0x00; |
| 1746 |
for (xx = 0; xx< width; xx ++) { |
| 1747 |
pixelPtr = blockPtr->pixelPtr |
| 1748 |
+ (yy * blockPtr->pitch) |
| 1749 |
+ (xx *blockPtr->pixelSize); |
| 1750 |
|
| 1751 |
red = pixelPtr[blockPtr->offset[0]]; |
| 1752 |
green = pixelPtr[blockPtr->offset[1]]; |
| 1753 |
blue = pixelPtr[blockPtr->offset[2]]; |
| 1754 |
|
| 1755 |
alpha = *(alphaPtr + (yy * alphaPitch) |
| 1756 |
+ (xx * alphaIncr) + alphaOffset); |
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
if ((alpha != 0) && |
| 1763 |
( 0.3086 * red |
| 1764 |
+ 0.6094 * green |
| 1765 |
+ 0.082 * blue >= 128)) { |
| 1766 |
data |= mask; |
| 1767 |
} |
| 1768 |
mask >>= 1; |
| 1769 |
if (mask == 0) { |
| 1770 |
sprintf(buffer, "%02X", data); |
| 1771 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1772 |
lineLen += 2; |
| 1773 |
if (lineLen >= 60) { |
| 1774 |
lineLen = 0; |
| 1775 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1776 |
} |
| 1777 |
mask=0x80; |
| 1778 |
data=0x00; |
| 1779 |
} |
| 1780 |
} |
| 1781 |
if ((width % 8) != 0) { |
| 1782 |
sprintf(buffer, "%02X", data); |
| 1783 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1784 |
mask=0x80; |
| 1785 |
data=0x00; |
| 1786 |
} |
| 1787 |
break; |
| 1788 |
} |
| 1789 |
case 1: { |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
for (xx = 0; xx < width; xx ++) { |
| 1797 |
alpha = *(alphaPtr + (yy * alphaPitch) |
| 1798 |
+ (xx * alphaIncr) + alphaOffset); |
| 1799 |
sprintf(buffer, "%02X", alpha | 0x01); |
| 1800 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1801 |
lineLen += 2; |
| 1802 |
if (lineLen >= 60) { |
| 1803 |
lineLen = 0; |
| 1804 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1805 |
} |
| 1806 |
} |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
for (xx = 0; xx < width; xx ++) { |
| 1815 |
pixelPtr = blockPtr->pixelPtr |
| 1816 |
+ (yy * blockPtr->pitch) |
| 1817 |
+ (xx *blockPtr->pixelSize); |
| 1818 |
|
| 1819 |
red = pixelPtr[blockPtr->offset[0]]; |
| 1820 |
green = pixelPtr[blockPtr->offset[1]]; |
| 1821 |
blue = pixelPtr[blockPtr->offset[2]]; |
| 1822 |
|
| 1823 |
sprintf(buffer, "%02X", (int) floor(0.5 + |
| 1824 |
( 0.3086 * red + 0.6094 * green + 0.0820 * blue))); |
| 1825 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1826 |
lineLen += 2; |
| 1827 |
if (lineLen >= 60) { |
| 1828 |
lineLen = 0; |
| 1829 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1830 |
} |
| 1831 |
} |
| 1832 |
break; |
| 1833 |
} |
| 1834 |
default: { |
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
for (xx = 0; xx < width; xx ++) { |
| 1842 |
alpha = *(alphaPtr + (yy * alphaPitch) |
| 1843 |
+ (xx * alphaIncr) + alphaOffset); |
| 1844 |
sprintf(buffer, "%02X", alpha | 0x01); |
| 1845 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1846 |
lineLen += 2; |
| 1847 |
if (lineLen >= 60) { |
| 1848 |
lineLen = 0; |
| 1849 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1850 |
} |
| 1851 |
} |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
for (xx = 0; xx < width; xx ++) { |
| 1860 |
pixelPtr = blockPtr->pixelPtr |
| 1861 |
+ (yy * blockPtr->pitch) |
| 1862 |
+ (xx *blockPtr->pixelSize); |
| 1863 |
|
| 1864 |
sprintf(buffer, "%02X%02X%02X", |
| 1865 |
pixelPtr[blockPtr->offset[0]], |
| 1866 |
pixelPtr[blockPtr->offset[1]], |
| 1867 |
pixelPtr[blockPtr->offset[2]]); |
| 1868 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1869 |
lineLen += 6; |
| 1870 |
if (lineLen >= 60) { |
| 1871 |
lineLen = 0; |
| 1872 |
Tcl_AppendResult(interp, "\n", (char *) NULL); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
break; |
| 1876 |
} |
| 1877 |
} |
| 1878 |
} |
| 1879 |
|
| 1880 |
Tcl_AppendResult(interp, ">\n", (char *) NULL); |
| 1881 |
return TCL_OK; |
| 1882 |
} |
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|