typo-drp.mkiv /size: 4543 b    last modification: 2021-10-28 13:50
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}{}
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
29%D parameters shown in the example you can use the \type {style} and
30%D more low level \type {font} keys to set up the font where
31%D the first one wins. If you don't like the behaviour you can always
32%D roll out your own command.
33%D
34%D \starttyping
35%D \placeinitial \input ward \par \input ward \par \placeinitial \input tufte
36%D
37%D \setupinitial
38%D   [location=text,
39%D    n=2,
40%D    color=darkred,
41%D    distance=-1em,
42%D    hoffset=1em,
43%D    voffset=-3ex,
44%D    before=\blank]
45%D
46%D \placeinitial \input ward \par \input ward \placeinitial \input tufte
47%D \stoptyping
48
49% todo: angle (once we can set parshape at the Lua end)
50
51\installcorenamespace{initial}
52
53\installcommandhandler \??initial {initial} \??initial
54
55\definemeasure[initial:n][\lineheight*\initialparameter\c!n - \strutdp]
56
57\setupinitial
58  [\c!location=\v!text,
59   \c!n=3,
60   \c!m=1,
61   \c!method=\v!none,
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\unexpanded\def\placeinitial % we cannot group so no settings
73  {\dosingleempty\typo_initials_place}
74
75\def\typo_initials_place[#1]% old command
76  {\par
77   \namedinitialparameter{#1}\c!before
78   \setinitial[#1]\relax}
79
80\unexpanded\def\setinitial
81  {\dodoubleempty\typo_initials_set}
82
83\unexpanded\def\typo_initials_set[#1][#2]%
84  {\edef\typo_initial_handle{\typo_initial_handle_indeed{#1}{#2}}}
85
86\unexpanded\def\typo_initial_handle_indeed#1#2%
87  {\dontleavehmode
88   \begingroup
89   \edef\currentinitial{#1}%
90   \setupcurrentinitial[#2]%
91   \resetfontfeature % might be needed in more places
92   \doifelsenothing{\initialparameter\c!style}
93     {\definedfont[\initialparameter\c!font]}
94     {\useinitialstyleparameter\c!style}%
95   \useinitialcolorparameter\c!color
96   \edef\p_voffset{\initialparameter\c!voffset}%
97   \scratchcounter \initialparameter\c!n\relax
98   \scratchvoffset\dimexpr\ifx\p_voffset\v!line\scratchcounter\lineheight-\lineheight\else\p_voffset\fi\relax
99   \clf_setinitial
100        location  {\initialparameter\c!location}%
101        enabled   true\space
102        n         \scratchcounter
103        m         \numexpr\initialparameter\c!m\relax
104        method    {\initialparameter\c!method}%
105        distance  \dimexpr\initialparameter\c!distance\relax
106        hoffset   \dimexpr\initialparameter\c!hoffset\relax
107        voffset   \scratchvoffset
108        ma        \c_attr_colormodel
109        ca        \c_attr_color
110        ta        \c_attr_transparency
111        font      \fontid\font
112        dynamic   \font_dynamic_value % it's a bit over the top to support this here
113   \relax
114   \c_attr_initial\plusone
115   \initialparameter\c!text
116   \endgroup
117   \glet\typo_initial_handle\relax}
118
119\let\typo_initial_handle\relax
120
121% \setupbodyfont[dejavu,9pt]
122%
123% \startbuffer
124% \setinitial[two]            D. E. Knuth   \ignorespaces\input knuth \par
125% \setinitial[two]                  Knuth   \ignorespaces\input knuth \par
126% \setinitial[two] \quotation{D. E. Knuth}  \ignorespaces\input knuth \par
127% \setinitial[two] \quotation      {Knuth}  \ignorespaces\input knuth \par
128% \setinitial[two]      [text={D.E. Knuth}] \ignorespaces\input knuth \par
129% \setinitial[two]       [m=4] D. E. Knuth  \ignorespaces\input knuth \par
130% \stopbuffer
131%
132% \type{m=2}                          \start \defineinitial[two][m=2,method=none]              \getbuffer \page \stop
133% \type{m=1,method=auto}              \start \defineinitial[two][m=1,method=auto]              \getbuffer \page \stop
134% \type{m=1,method={auto,first,last}} \start \defineinitial[two][m=1,method={first,auto,last}] \getbuffer \page \stop
135
136\protect \endinput
137