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
|
/*@z23.c:Galley Printer:ScaleFactor()@****************************************/
/* */
/* THE LOUT DOCUMENT FORMATTING SYSTEM (VERSION 3.30) */
/* COPYRIGHT (C) 1991, 2004 Jeffrey H. Kingston */
/* */
/* Jeffrey H. Kingston (jeff@it.usyd.edu.au) */
/* School of Information Technologies */
/* The University of Sydney 2006 */
/* AUSTRALIA */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either Version 2, or (at your option) */
/* any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA */
/* */
/* FILE: z23.c */
/* MODULE: Galley Printer */
/* EXTERNS: FixAndPrintObject() */
/* */
/*****************************************************************************/
#include "externs.h"
#define NO_SUPPRESS FALSE
#define SUPPRESS TRUE
#define word_equal(x, str) (is_word(type(x)) && StringEqual(string(x), str))
/*****************************************************************************/
/* */
/* FirstDefiniteLDN(x, link, y, jn, ymk, dim, sp, pg) */
/* NextDefiniteWithGapLDN(x, link, y, g, jn, ymk, dim, sp, pg) */
/* */
/* Like FirstDefinite and NextDefiniteWithGap but during the scan, if a */
/* LINK_DEST_NULL is encountered, call FixAndPrintObject on it before */
/* continuing on to find the next definite object. */
/* */
/*****************************************************************************/
#define FirstDefiniteLDN(x, link, y, jn, ymk, dim, sp, pg) \
{ jn = TRUE; \
for( link = Down(x); link != x; link = NextDown(link) ) \
{ Child(y, link); \
if( type(y) == GAP_OBJ ) jn = jn && join(gap(y)); \
else if( type(y)==SPLIT ? SplitIsDefinite(y) : is_definite(type(y)))\
break; \
else if( type(y) == LINK_DEST_NULL ) \
FixAndPrintObject(y, ymk, 0, 0, dim, sp, pg, 0, &aback, &afwd); \
} \
} /* end FirstDefiniteLDN */
#define NextDefiniteWithGapLDN(x, link, y, g, jn, ymk, dim, sp, pg) \
{ g = nilobj; jn = TRUE; \
for( link = NextDown(link); link != x; link = NextDown(link) ) \
{ Child(y, link); \
if( type(y) == GAP_OBJ ) g = y, jn = jn && join(gap(y)); \
else if( type(y)==SPLIT ? SplitIsDefinite(y):is_definite(type(y)) ) \
{ \
debug2(DFS, D, " NextDefiniteWithGap at %s %s", \
Image(type(y)), EchoObject(y)); \
assert( g != nilobj, "NextDefiniteWithGap: g == nilobj!" ); \
break; \
} \
else if( type(y) == LINK_DEST_NULL ) \
FixAndPrintObject(y, ymk, 0, 0, dim, sp, pg, 0, &aback, &afwd); \
} \
} /* end NextDefiniteWithGapLDN */
/*****************************************************************************/
/* */
/* static float ScaleFactor(avail_size, inner_size) */
/* */
/* Return the scale factor for this scaling, or 0 if impossible. */
/* */
/*****************************************************************************/
static float ScaleFactor(FULL_LENGTH avail_size, FULL_LENGTH inner_size)
{ float scale_factor;
scale_factor = avail_size <= 0 ? 0 :
inner_size <= 0 ? 0 : (float) avail_size / inner_size;
return scale_factor;
}
/*@::FindAdjustIncrement()@***************************************************/
/* */
/* static FULL_LENGTH FindAdjustIncrement(x, frame_size, dim) */
/* */
/* Find the amount by which to increase the width of the subobjects of */
/* concatenation object x so that it is adjusted to fill size frame_size. */
/* */
/*****************************************************************************/
static FULL_LENGTH FindAdjustIncrement(OBJECT x, FULL_LENGTH frame_size,int dim)
{ OBJECT y = nilobj, link, prev = nilobj, g;
int adjustable_gaps; BOOLEAN jn;
FULL_LENGTH inc, mk, actual_size;
debug2(DGP, DD, "FindAdjustIncrement(x, %s, %s)",
EchoLength(frame_size), dimen(dim));
FirstDefinite(x, link, prev, jn);
if( link != x )
{ adjustable_gaps = 0;
mk = back(prev, dim);
NextDefiniteWithGap(x, link, y, g, jn);
while( link != x )
{ if ( mode(gap(g)) == TAB_MODE || units(gap(g)) == AVAIL_UNIT
|| units(gap(g)) == FRAME_UNIT )
{ debug0(DGP, DD, "FindAdjustIncrement returning 0 (tab gap)");
return 0;
}
mk += ActualGap(fwd(prev, dim), back(y, dim), fwd(y, dim), &gap(g),
frame_size, mk);
prev = y;
adjustable_gaps++;
NextDefiniteWithGap(x, link, y, g, jn);
}
actual_size = mk + fwd(prev, dim);
debug2(DGP, DD, " actual_size = %s, adjustable_gaps = %d",
EchoLength(actual_size), adjustable_gaps);
inc = adjustable_gaps==0 ? 0 : (frame_size - actual_size) / adjustable_gaps;
}
else inc = 0;
debug1(DGP, DD, "FindAdjustIncrement returning %s", EchoLength(inc));
return inc;
} /* end FindAdjustIncrement */
/*@::FixAndPrintObject()@*****************************************************/
/* */
/* OBJECT FixAndPrintObject(x, xmk, xb, xf, dim, suppress, pg, count, */
/* actual_back, actual_fwd) */
/* */
/* Fix the absolute position of object x in dimension dim, in such a way */
/* that the principal mark of x has coordinate xmk, and x has actual size */
/* (xb, xf), where usually xb >= back(x, dim) and xf >= fwd(x, dim). */
/* */
/* Actually, in the case where x includes an object lying on a thread */
/* leading outside x, the final size of x may be different. Because */
/* of this, the procedure sets *actual_back and *actual_fwd to the actual */
/* size of x upon return. The caller assumes that x will exactly occupy */
/* this space (actual_back, actual_fwd). */
/* */
/* The suppress parameter is true if a temporary suppression of adjustment */
/* in this direction is in effect (because a neighbouring adjustment has */
/* already been done). This is for @HAdjust and @VAdjust, not @PAdjust. */
/* */
/* If dim == COLM, the coordinate information is merely stored; but if */
/* dim == ROWM, it is used to generate PostScript for printing x. */
/* */
/* Parameter pg records the height of the current page. This is used */
/* to correct for the fact that Lout places its origin at the top left, */
/* while PostScript places its origin at the bottom left. This correction */
/* cannot be made by transforming user space. */
/* */
/* x is child number count of its parent (used by COL_THR and ROW_THR only) */
/* */
/* FixAndPrintObject ordinarily returns the object passed to it; however */
/* it occasionally replaces that object with another, and then it is the */
/* replacement object that is returned. */
/* */
/*****************************************************************************/
OBJECT FixAndPrintObject(OBJECT x, FULL_LENGTH xmk, FULL_LENGTH xb,
FULL_LENGTH xf, int dim, BOOLEAN suppress, FULL_LENGTH pg, int count,
FULL_LENGTH *actual_back, FULL_LENGTH *actual_fwd)
{ OBJECT y = nilobj, link, prev = nilobj, g, z, face, thr, res, uplink;
/* OBJECT fixed_thr, tmp; */
FULL_LENGTH mk, ymk, frame_size, back_edge, yb, yf, inc, f;
FULL_LENGTH aback, afwd;
int i; float scale_factor; BOOLEAN jn;
debug8(DGP, DD, "[ FixAndPrintObject(%s %s%s, %s, %s,%s, %s, %s, pg, count)",
Image(type(x)),
((type(x) == WORD || type(x) == QWORD) ? string(x) : STR_EMPTY),
EchoFilePos(&fpos(x)),
EchoLength(xmk), EchoLength(xb), EchoLength(xf),dimen(dim),
(suppress == SUPPRESS ? "suppress" : "no_suppress"));
debug2(DGP, DD, " size(x) = %s,%s; x =",
EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
ifdebug(DGP, DD, DebugObject(x));
res = x;
/*** start and stop debugging
if( dim == COLM && is_word(type(x)) &&
StringEqual(string(x), AsciiToFull("STARTBUG")) )
dbg[DGP].on[DD] = dbg[DGP].on[D] = TRUE;
if( dim == COLM && is_word(type(x)) &&
StringEqual(string(x), AsciiToFull("STOPBUG")) )
dbg[DGP].on[DD] = dbg[DGP].on[D] = FALSE;
*** */
switch( type(x) )
{
case CLOSURE:
case NULL_CLOS:
case PAGE_LABEL:
case CROSS:
case FORCE_CROSS:
*actual_back = xb; *actual_fwd = xf;
break;
case START_HVSPAN:
case START_HSPAN:
case START_VSPAN:
CountChild(y, DownDim(x, dim), count);
if( type(y) == HSPANNER || type(y) == VSPANNER )
{
Child(z, Down(y));
Parent(thr, UpDim(x, dim));
save_mark(y) = xmk - back(thr, dim) + back(z, dim);
/* do the fix now if the first column is also the last one */
debug2(DGP, DD, " pre-inc spanner_fixed(y) = %d, spanner_count(y) = %d",
spanner_fixed(y), spanner_count(y));
if( ++spanner_fixed(y) == spanner_count(y) )
{
debug6(DGP, DD, " f+last SPAN: yf = max(%s + %s - %s, %s, %s - %s)",
EchoLength(xmk), EchoLength(xf), EchoLength(save_mark(y)),
EchoLength(fwd(z, dim)),
EchoLength(bfc(constraint(y))), EchoLength(back(z, dim)));
yf = find_max(xmk + xf - save_mark(y), fwd(z, dim));
yf = find_max(yf, bfc(constraint(y)) - back(z, dim));
z = FixAndPrintObject(z, save_mark(y), back(z, dim), yf, dim,
FALSE, pg, 1, &aback, &afwd);
spanner_fixed(y) = 0; /* restart for if printed again */
}
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
}
else
{
debug6(DGP, DD, "%s alternate FixAndPrintObject(%s, %s, %s, %s, %s, ..)",
Image(type(x)), Image(type(y)), EchoLength(xmk), EchoLength(xb),
EchoLength(xf), dimen(dim));
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case HSPAN:
case VSPAN:
/* do the fix on the last one */
if( (dim == COLM) == (type(x) == HSPAN) )
{
CountChild(y, DownDim(x, dim), count);
assert(type(y) == HSPANNER || type(y) == VSPANNER, "FAPO HSPAN/VSPAN!");
debug2(DGP, DD, " pre-inc spanner_fixed(y) = %d, spanner_count(y) = %d",
spanner_fixed(y), spanner_count(y));
if( ++spanner_fixed(y) == spanner_count(y) )
{
Child(z, Down(y));
debug6(DGP, DD, " last SPAN: yf = max(%s + %s - %s, %s, %s - %s)",
EchoLength(xmk), EchoLength(xf), EchoLength(save_mark(y)),
EchoLength(fwd(z, dim)),
EchoLength(bfc(constraint(y))), EchoLength(back(z, dim)));
yf = find_max(xmk + xf - save_mark(y), fwd(z, dim));
yf = find_max(yf, bfc(constraint(y)) - back(z, dim));
z = FixAndPrintObject(z, save_mark(y), back(z, dim), yf, dim,
FALSE, pg, 1, &aback, &afwd);
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
spanner_fixed(y) = 0; /* restart for if printed again */
}
}
break;
case WORD:
case QWORD:
if( dim == COLM )
{
/* save horizontal position for PrintWord below */
word_save_mark(x) = xmk;
/* if first occurrence of this font on this page, notify font */
if( string(x)[0] != '\0' )
{ face = finfo[word_font(x)].original_face;
if( font_page(face) < font_curr_page )
{ debug3(DFT, DD, "FAPO: x = %s, word_font = %d, face = %s",
string(x), word_font(x), EchoObject(face));
FontPageUsed(face);
}
}
}
else
{
if( string(x)[0] != '\0' )
{ BackEnd->PrintWord(x, word_save_mark(x), pg - xmk);
/* NB if this word is to be underlined, it will be already enclosed
in an ACAT by Manifest, and that ACAT will do the underlining */
}
}
*actual_back = xb; *actual_fwd = xf;
break;
case WIDE:
case HIGH:
CountChild(y, Down(x), count);
if( (dim == COLM) == (type(x) == WIDE) )
{ yf = bfc(constraint(x)) - back(y, dim);
y = FixAndPrintObject(y, xmk, back(y,dim), yf, dim, NO_SUPPRESS, pg,
count, &aback, &afwd);
*actual_back = xb; *actual_fwd = xf;
}
else
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case HSHIFT:
case VSHIFT:
CountChild(y, Down(x), count);
if( (dim == COLM) == (type(x) == HSHIFT) )
{
/* work out the size of the shift depending on the units */
f = FindShift(x, y, dim);
ymk = xmk - f;
yb = find_max(0, xb - f);
yf = find_max(0, xf + f);
y = FixAndPrintObject(y, ymk, yb, yf, dim, suppress, pg, count,
&aback, &afwd);
/* recalculate the size of x as in MinSize */
f = FindShift(x, y, dim);
*actual_back = find_min(MAX_FULL_LENGTH, find_max(0, aback + f));
*actual_fwd = find_min(MAX_FULL_LENGTH, find_max(0, afwd - f));
}
else
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case HCONTRACT:
case VCONTRACT:
CountChild(y, Down(x), count);
if( (dim == COLM) == (type(x) == HCONTRACT) )
{ y = FixAndPrintObject(y, xmk, back(y,dim), fwd(y,dim), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
*actual_back = xb; *actual_fwd = xf;
}
else
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case ONE_COL:
case ONE_ROW:
case HLIMITED:
case VLIMITED:
case HEXPAND:
case VEXPAND:
CountChild(y, Down(x), count);
if( (dim == COLM) == (type(x) == ONE_COL || type(x) == HEXPAND) )
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
*actual_back = xb; *actual_fwd = xf;
}
else
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case HMIRROR:
if( BackEnd->mirror_avail )
{
CountChild(y, Down(x), count);
if( dim == COLM )
{
save_mark(x) = xmk;
y = FixAndPrintObject(y, 0, back(y, COLM), fwd(y, COLM), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
}
else
{ BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(save_mark(x), pg - xmk);
BackEnd->CoordHMirror();
y = FixAndPrintObject(y, 0, back(y, ROWM), fwd(y, ROWM), dim,
NO_SUPPRESS, 0, count, &aback, &afwd);
BackEnd->RestoreGraphicState();
}
}
*actual_back = xb; *actual_fwd = xf;
break;
case VMIRROR:
debug0(DRS, DD, "FixAndPrintObject at VMIRROR");
if( BackEnd->mirror_avail )
{
CountChild(y, Down(x), count);
if( dim == COLM )
y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
else
{ BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(0, pg - xmk);
BackEnd->CoordVMirror();
y = FixAndPrintObject(y, 0, back(y, ROWM), fwd(y, ROWM), dim,
NO_SUPPRESS, 0, count, &aback, &afwd);
BackEnd->RestoreGraphicState();
}
}
*actual_back = xb; *actual_fwd = xf;
break;
case VSCALE:
debug0(DRS, DD, "FixAndPrintObject at VSCALE");
CountChild(y, Down(x), count);
if( BackEnd->scale_avail )
{
if( dim == COLM )
y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
else if( (scale_factor = ScaleFactor(xb+xf, size(y, ROWM))) > 0 )
{ BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(0,
pg - (xmk - xb + (FULL_LENGTH) (back(y, ROWM) * scale_factor)));
BackEnd->CoordScale(1.0, scale_factor);
y = FixAndPrintObject(y, 0, back(y,ROWM), fwd(y,ROWM), dim,
NO_SUPPRESS, 0, count, &aback, &afwd);
BackEnd->RestoreGraphicState();
}
else if( !is_word(type(y)) || string(y)[0] != '\0' )
Error(23, 1, "object deleted (it cannot be scaled vertically)",
WARN, &fpos(x));
}
*actual_back = xb; *actual_fwd = xf;
break;
case HSCALE:
debug0(DRS, DD, "FixAndPrintObject at HSCALE");
CountChild(y, Down(x), count);
if( BackEnd->scale_avail )
{ if( dim == COLM )
{ save_mark(x) = xmk;
bc(constraint(x)) = xb;
fc(constraint(x)) = xf;
if( (scale_factor = ScaleFactor(xb+xf, size(y, COLM))) > 0 )
y = FixAndPrintObject(y, 0, back(y, COLM), fwd(y, COLM), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
else if( !is_word(type(y)) || string(y)[0] != '\0' )
Error(23, 2, "object deleted (it cannot be scaled horizontally)",
WARN, &fpos(y));
}
else if( (scale_factor =
ScaleFactor(bc(constraint(x))+fc(constraint(x)),size(y,COLM))) > 0 )
{ BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(save_mark(x) - bc(constraint(x))
+ (FULL_LENGTH) (back(y, COLM)*scale_factor), 0);
BackEnd->CoordScale(scale_factor, 1.0);
y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
BackEnd->RestoreGraphicState();
}
}
*actual_back = xb; *actual_fwd = xf;
break;
case SCALE:
CountChild(y, Down(x), count);
if( BackEnd->scale_avail )
{
if( dim == COLM )
{ assert( bc(constraint(x)) > 0, "FAPO: horizontal scale factor!" );
save_mark(x) = xmk;
yb = xb * SF / bc(constraint(x));
yf = xf * SF / bc(constraint(x));
y = FixAndPrintObject(y, 0, yb, yf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
}
else
{ assert( fc(constraint(x)) > 0, "FAPO: vertical scale factor!" );
yb = xb * SF / fc(constraint(x));
yf = xf * SF / fc(constraint(x));
BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(save_mark(x), pg - xmk);
BackEnd->CoordScale( (float)bc(constraint(x))/SF,
(float)fc(constraint(x))/SF);
y = FixAndPrintObject(y, 0, yb, yf, dim, NO_SUPPRESS, 0, count,
&aback, &afwd);
BackEnd->RestoreGraphicState();
}
}
else if( bc(constraint(x)) == SF && fc(constraint(x)) == SF )
{
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
&aback, &afwd);
}
*actual_back = xb; *actual_fwd = xf;
break;
case KERN_SHRINK:
CountChild(y, LastDown(x), count);
if( dim == COLM )
{ y = FixAndPrintObject(y, xmk, back(y,dim), fwd(y,dim), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
}
else
{ y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
actual_back, actual_fwd);
}
break;
case BACKGROUND:
/* this object has the size of its second child; but its first */
/* child gets printed too, in the same space */
CountChild(y, Down(x), count);
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
&aback, &afwd);
CountChild(y, LastDown(x), count);
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
&aback, &afwd);
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
break;
case ROTATE:
CountChild(y, Down(x), count);
if( BackEnd->rotate_avail )
{
if( dim == COLM )
{ CONSTRAINT colc, rowc, yc;
save_mark(x) = xmk;
SetConstraint(colc, back(x,COLM), MAX_FULL_LENGTH, fwd(x,COLM));
SetConstraint(rowc, back(x,ROWM), MAX_FULL_LENGTH, fwd(x,ROWM));
RotateConstraint(&yc, y, sparec(constraint(x)), &colc, &rowc,COLM);
y = FixAndPrintObject(y, 0, bc(yc), fc(yc), COLM, NO_SUPPRESS, pg,
count, &aback, &afwd);
}
else
{ CONSTRAINT colc, rowc, yc;
BackEnd->SaveGraphicState(y);
BackEnd->CoordTranslate(save_mark(x), pg - xmk);
BackEnd->CoordRotate(sparec(constraint(x)));
SetConstraint(colc, back(x,COLM), MAX_FULL_LENGTH, fwd(x,COLM));
SetConstraint(rowc, back(x,ROWM), MAX_FULL_LENGTH, fwd(x,ROWM));
RotateConstraint(&yc, y, sparec(constraint(x)), &colc, &rowc, ROWM);
y = FixAndPrintObject(y, 0, bc(yc), fc(yc), ROWM, NO_SUPPRESS, 0,
count, &aback, &afwd);
BackEnd->RestoreGraphicState();
}
}
else if( sparec(constraint(x)) == 0 )
y = FixAndPrintObject(y,xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
*actual_back = xb; *actual_fwd = xf;
break;
case PLAIN_GRAPHIC:
CountChild(y, LastDown(x), count);
if( BackEnd->plaingraphic_avail )
{
if( dim == COLM )
{
back(x, dim) = xb; /* NB state change here */
fwd(x, dim) = xf;
save_mark(x) = xmk - back(x, dim);
debug2(DGP, DD, "PLAIN_GRAPHIC COLM storing size %s, %s",
EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
&aback, &afwd);
}
else
{ OBJECT tmp, pre, post;
Child(tmp, Down(x));
if( type(tmp) == VCAT )
{ Child(pre, Down(tmp));
Child(post, LastDown(tmp));
}
else pre = tmp, post = nilobj;
back(x, dim) = xb;
fwd(x, dim) = xf;
BackEnd->PrintPlainGraphic(pre, save_mark(x),
pg - (xmk - back(x, dim)), x);
y = FixAndPrintObject(y, xmk, xb, xf, dim, suppress, pg, count,
&aback, &afwd);
if( post != nilobj )
BackEnd->PrintPlainGraphic(post, save_mark(x),
pg - (xmk - back(x, dim)), x);
}
}
else
y = FixAndPrintObject(y, xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
*actual_back = xb; *actual_fwd = xf;
break;
case GRAPHIC:
CountChild(y, LastDown(x), count);
if( BackEnd->graphic_avail )
{
if( dim == COLM )
{
/* if first occurrence of this font on this page, notify font */
if( font(save_style(x)) > 0 )
{ face = finfo[font(save_style(x))].original_face;
if( font_page(face) < font_curr_page ) FontPageUsed(face);
}
back(x, dim) = xb; /* NB state change here */
fwd(x, dim) = xf;
debug2(DGP, DD, "GRAPHIC COLM storing size %s, %s",
EchoLength(back(x, dim)), EchoLength(fwd(x, dim)));
save_mark(x) = xmk - back(x, COLM);
y = FixAndPrintObject(y, xb, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
}
else
{ OBJECT tmp, pre, post;
Child(tmp, Down(x));
if( type(tmp) == VCAT )
{ Child(pre, Down(tmp));
Child(post, LastDown(tmp));
}
else pre = tmp, post = nilobj;
back(x, dim) = xb;
fwd(x, dim) = xf;
BackEnd->SaveTranslateDefineSave(x, save_mark(x),
pg - (xmk + fwd(x, ROWM)));
BackEnd->PrintGraphicObject(pre);
BackEnd->RestoreGraphicState();
y = FixAndPrintObject(y, xb, xb, xf, dim, NO_SUPPRESS, xb + xf,
count, &aback, &afwd);
if( post != nilobj ) BackEnd->PrintGraphicObject(post);
BackEnd->RestoreGraphicState();
}
}
else
y = FixAndPrintObject(y, xmk,xb,xf,dim,suppress,pg,count,&aback,&afwd);
*actual_back = xb; *actual_fwd = xf;
break;
case LINK_SOURCE:
case LINK_DEST:
case LINK_DEST_NULL:
case LINK_URL:
CountChild(y, LastDown(x), count);
if( dim == COLM )
save_mark(x) = xmk;
else
{ Child(z, Down(x));
switch( type(x) )
{
case LINK_SOURCE:
BackEnd->LinkSource(z, save_mark(x) - back(x, COLM),
(pg - xmk) - xf, save_mark(x) + fwd(x, COLM), (pg - xmk) + xb);
break;
case LINK_DEST:
case LINK_DEST_NULL:
BackEnd->LinkDest(z, save_mark(x) - back(x, COLM),
(pg - xmk) - xf, save_mark(x) + fwd(x, COLM), (pg - xmk) + xb);
break;
case LINK_URL:
BackEnd->LinkURL(z, save_mark(x) - back(x, COLM),
(pg - xmk) - xf, save_mark(x) + fwd(x, COLM), (pg - xmk) + xb);
break;
}
}
y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
*actual_back = xb; *actual_fwd = xf;
break;
case INCGRAPHIC:
case SINCGRAPHIC:
CountChild(y, Down(x), count);
if( BackEnd->incgraphic_avail )
{
if( dim == COLM )
{ save_mark(x) = xmk;
if( incgraphic_ok(x) )
{ debug2(DGP, DD, " %s (style %s)",
EchoObject(x), EchoStyle(&save_style(x)));
face = finfo[font(save_style(x))].original_face;
if( font_page(face) < font_curr_page )
{ debug3(DFT, DD, "FAPO-IG: x = %s, font = %d, face = %s",
string(x), font(save_style(x)), EchoObject(face));
FontPageUsed(face);
}
}
}
else if( incgraphic_ok(x) )
BackEnd->PrintGraphicInclude(x, save_mark(x), pg - xmk);
}
*actual_back = xb; *actual_fwd = xf;
break;
case SPLIT:
link = DownDim(x, dim); CountChild(y, link, count);
y = FixAndPrintObject(y, xmk, find_max(back(y, dim), xb),
find_max(fwd(y, dim), xf), dim, suppress, pg, count,
actual_back, actual_fwd);
break;
case VCAT:
case HCAT:
if( (type(x) == VCAT) == (dim == ROWM) )
{
debug6(DGP, DD, "[ FAPO-CAT %s (%s,%s): xmk %s, xb %s, xf %s",
Image(type(x)), EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
EchoLength(xmk), EchoLength(xb), EchoLength(xf));
FirstDefiniteLDN(x, link, prev, jn, xmk, dim, NO_SUPPRESS, pg);
if( link != x )
{
/*******************************************************************/
/* */
/* handle the special case of a 0rt gap at the beginning (left */
/* justify) by converting it to 0ie but increasing fwd(prev) to */
/* the maximum possible */
/* */
/*******************************************************************/
NextDefiniteWithGap(x, link, y, g, jn); /* not LDN since will redo */
if( link != x && mode(gap(g)) == TAB_MODE &&
units(gap(g)) == AVAIL_UNIT && width(gap(g)) == 0 )
{
debug2(DGP, DD, " FAPO-CAT converting 0rt (back(x, dim) %s, xb %s)",
EchoLength(back(x, dim)), EchoLength(xb));
/* NB state change here */
fwd(prev, dim) += xb - back(x, dim);
back(x, dim) = xb;
mode(gap(g)) = EDGE_MODE;
units(gap(g)) = FIXED_UNIT;
}
FirstDefinite(x, link, prev, jn); /* not LDN since already done */
/*******************************************************************/
/* */
/* Initialize the following variables: */
/* */
/* frame_size the total width actually available */
/* */
/* back_edge where the first element begins */
/* */
/* inc the adjust increment, used when adjusting gaps */
/* */
/* mk where the mark of prev is to go */
/* */
/*******************************************************************/
frame_size = back(x, dim) + xf;
back_edge = xmk - back(x, dim);
if( adjust_cat(x) && !suppress )
inc = FindAdjustIncrement(x, frame_size, dim);
else inc = 0;
mk = back_edge + back(prev, dim);
debug4(DGP, DD, " FAPO-CAT back_edge %s, mk %s, frame %s, inc %s",
EchoLength(back_edge), EchoLength(mk), EchoLength(frame_size),
EchoLength(inc));
/*******************************************************************/
/* */
/* Fix each element "prev" in turn along the cat operator */
/* */
/*******************************************************************/
NextDefiniteWithGapLDN(x, link, y, g, jn, mk, dim, NO_SUPPRESS, pg);
while( link != x )
{
if( mode(gap(g)) == TAB_MODE && units(gap(g)) == AVAIL_UNIT &&
width(gap(g))==FR )
{
/* object is followed by 1rt gap, give it full space to print */
debug5(DGP,D," FAPO (a) calling FAPO(%s, %s, %s, max(%s, %s))",
Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
EchoLength(fwd(prev, dim)), EchoLength(xmk+xf-mk-size(y,dim)));
prev = FixAndPrintObject(prev, mk, back(prev, dim),
find_max(fwd(prev, dim), xmk+xf-mk - size(y, dim)),
dim, NO_SUPPRESS, pg, count, &aback, &afwd);
}
else
{
debug5(DGP, DD, " FAPO-CAT (b) calling FAPO(%s, %s, %s, %s+%s)",
Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
EchoLength(fwd(prev, dim)), EchoLength(inc));
prev = FixAndPrintObject(prev, mk, back(prev, dim),
fwd(prev, dim) + inc, dim, NO_SUPPRESS, pg, count,&aback,&afwd);
}
mk += ActualGap(afwd, back(y, dim), fwd(y, dim), &gap(g),
frame_size, mk - back_edge);
prev = y;
NextDefiniteWithGapLDN(x, link, y, g, jn, mk, dim, NO_SUPPRESS, pg);
}
/*******************************************************************/
/* */
/* At end, fix last element in conformity with "suppress" */
/* and set *actual_back and *actual_fwd. */
/* */
/*******************************************************************/
if( suppress )
{
debug4(DGP, DD, " FAPO-CAT (c) calling FAPO(%s, %s, %s, %s)",
Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
EchoLength(fwd(prev, dim)));
prev = FixAndPrintObject(prev, mk, back(prev, dim), fwd(prev, dim),
dim, NO_SUPPRESS, pg, count, &aback, &afwd);
}
else
{
debug5(DGP, DD," FAPO-CAT (d) calls FAPO(%s, %s, %s, max(%s, %s))",
Image(type(prev)), EchoLength(mk), EchoLength(back(prev, dim)),
EchoLength(fwd(prev, dim)), EchoLength(xmk + xf - mk));
ifdebug(DGP, DD, DebugObject(prev));
prev = FixAndPrintObject(prev, mk, back(prev,dim),
find_max(fwd(prev, dim), xmk + xf - mk),
dim, NO_SUPPRESS, pg, count, &aback, &afwd);
}
*actual_back = find_max(back(x, dim), xb);
*actual_fwd = mk + fwd(prev, dim) - back_edge - *actual_back;
debugcond4(DGP, DD, type(x) == HCAT,
"HCAT original (%s, %s) to actual (%s, %s)",
EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
EchoLength(*actual_back), EchoLength(*actual_fwd));
}
else *actual_back = xb, *actual_fwd = xf;
debug0(DGP, DD, "] FAPO-CAT returning.");
}
else
{ OBJECT start_group, zlink, m; BOOLEAN dble_found;
FULL_LENGTH b, f, dlen;
start_group = nilobj; dble_found = FALSE; dlen = 0;
debug0(DGP, DD, " groups beginning.");
FirstDefiniteLDN(x, link, y, jn, xmk, dim, NO_SUPPRESS, pg);
if( link != x )
{
/* start first group, with or without join */
b = back(y, dim);
f = fwd(y, dim);
m = y;
start_group = link;
dble_found = !jn;
debug4(DGP, DD, " starting first group %s (%sdbl_found): b %s, f %s",
Image(type(y)), dble_found ? "" : "not ",
EchoLength(b), EchoLength(f));
NextDefiniteWithGapLDN(x, link, y, g, jn, xmk, dim, NO_SUPPRESS, pg);
while( link != x )
{
if( !jn )
{
/* finish off and fix the group ending just before g */
debug2(DGP, DD, " finishing group: b = %s, f = %s",
EchoLength(b), EchoLength(f));
m = FixAndPrintObject(m, xmk+b, b, xf-b, dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
b = back(m, dim); f = fwd(m, dim);
for( zlink = start_group; zlink != link; zlink=NextDown(zlink) )
{ CountChild(z, zlink, count);
if( !is_definite(type(z)) || z == m ) continue;
z = FixAndPrintObject(z, xmk + b, b, xf - b, dim,
SUPPRESS, pg, count, &aback, &afwd);
b = find_max(b, back(z, dim)); f = find_max(f, fwd(z, dim));
}
dlen = find_max(dlen, b + f);
dble_found = TRUE;
start_group = nilobj;
/* start new group */
b = back(y, dim);
f = fwd(y, dim);
m = y;
start_group = link;
debug2(DGP, DD, " starting group: b = %s, f = %s",
EchoLength(b), EchoLength(f));
}
else
{
/* continue with current group */
b = find_max(b, back(y, dim));
f = find_max(f, fwd(y, dim));
if( fwd(y, dim) > fwd(m, dim) ) m = y;
debug2(DGP, DD, " continuing group: b = %s, f = %s",
EchoLength(b), EchoLength(f));
}
NextDefiniteWithGapLDN(x, link, y, g, jn, xmk, dim, NO_SUPPRESS, pg);
}
assert( start_group != nilobj, "FAPO: final start_group!" );
if( dble_found || !jn )
{
/* finish off and fix this last group */
debug2(DGP, DD, " finishing last group: b = %s, f = %s",
EchoLength(b), EchoLength(f));
m = FixAndPrintObject(m, xmk+b, b, xf - b, dim, NO_SUPPRESS, pg,
count, &aback, &afwd);
b = back(m, dim); f = fwd(m, dim);
for( zlink = start_group; zlink != x; zlink = NextDown(zlink) )
{ CountChild(z, zlink, count);
if( !is_definite(type(z)) || z == m ) continue;
z = FixAndPrintObject(z, xmk+b, b, xf - b, dim, SUPPRESS, pg,
count, &aback, &afwd);
b = find_max(b, back(z, dim)); f = find_max(f, fwd(z, dim));
}
dlen = find_max(dlen, b + f);
*actual_back = 0; *actual_fwd = dlen;
}
else
{
/* finish off and fix this last and only group */
debug2(DGP, DD, " finishing last and only group: b = %s, f = %s",
EchoLength(b), EchoLength(f));
m = FixAndPrintObject(m, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&b, &f);
for( zlink = start_group; zlink != x; zlink = NextDown(zlink) )
{ CountChild(z, zlink, count);
if( !is_definite(type(z)) || z == m ) continue;
z = FixAndPrintObject(z, xmk, xb, xf, dim, SUPPRESS, pg, count,
&aback, &afwd);
b = find_max(b, aback); f = find_max(f, afwd);
}
*actual_back = b; *actual_fwd = f;
}
}
}
break;
case ACAT:
if( dim == COLM )
{ BOOLEAN will_adjust, adjusting;
FULL_LENGTH actual_size, adjust_indent, frame_size, back_edge;
FULL_LENGTH adjust_inc, inc = 0, adjust_sofar = 0;
int adjustable_gaps, gaps_sofar = 0;
BOOLEAN underlining; int underline_xstart = 0;
FONT_NUM underline_font = 0;
COLOUR_NUM underline_colour = 0;
TEXTURE_NUM underline_texture = 0;
OBJECT urec, last_bad_gap;
/*********************************************************************/
/* */
/* The first step is to calculate the following values: */
/* */
/* last_bad_gap The rightmost tab gap, or nilobj if none; */
/* */
/* adjustable_gaps the number of gaps suitable for adjustment; */
/* i.e. to the right of the right-most tab gap, */
/* and of non-zero width; */
/* */
/* actual_size the actual size of x without adjustment. */
/* */
/* These are needed when adjusting the line. */
/* */
/*********************************************************************/
FirstDefinite(x, link, y, jn); /* no LDN since this is initial pass */
if( link == x )
{
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
break; /* no definite children, nothing to print */
}
/*** nasty bug finder
{ OBJECT ff = y;
debugcond1(DGP, DD, word_equal(ff, "@ReportLayout"),
"FAPO(%s, COLM)", EchoObject(x));
debugcond1(DGP, DD, word_equal(ff, "@ReportLayout"),
" adjust_cat(x) = %s", bool(adjust_cat(x)));
}
***/
last_bad_gap = nilobj;
adjustable_gaps = 0;
back_edge = xmk - xb;
mk = back_edge + back(y, dim);
frame_size = xb + xf;
prev = y;
NextDefiniteWithGap(x, link, y, g, jn); /* no LDN, initial pass */
while( link != x )
{
save_actual_gap(g) = ActualGap(fwd(prev, dim), back(y, dim),
fwd(y, dim), &gap(g), frame_size, mk - back_edge);
mk += save_actual_gap(g);
if( mode(gap(g)) == TAB_MODE || units(gap(g)) == AVAIL_UNIT
|| units(gap(g)) == FRAME_UNIT )
{ last_bad_gap = g;
adjustable_gaps = 0;
}
else if( width(gap(g)) > 0 ) adjustable_gaps++;
prev = y;
NextDefiniteWithGap(x, link, y, g, jn); /* no LDN, initial pass */
}
actual_size = mk + fwd(prev, dim) - back_edge;
/*********************************************************************/
/* */
/* It is possible that the line cannot be displayed in any */
/* reasonable way, because the paragraph breaker was forced to */
/* produce an overfull line. In this case, actual_size will */
/* exceed frame_size and there will be no adjustable gaps. The */
/* solution is to horizontally scale the line if possible, or */
/* else to not print it at all. */
/* */
/*********************************************************************/
if( actual_size > frame_size && adjustable_gaps == 0 )
{
/* can't be fixed by adjustment, so scale the line or delete it */
CONSTRAINT c;
SetConstraint(c, 0, frame_size, frame_size);
fwd(x, dim) = actual_size;
debug2(DGP, DD, " oversize, actual_size = %s, frame_size = %s",
EchoLength(actual_size), EchoLength(frame_size));
if( BackEnd->scale_avail && InsertScale(x, &c) )
{
/* the problem has just been fixed, by inserting a @Scale above x */
OBJECT prnt;
Parent(prnt, Up(x));
Child(y, Down(x));
if( actual_size - frame_size < 1 * PT )
{
/* the correction is probably due to roundoff error, and */
/* anyway is too small to print an error message about */
}
else if( Down(x) == LastDown(x) && is_word(type(y)) )
{
Error(23, 3, "word %s horizontally scaled by factor %.2f (too wide for %s paragraph)",
WARN, &fpos(y), string(y), (float) bc(constraint(prnt)) / SF,
EchoLength(frame_size));
}
else
{
Error(23, 4, "%s object horizontally scaled by factor %.2f (too wide for %s paragraph)",
WARN, &fpos(x), EchoLength(size(x, COLM)),
(float) bc(constraint(prnt)) / SF, EchoLength(frame_size));
}
prnt = FixAndPrintObject(prnt, xmk, back(prnt, dim), fwd(prnt, dim), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
}
else
{
/* fix the problem by refraining from printing the line */
if( size(x, COLM) <= 0 )
Error(23, 5, "oversize object has size 0 or less", INTERN, &fpos(x));
Child(y, Down(x));
if( Down(x) == LastDown(x) && is_word(type(y)) )
{ Error(23, 6, "word %s deleted (too wide for %s paragraph)",
WARN, &fpos(y), string(y), EchoLength(frame_size));
}
else
{ Error(23, 7, "%s object deleted (too wide for %s paragraph)",
WARN, &fpos(x), EchoLength(size(x, COLM)), EchoLength(frame_size));
}
/* delete and dispose every child of x */
while( Down(x) != x )
DisposeChild(Down(x));
y = MakeWord(WORD, STR_EMPTY, &fpos(x));
Link(x, y);
back(y, COLM) = fwd(y, COLM) = 0;
back(y, ROWM) = fwd(y, ROWM) = 0;
}
}
else
{
/********************************************************************/
/* */
/* The line may be displayed in one of four ways: centred, right- */
/* justified, adjusted, or none of the above (i.e. left justified).*/
/* An overfull line is always adjusted; otherwise, the line will */
/* be centred or right justified if the display style asks for it; */
/* otherwise, the line will be adjusted if adjust_cat(x) == TRUE */
/* (i.e. there is an enclosing @PAdjust) or if the display style is*/
/* DO_ADJUST (meaning that this line is one of a paragraph set in */
/* the adjust or outdent break style, other than the last line); */
/* otherwise, the line is left justified. */
/* */
/* The second step is to decide which of these four cases holds */
/* for this line, and to record the decision in these variables: */
/* */
/* will_adjust TRUE if the adjusted style applies; in this */
/* case, variables adjust_inc and inc will be */
/* set to the appropriate adjustment value; */
/* */
/* adjust_indent If centring or right justification applies, */
/* the indent to produce this, else zero. */
/* */
/* NB adjust_inc may be negative, if the optimal paragraph breaker */
/* has chosen to shrink some gaps. */
/* */
/* NB we are assigning to adjust_cat here; is this a problem? */
/* */
/********************************************************************/
if( actual_size > frame_size )
{
assert( adjustable_gaps > 0, "FAPO: adjustable_gaps!" );
adjust_cat(x) = TRUE;
adjust_indent = 0;
}
else switch( display_style(save_style(x)) )
{
case DO_ADJUST: adjust_cat(x) = TRUE;
adjust_indent = 0;
debug1(DSF, D, "adjust %s", EchoObject(x));
break;
case DISPLAY_CENTRE: adjust_cat(x) = FALSE;
adjust_indent = (frame_size - actual_size)/2;
debug1(DGP, DD, "cdisp %s", EchoObject(x));
break;
case DISPLAY_RIGHT: adjust_cat(x) = FALSE;
adjust_indent = frame_size - actual_size;
debug1(DGP, DD, "rdisp %s", EchoObject(x));
debug1(DSF, D, "rdisp %s", EchoObject(x));
break;
default: /* leave adjust_cat(x) as is */
adjust_indent = 0;
break;
}
debug2(DGP, DD, "ACAT %s %s",
EchoStyle(&save_style(x)), EchoObject(x));
debug2(DGP, DD, "frame_size = %s, actual_size = %s",
EchoLength(frame_size), EchoLength(actual_size));
if( adjust_cat(x) && adjustable_gaps > 0 )
{ will_adjust = TRUE;
adjust_inc = (frame_size - actual_size) / adjustable_gaps;
inc = find_max(adjust_inc, 0);
gaps_sofar = 0; /* number of gaps adjusted so far */
adjust_sofar = 0; /* total width of adjustments so far */
debug2(DGP, DD,"will_adjust: adjustable_gaps = %d, adjust_inc = %s",
adjustable_gaps, EchoLength(adjust_inc));
}
else will_adjust = FALSE;
/********************************************************************/
/* */
/* The third and final step is to traverse x, fixing subobjects. */
/* Variable "adjusting" is true while adjusting is occurring. */
/* */
/********************************************************************/
underlining = FALSE;
adjusting = will_adjust && last_bad_gap == nilobj;
FirstDefiniteLDN(x, link, y, jn, xmk, dim, NO_SUPPRESS, pg);
prev = y;
mk = xmk - back(x, dim) + back(y, dim) + adjust_indent;
NextDefiniteWithGapLDN(x, link, y, g, jn, mk, dim, NO_SUPPRESS, pg);
while( link != x )
{
/* check for underlining */
if( underline(prev) == UNDER_ON )
{
debug3(DGP, D, " FAPO/ACAT1 underline() := %s for %s %s",
bool(FALSE), Image(type(prev)), EchoObject(prev));
if( !underlining )
{
/* underlining begins here */
underlining = TRUE;
debug2(DGP, DD, "underlining begins at %s %s",
Image(type(prev)), EchoObject(prev));
if( is_word(type(prev)) )
{
underline_font = word_font(prev);
underline_colour = word_colour(prev);
underline_texture = word_texture(prev);
}
else
{
underline_font = font(save_style(x));
underline_colour = colour(save_style(x));
underline_texture = texture(save_style(x));
}
underline_xstart = mk - back(prev, dim);
}
if( underline(g) == UNDER_OFF )
{
/* underlining ends here */
debug2(DGP, D, "underlining ends at %s %s",
Image(type(prev)), EchoObject(prev));
New(urec, UNDER_REC);
back(urec, COLM) = underline_xstart;
fwd(urec, COLM) = mk + fwd(prev, dim);
word_font(urec) = underline_font;
word_colour(urec) = underline_colour;
word_texture(urec) = underline_texture;
underlining = FALSE;
Link(Up(prev), urec);
}
}
/* fix previous definite now we know it is not the last one */
if( adjusting && width(gap(g)) > 0 )
{ int tmp;
prev = FixAndPrintObject(prev, mk, back(prev, dim),
fwd(prev, dim) + inc, dim, NO_SUPPRESS, pg, count,&aback,&afwd);
gaps_sofar++;
tmp = ((frame_size - actual_size) * gaps_sofar) / adjustable_gaps;
mk += save_actual_gap(g) + (tmp - adjust_sofar);
adjust_sofar = tmp;
}
else
{
prev = FixAndPrintObject(prev, mk, back(prev, dim), fwd(prev,dim),
dim, NO_SUPPRESS, pg, count, &aback, &afwd);
mk += save_actual_gap(g);
}
prev = y;
/* commence adjustment if required */
if( !adjusting && will_adjust && g == last_bad_gap )
adjusting = TRUE;
NextDefiniteWithGapLDN(x, link, y, g, jn, mk, dim, NO_SUPPRESS, pg);
}
/* check for underlining */
debugcond3(DGP, DD, underline(prev) == UNDER_UNDEF,
" underlining is UNDER_UNDEF in %s: %s %s in para:",
EchoFilePos(&fpos(prev)), Image(type(prev)), EchoObject(prev));
debugcond1(DGP, DD, underline(prev)==UNDER_UNDEF, "%s",EchoObject(x));
assert( underline(prev) == UNDER_OFF || underline(prev) == UNDER_ON,
"FixAndPrint: underline(prev)!" );
if( underline(prev) == UNDER_ON )
{
debug3(DGP, D, " FAPO/ACAT1 underline() := %s for %s %s",
bool(FALSE), Image(type(prev)), EchoObject(prev));
if( !underlining )
{
/* underlining begins here */
debug2(DGP, DD, "underlining begins at %s %s",
Image(type(prev)), EchoObject(prev));
underlining = TRUE;
if( is_word(type(prev)) )
{
underline_font = word_font(prev);
underline_colour = word_colour(prev);
underline_texture = word_texture(prev);
}
else
{
underline_font = font(save_style(x));
underline_colour = colour(save_style(x));
underline_texture = texture(save_style(x));
}
underline_xstart = mk - back(prev, dim);
}
/* underlining must end here */
debug2(DGP, DD, "underlining ends at %s %s",
Image(type(prev)), EchoObject(prev));
New(urec, UNDER_REC);
back(urec, COLM) = underline_xstart;
fwd(urec, COLM) = mk + fwd(prev, dim);
word_font(urec) = underline_font;
word_colour(urec) = underline_colour;
word_texture(urec) = underline_texture;
underlining = FALSE;
Link(Up(prev), urec);
}
/* fix the last definite subobject, prev, which must exist */
prev = FixAndPrintObject(prev, mk, back(prev, dim),
frame_size - (mk - xmk) - back(x, dim),
dim, NO_SUPPRESS, pg, count, &aback, &afwd);
}
}
else for( link = Down(x); link != x; link = NextDown(link) )
{ Child(y, link);
if( !is_definite(type(y)) && type(y) != LINK_DEST_NULL )
{
if( type(y) == UNDER_REC ) /* generate an underline now */
{ BackEnd->PrintUnderline(word_font(y),word_colour(y),
word_texture(y), back(y, COLM), fwd(y, COLM), pg - xmk);
link = PrevDown(link); /* remove all trace of underlining */
DisposeChild(Up(y)); /* in case we print this object again */
}
continue;
}
y = FixAndPrintObject(y, xmk, xb, xf, dim, NO_SUPPRESS, pg, count,
&aback, &afwd);
}
*actual_back = xb; *actual_fwd = xf;
break;
case COL_THR:
case ROW_THR:
assert( (type(x) == COL_THR) == (dim == COLM), "FixAndPrintObject: thr!" );
for( link = Down(x), uplink = Up(x), i = 1;
link != x && uplink != x && i < count;
link = NextDown(link), uplink = NextUp(uplink), i++ );
assert( link != x && uplink != x, "FixAndPrintObject: link or uplink!" );
CountChild(y, link, count);
debug7(DGP, DD, " fapo of %s (%s,%s) child %d %s (%s,%s)",
Image(type(x)),
EchoLength(back(x, dim)), EchoLength(fwd(x, dim)),
i, Image(type(y)), EchoLength(back(y, dim)), EchoLength(fwd(y, dim)));
/* This line seems to have been an optimization. It won't
* work if we are inside a running header, since subsequent
* passes will have forgotten the thread. JeffK 13/11/02
MoveLink(uplink, link, CHILD); DeleteLink(link);
*/
assert( type(y) != GAP_OBJ, "FAPO: THR!");
if( thr_state(x) != FINALSIZE )
{ back(x, dim) = xb; fwd(x, dim) = xf;
thr_state(x) = FINALSIZE;
}
y = FixAndPrintObject(y, xmk, back(x, dim), fwd(x, dim), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
*actual_back = xb; *actual_fwd = xf;
/* if( Up(x) == x ) Dispose(x); */
break;
/* convert everyone to FIXED_COL_THR or FIXED_ROW_THR as appropriate */
/* *** old code
if( thr_state(x) == FINALSIZE )
debug1(DGP, D, "thr_state(%d)", (int) x);
assert(thr_state(x) != FINALSIZE, "FAPO/COL_THR: thr_state(x)!");
ifdebug(DGP, D,
link = Down(x);
uplink = Up(x);
while( link != x && uplink != x )
{
Parent(tmp, uplink);
debug1(DGP, D, "parnt: %s", EchoObject(tmp));
Child(tmp, link);
debug1(DGP, D, "child: %s", EchoObject(tmp));
link = NextDown(link);
uplink = NextUp(uplink);
}
while( uplink != x )
{ Parent(tmp, uplink);
debug1(DGP, D, "extra parnt: %s", EchoObject(tmp));
uplink = NextUp(uplink);
}
while( link != x )
{ Child(tmp, link);
debug1(DGP, D, "extra child: %s", EchoObject(tmp));
link = NextDown(link);
}
)
i = 1; res = nilobj;
while( Down(x) != x && Up(x) != x )
{
New(fixed_thr, type(x) == COL_THR ? FIXED_COL_THR : FIXED_ROW_THR);
MoveLink(Up(x), fixed_thr, CHILD);
MoveLink(Down(x), fixed_thr, PARENT);
back(fixed_thr, dim) = xb;
fwd(fixed_thr, dim) = xf;
if( count == i )
res = fixed_thr;
i++;
}
if( Up(x) != x || Down(x) != x )
{
debug2(DGP, D, "links problem at %s %d:", Image(type(x)), (int) x);
if( Up(x) != x )
{
Parent(tmp, Up(x));
debug1(DGP, D, "first parent is %s", EchoObject(tmp));
}
if( Down(x) != x )
{
Child(tmp, Down(x));
debug1(DGP, D, "first child is %s", EchoObject(tmp));
}
}
assert( Up(x) == x && Down(x) == x, "FAPO/COL_THR: x links!" );
Dispose(x);
assert(res != nilobj, "FixAndPrintObject: COL_THR res!");
x = res;
*** */
/* NB NO BREAK! */
/* ***
case FIXED_COL_THR:
case FIXED_ROW_THR:
assert( (type(x) == FIXED_COL_THR) == (dim == COLM),
"FixAndPrintObject: fixed_thr!" );
CountChild(y, Down(x), count);
y = FixAndPrintObject(y, xmk, back(x, dim), fwd(x, dim), dim,
NO_SUPPRESS, pg, count, &aback, &afwd);
*actual_back = back(x, dim); *actual_fwd = fwd(x, dim);
break;
*** */
case BEGIN_HEADER:
case END_HEADER:
case SET_HEADER:
case CLEAR_HEADER:
if( dim == COLM )
Error(23, 8, "%s symbol ignored (out of place)", WARN, &fpos(x),
Image(type(x)));
break;
default:
assert1(FALSE, "FixAndPrintObject:", Image(type(x)));
break;
} /* end switch */
debug2(DGP, DD, "] FixAndPrintObject returning (actual %s,%s).",
EchoLength(*actual_back), EchoLength(*actual_fwd));
return res;
} /* end FixAndPrintObject */
|