Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3pdffield.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 \usepackage{l3pdffield,tikz}
32 \hypersetup{pdfauthor=The LaTeX Project,
33 pdftitle=l3pdffield (LaTeX PDF management bundle)}
34 \begin{document}
35 \DocInput{\jobname.dtx}
36 \end{document}
37 %</driver>
38 % \fi
39 % \NewDocElement[
40 % idxgroup=checkbox keys,
41 % idxtype = {checkbox key},
42 % printtype= \textit{checkbox key}
43 % ]{Checkboxkey}{checkboxkey}
44 % \NewDocElement[
45 % idxgroup=field keys,
46 % idxtype = {field key},
47 % printtype= \textit{field key}
48 % ]{Fieldkey}{fieldkey}
49 % \NewDocElement[
50 % idxgroup=setup keys,
51 % idxtype = {setup key},
52 % printtype= \textit{setup key}
53 % ]{Fieldsetupkey}{fieldsetupkey}
54 % \NewDocElement[
55 % idxgroup=annot keys,
56 % idxtype = {annot key},
57 % printtype= \textit{annot key}
58 % ]{Annotkey}{annotkey}%
59 % \providecommand\hook[1]{\texttt{#1}}
60 % \title{^^A
61 % The \pkg{l3pdffield} module\\ Commands to create form fields ^^A
62 % \\ \LaTeX{} PDF management bundle
63 % }
64 %
65 % \author{^^A
66 % The \LaTeX{} Project\thanks
67 % {^^A
68 % E-mail:
69 % \href{mailto:[email protected]}
70 % {[email protected]}^^A
71 % }^^A
72 % }
73 %
74 % \date{Version 0.97c, released 2026-05-26}
75 %
76 % \maketitle
77 % \begin{documentation}
78 % \section{\pkg{l3pdffield} Introduction}
79 % The implementation of form fields in hyperref has some bugs\footnote{see for example
80 % \url{https://github.com/latex3/hyperref/issues/94}}. This package is a first step
81 % towards the goal to review and improve the code of form fields.
82 %
83 % It is a temporary package:
84 % the definite home of the code is not yet decided, and during the development
85 % changes in the interfaces are possible.
86 %
87 % The package itself is currently loaded with
88 % \begin{verbatim}
89 % \usepackage{l3pdffield}
90 % \end{verbatim}
91 %
92 % The source code is split into various submodules. All code is combined in the
93 % sty, but the documentation is in individual PDF.
94 % \begin{description}
95 % \item[\texttt{l3pdffield}] This contains the basic commands and keys
96 % to create a form field.
97 % \item[\texttt{l3pdffield-checkbox}] The code to created checkboxes.
98 % \item[\texttt{l3pdffield-textfield}] The code to created text fields.
99 % \item[\texttt{l3pdffield-radiobutton}] The code to create radio buttons.
100 % \item[\texttt{l3pdffield-pushbutton}] The code to create push buttons.
101 % \item[\texttt{l3pdffield-choice}] The code to create choice fields (lists and drop-down/combo
102 % fields.
103 % \item[\texttt{l3pdffield-action}]
104 % Code related to actions, mostly submit and reset actions.
105 % \item[\texttt{l3pdffield-signature}] (not done yet) Code for signature fields
106 % \item[Form initialization] (not done yet) The |\Form| command/environment
107 % of \pkg{hyperref} initialize a few things like fonts
108 % for text fields which should be moved. It is not strictly necessary to
109 % have this code, most examples works without it, but in case of problems it is
110 % possible to do the initialization by using the \pkg{hyperref} command.
111 % \end{description}
112 %
113 % The code requires the new PDF management. The code makes use of
114 % \pkg{l3pdfxform} to create the form Xobjects of the appearances.
115 % This code doesn't support yet the the dvips backend.
116 %
117 % The code targets PDF~2.0. This doesn't mean that it won't work in older
118 % PDF versions, but it tries to implement requirements needed or recommended
119 % for 2.0; most importantly appearances are used by default everywhere and it
120 % deprecates |/NeedAppearances|.
121 %
122 % Please keep in mind
123 % \begin{itemize}
124 % \item Not every PDF viewer supports form fields or all types and features.
125 % \item The handling can depend on settings in the PDF viewer. In adobe reader for
126 % example I had to disable an option to avoid that it tries to create an appearance
127 % itself.
128 % \item Standards like pdf/A disable some features of form fields like javascript actions
129 % (as you typically can't change the PDF).
130 % \end{itemize}
131 %
132 % If \pkg{hyperref} is loaded before
133 % the package will suppress the deprecated |/NeedAppearances| setting. If \pkg{hyperref}
134 % is loaded later you should do it in the \cs{Form} options.
135 %
136 % So a typical use together with hyperref could look like this
137 %
138 % \begin{verbatim}
139 % \DocumentMetadata{}
140 % \documentclass{article}
141 % \usepackage{hyperref}
142 % \usepackage{l3pdffield}
143 % \begin{document}
144 % \Form
145 % \end{verbatim}
146 % or
147 % \begin{verbatim}
148 % \RequirePackage{pdfmanagement}
149 % \documentclass{article}
150 % \usepackage{hyperref}
151 % \usepackage{l3pdffield}
152 % \begin{document}
153 % \Form
154 % \end{verbatim}
155 %
156 % \section{Some background}
157 %
158 % A document can contain a arbitrary number of fields which can be organized in trees.
159 % The leaf fields in such a tree, the \emph{terminal fields}, typically have
160 % widget annotations as kids which are then the actual, visual instances of the field,
161 % and allow to interact with the field. I will call such a
162 % tree a \emph{fieldset}, nodes \emph{fields} and the widget annotation
163 % \emph{field annotations}.
164 %
165 % If a field has only one child annotation the content of the field dictionary and the
166 % widget annotation dictionary can be merged---some examples in the PDF reference
167 % show such merged dictionaries---but the code here keeps them separate, at the end
168 % this is clearer.
169 %
170 % A simple example would look like this
171 %
172 % \begin{tikzpicture}[level 2/.style={level distance=7mm},
173 % level 1/.style={sibling distance=25mm},
174 % level 2/.style={sibling distance=15mm}]
175 % \node[draw] {week}
176 % child {node[draw] {mon}
177 % child {node[draw,dashed] {annot}}
178 % }
179 % child {node[draw] {tue}
180 % child {node[draw,dashed] {annot}}
181 % }
182 % child {node[draw] {wen}
183 % child {node[draw,dashed] {annot}}
184 % child {node[draw,dashed] {annot}}
185 % }
186 % ;
187 % \end{tikzpicture}
188 %
189 % In many cases a fieldset consists of only one field along with its field annotation(s),
190 % but larger sets can be needed to build more complex interactions with javascript code.
191 % For example a datepicker can be built as a fieldset with various fields to represent
192 % the month and year choice and to select days.
193 %
194 % Fields in a fieldset should have a name, for example |wen| or |week| in the example
195 % above. This name is the \emph{partial name} of the field, the \emph{full name}
196 % is than built from it by adding the names of the parents separated by periods.
197 % In the example above the partial name is \texttt{mon} and the full name
198 % \texttt{week.mon}.
199 % Partial names shouldn't contain periods. If two fields have the same name they will
200 % work in unison: if you enter text in one field, the text appears also in the other, such
201 % fields must have the same type and the same value and default value entry.
202 % If a field has no name it is considered to be a simple widget annotation and so
203 % only another representation of its parent.
204 %
205 %
206 % All terminal fields should also have a type, e.g. \texttt{Btn} for a button field,
207 % or \texttt{Tx} for a textfield. The type can be set for the parent and then inherited.
208 % The fields in a fieldset can have different types.
209 %
210 % \subsection{The look of a field: Appearances and other settings}
211 %
212 % The look of widget annotation of a field can be set with various keys. The keys developed over
213 % time and some of them supersede older ones. There is for example the simple
214 % |/Border|, the more sophisticated |/BS| (\enquote{border style dictionary}),
215 % the \enquote{dynamic appearance dictionary} |MK|, with lots of keys,
216 % and the appearance dictionary |/AP| which
217 % may define as many as three separate appearances:
218 % the normal appearance (required), the rollover appearance and the down appearance.
219 % Such an appearance can be a simple form XObjects%
220 % \footnote{Such form XObjects are small pictures stored in the PDF which
221 % can be referenced in various part of the PDF. They can be
222 % created with the commands of the \pkg{l3pdfxform} package.}%
223 % , but in some cases the annotation can have different \emph{appearance states}:
224 % a checkbox
225 % for example can be checked or unchecked, in this case the appearances
226 % are dictionaries which
227 % maps state names like |/Yes| and |/Off| to form XObjects.
228 %
229 % The annotations cover a rectangular area on
230 % the page and form XObjects appearances are squeezed into this rectangle.
231 % So for the best result
232 % both should have the same ratio of width and height. Simple plain backgrounds can
233 % also be created in large size and reused for various annotations.
234 % Form XObjects used as appearances can not be rotated, if needed one has to
235 % create a new appearance.
236 %
237 %
238 % In PDF 2.0 widget annotations must have at least a normal |/AP| appearance
239 % (unless the size of the annotation is zero) and the keys \enquote{\itshape C, IC, Border,
240 % BS, BE, BM, CA, ca, H, DA, Q,
241 % DS, LE, LL, LLE, and Sy shall be ignored}. But it is quite unclear if
242 % PDF Viewer honor this, and if this make sense e.g. for text fields which require
243 % a DA entry. It is also not clear how appearances and the entries of the MK dictionary
244 % are related in a form field. Tests with some PDF viewers
245 % are needed here.
246 %
247 % \subsection{Tagged PDF}
248 %
249 % Field annotations are (like link annotations) not part of the page stream. But
250 % they are obviously nevertheless meaningful content and must be consider if
251 % a PDF is \enquote{tagged}, that means if a structure is added.
252 %
253 % According to the PDF references fields should be tagged by adding a |Form| structure
254 % element containing the object reference to a field annotations. Fields with more than
255 % one annotation like radio buttons need a |Form| structure for every one.
256 % Additional some cross references to structure relevant object like the parent tree
257 % are needed, for more info check the documentation of the \pkg{tagpdf} package.
258 %
259 % The commands of this module already contain the needed support. So if
260 % \pkg{tagpdf} is used and tagging activated the fields will be added as |Form| element
261 % to the structure where they are created. It is possible to deactivate tagging for
262 % a field annotation by setting the |tag| to false as described below.
263 %
264 % If lualatex is used tagging require either that \pkg{tagpdf} is used with the
265 % option |global-mc|, or mc-chunks must be correctly closed manually, as the automatic
266 % code can't escape the grouping.
267 %
268 % It is recommended to use the |TU|/|altname| key to give the field a readable
269 % name.
270 %
271 %
272 % \section{Commands}
273 % \begin{function}{\pdffield_field:nn}
274 % \begin{syntax}
275 % \cs{pdffield_field:nn} \Arg{key val list} \Arg{field ID}
276 % \end{syntax}
277 % This creates a new field. \meta{field ID} will be used to create and
278 % reference the needed objects but it is not the direct object name, so
279 % |pdf_object_ref:n| can not be used to access (and there will not
280 % clash with object names). It is recommended to start
281 % the name with a module prefix to avoid name clashes, so e.g. |mymodule/field/1| or
282 % |mymodule/field/week|.
283 %
284 % The list of handled keys is described below.
285 % Typically the \meta{key val list} should at least set the name |T|, fields that
286 % are kids in a fieldset must set the |parent| key, this should point to a field
287 % declared before.
288 %
289 % The command is meant as a basic command to build more complex variants like
290 % checkbox or textfields. For this reason it doesn't check if
291 % the combination of values and flags are sensible, and it uses as key names the
292 % names from the PDF reference.
293 % If you create a button field (Btn) and set MaxLen (which is only known for text
294 % fields), it will not complain.
295 %
296 % Root fields (fields without parent) are added automatically to the
297 % Catalog/AcroForm dictionary with
298 %
299 %
300 % \begin{verbatim}
301 % \pdfmanagement_add:nne{Catalog/AcroForm}{Fields}{<obj ref>}
302 % \end{verbatim}
303 %
304 % \end{function}
305 %
306 % \begin{function}{\pdffield_annot:n}
307 % \begin{syntax}
308 % \cs{pdffield_annot:n} \Arg{key val list}
309 % \end{syntax}
310 % This creates a new field annotation.
311 % It is a widget annotation box created with \cs{pdfannot_widget_box:nnn}, and
312 % it is possible to add values to its dictionary
313 % by using |\pdfannot_dict_put:nnn {widget}...|.
314 % But to correctly setup the parent/kid relationship some additional wrapper code is needed.
315 % The command also setup dictionaries to fill the |AP|, |MK| and |AA| dictionaries.
316 % \end{function}
317 %
318 % \begin{function}{\pdffield_annot_ref_last:}
319 % \begin{syntax}
320 % \cs{pdffield_annot_ref_last:}
321 % \end{syntax}
322 % If a tagged PDF should be created, the object
323 % of the annotation of a field should be referenced in the Form structure element.
324 % This command allows to retrieve the reference to this object.
325 % \end{function}
326
327 % \begin{function}{\pdffield_appearance:nn}
328 % \begin{syntax}
329 % \cs{pdffield_appearance:nn} \Arg{name} \Arg{content}
330 % \end{syntax}
331 % This is a small wrapper around \cs{pdfxform_new:nnn} (which could be used too)
332 % to create an appearance. To avoid name clashes \meta{name} should start with
333 % a module part, e.g. |mymodule/appearance/cross|.
334 % \end{function}
335 %
336 % \begin{function}{\pdffield_setup:n}
337 % \begin{syntax}
338 % \cs{pdffield_setup:n} \Arg{key val list}
339 % \end{syntax}
340 % This command allows to preset some field settings.
341 % \end{function}
342 % It knows currently the following keys:
343 %
344 % \begin{function}{create-style}
345 % \begin{syntax}
346 % |create-style| = \Arg{name}\Arg{key val list}
347 % \end{syntax}
348 % This defines a style which can then be used with the |style| key.
349 % \Arg{key val list} can be an arbitrary collection of the keys of the module.
350 % \end{function}
351 %
352 % \begin{function}{style}
353 % \begin{syntax}
354 % |style| = \Arg{style}
355 % \end{syntax}
356 % This uses a style define with the previous |create-style|.
357 % \end{function}
358 %
359 % \begin{function}{preset-checkbox}
360 % \begin{syntax}
361 % |preset-checkbox| = \Arg{key val list}
362 % \end{syntax}
363 % This allows to set default keys for a checkbox.
364 % \end{function}
365 %
366 % \begin{function}{preset-radio}
367 % \begin{syntax}
368 % |preset-radio| = \Arg{key val list}
369 % \end{syntax}
370 % This allows to set default keys for a radio button.
371 % \end{function}
372 %
373 % \begin{function}{preset-textfield}
374 % \begin{syntax}
375 % |preset-textfield| = \Arg{key val list}
376 % \end{syntax}
377 % This allows to set default keys for a text field.
378 % \end{function}
379 %
380 % \section{Special keys}
381 %
382 % \begin{function}{value,default}
383 % \begin{syntax}
384 % |value| = \Arg{value}\\
385 % |default| = \Arg{value}
386 % \end{syntax}
387 % These two keys pass the value to a handler which can be redefined.
388 % Their exact behaviour depends on field type. Please check their documentation.
389 % \end{function}
390 %
391 % \section{Field Keys}
392 %
393 % Table~\ref{tab:fieldkeys} summarize the keys which can be used.
394 % A number of keys have two names, the second is normally the name used by hyperref.
395 % Where is makes sense an empty value \enquote{unsets} a key.
396 %
397 % \begin{table}
398 % \caption{Keys for fields}\label{tab:fieldkeys}
399 % \centering
400 % \begin{tabular}{>{\ttfamily}lllll}
401 % \toprule
402 % key & value & required & inheritable &remark\\\midrule
403 % parent & field ID & for non-root fields & \\
404 % style & style name & & defined with |create-style| \\
405 % T, name & string & mostly & \\
406 % TU, altname & string & & \\
407 % TM, mappingname & string & & \\
408 % FT & name & terminal fields & yes \\
409 % setFf, & list of flags & & yes\\
410 % setfieldflags\\
411 % unsetFf, & list of flags & & yes \\
412 % unsetfieldflags \\
413 % V & various & & yes \\
414 % DV & various & & yes \\
415 % MaxLen & integer & with Comb & yes & only textfields\\
416 % Lock & object name & & & signature field\\
417 % SV & object name & & & signature field\\
418 % Opt & object name & & & buttons and choice fields\\
419 % TI & integer & & & list fields\\
420 % I & object name& & & list fields\\
421 % AA/K, keystroke & javascript \\
422 % AA/F, format & javascript\\
423 % AA/V, validate & javascript\\
424 % AA/C, calculate & javascript\\
425 % DA & string & yes & yes & variable text \\
426 % Q & 0, 1 or 2 & & yes &variable text \\
427 % DS & & & & (ignored) \\
428 % RV & & & & (ignored) \\\bottomrule
429 % \end{tabular}
430 % \end{table}
431 %
432 % \begin{function}{parent}
433 % \begin{syntax}
434 % |parent| = \meta{field ID}\\
435 % \end{syntax}
436 % This declares the parent of the field. It is required if
437 % the field is not the root of the fieldset. The value is the field ID
438 % of the parent, the parent should have been already declared.
439 % It will add the reference to the parent field to the |/Parent| key, and also
440 % add reference of the kid as |/Kid| in the parent field.
441 % \end{function}
442 %
443 % \begin{function}{name,T}
444 % \begin{syntax}
445 % |name| = \meta{partial name}\\
446 % |T| = \meta{partial name}
447 % \end{syntax}
448 % This sets the partial name of the field. It shouldn't contain
449 % a period, be not empty and sensibly consist of simple ascii chars.
450 % It is normally required, see above. The value is passed through \cs{pdf_string_from_unicode:nnN}.
451 % \end{function}
452 %
453 % \begin{function}{altname,TU}
454 % \begin{syntax}
455 % |altname| = \meta{string}\\
456 % |TU| = \meta{string}\\
457 % \end{syntax}
458 % This sets an alternative name for user interaction.
459 % Unlike the name field it can use unicode or periods.
460 % The value is passed through \cs{pdf_string_from_unicode:nnN}
461 % \end{function}
462 %
463 % \begin{function}{mappingname,TM}
464 % \begin{syntax}
465 % |mappingname| = \meta{string}\\
466 % |TM| = \meta{string}\\
467 % \end{syntax}
468 % This sets an alternative name for the export.
469 % The value is passed through \cs{pdf_string_from_unicode:nnN}
470 % \end{function}
471 %
472 % \begin{function}{FT}
473 % \begin{syntax}
474 % |FT| = |Btn|\verb"|"|Tx|\verb"|"|Ch|\verb"|"|Sig|
475 % \end{syntax}
476 % This sets the type of the field, the value should be one of
477 % \texttt{Btn} (button), \texttt{Tx} (text), \texttt{Ch} (choice), \texttt{Sig} (signature).
478 % The value is of relevance only for terminal fields, but it can be set in a parent
479 % and then inherited.
480 % \end{function}
481 %
482 % \begin{function}{setfieldflags,setFf,unsetfieldflags,unsetFf}
483 % \begin{syntax}
484 % |setfieldflags| = \meta{comma list of flags}\\
485 % |setFf| = \meta{comma list of flags}\\
486 % |unsetfieldflags| = |all| \verb"|" \meta{comma list of flags}\\
487 % |unsetFf| = |all| \verb"|" \meta{comma list of flags}
488 % \end{syntax}
489 % These keys accept a list of flag names and then sets or unsets them, the resulting value
490 % is then used with the \texttt{/Ff} key. Depending
491 % on the field type some flags must be set or unset, other are optional or are ignored.
492 % The flag name can be given in PDF spelling (\texttt{RadiosInUnison}),
493 % in lowercase (\texttt{radiosinunison}), and as number. |unsetFf| and its
494 % alias |unsetfieldflags| know the special value |all| which clears all the fields.
495 %
496 % The list of flags are:
497 % |ReadOnly|, |Required|,
498 % |NoExport|, |Multiline|, |Password|, |NoToggleToOff|, |Radio|, |Pushbotton|,
499 % |Combo|, |Edit|, |Sort|, |FileSelect|, |MultiSelect|, |DoNotSpellCheck|,
500 % |DoNotScroll|, |Comb|, |RadiosInUnison|, |RichText|, |CommitOnSelChange|.
501 %
502 % \end{function}
503 %
504 % \begin{function}{V}
505 % \begin{syntax}
506 % |V| = \meta{various}
507 % \end{syntax}
508 % This sets the value of the field. Its
509 % format varies depending on the field type, so typically
510 % commands for the various type will have to preprocess and sanitize it.
511 % The value given here is x-expanded and then added to the dictionary!
512 % See the descriptions of individual field types for further information.
513 % (Pushbuttons for example don't have a value).
514 % \end{function}
515 %
516 % \begin{function}{DV}
517 % \begin{syntax}
518 % |DV| = \meta{various}
519 % \end{syntax}
520 % The default value, to which the field reverts
521 % when a reset-form action is executed. The format of this value is the
522 % same as that of \texttt{DV}.
523 % \end{function}
524 %
525 % \begin{function}{MaxLen}
526 % \begin{syntax}
527 % |MaxLen| = \meta{integer}
528 % \end{syntax}
529 % Only relevant for textfields.
530 % The value is an integer and describes the maximum length of the field’s text in characters.
531 % Required if the |Comb| flag is used.
532 % \end{function}
533 %
534 % \begin{function}{Lock}
535 % \begin{syntax}
536 % |MaxLen| = \meta{object name}
537 % \end{syntax}
538 % Only relevant for signature fields. The value is an object name
539 % which should point to a dictionary that specifies a set of form fields
540 % that shall be locked when this signature field is signed. The exact format of
541 % the dictionary is described in the PDF reference.
542 % \end{function}
543 %
544 % \begin{function}{SV}
545 % \begin{syntax}
546 % |SV| = \meta{object name}
547 % \end{syntax}
548 % Only relevant for signature fields. The value is an object name
549 % which should point to a seed value dictionary. The exact format of
550 % the dictionary is described in the PDF reference.
551 % \end{function}
552 %
553 % \begin{function}{Opt}
554 % \begin{syntax}
555 % |Opt| = \meta{object name}
556 % \end{syntax}
557 % Only relevant for checkboxes, radiobuttons and choice fields.
558 % The value is an object name
559 % which should point to a array. The exact format of
560 % the array is described in the PDF reference.
561 % \end{function}
562 %
563 % \begin{function}{TI}
564 % \begin{syntax}
565 % |TI| = \meta{integer}
566 % \end{syntax}
567 % Only relevant for scrollable list boxes.
568 % The value is an integer, the top index (the index in the Opt array
569 % of the first option visible in the list). Default value: 0
570 % \end{function}
571 %
572 % \begin{function}{I}
573 % \begin{syntax}
574 % |I| = \meta{object name}
575 % \end{syntax}
576 % For choice fields that allow
577 % multiple selection (MultiSelect flag set). The value is an object name
578 % which should point to a array. The exact format of
579 % the array is described in the PDF reference
580 % (I have no idea what exactly should be added there, perhaps some future test will make
581 % it more understandable.)
582 % \end{function}
583 %
584 % The following four keys are used to add javascript (\enquote{ECMAScript}) code.
585 % The values are expanded. It is recommended to store
586 % the javascript in a stream object and to pass the object reference, but passing
587 % a string (including parentheses) is possible too.
588 % The keys will be ignored if a pdfstandard
589 % is used that prohibits such actions.
590 %
591 % \begin{function}{AA/K,keystroke}
592 % \begin{syntax}
593 % |AA/K| = \meta{ECMAScript}\\
594 % |keystroke| = \meta{ECMAScript}
595 % \end{syntax}
596 % This adds a keystroke action to the
597 % additional action dictionary. The action is meant for text and choice fields.
598 % It is quite unclear if such an action
599 % make sense for non-terminal fields.
600 % \end{function}
601 %
602 % \begin{function}{AA/F,format}
603 % \begin{syntax}
604 % |AA/F| = \meta{ECMAScript}\\
605 % |format| = \meta{ECMAScript}
606 % \end{syntax}
607 % This adds a format action to the
608 % additional action dictionary. The action is meant for text and choice fields.
609 % It is quite unclear if such an action
610 % make sense for non-terminal fields.
611 % \end{function}
612 %
613 % \begin{function}{AA/V,validate}
614 % \begin{syntax}
615 % |AA/V| = \meta{ECMAScript}\\
616 % |validate| = \meta{ECMAScript}
617 % \end{syntax}
618 % This adds a validate action to the
619 % additional action dictionary. It is quite unclear if such an action
620 % make sense for non-terminal fields.
621 % \end{function}
622 %
623 % \begin{function}{AA/C,calculate}
624 % \begin{syntax}
625 % |AA/C| = \meta{string (ECMAScript)}\\
626 % |calculate| = \meta{string (ECMAScript)}
627 % \end{syntax}
628 % This adds a calculate action to the
629 % additional action dictionary. It is quite unclear if such an action
630 % make sense for non-terminal fields.
631 % If an calculate action is used, the field will be added to the
632 % AcroForm/CO array to define the calculation order. The order can
633 % be controlled through the following key |sortkey|.
634 % \end{function}
635 %
636 % \begin{function}{sortkey}
637 % \begin{syntax}
638 % |sortkey| = \meta{string}
639 % \end{syntax}
640 % This sets a sortkey for fields with calculate action.
641 % The sortkeys are sorted lexically with |\str_compare:nNnTF|.
642 % fields without sortkey will get an empty sortkey and so be at the begin,
643 % the order of fields with the same sortkey is not defined.
644 % The module only sorts fields created with the commands of this module, the
645 % sorting of fields created by \pkg{hyperref} is independent.
646 % \end{function}
647 %
648 % \begin{function}{DA}
649 % \begin{syntax}
650 % |DA| = \meta{string}
651 % \end{syntax}
652 % This contains instructions for the text in text fields.
653 % It is stored expanded and parentheses are added around the value.
654 % \end{function}
655 %
656 % \begin{function}{Q,align}
657 % \begin{syntax}
658 % |Q| = |left|\verb"|"|center|\verb"|"|right|\\
659 % |align| = |left|\verb"|"|center|\verb"|"|right|
660 % \end{syntax}
661 % The justification of the text.
662 % \end{function}
663 %
664 % \begin{function}{DS,RV}
665 % These two keys are currently not implemented
666 % as it is unclear if there are of any use.
667 % \end{function}
668 %
669 % \begin{function}{fieldID}
670 % \begin{syntax}
671 % |fieldID| = \meta{field ID}\\
672 % \end{syntax}
673 % \emph{For experts only!}
674 % This stores \meta{field ID} in an internal variable.
675 % The variable is not used by the basic commands,
676 % but by the commands to create the various field types.
677 % Check their documentation for use cases.
678 % \end{function}
679 % \section{Annot keys}
680 %
681 % Table~\ref{tab:annotkeys} summarize the keys which can be used.
682 % A number of keys have alias names which are mentioned in the descriptions.
683 %
684 % \begin{table}
685 % \caption{Keys for field annotations}\label{tab:annotkeys}
686 % \centering
687 % \begin{tabular}{>{\ttfamily}lllll}
688 % \toprule
689 % key & value & required &remark\\\midrule
690 % parent & field ID & yes \\
691 % width & dim expression & (yes) & default is 0pt \\
692 % height & dim expression & (yes) & default is 0pt \\
693 % depth & dim expression & (yes) & default is 0pt \\
694 % AP/N & appearance name & yes (in PDF 2.0) \\
695 % AP/R & appearance name & yes (in PDF 2.0) \\
696 % AP/D & appearance name & yes (in PDF 2.0) \\
697 % AS & name & yes (in PDF 2.0) \\
698 % setF & list of flags \\
699 % unsetF & list of flags \\
700 % AA/* & javascript & *= F, Bl, D, U, E, \\
701 % & & X, PO, PC,PV, PI\\
702 % MK/* & various & *= R, BC, BG, CA, RC, \\
703 % & & AC, I, RI, IX, IF, TP\\ \bottomrule
704 %
705 % \end{tabular}
706 % \end{table}
707 %
708 % \begin{function}{width,height,depth}
709 % \begin{syntax}
710 % |width| = \meta{dim expression}\\
711 % |height| = \meta{dim expression}\\
712 % |depth| = \meta{dim expression}
713 % \end{syntax}
714 % These keys allow to set the dimensions of the annotation.
715 % The value should be a command that expands to a dimension expression. By default
716 % all values are zero.
717 % \end{function}
718 %
719 % \begin{function}{tag}
720 % \begin{syntax}
721 % |tag| = |true|\verb+|+|false|
722 % \end{syntax}
723 % This key is related to tagging and enables/disables the tagging.
724 % \end{function}
725 %
726 % \begin{function}{parent}
727 % \begin{syntax}
728 % |parent| = \meta{field ID}\\
729 % \end{syntax}
730 % This sets the parent. The value should be field ID of
731 % an already declared field.
732 % \end{function}
733 %
734 % \begin{function}{AP/N,appearance,AP/R,rollover-appearance,AP/D,down-appearance}
735 % \begin{syntax}
736 % |AP/N| = \meta{appearance name}\\
737 % |appearance| = \meta{appearance name}\\
738 % |AP/R| = \meta{rollover appearance name}\\
739 % |rollover-appearance| = \meta{rollover appearance name}\\
740 % |AP/D| = \meta{down appearance name}\\
741 % |down appearance| = \meta{down appearance name}\\
742 % \end{syntax}
743 % This keys set the normal, rollover and down appearance. The names
744 % |appearance|, |rollover-appearance| and |down-appearance| are aliases.
745 % The value is by default a simple name of an appearance/form Xobject but
746 % modules like \pkg{l3pdffield-checkbox} change this to allow to add appearances for
747 % various states. So check the documentation for the various field types for the
748 % exact format of the value.
749 % \end{function}
750 %
751 % \begin{function}{AS}
752 % \begin{syntax}
753 % |AS| = \meta{appearance state name}
754 % \end{syntax}
755 % This key sets the default appearance state.
756 % The value is a name \emph{without} the starting slash
757 % (it is passed through |\pdf_name_from_unicode_e:n|),
758 % for checkbox for example |Yes|. If used it should typically have the same value
759 % as the V and DV key of the field.
760 % \end{function}
761 %
762 %\begin{function}{setannotflags,setF,unsetannotflags,unsetF}
763 % \begin{syntax}
764 % |setannotflags| = \meta{comma list of flags}\\
765 % |setF| = \meta{comma list of flags}\\
766 % |unsetannotflags| = |all| \verb"|" \meta{comma list of flags}\\
767 % |unsetF| = |all| \verb"|" \meta{comma list of flags}
768 % \end{syntax}
769 % These keys allow to set or unset the annot flags. They expect a comma lists of
770 % flag names. Allowed names |Invisible|, |Hidden|,
771 % |Print|, |NoZoom|,|NoRotate|, |NoView|, |ReadOnly|, |Locked|, |ToggleNoView|,
772 % |LockedContents|, or the lowercase variants or numbers.
773 % \end{function}
774 %
775 % \begin{function}{AA/*}
776 % \begin{syntax}
777 % |AA/*| = \meta{ECMAScript}
778 % \end{syntax}
779 % * should be one of |Fo|, |Bl|, |D|, |U|, |E|, |X|, |PO|, |PC|, |PV|, |PI|.
780 % Alias names for the first six keys are
781 % |onfocus|, |onblur|, |onmousedown|, |onmouseup|, |onenter|, |onexit|.
782 % These keys adds then the respective key to the |/AA| dictionary
783 % of the field annotation object.
784 % Their value should be javascript code. The value is expanded but not escaped.
785 % It is recommended to
786 % store the code in a stream object and to use the object reference as value.
787 % The |/AA| dictionary
788 % is suppressed if a pdf/A standard is set.
789 %
790 % For example
791 % \begin{verbatim}
792 % onenter={(app.alert('Hello');)}
793 % \end{verbatim}
794 % \end{function}
795 %
796 % The following keys add values to the \emph{dynamic appearance dictionary}
797 % |MK| directory. This is only relevant for
798 % annotations with dynamic content, like e.g. textfields.
799 % The settings can also affect checkboxes and radio buttons if the (deprecated)
800 % |NeedAppearances| is set to true.
801 %
802 % The |MK| dictionary can also be added by using |\pdfannot_dict_put:nnn{Widget}{MK}{...}|
803 % but the two methods should not be mixed.
804 %
805 % \begin{function}{MK/R,rotate}
806 % \begin{syntax}
807 % |MK/R| = |0| \verb"|" |90| \verb"|" |180| \verb"|" |270|\\
808 % |rotate| = |0| \verb"|" |90| \verb"|" |180| \verb"|" |270|
809 % \end{syntax}
810 % These rotates the content of the annotation.
811 % \end{function}
812 %
813 % \begin{function}{MK/BC,bordercolor}
814 % \begin{syntax}
815 % |MK/BC| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}\\
816 % |bordercolor| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}
817 % \end{syntax}
818 % These colors the border. Internally currently RGB is used.
819 % The colors used in
820 % \meta{color expression} must be known to the \pkg{l3color} commands.
821 % \end{function}
822 %
823 % \begin{function}{MK/BG,backgroundcolor}
824 % \begin{syntax}
825 % |MK/BG| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}\\
826 % |backgroundcolor| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}
827 % \end{syntax}
828 % These colors the background. Internally currently RGB is used.
829 % The colors used in
830 % \meta{color expression} must be known to the \pkg{l3color} commands.
831 % \end{function}
832 %
833 % \begin{function}{MK/CA,caption}
834 % \begin{syntax}
835 % |MK/CA| = \meta{string}\\
836 % |caption| = \meta{string}
837 % \end{syntax}
838 % This sets a text for the caption. \meta{string} is passed through \cs{pdf_string_from_unicode:nnN}
839 % and parentheses are added automatically. The font used seems to depend on
840 % the whims of the PDF reader: At least for checkboxes adobe reader quite insists to
841 % always use a symbol font and not a text font. It also shows always
842 % only one symbol, regardless how much one put in the string.
843 % hyperref uses the key names |checkboxsymbol| and
844 % |radiosymbol| for this setting.
845 % \end{function}
846 %
847 % \begin{function}{MK/RC,rollover-caption}
848 % \begin{syntax}
849 % |MK/RC| = \meta{string}\\
850 % |rollover-caption| = \meta{string}
851 % \end{syntax}
852 % This sets a text for the rollover-caption. \meta{string} is passed through \cs{pdf_string_from_unicode:nnN}
853 % and parentheses are added automatically. The key should be used only with
854 % pushbuttons. It is unclear if is actually used by the PDF viewer, but the
855 % pushbuttons modules uses the argument also to setup the appearance.
856 % \end{function}
857 %
858 % \begin{function}{MK/AC,down-caption}
859 % \begin{syntax}
860 % |MK/AC| = \meta{string}\\
861 % |down-caption| = \meta{string}
862 % \end{syntax}
863 % This sets a text for the down-caption.
864 % \meta{string} is passed through \cs{pdf_string_from_unicode:nnN}
865 % and parentheses are added automatically. The key should be used only with
866 % pushbuttons. It is unclear if is actually used by the PDF viewer, but the
867 % pushbuttons modules uses the argument also to setup the appearance.
868 % \end{function}
869 %
870 % The remaining key are like the two above useful for pushbuttons only.
871 % Currently no special syntax support
872 % is implemented. They will be handled if needed when the code for
873 % push buttons is developed and tested.
874 % \begin{function}{MK/I,MK/RI,MK/IX,MK/IF,MK/TP}
875 % \begin{syntax}
876 % |MK/*| = \meta{various}
877 % \end{syntax}
878 % These keys adds the various entries in the \emph{dynamic appearance dictionary}.
879 % * should be one of |I|, |RI|, |IX|, |IF|, |TP|.
880 % The |MK| dictionary can also be added by using |\pdfannot_dict_put:nnn{Widget}{MK}{...}|
881 % but the two methods should not be mixed.
882 % \end{function}
883 %
884 % \end{documentation}
885 %
886 % \begin{implementation}
887 % \DoNotIndex
888 % {
889 % \\
890 % ,\bitset_clear:N
891 % ,\bitset_new:Nn
892 % ,\bitset_set_false:Nn
893 % ,\bitset_set_true:Nn
894 % ,\bitset_to_arabic:N
895 % ,\bool_new:N
896 % ,\clist_map_inline:nn
897 % ,\color_export:nnN
898 % ,\color_set:nn
899 % ,\color_set:nnn
900 % ,\cs_new_protected:Npn
901 % ,\cs_set_eq:NN
902 % ,\cs_set_protected:Npn
903 % ,\cs_if_exist:NTF
904 % ,\cs_if_exist:NT
905 % ,\cs_new:Npn
906 % ,\csname
907 % ,\dim_eval:n
908 % ,\dim_new:N
909 % ,\endcsname
910 % ,\exp_args:Ne
911 % ,\exp_args:Nne
912 % ,\exp_args:NV
913 % ,\group_begin:
914 % ,\group_end:
915 % ,\hbox_to_wd:nn
916 % ,\hfill
917 % ,\hook_gput_code:nnn
918 % ,\int_eval:n
919 % ,\l_keys_choice_int
920 % ,\keys_define:nn
921 % ,\keys_set:nn
922 % ,\mode_leave_vertical:
923 % ,\msg_error:nnnn
924 % ,\msg_error:nne
925 % ,\msg_new:nnn
926 % ,\msg_warning:nn
927 % ,\msg_warning:nnn
928 % ,\msg_info:nnn
929 % ,\msg_warning:nnnnn
930 % ,\NeedsTeXFormat
931 % ,\pdf_name_from_unicode_e:n
932 % ,\pdf_object_if_exist:nTF
933 % ,\pdf_object_new:n
934 % ,\pdf_object_ref:n
935 % ,\pdf_object_ref_last:
936 % ,\pdf_object_unnamed_write:ne
937 % ,\pdf_object_write:nne
938 % ,\pdf_string_from_unicode:nnN
939 % ,\pdfannot_box_ref_last:
940 % ,\pdfannot_dict_put:nnn
941 % ,\pdfannot_dict_put:nne
942 % ,\pdfannot_dict_remove:nn
943 % ,\pdfannot_widget_box:nnn
944 % ,\pdfdict_if_empty:nTF
945 % ,\pdfdict_if_empty:nF
946 % ,\pdfdict_new:n
947 % ,\pdfdict_put:nnn
948 % ,\pdfdict_put:nne
949 % ,\pdfdict_remove:nn
950 % ,\pdfdict_use:n
951 % ,\pdfmanagement_add:nnn
952 % ,\pdfmanagement_add:nne
953 % ,\pdfmeta_standard_verify:nTF
954 % ,\pdfmeta_standard_verify:nT
955 % ,\pdfmeta_standard_verify:nF
956 % ,\pdfxform_if_exist:nTF
957 % ,\pdfxform_new:nnn
958 % ,\pdfxform_ref:n
959 % ,\ProvidesExplPackage
960 % ,\rule
961 % ,\seq_gput_right:Nn
962 % ,\seq_gput_right:ce
963 % ,\seq_if_exist:NTF
964 % ,\seq_if_exist:cTF
965 % ,\seq_new:N
966 % ,\seq_new:c
967 % ,\seq_use:Nn
968 % ,\seq_use:cn
969 % ,\str_if_empty:NTF
970 % ,\str_if_in:NnTF
971 % ,\str_if_in:NnT
972 % ,\str_new:N
973 % ,\tl_if_empty:NTF
974 % ,\tl_if_empty:NF
975 % ,\tl_if_empty:nTF
976 % ,\tl_if_head_eq_charcode:nNTF
977 % ,\tl_new:N
978 % ,\tl_set:Nn
979 % ,\tl_to_str:n
980 % }
981 % \section{\pkg{l3pdffield} Implementation}
982 % \begin{macrocode}
983 %<*package>
984 %<@@=pdffield>
985 \NeedsTeXFormat{LaTeX2e}
986 \ProvidesExplPackage{l3pdffield}{2026-05-26}{0.97c}%
987 {form fields}
988 % \end{macrocode}
989 % \subsection{hyperref specific command}
990 % hyperref sets NeedAppearances by default. As this is deprecated we disable this.
991 % \begin{macrocode}
992 \csname HyField@NeedAppearancesfalse\endcsname % suppress NeedAppearances
993 % \end{macrocode}
994 %
995 % \subsection{local variables}
996 %
997 % \begin{variable}
998 % {
999 % \l_@@_tmpa_str
1000 % ,\l_@@_tmpb_str
1001 % ,\l_@@_tmpa_tl
1002 % ,\l_@@_tmpa_keys_tl
1003 % ,\l_@@_currentparent_tl
1004 % ,\l_@@_fieldID_tl
1005 % ,\l_@@_caption_tl
1006 % ,\l_@@_rollover_caption_tl
1007 % ,\l_@@_down_caption_tl
1008 % ,\g_@@_CO_sortkeys_prop
1009 % ,\l_@@_CO_sortkey_str
1010 % ,\g_@@_annot_ref_last_tl
1011 % ,\l_@@_tag_bool
1012 % }
1013 % Some tmp variables, and a variable for the current parent and the
1014 % current fieldID.
1015 % \begin{macrocode}
1016 \str_new:N \l_@@_tmpa_str
1017 \str_new:N \l_@@_tmpb_str
1018 \tl_new:N \l_@@_tmpa_tl
1019 \tl_new:N \l_@@_tmpa_keys_tl
1020 \tl_new:N \l_@@_currentparent_tl
1021 \tl_new:N \l_@@_fieldID_tl
1022 \tl_new:N \l_@@_caption_tl
1023 \tl_new:N \l_@@_rollover_caption_tl
1024 \tl_new:N \l_@@_down_caption_tl
1025 \prop_new:N \g_@@_CO_sortkeys_prop
1026 \seq_new:N \g_@@_CO_sortkeys_seq
1027 \str_new:N \l_@@_CO_sortkey_str
1028 \tl_new:N \g_@@_annot_ref_last_tl
1029 \bool_new:N \l_@@_tag_bool
1030 \bool_set_true:N \l_@@_tag_bool
1031 % \end{macrocode}
1032 % \end{variable}
1033 %
1034 % \begin{macrocode}
1035 \cs_new_protected:Npn \@@_tmpa:n #1 {}
1036 \cs_new_protected:Npn \@@_tmpa:nn #1 #2 {}
1037 % \end{macrocode}
1038
1039 % \subsection{messages}
1040 % \begin{macrocode}
1041 \msg_new:nnn {pdffield}{no-period}
1042 {
1043 The~field~name~'#1'~contains~a~period. \\
1044 This~is~not~allowed.
1045 }
1046 \msg_new:nnn {pdffield}{empty-name}
1047 {
1048 The~field~name~is~empty. \\
1049 This~is~not~allowed.
1050 }
1051 \msg_new:nnn {pdffield}{appearance-missing}
1052 {
1053 The~appearance~definition~'#1'~is~missing~for~the~#2~appearance.
1054 }
1055 \msg_new:nnn {pdffield}{not-implemented}
1056 {
1057 Support~for~'/#1'~is~not~implemented\\
1058 The~key~is~ignored.
1059 }
1060 \msg_new:nnn {pdffield}{key-disabled}
1061 {
1062 key~'#2'~is~disabled~and~ignored~in~the~'#1'~command.\\
1063 Use~key~'#3'~instead.
1064 }
1065 \msg_new:nnn {pdffield}{parent-field-missing}
1066 {
1067 The~parent~field~'#1'~doesn't~exist\\
1068 Create~it~with~\tl_to_str:n{\pdffield_field:nn}
1069 }
1070 \msg_new:nnn {pdffield}{key-ignored}
1071 {
1072 key~'#1'~has~no~function~and~is~ignored
1073 }
1074 % \end{macrocode}
1075
1076 % An auxiliary command to disable some keys
1077 % \begin{macro}{\@@_key_disable:nnn}
1078 % \begin{macrocode}
1079 \cs_new_protected:Npn \@@_key_disable:nnn #1#2#3
1080 {
1081 \keys_define:nn {pdffield}
1082 {
1083 #2 .code:n =
1084 {
1085 \msg_warning:nnnnn {pdffield}{key-disabled}{#1}{#2}{#3}
1086 }
1087 }
1088 }
1089 % \end{macrocode}
1090 % \end{macro}
1091 % \subsection{bitsets}
1092 % \begin{macro}{\l_@@_Ff_bitset,\l_@@_F_bitset}
1093 % The field and the annot bitset.
1094 % \begin{macrocode}
1095 \bitset_new:Nn \l_@@_Ff_bitset
1096 {
1097 ReadOnly = 1,
1098 Required = 2,
1099 NoExport = 3,
1100 Multiline = 13,%Tx
1101 Password = 14,
1102 NoToggleToOff = 15,%Btn, radio button
1103 Radio = 16,%Btn: Radio: 16=1, 17=0
1104 Pushbutton = 17,%Btn: Checkbox: 16=0, 17=0
1105 %Btn: Pushbutton: 17=1
1106 Combo = 18,%Ch: Combo=1 List=0
1107 Edit = 19,%Ch, Combo=1 -> + edit field
1108 Sort = 20,%Ch, not relevant for view...
1109 FileSelect = 21,%Tx
1110 MultiSelect = 22,%Ch
1111 DoNotSpellCheck = 23,%Tx, Ch (if Combo + Edit set)
1112 DoNotScroll = 24,%Tx
1113 Comb = 25,%Tx, requires MaxLen in dict
1114 RadiosInUnison = 26,%Btn Radio
1115 RichText = 26,%Tx
1116 CommitOnSelChange = 27,
1117 readonly = 1,
1118 required = 2,
1119 noexport = 3,
1120 multiline = 13,%Tx
1121 password = 14,
1122 notoggletooff = 15,%Btn, radio button
1123 radio = 16,%Btn: Radio: 15=1, 16=0
1124 pushbutton = 17,%Btn: Checkbox: 15=0, 16=0
1125 %Btn: Pushbutton: 16=1
1126 combo = 18,%Ch: Combo=1 List=0
1127 edit = 19,%Ch, Combo=1 -> + edit field
1128 sort = 20,%Ch, not relevant for view...
1129 fileselect = 21,%Tx
1130 multiselect = 22,%Ch
1131 donotspellcheck = 23,%Tx, Ch (if Combo + Edit set)
1132 donotscroll = 24,%Tx
1133 comb = 25,%Tx, requires MaxLen in dict
1134 radiosinunison = 26,%Btn Radio
1135 richtext = 26,%Tx
1136 commitonselchange = 27
1137 }
1138
1139 \bitset_new:Nn \l_@@_F_bitset
1140 {
1141 Invisible = 1,
1142 Hidden = 2,
1143 Print = 3,
1144 NoZoom = 4,
1145 NoRotate = 5,
1146 NoView = 6,
1147 ReadOnly = 7,
1148 Locked = 8,
1149 ToggleNoView = 9,
1150 LockedContents = 10,
1151 invisible = 1,
1152 hidden = 2,
1153 print = 3,
1154 nozoom = 4,
1155 norotate = 5,
1156 noview = 6,
1157 readonly = 7,
1158 locked = 8,
1159 togglenoview = 9,
1160 lockedcontents = 10
1161 }
1162 % \end{macrocode}
1163 % \end{macro}
1164 % \subsection{The field dictionary}
1165 % The field dictionary is the main object.
1166 % To be able to set values from the outside it will use a
1167 % dictionary which can be filled by key-val.
1168 % \begin{macrocode}
1169 \pdfdict_new:n {l_@@/field}
1170 \pdfdict_new:n {l_@@/field/AA}
1171 % \end{macrocode}
1172 % \begin{macro}{\@@_field:n,\pdffield_field:nn}
1173 % \begin{syntax}
1174 % \cs{@@_field:n}\Arg{field ID}
1175 % \end{syntax}
1176 % \begin{macrocode}
1177 \cs_new_protected:Npn \@@_field:n #1
1178 {
1179 \pdf_object_new:n {@@/field/#1}
1180 \pdf_object_new:n {@@/field/Kids/#1}
1181 \tl_if_empty:NTF \l_@@_currentparent_tl
1182 {
1183 \pdfmanagement_add:nne
1184 { Catalog / AcroForm }
1185 { Fields }
1186 {\pdf_object_ref:n {@@/field/#1} }
1187 }
1188 {
1189 \exp_args:Ne
1190 \pdf_object_if_exist:nTF {@@/field/\l_@@_currentparent_tl}
1191 {
1192 \pdfdict_put:nne { l_@@/field }{Parent}
1193 {\exp_args:Ne \pdf_object_ref:n{@@/field/\l_@@_currentparent_tl}}
1194 \seq_gput_right:ce {g_@@_field/Kids/\l_@@_currentparent_tl _seq}
1195 { \exp_args:Ne \pdf_object_ref:n{@@/field/#1}}
1196 }
1197 {
1198 \msg_error:nne {pdffield}{parent-field-missing}{\l_@@_currentparent_tl}
1199 }
1200 }
1201 \seq_new:c {g_@@_field/Kids/#1_seq}
1202 \pdfdict_put:nne {l_@@/field}
1203 {Kids}
1204 {
1205 \pdf_object_ref:n {@@/field/Kids/#1}
1206 }
1207 \pdfdict_put:nne {l_@@/field}
1208 {Ff}
1209 {\bitset_to_arabic:N \l_@@_Ff_bitset }
1210 \pdfdict_if_empty:nF{l_@@/field/AA}
1211 {
1212 \pdfmeta_standard_verify:nT
1213 {annot_widget_no_AA}
1214 {
1215 \pdf_object_unnamed_write:ne {dict}{\pdfdict_use:n {l_@@/field/AA}}
1216 \pdfdict_put:nne
1217 {l_@@/field}
1218 {AA}
1219 {\pdf_object_ref_last:}
1220 \pdfdict_get:nnN {l_@@/field/AA}{C}\l_@@_tmpa_tl
1221 \quark_if_no_value:NF \l_@@_tmpa_tl
1222 {
1223 \prop_gput:Nee\g_@@_CO_sortkeys_prop
1224 { \pdf_object_ref:n {@@/field/#1} }{ \l_@@_CO_sortkey_str }
1225 \seq_gput_right:Ne\g_@@_CO_sortkeys_seq
1226 { \pdf_object_ref:n {@@/field/#1} }
1227 }
1228 }
1229 }
1230 \hook_gput_code:nnn {shipout/lastpage}{pdffield} %xetex needs this ...
1231 {
1232 \pdf_object_write:nne {@@/field/Kids/#1} { array }
1233 {
1234 \seq_use:cn{g_@@_field/Kids/#1_seq}{~}
1235 }
1236 }
1237 \pdf_object_write:nne {@@/field/#1} { dict } { \pdfdict_use:n {l_@@/field} }
1238 }
1239
1240 \hook_gput_code:nnn {shipout/lastpage}{pdffield}
1241 {
1242 \prop_if_empty:NF \g_@@_CO_sortkeys_prop
1243 {
1244 \seq_gsort:Nn \g_@@_CO_sortkeys_seq
1245 {
1246 \str_compare:eNeTF
1247 { \prop_item:Nn \g_@@_CO_sortkeys_prop {#1} }
1248 >
1249 { \prop_item:Nn \g_@@_CO_sortkeys_prop {#2} }
1250 { \sort_return_swapped: }
1251 { \sort_return_same: }
1252 }
1253 \pdfmanagement_add:nne
1254 { Catalog / AcroForm }
1255 { CO }
1256 { \seq_use:Nn \g_@@_CO_sortkeys_seq{~} }
1257 }
1258 }
1259
1260 \cs_new_protected:Npn \pdffield_field:nn #1 #2
1261 {
1262 \group_begin:
1263 \keys_set:nn { pdffield } {#1}
1264 \@@_field:n {#2}
1265 \group_end:
1266 }
1267 % \end{macrocode}
1268 % \end{macro}
1269 %
1270 % \subsection{The annot dictionary}
1271 % We assume that the annotation should really occupy space on the page and
1272 % leave vertical mode.
1273 %
1274 % \begin{macro}{\@@_annot:,\pdffield_annot:n}
1275 % The command doesn't add grouping, so should only be used inside a group.
1276 %
1277 % \begin{macrocode}
1278 \cs_new_protected:Npn \@@_annot:
1279 {
1280 \pdfmeta_standard_verify:nF
1281 {annot_flags}
1282 {
1283 \bitset_set_true:Nn \l_@@_F_bitset {Print}
1284 \bitset_set_false:Nn \l_@@_F_bitset {Hidden}
1285 \bitset_set_false:Nn \l_@@_F_bitset {Invisible}
1286 \bitset_set_false:Nn \l_@@_F_bitset {NoView}
1287 }
1288 \pdfannot_dict_put:nne {widget}{F}{ \bitset_to_arabic:N \l_@@_F_bitset }
1289 \@@_tag_add_struct_parent:
1290 \tl_if_empty:NF \l_@@_currentparent_tl
1291 {
1292 \exp_args:Ne
1293 \pdf_object_if_exist:nTF { @@/field/\l_@@_currentparent_tl }
1294 {
1295 \pdfannot_dict_put:nne {widget}{Parent}
1296 {
1297 \exp_args:Ne
1298 \pdf_object_ref:n{@@/field/\l_@@_currentparent_tl}
1299 }
1300 }
1301 {
1302 \msg_error:nne { pdffield }{parent-field-missing}{\l_@@_currentparent_tl}
1303 }
1304 }
1305 \mode_leave_vertical:
1306 \@@_tag_struct_begin:
1307 \hbox_to_wd:nn
1308 { \l_@@_annot_wd_dim }
1309 {
1310 \rule [-\l_@@_annot_dp_dim]{0pt}{\dim_eval:n{\l_@@_annot_ht_dim+\l_@@_annot_dp_dim} }
1311 \pdfannot_widget_box:nnn
1312 { \l_@@_annot_wd_dim }
1313 { \l_@@_annot_ht_dim }
1314 { \l_@@_annot_dp_dim }
1315 \hfill
1316 }
1317 \tl_gset:Ne \g_@@_annot_ref_last_tl { \pdfannot_box_ref_last: }
1318 \exp_args:NV \@@_tag_add_objr:n \g_@@_annot_ref_last_tl
1319 \@@_tag_struct_end:
1320 \tl_if_empty:NF \l_@@_currentparent_tl
1321 {
1322 \seq_if_exist:cTF {g_@@_field/Kids/\l_@@_currentparent_tl _seq}
1323 {
1324 \seq_gput_right:ce
1325 {g_@@_field/Kids/\l_@@_currentparent_tl _seq}
1326 { \g_@@_annot_ref_last_tl }
1327 }
1328 {
1329 \msg_error:nne { pdffield}{parent-field-missing}{\l_@@_currentparent_tl}
1330 }
1331 }
1332 }
1333 \cs_new_protected:Npn \pdffield_annot:n #1
1334 {
1335 \group_begin:
1336 \keys_set:nn { pdffield } {#1}
1337 \@@_annot:
1338 \group_end:
1339 }
1340 % \end{macrocode}
1341 % \end{macro}
1342 %
1343 % \begin{macro}{\pdffield_annot_ref_last:}
1344 % \begin{macrocode}
1345 \cs_new:Npn \pdffield_annot_ref_last: { \g_@@_annot_ref_last_tl }
1346 % \end{macrocode}
1347 % \end{macro}
1348 % \subsection{Tagging}
1349 % \begin{macro}
1350 % {
1351 % \@@_tag_add_struct_parent:,
1352 % \@@_tag_add_objr:n,
1353 % \@@_tag_struct_begin:
1354 % \@@_tag_struct_end:
1355 % }
1356 % \begin{macrocode}
1357 \cs_new_protected:Npn \@@_tag_add_struct_parent: {}
1358 \cs_new_protected:Npn \@@_tag_add_objr:n #1 {}
1359 \cs_new_protected:Npn \@@_tag_struct_begin: {}
1360 \cs_new_protected:Npn \@@_tag_struct_end: {}
1361 \hook_gput_code:nnn {begindocument} { l3pdffield }
1362 {
1363 \cs_if_exist:NT \tag_if_active:T
1364 {
1365 \tag_if_active:T
1366 {
1367 \cs_set_protected:Npn \@@_tag_add_struct_parent:
1368 {
1369 \bool_if:NT \l_@@_tag_bool
1370 {
1371 \pdfannot_dict_put:nne {widget}{StructParent}{ \tag_struct_parent_int: }
1372 }
1373 }
1374 \cs_set_protected:Npn \@@_tag_add_objr:n #1
1375 {
1376 \bool_if:NT \l_@@_tag_bool
1377 {
1378 \exp_args:Nne
1379 \tag_struct_insert_annot:nn {#1}{ \tag_struct_parent_int: }
1380 }
1381 }
1382 \cs_set_protected:Npn \@@_tag_struct_begin:
1383 {
1384 \bool_if:NT \l_@@_tag_bool
1385 {
1386 \tag_mc_end_push:
1387 \tag_struct_begin:n{tag=Form}
1388 }
1389 }
1390 \cs_set_protected:Npn \@@_tag_struct_end:
1391 {
1392 \bool_if:NT \l_@@_tag_bool
1393 {
1394 \tag_struct_end:
1395 \tag_mc_begin_pop:n{}
1396 }
1397 }
1398 }
1399 }
1400 }
1401 % \end{macrocode}
1402 % \end{macro}
1403 % \subsection{auxiliary command for color keys}
1404 % \begin{macro}{\@@_color_set:nn }
1405 % \begin{macrocode}
1406 \cs_new_protected:Npn \@@_color_set:nn #1 #2
1407 {
1408 \tl_if_head_eq_charcode:nNTF {#2}[ %]
1409 {
1410 \@@_color_set_aux:nwn { #1 } #2
1411 }
1412 {
1413 \color_set:nn {#1} {#2}
1414 }
1415 }
1416
1417 \cs_new_protected:Npn \@@_color_set_aux:nwn #1 [#2] #3
1418 {
1419 \color_set:nnn {#1}{#2}{#3}
1420 }
1421
1422 % \end{macrocode}
1423 % \end{macro}
1424 % \subsection{Field keys}
1425 % The names. The main name should not be empty, it is added to the dictionary
1426 % when the field is created. A new name means a new field.
1427 % The other names can only be set when the field is created,
1428 % so we put them in the field group.
1429 % \begin{macro}{\@@_V_handler:nN}
1430 % Values (V and DV) need different handling in the various field types. So
1431 % it uses a handler which can be redefined locally. By default it simply stores
1432 % the value in a tl var.
1433 % \begin{macrocode}
1434 \cs_new_protected:Npn \@@_V_handler:nN #1#2
1435 {
1436 \tl_set:Nn #2 {#1}
1437 }
1438 % \end{macrocode}
1439 % \end{macro}
1440 % \begin{macro}{parent,T,name,TU,altname,TM,mappingname}
1441 % \begin{macrocode}
1442 \keys_define:nn { pdffield }
1443 {
1444 ,parent .tl_set:N = \l_@@_currentparent_tl
1445 ,parent .groups:n = {field,annot}
1446 ,T .code:n =
1447 {
1448 \pdf_string_from_unicode:nnN {utf8/string-raw}{#1}\l_@@_tmpa_str
1449 \str_if_in:NnT \l_@@_tmpa_str {.}
1450 {
1451 \msg_error:nne {pdffield}{no-period}{\l_@@_tmpa_str}
1452 }
1453 \str_if_empty:NTF\l_@@_tmpa_str
1454 {
1455 \msg_warning:nn {pdffield}{empty-name}
1456 \pdfdict_remove:nn { l_@@/field }{T}
1457 }
1458 {
1459 \pdfdict_put:nne { l_@@/field }{T}{(\l_@@_tmpa_str)}
1460 }
1461 }
1462 ,T .value_required:n = true
1463 ,T .groups:n = {field}
1464 ,name .meta:n = {T={#1}}
1465 ,name .value_required:n = true
1466 ,name .groups:n = {field}
1467 ,TU .groups:n = {field}
1468 ,TU .code:n =
1469 {
1470 \tl_if_empty:nTF {#1}
1471 {
1472 \pdfdict_remove:nn { l_@@/field }{TU}
1473 }
1474 {
1475 \pdf_string_from_unicode:nnN {utf16/hex}{#1}\l_@@_tmpa_str
1476 \pdfdict_put:nne { l_@@/field }{TU}{\l_@@_tmpa_str}
1477 }
1478 }
1479 ,TU .groups:n = {field}
1480 ,altname .meta:n = {TU={#1}}
1481 ,altname .groups:n = {field}
1482 ,TM .code:n =
1483 {
1484 \tl_if_empty:nTF {#1}
1485 {
1486 \pdfdict_remove:nn { l_@@/field }{TM}
1487 }
1488 {
1489 \pdf_string_from_unicode:nnN {utf16/hex}{#1}\l_@@_tmpa_str
1490 \pdfdict_put:nne { l_@@/field }{TM}{\l_@@_tmpa_str}
1491 }
1492 }
1493 ,TM .groups:n = {field}
1494 ,mappingname .meta:n = {TM={#1}}
1495 ,mappingname .groups:n = {field}
1496 }
1497 % \end{macrocode}
1498 % \end{macro}
1499 %
1500 % \begin{macro}{fieldID}
1501 % For some field types we need a fieldID.
1502 %
1503 % \begin{macrocode}
1504 \keys_define:nn { pdffield }
1505 {
1506 fieldID .tl_set:N = \l_@@_fieldID_tl
1507 }
1508 % \end{macrocode}
1509 % \end{macro}
1510 %
1511 % \begin{macro}{FT,V,DV,MaxLen,Lock,SV,Opt,TI,I}
1512 % \begin{macrocode}
1513 \keys_define:nn{pdffield}
1514 {
1515 ,FT .choices:nn =
1516 { Btn, Tx, Ch, Sig }
1517 {
1518 \pdfdict_put:nnn { l_@@/field }{FT}{ /#1 }
1519 }
1520 ,FT .groups:n = {field}
1521 ,V .code:n =
1522 {
1523 \tl_if_empty:nTF {#1}
1524 {
1525 \pdfdict_remove:nn { l_@@/field }{V}
1526 }
1527 {
1528 \@@_V_handler:nN{#1}\l_@@_tmpa_str
1529 \pdfdict_put:nne { l_@@/field }{V}{ \l_@@_tmpa_str }
1530 }
1531 }
1532 ,V .groups:n = {field}
1533 ,DV .code:n =
1534 {
1535 \tl_if_empty:nTF {#1}
1536 {
1537 \pdfdict_remove:nn { l_@@/field }{DV}
1538 }
1539 {
1540 \@@_V_handler:nN{#1}\l_@@_tmpa_str
1541 \pdfdict_put:nne { l_@@/field }{DV}{ \l_@@_tmpa_str }
1542 }
1543 }
1544 ,DV .groups:n = {field}
1545 ,MaxLen .code:n =
1546 {
1547 \tl_if_empty:nTF {#1}
1548 {
1549 \pdfdict_remove:nn { l_@@/field }{MaxLen}
1550 }
1551 {
1552 \pdfdict_put:nne { l_@@/field }{MaxLen}{ #1 }
1553 }
1554 }
1555 ,MaxLen .groups:n = {field}
1556 ,Lock .code:n =
1557 {
1558 \tl_if_empty:nTF {#1}
1559 {
1560 \pdfdict_remove:nn { l_@@/field }{Lock}
1561 }
1562 {
1563 \pdfdict_put:nne { l_@@/field }{Lock}{ \pdf_object_ref:n{#1} }
1564 }
1565 }
1566 ,Lock .groups:n = {field}
1567 ,SV .code:n =
1568 {
1569 \tl_if_empty:nTF {#1}
1570 {
1571 \pdfdict_remove:nn { l_@@/field }{SV}
1572 }
1573 {
1574 \pdfdict_put:nne { l_@@/field }{SV}{ \pdf_object_ref:n{#1} }
1575 }
1576 }
1577 ,SV .groups:n = {field}
1578 ,Opt .code:n =
1579 {
1580 \tl_if_empty:nTF {#1}
1581 {
1582 \pdfdict_remove:nn { l_@@/field }{Opt}
1583 }
1584 {
1585 \pdfdict_put:nne { l_@@/field }{Opt}{ \pdf_object_ref:n{#1} }
1586 }
1587 }
1588 ,Opt .groups:n = {field}
1589 ,TI .code:n =
1590 {
1591 \tl_if_empty:nTF {#1}
1592 {
1593 \pdfdict_remove:nn { l_@@/field }{TI}
1594 }
1595 {
1596 \pdfdict_put:nne { l_@@/field }{TI}{ #1 }
1597 }
1598 }
1599 ,TI .groups:n = {field}
1600 ,I .code:n =
1601 {
1602 \tl_if_empty:nTF {#1}
1603 {
1604 \pdfdict_remove:nn { l_@@/field }{I}
1605 }
1606 {
1607 \pdfdict_put:nne { l_@@/field }{I}{ \pdf_object_ref:n{#1} }
1608 }
1609 }
1610 ,I .groups:n = {field}
1611 }
1612 % \end{macrocode}
1613 % \end{macro}
1614 % Flags. We don't add lots of individual keys but map the key names directly
1615 % \begin{macro}{setFf,setfieldflags,unsetFf,unsetfieldflags}
1616 % \begin{macrocode}
1617 \keys_define:nn { pdffield }
1618 {
1619 ,setFf .code:n =
1620 {
1621 \clist_map_inline:nn {#1}
1622 {
1623 \bitset_set_true:Nn \l_@@_Ff_bitset {##1}
1624 }
1625 }
1626 ,setFf .groups:n = {field}
1627 ,setfieldflags .meta:n =
1628 {setFf={#1}}
1629 ,setfieldflags .groups:n = {field}
1630 ,unsetFf .multichoice:
1631 ,unsetFf / all .code:n = { \bitset_clear:N \l_@@_Ff_bitset}
1632 ,unsetFf / unknown .code:n =
1633 {
1634 \bitset_set_false:Nn \l_@@_Ff_bitset {#1}
1635 }
1636 ,unsetFf .groups:n = {field}
1637 ,unsetfieldflags .meta:n = {unsetFf={#1}}
1638 ,unsetfieldflags .groups:n = {field}
1639 }
1640
1641 % \end{macrocode}
1642 % \end{macro}
1643 % \begin{macro}
1644 % {
1645 % AA/K,keystroke,AA/F,format,
1646 % AA/V,validate,AA/C,calculate
1647 % }
1648 % Keys for the AA dictionary. They all trigger a javascript option.
1649 % K=keystroke, F=format, V=validate, C=calculate
1650 % \begin{macrocode}
1651 \cs_set_protected:Npn \@@_tmpa:n #1 %
1652 {
1653 \keys_define:nn { pdffield }
1654 {
1655 AA/#1 .code:n =
1656 {
1657 \tl_if_empty:nTF {#1}
1658 {
1659 \pdfdict_remove:nn {l_@@/field/AA}{#1}
1660 }
1661 {
1662 \pdfdict_put:nne {l_@@/field/AA}
1663 {#1}
1664 {<</S/JavaScript/JS\c_space_tl ##1>>}
1665 }
1666 },
1667 AA/#1 .groups:n = {field}
1668 }
1669 }
1670
1671 \clist_map_inline:nn {K,F,V,C}{\@@_tmpa:n{#1}}
1672
1673 \cs_set_protected:Npn \@@_tmpa:nn #1 #2
1674 {
1675 \keys_define:nn { pdffield }
1676 {
1677 #1 .meta:nn =
1678 { pdffield }{AA/#2={##1}},
1679 #1 .groups:n = {field}
1680 }
1681 }
1682 \@@_tmpa:nn {keystroke}{K}
1683 \@@_tmpa:nn {format} {F}
1684 \@@_tmpa:nn {validate} {V}
1685 \@@_tmpa:nn {calculate}{C}
1686
1687 \keys_define:nn {pdffield}
1688 {
1689 sortkey .code:n = {\str_set:Ne \l_@@_CO_sortkey_str {\tl_to_str:n{#1}}}
1690 }
1691 % \end{macrocode}
1692 % \end{macro}
1693 %
1694 % \begin{macro}{DA,Q,align,DS,RV}
1695 % The following keys are related to textfield and their format.
1696 % \begin{macrocode}
1697 \keys_define:nn { pdffield }
1698 {
1699 DA .code:n =
1700 {
1701 \tl_if_empty:nTF {#1}
1702 {
1703 \pdfdict_remove:nn { l_@@/field }{DA}
1704 }
1705 {
1706 \pdfdict_put:nne { l_@@/field }{DA}{ (#1) }
1707 }
1708 }
1709 ,DA .groups:n = {field}
1710 ,Q .choices:nn = {left,center,right}
1711 {
1712 \pdfdict_put:nne { l_@@/field }{Q}{ \int_eval:n{\l_keys_choice_int-1} }
1713 }
1714 ,Q / .code:n = { \pdfdict_remove:nn { l_@@/field }{Q} }
1715 ,Q .groups:n = {field}
1716 ,align .meta:n={Q=#1}
1717 ,DS .code:n =
1718 {
1719 \msg_warning:nnn {pdffield}{not-implemented}{DS}
1720 }
1721 ,DS .groups:n = {field}
1722 ,RV .code:n =
1723 {
1724 \msg_warning:nnn {pdffield}{not-implemented}{RV}
1725 }
1726 ,RV .groups:n = {field}
1727 }
1728 % \end{macrocode}
1729 % \end{macro}
1730 % \subsection{Annotation keys}
1731 % The size of the field annotation
1732 % \begin{variable}
1733 % {
1734 % \l_@@_annot_ht_dim,
1735 % \l_@@_annot_wd_dim,
1736 % \l_@@_annot_dp_dim
1737 % }
1738 % \begin{macrocode}
1739 \dim_new:N \l_@@_annot_ht_dim
1740 \dim_new:N \l_@@_annot_wd_dim
1741 \dim_new:N \l_@@_annot_dp_dim
1742 % \end{macrocode}
1743 % \end{variable}
1744 % \begin{macro}{width,height,depth}
1745 % The size of the field annotation.
1746 % \begin{macrocode}
1747 \keys_define:nn { pdffield }
1748 {
1749 ,width .dim_set:N = \l_@@_annot_wd_dim
1750 ,height .dim_set:N = \l_@@_annot_ht_dim
1751 ,depth .dim_set:N = \l_@@_annot_dp_dim
1752 ,width .initial:n = 0pt
1753 ,height .initial:n = 0pt
1754 ,depth .initial:n = 0pt
1755 }
1756 % \end{macrocode}
1757 % \end{macro}
1758 % \begin{macro}{tag}
1759 % to disable tagging locally
1760 % \begin{macrocode}
1761 \keys_define:nn { pdffield }
1762 {
1763 ,tag .bool_set:N = \l_@@_tag_bool
1764 }
1765 % \end{macrocode}
1766 % \end{macro}
1767 % \begin{macro}{\@@_appearance_handler:nnn}
1768 % Appearances have to be handled in various ways, so we use a handler, that
1769 % the field types can redefine if needed.
1770 % \begin{macrocode}
1771 \cs_new_protected:Npn \@@_appearance_handler:nnn #1#2#3
1772 {
1773 \pdfxform_if_exist:nTF { #1 }
1774 {
1775 \pdfannot_dict_put:nne {widget/AP}{#2}
1776 {
1777 \pdfxform_ref:n {#1}
1778 }
1779 }
1780 {
1781 \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
1782 }
1783 }
1784 % \end{macrocode}
1785 % \end{macro}
1786 % \begin{macro}{AS,AP/N,appearance,AP/R,rollover-appearance,AP/D,down-appearance}
1787 % The key for the default appearance and the various types.
1788 % \begin{macrocode}
1789 \keys_define:nn { pdffield }
1790 {
1791 %parent is defined in field
1792 ,AS .code:n =
1793 {
1794 \tl_if_empty:nTF {#1}
1795 {
1796 \pdfannot_dict_remove:nn { widget }{AS}
1797 }
1798 {
1799 \pdfannot_dict_put:nne {widget}{AS}{\pdf_name_from_unicode_e:n{#1}}
1800 }
1801 }
1802 ,AS .groups:n = annot
1803 }
1804 \keys_define:nn { pdffield }
1805 {
1806 AP/N .code:n =
1807 {
1808 \tl_if_empty:nTF {#1}
1809 {
1810 \pdfannot_dict_remove:nn { widget/AP }{N}
1811 }
1812 {
1813 \@@_appearance_handler:nnn {#1}{N}{normal}
1814 }
1815 }
1816 ,AP/N .groups:n = annot
1817 ,appearance .meta:n = {AP/N={#1}}
1818 ,appearance .groups:n = annot
1819 }
1820 \keys_define:nn { pdffield }
1821 {
1822 AP/R .code:n =
1823 {
1824 \tl_if_empty:nTF {#1}
1825 {
1826 \pdfannot_dict_remove:nn { widget/AP }{R}
1827 }
1828 {
1829 \@@_appearance_handler:nnn {#1}{R}{rollover}
1830 }
1831 }
1832 ,AP/R .groups:n = annot
1833 ,rollover-appearance .meta:n = {AP/R={#1}}
1834 ,rollover-appearance .groups:n = annot
1835 }
1836 \keys_define:nn { pdffield }
1837 {
1838 AP/D .code:n =
1839 {
1840 \tl_if_empty:nTF {#1}
1841 {
1842 \pdfannot_dict_remove:nn { widget/AP }{D}
1843 }
1844 {
1845 \@@_appearance_handler:nnn {#1}{D}{down}
1846 }
1847 }
1848 ,AP/D .groups:n = annot
1849 ,down-appearance .meta:n = {AP/D={#1}}
1850 ,down-appearance .groups:n = annot
1851 }
1852 % \end{macrocode}
1853 % \end{macro}
1854 % \begin{macro}{MK/R,rotate,MK/BC,bordercolor,MK/BG,backgroundcolor,MK/CA,caption}
1855 % This are the keys for the dynamic appearance. A number are not handled yet fully.
1856 % \begin{macrocode}
1857 \keys_define:nn { pdffield }
1858 {
1859 MK/R .choices:nn = {0,90,180,270}
1860 {
1861 \pdfannot_dict_put:nne {widget/MK}{R}{#1}
1862 }
1863 ,MK/R / .code:n =
1864 {
1865 \pdfannot_dict_remove:nn { widget/MK }{R}
1866 }
1867 ,MK/R .groups:n = annot
1868 ,rotate .meta:n = {MK/R=#1}
1869 }
1870
1871 \keys_define:nn { pdffield }
1872 {
1873 MK/BC .code:n =
1874 {
1875 \tl_if_empty:nTF {#1}
1876 {
1877 \pdfannot_dict_remove:nn { widget/MK }{BC}
1878 }
1879 {
1880 \@@_color_set:nn {@@/tmp}{#1}
1881 \color_export:nnN{@@/tmp}{space-sep-rgb}\l_@@_tmpa_tl
1882 \pdfannot_dict_put:nne {widget/MK}{BC}{[\l_@@_tmpa_tl]}
1883 }
1884 }
1885 ,MK/BC .groups:n = annot
1886 ,bordercolor .meta:n = {MK/BC=#1}
1887 }
1888
1889 \keys_define:nn { pdffield }
1890 {
1891 MK/BG .code:n =
1892 {
1893 \tl_if_empty:nTF {#1}
1894 {
1895 \pdfannot_dict_remove:nn { widget/MK }{BG}
1896 }
1897 {
1898 \@@_color_set:nn {@@/tmp}{#1}
1899 \color_export:nnN{@@/tmp}{space-sep-rgb}\l_@@_tmpa_tl
1900 \pdfannot_dict_put:nne {widget/MK}{BG}{[\l_@@_tmpa_tl]}
1901 }
1902 }
1903 ,MK/BG .groups:n = annot
1904 ,backgroundcolor .meta:n = {MK/BG=#1}
1905 }
1906
1907
1908 \keys_define:nn { pdffield }
1909 {
1910 MK/CA .code:n =
1911 {
1912 \tl_set:Nn \l_@@_caption_tl {#1}
1913 \tl_if_empty:nTF {#1}
1914 {
1915 \pdfannot_dict_remove:nn { widget/MK }{CA}
1916 }
1917 {
1918 \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_tmpa_str
1919 \pdfannot_dict_put:nne {widget/MK}{CA}{\l_@@_tmpa_str}
1920 }
1921 }
1922 ,MK/CA .groups:n = annot
1923 ,caption .meta:n = {MK/CA=#1}
1924 }
1925
1926 \keys_define:nn { pdffield }
1927 {
1928 MK/RC .code:n =
1929 {
1930 \tl_set:Nn \l_@@_rollover_caption_tl {#1}
1931 \tl_if_empty:nTF {#1}
1932 {
1933 \pdfannot_dict_remove:nn { widget/MK }{RC}
1934 }
1935 {
1936 \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_tmpa_str
1937 \pdfannot_dict_put:nne {widget/MK}{RC}{\l_@@_tmpa_str}
1938 }
1939 }
1940 ,MK/RC .groups:n = annot
1941 ,rollover-caption .meta:n = {MK/RC=#1}
1942 }
1943
1944 \keys_define:nn { pdffield }
1945 {
1946 MK/AC .code:n =
1947 {
1948 \tl_set:Nn \l_@@_down_caption_tl {#1}
1949 \tl_if_empty:nTF {#1}
1950 {
1951 \pdfannot_dict_remove:nn { widget/MK }{AC}
1952 }
1953 {
1954 \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_tmpa_str
1955 \pdfannot_dict_put:nne {widget/MK}{AC}{\l_@@_tmpa_str}
1956 }
1957 }
1958 ,MK/AC .groups:n = annot
1959 ,down-caption .meta:n = {MK/AC=#1}
1960 }
1961 % \end{macrocode}
1962 % \end{macro}
1963 %
1964 % \begin{macro}{MK/I,MK/RI,MK/IX,MK/IF,MK/TP}
1965 % The following keys are pushputtons only. Currently there is no special handling
1966 % involved as it is unclear if they are useful.
1967 % \begin{macrocode}
1968
1969 \cs_set_protected:Npn \@@_tmpa:n #1
1970 {
1971 \keys_define:nn { pdffield }
1972 {
1973 MK/#1 .code:n =
1974 {
1975 \tl_if_empty:nTF {##1}
1976 {
1977 \pdfannot_dict_remove:nn { widget/MK }{#1}
1978 }
1979 {
1980 \pdfannot_dict_put:nne {widget/MK}{#1}{##1}
1981 }
1982 }
1983 ,MK/#1 .groups:n = annot
1984 }
1985 }
1986
1987 \clist_map_inline:nn {I,RI,IX,IF,TP}
1988 { \@@_tmpa:n {#1} }
1989 % \end{macrocode}
1990 % \end{macro}
1991 %
1992 % Flags.
1993 % \begin{macro}{setF,setannotflags,unsetF,unsetannotflags}
1994 % \begin{macrocode}
1995 \keys_define:nn { pdffield }
1996 {
1997 ,setF .code:n =
1998 {
1999 \clist_map_inline:nn {#1}
2000 {
2001 \bitset_set_true:Nn \l_@@_F_bitset {##1}
2002 }
2003 }
2004 ,setF .groups:n = annot
2005 ,setannotflags .meta:nn =
2006 { pdffield }{setF={#1}}
2007 ,setannotflags .groups:n = annot
2008 ,unsetF .multichoice:
2009 ,unsetF / all .code:n = { \bitset_clear:N \l_@@_F_bitset}
2010 ,unsetF / unknown .code:n =
2011 {
2012 \bitset_set_false:Nn \l_@@_F_bitset {#1}
2013 }
2014 ,unsetF .groups:n = annot
2015 ,unsetannotflags .meta:nn =
2016 { pdffield }{unsetF= {#1} }
2017 ,unsetannotflags .groups:n = annot
2018 }
2019
2020 % \end{macrocode}
2021 % \end{macro}
2022 % Keys for the AA dictionary. They all trigger a javascript option.
2023 % Fo = onfocus, Bl = onblur, D = onmousedown, U = onmouseup,
2024 % E = onenter, X = onexit, PO = pageopen, PC = pageclose,
2025 % PV = pagevisible, PI = pageinvisible
2026 % \begin{macro}
2027 % {
2028 % AA/*,AA/Fo,onfocus, AA/Bl,onblur, AA/D,onmousedown, AA/U,onmouseup,
2029 % AA/E,onenter, AA/X,onexit, AA/PO,pageopen, AA/PC,pageclose,
2030 % AA/PV,pagevisible, AA/PI,pageinvisible
2031 % }
2032 % \begin{macrocode}
2033 \cs_set_protected:Npn \@@_tmpa:n #1 %
2034 {
2035 \keys_define:nn { pdffield }
2036 {
2037 AA/#1 .code:n =
2038 {
2039 \tl_if_empty:nTF {#1}
2040 {
2041 \pdfannot_dict_remove:nn {widget/AA}{#1}
2042 }
2043 {
2044 \pdfannot_dict_put:nne {widget/AA}
2045 {#1}
2046 {<</S/JavaScript/JS\c_space_tl##1>>}
2047 }
2048 },
2049 ,AA/#1 .groups:n = annot
2050 }
2051 }
2052
2053 \clist_map_inline:nn {Fo,Bl,D,U,E,X,PO,PC,PV,PI}{\@@_tmpa:n{#1}}
2054
2055 \cs_set_protected:Npn \@@_tmpa:nn #1 #2
2056 {
2057 \keys_define:nn { pdffield }
2058 {
2059 #1 .meta:nn =
2060 { pdffield }{AA/#2={##1}},
2061 #1 .groups:n = {annot}
2062 }
2063 }
2064 \@@_tmpa:nn {onfocus} {Fo}
2065 \@@_tmpa:nn {onblur} {Bl}
2066 \@@_tmpa:nn {onmousedown}{D}
2067 \@@_tmpa:nn {onmouseup}{U}
2068 \@@_tmpa:nn {onenter} {E}
2069 \@@_tmpa:nn {onexit} {X}
2070 % \end{macrocode}
2071 % \end{macro}
2072 % \subsection{Appearances}
2073 % \begin{macro}{\pdffield_appearance:nn,\pdffield_store_appearance:nn}
2074 % \begin{macrocode}
2075 \cs_new_protected:Npn \pdffield_appearance:nn #1 #2
2076 {
2077 \pdfxform_new:nnn {#1}{}{#2}
2078 }
2079
2080 \cs_set_eq:NN \pdffield_store_appearance:nn\pdffield_appearance:nn
2081 % \end{macrocode}
2082 % \end{macro}
2083 % \subsection{Setup command}
2084 % \begin{macro}{create-style,preset-checkbox,preset-radio,preset-textfield}
2085 % \begin{macrocode}
2086 \keys_define:nn { pdffield / setup }
2087 {
2088 ,create-style .code:n = { \@@_style_create:nn #1 }
2089 ,preset-checkbox .code:n =
2090 {
2091 \keys_define:nn { pdffield }
2092 {
2093 @@/preset/checkbox .meta:n = {#1},
2094 }
2095 }
2096 ,preset-radiobutton .code:n =
2097 {
2098 \keys_define:nn { pdffield }
2099 {
2100 @@/preset/radiobutton .meta:n = {#1},
2101 }
2102 }
2103 ,preset-textfield .code:n =
2104 {
2105 \keys_define:nn { pdffield }
2106 {
2107 @@/preset/textfield .meta:n = {#1},
2108 }
2109 }
2110 ,preset-pushbutton .code:n =
2111 {
2112 \keys_define:nn { pdffield }
2113 {
2114 @@/preset/pushbutton .meta:n = {#1},
2115 }
2116 }
2117 ,preset-choice .code:n =
2118 {
2119 \keys_define:nn { pdffield }
2120 {
2121 @@/preset/choice .meta:n = {#1},
2122 }
2123 }
2124 }
2125 \keys_set:nn{ pdffield / setup }{preset-checkbox={}}
2126 \keys_set:nn{ pdffield / setup }{preset-textfield={}}
2127 \keys_set:nn{ pdffield / setup }{preset-radiobutton={}}
2128 \keys_set:nn{ pdffield / setup }{preset-pushbutton={}}
2129 \keys_set:nn{ pdffield / setup }{preset-choice={}}
2130 % \end{macrocode}
2131 % \end{macro}
2132 % \begin{macro}{\@@_style_create:nn}
2133 % \begin{macrocode}
2134 \cs_new_protected:Npn \@@_style_create:nn #1#2
2135 {
2136 \keys_define:nn { pdffield }
2137 {
2138 @@/style/#1 .meta:n = {#2},
2139 }
2140 }
2141
2142 % \end{macrocode}
2143 % \end{macro}
2144 % \begin{macro}{\pdffield_setup:n,style}
2145 % \begin{macrocode}
2146 \cs_new_protected:Npn \pdffield_setup:n #1
2147 {
2148 \keys_set:nn{ pdffield / setup }{#1}
2149 }
2150
2151 \keys_define:nn { pdffield }
2152 {
2153 style .code:n = {\keys_set:nn {pdffield}{@@/style/#1={#1}}}
2154 }
2155 % \end{macrocode}
2156 % \end{macro}
2157 % \section{Value keys}
2158 % \begin{macro}{value,default,\@@_value_handler:n,\@@_default_handler:n}
2159 % \begin{macrocode}
2160 \cs_new_protected:Npn \@@_value_handler:n #1
2161 {
2162 \msg_info:nnn {pdffield}{key-ignored}{value}
2163 }
2164 \cs_new_protected:Npn \@@_default_handler:n #1
2165 {
2166 \msg_info:nnn {pdffield}{key-ignored}{default}
2167 }
2168 \keys_define:nn {pdffield}
2169 {
2170 value .code:n = { \@@_value_handler:n {#1} }
2171 ,default .code:n = { \@@_default_handler:n {#1}}
2172 }
2173 % \end{macrocode}
2174 % \end{macro}
2175 % \begin{macrocode}
2176 %</package>
2177 % \end{macrocode}
2178 % \begin{macrocode}
2179 %<*wrapper>
2180 \NeedsTeXFormat{LaTeX2e}
2181 \ProvidesExplPackage{l3pdffield-testphase}{2026-05-26}{0.97c}%
2182 {form fields}
2183 \RequirePackage{l3pdffield}
2184 %</wrapper>
2185 % \end{macrocode}
2186 %\end{implementation}
2187 %
2188 % \PrintIndex