%%
%% 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.0d}
\def\documentmetadatasupportdate{2023-06-07}

\RequirePackage{pdfmanagement-testphase}
\ExplSyntaxOn\makeatletter

\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 } { lang=en-US, #1 }
        \bool_if:NT \g__pdfmanagement_active_bool
          {
            \PassOptionsToPackage{customdriver=hgeneric-testphase}{hyperref}
          }
        \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:Nnx
        \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 / 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,paratagging,interwordspace}
                \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{paratagging-show}
          }
      }
    ,debug / log .code:n =
      {
        \AddToHook
          {
           package/tagpdf/after
          }
          {
             \tagpdfsetup{log=#1}
          }
      }
    ,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.
              }
\ExplSyntaxOff\makeatother
\endinput
%%
%% End of file `documentmetadata-support.ltx'.
