summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdf-attr-code.sty
blob: 9bb57f2bb3846fff2b660c3ce4c375df71adc451 (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
\ProvidesExplPackage {tagpdf-attr-code} {2019/07/02} {0.61}
 {part of tagpdf - code related to attributes and attribute classes}

% the obj is written in tagpdf-tree-code.

\seq_new:N  \g__uftag_attr_class_used_seq
\prop_new:N \g__uftag_attr_objnum_prop %will contain obj num of used attributes

\prop_new:N \g__uftag_attr_entries_prop
\tl_new:N   \g__uftag_attr_class_content_tl
\tl_new:N   \l__uftag_attr_objtmp_tl
\tl_new:N   \l__uftag_attr_value_tl


\cs_new_protected:Nn \__uftag_attr_new_entry:nn %#1:name, #2: content
 {
  \prop_gput:Nnn \g__uftag_attr_entries_prop
   {#1}{#2}
 }

\keys_define:nn { uftag / setup }
 {
  newattribute .code:n =
   {
    \__uftag_attr_new_entry:nn #1
   }
 }


% the key for the structure:
\keys_define:nn { uftag / struct }
{
 attribute-class .code:n =
 {
   \clist_set:No \l_tmpa_clist { #1 }
   \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist
   \seq_map_inline:Nn \l_tmpa_seq
    {
     \prop_if_in:NnF \g__uftag_attr_entries_prop {##1}
      {
       \msg_error:nnn { uftag } { attr-unknown } { ##1 }
      }
     \seq_gput_left:Nn\g__uftag_attr_class_used_seq { ##1}
    }
   \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
   {
     /##1
   }
  \tl_set:Nx \l_tmpa_tl
   {
    \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[}
    \seq_use:Nn \l_tmpb_seq  { \c_space_tl  }
    \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]}
   }
   \int_compare:nT { \seq_count:N \l_tmpa_seq > 0 }
    {
      \__uftag_prop_gput:cnx
       { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop }
       { C }
       { \l_tmpa_tl }
      %\prop_show:c  { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop }
    }
   }
}

\keys_define:nn { uftag / struct }
 {
  attribute .code:n  = % A property (attribute, value currently a dictionary)
   {
    \clist_set:No          \l_tmpa_clist { #1 }
    \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist
    \tl_set:Nx \l__uftag_attr_value_tl
    {
     \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[}
    }
    \seq_map_inline:Nn \l_tmpa_seq
    {
     \prop_if_in:NnF \g__uftag_attr_entries_prop {##1}
      {
       \msg_error:nnn { uftag } { attr-unknown } { ##1 }
      }
     \prop_if_in:NnF \g__uftag_attr_objnum_prop {##1}
      {
       \__uftag_pdfreserveobjnum:N \l_tmpa_tl
       \__uftag_pdfuseobjnum:Nx    \l_tmpa_tl
        {
          \prop_item:Nn\g__uftag_attr_entries_prop {##1}
        }
        \prop_gput:NnV \g__uftag_attr_objnum_prop {##1} {\l_tmpa_tl}
      }
     \tl_put_right:Nx \l__uftag_attr_value_tl
      {
       \c_space_tl
       \prop_item:Nn \g__uftag_attr_objnum_prop {##1}
       \c_space_tl 0 \c_space_tl R
      }
 %    \tl_show:N \l__uftag_attr_value_tl
    }
    \tl_put_right:Nx \l__uftag_attr_value_tl
     {
      \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]}
     }
 %   \tl_show:N \l__uftag_attr_value_tl
    \__uftag_prop_gput:cnx
     { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop }
     { A }
     { \l__uftag_attr_value_tl }
   },
 }
\endinput