[latex3-commits] [git/LaTeX3-latex3-pdfresources] renamedict77: added commands to reset a dict (a56c699)

Ulrike Fischer fischer at troubleshooting-tex.de
Sun Apr 26 01:03:36 CEST 2020


Repository : https://github.com/latex3/pdfresources
On branch  : renamedict77
Link       : https://github.com/latex3/pdfresources/commit/a56c69975dd8e8bdfb2df5ac1b38fd7a6ee6e166

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

commit a56c69975dd8e8bdfb2df5ac1b38fd7a6ee6e166
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sun Apr 26 01:03:36 2020 +0200

    added commands to reset a dict


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

a56c69975dd8e8bdfb2df5ac1b38fd7a6ee6e166
 experiments/embedfiles.tex |  9 ++++----
 l3pdffile.dtx              | 51 ++++++++++++++++++++++++++++------------------
 pdfresources.dtx           | 27 ++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/experiments/embedfiles.tex b/experiments/embedfiles.tex
index 1cc8b75..4422dfa 100644
--- a/experiments/embedfiles.tex
+++ b/experiments/embedfiles.tex
@@ -13,15 +13,16 @@
 \group_begin:
 \pdfdict_put:nnn  {file/FileSpec} {AFRelationship}{/Source}
 \pdfdict_put:nnn  {file/FileSpec} {Desc}{(this~is~a~eps)}
+\pdfdict_show:n   {file/FileSpec}
 \pdffile_embed:nn {example}{grüße.txt}
 \pdffile_attach:n {example}
 \group_end:
-\end{document}
+
 \group_begin:
 \pdfdict_put:nnn  {file/FileSpec} {AFRelationship}{/Source}
 \pdfdict_put:nnn  {file/FileSpec} {Desc}{(this~is~a~eps)}
-\pdffile_embed:nn {example}{example-image.eps}
-\pdffile_attach:n {example}
+\pdffile_embed:nn {example2}{example-image.eps}
+\pdffile_attach:n {example2}
 \group_end:
 %
 \group_begin:
@@ -36,7 +37,7 @@
 \group_begin:
 \pdfdict_put:nnn  {file/FileSpec} {AFRelationship}{/Source}
 \pdfdict_put:nnn  {file/FileSpec} {Desc}{(this~is~a~tex~file)}
-\pdffile_embed:nn {tex} {links.tex}
+\pdffile_embed:nn  {tex} {links.tex}
 \pdffile_attach:nN {tex}\l_tmpa_tl
 \group_end:
 
diff --git a/l3pdffile.dtx b/l3pdffile.dtx
index a7c8f09..c49d79f 100644
--- a/l3pdffile.dtx
+++ b/l3pdffile.dtx
@@ -297,29 +297,40 @@
 \str_new:N  \l_pdffile_full_name_str
 \str_new:N  \l_pdffile_full_name_convert_str
 %    \end{macrocode}
-% Here we define and setup the local dictionaries
+% Here we define and setup the local dictionaries. We also define constants.
 %    \begin{macrocode}
-\pdfdict_new:n   {file}
-\pdfdict_put:nnn {file}{Type}{/EmbeddedFile}
+\pdfdict_new:n   { file }
+\cs_new_protected:Npn \@@_dict_file_reset:
+  {
+    \pdfdict_put:nnn { file }{Type}{/EmbeddedFile}
+  }
+\pdfdict_reset:n { file }
 
-\pdfdict_new:n   {file/Params}
-\pdfdict_put:nnn {file/Params}
-  {ModDate}  { (\file_timestamp:n { \l_pdffile_full_name_str }) }
-\pdfdict_put:nnn {file/Params}
-  {Size}     { \file_size:n { \l_pdffile_full_name_str } }
-\pdfdict_put:nnn {file/Params}
-  {CheckSum} { (\file_mdfive_hash:n { \l_pdffile_full_name_str }) }
+\pdfdict_new:n   { file/Params }
+\cs_new_protected:cpn { @@_dict_file/Params_reset: }
+  {
+    \pdfdict_put:nnn { file/Params }
+      {ModDate}  { (\file_timestamp:n { \l_pdffile_full_name_str }) }
+    \pdfdict_put:nnn { file/Params }
+      {Size}     { \file_size:n { \l_pdffile_full_name_str } }
+    \pdfdict_put:nnn { file/Params }
+      {CheckSum} { (\file_mdfive_hash:n { \l_pdffile_full_name_str }) }
+  }
+\pdfdict_reset:n { file/Params }
 
-\pdfdict_new:n   {file/FileSpec}
-\pdfdict_put:nnn {file/FileSpec}
-  {Type} { /FileSpec }
-%escaping??
-\pdfdict_put:nnn {file/FileSpec}
-  {F} { (\l_pdffile_full_name_convert_str) }
-\pdfdict_put:nnn {file/FileSpec}
-  {UF} { (\l_pdffile_full_name_convert_str) }
-\pdfdict_put:nnn {file/FileSpec}
-  {AFRelationship} { /Unspecified }
+\pdfdict_new:n   { file/FileSpec }
+\cs_new_protected:cpn { @@_dict_file/FileSpec_reset: }
+  {
+    \pdfdict_put:nnn { file/FileSpec }
+      {Type} { /FileSpec }
+    \pdfdict_put:nnn { file/FileSpec }
+      {F} { (\l_pdffile_full_name_convert_str) }
+    \pdfdict_put:nnn { file/FileSpec }
+      {UF} { (\l_pdffile_full_name_convert_str) }
+    \pdfdict_put:nnn { file/FileSpec }
+      {AFRelationship} { /Unspecified }
+  }
+\pdfdict_reset:n { file/FileSpec }
 
 %    \end{macrocode}
 % \end{variable}
diff --git a/pdfresources.dtx b/pdfresources.dtx
index 26e3514..56bc488 100644
--- a/pdfresources.dtx
+++ b/pdfresources.dtx
@@ -627,6 +627,7 @@
 %
 %  \begin{macro}{
 %                \@@_dict_clear,
+%                \@@_dict_reset,
 %                \@@_dict_handler_put:nnn,
 %                \@@_dict_get:nnN,
 %                \@@_dict_remove:nn,
@@ -648,6 +649,17 @@
       }
   }
 
+%reset clears and then fills with the default
+\cs_new_protected:Npn \@@_dict_reset:n #1
+  {
+    \@@_dict_if_local:nT { #1 }
+      {
+        \prop_clear:c  { \@@_dict_name:n { #1 } }
+        \use:c { @@_dict_#1_reset: }
+      }
+  }
+
+
 %local + global
 \cs_new_protected:Npn \@@_dict_handler_put:nnn #1 #2 #3  %#1 path, #2 name, #3 value
   {
@@ -902,6 +914,21 @@
     \@@_dict_map:n { #1 }
   }
 %    \end{macrocode}
+%
+% \begin{function}[added = 2020-04-25]
+%   {\pdfdict_reset:n }
+%   \begin{syntax}
+%     \cs{pdfdict_reset:n}  \Arg{(local) dictionary}
+%   \end{syntax}
+% This resets a dictionary: it clears the entries and then adds eventually
+% default values (normally at least the Type entry).
+%  \end{function}
+%    \begin{macrocode}
+\cs_new_protected:Npn \pdfdict_reset:n #1
+  {
+    \@@_dict_reset:n { #1 }
+  }
+%    \end{macrocode}
 % \begin{function}[added = 2020-04-08]
 %   {\pdfdict_show:n }
 %   \begin{syntax}





More information about the latex3-commits mailing list.