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
|
%D \module
%D [ file=core-grd,
%D version=1998.03.10,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Grid Snapping (Experimental),
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\writestatus{loading}{Context Core Macros / Grid Snapping}
\unprotect
%D Moved from supp-box:
%D \macros
%D {startbaselinecorrection,baselinecorrection,
%D showbaselinecorrection,offbaselinecorrection}
%D
%D Spacing around ruled boxes can get pretty messed up. The
%D next macro tries as good as possible to fix this.
%D
%D \startbuffer[1]
%D \startbaselinecorrection
%D \ruledhbox{Rule Brittanica}
%D \stopbaselinecorrection
%D \stopbuffer
%D
%D \typebuffer[1]
%D
%D The macros put some white space around the box:
%D
%D \getbuffer[1]
%D
%D A simple alternative is \type {\baselinecorrection}, which
%D only looks at the previous line.
%D
%D \startbuffer[2]
%D \baselinecorrection
%D \ruledhbox{Rule Brittanica}
%D \baselinecorrection
%D \stopbuffer
%D
%D \typebuffer[2]
%D
%D This time the last preceding line gets a correction,%
%D dependant on the depth.
%D
%D \getbuffer[2]
%D
%D One can make the correction visible by saying \type
%D {\showbaselinecorrection}. Part of the correction is
%D calculated from the dimensions of a~(. One can disble the
%D correction by calling \type {\offbaselinecorrection}.
%D
%D When visualize the first example looks like:
%D
%D {\showbaselinecorrection\getbuffer[1]}
%D
%D and the second one comes out as:
%D
%D {\showbaselinecorrection\getbuffer[2]}
% \definecolor[GridLineColor][red]
% \definecolor[GridTextColor][blue]
\definepalet
[grid]
[ one=red,
two=green,
three=blue,
four=gray]
\def\setbaselinecorrections
{\setbox0\hbox{\setstrut\strut}%
\setbox2\hbox{(}%
\dimen0\ht0\advance\dimen0 -\ht2
\ifdim\dimen0<\zeropoint\dimen0\zeropoint\fi
\dimen2\dp0\advance\dimen2 -\dp2
\ifdim\dimen2<\zeropoint\dimen2\zeropoint\fi
\edef\thetopbaselinecorrection {\the\dimen0}\dimen0-\dimen0
\edef\thebotbaselinecorrection {\the\dimen2}\dimen2-\dimen2
\edef\thenegtopbaselinecorrection{\the\dimen0}%
\edef\thenegbotbaselinecorrection{\the\dimen2}}
\def\dotopbaselinecorrection {\kern\thetopbaselinecorrection}
\def\dobotbaselinecorrection {\kern\thebotbaselinecorrection}
\def\donegtopbaselinecorrection{\kern\thenegtopbaselinecorrection}
\def\donegbotbaselinecorrection{\kern\thenegbotbaselinecorrection}
\def\showbaselinecorrection
{\def\dobaselinecorrection % visualization is not watertight!
{\bgroup
\ifdim\prevdepth>\zeropoint\kern-\prevdepth\fi
\setbox0\null
\wd0\hsize
\dp0\strutdp
\nointerlineskip
\ruledvbox{\box0}%
\egroup
\prevdepth\strutdp}%
\def\dotopbaselinecorrection
{\hrule\!!height\thetopbaselinecorrection}%
\def\dobotbaselinecorrection
{\hrule\!!height\thebotbaselinecorrection}}
\def\dobaselinecorrection
{\ifdim\prevdepth>\zeropoint\kern-\prevdepth\fi
\kern\strutdp
\prevdepth\strutdp}
% \def\baselinecorrection
% {\endgraf
% \ifvmode
% \ifdim\prevdepth<\maxdimen
% \ifdim\prevdepth<\zeropoint \else
% \ifdim\prevdepth<\strutdp
% \dobaselinecorrection
% \fi
% \fi
% \fi
% \fi}
\def\baselinecorrection
{\endgraf
\ifvmode
\ifdim\prevdepth<\maxdimen
\ifdim\prevdepth<\zeropoint \else
\ifdim\prevdepth<\strutdepth \relax
\pushlastnode
\dobaselinecorrection
\poplastnode
\fi
\fi
\fi
\fi}
\def\pagebaselinecorrection
{\ifdim\pagegoal<\maxdimen
\ifdim\pagetotal>\lineheight % or \topskip
\scratchdimen\pagetotal
\advance\scratchdimen\lineheight
\ifdim\scratchdimen<\pagegoal
\baselinecorrection
\fi
\fi
\fi}
% Beware, keep this one as it is, see for instance module
% m-steps.tex, where we apply a \localhsize to the \vbox, in
% order to follow narrower and side floats !
\def\startbaselinecorrection
{\baselinecorrection
\ifvmode
\bgroup
\setbox\scratchbox\vbox\bgroup
\ignorespaces
\let\stopbaselinecorrection\dostopbaselinecorrection
\else
\let\stopbaselinecorrection\relax
\fi}
%D We do a bit more checking than needed. The pageborder check
%D is not needed, but I want to look the visualization as good
%D as possible too.
\def\dostopbaselinecorrection % I have to check columns yet.
{\endgraf
\egroup
\topbaselinecorrection
\box\scratchbox
\botbaselinecorrection
\egroup}
\let\stopbaselinecorrection=\relax
\def\offbaselinecorrection % Can be used inside correction.
{\def\startbaselinecorrection
{\bgroup\let\stopbaselinecorrection\egroup}}
%D \macros
%D {topbaselinecorrection,botbaselinecorrection}
%D
%D The actual top and bottom corrections are implemented as:
% \def\topbaselinecorrection
% {\ifvmode
% \bgroup
% \setbaselinecorrections
% \ifdim\pagegoal<\maxdimen
% \ifdim\pagetotal<\pagegoal
% \dimen2=\ht\scratchbox
% \advance\dimen2 \dp\scratchbox
% \advance\dimen2 \parskip
% \advance\dimen2 \thetopbaselinecorrection
% \advance\dimen2 \thebotbaselinecorrection
% \dimen0=\pagetotal
% \advance\dimen0 \dimen2
% % \ifdim\dimen0<\pagegoal % does more harm than good
% \witruimte
% \nointerlineskip
% \dotopbaselinecorrection
% % \else
% % \ifinsidecolumns
% % % \vskip\dimen2 % this could definitely
% % % \penalty\outputpenalty % be improved
% % \else
% % % %
% % % \vfill\eject % pretty old and wrong
% % %
% % % \nobreak % needed for headings
% % % \vskip\parskip % but often splits
% % % \vskip\dimen2 % normal paragraphs
% % % \penalty\outputpenalty % and therefore
% % % \vskip-\dimen2 % obsolete
% % %
% % % do nothing, sub optimal spacing after headings
% % % still to be sorted out; use manuals as test case
% % \fi
% % \fi
% \else % probably a preceding
% \witruimte % one-liner
% \nointerlineskip
% \dotopbaselinecorrection
% \fi
% \fi
% \egroup
% \fi}
\def\topbaselinecorrection
{\ifvmode \ifdim\pagegoal<\maxdimen
\bgroup
\setbaselinecorrections
\whitespace
\nointerlineskip
\dotopbaselinecorrection
\egroup
\fi \fi}
\def\botbaselinecorrection
{\ifvmode
\bgroup
\setbaselinecorrections
\dobotbaselinecorrection
\allowbreak % new, otherwise problems when many in a row
\prevdepth\strutdp
\egroup
\fi}
%D Still very experimental and therefore undocumented.
\newif\ifgridsnapping % UNDER DEVELOPMENT, USE WITH CARE
\newif\ifforcepresnap \forcepresnaptrue % false in mixed single/double
\newif\ifstrutsnapping \strutsnappingtrue % sometimes handy to be false
\def\positiveextrasnap {\gdef\extrasnapsign{+}}
\def\negativeextrasnap {\gdef\extrasnapsign{-}}
\def\extrasnapreset {\global\chardef\@@extrasnap0
\positiveextrasnap}
\def\extrasnapbefore {\global\chardef\@@extrasnap1 }
\def\extrasnaparound {\global\chardef\@@extrasnap2 }
\def\extrasnapafter {\global\chardef\@@extrasnap3 }
\def\enablepresnapcorrection {\global\chardef\@@presnap\zerocount}
\def\disablepresnapcorrection {\global\chardef\@@presnap\plusone}
\extrasnapreset \enablepresnapcorrection
\newif\iftracegridsnapping
\newif\ifshowgridboxes
\newif\ifshowfuzzyskips
\let\showgridboxes\showgridboxestrue
\def\showgridsnapping
{\tracegridsnappingtrue
\showgridboxestrue}
\chardef\@@alignsnap =0
\chardef\@@alignsnapbox =0
\chardef\@@alignsnapmethod=0
\let\presnapskip \!!zeropoint \def\presnap {-}
\let\postsnapskip\!!zeropoint \let\postsnap\presnap
\def\tracedsnapping
{\iftracegridsnapping
\llap
{\startlayoutcomponent{gridsnaps}{grid snaps}%
\infofont
\doglobal\increment\currentsnap
\color[grid:three]{\vl\presnapskip
\vl\presnap
\vl\postsnap
\ifcase\@@alignsnapbox\relax
\vl\ifcase\@@extrasnap
00\or
\extrasnapsign0\or
\extrasnapsign\extrasnapsign\or
0\extrasnapsign\fi
\fi
\vl\currentsnap\vl}%
\stoplayoutcomponent}%
\fi}
\def\snaptogrid% [#1]#2 -> #2 == \hbox|\vbox
{\dosingleempty\dosnaptogrid}
% \def\dosnaptogrid[#1]%
% {\ifgridsnapping
% \iffirstargument\doifsomething{#1}{\verplaatsopgrid[#1]}\fi
% \expandafter\dodosnaptogrid
% \fi}
\def\dosnaptogrid[#1]%
{\resetlastlinewidth % maybe in more places, otherwise spacing gets messed up
\ifgridsnapping
\iffirstargument\doifsomething{#1}{\moveongrid[#1]}\fi
\expandafter\dodosnaptogrid
\fi}
% \def\forcedpresnapcorrection % test this on 'details'
% {\ifforcepresnap
% \ifvmode \else \par \fi % new
% % we don't want top of page space when 'top' option
% %\verticalstrut\nobreak\vskip-\struttotal
% %\verticalstrut\vskip-\struttotal
% % nobreak really needed
% \allowbreak\verticalstrut\nobreak\vskip-\struttotal
% %\ifdim\pagetotal>\topskip \else
% % eigenlijk signal
% %\writestatus{grid}{removing dummy at top of page}%
% %\bgroup
% %\output{\setbox\scratchbox\box255}%
% %\penalty\outputpenalty
% %\egroup
% %\fi
% \fi}
\def\forcedpresnapcorrection % test this on 'details'
{\ifforcepresnap
\ifvmode \else \par \fi % new
% we don't want top of page space when 'top' option
%\verticalstrut\nobreak\vskip-\struttotal
%\verticalstrut\vskip-\struttotal
% nobreak really needed
\dosomebreak\allowbreak\verticalstrut\nobreak\vskip-\struttotal % new: \dosomebreak
%\ifdim\pagetotal>\topskip \else
% eigenlijk signal
%\writestatus{grid}{removing dummy at top of page}%
%\bgroup
%\output{\setbox\scratchbox\box255}%
%\penalty\outputpenalty
%\egroup
%\fi
\fi}
\def\setgridtracebox#1[#2]% % maybe reverse the order
{\setbox\nextbox#1%
{\hbox
{\hbox to \zeropoint
{\startlayoutcomponent{gridsnaps}{grid snaps}%
\color[grid:#2]{\ruledhbox{\fakebox\nextbox}}%
\stoplayoutcomponent
\hss}%
\flushnextbox}}}
\newif\ifboxedsnapping \boxedsnappingtrue
\chardef\depthsnapmethod \plusone % downward compatible, minus one line
\chardef\heightsnapmethod\plusone % downward compatible, minus one line
\def\dodosnaptogrid
{\dowithnextbox
{\bgroup
\ifcase\@@alignsnapmethod \or
% we're dealing with text with a possible big depth/height
\chardef\depthsnapmethod \plustwo
\chardef\heightsnapmethod\plustwo
\fi
\ifdim\nextboxht<\textheight % handle special case (like page fig)
\ifcase\@@alignsnapbox\relax
\ifcase\@@alignsnap\else % 1=top 2=high 3=middle 4=low
\ifshowgridboxes
\setgridtracebox\hbox[two]%
\fi
%\getnoflines{\nextboxht}%
\getnoflines\nextboxht
\setbox\nextbox\vbox to \noflines\lineheight
{\ifnum\@@alignsnap=1 \kern\lineheight\kern-\topskip\fi
\ifnum\@@alignsnap>2 \vfill\fi
\flushnextbox
\ifnum\@@alignsnap<4 \vfill\fi}%
\fi
\ifshowgridboxes
\setgridtracebox\hbox[three]%
\fi
\forgetall
\par
\ifvbox\nextbox
\setbox\nextbox\hbox{\flushnextbox}% don't ask
\fi
\scratchskip\lastskip
\edef\presnapskip{\the\lastskip}%
% mixing single/double columns sometimes goes wrong,
% check 'som' document
\ifinsidecolumns
\forcepresnaptrue
\fi
\forcedpresnapcorrection
\ifdim\nextboxht>\strutht
\scratchdimen\nextboxht
\ifcase\@@presnap\relax
\ifdim\scratchskip>\zeropoint\relax
\scratchcounter\scratchskip
\advance\scratchcounter -\openlineheight
\ifnum\scratchcounter<0
\scratchcounter-\scratchcounter
\fi
\ifnum\scratchcounter<10 % \lastkip is about \openlineheight
\advance\scratchdimen -\openstrutdepth
\edef\presnapskip{*\presnapskip}%
\else\ifdim\scratchskip>\openlineheight
%<\openlineheight \else
\advance\scratchdimen -\openstrutdepth
\edef\presnapskip{*\presnapskip}%
\fi\fi
\fi
\fi
% \getnoflines\scratchdimen % maybe raw ?
% \advance\noflines -1
\ifcase\heightsnapmethod
% raw
\or
\advance\scratchdimen-\lineheight % tight (default)
\or
\advance\scratchdimen-\strutheight % fit (text)
\or
\advance\scratchdimen-\strutheight % tolerant
\advance\scratchdimen-\roundingeps
\fi
\getnoflines\scratchdimen
\ifnum\noflines>0
\scratchdimen\noflines\lineheight
\else
\scratchdimen\zeropoint
\fi
\else
\scratchdimen\zeropoint
\fi
\ifnum\@@extrasnap=1 \advance\scratchdimen \extrasnapsign \lineheight \fi
\ifnum\@@extrasnap=2 \advance\scratchdimen \extrasnapsign.5\lineheight \fi
\edef\presnap{\the\scratchdimen}%
\ifstrutsnapping
\ifboxedsnapping
\getrawnoflines\scratchdimen
\advance\scratchdimen-\noflines\lineheight
\vskip\scratchdimen % disappears at top of page
\dorecurse\noflines{\verticalstrut\nobreak}%
\else \ifdim\scratchdimen=\zeropoint
% nothing to skip
\else % disappears at top of page
\vskip\scratchdimen
\fi \fi
\fi
\ifdim\nextboxdp>\strutdp
% \getnoflines\nextboxdp
% \advance\noflines \minusone
\scratchdimen\nextboxdp\relax
\ifcase\depthsnapmethod
% raw
\or
\advance\scratchdimen-\lineheight % tight (default)
\or
\advance\scratchdimen-\strutdepth % fit (text)
\or
\advance\scratchdimen-\strutdepth % tolerant
\advance\scratchdimen-\roundingeps
\fi
\getnoflines\scratchdimen
\ifnum\noflines>0
\scratchdimen\noflines\lineheight
\else
\scratchdimen\zeropoint
\fi
\else
\scratchdimen\zeropoint
\fi
\ifnum\@@extrasnap=2 \advance\scratchdimen \extrasnapsign.5\lineheight \fi
\ifnum\@@extrasnap=3 \advance\scratchdimen \extrasnapsign \lineheight \fi
\edef\postsnap{\the\scratchdimen}%
\ifstrutsnapping
\nextboxht\strutht
\nextboxdp\strutdp
\else
\scratchdimen\presnap
\advance\scratchdimen \strutht
\nextboxht\scratchdimen
\scratchdimen\postsnap
\advance\scratchdimen \strutdp
\nextboxdp\scratchdimen
\fi
\hbox{\tracedsnapping\flushnextbox}%
\ifstrutsnapping
\ifdim\scratchdimen=\zeropoint\else\vskip\scratchdimen\fi
\fi
\else
\scratchdimen\nextboxht\relax
\ifcase\@@alignsnapbox
% can't happen here
\or
\getrawnoflines\scratchdimen
\else
\getnoflines \scratchdimen
\fi
\scratchdimen\noflines\lineheight\relax
\advance\scratchdimen-\strutdepth
% spoils the whole game (fit/broad/line)
% \ifnum\pagetotal>\zeropoint \else % disable this as option
% \advance\scratchdimen-\strutheight
% \advance\scratchdimen+\topskip
% \fi
\dimen0=\scratchdimen
\dimen2=\strutdepth
\ifshowgridboxes
\setgridtracebox\hbox[two]%
\fi
\nextboxdp\strutdp
\dimen4=\nextboxht
\dimen6=\nextboxdp
\iftracegridsnapping
\setbox\scratchbox\hbox
{\scratchdimen\@@alignsnapamount\relax
\ifdim\scratchdimen<\zeropoint
\tracedgridamount\zeropoint{-\scratchdimen}%
\else
\tracedgridamount\scratchdimen\zeropoint
\fi}%
\smashbox\scratchbox
\setbox\nextbox\hbox{\box\scratchbox\flushnextbox}%
\fi
\setbox\nextbox\hbox
{\scratchdimen\@@alignsnapamount\relax
\ifcase\@@alignsnapdepth\or
% don't change this ever !
\ifdim\dimen0<\lineheight
% otherwise it is ok, but ending up inside
% the next paragraph is seldom what we want,
% so we move one line up
\advance\scratchdimen-\lineheight
\advance\scratchdimen\strutheight
\else
% otherwise we can move down to the
% baseline
\advance\scratchdimen\dimen6 % == \strutdepth
\fi
\fi
\lower\scratchdimen\flushnextbox}%
\nextboxht\dimen4
\nextboxdp\dimen6
\ifnum\@@alignsnap<4 % 4 = regel
\setbox\nextbox\vbox to \scratchdimen
{\forgetall
\ifnum\@@alignsnap>2 \vfill\fi % 3 4
\flushnextbox
\nointerlineskip % \offinterlineskip
\ifnum\@@alignsnap<4 \vfill\fi % 2 3
\kern\zeropoint}%
\fi
\ifshowgridboxes
\setgridtracebox\vbox[three]%
\fi
\scratchdimen\@@alignsnapamount
\edef\presnapskip{\the\scratchdimen}%
\ifnum\@@alignsnap>2 \def\presnap {+}\fi
\ifnum\@@alignsnap<4 \def\postsnap{+}\fi
\setbox\nextbox\hbox{\tracedsnapping\flushnextbox}%
\par
\nextboxht\dimen0
\nextboxdp\dimen2
\forcedpresnapcorrection
\nointerlineskip
\flushnextbox
\fi
\else
\setbox\nextbox\vbox to \textheight
{\ifdim\nextboxdp=\zeropoint
\hbox{\lower\strutdepth\flushnextbox}
\else % this branch is yet untested
\vss
\hbox{\lower\nextboxdp\flushnextbox}
\vskip-\strutdepth
\fi}%
\nextboxdp\strutdepth
\flushnextbox
\fi
\extrasnapreset
\enablepresnapcorrection
\global\chardef\@@alignsnap\zerocount
\global\chardef\@@alignsnapbox\zerocount
\egroup}}
\def\tracedgridamount#1#2%
{\startlayoutcomponent{gridsnaps}{grid snaps}%
\color[grid:four]{\vrule\!!width\nextboxwd\!!height#1\!!depth#2}%
\stoplayoutcomponent}
\def\snaptomathgrid % probably not working ok, also kind of obsolete
{\ifgridsnapping
\dowithnextbox
{\blank[\v!line]\snaptogrid\vbox{\flushnextbox}\blank[\v!line]}
\vbox\bgroup
\let\setdisplayskips\relax
\abovedisplayskip\zeropoint
\abovedisplayshortskip\zeropoint
\belowdisplayskip\zeropoint
\belowdisplayshortskip\zeropoint
\@EA\let\@EA\next
\fi}
\def\topsnaptogrid
{\ifgridsnapping
\dowithnextbox
{\scratchdimen\nextboxht
\advance\scratchdimen -\strutht
\advance\scratchdimen \topskip
\nextboxht\scratchdimen
\nextboxdp\zeropoint
\flushnextbox
\kern\lineheight
\kern-\topskip
\nointerlineskip}
\hbox
\fi}
% \def\centertogrid % meant for special situations
% {\ifgridsnapping
% \dowithnextboxcontent
% {\ignorespaces}
% {\bgroup
% \par
% \scratchdimen\nextboxht
% \advance\scratchdimen \nextboxdp
% \getnoflines\scratchdimen
% \setbox\nextbox\vbox to \noflines\lineheight
% {\forgetall
% \vskip\zeropoint \!!plus \nextboxht
% \copy\nextbox
% \kern.5\strutdp % VOORLOPIGE WAARDE
% \vskip\zeropoint \!!plus \nextboxdp}%
% \noindent\snaptogrid\vbox{\flushnextbox}%
% \egroup}
% \vbox % was \hbox
% \fi}
% The next implementation is sub-optimal
%
% \def\centertogrid % usage: see ie pascal / stepcharts
% {\snaptogrid[\v!midden,.5\strutdp]\vbox}
\def\centertogrid % meant for special situations
{\ifgridsnapping
\dowithnextboxcontent
{\ignorespaces}
{\bgroup
\par
\scratchdimen\nextboxht
\advance\scratchdimen \nextboxdp
\getnoflines\scratchdimen
\setbox\nextbox\vbox to \noflines\lineheight
{\forgetall
\vss
\topbaselinecorrection
\copy\nextbox
\botbaselinecorrection
\vss}%
\setbox\nextbox\hbox{\lower\strutdp\flushnextbox}%
\noindent\snaptogrid\vbox{\flushnextbox}%
\egroup}
\vbox % was \hbox
\fi}
% testbed for \centertogrid
%
% \strut Bruggetje
% \startlinecorrection
% \startcombination
% {\framed{test}} {} {\framed{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection
% \startcombination[2*2]
% {\framed{test}} {} {\framed{test}} {}
% {\framed{test}} {} {\framed{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection[blank]
% \startcombination
% {\framed{test}} {} {\framed{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection[blank]
% \startcombination[2*2]
% {\framed{test}} {} {\framed{test}} {}
% {\framed{test}} {} {\framed{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection
% \startcombination
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection
% \startcombination[2*2]
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection[blank]
% \startcombination
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% \stopcombination
% \stoplinecorrection
% \strut Bruggetje
% \startlinecorrection[blank]
% \startcombination[2*2]
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% {\framed[lines=1]{test}} {} {\framed[lines=1]{test}} {}
% \stopcombination
% \stoplinecorrection
\ifx\startbaselinecorrection\undefined \wait \fi % change order
\let\normalstartbaselinecorrection=\startbaselinecorrection
\def\startbaselinecorrection
{\ifgridsnapping
\centertogrid\bgroup
\let\stopbaselinecorrection\egroup
\else
\normalstartbaselinecorrection
\fi}
\def\setgridbox#1#2#3%
{\setbox#1\ruledvbox to #3 % given size
{\forgetall
\resetteststrut
\offinterlineskip
\hsize#2%
\baselinerulefalse
\ruledvbox % calculated size
{\getrawnoflines{#3}% \getnoflines{#3}%
\vskip\topskip
\vskip-\strutht
\scratchdimen#2\advance\scratchdimen \lineheight
\dorecurse\noflines
{\strut
\hskip-.5\lineheight
\rlap
{\hskip\scratchdimen
\hskip2pt\infofont
\hbox to 1em{\hss\recurselevel}}%
\vrule
\!!height .5\testrulewidth
\!!depth .5\testrulewidth
\!!width \scratchdimen
\par}}
\vfill}}
%D Some intervention macros:
\def\gridwarning#1{\message{[beware of #1 extra snap]}}
\global\let\@@alignsnapamount\!!zeropoint
\global\chardef\@@alignsnapdepth0
\def\@@unknowngriddisplacement
{\global\chardef\@@alignsnapbox3
\global\let\@@alignsnapamount\commalistelement}
\def\domoveongrid[#1]%
{\ifgridsnapping\doifsomething{#1}{\dodomoveongrid[#1]}\fi}
\def\dodomoveongrid[#1]% some day : speed up
{\global\chardef\@@alignsnap\zerocount
\global\chardef\@@alignsnapbox\zerocount
\global\chardef\@@alignsnapdepth\zerocount
\global\chardef\@@alignsnapmethod\zerocount
\global\let\@@alignsnapamount\!!zeropoint
\donefalse
\expanded{\processallactionsinset[#1]}
[\v!standard=>,
\v!normal=>, % to be sure
\v!yes=>, % to be sure
\v!top=>\gridwarning+\positiveextrasnap\extrasnapbefore,
\v!bottom=>\gridwarning+\positiveextrasnap\extrasnapafter,
\v!both=>\positiveextrasnap\extrasnaparound,
-\v!top=>\gridwarning-\negativeextrasnap\extrasnapbefore,
-\v!bottom=>\gridwarning-\negativeextrasnap\extrasnapafter,
-\v!both=>\negativeextrasnap\extrasnaparound,
\v!text=>\global\chardef\@@alignsnapmethod\plusone, % accurate calculations
\v!page=>\global\chardef\@@alignsnap1, % topskip
\v!high=>\global\chardef\@@alignsnap2,
\v!middle=>\global\chardef\@@alignsnap3,
\v!low=>\global\chardef\@@alignsnap4,
\v!fit=>\global\chardef\@@alignsnapbox1, % new
\v!broad=>\global\chardef\@@alignsnapbox2, % new
\v!depth=>\global\chardef\@@alignsnapdepth1, % new
\v!line=>\global\chardef\@@alignsnapbox3
% \global\chardef\@@alignsnapdepth1
\global\chardef\@@alignsnap4,
\v!reset=>\positiveextrasnap\extrasnapreset,
\v!none=>\global\chardef\@@alignsnap0
\global\chardef\@@alignsnapbox0,
\s!default=>,
\s!unknown=>\@@unknowngriddisplacement]}
\def\moveongrid
{\dosingleempty\domoveongrid}
\def\doplaceongrid[#1]%
{\domoveongrid[#1]\snaptogrid\vbox}
\def\placeongrid
{\dosingleempty\doplaceongrid}
%D Snapping is rather robust as long as we use whole lines.
%D Half lines of white space can however be handled when they
%D come in pairs. The corrections needed when crossing page
%D boundaries in the middle of such a pair, are handled by
%D macros that are (named) sort of fuzzy. This fuzzy mechanism
%D was written as an extension to the grid typesetting needed
%D for typesetting (part of) the \MAPS.
%D
%D \starttyping
%D \setuptyping
%D [before={\blank[halfline]},
%D after={\blank[halfline]}]
%D \stoptyping
\newif\iffuzzysnapdone
\newif\iffuzzysnapping
\newif\iffuzzysnapped
\chardef\fuzzysnappedleft=0 % ==1 when fuzzybegin still open
\newpersistentmark\fuzzymark % (!)
\newcount\fuzzymarker
\newbox\fuzzysnapbox
\newbox\fuzzysnapsplit
%\def\dosyncfuzzyvskip
% {\ifvmode\ifdim\lastskip<\lineheight\ifdim\lastskip>\zeropoint
% \bgroup
% \endgraf
% \forgetall
% \verticalstrut
% \kern-\struttotal
% \kern-\lineheight
% \nobreak
% \vskip\lineheight
% \egroup
% \fi\fi\fi}
%\def\fuzzyvskip#1%
% {\iffuzzysnapdone
% \endfuzzysnapping
% \vskip#1\relax
% \dosyncfuzzyvskip % NEW
% \global\fuzzysnapdonefalse
% \else
% \vskip#1\relax
% \beginfuzzysnapping
% \global\fuzzysnapdonetrue
% \fi}
\def\dosyncfuzzyvskip
{\ifvmode\ifdim\lastskip<\lineheight\ifdim\lastskip>\zeropoint
\bgroup % - added 28/2/2003: check this, there was no -
\endgraf\forgetall\verticalstrut\nobreak\vskip-\struttotal
\egroup
\fi\fi\fi}
\def\fuzzyvskip#1%
{\iffuzzysnapdone
\dosyncfuzzyvskip % NEWER
\endfuzzysnapping
\vskip#1\relax
\global\fuzzysnapdonefalse
\else
\vskip#1\relax
\beginfuzzysnapping
\global\fuzzysnapdonetrue
\fi}
\def\setfuzzymark#1#2#3% #1/#2 => error recovery
{\ifgridsnapping
\global\fuzzysnappingtrue
\global\advance\fuzzymarker \ifodd\fuzzymarker#1\else#2\fi
\nobreak
\ifshowfuzzyskips
\hbox{\color[grid:three]
{\llap{\infofont#3\vl\the\fuzzymarker}\nobreak
\vrule\!!width\hsize\!!height.1\lineheight}}
\nobreak
\fi
%[\the\fuzzymarker]
%\expandafter\fuzzymark\expandafter{\the\fuzzymarker}%
\expandafter\rawsetmark\expandafter\fuzzymark\expandafter{\the\fuzzymarker}%
\nobreak
\fi}
\def\beginfuzzysnapping{\setfuzzymark21\v!start} % odd
\def\endfuzzysnapping {\setfuzzymark12\v!stop } % even
\def\removelastfuzzyvskip
{\ifgridsnapping
\iffuzzysnapping
\ifdim\lastskip<\openlineheight
\else
\removelastskip
\fi
\else
\removelastskip
\fi
\else
\removelastskip
\fi}
\def\docheckfuzzysnap#1%
{\bgroup
\dontcomplain
\setbox\fuzzysnapbox\copy#1\relax
\setbox\fuzzysnapsplit\vsplit\fuzzysnapbox to 1\lineheight
\let\topfuzzymark\empty % indeed here ... no real mark
\getsplitmarks\fuzzymark
% \ifcase0\topfuzzymark
\ifcase0\rawgetsplittopmark\fuzzymark
\global\chardef\fuzzysnappedleft\zerocount
\global\fuzzysnappedfalse
% \else\ifodd\topfuzzymark
\else\ifodd\rawgetsplittopmark\fuzzymark
\global\chardef\fuzzysnappedleft\plusone
\global\fuzzysnappedtrue
\else
\global\chardef\fuzzysnappedleft=2
\global\fuzzysnappedtrue
\fi\fi
\iffuzzysnapped \else
\doloop
{\ifvoid\fuzzysnapbox
\exitloop
\else
\setbox\fuzzysnapsplit=\vsplit\fuzzysnapbox to \lineheight
%\let\topfuzzymark=\empty % ... but not here
\getsplitmarks\fuzzymark
% \ifcase0\topfuzzymark
\ifcase0\rawgetsplittopmark\fuzzymark
% continue
% \else\ifodd\topfuzzymark
\else\ifodd\rawgetsplittopmark\fuzzymark
\exitloop
\else
\global\chardef\fuzzysnappedleft\plusone
\global\fuzzysnappedtrue
\exitloop
\fi\fi
\fi}%
\fi
\egroup}
\def\getfuzzysnapcorrection#1%
{\global\let\presnapcorrection \relax
\global\let\postsnapcorrection\relax
\ifgridsnapping\iffuzzysnapping
\docheckfuzzysnap{#1}%
\iffuzzysnapped
\iftracegridsnapping
\gdef\presnapcorrection
{\color[grid:four]{\hrule\!!height.5\openlineheight\!!width\hsize}}%
\else
\gdef\presnapcorrection{\kern.5\openlineheight}%
\fi
\gdef\postsnapcorrection{\kern-.5\openlineheight}% get the height ok
\fi
\fi\fi}
\def\fuzzysnappedbox#1#2% \box<n> \unvbox<n>
{\getfuzzysnapcorrection{#2}%
\presnapcorrection
#1#2%
\postsnapcorrection}
\def\adaptfuzzypagegoal
{\ifgridsnapping\iffuzzysnapping\ifcase\fuzzysnappedleft\or % see dopagecontents
\scratchdimen\pagegoal
\advance\scratchdimen -.5\openlineheight
\global\pagegoal\scratchdimen
\global\advance\vsize -.5\openlineheight
\global\chardef\fuzzysnappedleft0
\fi\fi\fi}
%D New, experimental, used in caption snapping:
%D
%D \starttyping
%D \startcolumnset
%D
%D \setupcaption[figure][style=\tfx\setupinterlinespace,inbetween=,grid=top]
%D
%D \placefigure [lrtb] {\dorecurse{5}{green gras}}
%D {\externalfigure[dummy][width=\textwidth,height=3cm,grid=height]}
%D \placefigure [lrtb] {\dorecurse{15}{green gras}}
%D {\externalfigure[dummy][width=\textwidth,height=3cm,grid=height]}
%D
%D \setupcaption[figure][style=\tfx\setupinterlinespace,inbetween=,grid=bottom]
%D
%D \placefigure [rltb] {\dorecurse{5}{green gras}}
%D {\externalfigure[dummy][width=\textwidth,height=3cm,grid=height]}
%D \placefigure [rltb] {\dorecurse{15}{green gras}}
%D {\externalfigure[dummy][width=\textwidth,height=3cm,grid=height]}
%D
%D \input thuan
%D
%D \stopcolumnset
%D \stoptyping
\def\moveboxontogrid#1#2#3% box method firstlineht % experimental ! ! !
{\doifsomething{#2}
{\getnoflines{\ht#1}% no depth taken into account, depth preserved
\scratchdimen\noflines\lineheight
\advance\scratchdimen-\strutdp
\bgroup
\advance\scratchdimen-\onepoint % be a bit tolerant
\ifdim\scratchdimen>\ht#1\relax
\egroup
\doif{#2}\v!top {\setbox#1\vbox to \scratchdimen{\vskip-#3\vskip\strutht\box#1\vfill}}%
\doif{#2}\v!bottom{\setbox#1\vbox to \scratchdimen{\vfill\box#1\removedepth}}%
\dp#1\strutdp
\else
\egroup
\ht#1\scratchdimen
\dp#1\strutdp
\fi}}
%D New:
\let\checkgridsnapping\relax
\protect \endinput
|