[latex3-commits] [git/LaTeX3-latex3-pdfresources] textfields: docu (e95b382)

Ulrike Fischer fischer at troubleshooting-tex.de
Wed May 12 19:26:42 CEST 2021


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

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

commit e95b382db27e26eca961241440e123af8a2206f2
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Wed May 12 19:26:42 2021 +0200

    docu


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

e95b382db27e26eca961241440e123af8a2206f2
 experiments/radio.tex      |  81 ++++++++++++++++++++++++------
 l3pdffield-radiobutton.dtx | 119 +++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 174 insertions(+), 26 deletions(-)

diff --git a/experiments/radio.tex b/experiments/radio.tex
index 39244d6..ad87f90 100644
--- a/experiments/radio.tex
+++ b/experiments/radio.tex
@@ -1,3 +1,4 @@
+% !Mode:: "TeX:DE:UTF-8:Main"
 \RequirePackage{pdfmanagement-testphase}
 \DeclareDocumentMetadata{uncompress}
 %\RequirePackage{pdfmanagement-regressiontest}
@@ -23,26 +24,74 @@
 \begin{document}
 
 \ExplSyntaxOn
-%\pdffield_field:nn{name=parent,V=/Yes}{parent}
+\pdffield_field:nn{name=parent}{parent}
 %\pdffield_checkbox:n{name=a,parent=parent}
 %\pdffield_checkbox:n{name=b,parent=parent}
 
 %\pdffield_field:nn{name=parent}{parent}
-\tl_set:Nn \l__pdffield_radiovalue_tl{A}
-\pdffield_radio:n{name=AAAA,V=/B,AS=Off}
-\tl_set:Nn \l__pdffield_radiovalue_tl{B}
-\pdffield_radio:n{name=AAAA,AS=B}
-\tl_set:Nn \l__pdffield_radiovalue_tl{C}
-\pdffield_radio:n{name=AAAA,AS=Off}
-
-
-\tl_set:Nn \l__pdffield_radiovalue_tl{A}
-\pdffield_radio:n{name=BBB,V=/B,AS=Off,setfieldflags={
-    RadiosInUnison},unsetfieldflags={NoToggleToOff}}
-%\tl_set:Nn \l__pdffield_radiovalue_tl{B}
-\pdffield_radio:n{name=BBB,AS=A}
-%\tl_set:Nn \l__pdffield_radiovalue_tl{C}
-\pdffield_radio:n{name=BBB,AS=Off}
+%\tl_set:Nn \l__pdffield_radiovalue_on_tl{A}
+%\pdffield_radio:n{name=AAAA,V=/B,AS=Off}
+%\tl_set:Nn \l__pdffield_radiovalue_on_tl{B}
+%\pdffield_radio:n{name=AAAA,AS=B}
+%\tl_set:Nn \l__pdffield_radiovalue_on_tl{C}
+%\pdffield_radio:n{name=AAAA,AS=Off}
+
+CC
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{0}
+\tl_set:Nn \l__pdffield_radiovalue_off_tl{Off}
+\pdf_object_new:nn{opt}{array}
+\pdf_object_write:nn{opt}{(A)~(B)~(C)}
+\pdffield_radio:n{name=CC,V=/1,AS=Off,appearance=pdffield/bear,parent=parent,
+Opt=opt,%setfieldflags=radiosinunison
+}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{1}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Boff}
+\pdffield_radio:n{name=CC,AS=Off,appearance=pdffield/bear,bordercolor=yellow}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{2}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Coff}
+\pdffield_radio:n{name=CC,AS=Off}
+%\pdffield_radio:n{name=EE,AS=Off,parent=parent}
+
+
+\newpage
+
+CC
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{1}
+\tl_set:Nn \l__pdffield_radiovalue_off_tl{Off}
+%\pdf_object_new:nn{opt}{array}
+%\pdf_object_write:nn{opt}{(A)~(B)~(A)}
+\pdffield_radio:n{name=DD,V=/1,AS=1,appearance=pdffield/bear,parent=parent,
+Opt=opt,setfieldflags=radiosinunison
+}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{2}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Boff}
+\pdffield_radio:n{name=DD,AS=1,appearance=pdffield/bear,bordercolor=yellow}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{1}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Coff}
+\pdffield_radio:n{name=DD,AS=Off}
+%\pdffield_radio:n{name=EE,AS=Off,parent=parent}
+
+
+
+DD
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{A}
+\tl_set:Nn \l__pdffield_radiovalue_off_tl{Off}
+\pdffield_radio:n{name=DD,V=/B,AS=Off,appearance=pdffield/bear}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{B}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Boff}
+\pdffield_radio:n{name=DD,AS=B,appearance=pdffield/bear,bordercolor=yellow}
+\tl_set:Nn \l__pdffield_radiovalue_on_tl{C}
+%\tl_set:Nn \l__pdffield_radiovalue_off_tl{Coff}
+\pdffield_radio:n{name=DD,AS=Off}
+
+
+%\tl_set:Nn \l__pdffield_radiovalue_on_tl{A}
+%\pdffield_radio:n{name=BBB,V=/B,AS=Off,setfieldflags={
+%    RadiosInUnison},unsetfieldflags={NoToggleToOff}}
+%%\tl_set:Nn \l__pdffield_radiovalue_tl{B}
+%\pdffield_radio:n{name=BBB,AS=A}
+%%\tl_set:Nn \l__pdffield_radiovalue_tl{C}
+%\pdffield_radio:n{name=BBB,AS=Off}
 
 %\pdffield_radio:n{name=B,parent=parent}
 %\pdffield_radio:n{name=C,parent=parent}
