1
2
3
4
5
6
7
8
9
10
11
12
13
14\unprotect
15
16\definepalet
17 [fakerule]
18 [fr1c=darkred,
19 fr2c=darkgreen,
20 fr3c=darkblue,
21 fr4c=darkyellow,
22 fr5c=darkgray,
23 fr6c=darkred,
24 fr7c=darkgreen,
25 fr8c=darkblue,
26 fr9c=darkyellow,
27 fr0c=darkgray]
28
29\installcorenamespace {simulatewords}
30
31\installcommandhandler \??simulatewords {simulatewords} \??simulatewords
32
33\setupsimulatewords
34 [\c!n =\plusten,
35 \c!m =40,
36 \c!min =\plusone,
37 \c!max =\plusfive,
38 \c!minwidth=0.50\emwidth,
39 \c!maxwidth=1.25\emwidth,
40 \c!color =\empty,
41 \c!hyphen =\v!yes,
42 \c!distance=.2\onebasepoint]
43
44\unexpanded\def\dosimulatedword
45 {\clf_fakeword
46 factor \exheight
47 name {\p_line}
48 min \scratchdimenone
49 max \scratchdimentwo
50 \relax}
51
52\def\simulatedhyphen
53 {\kern.2\points\kern.2\points}
54
55\unexpanded\def\simulatewords
56 {\dodoubleempty\dosimulatewords}
57
58\unexpanded\def\dosimulatewords[#1][#2]
59 {\dontleavehmode
60 \begingroup
61 \begstrut
62 \ifsecondargument
63 \edef\currentsimulatewords{#1}
64 \setupcurrentsimulatewords[#2]
65 \else
66 \doifassignmentelse{#1}
67 {\let\currentsimulatewords\empty
68 \setupcurrentsimulatewords[#1]}
69 {\edef\currentsimulatewords{#1}
70 \setupcurrentsimulatewords[#2]}
71 \fi
72 \scratchcounterone\simulatewordsparameter\c!n
73 \scratchcountertwo\simulatewordsparameter\c!m
74 \scratchmin \simulatewordsparameter\c!min
75 \scratchmax \simulatewordsparameter\c!max
76 \scratchdimenone \simulatewordsparameter\c!minwidth
77 \scratchdimentwo \simulatewordsparameter\c!maxwidth
78 \scratchdimenthree\simulatewordsparameter\c!distance
79 \edef\p_random{\simulatewordsparameter\c!random}
80 \edef\p_color {\simulatewordsparameter\c!color}
81 \edef\p_line {\simulatewordsparameter\c!line}
82 \edef\p_hyphen{\simulatewordsparameter\c!hyphen}
83 \edef\p_line {fake:\ifx\p_line\v!yes word\else rule\fi}
84 \ifx\p_color\v!text
85
86 \else
87 \setuppalet[fakerule]
88 \ifx\p_color\empty
89 \directcolored[fakerulecolor]
90 \else\ifx\p_color\v!auto
91
92 \else
93 \directcolored[\p_color]
94 \fi\fi
95 \fi
96 \edef\p_hyphen
97 {\ifx\p_hyphen\v!yes
98 \discretionary{\bf\simulatedhyphen}{}{\kern\scratchdimenthree}
99 \else\ifx\p_hyphen\v!margin
100 \discretionary{\hpack to \zeropoint{\bf\simulatedhyphen\hss}}{}{\kern\scratchdimenthree}
101 \else\ifx\p_hyphen\v!none
102 \allowbreak\kern\scratchdimenthree
103 \else\ifx\p_hyphen\v!no
104 \allowbreak\kern\scratchdimenthree
105 \else\ifx\p_hyphen\v!both
106 \discretionary{\bf\simulatedhyphen}{\bf\simulatedhyphen}{\kern\scratchdimenthree}
107 \else\ifx\p_hyphen\empty
108 \allowbreak\kern\scratchdimenthree
109 \else
110 \discretionary{\p_hyphen}{}{\kern\scratchdimenthree}
111 \fi\fi\fi\fi\fi\fi}
112 \def\truncated##1##2\relax{##1}
113
114 \ifx\p_random\empty \else
115 \pushrandomseed
116 \setrandomseed\p_random
117 \fi
118 \dorecurse{\randomnumber\scratchcounterone\scratchcountertwo} {
119 \let\dosimulatedhyphen\relax
120 \dorecurse{\randomnumber\scratchmin\scratchmax} {
121 \dosimulatedhyphen
122 \begingroup
123 \ifx\p_color\v!auto
124 \directcolored[fr\truncated####1\relax c]
125 \fi
126 \dosimulatedword
127 \endgroup
128 \let\dosimulatedhyphen\p_hyphen
129 }
130 \relax
131 \space
132 }
133 \ifx\p_random\empty \else
134 \poprandomseed
135 \fi
136 \removeunwantedspaces
137 \endstrut
138 \endgroup}
139
140
141
142\unexpanded\def\fakewords#1#2
143 {\simulatewords[\c!n=#1,\c!m=#2,\c!min=1,\c!max=5,\c!hyphen=\v!none,\c!color=\v!text,\c!line=\v!yes]}
144
145
146
147\unexpanded\def\fakeline
148 {\dosingleempty\dofakeline}
149
150\unexpanded\def\dofakeline[#1]
151 {\par
152 \dontleavehmode
153 \hpack\bgroup
154 \scratchwidth \availablehsize
155 \scratchheight.8\strutht
156 \scratchdepth .8\strutdp
157 \iffirstargument
158 \letsimulatewordsparameter\c!width \scratchwidth
159 \letsimulatewordsparameter\c!height\scratchheight
160 \letsimulatewordsparameter\c!depth \scratchdepth
161 \getcurrentsimulatewords[#1]
162 \scratchwidth \simulatewordsparameter\c!width
163 \scratchheight\simulatewordsparameter\c!height
164 \scratchdepth \simulatewordsparameter\c!depth
165 \fi
166 \edef\p_color{\simulatewordsparameter\c!color}
167 \begingroup
168 \ifx\p_color\empty
169 \directcolored[fakerulecolor]
170 \else\ifx\p_color\v!auto
171
172 \else
173 \directcolored[\p_color]
174 \fi\fi
175 \vrule
176 \s!width \scratchwidth
177 \s!height\scratchheight
178 \s!depth \scratchdepth
179 \endgroup
180 \hskip\scratchwidth
181 \directcolored[\s!white]
182 \scratchdimen.5\onepoint
183 \vrule
184 \s!width \scratchwidth
185 \s!height\scratchdimen
186 \s!depth \scratchdimen
187 \egroup
188 \par}
189
190\protect
191
192\continueifinputfile{msimulate.mkiv}
193
194\starttext
195
196 \simulatewords[n=50,m=100,min=1,max=5,color=auto,hyphen=margin,line=yes]\par
197 \simulatewords[n=50,m=100,min=3,max=9,color=auto,hyphen=margin,line=yes]\par
198 \simulatewords[n=50,m=100,min=3,max=9,color=auto,hyphen=margin,line=yes]\par
199 \page
200 \simulatewords[n=50,m=100,min=2,max=6,hyphen=yes]\par
201 \simulatewords[n=50,m=100,min=2,max=6,hyphen=both]\par
202 \simulatewords[n=50,m=100,min=2,max=6,hyphen=both]\par
203
204 \startcolor[red]
205 \simulatewords[n=50,m=100,min=2,max=6,color=text]\par
206 \stopcolor
207
208 \definesimulatewords[foo][n=50,m=100,min=2,max=6,color=text]
209
210 \startcolor[green]
211 \simulatewords[foo][color=darkyellow,random=1234]
212 \stopcolor
213
214 \page
215
216 \fakeline
217
218 \startnarrower
219 \fakeline
220 \stopnarrower
221
222\stoptext
223 |