[latex3-commits] [git/LaTeX3-latex3-pdfresources] test-checkbox: storing (72589ce)

Ulrike Fischer fischer at troubleshooting-tex.de
Thu Mar 4 18:09:09 CET 2021


Repository : https://github.com/latex3/pdfresources
On branch  : test-checkbox
Link       : https://github.com/latex3/pdfresources/commit/72589ced31e3ed08b7a6774cef3827bbf6fa9b45

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

commit 72589ced31e3ed08b7a6774cef3827bbf6fa9b45
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Thu Mar 4 18:09:09 2021 +0100

    storing


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

72589ced31e3ed08b7a6774cef3827bbf6fa9b45
 experiments/checkbox2-test.tex      |  7 ++-
 newpackages/l3pdffield-checkbox.dtx | 86 ++++++++++++++++++++++++++++---------
 2 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/experiments/checkbox2-test.tex b/experiments/checkbox2-test.tex
index 806e701..18cfda5 100644
--- a/experiments/checkbox2-test.tex
+++ b/experiments/checkbox2-test.tex
@@ -55,9 +55,14 @@
 
 \begin{document}%\showoutput
 %\Form[NeedAppearances=false]
+\ExplSyntaxOn
+\keys_set:nn{pdffield/checkbox}{width=1cm}
+\ExplSyntaxOff
+1: \checkboxfield[altname=blub]{checkbox1}
 
-1: \checkboxfield{checkbox1}
+1: \checkboxfield[checked,width=3cm,height=2cm,depth=1cm,altname=zzz]{checkbox1}
 
+\checkboxfield[checked,width=3cm,height=2cm,depth=1cm]{checkbox1}
 1: \checkboxfield[checked]{checkbox2}
 \end{document}
    \checkboxfield{checkbox1}
diff --git a/newpackages/l3pdffield-checkbox.dtx b/newpackages/l3pdffield-checkbox.dtx
index 0fd26cf..9856cc0 100644
--- a/newpackages/l3pdffield-checkbox.dtx
+++ b/newpackages/l3pdffield-checkbox.dtx
@@ -183,6 +183,8 @@
 % \item[MK] this is what hyperref uses to set the appearance, but I
 %  explicitly leave it out and use |AP|.
 %
+% \item[Q] (alignment), used by hyperref but not relevant as we don't have variable
+% text here.
 % \end{description}
 % \end{documentation}
 % \begin{implementation}
@@ -203,8 +205,10 @@
 %    \end{macrocode}
 % \section{local variables}
 %    \begin{macrocode}
+\str_new:N\l_@@_field_name_str
 \str_new:N \l_@@_tmpa_str
 \str_new:N \l_@@_name_tmpa_str
+\tl_new:N \l_@@_keys_tmpa_tl
 %    \end{macrocode}
 % \section{Variants}
 %    \begin{macrocode}
@@ -221,6 +225,11 @@
     The~field~name~`#1`~contains~a~period. \\
     This~is~not~allowed. `
   }
+\msg_new:nnn {pdffield}{field-keys-ignored}
+  {
+    The~field~`#1`~is~already~initialized\\
+    The~field~keys~`#2`~are~ignored.
+  }
 %    \end{macrocode}
 
 % \section{bitsets}
@@ -274,10 +283,8 @@
 % \meta{name} should be a PDF text string without period. It identifies the
 % field.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_checkbox_field_add:n #1
