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 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
|
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include "gr.hh"
#include "extern.hh"
#include "GriPath.hh"
#include "superus.hh"
#include "defaults.hh"
double gr_current_descender(void);
#define default_fontID gr_font_Helvetica
#define default_encoding font_encoding_isolatin1
#define default_fontsize_pt 12.0
static gr_font CurrentFont = {
default_fontID,
default_encoding,
default_fontsize_pt
};
// Q: should this be done in Moveup() routine? [then what about $N$N though]
#define START_NEW_TEXT {\
if (_grWritePS) { \
fprintf(_grPS, "(");\
check_psfile();\
}\
}
#define STOP_OLD_TEXT {\
if (_grWritePS) {\
fprintf(_grPS, ") sh\n");\
check_psfile();\
}\
}
enum position {Superscript, Subscript}; // Indicator
// Use spacing patterned on results of a TeX example (using Large font). All
// quantities are multiples of Mspace.
static const double SubSize = 0.75; // relative height of subscripts = 6/8
static const double SuperSize = 0.75; // relative height of superscripts = 6/8
static const double SuperMoveUp =0.625; // Move up for super = 5/8
static const double SubMoveDown =0.375; // Move down for sub = 3/8
#define PS_showpage "showpage\n"
#define PS_stroke "s\n"
extern FILE *_grPS;
extern bool _grNeedBegin;
extern bool _grPathExists;
extern bool _grWritePS;
static void gr_drawstring(const char *s);
static int index_for_math_symbol(char *s); // base routine
static double gr_charwidth_cm(int c, int font, double fontsize_pt);
static void gr_DrawChar(const char *c);
static void gr_setfont_fontsize(gr_fontID newID);
static void ClearStack(void);
static void PopStack(void);
static void MoveDown(void);
static void MoveUp(void);
static void MoveHorizontally(double em_distance);
static char *symbol_in_math(const char *sPtr, int *inc);
gr_font_info font_list[] =
{
{gr_font_Courier, "Courier"},
{gr_font_CourierOblique, "Courier-Oblique"},
{gr_font_CourierBold, "Courier-Bold"},
{gr_font_CourierBoldOblique, "Courier-BoldOblique"},
{gr_font_Helvetica, "Helvetica"},
{gr_font_HelveticaBold, "Helvetica-Bold"},
{gr_font_HelveticaOblique, "Helvetica-Oblique"},
{gr_font_PalatinoRoman, "Palatino-Roman"},
{gr_font_PalatinoItalic, "Palatino-Italic"},
{gr_font_PalatinoBold, "Palatino-Bold"},
{gr_font_PalatinoBoldItalic, "Palatino-BoldItalic"},
{gr_font_Symbol, "Symbol"},
{gr_font_TimesRoman, "Times-Roman"},
{gr_font_TimesItalic, "Times-Italic"},
{gr_font_TimesBold, "Times-Bold"},
{gr_font_TimesBoldItalic, "Times-BoldItalic"},
{gr_font_end_of_list, ""}
};
// Draw text at specified location.
void
gr_show_at(/*const*/ char *s, double xcm, double ycm, gr_textStyle style, double angle_deg)
{
double oldfontsize_pt = gr_currentfontsize_pt();
gr_fontID oldfontID = gr_currentfont();
double width_cm, ascent_cm, descent_cm;
if (0.0 == gr_currentfontsize_pt() || !strlen(s)) {
return;
}
rectangle box;
extern bool _warn_offpage;
if (_warn_offpage
&& ( xcm < OFFPAGE_LEFT
|| xcm > OFFPAGE_RIGHT
|| ycm < OFFPAGE_BOTTOM
|| ycm > OFFPAGE_TOP)) {
warning("Drawing text at a location which is offpage.");
}
fprintf(_grPS, "%% gr_show_at() BEGIN\n");
void set_ps_color(char what);
set_ps_color('t');
gr_setfontsize_pt(oldfontsize_pt);
gr_setfont(oldfontID);
gr_stringwidth(s, &width_cm, &ascent_cm, &descent_cm);
switch (style) {
case TEXT_LJUST:
gr_moveto_cm(xcm, ycm);
if (_grWritePS && fabs(angle_deg) > 0.1)
fprintf(_grPS, "%.2f rotate ", angle_deg);
gr_drawstring(s);
// This box not tested specifically
box.set(0, -descent_cm, width_cm, ascent_cm);
box.rotate(angle_deg);
box.shift_x(xcm);
box.shift_y(ycm);
break;
case TEXT_RJUST:
if (_grWritePS) {
fprintf(_grPS, "%.1f %.1f m ",
PT_PER_CM * (xcm - width_cm * cos(angle_deg / DEG_PER_RAD)),
PT_PER_CM * (ycm - width_cm * sin(angle_deg / DEG_PER_RAD)));
if (fabs(angle_deg) > 0.1)
fprintf(_grPS, "%.2f rotate ", angle_deg);
}
gr_drawstring(s);
// This box not tested specifically
box.set(-width_cm, -descent_cm, 0.0, ascent_cm);
box.rotate(angle_deg);
box.shift_x(xcm);
box.shift_y(ycm);
break;
case TEXT_CENTERED:
if (_grWritePS) {
fprintf(_grPS, "%.1f %.1f m ",
PT_PER_CM * (xcm - 0.5 * width_cm * cos(angle_deg / DEG_PER_RAD)),
PT_PER_CM * (ycm - 0.5 * width_cm * sin(angle_deg / DEG_PER_RAD)));
if (fabs(angle_deg) > 0.1)
fprintf(_grPS, "%.2f rotate ", angle_deg);
}
gr_drawstring(s);
box.set(-width_cm/2, -descent_cm, width_cm/2, ascent_cm);
box.rotate(angle_deg);
box.shift_x(xcm);
box.shift_y(ycm);
break;
default:
warning("gr_show_at type is UNKNOWN\n");
}
if (_grWritePS && fabs(angle_deg) > 0.1) {
fprintf(_grPS, "%.2f rotate ", -angle_deg);
check_psfile();
}
fprintf(_grPS, "%% gr_show_at() END\n");
// Update bounding box
bounding_box_update(box);
_drawingstarted = true;
}
// gr_drawstring() -- draw string, including font changes &super/subscripts
static position pstack[100];
static int istack = 0;
static void
gr_drawstring(const char *s)
{
char slast = '\0';
int slen = strlen(s);
bool inmath = false;
gr_fontID original_font = gr_currentfont();
gr_fontID current_font = original_font;
gr_fontID slant_font = original_font; // prevent compiler warning
double original_fontsize = gr_currentfontsize_pt();
bool know_slant_font = false;
if (slen <= 0)
return;
if (0.0 == gr_currentfontsize_pt())
return;
ClearStack();
// Figure out slant font, if there is an appropriate one
switch (original_font) {
case gr_font_TimesRoman:
slant_font = gr_font_TimesItalic;
know_slant_font = true;
break;
case gr_font_TimesBold:
slant_font = gr_font_TimesBoldItalic;
know_slant_font = true;
break;
case gr_font_Helvetica:
slant_font = gr_font_HelveticaOblique;
know_slant_font = true;
break;
case gr_font_HelveticaBold:
slant_font = gr_font_HelveticaBoldOblique;
know_slant_font = true;
break;
case gr_font_Courier:
slant_font = gr_font_CourierOblique;
know_slant_font = true;
break;
case gr_font_CourierBold:
slant_font = gr_font_CourierBoldOblique;
know_slant_font = true;
break;
case gr_font_PalatinoRoman:
slant_font = gr_font_PalatinoItalic;
know_slant_font = true;
break;
case gr_font_PalatinoBold:
slant_font = gr_font_PalatinoBoldItalic;
know_slant_font = true;
break;
default:
know_slant_font = false;
}
// Scan through whole string.
START_NEW_TEXT;
while (*s != '\0') {
if (*s == '-' && CurrentFont.encoding == font_encoding_isolatin1) {
// Use a different character to avoid looking like underscore.
if (_grWritePS) {
STOP_OLD_TEXT;
fprintf(_grPS, "(\\255) sh\n"); // endash
check_psfile();
START_NEW_TEXT;
}
s++;
continue;
}
// Figure out whether entering or leaving math mode; enter/leave if
// find $ without preceeding \. Thus a$b$ has math but a\$b\$ does
// not.
if (*s == '$' && slast != '\\') {
if (inmath) {
// Were in math; now go back to original font.
inmath = false;
if (current_font != original_font) {
current_font = original_font;
STOP_OLD_TEXT;
gr_setfont(current_font);
START_NEW_TEXT;
}
} else {
// Go to Italic/Oblique font, as case may be. Unfortunately,
// PostScript uses different names for this slanted font.
inmath = true;
if (know_slant_font) {
current_font = slant_font;
STOP_OLD_TEXT;
gr_setfont(current_font);
START_NEW_TEXT;
}
}
slast = *s++;
continue;
}
// Handle math mode. This code is a little kludgy, so be carefull.
if (inmath) {
if (*s == '^') {
// Handle superscripts
slast = *s++;
if (*s == '\0') {
// Odd -- nothing to superscript
if (current_font != original_font) {
STOP_OLD_TEXT;
gr_setfontsize_pt(original_fontsize);
gr_setfont(original_font);
}
return;
} else if (*s == '{') {
// Several characters to superscript
pstack[istack++] = Superscript;
MoveUp();
} else if (*s == '\\') {
// Math character to superscript
int inc;
char * insert;
insert = symbol_in_math(s, &inc);
if (inc) {
gr_fontID oldfontID = gr_currentfont();
pstack[istack++] = Superscript;
MoveUp();
STOP_OLD_TEXT;
gr_setfont(gr_font_Symbol);
if (_grWritePS) {
fprintf(_grPS, "(%s) sh\n", insert);
check_psfile();
}
gr_setfont(oldfontID);
START_NEW_TEXT;
s += inc;
PopStack();
}
} else {
// Single character to superscript
pstack[istack++] = Superscript;
MoveUp();
// Draw single character in math mode. If it's a digit,
// do not do in italics!
if (isdigit(*s) || ispunct(*s)) {
if (*s == '/' && !isdigit(slast)) {
gr_DrawChar(s);
} else {
STOP_OLD_TEXT;
gr_setfont(original_font);
START_NEW_TEXT;
gr_DrawChar(s);
STOP_OLD_TEXT;
gr_setfont(slant_font);
START_NEW_TEXT;
}
} else {
gr_DrawChar(s);
}
PopStack();
}
} else if (*s == '_') {
// Handle subscript
slast = *s++;
if (*s == '\0') {
// Odd -- nothing to subscript
if (current_font != original_font) {
STOP_OLD_TEXT;
gr_setfontsize_pt(original_fontsize);
gr_setfont(original_font);
}
return;
} else if (*s == '{') {
// Several characters to subscript
pstack[istack++] = Subscript;
MoveDown();
} else if (*s == '\\') {
// Math character to subscript
int inc;
char * insert;
insert = symbol_in_math(s, &inc);
if (inc) {
gr_fontID oldfontID = gr_currentfont();
pstack[istack++] = Subscript;
MoveDown();
STOP_OLD_TEXT;
gr_setfont(gr_font_Symbol);
if (_grWritePS) {
fprintf(_grPS, "(%s) sh\n", insert);
check_psfile();
}
gr_setfont(oldfontID);
START_NEW_TEXT;
s += inc;
PopStack();
}
} else {
// Single character to subscript
pstack[istack++] = Subscript;
MoveDown();
// Draw single character in math mode. If it's a digit,
// do not do in italics!
if (isdigit(*s) || ispunct(*s)) {
if (*s == '/' && !isdigit(slast)) {
gr_DrawChar(s);
} else {
STOP_OLD_TEXT;
gr_setfont(original_font);
START_NEW_TEXT;
gr_DrawChar(s);
STOP_OLD_TEXT;
gr_setfont(slant_font);
START_NEW_TEXT;
}
} else {
gr_DrawChar(s);
}
PopStack();
}
} else if (*s == '{') {
; // EMPTY
} else if (*s == '}') { // finished with super/sub in math
PopStack();
} else if (*s == '\\') {
// Substitute math symbol, unless it's
// an escaped string
int inc;
char *insert;
if (*(s + 1) == '$') {
slast = *s++;
} else if (*(s + 1) == ',') {
slast = *s++;
MoveHorizontally(0.1666666); // thinspace
} else if (*(s + 1) == '!') {
slast = *s++;
MoveHorizontally(-0.1666666); // neg thinspace
} else if (*(s + 1) == '"') {
slast = *s++;
} else if (*(s + 1) == '\\') {
slast = *s++;
} else if (*(s + 1) == '{' || *(s + 1) == '}') {
STOP_OLD_TEXT;
gr_setfont(original_font);
START_NEW_TEXT;
gr_DrawChar(s + 1);
STOP_OLD_TEXT;
gr_setfont(slant_font);
START_NEW_TEXT;
slast = *s++;
} else {
insert = symbol_in_math(s, &inc);
if (inc) {
// math symbol in symbol font
gr_fontID oldfontID = gr_currentfont();
STOP_OLD_TEXT;
gr_setfont(gr_font_Symbol);
if (_grWritePS) {
fprintf(_grPS, "(%s) sh\n", insert);
check_psfile();
}
gr_setfont(oldfontID);
START_NEW_TEXT;
s += inc;
} else {
// Not a known math-mode symbol, so just
// draw it. Is this the right thing to do?
gr_DrawChar(s + 1);
}
}
} else {
// Draw single character in math mode.
// If it's a digit, do not use italics.
if (isdigit(*s) || ispunct(*s)) {
if (*s == '/' && !isdigit(slast)) {
gr_DrawChar(s);
} else {
STOP_OLD_TEXT;
gr_setfont(original_font);
START_NEW_TEXT;
gr_DrawChar(s);
STOP_OLD_TEXT;
gr_setfont(slant_font);
START_NEW_TEXT;
}
} else {
gr_DrawChar(s);
}
}
} else {
// draw simple character outside math mode
if (*s == '\\') {
if (*(s + 1) == '$') {
slast = *s++;
} else if (*(s + 1) == '"') {
slast = *s++;
} else if (*(s + 1) == '\\') {
slast = *s++;
}
}
gr_DrawChar(s);
}
slast = *s++;
}
STOP_OLD_TEXT;
gr_setfontsize_pt(original_fontsize);
gr_setfont(original_font);
_drawingstarted = true;
return;
}
// set fontsize in points
void
gr_setfontsize_pt(double fontsize_pt)
{
if (fontsize_pt < 0.0)
CurrentFont.size_pt = default_fontsize_pt;
else
CurrentFont.size_pt = fontsize_pt;
gr_setfont_fontsize(CurrentFont.id);
}
// Set font encoding
void
gr_set_font_encoding(gr_font_encoding encoding)
{
CurrentFont.encoding = encoding;
}
// Get font encoding
gr_font_encoding
gr_current_font_encoding()
{
return CurrentFont.encoding;
}
/*
* gr_currentfont() -- find current font synopsis int gr_currentfont()
* description: gets the current font,as set by gr_setfont(). return value:
* current font number.
*/
gr_fontID
gr_currentfont()
{
return CurrentFont.id;
}
/*
* gr_currentfontsize_pt() -- return current fontsize in points
*/
double
gr_currentfontsize_pt()
{
return CurrentFont.size_pt;
}
/*
* gr_setfont() -- set new font. SYNOPSIS void gr_setfont(int new_font)
* DESCRIPTION: Sets the font for future string drawing to 'new_font'. These
* fonts are predefined: Times_Roman Helvetica Courier Symbol Palatino-Roman
* Palatino-Italic.
*
*/
void
gr_setfont(gr_fontID newID)
{
gr_setfont_fontsize(newID);
}
static void
gr_setfont_fontsize(gr_fontID newID)
{
int i = 0;
static bool have_set_font = false;
static gr_font last_font;
/* Search the font list */
while (font_list[i].id != gr_font_end_of_list) {
if (newID == font_list[i].id) {
/* Found the font, but ignore request if no change */
if (!have_set_font
|| newID != last_font.id
|| CurrentFont.encoding != last_font.encoding
|| CurrentFont.size_pt != last_font.size_pt) {
CurrentFont.id = newID;
if (!_grNeedBegin) {
/*
* Don't try to write if haven't done gr_begin() yet,
* since then will ruin things like
* gr_setup_ps_filename();
*/
if (_grWritePS) {
switch (CurrentFont.encoding) {
case font_encoding_standard:
fprintf(_grPS, "/%s findfont ", font_list[i].name);
break;
case font_encoding_isolatin1:
if (CurrentFont.id == gr_font_Symbol)
fprintf(_grPS, "/%s findfont ", font_list[i].name);
else
fprintf(_grPS, "/%s-ISOLatin1 findfont ", font_list[i].name);
break;
}
fprintf(_grPS, "%.2f sc sf\n", CurrentFont.size_pt);
}
have_set_font = true;
last_font.id = newID;
last_font.encoding = CurrentFont.encoding;
last_font.size_pt = CurrentFont.size_pt;
}
}
return;
}
i++;
}
warning("Ignoring request for unknown font.");
}
#define NCODES 100
// symbol_code (p 604 new PostScript book): (1) define name, (2) Postscript
// code, (3) symbol-font crossref code (used for estimage of symbol
// size, by index_for_math_symbol() ... a bad idea, really).
static char *symbol_code[NCODES][3] = {
// name, code in Table E.11, p604 new ps book, char-equivalent}
//
// Organization of list below is as in the tables in
// Lamport's Latex book
//
// Table 3.3 Greek Letters
// lowercase
{"alpha", "\\141", "a"},
{"beta", "\\142", "b"},
{"gamma", "\\147", "g"},
{"delta", "\\144", "d"},
{"epsilon", "\\145", "e"},
// varepsilon
{"zeta", "\\172", "z"},
{"eta", "\\150", "h"},
{"theta", "\\161", "q"},
{"vartheta", "\\112", "q"},
{"iota", "\\151", "i"},
{"kappa", "\\153", "k"},
{"lambda", "\\154", "l"},
{"mu", "\\155", "m"},
{"nu", "\\156", "n"},
{"xi", "\\170", "x"},
// o [not needed, really]
{"pi", "\\160", "p"},
{"varpi", "\\166", "p"}, // guess that size is same as pi
{"rho", "\\162", "r"},
{"sigma", "\\163", "s"},
{"varsigma", "\\126", "s"},
{"tau", "\\164", "t"},
{"upsilon", "\\165", "u"},
{"psi", "\\171", "y"},
{"chi", "\\143", "c"},
{"phi", "\\146", "f"},
{"varphi", "\\152", "f"},
{"omega", "\\167", "w"},
//
// Uppercase
{"Gamma", "\\107", "G"},
{"Delta", "\\104", "D"},
{"Theta", "\\121", "Q"},
{"Lambda", "\\114", "L"},
{"Xi", "\\130", "X"},
{"Pi", "\\120", "P"},
{"Sigma", "\\123", "S"},
{"Upsilon", "\\241", "Y"}, // guess that size is same as psi
{"Phi", "\\106", "F"},
{"Psi", "\\131", "Y"},
{"Omega", "\\127", "W"},
//
// Table 3.4: Binary Operation Symbols
{"pm", "\\261", "+"}, // guess that size is same as +
// mp
{"times", "\\264", "x"}, // guess that size is same as x
{"div", "\\270", "x"}, // guess that size is same as x
{"ast", "\\052", "*"},
// star
{"circ", "\\260", "."}, // guess that size is same as .
{"bullet", "\\267", "*"}, // guess that size is same as *
{"cdot", "\\327", ","},
// cap
// cup
// uplus
// sqcap
// sqcup
// vee
{"wedge", "\\331", "M"}, // guess that size is same as M
// setminus
// wr
// diamond
// bigtriangleup
// bigtriangledown
// triangleleft
// triangleright
// lhd
// rhd
// unlhd
// unrhd
{"oplus", "\\305", "o"},
// ominus
{"otimes", "\\304", "o"},
// oslash
// odot
// bigcirc
// dagger
// ddagger
// amalg
//
// Table 3.5: Relation Symbols
{"leq", "\\243", "<"}, // guess that size is same as <
// prec
// preceq
// ll
{"subset", "\\314", "<"}, // guess that size is same as <
{"subseteq", "\\315", "<"}, // guess that size is same as <
// sqsubset
// sqsubseteq
// MOVE 'in' to after 'infty'
// vdash
{"geq", "\\263", ">"}, // guess that size is same as >
// succ
// succeq
// gg
{"supset", "\\311", ">"}, // guess that size is same as >
{"supseteq", "\\312", ">"}, // guess that size is same as >
// sqsupset
// sqsupseteq
// ni
// dashv
{"equiv", "\\272", "="}, // guess that size is same as =
{"sim", "\\176", "~"},
// simeq
// asymp
{"approx", "\\273", "~"}, // guess that size is same as ~
{"cong", "\\100", "="}, // guess that size is same as =
{"neq", "\\271", "="}, // guess that size is same as =
// doteq
{"propto", "\\265", "~"}, // guess that size is same as ~
// models
{"perp", "\\136", "M"},
// mid
// parallel
// bowtie
// join
// smile
// frown
//
// Table 3.6: Arrow Symbols
{"leftarrow", "\\254", "M"},
{"Leftarrow", "\\334", "M"},
{"rightarrow", "\\256", "M"},
{"Rightarrow", "\\336", "M"},
{"leftrightarrow", "\\253", "M"},
{"Leftrightarrow", "\\333", "M"},
// mapsto
// hookleftarrow
// leftharpoonup
// leftharpoondown
// rightleftharpoons
// longleftarrow
// Longleftarrow
// longrightarrow
// Longrightarrow
// longleftrightarrow
// Longleftrightarrow
// longmapsto
// hookrightarrow
// rightharpoonup
// rightharpoon down
// leadsto
{"uparrow", "\\255", "|"}, // guess that size is same as "|"
{"Uparrow", "\\335", "|"}, // guess that size is same as "|"
{"downarrow", "\\257", "|"}, // guess that size is same as "|"
{"Downarrow", "\\337", "|"}, // guess that size is same as "|"
// updownarrow
// Updownarrow
// neararrow
// searrow
// swarrow
// nwarrow
//
// Table 3.7: Miscellaneous Symbols
{"aleph", "\\300", "M"},
// hbar
// imath
// jmath
// ell
{"wp", "\\303", "M"},
{"Re", "\\302", "R"}, // guess that size is same as R
{"Im", "\\301", "M"}, // guess that size is same as M
// mho
{"prime", "\\242", "'"},
{"emptyset", "\\306", "M"},
{"nabla", "\\321", "M"}, // guess that size is same as M
{"surd", "\\326", "M"}, // guess that size is same as M
{"sqrt", "\\326", "M"}, // not in this table, but what the heck
// top
{"bot", "\\136", "M"},
// |
{"angle", "\\320", "M"},
{"forall", "\\042", "M"}, // guess that size is same as M
{"exists", "\\044", "M"}, // guess that size is same as M
{"neg", "\\330", "M"},
// flat
// natural
// sharp
// backslash
{"partial", "\\266", "d"}, // guess that size is same as d
{"infty", "\\245", "M"}, // guess that size is same as M
// Interpose 'int' and 'in' here to avoid clashes with 'infty'
{"int", "\\362", "M"}, // guess that size is same as M
{"in", "\\316", "<"}, // guess that size is same as <
// Box
// Diamond
// triangle
{"clubsuit", "\\247", "M"},
{"diamondsuit", "\\340", "M"},
// heartsuit
{"spadesuit", "\\252", "M"},
//
// Table 3.8 Variable-sized symbols
{"sum", "\\345", "M"}, // guess that size is same as M
{"prod", "\\325", "M"}, // guess that size is same as M
// int -- moved up to avoid name clashes
// oint
// bigcap
// bigcup
// bigsqcup
// bigvee
// bigwedge
// bigodot
// bigotimes
// bigoplus
// biguplus
//
// Table 3.10
// (
// [
// {
{"lfloor", "\\353", "M"},
{"lceil", "\\351", "M"},
{"langle", "\\341", "<"},
// /
// |
// )
// ]
// }
{"rfloor", "\\373", "M"},
{"rceil", "\\371", "M"},
{"rangle", "\\361", ">"}
// backslash SEE ABOVE
// \|
// uparrow SEE ABOVE
// downarrow SEE ABOVE
// updownarrow SEE ABOVE
// Uparrow SEE ABOVE
// Downarrow SEE ABOVE
// Updownarrow SEE ABOVE
};
static char *
symbol_in_math(const char *sPtr, int *inc)
{
/* handle greek letter or symbol in math mode */
int i;
sPtr++;
*inc = 0;
for (i = 0; i < NCODES; i++) {
int len = strlen(symbol_code[i][0]);
if (!strncmp(sPtr, symbol_code[i][0], len)) {
*inc = len;
return symbol_code[i][1];
}
}
return NULL;
}
static void
PopStack()
{
if (istack > 0 && pstack[istack - 1] == Superscript)
MoveDown();
else if (istack > 0 && pstack[istack - 1] == Subscript)
MoveUp();
istack--;
}
static void
ClearStack()
{
istack = 0;
}
// Move left/right by indicated number of M spaces
static void
MoveHorizontally(double em_distance)
{
double w, a, d;
gr_stringwidth("M", &w, &a, &d);
STOP_OLD_TEXT;
gr_rmoveto_cm(em_distance * w, 0.0);
START_NEW_TEXT;
}
// MoveUp() -- move up, shifting to smaller/larger size if necessary
static void
MoveUp()
{
STOP_OLD_TEXT;
// See if already in subscript.
if ((istack > 0) && pstack[istack - 1] == Subscript) {
// Moving up from subscript, so enlarge font, then undo last move
// down.
gr_setfontsize_pt(gr_currentfontsize_pt() / SubSize);
gr_rmoveto_pt(0.0, SubMoveDown * gr_currentCapHeight_cm() * PT_PER_CM);
} else {
// Moving up for superscript, so move up, then reduce font.
gr_rmoveto_pt(0.0, SuperMoveUp * gr_currentCapHeight_cm() * PT_PER_CM);
gr_setfontsize_pt(gr_currentfontsize_pt() * SuperSize);
}
START_NEW_TEXT;
}
// MoveDown() -- move down, shifting to smaller/larger size if necessary
static void
MoveDown()
{
STOP_OLD_TEXT;
// See if already in superscript.
if ((istack > 0) && pstack[istack - 1] == Superscript) {
// Moving down from superscript, so enlarge font, then undo last move
// up.
gr_setfontsize_pt(gr_currentfontsize_pt() / SuperSize);
gr_rmoveto_pt(0.0, -SuperMoveUp * gr_currentCapHeight_cm() * PT_PER_CM);
} else {
// Moving down for subscript, so move down, then reduce font.
gr_rmoveto_pt(0.0, -SubMoveDown * gr_currentCapHeight_cm() * PT_PER_CM);
gr_setfontsize_pt(gr_currentfontsize_pt() * SubSize);
}
START_NEW_TEXT;
}
static void
gr_DrawChar(const char *c)
{
extern bool _grWritePS;
if (_grWritePS) {
extern FILE *_grPS;
switch (*c) {
case '\\':
fprintf(_grPS, "\\\\");
break;
case '(':
fprintf(_grPS, "\\(");
break;
case ')':
fprintf(_grPS, "\\)");
break;
default:
fprintf(_grPS, "%c", *c);
break;
}
check_psfile();
}
_drawingstarted = true;
}
// Draw indicated text in a "whiteout" box of indicated color, left-right
// centered at the indicated (x,y) locn specified in user-units. The text
// and box will be rotated by gr_currenttextangle_deg() degrees, measured
// counterclockwise from the horizontal.
void
gr_show_in_box(/*const*/GriString &s,
const GriColor& text_color,
const GriColor& box_color,
double x, // cm units
double y,
double angle_deg)
{
GriColor old_text_color = _griState.color_text();
GriColor old_line_color = _griState.color_line();
double width, ascent, descent;
double x0, y0, dx, dy, dx_rot, dy_rot;
double thin_space = gr_thinspace_cm();
if (0.0 == gr_currentfontsize_pt())
return;
gr_stringwidth(s.getValue(), &width, &ascent, &descent);
x0 = x; // save
y0 = y;
// White out below text.
dx = -0.5 * width - thin_space;
dy = -thin_space;
gr_rotate_xy(dx, dy, angle_deg, &dx_rot, &dy_rot);
static GriPath p(5);
p.clear();
p.push_back(x0 + dx_rot, y0 + dy_rot, 'm');
dx = -dx;
gr_rotate_xy(dx, dy, angle_deg, &dx_rot, &dy_rot);
p.push_back(x0 + dx_rot, y0 + dy_rot, 'l');
dx = 0.5 * width + thin_space;
dy = ascent + thin_space;
gr_rotate_xy(dx, dy, angle_deg, &dx_rot, &dy_rot);
p.push_back(x0 + dx_rot, y0 + dy_rot, 'l');
dx = -dx;
gr_rotate_xy(dx, dy, angle_deg, &dx_rot, &dy_rot);
p.push_back(x0 + dx_rot, y0 + dy_rot, 'l');
p.push_back(x0 + dx_rot, y0 + dy_rot, 'l');
_griState.set_color_line(box_color);
p.fill(units_cm);
bounding_box_update(p.bounding_box(units_cm));
// Draw text
_griState.set_color_text(text_color);
dx = -0.5 * width;
dy = 0.0;
gr_rotate_xy(dx, dy, angle_deg, &dx_rot, &dy_rot);
gr_show_at(s.getValue(),
x0 + dx_rot,
y0 + dy_rot,
TEXT_LJUST,
angle_deg);
_griState.set_color_line(old_line_color);
_griState.set_color_text(old_text_color);
_drawingstarted = true;
}
// Rotate (x,y) into (xx,yy), through `angle' degrees counterclockwise.
void
gr_rotate_xy(double x, double y, double angle, double *xx, double *yy)
{
angle /= DEG_PER_RAD; // convert to radians
double c = cos(angle);
double s = sin(angle);
*xx = c * x - s * y;
*yy = s * x + c * y;
}
// Get the width, ascent and descent of string s, in current font.
// BUG: Ascent and descent are inaccurate.
// BUG: Smaller size of super/subscripts not accounted for.
void
gr_stringwidth(const char *s, double *w, double *a, double *d)
{
*w = *a = *d = 0.0;
if (strlen(s) == 0)
return;
bool used_supers = false;
bool used_subs = false;
bool inmath = false;
bool oldWritePS = _grWritePS;
double oldfontsize_pt = gr_currentfontsize_pt();
_grWritePS = false;
while (*s != '\0') {
// figure out whether entering or leaving math mode
if (*s == '$' && *(s - 1) != '\\') {
inmath = (inmath ? false : true);
s++;
continue;
}
// handle math mode differently
// ?? BUG Superscripts and subscripts are printed smaller, but
// ?? BUG their size is assumed to be the same as normal chars.
if (inmath) {
if (*s == '^') // handle superscript
used_supers = true;
else if (*s == '_') // handle subscript
used_subs = true;
else if (*s == '{') // ignore groups
; // EMPTY
else if (*s == '}') // ignore groups
; // EMPTY
else if (*s == '\\') { // handle synonym
int skip;
char * ss;
// First catch thinspace commands
if (*(s + 1) == ',') {
// Thinspace = Mwidth/6
*w += gr_charwidth_cm((int)'M', CurrentFont.id, CurrentFont.size_pt) / 6.0;
s += 1;
} else if (*(s + 1) == '!') {
// Negative thinspace = -Mwidth/6
*w -= gr_charwidth_cm((int)'M', CurrentFont.id, CurrentFont.size_pt) / 6.0;
s += 1;
} else {
ss = symbol_in_math(s, &skip); // NULL if can't find
if (ss != NULL) {
gr_fontID oldfontID = CurrentFont.id;
int C = index_for_math_symbol(ss);
s += skip;
*w += gr_charwidth_cm(C, gr_font_Symbol, CurrentFont.size_pt);
CurrentFont.id = oldfontID;
} else {
// it's not a known math symbol
*w += gr_charwidth_cm('\\', CurrentFont.id, CurrentFont.size_pt);
}
}
} else {
// We are in mathmode, but it's not a special character. Add
// appropriate amount for either super/subscript or normal
// character.
*w += gr_charwidth_cm((int) *s, CurrentFont.id, CurrentFont.size_pt);
}
} else {
// not inmath
*w += gr_charwidth_cm((int) *s, CurrentFont.id, CurrentFont.size_pt);
}
s++;
}
// Calculate ascent/descent. BUG: doesn't take math chars into acct
*a = gr_currentCapHeight_cm() * (1 + (used_supers ? 1 : 0) *
(SuperSize + SuperMoveUp - 1));
#if 0 // before 2.054
*d = gr_currentCapHeight_cm() * (1.0 + 0.5 * (int) used_subs);
#endif
*d = gr_current_descender() * (1 + (used_subs ? 1.0 : 0.0) *
(SubSize + SubMoveDown - 1));
// reset fontsize ... can't do with gr_setfontsize_pt()
// because that would call this function in infinite recursion.
CurrentFont.size_pt = oldfontsize_pt;
_grWritePS = oldWritePS;
}
// return index (for size-table) for a character (given as integer)
static int
index_for_math_symbol(char *s)
{
for (int i = 0; i < NCODES; i++)
if (!strncmp(s, symbol_code[i][1], strlen(symbol_code[i][1])))
return (int) *symbol_code[i][2];
// return index(M) as a guess (since later using for width)
return (int) 'M';
}
// Return thinspace (=1/6 of width of "M" in current font), in cm
double
gr_thinspace_cm()
{
return (gr_charwidth_cm(int('M'), CurrentFont.id, CurrentFont.size_pt) / 6.0);
}
// Return width of quad (= width of "M" in current font), in cm
double
gr_quad_cm()
{
return (gr_charwidth_cm((int) 'M', CurrentFont.id, CurrentFont.size_pt));
}
// Following page should substituted as output from
// ~kelley/src/gri/src/get_font_metrics
struct font_metric {
float XHeight;
float CapHeight;
float Ascender;
float Descender;
float width[128];
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Courier.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Courier = {
0.015028, // XHeight
0.019826, // CapHeight
0.022190, // Ascender
-0.005539, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0211667, 0.0211667, 0.0211667,
0.0211667, 0.0211667, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Helvetica.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Helvetica = {
0.018450, // XHeight
0.025329, // CapHeight
0.025329, // Ascender
-0.007302, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0098072, 0.0098072, 0.0125236,
0.0196144, 0.0196144, 0.0313619, 0.0235303, 0.0078317,
0.0117475, 0.0117475, 0.0137231, 0.0206022, 0.0098072,
0.0117475, 0.0098072, 0.0098072, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0098072, 0.0098072,
0.0206022, 0.0206022, 0.0206022, 0.0196144, 0.0358069,
0.0235303, 0.0235303, 0.0254706, 0.0254706, 0.0235303,
0.0215547, 0.0274461, 0.0254706, 0.0098072, 0.0176389,
0.0235303, 0.0196144, 0.0293864, 0.0254706, 0.0274461,
0.0235303, 0.0274461, 0.0254706, 0.0235303, 0.0215547,
0.0254706, 0.0235303, 0.0333022, 0.0235303, 0.0235303,
0.0215547, 0.0098072, 0.0098072, 0.0098072, 0.0165453,
0.0196144, 0.0078317, 0.0196144, 0.0196144, 0.0176389,
0.0196144, 0.0196144, 0.0098072, 0.0196144, 0.0196144,
0.0078317, 0.0078317, 0.0176389, 0.0078317, 0.0293864,
0.0196144, 0.0196144, 0.0196144, 0.0196144, 0.0117475,
0.0176389, 0.0098072, 0.0196144, 0.0176389, 0.0254706,
0.0176389, 0.0176389, 0.0176389, 0.0117828, 0.0091722,
0.0117828, 0.0206022, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Helvetica-Oblique.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Helvetica_Oblique = {
0.018450, // XHeight
0.025329, // CapHeight
0.025329, // Ascender
-0.007302, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0098072, 0.0098072, 0.0125236,
0.0196144, 0.0196144, 0.0313619, 0.0235303, 0.0078317,
0.0117475, 0.0117475, 0.0137231, 0.0206022, 0.0098072,
0.0117475, 0.0098072, 0.0098072, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0098072, 0.0098072,
0.0206022, 0.0206022, 0.0206022, 0.0196144, 0.0358069,
0.0235303, 0.0235303, 0.0254706, 0.0254706, 0.0235303,
0.0215547, 0.0274461, 0.0254706, 0.0098072, 0.0176389,
0.0235303, 0.0196144, 0.0293864, 0.0254706, 0.0274461,
0.0235303, 0.0274461, 0.0254706, 0.0235303, 0.0215547,
0.0254706, 0.0235303, 0.0333022, 0.0235303, 0.0235303,
0.0215547, 0.0098072, 0.0098072, 0.0098072, 0.0165453,
0.0196144, 0.0078317, 0.0196144, 0.0196144, 0.0176389,
0.0196144, 0.0196144, 0.0098072, 0.0196144, 0.0196144,
0.0078317, 0.0078317, 0.0176389, 0.0078317, 0.0293864,
0.0196144, 0.0196144, 0.0196144, 0.0196144, 0.0117475,
0.0176389, 0.0098072, 0.0196144, 0.0176389, 0.0254706,
0.0176389, 0.0176389, 0.0176389, 0.0117828, 0.0091722,
0.0117828, 0.0206022, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Helvetica-Bold.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Helvetica_Bold = {
0.018768, // XHeight
0.025329, // CapHeight
0.025329, // Ascender
-0.007302, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0098072, 0.0117475, 0.0167217,
0.0196144, 0.0196144, 0.0313619, 0.0254706, 0.0098072,
0.0117475, 0.0117475, 0.0137231, 0.0206022, 0.0098072,
0.0117475, 0.0098072, 0.0098072, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0196144, 0.0196144,
0.0196144, 0.0196144, 0.0196144, 0.0117475, 0.0117475,
0.0206022, 0.0206022, 0.0206022, 0.0215547, 0.0343958,
0.0254706, 0.0254706, 0.0254706, 0.0254706, 0.0235303,
0.0215547, 0.0274461, 0.0254706, 0.0098072, 0.0196144,
0.0254706, 0.0215547, 0.0293864, 0.0254706, 0.0274461,
0.0235303, 0.0274461, 0.0254706, 0.0235303, 0.0215547,
0.0254706, 0.0235303, 0.0333022, 0.0235303, 0.0235303,
0.0215547, 0.0117475, 0.0098072, 0.0117475, 0.0206022,
0.0196144, 0.0098072, 0.0196144, 0.0215547, 0.0196144,
0.0215547, 0.0196144, 0.0117475, 0.0215547, 0.0215547,
0.0098072, 0.0098072, 0.0196144, 0.0098072, 0.0313619,
0.0215547, 0.0215547, 0.0215547, 0.0215547, 0.0137231,
0.0196144, 0.0117475, 0.0215547, 0.0196144, 0.0274461,
0.0196144, 0.0196144, 0.0176389, 0.0137231, 0.0098778,
0.0137231, 0.0206022, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Palatino-Roman.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Palatino_Roman = {
0.016545, // XHeight
0.024412, // CapHeight
0.025612, // Ascender
-0.009913, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0088194, 0.0098072, 0.0130881,
0.0176389, 0.0176389, 0.0296333, 0.0274461, 0.0098072,
0.0117475, 0.0117475, 0.0137231, 0.0213783, 0.0088194,
0.0117475, 0.0088194, 0.0213783, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0088194, 0.0088194,
0.0213783, 0.0213783, 0.0213783, 0.0156633, 0.0263525,
0.0274461, 0.0215547, 0.0250119, 0.0273050, 0.0215547,
0.0196144, 0.0269169, 0.0293511, 0.0118886, 0.0117475,
0.0256117, 0.0215547, 0.0333728, 0.0293158, 0.0277283,
0.0213078, 0.0277283, 0.0235656, 0.0185208, 0.0216253,
0.0274461, 0.0254706, 0.0352778, 0.0235303, 0.0235303,
0.0235303, 0.0117475, 0.0213783, 0.0117475, 0.0213783,
0.0176389, 0.0098072, 0.0176389, 0.0195086, 0.0156633,
0.0215547, 0.0168981, 0.0117475, 0.0196144, 0.0205317,
0.0102658, 0.0082550, 0.0196144, 0.0102658, 0.0311503,
0.0205317, 0.0192617, 0.0212019, 0.0197556, 0.0139347,
0.0149578, 0.0115006, 0.0212725, 0.0199319, 0.0294217,
0.0182033, 0.0196144, 0.0176389, 0.0117475, 0.0213783,
0.0117475, 0.0213783, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Symbol.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Symbol = {
0.000000, // XHeight
0.000000, // CapHeight
0.000000, // Ascender
0.000000, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0088194, 0.0117475, 0.0251531,
0.0176389, 0.0193675, 0.0293864, 0.0274461, 0.0154869,
0.0117475, 0.0117475, 0.0176389, 0.0193675, 0.0088194,
0.0193675, 0.0088194, 0.0098072, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0098072, 0.0098072,
0.0193675, 0.0193675, 0.0193675, 0.0156633, 0.0193675,
0.0254706, 0.0235303, 0.0254706, 0.0215900, 0.0215547,
0.0269169, 0.0212725, 0.0254706, 0.0117475, 0.0222603,
0.0254706, 0.0242006, 0.0313619, 0.0254706, 0.0254706,
0.0270933, 0.0261408, 0.0196144, 0.0208844, 0.0215547,
0.0243417, 0.0154869, 0.0270933, 0.0227542, 0.0280458,
0.0215547, 0.0117475, 0.0304447, 0.0117475, 0.0232128,
0.0176389, 0.0176389, 0.0222603, 0.0193675, 0.0193675,
0.0174272, 0.0154869, 0.0183797, 0.0144992, 0.0212725,
0.0116064, 0.0212725, 0.0193675, 0.0193675, 0.0203200,
0.0183797, 0.0193675, 0.0193675, 0.0183797, 0.0193675,
0.0212725, 0.0154869, 0.0203200, 0.0251531, 0.0242006,
0.0173919, 0.0242006, 0.0174272, 0.0169333, 0.0070556,
0.0169333, 0.0193675, 0.0000000
}
};
//
// Following font metric generated by `get_font_metrics'
// perlscript from Font Metric file `/usr/openwin/lib/X11/fonts/F3/afm/Times-Roman.afm'.
// All measurement in centimetres, given a pointsize of 1.0
//
struct font_metric Times_Roman = {
0.015875, // XHeight
0.023354, // CapHeight
0.024095, // Ascender
-0.007655, // Descender
{ // Widths of first 128 characters
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0088194, 0.0117475, 0.0143933,
0.0176389, 0.0176389, 0.0293864, 0.0274461, 0.0117475,
0.0117475, 0.0117475, 0.0176389, 0.0198967, 0.0088194,
0.0117475, 0.0088194, 0.0098072, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0176389, 0.0176389,
0.0176389, 0.0176389, 0.0176389, 0.0098072, 0.0098072,
0.0198967, 0.0198967, 0.0198967, 0.0156633, 0.0324908,
0.0254706, 0.0235303, 0.0235303, 0.0254706, 0.0215547,
0.0196144, 0.0254706, 0.0254706, 0.0117475, 0.0137231,
0.0254706, 0.0215547, 0.0313619, 0.0254706, 0.0254706,
0.0196144, 0.0254706, 0.0235303, 0.0196144, 0.0215547,
0.0254706, 0.0254706, 0.0333022, 0.0254706, 0.0254706,
0.0215547, 0.0117475, 0.0098072, 0.0117475, 0.0165453,
0.0176389, 0.0117475, 0.0156633, 0.0176389, 0.0156633,
0.0176389, 0.0156633, 0.0117475, 0.0176389, 0.0176389,
0.0098072, 0.0098072, 0.0176389, 0.0098072, 0.0274461,
0.0176389, 0.0176389, 0.0176389, 0.0176389, 0.0117475,
0.0137231, 0.0098072, 0.0176389, 0.0176389, 0.0254706,
0.0176389, 0.0176389, 0.0156633, 0.0169333, 0.0070556,
0.0169333, 0.0190853, 0.0000000
}
};
/*
* gr_charwidth_cm(char c, int font, double fontsize_pt)
*
* RETURN VALUE the width of the character, in centimetres
*
* Font info created by the `get_font_metrics' perlscript, in the Gri src
* directory. This looks in the OpenWindows font metrics files to figure the
* pertintent stuff out. (You might have to edit this for different
* machines).
*/
static double
gr_charwidth_cm(int c, int font, double fontsize_pt)
{
unsigned char i = (int) c;
if (i > 127)
return fontsize_pt * 0.0211663; /* error, but guess Courier size
* anyway */
switch (font) {
case gr_font_TimesRoman:
return fontsize_pt * Times_Roman.width[i];
case gr_font_Courier:
return fontsize_pt * 0.0211663; /* Courier has fixed width */
case gr_font_Symbol:
return fontsize_pt * Symbol.width[i];
case gr_font_Helvetica:
return fontsize_pt * Helvetica.width[i];
case gr_font_HelveticaBold:
return fontsize_pt * Helvetica_Bold.width[i];
case gr_font_PalatinoRoman:
return fontsize_pt * Palatino_Roman.width[i];
default:
break;
/* Guess similar size to Helvetica */
}
return (fontsize_pt * Helvetica.width[i]);
}
double
gr_current_descender() // descender, in positive cm
{
switch (CurrentFont.id) {
case gr_font_Courier:
return (-CurrentFont.size_pt * Courier.Descender);
case gr_font_Helvetica:
return(-CurrentFont.size_pt * Helvetica.Descender);
case gr_font_Symbol:
return(-CurrentFont.size_pt * Symbol.Descender);
case gr_font_TimesRoman:
return(-CurrentFont.size_pt * Times_Roman.Descender);
default:
break;
}
return CurrentFont.size_pt * 0.025329; // Guess similar to Helvetica
}
// gr_currentCapHeight_cm() -- find height of capital characters
double
gr_currentCapHeight_cm()
{
double height_cm = 0.0;
switch (CurrentFont.id) {
case gr_font_Courier:
height_cm = (CurrentFont.size_pt * Courier.CapHeight);
break;
case gr_font_Helvetica:
height_cm = (CurrentFont.size_pt * Helvetica.CapHeight);
break;
case gr_font_Symbol:
height_cm = (CurrentFont.size_pt * Symbol.CapHeight);
break;
case gr_font_TimesRoman:
height_cm = (CurrentFont.size_pt * Times_Roman.CapHeight);
break;
default:
/*
* Don't know this font.
*/
break;
}
if (height_cm > 0.0)
return height_cm;
else
return CurrentFont.size_pt * 0.025329; /* Guess Helvetica */
}
|