summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/page-grd.mkiv
blob: 4125eb46aeabd8124cbf2cf954c52d362bdadc61 (plain)
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
%D \module
%D   [       file=page-grd,   % moved from page-ini
%D        version=2011.12.07, % 2000.10.20,
%D          title=\CONTEXT\ Page Macros,
%D       subtitle=Grids,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 Page Macros / Grids}

\unprotect

\newconstant\c_page_grids_location
\newconstant\c_page_grids_line_mode
\newconstant\c_page_grids_lineno_mode
\newconstant\c_page_grids_columns_mode

\unexpanded\def\showgrid
  {\dosingleempty\page_grids_show}

\def\page_grids_show[#1]%
  {\c_page_grids_location    \plusone % downward compatible default
   \c_page_grids_line_mode   \plusone
   \c_page_grids_lineno_mode \plusone
   \c_page_grids_columns_mode\plusone
   \processallactionsinset
     [#1]%
     [   \v!reset=>\c_page_grids_location    \zerocount
                   \c_page_grids_columns_mode\zerocount,
        \v!bottom=>\c_page_grids_location    \plusone,
           \v!top=>\c_page_grids_location    \plustwo,
          \v!none=>\c_page_grids_line_mode   \zerocount,
           \v!all=>\c_page_grids_line_mode   \plusone,
         \v!lines=>\c_page_grids_line_mode   \plustwo,
         \v!frame=>\c_page_grids_line_mode   \plusthree,
      \v!nonumber=>\c_page_grids_lineno_mode \zerocount,
         \v!right=>\c_page_grids_lineno_mode \plusone,
          \v!left=>\c_page_grids_lineno_mode \plustwo,
         \v!outer=>\c_page_grids_lineno_mode \plusthree,
       \v!columns=>\c_page_grids_columns_mode\plusone]% new option
   \ifcase\c_page_grids_location
     \let\page_grids_add_to_box\gobbleoneargument
   \else % 1=bottom 2=top
     \let\page_grids_add_to_box\page_grids_add_to_box_indeed
   \fi
   \ifcase\c_page_grids_columns_mode
     \let\page_grids_add_to_one\gobbleoneargument
     \let\page_grids_add_to_mix\gobbleoneargument
   \else
     \let\page_grids_add_to_one\page_grids_add_to_one_indeed
     \let\page_grids_add_to_mix\page_grids_add_to_mix_indeed
   \fi}

% if really needed for speed we can cache the grid

\let\page_grids_add_to_box\gobbleoneargument
\let\page_grids_add_to_one\gobbleoneargument
\let\page_grids_add_to_mix\gobbleoneargument

\def\page_grids_add_to_box_indeed#1% to be checked for color and layer ..... use mp
  {\startcolor[layout:grid]%
   \resetvisualizers
   \gridboxlinemode  \c_page_grids_line_mode
   \gridboxlinenomode\c_page_grids_lineno_mode
   \setgridbox\scratchbox\makeupwidth\textheight % todo: check color
   \global\setbox#1\hbox % global ?
     {\ifcase\c_page_grids_location\or\or\box#1\hskip-\makeupwidth\fi
      \begingroup % color
      \ifcase\layoutcolumns\else
        \gray
        \setlayoutcomponentattribute{\v!grid:\v!columns}%
        \hbox \layoutcomponentboxattribute to \makeupwidth
          {\dorecurse\layoutcolumns
             {\hskip\layoutcolumnwidth
              \ifnum\recurselevel<\layoutcolumns
                \vrule
                  \s!height\ht\scratchbox
                  \s!depth \dp\scratchbox
                  \s!width \layoutcolumndistance
              \fi}}%
        \hskip-\makeupwidth
      \fi
      \setlayoutcomponentattribute{\v!grid:\v!lines}%
      \hbox \layoutcomponentboxattribute{\box\scratchbox}%
      \endgroup
      \ifcase\c_page_grids_location\or\hskip-\makeupwidth\box#1\fi}%
   \stopcolor}

\def\page_grids_add_to_one_indeed#1%
  {\begingroup
   \resetvisualizers
   \global\setbox#1\vpack{\backgroundline[layout:one]{\box#1}}%
   \endgroup}

\def\page_grids_add_to_mix_indeed#1%
  {\begingroup
   \resetvisualizers
   \global\setbox#1\vpack{\backgroundline[layout:mix]{\box#1}}%
   \endgroup}

\protect \endinput