1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Packaging Macros More Rules}
15
16
17
18\unprotect
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37\installcorenamespace{blackrules}
38
39\installsimplecommandhandler \??blackrules {blackrules} \??blackrules
40
41\permanent\protected\def\blackrule
42 {
43 \begingroup
44 \doifelsenextoptionalcs\pack_black_rule_pickup\pack_black_rule_indeed}
45
46\def\pack_black_rule_pickup[#S#1]
47 {\setupcurrentblackrules[#1]
48 \pack_black_rule_indeed}
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70\def\pack_black_rule_indeed
71 {\edef\p_width {\directblackrulesparameter\c!width}
72 \edef\p_height {\directblackrulesparameter\c!height}
73 \edef\p_depth {\directblackrulesparameter\c!depth}
74 \edef\p_stretch{\directblackrulesparameter\c!stretch}
75 \edef\p_shrink {\directblackrulesparameter\c!shrink}
76 \ifx\p_height\v!max
77 \setstrut
78 \let\p_height\strutdp
79 \orelse\ifx\p_depth\v!max
80 \setstrut
81 \fi
82
83
84
85 \ifx\p_depth\v!max
86 \let\p_depth\strutdp
87 \fi
88 \ifx\p_width\v!max
89 \let\p_width\emwidth
90 \fi
91 \useblackrulesstyleandcolor\c!style\c!color
92 \ifempty\p_stretch
93 \ifempty\p_shrink
94 \donefalse
95 \else
96 \donetrue
97 \leaders
98 \fi
99 \else
100 \donetrue
101 \leaders
102 \fi
103 \ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
104 \lastnamedcs
105 \else
106 \vrule
107 \fi
108 \ifempty\p_height\else\s!height\p_height\fi
109 \ifempty\p_depth\else\s!depth\p_depth\fi
110 \ifdone
111 \hskip\ifempty\p_width\zeropoint\else\p_width\fi
112 \ifempty\p_stretch\else\s!plus\p_stretch\fi
113 \ifempty\p_shrink\else\s!minus\p_shrink\fi
114 \else
115 \ifempty\p_width\else\s!width\p_width\fi
116 \fi
117 \endgroup}
118
119\setupblackrules
120 [\c!width=\emwidth,
121 \c!height=\exheight,
122 \c!depth=\zeropoint,
123 \c!color=]
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\permanent\tolerant\protected\def\blackrules[#S#1]
152 {\hpack\bgroup
153 \ifarguments\or\setupcurrentblackrules[#1]\fi
154 \scratchwidth \directblackrulesparameter\c!width
155 \scratchheight \directblackrulesparameter\c!height
156 \scratchdepth \directblackrulesparameter\c!depth
157 \scratchdistance\directblackrulesparameter\c!distance
158 \scratchcounter \directblackrulesparameter\c!n
159 \edef\p_alternative{\blackrulesparameter\c!alternative}
160 \ifx\p_alternative\c!b
161 \ifnum\scratchcounter=\plusone
162 \scratchdistance\zeropoint
163 \else
164 \scratchwidth\dimexpr(\scratchwidth\scratchcounter\scratchdistance\scratchdistance)\scratchcounter\relax
165 \fi
166 \fi
167 \useblackrulesstyleandcolor\c!style\c!color
168
169 \dorecurse\scratchcounter\pack_black_rules_step
170 \unskip
171 \egroup}
172
173\def\pack_black_rules_step
174 {\ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
175 \lastnamedcs
176 \else
177 \vrule
178 \fi
179 \s!width \scratchwidth
180 \s!height\scratchheight
181 \s!depth \scratchdepth
182 \relax
183 \ifzeropt\scratchdistance\else
184 \kern\scratchdistance
185 \fi}
186
187\installcorenamespace{blackruletype}
188
189\defcsname\??blackruletype mp\endcsname
190 {\frule
191 type {mp}
192 data {\includeMPgraphic{\directblackrulesparameter\c!mp}}
193 line \dimexpr\directblackrulesparameter\c!rulethickness\relax
194 }
195
196\letcsname\??blackruletype\s!no \endcsname\novrule
197
198
199\setupblackrules
200 [\c!n=3,
201 \c!rulethickness=\linewidth,
202 \c!alternative=\c!a,
203 \c!distance=.25\emwidth,
204 \c!color=]
205
206
207
208
209
210
211
212
213
214
215
216
217
218\protected\def\pack_rule_vl_indeed#1#2#3
219 {\dontleavehmode
220 \begingroup
221 \setbox\scratchbox\hbox
222 {\vrule
223 \s!width #1\linewidth
224 \s!height#2\strutht
225 \s!depth #3\strutdp}
226 \dp\scratchbox\strutdp
227 \ht\scratchbox\strutht
228 \box\scratchbox
229 \endgroup}
230
231\permanent\tolerant\protected\def\vl[#1]
232 {\pack_rule_vl_indeed{#1}{#1}{#1}}
233
234\permanent\tolerant\protected\def\hl[#1]
235 {\dontleavehmode
236 \hbox
237 {\vrule
238 \s!width #1\emwidth
239 \s!height\linewidth
240 \s!depth \zeropoint}}
241
242\let\dovlwdhtdp\pack_rule_vl_indeed
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\installcorenamespace{thinrules}
291\installcorenamespace{thinrulealternatives}
292
293\installdirectcommandhandler \??thinrules {thinrules}
294
295\setupthinrules
296 [\c!interlinespace=\v!small,
297 \c!n=3,
298 \c!before=,
299 \c!inbetween={\blank[\v!white]},
300 \c!after=,
301 \c!color=,
302 \c!height=.5\linewidth,
303 \c!depth=.5\linewidth,
304 \c!frame=\v!on,
305 \c!alternative=\v!b,
306 \c!backgroundcolor=,
307 \c!background=,
308 \c!rulethickness=\linewidth]
309
310\letcsname\??thinrulealternatives\v!a \endcsname\zerocount
311\letcsname\??thinrulealternatives\v!b \endcsname\plusone
312\letcsname\??thinrulealternatives\v!c \endcsname\plustwo
313\letcsname\??thinrulealternatives\v!none\endcsname\zerocount
314
315\newconstant\c_pack_thinrules_type
316
317\permanent\protected\def\thinrule
318 {\strut
319 \bgroup
320 \edef\p_height {\directthinrulesparameter\c!height}
321 \edef\p_depth {\directthinrulesparameter\c!depth}
322 \edef\p_background{\directthinrulesparameter\c!background}
323 \edef\p_frame {\directthinrulesparameter\c!frame}
324 \linewidth\dimexpr\directthinrulesparameter\c!rulethickness\plustwo\relax
325 \ifzeropt\linewidth
326 \c_pack_thinrules_type\zerocount
327 \orelse\ifx\p_frame\v!on
328 \c_pack_thinrules_type\expandnamespaceparameter\??thinrulealternatives\directthinrulesparameter\c!alternative\v!b\relax
329 \else
330 \c_pack_thinrules_type\zerocount
331 \fi
332 \ifnum\c_pack_thinrules_type=\plusone
333 \ifx\p_height\v!max
334 \scratchheight\strutht
335 \else
336 \setdimensionwithunit\scratchheight\p_height\strutht
337 \fi
338 \ifx\p_depth\v!max
339 \scratchdepth\strutdp
340 \else
341 \setdimensionwithunit\scratchdepth\p_depth\strutdp
342 \fi
343 \else
344 \scratchheight\strutht
345 \scratchdepth \strutdp
346 \fi
347 \ifx\p_background\v!color
348 \startcolor[\directthinrulesparameter\c!backgroundcolor]
349 \ifnum\c_pack_thinrules_type=\plustwo
350 \leaders
351 \hrule
352 \s!height\dimexpr\scratchheight\linewidth\relax
353 \s!depth \dimexpr\scratchdepth \linewidth\relax
354 \hfill
355 \else
356 \leaders
357 \hrule
358 \s!height\scratchheight
359 \s!depth \scratchdepth
360 \hfill
361 \fi
362 \stopcolor
363 \ifcase\c_pack_thinrules_type
364
365 \or
366 \startcolor[\directthinrulesparameter\c!color]
367 \hfillneg
368 \leaders
369 \hrule
370 \s!height\linewidth
371 \s!depth \linewidth
372 \hfill
373 \stopcolor
374 \or
375 \startcolor[\directthinrulesparameter\c!color]
376 \hfillneg
377 \leaders
378 \hrule
379 \s!height\dimexpr\scratchdepth\linewidth\relax
380 \s!depth \scratchdepth
381 \hfill
382 \hfillneg
383 \leaders
384 \hrule
385 \s!height\scratchheight
386 \s!depth \dimexpr\scratchheight\linewidth\relax
387 \hfill
388 \stopcolor
389 \fi
390 \else
391 \ifcase\c_pack_thinrules_type
392
393 \else
394 \startcolor[\directthinrulesparameter\c!color]
395 \leaders
396 \hrule
397 \s!height\scratchheight
398 \s!depth \scratchdepth
399 \hfill
400 \stopcolor
401 \fi
402 \fi
403 \strut
404 \carryoverpar\egroup}
405
406\permanent\protected\def\hairline
407 {\endgraf
408 \thinrule
409 \endgraf}
410
411\permanent\tolerant\protected\def\thinrules[#S#1]
412 {\bgroup
413 \setupcurrentthinrules[#1]
414 \scratchcounter\directthinrulesparameter\c!n\relax
415 \ifcase\scratchcounter
416
417 \let\p_after\relax
418 \else
419 \assignvalue{\directthinrulesparameter\c!interlinespace}\m_pack_thinrules_interlinespace{1.0}{1.5}{2.0}
420 \spacing\m_pack_thinrules_interlinespace
421 \edef\p_after {\directthinrulesparameter\c!after}
422 \edef\p_inbetween{\directthinrulesparameter\c!inbetween}
423 \directthinrulesparameter\c!before
424 \ifcase\scratchcounter\or
425 \thinrule
426 \else
427 \dorecurse\scratchcounter
428 {\ifnum\recurselevel=\scratchcounter \directvspacing\v!samepage \else
429 \ifnum\recurselevel=\plustwo \directvspacing\v!samepage \fi\fi
430 \thinrule
431 \ifnum\recurselevel<\scratchcounter\relax
432
433 \ifempty\p_inbetween
434 \softbreak
435 \else
436 \endgraf
437 \nowhitespace
438 \p_inbetween
439 \fi
440 \fi}
441 \fi
442 \fi
443 \ifempty\p_after
444 \carryoverpar\egroup
445 \else
446 \p_after\egroup
447 \fi{}}
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\installcorenamespace{textrules}
556\installcorenamespace{textrulealternatives}
557
558\installdirectcommandhandler \??textrules {textrules}
559
560\setuptextrules
561 [\c!location=\v!left,
562 \c!before=\blank,
563 \c!after=\blank,
564 \c!inbetween=,
565 \c!width=2\emwidth,
566 \c!style=\v!bold,
567 \c!color=,
568 \c!rulecolor=,
569 \c!bodyfont=,
570 \c!depthcorrection=\v!on,
571 \c!rulethickness=\linewidth,
572 \c!distance=.5\emwidth]
573
574
575
576\permanent\tolerant\protected\def\textrule[#1]
577 {\ifarguments
578 \expandafter\pack_textrule_nop
579 \else
580 \expandafter\pack_textrule_yes
581 \fi[#1]}
582
583\def\pack_textrule_yes[#1]
584 {\expandnamespacevalue\??textrulealternatives{#1}\v!bottom}
585
586
587
588
589
590
591
592
593\def\pack_textrule_nop[#1]
594 {\doifelsenextbgroupcs\pack_textrule_nop_indeed_yes\pack_textrule_nop_indeed_nop}
595
596\def\pack_textrule_nop_indeed_yes{\csname\??textrulealternatives\v!top \endcsname}
597\def\pack_textrule_nop_indeed_nop{\csname\??textrulealternatives\v!bottom\endcsname\empty}
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615\defcsname\??textrulealternatives\v!top\endcsname#1
616 {\page[\v!preference]
617 \directtextrulesparameter\c!before\relax
618 \blank[\v!samepage,\v!nowhite]
619 \pack_textrule_with_text_yes{#1}
620 \blank[\v!samepage,\v!nowhite]
621 \directtextrulesparameter\c!inbetween\relax
622 \endgraf}
623
624\defcsname\??textrulealternatives\v!bottom\endcsname#1
625 {\blank[\v!samepage,\v!nowhite]
626 \pack_textrule_following{#1}
627 \blank[\v!samepage,\v!nowhite]
628 \directtextrulesparameter\c!after\relax
629 \page[\v!preference]}
630
631\defcsname\??textrulealternatives\v!middle\endcsname#1
632 {\blank[\v!samepage,\v!nowhite]
633 \directtextrulesparameter\c!inbetween\relax
634 \pack_textrule_following{#1}
635 \blank[\v!samepage,\v!nowhite]
636 \directtextrulesparameter\c!inbetween\relax
637 \page[\v!preference]}
638
639\def\pack_textrule_with_text_yes#1
640 {\noindent
641 \bgroup
642 \setbox\scratchbox\hpack to \availablehsize
643 {\scratchwidth \directtextrulesparameter\c!rulethickness\relax
644 \scratchheight\dimexpr .5\exheight.5\scratchwidth\relax
645 \scratchdepth \dimexpr.5\exheight.5\scratchwidth\relax
646 \ifempty{#1}
647
648 \orelse\ifcstok{\directtextrulesparameter\c!location}\v!inmargin
649 \llap
650 {\usetextrulesstyleandcolor\c!style\c!color
651 #1
652 \kern\leftmargindistance}
653 \else
654 \color[\directtextrulesparameter\c!rulecolor]
655 {\vrule
656 \s!height\scratchheight
657 \s!depth \scratchdepth
658 \s!width \directtextrulesparameter\c!width}
659 \hbox spread 2\dimexpr\directtextrulesparameter\c!distance\relax
660 {\hss
661 \usetextrulesstyleandcolor\c!style\c!color
662 \strut#1
663 \hss}
664 \fi
665 \color[\directtextrulesparameter\c!rulecolor]
666 {\leaders\hrule
667 \s!height\scratchheight
668 \s!depth \scratchdepth
669 \hfill}}
670 \ht\scratchbox\strutht
671 \dp\scratchbox\strutdp
672 \box\scratchbox
673
674 \egroup}
675
676\def\pack_textrule_with_text_nop#1
677 {\ifhmode
678 \endgraf
679 \fi
680 \ifcstok{\directtextrulesparameter\c!depthcorrection}\v!on
681 \pack_textrule_correct_depth_yes
682 \else
683 \pack_textrule_correct_depth_nop
684 \fi
685 \nointerlineskip
686 \noindent\naturalvpack
687 {\color[\directtextrulesparameter\c!rulecolor]
688 {\hrule
689 \s!depth \directtextrulesparameter\c!rulethickness
690 \s!height\zeropoint
691 \s!width \availablehsize}}}
692
693\def\pack_textrule_correct_depth_yes
694 {\vskip\dimexpr
695 \strutdp .5\exheight
696 \ifdim\prevdepth>\strutdp\else
697 \ifdim\prevdepth>\zeropoint
698 \prevdepth
699 \fi
700 \fi
701 \relax
702 \relax}
703
704\def\pack_textrule_correct_depth_nop
705 {\vskip\dimexpr
706 \strutdp .5\exheight
707 \relax
708 \relax}
709
710\def\pack_textrule_following#1
711 {\ifempty{#1}
712 \expandafter\pack_textrule_with_text_nop
713 \else
714 \expandafter\pack_textrule_with_text_yes
715 \fi{#1}
716 \ifvmode
717 \prevdepth\zeropoint
718 \fi}
719
720
721
722\permanent\protected\def\starttextrule#1
723 {\bgroup
724 \def\pack_textrule_nop_indeed_nop{\csname\??textrulealternatives\v!middle\endcsname}
725
726 \csname\??textrulealternatives\v!top\endcsname{#1}
727 \bgroup
728 \usebodyfontparameter\directtextrulesparameter}
729
730\permanent\protected\def\stoptextrule
731 {\par
732 \egroup
733 \csname\??textrulealternatives\v!bottom\endcsname\empty
734 \egroup}
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\installcorenamespace{fillinrules}
760
761\installdirectcommandhandler \??fillinrules {fillinrules}
762
763\setupfillinrules
764 [\c!width=\v!broad,
765 \c!distance=\emwidth,
766 \c!before=\blank,
767 \c!after=\blank,
768 \c!n=\plusone,
769 \c!interlinespace=\v!small,
770 \c!separator=,
771 \c!style=,
772 \c!color=]
773
774\def\pack_fillinrules_rule_indeed{\thinrules}
775
776\permanent\tolerant\protected\def\fillinrules[#S#1]#:#=#*#=
777 {\endgraf
778 \begingroup
779 \setupcurrentfillinrules[#1]
780 \directfillinrulesparameter\c!before
781 \setupcurrentthinrules
782 [\c!n=\directfillinrulesparameter\c!n,
783 \c!interlinespace=\directfillinrulesparameter\c!interlinespace,
784 \c!before=,
785 \c!after=]
786 \scratchdistance\directfillinrulesparameter\c!distance\relax
787 \noindent
788 \ifempty{#2}\else
789 \edef\p_width{\directfillinrulesparameter\c!width}
790 \ifx\p_width\v!fit
791 \scratchdistance\zeropoint
792 \hbox
793 \orelse\ifx\p_width\v!broad
794 \hbox
795 \else
796 \hbox to \directfillinrulesparameter\c!width
797 \fi
798 \bgroup
799 \usefillinrulesstyleandcolor\c!style\c!color
800 \strut
801 #2
802 \hfill\directfillinrulesparameter\c!separator
803 \kern\scratchdistance
804 \egroup
805 \fi
806 \setupwhitespace[\v!big]
807 \ignorespaces
808 \pack_fillinrules_rule_indeed
809 \ifempty{#3}\else
810 \kern\scratchdistance
811 \usefillinrulesstyleandcolor\c!style\c!color
812 #3
813 \strut
814 \fi
815 \endgraf
816 \directfillinrulesparameter\c!after
817 \endgroup}
818
819
820
821
822
823
824
825
826
827\permanent\tolerant\protected\def\fillintext[#S#1]#:#=#*#=
828 {\endgraf
829 \begingroup
830 \def\pack_fillinrules_rule_indeed{\unhbox\nextbox\unskip}
831 \dowithnextbox{\fillinrules[#1]{#2}{\hfill#3}}
832 \hbox\bgroup\enforced\let\par\egroup\ignorespaces}
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\installcorenamespace{fillinlines}
861
862\installdirectcommandhandler \??fillinlines {fillinlines}
863
864\setupfillinlines
865 [\c!width=8\emwidth,
866 \c!margin=\directfillinlinesparameter\c!width,
867 \c!rulethickness=\linewidth,
868 \c!color=,
869 \c!distance=\emwidth,
870 \c!before=\blank,
871 \c!after=\blank]
872
873\protected\def\pack_fillinline_before#1
874 {}
875
876\protected\def\pack_fillinline_after#1
877 {\begingroup
878 \setupcurrentfillinlines[#1]
879 \ifhmode\unskip\hfill\fi
880 \scratchdistance\directfillinlinesparameter\c!distance
881 \scratchheight\dimexpr\directfillinlinesparameter\c!rulethickness\plustwo\relax
882 \scratchwidth \dimexpr\directfillinlinesparameter\c!width\scratchdistance\relax
883 \ifdim\scratchwidth>\directfillinlinesparameter\c!margin\else
884 \expandafter\rlap
885 \fi
886 {\kern\scratchdistance
887 \blackrule
888 [\c!color=\directfillinlinesparameter\c!color,
889 \c!width=\scratchwidth,
890 \c!height=\scratchheight,
891 \c!depth=\scratchheight]}
892 \frozen\advanceby\rightskip \directfillinlinesparameter\c!margin\relax
893 \frozen\parfillskip\zeroskip\relax
894 \endgroup}
895
896\permanent\tolerant\protected\def\fillinline[#S#1]
897 {\dontleavehmode
898 \registerparwrapper
899 {fillinline}
900 {\pack_fillinline_before{#1}}
901 {\pack_fillinline_after {#1}
902 \unregisterparwrapper{fillinline}}}
903
904\protect \endinput
905 |