[latex3-commits] [git/LaTeX3-latex3-pdfresources] renamedict77: working on embedding files, new escape command (temporarly) (95756dd)

Ulrike Fischer fischer at troubleshooting-tex.de
Tue Apr 21 19:34:25 CEST 2020


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

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

commit 95756dd864dcdadd755171bda0016bac58fa83f1
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Tue Apr 21 19:34:25 2020 +0200

    working on embedding files, new escape command (temporarly)


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

95756dd864dcdadd755171bda0016bac58fa83f1
 build.lua                     |  1 +
 experiments/embedfiles.tex    | 12 +++++++
 l3pdffile.dtx                 | 53 +++++++++++++---------------
 newpackages/new-pdfescape.sty | 80 +++++++++++++++++++++++++++++++++++++++++++
 pdfresources.dtx              | 16 +++++++++
 5 files changed, 133 insertions(+), 29 deletions(-)

diff --git a/build.lua b/build.lua
index c738bf8..f37019a 100644
--- a/build.lua
+++ b/build.lua
@@ -15,6 +15,7 @@ sourcefiles =  {"*.dtx","*.ins",
                 "newpackages/bkm-generic.def",
                 "newpackages/new-attachfile.sty",
                 "newpackages/atfi-generic.def",
+                "newpackages/new-pdfescape.sty",
                 }
 
 checkruns = 3
diff --git a/experiments/embedfiles.tex b/experiments/embedfiles.tex
new file mode 100644
index 0000000..82f4f70
--- /dev/null
+++ b/experiments/embedfiles.tex
@@ -0,0 +1,12 @@
+\documentclass{article}
+\usepackage{pdfresources,l3pdffile}
+\ExplSyntaxOn
+\pdf_uncompress:
+\ExplSyntaxOff
+\begin{document}
+blub
+\ExplSyntaxOn
+\pdfdict_put:nnn {embeddedfile}{Subtype}{\pdftool_name:n{application/postscript}}
+\pdffile_embed:nN {example-image.eps}\l_tmpa_tl
+\ExplSyntaxOff
+\end{document}
\ No newline at end of file
diff --git a/l3pdffile.dtx b/l3pdffile.dtx
index 07e93fd..ce86082 100644
--- a/l3pdffile.dtx
+++ b/l3pdffile.dtx
@@ -135,64 +135,59 @@
 %
 %    \begin{macrocode}
 %<*package>
+\ProvidesExplPackage {l3pdffile} {2020-04-21} {0.1}
+  {embedding and referencing files in PDF}
+\RequirePackage{new-pdfescape}  %temporarly!!  
 %    \end{macrocode}
 %
 %    \begin{macrocode}
 %<@@=pdf>
 %    \end{macrocode}
-%
+% \begin{NOTE}{UF}
+% should the default value be stored in dedicated commands or tl vars?
+% \end{NOTE}
 % \begin{variable}
 %  {
-%   \l_pdffile_embed_filename_tl
-%   \c_pdffile_embed_moddate_tl,
-%   \c_pdffile_embed_size_tl,
-%   \c_pdffile_embed_checksum_tl,
-%
-%   }
-%
+%   \l_pdffile_embed_curfilename_tl
+%  }
+% \cs{l_pdffile_embed_curfilename_tl} will be set at the begin of the command, and
+% so can be used in dictionary values or other references.
 %    \begin{macrocode}
 \tl_new:N \l_pdffile_embed_filename_tl
-\tl_const:N \c_pdffile_embed_moddate_tl
-  {
-    \file_timestamp:n{ \l_pdffile_embed_filename_tl }
-  }
-\tl_const:N \c_pdffile_embed_size_tl
-  {
-    \file_size:n {\l_pdffile_embed_filename_tl}
-  }
-\tl_const:N \c_pdffile_embed_checksum_tl
-  {
-    \file_mdfive_hash:n {\l_pdffile_embed_filename_tl}
-  }
 
 \pdfdict_new:n {embeddedfile}
 \pdfdict_new:n {embeddedfile/Params}
 
 \pdfdict_put:nnn {embeddedfile/Params}
-  {ModDate} { \c_pdffile_embed_moddate_tl }
+  {ModDate}  { (\file_timestamp:n { \l_pdffile_embed_filename_tl }) }
 \pdfdict_put:nnn {embeddedfile/Params}
-  {Size} { \c_pdffile_embed_size_tl }
+  {Size}     { \file_size:n { \l_pdffile_embed_filename_tl } }
 \pdfdict_put:nnn {embeddedfile/Params}
-  {CheckSum} { \c_pdffile_embed_checksum_tl }
-
-
+  {CheckSum} { (\file_mdfive_hash:n { \l_pdffile_embed_filename_tl }) }
 %    \end{macrocode}
 % \end{variable}
 %
 % \begin{macro}{\pdffile_embed:nN}
 %    \begin{macrocode}
