grph-fig.mkiv /size: 13 Kb    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=grph-fig,
3%D        version=2006.08.26, % overhaul of 1997.03.31
4%D          title=\CONTEXT\ Graphic Macros,
5%D       subtitle=Figure Inclusion,
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 Used in the styledesign manual:
17%
18% beware in mkiv we don't have the typeset- prefix
19%
20% \setbuffer[typeset-b]\endbuffer
21% \setbuffer[typeset-a]\endbuffer
22%
23% todo:
24%
25% \appendtoks \setbuffer[typeset-b]\endbuffer\to \everystarttext
26% \appendtoks \setbuffer[typeset-a]\endbuffer\to \everystarttext
27
28% we could use \typesetbuffer[*] to access the last one
29
30\newconstant\c_grph_buffers_mode
31
32\let\lasttypesetbuffer\empty
33
34\unexpanded\def\typesetbuffer
35  {\bgroup
36   \setconstant\c_grph_buffers_mode\plusone
37   \dodoubleempty\grph_buffers_typeset}
38
39\unexpanded\def\typesetbufferonly
40  {\bgroup
41   \setconstant\c_grph_buffers_mode\zerocount
42   \dodoubleempty\grph_buffers_typeset}
43
44\def\grph_buffers_typeset[#1][#2]% beware: this will mix up the mp graphics
45  {\ifsecondargument
46     \grph_buffers_typeset_indeed[#1][#2]%
47   \else\iffirstargument
48     \doifelseassignment{#1}
49       {\grph_buffers_typeset_indeed[\jobname][#1]}%
50       {\grph_buffers_typeset_indeed[#1][]}%
51   \else
52     \grph_buffers_typeset_indeed[\jobname][]
53   \fi\fi}
54
55\def\grph_buffers_typeset_indeed[#1][#2]% we could use the via files
56  {\doifnot{#1}{*}{\xdef\lasttypesetbuffer{\clf_typesetbuffer{#1}}}%
57   \ifcase\c_grph_buffers_mode
58     % typesetonly
59   \or
60     \externalfigure[\lasttypesetbuffer][#2]%
61   \fi
62   \egroup}
63
64\unexpanded\def\runbuffer % for now
65  {\dotripleempty\grph_buffers_run_indeed}
66
67\def\grph_buffers_run_indeed[#1][#2]%
68  {\xdef\lasttypesetbuffer{\clf_runbuffer{#1}{#2}}}
69
70% For manuals and such:
71%
72% \definetypesetting [name] [options]   [settings-a]
73%
74% \typesetfile       [name] [file]      [settings-b]
75% \typesetfile       [file] [options]   [settings-b]
76% \typesetfile       [file] [settings-b]
77% \typesetfile       [file]
78%
79% \enabletrackers[files.run]
80% \starttext
81%     \typesetfile[oepsoeps.tex][width=10cm,frame=on]
82% \stoptext
83
84\installcorenamespace{typesettingfile}
85
86\unexpanded\def\definetypesetting{\dotripleempty\grph_typesetting_define}
87\unexpanded\def\typesetfile      {\dotripleempty\grph_typesetting_process}
88
89\def\grph_typesetting_define[#1][#2][#3]% <name> options settings-a
90  {\doifsomething{#1}{\setuvalue{\??typesettingfile#1}{\grph_typesetting_process_indeed{#2}{#3}}}}
91
92\def\grph_typesetting_process[#1][#2][#3]% <name> filename settings-b | filename options settings
93  {\ifcsname\??typesettingfile#1\endcsname
94     \lastnamedcs{#2}{#3}%
95   \else\ifthirdargument % filename options settings
96     \grph_typesetting_process_indeed{#2}{#3}{#1}{}%
97   \else\ifsecondargument % filename settings
98     \grph_typesetting_process_indeed{}{#2}{#1}{}%
99   \fi\fi\fi}
100
101\defineexternalfigure[typesetting] % so one can set a frame and such
102
103\def\grph_typesetting_process_indeed#1#2#3#4% options settings-a filename settings-b
104  {\begingroup
105   \edef\m_typesetting_name{\clf_runcontextjob{#3}{#1}}%
106   \ifx\m_typesetting_name\empty \else
107     \expanded{\externalfigure[\m_typesetting_name][typesetting]}[#2,#4]%
108   \fi
109   \endgroup}
110
111%D Whatever ... hardly used ... but historic ... needs checking ...
112%D will probably become m-fig-nn.mkiv .. or I will extend it cq. clean
113%D it up when I needed it. After all, it's documented in old manuals.
114
115\newcount\c_grph_steps_reference
116\newdimen\d_grph_steps_x
117\newdimen\d_grph_steps_y
118\newbox  \b_grph_steps_colorbar
119
120\let\placestopfigure\relax
121
122\unexpanded\def\placestartfigure[#1][#2][#3]#4\placestopfigure[#5]%
123  {\hpack
124     {\setbox\scratchbox\hpack
125        {\useexternalfigure[\s!dummy][#2][#3,#5]%
126         \externalfigure[\s!dummy]}%
127      \grph_steps_calculate
128      \startpositioning
129        \let\referring\grph_steps_one_referring
130        \let\marking  \grph_steps_one_marking
131        \let\remark   \grph_steps_one_remark
132        \let\colorbar \grph_steps_one_colorbar
133        \position(0,0){\box\scratchbox}%
134        \linewidth\onepoint
135        \setuppositioning
136          [\c!unit=pt,
137           \c!xscale=\withoutpt\the\d_grph_steps_x,
138           \c!yscale=\withoutpt\the\d_grph_steps_y,
139           \c!factor=1]%
140        \ignorespaces#4%
141        \let\referring\grph_steps_two_referring
142        \let\marking  \grph_steps_two_marking
143        \let\remark   \grph_steps_two_remark
144        \let\colorbar \grph_steps_two_colorbar
145        \ignorespaces#4%
146      \stoppositioning
147      \ifvoid\b_grph_steps_colorbar\else\box\b_grph_steps_colorbar\fi}} % not really needed
148
149\unexpanded\def\grph_steps_one_referring(#1,#2)#3(#4,#5)#6[#7]%
150  {\position(#1,#2){\grph_steps_goto(#4,#5){\externalfigureparameter\c!frames}[#7]}}
151
152\unexpanded\def\grph_steps_one_marking(#1,#2)#3(#4,#5)#6[#7]%
153  {\position(#1,#2){\grph_steps_this_is(#4,#5){\externalfigureparameter\c!frames}[#7]}}
154
155\unexpanded\def\grph_steps_one_remark(#1,#2)#3(#4,#5)%    (x,y)(h,b)[...]{tekst}
156  {\def\grph_steps_no_comment_indeed[##1]##2{}%
157   \dosingleempty\grph_steps_no_comment_indeed}
158
159\unexpanded\def\grph_steps_one_colorbar#1[#2]%
160  {}
161
162\unexpanded\def\grph_steps_two_referring(#1,#2)#3(#4,#5)#6[#7]%
163  {}
164
165\let\grph_steps_two_marking\grph_steps_two_referring
166
167\unexpanded\def\grph_steps_two_remark
168  {\grph_steps_comment\v!no}
169
170\unexpanded\def\grph_steps_two_colorbar#1[#2]
171  {\begingroup
172   \global\setbox\b_grph_steps_colorbar\vpack % \vbox ?
173     {\forgetall
174      \processcommalist[#2]\grph_colorbar_make_step}%
175   \global\setbox\b_grph_steps_colorbar\vpack
176     {\hskip2\emwidth\box\b_grph_steps_colorbar}%
177   \global\wd\b_grph_steps_colorbar\zeropoint
178   \endgroup}
179
180\unexpanded\def\grph_colorbar_make_step#1%
181  {\blackrule[\c!color=#1,\c!width=2\emwidth,\c!height=\exheight,\c!depth=\zeropoint]%
182   \endgraf}
183
184\unexpanded\def\startfigure % could be done nicer
185  {\grabuntil{\e!stop\v!figure}\grph_steps_figure_process}
186
187\let\stopfigure\relax
188
189\def\grph_steps_figure_process#1%
190  {\dotripleargument\grph_steps_figure_process_indeed#1\stopfigure}
191
192\def\grph_steps_figure_process_indeed[#1][#2][#3]#4\stopfigure
193  {\doifelse{\externalfigureparameter\c!option}\v!test
194     {\teststartfigure[#1][#2][#3]#4\teststopfigure
195      \letexternalfigureparameter\c!frames\v!on}
196     {\letexternalfigureparameter\c!frames\v!off}%
197   \setvalue{\??externalfigureinstance#1}%
198     {\dosingleempty{\placestartfigure[#1][#2][#3]#4\placestopfigure}}}
199
200\let\teststopfigure\relax
201
202\unexpanded\def\teststartfigure[#1][#2][#3]#4\teststopfigure
203  {\begingroup
204     \setbox\scratchbox\hpack
205       {\useexternalfigure[\s!dummy][#2][\c!wfactor=\v!max]%
206        \externalfigure[\s!dummy]}%
207     \let\referring\grph_steps_three_referring
208     \let\marking  \grph_steps_three_marking
209     \let\remark   \grph_steps_three_remark
210     \let\colorbar \grph_steps_three_colorbar
211     \c_grph_steps_reference\zerocount
212     \setbox0\vpack
213       {\hsize240\points
214        \startpositioning
215          \grph_steps_calculate
216          \position(0,0)
217            {\box\scratchbox}%
218          \position(0,0)
219            {\basegrid
220               [\c!nx=\externalfigureparameter\c!xmax,
221                \c!dx=\withoutpt\the\d_grph_steps_x,
222                \c!ny=\externalfigureparameter\c!ymax,
223                \c!dy=\withoutpt\the\d_grph_steps_y,
224                \c!xstep=1,
225                \c!ystep=1,
226                \c!scale=1,
227                \c!offset=\v!no,
228                \c!unit=pt]}%
229          \setuppositioning
230            [\c!unit=pt,
231             \c!xscale=\withoutpt\the\d_grph_steps_x,
232             \c!yscale=\withoutpt\the\d_grph_steps_y,
233             \c!factor=1]%
234          \linewidth\onepoint
235          \ignorespaces#4\relax
236        \stoppositioning
237        \vfill}%
238     \c_grph_steps_reference\zerocount
239     \let\referring\grph_steps_four_referring
240     \let\marking  \grph_steps_four_marking
241     \let\remark   \grph_steps_four_remark
242     \let\colorbar \grph_steps_four_colorbar
243     \setbox2\vbox % \vpack ?
244       {{\tfa\doifelsenothing{#1}{#2}{#1}}
245        \blank
246        \tfxx#4
247        \vfilll}%
248     \ifdim\ht0>\ht2
249       \ht2\ht0
250     \else
251       \ht0\ht2
252     \fi
253     \hpack
254       {\hskip3\emwidth
255        \tpack{\vskip12\points\box0\vskip6\points}%
256        \tpack{\vskip12\points\box2\vskip6\points}}%
257   \endgroup}
258
259\definesystemconstant {vwa}
260\definesystemconstant {vwb}
261
262\unexpanded\def\grph_steps_three_referring(#1,#2)#3(#4,#5)#6[#7]%
263  {\advance\c_grph_steps_reference\plusone
264   \position(#1,#2)
265     {\hbox{\the\c_grph_steps_reference}}%
266   \position(#1,#2)
267     {\gotosomeinternal\s!vwb{#7}\realfolio
268        {\grph_steps_marker(#4,#5)\v!on{\thisissomeinternal\s!vwa{#7}}}}}
269
270\unexpanded\def\grph_steps_three_remark
271  {\grph_steps_comment\v!yes}
272
273\let\grph_steps_three_marking \grph_steps_three_referring
274\let\grph_steps_three_colorbar\grph_steps_one_colorbar
275
276\unexpanded\def\grph_steps_four_referring
277  {\grph_steps_text{\normalstartimath\rightarrow\normalstopimath}}
278
279\unexpanded\def\grph_steps_four_marking
280  {\grph_steps_text{\normalstartimath\leftarrow\normalstopimath}}
281
282\let\grph_steps_four_remark  \grph_steps_one_remark
283\let\grph_steps_four_colorbar\grph_steps_one_colorbar
284
285% Helpers:
286
287\def\grph_steps_calculate
288  {\ifnum0\externalfigureparameter\c!xmax=\zerocount
289     \ifnum0\externalfigureparameter\c!ymax=\zerocount
290       \setexternalfigureparameter\c!ymax{24}%
291     \fi
292     \d_grph_steps_y\figureheight
293     \divide\d_grph_steps_y \externalfigureparameter\c!ymax
294     \d_grph_steps_x\d_grph_steps_y
295     \scratchdimen\figurewidth
296     \advance\scratchdimen\d_grph_steps_y
297     \divide \scratchdimen\d_grph_steps_y
298     \setexternalfigureparameter\c!xmax{\number\scratchdimen}%
299   \else
300     \d_grph_steps_x\figurewidth  \divide\d_grph_steps_x \externalfigureparameter\c!xmax\relax
301     \d_grph_steps_y\figureheight \divide\d_grph_steps_y \externalfigureparameter\c!ymax\relax
302   \fi}
303
304\def\grph_steps_comment#1(#2,#3)#4(#5,#6)%    {kader}(x,y)(h,b)[...]{tekst}
305  {\def\grph_steps_comment_indeed[##1]##2%
306     {\position(#2,#3)%
307        {\setnostrut
308         \framed
309           [\c!width=#5\d_grph_steps_x,
310            \c!height=#6\d_grph_steps_y,
311            \c!offset=\v!none,
312            \c!frame=#1,
313            ##1]%
314           {##2}}}%
315   \dosingleempty\grph_steps_comment_indeed}
316
317% \def\grph_steps_figure#1%
318%   {\position(0,0){\getvalue{#1}}}
319
320\def\grph_steps_goto(#1,#2)#3[#4]%    (h,b)kader[ref]
321  {\gotobox{\vpack{\grph_steps_area(#1,#2)#3{}}}[#4]}
322
323\def\grph_steps_text#1(#2,#3)#4(#5,#6)#7[#8]%
324  {\advance\c_grph_steps_reference\plusone
325   \hbox % \hpack ?
326     {\quad
327      \thisissomeinternal\s!vwb
328        {#8}%
329      \gotosomeinternal\s!vwa{#8}\realfolio
330        {\hbox to 1.5em{\the\c_grph_steps_reference\hfill}}%
331      \quad#1 (#2,#3) (#5,#6) [#8]\hfill}%
332   \endgraf}
333
334\def\grph_steps_this_is(#1,#2)#3[#4]%
335  {\grph_steps_area(#1,#2){#3}{\dosetdirectpagereference{#4}}}
336
337\def\grph_steps_area(#1,#2)#3#4% (h,b){kader}{tekst}
338  {\bgroup
339   \setnostrut
340   \framed
341     [\c!width=#1\d_grph_steps_x,
342      \c!height=#2\d_grph_steps_y,
343      \c!offset=\zeropoint,
344      \c!frame=#3]
345     {#4}%
346   \egroup}
347
348\def\grph_steps_marker(#1,#2)#3#4% (h,b){kader}{tekst}
349  {\framed
350     [\c!width=#1\d_grph_steps_x,
351      \c!height=#2\d_grph_steps_y,
352      \c!offset=\v!none,
353      \c!frame=#3]%
354     {#4}}
355
356\protect \endinput
357
358% \startbuffer
359% \definecolor [blue]   [c=1,m=.38,y=0,k=.64]
360% \definecolor [yellow] [c=0,m=.28,y=1,k=.06]
361%
362% \definespotcolor [blue-100]   [blue]   [p=1]
363% \definespotcolor [yellow-100] [yellow] [p=1]
364%
365% \definemultitonecolor [combicolor]   [blue=.12,yellow=.28] [c=.1,m=.1,y=.3,k=.1]
366%
367% \definemultitonecolor [combicolor-b] [blue=1]   [c=1,m=.38,y=0,k=.64] % force multitone
368% \definemultitonecolor [combicolor-y] [yellow=1] [c=0,m=.28,y=1,k=.06] % force multitone
369%
370% \useexternalfigure[demo-a][mill.png]     [object=no,width=.2\textwidth]
371% \useexternalfigure[demo-b][hacker-bw.jpg][object=no,width=.2\textwidth]
372%
373% \startbaselinecorrection \startcombination[4*1]
374%   {\externalfigure[demo-a]}                     {no color}
375%   {\externalfigure[demo-a][color=combicolor]}   {indexed duotone}
376%   {\externalfigure[demo-a][color=combicolor-b]} {spot color}
377%   {\externalfigure[demo-a][color=combicolor-y]} {spot color}
378% \stopcombination \stopbaselinecorrection
379%
380% \startbaselinecorrection \startcombination[4*1]
381%   {\externalfigure[demo-b]}                     {no color}
382%   {\externalfigure[demo-b][color=combicolor]}   {indexed duotone}
383%   {\externalfigure[demo-b][color=combicolor-b]} {spot color}
384%   {\externalfigure[demo-b][color=combicolor-y]} {spot color}
385% \stopcombination \stopbaselinecorrection
386%
387% \startbaselinecorrection \startcombination[4*1]
388%   {\externalfigure[demo-a]}                     {no color}
389%   {\externalfigure[demo-a][color=combicolor]}   {indexed duotone}
390%   {\externalfigure[demo-a][color=blue-100]}     {spot color}
391%   {\externalfigure[demo-a][color=yellow-100]}   {spot color}
392% \stopcombination \stopbaselinecorrection
393%
394% \startbaselinecorrection \startcombination[4*1]
395%   {\externalfigure[demo-b]}                     {no color}
396%   {\externalfigure[demo-b][color=combicolor]}   {indexed duotone}
397%   {\externalfigure[demo-b][color=blue-100]}     {spot color}
398%   {\externalfigure[demo-b][color=yellow-100]}   {spot color}
399% \stopcombination \stopbaselinecorrection
400% \stopbuffer
401%
402% \getbuffer \typebuffer
403