Skip to content

Commit

Permalink
switch to indexed structure object, WIP, still broken: lua, structure…
Browse files Browse the repository at this point in the history
… destinations
  • Loading branch information
u-fischer committed Mar 31, 2024
1 parent 9b23f70 commit 342c061
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 71 deletions.
88 changes: 43 additions & 45 deletions tagpdf-struct.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
%
% \begin{macrocode}
%<base>\newcounter { g_@@_struct_abs_int }
%<base>\int_gzero:N \c@g_@@_struct_abs_int
%<base>\int_gset:Nn \c@g_@@_struct_abs_int { 1 }
% \end{macrocode}
% \end{variable}
%
Expand Down Expand Up @@ -334,7 +334,7 @@
% When a sequence is opened it's number is put on the stack.
% \begin{macrocode}
\seq_new:N \g_@@_struct_stack_seq
\seq_gpush:Nn \g_@@_struct_stack_seq {0}
\seq_gpush:Nn \g_@@_struct_stack_seq {1}
% \end{macrocode}
% \end{variable}
%
Expand Down Expand Up @@ -365,8 +365,8 @@
% normally it should have only one kid, e.g. the document element.

% The data of the StructTreeRoot and the StructElem are in properties:
% |\g_@@_struct_0_prop| for the root and
% |\g_@@_struct_N_prop|, $N \geq =1$ for the other.
% |\g_@@_struct_1_prop| for the root and
% |\g_@@_struct_N_prop|, $N \geq =2$ for the other.
%
% This creates quite a number of properties, so perhaps we will have to
% do this more efficiently in the future.
Expand Down Expand Up @@ -530,15 +530,15 @@

% \subsection{Initialization of the StructTreeRoot}
% The first structure element, the StructTreeRoot is special, so
% created manually. The underlying object is |@@/struct/0| which is currently
% created manually. The underlying object is |@@/struct/1| which is currently
% created in the tree code (TODO move it here).
% The |ParentTree| and |RoleMap| entries are added at begin document
% in the tree code as they refer to object which are setup in other parts of the
% code. This avoid timing issues.
%
% \begin{macrocode}
%<*package>
\tl_gset:Nn \g_@@_struct_stack_current_tl {0}
\tl_gset:Nn \g_@@_struct_stack_current_tl {1}
% \end{macrocode}
% \begin{macro}{\@@_pdf_name_e:n}
% \begin{macrocode}
Expand All @@ -547,30 +547,30 @@
% \end{macrocode}
% \end{macro}
%
% \begin{variable}{g_@@_struct_0_prop,g_@@_struct_kids_0_seq}
% \begin{variable}{g_@@_struct_1_prop,g_@@_struct_kids_1_seq}
% \begin{macrocode}
%<*package>
\@@_prop_new:c { g_@@_struct_0_prop }
\@@_new_output_prop_handler:n {0}
\@@_seq_new:c { g_@@_struct_kids_0_seq }
\@@_prop_new:c { g_@@_struct_1_prop }
\@@_new_output_prop_handler:n {1}
\@@_seq_new:c { g_@@_struct_kids_1_seq }

\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ Type }
{ \pdf_name_from_unicode_e:n {StructTreeRoot} }

\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ S }
{ \pdf_name_from_unicode_e:n {StructTreeRoot} }

\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ rolemap }
{ {StructTreeRoot}{pdf} }

\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ parentrole }
{ {StructTreeRoot}{pdf} }

