summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/attr-lay.mkiv
blob: 67cd204e2f6df6ecadd2b55062e997422baad703 (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
%D \module
%D   [       file=attr-lay,
%D        version=2007.06.06,
%D          title=\CONTEXT\ Attribute Macros,
%D       subtitle=Viewerlayers,
%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 Attribute Macros / Viewerlayers}

\unprotect

\registerctxluafile{attr-lay}{1.001}

% needs to work over stopitemize grouping etc

% \def\registerviewerlayer#1#2% global !
%   {\setxvalue{\??ql:#1}{\global\attribute\viewerlayerattribute\ctxlua{tex.write(attributes.viewerlayers.register('#2'))} }}
%
% \setevalue{\??ql:}{\global\attribute\viewerlayerattribute\attributeunsetvalue}

\getparameters
  [\??lr]
  [\c!state=\v!start,
   \c!title=,
   \c!printable=\v!yes,
   \c!scope=\v!local, % maybe global but needs checking with layout
   \c!method=\v!none]

\def\defineviewerlayer
  {\dodoubleargument\dodefineviewerlayer}

\def\dodefineviewerlayer[#1][#2]% document wide properties
  {\begingroup
   \getparameters[\??lr][#2]%
   \ctxcommand{defineviewerlayer{
        tag       = "#1",
        title     = "\@@lrtitle",
        visible   = "\@@lrstate",
        editable  = "\v!yes",
        printable = "\@@lrprintable",
        scope     = "\@@lrscope"
   }}%
   \doif\@@lrmethod\v!command
     {\setugvalue{\e!start#1}{\startviewerlayer[#1]}%
      \setugvalue{\e!stop #1}{\stopviewerlayer     }}%
   \endgroup}

\unexpanded\def\startviewerlayer[#1]{\ctxcommand{startviewerlayer("#1")}}             % not grouped
\unexpanded\def\stopviewerlayer     {\ctxcommand{stopviewerlayer()}}                  % not grouped
\unexpanded\def\viewerlayer     [#1]{\groupedcommand{\startviewerlayer[#1]}{\stopviewerlayer}} % grouped

% some day we will keep this at the lua end as the info is only needed there

\let\currentviewerlayer\empty \newtoks\currentviewerlayertoks % soon we can set macros at the lua end

\def\currentviewerlayer{\the\currentviewerlayertoks}

\appendtoks
    \let\currentviewerlayer\empty
\to \everybeforepagebody

% layout components are implemented rather directly (speed)

\def\doinitializelayoutcomponent#1%
  {\edef\layoutcomponentboxattribute{\ctxcommand{definedviewerlayer{%
     tag       = "#1",
     title     = utilities.strings.nice("#1"), % only here as in steps we have step:<number>
     visible   = "\v!start",
     editable  = "\v!yes",
     printable = "\v!yes"
   }}}%
   \edef\layoutcomponentboxattribute{attr \viewerlayerattribute \layoutcomponentboxattribute\relax}%
   \expandafter\glet\csname\??lr:a:#1\endcsname\layoutcomponentboxattribute}

\def\dosetlayoutcomponentattribute#1% make this faster
  {\expandafter\let\expandafter\layoutcomponentboxattribute\csname\??lr:a:#1\endcsname
   \ifx\layoutcomponentboxattribute\relax
     \doinitializelayoutcomponent{#1}% get rid of { }
   \fi}

\def\doresetlayoutcomponentattribute
  {\let\layoutcomponentboxattribute\empty}

\let\setlayoutcomponentattribute  \gobbleoneargument
\let\resetlayoutcomponentattribute\relax
\let\layoutcomponentboxattribute  \empty

\def\showlayoutcomponents
  {\ctxlua{attributes.viewerlayers.enable()}% will go
   \let\setlayoutcomponentattribute  \dosetlayoutcomponentattribute
   \let\resetlayoutcomponentattribute\doresetlayoutcomponentattribute}

\protect \endinput