typo-drp.mkxl /size: 6811 b    last modification: 2025-02-21 11:03
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   \ifempty{\initialparameter\c!color}%
121     \c_attr_color       \attributeunsetvalue
122     \c_attr_transparency\attributeunsetvalue
123   \else
124     \useinitialcolorparameter\c!color
125   \fi
126   \scratchcounter{\initialparameter\c!n}%
127   \edef\p_voffset{\initialparameter\c!voffset}%
128   \scratchvoffset{\ifx\p_voffset\v!line\scratchcounter\lineheight-\lineheight\else\p_voffset\fi}%
129 % \scratchvoffset{\ifcstok{\initialparameter\c!voffset}\v!line\scratchcounter\lineheight-\lineheight\else\lastnamedcs\fi}%
130   \clf_setinitial
131        location   {\initialparameter\c!location}%
132        enabled    true\relaxedspace
133        n          \scratchcounter
134        m          {\initialparameter\c!m}%
135        method     {\initialparameter\c!method}%
136        continue   {\initialparameter\c!continue}%
137        distance   {\initialparameter\c!distance}%
138        hoffset    {\initialparameter\c!hoffset}%
139        voffset    \scratchvoffset
140        ma         \c_attr_colormodel
141        ca         \c_attr_color
142        ta         \c_attr_transparency
143        font       \fontid\font
144        glyphscale \glyphscale
145        dynamic    \font_dynamic_value % it's a bit over the top to support this here
146   \relax
147   \c_attr_initial\plusone
148   \initialparameter\c!text
149   \normalexpanded{\endgroup\c_initial_lines\the\scratchcounter}%
150   \enforced\glettonothing\typo_initial_handle
151   \ifconditional\c_initial_synchronize
152     \appendtoks \forgetinitial \to \everybeforepar
153   \fi}
154
155\lettonothing\typo_initial_handle % hook into everypar
156
157\permanent\protected\def\forgetinitial
158  {\ifcase\c_initial_lines\else
159     \begingroup
160     \advanceby\c_initial_lines-\prevgraf\relax
161     \ifcase\c_initial_lines\else
162       \obeydepth
163       \forgetall
164       \testpage[\the\c_initial_lines]%
165       \dorecurse\c_initial_lines{\nointerlineskip\hpack to \hsize{\strut}\par}%
166     \fi
167     \endgroup
168     \c_initial_lines\zerocount
169     \ifconditional\c_initial_synchronize
170       \removetoks \forgetinitial \from \everybeforepar
171     \fi
172  \fi}
173
174%D \starttyping
175%D \setupinitial[n=2,style=\tfd,location=text]
176%D \setuphead[chapter][after=\placeinitial]
177%D \enableexperiments[autoforgetinitials]
178%D
179%D \starttext
180%D   \chapter{Test me} Hello world!
181%D  %\forgetinitial \input tufte
182%D   \input tufte
183%D \stoptext
184%D \stoptyping
185
186% \enableexperiments[autoforgetinitials]
187
188\installtexexperiment
189   {autoforgetinitials}
190   {\c_initial_synchronize\conditionaltrue}
191   {\c_initial_synchronize\conditionalfalse}
192
193% \setupbodyfont[dejavu,9pt]
194%
195% \startbuffer
196% \setinitial[two]            D. E. Knuth   \ignorespaces\input knuth \par
197% \setinitial[two]                  Knuth   \ignorespaces\input knuth \par
198% \setinitial[two] \quotation{D. E. Knuth}  \ignorespaces\input knuth \par
199% \setinitial[two] \quotation      {Knuth}  \ignorespaces\input knuth \par
200% \setinitial[two]      [text={D.E. Knuth}] \ignorespaces\input knuth \par
201% \setinitial[two]       [m=4] D. E. Knuth  \ignorespaces\input knuth \par
202% \stopbuffer
203%
204% \type{m=2}                          \start \defineinitial[two][m=2,method=none]              \getbuffer \page \stop
205% \type{m=1,method=auto}              \start \defineinitial[two][m=1,method=auto]              \getbuffer \page \stop
206% \type{m=1,method={auto,first,last}} \start \defineinitial[two][m=1,method={first,auto,last}] \getbuffer \page \stop
207
208\protect \endinput
209