[latex3-commits] [git/LaTeX3-latex3-pdfresources] textfields: working on textfields (cf8e6e2)

Ulrike Fischer fischer at troubleshooting-tex.de
Mon May 10 20:21:20 CEST 2021


Repository : https://github.com/latex3/pdfresources
On branch  : textfields
Link       : https://github.com/latex3/pdfresources/commit/cf8e6e2a359b7fd7315b8d06f10023227b273e26

>---------------------------------------------------------------

commit cf8e6e2a359b7fd7315b8d06f10023227b273e26
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Mon May 10 20:21:20 2021 +0200

    working on textfields


>---------------------------------------------------------------

cf8e6e2a359b7fd7315b8d06f10023227b273e26
 l3pdffield-checkbox.dtx     |  35 ++--
 l3pdffield-textfield.dtx    | 397 ++++++++++++++++++++++++++++++++++++++++++++
 l3pdffield.dtx              | 172 ++++++++++++++++---
 pdfmanagement-testphase.ins |   1 +
 4 files changed, 561 insertions(+), 44 deletions(-)

diff --git a/l3pdffield-checkbox.dtx b/l3pdffield-checkbox.dtx
index c3c0ed8..1d876f0 100644
--- a/l3pdffield-checkbox.dtx
+++ b/l3pdffield-checkbox.dtx
@@ -113,16 +113,15 @@
 %
 % The new checkbox command accept all field and annot keys from l3pdffield.
 % A few keys are disabled or are forced to specific values.
-% Some keys have a more checkbox specific
-% behaviour or have other defaults than with the basic commands. Additionally there
+% The |appearance| keys have a more checkbox specific
+% behaviour, other keys have other defaults than with the basic commands.
+% Additionally there
 % are a small number of keys specific to a checkbox.
 %
 %
 % Disabled keys are
 %  \begin{itemize}
 %  \item |V|, |DV|, |AS|: use |checked| instead.
-%  \item |AP/N|, |AP/R|, |AP/D|: checkboxes need special formated
-%  appearances, use |appearance|, |rollover-appearance| and |down-appearance| instead.
 %  \item |FT| is overwritten.
 %  \item For checkboxes only the field flags  |ReadOnly|, |Required| and |NoExport| make sense.
 %  |Radio|, |Pushbotton| are set automatically automatically by the code
@@ -204,20 +203,24 @@
 % |width| and |height| use \cs{normalbaselineskip}, the |depth| is zero.
 % \end{function}
 %
-% \begin{function}{appearance,rollover-appearance,down-appearance}
+% \begin{function}{AP/N,appearance,AP/R,rollover-appearance,AP/D,down-appearance}
 %  \begin{syntax}
-%   |appearance| = \meta{name}\\
-%   |rollover-appearance| = \meta{name}\\
-%   |down-appearance| = \meta{name}
+%   |AP/N| = \meta{partial appearance name}\\
+%   |appearance| = \meta{partial appearance name}\\
+%   |AP/R| = \meta{partial appearance name}\\
+%   |rollover-appearance| = \meta{partial appearance name}\\
+%   |AP/D| = \meta{partial appearance name}\\
+%   |down-appearance| = \meta{partial appearance name}
 %  \end{syntax}
 % This keys sets the normal appearance, the rollover appearance (when the
 % mouse hovers over the checkbox) and the down appearance (when the
 % mouse clicks). They take as value a
-% \meta{name} and expects that the two appearances \meta{name}|/Yes| and \meta{name}|/Off|
-% has been created with the command described below. The initial value is |checkbox/default|
-% for the normal appearance and shows a \cs{texttimes}. The other appearance are not set by default.
+% \meta{partial appearance name} and expects that \emph{two} form Xobjects
+% \meta{partial appearance name}|/Yes| and \meta{partial appearance name}|/Off|
+% has been created. The initial value is |pdffield/checkbox/default|
+% for the normal appearance and shows a \cs{texttimes}.
+% The other appearance are not set by default.
 % \end{function}
