[latex3-commits] [git/LaTeX3-latex3-pdfresources] renamedict77: converting/escaping of strings (c28a668)

Ulrike Fischer fischer at troubleshooting-tex.de
Thu Apr 30 20:00:56 CEST 2020


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

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

commit c28a6687dd6f3ec638a136103e919efb2ac1c8fd
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Thu Apr 30 20:00:56 2020 +0200

    converting/escaping of  strings


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

c28a6687dd6f3ec638a136103e919efb2ac1c8fd
 experiments/embedfiles.tex     |  11 +++--
 experiments/new-attachfile.tex |   8 ++-
 hgeneric-experimental.def      |   1 +
 l3pdffile.dtx                  |   7 +--
 newpackages/new-attachfile.sty | 108 +++++++++++++++++++++++++++++++++++------
 newpackages/new-pdfescape.sty  |  43 ++++++++++++++--
 6 files changed, 152 insertions(+), 26 deletions(-)

diff --git a/experiments/embedfiles.tex b/experiments/embedfiles.tex
index 4422dfa..8e3f971 100644
--- a/experiments/embedfiles.tex
+++ b/experiments/embedfiles.tex
@@ -1,8 +1,11 @@
 % !Mode:: "TeX:UTF-8:Main"
+\RequirePackage{pdfresources}
+\DeclareDocumentMetaData{pdfversion=1.6}
 \documentclass{article}
 \usepackage{pdfresources}
 \usepackage{l3pdffile}
 \usepackage[customdriver=hgeneric-experimental]{hyperref}
+\hypersetup{pdfversion=1.6,pdfpagemode=UseAttachments}
 \ExplSyntaxOn
 \pdf_uncompress:
 \ExplSyntaxOff
@@ -10,12 +13,14 @@
 \begin{document}
 \section{grüße Testing embedding and attaching files}
 \ExplSyntaxOn
+\pdftool_textlitstring_print:nN {xxxgrüße}\l_tmpa_str
+\pdfextension outline goto name {Doc-Start}{\l_tmpa_str}
 \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}
+%\pdfdict_show:n   {file/FileSpec}
+%\pdffile_embed:nn {example}{grüße.txt}
+%\pdffile_attach:n {example}
 \group_end:
 
 \group_begin:
diff --git a/experiments/new-attachfile.tex b/experiments/new-attachfile.tex
index fc26790..ff9aa23 100644
--- a/experiments/new-attachfile.tex
+++ b/experiments/new-attachfile.tex
@@ -11,12 +11,18 @@
 \begin{document}
 abc
 \makeatletter
+\attachfile[icon=Graph,mimetype=text/plain]{catalogue.tex} some text
 \atfi at acroPaperclip
 \atfi at acroTag
 \atfi at acroGraph
 \atfi at acroPushPin
-\end{document}
+
 \ExplSyntaxOn
+\keys_set:nn {atfi}{mimetype=text/mix}
+\pdfdict_show:n{file}
+\pdfdict_show:n{file/FileSpec}
+\ExplSyntaxOff
+\end{document}
 \__pdf_backend_xform_if_exist:nTF { atfi at appearancebox }{true}{false}
 \par
 
diff --git a/hgeneric-experimental.def b/hgeneric-experimental.def
index d633a6a..d779a8d 100644
--- a/hgeneric-experimental.def
+++ b/hgeneric-experimental.def
@@ -412,6 +412,7 @@
   }
 
 %replace Hy at pstringdef definition.
+%!!!!!!!! check if utf16 (string or hex) isn't better, see new-pdfescape!!!!!!!!!
 \cs_new:Npn \__hyp_pstringdef:Nn #1 #2
   {
     \group_begin:
diff --git a/l3pdffile.dtx b/l3pdffile.dtx
index c49d79f..5162371 100644
--- a/l3pdffile.dtx
+++ b/l3pdffile.dtx
@@ -215,6 +215,7 @@
 \ProvidesExplPackage {l3pdffile} {2020-04-21} {0.1}
   {embedding and referencing files in PDF}
 \RequirePackage{new-pdfescape}  %temporarly!!
+\cs_set_eq:NN \@@_file_filename_convert:nN \pdftool_textstringhex_print:nN
 %    \end{macrocode}
 %
 %    \begin{macrocode}
@@ -324,9 +325,9 @@
     \pdfdict_put:nnn { file/FileSpec }
       {Type} { /FileSpec }
     \pdfdict_put:nnn { file/FileSpec }
-      {F} { (\l_pdffile_full_name_convert_str) }
+      {F}  { \l_pdffile_full_name_convert_str }
     \pdfdict_put:nnn { file/FileSpec }
-      {UF} { (\l_pdffile_full_name_convert_str) }
+      {UF} { \l_pdffile_full_name_convert_str }
     \pdfdict_put:nnn { file/FileSpec }
       {AFRelationship} { /Unspecified }
   }
