meta-imp-dum.mkiv /size: 6101 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=meta-dum,
3%D        version=2003.03.21,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=Dummy (External) Graphics,
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\unprotect
15
16%D This library overloads the normal external figure placeholder by a nicer one.
17%D
18%D \startbuffer
19%D \useMPlibrary[dum]
20%D
21%D \startlinecorrection
22%D \externalfigure[unknown-a][width=3cm,height=1cm]
23%D \stoplinecorrection
24%D
25%D \startlinecorrection
26%D \externalfigure[unknown-b][width=4cm,height=5cm]
27%D \stoplinecorrection
28%D \stopbuffer
29%D
30%D \typebuffer \getbuffer
31
32\startmkivmode
33
34%D Currently preparempvariables is unable to resolve number fractions like
35%D reduction.
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 (d/5 randomized (d/5))
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}] % weird, why do we need to prefix the palette
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%    \setuppalet[placeholder]%
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%D \starttyping
164%D \externalfigure[mediashow.swf][comment={Alas, we have no nice preview},background=figure:comment]
165%D \externalfigure[mediashow.swf][comment={Alas, we have no nice preview},background=figure:dummy]
166%D \externalfigure[mediashow.swf][background=figure:dummy]
167%D \stoptyping
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{meta-imp-dum.mkiv}
208
209\starttext
210
211    \externalfigure[whatever-missing]
212
213    \blank
214
215    \externalfigure[whatever-missing][width=2cm]
216
217\stoptext
218