1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18\writestatus{loading}{ConTeXt Spacing Macros Paragraph Shapes}
19
20\registerctxluafile{typoshp}{autosuffix}
21
22\unprotect
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\installcorenamespace {parshapes}
48\installcorenamespace {shapedparagraph}
49
50\installbasicnativeautosetuphandler \??shapedparagraph {shapedparagraph}
51
52\setupshapedparagraph
53 [\c!method=,
54 \c!list=,
55 \c!lines=\zerocount,
56 \c!mp=,
57 \c!repeat=,
58 \c!hoffset=\zeropoint,
59 \c!voffset=\zeropoint,
60 \c!distance=\zeropoint]
61
62\permanent\protected\lettonothing\stopparagraphshape
63
64\permanent\protected\def\startparagraphshape[#1]#2\stopparagraphshape
65 {\gdefcsname\??parshapes#1\endcsname{#2}}
66
67\permanent\protected\def\rawparagraphshape#1
68 {\begincsname\??parshapes#1\endcsname}
69
70\permanent\protected\def\setparagraphshape[#1]
71 {\ifcsname\??parshapes#1\endcsname
72 \expandafter\clf_setparagraphshape\lastnamedcs done\relax
73 \fi}
74
75\def\spac_shapes_calculate#1
76 {\startMPcalculation \includeMPgraphic{#1} \stopMPcalculation}
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94\newbox\b_spac_shapes
95
96\def\spac_shapes_list
97 {\edef\p_mp {\shapedparagraphparameter\c!mp}
98 \edef\p_repeat{\shapedparagraphparameter\c!repeat}
99 \normalexpanded
100 {\endgroup
101 \ifempty\p_mp
102 \setparagraphshape[\shapedparagraphparameter\c!list]
103 \else
104 \setparagraphmetashape[\p_mp][\ifx\p_repeat\v!yes repeat\fi]
105 \fi
106 \pushparagraphtweak{\shapedparagraphparameter\c!method}\relax}}
107
108\def\spac_shapes_text
109 {\getnoflines{\dimexpr\htdp\b_spac_shapes\shapedparagraphparameter\c!voffset}
110 \normalexpanded
111 {\endgroup
112 \clf_setparagraphshape
113 left \the\dimexpr
114 \wd\b_spac_shapes\shapedparagraphparameter\c!distance
115 \shapedparagraphparameter\c!hoffset
116 \relax
117 right \zeropoint
118 copy \the\numexpr
119 \noflines
120 \shapedparagraphparameter\c!lines
121 \relax
122 left \zeropoint
123 right \zeropoint
124
125 done
126 \relax
127 \pushparagraphtweak{shift}
128 \dontleavehmode
129 \vtop
130 xoffset \the\dimexpr
131 \shapedparagraphparameter\c!distance
132 \wd\b_spac_shapes
133 \relax
134 yoffset \the\dimexpr
135 \shapedparagraphparameter\c!voffset
136 \strutht
137 \relax
138 {\smashbox\b_spac_shapes
139 \box\b_spac_shapes}}}
140
141\def\spac_shapes_lines
142 {\normalexpanded
143 {\endgroup
144 \clf_setparagraphshape
145 left \shapedparagraphparameter\c!width
146 right \zeropoint
147 copy \shapedparagraphparameter\c!lines
148 left \zeropoint
149 right \zeropoint
150
151 done
152 \relax
153 \pushparagraphtweak{shift}}}
154
155\permanent\protected\tolerant\def\startshapedparagraph[#S#1]
156 {\begingroup
157 \lettonothing\currentshapedparagraph
158 \setupshapedparagraph[#1]
159 \setlocalhsize
160 \ifempty{\shapedparagraphparameter\c!text}\else
161 \global\setbox\b_spac_shapes\vpack\bgroup
162 \forgetall
163 \shapedparagraphparameter\c!text
164 \egroup
165 \fi
166 \ifvoid\b_spac_shapes
167 \ifnum\shapedparagraphparameter\c!lines>\zerocount
168 \spac_shapes_lines
169 \else
170 \spac_shapes_list
171 \fi
172 \else
173 \spac_shapes_text
174 \fi
175 \ignorespaces}
176
177\permanent\protected\def\stopshapedparagraph
178 {\popparagraphtweak}
179
180
181
182\newbox \shapetextbox
183\newinteger\shapetextindex
184
185\permanent\protected\def\startshapetext[#S#1]
186 {\begingroup
187 \global\shapetextindex\zerocount
188 \global\setbox\shapetextbox\vbox\bgroup
189 \setparagraphmetashape[#1]
190 \forgetall
191 \dontcomplain
192 \setuptolerance[\v!verytolerant,\v!stretch]
193
194 \pushparagraphtweak{shift}}
195
196\permanent\protected\def\stopshapetext
197 {\popparagraphtweak
198 \egroup
199 \endgroup}
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227\permanent\protected\def\getshapetext
228 {\vbox\bgroup
229 \forgetall
230 \dontcomplain
231 \global\advanceby\shapetextindex\plusone
232 \scratchcounter\getshapeparameter{lines}\relax
233 \ifnum\scratchcounter>\zerocount
234 \scratchwidth \getshapeparameter{width}\scaledpoint\relax
235 \scratchheight \getshapeparameter{height}\scaledpoint\relax
236 \scratchhoffset\dimexpr\getshapeparameter{hoffset}\scaledpoint\relax
237 \scratchvoffset\dimexpr\getshapeparameter{voffset}\scaledpoint\relax
238 \setbox\scratchbox\vpack to \scratchheight
239 {\splittopskip\strutheight
240 \vskip\scratchvoffset
241 \ifcase\numexpr\getshapeparameter{first}\relax\else
242 \vskip\lineheight
243 \fi
244 \hskip\scratchhoffset
245 \hpack{\vsplit\shapetextbox to \scratchcounter\lineheight}}
246 \wd\scratchbox\dimexpr\scratchwidth \scratchhoffset\relax
247 \ht\scratchbox\dimexpr\scratchheight\scratchvoffset\relax
248 \dp\scratchbox\strutdp
249 \box\scratchbox
250 \else
251
252 \fi
253 \egroup}
254
255\protect
256 |