Debian Codegraph @

texmf-dist/source/latex/pdfmanagement/l3backend-pdfmanagement.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3backend-pdfmanagement.dtx
4 %
5 % Copyright (C) 2019-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "LaTeX PDF management bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/pdfresources
22 %
23 % for those people who are interested.
24 %
25 %
26 %<*driver>
27 \RequirePackage{pdfmanagement}
28 \SetKeys[document/metadata]{pdfversion=2.0}
29 %\DocumentMetadata{} %no tagging yet, as the arguments environment errors
30 \documentclass[full]{l3doc}
31 %\usepackage{latex-lab-testphase-l3doc}
32 \begin{document}
33 \DocInput{\jobname.dtx}
34 \end{document}
35 %</driver>
36 % \fi
37 %
38 % \title{^^A
39 % The \textsf{l3backend-pdfmanagement} package\\ Additional backend PDF features^^A
40 % \\ \LaTeX{} PDF management bundle
41 % }
42 %
43 % \author{^^A
44 % The \LaTeX{} Project\thanks
45 % {^^A
46 % E-mail:
47 % \href{mailto:[email protected]}
48 % {[email protected]}^^A
49 % }^^A
50 % }
51 %
52 % \date{Version 0.97c, released 2026-05-26}
53 %
54 % \maketitle
55 %
56 %
57 % \begin{implementation}
58 %
59 % \section{\pkg{l3backend-pdfmanagement} Implementation}
60 % \begin{macrocode}
61 %<drivers>\ProvidesExplFile
62 %<*dvipdfmx>
63 {l3backend-pdf-dvipdfmx.def}{2026-05-26}{0.97c}
64 {LaTeX~PDF~management~bundle~backend~support:~dvipdfmx}
65 %</dvipdfmx>
66 %<*dvips>
67 {l3backend-pdf-dvips.def}{2026-05-26}{0.97c}
68 {LaTeX~PDF~management~bundle~backend~support:~dvips}
69 %</dvips>
70 %<*dvisvgm>
71 {l3backend-pdf-dvisvgm.def}{2026-05-26}{0.97c}
72 {LaTeX~PDF~management~bundle~backend~support:~dvisvgm}
73 %</dvisvgm>
74 %<*luatex>
75 {l3backend-pdf-luatex.def}{2026-05-26}{0.97c}
76 {LaTeX~PDF~management~bundle~backend~support:~PDF~output~(LuaTeX)}
77 %</luatex>
78 %<*pdftex>
79 {l3backend-pdf-pdftex.def}{2026-05-26}{0.97c}
80 {LaTeX~PDF~management~bundle~backend~support:~PDF~output~(pdfTeX)}
81 %</pdftex>
82 %<*xdvipdfmx>
83 {l3backend-pdf-xetex.def}{2026-05-26}{0.97c}
84 {LaTeX~PDF~management~bundle~backend~support:~XeTeX}
85 %</xdvipdfmx>
86 % \end{macrocode}
87 % \subsection{Variants}
88 % We need to generate temporarily a few e-types variants of kernel backend commands.
89 % These can be removed once the kernel provides them.
90 % \begin{macrocode}
91 %<@@=pdf>
92 %<*luatex|pdftex>
93 \cs_generate_variant:Nn \__kernel_backend_literal_page:n { e }
94 %</luatex|pdftex>
95 %<*dvipdfmx|xdvipdfmx>
96 \cs_generate_variant:Nn \__kernel_backend_literal:n { e }
97 \cs_generate_variant:Nn \@@_backend:n { e }
98 %</dvipdfmx|xdvipdfmx>
99 %<*dvips>
100 \cs_generate_variant:Nn \__kernel_backend_postscript:n { e }
101 \cs_generate_variant:Nn \@@_backend_pdfmark:n { e }
102 %</dvips>
103 % \end{macrocode}
104 % \subsection{Support for delayed literal and special}
105 % Starting with TeXlive 2023 the engines support a \texttt{shipout} keyword
106 % for \cs{pdfliteral} and \cs{special}. When used the argument is not expanded
107 % when the command is used but only when the page is shipped out. This allows for example
108 % the tagging code to delay the page-wise numbering of MC-chunks until the page is
109 % actually built. For now we test the engine support. The boolean is setup
110 % in pdfmanagement-testphase.dtx.
111 % \begin{macrocode}
112 %<*drivers>
113 % \end{macrocode}
114 %
115 % The following commands provide the needed kernel backend support. This are basically
116 % copies of similar commands of l3backend-basics.
117 % \begin{macro}
118 % {
119 % \__kernel_backend_shipout_literal:e
120 % }
121 % The one shared function for all backends is access to the basic
122 % \tn{special} primitive.
123 % \begin{macrocode}
124 \cs_new_protected:Npn \__kernel_backend_shipout_literal:e #1
125 { \tex_special:D~shipout { #1} }
126 %</drivers>
127 % \end{macrocode}
128 % \end{macro}
129 %
130 % \begin{macrocode}
131 %<*luatex|pdftex>
132 % \end{macrocode}
133 % \begin{macro}{\__kernel_backend_shipout_literal_pdf:e}
134 % This is equivalent to \verb|\special{pdf:}| but the engine can
135 % track it. Without the \texttt{direct} keyword everything is kept in
136 % sync: the transformation matrix is set to the current point automatically.
137 % Note that this is still inside the text (\texttt{BT} \dots \texttt{ET}
138 % block).
139 % \begin{macrocode}
140 \cs_new_protected:Npn \__kernel_backend_shipout_literal_pdf:e #1
141 {
142 %<*luatex>
143 \tex_pdfextension:D ~ literal ~ shipout ~
144 %</luatex>
145 %<*pdftex>
146 \tex_pdfliteral:D ~ shipout ~
147 %</pdftex>
148 { #1 }
149 }
150 % \end{macrocode}
151 % \end{macro}
152 %
153 % \begin{macro}{\__kernel_backend_shipout_literal_page:e}
154 % Page literals are pretty simple.
155 % \begin{macrocode}
156 \cs_new_protected:Npn \__kernel_backend_shipout_literal_page:e #1
157 {
158 %<*luatex>
159 \tex_pdfextension:D ~ literal ~ shipout ~
160 %</luatex>
161 %<*pdftex>
162 \tex_pdfliteral:D ~ shipout ~
163 %</pdftex>
164 page { #1 }
165 }
166 %</luatex|pdftex>
167 % \end{macrocode}
168 % \end{macro}
169
170 % \subsection{Crossreferences}
171 % Commands to get a reference for the absolute page counter.
172 % \begin{macrocode}
173 %<*drivers>
174 % \end{macrocode}
175 % \begin{macrocode}
176 \cs_new_protected:Npn \@@_backend_record_abspage:n #1
177 {
178 \@bsphack
179 \property_record:nn{#1}{abspage}
180 \@esphack
181 }
182 \cs_new:Npn \@@_backend_ref_abspage:n #1
183 {
184 \property_ref:nn{#1}{abspage}
185 }
186
187 \cs_generate_variant:Nn \@@_backend_record_abspage:n {e}
188 \cs_generate_variant:Nn \@@_backend_ref_abspage:n {e}
189 %</drivers>
190 % \end{macrocode}
191 % avoid that destinations names are optimized with xelatex/dvipdfmx
192 % see https://tug.org/pipermail/dvipdfmx/2019-May/000002.html
193 % \begin{macrocode}
194 %<*dvipdfmx|xdvipdfmx>
195 \__kernel_backend_literal:n { dvipdfmx:config~C~ 0x0010 }
196 %</dvipdfmx|xdvipdfmx>
197 % \end{macrocode}
198 % \begin{variable}{\g_@@_tmpa_prop, \l_@@_tmpa_tl, \l_@@_backend_tmpa_box }
199 % Some scratch variables
200 % \begin{macrocode}
201 %<*drivers>
202 \prop_new:N \g_@@_tmpa_prop
203 \tl_new:N \l_@@_tmpa_tl
204 \box_new:N \l_@@_backend_tmpa_box
205 \box_new:N \l_@@_backend_tmpb_box
206 %</drivers>
207 % \end{macrocode}
208 % \end{variable}
209
210 % \begin{variable}
211 % {\g_@@_backend_resourceid_int, \g_@@_backend_name_int, \g_@@_backend_page_int}
212 % a counter to create labels for the resources, a counter
213 % to number properties in bdc marks, a counter for the \cs{pdfpageref} implementation.
214 % \begin{macrocode}
215 %<*drivers>
216 \int_new:N \g_@@_backend_resourceid_int
217 \int_new:N \g_@@_backend_name_int
218 \int_new:N \g_@@_backend_page_int
219 %</drivers>
220 % \end{macrocode}
221 % \end{variable}
222 %
223 % \subsection{luacode}
224 % Load the lua code.
225 % \begin{macrocode}
226 %<*luatex>
227 \directlua { require("l3backend-pdf.lua") }
228 %</luatex>
229 % \end{macrocode}
230 % \subsection{Converting unicode strings to a pdfname}
231 % dvips needs a special function here, so we add this as backend function.
232 % \begin{macrocode}
233 %<*pdftex|luatex|dvipdfmx|xdvipdfmx|dvisvgm>
234 \cs_new:Npn \__kernel_pdf_name_from_unicode_e:n #1
235 {
236 / \str_convert_pdfname:e { \text_expand:n { #1 } }
237 }
238 %</pdftex|luatex|dvipdfmx|xdvipdfmx|dvisvgm>
239 %<*dvips>
240 \cs_new:Npn \__kernel_pdf_name_from_unicode_e:n #1
241 {
242 ~ ( \text_expand:n { #1 } ) ~ cvn
243 }
244 %</dvips>
245 % \end{macrocode}
246 % \subsection{Hooks}
247 % \subsubsection{Add the \enquote{end run} hooks}
248 % Here we add the end run hook to suitable
249 % end hooks.
250 % \begin{macrocode}
251 %<*pdftex|luatex>
252 % put in \@kernel@after@enddocument@afterlastpage
253 \tl_gput_right:Nn \@kernel@after@enddocument@afterlastpage
254 {
255 \g__kernel_pdfmanagement_end_run_code_tl
256 }
257 %</pdftex|luatex>
258 %<*dvipdfmx|xdvipdfmx>
259 % put in \@kernel@after@shipout@lastpage
260 \tl_gput_right:Nn \@kernel@after@shipout@lastpage
261 {
262 \g__kernel_pdfmanagement_end_run_code_tl
263 }
264 %</dvipdfmx|xdvipdfmx>
265 %<*dvips>
266 % put in \@kernel@after@shipout@lastpage
267 \tl_gput_right:Nn\@kernel@after@shipout@lastpage
268 {
269 \g__kernel_pdfmanagement_end_run_code_tl
270 }
271 %</dvips>
272 % \end{macrocode}
273 % \subsubsection{Add the \enquote{shipout} hooks}
274 % Now we add to the shipout hooks the relevant token lists.
275 % We also push the page resources in shipout/firstpage (AtBeginDvi)
276 % as the backend code sets color stack there. The xetex driver needs a rule here.
277 % If it clashes on the first page, we will need a test ...
278 % \begin{macrocode}
279 %<*drivers>
280 \tl_if_exist:NTF \@kernel@after@shipout@background
281 {
282 \g@addto@macro \@kernel@before@shipout@background{\relax}
283 \g@addto@macro \@kernel@after@shipout@background
284 {
285 \g__kernel_pdfmanagement_thispage_shipout_code_tl
286 }
287 }
288 {
289 \hook_gput_code:nnn{shipout/background}{pdf}
290 {
291 \g__kernel_pdfmanagement_thispage_shipout_code_tl
292 }
293 }
294
295 %</drivers>
296 % \end{macrocode}
297 % \subsection{ The /Pages dictionary (pdfpagesattr) }
298 % \begin{NOTE}{UF}
299 % path: Pages
300 % pdfpagesattr is a single token register which is used at the end of the compilation.
301 % dvips syntax: \verb+\special{ps: [/ABC /CDE /EFG /FGH /Rotate 90 /PAGES pdfmark}+
302 % dvipdfmx syntax: \verb+\special{pdf:put @pages <</ABC /WEZ /EFG /XYZ /Rotate 0>>}+
303 % both remove duplicate entries automatically, so there is no need to be careful.
304 % \end{NOTE}
305 % \begin{macro}{\@@_backend_Pages_primitive:n}
306 % This is the primitive command to add something to the /Pages dictionary.
307 % It works differently for the backends: pdftex and luatex overwrite existing
308 % content, dvips and dvipdfmx are additive. luatex sets it in lua.
309 % The higher level code has to take this into account.
310 % \begin{macrocode}
311 %<*pdftex>
312 \cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
313 {
314 \tex_global:D \tex_pdfpagesattr:D { #1 }
315 }
316 %</pdftex>
317 %<*luatex>
318 %luatex: does it in lua
319 \cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
320 {
321 \tex_directlua:D
322 {
323 pdf.setpagesattributes( \@@_backend_luastring:n { #1 } )
324 }
325 }
326 %</luatex>
327 %<*dvips>
328 \cs_new_protected:Npx \@@_backend_Pages_primitive:n #1
329 {
330 \tex_special:D{ps:~[#1~/PAGES~pdfmark} %]
331 }
332 %</dvips>
333 %<*dvipdfmx|xdvipdfmx>
334 \cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
335 {
336 \@@_backend:n{put~@pages~<<#1>>}
337 }
338 %</dvipdfmx|xdvipdfmx>
339 %<*dvisvgm>
340 \cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
341 {}
342 %</dvisvgm>
343 % \end{macrocode}
344 % \end{macro}
345 %
346 % \subsection{\enquote{Page} and \enquote{ThisPage} attributes (pdfpageattr)}
347 % \begin{NOTE}{UF}
348 % path: Page
349 % !!!!!!!!!!!!!!!!!!!!!!
350 % It also depends on code in l3pdfmanagement as the code uses the Core-dictionaries
351 % !!!!!!!!!!!!!!!!!!!!!!
352 %
353 % The engines differ a lot here: pdflatex and lualatex uses a register while with
354 % dvips/dvipdfmx a one-shot-special is used. So for pdflatex and lualatex code
355 % to assemble the content of the register is needed. Specials are used at shipout,
356 % the registers is set directly. With lualatex one can use
357 % \cs{latelua} to delay the setting, with pdflatex one has to use a shipout hook.
358 % To get the code on the correct page one has to use the aux with pdflatex.
359 % In sum this means that quite a lot backend commands are needed to handle
360 % this differences. Simply variants of \cs{pdfpageattr} are not enough ...%
361 % dvips syntax: \special{ps: [{ThisPage}<</Rotate 90>> /PUT pdfmark}%
362 % There seem to be an in-built management code: multiple uses don't lead to
363 % multiple entries (/Rotate is special: there is always a /Rotate 0 in the dict,
364 % but seems not to do harm).
365 % dvipdfmx syntax: \special{pdf: put @thispage << /Rotate 90 >>},
366 % like dvips the backend has an in-built management code.
367 % Both change only the current page, so to get the pdftex behavior (which sets
368 % also the following pages) one need to repeat it on every shipout.
369 % \end{NOTE}
370 % \begin{macro}
371 % {
372 % \@@_backend_Page_primitive:n,
373 % \@@_backend_Page_gput:nn,
374 % \@@_backend_Page_gremove:n,
375 % \@@_backend_ThisPage_gput:nn,
376 % \@@_backend_ThisPage_gpush:n
377 % }
378 % \cs{@@_backend_Page_primitive:n} is the primitive command to add
379 % something to the /Page dictionary.
380 % It works differently for the backends: pdftex and luatex overwrite existing
381 % content, dvips and dvipdfmx are additive. luatex sets it in lua.
382 % The higher level code has to take this into account.
383 % \cs{@@_backend_Page_gput:nn} stores default values.
384 % \cs{@@_backend_Page_gremove:n} allows to remove a value.
385 % \cs{@@_backend_ThisPage_gput:nn} adds a value to the current page.
386 % \cs{@@_backend_ThisPage_gpush:n} merges the default and the current page values
387 % and add them to the dictionary of the current page in
388 % \cs{g_@@_backend_thispage_shipout_tl}.
389 % \begin{macrocode}
390 % backend commands
391 %<*pdftex>
392 %the primitive
393 \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
394 {
395 \tex_global:D \tex_pdfpageattr:D { #1 }
396 }
397 % the command to store default values.
398 % Uses a prop with pdflatex + dvi,
399 % sets a lua table with lualatex
400 \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2 %key,value
401 {
402 \pdfdict_gput:nnn {g_@@_Core/Page}{ #1 }{ #2 }
403 }
404 % the command to remove a default value.
405 % Uses a prop with pdflatex + dvi,
406 % changes a lua table with lualatex
407 \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
408 {
409 \pdfdict_gremove:nn {g_@@_Core/Page}{ #1 }
410 }
411 % the command used in the document.
412 % direct call of the primitive special with dvips/dvipdfmx
413 % \latelua: fill a page related table with lualatex, merge it with the page
414 % table and push it directly
415 % write to aux and store in prop with pdflatex
416 \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
417 {
418 %we need to know the page the resource should be added too.
419 \int_gincr:N\g_@@_backend_resourceid_int
420 \@@_backend_record_abspage:e { l3pdf\int_use:N\g_@@_backend_resourceid_int }
421 \tl_set:Ne \l_@@_tmpa_tl
422 {
423 \@@_backend_ref_abspage:e {l3pdf\int_use:N\g_@@_backend_resourceid_int}
424 }
425 \pdfdict_if_exist:nF { g_@@_Core/backend_Page\l_@@_tmpa_tl}
426 {
427 \pdfdict_new:n { g_@@_Core/backend_Page\l_@@_tmpa_tl}
428 }
429 %backend_Page has no handler.
430 \pdfdict_gput:nnn {g_@@_Core/backend_Page\l_@@_tmpa_tl}{ #1 }{ #2 }
431 }
432 %the code to push the values, used in shipout
433 %merges the two props and then fills the register in pdflatex
434 %merges the two tables and then fills (in lua) in luatex
435 %issues the values stored in the global prop with dvi
436 \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
437 {
438 \prop_gset_eq:Nc \g_@@_tmpa_prop { \__kernel_pdfdict_name:n { g_@@_Core/Page } }
439 \prop_if_exist:cT { \__kernel_pdfdict_name:n { g_@@_Core/backend_Page#1 } }
440 {
441 \prop_map_inline:cn { \__kernel_pdfdict_name:n { g_@@_Core/backend_Page#1 } }
442 {
443 \prop_gput:Nnn \g_@@_tmpa_prop { ##1 }{ ##2 }
444 }
445 }
446 \@@_backend_Page_primitive:e
447 {
448 \prop_map_function:NN \g_@@_tmpa_prop \pdfdict_item:ne
449 }
450 }
451 %</pdftex>
452 %<*luatex>
453 % do we need to use some escaping for the values?????
454 \cs_new:Npn \@@_backend_luastring:n #1
455 {
456 "\tex_luaescapestring:D { \tex_unexpanded:D { #1 } }"
457 }
458 %not used, only there for consistency
459 \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
460 {
461 \tex_latelua:D
462 {
463 pdf.setpageattributes(\@@_backend_luastring:n { #1 })
464 }
465 }
466 % the command to store default values.
467 % Uses a prop with pdflatex + dvi,
468 % sets a lua table with lualatex
469 \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
470 {
471 \tex_directlua:D
472 {
473 ltx.@@.backend_Page_gput
474 (
475 \@@_backend_luastring:n { #1 },
476 \@@_backend_luastring:n { #2 }
477 )
478 }
479 }
480 % the command to remove a default value.
481 % Uses a prop with pdflatex + dvi,
482 % changes a lua table with lualatex
483 \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
484 {
485 \tex_directlua:D
486 {
487 ltx.@@.backend_Page_gremove (\@@_backend_luastring:n { #1 })
488 }
489 }
490 % the command used in the document.
491 % direct call of the primitive special with dvips/dvipdfmx
492 % \latelua: fill a page related table with lualatex, merge it with the page
493 % table and push it directly
494 % write to aux and store in prop with pdflatex
495 \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
496 {
497 \tex_latelua:D
498 {
499 ltx.@@.backend_ThisPage_gput
500 (
501 tex.count["g_shipout_readonly_int"],
502 \@@_backend_luastring:n { #1 },
503 \@@_backend_luastring:n { #2 }
504 )
505 ltx.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
506 }
507 }
508 %the code to push the values, used in shipout
509 %merges the two props and then fills the register in pdflatex
510 %merges the two tables (the one is probably still empty) and then fills (in lua) in luatex
511 %issues the values stored in the global prop with dvi
512 \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
513 {
514 \tex_latelua:D
515 {
516 ltx.@@.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
517 }
518 }
519
520 %</luatex>
521 %<*dvipdfmx|xdvipdfmx>
522 %the primitive
523 \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
524 {
525 \tex_special:D{pdf:~put~@thispage~<<#1>>}
526 }
527 % the command to store default values.
528 % Uses a prop with pdflatex + dvi,
529 % sets a lua table with lualatex
530 \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
531 {
532 \pdfdict_gput:nnn {g_@@_Core/Page}{ #1 }{ #2 }
533 }
534 % the command to remove a default value.
535 % Uses a prop with pdflatex + dvi,
536 % changes a lua table with lualatex
537 \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
538 {
539 \pdfdict_gremove:nn {g_@@_Core/Page}{ #1 }
540 }
541 % the command used in the document.
542 % direct call of the primitive special with dvips/dvipdfmx
543 % \latelua: fill a page related table with lualatex, merge it with the page
544 % table and push it directly
545 % write to aux and store in prop with pdflatex
546 \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
547 {
548 \@@_backend_Page_primitive:n { /#1~#2 }
549 }
550 %the code to push the values, used in shipout
551 %merges the two props and then fills the register in pdflatex
552 %merges the two tables (the one is probably still empty)
553 % and then fills (in lua) in luatex
554 %issues the values stored in the global prop with dvi
555 \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
556 {
557 \@@_backend_Page_primitive:e
558 { \pdfdict_use:n { g_@@_Core/Page} }
559 }
560 %</dvipdfmx|xdvipdfmx>
561 %<*dvips>
562 \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
563 {
564 \tex_special:D{ps:~[{ThisPage}<<#1>>~/PUT~pdfmark} %]
565 }
566 % the command to store default values.
567 % Uses a prop with pdflatex + dvi,
568 % sets a lua table with lualatex
569 \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
570 {
571 \pdfdict_gput:nnn {g_@@_Core/Page}{ #1 }{ #2 }
572 }
573 % the command to remove a default value.
574 % Uses a prop with pdflatex + dvi,
575 % changes a lua table with lualatex
576 \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
577 {
578 \pdfdict_gremove:nn {g_@@_Core/Page}{ #1 }
579 }
580 % the command used in the document.
581 % direct call of the primitive special with dvips/dvipdfmx
582 % \latelua: fill a page related table with lualatex, merge it with the page
583 % table and push it directly
584 % write to aux and store in prop with pdflatex
585 \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
586 {
587 \@@_backend_Page_primitive:n { /#1~#2 }
588 }
589 %the code to push the values, used in shipout
590 %merges the two props and then fills the register in pdflatex
591 %merges the two tables (the one is probably still empty)
592 %and then fills (in lua) in luatex
593 %issues the values stored in the global prop with dvi
594 \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
595 {
596 \@@_backend_Page_primitive:e
597 { \pdfdict_use:n { g_@@_Core/Page} }
598 }
599 %</dvips>
600 %<*dvisvgm>
601 % mostly only dummies ...
602 \cs_new_protected:Npn \@@_backend_Page_primitive:n #1
603 {}
604 % Uses a prop with pdflatex + dvi,
605 \cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
606 {
607 \pdfdict_gput:nnn {g_@@_Core/Page}{ #1 }{ #2 }
608 }
609 % the command to remove a default value.
610 % Uses a prop with pdflatex + dvi,
611 \cs_new_protected:Npn \@@_backend_Page_gremove:n #1
612 {
613 \pdfdict_gremove:nn {g_@@_Core/Page}{ #1 }
614 }
615 % the command used in the document.
616 \cs_new_protected:Npn \@@_backend_ThisPage_gput:nn #1 #2
617 {}
618 %the code to push the values, used in shipout
619 \cs_new_protected:Npn \@@_backend_ThisPage_gpush:n #1
620 {}
621 %</dvisvgm>
622 %<*drivers>
623 \cs_generate_variant:Nn \@@_backend_Page_primitive:n { e }
624 %</drivers>
625 % \end{macrocode}
626 % \end{macro}
627 %
628 % \subsection{\enquote{Page/Resources}: ExtGState, ColorSpace, Shading, Pattern}
629 % Path: Page/Resources/ExtGState etc. The actual output of the resources is handled
630 % together with the bdc/Properties. Here is only special code.
631 % \begin{macro}{\c_@@_backend_PageResources_clist}
632 % The names are quite often needed
633 % a similar list is now in l3pdfmanagement. Perhaps it should be merged.
634 % \begin{macrocode}
635 %<*drivers>
636 \clist_const:Nn \c_@@_backend_PageResources_clist
637 {
638 ExtGState,
639 ColorSpace,
640 Pattern,
641 Shading,
642 }
643 %</drivers>
644 % \end{macrocode}
645 % \end{macro}
646 %
647 % Now the backend commands the command to fill the register
648 % and to push the values.
649 %
650 % \begin{macro}{\@@_backend_PageResources_gput:nnn}
651 % stores values for the page resources.
652 % \begin{arguments}
653 % \item name of the resource (ExtGState, ColorSpace, Shading, Pattern)
654 % \item a pdf name without slash
655 % \item value
656 % \end{arguments}
657 % \begin{macro}{\@@_backend_PageResources_obj_gpush:}
658 % This pushes out the objects. It should be a no-op with xdvipdfmx and dvips
659 % as it is currently issued in the end-of-run hook!
660 % create the backend objects:
661 % \begin{macrocode}
662 %<*pdftex|luatex>
663 \clist_map_inline:Nn \c_@@_backend_PageResources_clist
664 {
665 \pdf_object_new:n {@@/Page/Resources/#1}
666 \cs_if_exist:NT \tex_directlua:D
667 {
668 \tex_directlua:D
669 {
670 ltx.@@.object["@@/Page/Resources/#1"]
671 =
672 "\pdf_object_ref:n{@@/Page/Resources/#1}"
673 }
674 }
675 }
676 %</pdftex|luatex>
677 % \end{macrocode}
678 % values are only stored in a prop and will be output at end document.
679 % luatex must also trigger the lua side
680 % \begin{macrocode}
681 %<*luatex>
682 \cs_new_protected:Npn \@@_backend_PageResources_gput:nnn #1 #2 #3
683 {
684 \pdfdict_gput:nnn {g_@@_Core/Page/Resources/#1} { #2 }{ #3 }
685 \tex_directlua:D{ltx.@@.Page.Resources.#1=true}
686 \tex_directlua:D
687 {
688 ltx.pdf.Page_Resources_gpush(tex.count["g_shipout_readonly_int"])
689 }
690 }
691 %</luatex>
692 %<*pdftex>
693 \cs_new_protected:Npn \@@_backend_PageResources_gput:nnn #1 #2 #3
694 {
695 \pdfdict_gput:nnn {g_@@_Core/Page/Resources/#1} { #2 }{ #3 }
696 }
697 %</pdftex>
698 % \end{macrocode}
699 % code for end of document code. Change 2026-03-11: we push out the
700 % objects even if they are empty as tikz references them in X-objects (fadings)
701 % \begin{macrocode}
702 %<*pdftex|luatex>
703 \cs_new_protected:Npn \@@_backend_PageResources_obj_gpush:
704 {
705 \clist_map_inline:Nn \c_@@_backend_PageResources_clist
706 {
707 \pdf_object_write:nne
708 { @@/Page/Resources/##1 } { dict }
709 { \pdfdict_use:n { g_@@_Core/Page/Resources/##1} }
710 }
711 }
712 %</pdftex|luatex>
713 % \end{macrocode}
714 % xdvipdfmx
715 % \special{pdf:pageresources<<#1>>} doesn't work correctly with object names ...
716 % https://tug.org/pipermail/dvipdfmx/2019-August/000021.html,
717 % so we use \special{pdf:put @resources}
718 % this must be issued on every page!
719 % objects should not only be created but also "initialized"
720 % initialization should be done before anyone tries to write
721 % so we add rules for the backend.
722 % The push command should not be used as it is
723 % in the wrong end document hook. If needed a new command must be added.
724 % \begin{macrocode}
725 %<*dvipdfmx|xdvipdfmx>
726 %<xdvipdfmx>\hook_gset_rule:nnnn{shipout/firstpage}{l3backend-xetex}{after}{pdf}
727 %<dvipdfmx>\hook_gset_rule:nnnn{shipout/firstpage}{l3backend-dvipdfmx}{after}{pdf}
728 %
729 \clist_map_inline:Nn \c_@@_backend_PageResources_clist
730 {
731 \pdf_object_new:n { @@/Page/Resources/#1 }
732 \hook_gput_code:nnn
733 {shipout/firstpage}
734 {pdf}
735 {\pdf_object_write:nnn { @@/Page/Resources/#1 } { dict } {}}
736 }
737 \cs_new_protected:Npn \@@_backend_PageResources:n #1
738 {
739 \@@_backend:n {put~@resources~<<#1>>}
740 }
741 \cs_new_protected:Npn \@@_backend_PageResources_gput:nnn #1 #2 #3
742 {
743 % this is not used for output, but there is a test if the resource is empty
744 \prop_gput:cne { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/#1} }
745 { \str_convert_pdfname:n {#2} }{ #3 }
746 %objects are not filled with \pdf_object_write as this is not additive!
747 \@@_backend:e
748 {
749 put~\pdf_object_ref:n {@@/Page/Resources/#1}<</#2~#3>>
750 }
751 }
752
753 \cs_new_protected:Npn \@@_backend_PageResources_obj_gpush: {}
754 %</dvipdfmx|xdvipdfmx>
755 % \end{macrocode}
756 % dvips unneeded, or no-op. The push command should not be used as it is
757 % in the wrong end document hook. If needed a new command must be added.
758 % \begin{macrocode}
759 %<*dvips>
760 \cs_new_protected:Npn \@@_backend_PageResources:n #1 {}
761 \cs_new_protected:Npn \@@_backend_PageResources_gput:nnn #1 #2 #3
762 { %only for the show command TEST!!
763 \pdfdict_gput:nnn {g_@@_Core/Page/Resources/#1} { #2 }{ #3 }
764 }
765 \cs_new_protected:Npn \@@_backend_PageResources_obj_gpush: {}
766 %</dvips>
767 % \end{macrocode}
768 % dvipsvgm unneeded, or no-op
769 % \begin{macrocode}
770 %<*dvisvgm>
771 \cs_new_protected:Npn \@@_backend_PageResources:n #1 {}
772 \cs_new_protected:Npn \@@_backend_PageResources_gput:nnn #1 #2 #3
773 { %only for the show command TEST!!
774 \pdfdict_gput:nnn {g_@@_Core/Page/Resources/#1} { #2 }{ #3 }
775 }
776 \cs_new_protected:Npn \@@_backend_PageResources_obj_gpush: {}
777 %</dvisvgm>
778 % \end{macrocode}
779 % \end{macro}
780 % \end{macro}
781 %
782 % \subsubsection{Page resources /Properties + BDC operators}
783 % \begin{macro}
784 % {
785 % \@@_backend_bdc:nn,
786 % \@@_backend_shipout_bdc:ee,
787 % \@@_backend_bdcobject:nn,
788 % \@@_backend_bdcobject:n,
789 % \@@_backend_bmc:n,
790 % \@@_backend_emc:,
791 % \@@_backend_PageResources_gpush:n
792 % }
793 % \cs{@@_backend_bdc:nn}, \cs{@@_backend_shipout_bdc:ee},
794 % \cs{@@_backend_bdcobject:nn}, \cs{@@_backend_bdcobject:n},
795 % \cs{@@_backend_bmc:n} and \cs{@@_backend_emc:}
796 % are the backend command that
797 % create the bdc/emc marker and store the properties.
798 % \cs{@@_backend_PageResources_gpush:n} outputs the /Properties and/or the other
799 % resources for the current page.
800 %
801 % pdftex and luatex (and perhaps dvips ...) need to know if there are in a
802 % xform stream ...
803 % \begin{macrocode}
804 %<*drivers>
805 \bool_new:N \l_@@_backend_xform_bool
806 %</drivers>
807 % \end{macrocode}
808 %
809 % dvips is easy: create an object, and reference it in the bdc
810 % ghostscript will then automatically replace it by a name
811 % and add the name to the /Properties dict,
812 % special variant von accsupp
813 % \url{https://chat.stackexchange.com/transcript/message/50831812#50831812}
814 % \begin{macrocode}
815 %<*dvips>
816 %
817 \cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: dict_content
818 {
819 \@@_backend_pdfmark:n{/#1~<<#2>>~/BDC}
820 }
821 % \end{macrocode}
822 % There is not difference here between inline and property BDC, it is always
823 % a property:
824 % \begin{macrocode}
825 \cs_set_eq:NN \@@_backend_bdc_contobj:nn \@@_backend_bdc:nn
826 \cs_set_eq:NN \@@_backend_bdc_contstream:nn \@@_backend_bdc:nn
827
828 \cs_new_protected:Npn \@@_backend_bdc_shipout:ee #1 #2 % #1 eg. Span, #2: dict_content
829 {
830 \__kernel_backend_shipout_literal:e
831 {ps: SDict ~ begin ~ mark /#1~<<#2>>~/BDC ~ pdfmark ~ end }
832 }
833
834 \cs_set_protected:Npn \@@_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
835 {
836 \@@_backend_pdfmark:e{/#1~\pdf_object_ref:n{#2}~/BDC}
837 }
838 \cs_set_protected:Npn \@@_backend_bdcobject:n #1 % #1 eg. Span,
839 {
840 \@@_backend_pdfmark:e{/#1~\@@_backend_object_last:~/BDC}
841 }
842 \cs_set_protected:Npn \@@_backend_emc:
843 {
844 \@@_backend_pdfmark:n{/EMC} %
845 }
846 \cs_set_protected:Npn \@@_backend_bmc:n #1
847 {
848 \@@_backend_pdfmark:n{/#1~/BMC} %
849 }
850 \cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
851
852 %</dvips>
853 %<*dvisvgm>
854 % dvisvgm should do nothing
855 %
856 \cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: dict_content
857 {}
858 \cs_set_eq:NN \@@_backend_bdc_contobj:nn \@@_backend_bdc:nn
859 \cs_set_eq:NN \@@_backend_bdc_contstream:nn \@@_backend_bdc:nn
860
861 \cs_set_protected:Npn \@@_backend_shipout_bdc:ee #1 #2 % #1 eg. Span, #2: dict_content
862 {}
863 \cs_set_protected:Npn \@@_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
864 {}
865 \cs_set_protected:Npn \@@_backend_bdcobject:n #1 % #1 eg. Span,
866 {}
867 \cs_set_protected:Npn \@@_backend_emc:
868 {}
869 \cs_set_protected:Npn \@@_backend_bmc:n #1
870 {}
871 \cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
872
873 %</dvisvgm>
874 %
875 % xetex has to create the entries in the /Properties manually
876 % (like the other backends)
877 % use pdfbase special
878 % https://chat.stackexchange.com/transcript/message/50832016#50832016
879 % the property is added to xform resources automatically,
880 % no need to worry about it.
881 %<*dvipdfmx|xdvipdfmx>
882 \cs_set_protected:Npn \@@_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
883 {
884 \int_gincr:N \g_@@_backend_name_int
885 \__kernel_backend_literal:e
886 {
887 pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
888 }
889 \__kernel_backend_literal:e
890 {
891 pdf:put~@resources~
892 <<
893 /Properties~
894 <<
895 /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
896 \pdf_object_ref:n { #2 }
897 >>
898 >>
899 }
900 }
901 \cs_set_protected:Npn \@@_backend_bdcobject:n #1 % #1 eg. Span
902 {
903 \int_gincr:N \g_@@_backend_name_int
904 \__kernel_backend_literal:e
905 {
906 pdf:code~/\exp_not:n{#1}/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
907 }
908 \__kernel_backend_literal:e
909 {
910 pdf:put~@resources~
911 <<
912 /Properties~
913 <<
914 /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
915 \@@_backend_object_last:
916 >>
917 >>
918 }
919 }
920 \cs_set_protected:Npn \@@_backend_bmc:n #1
921 {
922 \__kernel_backend_literal:n {pdf:code~/#1~BMC} %pdfbase
923 }
924
925 %this require management
926 \cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
927 {
928 \pdf_object_unnamed_write:nn { dict }{ #2 }
929 \@@_backend_bdcobject:n { #1 }
930 }
931
932 \cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
933 {
934 \__kernel_backend_literal:n {pdf:code~ /#1~<<#2>>~BDC }
935 }
936
937 \cs_set_protected:Npn \@@_backend_bdc:nn #1 #2
938 {
939 \cs_gset_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contobj:nn
940 \@@_backend_bdc:nn {#1}{#2}
941 }
942
943 \cs_set_protected:Npn \@@_backend_bdc_shipout_contstream:ee #1 #2
944 {
945 \__kernel_backend_shipout_literal:e {pdf:code~ /#1~<<#2>>~BDC }
946 }
947 \cs_set_eq:NN \@@_backend_bdc_shipout:ee \@@_backend_bdc_shipout_contstream:ee
948
949 \cs_set_protected:Npn \@@_backend_emc:
950 {
951 \__kernel_backend_literal:n {pdf:code~EMC} %pdfbase
952 }
953 % properties are handled automatically, but the other resources should be added
954 % at shipout
955 \cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1
956 {
957 \clist_map_inline:Nn \c_@@_backend_PageResources_clist
958 {
959 \prop_if_empty:cF { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/##1} }
960 {
961 \__kernel_backend_literal:e
962 {
963 pdf:put~@resources~
964 <</##1~\pdf_object_ref:n {@@/Page/Resources/##1}>>
965 }
966 }
967 }
968 }
969 %</dvipdfmx|xdvipdfmx>
970 % luatex + pdftex
971 %<*luatex>
972 \cs_set_protected:Npn \@@_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
973 {
974 \int_gincr:N \g_@@_backend_name_int
975 \__kernel_backend_literal_page:e
976 { /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
977 \bool_if:NTF \l_@@_backend_xform_bool
978 {
979 \pdfdict_gput:nee
980 { g_@@_Core/Xform/Resources/Properties }
981 { l3pdf\int_use:N\g_@@_backend_name_int }
982 { \pdf_object_ref:n { #2 } }
983 }
984 {
985 \exp_args:Ne \tex_latelua:D
986 {
987 ltx.pdf.Page_Resources_Properties_gput
988 (
989 tex.count["g_shipout_readonly_int"],
990 "l3pdf\int_use:N\g_@@_backend_name_int",
991 "\pdf_object_ref:n { #2 }"
992 )
993 }
994 }
995 }
996 \cs_set_protected:Npn \@@_backend_bdcobject:n #1% #1 eg. Span
997 {
998 \int_gincr:N \g_@@_backend_name_int
999 \__kernel_backend_literal_page:e
1000 { /\exp_not:n{#1} ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
1001 \bool_if:NTF \l_@@_backend_xform_bool
1002 {
1003 \pdfdict_gput:nee %no handler needed
1004 { g_@@_Core/Xform/Resources/Properties }
1005 { l3pdf\int_use:N\g_@@_backend_name_int }
1006 { \@@_backend_object_last: }
1007 }
1008 {
1009 \exp_args:Ne \tex_latelua:D
1010 {
1011 ltx.pdf.Page_Resources_Properties_gput
1012 (
1013 tex.count["g_shipout_readonly_int"],
1014 "l3pdf\int_use:N\g_@@_backend_name_int",
1015 "\@@_backend_object_last:"
1016 )
1017 }
1018 }
1019 }
1020 \cs_set_protected:Npn \@@_backend_bmc:n #1
1021 {
1022 \__kernel_backend_literal_page:n { /#1~BMC }
1023 }
1024 \cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
1025 {
1026 \pdf_object_unnamed_write:nn { dict } { #2 }
1027 \@@_backend_bdcobject:n { #1 }
1028 }
1029 \cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
1030 {
1031 \__kernel_backend_literal_page:n { /#1~<<#2>>~BDC }
1032 }
1033
1034 % \end{macrocode}
1035 % \changes{v0.96n}{2024/10/23}{Use inline dictionaries in bdc always.}
1036 % \begin{macrocode}
1037 \cs_set_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contstream:nn
1038
1039 \cs_set_protected:Npn \@@_backend_bdc_shipout_contstream:ee #1 #2
1040 {
1041 \__kernel_backend_shipout_literal_page:e { /#1~<<#2>>~BDC }
1042 }
1043 \cs_set_eq:NN \@@_backend_bdc_shipout:ee \@@_backend_bdc_shipout_contstream:ee
1044
1045 \cs_set_protected:Npn \@@_backend_emc:
1046 {
1047 \__kernel_backend_literal_page:n { EMC }
1048 }
1049
1050 \cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
1051 %</luatex>
1052 % \end{macrocode}
1053 % pdflatex is the most complicated if we want to use properties
1054 % as it has to go through the aux ...
1055 % the push command is extended to take other resources too
1056 % \begin{macrocode}
1057 %<*pdftex>
1058 \cs_set_protected:Npn \@@_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
1059 {
1060 \int_gincr:N \g_@@_backend_name_int
1061 \__kernel_backend_literal_page:e
1062 { /#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
1063 % code to set the property ....
1064 \int_gincr:N\g_@@_backend_resourceid_int
1065 \bool_if:NTF \l_@@_backend_xform_bool
1066 {
1067 \pdfdict_gput:nee %no handler needed
1068 { g_@@_Core/Xform/Resources/Properties }
1069 { l3pdf\int_use:N\g_@@_backend_resourceid_int }
1070 { \pdf_object_ref:n { #2 } }
1071 }
1072 {
1073 \@@_backend_record_abspage:e {l3pdf\int_use:N\g_@@_backend_resourceid_int}
1074 \tl_set:Ne \l_@@_tmpa_tl
1075 {
1076 \@@_backend_ref_abspage:e{l3pdf\int_use:N\g_@@_backend_resourceid_int}
1077 }
1078 \pdfdict_if_exist:nF { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1079 {
1080 \pdfdict_new:n { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1081 }
1082 \pdfdict_gput:nee
1083 { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1084 { l3pdf\int_use:N\g_@@_backend_resourceid_int }
1085 { \pdf_object_ref:n{#2} }
1086 }
1087 }
1088 \cs_set_protected:Npn \@@_backend_bdcobject:n #1% #1 eg. Span
1089 {
1090 \int_gincr:N \g_@@_backend_name_int
1091 \__kernel_backend_literal_page:e
1092 { /\exp_not:n{#1} ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC }
1093 % code to set the property ....
1094 \int_gincr:N\g_@@_backend_resourceid_int
1095 \bool_if:NTF \l_@@_backend_xform_bool
1096 {
1097 \pdfdict_gput:nee
1098 { g_@@_Core/Xform/Resources/Properties }
1099 { l3pdf\int_use:N\g_@@_backend_resourceid_int }
1100 { \@@_backend_object_last: }
1101 }
1102 {
1103 \@@_backend_record_abspage:e{l3pdf\int_use:N\g_@@_backend_resourceid_int}
1104 \tl_set:Ne \l_@@_tmpa_tl
1105 {
1106 \@@_backend_ref_abspage:e{l3pdf\int_use:N\g_@@_backend_resourceid_int}
1107 }
1108 \pdfdict_if_exist:nF { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1109 {
1110 \pdfdict_new:n { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1111 }
1112 \pdfdict_gput:nee
1113 { g_@@_Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
1114 { l3pdf\int_use:N\g_@@_backend_resourceid_int }
1115 { \@@_backend_object_last: }
1116 %\pdfdict_show:n { g_backend_Page\l_@@_tmpa_tl/Resources/Properties }
1117 }
1118 }
1119 \cs_set_protected:Npn \@@_backend_bmc:n #1
1120 {
1121 \__kernel_backend_literal_page:n { /#1~BMC }
1122 }
1123 \cs_set_protected:Npn \@@_backend_bdc_contobj:nn #1 #2
1124 {
1125 \pdf_object_unnamed_write:nn { dict } { #2 }
1126 \@@_backend_bdcobject:n { #1 }
1127 }
1128 \cs_set_protected:Npn \@@_backend_bdc_contstream:nn #1 #2
1129 {
1130 \__kernel_backend_literal_page:n { /#1~<<#2>>~BDC }
1131 }
1132 % \end{macrocode}
1133 % \changes{v0.96n}{2024/10/23}{Use inline dictionaries in bdc always.}
1134 % We use by default the direct BDC.
1135 % \begin{macrocode}
1136 \cs_set_eq:NN \@@_backend_bdc:nn \@@_backend_bdc_contstream:nn
1137
1138 \cs_set_protected:Npn \@@_backend_bdc_shipout_contstream:ee #1 #2
1139 {
1140 \__kernel_backend_shipout_literal_page:e { /#1~<<#2>>~BDC }
1141 }
1142 \cs_set_eq:NN \@@_backend_bdc_shipout:ee \@@_backend_bdc_shipout_contstream:ee
1143
1144
1145 \cs_set_protected:Npn \@@_backend_emc:
1146 {
1147 \__kernel_backend_literal_page:n { EMC }
1148 }
1149
1150 \cs_new:Npn \@@_backend_PageResources_gpush_aux:n #1 %#1 ExtGState etc
1151 {
1152 \prop_if_empty:cF
1153 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/#1} }
1154 {
1155 \pdfdict_item:ne { #1 }{ \pdf_object_ref:n {@@/Page/Resources/#1}}
1156 }
1157 }
1158
1159 \cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1
1160 {
1161 \exp_args:NNe \tex_global:D \tex_pdfpageresources:D
1162 {
1163 \prop_if_exist:cT
1164 { \__kernel_pdfdict_name:n { g_@@_Core/backend_Page#1/Resources/Properties } }
1165 {
1166 /Properties~
1167 <<
1168 \prop_map_function:cN
1169 { \__kernel_pdfdict_name:n { g_@@_Core/backend_Page#1/Resources/Properties } }
1170 \pdfdict_item:ne
1171 >>
1172 }
1173 %% add ExtGState etc
1174 \clist_map_function:NN
1175 \c_@@_backend_PageResources_clist
1176 \@@_backend_PageResources_gpush_aux:n
1177 }
1178 }
1179
1180 %</pdftex>
1181 % \end{macrocode}
1182 % \end{macro}
1183 %
1184 % \subsection{\enquote{Catalog} \& subdirectories (pdfcatalog) }
1185 % The backend command is already in the driver:
1186 % \cs{@@_backend_catalog_gput:nn}
1187 % \subsubsection { Special case: the /Names/EmbeddedFiles dictionary }
1188 % Entries to /Names are handled differently, in part (/Desc) it is automatic, for
1189 % other special commands like \cs{pdfnames} must be used. For EmbeddedFiles
1190 % dvips wants code for every file and then creates the Name tree automatically.
1191 % Other name trees are ignored.
1192 % TODO: Currently the code for EmbeddedFiles is still a bit
1193 % different but this should be merged, all name trees should be handled with the
1194 % same code.
1195 % \begin{macrocode}
1196 % pdflatex
1197 %<*pdftex>
1198 \cs_new_protected:Npn \@@_backend_Names_gpush:nn #1 #2 %#1 name of name tree, #2 array content
1199 {
1200 \pdf_object_unnamed_write:nn {dict} {/Names [#2] }
1201 \tex_pdfnames:D {/#1~\pdf_object_ref_last:}
1202 }
1203 %</pdftex>
1204 %<*luatex>
1205 \cs_new_protected:Npn \@@_backend_Names_gpush:nn #1 #2 %#1 name of name tree, #2 array content
1206 {
1207 \pdf_object_unnamed_write:nn {dict} {/Names [#2] }
1208 \tex_pdfextension:D~names~ {/#1~\pdf_object_ref_last:}
1209 }
1210 %</luatex>
1211 %<*dvipdfmx|xdvipdfmx>
1212 \cs_new_protected:Npn \@@_backend_Names_gpush:nn #1 #2 %#1 name of name tree, #2 array content
1213 {
1214 \pdf_object_unnamed_write:nn {dict} {/Names [#2] }
1215 \@@_backend:e {put~@names~<</#1~\pdf_object_ref_last: >>}
1216 }
1217 %</dvipdfmx|xdvipdfmx>
1218
1219 %dvips: noop
1220 %<*dvips>
1221 \cs_new_protected:Npn \@@_backend_Names_gpush:nn #1 #2 {}
1222 %</dvips>
1223 %dvisvgm: noop
1224 %<*dvisvgm>
1225 \cs_new_protected:Npn \@@_backend_Names_gpush:nn #1 #2 {}
1226 %</dvisvgm>
1227 % \end{macrocode}
1228 % EmbeddedFiles is a bit special.
1229 % For once we need backend commands for dvips.
1230 % But we want also an option to create the name on the fly.
1231 %
1232 % \begin{macro}{\@@_backend_NamesEmbeddedFiles_add:nn}
1233 % dvips need special backend code to create the name tree.
1234 % With the other engines it does nothing.
1235 % \begin{macrocode}
1236 %<*pdftex|luatex|dvipdfmx|xdvipdfmx>
1237 \cs_new_protected:Npn \@@_backend_NamesEmbeddedFiles_add:nn #1 #2 {}
1238 %</pdftex|luatex|dvipdfmx|xdvipdfmx>
1239 %<*dvips>
1240 \cs_new_protected:Npn \@@_backend_NamesEmbeddedFiles_add:nn #1 #2
1241 {
1242 \@@_backend_pdfmark:e
1243 {
1244 /Name~#1~
1245 /FS~#2~
1246 /EMBED
1247 }
1248 }
1249 %</dvips>
1250 %<*dvisvgm>
1251 %no op. Or is there any sensible use for it?
1252 \cs_new_protected:Npn \@@_backend_NamesEmbeddedFiles_add:nn #1 #2
1253 {}
1254
1255 %</dvisvgm>
1256 % \end{macrocode}
1257 % \end{macro}
1258 %
1259 % \subsubsection{Additional annotation commands}
1260 % Starting with texlive 2021 pdftex and luatex offer commands to interrupt
1261 % a link. That can for example be used to exclude the header and footer from
1262 % the link. The backend support is now in l3kernel. We only provide the user command.
1263 % \begin{macrocode}
1264 %<*pdftex>
1265 \cs_if_exist:NT \pdfrunninglinkoff
1266 {
1267 \cs_set_protected:Npn \__pdfannot_backend_link_off:
1268 {
1269 \pdfrunninglinkoff
1270 }
1271 \cs_set_protected:Npn \__pdfannot_backend_link_on:
1272 {
1273 \pdfrunninglinkon
1274 }
1275 }
1276 %</pdftex>
1277 % \end{macrocode}
1278 %
1279 % \subsubsection{Split links}
1280 % With luatex we use luacode to handle link annotations. This allows us
1281 % to retrieve the annotations as needed by the tagging code.
1282 % It also allow to prevent that link areas spill over into unwanted regions like
1283 % footnotes. See the documentation in lualinksplit.lua for more details.
1284 % We therefore add a plug for the build/column/footnotes.
1285 % \begin{macrocode}
1286 %<*luatex>
1287 \lua_load_module:n{lualinksplit}
1288 \NewSocketPlug{build/column/footnotes}{lualinksplit}{%
1289 \setbox\footins=\vbox{\pdfextension linkstate-2\unvbox\footins}%
1290 }
1291 \AssignSocketPlug{build/column/footnotes}{lualinksplit}
1292 %</luatex>
1293 % \end{macrocode}
1294 % \subsubsection{Form XObject / backend }
1295 % \begin{macro}{ \@@_backend_xform_new:nnnn }
1296 % \begin{arguments}
1297 % \item name
1298 % \item attributes
1299 % \item resources %needed?? or are all resources autogenerated?
1300 % \item content, this doesn't need to be a box!
1301 % \end{arguments}
1302 % \begin{macro}{ \@@_backend_xform_use:n, \@@_backend_xform_ref:n }
1303 % \begin{macrocode}
1304 %<*pdftex>
1305 \cs_new_protected:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
1306 % #1 name
1307 % #2 attributes
1308 % #3 resources
1309 % #4 content, not necessarily a box!
1310 {
1311 \hbox_set:Nn \l_@@_backend_tmpa_box
1312 {
1313 \bool_set_true:N \l_@@_backend_xform_bool
1314 \prop_gclear:c {\__kernel_pdfdict_name:n { g_@@_Core/Xform/Resources/Properties }}
1315 #4
1316 }
1317 %store the dimensions
1318 \tl_const:ce
1319 { c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
1320 { \tex_the:D \box_wd:N \l_@@_backend_tmpa_box }
1321 \tl_const:ce
1322 { c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
1323 { \tex_the:D \box_ht:N \l_@@_backend_tmpa_box }
1324 \tl_const:ce
1325 { c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
1326 { \tex_the:D \box_dp:N \l_@@_backend_tmpa_box }
1327 %% do we need to test if #2 and #3 are empty??
1328 \tex_immediate:D \tex_pdfxform:D
1329 ~ attr ~ { #2 }
1330 %% which other resources should be default? Is an argument actually needed?
1331 ~ resources ~
1332 {
1333 #3
1334 \int_compare:nNnT
1335 { \prop_count:c { \__kernel_pdfdict_name:n { g_@@_Core/Xform/Resources/Properties } } }
1336 >
1337 { 0 }
1338 {
1339 /Properties~
1340 <<
1341 \pdfdict_use:n { g_@@_Core/Xform/Resources/Properties }
1342 >>
1343 }
1344
1345 \prop_if_empty:cF
1346 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/ExtGState } }
1347 {
1348 /ExtGState~ \pdf_object_ref:n { @@/Page/Resources/ExtGState }
1349 }
1350 \prop_if_empty:cF
1351 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/Pattern } }
1352 {
1353 /Pattern~ \pdf_object_ref:n { @@/Page/Resources/Pattern }
1354 }
1355 \prop_if_empty:cF
1356 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/Shading } }
1357 {
1358 /Shading~ \pdf_object_ref:n { @@/Page/Resources/Shading }
1359 }
1360 \prop_if_empty:cF
1361 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/ColorSpace } }
1362 {
1363 /ColorSpace~ \pdf_object_ref:n { @@/Page/Resources/ColorSpace }
1364 }
1365 }
1366 \l_@@_backend_tmpa_box
1367 \int_const:cn
1368 { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1369 { \tex_pdflastxform:D }
1370 }
1371
1372 \cs_new_protected:Npn \@@_backend_xform_use:n #1
1373 {
1374 \tex_pdfrefxform:D
1375 \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1376 \scan_stop:
1377 }
1378
1379 \cs_new:Npn \@@_backend_xform_ref:n #1
1380 {
1381 \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } ~ 0 ~ R
1382 }
1383 %</pdftex>
1384 %<*luatex>
1385 %luatex
1386 %nearly identical but not completely ...
1387 \cs_new_protected:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
1388 % #1 name
1389 % #2 attributes
1390 % #3 resources
1391 % #4 content, not necessarily a box!
1392 {
1393 \hbox_set:Nn \l_@@_backend_tmpa_box
1394 {
1395 \bool_set_true:N \l_@@_backend_xform_bool
1396 \prop_gclear:c { \__kernel_pdfdict_name:n { g_@@_Core/Xform/Resources/Properties } }
1397 #4
1398 }
1399 \tl_const:ce
1400 { c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
1401 { \tex_the:D \box_wd:N \l_@@_backend_tmpa_box }
1402 \tl_const:ce
1403 { c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
1404 { \tex_the:D \box_ht:N \l_@@_backend_tmpa_box }
1405 \tl_const:ce
1406 { c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
1407 { \tex_the:D \box_dp:N \l_@@_backend_tmpa_box }
1408 %% do we need to test if #2 and #3 are empty??
1409 \tex_immediate:D \tex_pdfxform:D
1410 ~ attr ~ { #2 }
1411 %% which resources should be default? Is an argument actually needed?
1412 ~ resources ~
1413 {
1414 #3
1415 \int_compare:nNnT
1416 {\prop_count:c { \__kernel_pdfdict_name:n { g_@@_Core/Xform/Resources/Properties } }}
1417 >
1418 { 0 }
1419 {
1420 /Properties~
1421 <<
1422 \pdfdict_use:n { g_@@_Core/Xform/Resources/Properties }
1423 >>
1424 }
1425 \prop_if_empty:cF
1426 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/ExtGState } }
1427 {
1428 /ExtGState~ \pdf_object_ref:n { @@/Page/Resources/ExtGState }
1429 }
1430 \prop_if_empty:cF
1431 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/Pattern } }
1432 {
1433 /Pattern~ \pdf_object_ref:n { @@/Page/Resources/Pattern }
1434 }
1435 \prop_if_empty:cF
1436 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/Shading } }
1437 {
1438 /Shading~ \pdf_object_ref:n { @@/Page/Resources/Shading }
1439 }
1440 \prop_if_empty:cF
1441 { \__kernel_pdfdict_name:n { g_@@_Core/Page/Resources/ColorSpace } }
1442 {
1443 /ColorSpace~ \pdf_object_ref:n { @@/Page/Resources/ColorSpace }
1444 }
1445 }
1446 \l_@@_backend_tmpa_box
1447 \int_const:cn
1448 { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1449 { \tex_pdflastxform:D }
1450 }
1451
1452 \cs_new_protected:Npn \@@_backend_xform_use:n #1 %protected as with xelatex
1453 {
1454 \tex_pdfrefxform:D \int_use:c
1455 {
1456 c_@@_backend_xform_ \tl_to_str:n {#1} _int
1457 }
1458 \scan_stop:
1459 }
1460
1461 \cs_new:Npn \@@_backend_xform_ref:n #1
1462 { \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } ~ 0 ~ R }
1463
1464 %</luatex>
1465 %<*dvipdfmx|xdvipdfmx>
1466 % xetex
1467 % it needs a bit testing if it really works to set the box to 0 before the special ...
1468 % does it disturb viewing the xobject?
1469 % what happens with the resources (bdc)? (should work as they are specials too)
1470 % xetex requires that the special is in horizontal mode. This means it affects
1471 % typesetting. But we can no delay the whole form code to shipout
1472 % as the object reference and the size is often wanted on the current page.
1473 % so we need to allocate a box - but probably they won't be thousands xform
1474 % in a document so it shouldn't matter.
1475 \cs_new_protected:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
1476 % #1 name
1477 % #2 attributes
1478 % #3 resources
1479 % #4 content, not necessarily a box!
1480 {
1481 \int_gincr:N \g_@@_backend_object_int
1482 \int_const:cn
1483 { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1484 { \g_@@_backend_object_int }
1485 \box_new:c { g_@@_backend_xform_#1_box }
1486 \hbox_gset:cn { g_@@_backend_xform_#1_box }
1487 {
1488 \bool_set_true:N \l_@@_backend_xform_bool
1489 #4
1490 }
1491 \tl_const:ce
1492 { c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
1493 { \tex_the:D \box_wd:c { g_@@_backend_xform_#1_box } }
1494 \tl_const:ce
1495 { c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
1496 { \tex_the:D \box_ht:c { g_@@_backend_xform_#1_box } }
1497 \tl_const:ce
1498 { c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
1499 { \tex_the:D \box_dp:c { g_@@_backend_xform_#1_box } }
1500 \box_set_dp:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
1501 \box_set_ht:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
1502 \box_set_wd:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
1503 \hook_gput_next_code:nn {shipout/background}
1504 {
1505 \mode_leave_vertical: %needed, the xform disappears without it.
1506 \@@_backend:e
1507 {
1508 bxobj ~ \@@_backend_xform_ref:n { #1 }
1509 \c_space_tl width ~ \pdfxform_wd:n { #1 }
1510 \c_space_tl height ~ \pdfxform_ht:n { #1 }
1511 \c_space_tl depth ~ \pdfxform_dp:n { #1 }
1512 }
1513 \box_use_drop:c { g_@@_backend_xform_#1_box }
1514 \@@_backend:e {put ~ @resources ~<<#3>> }
1515 \@@_backend:e
1516 {
1517 put~ @resources ~
1518 <<
1519 /ExtGState~ \pdf_object_ref:n { @@/Page/Resources/ExtGState }
1520 >>
1521 }
1522 \@@_backend:e
1523 {
1524 put~ @resources ~
1525 <<
1526 /Pattern~ \pdf_object_ref:n { @@/Page/Resources/Pattern }
1527 >>
1528 }
1529 \@@_backend:e
1530 {
1531 put~ @resources ~
1532 <<
1533 /Shading~ \pdf_object_ref:n { @@/Page/Resources/Shading }
1534 >>
1535 }
1536 \@@_backend:e
1537 {
1538 put~ @resources ~
1539 <<
1540 /ColorSpace~
1541 \pdf_object_ref:n { @@/Page/Resources/ColorSpace }
1542 >>
1543 }
1544 \@@_backend:e {exobj ~<<#2>>}
1545 }
1546 }
1547
1548
1549
1550 \cs_new:Npn \@@_backend_xform_ref:n #1
1551 {
1552 @pdf.xform \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1553 }
1554
1555 \cs_new_protected:Npn \@@_backend_xform_use:n #1
1556 {
1557 \hbox_set:Nn \l_@@_backend_tmpa_box
1558 {
1559 \@@_backend:e
1560 {
1561 uxobj~ \@@_backend_xform_ref:n { #1 }
1562 }
1563 }
1564 \box_set_wd:Nn \l_@@_backend_tmpa_box { \pdfxform_wd:n { #1 } }
1565 \box_set_ht:Nn \l_@@_backend_tmpa_box { \pdfxform_ht:n { #1 } }
1566 \box_set_dp:Nn \l_@@_backend_tmpa_box { \pdfxform_dp:n { #1 } }
1567 \box_use_drop:N \l_@@_backend_tmpa_box
1568 }
1569 %</dvipdfmx|xdvipdfmx>
1570 %<*dvisvgm>
1571 % unclear what it should do!!
1572 \cs_new_protected:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4 {}
1573 \cs_new_protected:Npn \@@_backend_xform_use:n #1 {}
1574 \cs_new:Npn \@@_backend_xform_ref:n {}
1575 %</dvisvgm>
1576 % \end{macrocode}
1577 % The xform code for dvips is based on code from the attachfile2 package
1578 % (in atfi-dvips), along with some ideas from pdfbase and has been corrected
1579 % with the help of Alexander Grahn.
1580 % Details like clipping and landscape will probably be corrected in the future.
1581 % We need some temporary variables to store dimensions
1582 % \begin{macrocode}
1583 %<*dvips>
1584 \tl_new:N \l_@@_backend_xform_tmpwd_tl
1585 \tl_new:N \l_@@_backend_xform_tmpdp_tl
1586 \tl_new:N \l_@@_backend_xform_tmpht_tl
1587 % \end{macrocode}
1588 %
1589 % \begin{macrocode}
1590 \cs_new_protected:Npn\@@_backend_xform_new:nnnn #1 #2 #3 #4 % #1 name, #2 attribute, #4 content
1591 {
1592 \int_gincr:N \g_@@_backend_object_int
1593 \int_const:cn
1594 { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1595 { \g_@@_backend_object_int }
1596
1597 \hbox_set:Nn \l_@@_backend_tmpa_box
1598 {
1599 \bool_set_true:N \l_@@_backend_xform_bool
1600 \prop_gclear:c {\__kernel_pdfdict_name:n { g_@@_Core/Xform/Resources/Properties }}
1601 #4
1602 }
1603 %store the dimensions
1604 \tl_const:ce
1605 { c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
1606 { \tex_the:D \box_wd:N \l_@@_backend_tmpa_box }
1607 \tl_const:ce
1608 { c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
1609 { \tex_the:D \box_ht:N \l_@@_backend_tmpa_box }
1610 \tl_const:ce
1611 { c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
1612 { \tex_the:D \box_dp:N \l_@@_backend_tmpa_box }
1613 %store content dimensions in DPI units (Dots) (code from issue 25)
1614 \tl_set:Ne\l_@@_backend_xform_tmpwd_tl
1615 {
1616 \dim_to_decimal_in_sp:n{ \box_wd:N \l_@@_backend_tmpa_box }~
1617 65536~div~72.27~div~DVImag~mul~Resolution~mul~
1618 }
1619 \tl_set:Ne\l_@@_backend_xform_tmpht_tl
1620 {
1621 \dim_to_decimal_in_sp:n{ \box_ht:N \l_@@_backend_tmpa_box }~
1622 65536~div~72.27~div~DVImag~mul~VResolution~mul~
1623 }
1624 \tl_set:Ne\l_@@_backend_xform_tmpdp_tl
1625 {
1626 \dim_to_decimal_in_sp:n{ \box_dp:N \l_@@_backend_tmpa_box }~
1627 65536~div~72.27~div~DVImag~mul~VResolution~mul~
1628 }
1629 % mirror the box
1630 %\box_scale:Nnn \l_@@_backend_tmpa_box {1} {-1}
1631 \hbox_set:Nn\l_@@_backend_tmpb_box
1632 {
1633 \__kernel_backend_postscript:e
1634 {
1635 gsave~currentpoint~
1636 initclip~ % restore default clipping path (page device/whole page)
1637 clippath~pathbbox~newpath~pop~pop~
1638 \tl_use:N\l_@@_backend_xform_tmpdp_tl~add~translate~
1639 mark~
1640 /_objdef~{ pdf.obj \int_use:N\g_@@_backend_object_int }\c_space_tl~
1641 /BBox[
1642 0~
1643 \tl_use:N\l_@@_backend_xform_tmpht_tl~
1644 \tl_use:N\l_@@_backend_xform_tmpwd_tl~
1645 \tl_use:N\l_@@_backend_xform_tmpdp_tl~
1646 neg
1647 ]
1648 \str_if_eq:eeF{#1}{}
1649 {
1650 product~(Distiller)~search~{pop~pop~pop~#2}{pop}ifelse~
1651 }
1652 /BP~pdfmark~1~-1~scale~neg~exch~neg~exch~translate
1653 }
1654 \box_use_drop:N\l_@@_backend_tmpa_box
1655 \__kernel_backend_postscript:n
1656 {
1657 mark ~ /EP~pdfmark ~ grestore
1658 }
1659 \str_if_eq:eeF{#1}{}
1660 {
1661 \__kernel_backend_postscript:e
1662 {
1663 product~(Ghostscript)~search~
1664 {
1665 pop~pop~pop~
1666 mark~
1667 { pdf.obj \int_use:c{c_@@_backend_xform_ \tl_to_str:n {#1} _int} }
1668 ~<<#2>>~/PUT~pdfmark
1669 }{pop}ifelse
1670 }
1671 }
1672 }
1673 \box_set_dp:Nn \l_@@_backend_tmpb_box { \c_zero_dim }
1674 \box_set_ht:Nn \l_@@_backend_tmpb_box { \c_zero_dim }
1675 \box_set_wd:Nn \l_@@_backend_tmpb_box { \c_zero_dim }
1676 \hook_gput_code:nnn {begindocument/end}{pdfxform}
1677 {
1678 \mode_leave_vertical:
1679 \box_use:N\l_@@_backend_tmpb_box
1680 }
1681 }
1682
1683
1684 \cs_new_protected:Npn \@@_backend_xform_use:n #1
1685 {
1686 \hbox_set:Nn \l_@@_backend_tmpa_box
1687 {
1688 \__kernel_backend_postscript:e
1689 {
1690 gsave~currentpoint~translate~1~-1~scale~
1691 mark~{ pdf.obj \int_use:c{c__pdf_backend_xform_ \tl_to_str:n {#1} _int }}~
1692 /SP~pdfmark ~ grestore
1693 }
1694 }
1695 \box_set_wd:Nn \l_@@_backend_tmpa_box { \pdfxform_wd:n { #1 } }
1696 \box_set_ht:Nn \l_@@_backend_tmpa_box { \pdfxform_ht:n { #1 } }
1697 \box_set_dp:Nn \l_@@_backend_tmpa_box { \pdfxform_dp:n { #1 } }
1698 \box_use_drop:N \l_@@_backend_tmpa_box
1699 }
1700 \cs_new:Npn \@@_backend_xform_ref:n #1
1701 {
1702 { pdf.obj \int_use:c{c_@@_backend_xform_ \tl_to_str:n {#1} _int} }
1703 }
1704
1705 %</dvips>
1706 %<*drivers>
1707 %% all
1708 \prg_new_conditional:Npnn \@@_backend_xform_if_exist:n #1 { p , T , F , TF }
1709 {
1710 \int_if_exist:cTF { c_@@_backend_xform_ \tl_to_str:n {#1} _int }
1711 { \prg_return_true: }
1712 { \prg_return_false:}
1713 }
1714 \prg_new_eq_conditional:NNn \pdfxform_if_exist:n\@@_backend_xform_if_exist:n
1715 { TF , T , F , p }
1716 %</drivers>
1717 % \end{macrocode}
1718 % \end{macro}
1719 % \end{macro}
1720 %
1721 % \subsection{Structure Destinations}
1722 % Standard destinations consist of a reference to a page in the pdf and instructions
1723 % how to display it---typically they will put a specific location in the left top corner
1724 % of the viewer and so give the impression that a link jumped to the word in this place.
1725 % But in reality they are not connected to the content.
1726 %
1727 % Starting with pdf~2.0 destinations can in a tagged PDF also point to a structure, to a /StructElem object.
1728 % GoTo links can then additionally to the \texttt{/D} key pointing to a
1729 % page destination also point to such a structure destination with an \texttt{/SD} key.
1730 % Programs that e.g. convert such a PDF to html can then create better links.
1731 % (According to the reference, PDF-viewer should prefer the structure destination
1732 % over the page destination, but as far as it is known this isn't done yet.)
1733 %
1734 % Currently structure destinations and GoTo links making use of it could natively only
1735 % be created with the dvipdfmx backend. With pdftex and lualatex it was only possible to create
1736 % a restricted type which used only the \enquote{Fit} mode. Starting with
1737 % \TeX{}live 2022 (earlier in miktex) both engine will knew new keywords which allow
1738 % to create structure destination easily.
1739 %
1740 % The following backend code prepares the use of structure destinations. The general idea is
1741 % that if structure destinations are used, they should be used always. So we define
1742 % alternative commands which can be activated by mapping them to the standard backend commands.
1743 %
1744 % The needed code differ depending on if structure objects use standard or indexed object names.
1745 % At the end we will probably always use indexed objects, but for now we offer
1746 % both options.
1747 %
1748 % \begin{variable}[no-user-doc]{\l_pdf_current_structure_destination_tl}
1749 %
1750 % This command holds the name of the structure object to use in the following commands
1751 % which creates a destination. The code which activates structure destinations
1752 % must also ensure that it has a sensible, expandable content. \pkg{tagpdf} for example
1753 % will define it as
1754 % \begin{verbatim}
1755 % \tl_set:Nn \l_pdf_current_structure_destination_tl { __tag/struct/\g__tag_struct_stack_current_tl }
1756 % \end{verbatim}
1757 % or if indexed structure object names are used
1758 % \begin{verbatim}
1759 % \tl_set:Nn \l_pdf_current_structure_destination_tl { {__tag/struct}{\g__tag_struct_stack_current_tl} }
1760 % \end{verbatim}
1761 % \begin{macrocode}
1762 %<*drivers>
1763 \tl_new:N \l_pdf_current_structure_destination_tl
1764 %</drivers>
1765 % \end{macrocode}
1766 % \end{variable}
1767 %
1768 % We will define alternatives for three backend commands:
1769 % \begin{verbatim}
1770 % \__pdf_backend_destination:nn -> \__pdf_backend_structure_destination:nn
1771 % \__pdf_backend_destination:nnnn -> \__pdf_backend_structure_destination:nnnn
1772 % \__pdfannot_backend_link_begin_goto:nnw -> \__pdf_backend_link_begin_structure_goto:nnw
1773 % \__pdf_backend_destination:nn -> \__pdf_backend_indexed_structure_destination:nn
1774 % \__pdf_backend_destination:nnnn -> \__pdf_backend_indexed_structure_destination:nnnn
1775 % \__pdfannot_backend_link_begin_goto:nnw -> \__pdf_backend_indexed_link_begin_structure_goto:nnw
1776 % \end{verbatim}
1777 %
1778 % Activating means mapping them onto the original commands. Be aware that not
1779 % all engines and compilation routes support structure destinations, for them
1780 % the command will be a no-op.
1781 %
1782 % \begin{macro}[no-user-doc]{\pdf_activate_structure_destination:,\pdf_activate_indexed_structure_destination:}
1783 % \begin{macrocode}
1784 %<*drivers>
1785 \cs_new_protected:Npn \pdf_activate_structure_destination:
1786 {
1787 \cs_gset_eq:NN \@@_backend_destination:nn \@@_backend_structure_destination:nn
1788 \cs_gset_eq:NN \@@_backend_destination:nnnn \@@_backend_structure_destination:nnnn
1789 \cs_gset_eq:NN \__pdfannot_backend_link_begin_goto:nnw \__pdfannot_backend_link_begin_structure_goto:nnw
1790 }
1791 \cs_new_protected:Npn \pdf_activate_indexed_structure_destination:
1792 {
1793 \cs_gset_eq:NN \@@_backend_destination:nn \@@_backend_indexed_structure_destination:nn
1794 \cs_gset_eq:NN \@@_backend_destination:nnnn \@@_backend_indexed_structure_destination:nnnn
1795 \cs_gset_eq:NN \__pdfannot_backend_link_begin_goto:nnw \__pdfannot_backend_link_begin_structure_goto:nnw
1796 }
1797 %</drivers>
1798 % \end{macrocode}
1799 % \end{macro}
1800 % Now the driver dependent parts.
1801 % By default the new commands are simply copies of the original commands.
1802 % We adapt them then for the engines and engine version which provide support
1803 % for structure destinations.
1804 %
1805 % \begin{macrocode}
1806 %<*drivers>
1807 \cs_set_eq:NN \@@_backend_structure_destination:nn \@@_backend_destination:nn
1808 \cs_set_eq:NN \@@_backend_structure_destination:nnnn \@@_backend_destination:nnnn
1809 \cs_set_eq:NN \__pdfannot_backend_link_begin_structure_goto:nnw \__pdfannot_backend_link_begin_goto:nnw
1810 \cs_set_eq:NN \@@_backend_indexed_structure_destination:nn \@@_backend_destination:nn
1811 \cs_set_eq:NN \@@_backend_indexed_structure_destination:nnnn \@@_backend_destination:nnnn
1812 %</drivers>
1813 % \end{macrocode}
1814 % \begin{macro}{\@@_backend_structure_destination:nn,
1815 % \@@_backend_structure_destination:nnnn,
1816 % \__pdfannot_backend_link_begin_structure_goto:nnw}
1817 % These commands are the backend commands to create a destination.
1818 % which create also a structure destination.
1819 % At first xetex/dvipdfmx.
1820 % The structure destination is an array, so we use obj for it
1821 % so that we can reference it:
1822 % \begin{macrocode}
1823 %<*xdvipdfmx|dvipdfmx>
1824 \cs_set_protected:Npn \@@_backend_structure_destination:nn #1#2
1825 {
1826 \@@_backend:e
1827 {
1828 dest ~ ( \exp_not:n {#1} )
1829 [
1830 @thispage
1831 \str_case:nnF {#2}
1832 {
1833 { xyz } { /XYZ ~ @xpos ~ @ypos ~ null }
1834 { fit } { /Fit }
1835 { fitb } { /FitB }
1836 { fitbh } { /FitBH }
1837 { fitbv } { /FitBV ~ @xpos }
1838 { fith } { /FitH ~ @ypos }
1839 { fitv } { /FitV ~ @xpos }
1840 { fitr } { /Fit }
1841 }
1842 { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
1843 ]
1844 }
1845 % \end{macrocode}
1846 % We test if the structure object exist. The object of the structure destination
1847 % gets the name \texttt{@pdf.Sdest.\meta{destname}}, where \meta{destname} is the
1848 % name of the standard destination so that we can reference it in the GoTo links.
1849 % \begin{macrocode}
1850 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
1851 {
1852 \@@_backend:e
1853 {
1854 obj ~ @pdf.SDest.\exp_not:n{#1}
1855 [
1856 \exp_args:Ne \pdf_object_ref:n { \l_pdf_current_structure_destination_tl }
1857 \str_case:nnF {#2}
1858 {
1859 { xyz } { /XYZ ~ @xpos ~ @ypos ~ null }
1860 { fit } { /Fit }
1861 { fitb } { /FitB }
1862 { fitbh } { /FitBH }
1863 { fitbv } { /FitBV ~ @xpos }
1864 { fith } { /FitH ~ @ypos }
1865 { fitv } { /FitV ~ @xpos }
1866 { fitr } { /Fit }
1867 }
1868 { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
1869 ]
1870 }
1871 }
1872 }
1873 % \end{macrocode}
1874 % The second destination command is for the boxed destination. Here we need to define
1875 % an new auxiliary command:
1876 % \begin{macrocode}
1877 \cs_new_protected:Npn \@@_backend_structure_destination_aux:nnnn #1#2#3#4
1878 {
1879 \vbox_to_zero:n
1880 {
1881 \__kernel_kern:n {#4}
1882 \hbox:n
1883 {
1884 \@@_backend:n { obj ~ @pdf_ #2 _llx ~ @xpos }
1885 \@@_backend:n { obj ~ @pdf_ #2 _lly ~ @ypos }
1886 }
1887 \tex_vss:D
1888 }
1889 \__kernel_kern:n {#1}
1890 \vbox_to_zero:n
1891 {
1892 \__kernel_kern:n { -#3 }
1893 \hbox:n
1894 {
1895 \@@_backend:n
1896 {
1897 dest ~ (#2)
1898 [
1899 @thispage
1900 /FitR ~
1901 @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
1902 @xpos ~ @ypos
1903 ]
1904 }
1905 % \end{macrocode}
1906 % Here we add the structure destination to the same box
1907 % \begin{macrocode}
1908 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
1909 {
1910 \@@_backend:e
1911 {
1912 obj ~ @pdf.SDest.\exp_not:n{#2}
1913 [
1914 \exp_args:Ne \pdf_object_ref:n { \l_pdf_current_structure_destination_tl }
1915 /FitR ~
1916 @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
1917 @xpos ~ @ypos
1918 ]
1919 }
1920 }
1921 }
1922 \tex_vss:D
1923 }
1924 \__kernel_kern:n { -#1 }
1925 }
1926 % \end{macrocode}
1927 % And now we redefine the destination command:
1928 % \begin{macrocode}
1929 \cs_set_protected:Npn \@@_backend_structure_destination:nnnn #1#2#3#4
1930 {
1931 \exp_args:Ne \@@_backend_structure_destination_aux:nnnn
1932 { \dim_eval:n {#2} } {#1} {#3} {#4}
1933 }
1934 % \end{macrocode}
1935 % At last the goto link.
1936 % \begin{macrocode}
1937 \cs_set_protected:Npn \__pdfannot_backend_link_begin_structure_goto:nnw #1#2
1938 {
1939 \__pdfannot_backend_link_begin:n { #1 /Subtype /Link /A << /S /GoTo /D ( #2 ) /[email protected].#2 >> }
1940 }
1941 %</xdvipdfmx|dvipdfmx>
1942 % \end{macrocode}
1943 % Now pdftex. We only redefine for version 1.40 revision 24 or later.
1944 % \begin{macrocode}
1945 %<*pdftex>
1946 \bool_lazy_and:nnT
1947 { \int_compare_p:nNn {\tex_pdftexversion:D } > {139} }
1948 { \int_compare_p:nNn {\tex_pdftexrevision:D } > {23} }
1949 {
1950 \cs_set_protected:Npn \@@_backend_structure_destination:nn #1#2
1951 {
1952 \tex_pdfdest:D
1953 name {#1}
1954 \str_case:nnF {#2}
1955 {
1956 { xyz } { xyz }
1957 { fit } { fit }
1958 { fitb } { fitb }
1959 { fitbh } { fitbh }
1960 { fitbv } { fitbv }
1961 { fith } { fith }
1962 { fitv } { fitv }
1963 { fitr } { fitr }
1964 }
1965 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
1966 \scan_stop:
1967 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
1968 {
1969 \tex_pdfdest:D
1970 struct~
1971 \int_use:c
1972 { c_@@_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
1973 name {#1}
1974 \str_case:nnF {#2}
1975 {
1976 { xyz } { xyz }
1977 { fit } { fit }
1978 { fitb } { fitb }
1979 { fitbh } { fitbh }
1980 { fitbv } { fitbv }
1981 { fith } { fith }
1982 { fitv } { fitv }
1983 { fitr } { fitr }
1984 }
1985 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
1986 \scan_stop:
1987 }
1988 }
1989 \cs_set_protected:Npn \@@_backend_structure_destination:nnnn #1#2#3#4
1990 {
1991 \tex_pdfdest:D
1992 name {#1}
1993 fitr ~
1994 width \dim_eval:n {#2} ~
1995 height \dim_eval:n {#3} ~
1996 depth \dim_eval:n {#4} \scan_stop:
1997 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
1998 {
1999 \tex_pdfdest:D
2000 struct~
2001 \int_use:c
2002 { c_@@_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
2003 name {#1}
2004 fitr ~
2005 width \dim_eval:n {#2} ~
2006 height \dim_eval:n {#3} ~
2007 depth \dim_eval:n {#4} \scan_stop:
2008 }
2009 }
2010 \cs_set_protected:Npn \__pdfannot_backend_link_begin_structure_goto:nnw #1#2
2011 {
2012 \__pdfannot_backend_link_begin:nnnw {#1} { goto~struct~name~{#2}~name } {#2}
2013 }
2014 }
2015 %</pdftex>
2016 % \end{macrocode}
2017 % luatex is quite similar to pdftex. Mostly the test for the version is different
2018 % \begin{macrocode}
2019 %<*luatex>
2020 \int_compare:nNnT {\directlua{tex.print(status.list()["development_id"])} } > {7468}
2021 {
2022 \cs_set_protected:Npn \@@_backend_structure_destination:nn #1#2
2023 {
2024 \tex_pdfextension:D dest
2025 name {#1}
2026 \str_case:nnF {#2}
2027 {
2028 { xyz } { xyz }
2029 { fit } { fit }
2030 { fitb } { fitb }
2031 { fitbh } { fitbh }
2032 { fitbv } { fitbv }
2033 { fith } { fith }
2034 { fitv } { fitv }
2035 { fitr } { fitr }
2036 }
2037 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2038 \scan_stop:
2039 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
2040 {
2041 \tex_pdfextension:D dest
2042 struct~
2043 \int_use:c
2044 { c_@@_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
2045 name {#1}
2046 \str_case:nnF {#2}
2047 {
2048 { xyz } { xyz }
2049 { fit } { fit }
2050 { fitb } { fitb }
2051 { fitbh } { fitbh }
2052 { fitbv } { fitbv }
2053 { fith } { fith }
2054 { fitv } { fitv }
2055 { fitr } { fitr }
2056 }
2057 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2058 \scan_stop:
2059 }
2060 }
2061 \cs_set_protected:Npn \@@_backend_structure_destination:nnnn #1#2#3#4
2062 {
2063 \tex_pdfextension:D dest
2064 name {#1}
2065 fitr ~
2066 width \dim_eval:n {#2} ~
2067 height \dim_eval:n {#3} ~
2068 depth \dim_eval:n {#4} \scan_stop:
2069 \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
2070 {
2071 \tex_pdfextension:D dest
2072 struct~
2073 \int_use:c
2074 { c_@@_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
2075 name {#1}
2076 fitr ~
2077 width \dim_eval:n {#2} ~
2078 height \dim_eval:n {#3} ~
2079 depth \dim_eval:n {#4} \scan_stop:
2080 }
2081 }
2082 \cs_set_protected:Npn \__pdfannot_backend_link_begin_structure_goto:nnw #1#2
2083 {
2084 \__pdfannot_backend_link_begin:nnnw {#1} { goto~struct~name~{#2}~name } {#2}
2085 }
2086 }
2087 %</luatex>
2088 % \end{macrocode}
2089 % \end{macro}
2090 %
2091 % \begin{macro}{\@@_backend_indexed_structure_destination:nn,
2092 % \@@_backend_indexed_structure_destination:nnnn}
2093 % This are the indexed variants of the commands to create a destination
2094 % and a structure destination.
2095 % At first xetex/dvipdfmx.
2096 % The structure destination is an array, so we use obj for it
2097 % so that we can reference it:
2098 % \begin{macrocode}
2099 %<*xdvipdfmx|dvipdfmx>
2100 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nn #1#2
2101 {
2102 \@@_backend:e
2103 {
2104 dest ~ ( \exp_not:n {#1} )
2105 [
2106 @thispage
2107 \str_case:nnF {#2}
2108 {
2109 { xyz } { /XYZ ~ @xpos ~ @ypos ~ null }
2110 { fit } { /Fit }
2111 { fitb } { /FitB }
2112 { fitbh } { /FitBH }
2113 { fitbv } { /FitBV ~ @xpos }
2114 { fith } { /FitH ~ @ypos }
2115 { fitv } { /FitV ~ @xpos }
2116 { fitr } { /Fit }
2117 }
2118 { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
2119 ]
2120 }
2121 % \end{macrocode}
2122 % We do not test anymore if the structure object exist. The object of the structure destination
2123 % gets the name \texttt{@pdf.Sdest.\meta{destname}}, where \meta{destname} is the
2124 % name of the standard destination so that we can reference it in the GoTo links.
2125 % \begin{macrocode}
2126 \@@_backend:e
2127 {
2128 obj ~ @pdf.SDest.\exp_not:n{#1}
2129 [
2130 \exp_after:wN \pdf_object_ref_indexed:nn \l_pdf_current_structure_destination_tl
2131 \str_case:nnF {#2}
2132 {
2133 { xyz } { /XYZ ~ @xpos ~ @ypos ~ null }
2134 { fit } { /Fit }
2135 { fitb } { /FitB }
2136 { fitbh } { /FitBH }
2137 { fitbv } { /FitBV ~ @xpos }
2138 { fith } { /FitH ~ @ypos }
2139 { fitv } { /FitV ~ @xpos }
2140 { fitr } { /Fit }
2141 }
2142 { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
2143 ]
2144 }
2145 }
2146 % \end{macrocode}
2147 %
2148 % The second destination command is for the boxed destination. Here we need to define
2149 % an new auxiliary command:
2150 % \begin{macrocode}
2151 \cs_new_protected:Npn \@@_backend_indexed_structure_destination_aux:nnnn #1#2#3#4
2152 {
2153 \vbox_to_zero:n
2154 {
2155 \__kernel_kern:n {#4}
2156 \hbox:n
2157 {
2158 \@@_backend:n { obj ~ @pdf_ #2 _llx ~ @xpos }
2159 \@@_backend:n { obj ~ @pdf_ #2 _lly ~ @ypos }
2160 }
2161 \tex_vss:D
2162 }
2163 \__kernel_kern:n {#1}
2164 \vbox_to_zero:n
2165 {
2166 \__kernel_kern:n { -#3 }
2167 \hbox:n
2168 {
2169 \@@_backend:n
2170 {
2171 dest ~ (#2)
2172 [
2173 @thispage
2174 /FitR ~
2175 @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
2176 @xpos ~ @ypos
2177 ]
2178 }
2179 % \end{macrocode}
2180 % Here we add the structure destination to the same box
2181 % \begin{macrocode}
2182 \@@_backend:e
2183 {
2184 obj ~ @pdf.SDest.\exp_not:n{#2}
2185 [
2186 \exp_after:wN \pdf_object_ref_indexed:nn \l_pdf_current_structure_destination_tl
2187 /FitR ~
2188 @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
2189 @xpos ~ @ypos
2190 ]
2191 }
2192 }
2193 \tex_vss:D
2194 }
2195 \__kernel_kern:n { -#1 }
2196 }
2197 % \end{macrocode}
2198 % And now we redefine the destination command:
2199 % \begin{macrocode}
2200 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nnnn #1#2#3#4
2201 {
2202 \exp_args:Ne \@@_backend_indexed_structure_destination_aux:nnnn
2203 { \dim_eval:n {#2} } {#1} {#3} {#4}
2204 }
2205 %</xdvipdfmx|dvipdfmx>
2206 % \end{macrocode}
2207 %
2208 % Now pdftex. We only redefine for version 1.40 revision 24 or later.
2209 % \begin{macrocode}
2210 %<*pdftex>
2211 \bool_lazy_and:nnT
2212 { \int_compare_p:nNn {\tex_pdftexversion:D } > {139} }
2213 { \int_compare_p:nNn {\tex_pdftexrevision:D } > {23} }
2214 {
2215 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nn #1#2
2216 {
2217 \tex_pdfdest:D
2218 name {#1}
2219 \str_case:nnF {#2}
2220 {
2221 { xyz } { xyz }
2222 { fit } { fit }
2223 { fitb } { fitb }
2224 { fitbh } { fitbh }
2225 { fitbv } { fitbv }
2226 { fith } { fith }
2227 { fitv } { fitv }
2228 { fitr } { fitr }
2229 }
2230 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2231 \scan_stop:
2232 \tex_pdfdest:D
2233 struct~
2234 \exp_after:wN \__kernel_pdf_object_id_indexed:nn \l_pdf_current_structure_destination_tl ~
2235 name {#1}
2236 \str_case:nnF {#2}
2237 {
2238 { xyz } { xyz }
2239 { fit } { fit }
2240 { fitb } { fitb }
2241 { fitbh } { fitbh }
2242 { fitbv } { fitbv }
2243 { fith } { fith }
2244 { fitv } { fitv }
2245 { fitr } { fitr }
2246 }
2247 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2248 \scan_stop:
2249 }
2250 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nnnn #1#2#3#4
2251 {
2252 \tex_pdfdest:D
2253 name {#1}
2254 fitr ~
2255 width \dim_eval:n {#2} ~
2256 height \dim_eval:n {#3} ~
2257 depth \dim_eval:n {#4} \scan_stop:
2258 \tex_pdfdest:D
2259 struct~
2260 \exp_after:wN \__kernel_pdf_object_id_indexed:nn \l_pdf_current_structure_destination_tl ~
2261 name {#1}
2262 fitr ~
2263 width \dim_eval:n {#2} ~
2264 height \dim_eval:n {#3} ~
2265 depth \dim_eval:n {#4} \scan_stop:
2266 }
2267 }
2268 %</pdftex>
2269 % \end{macrocode}
2270 % luatex is quite similar to pdftex. Mostly the test for the version is different
2271 % \begin{macrocode}
2272 %<*luatex>
2273 \int_compare:nNnT {\directlua{tex.print(status.list()["development_id"])} } > {7468}
2274 {
2275 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nn #1#2
2276 {
2277 \tex_pdfextension:D dest
2278 name {#1}
2279 \str_case:nnF {#2}
2280 {
2281 { xyz } { xyz }
2282 { fit } { fit }
2283 { fitb } { fitb }
2284 { fitbh } { fitbh }
2285 { fitbv } { fitbv }
2286 { fith } { fith }
2287 { fitv } { fitv }
2288 { fitr } { fitr }
2289 }
2290 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2291 \scan_stop:
2292 \tex_pdfextension:D dest
2293 struct~
2294 \exp_after:wN \__kernel_pdf_object_id_indexed:nn \l_pdf_current_structure_destination_tl ~
2295 name {#1}
2296 \str_case:nnF {#2}
2297 {
2298 { xyz } { xyz }
2299 { fit } { fit }
2300 { fitb } { fitb }
2301 { fitbh } { fitbh }
2302 { fitbv } { fitbv }
2303 { fith } { fith }
2304 { fitv } { fitv }
2305 { fitr } { fitr }
2306 }
2307 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
2308 \scan_stop:
2309 }
2310 \cs_set_protected:Npn \@@_backend_indexed_structure_destination:nnnn #1#2#3#4
2311 {
2312 \tex_pdfextension:D dest
2313 name {#1}
2314 fitr ~
2315 width \dim_eval:n {#2} ~
2316 height \dim_eval:n {#3} ~
2317 depth \dim_eval:n {#4} \scan_stop:
2318 \tex_pdfextension:D dest
2319 struct~
2320 \exp_after:wN \__kernel_pdf_object_id_indexed:nn \l_pdf_current_structure_destination_tl~
2321 name {#1}
2322 fitr ~
2323 width \dim_eval:n {#2} ~
2324 height \dim_eval:n {#3} ~
2325 depth \dim_eval:n {#4} \scan_stop:
2326 }
2327 \cs_set_protected:Npn \__pdfannot_backend_link_begin_structure_goto:nnw #1#2
2328 {
2329 \__pdfannot_backend_link_begin:nnnw {#1} { goto~struct~name~{#2}~name } {#2}
2330 }
2331 }
2332 %</luatex>
2333 % \end{macrocode}
2334 % \end{macro}
2335 % \subsection{Settings for regression tests}
2336 % When doing pdf based regression tests some meta data in the pdf should have
2337 % fixed values to get identical pdf's. We define here the backend dependent
2338 % part. The main command is then in l3pdfmeta
2339 % \begin{macrocode}
2340 %<*drivers>
2341 \cs_new_protected:Npn \@@_backend_set_regression_data:
2342 {
2343 \sys_gset_rand_seed:n{1000}
2344 \pdfmanagement_add:nnn{Info}{Creator}{(TeX)}
2345 %</drivers>
2346 %<*dvips>
2347 \AddToHook{begindocument}{\pdfmanagement_add:nnn{Info}{Producer}{(pdfTeX+dvips)}}
2348 \__kernel_backend_literal:e{!~<</DocumentUUID~(DocumentUUID)>>~setpagedevice}
2349 \__kernel_backend_literal:e{!~<</InstanceUUID~(InstanceUUID)>>~setpagedevice}
2350 \pdfmanagement_add:nne{Info}{CreationDate}{(\c_sys_timestamp_str)}
2351 \pdfmanagement_add:nne{Info}{ModDate}{(\c_sys_timestamp_str)}
2352 %</dvips>
2353 %<*dvipdfmx>
2354 \pdfmanagement_add:nnn{Info}{Producer}{(dvipdfmx)}
2355 \__kernel_backend_literal:e
2356 {pdf:trailerid [~
2357 <00112233445566778899aabbccddeeff>~
2358 <00112233445566778899aabbccddeeff>~
2359 ]}
2360 %</dvipdfmx>
2361 %<*xdvipdfmx>
2362 \pdfmanagement_add:nnn{Info}{Producer}{(xetex)}
2363 \__kernel_backend_literal:e
2364 {pdf:trailerid [~
2365 <00112233445566778899aabbccddeeff>~
2366 <00112233445566778899aabbccddeeff>~
2367 ]}
2368 %</xdvipdfmx>
2369 %<*pdftex>
2370 \pdfmanagement_add:nnn{Info}{Producer}{(pdfTeX)}
2371 \tex_pdfsuppressptexinfo:D 7 \scan_stop:
2372 \pdftrailerid{2350CAD05F8A7AF0AA4058486855344F}
2373 %</pdftex>
2374 %<*luatex>
2375 \pdfmanagement_add:nnn{Info}{Producer}{(LuaTeX)}
2376 \tex_pdfvariable:D suppressoptionalinfo 7\relax
2377 \tex_pdfvariable:D trailerid
2378 {[~
2379 <2350CAD05F8A7AF0AA4058486855344F>~
2380 <2350CAD05F8A7AF0AA4058486855344F>~
2381 ]}
2382 %</luatex>
2383 % \end{macrocode}
2384 % Embedded files should also have a fix date.
2385 % \begin{macrocode}
2386 %<*drivers>
2387 \pdfdict_put:nne {l_pdffile/Params} {ModDate}{(\c_sys_timestamp_str)}
2388 \AddToDocumentProperties[hyperref]{pdfinstanceid}{uuid:0a57c455-157a-4141-8c19-6237d832fc80}
2389 \AddToDocumentProperties[hyperref]{pdfproducer}{\c_sys_engine_exec_str-NN.NN.NN}
2390 }
2391 %</drivers>
2392 % \end{macrocode}
2393 %
2394 % \subsection{Uncompressed metadata object stream}
2395 % The xmp metadata should be written \enquote{uncompressed} to pdf.
2396 % It is not quite clear what exactly that means. Probably it only
2397 % means that there should be no |/Filter| key in the stream, but
2398 % packages like \pkg{pdfx} and \pkg{hyperref} try to suppress object
2399 % compression too, so we add support for it too.
2400 % With luatex this is possible by using the |uncompressed| key word.
2401 % With pdftex one can change locally the compresslevel. (x)dvipdfmx does
2402 % it automatically and doesn't need some special command. No solution
2403 % is known for the dvips route. We need it only once, so we make
2404 % it special and probably no public interface is needed. It writes
2405 % the |__pdfmeta/xmp| object which should be declared before.
2406 %
2407 % luatex has of now (2025-11-12) a bug: using the |uncompressed| key disables
2408 % object compression for all following objects. We therefor delay the writing
2409 % into the |enddocument/end| hook after the tagpdf code.
2410 %
2411 % \begin{macrocode}
2412 %<*luatex>
2413 \cs_new_protected:Npn \@@_backend_metadata_stream:n #1
2414 {
2415 \AddToHook{enddocument/end}
2416 {
2417 \tex_immediate:D \tex_pdfextension:D obj ~
2418 useobjnum ~ \int_eval:n{\@@_object_retrieve:n {__pdfmeta/xmp}}~uncompressed~
2419 \@@_backend_object_write:nn {stream}
2420 {{/Type~/Metadata~/Subtype~/XML}{#1}}
2421 }
2422 }
2423 %</luatex>
2424 %<*pdftex>
2425 \cs_new_protected:Npn \@@_backend_metadata_stream:n #1
2426 {
2427 \group_begin:
2428 \tex_pdfcompresslevel:D 0 \scan_stop:
2429 \tex_immediate:D \tex_pdfobj:D useobjnum ~ \int_eval:n{\@@_object_retrieve:n
2430 {__pdfmeta/xmp}}~
2431 \@@_backend_object_write:nn {stream} {{/Type~/Metadata~/Subtype~/XML}{#1}}
2432 \group_end:
2433 }
2434 %</pdftex>
2435 %<*xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2436 \cs_new_protected:Npn \@@_backend_metadata_stream:n #1
2437 {
2438 \pdf_object_write:nnn{__pdfmeta/xmp} {stream}{{/Type~/Metadata~/Subtype~/XML}{#1}}
2439 }
2440 %</xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2441 % \end{macrocode}
2442 %
2443 % \subsection{Suppressing deprecated PDF features}
2444 %
2445 % \texttt{/ProcSet}, \texttt{/CharSet} and the \texttt{/Info} dictionary
2446 % are deprecated in PDF 2.0. For the pdf/A-4 standard they must be suppressed.
2447 % Not every engine is able to do this, but for pdfTeX and luatex we define suitable
2448 % backend command. \texttt{/ProcSet} is suppressed automatically
2449 % for pdf version 2.0 starting with in texlive 2023.
2450 % \begin{macro}{\@@_backend_omit_charset:n}
2451 % The option to omit /Charset exists already for quite some time for the two
2452 % engines.
2453 % \begin{macrocode}
2454 %<*xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2455 \cs_new_protected:Npn \@@_backend_omit_charset:n #1 {} %#1 number
2456 %</xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2457 %<*pdftex>
2458 \cs_new_protected:Npn \@@_backend_omit_charset:n #1 %#1 number
2459 {
2460 \tex_pdfomitcharset:D = #1 \scan_stop:
2461 }
2462 %</pdftex>
2463 %<*luatex>
2464 \cs_new_protected:Npn \@@_backend_omit_charset:n #1 %#1 number
2465 {
2466 \tex_pdfvariable:D omitcharset = #1 \scan_stop:
2467 }
2468 %</luatex>
2469 % \end{macrocode}
2470 % \end{macro}
2471 %
2472 % \begin{macro}{\@@_backend_omit_info:n}
2473 % The option to suppress the info dictionary will be available in
2474 % texlive 2023.
2475 % \begin{macrocode}
2476 %<*xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2477 \cs_new_protected:Npn \@@_backend_omit_info:n #1 {} %#1 number
2478 %</xdvipdfmx|dvipdfmx|dvips|dvisvgm>
2479 %<*pdftex>
2480 \bool_lazy_and:nnTF
2481 { \int_compare_p:nNn {\tex_pdftexversion:D } > {139} }
2482 { \int_compare_p:nNn {\tex_pdftexrevision:D } > {24} }
2483 {
2484 \cs_new_protected:Npn \@@_backend_omit_info:n #1 %#1 number
2485 {
2486 \pdfomitinfodict = #1 \scan_stop:
2487 }
2488 }
2489 {
2490 \cs_new_protected:Npn \@@_backend_omit_info:n #1 {}%#1 number
2491
2492 }
2493 %</pdftex>
2494 %<*luatex>
2495 \int_compare:nNnTF {\directlua{tex.print(status.list()["development_id"])} } > {7560}
2496 {
2497 \cs_new_protected:Npn \@@_backend_omit_info:n #1 %#1 number
2498 {
2499 \tex_pdfvariable:D omitinfodict = #1 \scan_stop:
2500 }
2501 }
2502 {
2503 \cs_new_protected:Npn \@@_backend_omit_info:n #1 {} %#1 number
2504 }
2505 %</luatex>
2506 % \end{macrocode}
2507 % \end{macro}
2508 %
2509 % With luatex it is for some standards also necessary to suppress the CidSet
2510 % entry in the fonts (with xetex there seem to be no problem.
2511 % \begin{macro}{\@@_backend_omit_cidset:n}
2512 % The option to omit /Charset exists already for quite some time for the two
2513 % engines.
2514 % \begin{macrocode}
2515 %<*xdvipdfmx|dvipdfmx|dvips|dvisvgm|pdftex>
2516 \cs_new_protected:Npn \@@_backend_omit_cidset:n #1 {} %#1 number
2517 %</xdvipdfmx|dvipdfmx|dvips|dvisvgm|pdftex>
2518 %<*luatex>
2519 \cs_new_protected:Npn \@@_backend_omit_cidset:n #1 %#1 number
2520 {
2521 \tex_pdfvariable:D omitcidset = #1 \scan_stop:
2522 }
2523 %</luatex>
2524 % \end{macrocode}
2525 % \end{macro}
2526 %
2527 % \subsection{Outline backend}
2528 % \begin{macrocode}
2529 %<*dvips>
2530 \cs_new_protected:Npn \@@_backend_action:nnnnnnn #1#2#3#4#5#6#7
2531 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 action, #7 title,
2532 {
2533 \@@_backend_pdfmark:e
2534 {
2535 /Title~(\exp_not:n{#7})~
2536 /Count~\bool_if:nF{#3}{-}#2~
2537 \tl_if_blank:nF { #4 }{/C~[#4]}
2538 /F~#5
2539 /Action <<\exp_not:n{#6}>>
2540 /OUT
2541 }
2542 }
2543 \cs_new_protected:Npn \@@_backend_goto:nnnnnnn #1#2#3#4#5#6#7
2544 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 action, #7 title,
2545 {
2546 \@@_backend_pdfmark:e
2547 {
2548 /Title~(\exp_not:n{#7})~
2549 /Count~\bool_if:nF{#3}{-}#2~
2550 \tl_if_blank:nF { #4 }{/C~[#4]}
2551 /F~#5
2552 /Action/GoTo/Dest(\exp_not:n{#6})~cvn
2553 /OUT
2554 }
2555 }
2556 %</dvips>
2557 %<*pdftex>
2558 \cs_new_protected:Npn \@@_backend_action:nnnnnnn #1#2#3#4#5#6#7
2559 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 action, #7 title,
2560 {
2561 \tex_pdfoutline:D~attr
2562 {
2563 /F~#5~
2564 \tl_if_blank:nF { #4 }{/C~[#4]}
2565 }~
2566 user~{<<\exp_not:n{#6}>>}~
2567 count~\bool_if:nF{#3}{-}#2~
2568 {\exp_not:n{#7}}
2569 }
2570 \cs_new_protected:Npn \@@_backend_goto:nnnnnnn #1#2#3#4#5#6#7
2571 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 destination, #7 title,
2572 {
2573 \tex_pdfoutline:D~attr
2574 {
2575 /F~#5~
2576 \tl_if_blank:nF { #4 }{/C~[#4]}
2577 }~
2578 \tag_if_active:TF
2579 {goto~struct~name~{#6}~name~{#6}}
2580 {goto~name~{#6}}~
2581 count~\bool_if:nF{#3}{-}#2~
2582 {\exp_not:n{#7}}
2583 }
2584 %</pdftex>
2585 %<*luatex>
2586 \cs_new_protected:Npn \@@_backend_action:nnnnnnn #1#2#3#4#5#6#7
2587 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 action, #7 title,
2588 {
2589 \tex_pdfextension:D~outline~attr
2590 {
2591 /F~#5~
2592 \tl_if_blank:nF { #4 }{/C~[#4]}
2593 }~
2594 user~{<<\exp_not:n{#6}>>}~
2595 count~\bool_if:nF{#3}{-}#2~
2596 {\exp_not:n{#7}}
2597 }
2598 \cs_new_protected:Npn \@@_backend_goto:nnnnnnn #1#2#3#4#5#6#7
2599 % #1 level (ignored), #2 kid count, #3 open? #4 color (space separated values), #5 flag, #6 destination, #7 title,
2600 {
2601 \tex_pdfextension:D~outline~attr
2602 {
2603 /F~#5~
2604 \tl_if_blank:nF { #4 }{/Color~[#4]}
2605 }~
2606 \tag_if_active:TF
2607 {goto~struct~name~{#6}~name~{#6}}
2608 {goto~name~{#6}}~
2609 count~\bool_if:nF{#3}{-}#2~
2610 {\exp_not:n{#7}}
2611 }
2612 %</luatex>
2613 %<*xdvipdfmx|dvipdfmx>
2614 \cs_new_protected:Npn \@@_backend_action:nnnnnnn #1#2#3#4#5#6#7
2615 % #1 level, #2 kid count (ignored), #3 open? #4 color (space separated values), #5 flag, #6 action, #7 title,
2616 {
2617 \tex_special:D
2618 {
2619 pdf:out~
2620 [\bool_if:nF{#3}{-}]~#1~
2621 <<
2622 /A<<\exp_not:n{#6}>>~
2623 /Title~(\exp_not:n{#7})~
2624 /F~#5~
2625 \tl_if_blank:nF { #4 }{/C~[#4]}
2626 >>
2627 }
2628 }
2629 \cs_new_protected:Npn \@@_backend_goto:nnnnnnn #1#2#3#4#5#6#7
2630 % #1 level, #2 kid count (ignored), #3 open? #4 color (space separated values), #5 flag, #6 destination, #7 title,
2631 {
2632 \tex_special:D
2633 {
2634 pdf:out~
2635 [\bool_if:nF{#3}{-}]~#1~
2636 <<
2637 /A
2638 <<
2639 /S/GoTo/D(\exp_not:n{#6})
2640 \tag_if_active:T
2641 {
2642 /[email protected].#6
2643 }
2644 >>~
2645 /Title~(\exp_not:n{#7})~
2646 /F~#5~
2647 \tl_if_blank:nF { #4 }{/C~[#4]}
2648 >>
2649 }
2650 }
2651 %</xdvipdfmx|dvipdfmx>
2652 %<*dvisvgm>
2653 \cs_new_protected:Npn \@@_backend_action:nnnnnnn #1#2#3#4#5#6#7{}
2654 \cs_new_protected:Npn \@@_backend_goto:nnnnnnn #1#2#3#4#5#6#7 {}
2655 %</dvisvgm>
2656 % \end{macrocode}
2657 % \subsection{lua code for lualatex}
2658 % \begin{macrocode}
2659 %<*lua>
2660 ltx= ltx or {}
2661 ltx.@@ = ltx.@@ or {}
2662 ltx.@@.Page = ltx.@@.Page or {}
2663 ltx.@@.Page.dflt = ltx.@@.Page.dflt or {}
2664 ltx.@@.Page.Resources = ltx.@@.Resources or {}
2665 ltx.@@.Page.Resources.Properties = ltx.@@.Page.Resources.Properties or {}
2666 ltx.@@.Page.Resources.List={"ExtGState","ColorSpace","Pattern","Shading"}
2667 ltx.@@.object = ltx.@@.object or {}
2668
2669 ltx.pdf= ltx.pdf or {} -- for "public" functions
2670
2671 local @@ = ltx.@@
2672 local pdf = pdf
2673
2674 local function @@_backend_Page_gput (name,value)
2675 @@.Page.dflt[name]=value
2676 end
2677
2678 local function @@_backend_Page_gremove (name)
2679 @@.Page.dflt[name]=nil
2680 end
2681
2682 local function @@_backend_Page_gclear ()
2683 @@.Page.dflt={}
2684 end
2685
2686 local function @@_backend_ThisPage_gput (page,name,value)
2687 @@.Page[page] = @@.Page[page] or {}
2688 @@.Page[page][name]=value
2689 end
2690
2691 local function @@_backend_ThisPage_gpush (page)
2692 local token=""
2693 local t = {}
2694 local tkeys= {}
2695 for name,value in pairs(@@.Page.dflt) do
2696 t[name]=value
2697 end
2698 if @@.Page[page] then
2699 for name,value in pairs(@@.Page[page]) do
2700 t[name] = value
2701 end
2702 end
2703 -- sort the table to get reliable test files.
2704 for name,value in pairs(t) do
2705 table.insert(tkeys,name)
2706 end
2707 table.sort(tkeys)
2708 for _,name in ipairs(tkeys) do
2709 token = token .. "/"..name.." "..t[name]
2710 end
2711 return token
2712 end
2713
2714 function ltx.@@.backend_ThisPage_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
2715 @@_backend_ThisPage_gput (page,name,value)
2716 end
2717
2718 function ltx.@@.backend_ThisPage_gpush (page)
2719 pdf.setpageattributes(@@_backend_ThisPage_gpush (page))
2720 end
2721
2722 function ltx.@@.backend_Page_gput (name,value)
2723 @@_backend_Page_gput (name,value)
2724 end
2725
2726 function ltx.@@.backend_Page_gremove (name)
2727 @@_backend_Page_gremove (name)
2728 end
2729
2730 function ltx.@@.backend_Page_gclear ()
2731 @@_backend_Page_gclear ()
2732 end
2733
2734
2735 local Properties = ltx.@@.Page.Resources.Properties
2736 local ResourceList= ltx.@@.Page.Resources.List
2737 local function @@_backend_PageResources_gpush (page)
2738 local token=""
2739 if Properties[page] then
2740 -- we sort the table, so that the pdf test works
2741 local t = {}
2742 for name,value in pairs (Properties[page]) do
2743 table.insert (t,name)
2744 end
2745 table.sort (t)
2746 for _,name in ipairs(t) do
2747 token = token .. "/"..name.." ".. Properties[page][name]
2748 end
2749 token = "/Properties <<"..token..">>"
2750 end
2751 for i,name in ipairs(ResourceList) do
2752 if ltx.@@.Page.Resources[name] then
2753 token = token .. "/"..name.." "..ltx.pdf.object_ref("@@/Page/Resources/"..name)
2754 end
2755 end
2756 return token
2757 end
2758
2759 -- the function is public, as I probably need it in tagpdf too ...
2760 function ltx.pdf.Page_Resources_Properties_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
2761 Properties[page] = Properties[page] or {}
2762 Properties[page][name]=value
2763 pdf.setpageresources(@@_backend_PageResources_gpush (page))
2764 end
2765
2766 function ltx.pdf.Page_Resources_gpush(page)
2767 pdf.setpageresources(@@_backend_PageResources_gpush (page))
2768 end
2769
2770 function ltx.pdf.object_ref (objname)
2771 if ltx.@@.object[objname] then
2772 local ref= ltx.@@.object[objname]
2773 return ref
2774 else
2775 return "false"
2776 end
2777 end
2778 %</lua>
2779 % \end{macrocode}
2780 % \end{implementation}
2781 %
2782 % \PrintIndex