| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3pdffield-choice.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 |
\usepackage{array,booktabs} |
| 30 |
\usepackage{l3pdffield} |
| 31 |
\hypersetup{pdfauthor=The LaTeX Project, |
| 32 |
pdftitle=l3pdffield (LaTeX PDF management bundle)} |
| 33 |
\begin{document} |
| 34 |
\DocInput{\jobname.dtx} |
| 35 |
\end{document} |
| 36 |
%</driver> |
| 37 |
% \fi |
| 38 |
% \providecommand\hook[1]{\texttt{#1}} |
| 39 |
% \title{^^A |
| 40 |
% The \pkg{l3pdffield-choice} module\\ Commands to create choice fields ^^A |
| 41 |
% \\ \LaTeX{} PDF management bundle |
| 42 |
% } |
| 43 |
% |
| 44 |
% \author{^^A |
| 45 |
% The \LaTeX{} Project\thanks |
| 46 |
% {^^A |
| 47 |
% E-mail: |
| 48 |
% \href{mailto:[email protected]} |
| 49 |
% {[email protected]}^^A |
| 50 |
% }^^A |
| 51 |
% } |
| 52 |
% |
| 53 |
% \date{Version 0.97c, released 2026-05-26} |
| 54 |
% |
| 55 |
% \maketitle |
| 56 |
% \begin{documentation} |
| 57 |
% \section{\pkg{l3pdffield-choice} Introduction} |
| 58 |
% This is the documentation for choice fields, for general information about form fields |
| 59 |
% check the documentation l3pdffield. |
| 60 |
% |
| 61 |
% |
| 62 |
% Please keep in mind |
| 63 |
% \begin{itemize} |
| 64 |
% \item Not every PDF viewer supports choice field. |
| 65 |
% \item The handling can depend on settings in the PDF viewer. In adobe reader for |
| 66 |
% example I had to disable an option to avoid that it tries to create an appearance |
| 67 |
% itself |
| 68 |
% \item Standards like pdf/A disable features of form fields too |
| 69 |
% (as you typically can't change the PDF). |
| 70 |
% \end{itemize} |
| 71 |
% \section{Choice fields} |
| 72 |
% |
| 73 |
% Choice fields are drop down menus or scrollable lists where |
| 74 |
% the user can select one or more entries. They can also contain a field where |
| 75 |
% users can insert a free text. The export value and the displayed value can differ. |
| 76 |
% Some values can be preselected. |
| 77 |
% |
| 78 |
% This means that various data will have to be set, and the sorting matters. |
| 79 |
% The module here will assume that the various values are stored in sequences: |
| 80 |
% |
| 81 |
% \begin{verbatim} |
| 82 |
% \seq_const_from_clist:Nn \c_my_values_seq {hippo,duck,bear} |
| 83 |
% \seq_const_from_clist:Nn \c_my_displayvalues_seq {Sieglinde,,Bär} |
| 84 |
% \seq_const_from_clist:Nn \c_my_defaultvalues_seq {duck,Bär} |
| 85 |
% \end{verbatim} |
| 86 |
% |
| 87 |
% Only the first sequence is required. |
| 88 |
% Empty values in the display sequence are possible, then the normal value is used. |
| 89 |
% |
| 90 |
% \subsection{Types} |
| 91 |
% Choice fields can be a drop down menu (called |Combo|), which can contain an editable |
| 92 |
% field. |
| 93 |
% |
| 94 |
% |setfieldflags={Combo,Edit}| or |setfieldflags={Combo}| |
| 95 |
% |
| 96 |
% If |Edit| is set, one can also set |DoNotSpellCheck|. |
| 97 |
% |
| 98 |
% Or they can be a list. |
| 99 |
% |
| 100 |
% |unsetfieldflags={Combo,Edit,DoNotSpellCheck}| |
| 101 |
% |
| 102 |
% |
| 103 |
% For both types it is possible to set or unset |MultiSelect| and |CommitOnSelChange|. |
| 104 |
% |
| 105 |
% |
| 106 |
% \subsection{Appearance} |
| 107 |
% By default the fields use a grey background as appearance, another appearance |
| 108 |
% can be defined with |\pdffield_appearance:nn| (described in the documentation of |
| 109 |
% l3pdffield) or directly with |\pdfxform_new:nnn| (in l3pdfxfom) |
| 110 |
% and then used with the |appearance| as in other form fields. |
| 111 |
% |
| 112 |
% |
| 113 |
% \subsection{Commands} |
| 114 |
% \begin{function}{\pdffield_choice:n} |
| 115 |
% \begin{syntax} |
| 116 |
% \cs{pdffield_choice:n} \Arg{key val list} |
| 117 |
% \end{syntax} |
| 118 |
% This creates a choice field. |
| 119 |
% The list of allowed keys is described below. |
| 120 |
% The \meta{key val list} should at least set the name, |
| 121 |
% without it the default |choice| is used. Choice fields with the same name |
| 122 |
% belong to the same field and if changed, the others are changed accordingly. |
| 123 |
% As default appearance we reuse the text appearance: a simple gray background. |
| 124 |
% |
| 125 |
% The first choice field setups the field and so should setup values and field flags. |
| 126 |
% \end{function} |
| 127 |
% |
| 128 |
% |
| 129 |
% \subsection{Keys} |
| 130 |
% |
| 131 |
% The new choice command accept all field and annot keys from l3pdffield. |
| 132 |
% A few keys are disabled or are forced to specific values. |
| 133 |
% The |appearance| keys have a ... |
| 134 |
% behaviour, other keys have other defaults than with the basic commands. |
| 135 |
% Additionally there |
| 136 |
% are a small number of keys specific to a choice field. |
| 137 |
% |value| and |default| have a special meaning. |
| 138 |
% |
| 139 |
% |
| 140 |
% Disabled keys are |
| 141 |
% \begin{itemize} |
| 142 |
% \item |V|, |DV|, |AS|: they are set by the other keys. |
| 143 |
% \item |FT| is overwritten. |
| 144 |
% \item For fields only the field flags |ReadOnly|, |Required|, |NoExport|, |
| 145 |
% |Combo|, |Edit|, |MultiSelect|, |Sort|, |DoNotSpellCheck| and |CommitOnSelChange| |
| 146 |
% make sense. The code will force some values (e.g. disable |Edit| if |Combo| is false). |
| 147 |
% \end{itemize} |
| 148 |
% |
| 149 |
% |
| 150 |
% \begin{function}{preset-choice} |
| 151 |
% \begin{syntax} |
| 152 |
% |preset-choice| = \Arg{key val list} |
| 153 |
% \end{syntax} |
| 154 |
% This allows to set default keys for a choice field. |
| 155 |
% \end{function} |
| 156 |
|
| 157 |
% \begin{function}{type} |
| 158 |
% \begin{syntax} |
| 159 |
% |type| = \texttt{combo}\verb+|+\texttt{combo-edit}\verb+|+\texttt{list} |
| 160 |
% \end{syntax} |
| 161 |
% This key is a choice key that allows to set the three types. |
| 162 |
% \end{function} |
| 163 |
|
| 164 |
% |
| 165 |
% \begin{function}{name,T} |
| 166 |
% \begin{syntax} |
| 167 |
% |name| = \meta{partial name}\\ |
| 168 |
% |T| = \meta{partial name} |
| 169 |
% \end{syntax} |
| 170 |
% These keys set the partial name of the field. They both do the same |
| 171 |
% thing, use the one you are more comfortable with. The value |
| 172 |
% shouldn't contain a period, be not empty and sensibly consist of simple chars. |
| 173 |
% Additionally the value is used to create the field ID. |
| 174 |
% This means that choice field with the same partial name are annotations |
| 175 |
% with the same field as parent. |
| 176 |
% The field ID is then internal and can not be used to |
| 177 |
% attach another annotation. |
| 178 |
% For explicit control of the field ID use the |fieldID| key. |
| 179 |
% \end{function} |
| 180 |
% |
| 181 |
% \begin{function}{value,values} |
| 182 |
% \begin{syntax} |
| 183 |
% |value| = \Arg{comma separated list of values} |
| 184 |
% |values| = \Arg{comma separated list of values} |
| 185 |
% \end{syntax} |
| 186 |
% With these keys you set the export value names. \meta{comma separated list of values} should contain |
| 187 |
% the values in the order as wanted. The values are passed through |\pdf_string_from_unicode:nnN| |
| 188 |
% and can use unicode. |
| 189 |
% \end{function} |
| 190 |
% |
| 191 |
% \begin{function}{display-values} |
| 192 |
% \begin{syntax} |
| 193 |
% |display-values| = \Arg{comma separated list of values} |
| 194 |
% \end{syntax} |
| 195 |
% With this key you set the display value names if they should be |
| 196 |
% different from the export values. They should be given in the same order as the values. |
| 197 |
% The values are passed through |\pdf_string_from_unicode:nnN| |
| 198 |
% and can use unicode. |
| 199 |
% \end{function} |
| 200 |
% |
| 201 |
% \begin{function}{default,default-values} |
| 202 |
% \begin{syntax} |
| 203 |
% |default| = \Arg{comma separated list of values} |
| 204 |
% |default-values| = \Arg{comma separated list of values} |
| 205 |
% \end{syntax} |
| 206 |
% With this keys you set the values which are selected when the PDF is opened. |
| 207 |
% The use of this keys is a bit dubious. It seems to work okay for combo fields, |
| 208 |
% but not for list fields. According to the PDF reference the |
| 209 |
% values should be the display values, but it is not clear if the PDF viewer |
| 210 |
% really implement it that way or if the export value should be preferred. |
| 211 |
% Depending on the values it could be needed to |
| 212 |
% add also an |I| array to the field. |
| 213 |
% \end{function} |
| 214 |
|
| 215 |
% \begin{function}{top-index} |
| 216 |
% \begin{syntax} |
| 217 |
% |top-index| = \Arg{integer} |
| 218 |
% \end{syntax} |
| 219 |
% With this key you set for a scrollable list field the number of the |
| 220 |
% value shown at the top. The first value has number 1 (that is the default). |
| 221 |
% I'm not sure if viewers handle this correctly, so the setting should be used with |
| 222 |
% care. |
| 223 |
% \end{function} |
| 224 |
|
| 225 |
% \begin{function}{fieldID} |
| 226 |
% \begin{syntax} |
| 227 |
% |fieldID| = \meta{field ID}\\ |
| 228 |
% \end{syntax} |
| 229 |
% \emph{For experts only!} |
| 230 |
% This allows to give the radio field a specific ID. This is only useful |
| 231 |
% in the context of a larger fieldset or if you want to attach another annotation |
| 232 |
% to the field with \cs{pdffield_annot:n}. If used wrongly you can |
| 233 |
% easily create invalid fieldset. It allows you to create to fields with the |
| 234 |
% same partial name, but if you want to see both |
| 235 |
% you need to ensure that their full names are |
| 236 |
% different---for example by adding some parent fields. |
| 237 |
% \end{function} |
| 238 |
% |
| 239 |
% \begin{function}{parent} |
| 240 |
% \begin{syntax} |
| 241 |
% |parent| = \meta{field ID}\\ |
| 242 |
% \end{syntax} |
| 243 |
% This is only needed if the field should be part |
| 244 |
% of a larger fieldset. The value should be a field ID of a field created previously |
| 245 |
% with \cs{pdffield_field:nn}. |
| 246 |
% \end{function} |
| 247 |
% |
| 248 |
% |
| 249 |
% \begin{function}{width,height,depth} |
| 250 |
% \begin{syntax} |
| 251 |
% |width| = \meta{dim expression}\\ |
| 252 |
% |height| = \meta{dim expression}\\ |
| 253 |
% |depth| = \meta{dim expression} |
| 254 |
% \end{syntax} |
| 255 |
% These keys allow to set the dimensions of the choice field. |
| 256 |
% The value should be a dimension expression. By default |
| 257 |
% |width| and |height| and |depth| are .... |
| 258 |
% \end{function} |
| 259 |
% |
| 260 |
% \begin{function}{AP/N,appearance,AP/R,rollover-appearance,AP/D,down-appearance} |
| 261 |
% \begin{syntax} |
| 262 |
% |AP/N| = \meta{appearance name}\\ |
| 263 |
% |appearance| = \meta{appearance name}\\ |
| 264 |
% |AP/R| = \meta{appearance name}\\ |
| 265 |
% |rollover-appearance| = \meta{appearance name}\\ |
| 266 |
% |AP/D| = \meta{appearance name}\\ |
| 267 |
% |down-appearance| = \meta{appearance name} |
| 268 |
% \end{syntax} |
| 269 |
% This adds appearances. \meta{appearance name} should be the name of an form Xobjects. |
| 270 |
% The default normal appearance is a simple gray background, the same as with |
| 271 |
% text fields. |
| 272 |
% \end{function} |
| 273 |
% |
| 274 |
% The font are handled in a similar way as in textfield. Most of the remarks made there |
| 275 |
% are true for choice fields too. |
| 276 |
% |
| 277 |
% \begin{function}{fontcolor} |
| 278 |
% \begin{syntax} |
| 279 |
% |fontcolor| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}\\ |
| 280 |
% \end{syntax} |
| 281 |
% This is sets the color of font in the textfield. Internally currently RGB is used. |
| 282 |
% The colors used in |
| 283 |
% \meta{color expression} must be known to the \pkg{l3color} commands. |
| 284 |
% The initial color is black. It is a \emph{field} setting, that means instances |
| 285 |
% share the color. |
| 286 |
% \end{function} |
| 287 |
% |
| 288 |
% \begin{function}{fontsize} |
| 289 |
% \begin{syntax} |
| 290 |
% |fontsize| = \meta{dim expression} |
| 291 |
% \end{syntax} |
| 292 |
% This is sets the size of the font in the textfield. |
| 293 |
% The default value is the current font size (\cs{f@size} in pt). |
| 294 |
% It is a \emph{field} setting, that means instances |
| 295 |
% share the size. |
| 296 |
% \end{function} |
| 297 |
% |
| 298 |
% \begin{function}{font} |
| 299 |
% \begin{syntax} |
| 300 |
% |font| = \meta{symbolic font name} |
| 301 |
% \end{syntax} |
| 302 |
% This is sets the font in the textfield. See the discussion at the begin of |
| 303 |
% the documentation about some background. The default value is |Helv| and this |
| 304 |
% name is setup if you load hyperref and issue the \cs{Form} command. |
| 305 |
% The default value is the current font size (\cs{f@size} in pt). |
| 306 |
% It is a \emph{field} setting, that means instances |
| 307 |
% share the font. |
| 308 |
% \end{function} |
| 309 |
% \subsection{Using with hyperref} |
| 310 |
% |
| 311 |
% hyperref combines radio button and choice field in one command. This makes it |
| 312 |
% difficult to replicate the hyperref commands here. |
| 313 |
% |
| 314 |
% \end{documentation} |
| 315 |
% |
| 316 |
% \begin{implementation} |
| 317 |
% % \DoNotIndex |
| 318 |
% {\\ |
| 319 |
% ,\bitset_clear:N |
| 320 |
% ,\bitset_new:Nn |
| 321 |
% ,\bitset_set_false:Nn |
| 322 |
% ,\bitset_set_true:Nn |
| 323 |
% ,\bitset_to_arabic:N |
| 324 |
% ,\bitset_item:Nn |
| 325 |
% ,\bool_new:N |
| 326 |
% ,\box_dp:N |
| 327 |
% ,\box_ht:N |
| 328 |
% ,\clist_map_inline:nn |
| 329 |
% ,\color_export:nnN |
| 330 |
% ,\color_set:nn |
| 331 |
% ,\color_set:nnn |
| 332 |
% ,\color_select:n |
| 333 |
% ,\cs_new_protected:Npn |
| 334 |
% ,\cs_new_protected:cpn |
| 335 |
% ,\cs_set_eq:NN |
| 336 |
% ,\cs_gset_eq:cN |
| 337 |
% ,\cs_set_protected:Npn |
| 338 |
% ,\cs_generate_variant:Nn |
| 339 |
% ,\cs_gset_eq:NN |
| 340 |
% ,\c_space_tl |
| 341 |
% ,\csname |
| 342 |
% ,\dim_eval:n |
| 343 |
% ,\dim_new:N |
| 344 |
% ,\dim_to_decimal_in_bp:n |
| 345 |
% ,\endcsname |
| 346 |
% ,\exp_args:Ne |
| 347 |
% ,\exp_args:Nc |
| 348 |
% ,\fboxsep |
| 349 |
% ,\fp_eval:n |
| 350 |
% ,\f@size |
| 351 |
% ,\group_begin: |
| 352 |
% ,\group_end: |
| 353 |
% ,\hbox_to_wd:nn |
| 354 |
% ,\hfill |
| 355 |
% ,\hook_gput_code:nnn |
| 356 |
% ,\int_eval:n |
| 357 |
% ,\int_compare:nNnT |
| 358 |
% ,\int_compare:nNnTF |
| 359 |
% ,\int_incr:N |
| 360 |
% ,\int_new:N |
| 361 |
% ,\int_use:N |
| 362 |
% ,\int_zero:N |
| 363 |
% ,\l_keys_choice_int |
| 364 |
% ,\keys_define:nn |
| 365 |
% ,\keys_set:nn |
| 366 |
% ,\mode_leave_vertical: |
| 367 |
% ,\msg_error:nnn |
| 368 |
% ,\msg_error:nnnn |
| 369 |
% ,\msg_new:nnn |
| 370 |
% ,\msg_warning:nn |
| 371 |
% ,\msg_warning:nnn |
| 372 |
% ,\msg_warning:nnnnn |
| 373 |
% ,\NeedsTeXFormat |
| 374 |
% ,\normalsize |
| 375 |
% ,\paperheight |
| 376 |
% ,\paperwidth |
| 377 |
% ,\pdf_name_from_unicode_e:n |
| 378 |
% ,\pdf_object_if_exist:nTF |
| 379 |
% ,\pdf_object_if_exist:nF |
| 380 |
% ,\pdf_object_new:n |
| 381 |
% ,\pdf_object_ref:n |
| 382 |
% ,\pdf_object_ref_last: |
| 383 |
% ,\pdf_object_unnamed_write:nn |
| 384 |
% ,\pdf_object_unnamed_write:ne |
| 385 |
% ,\pdf_object_write:nne |
| 386 |
% ,\pdf_object_write:nnn |
| 387 |
% ,\pdf_string_from_unicode:nnN |
| 388 |
% ,\pdfannot_box_ref_last: |
| 389 |
% ,\pdfannot_dict_put:nnn |
| 390 |
% ,\pdfannot_dict_put:nne |
| 391 |
% ,\pdfdict_put:nne |
| 392 |
% ,\pdfannot_dict_remove:nn |
| 393 |
% ,\pdfannot_widget_box:nnn |
| 394 |
% ,\pdfdict_if_empty:nTF |
| 395 |
% ,\pdfdict_get:nnN |
| 396 |
% ,\pdfdict_new:n |
| 397 |
% ,\pdfdict_put:nnn |
| 398 |
% ,\pdfdict_remove:nn |
| 399 |
% ,\pdfdict_use:n |
| 400 |
% ,\pdfmanagement_add:nnn |
| 401 |
% ,\pdfmeta_standard_verify:nTF |
| 402 |
% ,\pdfxform_if_exist:nTF |
| 403 |
% ,\pdfxform_new:nnn |
| 404 |
% ,\pdfxform_ref:n |
| 405 |
% ,\phantom |
| 406 |
% ,\prg_do_nothing: |
| 407 |
% ,\ProvidesExplPackage |
| 408 |
% ,\quark_if_no_value:NT |
| 409 |
% ,\raisebox |
| 410 |
% ,\RequirePackage |
| 411 |
% ,\rule |
| 412 |
% ,\seq_gput_right:Nn |
| 413 |
% ,\seq_gput_right:cV |
| 414 |
% ,\seq_gput_left:cV |
| 415 |
% ,\seq_if_in:cVF |
| 416 |
% ,\seq_map_break: |
| 417 |
% ,\seq_map_inline:Nn |
| 418 |
% ,\seq_new:c |
| 419 |
% ,\seq_use:cn |
| 420 |
% ,\seq_if_exist:NTF |
| 421 |
% ,\seq_new:N |
| 422 |
% ,\seq_use:Nn |
| 423 |
% ,\smash |
| 424 |
% ,\str_if_empty:NTF |
| 425 |
% ,\str_if_in:NnTF |
| 426 |
% ,\str_if_eq:nVTF |
| 427 |
% ,\str_new:N |
| 428 |
% ,\strut |
| 429 |
% ,\strutbox |
| 430 |
% ,\tl_put_right:Nn |
| 431 |
% ,\tl_if_empty:NTF |
| 432 |
% ,\tl_if_empty:NT |
| 433 |
% ,\tl_if_empty:NF |
| 434 |
% ,\tl_put_left:Nn |
| 435 |
% ,\tl_if_eq:NnF |
| 436 |
% ,\tl_if_empty:nTF |
| 437 |
% ,\tl_if_head_eq_charcode:nNTF |
| 438 |
% ,\tl_new:N |
| 439 |
% ,\tl_set:Nn |
| 440 |
% ,\tl_to_str:n |
| 441 |
% ,\use:c |
| 442 |
% } |
| 443 |
% \section{\pkg{l3pdffield-choice} Implementation} |
| 444 |
% \begin{macrocode} |
| 445 |
%<*package> |
| 446 |
%<@@=pdffield> |
| 447 |
\RequirePackage{l3draw} |
| 448 |
% \end{macrocode} |
| 449 |
% \subsection{Variables} |
| 450 |
% \begin{variable} |
| 451 |
% { |
| 452 |
% \l_@@_choice_values_seq |
| 453 |
% ,\l_@@_choice_defaultvalues_seq |
| 454 |
% ,\l_@@_choice_displayvalues_seq |
| 455 |
% ,\l_@@_choice_opt_seq |
| 456 |
% } |
| 457 |
% variables to hold the value, the default value, and display variants. The opt |
| 458 |
% seq will be used to build the content of opt |
| 459 |
% \begin{macrocode} |
| 460 |
\seq_new:N \l_@@_choice_values_seq |
| 461 |
\seq_new:N \l_@@_choice_defaultvalues_seq |
| 462 |
\seq_new:N \l_@@_choice_displayvalues_seq |
| 463 |
\seq_new:N \l_@@_choice_opt_seq |
| 464 |
% \end{macrocode} |
| 465 |
% \end{variable} |
| 466 |
% |
| 467 |
% \subsection{Appearances} |
| 468 |
% (probably take from textfield ...) |
| 469 |
% |
| 470 |
%\subsection{Creating the field} |
| 471 |
% A field should be created if the name doesn't exist yet |
| 472 |
% \begin{macro}{\@@_choice_field:n} |
| 473 |
% \begin{macrocode} |
| 474 |
\cs_new_protected:Npn \@@_choice_field:n #1 %name |
| 475 |
{ |
| 476 |
\pdf_object_if_exist:nF {@@/field/@@/choice/#1} |
| 477 |
{ |
| 478 |
% \end{macrocode} |
| 479 |
% We must at first build the Opt array. |
| 480 |
% \begin{macrocode} |
| 481 |
\seq_clear:N \l_@@_choice_opt_seq |
| 482 |
\seq_map_indexed_inline:Nn \l_@@_choice_values_seq |
| 483 |
{ |
| 484 |
\pdf_string_from_unicode:nnN{utf16/hex}{##2}\l_@@_tmpa_str |
| 485 |
\tl_set:Ne \l_@@_tmpa_tl {\seq_item:Nn \l_@@_choice_displayvalues_seq {##1} } |
| 486 |
\tl_if_empty:NTF \l_@@_tmpa_tl |
| 487 |
{ |
| 488 |
\seq_put_right:NV \l_@@_choice_opt_seq \l_@@_tmpa_str |
| 489 |
} |
| 490 |
{ |
| 491 |
\exp_args:NnV |
| 492 |
\pdf_string_from_unicode:nnN{utf16/hex}\l_@@_tmpa_tl\l_@@_tmpb_str |
| 493 |
\seq_put_right:Ne \l_@@_choice_opt_seq |
| 494 |
{ [ \l_@@_tmpa_str\c_space_tl\l_@@_tmpb_str] } |
| 495 |
} |
| 496 |
} |
| 497 |
\pdf_object_unnamed_write:ne {array}{\seq_use:Nn\l_@@_choice_opt_seq {~}} |
| 498 |
\pdfdict_put:nne { l_@@/field }{Opt} { \pdf_object_ref_last: } |
| 499 |
% \end{macrocode} |
| 500 |
% Now we handle the V value. If MultiSelect is set, we use the full |
| 501 |
% displayvalues seq, if not only the first value. |
| 502 |
% \begin{macrocode} |
| 503 |
\int_compare:nNnTF {\bitset_item:Nn \l_@@_Ff_bitset {MultiSelect}} = {1} |
| 504 |
{ |
| 505 |
\tl_clear:N \l_@@_tmpa_tl |
| 506 |
\seq_map_inline:Nn \l_@@_choice_defaultvalues_seq |
| 507 |
{ |
| 508 |
\pdf_string_from_unicode:nnN{utf16/hex}{##1}\l_@@_tmpa_str |
| 509 |
\tl_put_right:NV \l_@@_tmpa_tl \l_@@_tmpa_str |
| 510 |
\pdfdict_put:nne { l_@@/field }{V} { [ \l_@@_tmpa_tl ] } |
| 511 |
} |
| 512 |
} |
| 513 |
{ |
| 514 |
\tl_set:Ne \l_@@_tmpa_tl {\seq_item:Nn \l_@@_choice_defaultvalues_seq {1} } |
| 515 |
\exp_args:NnV |
| 516 |
\pdf_string_from_unicode:nnN{utf16/hex}\l_@@_tmpa_tl\l_@@_tmpb_str |
| 517 |
\pdfdict_put:nne { l_@@/field }{V} { \l_@@_tmpb_str } |
| 518 |
} |
| 519 |
% \end{macrocode} |
| 520 |
% now we create the field and set it as parent for the following annotation. |
| 521 |
% \begin{macrocode} |
| 522 |
\@@_field:n { @@/choice/#1 } |
| 523 |
} |
| 524 |
\keys_set:nn {pdffield}{parent={@@/choice/#1}} |
| 525 |
} |
| 526 |
\cs_generate_variant:Nn \@@_choice_field:n {V} |
| 527 |
% \end{macrocode} |
| 528 |
% \end{macro} |
| 529 |
% |
| 530 |
% \subsection{Assembling the choice field} |
| 531 |
% |
| 532 |
% \begin{macro}{\@@_choice:n} |
| 533 |
% The argument are key-val settings. |
| 534 |
% At first we map the handlers. |
| 535 |
% As default appearance we reuse the text appearance: a simple gray background. |
| 536 |
% \begin{macrocode} |
| 537 |
\cs_new_protected:Npn \@@_choice:n #1 |
| 538 |
{ |
| 539 |
\group_begin: |
| 540 |
\cs_set_eq:NN\@@_value_handler:n \@@_choice_value_handler:n |
| 541 |
\cs_set_eq:NN\@@_default_handler:n \@@_choice_default_handler:n |
| 542 |
\@@_textfield_default_appearance: |
| 543 |
% \end{macrocode} |
| 544 |
% Setting up the defaults. |
| 545 |
% \begin{macrocode} |
| 546 |
\keys_set:nn {pdffield} |
| 547 |
{ |
| 548 |
fieldID= |
| 549 |
,name=choice |
| 550 |
,appearance = pdffield/textfield/default |
| 551 |
,width = 3cm |
| 552 |
,height = \normalbaselineskip |
| 553 |
,type=combo-edit |
| 554 |
,@@/preset/choice |
| 555 |
,#1 |
| 556 |
,FT= Ch |
| 557 |
} |
| 558 |
\@@_choice_set_type: |
| 559 |
\keys_set:nn {pdffield} |
| 560 |
{ |
| 561 |
,DA= |
| 562 |
{ |
| 563 |
\pdf_name_from_unicode_e:n{\l_@@_DA_fontname_tl} |
| 564 |
\c_space_tl |
| 565 |
\dim_to_decimal_in_bp:n{\l_@@_DA_fontsize_dim} |
| 566 |
\c_space_tl |
| 567 |
Tf |
| 568 |
\c_space_tl |
| 569 |
\l_@@_DA_fontcolor_tl |
| 570 |
\c_space_tl |
| 571 |
%\l_@@_text_DAextra_tl |
| 572 |
} |
| 573 |
} |
| 574 |
% \end{macrocode} |
| 575 |
% If the fieldID has not been set explicitly, we use the name/T key |
| 576 |
% \begin{macrocode} |
| 577 |
\tl_if_empty:NT\l_@@_fieldID_tl |
| 578 |
{ |
| 579 |
\pdfdict_get:nnN {l_@@/field}{T}\l_@@_fieldID_tl |
| 580 |
\tl_put_left:Nn \l_@@_fieldID_tl {@@/choice/} |
| 581 |
} |
| 582 |
% \end{macrocode} |
| 583 |
% Now we build the field |
| 584 |
% \begin{macrocode} |
| 585 |
\@@_choice_field:V\l_@@_fieldID_tl |
| 586 |
% \end{macrocode} |
| 587 |
% And add the annotation. |
| 588 |
% \begin{macrocode} |
| 589 |
\@@_annot: |
| 590 |
\group_end: |
| 591 |
} |
| 592 |
% \end{macrocode} |
| 593 |
% \end{macro} |
| 594 |
% |
| 595 |
% \subsection{Keys and handlers} |
| 596 |
% Most keys are inherited simply the ones from the generic field and annot keys. |
| 597 |
% We define a group key, as the name is better. |
| 598 |
% The value key sets the export value. default the button which is checked on. |
| 599 |
% At first the two handlers |
| 600 |
% \begin{macro}{\@@_choice_value_handler:n,\@@_choice_default_handler:n,display-values} |
| 601 |
% \begin{macrocode} |
| 602 |
\cs_new_protected:Npn \@@_choice_value_handler:n #1 |
| 603 |
{ |
| 604 |
\seq_set_from_clist:Nn \l_@@_choice_values_seq {#1} |
| 605 |
} |
| 606 |
\cs_new_protected:Npn \@@_choice_default_handler:n #1 |
| 607 |
{ |
| 608 |
\seq_set_from_clist:Nn \l_@@_choice_defaultvalues_seq {#1} |
| 609 |
} |
| 610 |
\keys_define:nn{pdffield} |
| 611 |
{ |
| 612 |
values .meta:n = {value={#1}} |
| 613 |
,default-values .meta:n = {default={#1}} |
| 614 |
,display-values .code:n = |
| 615 |
{ |
| 616 |
\seq_set_from_clist:Nn \l_@@_choice_displayvalues_seq {#1} |
| 617 |
} |
| 618 |
,top-index .code:n = |
| 619 |
{ |
| 620 |
\pdfdict_put:nne {l_@@/field}{TI}{\int_eval:n{#1-1}} |
| 621 |
} |
| 622 |
} |
| 623 |
% \end{macrocode} |
| 624 |
% \end{macro} |
| 625 |
% |
| 626 |
% \begin{macro}{type} |
| 627 |
% \begin{macrocode} |
| 628 |
\cs_new_protected:Npn \@@_choice_set_type: {} |
| 629 |
|
| 630 |
\keys_define:nn { pdffield } |
| 631 |
{ |
| 632 |
type .choice: |
| 633 |
,type / combo .code:n = |
| 634 |
{ |
| 635 |
\cs_set_protected:Npn\@@_choice_set_type: |
| 636 |
{ |
| 637 |
\keys_set:nn{pdffield}{setFf={Combo},unsetFf={Edit,DoNotSpellCheck}} |
| 638 |
} |
| 639 |
} |
| 640 |
,type / combo-edit .code:n = |
| 641 |
{ |
| 642 |
\cs_set_protected:Npn\@@_choice_set_type: |
| 643 |
{ |
| 644 |
\keys_set:nn{pdffield}{setFf={Combo,Edit}} |
| 645 |
} |
| 646 |
} |
| 647 |
,type / list .code:n = |
| 648 |
{ |
| 649 |
\cs_set_protected:Npn\@@_choice_set_type: |
| 650 |
{ |
| 651 |
\keys_set:nn{pdffield}{unsetFf={Combo,Edit,},unsetFf={Edit,DoNotSpellCheck}} |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
% \end{macrocode} |
| 656 |
% \end{macro} |
| 657 |
% |
| 658 |
% |
| 659 |
% |
| 660 |
% \begin{macro}{\@@_choice_appearance_handler:nnn} |
| 661 |
% The handler for the appearances stores only the code |
| 662 |
% as it must be executed rather late. |
| 663 |
% \begin{macrocode} |
| 664 |
\cs_new_protected:Npn \@@_choice_appearance_handler:nnn #1 #2 #3 %name, type, text |
| 665 |
{ |
| 666 |
} |
| 667 |
|
| 668 |
% \end{macrocode} |
| 669 |
% |
| 670 |
% \end{macro} |
| 671 |
% |
| 672 |
% \subsection{User commands} |
| 673 |
% \begin{macro}{\pdffield_choice:n} |
| 674 |
% \begin{macrocode} |
| 675 |
\cs_set_eq:NN \pdffield_choice:n \@@_choice:n |
| 676 |
%</package> |
| 677 |
% \end{macrocode} |
| 678 |
% \end{macro} |
| 679 |
%\end{implementation} |
| 680 |
% \PrintIndex |