%%
%% This is file `tagpdf-attr-code.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tagpdf-struct.dtx  (with options: `attr')
%% 
%% Copyright (C) 2019 Ulrike Fischer
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    https://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "tagpdf bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: tagpdf-struct.dtx

\ProvidesExplPackage {tagpdf-attr-code} {2021/02/23} {0.80}
  {part of tagpdf - code related to attributes and attribute classes}


\seq_new:N  \g__tag_attr_class_used_seq
\prop_new:N \g__tag_attr_objref_prop %will contain obj num of used attributes

\prop_new:N \g__tag_attr_entries_prop
\tl_new:N   \g__tag_attr_class_content_tl
\tl_new:N   \l__tag_attr_objtmp_tl
\tl_new:N   \l__tag_attr_value_tl

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

\keys_define:nn { __tag / setup }
  {
    newattribute .code:n =
      {
        \__tag_attr_new_entry:nn #1
      }
  }

\keys_define:nn { __tag / 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__tag_attr_entries_prop {##1}
             {
               \msg_error:nnn { tag } { attr-unknown } { ##1 }
             }
           \seq_gput_left:Nn\g__tag_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 }
         {
           \__tag_prop_gput:cnx
             { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
             { C }
             { \l_tmpa_tl }
          %\prop_show:c  { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
         }
    }
  }

\keys_define:nn { __tag / 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__tag_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__tag_attr_entries_prop {##1}
              {
                \msg_error:nnn { tag } { attr-unknown } { ##1 }
              }
            \prop_if_in:NnF \g__tag_attr_objref_prop {##1}
              {%\prop_show:N \g__tag_attr_entries_prop
                \pdf_object_unnamed_write:nx
                  { dict }
                  {
                    \prop_item:Nn\g__tag_attr_entries_prop {##1}
                  }
                \prop_gput:Nnx \g__tag_attr_objref_prop {##1} {\pdf_object_ref_last:}
              }
            \tl_put_right:Nx \l__tag_attr_value_tl
              {
                \c_space_tl
                \prop_item:Nn \g__tag_attr_objref_prop {##1}
              }
 %     \tl_show:N \l__tag_attr_value_tl
          }
        \tl_put_right:Nx \l__tag_attr_value_tl
          { %[
            \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]}%
          }
 %     \tl_show:N \l__tag_attr_value_tl
        \__tag_prop_gput:cnx
          { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
          { A }
          { \l__tag_attr_value_tl }
    },
  }
%% 
%%
%% End of file `tagpdf-attr-code.sty'.
