summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/spac-prf.mkvi
blob: 8d150f58d4de20f6c23042104517f7530b12fe46 (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
%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
%D details can change. I moved it into the core because that way we can use
%D it on servers.

% framed: first reflow then profile

\unprotect

\registerctxluafile{spac-prf}{1.001}

\definesystemattribute[profilemethod][public]

\installcorenamespace {profile} % beware, profiles are not like in mkii at all
\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]

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

\unexpanded\def\setprofile[#profile]%
  {\edef\currentprofile{#profile}%
   \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}

\unexpanded\def\resetprofile
  {\attribute\profilemethodattribute\attributeunsetvalue}

\unexpanded\def\useprofileparameter#getparameter%
  {\edef\m_spac_profile_asked{#getparameter\c!profile}%
   \ifx\m_spac_profile_asked\empty
     \resetprofile
   \else
     \setprofile[\m_spac_profile_asked]%
   \fi}

\unexpanded\def\profiledbox
  {\vbox\bgroup
   \dodoubleempty\spac_profiling_box}

\def\spac_profiling_box[#profile][#settings]%
  {\ifsecondargument
     \edef\currentprofile{#profile}%
     \setupcurrentprofile[#settings]%
   \else
     \doifassignmentelse{#profile}
       {\let\currentprofile\v!none
        \setupcurrentprofile[#profile]}%
       {\edef\currentprofile{#profile}}%
   \fi
   \dowithnextbox
     {\profilegivenbox\currentprofile\nextbox
      \unvbox\nextbox
      \egroup}%
     \vbox}

\unexpanded\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}

\protect \endinput