spac-prf.mkvi /size: 3322 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=spac-prf,
3%D        version=2015.11.16, % moved from test module mathplus
4%D          title=\CONTEXT\ Spacing Macros,
5%D       subtitle=Profiling,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Spacing Macros / Profiling}
15
16%D This is experimental code that we need for a project. The interface and
17%D details can change. I moved it into the core because that way we can use
18%D it on servers.
19
20% framed: first reflow then profile
21
22\unprotect
23
24\registerctxluafile{spac-prf}{}
25
26\definesystemattribute[profilemethod][public]
27
28\installcorenamespace {profile} % beware, profiles are not like in mkii at all
29\installcorenamespace {profiles}
30
31\installcommandhandler \??profile {profile} \??profile
32
33\setupprofile
34  [\c!height=\strutht,
35   \c!depth=\strutdp,
36   \c!distance=\normallineskip,
37   \c!lines=\zerocount,
38   \c!factor=\plusone]
39
40\defineprofile
41  [\v!strict]
42  [\c!method=\v!strict]
43
44\defineprofile
45  [\v!fixed]
46  [\c!method=\v!fixed]
47
48\defineprofile
49  [\v!none]
50  [\c!method=\v!none,
51   \c!height=\zeropoint,
52   \c!depth=\zeropoint,
53   \c!distance=\zeropoint,
54   \c!factor=\plusone]
55
56\defineprofile[halffixed]   [\v!fixed][\c!factor=\plustwo]
57\defineprofile[quarterfixed][\v!fixed][\c!factor=\plusfour]
58\defineprofile[eightsfixed] [\v!fixed][\c!factor=\pluseight]
59
60\unexpanded\def\setprofile[#profile]%
61  {\edef\currentprofile{#profile}%
62   \clf_setprofile
63      name     {\currentprofile}%
64      height   \dimexpr\profileparameter\c!height\relax
65      depth    \dimexpr\profileparameter\c!depth\relax
66      distance \dimexpr\profileparameter\c!distance\relax
67      factor   \numexpr\profileparameter\c!factor\relax
68      lines    \numexpr\profileparameter\c!lines\relax
69      method   {\profileparameter\c!method}%
70   \relax}
71
72\unexpanded\def\resetprofile
73  {\c_attr_profilemethod\attributeunsetvalue}
74
75\unexpanded\def\useprofileparameter#getparameter%
76  {\edef\m_spac_profile_asked{#getparameter\c!profile}%
77   \ifx\m_spac_profile_asked\empty
78     \resetprofile
79   \else
80     \setprofile[\m_spac_profile_asked]%
81   \fi}
82
83\unexpanded\def\profiledbox
84  {\vbox\bgroup
85   \dodoubleempty\spac_profiling_box}
86
87\def\spac_profiling_box[#profile][#settings]%
88  {\ifsecondargument
89     \edef\currentprofile{#profile}%
90     \setupcurrentprofile[#settings]%
91   \else
92     \doifassignmentelse{#profile}
93       {\let\currentprofile\v!none
94        \setupcurrentprofile[#profile]}%
95       {\edef\currentprofile{#profile}}%
96   \fi
97   \dowithnextbox
98     {\profilegivenbox\currentprofile\nextbox
99      \unvbox\nextbox
100      \egroup}%
101     \vbox}
102
103\unexpanded\def\profilegivenbox#profile#box%
104  {\begingroup
105   \edef\currentprofile{#profile}%
106   \clf_profilebox
107      box      \numexpr#box\relax
108      height   \dimexpr\profileparameter\c!height\relax
109      depth    \dimexpr\profileparameter\c!depth\relax
110      distance \dimexpr\profileparameter\c!distance\relax
111      factor   \numexpr\profileparameter\c!factor\relax
112      lines    \numexpr\profileparameter\c!lines\relax
113      method   {\profileparameter\c!method}%
114    \relax
115    \endgroup}
116
117\protect \endinput
118