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 \todimension{
114 \wd\b_spac_shapes
115 (\shapedparagraphparameter\c!distance)
116 (\shapedparagraphparameter\c!hoffset)
117 }
118 right \zeropoint
119 copy \tointeger{
120 \noflines
121 (\shapedparagraphparameter\c!lines)
122 }
123 left \zeropoint
124 right \zeropoint
125
126 done
127 \relax
128 \pushparagraphtweak{shift}
129 \dontleavehmode
130 \vtop
131 \s!xoffset \todimension{
132 \zeropoint
133 (\shapedparagraphparameter\c!distance)
134 \wd\b_spac_shapes
135 }
136 \s!yoffset \todimension{
137 (\shapedparagraphparameter\c!voffset)
138 \strutht
139 }
140 {\smashbox\b_spac_shapes
141 \box\b_spac_shapes}}}
142
143\def\spac_shapes_lines
144 {\normalexpanded
145 {\endgroup
146 \clf_setparagraphshape
147 left \todimension{\shapedparagraphparameter\c!width}
148 right \zeropoint
149 copy \tointeger{\shapedparagraphparameter\c!lines}
150 left \zeropoint
151 right \zeropoint
152
153 done
154 \relax
155 \pushparagraphtweak{shift}}}
156
157\permanent\protected\tolerant\def\startshapedparagraph[#S#1]
158 {\begingroup
159 \lettonothing\currentshapedparagraph
160 \setupshapedparagraph[#1]
161 \setlocalhsize
162 \ifempty{\shapedparagraphparameter\c!text}\else
163 \global\setbox\b_spac_shapes\vpack\bgroup
164 \forgetall
165 \shapedparagraphparameter\c!text
166 \egroup
167 \fi
168 \ifvoid\b_spac_shapes
169 \ifnum{\shapedparagraphparameter\c!lines}>\zerocount
170 \spac_shapes_lines
171 \else
172 \spac_shapes_list
173 \fi
174 \else
175 \spac_shapes_text
176 \fi
177 \ignorespaces}
178
179\permanent\protected\def\stopshapedparagraph
180 {\popparagraphtweak}
181
182
183
184\newbox \shapetextbox
185\newinteger\shapetextindex
186
187\permanent\protected\def\startshapetext[#S#1]
188 {\begingroup
189 \global\shapetextindex\zerocount
190 \global\setbox\shapetextbox\vbox\bgroup
191 \setparagraphmetashape[#1]
192 \forgetall
193 \dontcomplain
194 \setuptolerance[\v!verytolerant,\v!stretch]
195
196 \pushparagraphtweak{shift}}
197
198\permanent\protected\def\stopshapetext
199 {\popparagraphtweak
200 \egroup
201 \endgroup}
202
203\permanent\protected\def\getshapetext
204 {\vbox\bgroup
205 \forgetall
206 \dontcomplain
207 \global\advanceby\shapetextindex\plusone
208 \scratchcounter\getshapeparameter{lines}\relax
209 \ifnum\scratchcounter>\zerocount
210 \scratchwidth {\getshapeparameter{width}\scaledpoint}
211 \scratchheight {\getshapeparameter{height}\scaledpoint}
212 \scratchhoffset{\getshapeparameter{hoffset}\scaledpoint}
213 \scratchvoffset{\getshapeparameter{voffset}\scaledpoint}
214 \setbox\scratchbox\vpack to \scratchheight
215 {\splittopskip\strutheight
216 \vskip\scratchvoffset
217 \ifcase{\getshapeparameter{first}}\else
218 \vskip\lineheight
219 \fi
220 \hskip\scratchhoffset
221 \hpack{\vsplit\shapetextbox to \scratchcounter\lineheight}}
222 \wd\scratchbox{\scratchwidth \scratchhoffset}
223 \ht\scratchbox{\scratchheight\scratchvoffset}
224 \dp\scratchbox\strutdp
225 \box\scratchbox
226 \else
227
228 \fi
229 \egroup}
230
231\protect
232 |