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 | 660 |
1 files changed, 413 insertions, 247 deletions
diff --git a/Master/texmf-dist/tex/context/base/supp-pdf.tex b/Master/texmf-dist/tex/context/base/supp-pdf.tex index 5197e564d7f..656a8f6fbce 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=2006.09.02, % 2004.12.16, +%D version=2004.12.16, %D title=\CONTEXT\ Support Macros, %D subtitle=\METAPOST\ to \PDF\ conversion, %D author=Hans Hagen \& others (see text), @@ -11,142 +11,6 @@ %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 @@ -161,10 +25,23 @@ %D his initials. (We keep the old code around because it's a %D nice illustration on how a module like this evolves.) -%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. +% 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 This module handles some \PDF\ conversion and insertions %D topics. By default, the macros use the \PDFTEX\ primitive @@ -172,6 +49,8 @@ %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 @@ -190,7 +69,7 @@ %D First we define a handy constant: -\bgroup \defineMPtoPDFfallbacks \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup +\bgroup \catcode`\%=\@@other \xdef\letterpercent{\string%} \egroup %D \macros %D {pdfimage,pdfimages,pdfclippedimage} @@ -215,6 +94,12 @@ %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#% @@ -229,8 +114,11 @@ \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} @@ -277,12 +165,218 @@ \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 @@ -411,17 +505,17 @@ \def\@@MP{@@MP} \def\setMPargument% #1% - {\advance\nofMParguments 1 + {\advance\nofMParguments \plusone \expandafter\def \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname} % {#1} \def\letMPargument - {\advance\nofMParguments 1 + {\advance\nofMParguments \plusone \expandafter\let \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname} \def\setMPsequence#1 % - {\advance\nofMParguments 1 + {\advance\nofMParguments \plusone \expandafter\def \csname\@@MP\the\nofMPsegments\the\nofMParguments\endcsname{#1}% \handleMPsequence} @@ -433,12 +527,12 @@ {\csname\@@MP\the\nofMPsegments\number#1\endcsname} \def\dogMPa#1% - {\expandafter\expandafter\expandafter\do\csname\@@MP0\number#1\endcsname} + {\@EAEAEA\do\csname\@@MP0\number#1\endcsname} \def\setMPkeyword#1 % {\expandafter\def\csname\@@MP\the\nofMPsegments0\endcsname{#1}% - \advance\nofMPsegments 1 - \nofMParguments0} + \advance\nofMPsegments \plusone + \nofMParguments\zerocount} \def\getMPkeyword% #1% {\csname\@@MP\the\nofMPsegments0\endcsname} % {\csname\@@MP#10\endcsname} @@ -455,7 +549,7 @@ %D when dealing with comments. \def\doresetMPstack - {\nofMParguments0} + {\nofMParguments\zerocount} \def\resetMPstack {\let\handleMPgraphic\handleMPendgraphic @@ -503,7 +597,6 @@ %D when needed we either ignore or obey them \bgroup -\defineMPtoPDFfallbacks \catcode`\|=\@@comment \catcode`\%=\@@active \catcode`\[=\@@active @@ -560,7 +653,6 @@ %D that we cannot change the catcodes in between. \bgroup -\defineMPtoPDFfallbacks \catcode`\%=\@@active \gdef\startMPscanning{\let%=\startMPconversion} \egroup @@ -588,15 +680,17 @@ %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 - \expandafter\expandafter\expandafter\dohandleMPsequenceA + \@EAEAEA\dohandleMPsequenceA \else - \expandafter\expandafter\expandafter\dohandleMPsequenceB + \@EAEAEA\dohandleMPsequenceB \fi \else - \expandafter\dohandleMPsequenceC + \@EA\dohandleMPsequenceC \fi#1} %\def\dohandleMPsequenceA#1 % @@ -756,20 +850,20 @@ {\ifnum#1>\currentMPboundingbox \xdef\MPllx{#2}\xdef\MPlly{#3}% \xdef\MPurx{#4}\xdef\MPury{#5}% - \dimen0=#2pt + \dimen0=#2\onepoint \dimen0=-\MPxscale\dimen0 - \dimen2=#3pt + \dimen2=#3\onepoint \dimen2=-\MPyscale\dimen2 \xdef\MPxoffset{\withoutpt\the\dimen0}% \xdef\MPyoffset{\withoutpt\the\dimen2}% - \dimen0=#2bp + \dimen0=#2\onebasepoint \dimen0=-\dimen0 - \dimen2=#3bp + \dimen2=#3\onebasepoint \dimen2=-\dimen2 - \advance\dimen0 #4bp + \advance\dimen0 #4\onebasepoint \dimen0=\MPxscale\dimen0 \xdef\MPwidth{\the\dimen0}% - \advance\dimen2 #5bp + \advance\dimen2 #5\onebasepoint \xdef\MPyshift{\the\dimen2}% unscaled \dimen2=\MPyscale\dimen2 \xdef\MPheight{\the\dimen2}% @@ -779,7 +873,7 @@ \let\handleMPsequence\dohandleMPsequence \let\next\handleMPsequence \ifskipemptyMPgraphic - \ifdim\MPheight=0pt\relax\ifdim\MPwidth=0pt\relax + \ifdim\MPheight=\zeropoint\relax\ifdim\MPwidth=\zeropoint\relax \def\next{\endinput\finishMPgraphic}% \fi\fi \fi @@ -837,31 +931,31 @@ \let\ \relax % mp breaks long lines and appends a \ \edef\size{\gMPa\nofMParguments}% \ifx\size\PSnfont % round font size (to pt) - \advance\nofMParguments -1 - \expandafter\scratchdimen\gMPa\nofMParguments pt\relax - \ifdim\scratchdimen<1pt + \advance\nofMParguments \minusone + \expandafter\scratchdimen\gMPa\nofMParguments\onepoint\relax + \ifdim\scratchdimen<\onepoint \def\size{1pt}% \else - \advance\scratchdimen .5pt + \advance\scratchdimen .5\onepoint \def\size##1.##2\relax{\def\size{##1pt}}% \expandafter\size\the\scratchdimen\relax \fi \else \edef\size{\size bp}% \fi - \advance\nofMParguments -1 + \advance\nofMParguments \minusone %\font\temp=\gMPa\nofMParguments\space at \size \let\temp\relax % to be sure \setMPfshowfont{\gMPa\nofMParguments}\size - \advance\nofMParguments -1 + \advance\nofMParguments \minusone \temp \MPfshowcommand - {\ifnum\nofMParguments=1 + {\ifnum\nofMParguments=\plusone \def\do(##1){##1}% \dogMPa1% \else % we need to catch ( a ) (a a a) (\123 \123 \123) etc - \scratchcounter1 + \scratchcounter\plusone \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}% @@ -869,7 +963,7 @@ \dogMPa\scratchcounter\MPspacechar \let\do\relax \loop - \advance\scratchcounter 1 + \advance\scratchcounter \plusone \ifnum\scratchcounter<\nofMParguments\relax \gMPa\scratchcounter\MPspacechar \repeat @@ -877,11 +971,25 @@ \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 bp\raise\lastMPmoveY bp\box\scratchbox}% - \ht\scratchbox0pt% - \dp\scratchbox0pt% - \wd\scratchbox0pt% + {\hskip\lastMPmoveX\onebasepoint\raise\lastMPmoveY\onebasepoint\box\scratchbox}% + \ht\scratchbox\zeropoint + \dp\scratchbox\zeropoint + \wd\scratchbox\zeropoint \box\scratchbox \egroup} @@ -923,11 +1031,11 @@ {\bgroup \ignoreMPspecials \def\somestring{[}% - \scratchcounter1 + \scratchcounter\plusone \loop \ifnum\scratchcounter<\nofMParguments \edef\somestring{\somestring\space\gMPa\scratchcounter}% - \advance\scratchcounter 1 + \advance\scratchcounter \plusone \repeat \edef\somestring{\somestring]\gMPa\scratchcounter\space d}% \PDFcode{\somestring}% @@ -961,7 +1069,7 @@ %D so we can use this one to trigger setting the linewidth. \def\handleMPdtransform - {\ifdim\gMPa1 pt>0pt + {\ifdim\gMPa1\onepoint>\zeropoint \PDFcode{\gMPa1 w}% \def\next##1 ##2 ##3 ##4 ##5 ##6 {\handleMPsequence}% \else @@ -1005,7 +1113,7 @@ \let\closeMPpath\relax \let\flushMPpath\flushnormalMPpath \resetMPstack - \nofMPsegments1 + \nofMPsegments\plusone \let\handleMPsequence\dohandleMPpath \dohandleMPpath} @@ -1051,19 +1159,19 @@ % \def\flushnormalMPpath % {\scratchcounter\nofMPsegments -% \nofMPsegments 1 +% \nofMPsegments\plusone % \loop % \flushnormalMPsegment -% \advance\nofMPsegments 1 +% \advance\nofMPsegments \plusone % \ifnum\nofMPsegments<\scratchcounter % \repeat} % % \def\flushconcatMPpath % {\scratchcounter\nofMPsegments -% \nofMPsegments 1 +% \nofMPsegments\plusone % \loop % \flushconcatMPsegment -% \advance\nofMPsegments 1 +% \advance\nofMPsegments \plusone % \ifnum\nofMPsegments<\scratchcounter % \repeat} % @@ -1071,14 +1179,14 @@ \def\doflushsomeMPpath {\dodoflushsomeMPpath - \advance\nofMPsegments 1 + \advance\nofMPsegments \plusone \ifnum\nofMPsegments<\scratchcounter \expandafter\doflushsomeMPpath \fi} \def\flushsomeMPpath {\scratchcounter\nofMPsegments - \nofMPsegments 1 + \nofMPsegments\plusone \doflushsomeMPpath} \def\flushnormalMPpath{\let\dodoflushsomeMPpath\flushnormalMPsegment\flushsomeMPpath} @@ -1116,7 +1224,7 @@ %OLD \def\doMPreducedimen#1 %OLD {\count0\MPconcatfactor -%OLD \advance\dimen#1 \ifdim\dimen#1>0pt .5\else -.5\fi\count0 +%OLD \advance\dimen#1 \ifdim\dimen#1>\zeropoint .5\else -.5\fi\count0 %OLD \divide\dimen#1 \count0\relax} %OLD % too inaccurate (see old pragma logo) @@ -1126,7 +1234,7 @@ %OLD \divide\dimen#1 \count0\relax} %OLD \def\doMPreducedimen#1 -%OLD {\advance\dimen#1 \ifdim\dimen#1>0pt .5\else -.5\fi\MPconcatfactor +%OLD {\advance\dimen#1 \ifdim\dimen#1>\zeropoint .5\else -.5\fi\MPconcatfactor %OLD \divide\dimen#1 \MPconcatfactor} %D The transformation code is rewritten by Daniel H. Luecking who @@ -1150,13 +1258,13 @@ \newdimen\MPscratchDim % will be assigned global \def\MPadjustdimen % sets \MPscratchDim and \MPscratchCnt - {\MPscratchCnt0 + {\MPscratchCnt\zerocount \doMPadjustdimen} \def\doMPadjustdimen - {\ifdim\MPscratchDim>1pt + {\ifdim\MPscratchDim>\onepoint \divide\MPscratchDim 2 - \advance\MPscratchCnt 1 + \advance\MPscratchCnt \plusone \expandafter\doMPadjustdimen \fi} @@ -1184,14 +1292,14 @@ \def\doMPreadjustdimen {\ifnum\MPscratchCnt>2 \divide\scratchdimen 2 - \advance\MPscratchCnt -1 + \advance\MPscratchCnt \minusone \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<0pt % we need a positive dimension + \ifdim\scratchdimen<\zeropoint % we need a positive dimension \scratchdimen-\scratchdimen % for \MPadjustdimen (?) \doMPreciprocal \scratchdimen-\scratchdimen @@ -1205,7 +1313,7 @@ % todo: dimexpr \def\doMPreciprocal % replace \scratchdimen with its reciprocal - {\ifdim\scratchdimen=1pt \else + {\ifdim\scratchdimen=\onepoint \else \MPadjustdimen \scratchcounter\MPnumerator \divide\scratchcounter\scratchdimen @@ -1214,20 +1322,20 @@ \fi} %OLD \def\presetMPconcat -%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 {\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 %OLD \def\presetMPscale -%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} +%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} \def\cleanupMPconcat {\ignoreMPspecials @@ -1236,24 +1344,24 @@ \keepMPspecials} \def\presetMPconcat - {\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 + {\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 \def\presetMPscale - {\dimen 0=\gMPs1pt - \dimen 2=0pt - \dimen 4=0pt - \dimen 6=\gMPs2pt - \dimen 8=0pt - \dimen10=0pt} + {\dimen 0=\gMPs1\onepoint + \dimen 2 \zeropoint + \dimen 4 \zeropoint + \dimen 6=\gMPs2\onepoint + \dimen 8 \zeropoint + \dimen10 \zeropoint} \def\noMPtranslate % use this one grouped - {\dimen 8=0pt % t_x - \dimen10=0pt} % t_y + {\dimen 8 \zeropoint % t_x + \dimen10 \zeropoint} % t_y %D \starttyping %D \def\doMPconcat#1#2#3#4% @@ -1429,18 +1537,18 @@ %OLD {\dimen12=#1pt % p_x %OLD \dimen14=#3pt % p_y %OLD % -%OLD \chardef\MPfactor0 +%OLD \chardef\MPfactor\zerocount %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\MPfactor1 +%OLD \chardef\MPfactor\plusone %OLD \fi\fi %OLD \fi\fi %OLD \fi\fi %OLD \fi\fi %OLD \ifcase\MPfactor % spurious 0 removed -%OLD \chardef\MPfactor1 +%OLD \chardef\MPfactor\plusone %OLD \ifdim\dimen12<\MPcriteriumA\ifdim\dimen12>-\MPcriteriumA %OLD \ifdim\dimen14<\MPcriteriumA\ifdim\dimen14>-\MPcriteriumA %OLD \chardef\MPfactor16 @@ -1482,8 +1590,8 @@ %OLD \multiply \dimen20 \dimen10 %OLD \advance \dimen12 -\dimen20 %OLD % -%OLD \ifdim\dimen16=1pt \else -%OLD \ifdim\dimen16>\MPconcatfactor 1pt \relax +%OLD \ifdim\dimen16=\onepoint \else +%OLD \ifdim\dimen16>\MPconcatfactor \onepoint \relax %OLD \doMPreducedimen16 %OLD \divide \dimen18 \dimen16 \doMPexpanddimen18 %OLD \divide \dimen12 \dimen16 \doMPexpanddimen12 @@ -1513,8 +1621,8 @@ %D If this should ever cause problems, the scale factors can be reduced. % \def\doMPconcat#1#2#3#4% -% {\dimen12=#1pt % p_x % #1pt -% \dimen14=#3pt % p_y % #3pt +% {\dimen12=#1pt % p_x % #1\onepoint +% \dimen14=#3pt % p_y % #3\onepoint % \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) @@ -1528,8 +1636,8 @@ % \edef#4{\withoutpt\the\dimen14}} % p_y^\prime \def\doMPconcat#1#2#3#4% - {\dimen12=#1pt % p_x % #1pt - \dimen14=#3pt % p_y % #3pt + {\dimen12=#1pt % p_x % #1\onepoint + \dimen14=#3pt % p_y % #3\onepoint \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) @@ -1809,7 +1917,7 @@ \fi \let\handleMPsequence\dohandleMPsequence \resetMPstack - \nofMPsegments0 + \nofMPsegments\zerocount \handleMPsequence} %D The following \METAPOST\ code is quite valid but, when @@ -1828,7 +1936,7 @@ {\ifcase\finiMPpath \ifnum\nofMPsegments<3 % n is one ahead \message{omitting zero clip path}% - \nofMPsegments0 + \nofMPsegments\zerocount \fi \fi} @@ -1851,9 +1959,9 @@ \def\dohandleMPpath#1% {\ifcase\lccode`#1\relax - \expandafter\dohandleMPpathA + \@EA\dohandleMPpathA \else - \expandafter\dohandleMPpathB + \@EA\dohandleMPpathB \fi#1} %\def\dohandleMPpathA#1 % @@ -1947,11 +2055,10 @@ \def\convertMPtoPDF % #1#2#3% {\bgroup - \defineMPtoPDFfallbacks \ifx\pdfdecimaldigits\undefined\else \pdfdecimaldigits=5 \fi % new \setbox\scratchbox\vbox\bgroup - \xdef\MPheight{0pt}% - \xdef\MPwidth {0pt}% + \xdef\MPheight{\zeropoint}% + \xdef\MPwidth {\zeropoint}% \forgetall \offinterlineskip \startMPresources @@ -1967,7 +2074,15 @@ \let\setMPextensions\relax \def\doprocessMPtoPDFfile#1#2#3% file xscale yscale - {\setMPspecials + {% 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 \setMPextensions \the\everyMPtoPDFconversion \catcode`\^^M=\@@endofline @@ -1977,16 +2092,65 @@ \xdef\MPyscale{#3}% \xdef\MPxoffset{0}% \xdef\MPyoffset{0}% - \xdef\MPyshift{0pt}% + \xdef\MPyshift{\zeropoint}% \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\undefined0pt\else\objectoffset\fi} + {\ifx\objectoffset\undefined\zeropoint\else\objectoffset\fi} -\chardef\blackoutMPgraphic0 % in ConTeXt 1 +\chardef\blackoutMPgraphic\zerocount % in ConTeXt \plusone \def\finishMPgraphic {\stopMPresources @@ -2000,7 +2164,7 @@ \PDFcode{Q}}}% \ht\scratchbox\MPheight \wd\scratchbox\MPwidth - \dp\scratchbox0pt\relax + \dp\scratchbox\zeropoint\relax \dopackageMPgraphic\scratchbox \egroup \endinput} @@ -2010,28 +2174,28 @@ \def\dopackageMPgraphic#1% #1 = boxregister {%\ifx\pdfxform\undefined - % \chardef\makeMPintoPDFobject0 % no pdftex at all + % \chardef\makeMPintoPDFobject\zerocount % no pdftex at all %\else\ifx\pdftexversion\undefined - % \chardef\makeMPintoPDFobject0 % no pdftex at all + % \chardef\makeMPintoPDFobject\zerocount % no pdftex at all %\else\ifnum\pdftexversion<14 - % \chardef\makeMPintoPDFobject0 % no resource support + % \chardef\makeMPintoPDFobject\zerocount % 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\makeMPintoPDFobject1 + \chardef\makeMPintoPDFobject\plusone \fi\fi \ifcase\makeMPintoPDFobject \box#1% \or \scratchdimen\PDFMPformoffset\relax - \ifdim\scratchdimen>0pt % compensate for error + \ifdim\scratchdimen>\zeropoint % 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>0pt % compensate for error + \ifdim\scratchdimen>\zeropoint % compensate for error \vbox to \MPheight {\forgetall\vss\hbox to \MPwidth{\hss\getMPPDFobject\hss}\vss}% \else @@ -2098,4 +2262,6 @@ %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 |