summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/back-pdf.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/back-pdf.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/back-pdf.mkiv204
1 files changed, 141 insertions, 63 deletions
diff --git a/Master/texmf-dist/tex/context/base/back-pdf.mkiv b/Master/texmf-dist/tex/context/base/back-pdf.mkiv
index 5b7de128de4..9e441e224a6 100644
--- a/Master/texmf-dist/tex/context/base/back-pdf.mkiv
+++ b/Master/texmf-dist/tex/context/base/back-pdf.mkiv
@@ -5,7 +5,7 @@
%D subtitle=\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,16 +13,18 @@
\writestatus{loading}{ConTeXt Backend Macros / PDF}
+%registerctxluafile{lpdf-aux}{1.001} % common helpers
\registerctxluafile{lpdf-ini}{1.001}
+\registerctxluafile{lpdf-nod}{1.001}
\registerctxluafile{lpdf-col}{1.000}
\registerctxluafile{lpdf-xmp}{1.001}
-\registerctxluafile{lpdf-nod}{1.001}
\registerctxluafile{lpdf-mis}{1.001}
\registerctxluafile{lpdf-ano}{1.001}
\registerctxluafile{lpdf-ren}{1.001}
\registerctxluafile{lpdf-grp}{1.001}
\registerctxluafile{lpdf-wid}{1.001}
\registerctxluafile{lpdf-fld}{1.001}
+\registerctxluafile{lpdf-mov}{1.001}
\registerctxluafile{lpdf-u3d}{1.001}
\registerctxluafile{lpdf-swf}{1.001}
\registerctxluafile{lpdf-tag}{1.001}
@@ -54,9 +56,9 @@
%D This one can be consulted by users although the suffix is also
%D a system mode.
-\setjobsuffix{pdf}
+\back_job_set_suffix{pdf}
-%D PDF/X (matbe combine the two lua calls)
+%D PDF/X (maybe combine the two lua calls)
\setupbackend
[xmpfile=]
@@ -85,22 +87,21 @@
%D These are the only official methods to add stuff to the resources.
-\def\pdfbackendsetcatalog #1#2{\ctxlua{lpdf.addtocatalog ("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetinfo #1#2{\ctxlua{lpdf.addtoinfo ("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetname #1#2{\ctxlua{lpdf.addtonames ("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetcatalog #1#2{\ctxlua{lpdf.addtocatalog ("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetinfo #1#2{\ctxlua{lpdf.addtoinfo ("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetname #1#2{\ctxlua{lpdf.addtonames ("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetpageattribute #1#2{\ctxlua{lpdf.addtopageattributes ("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetpagesattribute#1#2{\ctxlua{lpdf.addtopagesattributes("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetpageresource #1#2{\ctxlua{lpdf.addtopageresources ("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetpageattribute #1#2{\ctxlua{lpdf.addtopageattributes ("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetpagesattribute#1#2{\ctxlua{lpdf.addtopagesattributes("#1",\!!bs#2\!!es)}}
+\unexpanded\def\pdfbackendsetpageresource #1#2{\ctxlua{lpdf.addtopageresources ("#1",\!!bs#2\!!es)}}
-\def\pdfbackendsetextgstate #1#2{\ctxlua{lpdf.adddocumentextgstate ("#1",lpdf.verbose(\!!bs#2\!!es))}}
-\def\pdfbackendsetcolorspace #1#2{\ctxlua{lpdf.adddocumentcolorspace("#1",lpdf.verbose(\!!bs#2\!!es))}}
-\def\pdfbackendsetpattern #1#2{\ctxlua{lpdf.adddocumentpattern ("#1",lpdf.verbose(\!!bs#2\!!es))}}
-\def\pdfbackendsetshade #1#2{\ctxlua{lpdf.adddocumentshade ("#1",lpdf.verbose(\!!bs#2\!!es))}}
+\unexpanded\def\pdfbackendsetextgstate #1#2{\ctxlua{lpdf.adddocumentextgstate ("#1",lpdf.verbose(\!!bs#2\!!es))}}
+\unexpanded\def\pdfbackendsetcolorspace #1#2{\ctxlua{lpdf.adddocumentcolorspace("#1",lpdf.verbose(\!!bs#2\!!es))}}
+\unexpanded\def\pdfbackendsetpattern #1#2{\ctxlua{lpdf.adddocumentpattern ("#1",lpdf.verbose(\!!bs#2\!!es))}}
+\unexpanded\def\pdfbackendsetshade #1#2{\ctxlua{lpdf.adddocumentshade ("#1",lpdf.verbose(\!!bs#2\!!es))}}
-\def\pdfbackendcurrentresources {\ctxlua{lpdf.collectedresources()}}
-
-\def\pdfcolor #1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}} \let\PDFcolor\pdfcolor
+ \def\pdfbackendcurrentresources {\cldcontext{lpdf.collectedresources()}}
+ \def\pdfcolor #1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}} \let\PDFcolor\pdfcolor
%D Let's block these:
@@ -113,7 +114,7 @@
%D An example of usage is:
-\appendtoks
+\appendtoks % this will be moved to lua
\pdfbackendsetinfo{ConTeXt.Version}{\contextversion}%
\pdfbackendsetinfo{ConTeXt.Time} {\number\normalyear.\twodigits\normalmonth.\twodigits\normalday\space \twodigits\currenthour:\twodigits\currentminute}%
\pdfbackendsetinfo{ConTeXt.Jobname}{\jobname}%
@@ -122,31 +123,84 @@
%D Transformations. Some day we will use primitives (once they're fixed).
-\def\dostartrotation#1% grouped
- {\forcecolorhack
- \pdfliteral{q \ctxlua{lpdf.rotationcm(#1)}}}
-
-\def\dostoprotation
- {\pdfliteral{Q}}
-
-\def\dostartscaling#1#2% the test is needed because acrobat is bugged!
- {\forcecolorhack
- \pdfliteral{q \ifdim#1\points=\zeropoint.0001\else#1\fi\space 0 0
- \ifdim#2\points=\zeropoint.0001\else#2\fi\space 0 0 cm}}
-
-\def\dostopscaling
- {\pdfliteral{Q}}
-
-\def\dostartmirroring{\pdfliteral{-1 0 0 1 0 0 cm}}
-\def\dostopmirroring {\pdfliteral{-1 0 0 1 0 0 cm}}
-
-\def\dostartclipping#1#2#3% todo (still needed?)
+% \def\dostartscaling#1#2% the test is needed because acrobat is bugged!
+% {\forcecolorhack % maybe use signal instead
+% \pdfliteral{q \ifdim#1\points=\zeropoint.0001\else#1\fi\space 0 0
+% \ifdim#2\points=\zeropoint.0001\else#2\fi\space 0 0 cm}}
+%
+% \def\dostopscaling
+% {\pdfliteral{Q}}
+%
+% \def\dostartrotation#1% grouped
+% {\forcecolorhack % maybe use signal instead
+% \pdfliteral{q \cldcontext{lpdf.rotationcm(#1)}}}
+%
+% \def\dostoprotation
+% {\pdfliteral{Q}}
+%
+% function lpdf.rotationcm(a)
+% local s, c = sind(a), cosd(a)
+% return format("%s %s %s %s 0 0 cm",c,s,-s,c)
+% end
+%
+% \def\dostartmirroring{\pdfliteral{-1 0 0 1 0 0 cm}}
+% \def\dostopmirroring {\pdfliteral{-1 0 0 1 0 0 cm}}
+
+% todo: inject at the lua end cq. deal with #5 and #6 too
+
+\unexpanded\def\dostartrotation#1% grouped
+ {\forcecolorhack % maybe use signal instead
+ \advance\backendtransformlevel\plusone
+ \pdfsave
+ \pdfsetmatrix{\ctxcommand{pdfrotation(#1)}}}
+
+\unexpanded\def\dostoprotation
+ {\pdfrestore
+ \advance\backendtransformlevel\minusone}
+
+\unexpanded\def\dostartscaling#1#2% the test is needed because acrobat is bugged!
+ {\forcecolorhack % maybe use signal instead
+ \advance\backendtransformlevel\plusone
+ \pdfsave
+ \pdfsetmatrix
+ {\ifdim#1\points=\zeropoint.0001\else#1\fi\space 0 0
+ \ifdim#2\points=\zeropoint.0001\else#2\fi\space}}% 0 0
+
+\unexpanded\def\dostopscaling
+ {\pdfrestore
+ \advance\backendtransformlevel\minusone}
+
+\unexpanded\def\dostartmirroring
+ {\advance\backendtransformlevel\plusone
+ \pdfsave
+ \pdfsetmatrix{-1 0 0 1}} % 0 0
+
+\unexpanded\def\dostopmirroring
+ {\pdfrestore
+ \advance\backendtransformlevel\minusone}
+
+\unexpanded\def\dotransformnextbox#1#2#3#4#5#6% sx rx ry sy tx ty (will change) / basepoints !
+ {\advance\backendtransformlevel\plusone
+ % fixing ht/dp/wd should happen elsewhere
+ \dowithnextbox{\dodotransformnextbox{#5}{#6}{#1 #2 #3 #4}}}
+
+\unexpanded\def\dodotransformnextbox#1#2#3%
+ {\hbox
+ {\hskip#1\onebasepoint
+ \raise#2\onebasepoint\hbox
+ {\pdfsave
+ \pdfsetmatrix{#3}% 0 0 (no #5 #6 yet)
+ \box\nextbox
+ \pdfrestore
+ \advance\backendtransformlevel\minusone}}}
+
+\unexpanded\def\dostartclipping#1#2#3%
{\PointsToBigPoints{#2}\width
\PointsToBigPoints{#3}\height
- \grabMPclippath{#1}{1}\width\height{0 0 m \width\space 0 l \width \height l 0 \height l}%
+ \meta_grab_clip_path{#1}\width\height{0 0 m \width\space 0 l \width \height l 0 \height l}%
\pdfliteral{q 0 w \MPclippath\space W n}}
-\def\dostopclipping
+\unexpanded\def\dostopclipping
{\pdfliteral{Q n}}
%D The following will move to the backend \LUA\ code:
@@ -156,7 +210,8 @@
%D Temporary hack, will be removed or improved or default.
-\def\TransparencyHack{\ctxlua{backends.codeinjections.addtransparencygroup()}}
+%def\TransparencyHack{\ctxlua{backends.codeinjections.addtransparencygroup()}}
+\def\TransparencyHack{\setupcolors[\c!pagecolormodel=\v!auto]}
%D \macros
%D {dostartobject,dostopobject,doinsertobject}
@@ -168,13 +223,15 @@
\def\dostartobject#1#2#3#4#5%
{\bgroup
\setbox\objectbox\vbox\bgroup
- \def\dodostopobject{\egroup\doregisterobject{#1}{#2}}}
+ \def\back_object_stop{\egroup\back_object_register{#1}{#2}}}
\def\dostopobject
- {\dodostopobject
+ {\back_object_stop
\egroup}
-\def\doregisterobject#1#2%
+% attr {/Group << /S /Transparency /I false /K true >>}
+
+\def\back_object_register#1#2%
{\the\pdfbackendeveryxform
\finalizeobjectbox\objectbox
\immediate\pdfxform resources {\pdfbackendcurrentresources}\objectbox
@@ -183,10 +240,13 @@
\def\doresetobjects
{}
+\let\m_back_object_reference\empty
+
\def\doinsertobject#1#2%
{\begingroup
\doifobjectreferencefoundelse{#1}{#2}
- {\dogetobjectreference{#1}{#2}\PDFobjectreference\pdfrefxform\PDFobjectreference}%
+ {\dogetobjectreference{#1}{#2}\m_back_object_reference
+ \pdfrefxform\m_back_object_reference}%
\donothing
\endgroup}
@@ -196,8 +256,8 @@
{\begingroup
\xdef\lastpredefinedsymbol{#1}%
\settightobject{SYM}{#1}\hbox{\symbol[#1]}% to be checked ... maybe only fitting
- \dogetobjectreference{SYM}{#1}\lastref
- \ctxlua{backends.codeinjections.registersymbol("#1",\lastref)}%
+ \dogetobjectreference{SYM}{#1}\m_back_object_reference
+ \ctxlua{backends.codeinjections.registersymbol("#1",\m_back_object_reference)}%
\endgroup}
% for the moment here
@@ -213,24 +273,39 @@
%D implemented in the \POSTSCRIPT\ driver. This code is
%D somewhat obsolete as we now have metapost embedded.
-\def\doPDFovalcalc#1#2#3%
- {\PointsToBigPoints{\dimexpr#1+#2\relax}#3}
+% \def\back_oval_calculate#1#2#3%
+% {\PointsToBigPoints{\dimexpr#2+#3\relax}#1}
-\def\doovalbox#1#2#3#4#5#6#7#8% todo: \scratchdimen/\scatchbox
+\unexpanded\def\doovalbox#1#2#3#4#5#6#7#8%
{\forcecolorhack
\bgroup
- \dimen0=#4\divide\dimen0 \plustwo
- \doPDFovalcalc{0pt}{+\dimen0}\xmin
- \doPDFovalcalc{#1}{-\dimen0}\xmax
- \doPDFovalcalc{#2}{-\dimen0}\ymax
- \doPDFovalcalc{-#3}{+\dimen0}\ymin
- \advance\dimen0 by #5%
- \doPDFovalcalc{0pt}{+\dimen0}\xxmin
- \doPDFovalcalc{#1}{-\dimen0}\xxmax
- \doPDFovalcalc{#2}{-\dimen0}\yymax
- \doPDFovalcalc{-#3}{+\dimen0}\yymin
- \doPDFovalcalc{#4}{\zeropoint}\stroke
- \doPDFovalcalc{#5}{\zeropoint}\radius
+% \scratchdimen#4%
+% \divide\scratchdimen\plustwo
+% \back_oval_calculate\xmin \zeropoint\scratchdimen
+% \back_oval_calculate\xmax {#1}{-\scratchdimen}%
+% \back_oval_calculate\ymax {#2}{-\scratchdimen}%
+% \back_oval_calculate\ymin {-#3}\scratchdimen
+% \advance\scratchdimen by #5%
+% \back_oval_calculate\xxmin \zeropoint\scratchdimen
+% \back_oval_calculate\xxmax {#1}{-\scratchdimen}%
+% \back_oval_calculate\yymax {#2}{-\scratchdimen}%
+% \back_oval_calculate\yymin {-#3}\scratchdimen
+% \back_oval_calculate\stroke{#4}\zeropoint
+% \back_oval_calculate\radius{#5}\zeropoint
+ %
+ \PointsToBigPoints{#4} \stroke
+ \PointsToBigPoints{#5} \radius
+ \scratchdimen\dimexpr#4/\plustwo\relax
+ \PointsToBigPoints \scratchdimen \xmin
+ \PointsToBigPoints{\dimexpr #1-\scratchdimen}\xmax
+ \PointsToBigPoints{\dimexpr #2-\scratchdimen}\ymax
+ \PointsToBigPoints{\dimexpr-#3+\scratchdimen}\ymin
+ \advance\scratchdimen by #5\relax
+ \PointsToBigPoints \scratchdimen \xxmin
+ \PointsToBigPoints{\dimexpr #1-\scratchdimen}\xxmax
+ \PointsToBigPoints{\dimexpr #2-\scratchdimen}\yymax
+ \PointsToBigPoints{\dimexpr-#3+\scratchdimen}\yymin
+ %
\edef\dostroke{#6}%
\edef\dofill{#7}%
\edef\mode{\number#8 \space}%
@@ -428,10 +503,13 @@
\fi
Q}%
\fi}%
- \wd\scratchbox#1\ht\scratchbox#2\dp\scratchbox#3\box\scratchbox
+ \wd\scratchbox#1%
+ \ht\scratchbox#2%
+ \dp\scratchbox#3%
+ \box\scratchbox
\egroup}
-\unexpanded\def\pdfactualtext#1#2%
+\unexpanded\def\pdfactualtext#1#2% not interfaced
{\pdfliteral direct{/Span <</ActualText \ctxlua{tex.write(lpdf.tosixteen("#2"))} >> BDC}%
#1%
\pdfliteral direct{EMC}}