diff options
Diffstat (limited to 'macros/latex/contrib/tagpdf/tagpdf-tree.dtx')
-rw-r--r-- | macros/latex/contrib/tagpdf/tagpdf-tree.dtx | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/macros/latex/contrib/tagpdf/tagpdf-tree.dtx b/macros/latex/contrib/tagpdf/tagpdf-tree.dtx index f8c7aa27d7..2a02a7c5df 100644 --- a/macros/latex/contrib/tagpdf/tagpdf-tree.dtx +++ b/macros/latex/contrib/tagpdf/tagpdf-tree.dtx @@ -47,13 +47,13 @@ % }^^A % } % -% \date{Version 0.98a, released 2022-12-22} +% \date{Version 0.98b, released 2023-01-24} % \maketitle % \begin{implementation} % \begin{macrocode} %<@@=tag> %<*header> -\ProvidesExplPackage {tagpdf-tree-code} {2022-12-22} {0.98a} +\ProvidesExplPackage {tagpdf-tree-code} {2023-01-24} {0.98b} {part of tagpdf - code related to writing trees and dictionaries to the pdf} %</header> % \end{macrocode} @@ -119,6 +119,73 @@ } % \end{macrocode} % +% \subsection{Writing the IDtree} +% +% The ID are currently quite simple: every structure has an ID build from +% the prefix ID together with the structure number padded with enough zeros to +% that we get directly an lexical order. We ship them out in bundles +% At first a seq to hold the references for the kids +% \begin{variable}{\g_@@_tree_id_pad_int} +% \begin{macrocode} +\int_new:N\g_@@_tree_id_pad_int +% \end{macrocode} +% \end{variable} +% Now we get the needed padding +% \begin{macrocode} +\cs_generate_variant:Nn \tl_count:n {e} +\hook_gput_code:nnn{begindocument}{tagpdf} + { + \int_gset:Nn\g_@@_tree_id_pad_int + {\tl_count:e { \@@_ref_value_lastpage:nn{tagstruct}{1000}}+1} + } + +% \end{macrocode} +% This is the main code to write the tree it basically splits the +% existing structure numbers in chunks of length 50 +% TODO consider is 50 is a good length. +% \begin{macrocode} +\cs_new_protected:Npn \@@_tree_write_idtree: + { + \tl_clear:N \l_@@_tmpa_tl + \tl_clear:N \l_@@_tmpb_tl + \int_zero:N \l_@@_tmpa_int + \int_step_inline:nn {\c@g_@@_struct_abs_int} + { + \int_incr:N\l_@@_tmpa_int + \tl_put_right:Nx \l_@@_tmpa_tl + { + \@@_struct_get_id:n{##1}~\pdf_object_ref:n{@@/struct/##1}~ + } + \int_compare:nNnF {\l_@@_tmpa_int}<{50} % + { + \pdf_object_unnamed_write:nx {dict} + { /Limits~[\@@_struct_get_id:n{##1-\l_@@_tmpa_int+1}~\@@_struct_get_id:n{##1}] + /Names~[\l_@@_tmpa_tl] + } + \tl_put_right:Nx\l_@@_tmpb_tl {\pdf_object_ref_last:\c_space_tl} + \int_zero:N \l_@@_tmpa_int + \tl_clear:N \l_@@_tmpa_tl + } + } + \tl_if_empty:NF \l_@@_tmpa_tl + { + \pdf_object_unnamed_write:nx {dict} + { + /Limits~ + [\@@_struct_get_id:n{\c@g_@@_struct_abs_int-\l_@@_tmpa_int+1}~ + \@@_struct_get_id:n{\c@g_@@_struct_abs_int}] + /Names~[\l_@@_tmpa_tl] + } + \tl_put_right:Nx\l_@@_tmpb_tl {\pdf_object_ref_last:} + } + \pdf_object_unnamed_write:nx {dict}{/Kids~[\l_@@_tmpb_tl]} + \@@_prop_gput:cnx + { g_@@_struct_0_prop } + { IDTree } + { \pdf_object_ref_last: } + } +% \end{macrocode} +% % \subsection{Writing structure elements} % The following commands are needed to write out the structure. % \begin{macro}{\@@_tree_write_structtreeroot:} @@ -135,8 +202,15 @@ \@@_prop_gput:cnx { g_@@_struct_0_prop } { RoleMap } - { \pdf_object_ref:n { @@/tree/rolemap } } - \@@_struct_write_obj:n { 0 } + { \pdf_object_ref:n { @@/tree/rolemap } } + \@@_struct_fill_kid_key:n { 0 } + \@@_struct_get_dict_content:nN { 0 } \l_@@_tmpa_tl + \pdf_object_write:nnx + { @@/struct/0 } + {dict} + { + \l_@@_tmpa_tl + } } } % \end{macrocode} @@ -149,7 +223,14 @@ { g_@@_struct_0_prop } { ParentTree } { \pdf_object_ref:n { @@/tree/parenttree } } - \@@_struct_write_obj:n { 0 } + \@@_struct_fill_kid_key:n { 0 } + \@@_struct_get_dict_content:nN { 0 } \l_@@_tmpa_tl + \pdf_object_write:nnx + { @@/struct/0 } + {dict} + { + \l_@@_tmpa_tl + } } } % \end{macrocode} @@ -459,6 +540,7 @@ \hook_use:n {tagpdf/finish/before} \@@_tree_final_checks: \@@_tree_write_parenttree: + \@@_tree_write_idtree: \@@_tree_write_rolemap: \@@_tree_write_classmap: \@@_tree_write_namespaces: |