Skip to content

Commit

Permalink
add structure to OpenAction
Browse files Browse the repository at this point in the history
  • Loading branch information
u-fischer committed Feb 23, 2024
1 parent 5ef83c2 commit 2846db1
Show file tree
Hide file tree
Showing 10 changed files with 2,119 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to the `tagpdf` package since the
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
this project uses date-based 'snapshot' version identifiers.

## [Unreleased]

### Added
- structure destination is added OpenAction if present
- viewer/startstructure key to setup the OpenAction structure.

## [2024-02-22]
Version 0.98w
### Changed
Expand Down
6 changes: 6 additions & 0 deletions doc/tagpdf.tex
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,12 @@ \subsection{Setup and activation}\label{ssec:setup}
it hasn't been tested yet with complicated documents containing
annotations etc. See also section~\ref{sec:lazy} for a discussion
about automatic tagging.

\item[\PrintKeyName{viewer/startstructure}] A structure number. If a \texttt{OpenAction}
is set in the PDF Catalog (which is normally the case if hyperref is used)
a structure destination pointing to the structure is added. The initial value is structure 1 (the \texttt{Document} structure), the default value is the current structure. The
key can be used more than once, the last setting will win.


\item[\PrintKeyName{debug/uncompress}] Sets both the \PDF{} compresslevel
and the \PDF{} objcompresslevel to 0 and so allows to inspect the
Expand Down
3 changes: 2 additions & 1 deletion doc/tagpdfsetup-keys.tex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
% TODO viewer/display-title
%% show mathml-files in attachment pane (old mathml-panel)
viewer/pane/mathml & --- & boolean &bool &latex-lab-math (dev)\\
viewer/pane/mathsource& --- &boolean &bool &latex-lab-math (dev)\\[4pt]\midrule
viewer/pane/mathsource& --- &boolean &bool &latex-lab-math (dev)\\
viewer/startstructure & --- &number &code &tagpdf-tree \\[4pt]\midrule
%%% Document element keys
%% page key path
page/tabsorder &tabsorder & choice & code & tagpdf\\
Expand Down
66 changes: 65 additions & 1 deletion tagpdf-tree.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,78 @@
% \end{macrocode}
% \end{macro}
%
% \subsection{Catalog: MarkInfo and StructTreeRoot}
% \subsection{Catalog: MarkInfo and StructTreeRoot and OpenAction}
% The StructTreeRoot and the MarkInfo entry must be added to the catalog.
% 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}
% This is the object for the root object, the StructTreeRoot
% \begin{macrocode}
\pdf_object_new:n { @@/struct/0 }
% \end{macrocode}
% \end{macro}
%
% \begin{variable}{\g_@@_tree_openaction_struct_tl}
% We need a variable that indicates which structure is wanted in the OpenAction. By default we use
% 1 (the Document structure).
% \begin{macrocode}
\tl_new:N \g_@@_tree_openaction_struct_tl
\tl_gset:Nn \g_@@_tree_openaction_struct_tl {1}
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{viewer/startpage (setup-key)}
% We also need an option to setup the start structure. So we setup a key
% which sets the variable to the current structure. This still requires
% hyperref to do most of the job, this should perhaps be changed.
% \begin{macrocode}
\keys_define:nn { @@ / setup }
{
viewer/startstructure .code:n =
{
\tl_gset:Ne \g_@@_tree_openaction_struct_tl {#1}
}
,viewer/startstructure .default:n = { \int_use:N \c@g_@@_struct_abs_int }
}
% \end{macrocode}
% \end{macro}
% The OpenAction should only be updated if it is there. So we inspect the
% Catalog-prop:
% \begin{macrocode}
\cs_new_protected:Npn \@@_tree_update_openaction:
{
\prop_get:cnNT
{ \__kernel_pdfdict_name:n { g__pdf_Core/Catalog } }
{OpenAction}
\l_@@_tmpa_tl
{
% \end{macrocode}
% we only do something if the OpenAction is an array (as set by hyperref)
% in other cases we hope that the author knows what they did.
% \begin{macrocode}
\tl_if_head_eq_charcode:eNT { \tl_trim_spaces:V\l_@@_tmpa_tl } [ %]
{
\seq_set_split:NnV\l_@@_tmpa_seq{/}\l_@@_tmpa_tl
\pdfmanagement_add:nne {Catalog} { OpenAction }
{
<<
/S/GoTo \c_space_tl
/D~\l_@@_tmpa_tl\c_space_tl
/SD~[\pdf_object_ref:e{__tag/struct/\g_@@_tree_openaction_struct_tl}
% \end{macrocode}
% there should be always a /Fit etc in the array but better play safe here ...
% \begin{macrocode}
\int_compare:nNnTF{ \seq_count:N \l_@@_tmpa_seq } > {1}
{ /\seq_item:Nn\l_@@_tmpa_seq{2} }
{ ] }
>>
}
}
}
}
% \end{macrocode}
%
% \begin{macrocode}
\hook_gput_code:nnn{shipout/lastpage}{tagpdf}
{
Expand All @@ -115,6 +178,7 @@
{ Catalog }
{ StructTreeRoot }
{ \pdf_object_ref:n { @@/struct/0 } }
\@@_tree_update_openaction:
}
}
% \end{macrocode}
Expand Down
18 changes: 18 additions & 0 deletions testfiles-pdftex/openaction-0.pvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
\ExplSyntaxOn
\debug_on:n { check-declarations , deprecation }
\msg_redirect_module:nnn { pdf } { none } { warning }
\ExplSyntaxOff

\DocumentMetadata{uncompress,testphase=phase-III}
\input{regression-test}

\documentclass{book}
\usepackage{hyperref}
\begin{document}

some text

some text

\end{document}

Loading

0 comments on commit 2846db1

Please sign in to comment.