Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3pdffield-radiobutton.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{} %no tagging, parent-child problems, no ua-2 yet, labels of widgets missing.
27 \documentclass[full]{l3doc}
28 % \usepackage{latex-lab-testphase-l3doc} % errors
29
30 \usepackage{array,booktabs}
31 \usepackage{l3pdffield,bearwear,tikzlings,tikzducks}
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 % \providecommand\hook[1]{\texttt{#1}}
40 % \ExplSyntaxOn
41 % \box_new:N\l_pdffield_bear_box
42 % \box_new:N\l_pdffield_hippo_box
43 % \box_new:N\l_pdffield_duck_box
44 % \hbox_set:Nn \l_pdffield_bear_box {\tikz\bear\bearwear[shirt=red,body~deco={\node[font=\tiny\bfseries,white]~at~(beartummy){Yes};}];}
45 % \hbox_set:Nn \l_pdffield_hippo_box {\vphantom{\tikz\bear;}\tikz\hippo;}
46 % \hbox_set:Nn \l_pdffield_duck_box {\vphantom{\tikz\bear;}\tikz\duck;}
47 %
48 %
49 % \pdffield_appearance:nn {pdffield/bear/Yes}
50 % {
51 % \fbox{\box_use:N \l_pdffield_bear_box}
52 % }
53 % \pdffield_appearance:nn {pdffield/bear/Off}
54 % {
55 % \fbox{\phantom{\box_use:N \l_pdffield_bear_box}}
56 % }
57 % \pdffield_appearance:nn {pdffield/hippo/Yes}
58 % {
59 % \fbox{\box_use:N \l_pdffield_hippo_box}
60 % }
61 % \pdffield_appearance:nn {pdffield/hippo/Off}
62 % {
63 % \fbox{\phantom{\box_use:N \l_pdffield_hippo_box}}
64 % }%
65 % \pdffield_appearance:nn {pdffield/duck/Yes}
66 % {
67 % \fbox{\box_use:N \l_pdffield_duck_box}
68 % }
69 % \pdffield_appearance:nn {pdffield/duck/Off}
70 % {
71 % \fbox{\phantom{\box_use:N \l_pdffield_duck_box}}
72 % }%
73 % \ExplSyntaxOff
74 % \title{^^A
75 % The \pkg{l3pdffield-radiobutton} module\\ Commands to create radio form fields ^^A
76 % \\ \LaTeX{} PDF management bundle
77 % }
78 %
79 % \author{^^A
80 % The \LaTeX{} Project\thanks
81 % {^^A
82 % E-mail:
83 % \href{mailto:[email protected]}
84 % {[email protected]}^^A
85 % }^^A
86 % }
87 %
88 % \date{Version 0.97c, released 2026-05-26}
89 %
90 % \maketitle
91 % \begin{documentation}
92 % \section{\pkg{l3pdffield-radiobutton} Introduction}
93 % This is the documentation for radio buttons fields, for general information about form fields
94 % check the documentation l3pdffield.
95 %
96 % \begin{center}
97 % Choose your favorite
98 %
99 % \medskip
100 % \ExplSyntaxOn
101 % \begin{tabular}{ccc}
102 % \pdffield_radio:n{name=A,value=Bär,default=B,appearance=pdffield/bear,width=\box_wd:N\l_pdffield_bear_box,height=\box_ht:N\l_pdffield_bear_box}&
103 % \pdffield_radio:n{name=A,value=Sieglinde,appearance=pdffield/hippo,width=\box_wd:N\l_pdffield_hippo_box,height=\box_ht:N\l_pdffield_hippo_box}&
104 % \pdffield_radio:n{name=A,value=Duck,appearance=pdffield/duck,width=\box_wd:N\l_pdffield_duck_box,height=\box_ht:N\l_pdffield_duck_box}\\[1ex]
105 % \pdffield_radio:n{name=A,value=Bär}&
106 % \pdffield_radio:n{name=A,value=Sieglinde}&
107 % \pdffield_radio:n{name=A,value=Duck}
108 % \end{tabular}
109 % \par not in unison: \par
110 %
111 % \begin{tabular}{ccc}
112 % \pdffield_radio:n{inunison=false,name=C,value=Bär,appearance=pdffield/bear,width=\box_wd:N\l_pdffield_bear_box,height=\box_ht:N\l_pdffield_bear_box}&
113 % \pdffield_radio:n{name=C,value=Sieglinde,default,appearance=pdffield/hippo,width=\box_wd:N\l_pdffield_hippo_box,height=\box_ht:N\l_pdffield_hippo_box}&
114 % \pdffield_radio:n{name=C,value=Duck,appearance=pdffield/duck,width=\box_wd:N\l_pdffield_duck_box,height=\box_ht:N\l_pdffield_duck_box}\\[1ex]
115 % \pdffield_radio:n{name=C,value=Bär}&
116 % \pdffield_radio:n{name=C,value=Sieglinde}&
117 % \pdffield_radio:n{name=C,value=Duck}
118 % \end{tabular}
119 % \ExplSyntaxOff
120 % \end{center}
121 %
122 % Please keep in mind
123 % \begin{itemize}
124 % \item Not every PDF viewer supports radio buttons.
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 features of form fields too
129 % (as you typically can't change the PDF).
130 % \end{itemize}
131 % \section{Radio buttons}
132 % Click me:
133 % \ExplSyntaxOn
134 % ^^A \pdffield_radio:n{name=bear,appearance=pdffield/bear,width=23pt,height=30pt,depth=10pt}
135 % \ExplSyntaxOff
136 %
137 % Radio buttons are similar to checkboxes and
138 % they have like checkboxes two \enquote{states}:
139 % checked and unchecked.
140 %
141 % The difference is that multiple checkboxes are either \enquote{clones} of each other
142 % which are checked and unchecked together,
143 % or they are independent of each other.
144 % Radio buttons on the other side build \emph{groups}
145 % where checking one of the buttons unchecks all other buttons.
146 % The elements of a such a radio button group are annotations of one field which
147 % has a flag set which makes it into a radio button group.
148 %
149 % In a checkbox field the two states have the
150 % fix names |/Yes| and |/Off|.
151 %
152 % \begin{center}
153 % \begin{tikzpicture}[level 2/.style={level distance=7mm},
154 % level 1/.style={sibling distance=25mm},
155 % level 2/.style={sibling distance=15mm}]
156 % \node[draw] {checkbox field}
157 % child {node[draw,dashed,align=left,font=\ttfamily]
158 % {\textrm{annotation}\\ /Yes\\
159 % /Off
160 % }}
161 % child {node[draw,dashed,align=left,font=\ttfamily]
162 % {\textrm{annotation}\\ /Yes\\
163 % /Off
164 % }}
165 % ;
166 % \end{tikzpicture}
167 % \end{center}
168 %
169 % In radio buttons
170 % the off state should still always have the name |/Off|\footnote{%
171 % the PDF reference doesn't say anything about this, but various tests showed that
172 % one better should stick to this name, with other names the buttons disappeared.}
173 % but the on state should be a specific value for every button.
174 % The field dictionary should then set
175 % in the |/V| key as the value of one of the button.
176 % This button is then set as selected and all the other are deselected when the
177 % PDF is opened or reset.
178 %
179 % It is theoretically possible to control the start appearance state for every
180 % button so e.g. all buttons could have the \enquote{selected} state when the PDF is opened.
181 % But as soon as one button is clicked
182 % you get one selected button and the other are unselected. You can't select or
183 % deselect all buttons. The PDF reference mentions an flag |NoToggleToOff| but this
184 % doesn't do anything, at least not in the PDF viewers I tried. For this
185 % reason setting special start states is currently not supported: it complicates the code and the
186 % input for no real gain.
187 %
188 %
189 % The values of the individual buttons can be coded as annotation state names:
190 %
191 % \begin{center}
192 % \begin{tikzpicture}[level 2/.style={level distance=7mm},
193 % level 1/.style={sibling distance=25mm},
194 % level 2/.style={sibling distance=15mm}]
195 % \node[draw,align=left,font=\ttfamily] {\textrm{radio button field}\\/V /value1 }
196 % child {node[draw,dashed,align=left,font=\ttfamily]
197 % {\textrm{annotation}\\ /value0 \\
198 % /Off
199 % }}
200 % child {node[draw,dashed,align=left,font=\ttfamily]
201 % {\textrm{annotation}\\ /value1 \\
202 % /Off
203 % }}
204 % child {node[draw,dashed,align=left,font=\ttfamily]
205 % {\textrm{annotation}\\ /value2 \\
206 % /Off
207 % }}
208 % ;
209 % \end{tikzpicture}
210 % \end{center}
211 %
212 % But it can be awkward to have to use the values also as names of appearances states, it
213 % makes it for example difficult to use unicode for the value names, so there is another
214 % option: One can set up an |/Opt| array which contains the values as strings,
215 % and used \enquote{named numbers} as appearance state name: The numbers
216 % |/0|, |/1| point then to the index position in the array.
217 %
218 % \begin{center}
219 % \begin{tikzpicture}[level 2/.style={level distance=7mm},
220 % level 1/.style={sibling distance=25mm},
221 % level 2/.style={sibling distance=15mm}]
222 % \node[draw,align=left,font=\ttfamily] {\textrm{radio button field}\\
223 % /Opt [(value0) (value1) (value2)]
224 % /V /0 }
225 % child {node[draw,dashed,align=left,font=\ttfamily]
226 % {\textrm{annotation}\\ /0 \\
227 % /Off
228 % }}
229 % child {node[draw,dashed,align=left,font=\ttfamily]
230 % {\textrm{annotation}\\ /1 \\
231 % /Off
232 % }}
233 % child {node[draw,dashed,align=left,font=\ttfamily]
234 % {\textrm{annotation}\\ /2 \\
235 % /Off
236 % }}
237 % ;
238 % \end{tikzpicture}
239 % \end{center}
240 %
241 % This method is clearly more flexible, and so it is used in this module.
242 %
243 % As radio buttons build a group of buttons, there is more interaction going on,
244 % and more values have to be set. Also the first command, which initializes the field,
245 % has to set the default value of the group.
246 %
247 % This means a typical setup should do something like this
248 %
249 % \begin{verbatim}
250 % \pdffield_radio:n
251 % {
252 % group = A, % required, can also be given as name=A or T=A
253 % value = button1, % required, on-state of this button
254 % % if not given choice (button1) is used
255 % % should refer to an existing button!
256 % % It will set the V and the DV key
257 % % button4 will be checked
258 % }
259 % \pdffield_radio:n
260 % {
261 % group = A, % required, can also be given as name=A or T=A
262 % value = button2, % required, export value of this button
263 % default % this button is default of the group,
264 % }
265 % \pdffield_radio:n
266 % {
267 % group = A, % required, can also be given as name=A or T=A
268 % value = button3, % required, choice/export value of this button
269 % }
270 % \pdffield_radio:n
271 % {
272 % group = A, % required, can also be given as name=A or T=A
273 % value = button4 % required, choice/export value of this button
274 % }
275 % \end{verbatim}
276 %
277 %
278 % If two radio field annotations use the same |value| this value can be mapped either
279 % to the same index or to two different indices in the \texttt{/Opt} array.
280 % In the first case they are selected and unselected together (\enquote{in unison}),
281 % like checkboxes with the same |/Yes| state. The key |inunison| below allows to switch
282 % between the two cases. The flag |RadiosInUnison|
283 % is neither needed for this (but doesn't harm either) nor
284 % does it change the behaviour, at least again not in the PDF viewers I tried,
285 % nevertheless the key will set it accordingly just in case. The two examples at
286 % the begin of the document show the two variants.
287 %
288 %
289 % The button with the key |default| will be selected at the start (together with the
290 % buttons with the same value). If no default is set this is the first button.
291 %
292 % \bigskip
293 % \subsection{Commands}
294 % \begin{function}{\pdffield_radio:n}
295 % \begin{syntax}
296 % \cs{pdffield_radio:n} \Arg{key val list}
297 % \end{syntax}
298 % This creates a radio button to check and uncheck.
299 % The list of allowed keys is described below.
300 % The \meta{key val list} should at least set the group name,
301 % without it the default group
302 % |radio| is used. Radiobuttons with the same
303 % group name belong to the same field and if checked, the others are unchecked.
304 % The default appearance
305 % is a circle frame with a black bullet in it for the checked case.
306 % The default appearance is setup at the first use. Its geometry is quadratic.
307 %
308 % The first radio button setups the field and should also set the button which
309 % should be shown as selected when the PDF is opened.
310 % \end{function}
311 %
312 %
313 % \subsection{Keys}
314 %
315 % The new radio command accept all field and annot keys from l3pdffield.
316 % A few keys are disabled or are forced to specific values.
317 % The |appearance| keys have a more radio specific
318 % behaviour, other keys have other defaults than with the basic commands.
319 % Additionally there
320 % are a small number of keys specific to a radio button.
321 % |value| and |default| have a special meaning.
322 %
323 %
324 % Disabled keys are
325 % \begin{itemize}
326 % \item |V|, |DV|, |AS|: they are set by the other keys.
327 % \item |FT| is overwritten.
328 % \item For radio buttons only the field flags |ReadOnly|, |Required|, |NoExport|,
329 % |NoToggleToOff| and |RadiosInUnison| make sense. The last two are as mentioned
330 % above probably useless.
331 % |Radio| is set automatically by the code
332 % as this is required for a radio button set.
333 % \end{itemize}
334 %
335 %
336 % \begin{function}{preset-radiobutton}
337 % \begin{syntax}
338 % |preset-radiobutton| = \Arg{key val list}
339 % \end{syntax}
340 % This key can be used with \cs{pdffield_setup:n} and allows to set default keys for a radio button.
341 % \end{function}
342 %
343 % \begin{function}{group,name,T}
344 % \begin{syntax}
345 % |group| = \meta{partial name}\\
346 % |name| = \meta{partial name}\\
347 % |T| = \meta{partial name}
348 % \end{syntax}
349 % These keys set the partial name of the field. They all do the same
350 % thing, use the one you are more comfortable with. The value
351 % shouldn't contain a period, be not empty and sensibly consist of simple chars.
352 % Additionally the value is used to create the field ID.
353 % This means that radio buttons with the same partial name are annotations
354 % with the same field as parent and so build a radio button group.
355 % The field ID is then internal and can not be used to
356 % attach another annotation.
357 % For explicit control of the field ID use the |fieldID| key.
358 % \end{function}
359 %
360 % \begin{function}{value}
361 % \begin{syntax}
362 % |value| = \meta{string}
363 % \end{syntax}
364 % With this key you set the export value name for the individual buttons.
365 % Every button should have a value.
366 % buttons with the same value are checked in unison. The value can use unicode.
367 % \end{function}
368 %
369 % \begin{function}{default}
370 % \begin{syntax}
371 % |default|
372 % \end{syntax}
373 % With this key you set the button which is checked when the PDF is opened.
374 % The key must be used in the command of the button which should be the default.
375 % If it is missing the first button is used as default.
376 % A label-ref system is used to get the right numbers, so normally two compilations
377 % are needed if the first button is not the default
378 % \end{function}
379 %
380 % \begin{function}{inunison}
381 % \begin{syntax}
382 % |inunison| = |true|\verb+|+|false|
383 % \end{syntax}
384 % As described above this handle the \enquote{inunison} behaviour.
385 % If set to true (the default)
386 % buttons with the same value will be selected and unselected together.
387 % The keys sets or unsets also the flag |RadiosInUnison| accordingly
388 % (but it is unknown if it has any effect). The key should be set on the first
389 % field. Normally it should be unneeded to use the key:
390 % to avoid the unison effect it makes more sense to use different values.
391 % \end{function}
392 %
393 % \begin{function}{fieldID}
394 % \begin{syntax}
395 % |fieldID| = \meta{field ID}\\
396 % \end{syntax}
397 % \emph{For experts only!}
398 % This allows to give the radio field a specific ID. This is only useful
399 % in the context of a larger fieldset or if you want to attach another annotation
400 % to the field with \cs{pdffield_annot:n}. If used wrongly you can
401 % easily create invalid fieldset. It allows you to create to fields with the
402 % same partial name, but if you want to see both
403 % you need to ensure that their full names are
404 % different---for example by adding some parent fields.
405 % \end{function}
406 %
407 % \begin{function}{parent}
408 % \begin{syntax}
409 % |parent| = \meta{field ID}\\
410 % \end{syntax}
411 % This is only needed if the field should be part
412 % of a larger fieldset. The value should be a field ID of a field created previously
413 % with \cs{pdffield_field:nn}.
414 % \end{function}
415 %
416 %
417 % \begin{function}{width,height,depth}
418 % \begin{syntax}
419 % |width| = \meta{dim expression}\\
420 % |height| = \meta{dim expression}\\
421 % |depth| = \meta{dim expression}
422 % \end{syntax}
423 % These keys allow to set the dimensions of radio button.
424 % The value should be a dimension expression. By default
425 % |width| and |height| use \cs{normalbaselineskip}, the |depth| is zero.
426 % \end{function}
427 %
428 % \begin{function}{AP/N,appearance,AP/R,rollover-appearance,AP/D,down-appearance}
429 % \begin{syntax}
430 % |AP/N| = \meta{partial appearance name}\\
431 % |appearance| = \meta{partial appearance name}\\
432 % |AP/R| = \meta{partial appearance name}\\
433 % |rollover-appearance| = \meta{partial appearance name}\\
434 % |AP/D| = \meta{partial appearance name}\\
435 % |down-appearance| = \meta{partial appearance name}
436 % \end{syntax}
437 % This keys sets the normal appearance, the rollover appearance (when the
438 % mouse hovers over the checkbox) and the down appearance (when the
439 % mouse clicks). They take as value a
440 % \meta{partial appearance name} and expects that \emph{two} form Xobjects
441 % \meta{partial appearance name}|/Yes| and \meta{partial appearance name}|/Off|
442 % has been created. The initial value is |pdffield/radio/default|
443 % for the normal appearance and shows a button.
444 % The down appearance enlarges the middle button a bit to give a visual feed back.
445 % \end{function}
446 %
447 % \subsection{Using with hyperref}
448 % Radio buttons in hyperref are created with \cs{ChoiceMenu} command, and
449 % they also print a label. choices are actually a different field type and
450 % so created with different commands. It is not quite clear yet,
451 % how this could be mapped.
452 %
453 %
454 % \end{documentation}
455 %
456 % \begin{implementation}
457 % % \DoNotIndex
458 % {\\
459 % ,\bitset_clear:N
460 % ,\bitset_new:Nn
461 % ,\bitset_set_false:Nn
462 % ,\bitset_set_true:Nn
463 % ,\bitset_to_arabic:N
464 % ,\bitset_item:Nn
465 % ,\bool_new:N
466 % ,\box_dp:N
467 % ,\box_ht:N
468 % ,\clist_map_inline:nn
469 % ,\color_export:nnN
470 % ,\color_set:nn
471 % ,\color_set:nnn
472 % ,\color_select:n
473 % ,\cs_new_protected:Npn
474 % ,\cs_new_protected:cpn
475 % ,\cs_set_eq:NN
476 % ,\cs_gset_eq:cN
477 % ,\cs_set_protected:Npn
478 % ,\cs_generate_variant:Nn
479 % ,\cs_gset_eq:NN
480 % ,\c_space_tl
481 % ,\csname
482 % ,\dim_eval:n
483 % ,\dim_new:N
484 % ,\dim_to_decimal_in_bp:n
485 % ,\endcsname
486 % ,\exp_args:Ne
487 % ,\exp_args:Nc
488 % ,\fboxsep
489 % ,\fp_eval:n
490 % ,\f@size
491 % ,\group_begin:
492 % ,\group_end:
493 % ,\hbox_to_wd:nn
494 % ,\hfill
495 % ,\hook_gput_code:nnn
496 % ,\int_eval:n
497 % ,\int_compare:nNnT
498 % ,\int_compare:nNnTF
499 % ,\int_incr:N
500 % ,\int_new:N
501 % ,\int_use:N
502 % ,\int_zero:N
503 % ,\l_keys_choice_int
504 % ,\keys_define:nn
505 % ,\keys_set:nn
506 % ,\mode_leave_vertical:
507 % ,\msg_error:nnn
508 % ,\msg_error:nnnn
509 % ,\msg_new:nnn
510 % ,\msg_warning:nn
511 % ,\msg_warning:nnn
512 % ,\msg_warning:nnnnn
513 % ,\NeedsTeXFormat
514 % ,\normalsize
515 % ,\paperheight
516 % ,\paperwidth
517 % ,\pdf_name_from_unicode_e:n
518 % ,\pdf_object_if_exist:nTF
519 % ,\pdf_object_if_exist:nF
520 % ,\pdf_object_new:n
521 % ,\pdf_object_ref:n
522 % ,\pdf_object_ref_last:
523 % ,\pdf_object_unnamed_write:nn
524 % ,\pdf_object_unnamed_write:ne
525 % ,\pdf_object_write:nne
526 % ,\pdf_object_write:nnn
527 % ,\pdf_string_from_unicode:nnN
528 % ,\pdfannot_box_ref_last:
529 % ,\pdfannot_dict_put:nnn
530 % ,\pdfannot_dict_put:nne
531 % ,\pdfdict_put:nne
532 % ,\pdfannot_dict_remove:nn
533 % ,\pdfannot_widget_box:nnn
534 % ,\pdfdict_if_empty:nTF
535 % ,\pdfdict_get:nnN
536 % ,\pdfdict_new:n
537 % ,\pdfdict_put:nnn
538 % ,\pdfdict_remove:nn
539 % ,\pdfdict_use:n
540 % ,\pdfmanagement_add:nnn
541 % ,\pdfmeta_standard_verify:nTF
542 % ,\pdfxform_if_exist:nTF
543 % ,\pdfxform_new:nnn
544 % ,\pdfxform_ref:n
545 % ,\phantom
546 % ,\prg_do_nothing:
547 % ,\ProvidesExplPackage
548 % ,\quark_if_no_value:NT
549 % ,\raisebox
550 % ,\RequirePackage
551 % ,\rule
552 % ,\seq_gput_right:Nn
553 % ,\seq_gput_right:cV
554 % ,\seq_gput_left:cV
555 % ,\seq_if_in:cVF
556 % ,\seq_map_break:
557 % ,\seq_map_inline:Nn
558 % ,\seq_new:c
559 % ,\seq_use:cn
560 % ,\seq_if_exist:NTF
561 % ,\seq_new:N
562 % ,\seq_use:Nn
563 % ,\smash
564 % ,\str_if_empty:NTF
565 % ,\str_if_in:NnTF
566 % ,\str_if_eq:nVTF
567 % ,\str_new:N
568 % ,\strut
569 % ,\strutbox
570 % ,\tl_put_right:Nn
571 % ,\tl_if_empty:NTF
572 % ,\tl_if_empty:NT
573 % ,\tl_if_empty:NF
574 % ,\tl_put_left:Nn
575 % ,\tl_if_eq:NnF
576 % ,\tl_if_empty:nTF
577 % ,\tl_if_head_eq_charcode:nNTF
578 % ,\tl_new:N
579 % ,\tl_set:Nn
580 % ,\tl_to_str:n
581 % ,\use:c
582 % }
583 % \section{\pkg{l3pdffield-radiobutton} Implementation}
584 % \begin{macrocode}
585 %<*package>
586 %<@@=pdffield>
587 \RequirePackage{l3draw}
588 % \end{macrocode}
589 % \subsection{Variables}
590 % \begin{variable}
591 % {
592 % \l_@@_radio_value_tl
593 % ,\l_@@_radio_default_bool
594 % ,\l_@@_radio_value_num_int
595 % ,\l_@@_radio_appearance_code_tl
596 % }
597 % variables to hold the value, its index numbers and the default value.
598 % radio buttons can setup the appearance only after the value is known,
599 % so the code is stored and executed later.
600 % \begin{macrocode}
601 \tl_new:N \l_@@_radio_value_tl
602 \bool_new:N \l_@@_radio_default_bool
603 \int_new:N \l_@@_radio_value_num_int
604 \tl_new:N \l_@@_radio_appearance_code_tl
605 \bool_new:N \l_@@_radio_unison_bool % if true use same name (e.g. /1) for same value
606 \bool_set_true:N \l_@@_radio_unison_bool
607 % \end{macrocode}
608 % \end{variable}
609 %
610 % \subsection{Appearances}
611 % The default appearances are a circle with button in it.
612 % Every appearance should have two versions and follow the naming
613 % module/\meta{name}/Yes and module/\meta{name}/Off.
614 %
615 % \begin{macro}[int]
616 % {
617 % \@@_radio_default_appearances:,
618 % pdffield/radio/default/Yes,
619 % pdffield/radio/default/Off,
620 % pdffield/radio/defaultdown/Yes,
621 % pdffield/radio/defaultdown/Off
622 % }
623 % This defines the standard appearances. They are setup at the first
624 % use of a radiobutton.
625 % \begin{macrocode}
626 \cs_new_protected:Npn \@@_radio_default_appearances:
627 {
628 \pdffield_appearance:nn {pdffield/radio/default/Yes}
629 {
630 \normalsize
631 \draw_begin:
632 \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
633 \draw_path_use_clear:n { stroke }
634 \draw_path_circle:nn {0pt,0pt}{0.2\normalbaselineskip}
635 \draw_path_use_clear:n { fill }
636 \draw_end:
637 }
638 \pdffield_appearance:nn {pdffield/radio/default/Off}
639 {
640 \normalsize
641 \draw_begin:
642 \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
643 \draw_path_use_clear:n { stroke }
644 \draw_end:
645 }
646
647 \pdffield_appearance:nn {pdffield/radio/defaultdown/Yes}
648 {
649 \normalsize
650 \draw_begin:
651 \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
652 \draw_path_use_clear:n { stroke }
653 \draw_path_circle:nn {0pt,0pt}{0.25\normalbaselineskip}
654 \draw_path_use_clear:n { fill }
655 \draw_end:
656 }
657 \pdffield_appearance:nn {pdffield/radio/defaultdown/Off}
658 {
659 \normalsize
660 \draw_begin:
661 \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
662 \draw_path_use_clear:n { stroke }
663 \draw_path_circle:nn {0pt,0pt}{0.25\normalbaselineskip}
664 \draw_path_use_clear:n { fill }
665 \draw_end:
666 }
667 \cs_gset_eq:NN \@@_radio_default_appearances: \prg_do_nothing:
668 }
669 % \end{macrocode}
670 % \end{macro}
671 %
672 %\subsection{Creating the field}
673 % We need to retrieve the index of the default through a
674 % label, so we need a property:
675 %
676 % \begin{macrocode}
677
678 \property_new:nnnn {pdfradioindex}{now}
679 {0}
680 {
681 \int_use:N\l_@@_radio_value_num_int
682 }
683
684 \cs_generate_variant:Nn \property_record:nn {V}
685 \cs_generate_variant:Nn \property_ref:nn {V}
686
687 % \end{macrocode}
688 % A field should be created if the name doesn't exist yet
689 % \begin{macro}{\@@_radio_field:n}
690 % \begin{macrocode}
691 \cs_new_protected:Npn \@@_radio_field:n #1 %name
692 {
693 \pdf_object_if_exist:nF {@@/field/@@/radio/#1}
694 {
695 % \end{macrocode}
696 % We need an object and a seq for the Opt array.
697 % The object is written at the end of the document.
698 % \begin{macrocode}
699 \pdf_object_new:n {@@/field/@@/radio-Opt/#1}
700 \pdfdict_put:nne { l_@@/field }{Opt} { \pdf_object_ref:n {@@/field/@@/radio-Opt/#1} }
701 \seq_new:c { g_@@_radio_opt_#1_seq }
702 \hook_gput_code:nnn {shipout/lastpage}{pdffield/radio}
703 {
704 \pdf_object_write:nne
705 {@@/field/@@/radio-Opt/#1} { array }
706 {\seq_use:cn {g_@@_radio_opt_#1_seq}{~}}
707 }
708 % \end{macrocode}
709 % The default value is retrieved through a label:
710 % \begin{macrocode}
711 \pdfdict_put:nne { l_@@/field }{V} { /\property_ref:nn{#1}{pdfradioindex} }
712 \pdfdict_put:nne { l_@@/field }{DV} { /\property_ref:nn{#1}{pdfradioindex} }
713 % \end{macrocode}
714 % now we create the field and set it as parent for the following annotation.
715 % \begin{macrocode}
716 \@@_field:n { @@/radio/#1 }
717 % \end{macrocode}
718 % If the inunison bool has been set to false we need to pass this to the
719 % kids.
720 % \begin{macrocode}
721 \bool_if:NF \l_@@_radio_unison_bool
722 {
723 \cs_new:cpn {g_@@_radio_unison_state_#1_tl}
724 {
725 \bool_set_false:N \l_@@_radio_unison_bool
726 }
727 }
728 }
729 \keys_set:nn {pdffield}{parent={@@/radio/#1}}
730 }
731 \cs_generate_variant:Nn \@@_radio_field:n {V}
732 % \end{macrocode}
733 % \end{macro}
734 %
735 % \subsection{Assembling the radio}
736 %
737 % \begin{macro}{\@@_radio:n}
738 % The argument are key-val settings.
739 % At first we map the handlers. To setup the appearance we need the
740 % Opt array, so the appearance handler only stores the code.
741 % \begin{macrocode}
742 \cs_new_protected:Npn \@@_radio:n #1
743 {
744 \group_begin:
745 \cs_set_eq:NN\@@_appearance_handler:nnn \@@_radio_appearance_handler:nnn
746 \cs_set_eq:NN\@@_value_handler:n \@@_radio_value_handler:n
747 \cs_set_eq:NN\@@_default_handler:n \@@_radio_default_handler:n
748 % \end{macrocode}
749 % Setting up the defaults.
750 % \begin{macrocode}
751 \tl_set:Nn\l_@@_radio_appearance_code_tl{}
752 \bool_set_false:N\l_@@_radio_default_bool
753 \keys_set:nn {pdffield}
754 {
755 fieldID=
756 ,name=radio
757 ,width = \normalbaselineskip
758 ,height = \normalbaselineskip
759 ,inunison
760 ,@@/preset/radiobutton
761 ,#1
762 ,unsetFf={Pushbutton}
763 ,setFf={Radio}
764 ,FT= Btn
765 }
766 % \end{macrocode}
767 % If the fieldID has not been set explicitly, we use the name/T key
768 % \begin{macrocode}
769 \tl_if_empty:NT\l_@@_fieldID_tl
770 {
771 \pdfdict_get:nnN {l_@@/field}{T}\l_@@_fieldID_tl
772 \tl_put_left:Nn \l_@@_fieldID_tl {@pdffield/radio/}
773 }
774 % \end{macrocode}
775 % If unison has been set for the field pass it on:
776 % \begin{macrocode}
777 \cs_if_exist_use:c {g_@@_radio_unison_state_ \l_@@_fieldID_tl _tl}
778 % \end{macrocode}
779 % Now we build the field
780 % \begin{macrocode}
781 \@@_radio_field:V\l_@@_fieldID_tl
782 % \end{macrocode}
783 % Put the value into the seq
784 % \begin{macrocode}
785 \seq_gput_right:cV { g_@@_radio_opt_ \l_@@_fieldID_tl _seq }\l_@@_radio_value_tl
786 % \end{macrocode}
787 % Retrieve the number for the label
788 % \begin{macrocode}
789 \bool_if:NTF \l_@@_radio_unison_bool
790 {
791 \int_zero:N \l_@@_radio_value_num_int
792 \exp_args:Nc
793 \seq_map_inline:Nn { g_@@_radio_opt_ \l_@@_fieldID_tl _seq }
794 {
795 \str_if_eq:nVTF { ##1 } \l_@@_radio_value_tl
796 {
797 \seq_map_break:
798 }
799 {
800 \int_incr:N \l_@@_radio_value_num_int
801 }
802 }
803 }
804 {
805 \int_set:Nn \l_@@_radio_value_num_int
806 {\seq_count:c { g_@@_radio_opt_ \l_@@_fieldID_tl _seq } -1 }
807 }
808 \bool_if:NT\l_@@_radio_default_bool
809 {
810 \mode_leave_vertical:
811 \property_record:Vn\l_@@_fieldID_tl{pdfradioindex}
812 }
813
814 % \end{macrocode}
815 % Annotations with the default value are set to on, the rest to off
816 % \begin{macrocode}
817 \int_compare:nNnTF { \l_@@_radio_value_num_int } =
818 {
819 \property_ref:Vn\l_@@_fieldID_tl{pdfradioindex}
820 }
821 { \pdfannot_dict_put:nne {widget}{AS}{/\property_ref:Vn\l_@@_fieldID_tl{pdfradioindex}} }
822 { \pdfannot_dict_put:nne {widget}{AS}{/Off} }
823 % \end{macrocode}
824 % Now we set the appearances, if no key has been use we take the default.
825 % \begin{macrocode}
826 \tl_if_empty:NT\l_@@_radio_appearance_code_tl
827 {
828 \@@_radio_default_appearances:
829 \keys_set:nn {pdffield}
830 {
831 appearance = pdffield/radio/default,
832 down-appearance = pdffield/radio/defaultdown,
833 }
834 }
835 \l_@@_radio_appearance_code_tl
836 \@@_annot:
837 \group_end:
838 }
839 % \end{macrocode}
840 % \end{macro}
841 %
842 % \subsection{Keys and handlers}
843 % Most keys are inherited simply the ones from the generic field and annot keys.
844 % We define a group key, as the name is better.
845 % The value key sets the export value. default the button which is checked on.
846 % At first the two handlers
847 % \begin{macro}{\@@_radio_value_handler:n,\@@_radio_default_handler:n}
848 % \begin{macrocode}
849 \cs_new_protected:Npn \@@_radio_value_handler:n #1
850 {
851 \pdf_string_from_unicode:nnN {utf16/string}{#1}\l_@@_radio_value_tl
852 }
853 \cs_new_protected:Npn \@@_radio_default_handler:n #1
854 {
855 %\pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_radio_default_tl
856 \bool_set_true:N \l_@@_radio_default_bool
857 }
858 % \end{macrocode}
859 % \end{macro}
860 %
861 % \begin{macro}{group}
862 % \begin{macrocode}
863 \keys_define:nn { pdffield }
864 {
865 group .meta:n = {T=#1}
866 }
867 % \end{macrocode}
868 % \end{macro}
869 %
870 % \begin{macro}{inunison}
871 % \begin{macrocode}
872 \keys_define:nn { pdffield }
873 {
874 inunison .choice:
875 ,inunison / true .code:n =
876 {
877 \bool_set_true:N \l_@@_radio_unison_bool
878 \bitset_set_true:Nn \l_@@_Ff_bitset {RadiosInUnison}
879 }
880 ,inunison / false .code:n =
881 {
882 \bool_set_false:N \l_@@_radio_unison_bool
883 \bitset_set_false:Nn \l_@@_Ff_bitset {RadiosInUnison}
884 }
885 ,inunison .default:n = {true}
886 }
887 % \end{macrocode}
888 % \end{macro}
889 % \begin{macro}{\@@_radio_appearance_handler:nnn}
890 % The handler for the appearances stores only the code
891 % as it must be executed rather late.
892 % \begin{macrocode}
893 \cs_new_protected:Npn \@@_radio_appearance_handler:nnn #1 #2 #3 %name, type, text
894 {
895 \tl_put_right:Nn \l_@@_radio_appearance_code_tl
896 {
897 \pdfxform_if_exist:nTF { #1 / Yes }
898 {
899 \pdf_object_unnamed_write:ne
900 {dict}
901 {
902 /\int_use:N \l_@@_radio_value_num_int
903 \c_space_tl \pdfxform_ref:n { #1/Yes}
904 /Off ~ \pdfxform_ref:n { #1/Off}
905 }
906 \pdfannot_dict_put:nne {widget/AP}{#2}{\pdf_object_ref_last:}
907 }
908 {
909 \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
910 }
911 }
912 }
913
914 % \end{macrocode}
915 %
916 % \end{macro}
917 %
918 % \subsection{User commands}
919 % \begin{macro}{\pdffield_radio:n}
920 % \begin{macrocode}
921 \cs_set_eq:NN \pdffield_radio:n \@@_radio:n
922 %</package>
923 % \end{macrocode}
924 % \end{macro}
925 %\end{implementation}
926 % \PrintIndex