-\cs_new_protected:Npn \pdffile_embed:nN
+\cs_new_protected:Npn \pdffile_embed:nN #1 #2
   {
     \tl_set:Nn \l_pdffile_embed_filename_tl {#1}
     \pdf_object_now:nx {fstream}
       {
        {
-        \@@_dict_map_dict_item:n {embeddedfile}
-        % if empty params ...
-
+        \pdfdict_map:n {embeddedfile}
+        \pdfdict_if_empty:nF {embeddedfile/Params}
+         {
+          /Params
+           <<
+            \pdfdict_map:n {embeddedfile/Params}
+           >>
+         }
        }
        { #1 }
       }
+    \tl_set:Nx #2 {\pdf_object_last:}
+  }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/newpackages/new-pdfescape.sty b/newpackages/new-pdfescape.sty
new file mode 100644
index 0000000..d177c92
--- /dev/null
+++ b/newpackages/new-pdfescape.sty
@@ -0,0 +1,80 @@
+\ProvidesExplPackage {new-pdfescape} {2020-04-21} {0.1}
+  {escape command for PDF}
+%very temporarly until this is in l3 properly!!!!
+\cs_new:Npn \str_escape_pdfname:n #1
+  {
+    \exp_args:Ne \tl_to_str:n
+      {
+         \exp_after:wN \__str_escape_pdfname:n \exp_after:wN
+           { \tl_to_str:n {#1} }
+      }
+  }
+\cs_new:Npx \__str_escape_pdfname:n #1
+  {
+    \exp_not:N \__str_escape_pdfname_first:w #1 ~
+      \exp_not:N \q_recursion_tail \c_space_tl
+      \exp_not:N \q_recursion_stop
+  }
+\cs_new:Npn \__str_escape_pdfname_first:w #1 ~
+  {
+    \quark_if_recursion_tail_stop:n {#1}
+    \__str_escape_pdfname_outer:n {#1}
+  }
+\cs_new:Npn \__str_escape_pdfname_loop:w #1 ~
+  {
+    \quark_if_recursion_tail_stop:n {#1}
+    \c_hash_str 20
+    \__str_escape_pdfname_outer:n {#1}
+  }
+\cs_new:Npx \__str_escape_pdfname_outer:n #1
+  {
+    \exp_not:N \__str_escape_pdfname_inner:w #1
+      \exp_not:N \q_recursion_tail \exp_not:N \q_recursion_stop
+    \exp_not:N \__str_escape_pdfname_loop:w
+  }
+\bool_lazy_or:nnTF
+  { \sys_if_engine_luatex_p: }
+  { \sys_if_engine_xetex_p: }
+  {
+    \cs_new:Npn \__str_escape_pdfname_inner:w #1
+      {
+        \quark_if_recursion_tail_stop:n {#1}
+        \int_compare:nNnTF { `#1 } > { "7F }
+          { \__str_escape_pdfname_bytes:n {#1} }
+          { \__str_escape_name_char:N #1 }
+        \__str_escape_pdfname_inner:w
+      }
+    \cs_new:Npn \__str_escape_pdfname_bytes:n #1
+      {
+        \exp_args:Ne \__str_escape_pdfname_bytes_aux:n
+          { \char_to_utfviii_bytes:n {`#1} }
+      }
+    \cs_new:Npn \__str_escape_pdfname_bytes_aux:n #1
+      { \__str_escape_pdfname_bytes_aux:nnnn #1 }
+    \cs_new:Npx \__str_escape_pdfname_bytes_aux:nnnn #1#2#3#4
+      {
+        \c_hash_str \exp_not:N \__str_output_hexadecimal:n {#1}
+        \c_hash_str \exp_not:N \__str_output_hexadecimal:n {#2}
+        \exp_not:N \tl_if_blank:nF {#3}
+          {
+            \c_hash_str \exp_not:N \__str_output_hexadecimal:n {#3}
+            \exp_not:N \tl_if_blank:nF {#4}
+              {
+                \c_hash_str \exp_not:N \__str_output_hexadecimal:n {#4}
+              }
+          }
+      }
+  }
+  {
+    \cs_new:Npn \__str_escape_pdfname_inner:w #1
+      {
+        \quark_if_recursion_tail_stop:n {#1}
+        \__str_escape_name_char:N #1
+        \__str_escape_pdfname_inner:w
+      }
+  }
+
+ \cs_generate_variant:Nn \str_escape_pdfname:n { e }
+
+ \cs_set:Npn \pdftool_name:n #1
+    { / \str_escape_pdfname:e { \text_expand:n{#1} } }
diff --git a/pdfresources.dtx b/pdfresources.dtx
index 980757d..79d785a 100644
--- a/pdfresources.dtx
+++ b/pdfresources.dtx
@@ -883,6 +883,22 @@
 \cs_generate_variant:Nn \pdfdict_put:nnn {nnx}
 \cs_generate_variant:Nn \pdfdict_gput:nnn {nnx}
 %    \end{macrocode}
+% \begin{function}[EXP,added = 2020-04-21]
+%   {\pdfdict_map:n }
+%   \begin{syntax}
+%     \cs{pdfdict_map:n}  \Arg{dictionary}
+%   \end{syntax}
+%   This outputs the property list of the dictionary as a list of
+%   \texttt{/key value} pairs.
+%   This is suitable for simple, local dictionaries which can be written directly
+%   to the PDF.
+% \end{function}
+%    \begin{macrocode}
+\cs_new:Npn \pdfdict_map:n #1
+  {
+    \@@_dict_map:n { #1 }
+  }
+%    \end{macrocode}
 % \begin{function}[added = 2020-04-08]
 %   {\pdfdict_show:n }
 %   \begin{syntax}





More information about the latex3-commits mailing list.