Expand All @@ -581,18 +581,18 @@
\pdf_version_compare:NnF < {2.0}
{
\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ Namespaces }
{ \pdf_object_ref:n { @@/tree/namespaces } }
}
%</package>
% \end{macrocode}
% In debug mode we have to copy the root manually as it is already setup:
% \begin{macrocode}
%<debug>\prop_new:c { g_@@_struct_debug_0_prop }
%<debug>\seq_new:c { g_@@_struct_debug_kids_0_seq }
%<debug>\prop_gset_eq:cc { g_@@_struct_debug_0_prop }{ g_@@_struct_0_prop }
%<debug>\prop_gremove:cn { g_@@_struct_debug_0_prop }{Namespaces}
%<debug>\prop_new:c { g_@@_struct_debug_1_prop }
%<debug>\seq_new:c { g_@@_struct_debug_kids_1_seq }
%<debug>\prop_gset_eq:cc { g_@@_struct_debug_1_prop }{ g_@@_struct_1_prop }
%<debug>\prop_gremove:cn { g_@@_struct_debug_1_prop }{Namespaces}
% \end{macrocode}
% \end{variable}
%
Expand Down Expand Up @@ -739,7 +739,7 @@
\@@_seq_gput_right:ce
{ g_@@_struct_kids_#1_seq }
{
\pdf_object_ref:n { @@/struct/#2 }
\pdf_object_ref_indexed:nn { @@/struct }{ #2 }
}
%<debug> \seq_gput_right:cn
%<debug> { g_@@_struct_debug_kids_#1_seq }
Expand Down Expand Up @@ -944,7 +944,7 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_struct_write_obj:n #1 % #1 is the struct num
{
\pdf_object_if_exist:nTF { @@/struct/#1 }
\prop_if_exist:cTF { g_@@_struct_#1_prop }
{
% \end{macrocode}
% It can happen that a structure is not used and so has not parent.
Expand All @@ -953,7 +953,7 @@
% \begin{macrocode}
\prop_get:cnNF { g_@@_struct_#1_prop } {P}\l_@@_tmpb_tl
{
\prop_gput:cne { g_@@_struct_#1_prop } {P}{\pdf_object_ref:n { @@/struct/0 }}
\prop_gput:cne { g_@@_struct_#1_prop } {P}{\pdf_object_ref_indexed:nn { @@/struct }{1}}
\prop_gput:cne { g_@@_struct_#1_prop } {S}{/Artifact}
\seq_if_empty:cF {g_@@_struct_kids_#1_seq}
{
Expand All @@ -966,14 +966,13 @@
}
\@@_struct_fill_kid_key:n { #1 }
\@@_struct_get_dict_content:nN { #1 } \l_@@_tmpa_tl
\exp_args:Ne
\pdf_object_write:nne
{ @@/struct/#1 }
{dict}
{
\l_@@_tmpa_tl\c_space_tl
/ID~\@@_struct_get_id:n{#1}
}
\pdf_object_write_indexed:nnne
{ @@/struct }{ #1 }
{dict}
{
\l_@@_tmpa_tl\c_space_tl
/ID~\@@_struct_get_id:n{#1}
}

}
{
Expand Down Expand Up @@ -1038,7 +1037,7 @@
#2
}
{
\pdf_object_ref:e { @@/struct/\l_@@_struct_stack_parent_tmpa_tl }
\pdf_object_ref_indexed:nn { @@/struct }{ \l_@@_struct_stack_parent_tmpa_tl }
}
% increase the int:
\int_gincr:N \c@g_@@_parenttree_obj_int
Expand Down Expand Up @@ -1409,14 +1408,14 @@
{
\pdf_object_if_exist:nTF {#1}
{
\@@_struct_add_AF:ee { 0 }{\pdf_object_ref:n {#1}}
\@@_struct_add_AF:ee { 1 }{\pdf_object_ref:n {#1}}
\@@_struct_prop_gput:nne
{ 0 }
{ 1 }
{ AF }
{
[
\tl_use:c
{ g_@@_struct_0_AF_tl }
{ g_@@_struct_1_AF_tl }
]
}
}
Expand Down Expand Up @@ -1455,9 +1454,8 @@
\@@_new_output_prop_handler:n {\int_eval:n { \c@g_@@_struct_abs_int }}
\@@_seq_new:c { g_@@_struct_kids_\int_eval:n { \c@g_@@_struct_abs_int }_seq}
%<debug> \seq_new:c { g_@@_struct_debug_kids_\int_eval:n {\c@g_@@_struct_abs_int}_seq }
\exp_args:Ne
\pdf_object_new:n
{ @@/struct/\int_eval:n { \c@g_@@_struct_abs_int } }
\pdf_object_new_indexed:nn { @@/struct }
{ \c@g_@@_struct_abs_int }
\@@_struct_prop_gput:nnn
{ \int_use:N \c@g_@@_struct_abs_int }
{ Type }
Expand Down Expand Up @@ -1607,7 +1605,7 @@
{ \int_use:N \c@g_@@_struct_abs_int }
{ P }
{
\pdf_object_ref:e { @@/struct/\l_@@_struct_stack_parent_tmpa_tl }
\pdf_object_ref_indexed:nn { @@/struct} { \l_@@_struct_stack_parent_tmpa_tl }
}
% \end{macrocode}
% \begin{macrocode}
Expand Down Expand Up @@ -1713,19 +1711,19 @@
%add the label structure as kid to the current structure (can be the root)
\@@_struct_kid_struct_gput_right:ee
{ \g_@@_struct_stack_current_tl }
{ \@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{0} }
{ \@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{1} }
%add the current structure to the labeled one as parents
\@@_prop_gput:cne
{ g_@@_struct_\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{0}_prop }
{ g_@@_struct_\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}_prop }
{ P }
{
\pdf_object_ref:e { @@/struct/\g_@@_struct_stack_current_tl }
\pdf_object_ref_indexed:nn { @@/struct } { \g_@@_struct_stack_current_tl }
}
% \end{macrocode}
% debug code
% \begin{macrocode}
%<debug> \prop_gput:cne
%<debug> { g_@@_struct_debug_\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{0}_prop }
%<debug> { g_@@_struct_debug_\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}_prop }
%<debug> { P }
%<debug> {
%<debug> parent~structure:~\g_@@_struct_stack_current_tl\c_space_tl=~
Expand All @@ -1737,7 +1735,7 @@
% the global tl-vars:
% \begin{macrocode}
\@@_struct_get_parentrole:eNN
{\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{0}}
{\@@_property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}}
\l_@@_tmpa_tl
\l_@@_tmpb_tl
\@@_check_parent_child:VVVVN
Expand Down Expand Up @@ -1798,7 +1796,7 @@
{ #1 }
{ P }
{
\pdf_object_ref:e { @@/struct/\g_@@_struct_stack_current_tl }
\pdf_object_ref_indexed:nn { @@/struct }{ \g_@@_struct_stack_current_tl }
}
%<debug> \prop_gput:cne
%<debug> { g_@@_struct_debug_#1_prop }
Expand Down Expand Up @@ -1851,7 +1849,7 @@
%<*package>
\cs_new:Npn \tag_struct_object_ref:n #1
{
\pdf_object_ref:n {@@/struct/#1}
\pdf_object_ref_indexed:nn {@@/struct}{ #1 }
}
\cs_generate_variant:Nn \tag_struct_object_ref:n {e}
% \end{macrocode}
Expand Down
44 changes: 22 additions & 22 deletions tagpdf-tree.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
% If there is an OpenAction entry we must update it,
% so that it contains also a structure destination.
% We do it late so that we can win, but before the pdfmanagement hook.
% \begin{macro}{@@/struct/0}
% \begin{macro}{@@/struct/1}
% This is the object for the root object, the StructTreeRoot
% \begin{macrocode}
\pdf_object_new:n { @@/struct/0 }
\pdf_object_new_indexed:nn { @@/struct }{ 1 }
% \end{macrocode}
% \end{macro}
%
Expand Down Expand Up @@ -178,7 +178,7 @@
\pdfmanagement_add:nne
{ Catalog }
{ StructTreeRoot }
{ \pdf_object_ref:n { @@/struct/0 } }
{ \pdf_object_ref_indexed:nn { @@/struct } { 1 } }
\@@_tree_update_openaction:
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@
\int_incr:N\l_@@_tmpa_int
\tl_put_right:Ne \l_@@_tmpa_tl
{
\@@_struct_get_id:n{##1}~\pdf_object_ref:n{@@/struct/##1}~
\@@_struct_get_id:n{##1}~\pdf_object_ref_indexed:nn {@@/struct}{##1}~
}
\int_compare:nNnF {\l_@@_tmpa_int}<{50} %
{
Expand All @@ -245,7 +245,7 @@
}
\pdf_object_unnamed_write:ne {dict}{/Kids~[\l_@@_tmpb_tl]}
\@@_prop_gput:cne
{ g_@@_struct_0_prop }
{ g_@@_struct_1_prop }
{ IDTree }
{ \pdf_object_ref_last: }
}
Expand All @@ -259,18 +259,18 @@
\cs_new_protected:Npn \@@_tree_write_structtreeroot:
{
\@@_prop_gput:cne
{ g_@@_struct_0_prop }
{ g_@@_struct_1_prop }
{ ParentTree }
{ \pdf_object_ref:n { @@/tree/parenttree } }
\@@_prop_gput:cne
{ g_@@_struct_0_prop }
{ g_@@_struct_1_prop }
{ RoleMap }
{ \pdf_object_ref:n { @@/tree/rolemap } }
\@@_struct_fill_kid_key:n { 0 }
\prop_gremove:cn { g_@@_struct_0_prop } {S}
\@@_struct_get_dict_content:nN { 0 } \l_@@_tmpa_tl
\pdf_object_write:nne
{ @@/struct/0 }
\@@_struct_fill_kid_key:n { 1 }
\prop_gremove:cn { g_@@_struct_1_prop } {S}
\@@_struct_get_dict_content:nN { 1 } \l_@@_tmpa_tl
\pdf_object_write_indexed:nnne
{ @@/struct } { 1 }
{dict}
{
\l_@@_tmpa_tl
Expand All @@ -284,7 +284,7 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_tree_write_structelements:
{
\int_step_inline:nnnn {1}{1}{\c@g_@@_struct_abs_int}
\int_step_inline:nnnn {2}{1}{\c@g_@@_struct_abs_int}
{
\@@_struct_write_obj:n { ##1 }
}
Expand Down Expand Up @@ -376,7 +376,7 @@
\int_eval:n {##1-1}\c_space_tl
[\c_space_tl %]
}
\int_step_inline:nnnn
\int_step_inline:nnnn %####1
{0}
{1}
{ \prop_count:N \l_@@_tmpa_prop -1 }
Expand All @@ -385,13 +385,13 @@
{% page#1:mcid##1:\l_@@_tmpa_tl :content
\tl_put_right:Ne \l_@@_parenttree_content_tl
{
\pdf_object_if_exist:eTF { @@/struct/\l_@@_tmpa_tl }
{
\pdf_object_ref:e { @@/struct/\l_@@_tmpa_tl }
}
{
null
}
\prop_if_exist:cTF { g_@@_struct_ \l_@@_tmpa_tl _prop }
{
\pdf_object_ref_indexed:nn { @@/struct }{ \l_@@_tmpa_tl }
}
{
null
}
\c_space_tl
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@
{dict}
{ \l_@@_tmpa_tl }
\@@_prop_gput:cne
{ g_@@_struct_0_prop }
{ g_@@_struct_1_prop }
{ ClassMap }
{ \pdf_object_ref:n { @@/tree/classmap } }
}
Expand Down
6 changes: 2 additions & 4 deletions tagpdf.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
% possible, so we define a command which a special in the relevant backends:
% \begin{macrocode}
%<*base>
\prg_new_eq_conditional:NNn \intarray_if_exist:N \cs_if_exist:N {T,F,TF}
\AddToHook{begindocument}
{
\str_case:VnF \c_sys_backend_str
Expand Down Expand Up @@ -404,10 +405,7 @@
{0} { \int_use:N \c@g_@@_struct_abs_int }
\@@_property_new:nnnn { tagstructobj } { now } {}
{
\pdf_object_if_exist:eT {@@/struct/\int_use:N \c@g__tag_struct_abs_int}
{
\pdf_object_ref:e{@@/struct/\int_use:N \c@g_@@_struct_abs_int}
}
\pdf_object_ref_indexed:nn { @@/struct } { \c@g_@@_struct_abs_int }
}
\@@_property_new:nnnn
{ tagabspage } { shipout }
Expand Down

0 comments on commit 342c061

Please sign in to comment.