Debian Codegraph @

texmf-dist/source/latex/l3kernel/l3pdf.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3pdf.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 % http://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3kernel 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]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3pdf} module\\ Core PDF support^^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-05-15}
47 %
48 % \maketitle
49 %
50 % \begin{documentation}
51 %
52 % \section{Objects}
53 %
54 % \subsection{Named objects}
55 %
56 % An \meta{object} name should fully expand to tokens suitable for use in a
57 % label-like context.
58 %
59 % \begin{function}[added = 2022-08-23]{\pdf_object_new:n}
60 % \begin{syntax}
61 % \cs{pdf_object_new:n} \Arg{object}
62 % \end{syntax}
63 % Declares \meta{object} as a PDF object. The object may be referenced
64 % from this point on, and written later using \cs{pdf_object_write:nnn}.
65 % \end{function}
66 %
67 % \begin{function}[added = 2022-08-23]
68 % {\pdf_object_write:nnn, \pdf_object_write:nne}
69 % \begin{syntax}
70 % \cs{pdf_object_write:nnn} \Arg{object} \Arg{type} \Arg{content}
71 % \end{syntax}
72 % Writes the \meta{content} as content of the \meta{object}. Depending on the
73 % \meta{type} declared for the object, the format required for
74 % \meta{content} will vary:
75 % \begin{itemize}
76 % \item[\texttt{array}] A space-separated list of values
77 % \item[\texttt{dict}] Key--value pairs in the form
78 % \texttt{/\meta{key} \meta{value}}
79 % \item[\texttt{fstream}] Two brace groups: \meta{file name} and
80 % \meta{file content}
81 % \item[\texttt{stream}] Two brace groups: \meta{attributes (dictionary)}
82 % and \meta{stream contents}
83 % \end{itemize}
84 % \end{function}
85 %
86 % \begin{function}[EXP, added = 2021-02-10]{\pdf_object_ref:n}
87 % \begin{syntax}
88 % \cs{pdf_object_ref:n} \Arg{object}
89 % \end{syntax}
90 % Inserts the appropriate information to reference the \meta{object}
91 % in for example page resource allocation. If the \meta{object} does
92 % not exist then the function expands to a reference to object zero;
93 % no PDF indirect object ever has this number, so this is a marker for
94 % error.
95 % \end{function}
96 %
97 % \begin{function}[EXP, pTF, added = 2020-05-15]{\pdf_object_if_exist:n}
98 % \begin{syntax}
99 % \cs{pdf_object_if_exist_p:n} \Arg{object}
100 % \cs{pdf_object_if_exist:nTF} \Arg{object} \Arg{true code} \Arg{false code}
101 % \end{syntax}
102 % Tests whether an object with name \Arg{object} has been defined.
103 % \end{function}
104 %
105 % \subsection{Indexed objects}
106 %
107 % Objects can also be created using a pair of \meta{class} and \emph{index};
108 % the \meta{class} argument should expand to character tokens, whilst the
109 % \meta{index} is an \meta{int expr} and starts at $1$. For large
110 % families of objects, this approach is more efficient than using
111 % individual names.
112 %
113 % \begin{function}[added = 2024-04-01]{\pdf_object_new_indexed:nn}
114 % \begin{syntax}
115 % \cs{pdf_object_new_indexed:nn} \Arg{class} \Arg{index}
116 % \end{syntax}
117 % Declares a PDF object of \meta{class} and \meta{index}. The object may be
118 % referenced from this point on, and written later using
119 % \cs{pdf_object_write_indexed:nnnn}.
120 % \end{function}
121 %
122 % \begin{function}[added = 2024-04-01]
123 % {\pdf_object_write_indexed:nnnn, \pdf_object_write_indexed:nnne}
124 % \begin{syntax}
125 % \cs{pdf_object_write_indexed:nnnn} \Arg{class} \Arg{index} \Arg{type} \Arg{content}
126 % \end{syntax}
127 % Writes the \meta{content} as content of the object of \meta{class} and
128 % \meta{index}. Depending on the
129 % \meta{type} declared for the object, the format required for the
130 % \meta{content} will vary
131 % \begin{itemize}
132 % \item[\texttt{array}] A space-separated list of values
133 % \item[\texttt{dict}] Key--value pairs in the form
134 % \texttt{/\meta{key} \meta{value}}
135 % \item[\texttt{fstream}] Two brace groups: \meta{file name} and
136 % \meta{file content}
137 % \item[\texttt{stream}] Two brace groups: \meta{attributes (dictionary)}
138 % and \meta{stream contents}
139 % \end{itemize}
140 % \end{function}
141 %
142 % \begin{function}[EXP, added = 2024-04-01]{\pdf_object_ref_indexed:nn}
143 % \begin{syntax}
144 % \cs{pdf_object_ref_indexed:nn} \Arg{class} \Arg{index}
145 % \end{syntax}
146 % Inserts the appropriate information to reference the object of \meta{class}
147 % and \meta{index} in for example page resource allocation. If the
148 % \meta{class}/\meta{index} combination does
149 % not exist then the function expands to a reference to object zero;
150 % no PDF indirect object ever has this number, so this is a marker for
151 % error.
152 % \end{function}
153 %
154 % \subsection{General functions}
155 %
156 % \begin{function}[added = 2021-02-10]
157 % {\pdf_object_unnamed_write:nn, \pdf_object_unnamed_write:ne}
158 % \begin{syntax}
159 % \cs{pdf_object_unnamed_write:nn} \Arg{type} \Arg{content}
160 % \end{syntax}
161 % Writes the \meta{content} as content of an anonymous object. Depending on the
162 % \meta{type}, the format required for \meta{content} will vary:
163 % \begin{itemize}
164 % \item[\texttt{array}] A space-separated list of values
165 % \item[\texttt{dict}] Key--value pairs in the form
166 % \texttt{/\meta{key} \meta{value}}
167 % \item[\texttt{fstream}] Two brace groups: \meta{attributes (dictionary)}
168 % and \meta{file name}
169 % \item[\texttt{stream}] Two brace groups: \meta{attributes (dictionary)}
170 % and \meta{stream contents}
171 % \end{itemize}
172 % \end{function}
173 %
174 % \begin{function}[EXP, added = 2021-02-10]{\pdf_object_ref_last:}
175 % \begin{syntax}
176 % \cs{pdf_object_ref_last:}
177 % \end{syntax}
178 % Inserts the appropriate information to reference the last \meta{object}
179 % created. This is particularly useful for anonymous objects.
180 % \end{function}
181 %
182 % \begin{function}[EXP, added = 2021-02-10, updated = 2024-04-22]
183 % {\pdf_pageobject_ref:n}
184 % \begin{syntax}
185 % \cs{pdf_pageobject_ref:n} \Arg{abspage}
186 % \end{syntax}
187 % Inserts the appropriate information to reference the \meta{abspage};
188 % the latter is expanded fully before further processing.
189 % \end{function}
190 %
191 % \section{Version}
192 %
193 % \begin{function}[pTF, EXP, added = 2021-02-10]{\pdf_version_compare:Nn}
194 % \begin{syntax}
195 % \cs{pdf_version_compare_p:Nn} \meta{relation} \Arg{version}
196 % \cs{pdf_version_compare:NnTF} \meta{relation} \Arg{version} \Arg{true code} \Arg{false code}
197 % \end{syntax}
198 % Compares the version of the PDF being created with the \meta{version}
199 % string specified, using the \meta{relation}. Either the \meta{true code}
200 % or \meta{false code} will be left in the output stream.
201 % \end{function}
202 %
203 % \begin{function}[added = 2021-02-10]
204 % {\pdf_version_gset:n, \pdf_version_min_gset:n}
205 % \begin{syntax}
206 % \cs{pdf_version_gset:n} \Arg{version}
207 % \end{syntax}
208 % Sets the \meta{version} of the PDF being created. The |min| version will
209 % not alter the output version unless it is currently lower than the
210 % \meta{version} requested.
211 %
212 % This function may only be used up to the point where the PDF file is
213 % initialized. With |dvips| it sets \cs{pdf_version_major:} and
214 % \cs{pdf_version_minor:} and allows to compare the values with
215 % \cs{pdf_version_compare:Nn}, but the
216 % PDF version itself still has to be set with the command line option
217 % |-dCompatibilityLevel| of |ps2pdf|.
218 % \end{function}
219 %
220 % \begin{function}[EXP, added = 2021-02-10]
221 % {\pdf_version:, \pdf_version_major:, \pdf_version_minor:}
222 % \begin{syntax}
223 % \cs{pdf_version:}
224 % \end{syntax}
225 % Expands to the currently-active PDF version.
226 %
227 % With |dvips|, the PDF version is initialized to |-1.-1|. With
228 % |dvipdfmx|, it is initialized to |1.7| in releases since 2025 June,
229 % following the default \TeX{} Live 2025 setting; and |1.5| in previous
230 % releases.
231 % \end{function}
232 %
233 % \section{Page (media) size}
234 %
235 % \begin{function}[added = 2023-01-14]{\pdf_pagesize_gset:nn}
236 % \begin{syntax}
237 % \cs{pdf_pagesize_gset:nn} \Arg{width} \Arg{height}
238 % \end{syntax}
239 % Sets the page size (|mediabox|) of the PDF being created to the
240 % \meta{width} and \meta{height}, both of which are \meta{dimexpr}.
241 % The page size can only be set at the start of the output with
242 % \texttt{dvips}; with other backends, this can be adjusted on a
243 % per-page basis.
244 % \end{function}
245 %
246 % \section{Compression}
247 %
248 % \begin{function}[added = 2021-02-10]{\pdf_uncompress:}
249 % \begin{syntax}
250 % \cs{pdf_uncompress:}
251 % \end{syntax}
252 % Disables any compression of the PDF, where possible.
253 %
254 % This function may only be used up to the point where the PDF file is
255 % initialized.
256 % \end{function}
257 %
258 % \section{Destinations}
259 %
260 % Destinations are the places a link jumped to.
261 % Unlike the name may suggest, they don't describe
262 % an exact location in the PDF. Instead, a destination contains a reference to
263 % a page along with an instruction how to display this page.
264 % The normally used \enquote{XYZ \textit{top left zoom}} for example instructs
265 % the viewer to show the page with the given \textit{zoom} and
266 % the top left corner at the \textit{top left} coordinates---which then gives
267 % the impression that there is an anchor at this position.
268 %
269 % If an instruction takes a coordinate, it is calculated by the following
270 % commands relative to the location the command is issued.
271 % So to get a specific coordinate one has to move the command to the right place.
272 %
273 % \begin{function}[added = 2021-01-03]
274 % {\pdf_destination:nn}
275 % \begin{syntax}
276 % \cs{pdf_destination:nn} \Arg{name} \Arg{type or integer}
277 % \end{syntax}
278 % This creates a destination. \Arg{type or integer} can be one of |fit|, |fith|,
279 % |fitv|, |fitb|, |fitbh|, |fitbv|, |fitr|, |xyz|
280 % or an integer representing a scale factor in percent.
281 % |fitr| here gives only a lightweight version of |/FitR|:
282 % The backend code defines |fitr| so that it will with pdf\LaTeX{} and
283 % Lua\LaTeX{} use the coordinates of the surrounding box,
284 % with \texttt{dvips} and \texttt{dvipdfmx} it falls back to |fit|.
285 % For full control use \cs{pdf_destination:nnnn}.
286 %
287 % The keywords match to the PDF names as described in the following tabular.
288 %
289 % \medskip
290 % \noindent\begin{tabular}{ll>{\raggedright\arraybackslash}p{6cm}}
291 % \toprule
292 % Keyword & PDF & Remarks \\ \midrule
293 % |fit| & |/Fit|
294 % & Fits the page to the window\\
295 % |fith| & |/FitH| \textit{top}
296 % & Fits the width of the page to the window \\
297 % |fitv| & |/FitV| \textit{left}
298 % & Fits the height of the page to the window \\
299 % |fitb| & |/FitB|
300 % & Fits the page bounding box to the window \\
301 % |fitbh|& |/FitBH| \textit{top}
302 % & Fits the width of the page bounding box to the window. \\
303 % |fitbv|& |/FitBV| \textit{left}
304 % & Fits the height of the page bounding box to the window. \\
305 % |fitr| & |/FitR| \textit{left bottom right top}
306 % & Fits the rectangle specified by the four coordinates to the window
307 % (see above for the restrictions)\\
308 % |xyz| & |/XYZ| \textit{left top} null
309 % & Sets a coordinate but doesn't change the zoom.\\
310 % \Arg{integer} & |/XYZ| \textit{left top zoom}
311 % & Sets a coordinate and a zoom meaning \Arg{integer}\%.
312 % \\\bottomrule
313 % \end{tabular}
314 %
315 % \end{function}
316 %
317 % \begin{function}[added = 2021-01-17]
318 % {\pdf_destination:nnnn}
319 % \begin{syntax}
320 % \cs{pdf_destination:nnnn} \Arg{name} \Arg{width} \Arg{height} \Arg{depth}
321 % \end{syntax}
322 % This creates a destination with |/FitR| type with the given dimensions relative
323 % to the current location. The destination is in a box of size zero, but it doesn't
324 % switch to horizontal mode.
325 % \end{function}
326 % \end{documentation}
327 %
328 % \begin{implementation}
329 %
330 % \section{\pkg{l3pdf} implementation}
331 %
332 % \begin{macrocode}
333 %<@@=pdf>
334 % \end{macrocode}
335 %
336 % \begin{macrocode}
337 %<*code>
338 % \end{macrocode}
339 %
340 % \begin{variable}{\s_@@_stop}
341 % Internal scan marks.
342 % \begin{macrocode}
343 \scan_new:N \s_@@_stop
344 % \end{macrocode}
345 % \end{variable}
346 %
347 % \begin{variable}{\g_@@_init_bool}
348 % A boolean so we have some chance of avoiding setting things we are not
349 % allowed to. As we are potentially early in the format, we have to work
350 % a bit harder than ideal.
351 % \begin{macrocode}
352 \bool_new:N \g_@@_init_bool
353 \bool_lazy_and:nnT
354 { \str_if_eq_p:Vn \fmtname { LaTeX2e } }
355 { \tl_if_exist_p:N \@expl@finalise@setup@@@@ }
356 {
357 \tl_gput_right:Nn \@expl@finalise@setup@@@@
358 {
359 \tl_gput_right:Nn \@kernel@after@begindocument
360 { \bool_gset_true:N \g_@@_init_bool }
361 }
362 }
363 % \end{macrocode}
364 % \end{variable}
365 %
366 % \subsection{Compression}
367 %
368 % \begin{macro}{\pdf_uncompress:}
369 % Simple to do.
370 % \begin{macrocode}
371 \cs_new_protected:Npn \pdf_uncompress:
372 {
373 \bool_if:NF \g_@@_init_bool
374 {
375 \@@_backend_compresslevel:n { 0 }
376 \@@_backend_compress_objects:n { \c_false_bool }
377 }
378 }
379 % \end{macrocode}
380 % \end{macro}
381 %
382 % \subsection{Objects}
383 %
384 % \begin{variable}{\g_@@_backend_object_int}
385 % For returning object numbers.
386 % \begin{macrocode}
387 \int_new:N \g_@@_backend_object_int
388 % \end{macrocode}
389 % \end{variable}
390 %
391 % \begin{macro}{\pdf_object_new:n}
392 % \begin{macro}
393 % {\pdf_object_write:nnn, \pdf_object_write:nne, \pdf_object_write:nnx}
394 % \begin{macro}{\pdf_object_ref:n}
395 % \begin{macro}{\__kernel_pdf_object_id:n}
396 % Simple to do: all objects create a constant |int| so it is not a
397 % backend-specific name.
398 % \begin{macrocode}
399 \cs_new_protected:Npn \pdf_object_new:n #1
400 {
401 \@@_backend_object_new:
402 \@@_object_record:nN {#1} \g_@@_backend_object_int
403 }
404 \cs_new_protected:Npn \pdf_object_write:nnn #1#2#3
405 {
406 \exp_args:Ne \@@_backend_object_write:nnn
407 { \@@_object_retrieve:n {#1} } {#2} {#3}
408 \bool_gset_true:N \g_@@_init_bool
409 }
410 \cs_generate_variant:Nn \pdf_object_write:nnn { nne , nnx }
411 \cs_new:Npn \pdf_object_ref:n #1
412 {
413 \exp_args:Ne \@@_backend_object_ref:n
414 { \@@_object_retrieve:n {#1} }
415 }
416 \cs_new:Npn \__kernel_pdf_object_id:n #1
417 {
418 \exp_args:Ne \@@_backend_object_id:n
419 { \@@_object_retrieve:n {#1} }
420 }
421 %</code>
422 % \end{macrocode}
423 % \end{macro}
424 % \end{macro}
425 % \end{macro}
426 % \end{macro}
427 % \begin{macro}{\@@_object_record:nN}
428 % \begin{macro}[EXP]{\@@_object_retrieve:n}
429 % \begin{macro}{ltx.pdf.object_id}
430 % Object mappings are tracked in Lua for \LuaTeX{} as this makes retrieving
431 % them much easier; as a result, there is a split in approaches. In Lua we
432 % store values in a table indexed by name. The Lua function here is set up
433 % to deal with both named and indexed objects: fits the Lua idiom well.
434 % \begin{macrocode}
435 %<*lua>
436
437 local scan_int = token.scan_int
438 local scan_string = token.scan_string
439 local cprint = tex.cprint
440
441 local @@_objects_named = {}
442 local @@_objects_indexed = {}
443
444 luacmd('@@_object_record:nN', function()
445 local name = scan_string()
446 local n = scan_int()
447 @@_objects_named[name] = n
448 end,'protected','global')
449
450 local function object_id(name,index)
451 if index then
452 return @@_objects_indexed[name][index] or 0
453 else
454 return @@_objects_named[name] or 0
455 end
456 end
457
458 luacmd('@@_object_retrieve:n', function()
459 local name = scan_string()
460 return cprint(12,tostring(object_id(name)))
461 end,'global')
462
463 ltx.pdf = ltx.pdf or {}
464 ltx.pdf.object_id = object_id
465
466 %</lua>
467 % \end{macrocode}
468 % Whereas in \TeX{} we use integer constants.
469 % \begin{macrocode}
470 %<*code>
471 \sys_if_engine_luatex:F
472 {
473 \cs_new_protected:Npn \@@_object_record:nN #1#2
474 {
475 \int_const:cn
476 { c_@@_object_ #1 _int } {#2}
477 }
478 \cs_new:Npn \@@_object_retrieve:n #1
479 {
480 \int_if_exist:cTF { c_@@_object_ #1 _int }
481 {
482 \int_use:c
483 { c_@@_object_ #1 _int }
484 }
485 { 0 }
486 }
487 }
488 % \end{macrocode}
489 % \end{macro}
490 % \end{macro}
491 % \end{macro}
492 % \begin{macro}[pTF,EXP]{\pdf_object_if_exist:n}
493 % \begin{macrocode}
494 \prg_new_conditional:Npnn \pdf_object_if_exist:n #1 { p , T , F , TF }
495 {
496 \int_compare:nNnTF { \@@_object_retrieve:n {#1} } = 0
497 \prg_return_false:
498 \prg_return_true:
499 }
500 % \end{macrocode}
501 % \end{macro}
502 %
503 % \begin{macro}{\pdf_object_new_indexed:nn}
504 % \begin{macro}{\pdf_object_write_indexed:nnnn, \pdf_object_write_indexed:nnne}
505 % \begin{macro}[EXP]{\pdf_object_ref_indexed:nn}
506 % \begin{macro}[EXP]{\__kernel_pdf_object_id_indexed:nn}
507 % Again we split between the common code and the macro- or Lua-based
508 % implementation. To make life easier for the Lua route, all of the
509 % potential expressions are expanded to braced numbers.
510 % \begin{macrocode}
511 \cs_new_protected:Npn \pdf_object_new_indexed:nn #1#2
512 {
513 \@@_backend_object_new:
514 \@@_object_record:neN {#1}
515 { \int_eval:n {#2} } \g_@@_backend_object_int
516 }
517 \cs_new_protected:Npn \pdf_object_write_indexed:nnnn #1#2#3#4
518 {
519 \exp_args:Ne \@@_backend_object_write:nnn
520 { \@@_object_retrieve:ne {#1} { \int_eval:n {#2} } } {#3} {#4}
521 \bool_gset_true:N \g_@@_init_bool
522 }
523 \cs_generate_variant:Nn \pdf_object_write_indexed:nnnn { nnne }
524 \cs_new:Npn \pdf_object_ref_indexed:nn #1#2
525 {
526 \exp_args:Ne \@@_backend_object_ref:n
527 { \@@_object_retrieve:ne {#1} { \int_eval:n {#2} } }
528 }
529 \cs_new:Npn \__kernel_pdf_object_id_indexed:nn #1#2
530 {
531 \exp_args:Ne \@@_backend_object_id:n
532 { \@@_object_retrieve:ne {#1} { \int_eval:n {#2} } }
533 }
534 %</code>
535 % \end{macrocode}
536 % \end{macro}
537 % \end{macro}
538 % \end{macro}
539 % \end{macro}
540 % \begin{macro}{\@@_object_record:nnN, \@@_object_record:neN}
541 % \begin{macro}[EXP]{\@@_object_retrieve:nn}
542 % \begin{macro}{\@@_object_record:NnN}
543 % \begin{macro}[EXP]{\@@_object_retrieve:Nn}
544 % Again we split for Lua: the same idea as above but with nested tables.
545 % As we've arranged above that the \TeX{} code passes a braced number,
546 % we can use |tonumber(scan_string())| rather than |scan_int()|
547 % for the index.
548 % \begin{macrocode}
549 %<*lua>
550
551 luacmd('@@_object_record:nnN', function()
552 local name = scan_string()
553 local index = tonumber(scan_string())
554 local n = scan_int()
555 @@_objects_indexed[name] = @@_objects_indexed[name] or {}
556 @@_objects_indexed[name][index] = n
557 end,'protected','global')
558
559 luacmd('@@_object_retrieve:nn', function()
560 local name = scan_string()
561 local index = tonumber(scan_string())
562 return cprint(12,tostring(object_id(name,index)))
563 end,'global')
564
565 %</lua>
566 % \end{macrocode}
567 % The non-Lua approach is to divide the range into blocks, and store in integer
568 % arrays that can simulate dynamic assignment.
569 % \begin{macrocode}
570 %<*code>
571 \sys_if_engine_luatex:F
572 {
573 \cs_new_protected:Npn \@@_object_record:nnN #1#2#3
574 {
575 \use:e
576 {
577 \@@_object_record:NnN
578 \@@_object_index_split:nn {#1} {#2}
579 \exp_not:N #3
580 }
581 }
582 \cs_new_protected:Npn \@@_object_record:NnN #1#2#3
583 {
584 \intarray_if_exist:NF #1
585 { \intarray_new:Nn #1 \c_@@_object_block_size_int }
586 \intarray_gset:Nnn #1 {#2} #3
587 }
588 \cs_new:Npn \@@_object_retrieve:nn #1#2
589 {
590 \use:e
591 {
592 \exp_not:N \@@_object_retrieve:Nn
593 \@@_object_index_split:nn {#1} {#2}
594 }
595 }
596 \cs_new:Npn \@@_object_retrieve:Nn #1#2
597 { \intarray_item:Nn #1 {#2} }
598 % \end{macrocode}
599 % As we want blocks to start from one, and within the block for the top value
600 % to be \enquote{in} the block, we do a little bit of manipulation. By shifting
601 % down by one, we keep the values \enquote{in} the block, then we adjust the
602 % block/index number to get back on track.
603 % \begin{macrocode}
604 \cs_new:Npn \@@_object_index_split:nn #1#2
605 {
606 \exp_not:c
607 {
608 g_@@_object_ #1 _
609 \int_eval:n
610 {
611 \int_div_truncate:nn { #2 - 1 }
612 \c_@@_object_block_size_int + 1
613 }
614 _intarray
615 }
616 {
617 \int_eval:n
618 { \int_mod:nn { #2 - 1 } \c_@@_object_block_size_int + 1 }
619 }
620 }
621 % \end{macrocode}
622 % \end{macro}
623 % \end{macro}
624 % \end{macro}
625 % \end{macro}
626 % \begin{variable}{\c_@@_object_block_size_int}
627 % Sets the block size used for managing indexed objects.
628 % \begin{macrocode}
629 \int_const:Nn \c_@@_object_block_size_int { 10000 }
630 }
631 % \end{macrocode}
632 % \end{variable}
633 % \begin{macro}{\@@_object_record:neN}
634 % \begin{macro}[EXP]{\@@_object_retrieve:ne}
635 % Common variants.
636 % \begin{macrocode}
637 \cs_generate_variant:Nn \@@_object_record:nnN { ne }
638 \cs_generate_variant:Nn \@@_object_retrieve:nn { ne }
639 % \end{macrocode}
640 % \end{macro}
641 % \end{macro}
642 %
643 % \begin{macro}
644 % {
645 % \pdf_object_unnamed_write:nn, \pdf_object_unnamed_write:ne,
646 % \pdf_object_unnamed_write:nx
647 % }
648 % No tracking needed here.
649 % \begin{macrocode}
650 \cs_new_protected:Npn \pdf_object_unnamed_write:nn #1#2
651 {
652 \exp_args:Ne \@@_backend_object_now:nn {#1} {#2}
653 \bool_gset_true:N \g_@@_init_bool
654 }
655 \cs_generate_variant:Nn \pdf_object_unnamed_write:nn { ne , nx }
656 % \end{macrocode}
657 % \end{macro}
658 %
659 % \begin{macro}{\pdf_object_ref_last:}
660 % A one-step wrapper for consistency.
661 % \begin{macrocode}
662 \cs_new:Npn \pdf_object_ref_last: { \@@_backend_object_last: }
663 % \end{macrocode}
664 % \end{macro}
665 %
666 % \begin{macro}{\pdf_pageobject_ref:n}
667 % \begin{macrocode}
668 \cs_new:Npn \pdf_pageobject_ref:n #1
669 { \exp_args:Ne \@@_backend_pageobject_ref:n {#1} }
670 % \end{macrocode}
671 % \end{macro}
672 %
673 % \subsection{Version}
674 %
675 % \begin{macro}[pTF,EXP]{\pdf_version_compare:Nn}
676 % \begin{macro}
677 % {
678 % @@_version_compare_=:w ,
679 % @@_version_compare_<:w ,
680 % @@_version_compare_>:w
681 % }
682 % To compare version, we need to split the given value then deal with both
683 % major and minor version
684 % \begin{macrocode}
685 \prg_new_conditional:Npnn \pdf_version_compare:Nn #1#2 { p , T , F , TF }
686 { \use:c { @@_version_compare_ #1 :w } #2 . . \s_@@_stop }
687 \cs_new:cpn { @@_version_compare_=:w } #1 . #2 . #3 \s_@@_stop
688 {
689 \bool_lazy_and:nnTF
690 { \int_compare_p:nNn \@@_backend_version_major: = {#1} }
691 { \int_compare_p:nNn \@@_backend_version_minor: = {#2} }
692 { \prg_return_true: }
693 { \prg_return_false: }
694 }
695 \cs_new:cpn { @@_version_compare_<:w } #1 . #2 . #3 \s_@@_stop
696 {
697 \bool_lazy_or:nnTF
698 { \int_compare_p:nNn \@@_backend_version_major: < {#1} }
699 {
700 \bool_lazy_and_p:nn
701 { \int_compare_p:nNn \@@_backend_version_major: = {#1} }
702 { \int_compare_p:nNn \@@_backend_version_minor: < {#2} }
703 }
704 { \prg_return_true: }
705 { \prg_return_false: }
706 }
707 \cs_new:cpn { @@_version_compare_>:w } #1 . #2 . #3 \s_@@_stop
708 {
709 \bool_lazy_or:nnTF
710 { \int_compare_p:nNn \@@_backend_version_major: > {#1} }
711 {
712 \bool_lazy_and_p:nn
713 { \int_compare_p:nNn \@@_backend_version_major: = {#1} }
714 { \int_compare_p:nNn \@@_backend_version_minor: > {#2} }
715 }
716 { \prg_return_true: }
717 { \prg_return_false: }
718 }
719 % \end{macrocode}
720 % \end{macro}
721 % \end{macro}
722 %
723 % \begin{macro}{\pdf_version_gset:n, \pdf_version_min_gset:n}
724 % \begin{macro}{\@@_version_gset:w}
725 % Split the version and set.
726 % \begin{macrocode}
727 \cs_new_protected:Npn \pdf_version_gset:n #1
728 { \@@_version_gset:w #1 . . \s_@@_stop }
729 \cs_new_protected:Npn \pdf_version_min_gset:n #1
730 {
731 \pdf_version_compare:NnT < {#1}
732 { \@@_version_gset:w #1 . . \s_@@_stop }
733 }
734 \cs_new_protected:Npn \@@_version_gset:w #1 . #2 . #3\s_@@_stop
735 {
736 \bool_if:NF \g_@@_init_bool
737 {
738 \@@_backend_version_major_gset:n {#1}
739 \@@_backend_version_minor_gset:n {#2}
740 }
741 }
742 % \end{macrocode}
743 % \end{macro}
744 % \end{macro}
745 %
746 % \begin{macro}[EXP]{\pdf_version:, \pdf_version_major:, \pdf_version_minor:}
747 % Wrappers.
748 % \begin{macrocode}
749 \cs_new:Npn \pdf_version:
750 { \@@_backend_version_major: . \@@_backend_version_minor: }
751 \cs_new:Npn \pdf_version_major: { \@@_backend_version_major: }
752 \cs_new:Npn \pdf_version_minor: { \@@_backend_version_minor: }
753 % \end{macrocode}
754 % \end{macro}
755 %
756 % \subsection{Page size}
757 %
758 % \begin{macro}{\pdf_pagesize_gset:nn}
759 % \begin{macrocode}
760 \cs_new_protected:Npn \pdf_pagesize_gset:nn #1#2
761 { \@@_backend_pagesize_gset:nn {#1} {#2} }
762 % \end{macrocode}
763 % \end{macro}
764 %
765 % \subsection{Destinations}
766 %
767 % \begin{macro}{\pdf_destination:nn}
768 % \begin{macrocode}
769 \cs_new_protected:Npn \pdf_destination:nn #1#2
770 { \@@_backend_destination:nn {#1} {#2} }
771 % \end{macrocode}
772 % \end{macro}
773 %
774 % \begin{macro}{\pdf_destination:nnnn}
775 % \begin{macrocode}
776 \cs_new_protected:Npn \pdf_destination:nnnn #1#2#3#4
777 {
778 \hbox_to_zero:n
779 { \@@_backend_destination:nnnn {#1} {#2} {#3} {#4} }
780 }
781 % \end{macrocode}
782 % \end{macro}
783 %
784 % \subsection{PDF Page size (media box)}
785 %
786 % Everything here is delayed to the start of the document so that the
787 % backend will definitely be loaded.
788 % \begin{macrocode}
789 \cs_if_exist:NT \@kernel@before@begindocument
790 {
791 \tl_gput_right:Nn \@kernel@before@begindocument
792 {
793 \bool_lazy_all:nT
794 {
795 { \cs_if_exist_p:N \stockheight }
796 { \cs_if_exist_p:N \stockwidth }
797 { \cs_if_exist_p:N \IfPDFManagementActiveTF }
798 { \IfPDFManagementActiveTF { \c_true_bool } { \c_false_bool } }
799 { \int_compare_p:nNn \tex_mag:D = { 1000 } }
800 }
801 {
802 \bool_lazy_and:nnTF
803 { \dim_compare_p:nNn \stockheight > { 0pt } }
804 { \dim_compare_p:nNn \stockwidth > { 0pt } }
805 {
806 \@@_backend_pagesize_gset:nn
807 \stockwidth \stockheight
808 }
809 {
810 \bool_lazy_or:nnF
811 { \dim_compare_p:nNn \stockheight < { 0pt } }
812 { \dim_compare_p:nNn \stockwidth < { 0pt } }
813 {
814 \bool_lazy_and:nnT
815 { \dim_compare_p:nNn \paperheight > { 0pt } }
816 { \dim_compare_p:nNn \paperwidth > { 0pt } }
817 {
818 \@@_backend_pagesize_gset:nn
819 \paperwidth \paperheight
820 }
821 }
822 }
823 }
824 }
825 }
826 % \end{macrocode}
827 %
828 % \begin{macrocode}
829 %</code>
830 % \end{macrocode}
831 %
832 % \end{implementation}
833 %
834 % \PrintIndex