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\unexpanded\def\blackrule
42 {\hpack\bgroup
43 \doifelsenextoptionalcs\pack_black_rule_pickup\pack_black_rule_indeed}
44
45\def\pack_black_rule_pickup[#1]
46 {\setupcurrentblackrules[#1]
47 \pack_black_rule_indeed}
48
49\def\pack_black_rule_indeed
50 {\edef\p_width {\directblackrulesparameter\c!width }
51 \edef\p_height{\directblackrulesparameter\c!height}
52 \edef\p_depth {\directblackrulesparameter\c!depth }
53 \ifx\p_height\v!max
54 \setstrut
55 \else\ifx\p_depth\v!max
56 \setstrut
57 \fi\fi
58 \useblackrulesstyleandcolor\c!style\c!color
59 \ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
60 \lastnamedcs
61 \else
62 \vrule
63 \fi
64 \ifx\p_width \v!max\s!width \emwidth\else\ifx\p_width \empty\else\s!width \p_width \fi\fi
65 \ifx\p_height\v!max\s!height\strutht\else\ifx\p_height\empty\else\s!height\p_height\fi\fi
66 \ifx\p_depth \v!max\s!depth \strutdp\else\ifx\p_depth \empty\else\s!depth \p_depth \fi\fi
67 \egroup}
68
69\setupblackrules
70 [\c!width=\emwidth,
71 \c!height=\exheight,
72 \c!depth=\zeropoint,
73 \c!color=]
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\unexpanded\def\blackrules
102 {\hpack\bgroup
103 \doifelsenextoptionalcs\pack_black_rules_pickup\pack_black_rules_indeed}
104
105\def\pack_black_rules_pickup[#1]
106 {\setupcurrentblackrules[#1]
107 \pack_black_rules_indeed}
108
109\def\pack_black_rules_indeed
110 {\scratchwidth \directblackrulesparameter\c!width
111 \scratchheight \directblackrulesparameter\c!height
112 \scratchdepth \directblackrulesparameter\c!depth
113 \scratchdistance\directblackrulesparameter\c!distance
114 \scratchcounter \directblackrulesparameter\c!n
115 \edef\p_alternative{\blackrulesparameter\c!alternative}
116 \ifx\p_alternative\c!b
117 \ifnum\scratchcounter=\plusone
118 \scratchdistance\zeropoint
119 \else
120 \scratchwidth\dimexpr(\scratchwidth\scratchcounter\scratchdistance\scratchdistance)\scratchcounter\relax
121 \fi
122 \fi
123 \useblackrulesstyleandcolor\c!style\c!color
124
125 \dorecurse\scratchcounter\pack_black_rules_step
126 \unskip
127 \egroup}
128
129\def\pack_black_rules_step
130 {\ifcsname\??blackruletype\directblackrulesparameter\c!type\endcsname
131 \lastnamedcs
132 \else
133 \vrule
134 \fi
135 \s!width \scratchwidth
136 \s!height\scratchheight
137 \s!depth \scratchdepth
138 \relax
139 \ifzeropt\scratchdistance\else
140 \hskip\scratchdistance
141 \fi}
142
143\installcorenamespace{blackruletype}
144
145\setvalue{\??blackruletype mp}
146 {\frule
147 type {mp}
148 data {\includeMPgraphic{\directblackrulesparameter\c!mp}}
149 line \dimexpr\directblackrulesparameter\c!rulethickness\relax
150 }
151
152\letvalue{\??blackruletype\s!no }\novrule
153
154
155\setupblackrules
156 [\c!n=3,
157 \c!rulethickness=\linewidth,
158 \c!alternative=\c!a,
159 \c!distance=.25\emwidth,
160 \c!color=]
161
162
163
164
165
166
167
168
169
170
171
172
173
174\unexpanded\def\pack_rule_vl_indeed#1#2#3
175 {\dontleavehmode
176 \begingroup
177 \setbox\scratchbox\hbox
178 {\vrule
179 \s!width #1\linewidth
180 \s!height#2\strutht
181 \s!depth #3\strutdp}
182 \dp\scratchbox\strutdp
183 \ht\scratchbox\strutht
184 \box\scratchbox
185 \endgroup}
186
187\def\pack_rule_vl[#1]
188 {\pack_rule_vl_indeed{#1}{#1}{#1}}
189
190\def\pack_rule_hl[#1]
191 {\dontleavehmode
192 \hbox
193 {\vrule
194 \s!width #1\emwidth
195 \s!height\linewidth
196 \s!depth \zeropoint}}
197
198\unexpanded\def\vl{\dosingleempty\pack_rule_vl}
199\unexpanded\def\hl{\dosingleempty\pack_rule_hl}
200
201\let\dovlwdhtdp\pack_rule_vl_indeed
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\installcorenamespace{thinrules}
250\installcorenamespace{thinrulealternatives}
251
252\installdirectcommandhandler \??thinrules {thinrules}
253
254\setupthinrules
255 [\c!interlinespace=\v!small,
256 \c!n=3,
257 \c!before=,
258 \c!inbetween={\blank[\v!white]},
259 \c!after=,
260 \c!color=,
261 \c!height=.5\linewidth,
262 \c!depth=.5\linewidth,
263 \c!frame=\v!on,
264 \c!alternative=\v!b,
265 \c!backgroundcolor=,
266 \c!background=,
267 \c!rulethickness=\linewidth]
268
269\letvalue{\??thinrulealternatives\v!a }\zerocount
270\letvalue{\??thinrulealternatives\v!b }\plusone
271\letvalue{\??thinrulealternatives\v!c }\plustwo
272\letvalue{\??thinrulealternatives\v!none}\zerocount
273
274\newconstant\c_pack_thinrules_type
275
276\unexpanded\def\thinrule
277 {\strut
278 \bgroup
279 \edef\p_height {\directthinrulesparameter\c!height}
280 \edef\p_depth {\directthinrulesparameter\c!depth}
281 \edef\p_background{\directthinrulesparameter\c!background}
282 \edef\p_frame {\directthinrulesparameter\c!frame}
283 \linewidth\dimexpr\directthinrulesparameter\c!rulethickness\plustwo\relax
284 \ifzeropt\linewidth
285 \c_pack_thinrules_type\zerocount
286 \else\ifx\p_frame\v!on
287 \c_pack_thinrules_type\expandnamespaceparameter\??thinrulealternatives\directthinrulesparameter\c!alternative\v!b\relax
288 \else
289 \c_pack_thinrules_type\zerocount
290 \fi\fi
291 \ifnum\c_pack_thinrules_type=\plusone
292 \ifx\p_height\v!max
293 \scratchheight\strutht
294 \else
295 \setdimensionwithunit\scratchheight\p_height\strutht
296 \fi
297 \ifx\p_depth\v!max
298 \scratchdepth\strutdp
299 \else
300 \setdimensionwithunit\scratchdepth\p_depth\strutdp
301 \fi
302 \else
303 \scratchheight\strutht
304 \scratchdepth \strutdp
305 \fi
306 \ifx\p_background\v!color
307 \startcolor[\directthinrulesparameter\c!backgroundcolor]
308 \ifnum\c_pack_thinrules_type=\plustwo
309 \leaders
310 \hrule
311 \s!height\dimexpr\scratchheight\linewidth\relax
312 \s!depth \dimexpr\scratchdepth \linewidth\relax
313 \hfill
314 \else
315 \leaders
316 \hrule
317 \s!height\scratchheight
318 \s!depth \scratchdepth
319 \hfill
320 \fi
321 \stopcolor
322 \ifcase\c_pack_thinrules_type
323
324 \or
325 \startcolor[\directthinrulesparameter\c!color]
326 \hfillneg
327 \leaders
328 \hrule
329 \s!height\linewidth
330 \s!depth \linewidth
331 \hfill
332 \stopcolor
333 \or
334 \startcolor[\directthinrulesparameter\c!color]
335 \hfillneg
336 \leaders
337 \hrule
338 \s!height\dimexpr\scratchdepth\linewidth\relax
339 \s!depth \scratchdepth
340 \hfill
341 \hfillneg
342 \leaders
343 \hrule
344 \s!height\scratchheight
345 \s!depth \dimexpr\scratchheight\linewidth\relax
346 \hfill
347 \stopcolor
348 \fi
349 \else
350 \ifcase\c_pack_thinrules_type
351
352 \else
353 \startcolor[\directthinrulesparameter\c!color]
354 \leaders
355 \hrule
356 \s!height\scratchheight
357 \s!depth \scratchdepth
358 \hfill
359 \stopcolor
360 \fi
361 \fi
362 \strut
363 \carryoverpar\egroup}
364
365\unexpanded\def\hairline
366 {\endgraf
367 \thinrule
368 \endgraf}
369
370\unexpanded\def\thinrules
371 {\dosingleempty\pack_thinrules}
372
373\def\pack_thinrules[#1]
374 {\bgroup
375 \setupcurrentthinrules[#1]
376 \scratchcounter\directthinrulesparameter\c!n\relax
377 \ifcase\scratchcounter
378
379 \let\p_after\relax
380 \else
381 \assignvalue{\directthinrulesparameter\c!interlinespace}\m_pack_thinrules_interlinespace{1.0}{1.5}{2.0}
382 \spacing\m_pack_thinrules_interlinespace
383 \edef\p_after {\directthinrulesparameter\c!after}
384 \edef\p_inbetween{\directthinrulesparameter\c!inbetween}
385 \directthinrulesparameter\c!before
386 \ifcase\scratchcounter\or
387 \thinrule
388 \else
389 \dorecurse\scratchcounter
390 {\ifnum\recurselevel=\scratchcounter \directvspacing\v!samepage \else
391 \ifnum\recurselevel=\plustwo \directvspacing\v!samepage \fi\fi
392 \thinrule
393 \ifnum\recurselevel<\scratchcounter\relax
394
395 \ifx\p_inbetween\empty
396 \softbreak
397 \else
398 \endgraf
399 \nowhitespace
400 \p_inbetween
401 \fi
402 \fi}
403 \fi
404 \fi
405 \ifx\p_after\empty
406 \carryoverpar\egroup
407 \else
408 \p_after\egroup
409 \fi{}}
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\installcorenamespace{textrules}
518\installcorenamespace{textrulealternatives}
519
520\installdirectcommandhandler \??textrules {textrules}
521
522\setuptextrules
523 [\c!location=\v!left,
524 \c!before=\blank,
525 \c!after=\blank,
526 \c!inbetween=,
527 \c!width=2\emwidth,
528 \c!style=\v!bold,
529 \c!color=,
530 \c!rulecolor=,
531 \c!bodyfont=,
532 \c!depthcorrection=\v!on,
533 \c!rulethickness=\linewidth,
534 \c!distance=.5\emwidth]
535
536\unexpanded\def\textrule
537 {\dosingleempty\pack_textrule}
538
539\def\pack_textrule
540 {\iffirstargument
541 \expandafter\pack_textrule_yes
542 \else
543 \expandafter\pack_textrule_nop
544 \fi}
545
546\def\pack_textrule_yes[#1]
547 {\expandnamespacevalue\??textrulealternatives{#1}\v!bottom}
548
549\def\pack_textrule_nop[#1]
550 {\dosinglegroupempty\pack_textrule_nop_indeed}
551
552\def\pack_textrule_nop_indeed
553 {\iffirstargument
554 \expandafter\pack_textrule_nop_indeed_yes
555 \else
556 \expandafter\pack_textrule_nop_indeed_nop
557 \fi}
558
559\def\pack_textrule_nop_indeed_yes
560 {\csname\??textrulealternatives\v!top\endcsname}
561
562\def\pack_textrule_nop_indeed_nop
563 {\csname\??textrulealternatives\v!bottom\endcsname\empty}
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581\setvalue{\??textrulealternatives\v!top}#1
582 {\page[\v!preference]
583 \directtextrulesparameter\c!before\relax
584 \blank[\v!samepage,\v!nowhite]
585 \pack_textrule_with_text_yes{#1}
586 \blank[\v!samepage,\v!nowhite]
587 \directtextrulesparameter\c!inbetween\relax
588 \endgraf}
589
590\setvalue{\??textrulealternatives\v!bottom}#1
591 {\blank[\v!samepage,\v!nowhite]
592 \pack_textrule_following{#1}
593 \blank[\v!samepage,\v!nowhite]
594 \directtextrulesparameter\c!after\relax
595 \page[\v!preference]}
596
597\setvalue{\??textrulealternatives\v!middle}#1
598 {\blank[\v!samepage,\v!nowhite]
599 \directtextrulesparameter\c!inbetween\relax
600 \pack_textrule_following{#1}
601 \blank[\v!samepage,\v!nowhite]
602 \directtextrulesparameter\c!inbetween\relax
603 \page[\v!preference]}
604
605\def\pack_textrule_with_text_yes#1
606 {\noindent
607 \bgroup
608 \setbox\scratchbox\hpack to \availablehsize
609 {\scratchwidth \directtextrulesparameter\c!rulethickness\relax
610 \scratchheight\dimexpr .5\exheight.5\scratchwidth\relax
611 \scratchdepth \dimexpr.5\exheight.5\scratchwidth\relax
612 \doifsomething{#1}
613 {\doifelse{\directtextrulesparameter\c!location}\v!inmargin
614 {\llap
615 {\usetextrulesstyleandcolor\c!style\c!color
616 #1
617 \hskip\leftmargindistance}}
618 {\color[\directtextrulesparameter\c!rulecolor]
619 {\vrule
620 \s!height\scratchheight
621 \s!depth \scratchdepth
622 \s!width \directtextrulesparameter\c!width}
623 \hbox spread 2\dimexpr\directtextrulesparameter\c!distance\relax
624 {\hss
625 \usetextrulesstyleandcolor\c!style\c!color
626 \strut#1
627 \hss}}}
628 \color[\directtextrulesparameter\c!rulecolor]
629 {\leaders\hrule
630 \s!height\scratchheight
631 \s!depth \scratchdepth
632 \hfill}}
633 \ht\scratchbox\strutht
634 \dp\scratchbox\strutdp
635 \box\scratchbox
636
637 \egroup}
638
639\def\pack_textrule_with_text_nop#1
640 {\ifhmode
641 \endgraf
642 \fi
643 \doifelse{\directtextrulesparameter\c!depthcorrection}\v!on
644 \pack_textrule_correct_depth_yes
645 \pack_textrule_correct_depth_nop
646 \nointerlineskip
647 \noindent\naturalvpack
648 {\color[\directtextrulesparameter\c!rulecolor]
649 {\hrule
650 \s!depth \directtextrulesparameter\c!rulethickness
651 \s!height\zeropoint
652 \s!width \availablehsize}}}
653
654\def\pack_textrule_correct_depth_yes
655 {\vskip\dimexpr
656 \strutdp .5\exheight
657 \ifdim\prevdepth>\strutdp\else
658 \ifdim\prevdepth>\zeropoint
659 \prevdepth
660 \fi
661 \fi
662 \relax
663 \relax}
664
665\def\pack_textrule_correct_depth_nop
666 {\vskip\dimexpr
667 \strutdp .5\exheight
668 \relax
669 \relax}
670
671\def\pack_textrule_following#1
672 {\doifelsenothing{#1}
673 \pack_textrule_with_text_nop
674 \pack_textrule_with_text_yes
675 {#1}
676 \ifvmode
677 \prevdepth\zeropoint
678 \fi}
679
680
681
682\unexpanded\def\starttextrule#1
683 {\bgroup
684 \def\pack_textrule_nop_indeed{\csname\??textrulealternatives\v!middle\endcsname}
685 \csname\??textrulealternatives\v!top\endcsname{#1}
686 \bgroup
687 \usebodyfontparameter\directtextrulesparameter}
688
689\unexpanded\def\stoptextrule
690 {\par
691 \egroup
692 \csname\??textrulealternatives\v!bottom\endcsname\empty
693 \egroup}
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717\installcorenamespace{fillinrules}
718
719\installdirectcommandhandler \??fillinrules {fillinrules}
720
721\setupfillinrules
722 [\c!width=\v!broad,
723 \c!distance=\emwidth,
724 \c!before=\blank,
725 \c!after=\blank,
726 \c!n=\plusone,
727 \c!interlinespace=\v!small,
728 \c!separator=,
729 \c!style=,
730 \c!color=]
731
732\unexpanded\def\fillinrules
733 {\dosingleempty\pack_fillinrules}
734
735\def\pack_fillinrules[#1]
736 {\endgraf
737 \begingroup
738 \setupcurrentfillinrules[#1]
739 \let\pack_fillinrules_rule\thinrules
740 \dodoublegroupempty\pack_fillinrules_indeed}
741
742\def\pack_fillinrules_indeed#1#2
743 {\directfillinrulesparameter\c!before
744 \setupcurrentthinrules
745 [\c!n=\directfillinrulesparameter\c!n,
746 \c!interlinespace=\directfillinrulesparameter\c!interlinespace,
747 \c!before=,
748 \c!after=]
749 \scratchdistance\directfillinrulesparameter\c!distance\relax
750 \edef\m_fillinrules_one{#1}
751 \edef\m_fillinrules_two{#2}
752 \noindent
753 \ifx\m_fillinrules_one\empty \else
754 \edef\p_width{\directfillinrulesparameter\c!width}
755 \ifx\p_width\v!fit
756 \scratchdistance\zeropoint
757 \hbox
758 \else\ifx\p_width\v!broad
759 \hbox
760 \else
761 \hbox to \directfillinrulesparameter\c!width
762 \fi\fi
763 \bgroup
764 \usefillinrulesstyleandcolor\c!style\c!color
765 \strut
766 \m_fillinrules_one
767 \hfill\directfillinrulesparameter\c!separator
768 \hskip\scratchdistance
769 \egroup
770 \fi
771 \setupwhitespace[\v!big]
772 \ignorespaces
773 \pack_fillinrules_rule
774 \ifx\m_fillinrules_two\empty \else
775 \kern\scratchdistance
776 \usefillinrulesstyleandcolor\c!style\c!color
777 \m_fillinrules_two
778 \strut
779 \fi
780 \endgraf
781 \directfillinrulesparameter\c!after
782 \endgroup}
783
784
785
786
787
788
789
790
791
792\unexpanded\def\fillintext
793 {\dosingleempty\pack_fillintext}
794
795\def\pack_fillintext[#1]
796 {\endgraf
797 \begingroup
798 \setupcurrentfillinrules[#1]
799 \dodoublegroupempty\pack_fillintext_indeed}
800
801\def\pack_fillintext_indeed#1#2
802 {\def\pack_fillinrules_rule{\unhbox\nextbox\unskip}
803 \dowithnextbox{\pack_fillinrules_indeed{#1}{\hfill#2}}
804 \hbox\bgroup\let\par\egroup\ignorespaces}
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\installcorenamespace{fillinlines}
831
832\installdirectcommandhandler \??fillinlines {fillinlines}
833
834\setupfillinlines
835 [\c!width=8\emwidth,
836 \c!margin=\directfillinlinesparameter\c!width,
837 \c!rulethickness=\linewidth,
838 \c!color=,
839 \c!distance=\emwidth,
840 \c!before=\blank,
841 \c!after=\blank]
842
843\unexpanded\def\fillinline
844 {\dosingleempty\pack_fillinline}
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 \def\pack_fillinline[#1]
874 {
875 \begingroup
876 \setupcurrentfillinlines[#1]
877 \directfillinlinesparameter\c!before
878 \begingroup
879 \advance\rightskip \directfillinlinesparameter\c!margin\relax
880 \parfillskip\zeropoint
881 \def\par
882 {\let\par\endgraf
883 \ifhmode\unskip\hfill\fi
884 \scratchwidth\dimexpr\directfillinlinesparameter\c!width\directfillinlinesparameter\c!distance\relax
885 \ifdim\scratchwidth>\directfillinlinesparameter\c!margin\else\expandafter\rlap\fi
886 {\kern\directfillinlinesparameter\c!distance
887 \scratchheight\dimexpr\directfillinlinesparameter\c!rulethickness\plustwo\relax
888 \color[\directfillinlinesparameter\c!color]{\vrule\s!width\scratchwidth\s!height\scratchheight\s!depth\scratchheight}}
889 \endgraf
890 \endgroup
891 \endgraf
892 \directfillinlinesparameter\c!after
893 \endgroup}}
894
895
896
897\protect \endinput
898 |