diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mlib-pdf.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mlib-pdf.mkiv | 192 |
1 files changed, 124 insertions, 68 deletions
diff --git a/Master/texmf-dist/tex/context/base/mlib-pdf.mkiv b/Master/texmf-dist/tex/context/base/mlib-pdf.mkiv index 8506b3b15e6..b9871eeadae 100644 --- a/Master/texmf-dist/tex/context/base/mlib-pdf.mkiv +++ b/Master/texmf-dist/tex/context/base/mlib-pdf.mkiv @@ -5,7 +5,7 @@ %D subtitle=Conversion to PDF, %D author=Hans Hagen, %D date=\currentdate, -%D copyright=PRAGMA] +%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 @@ -13,84 +13,140 @@ \unprotect +% We use bit more code that needed because we want to limit the +% amount of boxing. + \registerctxluafile{mlib-pdf}{1.001} -\def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}} +%D Some code is shared between MPLIB and MPS. The following variables +%D are also available for introspection and other purposes. -\def\MPLIBboundingbox#1#2#3#4% - {\xdef\MPllx{#1}% - \xdef\MPlly{#2}% - \xdef\MPurx{#3}% - \xdef\MPury{#4}% - \xdef\MPwidth {\the\dimexpr#3\onebasepoint-#1\onebasepoint\relax}% - \xdef\MPheight{\the\dimexpr#4\onebasepoint-#2\onebasepoint\relax}} +\newdimen\MPwidth +\newdimen\MPheight -\def\startMPLIBtoPDF#1#2#3#4% watch the transparency reset - {\dostarttagged\t!mpgraphic\empty - \naturalhbox attr \imageattribute 1 \bgroup - \doactivatecolor\s!black\forcecolorhack - \MPLIBboundingbox{#1}{#2}{#3}{#4}% - %\forgetall % done already elsewhere - \setbox\scratchbox\vbox\bgroup - \noindent % this is really needed in order to force tex into proper cm's - \startMPresources} - -\def\stopMPLIBtoPDF % watch the transparency reset - {%\dohandleMPresettransparency % not needed - \stopMPresources - \egroup - \setbox\scratchbox\hbox\bgroup - \hskip-\MPllx\onebasepoint - \raise-\MPlly\onebasepoint - \box\scratchbox - \egroup - \setbox\scratchbox\vbox to \MPheight\bgroup +\newdimen\MPllx +\newdimen\MPlly +\newdimen\MPurx +\newdimen\MPury + +\newbox \MPbox + +\def\setMPboundingbox#1#2#3#4% at some point we might pass them as base or scaled points + {\global\MPllx #1\onebasepoint + \global\MPlly #2\onebasepoint + \global\MPurx #3\onebasepoint + \global\MPury #4\onebasepoint + \global\MPwidth \dimexpr\MPurx-\MPllx\relax + \global\MPheight\dimexpr\MPury-\MPlly\relax} + +\def\resetMPboundingbox + {\global\MPwidth \zeropoint + \global\MPheight\zeropoint + \global\MPllx \zeropoint + \global\MPlly \zeropoint + \global\MPurx \zeropoint + \global\MPury \zeropoint} + +\def\repositionMPboxindeed + {\setbox\MPbox\hbox\bgroup + \hskip-\MPllx + \raise-\MPlly + \box\MPbox + \egroup} + +\def\repositionMPbox + {\ifzeropt\MPllx + \ifzeropt\MPlly + % okay + \else + \repositionMPboxindeed + \fi + \else + \repositionMPboxindeed + \fi} + +\def\finalizeMPbox + {\repositionMPbox + \setbox\MPbox\vbox to \MPheight\bgroup \vfill \hsize\MPwidth - \smashbox\scratchbox - \box\scratchbox - \egroup - \wd\scratchbox\MPwidth - \ht\scratchbox\MPheight - \dopackageMPgraphic\scratchbox + \smashbox\MPbox + \box\MPbox \egroup - \dostoptagged} + \wd\MPbox\MPwidth + \ht\MPbox\MPheight} -% \def\MPLIBtextext#1#2#3#4#5% -% {\begingroup -% \def\MPtextdata{#3}% delegate the splitter to lua -% \defconvertedcommand\MPtextdata\MPtextdata % no edef -% \splitstring\MPtextdata\at::::\to\MPtexttag\and\MPtextnumber -% \executeifdefined{handleMPtext\MPtexttag} -% {\setbox\scratchbox\hbox -% {\font\temp=#1\space at #2\onebasepoint -% \let\c\char -% \temp -% \MPfshowcommand{#3}}% -% \setbox\scratchbox\hbox -% {\hskip#4\onebasepoint -% \raise#5\onebasepoint -% \box\scratchbox}% -% \smashbox\scratchbox -% \box\scratchbox}% -% \endgroup} - -\def\MPLIBtextext#1#2#3#4#5% +\def\MPtextext#1#2#3#4#5% beware: we use a different method now (see mlib-pps) {\begingroup - \setbox\scratchbox\hbox - {\font\temp=#1\space at #2\onebasepoint - \let\c\char - \temp - #3}% - \setbox\scratchbox\hbox - {\hskip#4\onebasepoint - \raise#5\onebasepoint - \box\scratchbox}% - \smashbox\scratchbox - \box\scratchbox + \setbox\MPbox\hbox{\font\temp=#1\space at #2\onebasepoint \let\c\char \temp #3}% + \MPllx-#4\onebasepoint + \MPlly-#5\onebasepoint + \repositionMPbox + \smashbox\MPbox + \box\MPbox \endgroup} -\def\MPLIBflushreset +% MPLIB specific: + +\def\MPLIBtoPDF#1{\ctxlua{metapost.flushliteral(#1)}} + +\def\startMPLIBtoPDF#1#2#3#4% + {\dostarttagged\t!mpgraphic\empty + \naturalhbox attr \imageattribute 1 \bgroup + \dousecolorparameter\s!black\forcecolorhack + \setMPboundingbox{#1}{#2}{#3}{#4}% + \setbox\MPbox\vbox\bgroup + % \forgetall % already done elsewhere + \noindent} % forces the proper cm in the backend + +\def\stopMPLIBtoPDF + {\egroup + \finalizeMPbox + \box\MPbox + \egroup + \dostoptagged} + +\def\MPLIBflushreset % This can (will) move to the Lua end. {\ctxlua{metapost.flushreset()}} +%D Kind of special: +% +% test.mp: +% +% beginfig(1) fill fullcircle scaled 10cm withcolor red ; endfig ; +% beginfig(2) draw fullcircle scaled 5cm withcolor blue ; endfig ; +% beginfig(3) draw textext("just some text") ; endfig ; +% +% standalone pages: +% +% \starttext +% \directMPgraphic{input "test.mp" ;} +% \stoptext + +\let\normalstartMPLIBtoPDF\startMPLIBtoPDF +\let\normalstopMPLIBtoPDF \stopMPLIBtoPDF + +\def\directstartMPLIBtoPDF{\startTEXpage\normalstartMPLIBtoPDF} +\def\directstopMPLIBtoPDF {\normalstopMPLIBtoPDF\stopTEXpage} + +\unexpanded\def\directMPgraphic + {\dodoublegroupempty\mlib_direct_graphic} + +\def\mlib_direct_graphic#1#2% makes pages (todo: make boxes) + {\meta_begin_graphic_group{#1}% + \let\startMPLIBtoPDF\directstartMPLIBtoPDF + \let\stopMPLIBtoPDF \directstopMPLIBtoPDF + \meta_start_current_graphic + \forgetall + \normalexpanded{\noexpand\ctxlua{metapost.graphic( + "\currentMPinstance", + "\currentMPformat", + \!!bs#2;\!!es, + \!!bs\meta_flush_current_initializations;\!!es, + \!!bs\meta_flush_current_preamble;\!!es, + "all" + )}}% + \meta_stop_current_graphic + \meta_end_graphic_group} + \protect \endinput |