Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3backend-pdf.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 "l3backend 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/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \documentclass[full,kernel]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3backend-pdf} module\\ Backend PDF features^^A
35 % }
36 %
37 % \author{^^A
38 % The \LaTeX{} Project\thanks
39 % {^^A
40 % E-mail:
41 % \href{mailto:[email protected]}
42 % {[email protected]}^^A
43 % }^^A
44 % }
45 %
46 % \date{Released 2026-02-18}
47 %
48 % \maketitle
49 %
50 % \begin{documentation}
51 %
52 % \end{documentation}
53 %
54 % \begin{implementation}
55 %
56 % \section{\pkg{l3backend-pdf} implementation}
57 %
58 % \begin{macrocode}
59 %<*package>
60 %<@@=pdf>
61 % \end{macrocode}
62 %
63 % Setting up PDF resources is a complex area with only limited documentation
64 % in the engine manuals. The following code builds heavily on existing ideas
65 % from \pkg{hyperref} work by Sebastian Rahtz and Heiko Oberdiek, and
66 % significant contributions by Alexander Grahn, in addition to the specific
67 % code referenced a various points.
68 %
69 % \subsection{\texttt{dvips} backend}
70 %
71 % \begin{macrocode}
72 %<*dvips>
73 % \end{macrocode}
74 %
75 % \begin{macro}{\@@_backend_pdfmark:n, \@@_backend_pdfmark:e}
76 % Used often enough it should be a separate function.
77 % \begin{macrocode}
78 \cs_new_protected:Npn \@@_backend_pdfmark:n #1
79 { \__kernel_backend_postscript:n { mark #1 ~ pdfmark } }
80 \cs_generate_variant:Nn \@@_backend_pdfmark:n { e }
81 % \end{macrocode}
82 % \end{macro}
83 %
84 % \subsubsection{Catalogue entries}
85 %
86 % \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
87 % \begin{macrocode}
88 \cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2
89 { \@@_backend_pdfmark:n { { Catalog } << /#1 ~ #2 >> /PUT } }
90 \cs_new_protected:Npn \@@_backend_info_gput:nn #1#2
91 { \@@_backend_pdfmark:n { /#1 ~ #2 /DOCINFO } }
92 % \end{macrocode}
93 % \end{macro}
94 %
95 % \subsubsection{Objects}
96 %
97 % \begin{macro}{\@@_backend_object_new:}
98 % \begin{macro}[EXP]{\@@_backend_object_ref:n, \@@_backend_object_id:n}
99 % \begin{macrocode}
100 \cs_new_protected:Npn \@@_backend_object_new:
101 { \int_gincr:N \g_@@_backend_object_int }
102 \cs_new:Npn \@@_backend_object_ref:n #1 { { pdf.obj #1 } }
103 \cs_new_eq:NN \@@_backend_object_id:n \@@_backend_object_ref:n
104 % \end{macrocode}
105 % \end{macro}
106 % \end{macro}
107 %
108 % \begin{macro}
109 % {
110 % \@@_backend_object_write:nnn, \@@_backend_object_write:nne,
111 % \@@_backend_object_write_aux:nnn
112 % }
113 % \begin{macro}
114 % {
115 % \@@_backend_object_write_array:nn ,
116 % \@@_backend_object_write_dict:nn ,
117 % \@@_backend_object_write_fstream:nn ,
118 % \@@_backend_object_write_stream:nn
119 % }
120 % \begin{macro}{\@@_backend_object_write_stream:nnn}
121 % This is where we choose the actual type: some work to get things
122 % right. To allow code sharing with the anonymous version, we use an
123 % auxiliary.
124 % \begin{macrocode}
125 \cs_new_protected:Npn \@@_backend_object_write:nnn #1#2#3
126 {
127 \@@_backend_object_write_aux:nnn
128 { \@@_backend_object_ref:n {#1} }
129 {#2} {#3}
130 }
131 \cs_generate_variant:Nn \@@_backend_object_write:nnn { nne }
132 \cs_new_protected:Npn \@@_backend_object_write_aux:nnn #1#2#3
133 {
134 \@@_backend_pdfmark:e
135 {
136 /_objdef ~ #1
137 /type
138 \str_case:nn {#2}
139 {
140 { array } { /array }
141 { dict } { /dict }
142 { fstream } { /stream }
143 { stream } { /stream }
144 }
145 /OBJ
146 }
147 \use:c { @@_backend_object_write_ #2 :nn } {#1} {#3}
148 }
149 \cs_new_protected:Npn \@@_backend_object_write_array:nn #1#2
150 {
151 \@@_backend_pdfmark:e
152 { #1 ~0~ [ ~ \exp_not:n {#2} ~ ] ~ /PUTINTERVAL }
153 }
154 \cs_new_protected:Npn \@@_backend_object_write_dict:nn #1#2
155 {
156 \@@_backend_pdfmark:e
157 { #1 << \exp_not:n {#2} >> /PUT }
158 }
159 \cs_new_protected:Npn \@@_backend_object_write_fstream:nn #1#2
160 {
161 \exp_args:Ne
162 \@@_backend_object_write_fstream:nnn {#1} #2
163 }
164 \cs_new_protected:Npn \@@_backend_object_write_fstream:nnn #1#2#3
165 {
166 \__kernel_backend_postscript:n
167 {
168 SDict ~ begin ~
169 mark ~ #1 ~ << #2 >> /PUT ~ pdfmark ~
170 mark ~ #1 ~ ( #3 )~ ( r )~ file ~ /PUT ~ pdfmark ~
171 end
172 }
173 }
174 \cs_new_protected:Npn \@@_backend_object_write_stream:nn #1#2
175 {
176 \exp_args:Ne
177 \@@_backend_object_write_stream:nnn {#1} #2
178 }
179 \cs_new_protected:Npn \@@_backend_object_write_stream:nnn #1#2#3
180 {
181 \__kernel_backend_postscript:n
182 {
183 mark ~ #1 ~ ( #3 ) /PUT ~ pdfmark ~
184 mark ~ #1 ~ << #2 >> /PUT ~ pdfmark
185 }
186 }
187 % \end{macrocode}
188 % \end{macro}
189 % \end{macro}
190 % \end{macro}
191 %
192 % \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:ne}
193 % No anonymous objects, so things are done manually.
194 % \begin{macrocode}
195 \cs_new_protected:Npn \@@_backend_object_now:nn #1#2
196 {
197 \int_gincr:N \g_@@_backend_object_int
198 \@@_backend_object_write_aux:nnn
199 { { pdf.obj \int_use:N \g_@@_backend_object_int } }
200 {#1} {#2}
201 }
202 \cs_generate_variant:Nn \@@_backend_object_now:nn { ne }
203 % \end{macrocode}
204 % \end{macro}
205 %
206 % \begin{macro}[EXP]{\@@_backend_object_last:}
207 % Much like the annotation version.
208 % \begin{macrocode}
209 \cs_new:Npn \@@_backend_object_last:
210 { { pdf.obj \int_use:N \g_@@_backend_object_int } }
211 % \end{macrocode}
212 % \end{macro}
213 %
214 % \begin{macro}[EXP]{\@@_backend_pageobject_ref:n}
215 % Page references are easy in \texttt{dvips}.
216 % \begin{macrocode}
217 \cs_new:Npn \@@_backend_pageobject_ref:n #1
218 { { Page #1 } }
219 % \end{macrocode}
220 % \end{macro}
221 %
222 % \subsubsection{Destinations}
223 %
224 % \begin{macro}{\@@_backend_destination:nn}
225 % \begin{macro}{\@@_backend_destination:nnnn, \@@_backend_destination_aux:nnnn}
226 % Here, we need to turn the zoom into a scale. We also need to know where
227 % the current anchor point actually is: worked out in PostScript. For the
228 % rectangle version, we have a bit more PostScript: we need two points.
229 % fitr without rule spec doesn't work, so it falls back to \texttt{/Fit} here.
230 % \begin{macrocode}
231 \cs_new_protected:Npn \@@_backend_destination:nn #1#2
232 {
233 \__kernel_backend_postscript:n { pdf.dest.anchor }
234 \@@_backend_pdfmark:e
235 {
236 /View
237 [
238 \str_case:nnF {#2}
239 {
240 { xyz } { /XYZ ~ pdf.dest.point ~ null }
241 { fit } { /Fit }
242 { fitb } { /FitB }
243 { fitbh } { /FitBH ~ pdf.dest.y }
244 { fitbv } { /FitBV ~ pdf.dest.x }
245 { fith } { /FitH ~ pdf.dest.y }
246 { fitv } { /FitV ~ pdf.dest.x }
247 { fitr } { /Fit }
248 }
249 {
250 /XYZ ~ pdf.dest.point ~ \fp_eval:n { (#2) / 100 }
251 }
252 ]
253 /Dest ( \exp_not:n {#1} ) cvn
254 /DEST
255 }
256 }
257 \cs_new_protected:Npn \@@_backend_destination:nnnn #1#2#3#4
258 {
259 \exp_args:Ne \@@_backend_destination_aux:nnnn
260 { \dim_eval:n {#2} } {#1} {#3} {#4}
261 }
262 \cs_new_protected:Npn \@@_backend_destination_aux:nnnn #1#2#3#4
263 {
264 \vbox_to_zero:n
265 {
266 \dim_vertical:n {#4}
267 \hbox:n { \__kernel_backend_postscript:n { pdf.save.ll } }
268 \tex_vss:D
269 }
270 \dim_horizontal:n {#1}
271 \vbox_to_zero:n
272 {
273 \dim_vertical:n { -#3 }
274 \hbox:n { \__kernel_backend_postscript:n { pdf.save.ur } }
275 \tex_vss:D
276 }
277 \dim_horizontal:n { -#1 }
278 \@@_backend_pdfmark:n
279 {
280 /View
281 [
282 /FitR ~
283 pdf.llx ~ pdf.lly ~ pdf.dest2device ~
284 pdf.urx ~ pdf.ury ~ pdf.dest2device
285 ]
286 /Dest ( #2 ) cvn
287 /DEST
288 }
289 }
290 % \end{macrocode}
291 % \end{macro}
292 % \end{macro}
293 %
294 % \subsubsection{Structure}
295 %
296 % \begin{macro}{\@@_backend_compresslevel:n}
297 % \begin{macro}{\@@_backend_compress_objects:n}
298 % Doable for the usual \texttt{ps2pdf} method.
299 % \begin{macrocode}
300 \cs_new_protected:Npn \@@_backend_compresslevel:n #1
301 {
302 \int_compare:nNnT {#1} = 0
303 {
304 \__kernel_backend_literal_postscript:n
305 {
306 /setdistillerparams ~ where
307 { pop << /CompressPages ~ false >> setdistillerparams }
308 if
309 }
310 }
311 }
312 \cs_new_protected:Npn \@@_backend_compress_objects:n #1
313 {
314 \bool_if:nF {#1}
315 {
316 \__kernel_backend_literal_postscript:n
317 {
318 /setdistillerparams ~ where
319 { pop << /CompressStreams ~ false >> setdistillerparams }
320 if
321 }
322 }
323 }
324 % \end{macrocode}
325 % \end{macro}
326 % \end{macro}
327 %
328 % \begin{macro}
329 % {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
330 % \begin{macrocode}
331 \cs_new_protected:Npn \@@_backend_version_major_gset:n #1
332 {
333 \cs_gset:Npe \@@_backend_version_major: { \int_eval:n {#1} }
334 }
335 \cs_new_protected:Npn \@@_backend_version_minor_gset:n #1
336 {
337 \cs_gset:Npe \@@_backend_version_minor: { \int_eval:n {#1} }
338 }
339 % \end{macrocode}
340 % \end{macro}
341 %
342 % \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
343 % Data not available!
344 % \begin{macrocode}
345 \cs_new:Npn \@@_backend_version_major: { -1 }
346 \cs_new:Npn \@@_backend_version_minor: { -1 }
347 % \end{macrocode}
348 % \end{macro}
349 %
350 % \subsubsection{Marked content}
351 %
352 % \begin{macro}{\@@_backend_bdc:nn}
353 % \begin{macro}{\@@_backend_emc:}
354 % Simple wrappers.
355 % \begin{macrocode}
356 \cs_new_protected:Npn \@@_backend_bdc:nn #1#2
357 { \@@_backend_pdfmark:n { /#1 ~ #2 /BDC } }
358 \cs_new_protected:Npn \@@_backend_emc:
359 { \@@_backend_pdfmark:n { /EMC } }
360 % \end{macrocode}
361 % \end{macro}
362 % \end{macro}
363 %
364 % \begin{macrocode}
365 %</dvips>
366 % \end{macrocode}
367 %
368 % \subsection{\LuaTeX{} and \pdfTeX{} backend}
369 %
370 % \begin{macrocode}
371 %<*luatex|pdftex>
372 % \end{macrocode}
373 %
374 % \subsubsection{Destinations}
375 %
376 % \begin{macro}{\@@_backend_destination:nn}
377 % \begin{macro}{\@@_backend_destination:nnnn}
378 % A simple task: pass the data to the primitive. The |\scan_stop:| deals
379 % with the danger of an unterminated keyword. The zoom given here is a
380 % percentage, but we need to pass it as \emph{per mille}. The rectangle
381 % version is also easy as everything is build in.
382 % \begin{macrocode}
383 \cs_new_protected:Npn \@@_backend_destination:nn #1#2
384 {
385 %<*luatex>
386 \tex_pdfextension:D dest ~
387 %</luatex>
388 %<*pdftex>
389 \tex_pdfdest:D
390 %</pdftex>
391 name {#1}
392 \str_case:nnF {#2}
393 {
394 { xyz } { xyz }
395 { fit } { fit }
396 { fitb } { fitb }
397 { fitbh } { fitbh }
398 { fitbv } { fitbv }
399 { fith } { fith }
400 { fitv } { fitv }
401 { fitr } { fitr }
402 }
403 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
404 \scan_stop:
405 }
406 \cs_new_protected:Npn \@@_backend_destination:nnnn #1#2#3#4
407 {
408 %<*luatex>
409 \tex_pdfextension:D dest ~
410 %</luatex>
411 %<*pdftex>
412 \tex_pdfdest:D
413 %</pdftex>
414 name {#1}
415 fitr ~
416 width \dim_eval:n {#2} ~
417 height \dim_eval:n {#3} ~
418 depth \dim_eval:n {#4} \scan_stop:
419 }
420 % \end{macrocode}
421 % \end{macro}
422 % \end{macro}
423 %
424 % \subsubsection{Catalogue entries}
425 %
426 % \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
427 % \begin{macrocode}
428 \cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2
429 {
430 %<*luatex>
431 \tex_pdfextension:D catalog
432 %</luatex>
433 %<*pdftex>
434 \tex_pdfcatalog:D
435 %</pdftex>
436 { / #1 ~ #2 }
437 }
438 \cs_new_protected:Npn \@@_backend_info_gput:nn #1#2
439 {
440 %<*luatex>
441 \tex_pdfextension:D info
442 %</luatex>
443 %<*pdftex>
444 \tex_pdfinfo:D
445 %</pdftex>
446 { / #1 ~ #2 }
447 }
448 % \end{macrocode}
449 % \end{macro}
450 %
451 % \subsubsection{Objects}
452 %
453 % \begin{variable}{\g_@@_backend_object_prop}
454 % For tracking objects to allow finalization.
455 % \begin{macrocode}
456 \prop_new:N \g_@@_backend_object_prop
457 % \end{macrocode}
458 % \end{variable}
459 %
460 % \begin{macro}{\@@_backend_object_new:}
461 % \begin{macro}[EXP]{\@@_backend_object_ref:n, \@@_backend_object_id:n}
462 % Declaring objects means reserving at the PDF level plus starting
463 % tracking.
464 % \begin{macrocode}
465 \cs_new_protected:Npn \@@_backend_object_new:
466 {
467 %<*luatex>
468 \tex_pdfextension:D obj ~
469 %</luatex>
470 %<*pdftex>
471 \tex_pdfobj:D
472 %</pdftex>
473 reserveobjnum ~
474 \int_gset:Nn \g_@@_backend_object_int
475 %<*luatex>
476 { \tex_pdffeedback:D lastobj }
477 %</luatex>
478 %<*pdftex>
479 { \tex_pdflastobj:D }
480 %</pdftex>
481 }
482 \cs_new:Npn \@@_backend_object_ref:n #1 { #1 ~ 0 ~ R }
483 \cs_new:Npn \@@_backend_object_id:n #1 {#1}
484 % \end{macrocode}
485 % \end{macro}
486 % \end{macro}
487 %
488 % \begin{macro}{\@@_backend_object_write:nnn, \@@_backend_object_write:nne}
489 % \begin{macro}[EXP]{\@@_backend_object_write:nn}
490 % \begin{macro}[EXP]{\@@_exp_not_i:nn, \@@_exp_not_ii:nn}
491 % Writing the data needs a little information about the structure of the
492 % object.
493 % \begin{macrocode}
494 \cs_new_protected:Npn \@@_backend_object_write:nnn #1#2#3
495 {
496 %<*luatex>
497 \tex_immediate:D \tex_pdfextension:D obj ~
498 %</luatex>
499 %<*pdftex>
500 \tex_immediate:D \tex_pdfobj:D
501 %</pdftex>
502 useobjnum ~ #1
503 \@@_backend_object_write:nn {#2} {#3}
504 }
505 \cs_new:Npn \@@_backend_object_write:nn #1#2
506 {
507 \str_case:nn {#1}
508 {
509 { array } { { [ ~ \exp_not:n {#2} ~ ] } }
510 { dict } { { << ~ \exp_not:n {#2} ~ >> } }
511 { fstream }
512 {
513 stream ~ attr ~ { \@@_exp_not_i:nn #2 } ~
514 file ~ { \@@_exp_not_ii:nn #2 }
515 }
516 { stream }
517 {
518 stream ~ attr ~ { \@@_exp_not_i:nn #2 } ~
519 { \@@_exp_not_ii:nn #2 }
520 }
521 }
522 }
523 \cs_generate_variant:Nn \@@_backend_object_write:nnn { nne }
524 \cs_new:Npn \@@_exp_not_i:nn #1#2 { \exp_not:n {#1} }
525 \cs_new:Npn \@@_exp_not_ii:nn #1#2 { \exp_not:n {#2} }
526 % \end{macrocode}
527 % \end{macro}
528 % \end{macro}
529 % \end{macro}
530 %
531 % \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:ne}
532 % Much like writing, but direct creation.
533 % \begin{macrocode}
534 \cs_new_protected:Npn \@@_backend_object_now:nn #1#2
535 {
536 %<*luatex>
537 \tex_immediate:D \tex_pdfextension:D obj ~
538 %</luatex>
539 %<*pdftex>
540 \tex_immediate:D \tex_pdfobj:D
541 %</pdftex>
542 \@@_backend_object_write:nn {#1} {#2}
543 }
544 \cs_generate_variant:Nn \@@_backend_object_now:nn { ne }
545 % \end{macrocode}
546 % \end{macro}
547 %
548 % \begin{macro}[EXP]{\@@_backend_object_last:}
549 % Much like annotation.
550 % \begin{macrocode}
551 \cs_new:Npe \@@_backend_object_last:
552 {
553 \exp_not:N \int_value:w
554 %<*luatex>
555 \exp_not:N \tex_pdffeedback:D lastobj ~
556 %</luatex>
557 %<*pdftex>
558 \exp_not:N \tex_pdflastobj:D
559 %</pdftex>
560 \c_space_tl 0 ~ R
561 }
562 % \end{macrocode}
563 % \end{macro}
564 %
565 % \begin{macro}[EXP]{\@@_backend_pageobject_ref:n}
566 % The usual wrapper situation; the three spaces here are essential.
567 % \begin{macrocode}
568 \cs_new:Npe \@@_backend_pageobject_ref:n #1
569 {
570 \exp_not:N \int_value:w
571 %<*luatex>
572 \exp_not:N \tex_pdffeedback:D pageref
573 %</luatex>
574 %<*pdftex>
575 \exp_not:N \tex_pdfpageref:D
576 %</pdftex>
577 \c_space_tl #1 \c_space_tl \c_space_tl \c_space_tl 0 ~ R
578 }
579 % \end{macrocode}
580 % \end{macro}
581 %
582 % \subsubsection{Structure}
583 %
584 % \begin{macro}{\@@_backend_compresslevel:n}
585 % \begin{macro}{\@@_backend_compress_objects:n}
586 % \begin{macro}{\@@_backend_objcompresslevel:n}
587 % Simply pass data to the engine.
588 % \begin{macrocode}
589 \cs_new_protected:Npn \@@_backend_compresslevel:n #1
590 {
591 \tex_global:D
592 %<*luatex>
593 \tex_pdfvariable:D compresslevel
594 %</luatex>
595 %<*pdftex>
596 \tex_pdfcompresslevel:D
597 %</pdftex>
598 \int_value:w \int_eval:n {#1} \scan_stop:
599 }
600 \cs_new_protected:Npn \@@_backend_compress_objects:n #1
601 {
602 \bool_if:nTF {#1}
603 { \@@_backend_objcompresslevel:n { 2 } }
604 { \@@_backend_objcompresslevel:n { 0 } }
605 }
606 \cs_new_protected:Npn \@@_backend_objcompresslevel:n #1
607 {
608 \tex_global:D
609 %<*luatex>
610 \tex_pdfvariable:D objcompresslevel
611 %</luatex>
612 %<*pdftex>
613 \tex_pdfobjcompresslevel:D
614 %</pdftex>
615 #1 \scan_stop:
616 }
617 % \end{macrocode}
618 % \end{macro}
619 % \end{macro}
620 % \end{macro}
621 %
622 % \begin{macro}
623 % {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
624 % The availability of the primitive is not universal, so we have to test
625 % at load time.
626 % \begin{macrocode}
627 \cs_new_protected:Npe \@@_backend_version_major_gset:n #1
628 {
629 %<*luatex>
630 \int_compare:nNnT \tex_luatexversion:D > { 106 }
631 {
632 \exp_not:N \tex_global:D \tex_pdfvariable:D majorversion
633 \exp_not:N \int_eval:n {#1} \scan_stop:
634 }
635 %</luatex>
636 %<*pdftex>
637 \cs_if_exist:NT \tex_pdfmajorversion:D
638 {
639 \exp_not:N \tex_global:D \tex_pdfmajorversion:D
640 \exp_not:N \int_eval:n {#1} \scan_stop:
641 }
642 %</pdftex>
643 }
644 \cs_new_protected:Npn \@@_backend_version_minor_gset:n #1
645 {
646 \tex_global:D
647 %<*luatex>
648 \tex_pdfvariable:D minorversion
649 %</luatex>
650 %<*pdftex>
651 \tex_pdfminorversion:D
652 %</pdftex>
653 \int_eval:n {#1} \scan_stop:
654 }
655 % \end{macrocode}
656 % \end{macro}
657 %
658 % \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
659 % As above.
660 % \begin{macrocode}
661 \cs_new:Npe \@@_backend_version_major:
662 {
663 %<*luatex>
664 \int_compare:nNnTF \tex_luatexversion:D > { 106 }
665 { \exp_not:N \tex_the:D \tex_pdfvariable:D majorversion }
666 { 1 }
667 %</luatex>
668 %<*pdftex>
669 \cs_if_exist:NTF \tex_pdfmajorversion:D
670 { \exp_not:N \tex_the:D \tex_pdfmajorversion:D }
671 { 1 }
672 %</pdftex>
673 }
674 \cs_new:Npn \@@_backend_version_minor:
675 {
676 \tex_the:D
677 %<*luatex>
678 \tex_pdfvariable:D minorversion
679 %</luatex>
680 %<*pdftex>
681 \tex_pdfminorversion:D
682 %</pdftex>
683 }
684 % \end{macrocode}
685 % \end{macro}
686 %
687 % \subsubsection{Marked content}
688 %
689 % \begin{macro}{\@@_backend_bdc:nn}
690 % \begin{macro}{\@@_backend_emc:}
691 % Simple wrappers. May need refinement: see
692 % \url{https://chat.stackexchange.com/transcript/message/49970158#49970158}.
693 % \begin{macrocode}
694 \cs_new_protected:Npn \@@_backend_bdc:nn #1#2
695 { \__kernel_backend_literal_page:n { /#1 ~ #2 ~ BDC } }
696 \cs_new_protected:Npn \@@_backend_emc:
697 { \__kernel_backend_literal_page:n { EMC } }
698 % \end{macrocode}
699 % \end{macro}
700 % \end{macro}
701 %
702 % \begin{macrocode}
703 %</luatex|pdftex>
704 % \end{macrocode}
705 %
706 % \subsection{\texttt{dvipdfmx} backend}
707 %
708 % \begin{macrocode}
709 %<*dvipdfmx|xetex>
710 % \end{macrocode}
711 %
712 % \begin{macro}{\@@_backend:n, \@@_backend:e}
713 % A generic function for the backend PDF specials: used where we can.
714 % \begin{macrocode}
715 \cs_new_protected:Npe \@@_backend:n #1
716 { \__kernel_backend_literal:n { pdf: #1 } }
717 \cs_generate_variant:Nn \@@_backend:n { e }
718 % \end{macrocode}
719 % \end{macro}
720 %
721 % \subsubsection{Catalogue entries}
722 %
723 % \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
724 % \begin{macrocode}
725 \cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2
726 { \@@_backend:n { put ~ @catalog << /#1 ~ #2 >> } }
727 \cs_new_protected:Npn \@@_backend_info_gput:nn #1#2
728 { \@@_backend:n { docinfo << /#1 ~ #2 >> } }
729 % \end{macrocode}
730 % \end{macro}
731 %
732 % \subsubsection{Objects}
733 %
734 % \begin{variable}{\g_@@_backend_object_prop}
735 % For tracking objects to allow finalization.
736 % \begin{macrocode}
737 \prop_new:N \g_@@_backend_object_prop
738 % \end{macrocode}
739 % \end{variable}
740 %
741 % \begin{macro}{\@@_backend_object_new:}
742 % \begin{macro}[EXP]{\@@_backend_object_ref:n, \@@_backend_object_id:n}
743 % Objects are tracked at the macro level, but we don't have to do anything
744 % at this stage.
745 % \begin{macrocode}
746 \cs_new_protected:Npn \@@_backend_object_new:
747 { \int_gincr:N \g_@@_backend_object_int }
748 \cs_new:Npn \@@_backend_object_ref:n #1 { @pdf.obj #1 }
749 \cs_new_eq:NN \@@_backend_object_id:n \@@_backend_object_ref:n
750 % \end{macrocode}
751 % \end{macro}
752 % \end{macro}
753 %
754 % \begin{macro}{\@@_backend_object_write:nnn, \@@_backend_object_write:nne}
755 % \begin{macro}
756 % {
757 % \@@_backend_object_write_array:nn ,
758 % \@@_backend_object_write_dict:nn ,
759 % \@@_backend_object_write_fstream:nn ,
760 % \@@_backend_object_write_stream:nn
761 % }
762 % \begin{macro}{\@@_backend_object_write_stream:nnnn}
763 % This is where we choose the actual type.
764 % \begin{macrocode}
765 \cs_new_protected:Npn \@@_backend_object_write:nnn #1#2#3
766 {
767 \use:c { @@_backend_object_write_ #2 :nn }
768 { \@@_backend_object_ref:n {#1} } {#3}
769 }
770 \cs_generate_variant:Nn \@@_backend_object_write:nnn { nne }
771 \cs_new_protected:Npn \@@_backend_object_write_array:nn #1#2
772 {
773 \@@_backend:e
774 { obj ~ #1 ~ [ ~ \exp_not:n {#2} ~ ] }
775 }
776 \cs_new_protected:Npn \@@_backend_object_write_dict:nn #1#2
777 {
778 \@@_backend:e
779 { obj ~ #1 ~ << ~ \exp_not:n {#2} ~ >> }
780 }
781 \cs_new_protected:Npn \@@_backend_object_write_fstream:nn #1#2
782 { \@@_backend_object_write_stream:nnnn { f } {#1} #2 }
783 \cs_new_protected:Npn \@@_backend_object_write_stream:nn #1#2
784 { \@@_backend_object_write_stream:nnnn { } {#1} #2 }
785 \cs_new_protected:Npn \@@_backend_object_write_stream:nnnn #1#2#3#4
786 {
787 \@@_backend:e
788 {
789 #1 stream ~ #2 ~
790 ( \exp_not:n {#4} ) ~ << \exp_not:n {#3} >>
791 }
792 }
793 % \end{macrocode}
794 % \end{macro}
795 % \end{macro}
796 % \end{macro}
797 %
798 % \begin{macro}{\@@_backend_object_now:nn, \@@_backend_object_now:ne}
799 % No anonymous objects with \texttt{dvipdfmx} so we have to give an
800 % object name.
801 % \begin{macrocode}
802 \cs_new_protected:Npn \@@_backend_object_now:nn #1#2
803 {
804 \int_gincr:N \g_@@_backend_object_int
805 \exp_args:Nne \use:c { @@_backend_object_write_ #1 :nn }
806 { @pdf.obj \int_use:N \g_@@_backend_object_int }
807 {#2}
808 }
809 \cs_generate_variant:Nn \@@_backend_object_now:nn { ne }
810 % \end{macrocode}
811 % \end{macro}
812 %
813 % \begin{macro}{\@@_backend_object_last:}
814 % \begin{macrocode}
815 \cs_new:Npn \@@_backend_object_last:
816 { @pdf.obj \int_use:N \g_@@_backend_object_int }
817 % \end{macrocode}
818 % \end{macro}
819 %
820 % \begin{macro}[EXP]{\@@_backend_pageobject_ref:n}
821 % Page references are easy in \texttt{dvipdfmx}/\XeTeX{}.
822 % \begin{macrocode}
823 \cs_new:Npn \@@_backend_pageobject_ref:n #1
824 { @page #1 }
825 % \end{macrocode}
826 % \end{macro}
827 %
828 % \subsubsection{Destinations}
829 %
830 % \begin{macro}{\@@_backend_destination:nn}
831 % \begin{macro}{\@@_backend_destination:nnnn,\@@_backend_destination_aux:nnnn}
832 % Here, we need to turn the zoom into a scale. The method for \texttt{FitR}
833 % is from Alexander Grahn: the idea is to avoid needing to do any calculations
834 % in \TeX{} by using the backend data for \texttt{@xpos} and \texttt{@ypos}.
835 % \texttt{/FitR} without rule spec doesn't work, so it falls back to
836 % \texttt{/Fit} here.
837 % \begin{macrocode}
838 \cs_new_protected:Npn \@@_backend_destination:nn #1#2
839 {
840 \@@_backend:e
841 {
842 dest ~ ( \exp_not:n {#1} )
843 [
844 @thispage
845 \str_case:nnF {#2}
846 {
847 { xyz } { /XYZ ~ @xpos ~ @ypos ~ null }
848 { fit } { /Fit }
849 { fitb } { /FitB }
850 { fitbh } { /FitBH }
851 { fitbv } { /FitBV ~ @xpos }
852 { fith } { /FitH ~ @ypos }
853 { fitv } { /FitV ~ @xpos }
854 { fitr } { /Fit }
855 }
856 { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
857 ]
858 }
859 }
860 \cs_new_protected:Npn \@@_backend_destination:nnnn #1#2#3#4
861 {
862 \exp_args:Ne \@@_backend_destination_aux:nnnn
863 { \dim_eval:n {#2} } {#1} {#3} {#4}
864 }
865 \cs_new_protected:Npn \@@_backend_destination_aux:nnnn #1#2#3#4
866 {
867 \vbox_to_zero:n
868 {
869 \dim_vertical:n {#4}
870 \hbox:n
871 {
872 \@@_backend:n { obj ~ @pdf_ #2 _llx ~ @xpos }
873 \@@_backend:n { obj ~ @pdf_ #2 _lly ~ @ypos }
874 }
875 \tex_vss:D
876 }
877 \dim_horizontal:n {#1}
878 \vbox_to_zero:n
879 {
880 \dim_vertical:n { -#3 }
881 \hbox:n
882 {
883 \@@_backend:n
884 {
885 dest ~ (#2)
886 [
887 @thispage
888 /FitR ~
889 @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
890 @xpos ~ @ypos
891 ]
892 }
893 }
894 \tex_vss:D
895 }
896 \dim_horizontal:n { -#1 }
897 }
898 % \end{macrocode}
899 % \end{macro}
900 % \end{macro}
901 %
902 % \subsubsection{Structure}
903 %
904 % \begin{macro}{\@@_backend_compresslevel:n}
905 % \begin{macro}{\@@_backend_compress_objects:n}
906 % Pass data to the backend: these are a one-shot.
907 % \begin{macrocode}
908 \cs_new_protected:Npn \@@_backend_compresslevel:n #1
909 { \__kernel_backend_literal:e { dvipdfmx:config~z~ \int_eval:n {#1} } }
910 \cs_new_protected:Npn \@@_backend_compress_objects:n #1
911 {
912 \bool_if:nF {#1}
913 { \__kernel_backend_literal:n { dvipdfmx:config~C~0x40 } }
914 }
915 % \end{macrocode}
916 % \end{macro}
917 % \end{macro}
918 %
919 % \begin{macro}
920 % {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
921 % We start with the assumption that the default is active.
922 % \begin{macrocode}
923 \cs_new_protected:Npn \@@_backend_version_major_gset:n #1
924 {
925 \cs_gset:Npe \@@_backend_version_major: { \int_eval:n {#1} }
926 \__kernel_backend_literal:e { pdf:majorversion~ \@@_backend_version_major: }
927 }
928 \cs_new_protected:Npn \@@_backend_version_minor_gset:n #1
929 {
930 \cs_gset:Npe \@@_backend_version_minor: { \int_eval:n {#1} }
931 \__kernel_backend_literal:e { pdf:minorversion~ \@@_backend_version_minor: }
932 }
933 % \end{macrocode}
934 % \end{macro}
935 %
936 % \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
937 % We start with the assumption that the default is active.
938 % \begin{macrocode}
939 \cs_new:Npn \@@_backend_version_major: { 1 }
940 \cs_new:Npn \@@_backend_version_minor: { 7 }
941 % \end{macrocode}
942 % \end{macro}
943 %
944 % \subsubsection{Marked content}
945 %
946 % \begin{macro}{\@@_backend_bdc:nn}
947 % \begin{macro}{\@@_backend_emc:}
948 % Simple wrappers. May need refinement: see
949 % \url{https://chat.stackexchange.com/transcript/message/49970158#49970158}.
950 % \begin{macrocode}
951 \cs_new_protected:Npn \@@_backend_bdc:nn #1#2
952 { \__kernel_backend_literal_page:n { /#1 ~ #2 ~ BDC } }
953 \cs_new_protected:Npn \@@_backend_emc:
954 { \__kernel_backend_literal_page:n { EMC } }
955 % \end{macrocode}
956 % \end{macro}
957 % \end{macro}
958 %
959 % \begin{macrocode}
960 %</dvipdfmx|xetex>
961 % \end{macrocode}
962 %
963 % \subsection{\texttt{dvisvgm} backend}
964 %
965 % \begin{macrocode}
966 %<*dvisvgm>
967 % \end{macrocode}
968 %
969 % \subsubsection{Destinations}
970 %
971 % \begin{macro}{\@@_backend_destination:nn}
972 % \begin{macro}{\@@_backend_destination:nnnn}
973 % \begin{macrocode}
974 \cs_new_protected:Npn \@@_backend_destination:nn #1#2 { }
975 \cs_new_protected:Npn \@@_backend_destination:nnnn #1#2#3#4 { }
976 % \end{macrocode}
977 % \end{macro}
978 % \end{macro}
979 %
980 % \subsubsection{Catalogue entries}
981 %
982 % \begin{macro}{\@@_backend_catalog_gput:nn, \@@_backend_info_gput:nn}
983 % No-op.
984 % \begin{macrocode}
985 \cs_new_protected:Npn \@@_backend_catalog_gput:nn #1#2 { }
986 \cs_new_protected:Npn \@@_backend_info_gput:nn #1#2 { }
987 % \end{macrocode}
988 % \end{macro}
989 %
990 % \subsubsection{Objects}
991 %
992 % \begin{macro}{\@@_backend_object_new:}
993 % \begin{macro}[EXP]{\@@_backend_object_ref:n, \@@_backend_object_id:n}
994 % \begin{macro}{\@@_backend_object_write:nnn, \@@_backend_object_write:ne}
995 % \begin{macro}{\@@_backend_object_now:nn, , \@@_backend_object_now:ne}
996 % \begin{macro}{\@@_backend_object_last:}
997 % \begin{macro}[EXP]{\@@_backend_pageobject_ref:n}
998 % All no-ops here.
999 % \begin{macrocode}
1000 \cs_new_protected:Npn \@@_backend_object_new: { }
1001 \cs_new:Npn \@@_backend_object_ref:n #1 { }
1002 \cs_new:Npn \@@_backend_object_id:n #1 { }
1003 \cs_new_protected:Npn \@@_backend_object_write:nnn #1#2#3 { }
1004 \cs_new_protected:Npn \@@_backend_object_write:nne #1#2#3 { }
1005 \cs_new_protected:Npn \@@_backend_object_now:nn #1#2 { }
1006 \cs_new_protected:Npn \@@_backend_object_now:ne #1#2 { }
1007 \cs_new:Npn \@@_backend_object_last: { }
1008 \cs_new:Npn \@@_backend_pageobject_ref:n #1 { }
1009 % \end{macrocode}
1010 % \end{macro}
1011 % \end{macro}
1012 % \end{macro}
1013 % \end{macro}
1014 % \end{macro}
1015 % \end{macro}
1016 %
1017 % \subsubsection{Structure}
1018 %
1019 % \begin{macro}{\@@_backend_compresslevel:n}
1020 % \begin{macro}{\@@_backend_compress_objects:n}
1021 % These are all no-ops.
1022 % \begin{macrocode}
1023 \cs_new_protected:Npn \@@_backend_compresslevel:n #1 { }
1024 \cs_new_protected:Npn \@@_backend_compress_objects:n #1 { }
1025 % \end{macrocode}
1026 % \end{macro}
1027 % \end{macro}
1028 %
1029 % \begin{macro}
1030 % {\@@_backend_version_major_gset:n, \@@_backend_version_minor_gset:n}
1031 % Data not available!
1032 % \begin{macrocode}
1033 \cs_new_protected:Npn \@@_backend_version_major_gset:n #1 { }
1034 \cs_new_protected:Npn \@@_backend_version_minor_gset:n #1 { }
1035 % \end{macrocode}
1036 % \end{macro}
1037 %
1038 % \begin{macro}[EXP]{\@@_backend_version_major:, \@@_backend_version_minor:}
1039 % Data not available!
1040 % \begin{macrocode}
1041 \cs_new:Npn \@@_backend_version_major: { -1 }
1042 \cs_new:Npn \@@_backend_version_minor: { -1 }
1043 % \end{macrocode}
1044 % \end{macro}
1045 %
1046 % \begin{macro}{\@@_backend_bdc:nn}
1047 % \begin{macro}{\@@_backend_emc:}
1048 % More no-ops.
1049 % \begin{macrocode}
1050 \cs_new_protected:Npn \@@_backend_bdc:nn #1#2 { }
1051 \cs_new_protected:Npn \@@_backend_emc: { }
1052 % \end{macrocode}
1053 % \end{macro}
1054 % \end{macro}
1055 %
1056 % \begin{macrocode}
1057 %</dvisvgm>
1058 % \end{macrocode}
1059 %
1060 % \subsection{PDF Page size (media box)}
1061 %
1062 % For setting the media box, the split between backends is somewhat different
1063 % to other areas, thus we approach this separately. The code here assumes a
1064 % recent \LaTeXe{}: that is ensured at the level above.
1065 %
1066 % \begin{macrocode}
1067 %<*dvipdfmx|dvips>
1068 % \end{macrocode}
1069 %
1070 % \begin{macro}{\@@_backend_pagesize_gset:nn}
1071 % This is done as a backend literal, so we deal with it using the shipout
1072 % hook.
1073 % \begin{macrocode}
1074 \cs_new_protected:Npn \@@_backend_pagesize_gset:nn #1#2
1075 {
1076 \__kernel_backend_first_shipout:n
1077 {
1078 \__kernel_backend_literal:e
1079 {
1080 %<*dvipdfmx>
1081 pdf:pagesize ~
1082 width ~ \dim_eval:n {#1} ~
1083 height ~ \dim_eval:n {#2}
1084 %</dvipdfmx>
1085 %<*dvips>
1086 papersize = \dim_eval:n {#1} , \dim_eval:n {#2}
1087 %</dvips>
1088 }
1089 }
1090 }
1091 % \end{macrocode}
1092 % \end{macro}
1093 %
1094 % \begin{macrocode}
1095 %</dvipdfmx|dvips>
1096 % \end{macrocode}
1097 %
1098 % \begin{macrocode}
1099 %<*luatex|pdftex|xetex>
1100 % \end{macrocode}
1101 %
1102 % \begin{macro}{\@@_backend_pagesize_gset:nn}
1103 % Pass to the primitives.
1104 % \begin{macrocode}
1105 \cs_new_protected:Npn \@@_backend_pagesize_gset:nn #1#2
1106 {
1107 \dim_gset:Nn \tex_pagewidth:D {#1}
1108 \dim_gset:Nn \tex_pageheight:D {#2}
1109 }
1110 % \end{macrocode}
1111 % \end{macro}
1112 %
1113 % \begin{macrocode}
1114 %</luatex|pdftex|xetex>
1115 % \end{macrocode}
1116 %
1117 % \begin{macrocode}
1118 %<*dvisvgm>
1119 % \end{macrocode}
1120 %
1121 % \begin{macro}{\@@_backend_pagesize_gset:nn}
1122 % A no-op.
1123 % \begin{macrocode}
1124 \cs_new_protected:Npn \@@_backend_pagesize_gset:nn #1#2 { }
1125 % \end{macrocode}
1126 % \end{macro}
1127 %
1128 % \begin{macrocode}
1129 %</dvisvgm>
1130 % \end{macrocode}
1131 %
1132 % \begin{macrocode}
1133 %</package>
1134 % \end{macrocode}
1135 %
1136 % \end{implementation}
1137 %
1138 % \PrintIndex