-
 % \begin{function}{checked}
 %  \begin{syntax}
 %   |checked| = |true|\verb"|"|false|
@@ -339,8 +342,7 @@
         height = \normalbaselineskip,
       }
 %    \end{macrocode}
-% A number of keys should be undefined, to avoid that the value and
-% appearances has the wrong format.
+% Value keys should be undefined.
 %    \begin{macrocode}
     \@@_key_disable:nnn{checkbox}{V}{checked}
     \@@_key_disable:nnn{checkbox}{DV}{checked}
@@ -384,7 +386,6 @@
        \pdfannot_dict_put:nnn {widget}{AS}{ /Yes }
      }
    ,checked .default:n = {true}
-   ,checked .initial:n = {false}
    ,checked .groups:n  = {checkbox}
  }
 %    \end{macrocode}
@@ -395,7 +396,7 @@
    fieldID .tl_set:N = \l_@@_fieldID_tl
  }
 %    \end{macrocode}
-% \begin{macro}{\@@_checkbox_appearance:nnn}
+% \begin{macro}{\@@_checkbox_appearance_handler:nnn}
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_checkbox_appearance_handler:nnn #1 #2 #3 %name, type, text
   {
@@ -430,5 +431,3 @@
 %    \end{macrocode}
 % \end{macro}
 %\end{implementation}
-
-\endinput%
diff --git a/l3pdffield-textfield.dtx b/l3pdffield-textfield.dtx
new file mode 100644
index 0000000..a197de1
--- /dev/null
+++ b/l3pdffield-textfield.dtx
@@ -0,0 +1,397 @@
+% \iffalse meta-comment
+%
+%% File: l3pdfpdffield-textfield.dtx
+%
+% Copyright (C) 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
+%
+%    http://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.
+%
+% -----------------------------------------------------------------------
+%
+% The development version of the bundle can be found at
+%
+%    https://github.com/latex3/pdfresources
+%
+% for those people who are interested.
+%
+%<*driver>
+\RequirePackage{pdfmanagement-testphase}
+\DeclareDocumentMetadata{}
+\makeatletter
+\declare at file@substitution{doc.sty}{doc-v3beta.sty}
+\makeatother
+\documentclass[full]{l3doc}
+\usepackage{array,booktabs}
+\usepackage{l3pdffield-testphase}
+\hypersetup{pdfauthor=The LaTeX Project,
+ pdftitle=l3pdffield (LaTeX PDF management testphase bundle)}
+\begin{document}
+  \DocInput{\jobname.dtx}
+\end{document}
+%</driver>
+% \fi
+% \providecommand\hook[1]{\texttt{#1}}
+% \title{^^A
+%   The \pkg{l3pdffield-textfield} module\\ Commands to create textfield form fields   ^^A
+%   \\ \LaTeX{} PDF management testphase bundle
+% }
+%
+% \author{^^A
+%  The \LaTeX{} Project\thanks
+%    {^^A
+%      E-mail:
+%        \href{mailto:latex-team at latex-project.org}
+%          {latex-team at latex-project.org}^^A
+%    }^^A
+% }
+%
+% \date{Version 0.95c, released 2021-03-17}
+%
+% \maketitle
+% \begin{documentation}
+% \section{\pkg{l3pdffield-textfield} Introduction}
+% This is the documentation for textfield fields, for general information about form fields
+% check the documentation l3pdffield.
+%
+% Textfields allows the user to input text which is then rendered by the PDF viewer and
+% often can also be saved together with the PDF.
+%
+% A typical wish here it that a font matching the document font is used
+% in textfields too.  But it is quite unclear if and how this can be done.
+% Obviously it is not possible like with a checkbox to prepare and include appearances
+% with the right look, the PDF reader has to render the text dynamically.
+% It is possible to pass with the |DA| key a font operator to the textfield,
+% but
+%
+%
+%
+%
+% Please keep in mind
+% \begin{itemize}
+% \item Not every PDF viewer supports textfields.
+% \item The font and the exact position of the chars depends on the PDF viewer.
+% \item The handling can depend on settings in the PDF viewer. In adobe reader for
+% example I had to disable an option to avoid that it tries to create an appearance
+% itself
+% \item Standards like pdf/A disable features of form fields too
+% (as you typically can't change the PDF).
+% \end{itemize}
+% \section{Textfields}
+% Input a value:
+% \ExplSyntaxOn
+%  \pdffield_textfield:n{name=test,width=4cm,height=0.7\baselineskip,depth=0.3\baselineskip}
+% \ExplSyntaxOff
+%
+% \bigskip
+% \subsection{Commands}
+% \begin{function}{\pdffield_textfield:n}
+% \begin{syntax}
+%  \cs{pdffield_textfield:n}\Arg{key val list}
+% \end{syntax}
+% This creates a textfield. The list of allowed keys is described below.
+% The \meta{key val list} should at least set the name, without it the default name
+% |textfield| is used. Textfields with the same
+% name belong to the same field and are filled together. The default appearance
+% is a light gray background.
+% The default appearance is setup at the first use.
+% \end{function}
+%
+%
+% \subsection{Keys}
+%
+% The new textfield command accept all field and annot keys from l3pdffield.
+% A few keys are disabled or are forced to specific values.
+% Some keys have a more textfield specific
+% behaviour or have other defaults than with the basic commands. Additionally there
+% are a small number of keys specific to a textfield.
+%
+%
+% Disabled keys are
+%  \begin{itemize}
+%  \item |FT| is overwritten.
+%  \item For textfields only the field flags  |ReadOnly|, |Required| |NoExport|
+%  |Multiline|, |Password|, |FileSelect|, |DoNotSpellCheck|, |DoNotScroll| and |Comb|
+%  make sense.
+%  If |Comb| is set, |Multiline|, |Password| and |FileSelect| are unset, |MaxLen| is
+%  set to 10 if it hasn't been set previously.
+%  \end{itemize}
+%
+% \begin{function}{preset-textfield}
+%  \begin{syntax}
+%   |preset-textfield| = \Arg{key-val-list}
+%  \end{syntax}
+% This allows to set default keys for a textfield.
+% \end{function}
+%
+% \begin{function}{name,T}
+%  \begin{syntax}
+%   |name| = \meta{partial name}\\
+%   |T| = \meta{partial name}
+%  \end{syntax}
+% This sets like the |T| key for fields the partial name of the field. The value
+% shouldn't contain a period, be not empty and sensibly consist of simple chars.
+% Additionally the value is used to create the field ID.
+% This means that textfield with the same partial name are annotations
+% with the same field as parent and are filled together---this
+% what is typically expected.
+% The field ID is then internal and can not be used to
+% attach another annotation.
+% For explicit control of the field ID  use the |fieldID| key.
+% \end{function}
+%
+% \begin{function}{fieldID}
+%  \begin{syntax}
+%   |fieldID| = \meta{field ID}\\
+%  \end{syntax}
+% \emph{For experts only!}
+% This allows to give the textfield a specific ID. This is only useful
+% in the context of a larger fieldset or if you want to attach another annotation
+% to the field with \s{pdffield_annot:n}. If used wrongly you can
+% easily create invalid fieldset. It allows you to create to fields with the
+% same partial name, but if you want to see both
+% you need to ensure that their full names are
+% different---for example by adding some parent fields.
+% \end{function}
+%
+% \begin{function}{parent}
+%  \begin{syntax}
+%   |parent| = \meta{field ID}\\
+%  \end{syntax}
+% This is only needed if the field should be part
+% of a larger fieldset. The value should be a field ID of a field created previously
+% with \cs{pdffield_field:nn}.
+% \end{function}
+%
+% \begin{function}{altname,TU}
+%  \begin{syntax}
+%   |altname| = \meta{string}\\
+%   |TU| = \meta{string}\\
+%  \end{syntax}
+% This is sets an alternative name for user interaction.
+% This name can only be set at the first textfield instance, when the field is initialized.
+% \end{function}
+%
+% \begin{function}{mappingname,TM}
+%  \begin{syntax}
+%   |mappingname| = \meta{string}\\
+%   |TM| = \meta{string}\\
+%  \end{syntax}
+% This is sets an alternative name for export.
+% This name can only be set at the first textfield instance, when the field is initialized.
+% \end{function}
+%
+% \begin{function}{width,height,depth}
+% \begin{syntax}
+% |width| = \meta{dim expression}\\
+% |height| = \meta{dim expression}\\
+% |depth| = \meta{dim expression}
+% \end{syntax}
+% These keys allow to set the dimensions of textfield instance.
+% The value should be a dimension expression. By default
+% |width| is 3cm, the |height| use 0.7\cs{normalbaselineskip}, the |depth| is 0.3\cs{normalbaselineskip}.
+% \end{function}
+%
+% \begin{function}{appearance,rollover-appearance,down-appearance}
+%  \begin{syntax}
+%   |appearance| = \meta{name}\\
+%   |rollover-appearance| = \meta{name}\\
+%   |down-appearance| = \meta{name}
+%  \end{syntax}
+% This keys sets the normal appearance, the rollover appearance (when the
+% mouse hovers over the textfield) and the down appearance (when the
+% mouse clicks). They expect the name of an existing form Xobject as value.
+% The initial value is |pdffield/textfield/default|
+% for the normal appearance and shows a light gray background.
+% The other appearance are not set by default (and it is quite unclear if they
+% make sense for a textfield).
+% \end{function}
+%
+%
+% \subsection{Using with hyperref}
+% The \cs{TextField} command from hyperref also prints a label, something that the
+% command here doesn't do. A redefinition like the following should allow \cs{TextField}
+% to use the commands of this module. Be aware that the behaviour will not be identical!
+% Not every setting and key from \pkg{hyperref} has been copied.
+%
+% \begin{verbatim}
+% \ExplSyntaxOn\makeatletter
+% \def\@TextField[#1]#2{\LayoutTextField{#2}{\pdffield_textfield:n {name=#2,#1}}}
+% \ExplSyntaxOff\makeatother
+% \end{verbatim}
+%
+%
+% \end{documentation}
+%
+% \begin{implementation}
+% \section{\pkg{l3pdffield-textfield} Implementation}
+%    \begin{macrocode}
+%<*package>
+%<@@=pdffield>
+%    \end{macrocode}
+% \subsection{Variables}
+%    \begin{macrocode}
+\tl_new:N  \l_@@_DA_fontcolor_tl
+\dim_new:N \l_@@_DA_fontsize_dim
+\tl_new:N  \l_@@_DA_fontname_tl
+%    \end{macrocode}
+% \subsection{Messages}
+%    \begin{macrocode}
+%    \end{macrocode}
+% \subsection{Appearances}
+% The default appearances are a cross (\cs{texttimes}),
+% Every appearance should have two versions and follow the naming
+% module/\meta{name}/Yes and module/\meta{name}/Off.
+%  \begin{macro}{@@/textfield/default_appearances:}
+%  This defines the standard appearance. It is setup at the first
+%  use of a textfield.
+%    \begin{macrocode}
+\cs_new_protected:cn {@@/textfield/default_appearance:}
+  {
+    \pdffield_appearance:nn {pdffield/textfield/default}
+     {
+       { \color_select:n{black!5!white}\rule{\paperwidth}{\paperheight} }
+     }
+    \cs_gset_eq:cN {@@/textfield/default_appearance:} \prg_do_nothing:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+%\subsection{Creating the field}
+% A field should be created if the name doesn't exist
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_textfield_field:n #1 %name
+  {
+    \pdf_object_if_exist:nF {@@/field/@@/textfield/#1}
+      {
+        \@@_field:n { @@/textfield/#1 }
+      }
+    \keys_set:nn {pdffield}{parent=@@/textfield/#1}
+  }
+\cs_generate_variant:Nn \@@_textfield_field:n {V}
+%    \end{macrocode}
+% \subsection{Assembling the textfield}
+
+% \begin{macro}{\@@_textfield:n}
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_textfield:n #1
+  {
+    \group_begin:
+    \cs_set_eq:NN\@@_value_handler:nN \@@_textfield_value_handler:nN
+    \use:c {@@/textfield/default_appearance:}
+%    \end{macrocode}
+% Setting up the defaults.
+%    \begin{macrocode}
+    \keys_set:nn {pdffield}
+      {
+        fieldID=,
+        name=textfield,
+        appearance = pdffield/textfield/default,
+        width  = 3cm,
+        height = 0.7\normalbaselineskip,
+        depth  = 0.3\normalbaselineskip,
+        % font defaults!!
+      }
+%    \end{macrocode}
+%   \begin{macrocode}
+    \keys_set:nn { pdffield }{@@/preset/textfield,#1}
+    \int_compare:nNnT {\bitset_item:Nn \l_@@_Ff_bitset {Comb}}={1}
+      {
+        % warning if set?
+        \keys_set:nn { pdffield }
+          {
+            ,unsetFf={FileSelect,Multiline,Password}
+          }
+        \pdfdict_get:nnN {l_@@/field}{MaxLen}\l_@@_tmpa_tl
+        \quark_if_no_value:NT \l_@@_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_@@_DA_fontname_tl}
+              \c_space_tl
+              \dim_to_decimal_in_bp:n{\l_@@_DA_fontsize_dim}
+              \c_space_tl
+              Tf
+              \c_space_tl
+              \l_@@_DA_fontcolor_tl
+              \c_space_tl
+              %\l_@@_text_DAextra_tl
+           }
+      }
+    \tl_if_empty:NT\l_@@_fieldID_tl
+      {
+        \pdfdict_get:nnN {l_@@/field}{T}\l_@@_fieldID_tl
+        \tl_put_left:Nn \l_@@_fieldID_tl {@@/textfield/}
+      }
+
+    \@@_textfield_field:V\l_@@_fieldID_tl
+    \@@_annot:
+    \group_end:
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \subsection{Keys}
+% Most keys are inherited simply the ones from the generic field and annot keys.
+% A key to decide if the box is initially checked or not.
+% We stay in the same family so that we can build a style.
+%    \begin{macrocode}
+\keys_define:nn {pdffield}
+  {
+    ,fontcolor .code:n =
+       {
+         \@@_color_set:nn {@@/tmp}{#1}
+         \color_export:nnN{@@/tmp}{space-sep-rgb}\l_@@_DA_fontcolor_tl
+         \tl_put_right:Nn \l_@@_DA_fontcolor_tl{~rg}
+       }
+    ,fontcolor .initial:n = black,
+    ,font .tl_set:N      = \l_@@_DA_fontname_tl
+    ,font .initial:n     = {Helv}
+    ,fontsize .dim_set:N = \l_@@_DA_fontsize_dim
+    ,fontsize .initial:n = {10bp}
+  }
+%    \end{macrocode}
+% And a key to set a dedicated field ID
+%    \begin{macrocode}
+\keys_define:nn { pdffield }
+ {
+   fieldID .tl_set:N = \l_@@_fieldID_tl
+ }
+%    \end{macrocode}
+%
+% \subsection{Handler}
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_textfield_value_handler:nN #1#2
+  {
+     \pdf_string_from_unicode:nnN {utf8/string}{#1}#2
+  }
+%    \end{macrocode}
+%
+% \subsection{user commands}
+% \begin{macro}{\pdffield_textfield:n}
+%    \begin{macrocode}
+\cs_set_eq:NN \pdffield_textfield:n \@@_textfield:n
+%</package>
+%    \end{macrocode}
+% \end{macro}
+%\end{implementation}
+
+\endinput%
diff --git a/l3pdffield.dtx b/l3pdffield.dtx
index f20f01b..44cc0c3 100644
--- a/l3pdffield.dtx
+++ b/l3pdffield.dtx
@@ -430,13 +430,13 @@
 % (Pushbuttons for example don't have a value).
 % \end{function}
 %
-% \begin{function}{V}
+% \begin{function}{DV}
 %  \begin{syntax}
-%   |V| = \meta{various}
+%   |DV| = \meta{various}
 %  \end{syntax}
 % The default value, to which the field reverts
 % when a reset-form action is executed. The format of this value is the
-% same as that of \texttt{V}.
+% same as that of \texttt{DV}.
 % \end{function}
 %
 % \begin{function}{MaxLen}
@@ -557,12 +557,12 @@
 % It is stored expanded and parentheses are added around the value.
 % \end{function}
 %
-% \begin{function}{Q}
+% \begin{function}{Q,align}
 %  \begin{syntax}
-%   |Q| = |0|\verb"|"|1|\verb"|"|2|
+%   |Q| = |left|\verb"|"|center|\verb"|"|right|\\
+%   |align| = |left|\verb"|"|center|\verb"|"|right|
 %  \end{syntax}
-% The justification of the text,
-% the allow values are 0, 1, 2 for left, centered, right.
+% The justification of the text.
 % \end{function}
 %
 % \begin{function}{DS,RV}
@@ -573,6 +573,7 @@
 % \section{Annot keys}
 %
 % Table~\ref{tab:annotkeys} summarize the keys which can be used.
+% A number of keys have alias names which are mentioned in the descriptions.
 %
 % \begin{table}
 % \caption{Keys for field annotations}\label{tab:annotkeys}
@@ -584,9 +585,9 @@
 % width    & dim expression & (yes)  & default is 0pt \\
 % height   & dim expression & (yes)  & default is 0pt \\
 % depth   & dim expression & (yes)  & default is 0pt \\
-% AP/N    & xform or dict  & yes  (in PDF 2.0) \\
-% AP/R    & xform or dict  & yes  (in PDF 2.0) \\
-% AP/D    & xform or dict  & yes  (in PDF 2.0) \\
+% AP/N    & appearance name  & yes  (in PDF 2.0) \\
+% AP/R    & appearance name  & yes  (in PDF 2.0) \\
+% AP/D    & appearance name  & yes  (in PDF 2.0) \\
 % AS      & name  & yes  (in PDF 2.0) \\
 % setF    & list of flags \\
 % unsetF  & list of flags \\
@@ -617,17 +618,20 @@
 % an already declared field.
 % \end{function}
 %
-% \begin{function}{parent}
+% \begin{function}{AP/N,AP/R,AP/D}
 %  \begin{syntax}
-%   |AP/N| = \meta{xform reference} \verb"|" \meta{dictionary}\\
-%   |AP/R| = \meta{xform reference} \verb"|" \meta{dictionary}\\
-%   |AP/D| = \meta{xform reference} \verb"|" \meta{dictionary}
+%   |AP/N| = \meta{appearance name}\\
+%   |AP/R| = \meta{appearance name}\\
+%   |AP/D| = \meta{appearance name}
 %  \end{syntax}
-% This keys set the normal, rollover and down appearance. The value is either a
-% xform object or a dictionary mapping various states to an xform object.
+% This keys set the normal, rollover and down appearance. Alias names are
+% |appearance|, |rollover-appearance| and |down-appearance|.
+% The value is by default a simple name of an appearance/form Xobject but
+% modules like \pkg{l3pdffield-checkbox} change this to allow to add appearances for
+% various states.
 % \end{function}
 %
-% \begin{function}{parent}
+% \begin{function}{AS}
 %  \begin{syntax}
 %   |AS| = \meta{appearance state name}
 %  \end{syntax}
@@ -669,12 +673,46 @@
 % \end{verbatim}
 % \end{function}
 %
+% The following keys add values to the  \emph{dynamic appearance dictionary}
+% |MK| directory. This is only relevant for
+% annotations with dynamic content, like e.g. textfields.
+%
+% The |MK| dictionary can also be added by using |\pdfannot_dict_put:nnn{Widget}{MK}{...}|
+% but the two methods should not be mixed.
+%
+%  \begin{function}{MK/R,rotate}
+%  \begin{syntax}
+%  |MK/R| = |0| \verb"|" |90| \verb"|" |180| \verb"|" |270|\\
+%  |rotate| = |0| \verb"|" |90| \verb"|" |180| \verb"|" |270|
+%  \end{syntax}
+% These rotates the content of the annotation.
+% \end{function}
+%
+% \begin{function}{MK/BC,bordercolor}
+%  \begin{syntax}
+%  |MK/BC| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}\\
+%  |bordercolor| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}
+%  \end{syntax}
+% These colors the border. Internally currently RGB is used
+% \end{function}
+%
+% \begin{function}{MK/BG,backgroundcolor}
+%  \begin{syntax}
+%  |MK/BG| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}\\
+%  |backgroundcolor| = \meta{color expression} \verb"|" [\meta{model}]\Arg{values}
+%  \end{syntax}
+% These colors the background. Internally currently RGB is used
+% \end{function}
+%
+% The remaining key are useful for buttons only, currently no special syntax support
+% is implemented. They will be handled when the code for push buttons is developed and
+% tested.
 % \begin{function}{MK/*}
 %  \begin{syntax}
 %  |MK/*| = \meta{various}
 %  \end{syntax}
 % These keys adds the various entries in the \emph{dynamic appearance dictionary}.
-% * should be one of |R|, |BC|, |BG|, |CA|, |RC|, |AC|, |I|, |RI|, |IX|, |IF|, |TP|.
+% * should be one of  |CA|, |RC|, |AC|, |I|, |RI|, |IX|, |IF|, |TP|.
 % The |MK| dictionary can also be added by using |\pdfannot_dict_put:nnn{Widget}{MK}{...}|
 % but the two methods should not be mixed.
 % \end{function}
@@ -974,12 +1012,35 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \subsection{auxiliary command for color keys}
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_color_set:nn #1 #2
+ {
+   \tl_if_head_eq_charcode:nNTF {#2}[ %]
+    {
+      \@@_color_set_aux:nwn  { #1 } #2
+    }
+    {
+      \color_set:nn {#1} {#2}
+    }
+ }
+
+\cs_new_protected:Npn \@@_color_set_aux:nwn #1 [#2] #3
+  {
+     \color_set:nnn {#1}{#2}{#3}
+  }
+
+%    \end{macrocode}
 % \subsection{Field keys}
 % The names. The main name should not be empty, it is added to the dictionary
 % when the field is created. A new name means a new field.
 % The other names can only be set when the field is created,
 % so we put them in the field group.
 %    \begin{macrocode}
+\cs_new_protected:Npn \@@_value_handler:nN #1#2
+  {
+    \tl_set:Nn #2 {#1}
+  }
 \keys_define:nn { pdffield  }
   {
     ,parent .tl_set:N = \l_@@_currentparent_tl
@@ -1047,7 +1108,8 @@
            \pdfdict_remove:nn { l_@@/field }{V}
          }
          {
-           \pdfdict_put:nnx { l_@@/field }{V}{ #1 }
+           \@@_value_handler:nN{#1}\l_@@_tmpa_str
+           \pdfdict_put:nnx { l_@@/field }{V}{ \l_@@_tmpa_str }
          }
      }
     ,V .groups:n = {field}
@@ -1058,7 +1120,8 @@
            \pdfdict_remove:nn { l_@@/field }{DV}
          }
          {
-           \pdfdict_put:nnx { l_@@/field }{DV}{ #1 }
+           \@@_value_handler:nN{#1}\l_@@_tmpa_str
+           \pdfdict_put:nnx { l_@@/field }{DV}{ \l_@@_tmpa_str }
          }
      }
     ,DV .groups:n = {field}
@@ -1211,16 +1274,17 @@
            \pdfdict_remove:nn { l_@@/field }{DA}
          }
          {
-           \pdfdict_put:nnx { l_@@/field }{DA}{ #1 }
+           \pdfdict_put:nnx { l_@@/field }{DA}{ (#1) }
          }
       }
     ,DA .groups:n = {field}
-    ,Q .choices:nn = {0,1,2}
+    ,Q .choices:nn = {left,center,right}
      {
-       \pdfdict_put:nnx { l_@@/field }{Q}{ #1 }
+       \pdfdict_put:nnx { l_@@/field }{Q}{ \int_eval:n{\l_keys_choice_int-1} }
      }
     ,Q / .code:n = { \pdfdict_remove:nn { l_@@/field }{Q} }
     ,Q .groups:n = {field}
+    ,align .meta:n={Q=#1}
     ,DS .code:n =
      {
        \msg_warning:nnn {pdffield}{not-implemented}{DS}
@@ -1273,7 +1337,7 @@
  {
    \pdfxform_if_exist:nTF {  #1 }
      {
-       \pdfannot_dict_put:nnx {widget}{AP/#2}
+       \pdfannot_dict_put:nnx {widget/AP}{#2}
          {
            \pdfxform_ref:n {#1}
          }
@@ -1328,7 +1392,55 @@
    ,down-appearance .meta:n = {AP/D={#1}}
   }
 
+\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}
+        }
+        {
+          \@@_color_set:nn {@@/tmp}{#1}
+          \color_export:nnN{@@/tmp}{space-sep-rgb}\l_@@_tmpa_tl
+          \pdfannot_dict_put:nnx {widget/MK}{BC}{[\l_@@_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}
+        }
+        {
+          \@@_color_set:nn {@@/tmp}{#1}
+          \color_export:nnN{@@/tmp}{space-sep-rgb}\l_@@_tmpa_tl
+          \pdfannot_dict_put:nnx {widget/MK}{BG}{[\l_@@_tmpa_tl]}
+        }
+     }
+    ,MK/BG .groups:n = annot
+   ,bordercolor .meta:n = {MK/BG=#1}
+  }
 
 \cs_set_protected:Npn \@@_tmpa:n #1
  {
@@ -1338,7 +1450,7 @@
         {
           \tl_if_empty:nTF {##1}
             {
-              \pdfannot_dict_remove:nn { widget/AP }
+              \pdfannot_dict_remove:nn { widget/AP }{#1}
             }
             {
               \pdfannot_dict_put:nnx {widget/MK}{#1}{##1}
@@ -1348,7 +1460,7 @@
      }
  }
 
-\clist_map_inline:nn {R,BC,BG,CA,RC,AC,I,RI,IX,IF,TP}
+\clist_map_inline:nn {CA,RC,AC,I,RI,IX,IF,TP}
   { \@@_tmpa:n {#1} }
 %    \end{macrocode}
 % Flags.
@@ -1448,8 +1560,16 @@
            @@/preset/checkbox .meta:n = {#1},
          }
       }
+   ,preset-textfield .code:n =
+      {
+        \keys_define:nn { pdffield }
+         {
+           @@/preset/textfield .meta:n = {#1},
+         }
+      }
   }
 \keys_set:nn{ pdffield / setup }{preset-checkbox={}}
+\keys_set:nn{ pdffield / setup }{preset-textfield={}}
 
 \cs_new_protected:Npn \@@_style_create:nn #1#2
   {
diff --git a/pdfmanagement-testphase.ins b/pdfmanagement-testphase.ins
index 847c624..97db2f0 100644
--- a/pdfmanagement-testphase.ins
+++ b/pdfmanagement-testphase.ins
@@ -129,6 +129,7 @@ and all files in that bundle must be distributed together.
       {%
         \from{l3pdffield.dtx}{package}
         \from{l3pdffield-checkbox.dtx}{package}
+        \from{l3pdffield-textfield.dtx}{package}
       }%
   }
 





More information about the latex3-commits mailing list.