From 2fc2609488764102ce43194e9288b7bd8e25f17f Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Sun, 16 May 2021 03:00:44 +0000
Subject: CTAN sync 202105160300

---
 macros/latex/contrib/tagpdf/tagpdf-tree.dtx | 79 +++++++++++++++++------------
 1 file changed, 46 insertions(+), 33 deletions(-)

(limited to 'macros/latex/contrib/tagpdf/tagpdf-tree.dtx')

diff --git a/macros/latex/contrib/tagpdf/tagpdf-tree.dtx b/macros/latex/contrib/tagpdf/tagpdf-tree.dtx
index 35f622ca1c..dd6b7863c7 100644
--- a/macros/latex/contrib/tagpdf/tagpdf-tree.dtx
+++ b/macros/latex/contrib/tagpdf/tagpdf-tree.dtx
@@ -27,16 +27,22 @@
 %    \begin{macrocode}
 %<@@=tag>
 %<*tree>
-\ProvidesExplPackage {tagpdf-tree-code} {2021/02/23} {0.80}
+\ProvidesExplPackage {tagpdf-tree-code} {2021/05/14} {0.81}
  {part of tagpdf - code related to writing trees and dictionaries to the pdf}
 
 %this does the actual finishing:
-%Is \AfterEndDocument the best places??
+%Is \AddToHook{enddocument/end} the best places??
 \hook_gput_code:nnn{begindocument}{tagpdf}
   {
     \bool_if:NT \g_@@_active_tree_bool
       {
-        \AfterEndDocument { \tag_finish_structure: }
+        \sys_if_output_pdf:TF
+          {
+            \AddToHook{enddocument/end} { \tag_finish_structure: }
+          }
+          {
+            \AddToHook{shipout/lastpage} { \tag_finish_structure: }
+          }
       }
   }
 
@@ -48,7 +54,7 @@
 %\tl_const:Nx \c_@@_tree_obj_structtreeroot_tl { \l_tmpa_tl }
 
 %new
-\pdf_object_new:nn { c_@@_struct_0_obj }{ dict }
+\pdf_object_new:nn { @@/struct/0 }{ dict }
 
  %need to think about the best place ...
 \hook_gput_code:nnn{begindocument}{tagpdf}
@@ -58,7 +64,7 @@
         \pdfmanagement_add:nnx
           { Catalog }
           { StructTreeRoot }
-          { \pdf_object_ref:n { c_@@_struct_0_obj } }
+          { \pdf_object_ref:n { @@/struct/0 } }
       }
   }
 \cs_new_protected:Nn \@@_tree_write_structtreeroot:
@@ -82,7 +88,7 @@
 %\tl_const:Nx \c_@@_tree_obj_parenttree_tl    { \l_tmpa_tl }
 
 %new
-\pdf_object_new:nn { c_@@_tree_parenttree_obj }{ dict }
+\pdf_object_new:nn { @@/tree/parenttree }{ dict }
 
 % we have two sets of entries in the parent tree:
 % page streams and real objects.
@@ -188,39 +194,21 @@
         \@@_tree_fill_parenttree:
       }
     \tl_put_right:NV \l_@@_parenttree_content_tl\g_@@_parenttree_objr_tl
-    \pdf_object_write:nx  { c_@@_tree_parenttree_obj }
+    \pdf_object_write:nx  { @@/tree/parenttree }
       {
         /Nums\c_space_tl [\l_@@_parenttree_content_tl]
       }
   }
 
 %the Rolemap tree
-%deprecated
-%\@@_pdfreserveobjnum:N \l_tmpa_tl
-%\tl_const:Nx \c_@@_tree_obj_rolemap_tl { \l_tmpa_tl }
-
-%new
-\pdf_object_new:nn { c_@@_tree_rolemap_obj }{ dict }
 
-\tl_new:N \l_@@_rolemap_content_tl
-
-\cs_new_protected:Nn \@@_tree_fill_rolemap:
-  {
-    \prop_map_inline:Nn \g_@@_role_rolemap_prop
-      {
-        \tl_put_right:Nx \l_@@_rolemap_content_tl
-          {
-            /##1\c_space_tl/##2^^J
-          }
-      }
-  }
+\pdf_object_new:nn { @@/tree/rolemap }{ dict }
 
 \cs_new_protected:Nn \@@_tree_write_rolemap:
   {
-    \@@_tree_fill_rolemap:
-    \pdf_object_write:nx  { c_@@_tree_rolemap_obj }
+    \pdf_object_write:nx  { @@/tree/rolemap }
       {
-        \l_@@_rolemap_content_tl
+        \pdfdict_use:n{g_@@_role/RoleMap_dict}
       }
   }
 
@@ -248,16 +236,42 @@
     \tl_if_empty:NF
       \g_@@_attr_class_content_tl
       {
-        \pdf_object_new:nn { c_@@_tree_classmap_obj }{ dict }
+        \pdf_object_new:nn { @@/tree/classmap }{ dict }
      %   \@@_pdfreserveobjnum:N \l_tmpa_tl
      %   \tl_const:Nx \c_@@_tree_obj_classmap_tl { \l_tmpa_tl }
         \pdf_object_write:nx
-          { c_@@_tree_classmap_obj }
+          { @@/tree/classmap }
           { \g_@@_attr_class_content_tl }
         \@@_prop_gput:cnx
           { g_@@_struct_0_prop }
           { ClassMap }
-          { \pdf_object_ref:n { c_@@_tree_classmap_obj }  }
+          { \pdf_object_ref:n { @@/tree/classmap }  }
+      }
+  }
+
+% namespaces are only relevant for pdf2.0 but we don't care
+\pdf_object_new:nn{ @@/tree/namespaces }{array}
+\cs_new_protected:Npn \@@_tree_write_namespaces:
+  {
+    \prop_map_inline:Nn \g_@@_role_NS_prop
+      {
+        \pdfdict_if_empty:nF {g_@@_role/RoleMapNS_##1_dict}
+          {
+            \pdf_object_write:nx {@@/RoleMapNS/##1}
+              {
+                \pdfdict_use:n {g_@@_role/RoleMapNS_##1_dict}
+              }
+            \pdfdict_gput:nnx{g_@@_role/Namespace_##1_dict}
+              {RoleMapNS}{\pdf_object_ref:n {@@/RoleMapNS/##1}}
+          }
+        \pdf_object_write:nx{tag/NS/##1}
+          {
+             \pdfdict_use:n {g_@@_role/Namespace_##1_dict}
+          }
+      }
+    \pdf_object_write:nx {@@/tree/namespaces}
+      {
+        \prop_map_tokens:Nn \g_@@_role_NS_prop{\use_ii:nn}
       }
   }
 
@@ -267,12 +281,11 @@
     \@@_tree_write_parenttree:
     \@@_tree_write_rolemap:
     \@@_tree_write_classmap:
+    \@@_tree_write_namespaces:
     \@@_tree_write_structelements: %this is rather slow!!
     \@@_tree_write_structtreeroot:
   }
 
-%deprecated
-\cs_set_eq:NN \uftag_finish_structure: \tag_finish_structure:
 
 %StructParents !!! we need a better hook for \g__pdf_BACKEND_thispage_shipout_tl!!
 % No actually
-- 
cgit v1.2.3

