1
2
3
4
5
6
7
8
9
10
11
12
13
14\unprotect
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32\startmkivmode
33
34
35
36
37 \startuseMPgraphic{minifun::figure:placeholder}{width,height,reduction,color}
38 begingroup ;
39 save w, h, d, r, p, c, b ;
40 numeric w, h, d, r ; path p ;
41 if cmykcolor \MPvar{color} :
42 cmykcolor c, b ; b := (0,0,0,0)
43 else :
44 color c, b ; b := (1,1,1)
45 fi ;
46 c := \MPvar{color} ;
47 w := \MPvar{width} ;
48 h := \MPvar{height} ;
49 r := \MPvar{reduction} ;
50 d := max(w,h) ;
51 p := unitsquare xyscaled (w,h) ;
52 fill p withcolor r[.5c,b] ;
53 for i := 1 upto 60 :
54 fill fullcircle
55 scaled (d5 randomized (d5))
56 shifted (center p randomized (d))
57 withcolor r[c randomized(.3,.9),b] ;
58 endfor ;
59 clip currentpicture to p ;
60 endgroup ;
61 \stopuseMPgraphic
62
63 \defineoverlay
64 [figure:placeholder:graphic]
65 [\useMPgraphic
66 {minifun::figure:placeholder}
67 {width=\figurewidth,
68 height=\figureheight,
69 reduction=\externalfigureparameter\c!reduction,
70 color=placeholder:\the\c_grph_replacement_n}]
71
72\stopmkivmode
73
74\startlmtxmode
75
76 \defineMPparameterset
77 [placeholder]
78 [width=dimension,
79 height=dimension,
80 reduction=number,
81 color=string,
82 alternative=string]
83
84 \defineoverlay
85 [figure:placeholder:graphic]
86 [{\useMPmacro
87 [minifun]
88 [placeholder]
89 [width=\figurewidth,
90 height=\figureheight,
91 alternative=\externalfigureparameter\c!alternative,
92 reduction=\externalfigureparameter\c!reduction,
93 color=placeholder:\the\c_grph_replacement_n]}]
94
95\stoplmtxmode
96
97\definepalet
98 [placeholder]
99 [1=red,2=green,3=blue,4=cyan,5=magenta,6=yellow]
100
101\newinteger\c_grph_replacement_n
102
103\setupexternalfigures
104 [\c!reduction=0,
105 \c!text=\v!yes]
106
107\let\grph_include_replacement_saved\grph_include_replacement
108
109\unexpanded\def\grph_include_replacement#1#2#3
110 {\begingroup
111
112 \getpaletsize[placeholder]
113 \ifnum\c_grph_replacement_n=\zerocount
114 \getrandomnumber\m_grph_replacement_n\plusone\paletsize
115 \global\c_grph_replacement_n\m_grph_replacement_n\relax
116 \else
117 \global\advance\c_grph_replacement_n\plusone
118 \fi
119 \ifnum\c_grph_replacement_n>\paletsize
120 \global\c_grph_replacement_n\plusone
121 \fi
122 \setupcurrentexternalfigure
123 [\c!width=\figurewidth,
124 \c!height=\figureheight,
125 \c!frame=\v!off,
126 \c!strut=\v!no,
127 \c!align={\v!middle,\v!lohi},
128 \c!background=figure:placeholder:graphic,
129 \c!foregroundcolor=\s!white]
130 \doifelse{\externalfigureparameter\c!text}\v!yes
131 {\edef\m_graphics_text_a{#1}\edef\m_graphics_text_a{\ifx\m_graphics_text_a\s!dummy\else\detokenize\expandafter{\m_graphics_text_a}\fi}
132 \edef\m_graphics_text_b{#2}\edef\m_graphics_text_b{\ifx\m_graphics_text_b\s!dummy\else\detokenize\expandafter{\m_graphics_text_b}\fi}
133 \edef\m_graphics_text_c{#3}\edef\m_graphics_text_c{\ifx\m_graphics_text_c\s!dummy\else\detokenize\expandafter{\m_graphics_text_c}\fi}
134 \infofont\setupinterlinespace\dohyphens
135 \inheritedexternalfigureframed{\directsetup{figure:placeholder:text}}}
136 {\inheritedexternalfigureframed{}}
137 \endgroup}
138
139\unexpanded\def\dummyfigure
140 {\externalfigure[placeholder]}
141
142\startsetups figure:placeholder:text
143 \ifx\m_graphics_text_a\empty\else
144 \strut name: \m_graphics_text_a\par
145 \fi
146 \ifx\m_graphics_text_b\empty\else
147 \strut
148 \ifx\m_graphics_text_a\empty
149 \ifx\m_graphics_text_c\empty
150 \else
151 file:\space
152 \fi
153 \else
154 file:\space
155 \fi
156 \m_graphics_text_b\par
157 \fi
158 \ifx\m_graphics_text_c\empty\else
159 \strut state: \m_graphics_text_c\par
160 \fi
161\stopsetups
162
163
164
165
166
167
168
169\defineframed
170 [figurecomment]
171 [\c!background=\v!color,
172 \c!backgroundcolor=\s!gray,
173 \c!frame=\v!off,
174 \c!foregroundstyle=\ttbf,
175 \c!align={\v!middle,\v!lohi},
176 \c!height=\figureheight,
177 \c!width=\figurewidth]
178
179\defineframed
180 [figuredummy]
181 [\c!background=figure:dummy:only,
182 \c!foregroundcolor=\s!white,
183 \c!backgroundcolor=\v!gray,
184 \c!frame=\v!off,
185 \c!foregroundstyle=\ttbf,
186 \c!align={\v!middle,\v!lohi},
187 \c!height=\figureheight,
188 \c!width=\figurewidth]
189
190\defineoverlay
191 [figure:dummy:only]
192 [\grph_include_replacement\empty\empty\empty]
193
194\defineoverlay
195 [figure:comment]
196 [\figurecomment{\externalfigureparameter\c!comment}]
197
198\defineoverlay
199 [figure:dummy]
200 [\figuredummy{\externalfigureparameter\c!comment}]
201
202\setupexternalfigures
203 [\c!comment=]
204
205\protect
206
207\continueifinputfile{metaimpdum.mkiv}
208
209\starttext
210
211 \externalfigure[whatevermissing]
212
213 \blank
214
215 \externalfigure[whatevermissing][width=2cm]
216
217\stoptext
218 |