[latex3-commits] [git/LaTeX3-latex3-pdfresources] test-new-hooks: extending new-attachfile (b5f0d82)

Ulrike Fischer fischer at troubleshooting-tex.de
Mon May 4 00:06:32 CEST 2020


Repository : https://github.com/latex3/pdfresources
On branch  : test-new-hooks
Link       : https://github.com/latex3/pdfresources/commit/b5f0d828a05ed7fd6090b52d42f3157fdc13146b

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

commit b5f0d828a05ed7fd6090b52d42f3157fdc13146b
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Mon May 4 00:06:32 2020 +0200

    extending new-attachfile


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

b5f0d828a05ed7fd6090b52d42f3157fdc13146b
 experiments/new-attachfile.tex |  10 ++-
 newpackages/new-attachfile.sty | 178 +++++++++++++++++++++++------------------
 2 files changed, 107 insertions(+), 81 deletions(-)

diff --git a/experiments/new-attachfile.tex b/experiments/new-attachfile.tex
index 12a2890..9cb98d5 100644
--- a/experiments/new-attachfile.tex
+++ b/experiments/new-attachfile.tex
@@ -1,4 +1,5 @@
 % !Mode:: "TeX:UTF-8:Main"
+\RequirePackage{pdfresources}
 \documentclass{article}
 \usepackage{xcolor}
 \usepackage[customdriver=hgeneric-experimental]{hyperref}
@@ -11,11 +12,12 @@
 \begin{document}
 abc
 \makeatletter
-\attachfilesetup{color=red,author=Müsterhaße}
+\attachfilesetup{color=red,author=Müsterhaße,new-afrelationship=blub}
 \ExplSyntaxOn
-\tl_show:N \l__atfi_annot_color_tl
-\tl_show:N \l__atfi_setup_keyval_tl
-\keys_set:no {atfi} { \l__atfi_setup_keyval_tl }
+%\tl_show:N \l__atfi_annot_color_tl
+%\tl_show:N \l__atfi_setup_keyval_tl
+\keys_set:no {atfi} { \l__atfi_setup_keys_tl,afrelationship=blubx }
+\end{document}
 \pdfdict_show:n{annot/FileAttachment}
 \tl_show:N \l__atfi_annot_color_tl
 
diff --git a/newpackages/new-attachfile.sty b/newpackages/new-attachfile.sty
index 08fc344..3d5fad6 100644
--- a/newpackages/new-attachfile.sty
+++ b/newpackages/new-attachfile.sty
@@ -110,6 +110,13 @@
 
 \tl_new:N   \l__atfi_annot_icon_tl
 \tl_new:N   \l__atfi_annot_color_tl
+\clist_new:N   \g__atfi_file_afrelationship_clist
+\clist_gset:Nn \g__atfi_file_afrelationship_clist
+  {
+    Source, Data, Alternative, Supplement,
+    EncryptedPayload, FormData, Schema,
+    Unspecified (default)
+  }
 \fp_new:N   \l__atfi_annot_scale_fp
 \bool_new:N \l__atfi_annot_print_bool
 \bool_new:N \l__atfi_annot_appearance_bool
