From 0f16883734671b9de034bb28b54771c4e509783f Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sat, 31 Jul 2021 20:56:25 +0000
Subject: pdfmanagement-testphase (31jul21)

git-svn-id: svn://tug.org/texlive/trunk@60127 c570f23f-e606-0410-a88d-b1316a301751
---
 .../pdfmanagement-testphase.ltx                    | 120 ++++++++++++++++++---
 1 file changed, 104 insertions(+), 16 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/pdfmanagement-testphase/pdfmanagement-testphase.ltx')

diff --git a/Master/texmf-dist/tex/latex/pdfmanagement-testphase/pdfmanagement-testphase.ltx b/Master/texmf-dist/tex/latex/pdfmanagement-testphase/pdfmanagement-testphase.ltx
index 094041b27d7..ecfa1e60a1b 100644
--- a/Master/texmf-dist/tex/latex/pdfmanagement-testphase/pdfmanagement-testphase.ltx
+++ b/Master/texmf-dist/tex/latex/pdfmanagement-testphase/pdfmanagement-testphase.ltx
@@ -27,7 +27,7 @@
 %% and all files in that bundle must be distributed together.
 %% 
 %% File: pdfmanagement-testphase.dtx
-\ProvidesExplFile{pdfmanagement-testphase.ltx}{2021-07-21}{0.95g}
+\ProvidesExplFile{pdfmanagement-testphase.ltx}{2021-07-31}{0.95h}
   {PDF~management~code~(testphase)}
 %% File: l3pdfdict.dtx
 \cs_new:Npn \__pdfdict_get_type:n #1
@@ -270,6 +270,7 @@
 \cs_set_eq:NN \pdfdict_use:n \__pdfdict_use:n
 %% File: l3pdfmanagement.dtx
 
+
 \msg_new:nnn  { pdfmanagement } { unknown-dict }
               { The~PDF~management~resource~'#1'~is~unknown. }
 
@@ -282,6 +283,9 @@
 \msg_new:nnn  { pdfmanagement } { no-show }
               { It~is~not~possible~to~show~the~content~of~'#1'.}
 
+\msg_new:nnn  { pdfmanagement } { name-exist }
+              { The~name~'#1'~has~already~been~used~for~name~tree~'#2'.}
+
 \msg_new:nnn  { pdfmanagement } { show-dict }
   {
     The~PDF~resource~'#1'~
@@ -298,6 +302,10 @@
     The~PDF~resources~management~is~not~active\\
     command~'#1'~ignored.
   }
+\tl_new:N \l__pdfmanagement_tmpa_tl
+\tl_new:N \l__pdfmanagement_tmpb_tl
+\seq_new:N \l__pdfmanagement_tmpa_seq
+
 \bool_new:N \g__pdfmanagement_active_bool
 \prg_new_conditional:Npnn \__pdfmanagement_if_active:  { p , T , F , TF }
   {
@@ -308,6 +316,7 @@
 \prg_set_eq_conditional:NNn
   \pdfmanagement_if_active: \__pdfmanagement_if_active: { p , T , F , TF }
 
+\cs_set_eq:NN \IfPDFManagementActiveTF\pdfmanagement_if_active:TF
 \hook_new:n {pdfmanagement/add}
 \cs_new_protected:Npn \pdfmanagement_add:nnn #1 #2 #3
   {
@@ -332,7 +341,8 @@
       }
   }
 
-\cs_generate_variant:Nn \pdfmanagement_add:nnn {nnx,nxx}
+\cs_generate_variant:Nn \pdfmanagement_add:nnn {nnx,nxx,xxx}
+\cs_set_eq:NN \PDFManagementAdd \pdfmanagement_add:xxx
 \tl_new:N \g__kernel_pdfmanagement_thispage_shipout_code_tl
 \tl_new:N \g__kernel_pdfmanagement_lastpage_shipout_code_tl
 \tl_new:N \g__kernel_pdfmanagement_end_run_code_tl
@@ -622,6 +632,11 @@
     AcroForm/CO
   }
 
