typo-drp.mkxl /size: 6578 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=typo-drp, % was typo-par
3%D        version=2011.10.27,
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=Initials,
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 Typesetting Macros / Initials}
15
16%D This will change ... par specific attribute set and such.
17
18\unprotect
19
20\registerctxluafile{typo-drp}{autosuffix}
21
22\definesystemattribute[initial][public]
23
24\appendtoks
25    \c_attr_initial\attributeunsetvalue
26\to \everyforgetall
27
28%D For the moment here: dropped caps redone. In addition to the parameters shown in
29%D the example you can use the \type {style} and more low level \type {font} keys to
30%D set up the font where the first one wins. If you don't like the behaviour you can
31%D always roll out your own command.
32%D
33%D \starttyping
34%D \placeinitial \input ward \par \input ward \par \placeinitial \input tufte
35%D
36%D \setupinitial
37%D   [location=text,
38%D    n=2,
39%D    color=darkred,
40%D    distance=-1em,
41%D    hoffset=1em,
42%D    voffset=-3ex,
43%D    before=\blank]
44%D
45%D \placeinitial \input ward \par \input ward \placeinitial \input tufte
46%D \stoptyping
47
48% todo: angle (once we can set parshape at the Lua end)
49
50\installcorenamespace{initial}
51
52\installcommandhandler \??initial {initial} \??initial
53
54\definemeasure[initial:n][\lineheight*\initialparameter\c!n - \strutdp]
55
56\setupinitial
57  [\c!location=\v!text,
58   \c!n=3,
59   \c!m=1,
60   \c!method=\v!none,
61   \c!continue=\v!no, % yes will handle single line cases
62 % \c!font=Bold sa 4,
63 % \c!font=Bold ht \measure{initial:n},
64   \c!font=Bold cp \measure{initial:n},
65   \c!distance=.125\emwidth,
66   \c!hoffset=\zeropoint,
67   \c!voffset=\v!line, % \dimexp\lineheight*\initialparameter\c!n-\lineheight\relax]
68   \c!style=,
69   \c!color=,
70   \c!before=\blank]
71
72\permanent\tolerant\protected\def\placeinitial[#1]% old command
73  {\par
74   \namedinitialparameter{#1}\c!before
75   \enforced\edef\typo_initial_handle{\typo_initial_handle_indeed{#1}{}}}
76
77\permanent\tolerant\protected\def\setinitial[#1]#*[#S#2]%
78  {\enforced\edef\typo_initial_handle{\typo_initial_handle_indeed{#1}{#2}}}
79
80%D \starttyping
81%D \framed
82%D   [width=10cm,align=normal,strut=no,toffset=1ex]
83%D   {\placeinitial \flushinitial \samplefile{ward}}
84%D \stoptyping
85
86\permanent\tolerant\protected\def\flushinitial % when used inside a mechanism that forgets
87  {\typo_initial_handle}
88
89\newconstant   \c_initial_lines
90\newconditional\c_initial_synchronize
91
92% First experiment:
93%
94% \startluacode
95%     function nodes.handlers.forgetinitial(mode,indented,context)
96%         token.expandmacro("forgetinitial")
97%         return indented
98%     end
99%     utilities.sequencers.prependaction("paragraph","system","nodes.handlers.forgetinitial")
100%     utilities.sequencers.enableaction("paragraph","nodes.handlers.forgetinitial")
101% \stopluacode
102%
103% Second experiment:
104%
105% \appendtoks
106%     \forgetinitial
107% \to \everybeforepar
108
109\protected\def\typo_initial_handle_indeed#1#2%
110  {\dontleavehmode
111   \begingroup
112   \cdef\currentinitial{#1}%
113   \setupcurrentinitial[#2]%
114   \resetfontfeature % might be needed in more places
115   \ifempty{\initialparameter\c!style}%
116     \definedfont[\initialparameter\c!font]%
117   \else
118     \useinitialstyleparameter\c!style
119   \fi
120   \useinitialcolorparameter\c!color
121   \edef\p_voffset{\initialparameter\c!voffset}%
122   \scratchcounter \initialparameter\c!n\relax
123   \scratchvoffset\dimexpr\ifx\p_voffset\v!line\scratchcounter\lineheight-\lineheight\else\p_voffset\fi\relax
124   \clf_setinitial
125        location   {\initialparameter\c!location}%
126        enabled    true\space
127        n          \scratchcounter
128        m          \numexpr\initialparameter\c!m\relax
129        method     {\initialparameter\c!method}%
130        continue   {\initialparameter\c!continue}%
131        distance   \dimexpr\initialparameter\c!distance\relax
132        hoffset    \dimexpr\initialparameter\c!hoffset\relax
133        voffset    \scratchvoffset
134        ma         \c_attr_colormodel
135        ca         \c_attr_color
136        ta         \c_attr_transparency
137        font       \fontid\font
138        glyphscale \glyphscale
139        dynamic    \font_dynamic_value % it's a bit over the top to support this here
140   \relax
141   \c_attr_initial\plusone
142   \initialparameter\c!text
143   \normalexpanded{\endgroup\c_initial_lines\the\scratchcounter}%
144   \enforced\glettonothing\typo_initial_handle
145   \ifconditional\c_initial_synchronize
146     \appendtoks \forgetinitial \to \everybeforepar
147   \fi}
148
149\lettonothing\typo_initial_handle % hook into everypar
150
151\permanent\protected\def\forgetinitial
152  {\ifcase\c_initial_lines\else
153     \begingroup
154     \advanceby\c_initial_lines-\prevgraf\relax
155     \ifcase\c_initial_lines\else
156       \obeydepth
157       \forgetall
158       \testpage[\the\c_initial_lines]%
159       \dorecurse\c_initial_lines{\nointerlineskip\hpack to \hsize{\strut}\par}%
160     \fi
161     \endgroup
162     \c_initial_lines\zerocount
163     \ifconditional\c_initial_synchronize
164       \removetoks \forgetinitial \from \everybeforepar
165     \fi
166  \fi}
167
168%D \starttyping
169%D \setupinitial[n=2,style=\tfd,location=text]
170%D \setuphead[chapter][after=\placeinitial]
171%D \enableexperiments[autoforgetinitials]
172%D
173%D \starttext
174%D   \chapter{Test me} Hello world!
175%D  %\forgetinitial \input tufte
176%D   \input tufte
177%D \stoptext
178%D \stoptyping
179
180% \enableexperiments[autoforgetinitials]
181
182\installtexexperiment
183   {autoforgetinitials}
184   {\c_initial_synchronize\conditionaltrue}
185   {\c_initial_synchronize\conditionalfalse}
186
187% \setupbodyfont[dejavu,9pt]
188%
189% \startbuffer
190% \setinitial[two]            D. E. Knuth   \ignorespaces\input knuth \par
191% \setinitial[two]                  Knuth   \ignorespaces\input knuth \par
192% \setinitial[two] \quotation{D. E. Knuth}  \ignorespaces\input knuth \par
193% \setinitial[two] \quotation      {Knuth}  \ignorespaces\input knuth \par
194% \setinitial[two]      [text={D.E. Knuth}] \ignorespaces\input knuth \par
195% \setinitial[two]       [m=4] D. E. Knuth  \ignorespaces\input knuth \par
196% \stopbuffer
197%
198% \type{m=2}                          \start \defineinitial[two][m=2,method=none]              \getbuffer \page \stop
199% \type{m=1,method=auto}              \start \defineinitial[two][m=1,method=auto]              \getbuffer \page \stop
200% \type{m=1,method={auto,first,last}} \start \defineinitial[two][m=1,method={first,auto,last}] \getbuffer \page \stop
201
202\protect \endinput
203