diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/supp-pdf.tex')
-rw-r--r-- | Master/texmf-dist/tex/context/base/supp-pdf.tex | 1088 |
1 files changed, 570 insertions, 518 deletions
diff --git a/Master/texmf-dist/tex/context/base/supp-pdf.tex b/Master/texmf-dist/tex/context/base/supp-pdf.tex index 656a8f6fbce..754efa84795 100644 --- a/Master/texmf-dist/tex/context/base/supp-pdf.tex +++ b/Master/texmf-dist/tex/context/base/supp-pdf.tex @@ -1,6 +1,6 @@ %D \module %D [ file=supp-pdf, -%D version=2004.12.16, +%D version=2006.09.02, % 2004.12.16, %D title=\CONTEXT\ Support Macros, %D subtitle=\METAPOST\ to \PDF\ conversion, %D author=Hans Hagen \& others (see text), @@ -11,6 +11,142 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. +\ifx\writestatus\undefined + \immediate\write16{[Loading MPS to PDF converter (version 2006.09.02).]} +\else + \writestatus{loading}{Context Support Macros / PDF} +\fi + +%D This module is not optimized because it is used outside +%D \CONTEXT\ and we cannot forsee what interference will take +%D place. We no longer load supp-mis. I got too tired of +%D keeping track of interferences with non \CONTEXT\ usage so +%D I moved the necessary code in here and use a derived version +%D in \CONTEXT. When I have the time I will clean up some of the +%D code that is of no use for non||\CONTEXT\ users. + +\ifx\contextversion\undefined + + \chardef\mptopdfstoredatcode\catcode`\@ + + \catcode\string`@=11 + + \def\unprotect + {\let\@@mpstopdf@@unprotect \unprotect + \let\@@mpstopdf@@protect \protect + \edef\protect + {\noexpand \let \noexpand \protect \noexpand \@@mpstopdf@@protect + \noexpand \let \noexpand \unprotect \noexpand \@@mpstopdf@@unprotect + % context specific + \catcode\string`\noexpand @=\the\catcode\string`@ + \catcode\string`\noexpand !=\the\catcode\string`! + \catcode\string`\noexpand ?=\the\catcode\string`? + % latex specific + \catcode\string`\noexpand /=\the\catcode\string`/ + \catcode\string`\noexpand -=\the\catcode\string`- + \catcode\string`\noexpand :=\the\catcode\string`: + \catcode\string`\noexpand ;=\the\catcode\string`; + \catcode\string`\noexpand "=\the\catcode\string`" + \catcode\string`\noexpand <=\the\catcode\string`< + \catcode\string`\noexpand >=\the\catcode\string`> + \catcode\string`\noexpand `=\the\catcode\string``} + \catcode\string`@=11 \catcode\string`!=11 \catcode\string`?=11 + \catcode\string`/=12 \catcode\string`-=12 + \catcode\string`:=12 \catcode\string`;=12 + \catcode\string`>=12 \catcode\string`<=12 + \catcode\string`"=12 \catcode\string``=12 } + + \def\defineMPtoPDFfallbacks + {% shortcuts + \chardef\@@escape 0 + \chardef\@@begingroup 1 + \chardef\@@endgroup 2 + \chardef\@@endofline 5 + \chardef\@@ignore 9 + \chardef\@@space 10 + \chardef\@@letter 11 + \chardef\@@other 12 + \chardef\@@active 13 + \chardef\@@comment 14 + % placeholders + \ifx\withoutpt \undefined \let\withoutpt \@@mptopdf@@withoutpt \fi + \ifx\twodigitrounding \undefined \let\twodigitrounding \@@mptopdf@@twodigitrounding \fi + \ifx\forgetall \undefined \let\forgetall \@@mptopdf@@forgetall \fi + \ifx\uncatcodespecials \undefined \let\uncatcodespecials \@@mptopdf@@uncatcodespecials \fi + \ifx\setnaturalcatcodes\undefined \let\setnaturalcatcodes\@@mptopdf@@setnaturalcatcodes \fi + \ifx\dospecials \undefined \let\dospecials \@@mptopdf@@dospecials \fi} + + \def\@@mptopdf@@forgetall + {\parskip0pt\leftskip0pt\parindent0pt\everypar{}} + + \def\@@mptopdf@@twodigitrounding#1% + {#1}% + + \def\@@mptopdf@@uncatcodespecials + {\def\do##1{\catcode`##1=\@@other}\dospecials + \catcode`\ =\@@space + \catcode`\^^L=\@@ignore + \catcode`\^^M=\@@endofline + \catcode`\^^?=\@@ignore} + + \def\@@mptopdf@@setnaturalcatcodes + {\catcode`\!=\@@other \catcode`\?=\@@other \catcode`\@=\@@other + \catcode`\#=\@@other \catcode`\&=\@@other \catcode`\|=\@@other + \catcode`\$=\@@other \catcode`\^=\@@other \catcode`\_=\@@other + \catcode`\*=\@@other \catcode`\/=\@@other + \catcode`\-=\@@other \catcode`+=\@@other + \catcode`\==\@@other \catcode`\<=\@@other \catcode`\>=\@@other + \catcode`\"=\@@other \catcode`\'=\@@other \catcode`\`=\@@other + \catcode`\:=\@@other \catcode`\;=\@@other + \catcode`\,=\@@other \catcode`\.=\@@other \catcode`\~=\@@other + \catcode`\(=\@@other \catcode`\)=\@@other + \catcode`\{=\@@other \catcode`\}=\@@other + \catcode`\\=\@@other \catcode`\%=\@@other} + + \def\@@mptopdf@@dospecials + {\do\ \do\\\do\{\do\}\do\$% + \do\#\do\^\do\_\do\&\do\%% + \do\~\do\^^A\do\^^K} + + { + \catcode`\.=12 + \catcode`\p=12 + \catcode`\t=12 + \gdef\@@MPTOPDF@@WITHOUTPT#1pt{#1} + } + + \def\@@mptopdf@@withoutpt#1% + {\expandafter\@@MPTOPDF@@WITHOUTPT#1} + +% \def\@@mptopdf@@newabove#1#2% \dimen \name +% {#1#2% +% \ifnum\expandafter\gobblesixarguments\meaning#2>20\else +% \expandafter\@@mptopdf@@newabove\expandafter#1\expandafter#2% +% \fi} + + \def\@@mptopdf@@stripnewabove#1% + {\ifnum10<9#1 #1\else\expandafter\@@mptopdf@@stripnewabove\fi}% + + \def\@@mptopdf@@newabove\csname#1\endcsname#2% \dimen \name + {\csname#1\endcsname#2% + \ifnum\expandafter\@@mptopdf@@stripnewabove\meaning#2>20\else + \@@mptopdf@@newabove\csname#1\endcsname#2% + \fi} + + \@@mptopdf@@newabove \csname newcount\endcsname \scratchcounter + \@@mptopdf@@newabove \csname newdimen\endcsname \scratchdimen + \csname newbox\endcsname \scratchbox + + \expandafter \newif \csname ifdone\endcsname + + \catcode`\@=\mptopdfstoredatcode + +\else + + \let\defineMPtoPDFfallbacks\relax + +\fi + %D These macros are written as generic as possible. Some %D general support macro's are loaded from a small module %D especially made for non \CONTEXT\ use. In this module I @@ -25,23 +161,10 @@ %D his initials. (We keep the old code around because it's a %D nice illustration on how a module like this evolves.) -% Beware, we cannot use \zeropoint here since it may be -% defined in the range \dimen 0 - 20 which we happen to use -% as scratch registers; inside context we may consider -% using dedicated registers. - -% fails: ( ) vect10 9.96265 fshow % \040\040\040\040 -% -% some optimizations are possible, but we need to be generic - -%D First we take care of non||\CONTEXT\ use (newlines needed, -%D expandafter not -). - -\ifx \undefined \writestatus \input supp-mis.tex \relax \fi - -\ifx \undefined \convertMPtoPDF \else \expandafter \endinput \fi - -\ifx \undefined \StartLatexHack \else \StartLatexHack \fi +%D Beware, we cannot use \zeropoint here since it may be +%D defined in the range \dimen 0 - 20 which we happen to use +%D as scratch registers; inside context we may consider +%D using dedicated registers. %D This module handles some \PDF\ conversion and insertions %D topics. By default, the macros use the \PDFTEX\ primitive @@ -49,8 +172,6 @@ %D default engine for \TEX\ distributions, we need a more complex %D test. -\writestatus{loading}{Context Support Macros / PDF (2004.03.26)} - \unprotect \ifx\PDFcode\undefined @@ -69,7 +190,7 @@ %D First we define a handy constant: -\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup +\bgroup \defineMPtoPDFfallbacks \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup %D \macros %D {pdfimage,pdfimages,pdfclippedimage} @@ -94,12 +215,6 @@ %D \pdfclippedimage <optional dimensions> {file} {l} {r} {t} {b} %D \stoptyping -% \ifx\pdftexversion\undefined % no \m!systems for the sake of latex -% \writestatus{systems}{Why not use pdf(e)TeX binaries?} -% \protect -% \expandafter\endinput -% \fi - \ifx\pdftexversion\undefined \else \ifnum\pdftexversion>13 \def\pdfimage#1#% @@ -114,11 +229,8 @@ \def\dopdfimages#1#2#3% {\immediate\pdfximage#1{#2}% - \immediate\pdfobj - {[ << /Image \the\pdflastximage\space0 R - /DefaultForPrinting true >> ]}% - \immediate\pdfximage#1 - attr {/Alternates \the\pdflastobj\space0 R}{#3}% + \immediate\pdfobj{[ << /Image \the\pdflastximage\space0 R /DefaultForPrinting true >> ]}% + \immediate\pdfximage#1 attr {/Alternates \the\pdflastobj\space0 R}{#3}% \pdfrefximage\pdflastximage} \def\pdfclippedimage#1#% specs {file}{left}{right}{top}{bottom} @@ -165,218 +277,12 @@ \fi \fi -%D \macros -%D {convertPDFtoPDF} -%D -%D \PDFTEX\ supports verbatim inclusion of \PDF\ code. The -%D following macro takes care of inserting externally defined -%D illustrations in \PDF\ format. According to a suggestion -%D Tanmoy Bhattacharya posted to the \PDFTEX\ mailing list, we -%D first skip lines until \type{stream} is reached and then -%D copy lines until \type{endstream} is encountered. This -%D scheme only works with vectorized graphics in which no -%D indirect references to objects are used. Bitmaps also don't -%D work. Interpreting their specifications is beyond the -%D current implementation. -%D -%D \starttyping -%D \convertPDFtoPDF -%D {filename} -%D {x scale} {y scale} -%D {x offset } {y offset} -%D {width} {height} -%D \stoptyping -%D -%D When the scales are set to~1, the last last four values -%D are the same as the bounding box, e.g. -%D -%D \starttyping -%D \convertPDFtoPDF{mp-pra-1.pdf} {1} {1}{-1bp}{-1bp}{398bp}{398bp} -%D \convertPDFtoPDF{mp-pra-1.pdf}{.5}{.5} {0bp} {0bp}{199bp}{199bp} -%D \stoptyping -%D -%D Keep in mind, that this kind of copying only works for -%D pure and valid pdf code (without fonts). - -%D The scanning and copying is straightforward and quite fast. -%D To speed up things we use two constants. - -\def\@@PDFstream@@ {stream} -\def\@@PDFendstream@@ {endstream} - -%D \macros -%D {PDFmediaboxprefered} -%D -%D If needed, the macros can scan for the mediabox that -%D specifies the dimensions and offsets of the graphic. When -%D we say: -%D -%D \starttyping -%D \PDFmediaboxpreferedtrue -%D \stoptyping -%D -%D the mediabox present in the file superseded the user -%D specified, already scaled and calculated offset and -%D dimensions. Beware: the user supplied values are not the -%D bounding box ones! - -%D This code has become obsolete. - -% \newif\ifPDFmediaboxprefered - -\def\setPDFboundingbox#1#2#3#4#5#6% - {\dimen0=#1\dimen0=#5\dimen0 - \ScaledPointsToBigPoints{\number\dimen0}\PDFxoffset - \dimen0=#3\dimen0=#5\dimen0 - \xdef\PDFwidth{\the\dimen0}% - \dimen0=#2\dimen0=#6\dimen0 - \ScaledPointsToBigPoints{\number\dimen0}\PDFyoffset - \dimen0=#4\dimen0=#6\dimen0 - \xdef\PDFheight{\the\dimen0}% - \global\let\PDFxoffset\PDFxoffset - \global\let\PDFyoffset\PDFyoffset} - -\def\setPDFmediabox#1[#2 #3 #4 #5]#6\done - {\dimen2=#2bp\dimen2=-\dimen2 % \dimen2=-#2bp also works since tex handles -- - \dimen4=#3bp\dimen4=-\dimen4 % \dimen4=-#3bp also works since tex handles -- - \dimen6=#4bp\advance\dimen6 \dimen2 - \dimen8=#5bp\advance\dimen8 \dimen4 - \setPDFboundingbox{\dimen2}{\dimen4}{\dimen6}{\dimen8}\PDFxscale\PDFyscale} - -% \def\checkPDFmediabox#1/MediaBox#2#3\done -% {\ifx#2\relax \else -% \message{mediabox}% -% \setPDFmediabox#2#3\done -% \fi} - -%D We use the general macro \type{\doprocessfile} and feed this -%D with a line handling macro that changes it's behavior when -%D the stream operators are encountered. - -% \def\handlePDFline -% {\ifx\@@PDFstream@@\fileline -% \let\doprocessPDFline\copyPDFobject -% \startPDFtoPDF -% \else\ifPDFmediaboxprefered -% \expandafter\checkPDFmediabox\fileline/MediaBox\relax\done -% \fi\fi} - -% \def\copyPDFobject -% {\ifx\@@PDFendstream@@\fileline -% \ifPDFmediaboxprefered -% \let\doprocessPDFline\findPDFmediabox -% \else -% \let\doprocessPDFline\relax -% \fi -% \else -% \advance\scratchcounter 1 -% \PDFcode{\fileline}% -% \fi} - -% \def\findPDFmediabox -% {\expandafter\checkPDFmediabox\fileline/MediaBox\relax\done} - %D The main conversion macro wraps the \PDF\ codes in a box %D that is output as an object. The graphics are embedded %D in~\type{q} and~\type{Q} and are scaled and positioned using %D one transform call (\type{cm}). This saves some additional %D scaling. -%D \starttyping -%D \def\startPDFtoPDF% -%D {\setbox0=\vbox\bgroup -%D \message{[PDF to PDF \PDFfilename}% -%D \forgetall -%D \scratchcounter=0 -%D \let\stopPDFtoPDF=\dostopPDFtoPDF} -%D -%D \def\dostopPDFtoPDF% -%D {\ifnum\scratchcounter<0 \scratchcounter=1 \fi -%D \message{(\the\scratchcounter\space lines)]}% -%D \egroup -%D \wd0=\PDFwidth -%D \vbox to \PDFheight -%D {\forgetall -%D \vfill -%D \PDFcode{q}% -%D \PDFcode{1 0 0 1 \PDFxoffset\space \PDFyoffset\space cm}% -%D \PDFcode{\PDFxscale\space 0 0 \PDFyscale\space 0 0 cm}% -%D \box0 -%D \PDFcode{Q}}} -%D -%D \def\stopPDFtoPDF% -%D {\message{[PDF to PDF \PDFfilename\space not found]}} -%D -%D \def\convertPDFtoPDF#1#2#3#4#5#6#7% -%D {\bgroup -%D \def\PDFfilename{#1}% -%D \def\PDFxscale {#2}% -%D \def\PDFyscale {#3}% -%D \setPDFboundingbox{#4}{#5}{#6}{#7}{1}{1}% -%D \uncatcodespecials -%D \endlinechar=-1 -%D \let\doprocessPDFline=\handlePDFline -%D \doprocessfile\scratchread\PDFfilename\doprocessPDFline -%D \stopPDFtoPDF -%D \egroup} - -\def\convertPDFtoPDF#1#2#3#4#5#6#7% - {\message{[PDF to PDF use \string\PDFcode instead]}% - \vbox{use the direct method instead}} - -%D \macros -%D {dogetPDFmediabox} -%D -%D The next macro can be used to find the mediabox of a \PDF\ -%D illustration. -%D -%D \starttyping -%D \dogetPDFmediabox -%D {filename} -%D {new dimen}{new dimen}{new dimen}{new dimen} -%D \stoptyping -%D -%D Beware of dimen clashes: this macro uses the 5~default -%D scratch registers! When no file or mediabox is found, the -%D dimensions are zeroed. - -\def\dogetPDFmediabox#1#2#3#4#5% - {\bgroup - \def\PDFxscale{1}% - \def\PDFyscale{1}% - \uncatcodespecials - \endlinechar\minusone - \def\checkPDFtypepage##1/Type /Page##2##3\done% - {\ifx##2\relax - \else\if##2s% accept /Page and /Pages - \let\doprocessPDFline\findPDFmediabox - \else - \let\doprocessPDFline\findPDFmediabox - \fi\fi}% - \def\findPDFtypepage - {\expandafter\checkPDFtypepage\fileline/Type /Page\relax\done}% - \def\checkPDFmediabox##1/MediaBox##2##3\done% - {\ifx##2\relax \else - \setPDFmediabox##2##3\done - \fileprocessedtrue - \fi}% - \def\findPDFmediabox - {\expandafter\checkPDFmediabox\fileline/MediaBox\relax\done}% - \let\doprocessPDFline\findPDFtypepage - \doprocessfile\scratchread{#1}\doprocessPDFline - \egroup - \ifx\PDFxoffset\undefined - #2\zeropoint - #3\zeropoint - #4\zeropoint - #5\zeropoint - \else - #2=\PDFxoffset\onebasepoint - #3=\PDFyoffset\onebasepoint - #4=\PDFwidth - #5=\PDFheight - \fi} - %D \macros %D {convertMPtoPDF} %D @@ -440,6 +346,9 @@ \edef \PSMetaPostSpecial {\letterpercent\letterpercent MetaPostSpecial:} \edef \PSMetaPostSpecials {\letterpercent\letterpercent MetaPostSpecials:} \edef \PSPage {\letterpercent\letterpercent Page:} +\edef \PSBeginProlog {\letterpercent\letterpercent BeginProlog} +\edef \PSEndProlog {\letterpercent\letterpercent EndProlog} +\edef \PSEof {\letterpercent\letterpercent EOF} %D By the way, the \type {setcmykcolor} operator is not %D output by \METAPOST\ but can result from converting the @@ -505,17 +414,17 @@ \def\@@MP{@@MP} \def\setMPargument% #1% - {\advance\nofMParguments \plusone + {\advance\nofMParguments 1 \expandafter\def \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname} % {#1} \def\letMPargument - {\advance\nofMParguments \plusone + {\advance\nofMParguments 1 \expandafter\let \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname} \def\setMPsequence#1 % - {\advance\nofMParguments \plusone + {\advance\nofMParguments 1 \expandafter\def \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname{#1}% \handleMPsequence} @@ -527,12 +436,12 @@ {\csname\@@MP\the\nofMPsegments\number#1\endcsname} \def\dogMPa#1% - {\@EAEAEA\do\csname\@@MP0\number#1\endcsname} + {\expandafter\expandafter\expandafter\do\csname\@@MP0\number#1\endcsname} \def\setMPkeyword#1 % {\expandafter\def\csname\@@MP\the\nofMPsegments0\endcsname{#1}% - \advance\nofMPsegments \plusone - \nofMParguments\zerocount} + \advance\nofMPsegments 1 + \nofMParguments0} \def\getMPkeyword% #1% {\csname\@@MP\the\nofMPsegments0\endcsname} % {\csname\@@MP#10\endcsname} @@ -549,7 +458,7 @@ %D when dealing with comments. \def\doresetMPstack - {\nofMParguments\zerocount} + {\nofMParguments0\relax} \def\resetMPstack {\let\handleMPgraphic\handleMPendgraphic @@ -597,6 +506,7 @@ %D when needed we either ignore or obey them \bgroup +\defineMPtoPDFfallbacks \catcode`\|=\@@comment \catcode`\%=\@@active \catcode`\[=\@@active @@ -653,6 +563,7 @@ %D that we cannot change the catcodes in between. \bgroup +\defineMPtoPDFfallbacks \catcode`\%=\@@active \gdef\startMPscanning{\let%=\startMPconversion} \egroup @@ -680,17 +591,15 @@ %D speed up the conversion by handling the \type{path} %D seperately. -\def\@EAEAEA{\expandafter\expandafter\expandafter} % to be sure - \def\dohandleMPsequence#1% {\ifdone \ifcase\lccode`#1\relax - \@EAEAEA\dohandleMPsequenceA + \expandafter\expandafter\expandafter\dohandleMPsequenceA \else - \@EAEAEA\dohandleMPsequenceB + \expandafter\expandafter\expandafter\dohandleMPsequenceB \fi \else - \@EA\dohandleMPsequenceC + \expandafter\dohandleMPsequenceC \fi#1} %\def\dohandleMPsequenceA#1 % @@ -699,80 +608,203 @@ \let\dohandleMPsequenceA\setMPsequence +% \def\dohandleMPsequenceB#1 % +% {\edef\somestring{#1}% +% \ifx\somestring\PSmoveto +% \edef\lastMPmoveX{\gMPa1}% +% \edef\lastMPmoveY{\gMPa2}% +% \PDFcode{\!MPgMPa1 \!MPgMPa2 m}% +% \resetMPstack +% \else\ifx\somestring\PSnewpath +% \let\handleMPsequence\handleMPpath +% \else\ifx\somestring\PSgsave +% \PDFcode{q}% +% \resetMPstack +% \else\ifx\somestring\PSgrestore +% \PDFcode{Q}% +% \resetMPstack +% \else\ifx\somestring\PSdtransform % == setlinewidth +% \let\handleMPsequence\handleMPdtransform +% % after that we will encounter more tokens until setlinewidth+pop +% % or pop+setlinewidth which we catch next; we explicitly need to +% % reset the stack since [] n setdash may follow; a more clever +% % approach would be to read on till the condition is met, but it's +% % the only pop / setlinewidth we will encounter so ... +% \else\ifx\somestring\PSsetlinewidth +% % already handled in dtransform +% \resetMPstack +% \else\ifx\somestring\PSpop +% % already handled in dtransform +% \resetMPstack +% \else\ifx\somestring\PSconcat +% \cleanupMPconcat +% \PDFcode{\gMPa1 \gMPa2 \gMPa3 \gMPa4 \gMPa5 \gMPa6 cm}% +% \resetMPstack +% \else\ifx\somestring\PSsetrgbcolor +% \handleMPrgbcolor +% \resetMPstack +% \else\ifx\somestring\PSsetcmykcolor +% \handleMPcmykcolor +% \resetMPstack +% \else\ifx\somestring\PSsetgray +% \handleMPgraycolor +% \resetMPstack +% \else\ifx\somestring\PStranslate +% \PDFcode{1 0 0 1 \gMPa1 \gMPa2 cm}% +% \resetMPstack +% \else\ifx\somestring\PSsetdash +% \handleMPsetdash +% \resetMPstack +% \else\ifx\somestring\PSsetlinejoin +% \PDFcode{\gMPa1 j}% +% \resetMPstack +% \else\ifx\somestring\PSsetmiterlimit +% \PDFcode{\gMPa1 M}% +% \resetMPstack +% \else\ifx\somestring\PSfshow +% \PDFcode{n}% +% \handleMPfshow +% \resetMPstack +% \else\ifx\somestring\PSsetlinecap +% \PDFcode{\gMPa1 J}% +% \resetMPstack +% \else\ifx\somestring\PSrlineto +% \PDFcode{\!MP\lastMPmoveX\space\!MP\lastMPmoveY\space l S}% +% \resetMPstack +% \else\ifx\somestring\PSscale +% \PDFcode{\gMPa1 0 0 \gMPa2 0 0 cm}% +% \resetMPstack +% \else\ifx\somestring\PSspecial +% \handleMPspecialcommand +% \resetMPstack +% \else +% \handleMPgraphic% {#1}% +% \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi +% \handleMPsequence} + +\def\installMPSkeywordN#1#2% + {\expandafter\def\csname\@@MP:N:#1\endcsname{#2}} + +\def\installMPSshortcutN#1#2% todo: \let + {\expandafter\let\csname\@@MP:N:#1\expandafter\endcsname\csname\@@MP:N:#2\endcsname} + \def\dohandleMPsequenceB#1 % {\edef\somestring{#1}% - \ifx\somestring\PSmoveto - \edef\lastMPmoveX{\gMPa1}% - \edef\lastMPmoveY{\gMPa2}% - \PDFcode{\!MPgMPa1 \!MPgMPa2 m}% - \resetMPstack - \else\ifx\somestring\PSnewpath - \let\handleMPsequence\handleMPpath - \else\ifx\somestring\PSgsave - \PDFcode{q}% - \resetMPstack - \else\ifx\somestring\PSgrestore - \PDFcode{Q}% - \resetMPstack - \else\ifx\somestring\PSdtransform % == setlinewidth - \let\handleMPsequence\handleMPdtransform - % after that we will encounter more tokens until setlinewidth+pop - % or pop+setlinewidth which we catch next; we explicitly need to - % reset the stack since [] n setdash may follow; a more clever - % approach would be to read on till the condition is met, but it's - % the only pop / setlinewidth we will encounter so ... - \else\ifx\somestring\PSsetlinewidth - % already handled in dtransform - \resetMPstack - \else\ifx\somestring\PSpop - % already handled in dtransform - \resetMPstack - \else\ifx\somestring\PSconcat - \cleanupMPconcat - \PDFcode{\gMPa1 \gMPa2 \gMPa3 \gMPa4 \gMPa5 \gMPa6 cm}% - \resetMPstack - \else\ifx\somestring\PSsetrgbcolor - \handleMPrgbcolor - \resetMPstack - \else\ifx\somestring\PSsetcmykcolor - \handleMPcmykcolor - \resetMPstack - \else\ifx\somestring\PSsetgray - \handleMPgraycolor - \resetMPstack - \else\ifx\somestring\PStranslate - \PDFcode{1 0 0 1 \gMPa1 \gMPa2 cm}% - \resetMPstack - \else\ifx\somestring\PSsetdash - \handleMPsetdash - \resetMPstack - \else\ifx\somestring\PSsetlinejoin - \PDFcode{\gMPa1 j}% - \resetMPstack - \else\ifx\somestring\PSsetmiterlimit - \PDFcode{\gMPa1 M}% - \resetMPstack - \else\ifx\somestring\PSfshow - \PDFcode{n}% - \handleMPfshow - \resetMPstack - \else\ifx\somestring\PSsetlinecap - \PDFcode{\gMPa1 J}% - \resetMPstack - \else\ifx\somestring\PSrlineto - \PDFcode{\!MP\lastMPmoveX\space\!MP\lastMPmoveY\space l S}% - \resetMPstack - \else\ifx\somestring\PSscale - \PDFcode{\gMPa1 0 0 \gMPa2 0 0 cm}% - \resetMPstack - \else\ifx\somestring\PSspecial - \handleMPspecialcommand - \resetMPstack + \ifcsname\@@MP:N:\somestring\endcsname + \csname\@@MP:N:\somestring\expandafter\endcsname \else - \handleMPgraphic% {#1}% - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi + \expandafter\handleMPgraphic + \fi \handleMPsequence} +\ifx\eTeXversion\undefined + \def\dohandleMPsequenceB#1 % + {\edef\somestring{#1}% + \expandafter\ifx\csname\@@MP:N:\somestring\endcsname\relax + \expandafter\handleMPgraphic + \else + \csname\@@MP:N:\somestring\expandafter\endcsname + \fi + \handleMPsequence} +\fi + +\installMPSkeywordN \PSmoveto + {\edef\lastMPmoveX{\gMPa1}% + \edef\lastMPmoveY{\gMPa2}% + \resetMPstack} +\installMPSkeywordN \PSnewpath + {\let\handleMPsequence\handleMPpath} +\installMPSkeywordN \PSgsave + {\PDFcode{q}% + \resetMPstack} +\installMPSkeywordN \PSgrestore + {\PDFcode{Q}% + \resetMPstack} +\installMPSkeywordN \PSdtransform % == setlinewidth + {\let\handleMPsequence\handleMPdtransform} + % after that we will encounter more tokens until setlinewidth+pop + % or pop+setlinewidth which we catch next; we explicitly need to + % reset the stack since [] n setdash may follow; a more clever + % approach would be to read on till the condition is met, but it's + % the only pop / setlinewidth we will encounter so ... +\installMPSkeywordN \PSsetlinewidth + {% already handled in dtransform + \resetMPstack} +\installMPSkeywordN \PSpop + {% already handled in dtransform + \resetMPstack} +\installMPSkeywordN \PSconcat + {\cleanupMPconcat + \PDFcode{\gMPa1 \gMPa2 \gMPa3 \gMPa4 \gMPa5 \gMPa6 cm}% + \resetMPstack} +\installMPSkeywordN \PSsetrgbcolor + {\handleMPrgbcolor + \resetMPstack} +\installMPSkeywordN \PSsetcmykcolor + {\handleMPcmykcolor + \resetMPstack} +\installMPSkeywordN \PSsetgray + {\handleMPgraycolor + \resetMPstack} +\installMPSkeywordN \PStranslate + {\PDFcode{1 0 0 1 \gMPa1 \gMPa2 cm}% + \resetMPstack} +\installMPSkeywordN \PSsetdash + {\handleMPsetdash + \resetMPstack} +\installMPSkeywordN \PSsetlinejoin + {\PDFcode{\gMPa1 j}% + \resetMPstack} +\installMPSkeywordN \PSsetmiterlimit + {\PDFcode{\gMPa1 M}% + \resetMPstack} +\installMPSkeywordN \PSfshow + {%\PDFcode{n}% removed ! + \handleMPfshow + \resetMPstack} +\installMPSkeywordN \PSsetlinecap + {\PDFcode{\gMPa1 J}% + \resetMPstack} +\installMPSkeywordN \PSrlineto + {\flushMPmoveto + \PDFcode{\!MP\lastMPmoveX\space\!MP\lastMPmoveY\space l S}% + \resetMPmoveto + \resetMPstack} +\installMPSkeywordN \PSscale + {\PDFcode{\gMPa1 0 0 \gMPa2 0 0 cm}% + \resetMPstack} +\installMPSkeywordN \PSspecial + {\handleMPspecialcommand + \resetMPstack} + +\installMPSshortcutN {n} \PSnewpath +\installMPSshortcutN {p} \PSclosepath +\installMPSshortcutN {l} \PSlineto +\installMPSshortcutN {r} \PSrlineto +\installMPSshortcutN {m} \PSmoveto +\installMPSshortcutN {c} \PScurveto +\installMPSshortcutN {C} \PSsetcmykcolor +\installMPSshortcutN {G} \PSsetgray +\installMPSshortcutN {R} \PSsetrgbcolor +\installMPSshortcutN {lj} \PSsetlinejoin +\installMPSshortcutN {ml} \PSsetmiterlimit +\installMPSshortcutN {lc} \PSsetlinecap +\installMPSshortcutN {sd} \PSsetdash +\installMPSshortcutN {S} \PSstroke +\installMPSshortcutN {F} \PSfill +\installMPSshortcutN {W} \PSclip + +\installMPSshortcutN {q} \PSgsave +\installMPSshortcutN {Q} \PSgrestore + +\installMPSshortcutN {s} \PSscale +\installMPSshortcutN {t} \PSconcat +\installMPSshortcutN {P} \PSshowpage + +\installMPSkeywordN {hlw} {\PDFcode{\gMPa1 w}\resetMPstack} +\installMPSkeywordN {vlw} {\PDFcode{\gMPa1 w}\resetMPstack} +\installMPSkeywordN {rd} {\PDFcode{[] 0 d}\resetMPstack} + \def\dohandleMPsequenceC#1 % {\edef\somestring{#1}% \handleMPgraphic % {#1}% @@ -805,9 +837,11 @@ \def\handleMPendgraphic % #1% {\ifx\somestring\PSshowpage \let\handleMPsequence\finishMPgraphic + \else\ifx\somestring\PSEof + \let\handleMPsequence\finishMPgraphic \else \letMPargument\somestring % {#1}% - \fi} + \fi\fi} \def\handleMPbegingraphic % #1% {\ifx\somestring\PSBoundingBox @@ -818,18 +852,34 @@ \def\handleMPsequence{\handleMPboundingbox3}% \else\ifx\somestring\PSshowpage \let\handleMPsequence\finishMPgraphic + \else\ifx\somestring\PSEof + \let\handleMPsequence\finishMPgraphic \else\ifx\somestring\PSPage \let\handleMPsequence\handleMPpage \else\ifx\somestring\PSMetaPostSpecials \let\handleMPsequence\handleMPspecialscomment \else\ifx\somestring\PSMetaPostSpecial \let\handleMPsequence\handleMPspecialcomment + \else\ifx\somestring\PSBeginProlog + \let\handleMPsequence\handleMPprolog \else \letMPargument\somestring % {#1}% - \fi\fi\fi\fi\fi\fi\fi} + \fi\fi\fi\fi\fi\fi\fi\fi\fi} \let\handleMPgraphic=\handleMPbegingraphic +%D New: we can best filter the prolog because nowdays it can contain +%D quite some code. + +% hm, catcode mess, so we need to tweak %'s catcode here +% \long\expandafter\def\expandafter\handleMPprolog\expandafter#\expandafter1\PSEndProlog% +% but today i'm not in the mood for ugly stuff + +\long\def\handleMPprolog#1EndProlog % + {\doresetMPstack + \let\handleMPsequence\dohandleMPsequence + \handleMPsequence} + %D We check for three kind of bounding boxes: the normal one %D and two high precision ones: %D @@ -850,20 +900,20 @@ {\ifnum#1>\currentMPboundingbox \xdef\MPllx{#2}\xdef\MPlly{#3}% \xdef\MPurx{#4}\xdef\MPury{#5}% - \dimen0=#2\onepoint + \dimen0=#2pt \dimen0=-\MPxscale\dimen0 - \dimen2=#3\onepoint + \dimen2=#3pt \dimen2=-\MPyscale\dimen2 \xdef\MPxoffset{\withoutpt\the\dimen0}% \xdef\MPyoffset{\withoutpt\the\dimen2}% - \dimen0=#2\onebasepoint + \dimen0=#2bp \dimen0=-\dimen0 - \dimen2=#3\onebasepoint + \dimen2=#3bp \dimen2=-\dimen2 - \advance\dimen0 #4\onebasepoint + \advance\dimen0 #4bp \dimen0=\MPxscale\dimen0 \xdef\MPwidth{\the\dimen0}% - \advance\dimen2 #5\onebasepoint + \advance\dimen2 #5bp \xdef\MPyshift{\the\dimen2}% unscaled \dimen2=\MPyscale\dimen2 \xdef\MPheight{\the\dimen2}% @@ -873,7 +923,7 @@ \let\handleMPsequence\dohandleMPsequence \let\next\handleMPsequence \ifskipemptyMPgraphic - \ifdim\MPheight=\zeropoint\relax\ifdim\MPwidth=\zeropoint\relax + \ifdim\MPheight=0pt\relax\ifdim\MPwidth=0pt\relax \def\next{\endinput\finishMPgraphic}% \fi\fi \fi @@ -931,31 +981,31 @@ \let\ \relax % mp breaks long lines and appends a \ \edef\size{\gMPa\nofMParguments}% \ifx\size\PSnfont % round font size (to pt) - \advance\nofMParguments \minusone - \expandafter\scratchdimen\gMPa\nofMParguments\onepoint\relax - \ifdim\scratchdimen<\onepoint + \advance\nofMParguments -1 + \expandafter\scratchdimen\gMPa\nofMParguments pt\relax + \ifdim\scratchdimen<1pt \def\size{1pt}% \else - \advance\scratchdimen .5\onepoint + \advance\scratchdimen .5pt \def\size##1.##2\relax{\def\size{##1pt}}% \expandafter\size\the\scratchdimen\relax \fi \else \edef\size{\size bp}% \fi - \advance\nofMParguments \minusone + \advance\nofMParguments -1 %\font\temp=\gMPa\nofMParguments\space at \size \let\temp\relax % to be sure \setMPfshowfont{\gMPa\nofMParguments}\size - \advance\nofMParguments \minusone + \advance\nofMParguments -1 \temp \MPfshowcommand - {\ifnum\nofMParguments=\plusone + {\ifnum\nofMParguments=1 \def\do(##1){##1}% \dogMPa1% \else % we need to catch ( a ) (a a a) (\123 \123 \123) etc - \scratchcounter\plusone + \scratchcounter1 \def\dodo##1% Andreas Fieger's bug: (\304...) {\edef\!!stringa{##1\empty\empty}% and another one: ( 11) -> \ifx 11 \ifx\!!stringa\MPspacechar\MPspacechar\else\expandafter##1\fi}% @@ -963,7 +1013,7 @@ \dogMPa\scratchcounter\MPspacechar \let\do\relax \loop - \advance\scratchcounter \plusone + \advance\scratchcounter 1 \ifnum\scratchcounter<\nofMParguments\relax \gMPa\scratchcounter\MPspacechar \repeat @@ -971,25 +1021,11 @@ \dogMPa\scratchcounter \fi \unskip}}% - % - % this fails in some versions of pdftex - % - % \dimen0=\lastMPmoveY bp - % \advance\dimen0 by \ht0 - % \ScaledPointsToBigPoints{\number\dimen0}\lastMPmoveY - % \PDFcode{n q 1 0 0 1 \lastMPmoveX\space\lastMPmoveY\space cm}% - % \dimen0=\ht0 - % \advance\dimen0 by \dp0 - % \box0 - % \vskip-\dimen0 - % \PDFcode{Q}% - % \egroup} - % \setbox\scratchbox\hbox - {\hskip\lastMPmoveX\onebasepoint\raise\lastMPmoveY\onebasepoint\box\scratchbox}% - \ht\scratchbox\zeropoint - \dp\scratchbox\zeropoint - \wd\scratchbox\zeropoint + {\hskip\lastMPmoveX bp\raise\lastMPmoveY bp\box\scratchbox}% + \ht\scratchbox0pt% + \dp\scratchbox0pt% + \wd\scratchbox0pt% \box\scratchbox \egroup} @@ -1031,11 +1067,11 @@ {\bgroup \ignoreMPspecials \def\somestring{[}% - \scratchcounter\plusone + \scratchcounter1 \loop \ifnum\scratchcounter<\nofMParguments \edef\somestring{\somestring\space\gMPa\scratchcounter}% - \advance\scratchcounter \plusone + \advance\scratchcounter 1 \repeat \edef\somestring{\somestring]\gMPa\scratchcounter\space d}% \PDFcode{\somestring}% @@ -1069,7 +1105,7 @@ %D so we can use this one to trigger setting the linewidth. \def\handleMPdtransform - {\ifdim\gMPa1\onepoint>\zeropoint + {\ifdim\gMPa1 pt>0pt \PDFcode{\gMPa1 w}% \def\next##1 ##2 ##3 ##4 ##5 ##6 {\handleMPsequence}% \else @@ -1113,7 +1149,7 @@ \let\closeMPpath\relax \let\flushMPpath\flushnormalMPpath \resetMPstack - \nofMPsegments\plusone + \nofMPsegments1 \let\handleMPsequence\dohandleMPpath \dohandleMPpath} @@ -1159,19 +1195,19 @@ % \def\flushnormalMPpath % {\scratchcounter\nofMPsegments -% \nofMPsegments\plusone +% \nofMPsegments 1 % \loop % \flushnormalMPsegment -% \advance\nofMPsegments \plusone +% \advance\nofMPsegments 1 % \ifnum\nofMPsegments<\scratchcounter % \repeat} % % \def\flushconcatMPpath % {\scratchcounter\nofMPsegments -% \nofMPsegments\plusone +% \nofMPsegments 1 % \loop % \flushconcatMPsegment -% \advance\nofMPsegments \plusone +% \advance\nofMPsegments 1 % \ifnum\nofMPsegments<\scratchcounter % \repeat} % @@ -1179,14 +1215,14 @@ \def\doflushsomeMPpath {\dodoflushsomeMPpath - \advance\nofMPsegments \plusone + \advance\nofMPsegments 1 \ifnum\nofMPsegments<\scratchcounter \expandafter\doflushsomeMPpath \fi} \def\flushsomeMPpath {\scratchcounter\nofMPsegments - \nofMPsegments\plusone + \nofMPsegments 1 \doflushsomeMPpath} \def\flushnormalMPpath{\let\dodoflushsomeMPpath\flushnormalMPsegment\flushsomeMPpath} @@ -1224,7 +1260,7 @@ %OLD \def\doMPreducedimen#1 %OLD {\count0\MPconcatfactor -%OLD \advance\dimen#1 \ifdim\dimen#1>\zeropoint .5\else -.5\fi\count0 +%OLD \advance\dimen#1 \ifdim\dimen#1>0pt .5\else -.5\fi\count0 %OLD \divide\dimen#1 \count0\relax} %OLD % too inaccurate (see old pragma logo) @@ -1234,7 +1270,7 @@ %OLD \divide\dimen#1 \count0\relax} %OLD \def\doMPreducedimen#1 -%OLD {\advance\dimen#1 \ifdim\dimen#1>\zeropoint .5\else -.5\fi\MPconcatfactor +%OLD {\advance\dimen#1 \ifdim\dimen#1>0pt .5\else -.5\fi\MPconcatfactor %OLD \divide\dimen#1 \MPconcatfactor} %D The transformation code is rewritten by Daniel H. Luecking who @@ -1258,13 +1294,13 @@ \newdimen\MPscratchDim % will be assigned global \def\MPadjustdimen % sets \MPscratchDim and \MPscratchCnt - {\MPscratchCnt\zerocount + {\MPscratchCnt0 \doMPadjustdimen} \def\doMPadjustdimen - {\ifdim\MPscratchDim>\onepoint + {\ifdim\MPscratchDim>1pt \divide\MPscratchDim 2 - \advance\MPscratchCnt \plusone + \advance\MPscratchCnt 1 \expandafter\doMPadjustdimen \fi} @@ -1292,14 +1328,14 @@ \def\doMPreadjustdimen {\ifnum\MPscratchCnt>2 \divide\scratchdimen 2 - \advance\MPscratchCnt \minusone + \advance\MPscratchCnt -1 \expandafter\doMPreadjustdimen \fi} \def\MPreciprocaldeterminant {\scratchdimen\withoutpt\the\dimen0 \dimen6 % s_x*s_y \advance\scratchdimen - \withoutpt\the\dimen2 \dimen4 % s_x*s_y - r_x*r_y - \ifdim\scratchdimen<\zeropoint % we need a positive dimension + \ifdim\scratchdimen<0pt % we need a positive dimension \scratchdimen-\scratchdimen % for \MPadjustdimen (?) \doMPreciprocal \scratchdimen-\scratchdimen @@ -1313,7 +1349,7 @@ % todo: dimexpr \def\doMPreciprocal % replace \scratchdimen with its reciprocal - {\ifdim\scratchdimen=\onepoint \else + {\ifdim\scratchdimen=1pt \else \MPadjustdimen \scratchcounter\MPnumerator \divide\scratchcounter\scratchdimen @@ -1322,20 +1358,20 @@ \fi} %OLD \def\presetMPconcat -%OLD {\dimen 0=\gMPs1\onepoint \doMPreducedimen 0 % r_x -%OLD \dimen 2=\gMPs2\onepoint \doMPreducedimen 2 % s_x -%OLD \dimen 4=\gMPs3\onepoint \doMPreducedimen 4 % s_y -%OLD \dimen 6=\gMPs4\onepoint \doMPreducedimen 6 % r_y -%OLD \dimen 8=\gMPs5\onepoint \doMPreducedimen 8 % t_x -%OLD \dimen10=\gMPs6\onepoint \doMPreducedimen10 } % t_y +%OLD {\dimen 0=\gMPs1pt \doMPreducedimen 0 % r_x +%OLD \dimen 2=\gMPs2pt \doMPreducedimen 2 % s_x +%OLD \dimen 4=\gMPs3pt \doMPreducedimen 4 % s_y +%OLD \dimen 6=\gMPs4pt \doMPreducedimen 6 % r_y +%OLD \dimen 8=\gMPs5pt \doMPreducedimen 8 % t_x +%OLD \dimen10=\gMPs6pt \doMPreducedimen10 } % t_y %OLD %OLD \def\presetMPscale -%OLD {\dimen 0=\gMPs1\onepoint \doMPreducedimen 0 -%OLD \dimen 2 \zeropoint -%OLD \dimen 4 \zeropoint -%OLD \dimen 6=\gMPs2\onepoint \doMPreducedimen 6 -%OLD \dimen 8 \zeropoint -%OLD \dimen10 \zeropoint} +%OLD {\dimen 0=\gMPs1pt \doMPreducedimen 0 +%OLD \dimen 2=0pt +%OLD \dimen 4=0pt +%OLD \dimen 6=\gMPs2pt \doMPreducedimen 6 +%OLD \dimen 8=0pt +%OLD \dimen10=0pt} \def\cleanupMPconcat {\ignoreMPspecials @@ -1344,24 +1380,24 @@ \keepMPspecials} \def\presetMPconcat - {\dimen 0=\gMPs1\onepoint % s_x - \dimen 2=\gMPs2\onepoint % r_x - \dimen 4=\gMPs3\onepoint % r_y - \dimen 6=\gMPs4\onepoint % s_y - \dimen 8=\gMPs5\onepoint % t_x - \dimen10=\gMPs6\onepoint} % t_y + {\dimen 0=\gMPs1pt % s_x + \dimen 2=\gMPs2pt % r_x + \dimen 4=\gMPs3pt % r_y + \dimen 6=\gMPs4pt % s_y + \dimen 8=\gMPs5pt % t_x + \dimen10=\gMPs6pt} % t_y \def\presetMPscale - {\dimen 0=\gMPs1\onepoint - \dimen 2 \zeropoint - \dimen 4 \zeropoint - \dimen 6=\gMPs2\onepoint - \dimen 8 \zeropoint - \dimen10 \zeropoint} + {\dimen 0=\gMPs1pt + \dimen 2=0pt + \dimen 4=0pt + \dimen 6=\gMPs2pt + \dimen 8=0pt + \dimen10=0pt} \def\noMPtranslate % use this one grouped - {\dimen 8 \zeropoint % t_x - \dimen10 \zeropoint} % t_y + {\dimen 8=0pt % t_x + \dimen10=0pt} % t_y %D \starttyping %D \def\doMPconcat#1#2#3#4% @@ -1537,18 +1573,18 @@ %OLD {\dimen12=#1pt % p_x %OLD \dimen14=#3pt % p_y %OLD % -%OLD \chardef\MPfactor\zerocount +%OLD \chardef\MPfactor0 %OLD \ifdim\dimen4<\MPcriteriumB\ifdim\dimen4>-\MPcriteriumB %OLD \ifdim\dimen6<\MPcriteriumB\ifdim\dimen6>-\MPcriteriumB %OLD \ifdim\dimen8<\MPcriteriumB\ifdim\dimen8>-\MPcriteriumB %OLD \ifdim\dimen10<\MPcriteriumB\ifdim\dimen10>-\MPcriteriumB -%OLD \chardef\MPfactor\plusone +%OLD \chardef\MPfactor1 %OLD \fi\fi %OLD \fi\fi %OLD \fi\fi %OLD \fi\fi %OLD \ifcase\MPfactor % spurious 0 removed -%OLD \chardef\MPfactor\plusone +%OLD \chardef\MPfactor1 %OLD \ifdim\dimen12<\MPcriteriumA\ifdim\dimen12>-\MPcriteriumA %OLD \ifdim\dimen14<\MPcriteriumA\ifdim\dimen14>-\MPcriteriumA %OLD \chardef\MPfactor16 @@ -1590,8 +1626,8 @@ %OLD \multiply \dimen20 \dimen10 %OLD \advance \dimen12 -\dimen20 %OLD % -%OLD \ifdim\dimen16=\onepoint \else -%OLD \ifdim\dimen16>\MPconcatfactor \onepoint \relax +%OLD \ifdim\dimen16=1pt \else +%OLD \ifdim\dimen16>\MPconcatfactor 1pt \relax %OLD \doMPreducedimen16 %OLD \divide \dimen18 \dimen16 \doMPexpanddimen18 %OLD \divide \dimen12 \dimen16 \doMPexpanddimen12 @@ -1621,8 +1657,8 @@ %D If this should ever cause problems, the scale factors can be reduced. % \def\doMPconcat#1#2#3#4% -% {\dimen12=#1pt % p_x % #1\onepoint -% \dimen14=#3pt % p_y % #3\onepoint +% {\dimen12=#1pt % p_x % #1pt +% \dimen14=#3pt % p_y % #3pt % \advance\dimen12 -\dimen8 % p_x - t_x % \advance\dimen14 -\dimen10 % p_y - t_y % \dimen18=\withoutpt\the\dimen6 \dimen12 % s_y(p_x - t_x) @@ -1636,8 +1672,8 @@ % \edef#4{\withoutpt\the\dimen14}} % p_y^\prime \def\doMPconcat#1#2#3#4% - {\dimen12=#1pt % p_x % #1\onepoint - \dimen14=#3pt % p_y % #3\onepoint + {\dimen12=#1pt % p_x % #1pt + \dimen14=#3pt % p_y % #3pt \advance\dimen12 -\dimen8 % p_x - t_x \advance\dimen14 -\dimen10 % p_y - t_y \dimen18=\withoutpt\the\dimen6 \dimen12 % s_y(p_x - t_x) @@ -1917,7 +1953,7 @@ \fi \let\handleMPsequence\dohandleMPsequence \resetMPstack - \nofMPsegments\zerocount + \nofMPsegments0 \handleMPsequence} %D The following \METAPOST\ code is quite valid but, when @@ -1936,7 +1972,7 @@ {\ifcase\finiMPpath \ifnum\nofMPsegments<3 % n is one ahead \message{omitting zero clip path}% - \nofMPsegments\zerocount + \nofMPsegments0 \fi \fi} @@ -1959,9 +1995,9 @@ \def\dohandleMPpath#1% {\ifcase\lccode`#1\relax - \@EA\dohandleMPpathA + \expandafter\dohandleMPpathA \else - \@EA\dohandleMPpathB + \expandafter\dohandleMPpathB \fi#1} %\def\dohandleMPpathA#1 % @@ -1970,44 +2006,118 @@ \let\dohandleMPpathA\setMPsequence +% \def\dohandleMPpathB#1 % +% {\def\somestring{#1}% +% \ifx\somestring\PSlineto +% \setMPkeyword0 +% \else\ifx\somestring\PScurveto +% \setMPkeyword1 +% \else\ifx\somestring\PSrlineto +% \setMPkeyword2 +% \else\ifx\somestring\PSmoveto +% \setMPkeyword3 +% \else\ifx\somestring\PSclip +% % \chardef\finiMPpath0 % already +% \let\handleMPsequence\processMPpath +% \else\ifx\somestring\PSgsave +% \chardef\finiMPpath3 +% \else\ifx\somestring\PSgrestore +% \else\ifx\somestring\PSfill +% \ifcase\finiMPpath +% \chardef\finiMPpath2 +% \let\handleMPsequence\processMPpath +% \fi +% \else\ifx\somestring\PSstroke +% \ifcase\finiMPpath +% \chardef\finiMPpath1 +% \fi +% \let\handleMPsequence\processMPpath +% \else\ifx\somestring\PSclosepath +% \def\closeMPpath{\PDFcode{h}}% +% \else\ifx\somestring\PSconcat +% \cleanupMPconcat +% \let\flushMPpath\flushconcatMPpath +% \handleMPpathconcat +% \else\ifx\somestring\PSscale +% \let\flushMPpath\flushconcatMPpath +% \handleMPpathscale +% \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi +% \handleMPsequence} + +\def\installMPSkeywordP#1#2% + {\expandafter\def\csname\@@MP:P:#1\endcsname{#2}} + +\def\installMPSshortcutP#1#2% todo: \let + {\expandafter\let\csname\@@MP:P:#1\expandafter\endcsname\csname\@@MP:P:#2\endcsname} + \def\dohandleMPpathB#1 % {\def\somestring{#1}% - \ifx\somestring\PSlineto - \setMPkeyword0 - \else\ifx\somestring\PScurveto - \setMPkeyword1 - \else\ifx\somestring\PSrlineto - \setMPkeyword2 - \else\ifx\somestring\PSmoveto - \setMPkeyword3 - \else\ifx\somestring\PSclip - % \chardef\finiMPpath0 % already - \let\handleMPsequence\processMPpath - \else\ifx\somestring\PSgsave - \chardef\finiMPpath3 - \else\ifx\somestring\PSgrestore - \else\ifx\somestring\PSfill - \ifcase\finiMPpath - \chardef\finiMPpath2 - \let\handleMPsequence\processMPpath - \fi - \else\ifx\somestring\PSstroke - \ifcase\finiMPpath - \chardef\finiMPpath1 - \fi - \let\handleMPsequence\processMPpath - \else\ifx\somestring\PSclosepath - \def\closeMPpath{\PDFcode{h}}% - \else\ifx\somestring\PSconcat - \cleanupMPconcat - \let\flushMPpath\flushconcatMPpath - \handleMPpathconcat - \else\ifx\somestring\PSscale - \let\flushMPpath\flushconcatMPpath - \handleMPpathscale - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi + \ifcsname\@@MP:P:\somestring\endcsname + \csname\@@MP:P:\somestring\expandafter\endcsname + \fi \handleMPsequence} +\ifx\eTeXversion\undefined + \def\dohandleMPpathB#1 % + {\def\somestring{#1}% + \csname\@@MP:P:\somestring\endcsname + \handleMPsequence} +\fi + +\installMPSkeywordP \PSlineto + {\setMPkeyword0 } +\installMPSkeywordP \PScurveto + {\setMPkeyword1 } +\installMPSkeywordP \PSrlineto + {\setMPkeyword2 } +\installMPSkeywordP \PSmoveto + {\edef\lastMPmoveX{\gMPs1}% + \edef\lastMPmoveY{\gMPs2}% + \resetMPstack + \setMPkeyword3 } +\installMPSkeywordP \PSclip + {% \chardef\finiMPpath\zerocount % already + \let\handleMPsequence\processMPpath} +\installMPSkeywordP \PSgsave + {\chardef\finiMPpath3 } +\installMPSkeywordP \PSgrestore + {} +\installMPSkeywordP \PSfill + {\ifcase\finiMPpath + \chardef\finiMPpath2 + \let\handleMPsequence\processMPpath + \fi} +\installMPSkeywordP \PSstroke + {\ifcase\finiMPpath + \chardef\finiMPpath1 + \fi + \let\handleMPsequence\processMPpath} +\installMPSkeywordP \PSclosepath + {\def\closeMPpath{\PDFcode{h}}} +\installMPSkeywordP \PSconcat + {\cleanupMPconcat + \let\flushMPpath\flushconcatMPpath + \handleMPpathconcat} +\installMPSkeywordP \PSscale + {\let\flushMPpath\flushconcatMPpath + \handleMPpathscale} + +\installMPSshortcutP {l} \PSlineto +\installMPSshortcutP {r} \PSrlineto +\installMPSshortcutP {m} \PSmoveto +\installMPSshortcutP {c} \PScurveto + +\installMPSshortcutP {q} \PSgsave +\installMPSshortcutP {Q} \PSgrestore +\installMPSshortcutP {S} \PSstroke +\installMPSshortcutP {F} \PSfill +\installMPSshortcutP {B} \PSgsave +\installMPSshortcutP {W} \PSclip +\installMPSshortcutP {p} \PSclosepath + +\installMPSshortcutP {s} \PSscale +\installMPSshortcutP {t} \PSconcat + %D The main conversion command is: %D %D \starttyping @@ -2055,10 +2165,11 @@ \def\convertMPtoPDF % #1#2#3% {\bgroup + \defineMPtoPDFfallbacks \ifx\pdfdecimaldigits\undefined\else \pdfdecimaldigits=5 \fi % new \setbox\scratchbox\vbox\bgroup - \xdef\MPheight{\zeropoint}% - \xdef\MPwidth {\zeropoint}% + \xdef\MPheight{0pt}% + \xdef\MPwidth {0pt}% \forgetall \offinterlineskip \startMPresources @@ -2074,15 +2185,7 @@ \let\setMPextensions\relax \def\doprocessMPtoPDFfile#1#2#3% file xscale yscale - {% the following line is needed for latex where onepoint is not - % onepoint but a number (maxdimen); some day i'll make a latex - % variant of this file so that i no longer have to deal with such - % issues; then i'll also speed up this module using a few context - % tricks - % - \let\onepoint\onerealpoint - % - \setMPspecials + {\setMPspecials \setMPextensions \the\everyMPtoPDFconversion \catcode`\^^M=\@@endofline @@ -2092,65 +2195,16 @@ \xdef\MPyscale{#3}% \xdef\MPxoffset{0}% \xdef\MPyoffset{0}% - \xdef\MPyshift{\zeropoint}% + \xdef\MPyshift{0pt}% \donefalse \let\handleMPsequence\dohandleMPsequence \message{[MP to PDF]}% was: [MP to PDF #1] but there is a (#1) anyway \input#1\relax} -% strange rounding/clip in pdftex/viewer -% -% \def\finishMPgraphic -% {\stopMPresources -% \egroup -% \ifx\pdftexversion\undefined\else\ifnum\pdftexversion<14 % for the moment -% \chardef\makeMPintoPDFobject=0 -% \fi\fi -% \ifcase\makeMPintoPDFobject\or\or\ifx\currentPDFresources\empty\else -% \chardef\makeMPintoPDFobject=1 -% \fi\fi -% \setbox\scratchbox=\vbox -% {\forgetall -% \hbox -% {\PDFcode{q \MPxscale\space 0 0 \MPyscale\space \MPxoffset\space \MPyoffset\space cm}% -% \lower\MPyshift\box\scratchbox % unscaled shift -% \PDFcode{Q}}}% -% \ht\scratchbox\MPheight -% \wd\scratchbox\MPwidth -% \dp\scratchbox\zeropoint -% \ifcase\makeMPintoPDFobject -% \box\scratchbox -% \or -% \immediate\pdfxform resources{\currentPDFresources}\scratchbox -% \xdef\lastPDFMPobject{\the\pdflastxform}% -% \pdfrefxform\lastPDFMPobject -% \global\let\currentPDFresources\empty -% \else -% \box\scratchbox -% \fi -% \egroup} -% -% funny clip in viewer -% -% \setbox\scratchbox=\vbox -% {\forgetall -% \dimen0=\MPllx bp -% \dimen2=\MPlly bp -% \setbox\scratchbox=\hbox{\hskip-\dimen0\raise-\dimen2\box\scratchbox}% -% \ht\scratchbox=\zeropoint -% \dp\scratchbox=\zeropoint -% \wd\scratchbox=\zeropoint -% \hbox -% {\PDFcode{q \MPxscale\space 0 0 \MPyscale\space 0 0 cm}% -% \lower\MPshift\box\scratchbox -% \PDFcode{Q}}}% - -% \let\PDFMPformoffset\zeropoint - \def\PDFMPformoffset - {\ifx\objectoffset\undefined\zeropoint\else\objectoffset\fi} + {\ifx\objectoffset\undefined0pt\else\objectoffset\fi} -\chardef\blackoutMPgraphic\zerocount % in ConTeXt \plusone +\chardef\blackoutMPgraphic0 % in ConTeXt 1 \def\finishMPgraphic {\stopMPresources @@ -2164,7 +2218,7 @@ \PDFcode{Q}}}% \ht\scratchbox\MPheight \wd\scratchbox\MPwidth - \dp\scratchbox\zeropoint\relax + \dp\scratchbox0pt\relax \dopackageMPgraphic\scratchbox \egroup \endinput} @@ -2174,28 +2228,28 @@ \def\dopackageMPgraphic#1% #1 = boxregister {%\ifx\pdfxform\undefined - % \chardef\makeMPintoPDFobject\zerocount % no pdftex at all + % \chardef\makeMPintoPDFobject0 % no pdftex at all %\else\ifx\pdftexversion\undefined - % \chardef\makeMPintoPDFobject\zerocount % no pdftex at all + % \chardef\makeMPintoPDFobject0 % no pdftex at all %\else\ifnum\pdftexversion<14 - % \chardef\makeMPintoPDFobject\zerocount % no resource support + % \chardef\makeMPintoPDFobject0 % no resource support %\else % % keep the default value %\fi\fi\fi \ifcase\makeMPintoPDFobject\or\or\ifx\currentPDFresources\empty\else % an existing value of 2 signals object support (set elsewhere) - \chardef\makeMPintoPDFobject\plusone + \chardef\makeMPintoPDFobject1 \fi\fi \ifcase\makeMPintoPDFobject \box#1% \or \scratchdimen\PDFMPformoffset\relax - \ifdim\scratchdimen>\zeropoint % compensate for error + \ifdim\scratchdimen>0pt % compensate for error \setbox#1\vbox spread 2\scratchdimen {\forgetall\vss\hbox spread 2\scratchdimen{\hss\box#1\hss}\vss}% \fi \setMPPDFobject{\currentPDFresources}{#1}% - \ifdim\scratchdimen>\zeropoint % compensate for error + \ifdim\scratchdimen>0pt % compensate for error \vbox to \MPheight {\forgetall\vss\hbox to \MPwidth{\hss\getMPPDFobject\hss}\vss}% \else @@ -2262,6 +2316,4 @@ %D does all the calculations. Converting other \POSTSCRIPT\ %D files would drive both me and \TEX\ crazy. -\ifx\undefined\StopLatexHack \else \StopLatexHack \fi - \protect \endinput |