%%
%% This is file `documentmetadata-support.ltx',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% documentmetadata-support.dtx  (with options: `code')
%% 
%% This is a generated file.
%% 
%% Copyright 2021-2023 LaTeX Project
%% 
%% This file was generated from file(s) of the  `LaTeX-lab Bundle'.
%% ------------------------------------------------------------------------------------
%% 
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%% 
%% This file may only be distributed together with a copy of the LaTeX
%% `LaTeX-lab Bundle'. You may however distribute the `LaTeX-lab Bundle'
%% without such generated files.
%% 
%% The newest sources can be found below
%% 
%%    https://github.com/latex3/latex2e/required/latex-lab
%% 
%% where one can also log issues in case there are any.
%% 
%% 
%% File: documentmetadata-support.dtx
\def\documentmetadatasupportversion{1.0h}
\def\documentmetadatasupportdate{2024-03-26}


\RequirePackage{pdfmanagement-testphase}
\ExplSyntaxOn\makeatletter

\clist_if_exist:NF \g__pdfmanagement_firstaidoff_clist
  { \clist_new:N \g__pdfmanagement_firstaidoff_clist }
\tl_if_exist:NF \g__pdfmanagement_testphase_tl
 { \tl_new:N \g__pdfmanagement_testphase_tl }

\cs_set_protected:Npn \DocumentMetadata #1
  {
    \cs_if_eq:NNTF \documentclass \@twoclasseserror
      { \msg_error:nn { meta } { after-class } }
      {
        \bool_gset_true:N \g__pdfmanagement_active_bool
        \keys_set_groups:nnn { document / metadata} {init}{ #1 }
        %if no backend has been loaded force it now:
        \str_if_exist:NF \c_sys_backend_str
          {
            \sys_load_backend:n {}
          }
        \ExplSyntaxOn\makeatletter
          \file_input:n {l3backend-testphase-\c_sys_backend_str.def}
        \ExplSyntaxOff\makeatother
        \keys_set_filter:nnn  { document / metadata } { init } { #1 }
        \bool_if:NT \g__pdfmanagement_active_bool
          {
            \PassOptionsToPackage{customdriver=hgeneric-testphase}{hyperref}
            \g@addto@macro\@kernel@after@begindocument
             {
               \pdfdict_get:nnN {g__pdf_Core/Catalog}{Lang}\l__pdfmanagement_tmpa_tl
               \quark_if_no_value:NT\l__pdfmanagement_tmpa_tl
                {
                  \tl_if_empty:eTF { \BCPdata{main.language} }
                   { \tl_set:Ne \l__pdfmanagement_tmpb_tl { \BCPdata{language} } }
                   { \tl_set:Ne \l__pdfmanagement_tmpb_tl { \BCPdata{main.language} } }
                  \msg_warning:nne { meta } { lang-missing }{ \l__pdfmanagement_tmpb_tl }
                  \exp_last_unbraced:Ne
                   \AddToDocumentProperties{[document]{lang}{\l__pdfmanagement_tmpb_tl}}
                  \pdfmanagement_add:nne {Catalog} {Lang}{(\l__pdfmanagement_tmpb_tl)}
                }
             }
          }
        \hook_use_once:n {pdfmanagement/add}
        \cs_set_protected:Npn \DocumentMetadata ##1
          {
            \keys_set_filter:nnn  { document / metadata } { init } { ##1 }
            \str_remove_all:cn {opt@hyperref.sty}{customdriver=hgeneric-testphase}
            \bool_if:NT \g__pdfmanagement_active_bool
             {
               \PassOptionsToPackage{customdriver=hgeneric-testphase}{hyperref}
             }
          }
        \g__pdfmanagement_testphase_tl
        \RequirePackage{pdfmanagement-firstaid}
      }
  }

\keys_define:nn { document / metadata }
  {
    backend .choices:nn =
      { dvipdfmx , dvips , dvisvgm , luatex , pdftex , pdfmode , xdvipdfmx , xetex }
      {
        \sys_load_backend:n {#1}
      },
    backend .groups:n = { init } ,
  }

\keys_define:nn { document / metadata }
  {
    ,pdfversion .code:n =
      {
        \pdf_version_gset:n { #1 }
        \AddToDocumentProperties[document]{pdfversion}{#1}
      }
    ,uncompress .code:n =
      {
        \pdf_uncompress:
      }
    ,uncompress .value_forbidden:n = true
    ,lang .code:n =
      {
        \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
        \AddToDocumentProperties[document]{lang}{#1}
      }
    %,xmpmeta .bool_gset:N = \g_pdfmeta_xmp_bool %see pdfmeta unused and undefined for now!
    % this uses internal command from pdfmeta, it should probably move there ...
    ,pdfstandard .code:n =
      {
        \exp_args:Nne
        \keys_set:nn {document / metadata} {_pdfstandard=\str_uppercase:n{#1}}
      }
    ,_pdfstandard .choices:nn =
      {A-1B,A-2A,A-2B,A-2U,A-3A,A-3B,A-3U,A-4}
      {
        \prop_if_exist:cT { g__pdfmeta_standard_pdf/#1_prop }
          {
            \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/#1 _prop }
          }
        \AddToDocumentProperties [document]{pdfstandard}{#1}
      }
    ,_pdfstandard / A-4F .code:n =
      {
        \prop_if_exist:cTF { g__pdfmeta_standard_pdf/A-4F_prop }
          {
            \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4F_prop }
          }
          {
            \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4_prop }
            \prop_gput:Nnn   \g__pdfmeta_standard_prop{conformance}{F}
          }
        \AddToDocumentProperties [document]{pdfstandard}{A-4F}
      }
    ,_pdfstandard / A-4E .code:n =
      {
        \prop_if_exist:cTF { g__pdfmeta_standard_pdf/A-4E_prop }
          {
            \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4E_prop }
          }
          {
            \prop_gset_eq:Nc \g__pdfmeta_standard_prop { g__pdfmeta_standard_pdf/A-4_prop }
            \prop_gput:Nnn   \g__pdfmeta_standard_prop{conformance}{E}
          }
        \AddToDocumentProperties [document]{pdfstandard}{A-4E}
      }
    ,_pdfstandard / unknown .code:n =
      {
        \msg_warning:nnn{pdf}{unknown-standard}{#1}
      }
    ,testphase .multichoice:
    ,testphase / tagpdf .code:n =
      {
        \tl_gput_right:Nn\g__pdfmanagement_testphase_tl
          {
            \file_if_exist_input:nF {tagpdf-latex-lab-testphase.ltx}
              {
                \RequirePackage{tagpdf}
                \AddToDocumentProperties [document]{testphase/tagpdf}{loaded}
                \tagpdfsetup{activate,para/tagging,activate/spaces}
                \AddToDocumentProperties [document]{tagging}{active}
                \AddToDocumentProperties [document]{tagging/para}{active}
                \AddToDocumentProperties [document]{tagging/interwordspace}{active}
              }
          }
      }
    ,testphase / unknown .code:n =
      {
        \tl_gput_right:Nn\g__pdfmanagement_testphase_tl
           {
             \AddToDocumentProperties [document]{testphase/#1}{loaded}
             \file_if_exist_input:nF {#1-latex-lab-testphase.ltx}
              {
                 \msg_warning:nnn{meta}{latex-lab-pkg-missing}{#1}
                 \AddToDocumentProperties [document]{testphase/#1}{missing}
              }
           }
      }
    ,activate .multichoice:
    ,activate / tagging .code:n =
      {
        \PackageWarning{pdfmanagement-testphase}
         {The~activate~key~is~deprecated.\MessageBreak
          Tagging~is~activated~with~'testphase=tagpdf'~directly}{}
      }
    ,debug .code:n =
      {
        \keys_set:nn { document / metadata / debug } {#1}
      }
    ,debug / para .code:n =
      {
        \AddToHook
          {
            package/tagpdf/after
          }
          {
             \tagpdfsetup{debug/show=para}
          }
      }
    ,debug / log .code:n =
      {
        \AddToHook
          {
           package/tagpdf/after
          }
          {
             \tagpdfsetup{debug/log=#1}
          }
      }
    ,debug / tagpdf .code:n =
      {
        \AddToHook
          {
           package/tagpdf/after
          }
          {
             \RequirePackage{tagpdf-debug}
          }
      }
    ,debug / uncompress .code:n =
      {
        \pdf_uncompress:
      }
    ,debug / pdfmanagement .bool_gset:N = \g__pdfmanagement_active_bool
    ,debug / firstaidoff .clist_gset:N = \g__pdfmanagement_firstaidoff_clist
  }

\prop_gput:Nnn \g_msg_module_type_prop { meta } { LaTeX }
\prop_gput:Nnn \g_msg_module_name_prop { meta } { DocumentMetadata }

\msg_new:nnn { meta } { after-class }
             {
                \token_to_str:N \DocumentMetadata \c_space_tl
                should~be~used~only~before~\token_to_str:N\documentclass
             }
\msg_new:nnn { meta } { latex-lab-pkg-missing }
             {
               LaTeX-lab~package~'#1'~not~found.
              }
\msg_new:nnn { meta } { lang-missing }
             {
               The~language~has~not~been~set~in~\token_to_str:N
               \DocumentMetadata.\\Setting~it~to~'#1'~as~fallback.
             }
\ExplSyntaxOff\makeatother
\endinput
%%
%% End of file `documentmetadata-support.ltx'.
