| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: tagpdf-struct.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2019-2026 Ulrike Fischer |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "tagpdf bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/tagpdf |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
%<*driver> |
| 25 |
\DocumentMetadata{tagging=on} |
| 26 |
\documentclass{l3in2edoc} |
| 27 |
\usepackage{array,booktabs,caption} |
| 28 |
\hypersetup{pdfauthor=Ulrike Fischer, |
| 29 |
pdftitle=tagpdf-tree module (tagpdf)} |
| 30 |
\input{tagpdf-docelements} |
| 31 |
\begin{document} |
| 32 |
\DocInput{\jobname.dtx} |
| 33 |
\end{document} |
| 34 |
%</driver> |
| 35 |
% \fi |
| 36 |
% \title{^^A |
| 37 |
% The \pkg{tagpdf-struct} module\\ Commands to create the structure ^^A |
| 38 |
% } |
| 39 |
% |
| 40 |
% \author{^^A |
| 41 |
% Ulrike Fischer\thanks |
| 42 |
% {^^A |
| 43 |
% E-mail: |
| 44 |
% \href{mailto:[email protected]} |
| 45 |
% {[email protected]}^^A |
| 46 |
% }^^A |
| 47 |
% } |
| 48 |
% |
| 49 |
% \date{Version 1.0c, released 2026-05-17} |
| 50 |
% \maketitle |
| 51 |
% \begin{documentation} |
| 52 |
% \section{Public Commands} |
| 53 |
% \begin{function}{\tag_struct_begin:n,\tag_struct_end:,\tag_struct_end:n} |
| 54 |
% \begin{syntax} |
| 55 |
% \cs{tag_struct_begin:n} \Arg{key-values}\\ |
| 56 |
% \cs{tag_struct_end:}\\ |
| 57 |
% \cs{tag_struct_end:n} \Arg{tag} |
| 58 |
% \end{syntax} |
| 59 |
% These commands start and end a new structure. |
| 60 |
% They don't start a group. They set all their values globally. |
| 61 |
% \cs{tag_struct_end:n} does nothing special normally (apart from |
| 62 |
% swallowing its argument, but if \texttt{tagpdf-debug} is loaded, |
| 63 |
% it will check if the \Arg{tag} (after expansion) |
| 64 |
% is identical to the current structure on the stack. The tag is not role mapped! |
| 65 |
% \end{function} |
| 66 |
% \begin{function}{\tag_struct_use:n,\tag_struct_use_num:n} |
| 67 |
% \begin{syntax} |
| 68 |
% \cs{tag_struct_use:n} \Arg{label}\\ |
| 69 |
% \cs{tag_struct_use_num:n} \Arg{structure number} |
| 70 |
% \end{syntax} |
| 71 |
% These commands insert a structure previously stashed away as kid |
| 72 |
% into the currently active structure. |
| 73 |
% A structure should be used only once, |
| 74 |
% if the structure already has a parent a warning is issued. |
| 75 |
% \end{function} |
| 76 |
% \begin{function}{\tag_struct_object_ref:n,\tag_struct_object_ref:e} |
| 77 |
% \begin{syntax} |
| 78 |
% \cs{tag_struct_object_ref:n} \Arg{structure number} |
| 79 |
% \end{syntax} |
| 80 |
% This is a small wrapper around |\pdf_object_ref:n| to retrieve the |
| 81 |
% object reference of the structure with the number \meta{struct number}. |
| 82 |
% This number can be retrieved and stored for the current structure |
| 83 |
% for example with \cs{tag_get:n}\Arg{struct_num}. Be aware that it can only |
| 84 |
% be used if the structure has already been created and that it doesn't check |
| 85 |
% if the object actually exists! |
| 86 |
% \end{function} |
| 87 |
% |
| 88 |
% The following two functions are used to add annotations. They must be used |
| 89 |
% together and with care to get the same numbers. Perhaps some improvements are needed |
| 90 |
% here. |
| 91 |
% \begin{function}{\tag_struct_insert_annot:nn} |
| 92 |
% \begin{syntax} |
| 93 |
% \cs{tag_struct_insert_annot:nn} \Arg{object reference} \Arg{struct parent number} |
| 94 |
% \end{syntax} |
| 95 |
% This inserts an annotation in the structure. \meta{object reference} |
| 96 |
% is there reference to the annotation. \meta{struct parent number} |
| 97 |
% should be the same number as had been inserted with \cs{tag_struct_parent_int:} |
| 98 |
% as |StructParent| value to the dictionary of the annotation. |
| 99 |
% The command will increase the value of the counter |
| 100 |
% used by \cs{tag_struct_parent_int:}. |
| 101 |
% \end{function} |
| 102 |
% \begin{function}{\tag_struct_parent_int:} |
| 103 |
% \begin{syntax} |
| 104 |
% \cs{tag_struct_parent_int:} |
| 105 |
% \end{syntax} |
| 106 |
% This gives back the next free /StructParent number (assuming that it is |
| 107 |
% together with \cs{tag_struct_insert_annot:nn} which will increase the number. |
| 108 |
% \end{function} |
| 109 |
% |
| 110 |
% \begin{function}{\tag_struct_gput:nnn} |
| 111 |
% \begin{syntax} |
| 112 |
% \cs{tag_struct_gput:nnn} \Arg{structure number} \Arg{keyword} \Arg{value} |
| 113 |
% \end{syntax} |
| 114 |
% This is a command that allows to update the data of a structure. |
| 115 |
% This often can't done simply by replacing the value, as we have to |
| 116 |
% preserve and extend existing content. We use therefore dedicated functions |
| 117 |
% adjusted to the key in question. |
| 118 |
% The first argument is the number of the structure, |
| 119 |
% the second a keyword referring to a function, |
| 120 |
% the third the value. Currently the only keyword is \texttt{ref} which updates |
| 121 |
% the Ref key (an array) |
| 122 |
% \end{function} |
| 123 |
% |
| 124 |
% \begin{function}{\tag_struct_gput_ref:nnn} |
| 125 |
% \begin{syntax} |
| 126 |
% \cs{tag_struct_gput_ref:nnn} \Arg{structure number} \Arg{keyword} \Arg{value} |
| 127 |
% \end{syntax} |
| 128 |
% This is an user interface to add a Ref key to an |
| 129 |
% existing structure. The target structure doesn't have to exist yet |
| 130 |
% but can be addressed by label, destname or even num. |
| 131 |
% \meta{keyword} is currently either \texttt{label}, \texttt{dest} |
| 132 |
% or \texttt{num}. The value is then either a label name, the name of a destination |
| 133 |
% or a structure number. |
| 134 |
% \end{function} |
| 135 |
% |
| 136 |
% \section{Public keys} |
| 137 |
% \subsection{Keys for the structure commands} |
| 138 |
% \begin{structkeydecl}{tag} |
| 139 |
% This is required. The value of the key is normally one of the |
| 140 |
% standard types listed in the main tagpdf documentation. |
| 141 |
% It is possible to setup new tags/types. |
| 142 |
% The value can also be of the form |type/NS|, where |NS| is the |
| 143 |
% shorthand of a declared name space. |
| 144 |
% Currently the names spaces |pdf|, |pdf2|, |mathml| and |user| are defined. |
| 145 |
% This allows to use a different name space than |
| 146 |
% the one connected by default to the tag. But normally this should not be needed. |
| 147 |
% \end{structkeydecl} |
| 148 |
% \begin{structkeydecl}{stash} |
| 149 |
% Normally a new structure inserts itself as a kid |
| 150 |
% into the currently active structure. This key prohibits this. |
| 151 |
% The structure is nevertheless from now on |
| 152 |
% \enquote{the current active structure} |
| 153 |
% and parent for following marked content and structures. |
| 154 |
% \end{structkeydecl} |
| 155 |
% \begin{structkeydecl}{label} |
| 156 |
% This key sets a label by which |
| 157 |
% one can refer to the structure. It is e.g. |
| 158 |
% used by \cs{tag_struct_use:n} (where a real label is actually not |
| 159 |
% needed as you can only use structures already defined), and by the |
| 160 |
% |ref| key (which can refer to future structures). |
| 161 |
% Internally the label name will start with \texttt{tagpdfstruct-} and it stores |
| 162 |
% the two attributes |tagstruct| (the structure number) and |tagstructobj| (the |
| 163 |
% object reference). |
| 164 |
% \end{structkeydecl} |
| 165 |
% \begin{structkeydecl}{parent} |
| 166 |
% By default a structure is added as kid to the currently active structure. |
| 167 |
% With the parent key one can choose another parent. The value is a structure number which |
| 168 |
% must refer to an already existing, previously created structure. Such a structure |
| 169 |
% number can for example be have been stored with \cs{tag_get:n}, but one can also use |
| 170 |
% a label on the parent structure and then use |
| 171 |
% \cs{property_ref:nn}|{tagpdfstruct-label}{tagstruct}| to retrieve it. |
| 172 |
% \end{structkeydecl} |
| 173 |
% \begin{structkeydecl}{firstkid} |
| 174 |
% If this key is used the structure is added at the left of the kids of |
| 175 |
% the parent structure (if the structure is not stashed). |
| 176 |
% This means that it will be the first kid of the structure |
| 177 |
% (unless some later structure uses the key too). |
| 178 |
% \end{structkeydecl} |
| 179 |
% \begin{structkeydecl}{title,title-o} |
| 180 |
% This keys allows to set the dictionary entry |
| 181 |
% \texttt{/Title} in the structure object. |
| 182 |
% The value is handled as verbatim string and hex encoded. |
| 183 |
% Commands are not expanded. |title-o| will expand the value once. |
| 184 |
% \end{structkeydecl} |
| 185 |
% |
| 186 |
% \begin{structkeydecl}{alt} |
| 187 |
% This key inserts an \texttt{/Alt} value in the dictionary of structure object. |
| 188 |
% The value is handled as verbatim string and hex encoded. |
| 189 |
% The value will be expanded first once. If it is empty, nothing will happen. |
| 190 |
% \end{structkeydecl} |
| 191 |
% \begin{structkeydecl}{actualtext} |
| 192 |
% This key inserts an \texttt{/ActualText} value in the dictionary of structure object. |
| 193 |
% The value is handled as verbatim string and hex encoded. |
| 194 |
% The value will be expanded first once. If it is empty, nothing will happen. |
| 195 |
% \end{structkeydecl} |
| 196 |
% \begin{structkeydecl}{lang} |
| 197 |
% This key allows to set the language for a structure element. The value should be a bcp-identifier, |
| 198 |
% e.g. |de-De|. |
| 199 |
% \end{structkeydecl} |
| 200 |
% \begin{structkeydecl}{ref} |
| 201 |
% This key allows to add references to other structure elements, |
| 202 |
% it adds the |/Ref| array to the structure. |
| 203 |
% The value should be a comma separated list of structure labels |
| 204 |
% set with the |label| key. e.g. |ref={label1,label2}|. |
| 205 |
% \end{structkeydecl} |
| 206 |
% \begin{structkeydecl}{E} |
| 207 |
% This key sets the |/E| key, the expanded form of an |
| 208 |
% abbreviation or an acronym |
| 209 |
% (I couldn't think of a better name, so I sticked to E). |
| 210 |
% \end{structkeydecl} |
| 211 |
% \begin{structkeydecl}{AF,AFref, |
| 212 |
% AFinline,AFinline-o,texsource,mathml} |
| 213 |
% These keys handle associated files in the structure element. |
| 214 |
% |
| 215 |
% \begin{syntax} |
| 216 |
% AF = \meta{object name}\\ |
| 217 |
% AFref = \meta{object reference}\\ |
| 218 |
% AF-inline = \meta{text content}\\ |
| 219 |
% \end{syntax} |
| 220 |
% |
| 221 |
% The value \meta{object name} should be the name of an object pointing |
| 222 |
% to the \texttt{/Filespec} dictionary as expected by |
| 223 |
% |\pdf_object_ref:n| from a current \texttt{l3kernel}. |
| 224 |
% |
| 225 |
% The value |AF-inline| is some text, |
| 226 |
% which is embedded in the PDF as a text file with mime type text/plain. |
| 227 |
% |AF-inline-o| is like |AF-inline| but expands the value once. |
| 228 |
% |
| 229 |
% Future versions will perhaps extend this to more mime types, but it is |
| 230 |
% still a research task to find out what is really needed. |
| 231 |
% |
| 232 |
% |texsource| is a special variant of |AF-inline-o| which embeds the content |
| 233 |
% as |.tex| source with the |/AFrelationship| key set to |/Source|. |
| 234 |
% It also sets the |/Desc| key to a (currently) fix text. |
| 235 |
% |
| 236 |
% |mathml| is a special variant of |AF-inline-o| which embeds the content |
| 237 |
% as |.xml| file with the |/AFrelationship| key set to |/Supplement|. |
| 238 |
% It also sets the |/Desc| key to a (currently) fix text. |
| 239 |
% |
| 240 |
% The argument of |AF| is an object name referring an embedded file as declared |
| 241 |
% for example with |
| 242 |
% \cs{pdf_object_new:n} or with the l3pdffile module. |AF| expands its argument |
| 243 |
% (this allows e.g. to use some variable for automatic numbering) |
| 244 |
% and can be used more than once, to associate more than one file. |
| 245 |
% |
| 246 |
% The argument of |AFref| is an object reference to an embedded file |
| 247 |
% or a variable expanding to such a object reference in the format |
| 248 |
% as you would get e.g. from \cs{pdf_object_ref_last:} or \cs{pdf_object_ref:n} |
| 249 |
% (and which is different for the various engines!). The key allows to make |
| 250 |
% use of anonymous objects. Like |AF| the |AFref| key expands its argument |
| 251 |
% and can be used more than once, to associate more than one file. \emph{It |
| 252 |
% does not check if the reference is valid!} |
| 253 |
% |
| 254 |
% The inline keys can be used only once per structure. Additional calls are ignored. |
| 255 |
% \end{structkeydecl} |
| 256 |
% |
| 257 |
% \begin{structkeydecl}{attribute} |
| 258 |
% This key takes as argument a comma list of attribute names |
| 259 |
% (use braces to protect the commas from the external key-val parser) |
| 260 |
% and allows to add one or more attribute dictionary entries in |
| 261 |
% the structure object. As an example |
| 262 |
% \begin{verbatim} |
| 263 |
% \tagstructbegin{tag=TH,attribute= TH-row} |
| 264 |
% \end{verbatim} |
| 265 |
% Attribute names and their content must be declared first in \cs{tagpdfsetup}. |
| 266 |
% |
| 267 |
% \end{structkeydecl} |
| 268 |
% |
| 269 |
% \begin{structkeydecl}{attribute-class} |
| 270 |
% This key takes as argument a comma list of attribute class names |
| 271 |
% (use braces to protect the commas from the external key-val parser) |
| 272 |
% and allows to add one or more attribute classes to the structure object. |
| 273 |
% |
| 274 |
% Attribute class names and their content |
| 275 |
% must be declared first in \cs{tagpdfsetup}. |
| 276 |
% \end{structkeydecl} |
| 277 |
% |
| 278 |
% \subsection{Setup keys} |
| 279 |
% \begin{function}{role/new-attribute (setup-key), newattribute (deprecated)} |
| 280 |
% \begin{syntax} |
| 281 |
% role/new-attribute = \Arg{name}\Arg{Content} |
| 282 |
% \end{syntax} |
| 283 |
% This key can be used in the setup command \cs{tagpdfsetup} and allow to declare a |
| 284 |
% new attribute, which can be used as attribute or attribute class. |
| 285 |
% The value are two brace groups, the first contains the name, the second the content. |
| 286 |
% \begin{verbatim} |
| 287 |
% \tagpdfsetup |
| 288 |
% { |
| 289 |
% role/new-attribute = |
| 290 |
% {TH-col}{/O /Table /Scope /Column}, |
| 291 |
% role/new-attribute = |
| 292 |
% {TH-row}{/O /Table /Scope /Row}, |
| 293 |
% } |
| 294 |
% \end{verbatim} |
| 295 |
% |
| 296 |
% \end{function} |
| 297 |
% \begin{setupkeydecl}{root-AF} |
| 298 |
% \begin{syntax} |
| 299 |
% root-AF = \meta{object name} |
| 300 |
% \end{syntax} |
| 301 |
% This key can be used in the setup command \cs{tagpdfsetup} and allows |
| 302 |
% to add associated files to the root structure. Like |AF| it can be used more than |
| 303 |
% once to add more than one file. |
| 304 |
% \end{setupkeydecl} |
| 305 |
% \end{documentation} |
| 306 |
% \begin{implementation} |
| 307 |
% \begin{macrocode} |
| 308 |
%<@@=tag> |
| 309 |
%<*header> |
| 310 |
\ProvidesExplPackage {tagpdf-struct-code} {2026-05-17} {1.0c} |
| 311 |
{part of tagpdf - code related to storing structure} |
| 312 |
%</header> |
| 313 |
% \end{macrocode} |
| 314 |
% \section{Variables} |
| 315 |
% \begin{variable}{\c@g_@@_struct_abs_int} |
| 316 |
% Every structure will have a unique, absolute number. |
| 317 |
% |
| 318 |
% \begin{macrocode} |
| 319 |
%<base>\int_new:N \c@g_@@_struct_abs_int |
| 320 |
%<base>\int_gset:Nn \c@g_@@_struct_abs_int { 1 } |
| 321 |
% \end{macrocode} |
| 322 |
% \end{variable} |
| 323 |
% |
| 324 |
% \begin{variable}{\g_@@_struct_objR_seq} |
| 325 |
% a sequence to store mapping between the |
| 326 |
% structure number and the object number. |
| 327 |
% We assume that structure numbers are assign |
| 328 |
% consecutively and so the index of the seq can be used. |
| 329 |
% A seq allows easy mapping over the structures. |
| 330 |
% \begin{macrocode} |
| 331 |
%<*package> |
| 332 |
\@@_seq_new:N \g_@@_struct_objR_seq |
| 333 |
% \end{macrocode} |
| 334 |
% \end{variable} |
| 335 |
% \begin{variable}{\c_@@_struct_null_tl} |
| 336 |
% In lua mode we have to test if the kids a null |
| 337 |
% \begin{macrocode} |
| 338 |
\tl_const:Nn\c_@@_struct_null_tl {null} |
| 339 |
% \end{macrocode} |
| 340 |
% \end{variable} |
| 341 |
|
| 342 |
% \begin{variable}{\g_@@_struct_cont_mc_prop} |
| 343 |
% in generic mode it can happen after |
| 344 |
% a page break that we have to inject into a structure |
| 345 |
% sequence an additional mc after. We will store this additional |
| 346 |
% info in a property. The key is the absolute mc num, the value the pdf directory. |
| 347 |
% \begin{macrocode} |
| 348 |
\@@_prop_new:N \g_@@_struct_cont_mc_prop |
| 349 |
% \end{macrocode} |
| 350 |
% \end{variable} |
| 351 |
% |
| 352 |
% \begin{variable}{\g_@@_struct_stack_seq} |
| 353 |
% A stack sequence for the structure stack. |
| 354 |
% When a sequence is opened it's number is put on the stack. |
| 355 |
% \begin{macrocode} |
| 356 |
\seq_new:N \g_@@_struct_stack_seq |
| 357 |
\seq_gpush:Nn \g_@@_struct_stack_seq {1} |
| 358 |
% \end{macrocode} |
| 359 |
% \end{variable} |
| 360 |
% |
| 361 |
% \begin{variable}{\g_@@_struct_tag_stack_seq} |
| 362 |
% We will perhaps also need the tags. While it is possible to get them from the |
| 363 |
% numbered stack, lets build a tag stack too. |
| 364 |
% We create one which contains also the real tags and one with only the rolemapped |
| 365 |
% tags for faster testing. |
| 366 |
% \begin{macrocode} |
| 367 |
\seq_new:N \g_@@_struct_tag_stack_seq |
| 368 |
\seq_new:N \g_@@_struct_roletag_stack_seq |
| 369 |
\seq_gpush:Nn \g_@@_struct_tag_stack_seq {{Root}{StructTreeRoot}} |
| 370 |
\seq_gpush:Nn \g_@@_struct_roletag_stack_seq {StructTreeRoot} |
| 371 |
% \end{macrocode} |
| 372 |
% \end{variable} |
| 373 |
% |
| 374 |
% |
| 375 |
% \begin{variable}{\g_@@_struct_stack_current_tl,\l_@@_struct_stack_parent_tmpa_tl} |
| 376 |
% The global variable will hold the current structure number. It is already |
| 377 |
% defined in \texttt{tagpdf-base}. |
| 378 |
% The local temporary variable will hold the parent when we fetch it from the stack. |
| 379 |
% \begin{macrocode} |
| 380 |
%</package> |
| 381 |
%<base>\tl_new:N \g_@@_struct_stack_current_tl |
| 382 |
%<base>\tl_gset:Nn \g_@@_struct_stack_current_tl {\int_use:N\c@g_@@_struct_abs_int} |
| 383 |
%<*package> |
| 384 |
\tl_new:N \l_@@_struct_stack_parent_tmpa_tl |
| 385 |
% \end{macrocode} |
| 386 |
% \end{variable} |
| 387 |
% |
| 388 |
% In luatex we will store the structure number as attribute. |
| 389 |
% \begin{macrocode} |
| 390 |
\sys_if_engine_luatex:TF |
| 391 |
{ |
| 392 |
\cs_new:Npn \@@_struct_set_attribute: |
| 393 |
{ |
| 394 |
\lua_now:e |
| 395 |
{ |
| 396 |
tex.setattribute |
| 397 |
( |
| 398 |
"global", |
| 399 |
luatexbase.attributes.g_@@_structnum_attr, |
| 400 |
\g_@@_struct_stack_current_tl |
| 401 |
) |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
{ |
| 406 |
\cs_new_eq:NN \@@_struct_set_attribute: \prg_do_nothing: |
| 407 |
} |
| 408 |
% \end{macrocode} |
| 409 |
% |
| 410 |
% I will need at least one structure: the StructTreeRoot |
| 411 |
% normally it should have only one kid, e.g. the document element. |
| 412 |
|
| 413 |
% The data of the StructTreeRoot and the StructElem are in properties: |
| 414 |
% |\g_@@_struct_1_prop| for the root and |
| 415 |
% |\g_@@_struct_N_prop|, $N \geq =2$ for the other. |
| 416 |
% |
| 417 |
% This creates quite a number of properties, so perhaps we will have to |
| 418 |
% do this more efficiently in the future. |
| 419 |
% |
| 420 |
% All properties have at least the keys |
| 421 |
% \begin{description} |
| 422 |
% \item[Type] StructTreeRoot or StructElem |
| 423 |
% \end{description} |
| 424 |
% and the keys from the two following lists |
| 425 |
% (the root has a special set of properties). |
| 426 |
% the values of the prop should be already escaped properly |
| 427 |
% when the entries are created (title,lange,alt,E,actualtext) |
| 428 |
% \begin{variable} |
| 429 |
% { |
| 430 |
% \c_@@_struct_StructTreeRoot_entries_seq, |
| 431 |
% \c_@@_struct_StructElem_entries_seq |
| 432 |
% } |
| 433 |
% These seq contain the keys we support in the two object types. |
| 434 |
% They are currently no longer used, but are provided as documentation and |
| 435 |
% for potential future checks. |
| 436 |
% They should be adapted if there are changes in the PDF format. |
| 437 |
% \begin{macrocode} |
| 438 |
\seq_const_from_clist:Nn \c_@@_struct_StructTreeRoot_entries_seq |
| 439 |
{%p. 857/858 |
| 440 |
Type, % always /StructTreeRoot |
| 441 |
K, % kid, dictionary or array of dictionaries |
| 442 |
IDTree, % currently unused |
| 443 |
ParentTree, % required,obj ref to the parent tree |
| 444 |
ParentTreeNextKey, % optional |
| 445 |
RoleMap, |
| 446 |
ClassMap, |
| 447 |
Namespaces, |
| 448 |
AF %pdf 2.0 |
| 449 |
} |
| 450 |
|
| 451 |
\seq_const_from_clist:Nn \c_@@_struct_StructElem_entries_seq |
| 452 |
{%p 858 f |
| 453 |
Type, %always /StructElem |
| 454 |
S, %tag/type |
| 455 |
P, %parent |
| 456 |
ID, %optional |
| 457 |
Ref, %optional, pdf 2.0 Use? |
| 458 |
Pg, %obj num of starting page, optional |
| 459 |
K, %kids |
| 460 |
A, %attributes, probably unused |
| 461 |
C, %class "" |
| 462 |
%R, %attribute revision number, irrelevant for us as we |
| 463 |
% don't update/change existing PDF and (probably) |
| 464 |
% deprecated in PDF 2.0 |
| 465 |
T, %title, value in () or <> |
| 466 |
Lang, %language |
| 467 |
Alt, % value in () or <> |
| 468 |
E, % abbreviation |
| 469 |
ActualText, |
| 470 |
AF, %pdf 2.0, array of dict, associated files |
| 471 |
NS, %pdf 2.0, dict, namespace |
| 472 |
PhoneticAlphabet, %pdf 2.0 |
| 473 |
Phoneme %pdf 2.0 |
| 474 |
} |
| 475 |
% \end{macrocode} |
| 476 |
% \end{variable} |
| 477 |
% |
| 478 |
% \subsection{Variables used by the keys} |
| 479 |
% \begin{variable}{\g_@@_struct_tag_tl,\g_@@_struct_tag_NS_tl, |
| 480 |
% \l_@@_struct_roletag_tl,\g_@@_struct_roletag_NS_tl, |
| 481 |
% \l_@@_struct_parenttag_tl,\l_@@_struct_parenttag_NS_tl} |
| 482 |
% Use by the tag key to store the tag and the namespace. |
| 483 |
% The \texttt{roletag} variables will hold locally rolemapping info needed |
| 484 |
% for the parent-child checks. The \texttt{parenttag} variables allow to |
| 485 |
% set the target role of the parent of stashed structures. |
| 486 |
% \begin{macrocode} |
| 487 |
\tl_new:N \g_@@_struct_tag_tl |
| 488 |
\tl_new:N \g_@@_struct_tag_NS_tl |
| 489 |
\tl_new:N \l_@@_struct_roletag_tl |
| 490 |
\tl_new:N \l_@@_struct_roletag_NS_tl |
| 491 |
\tl_new:N \l_@@_struct_parenttag_tl |
| 492 |
\tl_set:Nn \l_@@_struct_parenttag_tl {STASHED} |
| 493 |
\tl_new:N \l_@@_struct_parenttag_NS_tl |
| 494 |
\tl_set:Nn \l_@@_struct_parenttag_NS_tl {latex} |
| 495 |
% \end{macrocode} |
| 496 |
% \end{variable} |
| 497 |
% \begin{variable}{\g_@@_struct_label_num_prop} |
| 498 |
% This will hold for every structure label the associated |
| 499 |
% structure number. The prop will allow to |
| 500 |
% fill the /Ref key directly at the first compilation if the ref |
| 501 |
% key is used. |
| 502 |
% \begin{macrocode} |
| 503 |
\prop_new_linked:N \g_@@_struct_label_num_prop |
| 504 |
% \end{macrocode} |
| 505 |
% \end{variable} |
| 506 |
|
| 507 |
% \begin{variable}{\l_@@_struct_elem_stash_bool} |
| 508 |
% This will keep track of the stash status |
| 509 |
% \begin{macrocode} |
| 510 |
\bool_new:N \l_@@_struct_elem_stash_bool |
| 511 |
% \end{macrocode} |
| 512 |
% \end{variable} |
| 513 |
% |
| 514 |
% \begin{variable}{\l_@@_struct_addkid_tl} |
| 515 |
% This decides if a structure kid is added at the left or right of the parent. |
| 516 |
% The default is \texttt{right}. |
| 517 |
% \begin{macrocode} |
| 518 |
\tl_new:N \l_@@_struct_addkid_tl |
| 519 |
\tl_set:Nn \l_@@_struct_addkid_tl {right} |
| 520 |
% \end{macrocode} |
| 521 |
% \end{variable} |
| 522 |
|
| 523 |
% \subsection{Variables used by tagging code of basic elements} |
| 524 |
% |
| 525 |
% \begin{variable}{\g_@@_struct_dest_num_prop} |
| 526 |
% This variable records for (some or all, not clear yet) |
| 527 |
% destination names the related structure number to allow |
| 528 |
% to reference them in a Ref. The key is the destination. |
| 529 |
% It is currently used by the toc-tagging and sec-tagging code. |
| 530 |
% \begin{macrocode} |
| 531 |
%</package> |
| 532 |
%<base>\prop_new_linked:N \g_@@_struct_dest_num_prop |
| 533 |
%<*package> |
| 534 |
% \end{macrocode} |
| 535 |
% \end{variable} |
| 536 |
% |
| 537 |
% \begin{variable}{\g_@@_struct_ref_by_dest_prop} |
| 538 |
% This variable contains structures whose Ref key should be updated |
| 539 |
% at the end to point to structured related with this destination. |
| 540 |
% As this is probably need in other places too, it is not only a toc-variable. |
| 541 |
% TODO: remove after 11/2024 release. |
| 542 |
% \begin{macrocode} |
| 543 |
\prop_new_linked:N \g_@@_struct_ref_by_dest_prop |
| 544 |
%</package> |
| 545 |
% \end{macrocode} |
| 546 |
% \end{variable} |
| 547 |
% |
| 548 |
% \section{Commands} |
| 549 |
|
| 550 |
% \begin{macro}{\@@_struct_prop_gput:nnn} |
| 551 |
% The structure props must be filled in various places. |
| 552 |
% For this we use a common command which also takes care of the debug package: |
| 553 |
% \begin{macrocode} |
| 554 |
%<*package|debug> |
| 555 |
%<package>\cs_new_protected:Npn \@@_struct_prop_gput:nnn #1 #2 #3 |
| 556 |
%<debug>\cs_set_protected:Npn \@@_struct_prop_gput:nnn #1 #2 #3 |
| 557 |
{ |
| 558 |
\@@_prop_gput:cnn |
| 559 |
{ g_@@_struct_#1_prop }{#2}{#3} |
| 560 |
%<debug>\prop_gput:cnn { g_@@_struct_debug_#1_prop } {#2} {#3} |
| 561 |
} |
| 562 |
\cs_generate_variant:Nn \@@_struct_prop_gput:nnn {onn,nne,nee,nno} |
| 563 |
%</package|debug> |
| 564 |
% \end{macrocode} |
| 565 |
% \end{macro} |
| 566 |
|
| 567 |
% \subsection{Initialization of the StructTreeRoot} |
| 568 |
% The first structure element, the StructTreeRoot is special, so |
| 569 |
% created manually. The underlying object is |@@/struct/1| which is currently |
| 570 |
% created in the tree code (TODO move it here). |
| 571 |
% The |ParentTree| and |RoleMap| entries are added at begin document |
| 572 |
% in the tree code as they refer to object which are setup in other parts of the |
| 573 |
% code. This avoid timing issues. |
| 574 |
% |
| 575 |
% \begin{macrocode} |
| 576 |
%<*package> |
| 577 |
\tl_gset:Nn \g_@@_struct_stack_current_tl {1} |
| 578 |
% \end{macrocode} |
| 579 |
% \begin{macro}{\@@_pdf_name_e:n} |
| 580 |
% \begin{macrocode} |
| 581 |
\cs_new:Npn \@@_pdf_name_e:n #1{\pdf_name_from_unicode_e:n{#1}} |
| 582 |
%</package> |
| 583 |
% \end{macrocode} |
| 584 |
% \end{macro} |
| 585 |
% |
| 586 |
% \begin{variable}{g_@@_struct_1_prop,g_@@_struct_kids_1_seq} |
| 587 |
% \begin{macrocode} |
| 588 |
%<*package> |
| 589 |
\@@_prop_new:c { g_@@_struct_1_prop } |
| 590 |
\@@_seq_new:c { g_@@_struct_kids_1_seq } |
| 591 |
|
| 592 |
\@@_struct_prop_gput:nne |
| 593 |
{ 1 } |
| 594 |
{ Type } |
| 595 |
{ \pdf_name_from_unicode_e:n {StructTreeRoot} } |
| 596 |
|
| 597 |
\@@_struct_prop_gput:nne |
| 598 |
{ 1 } |
| 599 |
{ S } |
| 600 |
{ \pdf_name_from_unicode_e:n {StructTreeRoot} } |
| 601 |
|
| 602 |
\@@_struct_prop_gput:nne |
| 603 |
{ 1 } |
| 604 |
{ tag } |
| 605 |
{ {StructTreeRoot}{pdf} } |
| 606 |
|
| 607 |
\@@_struct_prop_gput:nne |
| 608 |
{ 1 } |
| 609 |
{ rolemap } |
| 610 |
{ {StructTreeRoot}{pdf} } |
| 611 |
|
| 612 |
\@@_struct_prop_gput:nne |
| 613 |
{ 1 } |
| 614 |
{ parentrole } |
| 615 |
{ {StructTreeRoot}{pdf} } |
| 616 |
|
| 617 |
% \end{macrocode} |
| 618 |
% Namespaces are pdf 2.0. |
| 619 |
% If the code moves into the kernel, the setting must be probably delayed. |
| 620 |
% \begin{macrocode} |
| 621 |
\pdf_version_compare:NnF < {2.0} |
| 622 |
{ |
| 623 |
\@@_struct_prop_gput:nne |
| 624 |
{ 1 } |
| 625 |
{ Namespaces } |
| 626 |
{ \pdf_object_ref:n { @@/tree/namespaces } } |
| 627 |
} |
| 628 |
%</package> |
| 629 |
% \end{macrocode} |
| 630 |
% In debug mode we have to copy the root manually as it is already setup: |
| 631 |
% \begin{macrocode} |
| 632 |
%<debug>\prop_new:c { g_@@_struct_debug_1_prop } |
| 633 |
%<debug>\seq_new:c { g_@@_struct_debug_kids_1_seq } |
| 634 |
%<debug>\prop_gset_eq:cc { g_@@_struct_debug_1_prop }{ g_@@_struct_1_prop } |
| 635 |
%<debug>\prop_gremove:cn { g_@@_struct_debug_1_prop }{Namespaces} |
| 636 |
% \end{macrocode} |
| 637 |
% \end{variable} |
| 638 |
% |
| 639 |
% \subsection{Adding the /ID key} |
| 640 |
% Every structure gets automatically an ID which is currently |
| 641 |
% simply calculated from the structure number. |
| 642 |
% \begin{macro}{\@@_struct_get_id:n} |
| 643 |
% \begin{macrocode} |
| 644 |
%<*package> |
| 645 |
\cs_new:Npn \@@_struct_get_id:n #1 %#1=struct num |
| 646 |
{ |
| 647 |
( |
| 648 |
ID. |
| 649 |
\prg_replicate:nn |
| 650 |
{ \int_abs:n{\g_@@_tree_id_pad_int - \tl_count:e { \int_to_arabic:n { #1 } }} } |
| 651 |
{ 0 } |
| 652 |
\int_to_arabic:n { #1 } |
| 653 |
) |
| 654 |
} |
| 655 |
% \end{macrocode} |
| 656 |
% \end{macro} |
| 657 |
% |
| 658 |
% \subsection{Filling in the tag info} |
| 659 |
|
| 660 |
% \begin{macro}{\@@_struct_set_tag_info:nnn } |
| 661 |
% This adds or updates the tag info to a structure given by a number. |
| 662 |
% We need also the original data, so we store both. |
| 663 |
% \begin{macrocode} |
| 664 |
\pdf_version_compare:NnTF < {2.0} |
| 665 |
{ |
| 666 |
\cs_new_protected:Npn \@@_struct_set_tag_info:nnn #1 #2 #3 |
| 667 |
%#1 structure number, #2 tag, #3 NS |
| 668 |
{ |
| 669 |
\@@_struct_prop_gput:nne |
| 670 |
{ #1 } |
| 671 |
{ S } |
| 672 |
{ \pdf_name_from_unicode_e:n {#2} } % |
| 673 |
\@@_struct_prop_gput:nnn |
| 674 |
{ #1 } |
| 675 |
{ tag } |
| 676 |
{ {#2} {} } |
| 677 |
} |
| 678 |
} |
| 679 |
{ |
| 680 |
\cs_new_protected:Npn \@@_struct_set_tag_info:nnn #1 #2 #3 |
| 681 |
{ |
| 682 |
\@@_struct_prop_gput:nne |
| 683 |
{ #1 } |
| 684 |
{ S } |
| 685 |
{ \pdf_name_from_unicode_e:n {#2} } % |
| 686 |
\prop_get:NnNT \g_@@_role_NS_prop {#3} \l_@@_get_tmpc_tl |
| 687 |
{ |
| 688 |
\@@_struct_prop_gput:nne |
| 689 |
{ #1 } |
| 690 |
{ NS } |
| 691 |
{ \l_@@_get_tmpc_tl } % |
| 692 |
} |
| 693 |
\@@_struct_prop_gput:nnn |
| 694 |
{ #1 } |
| 695 |
{ tag } |
| 696 |
{ {#2} {#3} } |
| 697 |
} |
| 698 |
} |
| 699 |
\cs_generate_variant:Nn \@@_struct_set_tag_info:nnn {eoo} |
| 700 |
% \end{macrocode} |
| 701 |
% \end{macro} |
| 702 |
% |
| 703 |
% \begin{macro}{\@@_struct_get_role:nnNN} |
| 704 |
% We also need a way to get the tag info needed for parent child |
| 705 |
% check from parent structures. |
| 706 |
% The tag info is stored as the value of the rolemap key, but for |
| 707 |
% \enquote{transparent} structures we also have to look into parentrole key. |
| 708 |
% |
| 709 |
% \begin{macrocode} |
| 710 |
\cs_new_protected:Npn \@@_struct_get_role:nnNN #1 #2 #3 #4 |
| 711 |
%#1 :struct num, |
| 712 |
%#2 :rolemap or parentrole |
| 713 |
%#3 :tlvar for tag (rolemapped) |
| 714 |
%#4 :tlvar for NS (rolemapped, so standard or empty or UNKNOWN) |
| 715 |
{ |
| 716 |
\prop_get:cnNTF |
| 717 |
{ g_@@_struct_#1_prop } |
| 718 |
{ #2 } |
| 719 |
\l_@@_get_tmpc_tl |
| 720 |
{ |
| 721 |
\tl_set:Ne #3{\exp_last_unbraced:No\use_i:nn { \l_@@_get_tmpc_tl }} |
| 722 |
\tl_set:Ne #4{\exp_last_unbraced:No\use_ii:nn { \l_@@_get_tmpc_tl }} |
| 723 |
} |
| 724 |
{ |
| 725 |
\tl_clear:N#3 |
| 726 |
\tl_clear:N#4 |
| 727 |
} |
| 728 |
} |
| 729 |
\cs_generate_variant:Nn\@@_struct_get_role:nnNN {enNN} |
| 730 |
% \end{macrocode} |
| 731 |
% \end{macro} |
| 732 |
% \subsection{Handlings kids} |
| 733 |
% Commands to store the kids. Kids in a structure can be a reference to a mc-chunk, |
| 734 |
% an object reference to another structure element, or a object reference to an |
| 735 |
% annotation (through an OBJR object). |
| 736 |
% \begin{macro}{\@@_struct_kid_mc_gput_right:nn,\@@_struct_kid_mc_gput_right:ne} |
| 737 |
% The command to store an mc-chunk, this is a dictionary of type MCR. |
| 738 |
% It would be possible to write out the content directly as unnamed object |
| 739 |
% and to store only the object reference, but probably this would be slower, |
| 740 |
% and the PDF is more readable like this. |
| 741 |
% The code doesn't try to avoid the use of the /Pg key by checking page numbers. |
| 742 |
% That imho only slows down without much gain. |
| 743 |
% In generic mode the page break code will perhaps to have to insert |
| 744 |
% an additional mcid after an existing one. For this we use a property list |
| 745 |
% At first an auxiliary to write the MCID dict. This should normally be expanded! |
| 746 |
% \begin{macrocode} |
| 747 |
\cs_new:Npn \@@_struct_mcid_dict:n #1 %#1 MCID absnum |
| 748 |
{ |
| 749 |
<< |
| 750 |
/Type \c_space_tl /MCR \c_space_tl |
| 751 |
/Pg |
| 752 |
\c_space_tl |
| 753 |
\pdf_pageobject_ref:n { \property_ref:enn{mcid-#1}{tagabspage}{1} } |
| 754 |
/MCID \c_space_tl \property_ref:enn{mcid-#1}{tagmcid}{1} |
| 755 |
>> |
| 756 |
} |
| 757 |
%</package> |
| 758 |
% \end{macrocode} |
| 759 |
% \begin{macrocode} |
| 760 |
%<*package|debug> |
| 761 |
%<package>\cs_new_protected:Npn \@@_struct_kid_mc_gput_right:nn #1 #2 |
| 762 |
%<debug>\cs_set_protected:Npn \@@_struct_kid_mc_gput_right:nn #1 #2 |
| 763 |
%#1 structure num, #2 MCID absnum% |
| 764 |
{ |
| 765 |
\@@_seq_gput_right:ce |
| 766 |
{ g_@@_struct_kids_#1_seq } |
| 767 |
{ |
| 768 |
\@@_struct_mcid_dict:n {#2} |
| 769 |
} |
| 770 |
%<debug> \seq_gput_right:cn |
| 771 |
%<debug> { g_@@_struct_debug_kids_#1_seq } |
| 772 |
%<debug> { |
| 773 |
%<debug> MC~#2 |
| 774 |
%<debug> } |
| 775 |
\@@_seq_gput_right:cn |
| 776 |
{ g_@@_struct_kids_#1_seq } |
| 777 |
{ |
| 778 |
\prop_item:Nn \g_@@_struct_cont_mc_prop {#2} |
| 779 |
} |
| 780 |
} |
| 781 |
%<package>\cs_generate_variant:Nn \@@_struct_kid_mc_gput_right:nn {ne} |
| 782 |
% \end{macrocode} |
| 783 |
% \end{macro} |
| 784 |
% \begin{macro} |
| 785 |
% { |
| 786 |
% \@@_struct_kid_struct_gput_right:nn,\@@_struct_kid_struct_gput_right:ee |
| 787 |
% } |
| 788 |
% This commands adds a structure as kid. We only need to record the object |
| 789 |
% reference in the sequence. |
| 790 |
% \begin{macrocode} |
| 791 |
%<package>\cs_new_protected:Npn\@@_struct_kid_struct_gput_right:nn #1 #2 |
| 792 |
%<debug>\cs_set_protected:Npn\@@_struct_kid_struct_gput_right:nn #1 #2 |
| 793 |
%%#1 num of parent struct, #2 kid struct |
| 794 |
{ |
| 795 |
\@@_seq_gput_right:ce |
| 796 |
{ g_@@_struct_kids_#1_seq } |
| 797 |
{ |
| 798 |
\pdf_object_ref_indexed:nn { @@/struct }{ #2 } |
| 799 |
} |
| 800 |
%<debug> \seq_gput_right:cn |
| 801 |
%<debug> { g_@@_struct_debug_kids_#1_seq } |
| 802 |
%<debug> { |
| 803 |
%<debug> Struct~#2 |
| 804 |
%<debug> } |
| 805 |
} |
| 806 |
%<package>\cs_generate_variant:Nn \@@_struct_kid_struct_gput_right:nn {ee} |
| 807 |
% \end{macrocode} |
| 808 |
% \end{macro} |
| 809 |
% \begin{macro} |
| 810 |
% { |
| 811 |
% \@@_struct_kid_struct_gput_left:nn,\@@_struct_kid_struct_gput_left:ee |
| 812 |
% } |
| 813 |
% This commands adds a structure as kid one the left, so as first |
| 814 |
% kid. We only need to record the object reference in the sequence. |
| 815 |
% \begin{macrocode} |
| 816 |
%<package>\cs_new_protected:Npn\@@_struct_kid_struct_gput_left:nn #1 #2 |
| 817 |
%<debug>\cs_set_protected:Npn\@@_struct_kid_struct_gput_left:nn #1 #2 |
| 818 |
%%#1 num of parent struct, #2 kid struct |
| 819 |
{ |
| 820 |
\@@_seq_gput_left:ce |
| 821 |
{ g_@@_struct_kids_#1_seq } |
| 822 |
{ |
| 823 |
\pdf_object_ref_indexed:nn { @@/struct }{ #2 } |
| 824 |
} |
| 825 |
%<debug> \seq_gput_left:cn |
| 826 |
%<debug> { g_@@_struct_debug_kids_#1_seq } |
| 827 |
%<debug> { |
| 828 |
%<debug> Struct~#2 |
| 829 |
%<debug> } |
| 830 |
} |
| 831 |
%<package>\cs_generate_variant:Nn \@@_struct_kid_struct_gput_left:nn {ee} |
| 832 |
% \end{macrocode} |
| 833 |
% \end{macro} |
| 834 |
% |
| 835 |
% \begin{macro} |
| 836 |
% {\@@_struct_kid_OBJR_gput_right:nnn,\@@_struct_kid_OBJR_gput_right:eee} |
| 837 |
% At last the command to add an OBJR object. This has to write an object first. |
| 838 |
% The first argument is the number of the parent structure, the second the |
| 839 |
% (expanded) object reference of the annotation. The last argument is the page |
| 840 |
% object reference |
| 841 |
% |
| 842 |
% \begin{macrocode} |
| 843 |
%<package>\cs_new_protected:Npn\@@_struct_kid_OBJR_gput_right:nnn #1 #2 #3 |
| 844 |
%<package> |
| 845 |
%<package> |
| 846 |
%<debug>\cs_set_protected:Npn\@@_struct_kid_OBJR_gput_right:nnn #1 #2 #3 |
| 847 |
%%#1 num of parent struct,#2 obj reference,#3 page object reference |
| 848 |
{ |
| 849 |
\pdf_object_unnamed_write:nn |
| 850 |
{ dict } |
| 851 |
{ |
| 852 |
/Type/OBJR/Obj~#2/Pg~#3 |
| 853 |
} |
| 854 |
\@@_seq_gput_right:ce |
| 855 |
{ g_@@_struct_kids_#1_seq } |
| 856 |
{ |
| 857 |
\pdf_object_ref_last: |
| 858 |
} |
| 859 |
%<debug> \seq_gput_right:ce |
| 860 |
%<debug> { g_@@_struct_debug_kids_#1_seq } |
| 861 |
%<debug> { |
| 862 |
%<debug> OBJR~reference |
| 863 |
%<debug> } |
| 864 |
} |
| 865 |
%</package|debug> |
| 866 |
%<*package> |
| 867 |
\cs_generate_variant:Nn\@@_struct_kid_OBJR_gput_right:nnn { eee } |
| 868 |
% \end{macrocode} |
| 869 |
% \end{macro} |
| 870 |
% \begin{macro} |
| 871 |
% {\@@_struct_exchange_kid_command:N, \@@_struct_exchange_kid_command:c} |
| 872 |
% In luamode it can happen that a single kid in a structure is split at a page |
| 873 |
% break into two or more mcid. In this case the lua code has to convert |
| 874 |
% put the dictionary of the kid into an array. See issue 13 at tagpdf repo. |
| 875 |
% We exchange the dummy command for the kids to mark this case. |
| 876 |
% Change 2024-03-19: don't use a regex - that is slow. |
| 877 |
% \begin{macrocode} |
| 878 |
\cs_new_protected:Npn\@@_struct_exchange_kid_command:N #1 %#1 = seq var |
| 879 |
{ |
| 880 |
\seq_gpop_left:NN #1 \l_@@_tmpa_tl |
| 881 |
\tl_replace_once:Nnn \l_@@_tmpa_tl |
| 882 |
{\@@_mc_insert_mcid_kids:n} |
| 883 |
{\@@_mc_insert_mcid_single_kids:n} |
| 884 |
\seq_gput_left:No #1 { \l_@@_tmpa_tl } |
| 885 |
} |
| 886 |
|
| 887 |
\cs_generate_variant:Nn\@@_struct_exchange_kid_command:N { c } |
| 888 |
% \end{macrocode} |
| 889 |
% \end{macro} |
| 890 |
% \begin{macro}{ \@@_struct_fill_kid_key:n } |
| 891 |
% This command adds the kid info to the K entry. In lua mode the |
| 892 |
% content contains commands which are expanded later. The argument is the structure |
| 893 |
% number. |
| 894 |
% |
| 895 |
% \begin{macrocode} |
| 896 |
\cs_new_protected:Npn \@@_struct_fill_kid_key:n #1 %#1 is the struct num |
| 897 |
{ |
| 898 |
\bool_if:NF \g_@@_mode_lua_bool |
| 899 |
{ |
| 900 |
\seq_clear:N \l_@@_tmpa_seq |
| 901 |
\seq_map_inline:cn { g_@@_struct_kids_#1_seq } |
| 902 |
{ \seq_put_right:Ne \l_@@_tmpa_seq { ##1 } } |
| 903 |
%\seq_show:c { g_@@_struct_kids_#1_seq } |
| 904 |
%\seq_show:N \l_@@_tmpa_seq |
| 905 |
\seq_remove_all:Nn \l_@@_tmpa_seq {} |
| 906 |
%\seq_show:N \l_@@_tmpa_seq |
| 907 |
\seq_gset_eq:cN { g_@@_struct_kids_#1_seq } \l_@@_tmpa_seq |
| 908 |
} |
| 909 |
|
| 910 |
\int_case:nnF |
| 911 |
{ |
| 912 |
\seq_count:c |
| 913 |
{ |
| 914 |
g_@@_struct_kids_#1_seq |
| 915 |
} |
| 916 |
} |
| 917 |
{ |
| 918 |
{ 0 } |
| 919 |
{ } %no kids, do nothing |
| 920 |
{ 1 } % 1 kid, insert |
| 921 |
{ |
| 922 |
% in this case we need a special command in |
| 923 |
% luamode to get the array right. See issue #13 |
| 924 |
\sys_if_engine_luatex:TF |
| 925 |
{ |
| 926 |
\@@_struct_exchange_kid_command:c |
| 927 |
{g_@@_struct_kids_#1_seq} |
| 928 |
% \end{macrocode} |
| 929 |
% check if we get null |
| 930 |
% \begin{macrocode} |
| 931 |
\tl_set:Ne\l_@@_tmpa_tl |
| 932 |
{\use:e{\seq_item:cn {g__tag_struct_kids_#1_seq} {1}}} |
| 933 |
\tl_if_eq:NNF\l__tag_tmpa_tl \c_@@_struct_null_tl |
| 934 |
{ |
| 935 |
\@@_struct_prop_gput:nne |
| 936 |
{#1} |
| 937 |
{K} |
| 938 |
{ |
| 939 |
\seq_item:cn |
| 940 |
{ |
| 941 |
g_@@_struct_kids_#1_seq |
| 942 |
} |
| 943 |
{1} |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
{ |
| 948 |
\@@_struct_prop_gput:nne |
| 949 |
{#1} |
| 950 |
{K} |
| 951 |
{ |
| 952 |
\seq_item:cn |
| 953 |
{ |
| 954 |
g_@@_struct_kids_#1_seq |
| 955 |
} |
| 956 |
{1} |
| 957 |
} |
| 958 |
} |
| 959 |
} % |
| 960 |
} |
| 961 |
{ %many kids, use an array |
| 962 |
\@@_struct_prop_gput:nne |
| 963 |
{#1} |
| 964 |
{K} |
| 965 |
{ |
| 966 |
[ |
| 967 |
\seq_use:cn |
| 968 |
{ |
| 969 |
g_@@_struct_kids_#1_seq |
| 970 |
} |
| 971 |
{ |
| 972 |
\c_space_tl |
| 973 |
} |
| 974 |
] |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
|
| 979 |
% \end{macrocode} |
| 980 |
% \end{macro} |
| 981 |
% \subsection{Output of the object} |
| 982 |
% \begin{macro}{\@@_struct_get_dict_content:nN} |
| 983 |
% This maps the dictionary content of a structure into a tl-var. |
| 984 |
% Basically it does what |\pdfdict_use:n| does. |
| 985 |
% This is used a lot so should be rather fast. |
| 986 |
% \begin{macrocode} |
| 987 |
\cs_new_protected:Npn \@@_struct_get_dict_content:nN #1 #2 %#1: structure num |
| 988 |
{ |
| 989 |
\tl_clear:N #2 |
| 990 |
\prop_map_inline:cn { g_@@_struct_#1_prop } |
| 991 |
{ |
| 992 |
% \end{macrocode} |
| 993 |
% Some keys needs the option to format the value, e.g. add brackets for an |
| 994 |
% array, we also need the option to ignore some entries in the properties. |
| 995 |
% \begin{macrocode} |
| 996 |
\cs_if_exist_use:cTF {@@_struct_format_##1:nnN} |
| 997 |
{ |
| 998 |
{##1}{##2}#2 |
| 999 |
} |
| 1000 |
{ |
| 1001 |
\tl_put_right:Ne #2 { \c_space_tl/##1~##2 } |
| 1002 |
} |
| 1003 |
} |
| 1004 |
} |
| 1005 |
% \end{macrocode} |
| 1006 |
% \end{macro} |
| 1007 |
% |
| 1008 |
% \begin{macro}{\@@_struct_format_rolemap:nnN,\@@_struct_format_parentrole:nnN, |
| 1009 |
% \@@_struct_format_P:nnN,\@@_struct_format_tag:nnN} |
| 1010 |
% This three entries should not end in the PDF. |
| 1011 |
% Todo: check if the S/NS keys can be dropped and replaced by a processing of the tag key. |
| 1012 |
% \begin{macrocode} |
| 1013 |
\cs_new:Nn\@@_struct_format_rolemap:nnN{} |
| 1014 |
\cs_new:Nn\@@_struct_format_parentrole:nnN{} |
| 1015 |
\cs_new:Nn\@@_struct_format_tag:nnN{} |
| 1016 |
% \end{macrocode} |
| 1017 |
% \end{macro} |
| 1018 |
% \begin{macro}{\@@_struct_format_parentnum:nnN} |
| 1019 |
% parent is a structure number and |
| 1020 |
% should expand to the object reference. |
| 1021 |
% \begin{macrocode} |
| 1022 |
\cs_new_protected:Nn\@@_struct_format_parentnum:nnN |
| 1023 |
{ |
| 1024 |
\tl_put_right:Ne #3 { ~/P~\pdf_object_ref_indexed:nn { @@/struct} { #2 } } |
| 1025 |
} |
| 1026 |
% \end{macrocode} |
| 1027 |
% \end{macro} |
| 1028 |
% \begin{macro}{\@@_struct_format_Ref:nnN} |
| 1029 |
% Ref is an array, we store values as a clist of commands that must |
| 1030 |
% be executed here, the formatting has to add also brackets. |
| 1031 |
% |
| 1032 |
% \begin{macrocode} |
| 1033 |
\cs_new_protected:Nn\@@_struct_format_Ref:nnN |
| 1034 |
{ |
| 1035 |
\tl_put_right:Nn #3 { ~/#1~[ } %] |
| 1036 |
\clist_map_inline:nn{ #2 } |
| 1037 |
{ |
| 1038 |
##1 #3 |
| 1039 |
} |
| 1040 |
\tl_put_right:Nn #3 |
| 1041 |
{ %[ |
| 1042 |
\c_space_tl] |
| 1043 |
} |
| 1044 |
} |
| 1045 |
% \end{macrocode} |
| 1046 |
% \end{macro} |
| 1047 |
% \begin{macro}{\@@_struct_write_obj:n} |
| 1048 |
% This writes out the structure object. |
| 1049 |
% This is done in the finish code, in the tree module and |
| 1050 |
% guarded by the tree boolean. |
| 1051 |
% \begin{macrocode} |
| 1052 |
\cs_new_protected:Npn \@@_struct_write_obj:n #1 % #1 is the struct num |
| 1053 |
{ |
| 1054 |
\prop_if_exist:cTF { g_@@_struct_#1_prop } |
| 1055 |
{ |
| 1056 |
% \end{macrocode} |
| 1057 |
% It can happen that a structure is not used and so has not parent. |
| 1058 |
% Simply ignoring it is problematic as it is also recorded in |
| 1059 |
% the IDTree, so we make an artifact out of it. |
| 1060 |
% \begin{macrocode} |
| 1061 |
\prop_get:cnNF { g_@@_struct_#1_prop } {parentnum}\l_@@_tmpb_tl |
| 1062 |
{ |
| 1063 |
% \prop_gput:cne { g_@@_struct_#1_prop } {P} |
| 1064 |
% {\pdf_object_ref_indexed:nn { @@/struct }{1}} |
| 1065 |
\prop_gput:cne { g_@@_struct_#1_prop } {parentnum}{2} |
| 1066 |
\prop_gput:cne { g_@@_struct_#1_prop } {S}{/Artifact} |
| 1067 |
\seq_if_empty:cF {g_@@_struct_kids_#1_seq} |
| 1068 |
{ |
| 1069 |
\msg_warning:nnee |
| 1070 |
{tag} |
| 1071 |
{struct-orphan} |
| 1072 |
{ #1 } |
| 1073 |
{\seq_count:c{g_@@_struct_kids_#1_seq}} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
\@@_struct_fill_kid_key:n { #1 } |
| 1077 |
\@@_struct_get_dict_content:nN { #1 } \l_@@_tmpa_tl |
| 1078 |
\pdf_object_write_indexed:nnne |
| 1079 |
{ @@/struct }{ #1 } |
| 1080 |
{dict} |
| 1081 |
{ |
| 1082 |
\l_@@_tmpa_tl\c_space_tl |
| 1083 |
/ID~\@@_struct_get_id:n{#1} |
| 1084 |
} |
| 1085 |
|
| 1086 |
} |
| 1087 |
{ |
| 1088 |
\msg_error:nnn { tag } { struct-no-objnum } { #1} |
| 1089 |
} |
| 1090 |
} |
| 1091 |
% \end{macrocode} |
| 1092 |
% \end{macro} |
| 1093 |
% \begin{macro}{\@@_struct_insert_annot:nn} |
| 1094 |
% This is the command to insert an annotation into the structure. |
| 1095 |
% It can probably be used for xform too. |
| 1096 |
% |
| 1097 |
% Annotations used as structure content must |
| 1098 |
% \begin{enumerate} |
| 1099 |
% \item add a StructParent integer to their dictionary |
| 1100 |
% \item push the object reference as OBJR object in the structure |
| 1101 |
% \item Add a Structparent/obj-nr reference to the parent tree. |
| 1102 |
% \end{enumerate} |
| 1103 |
% For a link this looks like this |
| 1104 |
% \begin{verbatim} |
| 1105 |
% \tag_struct_begin:n { tag=Link } |
| 1106 |
% \tag_mc_begin:n { tag=Link } |
| 1107 |
% (1) \pdfannot_dict_put:nne |
| 1108 |
% { link/URI } |
| 1109 |
% { StructParent } |
| 1110 |
% { \int_use:N\c@g_@@_parenttree_obj_int } |
| 1111 |
% <start link> link text <stop link> |
| 1112 |
% (2+3) \@@_struct_insert_annot:nn {obj ref}{parent num} |
| 1113 |
% \tag_mc_end: |
| 1114 |
% \tag_struct_end: |
| 1115 |
% \end{verbatim} |
| 1116 |
% \begin{macrocode} |
| 1117 |
\cs_new_protected:Npn \@@_struct_insert_annot:nn #1 #2 |
| 1118 |
%#1 object reference to the annotation/xform |
| 1119 |
%#2 structparent number |
| 1120 |
{ |
| 1121 |
\bool_if:NT \g_@@_active_struct_bool |
| 1122 |
{ |
| 1123 |
%get the number of the parent structure: |
| 1124 |
\seq_get:NNF |
| 1125 |
\g_@@_struct_stack_seq |
| 1126 |
\l_@@_struct_stack_parent_tmpa_tl |
| 1127 |
{ |
| 1128 |
\msg_error:nn { tag } { struct-faulty-nesting } |
| 1129 |
} |
| 1130 |
%put the obj number of the annot in the kid entry, this also creates |
| 1131 |
%the OBJR object |
| 1132 |
\@@_property_record:nn {@tag@objr@page@#2 }{ tagabspage } |
| 1133 |
\@@_struct_kid_OBJR_gput_right:eee |
| 1134 |
{ |
| 1135 |
\l_@@_struct_stack_parent_tmpa_tl |
| 1136 |
} |
| 1137 |
{ |
| 1138 |
#1 % |
| 1139 |
} |
| 1140 |
{ |
| 1141 |
\pdf_pageobject_ref:n |
| 1142 |
{ \property_ref:nnn {@tag@objr@page@#2 }{ tagabspage }{1} } |
| 1143 |
} |
| 1144 |
% add the parent obj number to the parent tree: |
| 1145 |
% the command always expands its arguments! |
| 1146 |
\@@_parenttree_add_objr:nn |
| 1147 |
{ |
| 1148 |
#2 |
| 1149 |
} |
| 1150 |
{ |
| 1151 |
\pdf_object_ref_indexed:nn |
| 1152 |
{ @@/struct }{ \l_@@_struct_stack_parent_tmpa_tl } |
| 1153 |
} |
| 1154 |
% increase the int: |
| 1155 |
\int_gincr:N \c@g_@@_parenttree_obj_int |
| 1156 |
} |
| 1157 |
} |
| 1158 |
% \end{macrocode} |
| 1159 |
% \end{macro} |
| 1160 |
% |
| 1161 |
% \begin{macro}{\@@_struct_insert_annot_shipout:nnn} |
| 1162 |
% This command is similar to the previous one but is meant to be used at shipout |
| 1163 |
% (currently only sensible for luatex). |
| 1164 |
% To move the OBJR into the right structure it has to get the structure number |
| 1165 |
% additionally as argument. But as it is used at shipout it doesn't need a label |
| 1166 |
% to get the page reference but can use \cs{g_shipout_readonly_int}. |
| 1167 |
% It does \emph{not} increase the parenttree integer (timing is wrong in |
| 1168 |
% lua), instead code using the command has to do it. See the lua code. |
| 1169 |
% \begin{macrocode} |
| 1170 |
\cs_new_protected:Npn\@@_struct_insert_annot_shipout:nnn #1#2#3 |
| 1171 |
% #1 structnum, #2 object reference, #3 StructParentNum |
| 1172 |
{ |
| 1173 |
\@@_struct_kid_OBJR_gput_right:eee |
| 1174 |
{ |
| 1175 |
#1 |
| 1176 |
} |
| 1177 |
{ |
| 1178 |
#2 |
| 1179 |
} |
| 1180 |
{ |
| 1181 |
\pdf_pageobject_ref:n |
| 1182 |
{ \int_use:N \g_shipout_readonly_int } % |
| 1183 |
} |
| 1184 |
% add the parent obj number to the parent tree: |
| 1185 |
% the command always expands its arguments! |
| 1186 |
\@@_parenttree_add_objr:nn |
| 1187 |
{ |
| 1188 |
#3 |
| 1189 |
} |
| 1190 |
{ |
| 1191 |
\pdf_object_ref_indexed:nn |
| 1192 |
{ @@/struct }{ #1 } |
| 1193 |
} |
| 1194 |
} |
| 1195 |
% \end{macrocode} |
| 1196 |
% \end{macro} |
| 1197 |
% \begin{macro}{\@@_get_data_struct_tag:} |
| 1198 |
% this command allows \cs{tag_get:n} to get the current |
| 1199 |
% structure tag with the keyword |struct_tag|. |
| 1200 |
% \begin{macrocode} |
| 1201 |
\cs_new:Npn \@@_get_data_struct_tag: |
| 1202 |
{ |
| 1203 |
\exp_args:Ne |
| 1204 |
\tl_tail:n |
| 1205 |
{ |
| 1206 |
\prop_item:cn {g_@@_struct_\g_@@_struct_stack_current_tl _prop}{S} |
| 1207 |
} |
| 1208 |
} |
| 1209 |
% \end{macrocode} |
| 1210 |
% \end{macro} |
| 1211 |
% |
| 1212 |
% \begin{macro}{\@@_get_data_struct_id:} |
| 1213 |
% this command allows \cs{tag_get:n} to get the current |
| 1214 |
% structure id with the keyword |struct_id|. |
| 1215 |
% \begin{macrocode} |
| 1216 |
\cs_new:Npn \@@_get_data_struct_id: |
| 1217 |
{ |
| 1218 |
\@@_struct_get_id:n {\g_@@_struct_stack_current_tl} |
| 1219 |
} |
| 1220 |
%</package> |
| 1221 |
% \end{macrocode} |
| 1222 |
% \end{macro} |
| 1223 |
% |
| 1224 |
% \begin{macro}{\@@_get_data_struct_num:} |
| 1225 |
% this command allows \cs{tag_get:n} to get the current |
| 1226 |
% structure number with the keyword |struct_num|. We will need to handle nesting |
| 1227 |
% \begin{macrocode} |
| 1228 |
%<*base> |
| 1229 |
\cs_new:Npn \@@_get_data_struct_num: |
| 1230 |
{ |
| 1231 |
\g_@@_struct_stack_current_tl |
| 1232 |
} |
| 1233 |
%</base> |
| 1234 |
% \end{macrocode} |
| 1235 |
% \end{macro} |
| 1236 |
% |
| 1237 |
% \begin{macro}{\@@_get_data_struct_counter:} |
| 1238 |
% this command allows \cs{tag_get:n} to get the current |
| 1239 |
% state of the structure counter with the keyword |struct_counter|. |
| 1240 |
% By comparing the numbers it can be used to check the number of |
| 1241 |
% structure commands in a piece of code. |
| 1242 |
% \begin{macrocode} |
| 1243 |
%<*base> |
| 1244 |
\cs_new:Npn \@@_get_data_struct_counter: |
| 1245 |
{ |
| 1246 |
\int_use:N \c@g_@@_struct_abs_int |
| 1247 |
} |
| 1248 |
%</base> |
| 1249 |
% \end{macrocode} |
| 1250 |
% \end{macro} |
| 1251 |
% |
| 1252 |
% \subsection{Commands for the parent-child checks} |
| 1253 |
% |
| 1254 |
% \begin{macro}{\@@_struct_check_parent_child_aux:nnnnN} |
| 1255 |
% \begin{macrocode} |
| 1256 |
%<*package> |
| 1257 |
\cs_new_protected:Npn \@@_struct_check_parent_child_aux:nnnnN #1#2#3#4#5 |
| 1258 |
{ |
| 1259 |
% #1 structure number of parent |
| 1260 |
% #2 key to use to retrieve role of parent (either rolemap or parentrole field) |
| 1261 |
% #3 structure number of parent |
| 1262 |
% #4 key to use to retrieve role of child (either rolemap or parentrole field) |
| 1263 |
% #5 tl for return value |
| 1264 |
% \end{macrocode} |
| 1265 |
% get parent rolemap |
| 1266 |
% \begin{macrocode} |
| 1267 |
\@@_struct_get_role:nnNN |
| 1268 |
{#1} |
| 1269 |
{#2} |
| 1270 |
\l_@@_get_parent_tmpa_tl |
| 1271 |
\l_@@_get_parent_tmpb_tl |
| 1272 |
% \end{macrocode} |
| 1273 |
% get child rolemap |
| 1274 |
% \begin{macrocode} |
| 1275 |
\@@_struct_get_role:nnNN |
| 1276 |
{#3} |
| 1277 |
{#4} |
| 1278 |
\l_@@_get_child_tmpa_tl |
| 1279 |
\l_@@_get_child_tmpb_tl |
| 1280 |
% \end{macrocode} |
| 1281 |
% check |
| 1282 |
% \begin{macrocode} |
| 1283 |
\@@_role_check_parent_child:ooooN |
| 1284 |
{ \l_@@_get_parent_tmpa_tl } % rolemapped from above |
| 1285 |
{ \l_@@_get_parent_tmpb_tl } % rolemapped from above |
| 1286 |
{ \l_@@_get_child_tmpa_tl } % |
| 1287 |
{ \l_@@_get_child_tmpb_tl } % |
| 1288 |
#5 |
| 1289 |
} |
| 1290 |
% \end{macrocode} |
| 1291 |
% \end{macro} |
| 1292 |
% |
| 1293 |
% \begin{macro}{\@@_struct_check_parent_child:nn} |
| 1294 |
% When comparing the relation between structures we use the structure |
| 1295 |
% numbers. |
| 1296 |
% \begin{macrocode} |
| 1297 |
\cs_new_protected:Npn \@@_struct_check_parent_child:nn #1 #2 |
| 1298 |
% #1 structure number of parent |
| 1299 |
% #2 structure number of child. % |
| 1300 |
% This assumes that the fields rolemap/parentrole has already been filled. |
| 1301 |
{ |
| 1302 |
% \end{macrocode} |
| 1303 |
% This records if logging is on |
| 1304 |
% \begin{macrocode} |
| 1305 |
\int_compare:nNnT {\l_@@_loglevel_int} > { 0 } |
| 1306 |
{ |
| 1307 |
\prop_get:cnN{g_@@_struct_#1_prop}{tag}\l_@@_get_parent_tmpa_tl |
| 1308 |
\prop_get:cnN{g_@@_struct_#2_prop}{tag}\l_@@_get_parent_tmpb_tl |
| 1309 |
\msg_note:nnee |
| 1310 |
{ tag } |
| 1311 |
{ role-parent-child-check } |
| 1312 |
{ |
| 1313 |
\quark_if_no_value:NTF \l__tag_get_parent_tmpa_tl |
| 1314 |
{??} |
| 1315 |
{ |
| 1316 |
\exp_last_unbraced:No\use_ii:nn |
| 1317 |
{ \l_@@_get_parent_tmpa_tl } |
| 1318 |
: |
| 1319 |
\exp_last_unbraced:No\use_i:nn |
| 1320 |
{ \l_@@_get_parent_tmpa_tl } |
| 1321 |
} |
| 1322 |
} |
| 1323 |
{ |
| 1324 |
\quark_if_no_value:NTF \l__tag_get_parent_tmpb_tl |
| 1325 |
{??} |
| 1326 |
{ |
| 1327 |
\exp_last_unbraced:No\use_ii:nn |
| 1328 |
{ \l_@@_get_parent_tmpb_tl } |
| 1329 |
: |
| 1330 |
\exp_last_unbraced:No\use_i:nn |
| 1331 |
{ \l_@@_get_parent_tmpb_tl } |
| 1332 |
} |
| 1333 |
} |
| 1334 |
} |
| 1335 |
\@@_struct_check_parent_child_aux:nnnnN |
| 1336 |
{#1} |
| 1337 |
{rolemap} |
| 1338 |
{#2} |
| 1339 |
{rolemap} |
| 1340 |
\l_@@_parent_child_check_tl |
| 1341 |
% \end{macrocode} |
| 1342 |
% if the return value is 7 we have to check against the parentrole field. |
| 1343 |
% \begin{macrocode} |
| 1344 |
\int_compare:nNnT {\l_@@_parent_child_check_tl} = { \c_@@_role_rule_checkparent_tl } |
| 1345 |
{ |
| 1346 |
\@@_struct_check_parent_child_aux:nnnnN |
| 1347 |
{#1} |
| 1348 |
{parentrole} |
| 1349 |
{#2} |
| 1350 |
{rolemap} |
| 1351 |
\l_@@_parent_child_check_tl |
| 1352 |
} |
| 1353 |
\@@_check_struct_forbidden_parent_child:onn |
| 1354 |
{\l_@@_parent_child_check_tl} |
| 1355 |
{#1} |
| 1356 |
{#2} |
| 1357 |
} |
| 1358 |
\cs_generate_variant:Nn \@@_struct_check_parent_child:nn {oo} |
| 1359 |
% \end{macrocode} |
| 1360 |
% \end{macro} |
| 1361 |
% |
| 1362 |
% \begin{macro}{\@@_struct_use_check_parent_child:nn} |
| 1363 |
% A similar command is needed if a structure is stashed and used. |
| 1364 |
% The child can be |
| 1365 |
% - a normal tag (e.g. H1) |
| 1366 |
% then rolemap = parentrole = {H1}{pdf2} |
| 1367 |
% and we should test |
| 1368 |
% rolemap (parent) and rolemap (child) |
| 1369 |
% if = 7 |
| 1370 |
% parentrole (parent) and rolemap (child) |
| 1371 |
% That is the normal check above. |
| 1372 |
% |
| 1373 |
% - Part/Div/Nonstruct |
| 1374 |
% then rolemap = {Part}{pdf2} |
| 1375 |
% and parentrole = {STASHED}{latex} or {target parent}{NS} |
| 1376 |
% |
| 1377 |
% If parentrole =STASHED we can't test if the child fits here. |
| 1378 |
% If parentrole is not STASHED, then would should test |
| 1379 |
% if target parent= rolemap (parent) or parentrole (parent) |
| 1380 |
% and if yet then test |
| 1381 |
% rolemap (child) against rolemap (parent) |
| 1382 |
% and if =7 rolemap(child) against parentrole(parent). |
| 1383 |
% that is again the normal check. |
| 1384 |
% \begin{macrocode} |
| 1385 |
\cs_new_protected:Npn \@@_struct_use_check_parent_child:nn #1 #2 |
| 1386 |
% #1 structure number of parent |
| 1387 |
% #2 structure number of child. % |
| 1388 |
{ |
| 1389 |
\@@_struct_get_role:enNN |
| 1390 |
{#2} |
| 1391 |
{rolemap} |
| 1392 |
\l_@@_get_child_tmpa_tl |
| 1393 |
\l_@@_get_child_tmpb_tl |
| 1394 |
\str_case:onTF { \l_@@_get_child_tmpa_tl } |
| 1395 |
{ |
| 1396 |
{Part} {} |
| 1397 |
{Div} {} |
| 1398 |
{NonStruct} {} |
| 1399 |
} |
| 1400 |
{ %child=Part etc |
| 1401 |
\@@_struct_get_role:enNN |
| 1402 |
{#2} |
| 1403 |
{parentrole} |
| 1404 |
\l_@@_get_child_tmpa_tl |
| 1405 |
\l_@@_get_child_tmpb_tl |
| 1406 |
\str_if_eq:noTF |
| 1407 |
{STASHED}{\l_@@_get_child_tmpa_tl} |
| 1408 |
{ |
| 1409 |
% warn about unknown relationship |
| 1410 |
} |
| 1411 |
{ |
| 1412 |
% test if |
| 1413 |
\@@_struct_get_role:enNN |
| 1414 |
{#1} |
| 1415 |
{parentrole} |
| 1416 |
\l_@@_get_parent_tmpa_tl |
| 1417 |
\l_@@_get_parent_tmpb_tl |
| 1418 |
\tl_if_eq:NNTF\l_@@_get_parent_tmpa_tl \l_@@_get_child_tmpa_tl |
| 1419 |
{ |
| 1420 |
\@@_struct_check_parent_child:nn {#1}{#2} |
| 1421 |
} |
| 1422 |
{ |
| 1423 |
%warn that parent-tag was misused. |
| 1424 |
} |
| 1425 |
} |
| 1426 |
} |
| 1427 |
{ |
| 1428 |
%child not Part etc, normal parent child test. |
| 1429 |
\@@_struct_check_parent_child:nn {#1}{#2} |
| 1430 |
} |
| 1431 |
} |
| 1432 |
\cs_generate_variant:Nn { \@@_struct_use_check_parent_child:nn }{oo} |
| 1433 |
% \end{macrocode} |
| 1434 |
% \end{macro} |
| 1435 |
% \section{Keys} |
| 1436 |
% This are the keys for the user commands. |
| 1437 |
% we store the tag in a variable. But we should be careful, it is only reliable |
| 1438 |
% at the begin. |
| 1439 |
% |
| 1440 |
% This socket is used by the tag key. It allows to switch between |
| 1441 |
% the latex-tabs and the standard tags. |
| 1442 |
% \begin{macrocode} |
| 1443 |
\socket_new:nn { tag/struct/tag }{1} |
| 1444 |
\socket_new_plug:nnn { tag/struct/tag }{ latex-tags } |
| 1445 |
{ |
| 1446 |
\prop_get:NeNTF \g__tag_role_tags_NS_prop {#1} \l_@@_tmp_unused_tl |
| 1447 |
{ |
| 1448 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1449 |
{#1/\l_@@_tmp_unused_tl} |
| 1450 |
} |
| 1451 |
{ |
| 1452 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1453 |
{#1/} |
| 1454 |
} |
| 1455 |
\tl_gset:Ne \g_@@_struct_tag_tl { \seq_item:Nn\l_@@_tmpa_seq {1} } |
| 1456 |
\tl_gset:Ne \g_@@_struct_tag_NS_tl{ \seq_item:Nn\l_@@_tmpa_seq {2} } |
| 1457 |
\@@_check_structure_tag:N \g_@@_struct_tag_tl |
| 1458 |
} |
| 1459 |
|
| 1460 |
\socket_new_plug:nnn { tag/struct/tag }{ pdf-tags } |
| 1461 |
{ |
| 1462 |
\prop_get:NeNTF \g__tag_role_tags_NS_prop {#1} \l_@@_tmp_unused_tl |
| 1463 |
{ |
| 1464 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1465 |
{#1/\l_@@_tmp_unused_tl} |
| 1466 |
} |
| 1467 |
{ |
| 1468 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1469 |
{#1/} |
| 1470 |
} |
| 1471 |
\tl_gset:Ne \g_@@_struct_tag_tl { \seq_item:Nn\l_@@_tmpa_seq {1} } |
| 1472 |
\tl_gset:Ne \g_@@_struct_tag_NS_tl{ \seq_item:Nn\l_@@_tmpa_seq {2} } |
| 1473 |
\@@_role_get:ooNN |
| 1474 |
{ \g_@@_struct_tag_tl } |
| 1475 |
{ \g_@@_struct_tag_NS_tl} |
| 1476 |
\l_@@_tmpa_tl |
| 1477 |
\l_@@_tmpb_tl |
| 1478 |
\tl_gset:Ne \g_@@_struct_tag_tl {\l_@@_tmpa_tl} |
| 1479 |
\tl_gset:Ne \g_@@_struct_tag_NS_tl{\l_@@_tmpb_tl} |
| 1480 |
\@@_check_structure_tag:N \g_@@_struct_tag_tl |
| 1481 |
} |
| 1482 |
\socket_assign_plug:nn { tag/struct/tag } {latex-tags} |
| 1483 |
% \end{macrocode} |
| 1484 |
|
| 1485 |
% \begin{structkeydecl} |
| 1486 |
% { |
| 1487 |
% label, |
| 1488 |
% stash, |
| 1489 |
% parent, |
| 1490 |
% firstkid, |
| 1491 |
% tag, |
| 1492 |
% title, |
| 1493 |
% title-o, |
| 1494 |
% alt, |
| 1495 |
% actualtext, |
| 1496 |
% lang, |
| 1497 |
% ref, |
| 1498 |
% E, |
| 1499 |
% phoneme |
| 1500 |
% } |
| 1501 |
% \begin{macrocode} |
| 1502 |
\keys_define:nn { @@ / struct } |
| 1503 |
{ |
| 1504 |
label .code:n = |
| 1505 |
{ |
| 1506 |
\prop_gput:Nee\g_@@_struct_label_num_prop |
| 1507 |
{#1}{\int_use:N \c@g_@@_struct_abs_int} |
| 1508 |
\@@_property_record:eo |
| 1509 |
{tagpdfstruct-#1} |
| 1510 |
{ \c_@@_property_struct_clist } |
| 1511 |
}, |
| 1512 |
stash .bool_set:N = \l_@@_struct_elem_stash_bool, |
| 1513 |
parent .code:n = |
| 1514 |
{ |
| 1515 |
\bool_lazy_and:nnTF |
| 1516 |
{ |
| 1517 |
\prop_if_exist_p:c { g_@@_struct_\int_eval:n {#1}_prop } |
| 1518 |
} |
| 1519 |
{ |
| 1520 |
\int_compare_p:nNn {#1}<{\c@g_@@_struct_abs_int} |
| 1521 |
} |
| 1522 |
{ \tl_set:Ne \l_@@_struct_stack_parent_tmpa_tl { \int_eval:n {#1} } } |
| 1523 |
{ |
| 1524 |
\msg_warning:nnee { tag } { struct-unknown } |
| 1525 |
{ \int_eval:n {#1} } |
| 1526 |
{ parent~key~ignored } |
| 1527 |
} |
| 1528 |
}, |
| 1529 |
parent .default:n = {-1}, |
| 1530 |
parent-tag .code:n = |
| 1531 |
{ |
| 1532 |
\prop_get:NeNTF \g__tag_role_tags_NS_prop {#1} \l_@@_tmp_unused_tl |
| 1533 |
{ |
| 1534 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1535 |
{#1/\l_@@_tmp_unused_tl} |
| 1536 |
} |
| 1537 |
{ |
| 1538 |
\seq_set_split:Nne \l_@@_tmpa_seq { / } |
| 1539 |
{#1/} |
| 1540 |
} |
| 1541 |
\tl_set:Ne \l_@@_struct_parenttag_tl { \seq_item:Nn\l_@@_tmpa_seq {1} } |
| 1542 |
\tl_set:Ne \l_@@_struct_parenttag_NS_tl{ \seq_item:Nn\l_@@_tmpa_seq {2} } |
| 1543 |
\@@_role_get:ooNN |
| 1544 |
{ \l_@@_struct_parenttag_tl } |
| 1545 |
{ \l_@@_struct_parenttag_NS_tl} |
| 1546 |
\l_@@_tmpa_tl |
| 1547 |
\l_@@_tmpb_tl |
| 1548 |
\tl_set:No \l_@@_struct_parenttag_tl {\l_@@_tmpa_tl} |
| 1549 |
\tl_set:No \l_@@_struct_parenttag_NS_tl{\l_@@_tmpb_tl} |
| 1550 |
\@@_check_structure_tag:N \l_@@_struct_parenttag_tl |
| 1551 |
}, |
| 1552 |
firstkid .code:n = { \tl_set:Nn \l_@@_struct_addkid_tl {left} }, |
| 1553 |
tag .code:n = % S property |
| 1554 |
{ |
| 1555 |
\socket_use:nn { tag/struct/tag }{#1} |
| 1556 |
}, |
| 1557 |
title .code:n = % T property |
| 1558 |
{ |
| 1559 |
\str_set_convert:Nnnn |
| 1560 |
\l_@@_tmpa_str |
| 1561 |
{ #1 } |
| 1562 |
{ default } |
| 1563 |
{ utf16/hex } |
| 1564 |
\@@_struct_prop_gput:nne |
| 1565 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1566 |
{ T } |
| 1567 |
{ <\l_@@_tmpa_str> } |
| 1568 |
}, |
| 1569 |
title-o .code:n = % T property |
| 1570 |
{ |
| 1571 |
\str_set_convert:Nonn |
| 1572 |
\l_@@_tmpa_str |
| 1573 |
{ #1 } |
| 1574 |
{ default } |
| 1575 |
{ utf16/hex } |
| 1576 |
\@@_struct_prop_gput:nne |
| 1577 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1578 |
{ T } |
| 1579 |
{ <\l_@@_tmpa_str> } |
| 1580 |
}, |
| 1581 |
alt .code:n = % Alt property |
| 1582 |
{ |
| 1583 |
\tl_if_empty:oF{#1} |
| 1584 |
{ |
| 1585 |
\str_set_convert:Noon |
| 1586 |
\l_@@_tmpa_str |
| 1587 |
{ #1 } |
| 1588 |
{ default } |
| 1589 |
{ utf16/hex } |
| 1590 |
\@@_struct_prop_gput:nne |
| 1591 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1592 |
{ Alt } |
| 1593 |
{ <\l_@@_tmpa_str> } |
| 1594 |
} |
| 1595 |
}, |
| 1596 |
alttext .meta:n = {alt=#1}, |
| 1597 |
actualtext .code:n = % ActualText property |
| 1598 |
{ |
| 1599 |
\tl_if_empty:oF{#1} |
| 1600 |
{ |
| 1601 |
\str_set_convert:Noon |
| 1602 |
\l_@@_tmpa_str |
| 1603 |
{ #1 } |
| 1604 |
{ default } |
| 1605 |
{ utf16/hex } |
| 1606 |
\@@_struct_prop_gput:nne |
| 1607 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1608 |
{ ActualText } |
| 1609 |
{ <\l_@@_tmpa_str>} |
| 1610 |
} |
| 1611 |
}, |
| 1612 |
phoneme .code:n = % Phoneme property |
| 1613 |
{ |
| 1614 |
\tl_if_empty:oF{#1} |
| 1615 |
{ |
| 1616 |
\str_set_convert:Noon |
| 1617 |
\l_@@_tmpa_str |
| 1618 |
{ #1 } |
| 1619 |
{ default } |
| 1620 |
{ utf16/hex } |
| 1621 |
\@@_struct_prop_gput:nne |
| 1622 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1623 |
{ Phoneme } |
| 1624 |
{ <\l_@@_tmpa_str>} |
| 1625 |
} |
| 1626 |
}, |
| 1627 |
lang .code:n = % Lang property |
| 1628 |
{ |
| 1629 |
\@@_struct_prop_gput:nne |
| 1630 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1631 |
{ Lang } |
| 1632 |
{ (#1) } |
| 1633 |
}, |
| 1634 |
} |
| 1635 |
% \end{macrocode} |
| 1636 |
% \end{structkeydecl} |
| 1637 |
% Ref is rather special as it values are often |
| 1638 |
% known only at the end of the document. |
| 1639 |
% It therefore stores it values as |
| 1640 |
% clist of commands which are executed at the end of the document, |
| 1641 |
% when the structure elements are written. |
| 1642 |
% \begin{macro}{\@@_struct_Ref_obj:nN,\@@_struct_Ref_label:nN, |
| 1643 |
% \@@_struct_Ref_dest:nN,\@@_struct_Ref_dest_parent:nN,\@@_struct_Ref_num:nN} |
| 1644 |
% this commands are helper commands that are stored as clist |
| 1645 |
% in the Ref key of a structure. They are executed when the structure |
| 1646 |
% elements are written in \cs{@@_struct_write_obj}. They are used |
| 1647 |
% in \cs{@@_struct_format_Ref}. They allow to add a Ref by object reference, |
| 1648 |
% label, destname, the parent structure of a destname and by structure number |
| 1649 |
% \begin{macrocode} |
| 1650 |
\cs_new_protected:Npn \@@_struct_Ref_obj:nN #1 #2 %#1 a object reference |
| 1651 |
{ |
| 1652 |
\tl_put_right:Ne#2 |
| 1653 |
{ |
| 1654 |
\c_space_tl#1 |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
\cs_new_protected:Npn \@@_struct_Ref_label:nN #1 #2 %#1 a label |
| 1659 |
{ |
| 1660 |
\prop_get:NnNTF \g_@@_struct_label_num_prop {#1} \l_@@_tmpb_tl |
| 1661 |
{ |
| 1662 |
\tl_put_right:Ne#2 |
| 1663 |
{ |
| 1664 |
\c_space_tl\tag_struct_object_ref:e{ \l_@@_tmpb_tl } |
| 1665 |
} |
| 1666 |
} |
| 1667 |
{ |
| 1668 |
\msg_warning:nnn {tag}{struct-Ref-unknown}{Label~'#1'} |
| 1669 |
} |
| 1670 |
} |
| 1671 |
\cs_new_protected:Npn \@@_struct_Ref_dest:nN #1 #2 %#1 a dest name |
| 1672 |
{ |
| 1673 |
\prop_get:NnNTF \g_@@_struct_dest_num_prop {#1} \l_@@_tmpb_tl |
| 1674 |
{ |
| 1675 |
\tl_put_right:Ne#2 |
| 1676 |
{ |
| 1677 |
\c_space_tl\tag_struct_object_ref:e{ \l_@@_tmpb_tl } |
| 1678 |
} |
| 1679 |
} |
| 1680 |
{ |
| 1681 |
\msg_warning:nnn {tag}{struct-Ref-unknown}{Destination~'#1'} |
| 1682 |
} |
| 1683 |
} |
| 1684 |
\cs_new_protected:Npn \@@_struct_Ref_dest_parent:nN #1 #2 %#1 a dest name |
| 1685 |
{ |
| 1686 |
\prop_get:NnNTF \g_@@_struct_dest_num_prop {#1} \l_@@_tmpb_tl |
| 1687 |
{ %do not overwrite \l_@@_tmpa_tl! |
| 1688 |
\prop_get:cnN |
| 1689 |
{ g_@@_struct_\l_@@_tmpb_tl _prop }{parentnum}\l_@@_tmpb_tl |
| 1690 |
\tl_put_right:Ne#2 |
| 1691 |
{ |
| 1692 |
\c_space_tl\tag_struct_object_ref:e{ \l_@@_tmpb_tl } |
| 1693 |
} |
| 1694 |
} |
| 1695 |
{ |
| 1696 |
\msg_warning:nnn {tag}{struct-Ref-unknown}{Destination~'#1'} |
| 1697 |
} |
| 1698 |
} |
| 1699 |
\cs_new_protected:Npn \@@_struct_Ref_num:nN #1 #2 %#1 a structure number |
| 1700 |
{ |
| 1701 |
\tl_put_right:Ne#2 |
| 1702 |
{ |
| 1703 |
\c_space_tl\tag_struct_object_ref:e{ #1 } |
| 1704 |
} |
| 1705 |
} |
| 1706 |
|
| 1707 |
% \end{macrocode} |
| 1708 |
% \end{macro} |
| 1709 |
% \begin{structkeydecl}{ref,E,} |
| 1710 |
% \begin{macrocode} |
| 1711 |
\keys_define:nn { @@ / struct } |
| 1712 |
{ |
| 1713 |
ref .code:n = % ref property |
| 1714 |
{ |
| 1715 |
\clist_map_inline:on {#1} |
| 1716 |
{ |
| 1717 |
\tag_struct_gput:nne |
| 1718 |
{\int_use:N \c@g_@@_struct_abs_int}{ref_label}{ ##1 } |
| 1719 |
} |
| 1720 |
}, |
| 1721 |
E .code:n = % E property |
| 1722 |
{ |
| 1723 |
\str_set_convert:Nnon |
| 1724 |
\l_@@_tmpa_str |
| 1725 |
{ #1 } |
| 1726 |
{ default } |
| 1727 |
{ utf16/hex } |
| 1728 |
\@@_struct_prop_gput:nne |
| 1729 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1730 |
{ E } |
| 1731 |
{ <\l_@@_tmpa_str> } |
| 1732 |
}, |
| 1733 |
} |
| 1734 |
% \end{macrocode} |
| 1735 |
% \end{structkeydecl} |
| 1736 |
% |
| 1737 |
% \begin{structkeydecl}{AF, AFref,AFinline,AFinline-o,texsource,mathml} |
| 1738 |
% keys for the AF keys (associated files). They use commands from l3pdffile! |
| 1739 |
% The stream variants use txt as extension to get the mimetype. |
| 1740 |
% TODO: check if this should be configurable. For math we will perhaps need another |
| 1741 |
% extension. |
| 1742 |
% AF/AFref is an array and can be used more than once, so we store it in a tl. |
| 1743 |
% which is expanded. |
| 1744 |
% AFinline currently uses the fix extension txt. |
| 1745 |
% texsource is a special variant which creates a tex-file, it expects a |
| 1746 |
% tl-var as value (e.g. from math grabbing) |
| 1747 |
% |
| 1748 |
% \begin{variable}{\g_@@_struct_AFobj_int} |
| 1749 |
% This variable is used to number the AF-object names |
| 1750 |
% \begin{macrocode} |
| 1751 |
\int_new:N\g_@@_struct_AFobj_int |
| 1752 |
% \end{macrocode} |
| 1753 |
% \end{variable} |
| 1754 |
% |
| 1755 |
% \begin{macrocode} |
| 1756 |
\cs_generate_variant:Nn \pdffile_embed_stream:nnN {neN} |
| 1757 |
\cs_new_protected:Npn \@@_struct_add_inline_AF:nn #1 #2 |
| 1758 |
% #1 content, #2 extension |
| 1759 |
{ |
| 1760 |
\tl_if_empty:nF{#1} |
| 1761 |
{ |
| 1762 |
\group_begin: |
| 1763 |
\int_gincr:N \g_@@_struct_AFobj_int |
| 1764 |
\pdffile_embed_stream:neN |
| 1765 |
{#1} |
| 1766 |
{tag-AFfile\int_use:N\g_@@_struct_AFobj_int.#2} |
| 1767 |
\l_@@_tmpa_tl |
| 1768 |
\@@_struct_add_AF:ee |
| 1769 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1770 |
{ \l_@@_tmpa_tl } |
| 1771 |
\@@_struct_prop_gput:nne |
| 1772 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1773 |
{ AF } |
| 1774 |
{ |
| 1775 |
[ |
| 1776 |
\tl_use:c |
| 1777 |
{ g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_AF_tl } |
| 1778 |
] |
| 1779 |
} |
| 1780 |
\group_end: |
| 1781 |
} |
| 1782 |
} |
| 1783 |
|
| 1784 |
\cs_generate_variant:Nn \@@_struct_add_inline_AF:nn {on} |
| 1785 |
% \end{macrocode} |
| 1786 |
% |
| 1787 |
% \begin{macrocode} |
| 1788 |
\cs_new_protected:Npn \@@_struct_add_AF:nn #1 #2 |
| 1789 |
% #1 struct num #2 object reference |
| 1790 |
{ |
| 1791 |
\tl_if_exist:cTF |
| 1792 |
{ |
| 1793 |
g_@@_struct_#1_AF_tl |
| 1794 |
} |
| 1795 |
{ |
| 1796 |
\tl_gput_right:ce |
| 1797 |
{ g_@@_struct_#1_AF_tl } |
| 1798 |
{ \c_space_tl #2 } |
| 1799 |
} |
| 1800 |
{ |
| 1801 |
\tl_new:c |
| 1802 |
{ g_@@_struct_#1_AF_tl } |
| 1803 |
\tl_gset:ce |
| 1804 |
{ g_@@_struct_#1_AF_tl } |
| 1805 |
{ #2 } |
| 1806 |
} |
| 1807 |
} |
| 1808 |
\cs_generate_variant:Nn \@@_struct_add_AF:nn {en,ee} |
| 1809 |
\keys_define:nn { @@ / struct } |
| 1810 |
{ |
| 1811 |
AF .code:n = % AF property |
| 1812 |
{ |
| 1813 |
\pdf_object_if_exist:eTF {#1} |
| 1814 |
{ |
| 1815 |
\@@_struct_add_AF:ee |
| 1816 |
{ \int_use:N \c@g_@@_struct_abs_int }{\pdf_object_ref:e {#1}} |
| 1817 |
\@@_struct_prop_gput:nne |
| 1818 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1819 |
{ AF } |
| 1820 |
{ |
| 1821 |
[ |
| 1822 |
\tl_use:c |
| 1823 |
{ g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_AF_tl } |
| 1824 |
] |
| 1825 |
} |
| 1826 |
} |
| 1827 |
{ |
| 1828 |
% message? |
| 1829 |
} |
| 1830 |
}, |
| 1831 |
AFref .code:n = % AF property |
| 1832 |
{ |
| 1833 |
\tl_if_empty:eF {#1} |
| 1834 |
{ |
| 1835 |
\@@_struct_add_AF:ee { \int_use:N \c@g_@@_struct_abs_int }{#1} |
| 1836 |
\@@_struct_prop_gput:nne |
| 1837 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1838 |
{ AF } |
| 1839 |
{ |
| 1840 |
[ |
| 1841 |
\tl_use:c |
| 1842 |
{ g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_AF_tl } |
| 1843 |
] |
| 1844 |
} |
| 1845 |
} |
| 1846 |
}, |
| 1847 |
,AFinline .code:n = |
| 1848 |
{ |
| 1849 |
\@@_struct_add_inline_AF:nn {#1}{txt} |
| 1850 |
} |
| 1851 |
,AFinline-o .code:n = |
| 1852 |
{ |
| 1853 |
\@@_struct_add_inline_AF:on {#1}{txt} |
| 1854 |
} |
| 1855 |
,texsource .code:n = |
| 1856 |
{ |
| 1857 |
\group_begin: |
| 1858 |
\pdfdict_put:nnn { l_pdffile/Filespec } {Desc}{(TeX~source)} |
| 1859 |
\pdfdict_put:nnn { l_pdffile/Filespec }{AFRelationship} { /Source } |
| 1860 |
\@@_struct_add_inline_AF:on {#1}{tex} |
| 1861 |
\group_end: |
| 1862 |
} |
| 1863 |
,mathml .code:n = |
| 1864 |
{ |
| 1865 |
\group_begin: |
| 1866 |
\pdfdict_put:nnn { l_pdffile/Filespec } {Desc}{(mathml~representation)} |
| 1867 |
\pdfdict_put:nnn { l_pdffile/Filespec }{AFRelationship} { /Supplement } |
| 1868 |
\pdfdict_put:nne { l_pdffile }{Subtype} |
| 1869 |
{ \pdf_name_from_unicode_e:n{application/mathml+xml} } |
| 1870 |
\@@_struct_add_inline_AF:on {#1}{xml} |
| 1871 |
\group_end: |
| 1872 |
} |
| 1873 |
} |
| 1874 |
% \end{macrocode} |
| 1875 |
% \end{structkeydecl} |
| 1876 |
% \begin{setupkeydecl}{root-AF} |
| 1877 |
% The root structure can take AF keys too, so we provide a key for it. |
| 1878 |
% This key is used with |\tagpdfsetup|, not in a structure! |
| 1879 |
% \begin{macrocode} |
| 1880 |
\keys_define:nn { @@ / setup } |
| 1881 |
{ |
| 1882 |
root-AF .code:n = |
| 1883 |
{ |
| 1884 |
\pdf_object_if_exist:nTF {#1} |
| 1885 |
{ |
| 1886 |
\@@_struct_add_AF:ee { 1 }{\pdf_object_ref:n {#1}} |
| 1887 |
\@@_struct_prop_gput:nne |
| 1888 |
{ 1 } |
| 1889 |
{ AF } |
| 1890 |
{ |
| 1891 |
[ |
| 1892 |
\tl_use:c |
| 1893 |
{ g_@@_struct_1_AF_tl } |
| 1894 |
] |
| 1895 |
} |
| 1896 |
} |
| 1897 |
{ |
| 1898 |
|
| 1899 |
} |
| 1900 |
}, |
| 1901 |
} |
| 1902 |
% \end{macrocode} |
| 1903 |
% \end{setupkeydecl} |
| 1904 |
% |
| 1905 |
% \begin{setupkeydecl}{root-supplemental-file} |
| 1906 |
% This key allows to add a file as root-AF with relationship Supplement. |
| 1907 |
% This is typically need to add a css or an html |
| 1908 |
% \begin{macrocode} |
| 1909 |
\keys_define:nn { @@ / setup } |
| 1910 |
{ |
| 1911 |
root-supplemental-file .code:n = |
| 1912 |
{ |
| 1913 |
\group_begin: |
| 1914 |
\pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Supplement} |
| 1915 |
\int_gincr:N \g_@@_unique_cnt_int |
| 1916 |
\pdffile_embed_file:eee |
| 1917 |
{#1} |
| 1918 |
{#1} |
| 1919 |
{__tag_latex_css_\int_use:N\g_@@_unique_cnt_int} |
| 1920 |
\keys_set:nn |
| 1921 |
{__tag / setup} |
| 1922 |
{root-AF={__tag_latex_css_\int_use:N\g_@@_unique_cnt_int}} |
| 1923 |
\group_end: |
| 1924 |
} |
| 1925 |
} |
| 1926 |
% \end{macrocode} |
| 1927 |
% \end{setupkeydecl} |
| 1928 |
% |
| 1929 |
% \begin{setupkeydecl}{catalog-supplemental-file} |
| 1930 |
% This key allows to add a file as AF with relationship Supplement to the Catalog. |
| 1931 |
% This is typically need to add a css or an html. |
| 1932 |
% \begin{macrocode} |
| 1933 |
\keys_define:nn { @@ / setup } |
| 1934 |
{ |
| 1935 |
catalog-supplemental-file .code:n = |
| 1936 |
{ |
| 1937 |
\group_begin: |
| 1938 |
\pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Supplement} |
| 1939 |
\int_gincr:N \g_@@_unique_cnt_int |
| 1940 |
\pdffile_embed_file:eee |
| 1941 |
{#1} |
| 1942 |
{#1} |
| 1943 |
{@@_latex_css_\int_use:N\g_@@_unique_cnt_int} |
| 1944 |
\pdfmanagement_add:nne |
| 1945 |
{Catalog} |
| 1946 |
{AF} |
| 1947 |
{\pdf_object_ref:e{@@_latex_css_\int_use:N\g_@@_unique_cnt_int }} |
| 1948 |
\group_end: |
| 1949 |
} |
| 1950 |
} |
| 1951 |
% \end{macrocode} |
| 1952 |
% \end{setupkeydecl} |
| 1953 |
% |
| 1954 |
% \section{User commands} |
| 1955 |
% We allow to set a language by default |
| 1956 |
% \begin{macro}{\l_@@_struct_lang_tl} |
| 1957 |
% \begin{macrocode} |
| 1958 |
\tl_new:N \l_@@_struct_lang_tl |
| 1959 |
%</package> |
| 1960 |
% \end{macrocode} |
| 1961 |
% \end{macro} |
| 1962 |
% |
| 1963 |
% \begin{macro}{\tag_struct_begin:n,\tag_struct_end:} |
| 1964 |
% \begin{macrocode} |
| 1965 |
%<base>\cs_new_protected:Npn \tag_struct_begin:n #1 {\int_gincr:N \c@g_@@_struct_abs_int} |
| 1966 |
%<base>\cs_new_protected:Npn \tag_struct_end:{} |
| 1967 |
%<base>\cs_new_protected:Npn \tag_struct_end:n{} |
| 1968 |
%<*package|debug> |
| 1969 |
%<package>\cs_set_protected:Npn \tag_struct_begin:n #1 %#1 key-val |
| 1970 |
%<debug>\cs_set_protected:Npn \tag_struct_begin:n #1 %#1 key-val |
| 1971 |
{ |
| 1972 |
%<package>\@@_check_if_active_struct:T |
| 1973 |
%<debug>\@@_check_if_active_struct:TF |
| 1974 |
{ |
| 1975 |
\group_begin: |
| 1976 |
\int_gincr:N \c@g_@@_struct_abs_int |
| 1977 |
\@@_prop_new:c { g_@@_struct_\int_eval:n { \c@g_@@_struct_abs_int }_prop } |
| 1978 |
%<debug> \prop_new:c { g_@@_struct_debug_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 1979 |
\@@_seq_new:c { g_@@_struct_kids_\int_eval:n { \c@g_@@_struct_abs_int }_seq} |
| 1980 |
%<debug> \seq_new:c { g_@@_struct_debug_kids_\int_eval:n {\c@g_@@_struct_abs_int}_seq } |
| 1981 |
\pdf_object_new_indexed:nn { @@/struct } |
| 1982 |
{ \c@g_@@_struct_abs_int } |
| 1983 |
\@@_struct_prop_gput:nnn |
| 1984 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1985 |
{ Type } |
| 1986 |
{ /StructElem } |
| 1987 |
\tl_if_empty:NF \l_@@_struct_lang_tl |
| 1988 |
{ |
| 1989 |
\@@_struct_prop_gput:nne |
| 1990 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1991 |
{ Lang } |
| 1992 |
{ (\l_@@_struct_lang_tl) } |
| 1993 |
} |
| 1994 |
\@@_struct_prop_gput:nnn |
| 1995 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 1996 |
{ Type } |
| 1997 |
{ /StructElem } |
| 1998 |
|
| 1999 |
\tl_set:Nn \l_@@_struct_stack_parent_tmpa_tl {-1} |
| 2000 |
\keys_set:nn { @@ / struct} { #1 } |
| 2001 |
% \end{macrocode} |
| 2002 |
% \begin{macrocode} |
| 2003 |
\@@_struct_set_tag_info:eoo |
| 2004 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2005 |
{ \g_@@_struct_tag_tl } |
| 2006 |
{ \g_@@_struct_tag_NS_tl } |
| 2007 |
\@@_check_structure_has_tag:n { \int_use:N \c@g_@@_struct_abs_int } |
| 2008 |
% \end{macrocode} |
| 2009 |
% The structure number of the parent is either taken from the stack or |
| 2010 |
% has been set with the parent key. |
| 2011 |
% \begin{macrocode} |
| 2012 |
\int_compare:nNnT { \l_@@_struct_stack_parent_tmpa_tl } = { -1 } |
| 2013 |
{ |
| 2014 |
\seq_get:NNF |
| 2015 |
\g_@@_struct_stack_seq |
| 2016 |
\l_@@_struct_stack_parent_tmpa_tl |
| 2017 |
{ |
| 2018 |
\msg_error:nn { tag } { struct-faulty-nesting } |
| 2019 |
} |
| 2020 |
} |
| 2021 |
\seq_gpush:NV \g_@@_struct_stack_seq \c@g_@@_struct_abs_int |
| 2022 |
\@@_role_get:ooNN |
| 2023 |
{ \g_@@_struct_tag_tl } |
| 2024 |
{ \g_@@_struct_tag_NS_tl } |
| 2025 |
\l_@@_struct_roletag_tl |
| 2026 |
\l_@@_struct_roletag_NS_tl |
| 2027 |
% \end{macrocode} |
| 2028 |
% We push the role tag on the stack:% |
| 2029 |
% \begin{macrocode} |
| 2030 |
\seq_gpush:Ne \g_@@_struct_tag_stack_seq |
| 2031 |
{{\g_@@_struct_tag_tl}{\l_@@_struct_roletag_tl}} |
| 2032 |
\seq_gpush:Ne \g_@@_struct_roletag_stack_seq |
| 2033 |
{\l_@@_struct_roletag_tl} |
| 2034 |
\tl_gset:NV \g_@@_struct_stack_current_tl \c@g_@@_struct_abs_int |
| 2035 |
\@@_struct_set_attribute: |
| 2036 |
%\seq_show:N \g_@@_struct_stack_seq |
| 2037 |
% \end{macrocode} |
| 2038 |
% the rolemapped role and its NS are stored in the rolemap key. |
| 2039 |
% \begin{macrocode} |
| 2040 |
\@@_struct_prop_gput:nne |
| 2041 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2042 |
{ rolemap } |
| 2043 |
{ |
| 2044 |
{\l_@@_struct_roletag_tl}{\l_@@_struct_roletag_NS_tl} |
| 2045 |
} |
| 2046 |
% \end{macrocode} |
| 2047 |
% If the role is one of Part, Div, NonStruct we have to (sometimes) retrieve |
| 2048 |
% the \enquote{real} parent for the parent/child test. The role of this |
| 2049 |
% real parent is stored in the key \texttt{parentrole}. |
| 2050 |
% If the current structure is stashed |
| 2051 |
% we use UNKNOWN as real parent if the current structure is rolemapped to |
| 2052 |
% Part, Div or NonStruct so that the children can detect that no reliable check is possible. |
| 2053 |
% For structures that are not rolemapped to Part, Div, NonStruct, |
| 2054 |
% \texttt{parentrole} and \texttt{rolemap} are always equal. |
| 2055 |
% \begin{macrocode} |
| 2056 |
\str_case:onTF { \l_@@_struct_roletag_tl } |
| 2057 |
{ |
| 2058 |
{Part} {} |
| 2059 |
{Div} {} |
| 2060 |
{NonStruct} {} |
| 2061 |
} |
| 2062 |
{ |
| 2063 |
\bool_if:NTF \l_@@_struct_elem_stash_bool |
| 2064 |
{ |
| 2065 |
\@@_struct_prop_gput:nne |
| 2066 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2067 |
{ parentrole } |
| 2068 |
{ |
| 2069 |
{\l_@@_struct_parenttag_tl}{\l_@@_struct_parenttag_NS_tl} |
| 2070 |
} |
| 2071 |
} |
| 2072 |
{ |
| 2073 |
\prop_get:cnNT |
| 2074 |
{ g_@@_struct_ \l_@@_struct_stack_parent_tmpa_tl _prop } |
| 2075 |
{ parentrole } |
| 2076 |
\l_@@_get_tmpc_tl |
| 2077 |
{ |
| 2078 |
\@@_struct_prop_gput:nno |
| 2079 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2080 |
{ parentrole } |
| 2081 |
{ |
| 2082 |
\l_@@_get_tmpc_tl |
| 2083 |
} |
| 2084 |
} |
| 2085 |
} |
| 2086 |
} |
| 2087 |
{ |
| 2088 |
\@@_struct_prop_gput:nne |
| 2089 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2090 |
{ parentrole } |
| 2091 |
{ |
| 2092 |
{\l_@@_struct_roletag_tl}{\l_@@_struct_roletag_NS_tl} |
| 2093 |
} |
| 2094 |
} |
| 2095 |
% \end{macrocode} |
| 2096 |
% |
| 2097 |
% \begin{macrocode} |
| 2098 |
\bool_if:NF |
| 2099 |
\l_@@_struct_elem_stash_bool |
| 2100 |
{ |
| 2101 |
% \end{macrocode} |
| 2102 |
% check if the tag can be used inside the parent. It only makes sense, |
| 2103 |
% if the structure is actually used here, so it is guarded by the stash boolean. |
| 2104 |
% \begin{macrocode} |
| 2105 |
\socket_use:nn{tag/check/parent-child} |
| 2106 |
{ |
| 2107 |
\@@_struct_check_parent_child:oo |
| 2108 |
{ \l_@@_struct_stack_parent_tmpa_tl } |
| 2109 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2110 |
} |
| 2111 |
% \end{macrocode} |
| 2112 |
% Set the Parent structure number. |
| 2113 |
% \begin{macrocode} |
| 2114 |
\@@_struct_prop_gput:nne |
| 2115 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2116 |
{ parentnum } |
| 2117 |
{ |
| 2118 |
\l_@@_struct_stack_parent_tmpa_tl |
| 2119 |
} |
| 2120 |
% \end{macrocode} |
| 2121 |
% \begin{macrocode} |
| 2122 |
%record this structure as kid: |
| 2123 |
%\tl_show:N \g_@@_struct_stack_current_tl |
| 2124 |
%\tl_show:N \l_@@_struct_stack_parent_tmpa_tl |
| 2125 |
\use:c { @@_struct_kid_struct_gput_ \l_@@_struct_addkid_tl :ee } |
| 2126 |
{ \l_@@_struct_stack_parent_tmpa_tl } |
| 2127 |
{ \g_@@_struct_stack_current_tl } |
| 2128 |
%\prop_show:c { g_@@_struct_\g_@@_struct_stack_current_tl _prop } |
| 2129 |
%\seq_show:c {g_@@_struct_kids_\l_@@_struct_stack_parent_tmpa_tl _seq} |
| 2130 |
} |
| 2131 |
% \end{macrocode} |
| 2132 |
% the debug mode stores in second prop and replaces value with more suitable ones. |
| 2133 |
% (If the structure is updated later this gets perhaps lost, but well ...) |
| 2134 |
% This must be done outside of the stash boolean. |
| 2135 |
% \begin{macrocode} |
| 2136 |
%<debug> \prop_gset_eq:cc |
| 2137 |
%<debug> { g_@@_struct_debug_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 2138 |
%<debug> { g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 2139 |
%<debug> \prop_gput:cne |
| 2140 |
%<debug> { g_@@_struct_debug_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 2141 |
%<debug> { parentnum } |
| 2142 |
%<debug> { |
| 2143 |
%<debug> \bool_if:NTF \l_@@_struct_elem_stash_bool |
| 2144 |
%<debug> {no~parent:~stashed} |
| 2145 |
%<debug> { |
| 2146 |
%<debug> \l_@@_struct_stack_parent_tmpa_tl\c_space_tl =~ |
| 2147 |
%<debug> \prop_item:cn{ g__tag_struct_\l_@@_struct_stack_parent_tmpa_tl _prop }{S} |
| 2148 |
%<debug> } |
| 2149 |
%<debug> } |
| 2150 |
%<debug> \prop_gput:cne |
| 2151 |
%<debug> { g_@@_struct_debug_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 2152 |
%<debug> { NS } |
| 2153 |
%<debug> { \g_@@_struct_tag_NS_tl } |
| 2154 |
% \end{macrocode} |
| 2155 |
% \begin{macrocode} |
| 2156 |
%\prop_show:c { g_@@_struct_\g_@@_struct_stack_current_tl _prop } |
| 2157 |
%\seq_show:c {g_@@_struct_kids_\l_@@_struct_stack_parent_tmpa_tl _seq} |
| 2158 |
%<debug> \@@_debug_struct_begin_insert:n { #1 } |
| 2159 |
\group_end: |
| 2160 |
} |
| 2161 |
%<debug>{ \@@_debug_struct_begin_ignore:n { #1 }} |
| 2162 |
} |
| 2163 |
%<package>\cs_set_protected:Nn \tag_struct_end: |
| 2164 |
%<debug>\cs_set_protected:Nn \tag_struct_end: |
| 2165 |
{ %take the current structure num from the stack: |
| 2166 |
%the objects are written later, lua mode hasn't all needed info yet |
| 2167 |
%\seq_show:N \g_@@_struct_stack_seq |
| 2168 |
%<package>\@@_check_if_active_struct:T |
| 2169 |
%<debug>\@@_check_if_active_struct:TF |
| 2170 |
{ |
| 2171 |
\seq_gpop:NN \g_@@_struct_roletag_stack_seq \l_@@_tmpa_tl |
| 2172 |
\seq_gpop:NN \g_@@_struct_tag_stack_seq \l_@@_tmpa_tl |
| 2173 |
\seq_gpop:NNTF \g_@@_struct_stack_seq \l_@@_tmpa_tl |
| 2174 |
{ |
| 2175 |
\@@_check_info_closing_struct:o { \g_@@_struct_stack_current_tl } |
| 2176 |
} |
| 2177 |
{ \@@_check_no_open_struct: } |
| 2178 |
% get the previous one, shouldn't be empty as the root should be there |
| 2179 |
\seq_get:NNTF \g_@@_struct_stack_seq \l_@@_tmpa_tl |
| 2180 |
{ |
| 2181 |
\tl_gset:No \g_@@_struct_stack_current_tl { \l_@@_tmpa_tl } |
| 2182 |
\@@_struct_set_attribute: |
| 2183 |
} |
| 2184 |
{ |
| 2185 |
\@@_check_no_open_struct: |
| 2186 |
} |
| 2187 |
\seq_get:NNT \g_@@_struct_tag_stack_seq \l_@@_tmpa_tl |
| 2188 |
{ |
| 2189 |
\tl_gset:Ne \g_@@_struct_tag_tl |
| 2190 |
{ \exp_last_unbraced:No\use_i:nn { \l_@@_tmpa_tl } } |
| 2191 |
\prop_get:NoNT\g_@@_role_tags_NS_prop { \g_@@_struct_tag_tl} \l_@@_tmpa_tl |
| 2192 |
{ |
| 2193 |
\tl_gset:Ne \g_@@_struct_tag_NS_tl { \l_@@_tmpa_tl } |
| 2194 |
} |
| 2195 |
} |
| 2196 |
%<debug>\@@_debug_struct_end_insert: |
| 2197 |
} |
| 2198 |
%<debug>{\@@_debug_struct_end_ignore:} |
| 2199 |
} |
| 2200 |
|
| 2201 |
\cs_set_protected:Npn \tag_struct_end:n #1 |
| 2202 |
{ |
| 2203 |
%<debug> \@@_check_if_active_struct:T{\@@_debug_struct_end_check:n{#1}} |
| 2204 |
\tag_struct_end: |
| 2205 |
} |
| 2206 |
%</package|debug> |
| 2207 |
% \end{macrocode} |
| 2208 |
% \end{macro} |
| 2209 |
% \begin{macro}{\tag_struct_use:n} |
| 2210 |
% This command allows to use a stashed structure in another place. |
| 2211 |
% TODO: decide how it should be guarded. Probably by the struct-check. |
| 2212 |
% \begin{macrocode} |
| 2213 |
%<base>\cs_new_protected:Npn \tag_struct_use:n #1 {} |
| 2214 |
%<*package|debug> |
| 2215 |
\cs_set_protected:Npn \tag_struct_use:n #1 %#1 is the label |
| 2216 |
{ |
| 2217 |
\@@_check_if_active_struct:T |
| 2218 |
{ |
| 2219 |
\prop_if_exist:cTF |
| 2220 |
{ g_@@_struct_\property_ref:enn{tagpdfstruct-#1}{tagstruct}{unknown}_prop } % |
| 2221 |
{ |
| 2222 |
\@@_check_struct_used:n {#1} |
| 2223 |
\tl_set:Ne \l_@@_get_child_tmpa_tl |
| 2224 |
{ \property_ref:enn{tagpdfstruct-#1}{tagstruct}{1} } |
| 2225 |
% \end{macrocode} |
| 2226 |
% add the label structure as kid to the current structure (can be the root) |
| 2227 |
% \begin{macrocode} |
| 2228 |
\@@_struct_kid_struct_gput_right:ee |
| 2229 |
{ \g_@@_struct_stack_current_tl } |
| 2230 |
{ \l_@@_get_child_tmpa_tl } |
| 2231 |
% \end{macrocode} |
| 2232 |
% add the current structure to the labeled one as parents |
| 2233 |
% \begin{macrocode} |
| 2234 |
\@@_prop_gput:cne |
| 2235 |
{ g_@@_struct_ \l_@@_get_child_tmpa_tl _prop } |
| 2236 |
{ parentnum } |
| 2237 |
{ |
| 2238 |
\g_@@_struct_stack_current_tl |
| 2239 |
} |
| 2240 |
% \end{macrocode} |
| 2241 |
% debug code |
| 2242 |
% \begin{macrocode} |
| 2243 |
%<debug> \prop_gput:cne |
| 2244 |
%<debug> { g_@@_struct_debug_ \l_@@_get_child_tmpa_tl _prop } |
| 2245 |
%<debug> { parentnum } |
| 2246 |
%<debug> { |
| 2247 |
%<debug> \g_@@_struct_stack_current_tl\c_space_tl=~ |
| 2248 |
%<debug> \g_@@_struct_tag_tl |
| 2249 |
%<debug> } |
| 2250 |
% \end{macrocode} |
| 2251 |
% check if the tag is allowed as child. |
| 2252 |
% If the tag of the child after rolemapping is \emph{not} one of Part, Div, NonStruct, |
| 2253 |
% then the parentrole field will be identically to the rolemap field and can be used for |
| 2254 |
% a check. |
| 2255 |
% Otherwise the parentrole will contain latex:STASHED (if not changed with the \texttt{parent-tag} |
| 2256 |
% key when the structure was stashed) and will produce a warning. |
| 2257 |
% \begin{macrocode} |
| 2258 |
\socket_use:nn{tag/check/parent-child} |
| 2259 |
{ |
| 2260 |
\@@_struct_use_check_parent_child:oo |
| 2261 |
{ \g_@@_struct_stack_current_tl } |
| 2262 |
{ \l_@@_get_child_tmpa_tl } |
| 2263 |
} |
| 2264 |
} |
| 2265 |
{ |
| 2266 |
\msg_warning:nnn{ tag }{struct-label-unknown}{#1} |
| 2267 |
} |
| 2268 |
} |
| 2269 |
} |
| 2270 |
%</package|debug> |
| 2271 |
% \end{macrocode} |
| 2272 |
% \end{macro} |
| 2273 |
% \begin{macro}{\tag_struct_use_num:n} |
| 2274 |
% This command allows to use a stashed structure in another place. |
| 2275 |
% differently to the previous command it doesn't use a label but directly |
| 2276 |
% a structure number to find the parent. |
| 2277 |
% TODO: decide how it should be guarded. Probably by the struct-check. |
| 2278 |
% \begin{macrocode} |
| 2279 |
%<base>\cs_new_protected:Npn \tag_struct_use_num:n #1 {} |
| 2280 |
%<*package|debug> |
| 2281 |
\cs_set_protected:Npn \tag_struct_use_num:n #1 %#1 is structure number |
| 2282 |
{ |
| 2283 |
\@@_check_if_active_struct:T |
| 2284 |
{ |
| 2285 |
\prop_if_exist:cTF |
| 2286 |
{ g_@@_struct_#1_prop } % |
| 2287 |
{ |
| 2288 |
\prop_get:cnNT |
| 2289 |
{g_@@_struct_#1_prop} |
| 2290 |
{parentnum} |
| 2291 |
\l_@@_tmpa_tl |
| 2292 |
{ |
| 2293 |
\msg_warning:nnn { tag } {struct-used-twice} {#1} |
| 2294 |
} |
| 2295 |
% \end{macrocode} |
| 2296 |
% add the \#1 structure as kid to the current structure (can be the root) |
| 2297 |
% \begin{macrocode} |
| 2298 |
\@@_struct_kid_struct_gput_right:ee |
| 2299 |
{ \g_@@_struct_stack_current_tl } |
| 2300 |
{ #1 } |
| 2301 |
% \end{macrocode} |
| 2302 |
% add the current structure to \#1 as parent |
| 2303 |
% \begin{macrocode} |
| 2304 |
\@@_struct_prop_gput:nne |
| 2305 |
{ #1 } |
| 2306 |
{ parentnum } |
| 2307 |
{ |
| 2308 |
\g_@@_struct_stack_current_tl |
| 2309 |
} |
| 2310 |
%<debug> \prop_gput:cne |
| 2311 |
%<debug> { g_@@_struct_debug_#1_prop } |
| 2312 |
%<debug> { parentnum } |
| 2313 |
%<debug> { |
| 2314 |
%<debug> \g_@@_struct_stack_current_tl\c_space_tl=~ |
| 2315 |
%<debug> \g_@@_struct_tag_tl |
| 2316 |
%<debug> } |
| 2317 |
% \end{macrocode} |
| 2318 |
% check if the tag is allowed as child. |
| 2319 |
% \begin{macrocode} |
| 2320 |
\socket_use:nn{tag/check/parent-child} |
| 2321 |
{ |
| 2322 |
\@@_struct_use_check_parent_child:oo |
| 2323 |
{\g_@@_struct_stack_current_tl} |
| 2324 |
{#1} |
| 2325 |
} |
| 2326 |
} |
| 2327 |
{ |
| 2328 |
\msg_warning:nnn{ tag }{struct-label-unknown}{#1} |
| 2329 |
} |
| 2330 |
} |
| 2331 |
} |
| 2332 |
\cs_generate_variant:Nn\tag_struct_use_num:n {o} |
| 2333 |
%</package|debug> |
| 2334 |
% \end{macrocode} |
| 2335 |
% \end{macro} |
| 2336 |
% \begin{macro}[EXP]{\tag_struct_object_ref:n} |
| 2337 |
% This is a command that allows to reference a structure. The argument is the |
| 2338 |
% number which can be get for the current structure with |\tag_get:n{struct_num}| |
| 2339 |
% TODO check if it should be in base too. |
| 2340 |
% \begin{macrocode} |
| 2341 |
%<*package> |
| 2342 |
\cs_new:Npn \tag_struct_object_ref:n #1 |
| 2343 |
{ |
| 2344 |
\pdf_object_ref_indexed:nn {@@/struct}{ #1 } |
| 2345 |
} |
| 2346 |
\cs_generate_variant:Nn \tag_struct_object_ref:n {e} |
| 2347 |
%</package> |
| 2348 |
% \end{macrocode} |
| 2349 |
% |
| 2350 |
% \end{macro} |
| 2351 |
% |
| 2352 |
% \begin{macro}{\tag_struct_gput:nnn} |
| 2353 |
% This is a command that allows to update the data of a structure. |
| 2354 |
% This often can't done simply by replacing the value, as we have to |
| 2355 |
% preserve and extend existing content. We use therefore dedicated functions |
| 2356 |
% adjusted to the key in question. |
| 2357 |
% The first argument is the number of the structure, |
| 2358 |
% the second a keyword referring to a function, |
| 2359 |
% the third the value. Currently the existing keywords are mostly related |
| 2360 |
% to the \texttt{Ref} key (an array). |
| 2361 |
% The keyword \texttt{ref} takes as value an explicit object reference to |
| 2362 |
% a structure. The keyword \texttt{ref_label} expects as value a label name (from |
| 2363 |
% a label set in a \cs{tagstructbegin} command). The keyword \texttt{ref_dest} |
| 2364 |
% expects a destination name set with \cs{MakeLinkTarget}. It then will refer to |
| 2365 |
% the structure in which this \cs{MakeLinkTarget} was used. The keyword \texttt{ref_dest_parent} |
| 2366 |
% expects a destination name set with \cs{MakeLinkTarget} too. It then will refer to |
| 2367 |
% the parent of structure in which this \cs{MakeLinkTarget} was used---this is useful if the |
| 2368 |
% target command is, e.g., in a list and one wants to reference the surrounding list item structure. |
| 2369 |
% The keyword \texttt{ref_num} expects a structure number. |
| 2370 |
% At last there is the keyword \texttt{attribute} which allows to add or extend the \texttt{/A} |
| 2371 |
% key of the structure. The value is the content of one attribute dictionary, so for example |
| 2372 |
% \texttt{/O /Layout /BBox [10 10 50 50]}. The content is stored in an object and the object |
| 2373 |
% reference is than added to the \texttt{/A}. |
| 2374 |
% |
| 2375 |
% \begin{macrocode} |
| 2376 |
%<base>\cs_new_protected:Npn \tag_struct_gput:nnn #1 #2 #3{} |
| 2377 |
%<*package> |
| 2378 |
\cs_set_protected:Npn \tag_struct_gput:nnn #1 #2 #3 |
| 2379 |
{ |
| 2380 |
\cs_if_exist_use:cF {@@_struct_gput_data_#2:nn} |
| 2381 |
{ %warning?? |
| 2382 |
\use_none:nn |
| 2383 |
} |
| 2384 |
{#1}{#3} |
| 2385 |
} |
| 2386 |
\cs_generate_variant:Nn \tag_struct_gput:nnn {ene,nne} |
| 2387 |
%</package> |
| 2388 |
% \end{macrocode} |
| 2389 |
% \end{macro} |
| 2390 |
% |
| 2391 |
% \begin{macro}{\@@_struct_gput_data_ref_aux:nnn} |
| 2392 |
% \begin{macrocode} |
| 2393 |
%<*package> |
| 2394 |
\cs_new_protected:Npn \@@_struct_gput_data_ref_aux:nnn #1 #2 #3 |
| 2395 |
% #1 receiving struct num, #2 key word #3 value |
| 2396 |
{ |
| 2397 |
\prop_get:cnNTF |
| 2398 |
{ g_@@_struct_#1_prop } |
| 2399 |
{Ref} |
| 2400 |
\l_@@_get_tmpc_tl |
| 2401 |
{ |
| 2402 |
\tl_put_right:No \l_@@_get_tmpc_tl |
| 2403 |
{\cs:w @@_struct_Ref_#2:nN \cs_end: {#3},} |
| 2404 |
} |
| 2405 |
{ |
| 2406 |
\tl_set:No \l_@@_get_tmpc_tl |
| 2407 |
{\cs:w @@_struct_Ref_#2:nN \cs_end: {#3},} |
| 2408 |
} |
| 2409 |
\@@_struct_prop_gput:nno |
| 2410 |
{ #1 } |
| 2411 |
{ Ref } |
| 2412 |
{ \l_@@_get_tmpc_tl } |
| 2413 |
} |
| 2414 |
\cs_new_protected:Npn \@@_struct_gput_data_ref:nn #1 #2 |
| 2415 |
{ |
| 2416 |
\@@_struct_gput_data_ref_aux:nnn {#1}{obj}{#2} |
| 2417 |
} |
| 2418 |
\cs_new_protected:Npn \@@_struct_gput_data_ref_label:nn #1 #2 |
| 2419 |
{ |
| 2420 |
\@@_struct_gput_data_ref_aux:nnn {#1}{label}{#2} |
| 2421 |
} |
| 2422 |
\cs_new_protected:Npn \@@_struct_gput_data_ref_dest:nn #1 #2 |
| 2423 |
{ |
| 2424 |
\@@_struct_gput_data_ref_aux:nnn {#1}{dest}{#2} |
| 2425 |
} |
| 2426 |
\cs_new_protected:Npn \@@_struct_gput_data_ref_dest_parent:nn #1 #2 |
| 2427 |
{ |
| 2428 |
\@@_struct_gput_data_ref_aux:nnn {#1}{dest_parent}{#2} |
| 2429 |
} |
| 2430 |
\cs_new_protected:Npn \@@_struct_gput_data_ref_num:nn #1 #2 |
| 2431 |
{ |
| 2432 |
\@@_struct_gput_data_ref_aux:nnn {#1}{num}{#2} |
| 2433 |
} |
| 2434 |
|
| 2435 |
\cs_generate_variant:Nn \@@_struct_gput_data_ref:nn {ee,no} |
| 2436 |
% \end{macrocode} |
| 2437 |
% \end{macro} |
| 2438 |
% |
| 2439 |
% \begin{macro}{\@@_struct_gput_data_attribute:nn} |
| 2440 |
% \begin{macrocode} |
| 2441 |
\cs_new_protected:Npn \@@_struct_gput_data_attribute:nn #1 #2 |
| 2442 |
{ |
| 2443 |
\pdf_object_unnamed_write:nn {dict} {#2} |
| 2444 |
\prop_get:cnNTF { g_@@_struct_#1_prop }{A} \l_@@_tmpa_tl |
| 2445 |
{ |
| 2446 |
\tl_remove_once:Nn\l_@@_tmpa_tl{[} |
| 2447 |
\tl_remove_once:Nn\l_@@_tmpa_tl{]} |
| 2448 |
\@@_prop_gput:cne { g_@@_struct_#1_prop } |
| 2449 |
{ A } |
| 2450 |
{ |
| 2451 |
[ \l_@@_tmpa_tl \c_space_tl \pdf_object_ref_last: ] |
| 2452 |
} |
| 2453 |
} |
| 2454 |
{ |
| 2455 |
\@@_prop_gput:cne { g_@@_struct_#1_prop } |
| 2456 |
{ A } |
| 2457 |
{ \pdf_object_ref_last: } |
| 2458 |
} |
| 2459 |
} |
| 2460 |
% \end{macrocode} |
| 2461 |
% \end{macro} |
| 2462 |
% \begin{macro} |
| 2463 |
% { |
| 2464 |
% \tag_struct_insert_annot:nn, |
| 2465 |
% \tag_struct_insert_annot:ee, |
| 2466 |
% \tag_struct_insert_annot:ee |
| 2467 |
% } |
| 2468 |
% \begin{macro}[EXP] |
| 2469 |
% { |
| 2470 |
% \tag_struct_parent_int: |
| 2471 |
% } |
| 2472 |
% This are the user command to insert annotations. They must be used |
| 2473 |
% together to get the numbers right. They use a counter to the |
| 2474 |
% |StructParent| and \cs{tag_struct_insert_annot:nn} increases the |
| 2475 |
% counter given back by \cs{tag_struct_parent_int:}. |
| 2476 |
% |
| 2477 |
% It must be used together with |\tag_struct_parent_int:| to insert an |
| 2478 |
% annotation. |
| 2479 |
% TODO: decide how it should be guarded if tagging is deactivated. |
| 2480 |
% \begin{macrocode} |
| 2481 |
\cs_new_protected:Npn \tag_struct_insert_annot:nn #1 #2 %#1 should be an object reference |
| 2482 |
%#2 struct parent num |
| 2483 |
{ |
| 2484 |
\@@_check_if_active_struct:T |
| 2485 |
{ |
| 2486 |
\@@_struct_insert_annot:nn {#1}{#2} |
| 2487 |
} |
| 2488 |
} |
| 2489 |
|
| 2490 |
\cs_generate_variant:Nn \tag_struct_insert_annot:nn {xx,ee} |
| 2491 |
\cs_new:Npn \tag_struct_parent_int: {\int_use:c { c@g_@@_parenttree_obj_int }} |
| 2492 |
|
| 2493 |
%</package> |
| 2494 |
|
| 2495 |
% \end{macrocode} |
| 2496 |
% \end{macro} |
| 2497 |
% \end{macro} |
| 2498 |
% \section{Attributes and attribute classes} |
| 2499 |
% \begin{macrocode} |
| 2500 |
%<*header> |
| 2501 |
\ProvidesExplPackage {tagpdf-attr-code} {2026-05-17} {1.0c} |
| 2502 |
{part of tagpdf - code related to attributes and attribute classes} |
| 2503 |
%</header> |
| 2504 |
% \end{macrocode} |
| 2505 |
% \subsection{Variables} |
| 2506 |
% \begin{variable} |
| 2507 |
% { |
| 2508 |
% ,\g_@@_attr_entries_prop |
| 2509 |
% ,\g_@@_attr_class_used_prop |
| 2510 |
% ,\g_@@_attr_objref_prop |
| 2511 |
% ,\l_@@_attr_value_tl |
| 2512 |
% } |
| 2513 |
% |\g_@@_attr_entries_prop| will store attribute names and their dictionary content.\\ |
| 2514 |
% |\g_@@_attr_class_used_prop| will hold the attributes which have been used as |
| 2515 |
% class name. |
| 2516 |
% |\l_@@_attr_value_tl| is used to build the attribute array or key. |
| 2517 |
% Every time an attribute is used for the first time, and object is created |
| 2518 |
% with its content, the name-object reference relation is stored in |
| 2519 |
% |\g_@@_attr_objref_prop| |
| 2520 |
% \begin{macrocode} |
| 2521 |
%<*package> |
| 2522 |
\prop_new:N \g_@@_attr_entries_prop |
| 2523 |
\prop_new_linked:N \g_@@_attr_class_used_prop |
| 2524 |
\tl_new:N \l_@@_attr_value_tl |
| 2525 |
\prop_new:N \g_@@_attr_objref_prop %will contain obj num of used attributes |
| 2526 |
% \end{macrocode} |
| 2527 |
% This seq is currently kept for compatibility with the table code. |
| 2528 |
% \begin{macrocode} |
| 2529 |
\seq_new:N\g_@@_attr_class_used_seq |
| 2530 |
% \end{macrocode} |
| 2531 |
% \end{variable} |
| 2532 |
% \subsection{Commands and keys} |
| 2533 |
% \begin{macro}{\@@_attr_new_entry:nn,role/new-attribute (setup-key), newattribute (deprecated)} |
| 2534 |
% This allows to define attributes. Defined attributes |
| 2535 |
% are stored in a global property. |role/new-attribute| expects |
| 2536 |
% two brace group, the name and the content. The content typically |
| 2537 |
% needs an |/O| key for the owner. An example look like |
| 2538 |
% this. |
| 2539 |
% |
| 2540 |
% TODO: consider to put them directly in the ClassMap, that is perhaps |
| 2541 |
% more effective. |
| 2542 |
% \begin{verbatim} |
| 2543 |
% \tagpdfsetup |
| 2544 |
% { |
| 2545 |
% role/new-attribute = |
| 2546 |
% {TH-col}{/O /Table /Scope /Column}, |
| 2547 |
% role/new-attribute = |
| 2548 |
% {TH-row}{/O /Table /Scope /Row}, |
| 2549 |
% } |
| 2550 |
% \end{verbatim} |
| 2551 |
% \begin{macrocode} |
| 2552 |
\cs_new_protected:Npn \@@_attr_new_entry:nn #1 #2 %#1:name, #2: content |
| 2553 |
{ |
| 2554 |
\prop_gput:Nen \g_@@_attr_entries_prop |
| 2555 |
{\pdf_name_from_unicode_e:n{#1}}{#2} |
| 2556 |
} |
| 2557 |
|
| 2558 |
\cs_generate_variant:Nn \__tag_attr_new_entry:nn {ee} |
| 2559 |
\keys_define:nn { @@ / setup } |
| 2560 |
{ |
| 2561 |
role/new-attribute .code:n = |
| 2562 |
{ |
| 2563 |
\@@_attr_new_entry:nn #1 |
| 2564 |
} |
| 2565 |
% \end{macrocode} |
| 2566 |
% deprecated name |
| 2567 |
% \begin{macrocode} |
| 2568 |
,newattribute .code:n = |
| 2569 |
{ |
| 2570 |
\@@_attr_new_entry:nn #1 |
| 2571 |
}, |
| 2572 |
} |
| 2573 |
% \end{macrocode} |
| 2574 |
% \end{macro} |
| 2575 |
% |
| 2576 |
% \begin{structkeydecl}{attribute-class} |
| 2577 |
% attribute-class has to store the used attribute names so that |
| 2578 |
% they can be added to the ClassMap later. |
| 2579 |
% \begin{macrocode} |
| 2580 |
\keys_define:nn { @@ / struct } |
| 2581 |
{ |
| 2582 |
attribute-class .code:n = |
| 2583 |
{ |
| 2584 |
\clist_set:Ne \l_@@_tmpa_clist { #1 } |
| 2585 |
\seq_set_from_clist:NN \l_@@_tmpb_seq \l_@@_tmpa_clist |
| 2586 |
% \end{macrocode} |
| 2587 |
% we convert the names into pdf names with slash |
| 2588 |
% \begin{macrocode} |
| 2589 |
\seq_set_map_e:NNn \l_@@_tmpa_seq \l_@@_tmpb_seq |
| 2590 |
{ |
| 2591 |
\pdf_name_from_unicode_e:n {##1} |
| 2592 |
} |
| 2593 |
\seq_map_inline:Nn \l_@@_tmpa_seq |
| 2594 |
{ |
| 2595 |
\prop_get:NnNF \g_@@_attr_entries_prop {##1}\l_@@_tmpa_tl |
| 2596 |
{ |
| 2597 |
\msg_error:nnn { tag } { attr-unknown } { ##1 } |
| 2598 |
} |
| 2599 |
\prop_gput:Nnn\g_@@_attr_class_used_prop { ##1} {} |
| 2600 |
} |
| 2601 |
\tl_set:Ne \l_@@_tmpa_tl |
| 2602 |
{ |
| 2603 |
\int_compare:nT { \seq_count:N \l_@@_tmpa_seq > 1 }{[} |
| 2604 |
\seq_use:Nn \l_@@_tmpa_seq { \c_space_tl } |
| 2605 |
\int_compare:nT { \seq_count:N \l_@@_tmpa_seq > 1 }{]} |
| 2606 |
} |
| 2607 |
\int_compare:nT { \seq_count:N \l_@@_tmpa_seq > 0 } |
| 2608 |
{ |
| 2609 |
\@@_struct_prop_gput:nne |
| 2610 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2611 |
{ C } |
| 2612 |
{ \l_@@_tmpa_tl } |
| 2613 |
%\prop_show:c { g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_prop } |
| 2614 |
} |
| 2615 |
} |
| 2616 |
} |
| 2617 |
% \end{macrocode} |
| 2618 |
% \end{structkeydecl} |
| 2619 |
% \begin{structkeydecl}{attribute} |
| 2620 |
% \begin{macrocode} |
| 2621 |
\keys_define:nn { @@ / struct } |
| 2622 |
{ |
| 2623 |
attribute .code:n = % A property (attribute, value currently a dictionary) |
| 2624 |
{ |
| 2625 |
\clist_set:Ne \l_@@_tmpa_clist { #1 } |
| 2626 |
\clist_if_empty:NF \l_@@_tmpa_clist |
| 2627 |
{ |
| 2628 |
\seq_set_from_clist:NN \l_@@_tmpb_seq \l_@@_tmpa_clist |
| 2629 |
% \end{macrocode} |
| 2630 |
% we convert the names into pdf names with slash |
| 2631 |
% \begin{macrocode} |
| 2632 |
\seq_set_map_e:NNn \l_@@_tmpa_seq \l_@@_tmpb_seq |
| 2633 |
{ |
| 2634 |
\pdf_name_from_unicode_e:n {##1} |
| 2635 |
} |
| 2636 |
\tl_set:Ne \l_@@_attr_value_tl |
| 2637 |
{ |
| 2638 |
\int_compare:nT { \seq_count:N \l_@@_tmpa_seq > 1 }{[}%] |
| 2639 |
} |
| 2640 |
\seq_map_inline:Nn \l_@@_tmpa_seq |
| 2641 |
{ |
| 2642 |
\prop_get:NnNF \g_@@_attr_entries_prop {##1}\l_@@_tmp_unused_tl |
| 2643 |
{ |
| 2644 |
\msg_error:nnn { tag } { attr-unknown } { ##1 } |
| 2645 |
} |
| 2646 |
\prop_get:NnNF \g_@@_attr_objref_prop {##1}\l_@@_tmpa_tl |
| 2647 |
{%\prop_show:N \g_@@_attr_entries_prop |
| 2648 |
\pdf_object_unnamed_write:ne |
| 2649 |
{ dict } |
| 2650 |
{ |
| 2651 |
\prop_item:Nn\g_@@_attr_entries_prop {##1} |
| 2652 |
} |
| 2653 |
\prop_gput:Nne \g_@@_attr_objref_prop {##1} {\pdf_object_ref_last:} |
| 2654 |
} |
| 2655 |
\tl_put_right:Ne \l_@@_attr_value_tl |
| 2656 |
{ |
| 2657 |
\c_space_tl |
| 2658 |
\prop_item:Nn \g_@@_attr_objref_prop {##1} |
| 2659 |
} |
| 2660 |
% \tl_show:N \l_@@_attr_value_tl |
| 2661 |
} |
| 2662 |
\tl_put_right:Ne \l_@@_attr_value_tl |
| 2663 |
{ %[ |
| 2664 |
\int_compare:nT { \seq_count:N \l_@@_tmpa_seq > 1 }{]}% |
| 2665 |
} |
| 2666 |
% \tl_show:N \l_@@_attr_value_tl |
| 2667 |
\@@_struct_prop_gput:nne |
| 2668 |
{ \int_use:N \c@g_@@_struct_abs_int } |
| 2669 |
{ A } |
| 2670 |
{ \l_@@_attr_value_tl } |
| 2671 |
} |
| 2672 |
}, |
| 2673 |
} |
| 2674 |
%</package> |
| 2675 |
% \end{macrocode} |
| 2676 |
% \end{structkeydecl} |
| 2677 |
% \end{implementation} |