| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3pdfannot.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2021-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 "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 |
%<*driver> |
| 26 |
\DocumentMetadata{tagging=on,pdfstandard=ua-2} |
| 27 |
\documentclass[full]{l3doc} |
| 28 |
\usepackage{latex-lab-testphase-l3doc} |
| 29 |
|
| 30 |
\usepackage{array,booktabs} |
| 31 |
\hypersetup{pdfauthor=The LaTeX Project, |
| 32 |
pdftitle=l3pdfannot (LaTeX PDF management bundle)} |
| 33 |
\begin{document} |
| 34 |
\DocInput{\jobname.dtx} |
| 35 |
\end{document} |
| 36 |
%</driver> |
| 37 |
% \fi |
| 38 |
% \providecommand\hook[1]{\texttt{#1}} |
| 39 |
% \title{^^A |
| 40 |
% The \pkg{l3pdfannot} module\\ Commands for PDF annotations ^^A |
| 41 |
% \\ \LaTeX{} PDF management bundle |
| 42 |
% } |
| 43 |
% |
| 44 |
% \author{^^A |
| 45 |
% The \LaTeX{} Project\thanks |
| 46 |
% {^^A |
| 47 |
% E-mail: |
| 48 |
% \href{mailto:[email protected]} |
| 49 |
% {[email protected]}^^A |
| 50 |
% }^^A |
| 51 |
% } |
| 52 |
% |
| 53 |
% \date{Version 0.97c, released 2026-05-26} |
| 54 |
% |
| 55 |
% \maketitle |
| 56 |
% \begin{documentation} |
| 57 |
% |
| 58 |
% \section{\pkg{l3pdfannot} documentation} |
| 59 |
% This module contains a number of commands to create PDF annotations. |
| 60 |
% The commands are \emph{not} always simple wrappers around primitive commands. |
| 61 |
% To allow external packages to configure links and other annotations, |
| 62 |
% some of the commands have hooks and use shared attribute dictionaries. |
| 63 |
% For these commands the hooks and dictionaries are selected depending on the \meta{type} |
| 64 |
% of the annotation. Currently the module only supports some general commands |
| 65 |
% and link annotations. Commands for other annotations like widgets will be added |
| 66 |
% later. |
| 67 |
% |
| 68 |
% \subsection{dvips specialities} |
| 69 |
% With most engines and backend the content of arguments like \Arg{annot spec} |
| 70 |
% are dictionaries with keys and values which looks like the PDF. |
| 71 |
% With dvips this is different. As it write at first a postscript file which is |
| 72 |
% then interpreted along the rule of the pdfmark reference (and the rules of the postscript |
| 73 |
% language) the handling is in some parts so different that it is difficult to hide |
| 74 |
% this in abstraction like the one of this module. |
| 75 |
% And there is the additional complication that the |
| 76 |
% two postscript processor ghostscript (ps2pdf) and distiller handles some code differently too. |
| 77 |
% |
| 78 |
% For now the following differences have been spotted, it is yet not quite clear |
| 79 |
% how to resolve them |
| 80 |
% \begin{itemize} |
| 81 |
% \item distiller doesn't like it if the action is provided by directly |
| 82 |
% providing the |/A| key with some values. |
| 83 |
% Instead it expects a keyword \texttt{/Action}, which it will |
| 84 |
% then translate to |/A|. For |GoTo| links this has been resolved at the backend level, |
| 85 |
% but for other link types this problem is open. |
| 86 |
% \item ghostscript doesn't like object references as values in some places. |
| 87 |
% The work around here (which is e.g. used by hyperref for GoToR link) is to |
| 88 |
% write the whole dictionary first as an object and to use its reference, but this |
| 89 |
% is something distiller doesn't like, sigh. |
| 90 |
% \item How to escaping text and create unicode can be different. |
| 91 |
% \end{itemize} |
| 92 |
% |
| 93 |
% |
| 94 |
% |
| 95 |
% \subsection{General annotation commands} |
| 96 |
% |
| 97 |
% \begin{function}[added = 2019-09-05, updated = 2020-04-14] |
| 98 |
% { \pdfannot_box:nnnn,\pdfannot_box:nnne } |
| 99 |
% \begin{syntax} |
| 100 |
% \cs{pdfannot_box:nnnn} \Arg{width} \Arg{height} \Arg{depth} \Arg{annot spec} |
| 101 |
% \end{syntax} |
| 102 |
% This creates an \texttt{/Type/Annot} object with the given dimensions. |
| 103 |
% It doesn't use hooks or dictionaries. The annotation doesn't occupy space but |
| 104 |
% as it is a whatsit it can affect spacing. |
| 105 |
% \end{function} |
| 106 |
% |
| 107 |
% \begin{function}[added = 2019-09-05] |
| 108 |
% { \pdfannot_box_ref_last: } |
| 109 |
% \begin{syntax} |
| 110 |
% \cs{pdfannot_box_ref_last:} |
| 111 |
% \end{syntax} |
| 112 |
% This retrieves the object reference of the last box annotation created. |
| 113 |
% \end{function} |
| 114 |
% \subsection{Dictionary for the annotation spec} |
| 115 |
% |
| 116 |
% \meta{annot spec} in the above command can be given in two ways. One way is |
| 117 |
% to enter the needed dictionary keys and values directly: |
| 118 |
% \begin{verbatim} |
| 119 |
% \pdfannot_box:nnnn{1cm}{1cm}{0cm}{/Subtype/Link /Border[0~0~1]} |
| 120 |
% \end{verbatim} |
| 121 |
% |
| 122 |
% A second method is to make use of the dictionary commands provided by \pkg{l3pdfdict}: |
| 123 |
% |
| 124 |
% \begin{verbatim} |
| 125 |
% \pdfdict_new:n {l_my_annot} |
| 126 |
% \pdfdict_put:nnn{l_my_annot}{Subtype}{/Link} |
| 127 |
% \pdfdict_put:nnn{l_my_annot}{Border}{[0~0~1]} |
| 128 |
% \pdfannot_box:nnne{1cm}{1cm}{0cm}{\pdfdict_use:n{l_my_annot}} |
| 129 |
% \end{verbatim} |
| 130 |
% |
| 131 |
% The second method is clearly slower and more to type. But it has the advantage |
| 132 |
% that using such a dictionary makes it easy to add, remove and change entries. |
| 133 |
% It also avoids the potential problem that a key is added twice with different |
| 134 |
% values. This allows to create user interfaces to change settings and |
| 135 |
% also makes it easy to extend the interfaces in case some new setting |
| 136 |
% should be included. For these reasons both the PDF management itself, |
| 137 |
% but also the specific annotation commands in the following sections |
| 138 |
% all make use of such dictionaries. |
| 139 |
% |
| 140 |
% \subsection{Link annotations} |
| 141 |
% Link annotations are special cases of annotations. In the PDF they are identified |
| 142 |
% by an |/Subtype/Link| entry in the dictionary. |
| 143 |
% Link annotations are quite important as many documents contain links, |
| 144 |
% both internal and external. They need a set of special commands for two reasons: |
| 145 |
% |
| 146 |
% At first the content of links are not only boxes. Links can contain line |
| 147 |
% and page breaks (this is normally implemented by the primitive command by |
| 148 |
% creating a set of annotations). |
| 149 |
% |
| 150 |
% At second link annotations are objects that need some |
| 151 |
% \enquote{management} as more than one |
| 152 |
% package wants to configure their look and behaviour. |
| 153 |
% For example \pkg{hyperref}, \pkg{ocgx2} and the code for tagged PDF (currently |
| 154 |
% in \pkg{tagpdf}) all want to add keys and values to the dictionaries of |
| 155 |
% link annotation and code around links. |
| 156 |
% So commands to create link annotations should offer suitable hooks. |
| 157 |
% There are three standard places in a link where such hooks are needed: |
| 158 |
% At the begin (for example for a structure command or color), |
| 159 |
% in the \emph{attr spec} dictionary of the link (for example for the border), and |
| 160 |
% at the end of the link (to close a structure or the color group). |
| 161 |
% For the begin and end hooks of the LaTeX hook management are predefined and used. |
| 162 |
% To add and remove values from the \emph{attr spec} dictionary special |
| 163 |
% commands described below are provided. The link commands switch to horizontal mode |
| 164 |
% as the commands of pdftex and luatex can't be used in vertical mode. |
| 165 |
% |
| 166 |
% \begin{variable}{\c_pdfannot_link_types_seq} |
| 167 |
% There are currently five link types, \texttt{URI}, \texttt{GoToR}, |
| 168 |
% \texttt{Launch}, \texttt{GoTo} or \texttt{Named}, and there are stored in this |
| 169 |
% constant. |
| 170 |
% \end{variable} |
| 171 |
% \begin{variable} |
| 172 |
% { |
| 173 |
% pdfannot/link/TYPE/before, |
| 174 |
% pdfannot/link/TYPE/begin, |
| 175 |
% pdfannot/link/TYPE/end, |
| 176 |
% pdfannot/link/TYPE/after |
| 177 |
% } |
| 178 |
% These are the hooks used by the following commands. TYPE can be one of |
| 179 |
% \texttt{URI}, \texttt{GoToR}, |
| 180 |
% \texttt{Launch}, \texttt{GoTo} or \texttt{Named} |
| 181 |
% \end{variable} |
| 182 |
% \begin{variable} |
| 183 |
% { |
| 184 |
% link/TYPE |
| 185 |
% } |
| 186 |
% These is the name of the dictionary used by the following commands. TYPE can be one of |
| 187 |
% \texttt{URI}, \texttt{GoToR}, |
| 188 |
% \texttt{Launch}, \texttt{GoTo} or \texttt{Named}. The dictionary can be changed |
| 189 |
% by the commands \cs{pdfannot_dict_put:nnn} and friends described below. |
| 190 |
% \end{variable} |
| 191 |
% \begin{function}[added = 2020-03-12, updated = 2020-12-06] |
| 192 |
% { \pdfannot_link:nnn,\pdfannot_link:nen } |
| 193 |
% \begin{syntax} |
| 194 |
% \cs{pdfannot_link:nnn} \Arg{type} \Arg{user action spec} \Arg{link text} |
| 195 |
% \end{syntax} |
| 196 |
% This creates a link around the \meta{link text}. |
| 197 |
% \texttt{/Subtype/Link} is added automatically through the dictionary. |
| 198 |
% \meta{user action spec}\footnote{The wording follows the pdftex documentation}. |
| 199 |
% is provided as a fast method to add dictionary contents, |
| 200 |
% but it should be noted that no provision is taken to avoid clashes with |
| 201 |
% values added through the dictionary. If needed clashing entries should be |
| 202 |
% removed from the dictionary first. Normally the argument is not needed, all |
| 203 |
% entries can be added through the dictionary too. |
| 204 |
% \meta{type} should be one of \texttt{URI}, \texttt{GoToR}, |
| 205 |
% \texttt{Launch}, \texttt{GoTo} or \texttt{Named}. The |GoTo| variant does |
| 206 |
% \emph{not} complain if the destination name is not known like |
| 207 |
% \cs{pdfannot_link_goto_begin:nw}. |
| 208 |
% The attributes stored in the local dictionary |
| 209 |
% \texttt{link/}\meta{type} are inserted as |
| 210 |
% \emph{attr spec} before \meta{user action spec}. |
| 211 |
% The code in the begin and end hook |
| 212 |
% \texttt{pdfannot/link/\meta{type}/before} |
| 213 |
% and \texttt{pdfannot/link/\meta{type}/after} |
| 214 |
% is executed before and after the link (outside the link command) |
| 215 |
% while \texttt{pdfannot/link/\meta{type}/begin} |
| 216 |
% and \texttt{pdfannot/link/\meta{type}/end} are directly around the link |
| 217 |
% text. None of the hooks introduce a group. |
| 218 |
% \meta{type} should normally be identical to the value of the |/S| key |
| 219 |
% in the action dictionary. |
| 220 |
% As example either with a direct action |
| 221 |
% \begin{verbatim} |
| 222 |
% \pdfannot_link:nnn { URI } |
| 223 |
% { |
| 224 |
% /A<< |
| 225 |
% /Type/Action |
| 226 |
% /S/URI |
| 227 |
% /URI(https://www.latex-project.org) |
| 228 |
% >> |
| 229 |
% } |
| 230 |
% { link text} |
| 231 |
% \end{verbatim} |
| 232 |
% Or through a dictionary: |
| 233 |
% \begin{verbatim} |
| 234 |
% \pdfdict_new:n {l_my_action_dict} |
| 235 |
% \pdfdict_put:nnn {l_my_action_dict}{Type}{/Action} |
| 236 |
% \pdfdict_put:nnn {l_my_action_dict}{S}{/URI} |
| 237 |
% \pdfdict_put:nnn {l_my_action_dict}{URI}{(https://www.latex-project.org)} |
| 238 |
% |
| 239 |
% \pdfannot_dict_put:nnn |
| 240 |
% {link/URI} { C } {[1~0~0]} %red border |
| 241 |
% |
| 242 |
% \pdfannot_link:nen { URI } |
| 243 |
% { |
| 244 |
% /A <<\pdfdict_use:n{l_my_action_dict}>> |
| 245 |
% } |
| 246 |
% { link text } |
| 247 |
% \end{verbatim} |
| 248 |
% |
| 249 |
% Or if you want to exclude the possibility of a duplicated /A entry |
| 250 |
% (if the action is already in the link/GoTo dictionary e.g. if you can expect |
| 251 |
% other packages to add a dictionary). An alternative is to ensure that |
| 252 |
% no /A is there by removing it explicitly. |
| 253 |
% |
| 254 |
% \begin{verbatim} |
| 255 |
% \pdfdict_new:n {l_my_action_dict} |
| 256 |
% \pdfdict_put:nnn {l_my_action_dict}{Type}{/Action} |
| 257 |
% \pdfdict_put:nnn {l_my_action_dict}{S}{/URI} |
| 258 |
% \pdfdict_put:nnn {l_my_action_dict}{URI}{(https://www.latex-project.org)} |
| 259 |
% |
| 260 |
% |
| 261 |
% \pdfannot_dict_put:nnn |
| 262 |
% {link/URI} { C } {[1~0~0]} %red border |
| 263 |
% |
| 264 |
% \group_begin: |
| 265 |
% \pdfannot_dict_put:nne {link/GoTo}{A}{<<\pdfdict_use:n{l_my_action_dict}>>} |
| 266 |
% \pdfannot_link:nnn { URI }{}{ link text } |
| 267 |
% \group_end: |
| 268 |
% \end{verbatim} |
| 269 |
% |
| 270 |
% |
| 271 |
% \end{function} |
| 272 |
% \begin{function}[updated = 2020-12-06]{ \pdfannot_link_begin:nnw, \pdfannot_link_end:n } |
| 273 |
% \begin{syntax} |
| 274 |
% \cs{pdfannot_link_begin:nnw} \Arg{type} \Arg{user action spec} \meta{content} |
| 275 |
% \cs{pdfannot_link_end:n} \Arg{type} |
| 276 |
% \end{syntax} |
| 277 |
% This creates a link like the previous command. |
| 278 |
% \texttt{/Subtype/Link} is added automatically through the dictionary. |
| 279 |
% \meta{user action spec}\footnote{The wording follows the pdftex documentation}. |
| 280 |
% is provided as a fast method to add dictionary contents, |
| 281 |
% but it should be noted that no provision is taken to avoid clashes with |
| 282 |
% values added through the dictionary. If needed clashing entries should be |
| 283 |
% removed from the dictionary first. Normally the argument is not needed, all |
| 284 |
% entries can be added through the dictionary too. |
| 285 |
% \texttt{/Subtype/Link} is added automatically. |
| 286 |
% In contrast to \cs{pdfannot_link:nnn} this function |
| 287 |
% does not absorb the argument when finding the \meta{content}, and so can |
| 288 |
% be used in circumstances where the \meta{content} may not be a simple |
| 289 |
% argument. But beside this, it works similar and use the same hooks. |
| 290 |
% As example |
| 291 |
% \begin{verbatim} |
| 292 |
% \pdfannot_link_begin:nnw { URI } |
| 293 |
% { |
| 294 |
% /A<< |
| 295 |
% /Type/Action |
| 296 |
% /S/URI |
| 297 |
% /URI(https://www.latex-project.org) |
| 298 |
% >> |
| 299 |
% } |
| 300 |
% link text |
| 301 |
% \pdfannot_link_end:n { URI } |
| 302 |
% \end{verbatim} |
| 303 |
% \end{function} |
| 304 |
% \begin{function}[updated = 2020-12-06]{ \pdfannot_link_goto_begin:nw, \pdfannot_link_goto_end: } |
| 305 |
% \begin{syntax} |
| 306 |
% \cs{pdfannot_link_goto_begin:nw} \Arg{destination} \meta{content} |
| 307 |
% \cs{pdfannot_link_goto_end:} |
| 308 |
% \end{syntax} |
| 309 |
% This is a special, shorter version for links to internal destinations. It always |
| 310 |
% uses the hooks and dictionary of the |GoTo| link type. \meta{destination} is a |
| 311 |
% destination name. In difference to |\pdfannot_link:nnn { GoTo }| it will complain if |
| 312 |
% \meta{destination} is an unknown destination and give the message |
| 313 |
% |
| 314 |
% |name{ZZZZ} has been referenced but does not exist, replaced by a fixed one| |
| 315 |
% |
| 316 |
% \end{function} |
| 317 |
% \begin{function}[added = 2021-02-14]{ \pdfannot_link_ref_last: } |
| 318 |
% This retrieves the object reference a link created previously with the commands |
| 319 |
% above. This doesn't work currently with xelatex but a feature request has |
| 320 |
% been made. see https://tug.org/pipermail/dvipdfmx/2020-December/000134.html |
| 321 |
% \end{function} |
| 322 |
% \begin{function}[added = 2021-02-14]{ \pdfannot_ref_last: } |
| 323 |
% This retrieves the object reference a previously annotation |
| 324 |
% created either with a link or a general box command. When the last was a link |
| 325 |
% it won't work with xelatex. |
| 326 |
% see https://tug.org/pipermail/dvipdfmx/2020-December/000134.html |
| 327 |
% \end{function} |
| 328 |
% \begin{NOTE}{UF} |
| 329 |
% only annot link or also annot? |
| 330 |
% \end{NOTE} |
| 331 |
% \begin{function}[added = 2020-03-12]{ \pdfannot_link_margin:n } |
| 332 |
% \begin{syntax} |
| 333 |
% \cs{pdfannot_link_margin:n} \Arg{dimen} |
| 334 |
% \end{syntax} |
| 335 |
% This sets the dimension of the link margin. |
| 336 |
% \end{function} |
| 337 |
% |
| 338 |
% \begin{function}[added=2021-08-19]{\pdfannot_link_off:,\pdfannot_link_on:} |
| 339 |
% In most engines links can broken over lines and pages. The backends then create |
| 340 |
% intermediate link objects to catch all the content between the start and end of |
| 341 |
% the links, mostly based on some heuristics using the boxlevel. This can |
| 342 |
% lead to the unpleasant result that header and footer are part of the link too. |
| 343 |
% Since texlive 2021 pdflatex and lualatex has commands similar to a special already |
| 344 |
% included in dvipdfmx which allows to interrupt a link. The commands must be used |
| 345 |
% with care: typically they must be outside a box that would be caught by link to |
| 346 |
% have the wanted effect. |
| 347 |
% |
| 348 |
% \end{function} |
| 349 |
% \begin{function}[added = 2020-12-04]{ \pdfannot_dict_put:nnn } |
| 350 |
% \begin{syntax} |
| 351 |
% \cs{pdfannot_dict_put:nnn} \Arg{dictionary name} \Arg{key} \Arg{value} |
| 352 |
% \end{syntax} |
| 353 |
% This adds (locally) a key-value to the internal annot dictionaries used |
| 354 |
% by the link commands above. |
| 355 |
% \meta{dictionary name} should be currently one of \texttt{link/URI}, |
| 356 |
% \texttt{link/URI},\texttt{link/GoToR}, \texttt{link/Launch}, |
| 357 |
% \texttt{link/GoTo}, \texttt{link/Named}. |
| 358 |
% \end{function} |
| 359 |
% \begin{function}[added = 2020-12-04]{ \pdfannot_dict_remove:nn } |
| 360 |
% \begin{syntax} |
| 361 |
% \cs{pdfannot_dict_remove:nn} \Arg{dictionary name} \Arg{key} |
| 362 |
% \end{syntax} |
| 363 |
% This removes a key-value from the internal annot dictionary |
| 364 |
% \meta{dictionary name} should be currently one of |
| 365 |
% \texttt{link/URI}, \texttt{link/GoToR}, \texttt{link/Launch}, |
| 366 |
% \texttt{link/GoTo}, \texttt{link/Named}. |
| 367 |
% \end{function} |
| 368 |
% \begin{function}[added = 2020-12-04]{ \pdfannot_dict_show:n } |
| 369 |
% \begin{syntax} |
| 370 |
% \cs{pdfannot_dict_show:n} \Arg{dictionary name} |
| 371 |
% \end{syntax} |
| 372 |
% This shows the content of the internal annot dictionary. |
| 373 |
% \meta{dictionary name} should be currently one of \texttt{link/URI}, |
| 374 |
% \texttt{link/URI}, \texttt{link/GoToR}, \texttt{link/Launch}, |
| 375 |
% \texttt{link/GoTo}, \texttt{link/Named}. |
| 376 |
% \end{function} |
| 377 |
% |
| 378 |
% \begin{function}[EXP,added = 2021-03-03] |
| 379 |
% { \pdfannot_dict_use:n } |
| 380 |
% \begin{syntax} |
| 381 |
% \cs{pdfannot_dict_use:n} \Arg{dictionary name} |
| 382 |
% \end{syntax} |
| 383 |
% This outputs the property list of the dictionary as a list of |
| 384 |
% |/key value| pairs. |
| 385 |
% This can be used e.g. when writing a dictionary object with |
| 386 |
% \cs{pdf_object_write:nne} |
| 387 |
% \end{function} |
| 388 |
% |
| 389 |
% \begin{variable}[added = 2020-12-28]{\l_pdfannot_F_bitset} |
| 390 |
% This is a bitset variable, with the named index names suitable for the |
| 391 |
% /F flag in an annotation. |
| 392 |
% It can be used for example like this: |
| 393 |
% \begin{verbatim} |
| 394 |
% \bitset_set_true:Nn \l_pdfannot_F_bitset {Print} |
| 395 |
% \pdfannot_dict_put:nne {link/URI} {F} |
| 396 |
% { \bitset_to_arabic:N \l_pdfannot_F_bitset } |
| 397 |
% \end{verbatim} |
| 398 |
% The known keys for the bitset are |Invisible|, |Hidden|, |
| 399 |
% |Print|, |NoZoom|, |NoRotate|, |NoView|, |ReadOnly|, |Locked|, |ToggleNoView|, |
| 400 |
% |LockedContents| which correspond to the names used in the PDF references. |
| 401 |
% \end{variable} |
| 402 |
% \subsection{Widget annotations} |
| 403 |
% Widget annotations are quite important for form fields, as they are used |
| 404 |
% to build the actually instance of such fields. |
| 405 |
% |
| 406 |
% As they can contain meaningful content hooks are probably needed to allow tagging |
| 407 |
% and other manipulations, so like with link special commands are provided. |
| 408 |
% Widget are normally in a box and line and page breaks are not relevant, so |
| 409 |
% the command is offered as box command. |
| 410 |
% |
| 411 |
% \begin{function}[added = 2021-03-02] |
| 412 |
% { \pdfannot_widget_box:nnn } |
| 413 |
% \begin{syntax} |
| 414 |
% \cs{pdfannot_widget_box:nnn} \Arg{width} \Arg{height} \Arg{depth} |
| 415 |
% \end{syntax} |
| 416 |
% This creates an \texttt{/Type/Annot} object with the given dimensions. |
| 417 |
% The annotation doesn't occupy space. |
| 418 |
% It will insert the attribute dictionary of the widget type (which |
| 419 |
% is prefilled with \texttt{/Subtype/Widget}). |
| 420 |
% The hooks \texttt{pdfannot/widget/before} and \texttt{pdfannot/widget/after} |
| 421 |
% are executed before and after the widget. |
| 422 |
% The widget has four subdirectories, |widget/AA|, |widget/AP|, |widget/MK| and |
| 423 |
% |widget/BS| |
| 424 |
% which can be filled with \cs{pdfannot_dict_put:nnn} and will be used if not |
| 425 |
% empty. |
| 426 |
% |
| 427 |
% \end{function} |
| 428 |
% \end{documentation} |
| 429 |
% |
| 430 |
% \begin{implementation} |
| 431 |
% |
| 432 |
% \section{\pkg{l3pdfannot} implementation} |
| 433 |
% |
| 434 |
% \begin{macrocode} |
| 435 |
%<@@=pdfannot> |
| 436 |
%<*header> |
| 437 |
\ProvidesExplPackage{l3pdfannot}{2026-05-26}{0.97c} |
| 438 |
{PDF-annotations} |
| 439 |
\RequirePackage{l3pdfdict} |
| 440 |
%</header> |
| 441 |
% \end{macrocode} |
| 442 |
% Annotations have a /F flag, we provide a public |
| 443 |
% bitset for it. |
| 444 |
% \begin{macrocode} |
| 445 |
%<*package> |
| 446 |
\cs_if_exist:NF \bitset_new:Nn |
| 447 |
{ \RequirePackage { l3bitset } } |
| 448 |
\bitset_new:Nn \l_pdfannot_F_bitset |
| 449 |
{ |
| 450 |
Invisible = 1, |
| 451 |
Hidden = 2, |
| 452 |
Print = 3, |
| 453 |
NoZoom = 4, |
| 454 |
NoRotate = 5, |
| 455 |
NoView = 6, |
| 456 |
ReadOnly = 7, |
| 457 |
Locked = 8, |
| 458 |
ToggleNoView = 9, |
| 459 |
LockedContents = 10 |
| 460 |
} |
| 461 |
% \end{macrocode} |
| 462 |
% \begin{NOTE}{UF} |
| 463 |
% The code/naming tries to unify general annotations and the special type of |
| 464 |
% link under a common name. |
| 465 |
% regarding naming and relation of annotation commands see |
| 466 |
% https://github.com/FrankMittelbach/AccessiblePDF/issues/73 |
| 467 |
% \subsection{Annotations / backend} |
| 468 |
% The backend commands are in l3backend: |
| 469 |
% \cs{__pdf_backend_annotation:nnnn} and \cs{__pdf_backend_annotation_last:} |
| 470 |
% \cs{__pdfannot_backend_link_begin_user:nnw}, etc |
| 471 |
% \end{NOTE} |
| 472 |
% |
| 473 |
% \subsection{ General Annotations } |
| 474 |
% \begin{variable} |
| 475 |
% { \g_@@_use_lastlink_bool } |
| 476 |
% The pdf engines have two different primitive commands to refer to the last created |
| 477 |
% annotation: one for links, one for boxed annotation. We use a boolean to decide |
| 478 |
% which one should be used, so that only one user command is needed. |
| 479 |
% \begin{macrocode} |
| 480 |
\bool_new:N \g_@@_use_lastlink_bool |
| 481 |
% \end{macrocode} |
| 482 |
% \end{variable} |
| 483 |
% \begin{NOTE}{UF} |
| 484 |
% type or not type? Syntax for type? |
| 485 |
% should there be a version without type? |
| 486 |
% \end{NOTE} |
| 487 |
% \begin{macro}{\pdfannot_box:nnnn,\pdfannot_box:nnne,\pdfannot_box_ref_last:} |
| 488 |
% \begin{macrocode} |
| 489 |
\cs_new_protected:Npn \pdfannot_box:nnnn #1 #2 #3 #4 |
| 490 |
{ |
| 491 |
\__pdf_backend_annotation:nnnn {#1}{#2}{#3}{#4} |
| 492 |
\bool_gset_false:N\g_@@_use_lastlink_bool |
| 493 |
} |
| 494 |
\cs_generate_variant:Nn \pdfannot_box:nnnn {nnne,nnnx} |
| 495 |
\cs_new:Npn \pdfannot_box_ref_last: |
| 496 |
{ |
| 497 |
\__pdf_backend_annotation_last: |
| 498 |
} |
| 499 |
|
| 500 |
% \end{macrocode} |
| 501 |
% \end{macro} |
| 502 |
% \subsection{Annotations, subtype Widget}\label{pdf:annot:widget} |
| 503 |
% Widgets are typically boxes, so we provide a box command. |
| 504 |
% A local dictionary \texttt{l_@@/Widget} is used. |
| 505 |
% It contains like the other dictionaries |
| 506 |
% the subtype setting (the /Type is added by the backend). |
| 507 |
% \begin{macrocode} |
| 508 |
\pdfdict_new:n { l_@@/widget } |
| 509 |
\pdfdict_new:n { l_@@/widget/AA } |
| 510 |
\pdfdict_new:n { l_@@/widget/AP } |
| 511 |
\pdfdict_new:n { l_@@/widget/MK } |
| 512 |
\pdfdict_new:n { l_@@/widget/BS } |
| 513 |
\pdfdict_put:nnn { l_@@/widget }{ Subtype }{ /Widget } |
| 514 |
\hook_new_pair:nn |
| 515 |
{pdfannot/widget/before} |
| 516 |
{pdfannot/widget/after} |
| 517 |
\cs_new_protected:Npn \pdfannot_widget_box:nnn #1 #2 #3 |
| 518 |
{ |
| 519 |
\hook_use:n { pdfannot/widget/before } |
| 520 |
\group_begin: |
| 521 |
\pdfmeta_standard_verify:nT |
| 522 |
{annot_widget_no_AA} |
| 523 |
{ |
| 524 |
\pdfdict_if_empty:nF { l_@@/widget/AA } |
| 525 |
{ |
| 526 |
\pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l_@@/widget/AA}} |
| 527 |
\pdfdict_put:nne { l_@@/widget } |
| 528 |
{AA} |
| 529 |
{\pdf_object_ref_last:} |
| 530 |
} |
| 531 |
} |
| 532 |
\pdfdict_if_empty:nF { l_@@/widget/AP } |
| 533 |
{ |
| 534 |
\pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l_@@/widget/AP}} |
| 535 |
\pdfdict_put:nne { l_@@/widget } |
| 536 |
{AP} |
| 537 |
{\pdf_object_ref_last:} |
| 538 |
} |
| 539 |
\pdfdict_if_empty:nF { l_@@/widget/MK } |
| 540 |
{ |
| 541 |
\pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l_@@/widget/MK}} |
| 542 |
\pdfdict_put:nne { l_@@/widget } |
| 543 |
{MK} |
| 544 |
{\pdf_object_ref_last:} |
| 545 |
} |
| 546 |
\pdfdict_if_empty:nF { l_@@/widget/BS } |
| 547 |
{ |
| 548 |
\pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n{l_@@/widget/BS}} |
| 549 |
\pdfdict_put:nne { l_@@/widget } |
| 550 |
{BS} |
| 551 |
{\pdf_object_ref_last:} |
| 552 |
} |
| 553 |
\pdfannot_box:nnne {#1}{#2}{#3} |
| 554 |
{ |
| 555 |
\pdfdict_use:n { l_@@/widget} |
| 556 |
} |
| 557 |
\hook_use:n { pdfannot/widget/end } |
| 558 |
\group_end: |
| 559 |
\bool_gset_false:N\g_@@_use_lastlink_bool |
| 560 |
} |
| 561 |
% \end{macrocode} |
| 562 |
% |
| 563 |
% \subsection{Annotations, subtype Link}\label{sec:links} |
| 564 |
% The code assumes that there will be different link types |
| 565 |
% (currently URI, GoToR, Launch, GoTo, Named, hyperref uses the names |
| 566 |
% url,file,run,link,menu) and that links of the same type share |
| 567 |
% the \emph{attr spec} and also the same begin/end |
| 568 |
% code. The list of link types need to stay restricted and well documented so that |
| 569 |
% all packages know which types they have to handle. It is stored in a constant |
| 570 |
% seq. |
| 571 |
% \begin{NOTE}{UF} |
| 572 |
% Perhaps a |cite| type will be useful at some time. -- Thinking more about it, |
| 573 |
% a |cite| type is not sensible. hyperref supports it, but it doesn't fit in. |
| 574 |
% Commands like cite, gls, acro, footnote and so on should locally change |
| 575 |
% linkcolor and linkbordercolor. |
| 576 |
% Probably we will need some commands to add an attribute to all link types |
| 577 |
% at once. |
| 578 |
% hyperref commands for the various type: |
| 579 |
% url |\hyper@linkurl|, |
| 580 |
% file |\hyper@linkfile|, |
| 581 |
% run |\@hyper@launch run|, |
| 582 |
% link |\hyper@link|, |\find@pdflink| |
| 583 |
% menu |\Acrobatmenu| |
| 584 |
% \end{NOTE} |
| 585 |
% \begin{variable}[added = 2020-03-12]{ \c_pdfannot_link_types_seq } |
| 586 |
% This constant sequence contains the list of currently supported link types |
| 587 |
% for which hooks and dictionaries exist. |
| 588 |
% \end{variable} |
| 589 |
% |
| 590 |
% \begin{variable} |
| 591 |
% { |
| 592 |
% link/TYPE, |
| 593 |
% pdfannot/link/TYPE/before, |
| 594 |
% pdfannot/link/TYPE/begin, |
| 595 |
% pdfannot/link/TYPE/end, |
| 596 |
% pdfannot/link/TYPE/after |
| 597 |
% } |
| 598 |
% These setup the dictionary and the hook pairs. |
| 599 |
% \begin{macrocode} |
| 600 |
\seq_const_from_clist:Nn \c_pdfannot_link_types_seq { URI , GoToR , Launch , GoTo, Named } |
| 601 |
\seq_map_inline:Nn \c_pdfannot_link_types_seq |
| 602 |
{ |
| 603 |
\pdfdict_new:n { l_@@/link/#1 } |
| 604 |
\pdfdict_put:nnn { l_@@/link/#1 }{ Subtype }{ /Link } |
| 605 |
\hook_new_pair:nn |
| 606 |
{pdfannot/link/#1/before} |
| 607 |
{pdfannot/link/#1/after} |
| 608 |
\hook_new_pair:nn |
| 609 |
{pdfannot/link/#1/begin} |
| 610 |
{pdfannot/link/#1/end} |
| 611 |
} |
| 612 |
% \end{macrocode} |
| 613 |
% \end{variable} |
| 614 |
% |
| 615 |
% \subsection{Interruption of links} |
| 616 |
% \begin{macrocode} |
| 617 |
\cs_if_free:NT \pdfannot_link_off: |
| 618 |
{ |
| 619 |
\cs_new_protected:Nn \pdfannot_link_off: { \__pdfannot_backend_link_off: } |
| 620 |
\cs_new_protected:Nn \pdfannot_link_on: { \__pdfannot_backend_link_on: } |
| 621 |
} |
| 622 |
% \end{macrocode} |
| 623 |
% |
| 624 |
% |
| 625 |
% \subsubsection{Annotations, subtype Link /management} |
| 626 |
% |
| 627 |
% \begin{macro}{\pdfannot_link:nnn,\pdfannot_link:nen} |
| 628 |
% \begin{macrocode} |
| 629 |
\cs_new_protected:Nn \pdfannot_link:nnn %#1 type (URI, GoTo etc), |
| 630 |
%#2 action spec, #3 link text |
| 631 |
{ |
| 632 |
\hook_use:n { pdfannot/link/#1/before} |
| 633 |
\mode_leave_vertical: |
| 634 |
\exp_args:Nee %xetex needs expansion |
| 635 |
\__pdfannot_backend_link_begin_user:nnw |
| 636 |
{ |
| 637 |
\pdfdict_if_exist:nT { l_@@/link/#1 } |
| 638 |
{ |
| 639 |
\pdfdict_use:n { l_@@/link/#1} |
| 640 |
} |
| 641 |
} |
| 642 |
{ |
| 643 |
#2 %exp_not? |
| 644 |
} |
| 645 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 646 |
\hook_use:n { pdfannot/link/#1/begin} |
| 647 |
#3 |
| 648 |
\hook_use:n { pdfannot/link/#1/end} |
| 649 |
\__pdfannot_backend_link_end: |
| 650 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 651 |
\hook_use:n { pdfannot/link/#1/after} |
| 652 |
} |
| 653 |
\cs_generate_variant:Nn \pdfannot_link:nnn {nen,nxn} |
| 654 |
% \end{macrocode} |
| 655 |
% \end{macro} |
| 656 |
% \begin{macro}{ |
| 657 |
% \pdfannot_link_begin:nnw, |
| 658 |
% \pdfannot_link_begin:new, |
| 659 |
% \pdfannot_link_end:n } |
| 660 |
% \begin{macrocode} |
| 661 |
\cs_new_protected:Npn \pdfannot_link_begin:nnw #1 #2 %#1 type, #2 action spec |
| 662 |
{ |
| 663 |
\hook_use:n { pdfannot/link/#1/before} |
| 664 |
\mode_leave_vertical: |
| 665 |
\exp_args:Nee %xetex needs expansion |
| 666 |
\__pdfannot_backend_link_begin_user:nnw |
| 667 |
{ |
| 668 |
\pdfdict_if_exist:nT { l_@@/link/#1 } |
| 669 |
{ |
| 670 |
\pdfdict_use:n { l_@@/link/#1} |
| 671 |
} |
| 672 |
} |
| 673 |
{ #2 } |
| 674 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 675 |
\hook_use:n { pdfannot/link/#1/begin} |
| 676 |
} |
| 677 |
|
| 678 |
\cs_new_protected:Nn \pdfannot_link_end:n %#1 type, e.g. url |
| 679 |
{ |
| 680 |
\hook_use:n { pdfannot/link/#1/end} |
| 681 |
\__pdfannot_backend_link_end: |
| 682 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 683 |
\hook_use:n { pdfannot/link/#1/after} |
| 684 |
} |
| 685 |
\cs_generate_variant:Nn \pdfannot_link_begin:nnw {new,nxw} |
| 686 |
% \end{macrocode} |
| 687 |
% \end{macro} |
| 688 |
% \begin{macro}{\pdfannot_link_goto_begin:nw, \pdfannot_link_goto_end:} |
| 689 |
% \begin{macrocode} |
| 690 |
\cs_new_protected:Npn \pdfannot_link_goto_begin:nw #1 %#1 destination |
| 691 |
{ |
| 692 |
\pdfdict_remove:nn { l_@@/link/GoTo} {Subtype} |
| 693 |
\hook_use:n { pdfannot/link/GoTo/before} %the backend add it too |
| 694 |
\mode_leave_vertical: |
| 695 |
\exp_args:Nee %xetex needs expansion |
| 696 |
\__pdfannot_backend_link_begin_goto:nnw |
| 697 |
{ |
| 698 |
\pdfdict_use:n { l_@@/link/GoTo} |
| 699 |
} |
| 700 |
{ #1 } |
| 701 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 702 |
\pdfdict_put:nnn { l_@@/link/GoTo} {Subtype}{GoTo} |
| 703 |
\hook_use:n { pdfannot/link/GoTo/begin} |
| 704 |
} |
| 705 |
|
| 706 |
\cs_new_protected:Nn \pdfannot_link_goto_end: |
| 707 |
{ |
| 708 |
\hook_use:n { pdfannot/link/GoTo/end} |
| 709 |
\__pdfannot_backend_link_end: |
| 710 |
\bool_gset_true:N \g_@@_use_lastlink_bool |
| 711 |
\hook_use:n { pdfannot/link/GoTo/after} |
| 712 |
} |
| 713 |
% \end{macrocode} |
| 714 |
% \end{macro} |
| 715 |
% \begin{macro}[EXP]{\pdfannot_link_ref_last:, \pdfannot_ref_last:} |
| 716 |
% \begin{macrocode} |
| 717 |
\cs_new:Nn \pdfannot_link_ref_last: { \__pdfannot_backend_link_last: } |
| 718 |
% \end{macrocode} |
| 719 |
% \begin{macrocode} |
| 720 |
\cs_new:Npn \pdfannot_ref_last: |
| 721 |
{ |
| 722 |
\bool_if:NTF \g_@@_use_lastlink_bool |
| 723 |
{ |
| 724 |
\__pdfannot_backend_link_last: |
| 725 |
} |
| 726 |
{ |
| 727 |
\__pdf_backend_annotation_last: |
| 728 |
} |
| 729 |
} |
| 730 |
% \end{macrocode} |
| 731 |
% \end{macro} |
| 732 |
% \begin{macro}{ \pdfannot_link_margin:n} |
| 733 |
% \begin{macrocode} |
| 734 |
\cs_new_protected:Npn \pdfannot_link_margin:n #1 |
| 735 |
{ |
| 736 |
\__pdfannot_backend_link_margin:n { #1 } |
| 737 |
} |
| 738 |
% \end{macrocode} |
| 739 |
% \end{macro} |
| 740 |
% \begin{macro} |
| 741 |
% { |
| 742 |
% \pdfannot_dict_put:nnn, |
| 743 |
% \pdfannot_dict_put:nne, |
| 744 |
% \pdfannot_dict_remove:nn, |
| 745 |
% \pdfannot_dict_show:n |
| 746 |
% \pdfannot_dict_use:n |
| 747 |
% } |
| 748 |
% \begin{macrocode} |
| 749 |
\cs_new_protected:Npn \pdfannot_dict_put:nnn #1 #2 #3 |
| 750 |
{ |
| 751 |
\pdfdict_put:nnn { l_@@/#1 } { #2 }{ #3 } |
| 752 |
} |
| 753 |
\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nne,nnx} |
| 754 |
% \end{macrocode} |
| 755 |
% \begin{macrocode} |
| 756 |
\cs_new_protected:Npn \pdfannot_dict_remove:nn #1 #2 |
| 757 |
{ |
| 758 |
\pdfdict_remove:nn { l_@@/#1 } { #2 } |
| 759 |
} |
| 760 |
% \end{macrocode} |
| 761 |
% \begin{macrocode} |
| 762 |
\cs_new_protected:Npn \pdfannot_dict_show:n #1 |
| 763 |
{ |
| 764 |
\pdfdict_show:n { l_@@/#1 } |
| 765 |
} |
| 766 |
|
| 767 |
\cs_new:Npn \pdfannot_dict_use:n #1 |
| 768 |
{ |
| 769 |
\pdfdict_use:n { l_@@/#1 } |
| 770 |
} |
| 771 |
%</package> |
| 772 |
% \end{macrocode} |
| 773 |
% \end{macro} |
| 774 |
% \end{implementation} |
| 775 |
% |
| 776 |
% \PrintIndex |