| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3backend-pdfannot.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2025,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-pdfannot} module\\ Backend PDF annotation 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-pdfannot} implementation} |
| 57 |
% |
| 58 |
% \begin{macrocode} |
| 59 |
%<*package> |
| 60 |
%<@@=pdfannot> |
| 61 |
% \end{macrocode} |
| 62 |
% |
| 63 |
% \subsection{\texttt{dvips} backend} |
| 64 |
% |
| 65 |
% \begin{macrocode} |
| 66 |
%<*dvips> |
| 67 |
% \end{macrocode} |
| 68 |
% |
| 69 |
% In \texttt{dvips}, annotations have to be constructed manually. As such, |
| 70 |
% we need the object code above for some definitions. Here, the PostScript |
| 71 |
% uses the \texttt{pdf} namespace: unlike for \pkg{expl3}, we do not really |
| 72 |
% control the namespacing and also have to cut across PDF-related areas. |
| 73 |
% |
| 74 |
% \begin{variable}{\l_@@_backend_content_box} |
| 75 |
% The content of an annotation. |
| 76 |
% \begin{macrocode} |
| 77 |
\box_new:N \l_@@_backend_content_box |
| 78 |
% \end{macrocode} |
| 79 |
% \end{variable} |
| 80 |
% |
| 81 |
% \begin{variable}{\l_@@_backend_model_box} |
| 82 |
% For creating model sizing for links. |
| 83 |
% \begin{macrocode} |
| 84 |
\box_new:N \l_@@_backend_model_box |
| 85 |
% \end{macrocode} |
| 86 |
% \end{variable} |
| 87 |
% |
| 88 |
% \begin{variable}{\g_@@_backend_int} |
| 89 |
% Needed to track annotations. |
| 90 |
% \begin{macrocode} |
| 91 |
\int_new:N \g_@@_backend_int |
| 92 |
% \end{macrocode} |
| 93 |
% \end{variable} |
| 94 |
% |
| 95 |
% \begin{macro}{\@@_backend_generic:nnnn, \@@_backend_generic_aux:nnnn} |
| 96 |
% Annotations are objects but they are not in the object data lists. Here, to |
| 97 |
% get the coordinates of the annotation, we need to have the data collected |
| 98 |
% at the PostScript level. That requires a bit of box trickery (effectively a |
| 99 |
% \LaTeXe{} |picture| of zero size). Once the data is collected, use it to |
| 100 |
% set up the annotation border. |
| 101 |
% \begin{macrocode} |
| 102 |
\cs_new_protected:Npn \@@_backend_generic:nnnn #1#2#3#4 |
| 103 |
{ |
| 104 |
\exp_args:Nf \@@_backend_generic_aux:nnnn |
| 105 |
{ \dim_eval:n {#1} } {#2} {#3} {#4} |
| 106 |
} |
| 107 |
\cs_new_protected:Npn \@@_backend_generic_aux:nnnn #1#2#3#4 |
| 108 |
{ |
| 109 |
\box_move_down:nn {#3} |
| 110 |
{ \hbox:n { \__kernel_backend_postscript:n { pdf.save.ll } } } |
| 111 |
\box_move_up:nn {#2} |
| 112 |
{ |
| 113 |
\hbox:n |
| 114 |
{ |
| 115 |
\dim_horizontal:n {#1} |
| 116 |
\__kernel_backend_postscript:n { pdf.save.ur } |
| 117 |
\dim_horizontal:n { -#1 } |
| 118 |
} |
| 119 |
} |
| 120 |
\int_gincr:N \g_@@_backend_int |
| 121 |
\__kernel_backend_postscript:e |
| 122 |
{ |
| 123 |
mark |
| 124 |
/_objdef { pdf.annot \int_use:N \g_@@_backend_int } |
| 125 |
pdf.rect |
| 126 |
#4 ~ |
| 127 |
/ANN ~ |
| 128 |
pdfmark |
| 129 |
} |
| 130 |
} |
| 131 |
% \end{macrocode} |
| 132 |
% \end{macro} |
| 133 |
% |
| 134 |
% \begin{macro}[EXP]{\@@_backend_last:} |
| 135 |
% Provide the last annotation we created: could get tricky of course if |
| 136 |
% other packages are loaded. |
| 137 |
% \begin{macrocode} |
| 138 |
\cs_new:Npn \@@_backend_last: |
| 139 |
{ { pdf.annot \int_use:N \g_@@_backend_int } } |
| 140 |
% \end{macrocode} |
| 141 |
% \end{macro} |
| 142 |
% |
| 143 |
% \begin{variable}{\g_@@_backend_link_int} |
| 144 |
% To track annotations which are links. |
| 145 |
% \begin{macrocode} |
| 146 |
\int_new:N \g_@@_backend_link_int |
| 147 |
% \end{macrocode} |
| 148 |
% \end{variable} |
| 149 |
% |
| 150 |
% \begin{variable}{\g_@@_backend_link_dict_tl} |
| 151 |
% To pass information to the end-of-link function. |
| 152 |
% \begin{macrocode} |
| 153 |
\tl_new:N \g_@@_backend_link_dict_tl |
| 154 |
% \end{macrocode} |
| 155 |
% \end{variable} |
| 156 |
% |
| 157 |
% \begin{variable}{\g_@@_backend_link_sf_int} |
| 158 |
% Needed to save/restore space factor, which is needed to deal with the face |
| 159 |
% we need a box. |
| 160 |
% \begin{macrocode} |
| 161 |
\int_new:N \g_@@_backend_link_sf_int |
| 162 |
% \end{macrocode} |
| 163 |
% \end{variable} |
| 164 |
% |
| 165 |
% \begin{variable}{\g_@@_backend_link_math_bool} |
| 166 |
% Needed to save/restore math mode. |
| 167 |
% \begin{macrocode} |
| 168 |
\bool_new:N \g_@@_backend_link_math_bool |
| 169 |
% \end{macrocode} |
| 170 |
% \end{variable} |
| 171 |
% |
| 172 |
% \begin{variable}{\g_@@_backend_link_bool} |
| 173 |
% Track link formation: we cannot nest at all. |
| 174 |
% \begin{macrocode} |
| 175 |
\bool_new:N \g_@@_backend_link_bool |
| 176 |
% \end{macrocode} |
| 177 |
% \end{variable} |
| 178 |
% |
| 179 |
% \begin{variable}{\l_@@_backend_breaklink_pdfmark_tl} |
| 180 |
% Swappable content for link breaking. |
| 181 |
% \begin{macrocode} |
| 182 |
\tl_new:N \l_@@_backend_breaklink_pdfmark_tl |
| 183 |
\tl_set:Nn \l_@@_backend_breaklink_pdfmark_tl { pdfmark } |
| 184 |
% \end{macrocode} |
| 185 |
% \end{variable} |
| 186 |
% |
| 187 |
% \begin{macro}{\@@_backend_breaklink_postscript:n} |
| 188 |
% To allow dropping material unless link breaking is active. |
| 189 |
% \begin{macrocode} |
| 190 |
\cs_new_protected:Npn \@@_backend_breaklink_postscript:n #1 { } |
| 191 |
% \end{macrocode} |
| 192 |
% \end{macro} |
| 193 |
% |
| 194 |
% \begin{macro}{\@@_backend_breaklink_usebox:N} |
| 195 |
% Swappable box unpacking or use. |
| 196 |
% \begin{macrocode} |
| 197 |
\cs_new_eq:NN \@@_backend_breaklink_usebox:N \box_use:N |
| 198 |
% \end{macrocode} |
| 199 |
% \end{macro} |
| 200 |
% |
| 201 |
% \begin{macro} |
| 202 |
% {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw} |
| 203 |
% \begin{macro}{\@@_backend_link:nw, \@@_backend_link_aux:nw} |
| 204 |
% \begin{macro}{\@@_backend_link_end:, \@@_backend_link_end_aux:} |
| 205 |
% \begin{macro}{\@@_backend_link_minima:} |
| 206 |
% \begin{macro}{\@@_backend_link_outerbox:n} |
| 207 |
% \begin{macro}{\@@_backend_link_sf_save:, \@@_backend_link_sf_restore:} |
| 208 |
% Links are created like annotations but with dedicated code to allow for |
| 209 |
% adjusting the size of the rectangle. In contrast to \pkg{hyperref}, we |
| 210 |
% grab the link content as a box which can then unbox: this allows the same |
| 211 |
% interface as for \pdfTeX{}. |
| 212 |
% |
| 213 |
% Notice that the link setup here uses |/Action| not |/A|. That is because |
| 214 |
% Distiller \emph{requires} this trigger word, rather than a \enquote{raw} |
| 215 |
% PDF dictionary key (Ghostscript can handle either form). |
| 216 |
% |
| 217 |
% Taking the idea of |evenboxes| from \pkg{hypdvips}, we implement a minimum |
| 218 |
% box height and depth for link placement. This means that \enquote{underlining} |
| 219 |
% with a hyperlink will generally give an even appearance. However, to ensure |
| 220 |
% that the full content is always above the link border, we do not allow |
| 221 |
% this to be negative (contrast \pkg{hypdvips} approach). The result should |
| 222 |
% be similar to \pdfTeX{} in the vast majority of foreseeable cases. |
| 223 |
% |
| 224 |
% The object number for a link is saved separately from the rest of the |
| 225 |
% dictionary as this allows us to insert it just once, at either an |
| 226 |
% unbroken link or only in the first line of a broken one. That makes the |
| 227 |
% code clearer but also avoids a low-level PostScript error with the code |
| 228 |
% as taken from \pkg{hypdvips}. |
| 229 |
% |
| 230 |
% Getting the outer dimensions of the text area may be better using a two-pass |
| 231 |
% approach and |\tex_savepos:D|. That plus generic mode are still to re-examine. |
| 232 |
% \begin{macrocode} |
| 233 |
\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2 |
| 234 |
{ |
| 235 |
\@@_backend_link_begin:nw |
| 236 |
{ #1 /Subtype /Link /Action << /S /GoTo /D ( #2 ) >> } |
| 237 |
} |
| 238 |
\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2 |
| 239 |
{ \@@_backend_link_begin:nw {#1#2} } |
| 240 |
\cs_new_protected:Npn \@@_backend_link_begin:nw #1 |
| 241 |
{ |
| 242 |
\bool_if:NF \g_@@_backend_link_bool |
| 243 |
{ \@@_backend_link_begin_aux:nw {#1} } |
| 244 |
} |
| 245 |
% \end{macrocode} |
| 246 |
% The definition of |pdf.link.dict| here is needed as there is code in the |
| 247 |
% PostScript headers for breaking links, and that can only work with this |
| 248 |
% available. |
| 249 |
% \begin{macrocode} |
| 250 |
\cs_new_protected:Npn \@@_backend_link_begin_aux:nw #1 |
| 251 |
{ |
| 252 |
\bool_gset_true:N \g_@@_backend_link_bool |
| 253 |
\__kernel_backend_postscript:n |
| 254 |
{ /pdf.link.dict ( #1 ) def } |
| 255 |
\tl_gset:Nn \g_@@_backend_link_dict_tl {#1} |
| 256 |
\@@_backend_link_sf_save: |
| 257 |
\mode_if_math:TF |
| 258 |
{ \bool_gset_true:N \g_@@_backend_link_math_bool } |
| 259 |
{ \bool_gset_false:N \g_@@_backend_link_math_bool } |
| 260 |
\hbox_set:Nw \l_@@_backend_content_box |
| 261 |
\@@_backend_link_sf_restore: |
| 262 |
\bool_if:NT \g_@@_backend_link_math_bool |
| 263 |
{ \c_math_toggle_token } |
| 264 |
} |
| 265 |
\cs_new_protected:Npn \@@_backend_link_end: |
| 266 |
{ |
| 267 |
\bool_if:NT \g_@@_backend_link_bool |
| 268 |
{ \@@_backend_link_end_aux: } |
| 269 |
} |
| 270 |
\cs_new_protected:Npn \@@_backend_link_end_aux: |
| 271 |
{ |
| 272 |
\bool_if:NT \g_@@_backend_link_math_bool |
| 273 |
{ \c_math_toggle_token } |
| 274 |
\@@_backend_link_sf_save: |
| 275 |
\hbox_set_end: |
| 276 |
\@@_backend_link_minima: |
| 277 |
\hbox_set:Nn \l_@@_backend_model_box { Gg } |
| 278 |
\exp_args:Ne \@@_backend_link_outerbox:n |
| 279 |
{ |
| 280 |
\int_if_odd:nTF { \value { page } } |
| 281 |
{ \oddsidemargin } |
| 282 |
{ \evensidemargin } |
| 283 |
} |
| 284 |
\box_move_down:nn { \box_dp:N \l_@@_backend_content_box } |
| 285 |
{ \hbox:n { \__kernel_backend_postscript:n { pdf.save.linkll } } } |
| 286 |
\@@_backend_breaklink_postscript:n { pdf.bordertracking.begin } |
| 287 |
\@@_backend_breaklink_usebox:N \l_@@_backend_content_box |
| 288 |
\@@_backend_breaklink_postscript:n { pdf.bordertracking.end } |
| 289 |
\box_move_up:nn { \box_ht:N \l_@@_backend_content_box } |
| 290 |
{ |
| 291 |
\hbox:n |
| 292 |
{ \__kernel_backend_postscript:n { pdf.save.linkur } } |
| 293 |
} |
| 294 |
\int_gincr:N \g_@@_backend_int |
| 295 |
\int_gset_eq:NN \g_@@_backend_link_int \g_@@_backend_int |
| 296 |
\__kernel_backend_postscript:e |
| 297 |
{ |
| 298 |
mark |
| 299 |
/_objdef { pdf.annot \int_use:N \g_@@_backend_link_int } |
| 300 |
\g_@@_backend_link_dict_tl \c_space_tl |
| 301 |
pdf.rect |
| 302 |
/ANN ~ \l_@@_backend_breaklink_pdfmark_tl |
| 303 |
} |
| 304 |
\@@_backend_link_sf_restore: |
| 305 |
\bool_gset_false:N \g_@@_backend_link_bool |
| 306 |
} |
| 307 |
\cs_new_protected:Npn \@@_backend_link_minima: |
| 308 |
{ |
| 309 |
\hbox_set:Nn \l_@@_backend_model_box { Gg } |
| 310 |
\__kernel_backend_postscript:e |
| 311 |
{ |
| 312 |
/pdf.linkdp.pad ~ |
| 313 |
\dim_to_decimal:n |
| 314 |
{ |
| 315 |
\dim_max:nn |
| 316 |
{ |
| 317 |
\box_dp:N \l_@@_backend_model_box |
| 318 |
- \box_dp:N \l_@@_backend_content_box |
| 319 |
} |
| 320 |
{ 0pt } |
| 321 |
} ~ |
| 322 |
pdf.pt.dvi ~ def |
| 323 |
/pdf.linkht.pad ~ |
| 324 |
\dim_to_decimal:n |
| 325 |
{ |
| 326 |
\dim_max:nn |
| 327 |
{ |
| 328 |
\box_ht:N \l_@@_backend_model_box |
| 329 |
- \box_ht:N \l_@@_backend_content_box |
| 330 |
} |
| 331 |
{ 0pt } |
| 332 |
} ~ |
| 333 |
pdf.pt.dvi ~ def |
| 334 |
} |
| 335 |
} |
| 336 |
\cs_new_protected:Npn \@@_backend_link_outerbox:n #1 |
| 337 |
{ |
| 338 |
\__kernel_backend_postscript:e |
| 339 |
{ |
| 340 |
/pdf.outerbox |
| 341 |
[ |
| 342 |
\dim_to_decimal:n {#1} ~ |
| 343 |
\dim_to_decimal:n { -\box_dp:N \l_@@_backend_model_box } ~ |
| 344 |
\dim_to_decimal:n { #1 + \textwidth } ~ |
| 345 |
\dim_to_decimal:n { \box_ht:N \l_@@_backend_model_box } |
| 346 |
] |
| 347 |
[ exch { pdf.pt.dvi } forall ] def |
| 348 |
/pdf.baselineskip ~ |
| 349 |
\dim_to_decimal:n { \tex_baselineskip:D } ~ dup ~ 0 ~ gt |
| 350 |
{ pdf.pt.dvi ~ def } |
| 351 |
{ pop ~ pop } |
| 352 |
ifelse |
| 353 |
} |
| 354 |
} |
| 355 |
\cs_new_protected:Npn \@@_backend_link_sf_save: |
| 356 |
{ |
| 357 |
\int_gset:Nn \g_@@_backend_link_sf_int |
| 358 |
{ |
| 359 |
\mode_if_horizontal:TF |
| 360 |
{ \tex_spacefactor:D } |
| 361 |
{ 0 } |
| 362 |
} |
| 363 |
} |
| 364 |
\cs_new_protected:Npn \@@_backend_link_sf_restore: |
| 365 |
{ |
| 366 |
\mode_if_horizontal:T |
| 367 |
{ |
| 368 |
\int_compare:nNnT \g_@@_backend_link_sf_int > { 0 } |
| 369 |
{ \int_set:Nn \tex_spacefactor:D \g_@@_backend_link_sf_int } |
| 370 |
} |
| 371 |
} |
| 372 |
% \end{macrocode} |
| 373 |
% \end{macro} |
| 374 |
% \end{macro} |
| 375 |
% \end{macro} |
| 376 |
% \end{macro} |
| 377 |
% \end{macro} |
| 378 |
% \end{macro} |
| 379 |
% |
| 380 |
% Hooks to allow link breaking: something will be needed in format mode |
| 381 |
% at some stage. At present this code is disabled, pending a decision to |
| 382 |
% activate. |
| 383 |
% \begin{macrocode} |
| 384 |
\use_none:nnn |
| 385 |
\cs_if_exist:NT \hook_gput_code:nnn |
| 386 |
{ |
| 387 |
\hook_gput_code:nnn { build/column/after } { backend } |
| 388 |
{ |
| 389 |
\box_if_empty:NF \l_shipout_box |
| 390 |
{ |
| 391 |
\vbox_set:Nn \l_shipout_box |
| 392 |
{ |
| 393 |
\__kernel_backend_postscript:n |
| 394 |
{ |
| 395 |
pdf.globaldict /pdf.brokenlink.rect ~ known |
| 396 |
{ pdf.bordertracking.continue } |
| 397 |
if |
| 398 |
} |
| 399 |
\vbox_unpack_drop:N \l_shipout_box |
| 400 |
\__kernel_backend_postscript:n |
| 401 |
{ pdf.bordertracking.endpage } |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
\tl_set:Nn \l_@@_backend_breaklink_pdfmark_tl { pdf.pdfmark } |
| 406 |
\cs_set_eq:NN \@@_backend_breaklink_postscript:n |
| 407 |
\__kernel_backend_postscript:n |
| 408 |
\cs_set_eq:NN \@@_backend_breaklink_usebox:N \hbox_unpack:N |
| 409 |
} |
| 410 |
% \end{macrocode} |
| 411 |
% |
| 412 |
% \begin{macro}{\@@_backend_link_last:} |
| 413 |
% The same as annotations, but with a custom integer. |
| 414 |
% \begin{macrocode} |
| 415 |
\cs_new:Npn \@@_backend_link_last: |
| 416 |
{ { pdf.annot \int_use:N \g_@@_backend_link_int } } |
| 417 |
% \end{macrocode} |
| 418 |
% \end{macro} |
| 419 |
% |
| 420 |
% \begin{macro}{\@@_backend_link_margin:n} |
| 421 |
% Convert to big points and pass to PostScript. |
| 422 |
% \begin{macrocode} |
| 423 |
\cs_new_protected:Npn \@@_backend_link_margin:n #1 |
| 424 |
{ |
| 425 |
\__kernel_backend_postscript:e |
| 426 |
{ |
| 427 |
/pdf.linkmargin { \dim_to_decimal:n {#1} ~ pdf.pt.dvi } def |
| 428 |
} |
| 429 |
} |
| 430 |
% \end{macrocode} |
| 431 |
% \end{macro} |
| 432 |
% |
| 433 |
% \begin{macro}{\@@_backend_link_on:, \@@_backend_link_off:} |
| 434 |
% \begin{macrocode} |
| 435 |
\cs_new_protected:Npn \@@_backend_link_on: { } |
| 436 |
\cs_new_protected:Npn \@@_backend_link_off: { } |
| 437 |
% \end{macrocode} |
| 438 |
% \end{macro} |
| 439 |
% |
| 440 |
% \begin{macrocode} |
| 441 |
%</dvips> |
| 442 |
% \end{macrocode} |
| 443 |
% |
| 444 |
% \subsection{\LuaTeX{} and \pdfTeX{} backend} |
| 445 |
% |
| 446 |
% \begin{macrocode} |
| 447 |
%<*luatex|pdftex> |
| 448 |
% \end{macrocode} |
| 449 |
% |
| 450 |
% \begin{macro}{\@@_backend_generic:nnnn} |
| 451 |
% Simply pass the raw data through, just dealing with evaluation of dimensions. |
| 452 |
% \begin{macrocode} |
| 453 |
\cs_new_protected:Npn \@@_backend_generic:nnnn #1#2#3#4 |
| 454 |
{ |
| 455 |
%<*luatex> |
| 456 |
\tex_pdfextension:D annot ~ |
| 457 |
%</luatex> |
| 458 |
%<*pdftex> |
| 459 |
\tex_pdfannot:D |
| 460 |
%</pdftex> |
| 461 |
width ~ \dim_eval:n {#1} ~ |
| 462 |
height ~ \dim_eval:n {#2} ~ |
| 463 |
depth ~ \dim_eval:n {#3} ~ |
| 464 |
{#4} |
| 465 |
} |
| 466 |
% \end{macrocode} |
| 467 |
% \end{macro} |
| 468 |
% |
| 469 |
% \begin{macro}[EXP]{\@@_backend_last:} |
| 470 |
% A tiny amount of extra data gets added here; we use \texttt{e}-type |
| 471 |
% expansion to get the space in the right place and form. The \enquote{extra} |
| 472 |
% space in the \LuaTeX{} version is \emph{required} as it is consumed in |
| 473 |
% finding the end of the keyword. |
| 474 |
% \begin{macrocode} |
| 475 |
\cs_new:Npe \@@_backend_last: |
| 476 |
{ |
| 477 |
\exp_not:N \int_value:w |
| 478 |
%<*luatex> |
| 479 |
\exp_not:N \tex_pdffeedback:D lastannot ~ |
| 480 |
%</luatex> |
| 481 |
%<*pdftex> |
| 482 |
\exp_not:N \tex_pdflastannot:D |
| 483 |
%</pdftex> |
| 484 |
\c_space_tl 0 ~ R |
| 485 |
} |
| 486 |
% \end{macrocode} |
| 487 |
% \end{macro} |
| 488 |
% |
| 489 |
% \begin{macro} |
| 490 |
% {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw} |
| 491 |
% \begin{macro}{\@@_backend_link_begin:nnnw} |
| 492 |
% \begin{macro}{\@@_backend_link_end:} |
| 493 |
% Links are all created using the same internals. |
| 494 |
% \begin{macrocode} |
| 495 |
\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2 |
| 496 |
{ \@@_backend_link_begin:nnnw {#1} { goto~name } {#2} } |
| 497 |
\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2 |
| 498 |
{ \@@_backend_link_begin:nnnw {#1} { user } {#2} } |
| 499 |
\cs_new_protected:Npn \@@_backend_link_begin:nnnw #1#2#3 |
| 500 |
{ |
| 501 |
%<*luatex> |
| 502 |
\tex_pdfextension:D startlink ~ |
| 503 |
%</luatex> |
| 504 |
%<*pdftex> |
| 505 |
\tex_pdfstartlink:D |
| 506 |
%</pdftex> |
| 507 |
attr {#1} |
| 508 |
#2 {#3} |
| 509 |
} |
| 510 |
\cs_new_protected:Npn \@@_backend_link_end: |
| 511 |
{ |
| 512 |
%<*luatex> |
| 513 |
\tex_pdfextension:D endlink \scan_stop: |
| 514 |
%</luatex> |
| 515 |
%<*pdftex> |
| 516 |
\tex_pdfendlink:D |
| 517 |
%</pdftex> |
| 518 |
} |
| 519 |
% \end{macrocode} |
| 520 |
% \end{macro} |
| 521 |
% \end{macro} |
| 522 |
% \end{macro} |
| 523 |
% |
| 524 |
% \begin{macro}{\@@_backend_link_last:} |
| 525 |
% Formatted for direct use. |
| 526 |
% \begin{macrocode} |
| 527 |
\cs_new:Npe \@@_backend_link_last: |
| 528 |
{ |
| 529 |
\exp_not:N \int_value:w |
| 530 |
%<*luatex> |
| 531 |
\exp_not:N \tex_pdffeedback:D lastlink ~ |
| 532 |
%</luatex> |
| 533 |
%<*pdftex> |
| 534 |
\exp_not:N \tex_pdflastlink:D |
| 535 |
%</pdftex> |
| 536 |
\c_space_tl 0 ~ R |
| 537 |
} |
| 538 |
% \end{macrocode} |
| 539 |
% \end{macro} |
| 540 |
% |
| 541 |
% \begin{macro}{\@@_backend_link_margin:n} |
| 542 |
% A simple task: pass the data to the primitive. |
| 543 |
% \begin{macrocode} |
| 544 |
\cs_new_protected:Npn \@@_backend_link_margin:n #1 |
| 545 |
{ |
| 546 |
%<*luatex> |
| 547 |
\tex_pdfvariable:D linkmargin |
| 548 |
%</luatex> |
| 549 |
%<*pdftex> |
| 550 |
\tex_pdflinkmargin:D |
| 551 |
%</pdftex> |
| 552 |
\dim_eval:n {#1} \scan_stop: |
| 553 |
} |
| 554 |
% \end{macrocode} |
| 555 |
% \end{macro} |
| 556 |
% |
| 557 |
% \begin{macro}{\@@_backend_link_on:, \@@_backend_link_off:} |
| 558 |
% Separate definitions for the two engines. |
| 559 |
% \begin{macrocode} |
| 560 |
\cs_new_protected:Npn \@@_backend_link_on: |
| 561 |
%<*luatex> |
| 562 |
{ \tex_pdfextension:D linkstate 0 ~ } |
| 563 |
%</luatex> |
| 564 |
%<*pdftex> |
| 565 |
{ \tex_pdfrunninglinkon:D } |
| 566 |
%</pdftex> |
| 567 |
\cs_new_protected:Npn \@@_backend_link_off: |
| 568 |
%<*luatex> |
| 569 |
{ \tex_pdfextension:D linkstate 1 ~ } |
| 570 |
%</luatex> |
| 571 |
%<*pdftex> |
| 572 |
{ \tex_pdfrunninglinkoff:D } |
| 573 |
%</pdftex> |
| 574 |
% \end{macrocode} |
| 575 |
% \end{macro} |
| 576 |
% |
| 577 |
% \begin{macrocode} |
| 578 |
%</luatex|pdftex> |
| 579 |
% \end{macrocode} |
| 580 |
% |
| 581 |
% \subsection{\texttt{dvipdfmx} backend} |
| 582 |
% |
| 583 |
% \begin{macrocode} |
| 584 |
%<*dvipdfmx|xetex> |
| 585 |
% \end{macrocode} |
| 586 |
% |
| 587 |
% \begin{macro}{\@@_backend:n, \@@_backend:e} |
| 588 |
% A generic function for the backend PDF specials |
| 589 |
% \begin{macrocode} |
| 590 |
\cs_new_protected:Npe \@@_backend:n #1 |
| 591 |
{ \__kernel_backend_literal:n { pdf: #1 } } |
| 592 |
\cs_generate_variant:Nn \@@_backend:n { e } |
| 593 |
% \end{macrocode} |
| 594 |
% \end{macro} |
| 595 |
% |
| 596 |
% \begin{variable}{\g_@@_backend_int} |
| 597 |
% Annotations are objects: but made with a separate tracker integer. |
| 598 |
% \begin{macrocode} |
| 599 |
\int_new:N \g_@@_backend_int |
| 600 |
% \end{macrocode} |
| 601 |
% \end{variable} |
| 602 |
% |
| 603 |
% \begin{macro}{\@@_backend_generic:nnnn} |
| 604 |
% Simply pass the raw data through, just dealing with evaluation of dimensions. |
| 605 |
% \begin{macrocode} |
| 606 |
\cs_new_protected:Npn \@@_backend_generic:nnnn #1#2#3#4 |
| 607 |
{ |
| 608 |
\int_gincr:N \g_@@_backend_int |
| 609 |
\@@_backend:e |
| 610 |
{ |
| 611 |
ann ~ @pdfannot \int_use:N \g_@@_backend_int \c_space_tl |
| 612 |
width ~ \dim_eval:n {#1} ~ |
| 613 |
height ~ \dim_eval:n {#2} ~ |
| 614 |
depth ~ \dim_eval:n {#3} ~ |
| 615 |
<< /Type /Annot #4 >> |
| 616 |
} |
| 617 |
} |
| 618 |
% \end{macrocode} |
| 619 |
% \end{macro} |
| 620 |
% |
| 621 |
% \begin{macro}{\@@_backend_last:} |
| 622 |
% \begin{macrocode} |
| 623 |
\cs_new:Npn \@@_backend_last: |
| 624 |
{ @pdfannot \int_use:N \g_@@_backend_int } |
| 625 |
% \end{macrocode} |
| 626 |
% \end{macro} |
| 627 |
% |
| 628 |
% \begin{variable}{\g_@@_backend_link_int} |
| 629 |
% To track annotations which are links. |
| 630 |
% \begin{macrocode} |
| 631 |
\int_new:N \g_@@_backend_link_int |
| 632 |
% \end{macrocode} |
| 633 |
% \end{variable} |
| 634 |
% |
| 635 |
% \begin{macro} |
| 636 |
% {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw} |
| 637 |
% \begin{macro}{\@@_backend_link_begin:n} |
| 638 |
% \begin{macro}{\@@_backend_link_end:} |
| 639 |
% All created using the same internals. |
| 640 |
% \begin{macrocode} |
| 641 |
\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2 |
| 642 |
{ |
| 643 |
\@@_backend_link_begin:n |
| 644 |
{ #1 /Subtype /Link /A << /S /GoTo /D ( #2 ) >> } |
| 645 |
} |
| 646 |
\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2 |
| 647 |
{ \@@_backend_link_begin:n {#1#2} } |
| 648 |
\cs_new_protected:Npe \@@_backend_link_begin:n #1 |
| 649 |
{ |
| 650 |
\int_gincr:N \exp_not:N \g_@@_backend_int |
| 651 |
\int_gset_eq:NN \exp_not:N \g_@@_backend_link_int |
| 652 |
\exp_not:N \g_@@_backend_int |
| 653 |
\@@_backend:e |
| 654 |
{ |
| 655 |
bann ~ |
| 656 |
@pdfannot |
| 657 |
\exp_not:N \int_use:N \exp_not:N \g_@@_backend_link_int |
| 658 |
\c_space_tl |
| 659 |
<< |
| 660 |
/Type /Annot |
| 661 |
#1 |
| 662 |
>> |
| 663 |
} |
| 664 |
} |
| 665 |
\cs_new_protected:Npn \@@_backend_link_end: |
| 666 |
{ \@@_backend:n { eann } } |
| 667 |
% \end{macrocode} |
| 668 |
% \end{macro} |
| 669 |
% \end{macro} |
| 670 |
% \end{macro} |
| 671 |
% |
| 672 |
% \begin{macro}{\@@_backend_link_last:} |
| 673 |
% Available using the backend mechanism with a suitably-recent |
| 674 |
% version. |
| 675 |
% \begin{macrocode} |
| 676 |
\cs_new:Npn \@@_backend_link_last: |
| 677 |
{ @pdfannot \int_use:N \g_@@_backend_link_int } |
| 678 |
% \end{macrocode} |
| 679 |
% \end{macro} |
| 680 |
% |
| 681 |
% \begin{macro}{\@@_backend_link_margin:n} |
| 682 |
% Pass to \texttt{dvipdfmx}. |
| 683 |
% \begin{macrocode} |
| 684 |
\cs_new_protected:Npn \@@_backend_link_margin:n #1 |
| 685 |
{ \__kernel_backend_literal:e { dvipdfmx:config~g~ \dim_eval:n {#1} } } |
| 686 |
% \end{macrocode} |
| 687 |
% \end{macro} |
| 688 |
% |
| 689 |
% \begin{macro}{\@@_backend_link_on:, \@@_backend_link_off:} |
| 690 |
% \begin{macrocode} |
| 691 |
\cs_new_protected:Npn \@@_backend_link_on: { \@@_backend:n { link } } |
| 692 |
\cs_new_protected:Npn \@@_backend_link_off: { \@@_backend:n { nolink } } |
| 693 |
% \end{macrocode} |
| 694 |
% \end{macro} |
| 695 |
% |
| 696 |
% \begin{macrocode} |
| 697 |
%</dvipdfmx|xetex> |
| 698 |
% \end{macrocode} |
| 699 |
% |
| 700 |
% \subsection{\texttt{dvisvgm} backend} |
| 701 |
% |
| 702 |
% \begin{macrocode} |
| 703 |
%<*dvisvgm> |
| 704 |
% \end{macrocode} |
| 705 |
% |
| 706 |
% \begin{macro}{\@@_backend_generic:nnnn} |
| 707 |
% \begin{macrocode} |
| 708 |
\cs_new_protected:Npn \@@_backend_generic:nnnn #1#2#3#4 { } |
| 709 |
% \end{macrocode} |
| 710 |
% \end{macro} |
| 711 |
% |
| 712 |
% \begin{macro}[EXP]{\@@_backend_last:} |
| 713 |
% \begin{macrocode} |
| 714 |
\cs_new:Npn \@@_backend_last: { } |
| 715 |
% \end{macrocode} |
| 716 |
% \end{macro} |
| 717 |
% |
| 718 |
% \begin{macro} |
| 719 |
% {\@@_backend_link_begin_goto:nnw, \@@_backend_link_begin_user:nnw} |
| 720 |
% \begin{macro}{\@@_backend_link_begin:nnnw} |
| 721 |
% \begin{macro}{\@@_backend_link_end:} |
| 722 |
% \begin{macrocode} |
| 723 |
\cs_new_protected:Npn \@@_backend_link_begin_goto:nnw #1#2 { } |
| 724 |
\cs_new_protected:Npn \@@_backend_link_begin_user:nnw #1#2 { } |
| 725 |
\cs_new_protected:Npn \@@_backend_link_begin:nnnw #1#2#3 { } |
| 726 |
\cs_new_protected:Npn \@@_backend_link_end: { } |
| 727 |
% \end{macrocode} |
| 728 |
% \end{macro} |
| 729 |
% \end{macro} |
| 730 |
% \end{macro} |
| 731 |
% |
| 732 |
% \begin{macro}{\@@_backend_link_last:} |
| 733 |
% \begin{macrocode} |
| 734 |
\cs_new:Npe \@@_backend_link_last: { } |
| 735 |
% \end{macrocode} |
| 736 |
% \end{macro} |
| 737 |
% |
| 738 |
% \begin{macro}{\@@_backend_link_margin:n} |
| 739 |
% \begin{macrocode} |
| 740 |
\cs_new_protected:Npn \@@_backend_link_margin:n #1 { } |
| 741 |
% \end{macrocode} |
| 742 |
% \end{macro} |
| 743 |
% |
| 744 |
% \begin{macro}{\@@_backend_link_on:, \@@_backend_link_off:} |
| 745 |
% For handling places like headers. |
| 746 |
% \begin{macrocode} |
| 747 |
\cs_new_protected:Npn \@@_backend_link_on: { } |
| 748 |
\cs_new_protected:Npn \@@_backend_link_off: { } |
| 749 |
% \end{macrocode} |
| 750 |
% \end{macro} |
| 751 |
% |
| 752 |
% \begin{macrocode} |
| 753 |
%</dvisvgm> |
| 754 |
% \end{macrocode} |
| 755 |
% |
| 756 |
% \subsection{Transitional code} |
| 757 |
% |
| 758 |
% This block is temporary: we have moved the backend functions here to a |
| 759 |
% dedicated prefix. To facilitate that, we turn off DocStrip substitution |
| 760 |
% and handle things manually. |
| 761 |
% |
| 762 |
% \begin{macrocode} |
| 763 |
%<@@=> |
| 764 |
% \end{macrocode} |
| 765 |
% |
| 766 |
% \begin{macrocode} |
| 767 |
\cs_new_eq:NN \__pdf_backend_annotation:nnnn \__pdfannot_backend_generic:nnnn |
| 768 |
\cs_new_eq:NN \__pdf_backend_annotation_last: \__pdfannot_backend_last: |
| 769 |
\clist_map_inline:nn |
| 770 |
{ |
| 771 |
begin_goto:nnw , |
| 772 |
begin_user:nnw , |
| 773 |
begin:nnnw , |
| 774 |
end: , |
| 775 |
last: , |
| 776 |
margin:n |
| 777 |
} |
| 778 |
{ \cs_new_eq:cc { __pdf_backend_link_ #1 } { __pdfannot_backend_link_ #1 } } |
| 779 |
% \end{macrocode} |
| 780 |
% |
| 781 |
% \begin{macrocode} |
| 782 |
%</package> |
| 783 |
% \end{macrocode} |
| 784 |
% |
| 785 |
% \end{implementation} |
| 786 |
% |
| 787 |
% \PrintIndex |