summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/back-pdf.mkiv
blob: 2d3ba85248b8122848e78fd72632e33ae48f1c0e (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
161
162
163
164
165
166
167
168
169
%D \module
%D   [       file=back-pdf,
%D        version=2009.04.15,
%D          title=\CONTEXT\ Backend Macros,
%D       subtitle=\PDF,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

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

\registerctxluafile{back-pdf}{1.001} % this will change

\unprotect

%D We will minimize the number of calls to \PDF\ specific primitives
%D and delegate all management and injection of code to the backend.
%D
%D Here we initialize some internal quantities.

\pdfoutput              =   1
\pdfhorigin             =   1 true in
\pdfvorigin             =   1 true in
\pdfimageresolution     = 300
\pdfpkresolution        = 600
\pdfdecimaldigits       =  10
\pdfinclusionerrorlevel =   0
\pdfminorversion        =   5
%pdfuniqueresname       =   1

%D This one can be consulted by users although the suffix is also
%D a system mode.

\setjobsuffix{pdf}

%D For the moment we keep these.

\newtoks \pdfbackendeveryximage
\newtoks \pdfbackendeveryxform

%D These are the only official methods to add stuff to the resources.

\def\pdfbackendsetcatalog       #1#2{\ctxlua{lpdf.addtocatalog        ("#1",\!!bs#2\!!es)}} \newtoks\pdfcatalog
\def\pdfbackendsetinfo          #1#2{\ctxlua{lpdf.addtoinfo           ("#1",\!!bs#2\!!es)}} \newtoks\pdfinfo
\def\pdfbackendsetname          #1#2{\ctxlua{lpdf.addtonames          ("#1",\!!bs#2\!!es)}} \newtoks\pdfnames

\def\pdfbackendsetpageattribute #1#2{\ctxlua{lpdf.addtopageattributes ("#1",\!!bs#2\!!es)}} \newtoks\pdfpageresources
\def\pdfbackendsetpagesattribute#1#2{\ctxlua{lpdf.addtopagesattributes("#1",\!!bs#2\!!es)}} \newtoks\pdfpageattr
\def\pdfbackendsetpageresource  #1#2{\ctxlua{lpdf.addtopageresources  ("#1",\!!bs#2\!!es)}} \newtoks\pdfpagesattr

\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))}}

\def\pdfbackendcurrentresources     {\ctxlua{lpdf.collectedresources()}}

%D An example of usage is:

\appendtoks % will change ...
  \pdfbackendsetinfo{ConTeXt.Version}{(\contextversion)}%
  \pdfbackendsetinfo{ConTeXt.Time}   {(\number\normalyear.\twodigits\normalmonth.\twodigits\normalday\space \twodigits\currenthour:\twodigits\currentminute)}%
  \pdfbackendsetinfo{ConTeXt.Jobname}{(\jobname)}%
  \pdfbackendsetinfo{ConTeXt.Url}    {(www.pragma-ade.com)}%
\to \everylastbackendshipout

%D Unfortunately this is still needed (also for  \METAPOST\ to
%D \PDF\ converter):

\def\doresetmapfilelist
  {\global\let\doresetmapfilelist\relax
   \pdfmapfile{original-empty.map}}

\def\doloadmapfile #1#2{\pdfmapfile{#1#2}}
\def\doloadmapline #1#2{\pdfmapline{#1#2}}

\appendtoksonce \loadallfontmapfiles \to \pdfbackendeveryxform
\appendtoksonce \loadallfontmapfiles \to \pdfbackendeveryximage

%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
  {\PointsToBigPoints{#2}\width
   \PointsToBigPoints{#3}\height
   \grabMPclippath{#1}{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
  {\pdfliteral{Q n}}

%D The following will move to the backend \LUA\ code:

\appendtoks \ctxlua{backends.codeinjections.finalizepage    ()}\to \everybackendshipout       % is immediate
\appendtoks \ctxlua{backends.codeinjections.finalizedocument()}\to \everylastbackendshipout   % is immediate

%D Temporary hack, will be removed or improved.

\def\TransparencyHack{\ctxlua{backends.codeinjections.addtransparencygroup()}}

%D \macros
%D  {dostartobject,dostopobject,doinsertobject}

%D This will change:

\newbox\objectbox

\def\dostartobject#1#2#3#4#5%
  {\bgroup
   \setbox\objectbox\vbox\bgroup
   \def\dodostopobject{\egroup\doregisterobject{#1}{#2}}}

\def\dostopobject
  {\dodostopobject
   \egroup}

\def\doregisterobject#1#2%
  {\the\pdfbackendeveryxform
   \finalizeobjectbox\objectbox
   \immediate\pdfxform resources {\pdfbackendcurrentresources}\objectbox
   \dosetobjectreference{#1}{#2}{\the\pdflastxform}}

\def\doresetobjects
  {}

\def\doinsertobject#1#2%
  {\begingroup
   \doifobjectreferencefoundelse{#1}{#2}
     {\dogetobjectreference{#1}{#2}\PDFobjectreference\pdfrefxform\PDFobjectreference}%
     \donothing
   \endgroup}

\def\doPDFgetobjectpage#1#2#3%
  {\dogetobjectreferencepage{#1}{#2}#3%
   \ifx#3\empty\def#3{\realfolio}\fi}

\def\doPDFgetobjectpagereference#1#2#3%
  {\dogetobjectreferencepage{#1}{#2}#3%
   \doPDFgetpagereference{\ifx#3\empty\realfolio\else#3\fi}#3}

\def\predefinesymbol[#1]%
  {\begingroup
   \settightobject{SYM}{#1}\hbox{\symbol[#1]}% to be checked ... maybe only fitting
   \dogetobjectreference{SYM}{#1}\lastref
   \ctxlua{backends.codeinjections.registersymbol("#1",\lastref)}%
   \endgroup}

\protect \endinput