From 5dac6ccc074f72d03d874ffcf70ddc2a9b0db096 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 21 Mar 2019 20:54:17 +0000 Subject: tagpdf (21mar19) git-svn-id: svn://tug.org/texlive/trunk@50509 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/tagpdf/tagpdf-attr-code.sty | 2 +- .../tex/latex/tagpdf/tagpdf-checks-code.sty | 6 +- .../texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def | 30 ++- .../tex/latex/tagpdf/tagpdf-mc-code-generic.sty | 24 +- .../tex/latex/tagpdf/tagpdf-mc-code-lua.sty | 85 +++++-- .../tex/latex/tagpdf/tagpdf-mc-code-shared.sty | 12 +- .../texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def | 18 +- .../tex/latex/tagpdf/tagpdf-roles-code.sty | 2 +- .../tex/latex/tagpdf/tagpdf-space-code.sty | 2 +- .../tex/latex/tagpdf/tagpdf-struct-code.sty | 90 ++++++- .../tex/latex/tagpdf/tagpdf-tree-code.sty | 28 ++- Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty | 16 +- Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua | 41 +++- Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty | 14 +- .../tex/latex/tagpdf/tagpdfdocu-patches.sty | 270 +++++++++++++++++++++ 15 files changed, 548 insertions(+), 92 deletions(-) create mode 100644 Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty (limited to 'Master/texmf-dist/tex/latex/tagpdf') diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty index 986a2ca9ca5..1219e519faa 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-attr-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-attr-code} {2019/03/20} {0.60} {part of tagpdf - code related to attributes and attribute classes} % the obj is written in tagpdf-tree-code. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty index 83822187ffb..dc9bc0fcf2b 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-checks-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-checks-code} {2019/03/20} {0.60} {part of tagpdf - code related to checks and messages} @@ -100,7 +100,7 @@ %mc \cs_new:Nn \__uftag_check_mc_if_nested: { - \_uftag_mc_if_in:T + \__uftag_mc_if_in:T { \msg_warning:nnx {uftag} {mc-nested} { \__uftag_get_mc_abs_cnt: } } @@ -108,7 +108,7 @@ \cs_new:Nn \__uftag_check_mc_if_open: { - \_uftag_mc_if_in:F + \__uftag_mc_if_in:F { \msg_warning:nnx {uftag} {mc-not-open} { \__uftag_get_mc_abs_cnt: } } diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def index f9085e96fbf..db7790e25ba 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def @@ -1,17 +1,31 @@ -\ProvidesExplFile {tagpdf-luatex.def} {2019/01/04} {0.50} +\ProvidesExplFile {tagpdf-luatex.def} {2019/03/20} {0.60} {tagpdf driver for luatex} -\newattribute \g__uftag_mc_type_attr %the value represent the type -\newattribute \g__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value +%\newattribute \g__uftag_mc_type_attr %the value represent the type +%\newattribute \g__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value + +\newattribute \l__uftag_mc_type_attr %the value represent the type +\newattribute \l__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value + \newattribute \g__uftag_interwordspace_attr \newattribute \g__uftag_interwordfont_attr % The lua code +% ensure that 10pt font has been loaded: +{ + \fontencoding{TU}\fontfamily{lmr}\fontseries{m}\fontshape{n}\fontsize{10pt}{10pt}\selectfont +} \directlua { tagpdf=require('tagpdf.lua') } %%%% driver (lualatex) commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% these should be in expl3!!! +\cs_new:Nn \__uftag_pdf_startlink:{ \pdfextension startlink } +\cs_new:Nn \__uftag_pdf_endlink: { \pdfextension endlink } +\cs_new_protected:Nn \__uftag_pdf_lastlink: { \numexpr\pdffeedback lastlink\relax } +\cs_new:Nn \__uftag_pdf_catalog: { \pdfextension catalog } + % needed for \str_set_convert:Nnon \tl_new:N \g__uftag_inputencoding_tl \tl_gset:Nn \g__uftag_inputencoding_tl {} @@ -104,16 +118,6 @@ } -\cs_new:Nn \__uftag_pdfcompresslevel:n - { - \__uftag_tex_pdfvariable:D compresslevel #1 - } - -\cs_new:Nn \__uftag_pdfobjcompresslevel:n - { - \__uftag_tex_pdfvariable:D objcompresslevel #1 - } - % I probably want also lua tables % I put them in the uftag.tables namespaces % The tables will be named like the variables but without backslash diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty index a26fd0fa3ad..85c4f453300 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-mc-code-generic} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-mc-code-generic} {2019/03/20} {0.60} {part of tagpdf - code related to marking chunks - generic mode} % for the label system @@ -13,6 +13,18 @@ % it will contain key-value of type "abspagenum=max mcid on this page" \__uftag_prop_new:N \g__uftag_MCID_byabspage_prop +%to test nesting mc: +\bool_new:N \g__uftag_in_mc_bool + +\prg_new_conditional:Nnn \__uftag_mc_if_in: {p,T,F,TF} + { + \bool_if:NTF \g__uftag_in_mc_bool + { \prg_return_true: } + { \prg_return_false: } + } + +\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__uftag_mc_if_in: {p,T,F,TF} + % this are the low level mc command. % they insert literals and so a are specific to generic mode @@ -122,6 +134,7 @@ % keyval definitions for the user commands: \tl_new:N \l__uftag_mc_key_tag_tl +\tl_new:N \g__uftag_mc_key_tag_tl %for "outside" queries \tl_new:N \l__uftag_mc_key_properties_tl %Attention! definitions are different in luamode. % tag and raw are expanded as \directlua in lua does it too. @@ -131,6 +144,7 @@ { %%????????? \pdfescapename?? \tl_set:Nx \l__uftag_mc_key_tag_tl { #1 } + \tl_gset:Nx \g__uftag_mc_key_tag_tl { #1 } }, raw .code:n = { @@ -207,7 +221,7 @@ { \g__uftag_struct_stack_current_tl } } -\cs_new:Nn \uftag_mc_begin:n +\cs_new_protected:Nn \uftag_mc_begin:n { \group_begin: \__uftag_check_mc_if_nested: @@ -232,14 +246,15 @@ \group_end: } -\cs_new:Nn \uftag_mc_end: +\cs_new_protected:Nn \uftag_mc_end: { \__uftag_check_mc_if_open: \bool_gset_false:N \g__uftag_in_mc_bool + \tl_gset:Nn \g__uftag_mc_key_tag_tl { } \__uftag_mc_emc: } -\cs_new:Nn \uftag_mc_use:n %#1: label name +\cs_new_protected:Nn \uftag_mc_use:n %#1: label name { \tl_set:Nx \l_tmpa_tl { \zref@extractdefault{tagpdf-#1}{tagmcabs}{} } \tl_if_empty:NTF\l_tmpa_tl @@ -265,5 +280,6 @@ } } +\cs_new:Nn \__uftag_get_data_mc_tag: { \g__uftag_mc_key_tag_tl } \endinput diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty index 5ae1c51f6ec..a59df867b9d 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty @@ -1,10 +1,12 @@ -\ProvidesExplPackage {tagpdf-mc-code-lua} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-mc-code-lua} {2019/03/20} {0.60} {tagpdf - mc code only for the luamode } % the two attibutes are defined in the driver file. % it also load the lua (as it can also contain functions needed by generic mode. -% \newattribute \g__uftag_mc_type_attr %the value represent the type -% \newattribute \g__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value +% (new) attributes for mc are local: +% \newattribute \l__uftag_mc_type_attr %the value represent the type +% \newattribute \l__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value + % An attribute for the current structure probably doesn't make sense as mc chunks can be used later. % \newattribute \g__uftag_struct_type_attr %represent the current structure type. Not sure if needed @@ -40,6 +42,15 @@ } } +\prg_new_conditional:Nnn \__uftag_mc_if_in: {p,T,F,TF} + { + \int_compare:nNnTF {-2147483647}={\l__uftag_mc_type_attr} + { \prg_return_true: } + { \prg_return_false: } + } + +\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__uftag_mc_if_in: {p,T,F,TF} + % the keys \tl_new:N \l__uftag_mc_key_tag_tl \tl_new:N \l__uftag_mc_key_label_tl @@ -145,31 +156,54 @@ \tex_global:D \setattribute #1 #2 } +\cs_set_protected:Npn \__uftag_attribute_set:Nn #1 #2 + { + \setattribute #1 #2 + } + \cs_set_protected:Npn \__uftag_attribute_gunset:N #1 { \tex_global:D \unsetattribute #1 } -\cs_new:Nn \__uftag_mc_lua_gset_mc_type_attr:n % #1 is a tag name +\cs_set_protected:Npn \__uftag_attribute_unset:N #1 { - \__uftag_attribute_gset:Nn \g__uftag_mc_type_attr { \directlua {uftag.func.output_num_from ("#1") } } - \__uftag_attribute_gset:Nn \g__uftag_mc_cnt_attr { \__uftag_get_mc_abs_cnt: } + \unsetattribute #1 } -\cs_generate_variant:Nn\__uftag_mc_lua_gset_mc_type_attr:n { o } -\cs_new:Nn \__uftag_mc_lua_gunset_mc_type_attr: +\cs_new:Nn \__uftag_mc_lua_set_mc_type_attr:n % #1 is a tag name { - \__uftag_attribute_gunset:N \g__uftag_mc_type_attr - \__uftag_attribute_gunset:N \g__uftag_mc_cnt_attr + \__uftag_attribute_set:Nn \l__uftag_mc_type_attr { \directlua {uftag.func.output_num_from ("#1") } } + \__uftag_attribute_set:Nn \l__uftag_mc_cnt_attr { \__uftag_get_mc_abs_cnt: } } +\cs_generate_variant:Nn\__uftag_mc_lua_set_mc_type_attr:n { o } + +\cs_new:Nn \__uftag_mc_lua_unset_mc_type_attr: + { + \__uftag_attribute_unset:N \l__uftag_mc_type_attr + \__uftag_attribute_unset:N \l__uftag_mc_cnt_attr + } + + + %This command will in the finish code replace the dummy for a mc by the real mcid kids +%we need a variant for the case that it is the only kid, to get the array right \cs_new:Nn \__uftag_mc_insert_mcid_kids:n { - \directlua {uftag.func.mc_insert_kids (#1) } + \directlua {uftag.func.mc_insert_kids (#1,0) } } +\cs_new:Nn \__uftag_mc_insert_mcid_single_kids:n + { + \directlua {uftag.func.mc_insert_kids (#1,1) } + } + + +% we need to pass the info if the kids are alone or already in an array +% so we add a second argument, which should == 1 if the kids are single + % puts an mcid absolute number in the current structure \cs_new:Nn \__uftag_mc_handle_stash:n %1 mcidnum @@ -178,7 +212,7 @@ \seq_gput_right:cn % Don't fill a lua table due to the command in the item, so the kernel command { g__uftag_struct_kids_\g__uftag_struct_stack_current_tl _seq } { - \__uftag_mc_insert_mcid_kids:n {#1} + \__uftag_mc_insert_mcid_kids:n {#1}% } \directlua { @@ -192,17 +226,18 @@ \cs_generate_variant:Nn \__uftag_mc_handle_stash:n { o } -\cs_new:Nn \uftag_mc_begin:n +\cs_new_protected:Nn \uftag_mc_begin:n { - \group_begin: - \__uftag_check_mc_if_nested: - \bool_gset_true:N \g__uftag_in_mc_bool + %\group_begin: + %\__uftag_check_mc_if_nested: + %\bool_gset_true:N \g__uftag_in_mc_bool \int_gincr:N \c@g__uftag_MCID_abs_int + \tl_clear:N\l__uftag_mc_key_properties_tl \keys_set:nn { uftag / mc }{ label={}, #1 } %check that a tag or artifact has been used \__uftag_check_mc_tag:N \l__uftag_mc_key_tag_tl - %set the attributes (is done globally!): - \__uftag_mc_lua_gset_mc_type_attr:o { \l__uftag_mc_key_tag_tl } + %set the attributes: + \__uftag_mc_lua_set_mc_type_attr:o { \l__uftag_mc_key_tag_tl } \bool_if:NF \l__uftag_mc_artifact_bool { % store the absolute num name in a label: \tl_if_empty:NF {\l__uftag_mc_key_label_tl} @@ -215,17 +250,18 @@ \exp_args:Nx \__uftag_mc_handle_stash:n { \__uftag_get_mc_abs_cnt: } } } - \group_end: + %\group_end: } -\cs_new:Nn \uftag_mc_end: +\cs_new_protected:Nn \uftag_mc_end: { - \__uftag_check_mc_if_open: - \bool_gset_false:N \g__uftag_in_mc_bool - \__uftag_mc_lua_gunset_mc_type_attr: + %\__uftag_check_mc_if_open: + %\bool_gset_false:N \g__uftag_in_mc_bool + \__uftag_mc_lua_unset_mc_type_attr: + \tl_set:Nn \l__uftag_mc_key_tag_tl { } } -\cs_new:Nn \uftag_mc_use:n %#1: label name +\cs_new_protected:Nn \uftag_mc_use:n %#1: label name { \tl_set:Nx \l_tmpa_tl { \zref@extractdefault{tagpdf-#1}{tagmcabs}{} } \tl_if_empty:NTF\l_tmpa_tl @@ -237,6 +273,7 @@ } } +\cs_new:Nn \__uftag_get_data_mc_tag: { \l__uftag_mc_key_tag_tl } \endinput diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty index 789059f4249..b707722cb2f 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-mc-code-shared} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-mc-code-shared} {2019/03/20} {0.60} {part of tagpdf - code related to marking chunks - code shared by generic and luamode } % I use a latex counter for the absolute count, so that it is added to @@ -28,16 +28,6 @@ % value: the structure number the mc is in \__uftag_prop_new:N \g__uftag_mc_parenttree_prop -%to test nesting mc: -\bool_new:N \g__uftag_in_mc_bool - -\prg_new_conditional:Nnn \_uftag_mc_if_in: {p,T,F,TF} - { - \bool_if:NTF \g__uftag_in_mc_bool - { \prg_return_true: } - { \prg_return_false: } - } - %shared keys %the rest are in the splitted code \tl_new:N \l__uftag_mc_artifact_type_tl diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def index 19d5bd926c5..52cc4750ff6 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def @@ -1,10 +1,17 @@ -\ProvidesExplFile {tagpdf-pdftex.def} {2019/01/04} {0.50} +\ProvidesExplFile {tagpdf-pdftex.def} {2019/03/20} {0.60} {tagpdf driver for pdftex} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% driver (pdflatex) commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% these should be in expl3!!! +\cs_new:Nn \__uftag_pdf_startlink:{ \pdfstartlink } +\cs_new:Nn \__uftag_pdf_endlink: { \pdfendlink } +\cs_new:Nn \__uftag_pdf_lastlink: { \pdflastlink } +\cs_new:Nn \__uftag_pdf_catalog: { \pdfcatalog } + + % needed for \str_set_convert:Nnon \tl_new:N \g__uftag_inputencoding_tl \tl_gset:Nn \g__uftag_inputencoding_tl {utf8} @@ -96,15 +103,6 @@ { \tl_set:No #1 { \__uftag_tex_the:D \__uftag_tex_pdfpageattr:D } } -\cs_new:Nn \__uftag_pdfcompresslevel:n - { - \__uftag_tex_pdfcompresslevel:D #1 - } - -\cs_new:Nn \__uftag_pdfobjcompresslevel:n - { - \__uftag_tex_pdfobjcompresslevel:D #1 - } % These commands are only aliases for pdflatex but are defined differently with luatex diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty index 47c55a640f8..fe0f494acd0 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-roles-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-roles-code} {2019/03/20} {0.60} {part of tagpdf - code related to roles and structure names} \__uftag_seq_new:N \g__uftag_role_tags_seq %to get names from numbers diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty index 7e8c5337010..74b252931c3 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-space-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-space-code} {2019/03/20} {0.60} {part of tagpdf - code related to real space chars} % luatex uses an attribute (declared in the driver file) and some luacode in tagpdf.lua % perhaps I will split the code by engine in the future diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty index c6da45cd34c..27106c12c59 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-struct-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-struct-code} {2019/03/20} {0.60} {part of tagpdf - code related to storing structure} % I will use a latex counter for the structure count @@ -159,6 +159,35 @@ } } +\cs_new:Nn\__uftag_struct_kid_link_gput_right:nn %#1 num of parent struct, #2 obj number of link + { + \__uftag_pdfobj:Nn \l__uftag_tmpa_tl + { + << + /Type \c_space_tl /OBJR \c_space_tl + /Obj \c_space_tl #2 \c_space_tl 0 \c_space_tl R + >> + } + \__uftag_seq_gput_right:cx + { g__uftag_struct_kids_#1_seq } + { + \l__uftag_tmpa_tl \c_space_tl 0 \c_space_tl R + } + } + +\cs_generate_variant:Nn\__uftag_struct_kid_link_gput_right:nn { nx} + +\cs_new:Nn\__uftag_struct_exchange_kid_command:N %N= seq + { + \seq_gpop_left:NN #1 \l_tmpa_tl + \regex_replace_once:nnN + {\c{\__uftag_mc_insert_mcid_kids:n}} + {\c{\__uftag_mc_insert_mcid_single_kids:n}} + \l_tmpa_tl + \seq_gput_left:NV #1 \l_tmpa_tl + } +\cs_generate_variant:Nn\__uftag_struct_exchange_kid_command:N { c } + \cs_new:Nn \__uftag_struct_fill_kid_key:n %#1 is the struct num { \int_case:nnF @@ -173,6 +202,12 @@ { } %no kids, do nothing { 1 } % 1 kid, insert { + % in this case we in luamode need a special command in luamode to get the array right. See issue #13 + \bool_if:NT\g__uftag_mode_lua_bool + { + \__uftag_struct_exchange_kid_command:c + {g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq} + } \__uftag_prop_gput:cnx { g__uftag_struct_#1_prop } {K} { \seq_item:cn @@ -190,7 +225,9 @@ { g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq } - {\c_space_tl} + { + \c_space_tl + } ] } } @@ -338,7 +375,7 @@ } -\cs_new:Nn \uftag_struct_begin:n +\cs_new_protected:Nn \uftag_struct_begin:n { \group_begin: \int_gincr:N \c@g__uftag_struct_abs_int @@ -402,13 +439,16 @@ \group_end: } -\cs_new:Nn \uftag_struct_end: +\cs_new_protected:Nn \uftag_struct_end: {%take the current structure num from the stack: %the objects are written later, lua mode hasn't all needed info yet %\seq_show:N \g__uftag_struct_stack_seq \seq_gpop:NNTF \g__uftag_struct_stack_seq \l_tmpa_tl { - \__uftag_check_info_closing_struct:o { \g__uftag_struct_stack_current_tl } + \int_compare:nNnT {\l__uftag_loglevel_int} > { 0 } + { + \__uftag_check_info_closing_struct:o { \g__uftag_struct_stack_current_tl } + } } { \__uftag_check_no_open_struck: } % get the previous one, shouldn't be empty as the root should be there @@ -421,7 +461,7 @@ } } -\cs_new:Nn \uftag_struct_use:n %#1 is the label +\cs_new_protected:Nn \uftag_struct_use:n %#1 is the label { \prop_if_exist:cTF { g__uftag_struct_\zref@extractdefault{tagpdfstruct-#1}{tagstruct}{unknown}_prop } %?????????? @@ -442,4 +482,42 @@ {\msg_warning:nnn{uftag}{struct-label-unknown}{#1}} } + +%%%% Code to tag links +%%%% this works for url, see exp-link.pdf. +%%%% it must be checked for other links + +\cs_new_protected:Nn \__uftag_struct_finish_link: +{ + \bool_if:NT \g_uftag_active_struct_bool + { + %get the number of the parent link structure: + \seq_get:NNF + \g__uftag_struct_stack_seq + \l__uftag_struct_stack_parent_tmp_tl + { + \msg_error:nn { uftag } { struct-faulty-nesting } + } + %put the obj number of link annot in the kid entry: + \__uftag_struct_kid_link_gput_right:nx + { + \l__uftag_struct_stack_parent_tmp_tl + } + { + \int_use:N\__uftag_pdf_lastlink: + } + % add the parent obj number to the parent tree: + \__uftag_parenttree_add_objr:nn + { + \int_use:N\c@g__uftag_parenttree_obj_int + } + { + \prop_item:cn{ g__uftag_struct_\l__uftag_struct_stack_parent_tmp_tl _prop } + { objnum } + } + % increase the int: + \stepcounter{ g__uftag_parenttree_obj_int } + } +} + \endinput diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty index b9667b43f75..acc72b2d668 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-tree-code} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-tree-code} {2019/03/20} {0.60} {part of tagpdf - code related to writing trees and dictionaries to the pdf} %this does the actual finishing: @@ -36,6 +36,31 @@ %the ParentTree \__uftag_pdfreserveobjnum:N \l_tmpa_tl \tl_const:Nx \c__uftag_tree_obj_parenttree_tl { \l_tmpa_tl } + +% we have two sets of entries in the parent tree: +% page streams and real objects. +% The numbers must be distinct and ordered +% So we rely on abspage and put the real objects at the end +% I use a counter to have a chance to get the correct number +% if code is process twice. +\newcounter { g__uftag_parenttree_obj_int } +\AtBeginDocument + { \int_gset:Nn \c@g__uftag_parenttree_obj_int + { \zref@extractdefault{LastPage}{abspage}{100} } + } + +% we need to record the obj references: + +\tl_new:N \g__uftag_parenttree_objr_tl + +\cs_new:Nn \__uftag_parenttree_add_objr:nn %#1 Structparent number, #2 obj number +{ + \tl_gput_right:Nx \g__uftag_parenttree_objr_tl + { + #1 \c_space_tl #2\c_space_tl 0 \c_space_tl R\c_space_tl ^^J + } +} + \tl_new:N \l__uftag_parenttree_content_tl \cs_new:Nn \__uftag_tree_fill_parenttree: @@ -92,6 +117,7 @@ { \__uftag_tree_fill_parenttree: } + \tl_put_right:NV \l__uftag_parenttree_content_tl\g__uftag_parenttree_objr_tl \__uftag_pdfuseobjnum:xx { \c__uftag_tree_obj_parenttree_tl } { <<\c_space_tl/Nums\c_space_tl [\l__uftag_parenttree_content_tl] \c_space_tl >> diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty index c4a16b29420..0f5a9d9059b 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty @@ -1,4 +1,4 @@ -\ProvidesExplPackage {tagpdf-user} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf-user} {2019/03/20} {0.60} {tagpdf - user commands} \NewDocumentCommand \tagpdfsetup { m } @@ -10,10 +10,16 @@ \cs_set_eq:NN\tagpdfifluatexT \sys_if_engine_luatex:T \cs_set_eq:NN\tagpdfifpdftexT \sys_if_engine_pdftex:T +%%% a generic command to retrieve data + +\cs_new:Npn \tagpdfget #1 { \uftag_get:n { #1} } +\cs_new:Npn \uftag_get:n #1 { \use:c {__uftag_get_data_#1: } } + + %%%% mc related user commands \NewDocumentCommand \tagmcifinTF { m m } { - \_uftag_mc_if_in:TF { #1 } { #2 } + \__uftag_mc_if_in:TF { #1 } { #2 } } \NewDocumentCommand \tagmcbegin { m } @@ -74,9 +80,9 @@ \directlua { uftag.trace.log( - "showtagpdfattributes: MC=>abscnt=\__uftag_get_mc_abs_cnt:=>attr=\the\g__uftag_mc_cnt_attr=>tag=" .. - tostring(uftag.func.get_tag_from (\the\g__uftag_mc_type_attr)) .. - "=\the\g__uftag_mc_type_attr",0 + "showtagpdfattributes: MC=>abscnt=\__uftag_get_mc_abs_cnt:=>attr=\the\l__uftag_mc_cnt_attr=>tag=" .. + tostring(uftag.func.get_tag_from (\the\l__uftag_mc_type_attr)) .. + "=\the\l__uftag_mc_type_attr",0 ) } \ignorespaces diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua index c0262626181..577afedaa11 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua @@ -1,5 +1,5 @@ --- Packageversion: 0.50 --- Packagedate: 2019/01/04 +-- Packageversion: 0.60 +-- Packagedate: 2019/03/20 -- tagpdf.lua -- Ulrike Fischer @@ -52,8 +52,8 @@ functions uftag.trace.showspaces : boolean --]] -local mctypeattributeid = luatexbase.registernumber ("g__uftag_mc_type_attr") -local mccntattributeid = luatexbase.registernumber ("g__uftag_mc_cnt_attr") +local mctypeattributeid = luatexbase.registernumber ("l__uftag_mc_type_attr") +local mccntattributeid = luatexbase.registernumber ("l__uftag_mc_cnt_attr") local iwspaceattributeid = luatexbase.registernumber ("g__uftag_interwordspace_attr") local iwfontattributeid = luatexbase.registernumber ("g__uftag_interwordfont_attr") @@ -184,6 +184,13 @@ local function __uftag_mark_spaces (head) if uftag.trace.showspaces then __uftag_show_spacemark (head,glyph) end + elseif glyph.next and (glyph.next.id==KERN) and not inside_math then + local kern = glyph.next + if kern.next and (kern.next.id== GLUE) and (kern.next.width >0) + then + nodesetattribute(kern.next,iwspaceattributeid,1) + nodesetattribute(kern.next,iwfontattributeid,glyph.font) + end end elseif id == PENALTY then local glyph = n @@ -297,7 +304,8 @@ function uftag.func.mark_page_elements (box,mcpagecnt,mccntprev,mcopen,name,mcty end elseif n.id == LOCAL_PAR then -- local_par is ignored elseif n.id == PENALTY then -- penalty is ignored - elseif n.id == KERN then -- kern is ignored + elseif n.id == KERN then -- kern is ignored + uftag.trace.log ("SUBTYPE KERN ".. n.subtype,3) else -- math is currently only logged. -- we could mark the whole as math @@ -504,10 +512,24 @@ function uftag.func.store_mc_kid (mcnum,kid,page) tableinsert(uftag.mc[mcnum]["kids"], kidtable ) end -function uftag.func.mc_insert_kids (mcnum) +function uftag.func.mc_num_of_kids (mcnum) + local num = 0 + if uftag.mc[mcnum] and uftag.mc[mcnum]["kids"] then + texio.write_nl("XXXXXXXXXXXXXXXXX") + texio.write_nl(table.serialize(uftag.mc[mcnum]["kids"])) + num = #uftag.mc[mcnum]["kids"] + end + uftag.trace.log ("MC" .. mcnum .. "has " .. num .. "KIDS",4) + return num +end + +function uftag.func.mc_insert_kids (mcnum,single) if uftag.mc[mcnum] then uftag.trace.log("MC-KIDS test " .. mcnum,4) if uftag.mc[mcnum]["kids"] then + if #uftag.mc[mcnum]["kids"] > 1 and single==1 then + tex.sprint("[") + end for i,kidstable in ipairs( uftag.mc[mcnum]["kids"] ) do local kidnum = kidstable["kid"] local kidpage = kidstable["page"] @@ -515,6 +537,9 @@ function uftag.func.mc_insert_kids (mcnum) uftag.trace.log("MC" .. mcnum .. " insert KID " ..i.. " with num " .. kidnum .. " on page " .. kidpage.."/"..kidpageobjnum,3) tex.sprint(catlatex,"<> " ) end + if #uftag.mc[mcnum]["kids"] > 1 and single==1 then + tex.sprint("]") + end else uftag.trace.log("WARN! MC"..mcnum.." has no kids",0) end @@ -561,7 +586,7 @@ function uftag.func.fill_parent_tree_line (page) mcchunks=#uftag.page[page] uftag.trace.log("PAGETREE PAGE "..page.." has "..mcchunks.."+1 Elements ",3) for i=0,mcchunks do - uftag.trace.log("PAGETREE CHUNKS "..uftag.page[page][i],0) + uftag.trace.log("PAGETREE CHUNKS "..uftag.page[page][i],3) end if mcchunks == 0 then -- only one chunk so no need for an array @@ -576,7 +601,7 @@ function uftag.func.fill_parent_tree_line (page) numsentry = pdfpage .. " [" for i=0,mcchunks do local mcnum = uftag.page[page][i] - local structnum = uftag.mc[mcnum]["parent"] + local structnum = uftag.mc[mcnum]["parent"] or 0 local propname = "g__uftag_struct_"..structnum.."_prop" local objnum = uftag.tables[propname]["objnum"] or "XXXX" numsentry = numsentry .. " ".. objnum .. " 0 R" diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty index 1c1b7740037..f583383c897 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty @@ -1,7 +1,7 @@ \RequirePackage{expl3}[2018/06/14] %\RequirePackage[enable-debug]{expl3}[2018/06/14] -\ProvidesExplPackage {tagpdf} {2019/01/04} {0.50} +\ProvidesExplPackage {tagpdf} {2019/03/20} {0.60} {A package to experiment with pdf tagging} %\debug_on:n{check-declarations,check-expressions,deprecation} @@ -83,11 +83,16 @@ tabsorder / structure .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {/Tabs/S}}, tabsorder / none .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {}}, tabsorder .initial:n = structure, - compresslevel .choices:nn = {0,1,2,3,4,5,6,7,8,9} + compresslevel .choices:nn = {1,2,3,4,5,6,7,8,9} { - \__uftag_pdfcompresslevel:n {#1} - \__uftag_pdfobjcompresslevel:n {#1} + \driver_pdf_compresslevel:n {#1} + \driver_pdf_objects_enable: }, + compresslevel / 0 .code:n = + { + \driver_pdf_compresslevel:n { 0 } + \driver_pdf_objects_disable: + }, compresslevel .value_required:n = true, uncompress .meta:n = { compresslevel = 0 }, inputencoding .code:n = @@ -168,6 +173,7 @@ \cs_generate_variant:Nn \__uftag_gset_pdfpageattr:n {x} % few temp tl +\tl_new:N \g__uftag_tmpa_tl \tl_new:N \l__uftag_tmpa_tl \tl_new:N \l__uftag_tmpb_tl \tl_new:N \l__uftag_tmpc_tl diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty new file mode 100644 index 00000000000..bbebe1a99f3 --- /dev/null +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty @@ -0,0 +1,270 @@ +\RequirePackage{expl3}[2018/06/14] +%\RequirePackage[enable-debug]{expl3}[2018/06/14] +\RequirePackage{xpatch} +\ProvidesExplPackage {tagpdfdocu-patches} {2019/03/20} {0.60} + {patches/commands for the tagpdf documentation} + +% to do : marginnote, perhaps the description macros ... +% to do: footnotes! +% printbibliography? + +\newbibmacro*{begentry}{\tagstructbegin{tag=BibEntry}\tagmcbegin{tag=BibEntry}} +\newbibmacro*{finentry}{\finentry\tagmcend\tagstructend} + +% hyperref +\@ifpackageloaded{hyperref}{% +\pdfstringdefDisableCommands{ + \let\tagstructbegin\@gobble + \let\tagmcbegin\@gobble + \let\tagmcend\relax + \let\tagstructend\relax +}}{} + +%%%%% +% Paragraphs +%%%%% + +% we need a command which simply starts a paragraph \TagP^, +% a "continuation" variant which closes the previous paragraph (\TagP), +% and a final end. + +\NewDocumentCommand\TagP{t{^}} + { + \uftag_mc_if_in:T { \uftag_mc_end: } + \IfBooleanF{#1} + { + \uftag_struct_end: + } + \uftag_struct_begin:n{tag=P} + \uftag_mc_begin:n{tag=P} + } +% close a mc and one structure + +\NewDocumentCommand\TagPend{} + { + \uftag_mc_if_in:T { \uftag_mc_end: } + \uftag_struct_end: + } + + +%%%%% +% maketitle +%%%%% +\tagpdfsetup{ add-new-tag=Title/H1 } + +%%%%% +% tableofcontents +%%%%% + +%Marking the toc entries +%around the whole entry so only structure: +\newcommand\tagscrtocentry[1]{\uftag_struct_begin:n{tag=TOCI}#1\uftag_struct_end:} + +%leaf so structure and mc: +\newcommand\tagscrtocpagenumber[1]{% + \uftag_struct_begin:n{tag=Reference}% + \uftag_mc_begin:n{tag=Reference}% + #1% + \uftag_mc_end: + \uftag_struct_end:} + + +\DeclareTOCStyleEntry[ + entryformat=\tagscrtocentry, + pagenumberformat=\tagscrtocpagenumber]{tocline}{section} +\DeclareTOCStyleEntry[ + entryformat=\tagscrtocentry, + pagenumberformat=\tagscrtocpagenumber]{tocline}{subsection} +\DeclareTOCStyleEntry[ + entryformat=\tagscrtocentry, + pagenumberformat=\tagscrtocpagenumber]{tocline}{subsubsection} +\DeclareTOCStyleEntry[ + entryformat=\tagscrtocentry, + pagenumberformat=\tagscrtocpagenumber]{tocline}{paragraph} + + + +\renewcommand{\addtocentrydefault}[3]{% + \ifstr{#3}{}{} + {%\ + \ifstr{#2}{} + {% + \addcontentsline{toc}{#1} + {% + \protect\nonumberline + \tagstructbegin{tag=P}% + \tagmcbegin{tag=P}% + #3% + \tagmcend + \tagstructend + }% + }% + {% + \addcontentsline{toc}{#1}{% + \tagstructbegin{tag=Lbl}% + \tagmcbegin{tag=Lbl}% + \protect\numberline{#2}% + \tagmcend\tagstructend + \tagstructbegin{tag=P}% + \tagmcbegin{tag=P}% + #3% + \tagmcend + \tagstructend + }% + }% + }}% + +% the dots must be marked too + +\renewcommand*{\TOCLineLeaderFill}[1][.]{ + \leaders\hbox{$\m@th + \mkern \@dotsep mu\hbox{\uftag_mc_begin:n{artifact}#1\uftag_mc_end:}\mkern \@dotsep + mu$}\hfill +} + +%%%%%%%%% +% Sectioning commands +%%%%%%%% + +\prop_new:N \g_tag_section_level_prop +\prop_gput:Nnn \g_tag_section_level_prop {section}{H1} +\prop_gput:Nnn \g_tag_section_level_prop {subsection}{H2} +\prop_gput:Nnn \g_tag_section_level_prop {subsubsection}{H3} +\prop_gput:Nnn \g_tag_section_level_prop {paragraph}{H4} + + + +%unnumbered sections level give an empty mc, need to think about it. +\renewcommand{\sectionlinesformat}[4] + { + \@hangfrom + {\hskip #2 + \tagstructbegin{tag=\prop_item:Nn\g_tag_section_level_prop{#1}} + \tl_if_empty:nF{#3} + { + \uftag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} + #3 + \uftag_mc_end: + } + } + {\uftag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} + #4 + \uftag_mc_end:\tagstructend}% + } + +%minisec is simply P, H6 doesn't work .... +\cs_new:Nn \__uftag_docu_tag_minisec:n +{ + \uftag_struct_begin:n {tag=P} + \uftag_mc_begin:n{tag=P} + #1 + \uftag_mc_end: + \uftag_struct_end: +} + +\addtokomafont{minisec}{\__uftag_docu_tag_minisec:n} + +\AfterTOCHead{\uftag_struct_begin:n{tag=TOC}} +\AfterStartingTOC{\uftag_struct_end:} %end TOC + +%% list + +\newcommand\uftag@enit@format@preset[1]{% + \tagstructbegin{tag=LI}% + \tagstructbegin{tag=Lbl}% + \tagmcbegin{tag=Lbl}% + #1% + \tagmcend + \tagstructend %end Lbl + \tagstructbegin{tag=LBody}} + +\newcommand\meti{% end of \item + \tagstructend %end of LBody + \tagstructend %end of LI +} + +\newcommand\Pmeti{% end of \item + \TagPend %end of P + \tagstructend %end of LBody + \tagstructend %end of LI +} + +\ExplSyntaxOff +\xpatchcmd\enit@preset{\@firstofone}{\uftag@enit@format@preset}{}{\fail} +\ExplSyntaxOn +\setlist{ + before*=\tagstructbegin{tag=L}, + after*={\tagstructend}} + +% keys that overwrite \enit@format must be patched, eg like the follow +% the font key should be patched in a similar way +\enitkv@key{enumitem}{format}{% + \def\enit@format{% + \tagstructbegin{tag=LI}% + \tagstructbegin{tag=Lbl}% + \tagmcbegin{tag=Lbl}% + #1\tagmcend}} + + %%% hooks for links + %%% attention, to get the order right, it is necessary currently to start a new + %%% mc after a link! I'm not sure if this can/group be included in the hooks + %%% grouping is a bit tricky ... +\cs_if_exist:NT\hook_put_left:nnn +{ + \hook_put_left:nnn + { pdf } + { startlink_url } + { + \uftag_struct_begin:n{tag=Link} + \uftag_mc_begin:n{tag=Link}\def\blub{abc} + } +\hook_put:nnnn + { pdf } + { startlink_url_attr } + { /StructParent } + { \int_use:N\c@g__uftag_parenttree_obj_int } + +\hook_put_right:nnn + { pdf } + { endlink_url } + { + \__uftag_struct_finish_link: + \uftag_mc_end: + \uftag_struct_end: + } + +\hook_put_left:nnn + { pdf } + { startlink_link } + { + \uftag_struct_begin:n{tag=Link} + \uftag_mc_begin:n{tag=Link} + } +\hook_put:nnnn + { pdf } + { startlink_link_attr } + { /StructParent } + { \int_use:N\c@g__uftag_parenttree_obj_int } +\hook_put_right:nnn + { pdf } + { endlink_link } + { + \__uftag_struct_finish_link: + \uftag_mc_end: + \uftag_struct_end: + } + +% "alternative descriptions " for PAX3. How to get better text here?? +\hook_put:nnnn + { pdf } + { startlink_url_attr } + { /Contents } + { (url) } + +\hook_put:nnnn + { pdf } + { startlink_link_attr } + { /Contents } + { (ref) } + } +\endinput -- cgit v1.2.3