summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty
blob: b1959acc42e98c307085eb2ce43ea0e5c4b12954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
\ProvidesExplPackage {tagpdf-checks-code} {2018/07/04} {0.1}
 {part of tagpdf - code related to checks and messages}


%messages

% mc
\msg_new:nnn { tagpdf } { mc-nested }       { nested~marked~content~found~-~mcid~#1 }
\msg_new:nnn { tagpdf } { mc-tag-missing }  { required~tag~missing~-~mcid~#1 }
\msg_new:nnn { tagpdf } { mc-label-unknown }{ label~#1~unknown~-~rerun }
\msg_new:nnn { tagpdf } { mc-used-twice }   { mc~#1~has~been~already~used }
\msg_new:nnn { tagpdf } { mc-not-open }     { there~is~no~mc~to~end~at~#1 }

% structures
\msg_new:nnn { tagpdf } { struct-no-objnum    }     { objnum~missing~for~structure~#1 }
\msg_new:nnn { tagpdf } { struct-faulty-nesting }   { there~is~no~open~structure~on~the~stack }
\msg_new:nnn { tagpdf } { struct-missing-tag }      { a~structure~must~have~a~tag! }
\msg_new:nnn { tagpdf } { struct-show-closing }     { closing~structure~#1~tagged~\prop_item:cn{g__uftag_struct_#1_prop}{S} }
\msg_new:nnn { tagpdf } { struct-used-twice}        { structure~with~label~#1~has~already~been~used}
\msg_new:nnn { tagpdf } { struct-label-unknown}     { structure~with~label~#1~is~unknown~rerun}


%Roles
\msg_new:nnn { tagpdf } { role-missing    }     { tag~#1~has~no~role~assigned  }
\msg_new:nnn { tagpdf } { role-unknown  }  { role~#1~is~not~known  }
\msg_new:nnn { tagpdf } { role-unknown-tag }   { tag~#1~is~not~known  }
\msg_new:nnn { tagpdf } { role-new-tag  }  { adding~new~tag~#1~mapped~to~role~#2  }


% trees
\msg_new:nnn { tagpdf } {tree-mcid-index-wrong } {something~is~wrong~with~the~mcid}

% obj
\msg_new:nnn { tagpdf } {obj-write-num } {write~obj~#1~to~pdf}


%checks
%structures

\cs_new:Nn \__uftag_check_structure_has_tag:n %#1 struct num
 {
  \prop_if_in:cnF { g__uftag_struct_#1_prop }
   {S}
   {
    \msg_error:nn { tagpdf }{ struct-missing-tag }
   }
 }

\cs_new:Nn \__uftag_check_info_closing_struct:n %#1 struct num
 {
  \msg_info:nnn {tagpdf}{struct-show-closing}{#1}
 }

\cs_generate_variant:Nn \__uftag_check_info_closing_struct:n {o,x}

\cs_new:Nn \__uftag_check_no_open_struck:
 {
  \msg_error:nn {tagpdf}{ struct-faulty-nesting }
 }

\cs_new:Nn \__uftag_check_struct_used:n %#1 label
 {
  \prop_get:cnNT
   {g__uftag_struct_\zref@extractdefault{tagpdfstruct-#1}{tagstruct}{unknown}_prop}
   {P}
   \l_tmpa_tl
   {\msg_warning:nnn {tagpdf}{struct-used-twice}{#1}}
 }

%roles

\cs_new:Nn \__uftag_check_add_tag_role:nn %#1 tag, #2 role
 {
  \tl_if_empty:nTF { #2 }
  {
   \msg_warning:nnn { tagpdf }{ role-missing } { #1 }
  }
  {
   \prop_get:NnNF \g__uftag_role_tags_prop { #2 } \l_tmpa_tl
    {
     \msg_warning:nnn { tagpdf }{ role-unknown } { #2 }
    }
    {
     \msg_info:nnnn { tagpdf }{ role-new-tag } { #1 }{ #2 }
    }
  }
 }

%mc
\cs_new:Nn \__uftag_check_mc_if_nested:
 {
  \_uftag_mc_if_in:T
   {
    \msg_warning:nnx {tagpdf}{mc-nested}{ \__uftag_get_mc_abs_cnt: }
   }
 }

\cs_new:Nn \__uftag_check_mc_if_open:
 {
  \_uftag_mc_if_in:F
   {
    \msg_warning:nnx {tagpdf}{mc-not-open}{ \__uftag_get_mc_abs_cnt: }
   }
 }

\cs_new:Nn \__uftag_check_mc_tag:N
 {
  \tl_if_empty:NT #1
   {
    \msg_error:nnx {tagpdf}{mc-tag-missing}{ \__uftag_get_mc_abs_cnt: }
   }
   \prop_if_in:NoF \g__uftag_role_tags_prop { #1 }
   {
    \msg_warning:nnx {tagpdf}{role-unknown-tag} { #1 }
   }
 }

\seq_new:N \g__uftag_check_mc_used_seq
\cs_new:Nn \__uftag_check_mc_used:n
 {
  \seq_if_in:NnTF \g__uftag_check_mc_used_seq { #1 }
   {
    \msg_warning:nnn {tagpdf}{mc-used-twice}{ #1 }
   }
   {
    \seq_gput_right:Nx\g__uftag_check_mc_used_seq { #1 }
   }
 }



\cs_new:Nn \__uftag_check_show_MCID_by_page:
 {
  \tl_set:Nx \l__uftag_tmpa_tl
  {
   \zref@extractdefault
    {LastPage} {abspage} {-1}
  }
  \int_step_inline:nnnn {1}{1}
  {
   \l__uftag_tmpa_tl
  }
  {
   \seq_clear:N \l_tmpa_seq
   \int_step_inline:nnnn {1}{1}
    {
     \zref@extractdefault
     {LastPage} {tagmcabs} {-1}
    }
    {
     \int_compare:nT
     {
      \zref@extractdefault
      {mcid-####1} {tagabspage} {-1}
      = ##1
     }
     {
      \seq_gput_right:Nx \l_tmpa_seq
      {
       Page##1-####1-\zref@extractdefault
       {mcid-####1} {tagmcid} {-1}
      }
     }
    }
    \seq_show:N \l_tmpa_seq
  }
 }

\cs_new:Nn\__uftag_check_record_pdfobj_num:n
 {
  \int_compare:nT {\l__uftag_loglevel_int >= 3 }
   {
    \msg_info:nnx { tagpdf }{obj-write-num}{#1}
   }
 }

\endinput