%D \module %D [ file=grph-fig, %D version=2006.08.26, % overhaul of 1997.03.31 %D title=\CONTEXT\ Graphic Macros, %D subtitle=Figure Inclusion, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. % ex => ef with proper parent \writestatus{loading}{ConTeXt Graphic Macros / Figure Handling} \unprotect \installcorenamespace{externalfigureinstance} \installcorenamespace{externalfigurecollection} \newtoks\everysetupexternalfigures % todo: command handler \unexpanded\def\setupexternalfigures {\dosingleempty\dosetupexternalfigures} \def\dosetupexternalfigures[#1]% {\getparameters[\??ef][#1]% local settings \getparameters[\??ex][#1]% global settings \the \everysetupexternalfigures} \appendtoks \setfigurepathlist % the path may be used elsewhere too (as in x-res-04) \to \everysetupexternalfigures \appendtoks \ctxcommand{setfigurelookuporder("\@@exorder")}% \to \everysetupexternalfigures \presetlocalframed[\??ef] \newconditional\externalfigurelevel % true=background false=normal \newconditional\externalfigureflush % true=place false=ignore \setfalse\externalfigurelevel \settrue \externalfigureflush \def\doplaceexternalfigure[#1][#2][#3][#4][#5]% {\doifsomething{#2}% catches \defineexternalfigure dummies {\ifcsname\??externalfigureinstance#2\endcsname \doifelse{#1}{#2} {\dodoplaceexternalfigure[#1][#2][#3][#4][#5]} {\getvalue{\??externalfigureinstance#2}[#5]}% \else \dodoplaceexternalfigure[#1][#2][#3][#4][#5]% \fi}} \ifdefined\dotagfigure \else \let\dotagfigure\relax \fi \def\dodoplaceexternalfigure[#1][#2][#3][#4][#5]% {\bgroup \dostarttagged\t!image\empty \let\textunderscore\letterunderscore % {\string _} % space needed as _ is now letter in unprotected mode \calculateexternalfigure[][#1][#2][#3][#4][#5]% [] is dummy dwcomp \dotagfigure \naturalvbox attr \imageattribute 2 {\box\foundexternalfigure}% \dostoptagged \egroup} \def\externalfigurereplacement#1#2#3% {\normalexpanded{\localframed [\??ef] [\c!width=\figurewidth, \c!height=\figureheight, \c!background=\v!color, \c!backgroundcolor=missingfigurecolor, \c!frame=\@@efframe]}% we need to expand this in order to prevent a loop {\tt\tfxx \nohyphens name: \expanded{\verbatimstring{#1}}\\% file: \expanded{\verbatimstring{#2}}\\% state: \expanded{\verbatimstring{#3}}}} \definecolor[missingfigurecolor][s=.8] \def\externalfigureplaceholder#1#2#3% {\localframed [\??ef] [\c!width=#2, \c!height=#3, \c!frame=\v!on]% {\tt\tfxx \nohyphens name: \expanded{\verbatimstring{#1}}\\% state: \expanded{\verbatimstring{placeholder}}}} % new: more convenient/efficient than % % \use..[a][a][setting] \externalfigure[b][a] % % is equivalent to: % % \def..[a][setting] \externalfigure[b][a] % % see x-res modules for usage: % % \defineexternalfigure[name][settings] \unexpanded\def\defineexternalfigure {\dodoubleargument\dodefineexternalfigure} \def\dodefineexternalfigure[#1][#2]% {\setvalue{\??externalfigureinstance#1}{\doplaceexternalfigure[#1][][][#2]}} % \useexternalfigure[alpha][koe] % \useexternalfigure[beta] [koe] [breedte=1cm] % \useexternalfigure[gamma][koe][alpha] % \useexternalfigure[delta][koe][alpha][breedte=2cm] % % volle breedte: \externalfigure[koe] \par % 3cm breed: \externalfigure[koe] [breedte=3cm] \par % volle breedte: \externalfigure[alpha] \par % 1cm breed: \externalfigure[beta] \par % volle breedte: \externalfigure[gamma] \par % 2cm breed: \externalfigure[delta] \par % 4cm breed: \externalfigure[beta] [breedte=4cm] \par % 5cm breed: \externalfigure[gamma][breedte=5cm] \par % \defineexternalfigure[a][width=10cm] % \defineexternalfigure[b][width=5cm] % \externalfigure[cow][a] % \externalfigure[cow][b][height=8cm] % \useexternalfigure[x][cow][width=10cm,height=1cm] % \externalfigure[x] % \externalfigure[x][width=3cm] % % [label] [filename] % [label] [filename] [parent] % [label] [filename] [parent] [settings] % [label] [filename] [settings] \def\useexternalfigure {\doquadrupleempty\douseexternalfigure} \def\douseexternalfigure[#1][#2][#3][#4]% {\doifelsenothing{#1} {\doifsomething{#2} {\doifassignmentelse{#3} {\dodouseexternalfigure{#2}{#2}{#3}{#4}} {\dodouseexternalfigure{#2}{#2}{}{#4}}}} {\doifelsenothing{#2} {\doifassignmentelse{#3} {\dodouseexternalfigure{#1}{#1}{}{#3}} {\dodouseexternalfigure{#1}{#1}{#3}{#4}}} {\doifassignmentelse{#3} {\dodouseexternalfigure{#1}{#2}{}{#3}} {\dodouseexternalfigure{#1}{#2}{#3}{#4}}}}} \def\dodouseexternalfigure#1#2#3#4% {\setvalue{\??externalfigureinstance#1}{\doplaceexternalfigure[#1][#2][#3][#4]}% \doanalyzeexternalfigurecollection[#2][#4]} \newconditional\inexternalfigurecollection \newdimen\xexternalfigurecollectionminwidth \newdimen\xexternalfigurecollectionmaxwidth \newdimen\xexternalfigurecollectionminheight \newdimen\xexternalfigurecollectionmaxheight \def\doanalyzeexternalfigurecollection[#1][#2]% {\ifconditional\inexternalfigurecollection \setfalse\inexternalfigurecollection \getfiguredimensions[#1][#2]% \settrue\inexternalfigurecollection \scratchdimen\naturalfigurewidth \ifdim\scratchdimen>\xexternalfigurecollectionmaxwidth \xexternalfigurecollectionmaxwidth \scratchdimen \fi \ifdim\scratchdimen<\xexternalfigurecollectionminwidth \xexternalfigurecollectionminwidth \scratchdimen \fi \scratchdimen\naturalfigureheight \ifdim\scratchdimen>\xexternalfigurecollectionmaxheight \xexternalfigurecollectionmaxheight\scratchdimen \fi \ifdim\scratchdimen<\xexternalfigurecollectionminheight \xexternalfigurecollectionminheight\scratchdimen \fi \fi} \unexpanded\def\startexternalfigurecollection[#1]% {\begingroup \def\currentexternalfigurecollection{#1}% \settrue\inexternalfigurecollection \xexternalfigurecollectionminwidth \maxdimen \xexternalfigurecollectionmaxwidth \zeropoint \xexternalfigurecollectionminheight\maxdimen \xexternalfigurecollectionmaxheight\zeropoint} \unexpanded\def\stopexternalfigurecollection {\setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!minwidth }{\the\xexternalfigurecollectionminwidth }% \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!maxwidth }{\the\xexternalfigurecollectionmaxwidth }% \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!minheight}{\the\xexternalfigurecollectionminheight}% \setxvalue{\??externalfigurecollection\currentexternalfigurecollection:\c!maxheight}{\the\xexternalfigurecollectionmaxheight}% \endgroup} \def\externalfigurecollectionparameter#1#2% {\csname \ifcsname\??externalfigurecollection#1:#2\endcsname \??externalfigurecollection#1:#2% \else \s!empty \fi \endcsname} \def\externalfigurecollectionminwidth #1{\externalfigurecollectionparameter{#1}\c!minwidth } \def\externalfigurecollectionmaxwidth #1{\externalfigurecollectionparameter{#1}\c!maxwidth } \def\externalfigurecollectionminheight#1{\externalfigurecollectionparameter{#1}\c!minheight} \def\externalfigurecollectionmaxheight#1{\externalfigurecollectionparameter{#1}\c!maxheight} \let\efcparameter\externalfigurecollectionparameter \let\efcminwidth \externalfigurecollectionminwidth \let\efcmaxwidth \externalfigurecollectionmaxwidth \let\efcminheight\externalfigurecollectionminheight \let\efcmaxheight\externalfigurecollectionmaxheight % \startexternalfigurecollection[name] % \useexternalfigure[cow] [cow.pdf] % \useexternalfigure[mill][mill.png] % \stopexternalfigurecollection % \starttext % \bTABLE % \bTR % \bTD \externalfigure[cow] [height=\externalfigurecollectionmaxheight{name}] \eTD % \bTD \externalfigure[mill][height=\externalfigurecollectionmaxheight{name}] \eTD % \eTR % \eTABLE % \stoptext \def\dosetefparameters#1#2#3% parent_id use_settings current_settings {\doifelsenothing{#1} % inherit from parent {\getparameters[\??ef][#2,#3]} {\ifcsname\??externalfigureinstance#1\endcsname \pushmacro\doplaceexternalfigure \def\doplaceexternalfigure[##1][##2][##3][##4]{\getparameters[\??ef][##4,#2,#3]}% \getvalue{\??externalfigureinstance#1}% \popmacro\doplaceexternalfigure \else \getparameters[\??ef][#2,#3]% \fi}} \unexpanded\def\externalfigure {\dotripleempty\doexternalfigure} \def\doexternalfigure[#1][#2][#3]% [label][file][settings] | [file][settings] | [file][parent][settings] {\bgroup % also catched #1 == empty ... scales nicer now \ifcsname\??externalfigureinstance#1\endcsname \doifassignmentelse{#2} {\getvalue{\??externalfigureinstance#1}[#2]}% {\getvalue{\??externalfigureinstance#1}[#3]}% \else \useexternalfigure[\s!dummy][#1][#2][#3]% \getvalue{\??externalfigureinstance\s!dummy}[]% [] is dummy arg 5 \fi \globallet\currentresourcecomment\empty \egroup} \def\resourcecomment#1% {\gdef\currentresourcecomment{#1}} \unexpanded\def\startresourcecomment#1\stopresourcecomment {\gdef\currentresourcecomment{#1}} \let\currentresourcecomment\empty \unexpanded\def\showexternalfigures % maybe run time command is better, but no core-run, unless figs-run ... {%\writestatus\m!system{for \string\showexternalfigures\space see \truefilename{x-res-20}.tex} \usemodule[res-20]% \showexternalfigures} % so for the moment we do it this way \unexpanded\def\overlayfigure#1% {\externalfigure[#1][\c!width=\overlaywidth,\c!height=\overlayheight]} %D Whatever \newbox\colorbarbox \unexpanded\def\makecolorbar[#1]% {\def\docommand##1% {\color[##1] {\blackrule [\c!width=2\emwidth, \c!height=\exheight, \c!depth=\zeropoint]}% \endgraf}% \global\setbox\colorbarbox\vbox {\forgetall \processcommalist[#1]\docommand}% \global\setbox\colorbarbox\vbox {\hskip2em\box\colorbarbox}% \wd\colorbarbox\zeropoint} \unexpanded\def\placestartfigure[#1][#2][#3]#4\placestopfigure[#5]% {\hbox {\setbox0\hbox {\useexternalfigure[\s!dummy][#2][#3,#5]% \externalfigure[\s!dummy]}% \calculateefsteps \startpositioning \def\referring(##1,##2)##3(##4,##5)##6[##7]% {\position(##1,##2){\efgoto(##4,##5){\@@exframes}[##7]}}% \def\marking(##1,##2)##3(##4,##5)##6[##7]% {\position(##1,##2){\efthisis(##4,##5){\@@exframes}[##7]}}% \def\remark{\efnocomment}% \def\colorbar##1[##2]{}% \position(0,0){\box0}% \linewidth\onepoint \setuppositioning [\c!unit=pt, \c!xscale=\withoutpt\the\efxsteps, \c!yscale=\withoutpt\the\efysteps, \c!factor=1]% \ignorespaces#4% \def\referring(##1,##2)##3(##4,##5)##6[##7]% {}% \let\marking\referring \def\remark{\efcomment\v!no}% \def\colorbar##1[##2]{\makecolorbar[##2]}% \ignorespaces#4% \stoppositioning \box\colorbarbox}} \def\dodostartfigure[#1][#2][#3]#4\stopfigure {\doifelse\v!test\@@exoption {\teststartfigure[#1][#2][#3]#4\teststopfigure \let\@@exframes\v!on} {\let\@@exframes\v!off}% \setvalue{\??externalfigureinstance#1}% {\dosingleempty{\placestartfigure[#1][#2][#3]#4\placestopfigure}}% }% no longer \doifundefined{#1}{\setvalue{#1}{\getexternalfigure{#1}}}} % De onderstaande macro mag niet zondermeer worden aangepast % en is afgestemd op gebruik in de handleiding. \def\teststartfigure[#1][#2][#3]#4\teststopfigure% {\begingroup \setbox0\hbox {\useexternalfigure[\s!dummy][#2][\c!wfactor=\v!max]% \externalfigure[\s!dummy]}% \def\referring{\efmark}% \def\marking{\efmark}% \def\remark{\efcomment\v!yes}% \def\colorbar##1[##2]{}% \efreference\zerocount \setbox0\vbox {\hsize240pt \startpositioning \calculateefsteps \position(0,0) {\box0}% \position(0,0) {\basegrid [\c!nx=\@@exxmax, \c!dx=\withoutpt\the\efxsteps, \c!ny=\@@exymax, \c!dy=\withoutpt\the\efysteps, \c!xstep=1, \c!ystep=1, \c!scale=1, \c!offset=\v!no, \c!unit=pt]}% \setuppositioning [\c!unit=pt, \c!xscale=\withoutpt\the\efxsteps, \c!yscale=\withoutpt\the\efysteps, \c!factor=1]% \linewidth\onepoint \ignorespaces#4\relax \stoppositioning \vfill}% \efreference\zerocount \def\referring{\eftext{$\rightarrow$}}% \def\marking{\eftext{$\leftarrow$}}% \def\remark{\efnocomment}% \def\colorbar##1[##2]{}% \setbox2\vbox {{\tfa\doifelsenothing{#1}{#2}{#1}} \blank \tfxx#4 \vfilll}% \ifdim\ht0>\ht2 \ht2\ht0 \else \ht0\ht2 \fi \hbox {\hskip3em \vtop{\vskip12pt\box0\vskip6pt}% \vtop{\vskip12pt\box2\vskip6pt}}% \endgroup} \def\dodostartfigure[#1][#2][#3]#4\stopfigure {\doifelse\v!test\@@exoption {\teststartfigure[#1][#2][#3]#4\teststopfigure \let\@@exframe\v!on} {\let\@@exframe\v!off}% \setvalue{\??externalfigureinstance#1}% {\def\next{\placestartfigure[#1][#2][#3]#4\placestopfigure}% \dosingleempty\next}% }% no longer: \doifundefined{#1}{\setvalue{#1}{\getexternalfigure{#1}}}} \long\def\dostartfigure#1% {\dotripleargument\dodostartfigure#1\stopfigure} \unexpanded\def\startfigure {\grabuntil{\e!stop\v!figure}\dostartfigure} %D NEW: used in styledesign manual % beware in mkiv we don't have the typeset- prefix % % \setbuffer[typeset-b]\endbuffer % \setbuffer[typeset-a]\endbuffer % % todo: % % \appendtoks \setbuffer[typeset-b]\endbuffer\to \everystarttext % \appendtoks \setbuffer[typeset-a]\endbuffer\to \everystarttext \newcount\noftypesetbuffers \def\typesetbuffer {\dodoubleempty\dotypesetbuffer} \def\dotypesetbuffer[#1][#2]% beware: this will mix up the mp graphics {\ifsecondargument \dodotypesetbuffer[#1][#2]% \else\iffirstargument \doifassignmentelse{#1} {\dodotypesetbuffer[\jobname][#1]}% {\dodotypesetbuffer[#1][]}% \else \dodotypesetbuffer[\jobname][] \fi\fi} \def\dodotypesetbuffer[#1][#2]% {\bgroup \global\advance\noftypesetbuffers\plusone \edef\bufferfilename{\jobname-buffer-\the\noftypesetbuffers}% \ctxcommand{runbuffer("\bufferfilename.tmp","#1",true)}% \externalfigure[\bufferfilename.pdf][#2]% \egroup} \def\dodotypesetbufferindeed#1% {} % for me only (manuals and such) % % \definetypesetting [name] [options] [settings-a] % % \typesetfile [name] [file] [settings-b] % \typesetfile [file] [options] [settings-b] % \typesetfile [file] [settings-b] % \typesetfile [file] % % \enabletrackers[files.run] % \starttext % \typesetfile[oepsoeps.tex][width=10cm,frame=on] % \stoptext \installcorenamespace{typesettingfile} \unexpanded\def\definetypesetting{\dotripleempty\dodefinetypesetting} \unexpanded\def\typesetfile {\dotripleempty\dotypesetfile} \def\dodefinetypesetting[#1][#2][#3]% options settings-a {\doifsomething{#1}{\setvalue{\??typesettingfile#1}{\dodotypesetfile{#2}{#3}}}} \def\dotypesetfile[#1][#2][#3]% filename settings-b | filename options settings {\ifcsname\??typesettingfile#1\endcsname \csname\??typesettingfile#1\endcsname{#2}{#3}% \else\ifthirdargument % filename options settings \dodotypesetfile{#2}{#3}{#1}{}% \else\ifsecondargument % filename settings \dodotypesetfile{}{#2}{#1}{}% \fi\fi\fi} \def\dodotypesetfile#1#2#3#4% options settings-a filename settings-b {\edef\typesetfilename{\ctxlua{tex.write(job.files.context("#3","#1"))}}% \expanded{\externalfigure[\typesetfilename]}[#2,#4]} \setupexternalfigures [\c!option=, \c!object=\v!yes, % we only check for no \c!reset=\v!no, \c!interaction=\v!none, \c!maxwidth=\@@efwidth, \c!maxheight=\@@efheight, \c!bodyfont=\bodyfontsize, \c!directory=, \c!radius=.5\bodyfontsize, \c!corner=\v!rectangular, \c!frame=\v!off, \c!background=, % new \c!splitcolor=\s!white, \c!order=, \c!conversion=, \c!resolution=, \c!prefix=, \c!cache=, % \c!grid=, \c!equalwidth=, \c!equalheight=, \c!location={\v!local,\v!global}] \setupexternalfigures [\c!frames=\v!off, \c!ymax=24, \c!xmax=] \useexternalfigure [buffer] [\jobname.buffer] [\c!object=\v!no] \protect \endinput % alternative for positioning % \definelayer[figure][width=\overlaywidth,height=\overlayheight] % \defineoverlay[figure][{\directsetup{figure}\tightlayer[figure]}] % \setupcolors[state=start] % \starttext % \startsetups figure % \setlayerframed[figure][preset=rightbottom,x=.25\layerwidth,y=.25\layerheight]{HERE} % \setlayerframed[figure][preset=leftbottom, x=.15\layerwidth,y=.35\layerheight]{THERE} % \stopsetups % \externalfigure[cow][background={foreground,figure},width=4cm,height=8cm] % \startsetups figure % \setlayerframed[figure][preset=righttop,x=.25\layerwidth,y=.25\layerheight]{MORE} % \setlayerframed[figure][preset=middle,foregroundcolor=green]{EVEN MORE} % \stopsetups % \externalfigure[cow][background={foreground,figure},width=14cm,height=2cm] % \defineexternalfigure[whatever][background={foreground,figure}] % \startsetups figure % \setlayerframed[figure][preset=righttop,x=.25\layerwidth,y=.25\layerheight]{\red MORE} % \setlayerframed[figure][preset=middle,foregroundcolor=green]{EVEN MORE} % \stopsetups % \externalfigure[cow][whatever][width=14cm,height=4cm] % \stoptext