diff --git a/l3pdffield-radiobutton.dtx b/l3pdffield-radiobutton.dtx
index 77f0336..6038c69 100644
--- a/l3pdffield-radiobutton.dtx
+++ b/l3pdffield-radiobutton.dtx
@@ -88,6 +88,100 @@
 %  ^^A \pdffield_radio:n{name=bear,appearance=pdffield/bear,width=23pt,height=30pt,depth=10pt}
 % \ExplSyntaxOff
 %
+% A radio button set is one field together with a number of field annotations which
+% represent the individual radio buttons.
+% Radio buttons are similar to checkboxes buttons and
+% they have like checkboxes two \enquote{states}:
+% checked and unchecked. In checkbox field two states have the
+% fix names |/Yes| and |/Off|,
+% and this means that even if there two or more annotations and so checkbox instances
+% the checkboxes are checked and unchecked together:
+%
+%  \begin{tikzpicture}[level 2/.style={level distance=7mm},
+%  level 1/.style={sibling distance=25mm},
+%  level 2/.style={sibling distance=15mm}]
+%   \node[draw] {checkbox field}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /Yes\\
+%               /Off
+%             }}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /Yes\\
+%               /Off
+%             }}
+%   ;
+%   \end{tikzpicture}
+%
+% Radio buttons typically have more than one annotation, and if one button is turned
+% on this should turn off the other. This is implemented by using different
+% states in the various annotations and by setting a flag in the field.
+% The off state should still always have the name |/Off|\footnote{%
+%  the PDF reference doesn't say anything about this, but various tests showed that
+%  one better should stick to this name, with other names the buttons disappeared.}
+%  but the on state should be the value. The field dictionary should then set
+%  in the |/V| key the start value (this doesn't necessarly mean that the button
+%  is also selected from the begin on, this can be set independantly).
+%
+%    \begin{tikzpicture}[level 2/.style={level distance=7mm},
+%  level 1/.style={sibling distance=25mm},
+%  level 2/.style={sibling distance=15mm}]
+%   \node[draw,align=left,font=\ttfamily] {\textrm{radio button field}\\/V /value1 }
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /value0 \\
+%               /Off
+%             }}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /value1 \\
+%               /Off
+%             }}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /value2 \\
+%               /Off
+%             }}
+%   ;
+%   \end{tikzpicture}
+%
+% It can be awkward to have to use the values also as names of appearances states, it
+% makes it for example difficult to use unicode for the value names, so there is another
+% option by using the |/Opt| array: The numbers |/0|, |/1| point then to the
+% index position in the array.
+%
+%  \begin{tikzpicture}[level 2/.style={level distance=7mm},
+%  level 1/.style={sibling distance=25mm},
+%  level 2/.style={sibling distance=15mm}]
+%   \node[draw,align=left,font=\ttfamily] {\textrm{radio button field}\\
+%           /Opt [(value0) (value1) (value2)]
+%           /V /0 }
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /0 \\
+%               /Off
+%             }}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /1 \\
+%               /Off
+%             }}
+%           child {node[draw,dashed,align=left,font=\ttfamily]
+%             {\textrm{annotation}\\ /2 \\
+%               /Off
+%             }}
+%   ;
+%   \end{tikzpicture}
+%
+% It is possible to set the start appearance for every button, so e.g. all
+% buttons could be selected when the PDF is opened. But as soon as one button is clicked
+% on you get one selected button and the other are unselected. You can't select or
+% deselect all buttons. The PDF reference mentions an flag |NoToggleToOff| but this
+% doesn't do anything, at least not in the PDF viewers I tried.
+%
+% If two radio field annotations use the same on-state name they are selected and
+% unselected together, like checkboxes with the same /Yes state. This can be used
+% to build radio groups which works \enquote{in unison}. The flag |RadiosInUnison|
+% is neither needed for this (but doesn't harm either) nor
+% does it change the behaviour, at least again not in the PDF viewers I tried.
+%
+%
+%
+%
 % \bigskip
 % \subsection{Commands}
 % \begin{function}{\pdffield_radio:n}
@@ -153,7 +247,7 @@
 % \emph{For experts only!}
 % This allows to give the checkbox field 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
+% to the field with \cs{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
@@ -267,7 +361,10 @@
 %    \end{macrocode}
 % \subsection{Variables}
 %    \begin{macrocode}
-\tl_new:N\l_@@_radiovalue_tl
+\tl_new:N\l_@@_radiovalue_on_tl
+\tl_new:N\l_@@_radiovalue_off_tl
+\tl_set:Nn \l_@@_radiovalue_on_tl {Yes}
+\tl_set:Nn \l_@@_radiovalue_off_tl {Off}
 %    \end{macrocode}
 % \subsection{Messages}
 %    \begin{macrocode}
@@ -326,15 +423,17 @@
     \use:c {@@/radio/default_appearances:}
     \cs_set_eq:NN\@@_appearance_handler:nnn \@@_radio_appearance_handler:nnn
 %    \end{macrocode}
-% Setting up the defaults.
+% Setting up the defaults. The Radio flag is set at the begin to
+% allow to unset it for tests/special effects.
 %    \begin{macrocode}
     \keys_set:nn {pdffield}
       {
-        fieldID=,
-        name=radio,
-        appearance = pdffield/radio/default,
-        width  = \normalbaselineskip,
-        height = \normalbaselineskip,
+        fieldID=
+       ,name=radio
+       ,appearance = pdffield/radio/default
+       ,width  = \normalbaselineskip
+       ,height = \normalbaselineskip
+       ,setFf={Radio}
       }
 %    \end{macrocode}
 % Value keys should be undefined.??
@@ -347,7 +446,7 @@
     \keys_set:nn { pdffield }
       {
         ,unsetFf={Pushbutton}
-        ,setFf={Radio}
+        %
         ,FT= Btn
       }
     \tl_if_empty:NT\l_@@_fieldID_tl
@@ -424,7 +523,7 @@
         \pdf_object_unnamed_write:nx
           {dict}
           {
-             /\l_@@_radiovalue_tl \c_space_tl \pdfxform_ref:n  { #1/Yes}
+             /\l_@@_radiovalue_on_tl \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:}





More information about the latex3-commits mailing list.