summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/back-imp-pdf.mkxl
blob: f2afe61daffb61f45d20205c5b3a4d632fba5ff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%D \module
%D   [       file=back-imp-pdf,
%D        version=2009.04.15,
%D          title=\CONTEXT\ Backend Macros,
%D       subtitle=\PDF,
%D         author=Hans Hagen,
%D           date=\currentdate,
%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
%C details.

%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.

%D Todo: a few delayed binding left:

% ./lpdf-ini.lmt : reserve | immediate | positions | matrix | pos | fontobject
% ./lpdf-lmt.lmt : fontname | object | boxresources
% ./lpdf-rul.lmt : mp stuff
% ./back-res.lmt : boxresources

\writestatus{loading}{ConTeXt Backend Macros / PDF}

% \registerctxluafile{back-imp-pdf}{autosuffix} % some code will move to lpdf-*

\registerctxluafile{lpdf-ini}{autosuffix}
\registerctxluafile{lpdf-lmt}{autosuffix}
\registerctxluafile{lpdf-col}{autosuffix}
\registerctxluafile{lpdf-xmp}{autosuffix}
\registerctxluafile{lpdf-ano}{autosuffix}
\registerctxluafile{lpdf-mis}{autosuffix}
\registerctxluafile{lpdf-ren}{autosuffix}
\registerctxluafile{lpdf-grp}{autosuffix}
\registerctxluafile{lpdf-wid}{autosuffix}
\registerctxluafile{lpdf-fld}{autosuffix}
\registerctxluafile{lpdf-tag}{autosuffix}
\registerctxluafile{lpdf-fmt}{autosuffix}
\registerctxluafile{lpdf-pde}{autosuffix}
\registerctxluafile{lpdf-img}{autosuffix}
\registerctxluafile{lpdf-epa}{autosuffix}
\registerctxluafile{lpdf-emb}{autosuffix}
\registerctxluafile{lpdf-fnt}{autosuffix}
\registerctxluafile{lpdf-rul}{autosuffix}

\registerctxluafile{back-imp-pdf}{autosuffix} % some code will move to lpdf-*
\registerctxluafile{back-imp-pdp}{autosuffix}

% \registerctxluafile{lpdf-u3d}{autosuffix}

\loadmkxlfile{back-imp-u3d}

\unprotect

%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 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. We fake them as primitives which is why they are
%D defined as untraced.

% \pdfextension % defined in lua
% \pdffeedback  % idem
% \pdfvariable  % idem
% \pdfliteral   % idem
% \pdfobj       % idem
% \pdflastobj   % idem
% \pdfrefobj    % idem

\untraced\permanent\protected\def\pdfrestore  {\pdfextension restore}
\untraced\permanent\protected\def\pdfsave     {\pdfextension save}
\untraced\permanent\protected\def\pdfsetmatrix{\pdfextension setmatrix}

\untraced\permanent\def\pdfxform              {\saveboxresource}
\untraced\permanent\def\pdflastxform          {\lastsavedboxresourceindex}
\untraced\permanent\def\pdfrefxform           {\useboxresource}

%D This is also needed for tikz:

\ifdefined\pdfsavepos\else
    \untraced\permanent\def\pdfsavepos {\savepos }
    \untraced\permanent\def\pdflastxpos{\lastxpos}
    \untraced\permanent\def\pdflastypos{\lastypos}
\fi

%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.

\untraced\permanent\protected\def\nopdfcompression        {\clf_setpdfcompression\zerocount\zerocount}
\untraced\permanent\protected\def\onlypdfobjectcompression{\clf_setpdfcompression\plusthree\zerocount}
\untraced\permanent\protected\def\maximumpdfcompression   {\clf_setpdfcompression\plusnine \plusnine }
\untraced\permanent\protected\def\normalpdfcompression    {\clf_setpdfcompression\plusthree\plusthree}

%D PDF/X (maybe combine the two lua calls)

\setupbackend
  [xmpfile=]

\appendtoks
    \edef\p_file{\backendparameter{xmpfile}}%
    \ifempty\p_file\else
      \clf_setxmpfile{\p_file}%
    \fi
\to \everysetupbackend

%D This will change:

\appendtoks
    \clf_setformat
         format  {\backendparameter\c!format}%
         level   {\backendparameter\c!level}%
         option  {\backendparameter\c!option}%
         profile {\backendparameter\c!profile}%
         intent  {\backendparameter\c!intent}%
         file    {\backendparameter\c!file}%
    \relax
\to \everysetupbackend

%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.

% \pdfbackendsetcatalog       #1#2 % defined in lua
% \pdfbackendsetinfo          #1#2 % idem
% \pdfbackendsetname          #1#2 % idem
%
% \pdfbackendsetpageattribute #1#2 % idem
% \pdfbackendsetpagesattribute#1#2 % idem
% \pdfbackendsetpageresource  #1#2 % idem
%
% \pdfbackendsetextgstate     #1#2 % idem
% \pdfbackendsetcolorspace    #1#2 % idem
% \pdfbackendsetpattern       #1#2 % idem
% \pdfbackendsetshade         #1#2 % idem
%
% \pdfbackendcurrentresources      %  idem, expandable
% \pdfcolor                     #1 %  idem, expandable

%D This is a temporary hack that will be removed, improved or somehow can become
%D default.

\permanent\def\TransparencyHack{\setupcolors[\c!pagecolormodel=\v!auto]}

%D Just in case one needs this \unknown:
%D
%D \starttyping
%D text \pdfbackendactualtext{Meier}{Müller} text
%D \stoptyping

\untraced\permanent\protected\def\pdfbackendactualtext#1#2% not interfaced
  {\clf_startactualtext{#2}%
   #1%
   \clf_stopactualtext}

\aliased\let\pdfactualtext\pdfbackendactualtext

\protect \endinput