@@ -153,10 +160,42 @@
         \tl_if_empty:nF { #1 }
           {
            \pdftool_textstringhex_print:nN  { #1 } \l__atfi_filename_tl %variable
-           \pdfdict_put:nnx { file/FileSpec } {F} { \l__atfi_filename_tl }
+           \pdfdict_put:nnx { file/FileSpec } {F}  { \l__atfi_filename_tl }
+           \pdfdict_put:nnx { file/FileSpec } {UF} { \l__atfi_filename_tl }
           }
       }
     ,filename .groups:n = {embed}
+    ,afrelationship .choices:nn =
+      {Source, Data, Alternative, Supplement, EncryptedPayload, FormData, Schema, Unspecified }
+      {
+        \pdfdict_put:nnx { file/FileSpec } {AFRelationship }  { \pdftool_name:n {#1} }
+      }
+    ,afrelationship .default:n = { Unspecified }
+    ,afrelationship / .code:n =
+      {
+        \pdfdict_remove:nn { file/FileSpec } {AFRelationship }
+      }
+    ,afrelationship  / unknown .code:n =
+      {
+        \msg_warning:nnxxx { atfi } { unknown-choice }
+         { afrelationship }
+         { \g__atfi_file_afrelationship_clist }
+         { \exp_not:n {#1} }
+      }
+    ,new-afrelationship .code:n =
+      {
+        \clist_gput_right:Nn \g__atfi_file_afrelationship_clist { #1~(user~defined) }
+        \keys_define:nn { atfi }
+          {
+            afrelationship / #1 .code:n =
+              {
+                \pdfdict_put:nnx
+                  { file/FileSpec }
+                  {AFRelationship }
+                  { \pdftool_name:n {#1} }
+              }
+          }
+      }
     %ucfilespec -> embed step
     %checksum   -> bool to suppress the checksum
     %creationdate ->additional /CreationDate in FileSpec-dict
@@ -324,8 +363,8 @@
     \group_end:
   }
 \ExplSyntaxOff
-\atfi at DisableOption{draft}%
-\atfi at DisableOption{final}%
+%\atfi at DisableOption{draft}%
+%\atfi at DisableOption{final}%
 \ifatfi at draft
   \def\atfi at dummy@pushpin{%
     \raisebox{-1.25bp}{\parbox[b][14bp]{24bp}{}}%
@@ -344,7 +383,7 @@
 
 \ExplSyntaxOn
 % embed the file and create the filespec dictionary:
-\cs_new_protected:Npn \__atfi_file_embed:nn #1 #2 % #1 keys, #2 symbolic name, #3 file name
+\cs_new_protected:Npn \__atfi_file_embed:nnn #1 #2 #3 % #1 keys, #2 symbolic name, #3 file name
   {
     \pdfobject_if_exist:nTF { g__atfi_file_obj_#2 }
       {
@@ -362,7 +401,7 @@
   }
 
 % create the appearance xform:
-\cs_new_protected:Npn \__atfi_annot_xform_appearance:n
+\cs_new_protected:Npn \__atfi_annot_xform_appearance:n #1
   {
     \pdf_xform_if_exist:nF { g__atfi_annot_iconxform_#1 }
       {
@@ -374,72 +413,66 @@
   }
 
 
-\def\atfi at insert@file at annot#1{%
-  \rule{0pt}{0pt}%
-  \ifatfi at appearance
-    \edef\atfi at appearance@dict{%
-      /AP<<%
-        /N~ \pdf_xform_ref:n { atfi at appearancebox }%
-        /R~ \pdf_xform_ref:n { atfi at appearancebox }%
-        /D~ \pdf_xform_ref:n { atfi at appearancebox }%
-      >>%
-    }%
-  \else
-    \let\atfi at appearance@dict\ltx at empty
-  \fi
-%  \ltx at IfUndefined{atfi at fsobj@#1}{%
-%    \begingroup
-%      \hypersetup{unicode=false}%
-%      \atfi at pdfstringdef\atfi at file{#1}%
-%      \pdf_object_now:nx{dict}{%
-%          /Type/Filespec%
-%          /F(\atfi at file)%
-%          \ifx\atfi at ucfilespec\ltx at empty
-%          \else
-%            /UF(\atfi at ucfilespec)%
-%          \fi
-%          /EF<<%
-%            /F~ \@nameuse{atfi at fileobj@#1}%
-%          >>%
-%      }%
-%      \expandafter\xdef\csname atfi at fsobj@#1\endcsname{%
-%        \pdf_object_last:
-%      }%
-%    \endgroup
-%  }{%
-%  }%
-  \pdfannot_box:nnnn
-     {\atfi at scale\atfi at appearancewidth}
-     {\atfi at scale\atfi at appearanceheight}
-     {\atfi at scale\atfi at appearancedepth}
-     {
-      \pdfdict_map:n {annot/FileAttachment}
-     % /Subtype/FileAttachment%
-%      \atfi at icon
-%      \atfi at color@annot
-%      \atfi at author
-%      \atfi at date
-%      \atfi at annotname
-%      \atfi at description
-%      \atfi at subject
-%      \atfi at appearance@dict
-      /F~ \bitsetGetDec {__atfi_annotFlags}
-      /FS~ \pdf_object_ref:n{atfi at fileobj@#1}%
+\cs_new_protected:Npn \__atfi_annot:n #1 {}%#1 symbolic object name from
+\def\atfi at insert@file at annot#1
+  {
+    \rule{0pt}{0pt}%
+    \pdfdict_put:nnx
+          { annot/FileAttachment }
+          {FS}
+          {\pdf_object_ref:n{g__atfi_file_obj_#1}}
+    \bool_if:NT \l__atfi_annot_appearance_bool
+      {
+        \pdfdict_put:nnx
+          { annot/FileAttachment/AP }
+          { N }
+          { \pdf_xform_ref:n { g__atfi_annot_iconxform_\l__atfi_annot_icon_tl } }
+        \pdfdict_put:nnx
+          { annot/FileAttachment/AP }
+          { R }
+          { \pdf_xform_ref:n { g__atfi_annot_iconxform_\l__atfi_annot_icon_tl } }
+        \pdfdict_put:nnx
+          { annot/FileAttachment/AP }
+          { D }
+          { \pdf_xform_ref:n { g__atfi_annot_iconxform_\l__atfi_annot_icon_tl } }
+       }
+     \pdfannot_box:nnnn
+        {
+          \fp_to_dim:n
+            {
+              \l__atfi_annot_scale_fp *
+              \pdf_xform_wd:n{g__atfi_annot_iconxform_\l__atfi_annot_icon_tl}
+            }
+        }
+        {
+          \fp_to_dim:n
+            {
+              \l__atfi_annot_scale_fp *
+              \pdf_xform_ht:n{g__atfi_annot_iconxform_\l__atfi_annot_icon_tl}
+            }
+        }
+        {
+          \fp_to_dim:n
+            {
+              \l__atfi_annot_scale_fp *
+              \pdf_xform_dp:n{g__atfi_annot_iconxform_\l__atfi_annot_icon_tl}
+            }
+        }
+        {
+          \pdfdict_map:n {annot/FileAttachment}
+          \bool_if:NT \l__atfi_annot_appearance_bool
+            {
+              /AF
+                <<
+                  \pdfdict_map:n {annot/FileAttachment/AF}
+                >>
+            }
+
+         /FS~ \pdf_object_ref:n{atfi at fileobj@#1}%
      }%
-  %\rule{0pt}{\atfi at appearanceheight}%
-%  \rule[-\atfi at appearancedepth]{0pt}{\atfi at appearancedepth}%
-%  \rule{\atfi at appearancewidth}{0pt}%
-}
+  }
 \ExplSyntaxOff
 
-%\def\attachfile at timezone#1{%
-%  \ifx\\#1\\%
-%    % no timezone information given
-%  \else
-%    \def\atfi at timezone{#1}%
-%  \fi
-%}
-
 \newcommand*{\attachfile at file}[2][]{%
   \EdefUnescapeHex\atfi at filename{#2}%
   \ifx\atfi at filename\ltx at empty
@@ -463,15 +496,6 @@
 
 \ExplSyntaxOn
 
-
-\def\atfi at set@appearance#1{%
-  \savebox{\atfi at appearancebox}{#1}%
-  \atfi at appearancewidth=\wd\atfi at appearancebox
-  \atfi at appearanceheight=\ht\atfi at appearancebox
-  \atfi at appearancedepth=\dp\atfi at appearancebox
-  \atfi at xform
-}
-
 \def\atfi at textattachfile#1#2{%
     \endgroup
     \atfi at textattachfile@i{#1}{#2}%





More information about the latex3-commits mailing list.