@@ -381,7 +382,7 @@
       \tl_clear:N \l_@@_file_subtype_tl
       \tl_set:Nx  \l_@@_file_object_last_tl {\pdf_object_last:}
       \pdf_object_new:nn   { #1 } {dict}
-      \pdftool_str_convert:nN  { #2 } \l_pdffile_full_name_convert_str
+      \@@_file_filename_convert:nN  { #2 } \l_pdffile_full_name_convert_str
       \pdf_object_write:nx { #1 }
         {
           \pdfdict_map:n {file/FileSpec}
diff --git a/newpackages/new-attachfile.sty b/newpackages/new-attachfile.sty
index 0ddac65..a2372f8 100644
--- a/newpackages/new-attachfile.sty
+++ b/newpackages/new-attachfile.sty
@@ -40,38 +40,104 @@
 \RequirePackage{l3color,l3draw,l3pdffile,bitset,xparse}
 
 
-%pattern matching removed. Perhaps later with regex ...
-
+% pattern matching removed. Perhaps later with regex ...
 
+% setup commands / options
+%document options, handle later
 \SetupKeyvalOptions{%
   family=AtFi,%
   prefix=atfi@%
 }
+\DeclareBoolOption{draft}
+\DeclareComplementaryOption{final}{draft}
+
+% keyval setup is stored in a list. It should be executed locally to be
+% able to change the dictionaries in a group
 
 \ExplSyntaxOn
+\cs_new:Npn \__atfi_clist_display:n #1 {*~#1\\}
+
+\tl_new:N \l__atfi_setup_keyval_tl
+\tl_new:N \l__atfi_annot_icon_tl
+\tl_new:N \l__atfi_filename_tl
+\msg_new:nnn
+  { atfi }
+  { unknown-choice }
+  {
+    Value~'#3'~is~invalid~for~key~'#1'.\\
+    The~key~accepts~only~the~choices\\
+    \clist_map_function:nN { #2 }\__atfi_clist_display:n
+    An~empty~value~removes~the~setting.
+  }
+
+
+\NewDocumentCommand\attachfilesetup { m }
+ {
+   \tl_put_right:Nn \l__atfi_setup_keyval_tl {, #1 }
+ }
+
+% replace later
 \cs_new_protected:Npn \atfi at setup #1
   {
-    \keys_set:nn {AtFi} { #1 }
+    \keys_set:nn {atfi} { #1 }
   }
-\ExplSyntaxOff
-\DeclareBoolOption{draft}
-\DeclareComplementaryOption{final}{draft}
 
-\ExplSyntaxOn
+% probably generic ....
+\pdfdict_new:n   {annot/FileAttachment}
+\pdfdict_put:nnn {annot/FileAttachment}{Subtype}{/FileAttachment}
+\pdfdict_new:n {annot/FileAttachment/AP} % appearance
+
 \keys_define:nn { atfi }
   {
-    %mimetype   -> embed step
-    ,mimetype  .tl_set:N = \l__atfi_mimetype_tl %escape with \pdftool_name:V later or now?
-
+    ,mimetype  .code:n   =
+      {
+        \tl_if_empty:nTF { #1 }
+          {
+            \pdfdict_remove:nn {file}{Subtype}
+          }
+          {
+            \pdfdict_put:nnx   {file}{Subtype}{\pdftool_name:n{#1} }
+          }
+      }
+    ,mimetype  .groups:n = { embed }
+    ,filename .code:n =
+      {
+        \tl_if_empty:nF { #1 }
+          {
+           \pdftool_str_convert:nN  { #1 } \l__atfi_filename_tl
            
+          }
+      }
     %ucfilespec -> embed step
     %checksum   -> bool to suppress the checksum
     %creationdate ->additional /CreationDate in FileSpec-dict
     %moddate    -> boolean to suppress /ModDate in FileSpec
-
-    %icon     -> attach step / setup
-    %         choice? PushPin, Data, Graph,
-    %         initial: PushPin
+   ,moddate  .code:n   =
+      {
+        \tl_if_empty:nTF { #1 }
+          {
+            \pdfdict_remove:nn {file/FileSpec}{ModDate}
+          }
+          {
+            \pdfdict_put:nnx   {file}{ModDate}{\pdftool_litstring:n{#1} }
+          }
+      }
+    ,moddate  .groups:n  = { embed }
+    ,icon     .choices:nn =
+      { Data, Graph, PushPin, Tag } =
+      {
+        \tl_set:Nn \l__atfi_annot_icon_tl { #1 }
+        \pdfdict_put:nnn { annot/FileAttachment }{ Name }{ #1 }
+      }
+    ,icon / unknown .code:n =
+      {
+        \msg_warning:nnxxx { atfi } { unknown-choice }
+          { icon }
+          { Data, Graph, PushPin, Tag }
+          { \exp_not:n {#1} }
+      }
+    ,icon     .groups:n =  { attach }
+    %         initial: PushPin, but should be set only in the command
 
     %color    -> attach step, affects icon
     %         decide allowed syntax of expressions ...
@@ -84,12 +150,22 @@
     %annotname /NM (..) (unique name)
     %          no initial value
 
-    % author  /T (...)
+    ,author    .code:n    =
+      {
+        %!! code to sanitize the value
+        \pdfdict_put:nnn {annot/FileAttachment}{T}{#1}
+      }
+    ,author     .groups:n =  { attach }
     %          no initial value
 
     % description /Contents
 
-    % subject    /Subj
+    ,subject    .code:n    =
+      {
+        %!! code to sanitize the value
+        \pdfdict_put:nnn {annot/FileAttachment}{Subj}{#1}
+      }
+    ,subject     .groups:n =  { attach }
 
     % appearance: decides if the appearance dict is insert. drop?
 
diff --git a/newpackages/new-pdfescape.sty b/newpackages/new-pdfescape.sty
index 3d5114e..1af11a8 100644
--- a/newpackages/new-pdfescape.sty
+++ b/newpackages/new-pdfescape.sty
@@ -2,11 +2,12 @@
   {temporary escape commands and tools for PDF}
 %very temporarly until this is in l3 properly!!!!
 
-
+%% test if object exist, doesn't belong here ...
 \prg_new_eq_conditional:NNn \pdfobject_if_exist:n\__pdf_backend_object_if_exist:n
   { TF , T , F , p }
 
 
+%% escape a pdfname expandably:
 \cs_new:Npn \str_escape_pdfname:n #1
   {
     \exp_args:Ne \tl_to_str:n
@@ -82,21 +83,57 @@
 
  \cs_generate_variant:Nn \str_escape_pdfname:n { e }
 
+%% tool command escape name
  \cs_new:Npn \pdftool_name:n #1
     { / \str_escape_pdfname:e { \text_expand:n{#1} } }
 
 \cs_generate_variant:Nn \pdftool_name:n {V}
 
+%% string conversions and printing
+%% we assume here that the text purify step has been done. The input is
+%% a list of (utf8) chars.
+%% str convert, not expandable. 
+% filespec (attachment view)  tests:
+% utf8:  gr\303\274\303\237e.txt                    %doesn't work, umlaut wrong,
+% utf8 with BOM \357\273\277gr\303\274\303\237e.txt %doesn't work, umlaut wrong, bom visible
+% utf16 with BE: (FEFF)  \376\377\000g\000r\000\374\000\337\000e\000.\000t\000x\000t %works
+%                xetex converts to <feff0067007200fc00df0065002e007400780074>
+% utf16 with BE / HEX: <FEFF0067007200FC00DF0065002E007400780074> works
+
+% bookmarks: as pdfoutline uses () currently only utf16 with BE is usable.
+% check if one can use HEX too when directly writing the object
 \sys_if_engine_pdftex:TF
   {
-    \cs_new:Npn \pdftool_str_convert:nN #1 #2
+    \cs_new:Npn \pdftool_textlitstring_print:nN #1 #2
       {
          \str_set_convert:Nnnn #2 { #1 }{ utf8 } {utf16/string}
+         \str_put_left:N #2  {(}
+         \str_put_right:N #2 {)}
+      }
+  }
+  {
+    \cs_new:Npn \pdftool_textlitstring_print:nN #1 #2
+      {
+        \str_set_convert:Nnnn #2 { #1 }{  } {utf16/string}
+        \str_put_left:N #2  {(}
+        \str_put_right:N #2 {)}
+      }
+  }
+
+\sys_if_engine_pdftex:TF
+  {
+    \cs_new:Npn \pdftool_textstringhex_print:nN #1 #2
+      {
+         \str_set_convert:Nnnn #2 { #1 }{ utf8 } {utf16/hex}
+         \str_put_left:N #2  {<}
+         \str_put_right:N #2 {>}
       }
   }
   {
-    \cs_new:Npn \pdftool_str_convert:nN #1 #2
+    \cs_new:Npn \pdftool_textstringhex_print:nN #1 #2
       {
         \str_set_convert:Nnnn #2 { #1 }{  } {utf16/string}
+         \str_put_left:N #2  {<}
+         \str_put_right:N #2 {>}
       }
   }





More information about the latex3-commits mailing list.