+\cs_new_protected:Npn \@@_checkbox_field_new:n #1
   {
-    \pdf_object_if_exist:nF {@@_checkbox/field/#1}
-     {
       \group_begin:
       \pdf_object_new:nn {@@_checkbox/field/#1}      {dict}
       \pdf_object_new:nn {@@_checkbox/field/#1/Kids} {array}
@@ -309,7 +316,6 @@
         { Fields }
         {\pdf_object_ref:n {@@_checkbox/field/#1} }
       \group_end:
-     }
   }
 
 %    \end{macrocode}
@@ -399,33 +405,73 @@
 \cs_new_protected:Npn \@@_checkbox_add:nn #1 #2 %#1: keys, #2 name
   {
     \group_begin:
-    \keys_set:nn {pdffield / checkbox } {#1}
+    \keys_set_filter:nnnN {pdffield / checkbox }{field}{#1}\l_@@_keys_tmpa_tl
     \str_if_in:nnT {#2}{.}
       {
         \msg_error:nnn {pdffield}{no-period}{#2}
       }
-    \pdf_string_from_unicode:nnN {utf8/string-raw}{#2}\l_@@_name_tmpa_str
-    \exp_args:No
-      \@@_checkbox_field_add:n {\l_@@_name_tmpa_str}
+    \pdf_string_from_unicode:nnN {utf8/string-raw}{#2}\l_@@_field_name_str
+    \exp_args:Nx
+      \pdf_object_if_exist:nTF {@@_checkbox/field/\l_@@_field_name_str}
+       {
+          \tl_if_empty:NF \l_@@_keys_tmpa_tl
+           {
+             \msg_warning:nnxx {pdffield}{field-keys-ignored}{#2}{\l_@@_keys_tmpa_tl}
+           }
+       }
+       {
+         \keys_set:nV { pdffield/checkbox } \l_@@_keys_tmpa_tl
+         \exp_args:No
+         \@@_checkbox_field_new:n {\l_@@_field_name_str}
+       }
     \exp_args:No
       \@@_checkbox_annot_add:nnnn
-        {\l_@@_name_tmpa_str}
-        {\l_@@_annot_ht_dim}
-        {\l_@@_annot_wd_dim}
-        {\l_@@_annot_dp_dim}
+        {\l_@@_field_name_str}
+        {\l_@@_annot_wd_tl }
+        {\l_@@_annot_ht_tl }
+        {\l_@@_annot_dp_tl }
     \group_end:
   }
+%    \end{macrocode}
+% \section{Keys}
+% The size of the checkbox
+%    \begin{macrocode}
 
+\tl_new:N \l_@@_annot_ht_tl
+\tl_new:N \l_@@_annot_wd_tl
+\tl_new:N \l_@@_annot_dp_tl
 
-\dim_new:N \l_@@_annot_ht_dim
-\dim_set:Nn \l_@@_annot_ht_dim {1cm}
-\dim_new:N \l_@@_annot_wd_dim
-\dim_set:Nn \l_@@_annot_wd_dim {1cm}
-\dim_new:N \l_@@_annot_dp_dim
-
+\keys_define:nn { pdffield / checkbox }
+  {
+    ,width  .tl_set:N = \l_@@_annot_wd_tl
+    ,height .tl_set:N = \l_@@_annot_ht_tl
+    ,depth  .tl_set:N = \l_@@_annot_dp_tl
+    ,width  .initial:n = \normalbaselineskip
+    ,height .initial:n = \normalbaselineskip
+    ,depth  .initial:n = 0pt
+  }
 %    \end{macrocode}
-% \section{Keys}
-% At first a key to decide if the Box is checked or not
+% The names. The main name is an argument.
+% The other names can only be set when the field is created.
+%    \begin{macrocode}
+\keys_define:nn { pdffield / checkbox }
+  {
+    ,altname .code:n =
+      {
+        \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_name_tmpa_str
+        \pdfdict_put:nnx { l_@@/checkbox/field }{TU}{\l_@@_name_tmpa_str}
+      }
+    ,altname .groups:n = {field}
+    ,mappingname .code:n =
+      {
+        \pdf_string_from_unicode:nnN {utf8/string}{#1}\l_@@_name_tmpa_str
+        \pdfdict_put:nnx { l_@@/checkbox/field }{TM}{\l_@@_name_tmpa_str}
+      }
+    ,mappingname .groups:n = {field}
+  }
+%    \end{macrocode}
+
+% A key to decide if the Box is initially checked or not
 %    \begin{macrocode}
 \keys_define:nn { pdffield / checkbox }
  {





More information about the latex3-commits mailing list.