%%
%% This is file `l3pdffield-testphase.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3pdffield.dtx  (with options: `package')
%% l3pdffield-checkbox.dtx  (with options: `package')
%% l3pdffield-radiobutton.dtx  (with options: `package')
%% l3pdffield-textfield.dtx  (with options: `package')
%% l3pdffield-pushbutton.dtx  (with options: `package')
%% l3pdffield-choice.dtx  (with options: `package')
%% l3pdffield-action.dtx  (with options: `package')
%% 
%% Copyright (C) 2019-2021 The LaTeX Project
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    https://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "LaTeX PDF management testphase bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: l3pdffield.dtx

\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{l3pdffield-testphase}{2022-02-16}{0.95l}%
  {form fields}
\csname HyField@NeedAppearancesfalse\endcsname % suppress NeedAppearances
\str_new:N \l__pdffield_tmpa_str
\str_new:N \l__pdffield_tmpb_str
\tl_new:N  \l__pdffield_tmpa_tl
\tl_new:N  \l__pdffield_tmpa_keys_tl
\tl_new:N  \l__pdffield_currentparent_tl
\tl_new:N  \l__pdffield_fieldID_tl
\tl_new:N  \l__pdffield_caption_tl
\tl_new:N  \l__pdffield_rollover_caption_tl
\tl_new:N  \l__pdffield_down_caption_tl
\prop_new:N \g__pdffield_CO_sortkeys_prop
\seq_new:N \g__pdffield_CO_sortkeys_seq
\str_new:N  \l__pdffield_CO_sortkey_str
\tl_new:N \g__pdffield_annot_ref_last_tl
\bool_new:N \l__pdffield_tag_bool
\bool_set_true:N \l__pdffield_tag_bool
\cs_new_protected:Npn \__pdffield_tmpa:n #1 {}
\cs_new_protected:Npn \__pdffield_tmpa:nn #1 #2 {}

\msg_new:nnn {pdffield}{no-period}
  {
    The~field~name~`#1`~contains~a~period. \\
    This~is~not~allowed. `
  }
\msg_new:nnn {pdffield}{empty-name}
  {
    The~field~name~is~empty. \\
    This~is~not~allowed. `
  }
\msg_new:nnn {pdffield}{appearance-missing}
  {
    The~appearance~definition~`#1`~is~missing~for~the~#2~appearance.
  }
\msg_new:nnn {pdffield}{not-implemented}
  {
    Support~for~'/#1'~is~not~implemented\\
    The~key~is~ignored.
  }
\msg_new:nnn {pdffield}{key-disabled}
  {
    key~`#2`~is~disabled~and~ignored~in~the~`#1`~command.\\
    Use~key~`#3`~instead.
  }
\msg_new:nnn {pdffield}{parent-field-missing}
  {
    The~parent~field~'#1'~doesn't~exist\\
    Create~it~with~\tl_to_str:n{\pdffield_field:nn}
  }
\msg_new:nnn {pdffield}{key-ignored}
  {
    key~`#1`~has~no~function~and~is~ignored
  }

\cs_new_protected:Npn \__pdffield_key_disable:nnn #1#2#3
 {
   \keys_define:nn {pdffield}
    {
      #2 .code:n =
       {
         \msg_warning:nnnnn {pdffield}{key-disabled}{#1}{#2}{#3}
       }
    }
 }
\bitset_new:Nn \l__pdffield_Ff_bitset
 {
    ReadOnly          = 1,
    Required          = 2,
    NoExport          = 3,
    Multiline         = 13,%Tx
    Password          = 14,
    NoToggleToOff     = 15,%Btn, radio button
    Radio             = 16,%Btn: Radio:    15=1, 16=0
    Pushbutton        = 17,%Btn: Checkbox: 15=0, 16=0
                           %Btn: Pushbutton: 16=1
    Combo             = 18,%Ch: Combo=1 List=0
    Edit              = 19,%Ch, Combo=1 -> + edit field
    Sort              = 20,%Ch, not relevant for view...
    FileSelect        = 21,%Tx
    MultiSelect       = 22,%Ch
    DoNotSpellCheck   = 23,%Tx, Ch (if Combo + Edit set)
    DoNotScroll       = 24,%Tx
    Comb              = 25,%Tx, requires MaxLen in dict
    RadiosInUnison    = 26,%Btn Radio
    RichText          = 26,%Tx
    CommitOnSelChange = 27,
    readonly          = 1,
    required          = 2,
    noexport          = 3,
    multiline         = 13,%Tx
    password          = 14,
    notoggletooff     = 15,%Btn, radio button
    radio             = 16,%Btn: Radio:    15=1, 16=0
    pushbutton        = 17,%Btn: Checkbox: 15=0, 16=0
                           %Btn: Pushbutton: 16=1
    combo             = 18,%Ch: Combo=1 List=0
    edit              = 19,%Ch, Combo=1 -> + edit field
    sort              = 20,%Ch, not relevant for view...
    fileselect        = 21,%Tx
    multiselect       = 22,%Ch
    donotspellcheck   = 23,%Tx, Ch (if Combo + Edit set)
    donotscroll       = 24,%Tx
    comb              = 25,%Tx, requires MaxLen in dict
    radiosinunison    = 26,%Btn Radio
    richtext          = 26,%Tx
    commitonselchange = 27
  }

\bitset_new:Nn \l__pdffield_F_bitset
  {
    Invisible      = 1,
    Hidden         = 2,
    Print          = 3,
    NoZoom         = 4,
    NoRotate       = 5,
    NoView         = 6,
    ReadOnly       = 7,
    Locked         = 8,
    ToggleNoView   = 9,
    LockedContents = 10,
    invisible      = 1,
    hidden         = 2,
    print          = 3,
    nozoom         = 4,
    norotate       = 5,
    noview         = 6,
    readonly       = 7,
    locked         = 8,
    togglenoview   = 9,
    lockedcontents = 10
  }
\pdfdict_new:n   {l__pdffield/field}
\pdfdict_new:n   {l__pdffield/field/AA}
\cs_new_protected:Npn \__pdffield_field:n #1
  {
    \pdf_object_new:nn {__pdffield/field/#1}      {dict}
    \pdf_object_new:nn {__pdffield/field/Kids/#1} {array}
    \tl_if_empty:NTF \l__pdffield_currentparent_tl
      {
        \pdfmanagement_add:nnx
          { Catalog / AcroForm }
          { Fields }
          {\pdf_object_ref:n {__pdffield/field/#1} }
      }
      {
        \exp_args:Ne
        \pdf_object_if_exist:nTF {__pdffield/field/\l__pdffield_currentparent_tl}
          {
            \pdfdict_put:nnx { l__pdffield/field }{Parent}
              {\exp_args:Ne \pdf_object_ref:n{__pdffield/field/\l__pdffield_currentparent_tl}}
            \seq_gput_right:cx {g__pdffield_field/Kids/\l__pdffield_currentparent_tl _seq}
              { \exp_args:Ne \pdf_object_ref:n{__pdffield/field/#1}}
          }
          {
            \msg_error:nnx {pdffield}{parent-field-missing}{\l__pdffield_currentparent_tl}
          }
      }
    \seq_new:c {g__pdffield_field/Kids/#1_seq}
    \pdfdict_put:nnx {l__pdffield/field}
      {Kids}
      {
        \pdf_object_ref:n {__pdffield/field/Kids/#1}
      }
    \pdfdict_put:nnx {l__pdffield/field}
      {Ff}
      {\bitset_to_arabic:N \l__pdffield_Ff_bitset }
    \pdfdict_if_empty:nF{l__pdffield/field/AA}
      {
        \pdfmeta_standard_verify:nT
          {annot_widget_no_AA}
          {
            \pdf_object_unnamed_write:nx {dict}{\pdfdict_use:n {l__pdffield/field/AA}}
            \pdfdict_put:nnx
              {l__pdffield/field}
              {AA}
              {\pdf_object_ref_last:}
            \pdfdict_get:nnN {l__pdffield/field/AA}{C}\l__pdffield_tmpa_tl
            \quark_if_no_value:NF \l__pdffield_tmpa_tl
              {
                \prop_gput:Nxx\g__pdffield_CO_sortkeys_prop
                  { \pdf_object_ref:n {__pdffield/field/#1} }{ \l__pdffield_CO_sortkey_str }
                \seq_gput_right:Nx\g__pdffield_CO_sortkeys_seq
                  { \pdf_object_ref:n {__pdffield/field/#1} }
              }
          }
      }
    \hook_gput_code:nnn {shipout/lastpage}{pdffield} %xetex needs this ...
      {
        \pdf_object_write:nx {__pdffield/field/Kids/#1}
          {
            \seq_use:cn{g__pdffield_field/Kids/#1_seq}{~}
          }
      }
    \pdf_object_write:nx {__pdffield/field/#1} { \pdfdict_use:n {l__pdffield/field} }
  }

\hook_gput_code:nnn {shipout/lastpage}{pdffield}
  {
     \prop_if_empty:NF \g__pdffield_CO_sortkeys_prop
       {
          \seq_sort:Nn \g__pdffield_CO_sortkeys_seq
           {
              \str_compare:eNeTF
                { \prop_item:Nn \g__pdffield_CO_sortkeys_prop {#1} }
                >
                { \prop_item:Nn \g__pdffield_CO_sortkeys_prop {#2} }
                { \sort_return_swapped: }
                { \sort_return_same: }
           }
           \pdfmanagement_add:nnx
            { Catalog / AcroForm }
            { CO }
            { \seq_use:Nn \g__pdffield_CO_sortkeys_seq{~} }
       }
   }

\cs_new_protected:Npn \pdffield_field:nn #1 #2
  {
    \group_begin:
    \keys_set:nn { pdffield } {#1}
    \__pdffield_field:n {#2}
    \group_end:
  }
\cs_new_protected:Npn \__pdffield_annot:
  {
    \pdfmeta_standard_verify:nF
      {annot_flags}
      {
        \bitset_set_true:Nn  \l__pdffield_F_bitset {Print}
        \bitset_set_false:Nn \l__pdffield_F_bitset {Hidden}
        \bitset_set_false:Nn \l__pdffield_F_bitset {Invisible}
        \bitset_set_false:Nn \l__pdffield_F_bitset {NoView}
      }
    \pdfannot_dict_put:nnx {widget}{F}{ \bitset_to_arabic:N \l__pdffield_F_bitset }
    \__pdffield_tag_add_struct_parent:
    \tl_if_empty:NF \l__pdffield_currentparent_tl
      {
         \exp_args:Ne
         \pdf_object_if_exist:nTF { __pdffield/field/\l__pdffield_currentparent_tl }
           {
             \pdfannot_dict_put:nnx {widget}{Parent}
               {
                 \exp_args:Ne
                   \pdf_object_ref:n{__pdffield/field/\l__pdffield_currentparent_tl}
               }
           }
           {
               \msg_error:nnx { pdffield }{parent-field-missing}{\l__pdffield_currentparent_tl}
           }
       }
    \mode_leave_vertical:
    \__pdffield_tag_struct_begin:
    \hbox_to_wd:nn
      { \l__pdffield_annot_wd_dim  }
      {
        \rule [-\l__pdffield_annot_dp_dim]{0pt}{\dim_eval:n{\l__pdffield_annot_ht_dim+\l__pdffield_annot_dp_dim} }
        \pdfannot_widget_box:nnn
           { \l__pdffield_annot_wd_dim }
           { \l__pdffield_annot_ht_dim }
           { \l__pdffield_annot_dp_dim }
         \hfill
      }
    \tl_gset:Nx \g__pdffield_annot_ref_last_tl { \pdfannot_box_ref_last: }
    \exp_args:NV \__pdffield_tag_add_objr:n \g__pdffield_annot_ref_last_tl
    \__pdffield_tag_struct_end:
    \tl_if_empty:NF \l__pdffield_currentparent_tl
      {
        \seq_if_exist:cTF {g__pdffield_field/Kids/\l__pdffield_currentparent_tl _seq}
         {
           \seq_gput_right:cx
             {g__pdffield_field/Kids/\l__pdffield_currentparent_tl _seq}
             { \g__pdffield_annot_ref_last_tl }
         }
         {
           \msg_error:nnx { pdffield}{parent-field-missing}{\l__pdffield_currentparent_tl}
         }
      }
  }
\cs_new_protected:Npn \pdffield_annot:n #1
  {
    \group_begin:
    \keys_set:nn { pdffield } {#1}
    \__pdffield_annot:
    \group_end:
  }
\cs_new:Npn \pdffield_annot_ref_last: { \g__pdffield_annot_ref_last_tl }
\cs_new_protected:Npn \__pdffield_tag_add_struct_parent: {}
\cs_new_protected:Npn \__pdffield_tag_add_objr:n #1 {}
\cs_new_protected:Npn \__pdffield_tag_struct_begin: {}
\cs_new_protected:Npn \__pdffield_tag_struct_end: {}
\hook_gput_code:nnn {begindocument} { l3pdffield }
 {
   \cs_if_exist:NT \tag_if_active:T
    {
      \tag_if_active:T
       {
         \cs_set_protected:Npn \__pdffield_tag_add_struct_parent:
           {
             \bool_if:NT \l__pdffield_tag_bool
              {
                \pdfannot_dict_put:nnx {widget}{StructParent}{ \tag_struct_parent_int: }
              }
           }
         \cs_set_protected:Npn \__pdffield_tag_add_objr:n #1
           {
             \bool_if:NT \l__pdffield_tag_bool
               {
                 \exp_args:Nnx
                 \tag_struct_insert_annot:nn {#1}{ \tag_struct_parent_int: }
               }
           }
         \cs_set_protected:Npn \__pdffield_tag_struct_begin:
          {
            \bool_if:NT \l__pdffield_tag_bool
             {
                \tag_mc_end_push:
                \tag_struct_begin:n{tag=Form}
             }
          }
         \cs_set_protected:Npn \__pdffield_tag_struct_end:
          {
            \bool_if:NT \l__pdffield_tag_bool
             {
               \tag_struct_end:
               \tag_mc_begin_pop:n{}
             }
          }
       }
    }
 }
\cs_new_protected:Npn \__pdffield_color_set:nn #1 #2
 {
   \tl_if_head_eq_charcode:nNTF {#2}[ %]
    {
      \__pdffield_color_set_aux:nwn  { #1 } #2
    }
    {
      \color_set:nn {#1} {#2}
    }
 }

\cs_new_protected:Npn \__pdffield_color_set_aux:nwn #1 [#2] #3
  {
     \color_set:nnn {#1}{#2}{#3}
  }

\cs_new_protected:Npn \__pdffield_V_handler:nN #1#2
  {
    \tl_set:Nn #2 {#1}
  }
\keys_define:nn { pdffield  }
  {
    ,parent .tl_set:N = \l__pdffield_currentparent_tl
    ,parent .groups:n = {field,annot}
    ,T .code:n =
      {
        \pdf_string_from_unicode:nnN {utf8/string-raw}{#1}\l__pdffield_tmpa_str
        \str_if_in:NnT \l__pdffield_tmpa_str {.}
          {
            \msg_error:nnx {pdffield}{no-period}{\l__pdffield_tmpa_str}
          }
        \str_if_empty:NTF\l__pdffield_tmpa_str
          {
            \msg_warning:nn {pdffield}{empty-name}
            \pdfdict_remove:nn { l__pdffield/field }{T}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{T}{(\l__pdffield_tmpa_str)}
          }
      }
    ,T .value_required:n = true
    ,T .groups:n = {field}
    ,name .meta:n          = {T={#1}}
    ,name .value_required:n = true
    ,name .groups:n = {field}
    ,TU .groups:n = {field}
    ,TU .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{TU}
          }
          {
            \pdf_string_from_unicode:nnN {utf16/hex}{#1}\l__pdffield_tmpa_str
            \pdfdict_put:nnx { l__pdffield/field }{TU}{\l__pdffield_tmpa_str}
          }
      }
    ,TU .groups:n = {field}
    ,altname .meta:n      = {TU={#1}}
    ,altname .groups:n = {field}
    ,TM .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{TM}
          }
          {
            \pdf_string_from_unicode:nnN {utf16/hex}{#1}\l__pdffield_tmpa_str
            \pdfdict_put:nnx { l__pdffield/field }{TM}{\l__pdffield_tmpa_str}
          }
      }
    ,TM .groups:n = {field}
    ,mappingname .meta:n   = {TM={#1}}
    ,mappingname .groups:n = {field}
    }
\keys_define:nn { pdffield }
 {
   fieldID .tl_set:N = \l__pdffield_fieldID_tl
 }
\keys_define:nn{pdffield}
  {
    ,FT .choices:nn =
      { Btn, Tx, Ch, Sig }
      {
        \pdfdict_put:nnn { l__pdffield/field }{FT}{ /#1 }
      }
    ,FT .groups:n = {field}
    ,V .code:n =
     {
       \tl_if_empty:nTF {#1}
         {
           \pdfdict_remove:nn { l__pdffield/field }{V}
         }
         {
           \__pdffield_V_handler:nN{#1}\l__pdffield_tmpa_str
           \pdfdict_put:nnx { l__pdffield/field }{V}{ \l__pdffield_tmpa_str }
         }
     }
    ,V .groups:n = {field}
    ,DV .code:n =
     {
       \tl_if_empty:nTF {#1}
         {
           \pdfdict_remove:nn { l__pdffield/field }{DV}
         }
         {
           \__pdffield_V_handler:nN{#1}\l__pdffield_tmpa_str
           \pdfdict_put:nnx { l__pdffield/field }{DV}{ \l__pdffield_tmpa_str }
         }
     }
    ,DV .groups:n = {field}
    ,MaxLen .code:n =
     {
       \tl_if_empty:nTF {#1}
         {
           \pdfdict_remove:nn { l__pdffield/field }{MaxLen}
         }
         {
           \pdfdict_put:nnx { l__pdffield/field }{MaxLen}{ #1 }
         }
      }
    ,MaxLen .groups:n = {field}
    ,Lock .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{Lock}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{Lock}{ \pdf_object_ref:n{#1} }
          }
      }
    ,Lock .groups:n = {field}
    ,SV .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{SV}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{SV}{ \pdf_object_ref:n{#1} }
          }
      }
    ,SV .groups:n = {field}
    ,Opt .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{Opt}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{Opt}{ \pdf_object_ref:n{#1} }
          }
      }
    ,Opt .groups:n = {field}
    ,TI .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{TI}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{TI}{ #1 }
          }
       }
    ,TI .groups:n = {field}
    ,I .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfdict_remove:nn { l__pdffield/field }{I}
          }
          {
            \pdfdict_put:nnx { l__pdffield/field }{I}{ \pdf_object_ref:n{#1} }
          }
      }
    ,I .groups:n = {field}
  }
\keys_define:nn { pdffield }
  {
    ,setFf .code:n =
      {
          \clist_map_inline:nn {#1}
           {
             \bitset_set_true:Nn \l__pdffield_Ff_bitset {##1}
           }
      }
    ,setFf .groups:n = {field}
    ,setfieldflags .meta:n =
      {setFf={#1}}
    ,setfieldflags .groups:n = {field}
    ,unsetFf .multichoice:
    ,unsetFf / all .code:n = { \bitset_clear:N \l__pdffield_Ff_bitset}
    ,unsetFf / unknown .code:n =
      {
        \bitset_set_false:Nn \l__pdffield_Ff_bitset {#1}
      }
    ,unsetFf .groups:n = {field}
    ,unsetfieldflags .meta:n = {unsetFf={#1}}
    ,unsetfieldflags .groups:n = {field}
  }

\cs_set_protected:Npn \__pdffield_tmpa:n #1  %
  {
    \keys_define:nn { pdffield  }
      {
         AA/#1 .code:n =
           {
             \tl_if_empty:nTF {#1}
               {
                 \pdfdict_remove:nn {l__pdffield/field/AA}{#1}
               }
               {
                 \pdfdict_put:nnx {l__pdffield/field/AA}
                  {#1}
                  {<</S/JavaScript/JS\c_space_tl ##1>>}
               }
           },
        AA/#1 .groups:n  = {field}
      }
  }

\clist_map_inline:nn {K,F,V,C}{\__pdffield_tmpa:n{#1}}

\cs_set_protected:Npn \__pdffield_tmpa:nn #1 #2
  {
    \keys_define:nn { pdffield  }
      {
         #1 .meta:nn =
           { pdffield }{AA/#2={##1}},
        #1 .groups:n  = {field}
      }
  }
\__pdffield_tmpa:nn {keystroke}{K}
\__pdffield_tmpa:nn {format}   {F}
\__pdffield_tmpa:nn {validate} {V}
\__pdffield_tmpa:nn {calculate}{C}

\keys_define:nn {pdffield}
 {
   sortkey .code:n = {\str_set:Nx \l__pdffield_CO_sortkey_str {\tl_to_str:n{#1}}}
 }
\keys_define:nn { pdffield }
  {
    DA .code:n =
     {
       \tl_if_empty:nTF {#1}
         {
           \pdfdict_remove:nn { l__pdffield/field }{DA}
         }
         {
           \pdfdict_put:nnx { l__pdffield/field }{DA}{ (#1) }
         }
      }
    ,DA .groups:n = {field}
    ,Q .choices:nn = {left,center,right}
     {
       \pdfdict_put:nnx { l__pdffield/field }{Q}{ \int_eval:n{\l_keys_choice_int-1} }
     }
    ,Q / .code:n = { \pdfdict_remove:nn { l__pdffield/field }{Q} }
    ,Q .groups:n = {field}
    ,align .meta:n={Q=#1}
    ,DS .code:n =
     {
       \msg_warning:nnn {pdffield}{not-implemented}{DS}
     }
    ,DS .groups:n = {field}
    ,RV .code:n =
     {
       \msg_warning:nnn {pdffield}{not-implemented}{RV}
     }
    ,RV .groups:n = {field}
  }
\dim_new:N \l__pdffield_annot_ht_dim
\dim_new:N \l__pdffield_annot_wd_dim
\dim_new:N \l__pdffield_annot_dp_dim
\keys_define:nn { pdffield }
  {
    ,width  .dim_set:N = \l__pdffield_annot_wd_dim
    ,height .dim_set:N = \l__pdffield_annot_ht_dim
    ,depth  .dim_set:N = \l__pdffield_annot_dp_dim
    ,width  .initial:n = 0pt
    ,height .initial:n = 0pt
    ,depth  .initial:n = 0pt
  }
\keys_define:nn { pdffield }
  {
    ,tag  .bool_set:N = \l__pdffield_tag_bool
  }
\cs_new_protected:Npn \__pdffield_appearance_handler:nnn #1#2#3
 {
   \pdfxform_if_exist:nTF {  #1 }
     {
       \pdfannot_dict_put:nnx {widget/AP}{#2}
         {
           \pdfxform_ref:n {#1}
         }
     }
     {
       \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
     }
 }
\keys_define:nn { pdffield }
 {
   %parent is defined in field
  ,AS .code:n =
    {
      \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget }{AS}
        }
        {
          \pdfannot_dict_put:nnx {widget}{AS}{\pdf_name_from_unicode_e:n{#1}}
        }
    }
  ,AS .groups:n = annot
 }
\keys_define:nn { pdffield }
  {
    AP/N .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfannot_dict_remove:nn { widget/AP }{N}
          }
          {
            \__pdffield_appearance_handler:nnn {#1}{N}{normal}
          }
        }
   ,AP/N .groups:n = annot
   ,appearance .meta:n = {AP/N={#1}}
   ,appearance .groups:n = annot
  }
\keys_define:nn { pdffield }
  {
    AP/R .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfannot_dict_remove:nn { widget/AP }{R}
          }
          {
             \__pdffield_appearance_handler:nnn {#1}{R}{rollover}
          }
        }
   ,AP/R .groups:n = annot
   ,rollover-appearance .meta:n = {AP/R={#1}}
   ,rollover-appearance .groups:n = annot
  }
\keys_define:nn { pdffield }
  {
    AP/D .code:n =
      {
        \tl_if_empty:nTF {#1}
          {
            \pdfannot_dict_remove:nn { widget/AP }{D}
          }
          {
             \__pdffield_appearance_handler:nnn {#1}{D}{down}
          }
        }
   ,AP/D .groups:n = annot
   ,down-appearance .meta:n = {AP/D={#1}}
   ,down-appearance .groups:n = annot
  }
\keys_define:nn { pdffield  }
  {
    MK/R .choices:nn = {0,90,180,270}
     {
       \pdfannot_dict_put:nnx {widget/MK}{R}{#1}
     }
   ,MK/R / .code:n =
     {
        \pdfannot_dict_remove:nn { widget/MK }{R}
     }
   ,MK/R .groups:n = annot
   ,rotate .meta:n = {MK/R=#1}
  }

\keys_define:nn { pdffield  }
  {
    MK/BC .code:n =
     {
       \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget/MK }{BC}
        }
        {
          \__pdffield_color_set:nn {__pdffield/tmp}{#1}
          \color_export:nnN{__pdffield/tmp}{space-sep-rgb}\l__pdffield_tmpa_tl
          \pdfannot_dict_put:nnx {widget/MK}{BC}{[\l__pdffield_tmpa_tl]}
        }
     }
    ,MK/BC .groups:n = annot
   ,bordercolor .meta:n = {MK/BC=#1}
  }

\keys_define:nn { pdffield  }
  {
    MK/BG .code:n =
     {
       \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget/MK }{BG}
        }
        {
          \__pdffield_color_set:nn {__pdffield/tmp}{#1}
          \color_export:nnN{__pdffield/tmp}{space-sep-rgb}\l__pdffield_tmpa_tl
          \pdfannot_dict_put:nnx {widget/MK}{BG}{[\l__pdffield_tmpa_tl]}
        }
     }
    ,MK/BG .groups:n = annot
   ,backgroundcolor .meta:n = {MK/BG=#1}
  }

\keys_define:nn { pdffield  }
  {
    MK/CA .code:n =
     {
       \tl_set:Nn \l__pdffield_caption_tl {#1}
       \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget/MK }{CA}
        }
        {
          \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_tmpa_str
          \pdfannot_dict_put:nnx {widget/MK}{CA}{\l__pdffield_tmpa_str}
        }
     }
    ,MK/CA .groups:n = annot
   ,caption .meta:n = {MK/CA=#1}
  }

\keys_define:nn { pdffield  }
  {
    MK/RC .code:n =
     {
       \tl_set:Nn \l__pdffield_rollover_caption_tl {#1}
       \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget/MK }{RC}
        }
        {
          \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_tmpa_str
          \pdfannot_dict_put:nnx {widget/MK}{RC}{\l__pdffield_tmpa_str}
        }
     }
    ,MK/RC .groups:n = annot
   ,rollover-caption .meta:n = {MK/RC=#1}
  }

\keys_define:nn { pdffield  }
  {
    MK/AC .code:n =
     {
       \tl_set:Nn \l__pdffield_down_caption_tl {#1}
       \tl_if_empty:nTF {#1}
        {
          \pdfannot_dict_remove:nn { widget/MK }{AC}
        }
        {
          \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_tmpa_str
          \pdfannot_dict_put:nnx {widget/MK}{AC}{\l__pdffield_tmpa_str}
        }
     }
    ,MK/AC .groups:n = annot
   ,down-caption .meta:n = {MK/AC=#1}
  }

\cs_set_protected:Npn \__pdffield_tmpa:n #1
 {
   \keys_define:nn { pdffield  }
     {
       MK/#1 .code:n =
        {
          \tl_if_empty:nTF {##1}
            {
              \pdfannot_dict_remove:nn { widget/MK }{#1}
            }
            {
              \pdfannot_dict_put:nnx {widget/MK}{#1}{##1}
            }
        }
      ,MK/#1 .groups:n = annot
     }
 }

\clist_map_inline:nn {I,RI,IX,IF,TP}
  { \__pdffield_tmpa:n {#1} }
\keys_define:nn { pdffield  }
  {
    ,setF .code:n =
      {
          \clist_map_inline:nn {#1}
           {
             \bitset_set_true:Nn \l__pdffield_F_bitset {##1}
           }
      }
    ,setF .groups:n = annot
    ,setannotflags .meta:nn =
      { pdffield }{setF={#1}}
    ,setannotflags .groups:n = annot
    ,unsetF .multichoice:
    ,unsetF / all .code:n = { \bitset_clear:N \l__pdffield_F_bitset}
    ,unsetF / unknown .code:n =
      {
        \bitset_set_false:Nn \l__pdffield_F_bitset {#1}
      }
    ,unsetF .groups:n = annot
    ,unsetannotflags .meta:nn =
      { pdffield }{unsetF= {#1} }
    ,unsetannotflags .groups:n = annot
  }

\cs_set_protected:Npn \__pdffield_tmpa:n #1  %
  {
    \keys_define:nn { pdffield }
      {
         AA/#1 .code:n =
           {
             \tl_if_empty:nTF {#1}
               {
                 \pdfannot_dict_remove:nn {widget/AA}{#1}
               }
               {
                 \pdfannot_dict_put:nnx {widget/AA}
                  {#1}
                  {<</S/JavaScript/JS\c_space_tl##1>>}
               }
           },
         ,AA/#1 .groups:n = annot
      }
  }

\clist_map_inline:nn {Fo,Bl,D,U,E,X,PO,PC,PV,PI}{\__pdffield_tmpa:n{#1}}

\cs_set_protected:Npn \__pdffield_tmpa:nn #1 #2
  {
    \keys_define:nn { pdffield }
      {
         #1 .meta:nn =
           { pdffield }{AA/#2={##1}},
         #1 .groups:n = {annot}
      }
  }
\__pdffield_tmpa:nn {onfocus}  {Fo}
\__pdffield_tmpa:nn {onblur}   {Bl}
\__pdffield_tmpa:nn {onmousedown}{D}
\__pdffield_tmpa:nn {onmouseup}{U}
\__pdffield_tmpa:nn {onenter}  {E}
\__pdffield_tmpa:nn {onexit}   {X}
\cs_new_protected:Npn \pdffield_appearance:nn #1 #2
  {
     \pdfxform_new:nnn {#1}{}{#2}
  }

\cs_set_eq:NN \pdffield_store_appearance:nn\pdffield_appearance:nn
\keys_define:nn { pdffield / setup }
  {
    ,create-style .code:n  = { \__pdffield_style_create:nn #1 }
    ,preset-checkbox .code:n =
      {
        \keys_define:nn { pdffield }
         {
           __pdffield/preset/checkbox .meta:n = {#1},
         }
      }
    ,preset-radiobutton .code:n =
      {
        \keys_define:nn { pdffield }
         {
           __pdffield/preset/radiobutton .meta:n = {#1},
         }
      }
   ,preset-textfield .code:n =
      {
        \keys_define:nn { pdffield }
         {
           __pdffield/preset/textfield .meta:n = {#1},
         }
      }
   ,preset-pushbutton .code:n =
      {
        \keys_define:nn { pdffield }
         {
           __pdffield/preset/pushbutton .meta:n = {#1},
         }
      }
  ,preset-choice .code:n =
      {
        \keys_define:nn { pdffield }
         {
           __pdffield/preset/choice .meta:n = {#1},
         }
      }
  }
\keys_set:nn{ pdffield / setup }{preset-checkbox={}}
\keys_set:nn{ pdffield / setup }{preset-textfield={}}
\keys_set:nn{ pdffield / setup }{preset-radiobutton={}}
\keys_set:nn{ pdffield / setup }{preset-pushbutton={}}
\keys_set:nn{ pdffield / setup }{preset-choice={}}
\cs_new_protected:Npn \__pdffield_style_create:nn #1#2
  {
    \keys_define:nn { pdffield }
      {
        __pdffield/style/#1 .meta:n = {#2},
      }
  }

\cs_new_protected:Npn \pdffield_setup:n #1
  {
     \keys_set:nn{ pdffield / setup }{#1}
  }

\keys_define:nn { pdffield }
  {
    style .code:n = {\keys_set:nn {pdffield}{__pdffield/style/#1={#1}}}
  }
\cs_new_protected:Npn \__pdffield_value_handler:n #1
  {
    \msg_info:nnn {pdffield}{key-ignored}{value}
  }
\cs_new_protected:Npn \__pdffield_default_handler:n #1
  {
    \msg_info:nnn {pdffield}{key-ignored}{default}
  }
\keys_define:nn {pdffield}
  {
     value   .code:n = { \__pdffield_value_handler:n {#1} }
    ,default .code:n = { \__pdffield_default_handler:n {#1}}
  }
%% File: l3pdfpdffield-checkbox.dtx
\cs_new_protected:Npn \__pdffield_checkbox_default_appearances:
  {
     \pdffield_appearance:nn {pdffield/checkbox/default/Yes}
       {
         \normalsize
         \fboxsep 0pt
         \framebox
           [ \dim_eval:n { \box_ht:N\strutbox+\box_dp:N\strutbox } ]
           { \texttimes \strut }
       }
     \pdffield_appearance:nn {pdffield/checkbox/default/Off}
       {
         \normalsize
         \fboxsep 0pt
         \framebox
           [ \dim_eval:n { \box_ht:N\strutbox+\box_dp:N\strutbox } ]
           { \phantom{\texttimes} \strut }
       }
    \cs_gset_eq:NN \__pdffield_checkbox_default_appearances: \prg_do_nothing:
  }
\cs_new_protected:Npn \__pdffield_checkbox_field:n #1 %name
  {
    \pdf_object_if_exist:nF {__pdffield/field/__pdffield/checkbox/#1}
      {
        \__pdffield_field:n { __pdffield/checkbox/#1 }
      }
    \keys_set:nn {pdffield}{parent=__pdffield/checkbox/#1}
  }
\cs_generate_variant:Nn \__pdffield_checkbox_field:n {V}
\cs_new_protected:Npn \__pdffield_checkbox:n #1
  {
    \group_begin:
    \__pdffield_checkbox_default_appearances:
    \cs_set_eq:NN\__pdffield_appearance_handler:nnn \__pdffield_checkbox_appearance_handler:nnn
    \cs_set_eq:NN\__pdffield_value_handler:n   \__pdffield_checkbox_value_handler:n
    \cs_set_eq:NN\__pdffield_default_handler:n \__pdffield_checkbox_default_handler:n
    \keys_set:nn {pdffield}
      {
        fieldID=,
        name=checkbox,
        appearance = pdffield/checkbox/default,
        checked=false,
        width  = \normalbaselineskip,
        height = \normalbaselineskip,
      }
    \__pdffield_key_disable:nnn{checkbox}{V}{checked}
    \__pdffield_key_disable:nnn{checkbox}{DV}{checked}
    \__pdffield_key_disable:nnn{checkbox}{AS}{checked}
    \keys_set:nn { pdffield }{__pdffield/preset/checkbox,#1}
    \keys_set:nn { pdffield }
      {
        ,unsetFf={Radio,Pushbutton}
        ,FT= Btn
      }
    \tl_if_empty:NT\l__pdffield_fieldID_tl
      {
        \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl
        \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/checkbox/}
      }
    \__pdffield_checkbox_field:V\l__pdffield_fieldID_tl
    \__pdffield_annot:
    \group_end:
  }
\keys_define:nn { pdffield  }
 {
   ,checked .choice:
   ,checked / false .code:n =
     {
       \pdfdict_put:nnx { l__pdffield/field }{V} { /Off }
       \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Off }
       \pdfannot_dict_put:nnn {widget}{AS}{ /Off }
     }
   ,checked / true .code:n =
     {
       \pdfdict_put:nnx { l__pdffield/field }{V} { /Yes }
       \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Yes }
       \pdfannot_dict_put:nnn {widget}{AS}{ /Yes }
     }
   ,checked .default:n = {true}
   ,checked .groups:n  = {checkbox}
 }
\keys_define:nn { pdffield  }
 {
   ,__value .choice:
   ,__value / Off .code:n =
     {
       \pdfdict_put:nnx { l__pdffield/field }{V} { /Off }
       \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Off }
       \pdfannot_dict_put:nnn {widget}{AS}{ /Off }
     }
   ,__value / Yes .code:n =
     {
       \pdfdict_put:nnx { l__pdffield/field }{V} { /Yes }
       \pdfdict_put:nnx { l__pdffield/field }{DV}{ /Yes }
       \pdfannot_dict_put:nnn {widget}{AS}{ /Yes }
     }
 }
\cs_new_protected:Npn \__pdffield_checkbox_value_handler:n #1
  {
    \keys_set:nn{pdffield}{__value={#1}}
  }
\cs_new_protected:Npn \__pdffield_checkbox_default_handler:n #1
  {
    \keys_set:nn{pdffield}{__value={#1}}
  }
\cs_new_protected:Npn \__pdffield_checkbox_appearance_handler:nnn #1 #2 #3 %name, type, text
  {
    \pdfxform_if_exist:nTF {  #1/Yes }
      {
        \pdf_object_if_exist:nF {__pdffield/checkbox/AP/#1}
          {
            \pdf_object_new:nn {__pdffield/checkbox/AP/#1}{dict}
            \pdf_object_write:nx
              {__pdffield/checkbox/AP/#1}
              {
                /Yes ~ \pdfxform_ref:n { #1/Yes}
                /Off ~ \pdfxform_ref:n { #1/Off}
              }
          }
        \pdfannot_dict_put:nnx {widget/AP}{#2}{\pdf_object_ref:n{__pdffield/checkbox/AP/#1}}
      }
      {
         \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
      }
   }

\cs_set_eq:NN \pdffield_checkbox:n \__pdffield_checkbox:n

%% File: l3pdfpdffield-radiobutton.dtx

\RequirePackage{l3draw}
\tl_new:N  \l__pdffield_radio_value_tl
\tl_new:N  \l__pdffield_radio_default_tl
\int_new:N \l__pdffield_radio_value_num_int
\tl_new:N  \l__pdffield_radio_appearance_code_tl
\cs_new_protected:Npn \__pdffield_radio_default_appearances:
  {
    \pdffield_appearance:nn {pdffield/radio/default/Yes}
       {
         \normalsize
         \draw_begin:
         \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
         \draw_path_use_clear:n { stroke }
         \draw_path_circle:nn {0pt,0pt}{0.2\normalbaselineskip}
         \draw_path_use_clear:n { fill }
         \draw_end:
       }
     \pdffield_appearance:nn {pdffield/radio/default/Off}
       {
         \normalsize
         \draw_begin:
         \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
         \draw_path_use_clear:n { stroke }
         \draw_end:
      }

    \pdffield_appearance:nn {pdffield/radio/defaultdown/Yes}
       {
         \normalsize
         \draw_begin:
         \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
         \draw_path_use_clear:n { stroke }
         \draw_path_circle:nn {0pt,0pt}{0.25\normalbaselineskip}
         \draw_path_use_clear:n { fill }
         \draw_end:
       }
     \pdffield_appearance:nn {pdffield/radio/defaultdown/Off}
       {
         \normalsize
         \draw_begin:
         \draw_path_circle:nn {0pt,0pt}{0.5\normalbaselineskip}
         \draw_path_use_clear:n { stroke }
         \draw_path_circle:nn {0pt,0pt}{0.25\normalbaselineskip}
         \draw_path_use_clear:n { fill }
         \draw_end:
      }
    \cs_gset_eq:NN \__pdffield_radio_default_appearances: \prg_do_nothing:
  }
\cs_new_protected:Npn \__pdffield_radio_field:n #1 %name
  {
    \pdf_object_if_exist:nF {__pdffield/field/__pdffield/radio/#1}
      {
        \pdf_object_new:nn {__pdffield/field/__pdffield/radio-Opt/#1}{array}
        \pdfdict_put:nnx { l__pdffield/field }{Opt} { \pdf_object_ref:n {__pdffield/field/__pdffield/radio-Opt/#1} }
        \seq_new:c { g__pdffield_radio_opt_#1_seq }
        \hook_gput_code:nnn {shipout/lastpage}{pdffield/radio}
          {
            \pdf_object_write:nx
              {__pdffield/field/__pdffield/radio-Opt/#1}
              {\seq_use:cn {g__pdffield_radio_opt_#1_seq}{~}}
          }
        \tl_if_eq:NnF \l__pdffield_radio_default_tl{()}
         {
           \seq_gput_left:cV { g__pdffield_radio_opt_#1_seq }\l__pdffield_radio_default_tl
         }
        \pdfdict_put:nnx { l__pdffield/field }{V}  { /0 }
        \pdfdict_put:nnx { l__pdffield/field }{DV} { /0 }
        \__pdffield_field:n { __pdffield/radio/#1 }
      }
    \keys_set:nn {pdffield}{parent=__pdffield/radio/#1}
  }
\cs_generate_variant:Nn \__pdffield_radio_field:n {V}
\cs_new_protected:Npn \__pdffield_radio:n #1
  {
    \group_begin:
    \cs_set_eq:NN\__pdffield_appearance_handler:nnn \__pdffield_radio_appearance_handler:nnn
    \cs_set_eq:NN\__pdffield_value_handler:n      \__pdffield_radio_value_handler:n
    \cs_set_eq:NN\__pdffield_default_handler:n    \__pdffield_radio_default_handler:n
    \tl_set:Nn\l__pdffield_radio_appearance_code_tl{}
    \keys_set:nn {pdffield}
      {
         fieldID=
        ,name=radio
        ,width  = \normalbaselineskip
        ,height = \normalbaselineskip
        ,__pdffield/preset/radiobutton
        ,#1
        ,unsetFf={Pushbutton}
        ,setFf={Radio}
        ,FT= Btn
      }
   \tl_if_empty:NT\l__pdffield_fieldID_tl
      {
        \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl
        \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/radio/}
      }
    \__pdffield_radio_field:V\l__pdffield_fieldID_tl
    \seq_if_in:cVF { g__pdffield_radio_opt_ \l__pdffield_fieldID_tl _seq }\l__pdffield_radio_value_tl
      {
        \seq_gput_right:cV { g__pdffield_radio_opt_ \l__pdffield_fieldID_tl _seq }\l__pdffield_radio_value_tl
      }
    \int_zero:N \l__pdffield_radio_value_num_int
    \exp_args:Nc
    \seq_map_inline:Nn { g__pdffield_radio_opt_ \l__pdffield_fieldID_tl _seq }
     {
       \str_if_eq:nVTF { ##1 } \l__pdffield_radio_value_tl
        {
          \seq_map_break:
        }
        {
          \int_incr:N \l__pdffield_radio_value_num_int
        }
     }
   \int_compare:nNnTF { \l__pdffield_radio_value_num_int } = 0
     { \pdfannot_dict_put:nnx {widget}{AS}{/0} }
     { \pdfannot_dict_put:nnx {widget}{AS}{/Off} }
    \tl_if_empty:NT\l__pdffield_radio_appearance_code_tl
      {
        \__pdffield_radio_default_appearances:
        \keys_set:nn {pdffield}
          {
            appearance      = pdffield/radio/default,
            down-appearance = pdffield/radio/defaultdown,
          }
      }
    \l__pdffield_radio_appearance_code_tl
    \__pdffield_annot:
    \group_end:
  }
\cs_new_protected:Npn \__pdffield_radio_value_handler:n #1
  {
    \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_radio_value_tl
  }
\cs_new_protected:Npn \__pdffield_radio_default_handler:n #1
  {
    \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_radio_default_tl
  }
\keys_define:nn { pdffield }
 {
    group .meta:n = {T=#1}
 }
\cs_new_protected:Npn \__pdffield_radio_appearance_handler:nnn #1 #2 #3 %name, type, text
  {
    \tl_put_right:Nn \l__pdffield_radio_appearance_code_tl
      {
         \pdfxform_if_exist:nTF {  #1 / Yes }
           {
             \pdf_object_unnamed_write:nx
               {dict}
               {
                  /\int_use:N \l__pdffield_radio_value_num_int
                   \c_space_tl   \pdfxform_ref:n  { #1/Yes}
                  /Off ~ \pdfxform_ref:n { #1/Off}
               }
            \pdfannot_dict_put:nnx {widget/AP}{#2}{\pdf_object_ref_last:}
           }
           {
              \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
           }
       }
   }

\cs_set_eq:NN \pdffield_radio:n \__pdffield_radio:n
%% File: l3pdfpdffield-textfield.dtx

\tl_new:N  \l__pdffield_DA_fontcolor_tl
\dim_new:N \l__pdffield_DA_fontsize_dim
\tl_new:N  \l__pdffield_DA_fontname_tl
\cs_new_protected:Npn {\__pdffield_textfield_default_appearance:}
  {
    \pdffield_appearance:nn {pdffield/textfield/default}
     {
       { \color_select:n{black!5!white}\rule{\paperwidth}{\paperheight} }
     }
    \cs_gset_eq:NN \__pdffield_textfield_default_appearance: \prg_do_nothing:
  }
\cs_new_protected:Npn \__pdffield_textfield_field:n #1 %name
  {
    \pdf_object_if_exist:nF {__pdffield/field/__pdffield/textfield/#1}
      {
        \__pdffield_field:n { __pdffield/textfield/#1 }
      }
    \keys_set:nn {pdffield}{parent=__pdffield/textfield/#1}
  }
\cs_generate_variant:Nn \__pdffield_textfield_field:n {V}
\cs_new_protected:Npn \__pdffield_textfield:n #1
  {
    \group_begin:
    \cs_set_eq:NN\__pdffield_V_handler:nN \__pdffield_textfield_V_handler:nN
    \cs_set_eq:NN\__pdffield_value_handler:n \__pdffield_textfield_value_handler:n
    \cs_set_eq:NN\__pdffield_default_handler:n \__pdffield_textfield_default_handler:n
    \__pdffield_textfield_default_appearance:
    \keys_set:nn {pdffield}
      {
        ,fieldID=
        ,name=textfield
        ,appearance = pdffield/textfield/default
        ,width  = 3cm
        ,fontsize= \f@size pt
        ,height =  \f@size pt,
         depth  =   \fp_eval:n {0.3*\f@size} pt,
        % font defaults!!
      }
    \keys_set:nn { pdffield }{__pdffield/preset/textfield,#1}
    \int_compare:nNnT {\bitset_item:Nn \l__pdffield_Ff_bitset {Comb}}={1}
      {
        % warning if set?
        \keys_set:nn { pdffield }
          {
            ,unsetFf={FileSelect,Multiline,Password}
          }
        \pdfdict_get:nnN {l__pdffield/field}{MaxLen}\l__pdffield_tmpa_tl
        \quark_if_no_value:NT \l__pdffield_tmpa_tl
         {
           \keys_set:nn { pdffield}
            {
              MaxLen = 10 %variable
            }
            % warning
         }
      }
    \keys_set:nn { pdffield }
      {
        ,FT= Tx
        ,AS=
        ,DA=
           {
              \pdf_name_from_unicode_e:n{\l__pdffield_DA_fontname_tl}
              \c_space_tl
              \dim_to_decimal_in_bp:n{\l__pdffield_DA_fontsize_dim}
              \c_space_tl
              Tf
              \c_space_tl
              \l__pdffield_DA_fontcolor_tl
              \c_space_tl
              %\l__pdffield_text_DAextra_tl
           }
      }
    \tl_if_empty:NT\l__pdffield_fieldID_tl
      {
        \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl
        \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/textfield/}
      }
    \__pdffield_textfield_field:V\l__pdffield_fieldID_tl
    \__pdffield_annot:
    \group_end:
  }
\keys_define:nn {pdffield}
  {
    ,fontcolor .code:n =
       {
         \__pdffield_color_set:nn {__pdffield/tmp}{#1}
         \color_export:nnN{__pdffield/tmp}{space-sep-rgb}\l__pdffield_DA_fontcolor_tl
         \tl_put_right:Nn \l__pdffield_DA_fontcolor_tl{~rg}
       }
    ,fontcolor .initial:n = black,
    ,fontcolor .groups:n = {textfield}
    ,font .tl_set:N      = \l__pdffield_DA_fontname_tl
    ,font .initial:n     = {Helv}
    ,font .groups:n = {textfield}
    ,fontsize .dim_set:N = \l__pdffield_DA_fontsize_dim
    ,fontsize .initial:n = {10bp}
    ,fontsize .groups:n = {textfield}
  }
\cs_new_protected:Npn \__pdffield_textfield_V_handler:nN #1#2
  {
     \pdf_string_from_unicode:nnN {utf16/hex}{#1}#2
  }
\cs_new_protected:Npn \__pdffield_textfield_value_handler:n #1
  {
     \keys_set:nn{pdffield}{V={#1}}
  }
\cs_new_protected:Npn \__pdffield_textfield_default_handler:n #1
  {
     \keys_set:nn{pdffield}{DV={#1}}
  }
\cs_set_eq:NN \pdffield_textfield:n \__pdffield_textfield:n
%% File: l3pdfpdffield-pushbutton.dtx
\tl_new:N   \l__pdffield_pushbutton_appearance_code_tl
\dim_new:N  \l__pdffield_pushbutton_linewidth_dim
\dim_new:N  \l__pdffield_pushbutton_totalht_dim
\int_new:N  \g__pdffield_pushbutton_cnt_int
\dim_set:Nn \l__pdffield_pushbutton_linewidth_dim {0.4pt}
\color_set:nn {pdffield/push/text}{black}
\color_set:nn {pdffield/push/border}{black!95!white}
\color_set:nn {pdffield/push/bordertop}{yellow!5!white}
\color_set:nn {pdffield/push/borderbot}{black!50!white}
\color_set:nn {pdffield/push/fill}{black!20!white}

\cs_new_protected:Npn \__pdffield_pushbutton_default_appearances:
  {
     \int_gincr:N \g__pdffield_pushbutton_cnt_int
     \exp_args:Nx
     \pdffield_appearance:nn {pdffield/pushbutton/default-\int_use:N \g__pdffield_pushbutton_cnt_int}
       {
         \draw_begin:
         \color_set:nn {pdffield/push/text}{.}
         \dim_set:Nn \l__pdffield_pushbutton_totalht_dim
           {\l__pdffield_annot_ht_dim + \l__pdffield_annot_dp_dim}
         \draw_linewidth:n {\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_rectangle_corners:nn
            {0.5\l__pdffield_pushbutton_linewidth_dim,0.5\l__pdffield_pushbutton_linewidth_dim}
            {
             \l__pdffield_annot_wd_dim-0.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-0.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/border}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
            {2\l__pdffield_pushbutton_linewidth_dim,2\l__pdffield_pushbutton_linewidth_dim}
            {
              \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
              \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/bordertop}
         \draw_path_use_clear:n { fill }
         \draw_path_moveto:n
           {
             2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {5\l__pdffield_pushbutton_linewidth_dim,5\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-5\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_close:
         \color_fill:n {pdffield/push/borderbot}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
           {
             1.5\l__pdffield_pushbutton_linewidth_dim,
             1.5\l__pdffield_pushbutton_linewidth_dim
           }
           {
             \l__pdffield_annot_wd_dim-1.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-1.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_stroke:n {pdffield/push/border}
         \draw_path_use_clear:n { stroke }
         \draw_path_rectangle_corners:nn
           {4\l__pdffield_pushbutton_linewidth_dim,4\l__pdffield_pushbutton_linewidth_dim}
           {
             \l__pdffield_annot_wd_dim-4\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-4\l__pdffield_pushbutton_linewidth_dim
           }
           \color_fill:n {pdffield/push/fill}
          \draw_path_use_clear:n { fill }
          \color_fill:n {pdffield/push/text}
          \draw_transform_shift:n
            {0.5 \l__pdffield_annot_wd_dim, \l__pdffield_annot_dp_dim }
          \hbox_set:Nn \l_tmpa_box { \makebox[0pt]{\l__pdffield_caption_tl} }
          \draw_box_use:N \l_tmpa_box
         \draw_end:
       }
    \exp_args:Nx
    \pdffield_appearance:nn {pdffield/pushbutton/defaultrollover-\int_use:N \g__pdffield_pushbutton_cnt_int}
       {
         \draw_begin:
         \dim_set:Nn \l__pdffield_pushbutton_totalht_dim
           {\l__pdffield_annot_ht_dim + \l__pdffield_annot_dp_dim}
         \draw_linewidth:n {\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_rectangle_corners:nn
            {0.5\l__pdffield_pushbutton_linewidth_dim,0.5\l__pdffield_pushbutton_linewidth_dim}
            {
             \l__pdffield_annot_wd_dim-0.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-0.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/border}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
            {2\l__pdffield_pushbutton_linewidth_dim,2\l__pdffield_pushbutton_linewidth_dim}
            {
              \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
              \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/borderbot}
         \draw_path_use_clear:n { fill }
         \draw_path_moveto:n
           {
             2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {5\l__pdffield_pushbutton_linewidth_dim,5\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-5\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_close:
         \color_fill:n {pdffield/push/bordertop}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
           {
             1.5\l__pdffield_pushbutton_linewidth_dim,
             1.5\l__pdffield_pushbutton_linewidth_dim
           }
           {
             \l__pdffield_annot_wd_dim-1.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-1.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_stroke:n {pdffield/push/border}
         \draw_path_use_clear:n { stroke }
         \draw_path_rectangle_corners:nn
           {4\l__pdffield_pushbutton_linewidth_dim,4\l__pdffield_pushbutton_linewidth_dim}
           {
             \l__pdffield_annot_wd_dim-4\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-4\l__pdffield_pushbutton_linewidth_dim
           }
           \color_fill:n {pdffield/push/fill}
          \draw_path_use_clear:n { fill }
          \color_fill:n {pdffield/push/text}
          \draw_transform_shift:n
            {0.5 \l__pdffield_annot_wd_dim, \l__pdffield_annot_dp_dim }
          \hbox_set:Nn \l_tmpa_box { \makebox[0pt]{\l__pdffield_rollover_caption_tl} }
          \draw_box_use:N \l_tmpa_box
         \draw_end:
       }
     \exp_args:Nx
     \pdffield_appearance:nn {pdffield/pushbutton/defaultdown-\int_use:N \g__pdffield_pushbutton_cnt_int}
       {
         \draw_begin:
         \dim_set:Nn \l__pdffield_pushbutton_totalht_dim
           {\l__pdffield_annot_ht_dim + \l__pdffield_annot_dp_dim}
         \draw_linewidth:n {\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_rectangle_corners:nn
            {0.5\l__pdffield_pushbutton_linewidth_dim,0.5\l__pdffield_pushbutton_linewidth_dim}
            {
             \l__pdffield_annot_wd_dim-0.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-0.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/border}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
            {2\l__pdffield_pushbutton_linewidth_dim,2\l__pdffield_pushbutton_linewidth_dim}
            {
              \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
              \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
            }
         \color_fill:n {pdffield/push/borderbot}
         \draw_path_use_clear:n { fill }
         \draw_path_moveto:n
           {
             2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {5\l__pdffield_pushbutton_linewidth_dim,5\l__pdffield_pushbutton_linewidth_dim}
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-5\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_lineto:n
           {
             \l__pdffield_annot_wd_dim-2\l__pdffield_pushbutton_linewidth_dim,
             2\l__pdffield_pushbutton_linewidth_dim
           }
         \draw_path_close:
         \color_fill:n {pdffield/push/bordertop}
         \draw_path_use_clear:n { fill }
         \draw_path_rectangle_corners:nn
           {
             1.5\l__pdffield_pushbutton_linewidth_dim,
             1.5\l__pdffield_pushbutton_linewidth_dim
           }
           {
             \l__pdffield_annot_wd_dim-1.5\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-1.5\l__pdffield_pushbutton_linewidth_dim
            }
         \color_stroke:n {pdffield/push/border}
         \draw_path_use_clear:n { stroke }
         \draw_path_rectangle_corners:nn
           {4\l__pdffield_pushbutton_linewidth_dim,4\l__pdffield_pushbutton_linewidth_dim}
           {
             \l__pdffield_annot_wd_dim-4\l__pdffield_pushbutton_linewidth_dim,
             \l__pdffield_pushbutton_totalht_dim-4\l__pdffield_pushbutton_linewidth_dim
           }
           \color_fill:n {pdffield/push/fill}
          \draw_path_use_clear:n { fill }
          \color_fill:n {pdffield/push/text}
          \draw_transform_shift:n
            {0.5 \l__pdffield_annot_wd_dim, \l__pdffield_annot_dp_dim }
          \hbox_set:Nn \l_tmpa_box { \makebox[0pt]{\l__pdffield_down_caption_tl} }
          \draw_box_use:N \l_tmpa_box
         \draw_end:
       }
    }
\cs_new_protected:Npn \__pdffield_pushbutton_field:n #1 %name
  {
    \pdf_object_if_exist:nF {__pdffield/field/__pdffield/pushbutton/#1}
      {
        \__pdffield_field:n { __pdffield/pushbutton/#1 }
      }
    \keys_set:nn {pdffield}{parent=__pdffield/pushbutton/#1}
  }
\cs_generate_variant:Nn \__pdffield_pushbutton_field:n {V}
\cs_new_protected:Npn \__pdffield_pushbutton:n #1
  {
    \group_begin:
    \tl_set:Nn\l__pdffield_pushbutton_appearance_code_tl{}
    \cs_set_eq:NN\__pdffield_appearance_handler:nnn \__pdffield_pushbutton_appearance_handler:nnn
    \keys_set:nn {pdffield}
      {
        fieldID=,
        name=pushbutton,
        width  = 3cm,
        height = 1.05\normalbaselineskip,
        depth  = 0.45\normalbaselineskip,
      }
    \keys_set:nn { pdffield }{__pdffield/preset/pushbutton,#1}
    \keys_set:nn { pdffield }
      {
        ,V=
        ,DV=
        ,setFf={Pushbutton}
        ,FT= Btn
      }
    \tl_if_empty:NT\l__pdffield_fieldID_tl
      {
        \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl
        \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/pushbutton/}
      }
   \tl_if_empty:NT\l__pdffield_pushbutton_appearance_code_tl
      {
        \__pdffield_pushbutton_default_appearances:
        \exp_args:Nnx
         \keys_set:nn {pdffield}
           {
             appearance          = pdffield/pushbutton/default-\int_eval:n{ \g__pdffield_pushbutton_cnt_int},
             down-appearance     = pdffield/pushbutton/defaultdown-\int_eval:n{ \g__pdffield_pushbutton_cnt_int},
             rollover-appearance = pdffield/pushbutton/defaultrollover-\int_eval:n{ \g__pdffield_pushbutton_cnt_int},
           }
      }
    \l__pdffield_pushbutton_appearance_code_tl
    \__pdffield_pushbutton_field:V\l__pdffield_fieldID_tl
    \__pdffield_annot:
    \group_end:
  }
\cs_new_protected:Npn \__pdffield_pushbutton_appearance_handler:nnn #1 #2 #3 %name, type, text
  {
    \tl_put_right:Nn \l__pdffield_pushbutton_appearance_code_tl
      {
        \pdfxform_if_exist:nTF {  #1  }
           {
            \pdfannot_dict_put:nnx {widget/AP}{#2}{\pdfxform_ref:n{#1}}
           }
           {
              \msg_error:nnnn{pdffield}{appearance-missing}{#1}{#3}
           }
      }
  }
\cs_set_eq:NN \pdffield_pushbutton:n \__pdffield_pushbutton:n

%% File: l3pdfpdffield-choice.dtx


\RequirePackage{l3draw}
\seq_new:N  \l__pdffield_choice_values_seq
\seq_new:N  \l__pdffield_choice_defaultvalues_seq
\seq_new:N  \l__pdffield_choice_displayvalues_seq
\seq_new:N  \l__pdffield_choice_opt_seq
\cs_new_protected:Npn \__pdffield_choice_field:n #1 %name
  {
    \pdf_object_if_exist:nF {__pdffield/field/__pdffield/choice/#1}
      {
        \seq_clear:N \l__pdffield_choice_opt_seq
        \seq_map_indexed_inline:Nn \l__pdffield_choice_values_seq
          {
            \pdf_string_from_unicode:nnN{utf16/hex}{##2}\l__pdffield_tmpa_str
            \tl_set:Nx \l__pdffield_tmpa_tl {\seq_item:Nn \l__pdffield_choice_displayvalues_seq {##1} }
            \tl_if_empty:NTF \l__pdffield_tmpa_tl
              {
                \seq_put_right:NV \l__pdffield_choice_opt_seq \l__pdffield_tmpa_str
              }
              {
                \exp_args:NnV
                \pdf_string_from_unicode:nnN{utf16/hex}\l__pdffield_tmpa_tl\l__pdffield_tmpb_str
                \seq_put_right:Nx \l__pdffield_choice_opt_seq
                  { [ \l__pdffield_tmpa_str\c_space_tl\l__pdffield_tmpb_str] }
              }
          }
        \pdf_object_unnamed_write:nx {array}{\seq_use:Nn\l__pdffield_choice_opt_seq {~}}
        \pdfdict_put:nnx { l__pdffield/field }{Opt}  { \pdf_object_ref_last: }
        \int_compare:nNnTF {\bitset_item:Nn \l__pdffield_Ff_bitset {MultiSelect}} = {1}
          {
            \tl_clear:N \l__pdffield_tmpa_tl
            \seq_map_inline:Nn \l__pdffield_choice_defaultvalues_seq
             {
                \pdf_string_from_unicode:nnN{utf16/hex}{##1}\l__pdffield_tmpa_str
                \tl_put_right:NV \l__pdffield_tmpa_tl \l__pdffield_tmpa_str
                \pdfdict_put:nnx { l__pdffield/field }{V}  { [ \l__pdffield_tmpa_tl ] }
             }
          }
          {
            \tl_set:Nx \l__pdffield_tmpa_tl {\seq_item:Nn \l__pdffield_choice_defaultvalues_seq {1} }
            \exp_args:NnV
              \pdf_string_from_unicode:nnN{utf16/hex}\l__pdffield_tmpa_tl\l__pdffield_tmpb_str
            \pdfdict_put:nnx { l__pdffield/field }{V}  { \l__pdffield_tmpb_str }
          }
        \__pdffield_field:n { __pdffield/choice/#1 }
      }
    \keys_set:nn {pdffield}{parent=__pdffield/choice/#1}
  }
\cs_generate_variant:Nn \__pdffield_choice_field:n {V}
\cs_new_protected:Npn \__pdffield_choice:n #1
  {
    \group_begin:
    \cs_set_eq:NN\__pdffield_value_handler:n      \__pdffield_choice_value_handler:n
    \cs_set_eq:NN\__pdffield_default_handler:n    \__pdffield_choice_default_handler:n
    \__pdffield_textfield_default_appearance:
    \keys_set:nn {pdffield}
      {
         fieldID=
        ,name=choice
        ,appearance = pdffield/textfield/default
        ,width  = 3cm
        ,height = \normalbaselineskip
        ,type=combo-edit
        ,__pdffield/preset/choice
        ,#1
        ,FT= Ch
      }
     \__pdffield_choice_set_type:
     \keys_set:nn {pdffield}
      {
        ,DA=
           {
              \pdf_name_from_unicode_e:n{\l__pdffield_DA_fontname_tl}
              \c_space_tl
              \dim_to_decimal_in_bp:n{\l__pdffield_DA_fontsize_dim}
              \c_space_tl
              Tf
              \c_space_tl
              \l__pdffield_DA_fontcolor_tl
              \c_space_tl
              %\l__pdffield_text_DAextra_tl
           }
      }
   \tl_if_empty:NT\l__pdffield_fieldID_tl
      {
        \pdfdict_get:nnN {l__pdffield/field}{T}\l__pdffield_fieldID_tl
        \tl_put_left:Nn \l__pdffield_fieldID_tl {__pdffield/choice/}
      }
    \__pdffield_choice_field:V\l__pdffield_fieldID_tl
    \__pdffield_annot:
    \group_end:
  }
\cs_new_protected:Npn \__pdffield_choice_value_handler:n #1
  {
    \seq_set_from_clist:Nn \l__pdffield_choice_values_seq {#1}
  }
\cs_new_protected:Npn \__pdffield_choice_default_handler:n #1
  {
    \seq_set_from_clist:Nn \l__pdffield_choice_defaultvalues_seq {#1}
  }
\keys_define:nn{pdffield}
  {
     values .meta:n = {value={#1}}
    ,default-values .meta:n = {default={#1}}
    ,display-values .code:n =
     {
       \seq_set_from_clist:Nn \l__pdffield_choice_displayvalues_seq {#1}
     }
   ,top-index .code:n =
     {
       \pdfdict_put:nnx {l__pdffield/field}{TI}{\int_eval:n{#1-1}}
     }
  }
\cs_new_protected:Npn \__pdffield_choice_set_type: {}

\keys_define:nn { pdffield }
  {
    type .choice:
   ,type / combo      .code:n =
     {
       \cs_set_protected:Npn\__pdffield_choice_set_type:
        {
          \keys_set:nn{pdffield}{setFf={Combo},unsetFf={Edit,DoNotSpellCheck}}
        }
     }
   ,type / combo-edit .code:n =
     {
       \cs_set_protected:Npn\__pdffield_choice_set_type:
         {
           \keys_set:nn{pdffield}{setFf={Combo,Edit}}
         }
     }
   ,type / list       .code:n =
     {
       \cs_set_protected:Npn\__pdffield_choice_set_type:
         {
           \keys_set:nn{pdffield}{unsetFf={Combo,Edit,},unsetFf={Edit,DoNotSpellCheck}}
         }
     }
  }
\cs_new_protected:Npn \__pdffield_choice_appearance_handler:nnn #1 #2 #3 %name, type, text
  {
  }

\cs_set_eq:NN \pdffield_choice:n \__pdffield_choice:n
%% File: l3pdfpdffield-action.dtx

\msg_new:nnn {pdffield}{action-name-undefined}
  {
    The~`#1`~action~name~`#2`~is~not~defined~and~
    will~be~ignored.
  }

\tl_new:N  \l__pdffield_action_export_tl
\seq_new:N \l__pdffield_action_Fields_seq
\tl_new:N  \l__pdffield_action_next_tl
\pdfdict_new:n   {l__pdffield/ResetForm}
\pdfdict_put:nnn {l__pdffield/ResetForm}{Type}{/Action}
\pdfdict_put:nnn {l__pdffield/ResetForm}{S}{/ResetForm}
\pdfdict_new:n   {l__pdffield/SubmitForm}
\pdfdict_put:nnn {l__pdffield/SubmitForm}{Type}{/Action}
\pdfdict_put:nnn {l__pdffield/SubmitForm}{S}{/SubmitForm}
\bitset_new:Nn \l__pdffield_Flags_bitset
  {
     Include/Exclude      = 1
    ,IncludeNoValueFields = 2
    ,ExportFormat         = 3
    ,GetMethod            = 4
    ,SubmitCoordinates    = 5
    ,XFDF                 = 6
    ,IncludeAppendSaves   = 7
    ,IncludeAnnotations   = 8
    ,SubmitPDF            = 9
    ,CanonicalFormat      = 10
    ,ExclNonUserAnnots    = 11
    ,ExclFKey             = 12
    ,EmbedForm            = 14
    ,include/exclude      = 1
    ,includenovaluefields = 2
    ,exportformat         = 3
    ,getmethod            = 4
    ,submitcoordinates    = 5
    ,xfdf                 = 6
    ,includeappendsaves   = 7
    ,includeannotations   = 8
    ,submitpdf            = 9
    ,canonicalformat      = 10
    ,exclnonuserannots    = 11
    ,exclfkey             = 12
    ,embedform            = 14
  }
\cs_new_protected:Npn \__pdffield_action_flags_pdf:
  {
    \bitset_clear:N \l__pdffield_Flags_bitset
    \bitset_set_true:Nn \l__pdffield_Flags_bitset { SubmitPDF }
  }

\cs_new_protected:Npn \__pdffield_action_flags_html:
  {
    \bitset_set_true:Nn \l__pdffield_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { IncludeAppendSaves }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { IncludeAnnotations }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { SubmitPDF }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExclNonUserAnnots }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExclFKey }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { EmbedForm }
  }

\cs_new_protected:Npn \__pdffield_action_flags_fdf:
  {
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { GetMethod }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { SubmitCoordinates }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { SubmitPDF }
  }

\cs_new_protected:Npn \__pdffield_action_flags_xfdf:
  {
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExportFormat }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { GetMethod }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { SubmitCoordinates }
    \bitset_set_true:Nn \l__pdffield_Flags_bitset { XFDF }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { IncludeAppendSaves }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { IncludeAnnotations }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { SubmitPDF }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExclNonUserAnnots }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { ExclFKey }
    \bitset_set_false:Nn \l__pdffield_Flags_bitset { EmbedForm }
  }
\keys_define:nn { pdffield }
  {
    reset .code:n =
      {
        \cs_if_exist:cTF { __pdffield_action_reset_#1: }
          {
            \use:c { __pdffield_action_reset_#1: }
            \pdfannot_dict_put:nnx{widget}
             {A}
             {\tl_use:c { c__pdffield_action_reset_#1_tl } }
          }
          {
            \msg_warning:nnnn{pdffield}{action-name-undefined}{reset}{#1}
          }
      }
   ,reset .default:n = all
  }

\keys_define:nn { pdffield }
  {
    submit .code:n =
      {
        \cs_if_exist:cTF { __pdffield_action_submit_#1: }
          {
            \use:c { __pdffield_action_submit_#1: }
            \pdfannot_dict_put:nnx{widget}
             {A}
             {\tl_use:c { c__pdffield_action_submit_#1_tl } }
          }
          {
            \msg_warning:nnnn{pdffield}{action-name-undefined}{submit}{#1}
          }
      }
  }

\keys_define:nn { pdffield }
  {
    import .code:n =
      {
        \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdffield_tmpa_str
        \pdf_object_unnamed_write:nx {dict}{/Type/Action/S/ImportData/F\l__pdffield_tmpa_str}
        \pdfannot_dict_put:nnx{widget}
          {A}
          {\pdf_object_ref_last: }
      }
  }

\keys_define:nn { pdffield / action }
  {
    fields .code:n  =
      {
        \clist_map_inline:nn {#1}
          {
            \pdf_string_from_unicode:nnN {utf8/string}{##1}\l__pdffield_tmpa_str
            \seq_put_right:NV\l__pdffield_action_Fields_seq \l__pdffield_tmpa_str
          }
      }
    ,exclude .code:n = { \bitset_set_true:Nn \l__pdffield_Flags_bitset {Include/Exclude }}
    ,include .code:n = { \bitset_set_false:Nn \l__pdffield_Flags_bitset {Include/Exclude }}
    ,export .choices:nn = {pdf,fdf,html,xfdf}
      {
        \tl_set:Nn \l__pdffield_action_export_tl {#1}
      }
    ,export .initial:n = {html}
    ,charset .choices:nn =
      {utf-8, utf-16, Shift-JIS, BigFive, GBK, UHC}
      { \pdfdict_put:nnn { l__pdffield/SubmitForm }{#1} }
    ,urlencode .bool_set:N = \l__pdffield_url_encode_bool
    ,next .tl_set:N = \l__pdffield_action_next_tl
 }
\keys_define:nn { pdffield / action }
  {
    ,setFlags .code:n =
      {
        \clist_map_inline:nn {#1}
          {
            \bitset_set_true:Nn \l__pdffield_Flags_bitset {##1}
          }
      }
    ,setsubmitflags .meta:n = {setFlags={#1}}
    ,unsetFlags .multichoice:
    ,unsetFlags / all .code:n = { \bitset_clear:N \l__pdffield_Flags_bitset}
    ,unsetFlags / unknown .code:n =
      {
        \bitset_set_false:Nn \l__pdffield_Flags_bitset {#1}
      }
    ,unsetsubmitflags .meta:n = {unsetFlags={#1}}
  }
\cs_new_protected:Npn \__pdffield_action_reset_new:nn #1 #2 %#1 name, #2 keyval
  {
    \cs_new_protected:cpn {__pdffield_action_reset_#1:}
      {
        \group_begin:
        \seq_clear:N \l__pdffield_action_Fields_seq
        \keys_set:nn { pdffield / action }{ #2 }
        \pdf_object_unnamed_write:nx
          { array }
          { \seq_use:Nn \l__pdffield_action_Fields_seq {~} }
        \tl_if_empty:NF \l__pdffield_action_next_tl
          {
            \pdfdict_put:nnx {l__pdffield/ResetForm}{Next}{\l__pdffield_action_next_tl}
          }
        \pdfdict_put:nnx
          { l__pdffield/ResetForm }
          { Fields }
          { \pdf_object_ref_last: }
        \pdfdict_put:nnx
          { l__pdffield/ResetForm }
          { Flags }
          { \bitset_item:Nn\l__pdffield_Flags_bitset{Include/Exclude} }
        \pdf_object_unnamed_write:nx
          { dict }
          { \pdfdict_use:n{l__pdffield/ResetForm} }
        \tl_const:cx { c__pdffield_action_reset_#1_tl } { \pdf_object_ref_last: }
        \cs_gset_eq:cN {__pdffield_action_reset_#1:} \prg_do_nothing:
        \group_end:
      }
  }

\__pdffield_action_reset_new:nn  {all}{fields={},exclude}
\cs_new_protected:Npn \__pdffield_action_submit_new:nn #1 #2 %#1 name, #2 keyval
  {
    \group_begin:
    \char_set_catcode_other:N \%
    \char_set_catcode_other:N \#
    \__pdffield_action_submit_new:nnn {#1}{#2}
  }
\cs_new_protected:Npn \__pdffield_action_submit_new:nnn #1 #2 #3 %#1 name, #2 keyval, #3 url
  {
    \group_end:
    \cs_new_protected:cpn {__pdffield_action_submit_#1:}
      {
        \group_begin:
        \seq_clear:N    \l__pdffield_action_Fields_seq
        \bitset_clear:N \l__pdffield_Flags_bitset
        \keys_set:nn {pdffield/action}{#2}
        \use:c{ __pdffield_action_flags_\l__pdffield_action_export_tl :}
        \pdfdict_put:nnx
          { l__pdffield/SubmitForm }
          { Flags }
          { \bitset_to_arabic:N \l__pdffield_Flags_bitset }
        \tl_if_empty:NF \l__pdffield_action_next_tl
          {
            \pdfdict_put:nnx {l__pdffield/SubmitForm}{Next}{\l__pdffield_action_next_tl}
          }
        \bool_if:NTF \l__pdffield_url_encode_bool
          { \pdf_string_from_unicode:nnN { utf8/URI }   {#3}\l__pdffield_tmpa_str }
          { \pdf_string_from_unicode:nnN { utf8/string }{#3}\l__pdffield_tmpa_str }
        \pdf_object_unnamed_write:nx {dict}
          {
            /FS/URL
            /F \l__pdffield_tmpa_str
          }
        \pdfdict_put:nnx
          { l__pdffield/SubmitForm }
          { F }
          { \pdf_object_ref_last: }
        \pdf_object_unnamed_write:nx
          { dict }
          { \pdfdict_use:n{ l__pdffield/SubmitForm } }
        \tl_const:cx { c__pdffield_action_submit_#1_tl } { \pdf_object_ref_last: }
        \cs_gset_eq:cN { __pdffield_action_submit_#1: } \prg_do_nothing:
        \group_end:
      }
  }

\cs_set_eq:NN \pdffield_reset_new:nn   \__pdffield_action_reset_new:nn
\cs_set_eq:NN \pdffield_submit_new:nnn \__pdffield_action_submit_new:nn

%% 
%%
%% End of file `l3pdffield-testphase.sty'.
