summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv188
1 files changed, 110 insertions, 78 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv b/Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv
index 9e88ab19399..3b0dd78520a 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv
+++ b/Master/texmf-dist/tex/context/base/mkiv/back-pdf.mkiv
@@ -11,10 +11,11 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-%D The less there is here, the better.
+%D The less ther ei shere, the better.
\writestatus{loading}{ConTeXt Backend Macros / PDF}
+%registerctxluafile{lpdf-aux}{optimize} % common helpers
\registerctxluafile{lpdf-ini}{optimize}
\registerctxluafile{lpdf-nod}{}
\registerctxluafile{lpdf-col}{}
@@ -31,22 +32,9 @@
\registerctxluafile{lpdf-swf}{} % this will become a module
\registerctxluafile{lpdf-tag}{}
\registerctxluafile{lpdf-fmt}{}
-\registerctxluafile{lpdf-pde}{}
-
-\ifcase\contextlmtxmode\else
- \registerctxluafile{lpdf-img}{optimize}
-\fi
-
+\registerctxluafile{lpdf-epd}{}
\registerctxluafile{lpdf-epa}{}
-\ifcase\contextlmtxmode\else
- \registerctxluafile{lpdf-emb}{optimize}
-\fi
-
-\registerctxluafile{back-pdp}{}
-
-\registerctxluafile{lpdf-fnt}{}
-
\registerctxluafile{back-pdf}{} % some code will move to lpdf-*
\loadmarkfile{back-u3d} % this will become a module
@@ -59,53 +47,26 @@
%D
%D Here we initialize some internal quantities. We also protect them.
-\ifdefined\outputmode
- \outputmode\plusone
- \let\outputmode\relax
- \newcount\outputmode
- \outputmode\plusone
- \let\normaloutputmode\outputmode
-\fi
+\outputmode\plusone \let\outputmode\relax \newcount\outputmode \outputmode\plusone
%D Because we do a lot in \LUA\ and don't want interferences, we nil most of the
%D \PDFTEX\ primitives. Of course one can always use the \type {\pdfvariable},
%D \type {\pdfextension} and \type {\pdffeedback} primitives but it will probably
%D have bad side effects.
-%D For the moment we put these here as they are pdf related but they might move to
-%D a better place. We overload the primitives with our own but use a bit of indirection
-%D for the purpose of tracing.
-
-\unexpanded\def\saveboxresource {\clf_saveboxresource}
-\unexpanded\def\lastsavedboxresourceindex {\numexpr\clf_lastsavedboxresourceindex\relax}
-\unexpanded\def\useboxresource {\clf_useboxresource}
-
-\unexpanded\def\saveimageresource {\clf_saveimageresource}
-\unexpanded\def\lastsavedimageresourceindex{\numexpr\clf_lastsavedimageresourceindex\relax}
-\unexpanded\def\lastsavedimageresourcepages{\numexpr\clf_lastsavedimageresourcepages\relax}
-\unexpanded\def\useimageresource {\clf_useimageresource}
-
-\unexpanded\def\savepos {\clf_savepos}
- \def\lastxpos {\clf_lastxpos}
- \def\lastypos {\clf_lastypos}
-
-\unexpanded\def\pdfextension {\clf_pdfextension}
- \def\pdffeedback {\clf_pdffeedback}
-
%D These are no-ops and don't even intercept what comes next. Maybe some day
%D I'll write a parser that maps onto \CONTEXT.
\unexpanded\def\unsupportedpdfprimitive#1%
- {\writestatus{fatal error}{the primitive \string#1\space is not supported}%
- \directlua{os.exit()}}
+ {\writestatus{error}{the primitive \string#1\space is not supported}}
\unexpanded\def\pdfcolorstack {\unsupportedpdfprimitive\pdfcolorstack}
\unexpanded\def\pdfcolorstackinit{\unsupportedpdfprimitive\pdfcolorstackinit}
-% pdfannot
+%unexpanded\def\pdfannot {\unsupportedpdfprimitive\pdfannot}
\unexpanded\def\pdfstartlink {\unsupportedpdfprimitive\pdfstartlink}
\unexpanded\def\pdfendlink {\unsupportedpdfprimitive\pdfendlink}
\unexpanded\def\pdfoutline {\unsupportedpdfprimitive\pdfoutline}
-% pdfdest
+%unexpanded\def\pdfdest {\unsupportedpdfprimitive\pdfdest}
\unexpanded\def\pdfthread {\unsupportedpdfprimitive\pdfthread}
\unexpanded\def\pdfstartthread {\unsupportedpdfprimitive\pdfstartthread}
\unexpanded\def\pdfendthread {\unsupportedpdfprimitive\pdfendthread}
@@ -136,24 +97,23 @@
%D But we still provide:
-\unexpanded\def\nopdfcompression {\clf_setpdfcompression\zerocount\zerocount}
-\unexpanded\def\onlypdfobjectcompression{\clf_setpdfcompression\zerocount\plusthree}
-\unexpanded\def\maximumpdfcompression {\clf_setpdfcompression\plusnine \plusnine }
-\unexpanded\def\normalpdfcompression {\clf_setpdfcompression\plusthree\plusthree}
+\unexpanded\def\nopdfcompression {\clf_setpdfcompression\zerocount\zerocount}
+\unexpanded\def\maximumpdfcompression {\clf_setpdfcompression\plusnine \plusnine }
+\unexpanded\def\normalpdfcompression {\clf_setpdfcompression\plusthree\plusthree}
%D These might even become no-ops as we don't need them in \CONTEXT:
-\unexpanded\def\pdfmapfile#1{} % obsolete
-\unexpanded\def\pdfmapline#1{} % obsolete
+\unexpanded\def\pdfmapfile#1{\clf_setmapfile{#1}}
+\unexpanded\def\pdfmapline#1{\clf_setmapline{#1}}
%D We don't support these directives, at least not this way. If they are needed
%D by third party modules we can provide some interface.
-%pdfcreationdate
+% \pdfcreationdate
\let\pdfdecimaldigits \relax \newcount\pdfdecimaldigits
\let\pdfdestmargin \relax \newdimen\pdfdestmargin
-% pdffontname
-% pdffontobjnum
+% \pdffontname
+% \pdffontobjnum
\let\pdffontsize \relax \newcount\pdffontsize
\let\pdfgamma \relax \newcount\pdfgamma
\let\pdfgentounicode \relax \newcount\pdfgentounicode
@@ -168,21 +128,21 @@
\let\pdfinclusioncopyfonts \relax \newcount\pdfinclusioncopyfonts
\let\pdfinclusionerrorlevel \relax \newcount\pdfinclusionerrorlevel
\let\pdfinfoomitdate \relax \newcount\pdfinfoomitdate
-% pdflastannot
-% pdflastlink
+% \pdflastannot
+% \pdflastlink
\let\pdflinkmargin \relax \newdimen\pdflinkmargin
\let\pdfmajorversion \relax \newcount\pdfmajorversion
\let\pdfminorversion \relax \newcount\pdfminorversion
\let\pdfpagebox \relax \newcount\pdfpagebox
-% pdfpageref
+% \pdfpageref
\let\pdfpkfixeddpi \relax \newcount\pdfpkfixeddpi
\let\pdfpkmode \relax \newtoks \pdfpkmode
\let\pdfpkresolution \relax \newcount\pdfpkresolution
-% pdfretval
+% \pdfretval
\let\pdfsuppressoptionalinfo \relax \newcount\pdfsuppressoptionalinfo
\let\pdfsuppressptexinfo \relax \newcount\pdfsuppressptexinfo
-% pdftexrevision
-% pdftexversion
+% \pdftexrevision
+% \pdftexversion
\let\pdfthreadmargin \relax \newdimen\pdfthreadmargin
\let\pdftrailerid \relax \newtoks \pdftrailerid
\let\pdfuniqueresname \relax \newcount\pdfuniqueresname
@@ -192,33 +152,27 @@
%D These are still accepted but are normally not needed.
-\let\pdfxform \saveboxresource
-\let\pdfximage \saveimageresource
-
\let\pdflastxform \lastsavedboxresourceindex
\let\pdflastximage \lastsavedimageresourceindex
-
-\let\pdfrefxform \useboxresource
-\let\pdfrefximage \useimageresource
-
\let\pdflastximagepages \lastsavedimageresourcepages
-
-\let\pdfsavepos \savepos
\let\pdflastxpos \lastxpos
\let\pdflastypos \lastypos
+\let\pdfrefxform \useboxresource
+\let\pdfrefximage \useimageresource
+\let\pdfsavepos \savepos
+\let\pdfxform \saveboxresource
+\let\pdfximage \saveimageresource
%D For the moment we keep these as they are but they will become \LUA\ calls
%D eventually, after which we will nil the three \type {\pdf} interface primitives.
-\normalprotected\def\pdfliteral {\clf_pdfliteral}%
-
-\normalprotected\def\pdfobj {\clf_pdfobj}%
-\normalprotected\def\pdflastobj {\numexpr\clf_pdflastobj\relax}%
-
+\normalprotected\def\pdfliteral {\pdfextension literal }
+\normalprotected\def\pdfobj {\pdfextension obj }
+ \def\pdflastobj {\numexpr\pdffeedback lastobj\relax}
\normalprotected\def\pdfrefobj {\pdfextension refobj }
-\normalprotected\def\pdfrestore {\clf_restore}
-\normalprotected\def\pdfsave {\clf_save}
-\normalprotected\def\pdfsetmatrix{\clf_setmatrix}
+\normalprotected\def\pdfrestore {\pdfextension restore\relax}
+\normalprotected\def\pdfsave {\pdfextension save\relax}
+\normalprotected\def\pdfsetmatrix{\pdfextension setmatrix }
%D This one can be consulted by users although the suffix is also a system mode.
@@ -271,6 +225,84 @@
\def\pdfcolor #1{\clf_lpdf_color\numexpr\thecolorattribute{#1}\relax}
\let\PDFcolor\pdfcolor
+%D Transformations
+
+% rotation
+
+\unexpanded\def\dostartrotation#1%
+ {\forcecolorhack
+ \clf_pdfstartrotation#1\relax} % todo: implement without Q q
+
+\unexpanded\def\dostoprotation
+ {\clf_pdfstoprotation
+ \forcecolorhack}
+
+% scaling
+
+\unexpanded\def\dostartscaling#1#2%
+ {\forcecolorhack
+ \clf_pdfstartscaling rx #1 ry #2\relax}
+
+\unexpanded\def\dostopscaling
+ {\clf_pdfstopscaling
+ \forcecolorhack}
+
+% mirroring
+
+\unexpanded\def\dostartmirroring
+ {\clf_pdfstartmirroring}
+
+\unexpanded\def\dostopmirroring
+ {\clf_pdfstopmirroring}
+
+% transform
+
+\unexpanded\def\dotransformnextbox#1#2#3#4#5#6%
+ {\dowithnextbox{\dodotransformnextbox{#1}{#2}{#3}{#4}{#5}{#6}}}
+
+\unexpanded\def\dodotransformnextbox#1#2#3#4#5#6%
+ {\hpack
+ {\kern #5\onebasepoint
+ \raise#6\onebasepoint
+ \hpack
+ {\clf_pdfstartmatrix rx #1 sx #2 sy #3 ry #4\relax
+ \box\nextbox
+ \clf_pdfstopmatrix}}}
+
+% somehow the shift is not happening .. bug in luatex?
+%
+% \unexpanded\def\dodotransformnextbox#1#2#3#4#5#6%
+% {\ctxcommand{pdftransformbox(\number\nextbox,#1,#2,#3,#4,\number\dimexpr#5\onebasepoint,\number\dimexpr#6\onebasepoint)}%
+% \box\nextbox}
+%
+% \startluacode
+% function commands.pdftransformbox(box,rx,sx,sy,ry,tx,ty)
+% if rx == 1 and sx == 0 and sy == 0 and ry == 1 then
+% if tx == 0 and ty == 0 then
+% local b = nodes.hpack(nodes.concat {
+% nodes.pool.kern(tx),
+% nodes.takebox(box),
+% })
+% b.shift = -ty
+% tex.setbox(box,b)
+% else
+% -- no need to transform
+% end
+% else
+% local b = nodes.hpack(nodes.concat {
+% nodes.pool.kern(tx),
+% nodes.pool.pdfsave(),
+% nodes.pool.pdfsetmatrix(rx,sx,sy,ry),
+% nodes.takebox(box),
+% nodes.pool.pdfsetmatrix(-rx,-sx,-sy,-ry),
+% nodes.pool.pdfrestore(),
+% })
+% b.shift = -ty
+% tex.setbox(box,b)
+% end
+% end
+% \stopluacode
+
% clipping
\unexpanded\def\dostartclipping#1#2#3% we can move this to lua and only set a box here