From 8b678f473da7b81842dbc13b50c6303991570521 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sat, 25 May 2019 11:48:47 +0200 Subject: 2019-05-25 10:53:00 --- tex/context/base/mkiv/back-pdf.mkiv | 468 ++++-------------------------------- 1 file changed, 49 insertions(+), 419 deletions(-) (limited to 'tex/context/base/mkiv/back-pdf.mkiv') diff --git a/tex/context/base/mkiv/back-pdf.mkiv b/tex/context/base/mkiv/back-pdf.mkiv index 776581413..80130577c 100644 --- a/tex/context/base/mkiv/back-pdf.mkiv +++ b/tex/context/base/mkiv/back-pdf.mkiv @@ -11,14 +11,23 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D The less there is here, the better. +%D The less there is here, the better. After a decade it is time to remove the \type +%D {\pdf*} ones completely. For the moment I keep them commented but even that will +%D go away. \writestatus{loading}{ConTeXt Backend Macros / PDF} \registerctxluafile{lpdf-ini}{optimize} \ifcase\contextlmtxmode\relax - \registerctxluafile{lpdf-nod}{} + % \doifelsefile {lpdf-nod-test.lua} { + % \registerctxluafile{lpdf-nod-test}{} + % } { + \registerctxluafile{lpdf-nod}{} + % } + \registerctxluafile{lpdf-eng}{optimize} +\else + \registerctxluafile{lpdf-lmt}{optimize} \fi \registerctxluafile{lpdf-col}{} @@ -47,10 +56,9 @@ \registerctxluafile{lpdf-emb}{optimize} \fi -\registerctxluafile{back-pdp}{} - \registerctxluafile{lpdf-fnt}{} +\registerctxluafile{back-pdp}{} \registerctxluafile{back-pdf}{} % some code will move to lpdf-* \loadmarkfile{back-u3d} % this will become a module @@ -61,167 +69,37 @@ %D We will minimize the number of calls to \PDF\ specific primitives and delegate %D all management and injection of code to the backend. %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 - %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 a -%D better place. We overload the primitives with our own but use a bit of -%D indirection for the purpose of tracing. Some of these are needes for packages like -%D tikz. - -\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} - -%D Maybe these are used: - -\unexpanded\def\savepos {\clf_savepos} - \def\lastxpos{\clf_lastxpos} - \def\lastypos{\clf_lastypos} - -%D We do some interception: - \unexpanded\def\pdfextension{\clf_pdfextension} \def\pdffeedback {\clf_pdffeedback} -%D These are no-ops and don't even intercept what comes next. We used to use -%D token registers for some so that they kept working but now we just abort the -%D run. - -\unexpanded\def\pdfannot {\clf_pdfannot} -\unexpanded\def\pdfcolorstack {\unsupportedcs\pdfcolorstack} -\unexpanded\def\pdfcolorstackinit{\unsupportedcs\pdfcolorstackinit} -\unexpanded\def\pdfdest {\clf_pdfdest} -\unexpanded\def\pdfendlink {\unsupportedcs\pdfendlink} -\unexpanded\def\pdfendthread {\unsupportedcs\pdfendthread} -\unexpanded\def\pdffontattr {\unsupportedcs\pdffontattr} -\unexpanded\def\pdfglyphtounicode{\unsupportedcs\pdfglyphtounicode} -\unexpanded\def\pdfoutline {\unsupportedcs\pdfoutline} -\unexpanded\def\pdfstartlink {\unsupportedcs\pdfstartlink} -\unexpanded\def\pdfstartthread {\unsupportedcs\pdfstartthread} -\unexpanded\def\pdfthread {\unsupportedcs\pdfthread} - -\unexpanded\def\pdfcatalog {\unsupportedcs\pdfcatalog} -\unexpanded\def\pdfinfo {\unsupportedcs\pdfinfo} -\unexpanded\def\pdfnames {\unsupportedcs\pdfnames} -\unexpanded\def\pdftrailer {\unsupportedcs\pdftrailer} -\unexpanded\def\pdfpageresources {\unsupportedcs\pdfpageresources} -\unexpanded\def\pdfpageattr {\unsupportedcs\pdfpageattr} -\unexpanded\def\pdfpagesattr {\unsupportedcs\pdfpagesattr} -\unexpanded\def\pdfxformattr {\unsupportedcs\pdfxformattr} -\unexpanded\def\pdfxformresources{\unsupportedcs\pdfxformresources} - -%D There is no need for these: - -\unexpanded\def\pdfmapfile {\unsupportedcs\pdfmapfile} -\unexpanded\def\pdfmapline {\unsupportedcs\pdfmapline} - -%D These have been no-ops for a long time so now we just abort on their usage. - -\unexpanded\def\pdfcompresslevel {\unsupportedcs\pdfcompresslevel} -\unexpanded\def\pdfobjcompresslevel{\unsupportedcs\pdfobjcompresslevel} - -%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} - -%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 -\def\pdfdecimaldigits {\unsupportedcs\pdfdecimaldigits} -\def\pdfdestmargin {\unsupportedcs\pdfdestmargin} -% pdffontname -% pdffontobjnum -\def\pdffontsize {\unsupportedcs\pdffontsize} -\def\pdfgamma {\unsupportedcs\pdfgamma} -\def\pdfgentounicode {\unsupportedcs\pdfgentounicode} -\def\pdfhorigin {\unsupportedcs\pdfhorigin} -\def\pdfignoreunknownimages {\unsupportedcs\pdfignoreunknownimages} -\def\pdfimageaddfilename {\unsupportedcs\pdfimageaddfilename} -\def\pdfimageapplygamma {\unsupportedcs\pdfimageapplygamma} -\def\pdfimagegamma {\unsupportedcs\pdfimagegamma} -\def\pdfimagehicolor {\unsupportedcs\pdfimagehicolor} -\def\pdfimageresolution {\unsupportedcs\pdfimageresolution} -\def\pdfincludechars {\unsupportedcs\pdfincludechars} -\def\pdfinclusioncopyfonts {\unsupportedcs\pdfinclusioncopyfonts} -\def\pdfinclusionerrorlevel {\unsupportedcs\pdfinclusionerrorlevel} -\def\pdfinfoomitdate {\unsupportedcs\pdfinfoomitdate} -% pdflastannot -% pdflastlink -\def\pdflinkmargin {\unsupportedcs\pdflinkmargin} -\def\pdfmajorversion {\unsupportedcs\pdfmajorversion} -\def\pdfminorversion {\unsupportedcs\pdfminorversion} -\def\pdfpagebox {\unsupportedcs\pdfpagebox} -% pdfpageref -\def\pdfpkfixeddpi {\unsupportedcs\pdfpkfixeddpi} -\def\pdfpkmode {\unsupportedcs\pdfpkmode} -\def\pdfpkresolution {\unsupportedcs\pdfpkresolution} -% pdfretval -\def\pdfsuppressoptionalinfo {\unsupportedcs\pdfsuppressoptionalinfo} -\def\pdfsuppressptexinfo {\unsupportedcs\pdfsuppressptexinfo} -% pdftexrevision -% pdftexversion -\def\pdfthreadmargin {\unsupportedcs\pdfthreadmargin} -\def\pdftrailerid {\unsupportedcs\pdftrailerid} -\def\pdfuniqueresname {\unsupportedcs\pdfuniqueresname} -\def\pdfvorigin {\unsupportedcs\pdfvorigin} -\def\pdfxformmargin {\unsupportedcs\pdfxformmargin} -% \pdfxformname - -%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 - -%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. - -\unexpanded\def\pdfliteral {\clf_pdfliteral}% +%D For the moment we keep this for tikz but hopefully it will at some point use +%D the proper ones. Consider them obsolete: +\unexpanded\def\pdfliteral {\clf_pdfliteral} \unexpanded\def\pdfobj {\clf_pdfobj}% -\unexpanded\def\pdflastobj {\numexpr\clf_pdflastobj\relax}% +\unexpanded\def\pdflastobj {\numexpr\clf_pdflastobj\relax} +\unexpanded\def\pdfrefobj {\clf_pdfrefobj } -\unexpanded\def\pdfrefobj {\pdfextension refobj } \unexpanded\def\pdfrestore {\clf_restore} \unexpanded\def\pdfsave {\clf_save} \unexpanded\def\pdfsetmatrix{\clf_setmatrix} -%D This one can be consulted by users although the suffix is also a system mode. + \let\pdfxform \saveboxresource + \let\pdflastxform \lastsavedboxresourceindex + \let\pdfrefxform \useboxresource -\back_job_set_suffix{pdf} +%D Here are quick and dirty compression flippers, mostly used when testing something +%D as one can best stick to the defaults that also adapt to specific standards. + +\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} %D PDF/X (maybe combine the two lua calls) @@ -229,11 +107,13 @@ [xmpfile=] \appendtoks - \doifsomething{\backendparameter{xmpfile}} - {\clf_setxmpfile{\backendparameter{xmpfile}}}% + \edef\p_file{\backendparameter{xmpfile}}% + \ifx\p_file\empty\else + \clf_setxmpfile{\p_file}% + \fi \to \everysetupbackend -% \doifsomething{\backendparameter\c!format} .. at the lua end +%D This will change: \appendtoks \clf_setformat @@ -246,281 +126,35 @@ \relax \to \everysetupbackend -%D For the moment we keep these. - -%newtoks \pdfbackendeveryximage -\newtoks \pdfbackendeveryxform +%D These are the only official methods to add stuff to the resources. If more is +%D needed for third party low level code, it can be added. -%D These are the only official methods to add stuff to the resources. +\unexpanded\def\pdfbackendsetcatalog #1#2{\clf_lpdf_addtocatalog{#1}{#2}} +\unexpanded\def\pdfbackendsetinfo #1#2{\clf_lpdf_addtoinfo{#1}{#2}} +\unexpanded\def\pdfbackendsetname #1#2{\clf_lpdf_addtonames{#1}{#2}} -\unexpanded\def\pdfbackendsetcatalog #1#2{\clf_lpdf_addtocatalog {#1}{#2}} -\unexpanded\def\pdfbackendsetinfo #1#2{\clf_lpdf_addtoinfo {#1}{#2}} -\unexpanded\def\pdfbackendsetname #1#2{\clf_lpdf_addtonames {#1}{#2}} +\unexpanded\def\pdfbackendsetpageattribute #1#2{\clf_lpdf_addtopageattributes{#1}{#2}} +\unexpanded\def\pdfbackendsetpagesattribute#1#2{\clf_lpdf_addtopagesattributes{#1}{#2}} +\unexpanded\def\pdfbackendsetpageresource #1#2{\clf_lpdf_addtopageresources{#1}{#2}} -\unexpanded\def\pdfbackendsetpageattribute #1#2{\clf_lpdf_addtopageattributes {#1}{#2}} -\unexpanded\def\pdfbackendsetpagesattribute#1#2{\clf_lpdf_addtopagesattributes {#1}{#2}} -\unexpanded\def\pdfbackendsetpageresource #1#2{\clf_lpdf_addtopageresources {#1}{#2}} - -\unexpanded\def\pdfbackendsetextgstate #1#2{\clf_lpdf_adddocumentextgstate {#1}{#2}} +\unexpanded\def\pdfbackendsetextgstate #1#2{\clf_lpdf_adddocumentextgstate{#1}{#2}} \unexpanded\def\pdfbackendsetcolorspace #1#2{\clf_lpdf_adddocumentcolorspace{#1}{#2}} -\unexpanded\def\pdfbackendsetpattern #1#2{\clf_lpdf_adddocumentpattern {#1}{#2}} -\unexpanded\def\pdfbackendsetshade #1#2{\clf_lpdf_adddocumentshade {#1}{#2}} +\unexpanded\def\pdfbackendsetpattern #1#2{\clf_lpdf_adddocumentpattern{#1}{#2}} +\unexpanded\def\pdfbackendsetshade #1#2{\clf_lpdf_adddocumentshade{#1}{#2}} \def\pdfbackendcurrentresources {\clf_lpdf_collectedresources} \def\pdfcolor #1{\clf_lpdf_color\numexpr\thecolorattribute{#1}\relax} - \let\PDFcolor\pdfcolor - -% clipping - -\unexpanded\def\dostartclipping#1#2#3% we can move this to lua and only set a box here - {\forcecolorhack - \edef\width {\tobigpoints#2}% - \edef\height{\tobigpoints#3}% - \meta_grab_clip_path{#1}\width\height{% - 0 0 m % - \width\space 0 l % - \width\space \height\space l % - 0 \height\space l% - }% - \pdfliteral{q 0 w \MPclippath\space W n}} - -\unexpanded\def\dostopclipping - {\pdfliteral{Q}} -%D Temporary hack, will be removed or improved or default. +%D This is a temporary hack mthat will be removed, improved or somehow can become +%D default. -% attr {/Group << /S /Transparency /I false /K true >>} - -%def\TransparencyHack{\ctxlua{backends.codeinjections.addtransparencygroup()}} \def\TransparencyHack{\setupcolors[\c!pagecolormodel=\v!auto]} -% Still here: - -%D \macros -%D {back_ovalbox} +%D Just in case one needs this \unknown: %D -%D Drawing frames with round corners is inherited from the main module. For drawing -%D ovals we use quite raw \PDF\ code. The next implementation does not differ that -%D much from the one implemented in the \POSTSCRIPT\ driver. This code is somewhat -%D obsolete as we now have metapost embedded. - -\unexpanded\def\back_ovalbox#1#2#3#4#5#6#7#8% - {\forcecolorhack - \bgroup - \edef\stroke{\tobigpoints\dimexpr#4\relax\space}% - \edef\radius{\tobigpoints\dimexpr#5\relax\space}% - \scratchdimen\dimexpr#4/\plustwo\relax - \edef\xmin {\tobigpoints \scratchdimen \space}% - \edef\xmax {\tobigpoints\dimexpr #1-\scratchdimen\relax\space}% - \edef\ymax {\tobigpoints\dimexpr #2-\scratchdimen\relax\space}% - \edef\ymin {\tobigpoints\dimexpr-#3+\scratchdimen\relax\space}% - \advance\scratchdimen by #5\relax - \edef\xxmin{\tobigpoints \scratchdimen \space}% - \edef\xxmax{\tobigpoints\dimexpr #1-\scratchdimen\relax\space}% - \edef\yymax{\tobigpoints\dimexpr #2-\scratchdimen\relax\space}% - \edef\yymin{\tobigpoints\dimexpr-#3+\scratchdimen\relax\space}% - % - \edef\dostroke{\number#6}% - \edef\dofill {\number#7}% - \scratchcounter#8\relax - \setbox\scratchbox\naturalhpack - {\ifnum\dostroke\dofill>\zerocount - \pdfliteral - {q - \stroke w - \ifcase\scratchcounter - \xxmin \ymin m - \xxmax \ymin l - \xmax \ymin \xmax \yymin y - \xmax \yymax l - \xmax \ymax \xxmax \ymax y - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - h - \or % 1 - \xxmin \ymin m - \xxmax \ymin l - \xmax \ymin \xmax \yymin y - \xmax \ymax l - \xmin \ymax l - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - h - \or % 2 - \xxmin \ymin m - \xmax \ymin l - \xmax \ymax l - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - h - \or % 3 - \xmin \ymin m - \xmax \ymin l - \xmax \yymax l - \xmax \ymax \xxmax \ymax y - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \ymin l - h - \or % 4 - \xmin \ymin m - \xxmax \ymin l - \xmax \ymin \xmax \yymin y - \xmax \yymax l - \xmax \ymax \xxmax \ymax y - \xmin \ymax l - \xmin \ymin l - h - \or % 5 - \xmin \ymin m - \xmax \ymin l - \xmax \yymax l - \xmax \ymax \xxmax \ymax y - \xmin \ymax l - \xmin \ymin l - h - \or % 6 - \xmin \ymin m - \xxmax \ymin l - \xmax \ymin \xmax \yymin y - \xmax \ymax l - \xmin \ymax l - \xmin \ymin l - h - \or % 7 - \xxmin \ymin m - \xmax \ymin l - \xmax \ymax l - \xmin \ymax l - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - h - \or % 8 - \xmin \ymin m - \xmax \ymin l - \xmax \ymax l - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \ymin l - h - \or % 9 top open - \xmin \ymax m - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - \xxmax \ymin l - \xmax \ymin \xmax \yymin y - \xmax \ymax l - \or % 10 right open - \xmax \ymax m - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \yymin l - \xmin \ymin \xxmin \ymin y - \xmax \ymin l - \or % 11 bottom open - \xmax \ymin m - \xmax \yymax l - \xmax \ymax \xxmax \ymax y - \xxmin \ymax l - \xmin \ymax \xmin \yymax y - \xmin \ymin l - \or % 12 left open - \xmin \ymax m - \xxmax \ymax l - \xmax \ymax \xmax \yymax y - \xmax \yymin l - \xmax \ymin \xxmax \ymin y - \xmin \ymin l - \or % 13 - \xmin \ymax m - \xxmax \ymax l - \xmax \ymax \xmax \yymax y - \xmax \ymin l - \or % 14 - \xmax \ymax m - \xmax \yymin l - \xmax \ymin \xxmax \ymin y - \xmin \ymin l - \or % 15 - \xmax \ymin m - \xxmin \ymin l - \xmin \ymin \xmin \yymin y - \xmin \ymax l - \or % 16 - \xmin \ymin m - \xmin \yymax l - \xmin \ymax \xxmin \ymax y - \xmax \ymax l - \or % 17 - \xxmax \ymax m - \xmax \ymax \xmax \yymax y - \or % 18 - \xmax \yymin m - \xmax \ymin \xxmax \ymin y - \or % 19 - \xxmin \ymin m - \xmin \ymin \xmin \yymin y - \or % 20 - \xmin \yymax m - \xmin \ymax \xxmin \ymax y - \or % 21 - \xxmax \ymax m - \xmax \ymax \xmax \yymax y - \xmin \yymax m - \xmin \ymax \xxmin \ymax y - \or % 22 - \xxmax \ymax m - \xmax \ymax \xmax \yymax y - \xmax \yymin m - \xmax \ymin \xxmax \ymin y - \or % 23 - \xmax \yymin m - \xmax \ymin \xxmax \ymin y - \xxmin \ymin m - \xmin \ymin \xmin \yymin y - \or % 24 - \xxmin \ymin m - \xmin \ymin \xmin \yymin y - \xmin \yymax m - \xmin \ymax \xxmin \ymax y - \or % 25 - \xxmax \ymax m - \xmax \ymax \xmax \yymax y - \xmax \yymin m - \xmax \ymin \xxmax \ymin y - \xxmin \ymin m - \xmin \ymin \xmin \yymin y - \xmin \yymax m - \xmin \ymax \xxmin \ymax y - \or % 26 - \xmax \yymin m - \xmax \ymin \xxmax \ymin y - \xmin \yymax m - \xmin \ymax \xxmin \ymax y - \or % 27 - \xxmax \ymax m - \xmax \ymax \xmax \yymax y - \xxmin \ymin m - \xmin \ymin \xmin \yymin y - \or % 28 - \fi - \ifnum\scratchcounter>\pluseight - S - \else - \ifnum\dostroke=\plusone S \fi - \ifnum\dofill =\plusone f \fi - \fi - Q}% - \fi}% - \wd\scratchbox#1% - \ht\scratchbox#2% - \dp\scratchbox#3% - \box\scratchbox - \egroup} +%D \starttyping +%D text \pdfbackendactualtext{Meier}{Müller} text +%D \stoptyping \unexpanded\def\pdfbackendactualtext#1#2% not interfaced {\clf_startactualtext{#2}% @@ -529,8 +163,4 @@ \let\pdfactualtext\pdfbackendactualtext -% \starttext -% text \pdfbackendactualtext{Meier}{Müller} text -% \stoptext - \protect \endinput -- cgit v1.2.3