1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 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 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 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 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 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 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 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 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 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 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 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 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 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 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 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 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
|
/*
* bltText.c --
*
* This module implements multi-line, rotate-able text for the BLT toolkit.
*
* Copyright 1993-1998 Lucent Technologies, Inc.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and warranty
* disclaimer appear in supporting documentation, and that the names
* of Lucent Technologies any of their entities not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
* Lucent Technologies disclaims all warranties with regard to this
* software, including all implied warranties of merchantability and
* fitness. In no event shall Lucent Technologies be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether in
* an action of contract, negligence or other tortuous action, arising
* out of or in connection with the use or performance of this
* software.
*/
#include "bltInt.h"
#include <X11/Xutil.h>
#define WINDEBUG 0
#define ROTATE_0 0
#define ROTATE_90 1
#define ROTATE_180 2
#define ROTATE_270 3
static Tcl_HashTable bitmapGCTable;
static int initialized;
static GC GetBitmapGC _ANSI_ARGS_((Tk_Window tkwin));
static void
DrawTextSegments(display, drawable, gc, x, y, layoutPtr)
Display *display;
Drawable drawable;
GC gc;
register int x, y; /* Origin of text */
TextLayout *layoutPtr;
{
register TextSegment *segPtr = layoutPtr->segArr;
register int i;
for (i = 0; i < layoutPtr->nSegments; i++, segPtr++) {
#if HAVE_UTF
Tk_DrawChars(display, drawable, gc, layoutPtr->font, segPtr->text,
segPtr->count, x + segPtr->x, y + segPtr->y);
#else
XDrawString(display, drawable, gc, x + segPtr->x, y + segPtr->y,
segPtr->text, segPtr->count);
#endif /*HAVE_UTF*/
}
}
/*
* -----------------------------------------------------------------
*
* Blt_GetTextLayout --
*
* Get the extents of a possibly multiple-lined text string.
*
* Results:
* Returns via *widthPtr* and *heightPtr* the dimensions of
* the text string.
*
* -----------------------------------------------------------------
*/
TextLayout *
Blt_GetTextLayout(string, stylePtr)
char string[];
TextStyle *stylePtr;
{
int maxHeight, maxWidth;
int count; /* Count # of characters on each line */
int nSegments;
int width; /* Running dimensions of the text */
TextSegment *segPtr;
TextLayout *layoutPtr;
int lineHeight;
int size;
register char *p;
register int i;
Tk_FontMetrics fontMetrics;
Tk_GetFontMetrics(stylePtr->font, &fontMetrics);
lineHeight = fontMetrics.linespace + stylePtr->leader +
stylePtr->shadow.offset;
nSegments = 0;
for (p = string; *p != '\0'; p++) {
if (*p == '\n') {
nSegments++;
}
}
if (*(p - 1) != '\n') {
nSegments++;
}
size = sizeof(TextLayout) + (sizeof(TextSegment) * (nSegments - 1));
layoutPtr = (TextLayout *)calloc(1, size);
layoutPtr->nSegments = nSegments;
layoutPtr->font = stylePtr->font;
nSegments = count = 0;
width = maxWidth = 0;
maxHeight = stylePtr->padTop;
segPtr = layoutPtr->segArr;
for (p = string; *p != '\0'; p++) {
if (*p == '\n') {
if (count > 0) {
width = Tk_TextWidth(stylePtr->font, string, count) +
stylePtr->shadow.offset;
if (width > maxWidth) {
maxWidth = width;
}
}
segPtr->width = width;
segPtr->count = count;
segPtr->y = maxHeight + fontMetrics.ascent;
segPtr->text = string;
segPtr++;
nSegments++;
maxHeight += lineHeight;
string = p + 1; /* Start the string on the next line */
count = 0; /* Reset to indicate the start of a new line */
continue;
}
count++;
}
if (nSegments < layoutPtr->nSegments) {
width = Tk_TextWidth(stylePtr->font, string, count) +
stylePtr->shadow.offset;
if (width > maxWidth) {
maxWidth = width;
}
segPtr->width = width;
segPtr->count = count;
segPtr->y = maxHeight + fontMetrics.ascent;
segPtr->text = string;
maxHeight += lineHeight;
nSegments++;
}
maxHeight += stylePtr->padBottom;
maxWidth += PADDING(stylePtr->padX);
segPtr = layoutPtr->segArr;
for (i = 0; i < nSegments; i++, segPtr++) {
switch (stylePtr->justify) {
default:
case TK_JUSTIFY_LEFT:
/* No offset for left justified text strings */
segPtr->x = stylePtr->padLeft;
break;
case TK_JUSTIFY_RIGHT:
segPtr->x = (maxWidth - segPtr->width) - stylePtr->padRight;
break;
case TK_JUSTIFY_CENTER:
segPtr->x = (maxWidth - segPtr->width) / 2;
break;
}
}
layoutPtr->width = maxWidth;
layoutPtr->height = maxHeight - stylePtr->leader;
return layoutPtr;
}
/*
* -----------------------------------------------------------------
*
* Blt_GetTextExtents --
*
* Get the extents of a possibly multiple-lined text string.
*
* Results:
* Returns via *widthPtr* and *heightPtr* the dimensions of
* the text string.
*
* -----------------------------------------------------------------
*/
void
Blt_GetTextExtents(stylePtr, string, widthPtr, heightPtr)
TextStyle *stylePtr;
char string[];
int *widthPtr, *heightPtr;
{
int count; /* Count # of characters on each line */
int width, height;
int w, lineHeight;
register char *p;
Tk_FontMetrics fontMetrics;
if (string == NULL) {
return; /* NULL string? */
}
Tk_GetFontMetrics(stylePtr->font, &fontMetrics);
lineHeight = fontMetrics.linespace + stylePtr->leader +
stylePtr->shadow.offset;
count = 0;
width = height = 0;
for (p = string; *p != '\0'; p++) {
if (*p == '\n') {
if (count > 0) {
w = Tk_TextWidth(stylePtr->font, string, count) +
stylePtr->shadow.offset;
if (w > width) {
width = w;
}
}
height += lineHeight;
string = p + 1; /* Start the string on the next line */
count = 0; /* Reset to indicate the start of a new line */
continue;
}
count++;
}
if ((count > 0) && (*(p - 1) != '\n')) {
height += lineHeight;
w = Tk_TextWidth(stylePtr->font, string, count) +
stylePtr->shadow.offset;
if (w > width) {
width = w;
}
}
*widthPtr = width + PADDING(stylePtr->padX);
*heightPtr = height + PADDING(stylePtr->padY);
}
/*
* -----------------------------------------------------------------
*
* Blt_GetBoundingBox
*
* Computes the dimensions of the bounding box surrounding a
* rectangle rotated about its center. If pointArr isn't NULL,
* the coordinates of the rotated rectangle are also returned.
*
* The dimensions are determined by rotating the rectangle, and
* doubling the maximum x-coordinate and y-coordinate.
*
* w = 2 * maxX, h = 2 * maxY
*
* Since the rectangle is centered at 0,0, the coordinates of
* the bounding box are (-w/2,-h/2 w/2,-h/2, w/2,h/2 -w/2,h/2).
*
* 0 ------- 1
* | |
* | x |
* | |
* 3 ------- 2
*
* Results:
* The width and height of the bounding box containing the
* rotated rectangle are returned.
*
* -----------------------------------------------------------------
*/
void
Blt_GetBoundingBox(width, height, theta, rotWidthPtr, rotHeightPtr, pointArr)
int width, height; /* Unrotated region */
double theta; /* Rotation of box */
int *rotWidthPtr, *rotHeightPtr; /* (out) Bounding box region */
XPoint *pointArr; /* (out) Points of the rotated box */
{
register int i;
double sinTheta, cosTheta;
double xMax, yMax;
register double x, y;
Point2D corner[4];
theta = FMOD(theta, 360.0);
if (FMOD(theta, (double)90.0) == 0.0) {
int ll, ur, ul, lr;
int rotWidth, rotHeight;
int quadrant;
/* Handle right-angle rotations specifically */
quadrant = (int)(theta / 90.0);
switch (quadrant) {
case ROTATE_270: /* 270 degrees */
ul = 3, ur = 0, lr = 1, ll = 2;
rotWidth = height;
rotHeight = width;
break;
case ROTATE_90: /* 90 degrees */
ul = 1, ur = 2, lr = 3, ll = 0;
rotWidth = height;
rotHeight = width;
break;
case ROTATE_180: /* 180 degrees */
ul = 2, ur = 3, lr = 0, ll = 1;
rotWidth = width;
rotHeight = height;
break;
default:
case ROTATE_0: /* 0 degrees */
ul = 0, ur = 1, lr = 2, ll = 3;
rotWidth = width;
rotHeight = height;
break;
}
if (pointArr != NULL) {
int sx, sy;
x = (double)rotWidth *0.5;
y = (double)rotHeight *0.5;
sx = ROUND(x);
sy = ROUND(y);
pointArr[ll].x = pointArr[ul].x = -sx;
pointArr[ur].y = pointArr[ul].y = -sy;
pointArr[lr].x = pointArr[ur].x = sx;
pointArr[ll].y = pointArr[lr].y = sy;
}
*rotWidthPtr = rotWidth;
*rotHeightPtr = rotHeight;
return;
}
/* Set the four corners of the rectangle whose center is the origin */
corner[1].x = corner[2].x = (double)width *0.5;
corner[0].x = corner[3].x = -corner[1].x;
corner[2].y = corner[3].y = (double)height *0.5;
corner[0].y = corner[1].y = -corner[2].y;
theta = (-theta / 180.0) * M_PI;
sinTheta = sin(theta), cosTheta = cos(theta);
xMax = yMax = 0.0;
/* Rotate the four corners and find the maximum X and Y coordinates */
for (i = 0; i < 4; i++) {
x = (corner[i].x * cosTheta) - (corner[i].y * sinTheta);
y = (corner[i].x * sinTheta) + (corner[i].y * cosTheta);
if (x > xMax) {
xMax = x;
}
if (y > yMax) {
yMax = y;
}
if (pointArr != NULL) {
pointArr[i].x = ROUND(x);
pointArr[i].y = ROUND(y);
}
}
/*
* By symmetry, the width and height of the bounding box are
* twice the maximum x and y coordinates.
*/
*rotWidthPtr = (int)((xMax + xMax) + 0.5);
*rotHeightPtr = (int)((yMax + yMax) + 0.5);
}
/*
* -----------------------------------------------------------------
*
* Blt_TranslateAnchor --
*
* Translate the coordinates of a given bounding box based
* upon the anchor specified. The anchor indicates where
* the given xy position is in relation to the bounding box.
*
* nw --- n --- ne
* | |
* w center e
* | |
* sw --- s --- se
*
* The coordinates returned are translated to the origin of the
* bounding box (suitable for giving to XCopyArea, XCopyPlane, etc.)
*
* Results:
* The translated coordinates of the bounding box are returned.
*
* -----------------------------------------------------------------
*/
void
Blt_TranslateAnchor(x, y, width, height, anchor, transXPtr, transYPtr)
int x, y; /* Window coordinates of anchor */
int width, height; /* Extents of the bounding box */
Tk_Anchor anchor; /* Direction of the anchor */
int *transXPtr, *transYPtr;
{
switch (anchor) {
case TK_ANCHOR_NW: /* Upper left corner */
break;
case TK_ANCHOR_W: /* Left center */
y -= (height / 2);
break;
case TK_ANCHOR_SW: /* Lower left corner */
y -= height;
break;
case TK_ANCHOR_N: /* Top center */
x -= (width / 2);
break;
case TK_ANCHOR_CENTER: /* Center */
x -= (width / 2);
y -= (height / 2);
break;
case TK_ANCHOR_S: /* Bottom center */
x -= (width / 2);
y -= height;
break;
case TK_ANCHOR_NE: /* Upper right corner */
x -= width;
break;
case TK_ANCHOR_E: /* Right center */
x -= width;
y -= (height / 2);
break;
case TK_ANCHOR_SE: /* Lower right corner */
x -= width;
y -= height;
break;
}
*transXPtr = x;
*transYPtr = y;
}
#ifdef WIN32
/*
* -----------------------------------------------------------------
*
* Blt_RotateBitmap --
*
* Creates a new bitmap containing the rotated image of the given
* bitmap. We also need a special GC of depth 1, so that we do
* not need to rotate more than one plane of the bitmap.
*
* Results:
* Returns a new bitmap containing the rotated image.
*
* -----------------------------------------------------------------
*/
Pixmap
Blt_RotateBitmap(tkwin, srcBitmap, srcWidth, srcHeight, theta,
destWidthPtr, destHeightPtr)
Tk_Window tkwin;
Pixmap srcBitmap; /* Source bitmap to be rotated */
int srcWidth, srcHeight; /* Width and height of the source bitmap */
double theta; /* Right angle rotation to perform */
int *destWidthPtr, *destHeightPtr;
{
Display *display; /* X display */
Window root; /* Root window drawable */
Pixmap destBitmap;
int destWidth, destHeight;
HDC srcDC, destDC;
TkWinDCState srcState, destState;
register int x, y; /* Destination bitmap coordinates */
register int sx, sy; /* Source bitmap coordinates */
unsigned long pixel;
TkWinDrawable *drawPtr;
BITMAPINFO *bmPtr;
int size;
unsigned char *srcBits, *destBits;
int srcBytesPerRow, destBytesPerRow;
display = Tk_Display(tkwin);
root = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
Blt_GetBoundingBox(srcWidth, srcHeight, theta, &destWidth, &destHeight,
(XPoint *)NULL);
destBitmap = Tk_GetPixmap(display, root, destWidth, destHeight, 1);
if (destBitmap == None) {
return None; /* Can't allocate pixmap. */
}
srcDC = TkWinGetDrawableDC(display, srcBitmap, &srcState);
drawPtr = (TkWinDrawable *) srcBitmap;
destDC = TkWinGetDrawableDC(display, destBitmap, &destState);
size = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2;
bmPtr = (BITMAPINFO *) calloc(1, size);
bmPtr->bmiColors[0].rgbBlue = bmPtr->bmiColors[0].rgbGreen =
bmPtr->bmiColors[0].rgbRed = 0;
bmPtr->bmiColors[1].rgbBlue = bmPtr->bmiColors[1].rgbGreen =
bmPtr->bmiColors[1].rgbRed = 0xFF;
bmPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmPtr->bmiHeader.biPlanes = 1;
bmPtr->bmiHeader.biBitCount = 1;
bmPtr->bmiHeader.biCompression = BI_RGB;
bmPtr->bmiHeader.biWidth = srcWidth;
bmPtr->bmiHeader.biHeight = srcHeight;
srcBytesPerRow = ((srcWidth + 31) & ~31) / 8;
srcBits = (unsigned char *)malloc(srcHeight * srcBytesPerRow);
if (!GetDIBits(destDC, drawPtr->bitmap.handle, 0, srcHeight,
(LPVOID) srcBits, bmPtr, DIB_RGB_COLORS)) {
#ifdef notdef
PurifyPrintf("can't setDIBits: %s\n", Blt_LastError());
#endif
goto error;
}
bmPtr->bmiHeader.biWidth = destWidth;
bmPtr->bmiHeader.biHeight = destHeight;
destBytesPerRow = ((destWidth + 31) & ~31) / 8;
destBits = (unsigned char *)calloc(destHeight, destBytesPerRow);
#define GetBit(x, y) \
srcBits[(srcBytesPerRow * y) + (x / 8)] & (0x80 >> (x % 8))
#define SetBit(x, y) \
destBits[(destBytesPerRow * y) + (x / 8)] |= (0x80 >> (x % 8))
theta = FMOD(theta, 360.0);
if (FMOD(theta, (double)90.0) == 0.0) {
int quadrant;
/* Handle right-angle rotations specifically */
quadrant = (int)(theta / 90.0);
switch (quadrant) {
case ROTATE_90: /* 90 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = y, sy = destWidth - x - 1;
pixel = GetBit(sx, sy);
if (pixel) {
SetBit(x, y);
}
}
}
break;
case ROTATE_0: /* 0 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = destWidth - x - 1, sy = destHeight - y - 1;
pixel = GetBit(sx, sy);
if (pixel) {
SetBit(x, y);
}
}
}
break;
case ROTATE_270: /* 270 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = destHeight - y - 1, sy = x;
pixel = GetBit(sx, sy);
if (pixel) {
SetBit(x, y);
}
}
}
break;
case ROTATE_180: /* 180 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
pixel = GetBit(x, y);
if (pixel) {
SetBit(x, y);
}
}
}
break;
default:
/* The calling routine should never let this happen. */
break;
}
} else {
double radians, sinTheta, cosTheta;
double srcCX, srcCY; /* Center of source rectangle */
double destCX, destCY; /* Center of destination rectangle */
double tx, ty;
double rx, ry; /* Angle of rotation for x and y coordinates */
radians = (theta / 180.0) * M_PI;
sinTheta = sin(-radians), cosTheta = cos(-radians);
/*
* Coordinates of the centers of the source and destination rectangles
*/
srcCX = srcWidth * 0.5;
srcCY = srcHeight * 0.5;
destCX = destWidth * 0.5;
destCY = destHeight * 0.5;
/* Rotate each pixel of dest image, placing results in source image */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
/* Translate origin to center of destination image */
tx = x - destCX;
ty = y - destCY;
/* Rotate the coordinates about the origin */
rx = (tx * cosTheta) - (ty * sinTheta);
ry = (tx * sinTheta) + (ty * cosTheta);
/* Translate back to the center of the source image */
rx += srcCX;
ry += srcCY;
sx = ROUND(rx);
sy = ROUND(ry);
/*
* Verify the coordinates, since the destination image can be
* bigger than the source
*/
if ((sx >= srcWidth) || (sx < 0) || (sy >= srcHeight) ||
(sy < 0)) {
continue;
}
pixel = GetBit(sx, sy);
if (pixel) {
SetBit(x, y);
}
}
}
}
drawPtr = (TkWinDrawable *) destBitmap;
if (!SetDIBits(destDC, drawPtr->bitmap.handle, 0, destHeight,
(LPVOID) destBits, bmPtr, DIB_RGB_COLORS)) {
#if WINDEBUG
PurifyPrintf("can't setDIBits: %s\n", Blt_LastError());
#endif
}
error:
free((char *)bmPtr);
free((char *)destBits);
free((char *)srcBits);
TkWinReleaseDrawableDC(srcBitmap, srcDC, &srcState);
TkWinReleaseDrawableDC(destBitmap, destDC, &destState);
*destWidthPtr = destWidth;
*destHeightPtr = destHeight;
return destBitmap;
}
#else
/*
* -----------------------------------------------------------------
*
* Blt_RotateBitmap --
*
* Creates a new bitmap containing the rotated image of the given
* bitmap. We also need a special GC of depth 1, so that we do
* not need to rotate more than one plane of the bitmap.
*
* Results:
* Returns a new bitmap containing the rotated image.
*
* -----------------------------------------------------------------
*/
Pixmap
Blt_RotateBitmap(tkwin, srcBitmap, srcWidth, srcHeight, theta,
destWidthPtr, destHeightPtr)
Tk_Window tkwin;
Pixmap srcBitmap; /* Source bitmap to be rotated */
int srcWidth, srcHeight; /* Width and height of the source bitmap */
double theta; /* Right angle rotation to perform */
int *destWidthPtr, *destHeightPtr;
{
Display *display; /* X display */
Window root; /* Root window drawable */
Pixmap destBitmap;
int destWidth, destHeight;
XImage *src, *dest;
register int x, y; /* Destination bitmap coordinates */
register int sx, sy; /* Source bitmap coordinates */
unsigned long pixel;
GC bitmapGC;
display = Tk_Display(tkwin);
root = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
/* Create a bitmap and image big enough to contain the rotated text */
Blt_GetBoundingBox(srcWidth, srcHeight, theta, &destWidth, &destHeight,
(XPoint *)NULL);
destBitmap = Tk_GetPixmap(display, root, destWidth, destHeight, 1);
bitmapGC = GetBitmapGC(tkwin);
XSetForeground(display, bitmapGC, 0x0);
XFillRectangle(display, destBitmap, bitmapGC, 0, 0, destWidth, destHeight);
src = XGetImage(display, srcBitmap, 0, 0, srcWidth, srcHeight, 1, ZPixmap);
dest = XGetImage(display, destBitmap, 0, 0, destWidth, destHeight, 1,
ZPixmap);
theta = FMOD(theta, 360.0);
if (FMOD(theta, (double)90.0) == 0.0) {
int quadrant;
/* Handle right-angle rotations specifically */
quadrant = (int)(theta / 90.0);
switch (quadrant) {
case ROTATE_270: /* 270 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = y, sy = destWidth - x - 1;
pixel = XGetPixel(src, sx, sy);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
break;
case ROTATE_180: /* 180 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = destWidth - x - 1, sy = destHeight - y - 1;
pixel = XGetPixel(src, sx, sy);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
break;
case ROTATE_90: /* 90 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
sx = destHeight - y - 1, sy = x;
pixel = XGetPixel(src, sx, sy);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
break;
case ROTATE_0: /* 0 degrees */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
pixel = XGetPixel(src, x, y);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
break;
default:
/* The calling routine should never let this happen. */
break;
}
} else {
double radians, sinTheta, cosTheta;
double srcCX, srcCY; /* Offset from the center of
* the source rectangle. */
double destCX, destCY; /* Offset to the center of the destination
* rectangle. */
double tx, ty; /* Translated coordinates from center */
double rx, ry; /* Angle of rotation for x and y coordinates */
radians = (theta / 180.0) * M_PI;
sinTheta = sin(radians), cosTheta = cos(radians);
/*
* Coordinates of the centers of the source and destination rectangles
*/
srcCX = srcWidth * 0.5;
srcCY = srcHeight * 0.5;
destCX = destWidth * 0.5;
destCY = destHeight * 0.5;
/* Rotate each pixel of dest image, placing results in source image */
for (x = 0; x < destWidth; x++) {
for (y = 0; y < destHeight; y++) {
/* Translate origin to center of destination image */
tx = x - destCX;
ty = y - destCY;
/* Rotate the coordinates about the origin */
rx = (tx * cosTheta) - (ty * sinTheta);
ry = (tx * sinTheta) + (ty * cosTheta);
/* Translate back to the center of the source image */
rx += srcCX;
ry += srcCY;
sx = ROUND(rx);
sy = ROUND(ry);
/*
* Verify the coordinates, since the destination image can be
* bigger than the source
*/
if ((sx >= srcWidth) || (sx < 0) || (sy >= srcHeight) ||
(sy < 0)) {
continue;
}
pixel = XGetPixel(src, sx, sy);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
}
/* Write the rotated image into the destination bitmap */
XPutImage(display, destBitmap, bitmapGC, dest, 0, 0, 0, 0, destWidth,
destHeight);
/* Clean up temporary resources used */
XDestroyImage(src), XDestroyImage(dest);
*destWidthPtr = destWidth;
*destHeightPtr = destHeight;
return destBitmap;
}
#endif /* WIN32 */
/*
* -----------------------------------------------------------------
*
* Blt_CreateTextBitmap --
*
* Draw a bitmap, using the the given window coordinates
* as an anchor for the text bounding box.
*
* Results:
* Returns the bitmap representing the text string.
*
* Side Effects:
* Bitmap is drawn using the given font and GC in the
* drawable at the given coordinates, anchor, and rotation.
*
* -----------------------------------------------------------------
*/
Pixmap
Blt_CreateTextBitmap(tkwin, layoutPtr, stylePtr, bmWidthPtr, bmHeightPtr)
Tk_Window tkwin;
TextLayout *layoutPtr; /* Text string to draw */
TextStyle *stylePtr; /* Text attributes: rotation, color, font,
* linespacing, justification, etc. */
int *bmWidthPtr;
int *bmHeightPtr; /* Extents of rotated text string */
{
int width, height;
Pixmap bitmap;
Display *display;
Window root;
GC bitmapGC;
#ifdef WIN32
HDC src;
TkWinDCState state;
#endif
display = Tk_Display(tkwin);
width = layoutPtr->width + 2;
height = layoutPtr->height + 2;
/* Create a temporary bitmap to contain the text string */
root = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
bitmap = Tk_GetPixmap(display, root, width, height, 1);
assert(bitmap != None);
if (bitmap == None) {
return None; /* Can't allocate pixmap. */
}
/* Clear the pixmap and draw the text string into it */
bitmapGC = GetBitmapGC(tkwin);
#ifdef WIN32
src = TkWinGetDrawableDC(display, bitmap, &state);
PatBlt(src, 0, 0, width, height, WHITENESS);
TkWinReleaseDrawableDC(bitmap, src, &state);
#else
XSetForeground(display, bitmapGC, 0);
XFillRectangle(display, bitmap, bitmapGC, 0, 0, width, height);
#endif /* WIN32 */
XSetFont(display, bitmapGC, Tk_FontId(stylePtr->font));
XSetForeground(display, bitmapGC, 1);
DrawTextSegments(display, bitmap, bitmapGC, 0, 0, layoutPtr);
#ifdef WIN32
/*
* Under Win32 when drawing into a bitmap, the bits are
* reversed. Which is why we are inverting the bitmap here.
*/
src = TkWinGetDrawableDC(display, bitmap, &state);
PatBlt(src, 0, 0, layoutPtr->width, layoutPtr->height, DSTINVERT);
TkWinReleaseDrawableDC(bitmap, src, &state);
#endif
if (stylePtr->theta != 0.0) {
Pixmap rotBitmap;
/* Replace the text pixmap with a rotated one */
rotBitmap = Blt_RotateBitmap(tkwin, bitmap, layoutPtr->width,
layoutPtr->height, stylePtr->theta, bmWidthPtr, bmHeightPtr);
assert(rotBitmap);
if (rotBitmap != None) {
Tk_FreePixmap(display, bitmap);
return rotBitmap;
}
}
*bmWidthPtr = layoutPtr->width, *bmHeightPtr = layoutPtr->height;
return bitmap;
}
#ifdef WIN32
/*
* -----------------------------------------------------------------------
*
* Blt_ScaleBitmapRegion --
*
* Creates a new scaled bitmap from another bitmap. The new bitmap
* is bounded by a specified region. Only this portion of the bitmap
* is scaled from the original bitmap.
*
* By bounding scaling to a region we can generate a new bitmap
* which is no bigger than the specified viewport.
*
* Results:
* The new scaled bitmap is returned.
*
* Side Effects:
* A new pixmap is allocated. The caller must release this.
*
* -----------------------------------------------------------------------
*/
Pixmap
Blt_ScaleBitmapRegion(tkwin, srcBitmap, srcWidth, srcHeight,
destWidth, destHeight, regionPtr)
Tk_Window tkwin;
Pixmap srcBitmap;
int srcWidth, srcHeight, destWidth, destHeight;
ImageRegion *regionPtr;
{
TkWinDCState srcState, destState;
HDC src, dest;
Pixmap destBitmap;
double xScale, yScale;
register int sx, sy; /* Source bitmap coordinates */
Window root;
Display *display;
/* Create a new bitmap the size of the region and clear it */
display = Tk_Display(tkwin);
root = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
destBitmap = Tk_GetPixmap(display, root, regionPtr->width,
regionPtr->height, 1);
if (destBitmap == None) {
return None;
}
/* Compute scaling factors from destination to source bitmaps */
xScale = (double)srcWidth / (double)destWidth;
yScale = (double)srcHeight / (double)destHeight;
src = TkWinGetDrawableDC(display, srcBitmap, &srcState);
dest = TkWinGetDrawableDC(display, destBitmap, &destState);
sx = ROUND(regionPtr->x * xScale);
sy = ROUND(regionPtr->y * yScale);
srcWidth = ROUND(regionPtr->width * xScale);
srcHeight = ROUND(regionPtr->height * yScale);
StretchBlt(dest, 0, 0, destWidth, destHeight, src, sx, sy,
srcWidth, srcHeight, SRCCOPY);
TkWinReleaseDrawableDC(srcBitmap, src, &srcState);
TkWinReleaseDrawableDC(destBitmap, dest, &destState);
return destBitmap;
}
#else
/*
* -----------------------------------------------------------------------
*
* Blt_ScaleBitmapRegion --
*
* Creates a new scaled bitmap from another bitmap. The new bitmap
* is bounded by a specified region. Only this portion of the bitmap
* is scaled from the original bitmap.
*
* By bounding scaling to a region we can generate a new bitmap
* which is no bigger than the specified viewport.
*
* Results:
* The new scaled bitmap is returned.
*
* Side Effects:
* A new pixmap is allocated. The caller must release this.
*
* -----------------------------------------------------------------------
*/
Pixmap
Blt_ScaleBitmapRegion(tkwin, srcBitmap, srcWidth, srcHeight,
destWidth, destHeight, regionPtr)
Tk_Window tkwin;
Pixmap srcBitmap;
int srcWidth, srcHeight, destWidth, destHeight;
ImageRegion *regionPtr;
{
Display *display;
Window root;
XImage *src, *dest;
Pixmap destBitmap;
GC bitmapGC;
double xScale, yScale;
register int x, y; /* Destination bitmap coordinates */
register int sx, sy; /* Source bitmap coordinates */
unsigned long pixel;
double tmp;
/* Create a new bitmap the size of the region and clear it */
display = Tk_Display(tkwin);
root = RootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
destBitmap = Tk_GetPixmap(display, root, regionPtr->width,
regionPtr->height, 1);
bitmapGC = GetBitmapGC(tkwin);
XSetForeground(display, bitmapGC, 0x0);
XFillRectangle(display, destBitmap, bitmapGC, 0, 0, regionPtr->width,
regionPtr->height);
src = XGetImage(display, srcBitmap, 0, 0, srcWidth, srcHeight, 1, ZPixmap);
dest = XGetImage(display, destBitmap, 0, 0, regionPtr->width,
regionPtr->height, 1, ZPixmap);
/*
* Scale each pixel of destination image from results of source
* image. Verify the coordinates, since the destination image can
* be bigger than the source
*/
xScale = (double)srcWidth / (double)destWidth;
yScale = (double)srcHeight / (double)destHeight;
for (y = 0; y < regionPtr->height; y++) {
tmp = (double)(y + regionPtr->y) * yScale;
sy = ROUND(tmp);
if (sy >= srcHeight) {
continue;
}
for (x = 0; x < regionPtr->width; x++) {
tmp = (double)(x + regionPtr->x) * xScale;
sx = ROUND(tmp);
if (sx >= srcWidth) {
continue;
}
pixel = XGetPixel(src, sx, sy);
if (pixel) {
XPutPixel(dest, x, y, pixel);
}
}
}
/* Write the rotated image into the destination bitmap */
XPutImage(display, destBitmap, bitmapGC, dest, 0, 0, 0, 0,
regionPtr->width, regionPtr->height);
XDestroyImage(src), XDestroyImage(dest);
return destBitmap;
}
#endif /* WIN32 */
/*
* -----------------------------------------------------------------------
*
* Blt_ScaleBitmap --
*
* Same as Blt_ScaleBitmapRegion, except that the region is unbounded.
* The scaled bitmap will be a fully scaled version of the original,
* not a portion of it.
*
* Results:
* The new scaled bitmap is returned.
*
* Side Effects:
* A new pixmap is allocated. The caller must release this.
*
* -----------------------------------------------------------------------
*/
Pixmap
Blt_ScaleBitmap(tkwin, srcBitmap, srcWidth, srcHeight, scaledWidth,
scaledHeight)
Tk_Window tkwin;
Pixmap srcBitmap;
int srcWidth, srcHeight, scaledWidth, scaledHeight;
{
ImageRegion region;
region.x = region.y = 0;
region.width = scaledWidth;
region.height = scaledHeight;
return Blt_ScaleBitmapRegion(tkwin, srcBitmap, srcWidth, srcHeight,
scaledWidth, scaledHeight, ®ion);
}
/*LINTLIBRARY*/
void
Blt_InitTextStyle(stylePtr)
TextStyle *stylePtr;
{
/* Initialize these attributes to zero */
stylePtr->leader = 0;
stylePtr->shadow.offset = 0;
stylePtr->padLeft = stylePtr->padRight = 0;
stylePtr->padTop = stylePtr->padBottom = 0;
stylePtr->shadow.color = stylePtr->activeColor =
stylePtr->color = (XColor *)NULL;
stylePtr->theta = 0.0;
stylePtr->state = 0;
stylePtr->anchor = TK_ANCHOR_CENTER;
stylePtr->justify = TK_JUSTIFY_CENTER;
stylePtr->font = NULL;
}
void
Blt_SetDrawTextStyle(stylePtr, font, gc, normalColor, activeColor,
shadowColor, theta, anchor, justify, leader, shadowOffset)
TextStyle *stylePtr;
Tk_Font font;
GC gc;
XColor *normalColor, *activeColor, *shadowColor;
double theta;
Tk_Anchor anchor;
Tk_Justify justify;
int leader, shadowOffset;
{
Blt_InitTextStyle(stylePtr);
stylePtr->gc = gc;
stylePtr->color = normalColor;
stylePtr->activeColor = activeColor;
stylePtr->shadow.color = shadowColor;
stylePtr->font = font;
stylePtr->theta = theta;
stylePtr->anchor = anchor;
stylePtr->justify = justify;
stylePtr->leader = leader;
stylePtr->shadow.offset = shadowOffset;
}
void
Blt_SetPrintTextStyle(stylePtr, font, fgColor, activeColor, shadowColor,
theta, anchor, justify, leader, shadowOffset)
TextStyle *stylePtr;
Tk_Font font;
XColor *fgColor, *activeColor, *shadowColor;
double theta;
Tk_Anchor anchor;
Tk_Justify justify;
int leader, shadowOffset;
{
Blt_InitTextStyle(stylePtr);
stylePtr->color = fgColor;
stylePtr->activeColor = activeColor;
stylePtr->shadow.color = shadowColor;
stylePtr->font = font;
stylePtr->theta = theta;
stylePtr->anchor = anchor;
stylePtr->justify = justify;
stylePtr->leader = leader;
stylePtr->shadow.offset = shadowOffset;
}
/*
* -----------------------------------------------------------------
*
* DrawText --
*
* Draw a text string, possibly rotated, using the the given
* window coordinates as an anchor for the text bounding box.
* If the text is not rotated, simply use the X text drawing
* routines. Otherwise, generate a bitmap of the rotated text.
*
* Results:
* Returns the x-coordinate to the right of the text.
*
* Side Effects:
* Text string is drawn using the given font and GC at the
* the given window coordinates.
*
* The Stipple, FillStyle, and TSOrigin fields of the GC are
* modified for rotated text. This assumes the GC is private,
* *not* shared (via Tk_GetGC)
*
* -----------------------------------------------------------------
*/
void
Blt_DrawTextLayout(tkwin, drawable, layoutPtr, stylePtr, x, y)
Tk_Window tkwin;
Drawable drawable;
TextLayout *layoutPtr;
TextStyle *stylePtr; /* Text attribute information */
int x, y; /* Window coordinates to draw text */
{
int width, height;
double theta;
Display *display;
Pixmap bitmap;
int active;
display = Tk_Display(tkwin);
theta = FMOD(stylePtr->theta, (double)360.0);
if (theta < 0.0) {
theta += 360.0;
}
active = stylePtr->state & STATE_ACTIVE;
if (theta == 0.0) {
/*
* This is the easy case of no rotation. Simply draw the text
* using the standard drawing routines. Handle offset printing
* for engraved (disabled) and shadowed text.
*/
width = layoutPtr->width, height = layoutPtr->height;
Blt_TranslateAnchor(x, y, width, height, stylePtr->anchor, &x, &y);
if (stylePtr->state & (STATE_DISABLED | STATE_EMPHASIS)) {
TkBorder *borderPtr = (TkBorder *) stylePtr->border;
XColor *color1, *color2;
color1 = borderPtr->lightColor, color2 = borderPtr->darkColor;
if (stylePtr->state & STATE_EMPHASIS) {
XColor *hold;
hold = color1, color1 = color2, color2 = hold;
}
if (color1 != NULL) {
XSetForeground(display, stylePtr->gc, color1->pixel);
}
DrawTextSegments(display, drawable, stylePtr->gc, x + 1, y + 1,
layoutPtr);
if (color2 != NULL) {
XSetForeground(display, stylePtr->gc, color2->pixel);
}
DrawTextSegments(display, drawable, stylePtr->gc, x, y, layoutPtr);
/* Reset the foreground color back to its original setting,
* so not to invalidate the GC cache. */
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
return; /* Done */
}
if ((stylePtr->shadow.offset > 0) && (stylePtr->shadow.color != NULL)) {
XSetForeground(display, stylePtr->gc,
stylePtr->shadow.color->pixel);
DrawTextSegments(display, drawable, stylePtr->gc,
x + stylePtr->shadow.offset, y + stylePtr->shadow.offset,
layoutPtr);
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
}
if (active) {
XSetForeground(display, stylePtr->gc, stylePtr->activeColor->pixel);
}
DrawTextSegments(display, drawable, stylePtr->gc, x, y, layoutPtr);
if (active) {
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
}
return; /* Done */
}
#ifdef WIN32
if (Blt_DrawRotatedText(display, drawable, x, y, theta, stylePtr,
layoutPtr)) {
return;
}
#endif
/*
* Rotate the text by writing the text into a bitmap and rotating
* the bitmap. Set the clip mask and origin in the GC first. And
* make sure we restore the GC because it may be shared.
*/
stylePtr->theta = theta;
bitmap = Blt_CreateTextBitmap(tkwin, layoutPtr, stylePtr, &width, &height);
if (bitmap == None) {
return;
}
Blt_TranslateAnchor(x, y, width, height, stylePtr->anchor, &x, &y);
theta = FMOD(theta, (double)90.0);
XSetClipMask(display, stylePtr->gc, bitmap);
if (stylePtr->state & (STATE_DISABLED | STATE_EMPHASIS)) {
TkBorder *borderPtr = (TkBorder *) stylePtr->border;
XColor *color1, *color2;
color1 = borderPtr->lightColor, color2 = borderPtr->darkColor;
if (stylePtr->state & STATE_EMPHASIS) {
XColor *hold;
hold = color1, color1 = color2, color2 = hold;
}
if (color1 != NULL) {
XSetForeground(display, stylePtr->gc, color1->pixel);
}
XSetClipOrigin(display, stylePtr->gc, x + 1, y + 1);
XCopyPlane(display, bitmap, drawable, stylePtr->gc, 0, 0, width, height,
x + 1, y + 1, 1);
if (color2 != NULL) {
XSetForeground(display, stylePtr->gc, color2->pixel);
}
XSetClipOrigin(display, stylePtr->gc, x, y);
XCopyPlane(display, bitmap, drawable, stylePtr->gc, 0, 0, width, height,
x, y, 1);
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
} else {
if ((stylePtr->shadow.offset > 0) && (stylePtr->shadow.color != NULL)) {
XSetClipOrigin(display, stylePtr->gc, x + stylePtr->shadow.offset,
y + stylePtr->shadow.offset);
XSetForeground(display, stylePtr->gc,
stylePtr->shadow.color->pixel);
XCopyPlane(display, bitmap, drawable, stylePtr->gc, 0, 0, width,
height, x + stylePtr->shadow.offset,
y + stylePtr->shadow.offset, 1);
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
}
if (active) {
XSetForeground(display, stylePtr->gc, stylePtr->activeColor->pixel);
}
XSetClipOrigin(display, stylePtr->gc, x, y);
XCopyPlane(display, bitmap, drawable, stylePtr->gc, 0, 0, width, height,
x, y, 1);
if (active) {
XSetForeground(display, stylePtr->gc, stylePtr->color->pixel);
}
}
XSetClipMask(display, stylePtr->gc, None);
Tk_FreePixmap(display, bitmap);
}
void
Blt_DrawText2(tkwin, drawable, string, stylePtr, x, y, areaPtr)
Tk_Window tkwin;
Drawable drawable;
char string[];
TextStyle *stylePtr; /* Text attribute information */
int x, y; /* Window coordinates to draw text */
Dim2D *areaPtr;
{
TextLayout *layoutPtr;
int width, height;
double theta;
if ((string == NULL) || (*string == '\0')) {
return; /* Empty string, do nothing */
}
layoutPtr = Blt_GetTextLayout(string, stylePtr);
Blt_DrawTextLayout(tkwin, drawable, layoutPtr, stylePtr, x, y);
theta = FMOD(stylePtr->theta, (double)360.0);
if (theta < 0.0) {
theta += 360.0;
}
width = layoutPtr->width;
height = layoutPtr->height;
if (theta != 0.0) {
Blt_GetBoundingBox(width, height, theta, &width, &height,
(XPoint *)NULL);
}
free((char *)layoutPtr);
areaPtr->width = width;
areaPtr->height = height;
}
void
Blt_DrawText(tkwin, drawable, string, stylePtr, x, y)
Tk_Window tkwin;
Drawable drawable;
char string[];
TextStyle *stylePtr; /* Text attribute information */
int x, y; /* Window coordinates to draw text */
{
TextLayout *layoutPtr;
if ((string == NULL) || (*string == '\0')) {
return; /* Empty string, do nothing */
}
layoutPtr = Blt_GetTextLayout(string, stylePtr);
Blt_DrawTextLayout(tkwin, drawable, layoutPtr, stylePtr, x, y);
free((char *)layoutPtr);
}
static GC
GetBitmapGC(tkwin)
Tk_Window tkwin;
{
int isNew;
GC gc;
Display *dpy;
Tcl_HashEntry *hPtr;
if (!initialized) {
Tcl_InitHashTable(&bitmapGCTable, TCL_ONE_WORD_KEYS);
initialized = TRUE;
}
dpy = Tk_Display(tkwin);
hPtr = Tcl_CreateHashEntry(&bitmapGCTable, (char *)dpy, &isNew);
if (isNew) {
Pixmap bitmap;
XGCValues gcValues;
unsigned int gcMask;
Window root;
root = RootWindow(dpy, Tk_ScreenNumber(tkwin));
bitmap = Tk_GetPixmap(dpy, root, 1, 1, 1);
gcValues.foreground = gcValues.background = 0;
gcMask = (GCForeground | GCBackground);
gc = Blt_GetPrivateGCFromDrawable(tkwin, bitmap, gcMask, &gcValues);
Tk_FreePixmap(dpy, bitmap);
Tcl_SetHashValue(hPtr, (ClientData)gc);
} else {
gc = (GC)Tcl_GetHashValue(hPtr);
}
return gc;
}
void
Blt_ResetTextStyle(tkwin, stylePtr)
Tk_Window tkwin;
TextStyle *stylePtr;
{
GC newGC;
XGCValues gcValues;
unsigned long gcMask;
gcMask = GCFont;
gcValues.font = Tk_FontId(stylePtr->font);
if (stylePtr->color != NULL) {
gcMask |= GCForeground;
gcValues.foreground = stylePtr->color->pixel;
}
newGC = Tk_GetGC(tkwin, gcMask, &gcValues);
if (stylePtr->gc != NULL) {
Tk_FreeGC(Tk_Display(tkwin), stylePtr->gc);
}
stylePtr->gc = newGC;
}
void
Blt_FreeTextStyle(display, stylePtr)
Display *display;
TextStyle *stylePtr;
{
if (stylePtr->gc != NULL) {
Tk_FreeGC(display, stylePtr->gc);
}
}
|