summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/spac-prf.mklx
blob: 824b14ca7ea66a4e54fc93fce299dcbc6553fd50 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
152
153
%D \module
%D   [       file=spac-prf,
%D        version=2015.11.16, % moved from test module mathplus
%D          title=\CONTEXT\ Spacing Macros,
%D       subtitle=Profiling,
%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 Spacing Macros / Profiling}

%D This is experimental code that we need for a project. The interface and details
%D can change. I moved it into the core because that way we can use it on servers.

% framed: first reflow then profile

\unprotect

\doiffileelse{spac-prf-new.lmt}{
    \registerctxluafile{spac-prf-new}{autosuffix}
} {
    \registerctxluafile{spac-prf}{autosuffix}
}

\definesystemattribute[profilemethod][public]

\installcorenamespace {profile}
\installcorenamespace {profiles}

\installcommandhandler \??profile {profile} \??profile

\setupprofile
  [\c!height=\strutht,
   \c!depth=\strutdp,
   \c!distance=\normallineskip,
   \c!lines=\zerocount,
   \c!factor=\plusone]

\defineprofile
  [\v!strict]
  [\c!method=\v!strict]

\defineprofile
  [\v!fixed]
  [\c!method=\v!fixed]

\defineprofile
  [\v!none]
  [\c!method=\v!none,
   \c!height=\zeropoint,
   \c!depth=\zeropoint,
   \c!distance=\zeropoint,
   \c!factor=\plusone]

\appendtoks
    \ifcstok{\profileparameter\c!define}\v!yes
        \frozen\protected\edefcsname\e!start\currentprofile\endcsname{\spac_profile_start{\currentprofile}}%
        \frozen\protected\defcsname \e!stop \currentprofile\endcsname{\spac_profile_stop}%
    \fi
\to \everydefineprofile

\def\spac_profile_set
  {\clf_setprofile
      name     {\currentprofile}%
      height   \dimexpr\profileparameter\c!height\relax
      depth    \dimexpr\profileparameter\c!depth\relax
      distance \dimexpr\profileparameter\c!distance\relax
      factor   \numexpr\profileparameter\c!factor\relax
      lines    \numexpr\profileparameter\c!lines\relax
      method   {\profileparameter\c!method}%
   \relax}

\tolerant\protected\def\spac_profile_start#profile#spacer[#settings]%
  {\begingroup
   \ifparameter#settings\or
     \edef\currentprofile{#profile}%
     \setupcurrentprofile[#settings]%
   \orelse\ifhastok={#profile}%
      \let\currentprofile\v!none
      \setupcurrentprofile[#profile]%
   \else
      \edef\currentprofile{#profile}%
   \fi
   \spac_profile_set
   \par
   \profileparameter\c!before}

\protected\def\spac_profile_stop
  {\par % otherwise not applied
   \profileparameter\c!after
   \endgroup}

\permanent\protected\def\startprofile[#profile]%
  {\spac_profile_start{#profile}}

\permanent\protected\def\stopprofile
  {\spac_profile_stop}

\permanent\protected\def\setprofile[#profile]%
  {\edef\currentprofile{#profile}%
   \spac_profile_set}

\permanent\protected\def\resetprofile
  {\c_attr_profilemethod\attributeunsetvalue}

\permanent\protected\def\useprofileparameter#getparameter%
  {\edef\m_spac_profile_asked{#getparameter\c!profile}%
   \ifempty\m_spac_profile_asked
     \resetprofile
   \else
     \setprofile[\m_spac_profile_asked]%
   \fi}

\permanent\tolerant\protected\def\profiledbox[#profile]#spacer[#settings]%
  {\vbox\bgroup
   \ifparameter#settings\or
     \edef\currentprofile{#profile}%
     \setupcurrentprofile[#settings]%
   \orelse\ifhastok={#profile}%
      \let\currentprofile\v!none
      \setupcurrentprofile[#profile]%
   \else
      \edef\currentprofile{#profile}%
   \fi
   \dowithnextbox
     {\profilegivenbox\currentprofile\nextbox
      \unvbox\nextbox
      \egroup}%
     \vbox}

\permanent\protected\def\profilegivenbox#profile#box%
  {\begingroup
   \edef\currentprofile{#profile}%
   \clf_profilebox
      box      \numexpr#box\relax
      height   \dimexpr\profileparameter\c!height\relax
      depth    \dimexpr\profileparameter\c!depth\relax
      distance \dimexpr\profileparameter\c!distance\relax
      factor   \numexpr\profileparameter\c!factor\relax
      lines    \numexpr\profileparameter\c!lines\relax
      method   {\profileparameter\c!method}%
    \relax
    \endgroup}

\defineprofile[halffixed]   [\v!fixed][\c!factor=\plustwo]
\defineprofile[quarterfixed][\v!fixed][\c!factor=\plusfour]
\defineprofile[eightsfixed] [\v!fixed][\c!factor=\pluseight]

\protect \endinput