+\clist_const:Nn \c__pdfmanagement_Catalog_nametree_clist
+  {
+    AP,
+    JavaScript,
+  }
 \clist_map_inline:Nn \c__pdfmanagement_Catalog_seq_clist
  {
    \seq_new:c { g__pdfmanagement_/Catalog/#1_seq } % new name later
@@ -637,6 +652,43 @@
       { g__pdfmanagement_/Catalog/OCProperties/Configs_seq }
       {  #1  }
   }
+\cs_new_protected:Npn \__pdfmanagement_nametree_add_aux:nnn #1 #2 #3
+  %#1 name tree, #2 sanitized name #3 value
+  {
+     \prop_get:coNTF
+       { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
+       { #2 }
+       \l__pdfmanagement_tmpb_tl
+       {
+         \msg_error:nnnn{pdfmanagement}{name-exist}{#2}{#1}
+       }
+       {
+         \prop_gput:con
+           { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
+           { #2 }
+           { #3 }
+       }
+  }
+\clist_map_inline:Nn \c__pdfmanagement_Catalog_nametree_clist
+ {
+   \pdfdict_new:n { g__pdf_Core/Catalog/Names/#1}
+   \cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/#1/?_gput:nn } ##1 ##2
+     {
+       \pdf_string_from_unicode:nnN {utf8/string}{##1}\l__pdfmanagement_tmpa_tl
+       \exp_args:Nno
+         \__pdfmanagement_nametree_add_aux:nnn {#1}{\l__pdfmanagement_tmpa_tl}{##2}
+     }
+ }
+\pdfdict_new:n { g__pdf_Core/Catalog/Names/EmbeddedFiles}
+\cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/EmbeddedFiles/?_gput:nn } #1 #2
+  {
+    \pdf_string_from_unicode:nnN {utf8/string}{#1}\l__pdfmanagement_tmpa_tl
+    \exp_args:Nno
+    \__pdfmanagement_nametree_add_aux:nnn
+      {EmbeddedFiles}{\l__pdfmanagement_tmpa_tl}{#2}
+    \exp_args:No
+    \__pdf_backend_NamesEmbeddedFiles_add:nn {\l__pdfmanagement_tmpa_tl}{#2}
+  }
 \cs_new_protected:Npn \__pdfmanagement_Catalog_gpush:
   {
     \use:c { __pdfmanagement_/Catalog/AA_gpush: }
@@ -655,7 +707,11 @@
       { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog} }
       \__pdf_backend_catalog_gput:nn
     % output names tree:
-    \use:c { __pdfmanagement_/Catalog/Names/EmbeddedFiles_gpush: }
+    \use:c{ __pdfmanagement_/Catalog/Names_gpush:n } {EmbeddedFiles}
+    \clist_map_inline:Nn \c__pdfmanagement_Catalog_nametree_clist
+     {
+      \use:c{ __pdfmanagement_/Catalog/Names_gpush:n } {##1}
+     }
   }
 \cs_new_protected:cpn { __pdfmanagement_/Catalog/AA_gpush: }
   {
@@ -789,12 +845,12 @@
       { 0 }
       {
         \__pdf_backend_object_new:nn  { __pdfmanagement/Catalog/OCProperties } { dict }
-        \seq_gpop_left:cN { g__pdfmanagement_/Catalog/OCProperties/Configs_seq} \l_tmpa_tl
+        \seq_gpop_left:cN { g__pdfmanagement_/Catalog/OCProperties/Configs_seq} \l__pdfmanagement_tmpa_tl
         \exp_args:Nnx
           \__pdf_backend_object_write:nn {__pdfmanagement/Catalog/OCProperties}
             {
               /OCGs~[ \seq_use:cn { g__pdfmanagement_/Catalog/OCProperties/OCGs_seq } {~} ]
-              /D~\l_tmpa_tl~
+              /D~\l__pdfmanagement_tmpa_tl~
               \seq_if_empty:cF { g__pdfmanagement_/Catalog/OCProperties/Configs_seq }
                 {
                   /Configs~
@@ -861,22 +917,54 @@
            }
      }
   }
+\int_new:N \g__pdfmanagement_EmbeddedFiles_int
+\cs_new:Npn \__pdfmanagement_EmbeddedFiles_name:
+ {
+   (
+    l3ef
+    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {10}
+     {0}
+    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {100}
+     {0}
+    \int_compare:nNnT {\g__pdfmanagement_EmbeddedFiles_int} < {1000}
+     {0}
+    \int_use:N \g__pdfmanagement_EmbeddedFiles_int
+   )
+ }
 \pdfdict_new:n { g__pdf_Core/Catalog/Names }
 
 \cs_new_protected:cpn { __pdfmanagement_handler/Catalog/Names/EmbeddedFiles_gput:n } #1
   {
-    \__pdf_backend_NamesEmbeddedFiles_add:n { #1 }
-  }
-\cs_new_protected:cpn { __pdfmanagement_/Catalog/Names/EmbeddedFiles_gpush: }
-  {
-    \seq_if_empty:NF \g__pdf_backend_EmbeddedFiles_seq
-      {
-        \exp_args:Nx \__pdf_backend_NamesEmbeddedFiles_gpush:n
-          {
-            \seq_use:Nn \g__pdf_backend_EmbeddedFiles_seq {~}
-          }
-      }
+    \int_gincr:N \g__pdfmanagement_EmbeddedFiles_int
+    \exp_args:Nnx
+    \prop_gput:cnn
+      { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/EmbeddedFiles }}
+      { \__pdfmanagement_EmbeddedFiles_name: }
+      { #1 }
+     \exp_args:Nx
+     \__pdf_backend_NamesEmbeddedFiles_add:nn {\__pdfmanagement_EmbeddedFiles_name:} { #1 }
   }
+\cs_new_protected:cpn  { __pdfmanagement_/Catalog/Names_gpush:n } #1 %#1 name of name tree
+ {
+   \pdfdict_if_empty:nF { g__pdf_Core/Catalog/Names/#1 }
+     {
+       \seq_clear:N \l__pdfmanagement_tmpa_seq
+       \prop_map_inline:cn
+         {\__kernel_pdfdict_name:n { g__pdf_Core/Catalog/Names/#1 }}
+         { \seq_put_right:Nn \l__pdfmanagement_tmpa_seq {##1~##2}}
+       \seq_sort:Nn  \l__pdfmanagement_tmpa_seq
+         {
+           \str_compare:nNnTF {##1} > {##2}
+             { \sort_return_swapped: }
+             { \sort_return_same: }
+         }
+       \exp_args:Nnx \__pdf_backend_Names_gpush:nn
+         {#1}
+         {
+           \seq_use:Nn \l__pdfmanagement_tmpa_seq {~}
+         }
+     }
+ }
 \cs_new_protected:cpn {__pdfmanagement_handler/Catalog/?_show:}
   {
     \iow_term:x
-- 
cgit v1.2.3

