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=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]
%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
\def\c!printable{printable} % todo
\registerctxluafile{attr-lay}{1.001}
% needs to work over stopitemize grouping etc
\def\registerviewerlayer#1#2% global !
{\setxvalue{(vl:#1)}{\global\attribute\viewerlayerattribute\ctxlua{tex.write(attributes.viewerlayers.register('#2'))} }}
\setevalue{(vl:)}{\global\attribute\viewerlayerattribute\attributeunsetvalue}
\def\dotriggerviewerlayer % move to lua
{\ctxlua{attributes.viewerlayers.enable()}%
\gdef\dotriggerviewerlayer##1{\csname(vl:##1)\endcsname}%
\dotriggerviewerlayer}
\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]{\ctxlua{attributes.viewerlayers.start("#1")}} % not grouped
\unexpanded\def\stopviewerlayer {\ctxlua{attributes.viewerlayers.stop()}} % 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 \everypagebody
% layout components are implemented rather directly (speed)
\def\doinitializelayoutcomponent#1#2%
{\ctxcommand{defineviewerlayer{% this will move to the lua end i.e be merged with register
tag = "#1:#2",
title = "#1 #2",
visible = "\v!start",
editable = "\v!yes",
printable = "\v!yes"
}}%
\edef\layoutcomponentboxattribute{attr \viewerlayerattribute \ctxlua{tex.write(attributes.viewerlayers.register('#1:#2',true))}\relax}%
\expandafter\glet\csname\??ly>#1:#2\endcsname\layoutcomponentboxattribute}
\def\dosetlayoutcomponentattribute#1#2% make this faster
{\expandafter\let\expandafter\layoutcomponentboxattribute\csname\??ly>#1:#2\endcsname
\ifx\layoutcomponentboxattribute\relax
\doinitializelayoutcomponent{#1}{#2}% get rid of { }
\fi}
\def\doresetlayoutcomponentattribute
{\let\layoutcomponentboxattribute\empty}
\let\setlayoutcomponentattribute \gobbletwoarguments
\let\resetlayoutcomponentattribute\relax
\let\layoutcomponentboxattribute \empty
\def\showlayoutcomponents
{\ctxlua{attributes.viewerlayers.enable()}%
\let\setlayoutcomponentattribute \dosetlayoutcomponentattribute
\let\resetlayoutcomponentattribute\doresetlayoutcomponentattribute}
\protect \endinput
|