%%
%% This is file `l3backend-testphase-pdftex.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3backend-testphase.dtx  (with options: `drivers,pdftex')
%% 
%% Copyright (C) 2019-2021 The LaTeX Project
%% 
%% 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 "LaTeX PDF management testphase bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: l3backend-testphase.dtx
\ProvidesExplFile
  {l3backend-testphase-pdftex.def}{2023-10-09}{}
  {LaTeX~PDF~management~testphase~bundle~backend~support: PDF output (pdfTeX)}
\cs_generate_variant:Nn \__kernel_backend_literal_page:n { e }
\bool_if:NT \l__pdfmanagement_delayed_shipout_bool
 {
   \cs_new_protected:Npn \__kernel_backend_shipout_literal:e #1
     { \tex_special:D~shipout { #1} }
  \cs_new_protected:Npn \__kernel_backend_shipout_literal_pdf:e #1
    {
      \tex_pdfliteral:D ~ shipout ~
        { #1 }
    }
  \cs_new_protected:Npn \__kernel_backend_shipout_literal_page:e #1
    {
      \tex_pdfliteral:D ~ shipout ~
        page { #1 }
    }
 }

\RequirePackage{l3ref-tmp}
\cs_if_exist:NTF \property_new:nnnn
 {
   \cs_new_protected:Npn \__pdf_backend_record_abspage:n #1
     {
        \@bsphack
        \property_record:nn{#1}{abspage}
        \@esphack
     }
   \cs_new:Npn \__pdf_backend_ref_abspage:n #1
     {
        \property_ref:nn{#1}{abspage}
     }

 }
 {
   \cs_new_protected:Npn \__pdf_backend_record_abspage:n #1
    %% \__pdf_backend_ref_label:nn #1 #2
     {
        \@bsphack
        \ref_label:nn{#1}{abspage}
        \@esphack
     }
   \cs_new:Npn \__pdf_backend_ref_abspage:n #1
    %% \__pdf_backend_ref_value:nn #1 #2
     {
        \ref_value:nn{#1}{abspage}
     }
 }
\cs_generate_variant:Nn \__pdf_backend_record_abspage:n {e}
\cs_generate_variant:Nn \__pdf_backend_ref_abspage:n {e}
\prop_new:N \g__pdf_tmpa_prop
\tl_new:N   \l__pdf_tmpa_tl
\box_new:N  \l__pdf_backend_tmpa_box
\box_new:N  \l__pdf_backend_tmpb_box
\int_new:N \g__pdf_backend_resourceid_int
\int_new:N \g__pdf_backend_name_int
\int_new:N \g__pdf_backend_page_int
\cs_new:Npn \__kernel_pdf_name_from_unicode_e:n #1
  {
    / \str_convert_pdfname:e { \text_expand:n { #1 } }
  }
\tl_gput_right:Nn \@kernel@after@enddocument@afterlastpage
  {
    \g__kernel_pdfmanagement_end_run_code_tl
  }
\tl_if_exist:NTF \@kernel@after@shipout@background
  {
    \g@addto@macro \@kernel@before@shipout@background{\relax}
    \g@addto@macro \@kernel@after@shipout@background
      {
        \g__kernel_pdfmanagement_thispage_shipout_code_tl
      }
  }
  {
    \hook_gput_code:nnn{shipout/background}{pdf}
      {
        \g__kernel_pdfmanagement_thispage_shipout_code_tl
      }
  }

\cs_new_protected:Npn \__pdf_backend_Pages_primitive:n #1
  {
    \tex_global:D \tex_pdfpagesattr:D { #1 }
  }
 %the primitive
  \cs_new_protected:Npn \__pdf_backend_Page_primitive:n #1
    {
      \tex_global:D \tex_pdfpageattr:D { #1 }
    }
 \cs_new_protected:Npn \__pdf_backend_Page_gput:nn #1 #2 %key,value
   {
     \pdfdict_gput:nnn {g__pdf_Core/Page}{ #1 }{ #2 }
   }
\cs_new_protected:Npn \__pdf_backend_Page_gremove:n #1
  {
    \pdfdict_gremove:nn  {g__pdf_Core/Page}{ #1 }
  }
\cs_new_protected:Npn \__pdf_backend_ThisPage_gput:nn #1 #2
  {
    %we need to know the page the resource should be added too.
    \int_gincr:N\g__pdf_backend_resourceid_int
    \__pdf_backend_record_abspage:e { l3pdf\int_use:N\g__pdf_backend_resourceid_int }
    \tl_set:Nx \l__pdf_tmpa_tl
      {
        \__pdf_backend_ref_abspage:e {l3pdf\int_use:N\g__pdf_backend_resourceid_int}
      }
    \pdfdict_if_exist:nF { g__pdf_Core/backend_Page\l__pdf_tmpa_tl}
      {
        \pdfdict_new:n { g__pdf_Core/backend_Page\l__pdf_tmpa_tl}
      }
    %backend_Page has no handler.
    \pdfdict_gput:nnn {g__pdf_Core/backend_Page\l__pdf_tmpa_tl}{ #1 }{ #2 }
  }
\cs_new_protected:Npn \__pdf_backend_ThisPage_gpush:n #1
  {
    \prop_gset_eq:Nc \g__pdf_tmpa_prop { \__kernel_pdfdict_name:n { g__pdf_Core/Page } }
    \prop_if_exist:cT  { \__kernel_pdfdict_name:n { g__pdf_Core/backend_Page#1 } }
      {
        \prop_map_inline:cn { \__kernel_pdfdict_name:n { g__pdf_Core/backend_Page#1 } }
          {
            \prop_gput:Nnn \g__pdf_tmpa_prop { ##1 }{ ##2 }
          }
      }
    \__pdf_backend_Page_primitive:e
      {
        \prop_map_function:NN \g__pdf_tmpa_prop \pdfdict_item:ne
      }
  }
\cs_generate_variant:Nn \__pdf_backend_Page_primitive:n { e }
\clist_const:Nn \c__pdf_backend_PageResources_clist
  {
    ExtGState,
    ColorSpace,
    Pattern,
    Shading,
  }
\clist_map_inline:Nn \c__pdf_backend_PageResources_clist
  {
    \pdf_object_new:n {__pdf/Page/Resources/#1}
    \cs_if_exist:NT \tex_directlua:D
      {
        \tex_directlua:D
          {
            ltx.__pdf.object["__pdf/Page/Resources/#1"]
            =
            "\__pdf_backend_object_ref:n{__pdf/Page/Resources/#1}"
          }
      }
   }
 \cs_new_protected:Npn \__pdf_backend_PageResources_gput:nnn #1 #2 #3
   {
     \pdfdict_gput:nnn {g__pdf_Core/Page/Resources/#1} { #2 }{ #3 }
   }
\cs_new_protected:Npn \__pdf_backend_PageResources_obj_gpush:
  {
    \clist_map_inline:Nn \c__pdf_backend_PageResources_clist
      {
        \prop_if_empty:cF
          { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/##1} }
          {
            \pdf_object_write:nnx
              { __pdf/Page/Resources/##1 } { dict }
              { \pdfdict_use:n { g__pdf_Core/Page/Resources/##1} }
          }
     }
  }
\bool_new:N \l__pdf_backend_xform_bool

\cs_set_protected:Npn \__pdf_backend_bdcobject:nn #1 #2 % #1 eg. Span, #2: object name
  {
    \int_gincr:N \g__pdf_backend_name_int
    \__kernel_backend_literal_page:e
      { /#1 ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC }
    % code to set the property ....
    \int_gincr:N\g__pdf_backend_resourceid_int
    \bool_if:NTF \l__pdf_backend_xform_bool
      {
        \pdfdict_gput:nee %no handler needed
          { g__pdf_Core/Xform/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_resourceid_int }
          { \__pdf_backend_object_ref:n { #2 } }
      }
      {
        \__pdf_backend_record_abspage:e {l3pdf\int_use:N\g__pdf_backend_resourceid_int}
        \tl_set:Nx \l__pdf_tmpa_tl
          {
            \__pdf_backend_ref_abspage:e{l3pdf\int_use:N\g__pdf_backend_resourceid_int}
          }
        \pdfdict_if_exist:nF { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          {
            \pdfdict_new:n { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          }
        \pdfdict_gput:nee
          { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_resourceid_int }
          { \__pdf_backend_object_ref:n{#2} }
      }
  }
\cs_set_protected:Npn \__pdf_backend_bdcobject:n #1% #1 eg. Span
  {
    \int_gincr:N \g__pdf_backend_name_int
    \__kernel_backend_literal_page:e
      { /\exp_not:n{#1} ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC }
    % code to set the property ....
    \int_gincr:N\g__pdf_backend_resourceid_int
    \bool_if:NTF \l__pdf_backend_xform_bool
      {
        \pdfdict_gput:nee
          { g__pdf_Core/Xform/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_resourceid_int }
          { \__pdf_backend_object_last: }
      }
      {
        \__pdf_backend_record_abspage:e{l3pdf\int_use:N\g__pdf_backend_resourceid_int}
        \tl_set:Nx \l__pdf_tmpa_tl
          {
            \__pdf_backend_ref_abspage:e{l3pdf\int_use:N\g__pdf_backend_resourceid_int}
          }
        \pdfdict_if_exist:nF { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          {
            \pdfdict_new:n { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          }
        \pdfdict_gput:nee
          { g__pdf_Core/backend_Page\l__pdf_tmpa_tl/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_resourceid_int }
          { \__pdf_backend_object_last: }
        %\pdfdict_show:n { g_backend_Page\l__pdf_tmpa_tl/Resources/Properties }
      }
  }
\cs_set_protected:Npn \__pdf_backend_bmc:n #1
  {
    \__kernel_backend_literal_page:n { /#1~BMC }
  }
\cs_set_protected:Npn \__pdf_backend_bdc_contobj:nn #1 #2
   {
     \pdf_object_unnamed_write:nn { dict } { #2 }
     \__pdf_backend_bdcobject:n { #1 }
   }
\cs_set_protected:Npn \__pdf_backend_bdc_contstream:nn #1 #2
   {
     \__kernel_backend_literal_page:n { /#1~<<#2>>~BDC }
   }

\cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2
  {
    \bool_if:NTF  \g__pdfmanagement_active_bool
      {\cs_gset_eq:NN \__pdf_backend_bdc:nn \__pdf_backend_bdc_contobj:nn}
      {\cs_gset_eq:NN \__pdf_backend_bdc:nn \__pdf_backend_bdc_contstream:nn}
      \__pdf_backend_bdc:nn {#1}{#2}
  }
\bool_if:NT\l__pdfmanagement_delayed_shipout_bool
  {
    \cs_set_protected:Npn \__pdf_backend_bdc_shipout_contstream:ee #1 #2
       {
         \__kernel_backend_shipout_literal_page:e { /#1~<<#2>>~BDC }
       }
    \cs_set_eq:NN \__pdf_backend_bdc_shipout:ee \__pdf_backend_bdc_shipout_contstream:ee
  }

\cs_set_protected:Npn \__pdf_backend_emc:
  {
    \__kernel_backend_literal_page:n { EMC }
  }

\cs_new:Npn \__pdf_backend_PageResources_gpush_aux:n #1 %#1 ExtGState etc
  {
    \prop_if_empty:cF
      { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/#1} }
      {
        \pdfdict_item:ne { #1 }{ \pdf_object_ref:n {__pdf/Page/Resources/#1}}
      }
  }

\cs_new_protected:Npn \__pdf_backend_PageResources_gpush:n #1
  {
     \exp_args:NNe \tex_global:D \tex_pdfpageresources:D
       {
         \prop_if_exist:cT
           { \__kernel_pdfdict_name:n { g__pdf_Core/backend_Page#1/Resources/Properties } }
           {
             /Properties~
               <<
                 \prop_map_function:cN
                   { \__kernel_pdfdict_name:n { g__pdf_Core/backend_Page#1/Resources/Properties } }
                   \pdfdict_item:ne
               >>
           }
         %% add ExtGState etc
         \clist_map_function:NN
           \c__pdf_backend_PageResources_clist
           \__pdf_backend_PageResources_gpush_aux:n
       }
  }

\cs_new_protected:Npn \__pdf_backend_Names_gpush:nn #1 #2 %#1 name of name tree, #2 array content
  {
     \pdf_object_unnamed_write:nn {dict} {/Names [#2] }
     \tex_pdfnames:D {/#1~\pdf_object_ref_last:}
  }

\cs_new_protected:Npn  \__pdf_backend_NamesEmbeddedFiles_add:nn #1 #2 {}
\cs_new_protected:Npn \__pdf_backend_link_off:{}
\cs_new_protected:Npn \__pdf_backend_link_on: {}
\cs_if_exist:NT \pdfrunninglinkoff
 {
   \cs_set_protected:Npn \__pdf_backend_link_off:
    {
      \pdfrunninglinkoff
    }
   \cs_set_protected:Npn \__pdf_backend_link_on:
    {
      \pdfrunninglinkon
    }
 }
\cs_new_protected:Npn \__pdf_backend_xform_new:nnnn #1 #2 #3 #4
  {
    \hbox_set:Nn \l__pdf_backend_tmpa_box
      {
        \bool_set_true:N \l__pdf_backend_xform_bool
        \prop_gclear:c {\__kernel_pdfdict_name:n { g__pdf_Core/Xform/Resources/Properties }}
        #4
      }
    %store the dimensions
    \tl_const:cx
      { c__pdf_backend_xform_wd_ \tl_to_str:n {#1} _tl }
      { \tex_the:D \box_wd:N \l__pdf_backend_tmpa_box }
    \tl_const:cx
      { c__pdf_backend_xform_ht_ \tl_to_str:n {#1} _tl }
      { \tex_the:D \box_ht:N \l__pdf_backend_tmpa_box }
    \tl_const:cx
      { c__pdf_backend_xform_dp_ \tl_to_str:n {#1} _tl }
      { \tex_the:D \box_dp:N \l__pdf_backend_tmpa_box }
    %% do we need to test if #2 and #3 are empty??
    \tex_immediate:D \tex_pdfxform:D
      ~  attr      ~ { #2 }
    %% which other resources should be default? Is an argument actually needed?
      ~  resources ~
      {
        #3
        \int_compare:nNnT
          { \prop_count:c { \__kernel_pdfdict_name:n { g__pdf_Core/Xform/Resources/Properties } } }
          >
          { 0 }
          {
            /Properties~
              <<
                \pdfdict_use:n { g__pdf_Core/Xform/Resources/Properties }
              >>
          }

        \prop_if_empty:cF
          { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/ExtGState } }
          {
            /ExtGState~ \pdf_object_ref:n { __pdf/Page/Resources/ExtGState }
          }
        \prop_if_empty:cF
          { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/Pattern } }
          {
            /Pattern~ \pdf_object_ref:n { __pdf/Page/Resources/Pattern }
          }
        \prop_if_empty:cF
          { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/Shading } }
          {
            /Shading~ \pdf_object_ref:n { __pdf/Page/Resources/Shading }
          }
        \prop_if_empty:cF
          { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/ColorSpace } }
          {
            /ColorSpace~ \pdf_object_ref:n { __pdf/Page/Resources/ColorSpace }
          }
      }
      \l__pdf_backend_tmpa_box
   \int_const:cn
     { c__pdf_backend_xform_ \tl_to_str:n {#1} _int }
     { \tex_pdflastxform:D }
  }

\cs_new_protected:Npn \__pdf_backend_xform_use:n #1
  {
    \tex_pdfrefxform:D
      \int_use:c { c__pdf_backend_xform_ \tl_to_str:n {#1} _int }
      \scan_stop:
  }

\cs_new:Npn \__pdf_backend_xform_ref:n #1
  {
    \int_use:c { c__pdf_backend_xform_ \tl_to_str:n {#1} _int } ~ 0 ~ R
  }
%% all
\prg_new_conditional:Npnn \__pdf_backend_xform_if_exist:n #1 { p , T , F , TF }
  {
    \int_if_exist:cTF { c__pdf_backend_xform_ \tl_to_str:n {#1} _int }
     { \prg_return_true: }
     { \prg_return_false:}
  }
\prg_new_eq_conditional:NNn \pdfxform_if_exist:n\__pdf_backend_xform_if_exist:n
  { TF , T , F , p }
\tl_new:N   \l_pdf_current_structure_destination_tl
\cs_new_protected:Npn \pdf_activate_structure_destination:
 {
   \cs_gset_eq:NN \__pdf_backend_destination:nn \__pdf_backend_structure_destination:nn
   \cs_gset_eq:NN \__pdf_backend_destination:nnnn \__pdf_backend_structure_destination:nnnn
   \cs_gset_eq:NN \__pdf_backend_link_begin_goto:nnw  \__pdf_backend_link_begin_structure_goto:nnw
 }
\cs_set_eq:NN \__pdf_backend_structure_destination:nn       \__pdf_backend_destination:nn
\cs_set_eq:NN \__pdf_backend_structure_destination:nnnn \__pdf_backend_destination:nnnn
\cs_set_eq:NN \__pdf_backend_link_begin_structure_goto:nnw  \__pdf_backend_link_begin_goto:nnw
\bool_lazy_and:nnT
  { \int_compare_p:nNn {\tex_pdftexversion:D } > {139} }
  { \int_compare_p:nNn {\tex_pdftexrevision:D } > {23} }
  {
    \cs_set_protected:Npn \__pdf_backend_structure_destination:nn #1#2
      {
        \tex_pdfdest:D
           name {#1}
           \str_case:nnF {#2}
             {
               { xyz }   { xyz }
               { fit }   { fit }
               { fitb }  { fitb }
               { fitbh } { fitbh }
               { fitbv } { fitbv }
               { fith }  { fith }
               { fitv }  { fitv }
               { fitr }  { fitr }
             }
             { xyz ~ zoom \fp_eval:n { #2 * 10 } }
           \scan_stop:
        \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
          {
            \tex_pdfdest:D
               struct~
               \int_use:c
                 { c__pdf_backend_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
               name {#1}
               \str_case:nnF {#2}
                 {
                   { xyz }   { xyz }
                   { fit }   { fit }
                   { fitb }  { fitb }
                   { fitbh } { fitbh }
                   { fitbv } { fitbv }
                   { fith }  { fith }
                   { fitv }  { fitv }
                   { fitr }  { fitr }
                 }
                 { xyz ~ zoom \fp_eval:n { #2 * 10 } }
               \scan_stop:
          }
      }
    \cs_set_protected:Npn \__pdf_backend_destination:nnnn #1#2#3#4
      {
       \tex_pdfdest:D
        name {#1}
        fitr ~
        width  \dim_eval:n {#2} ~
        height \dim_eval:n {#3} ~
        depth  \dim_eval:n {#4} \scan_stop:
       \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
         {
           \tex_pdfdest:D
             struct~
             \int_use:c
               { c__pdf_backend_object_ \exp_args:Ne \tl_to_str:n {\l_pdf_current_structure_destination_tl} _int }~
             name {#1}
             fitr ~
             width  \dim_eval:n {#2} ~
             height \dim_eval:n {#3} ~
             depth  \dim_eval:n {#4} \scan_stop:
         }
     }
    \cs_set_protected:Npn \__pdf_backend_link_begin_structure_goto:nnw #1#2
      {
        \__pdf_backend_link_begin:nnnw {#1} { goto~struct~name~{#2}~name } {#2}
      }
  }
\cs_new_protected:Npn \__pdf_backend_set_regression_data:
  {
    \sys_gset_rand_seed:n{1000}
    \pdfmanagement_add:nnn{Info}{Creator}{(TeX)}
   \pdfmanagement_add:nnn{Info}{Producer}{(pdfTeX)}
   \tex_pdfsuppressptexinfo:D 7 \scan_stop:
   \pdftrailerid{2350CAD05F8A7AF0AA4058486855344F}
    \str_if_exist:NF\c_sys_timestamp_str
      {
       \pdfmanagement_add:nnn{Info}{CreationDate}{(D:20010101205959-00'00')}
       \pdfmanagement_add:nnn{Info}{ModDate}{(D:20010101205959-00'00')}
       \AddToDocumentProperties[document]{creationdate}{D:20010101205959-00'00'}
       \AddToDocumentProperties[document]{moddate}{D:20010101205959-00'00'}
       \AddToDocumentProperties[hyperref]{pdfmetadate}{D:20010101205959-00'00'}
       \AddToDocumentProperties[hyperref]{pdfdate}{D:20010101205959-00'00'}
      }
    \AddToDocumentProperties[hyperref]{pdfinstanceid}{uuid:0a57c455-157a-4141-8c19-6237d832fc80}
    \AddToDocumentProperties[hyperref]{pdfproducer}{\c_sys_engine_exec_str-NN.NN.NN}
   }
\cs_new_protected:Npn \__pdf_backend_metadata_stream:n #1
  {
    \group_begin:
     \tex_pdfcompresslevel:D  0 \scan_stop:
     \tex_immediate:D \tex_pdfobj:D
     \__pdf_backend_object_write:nn {stream} {{/Type~/Metadata~/Subtype~/XML}{#1}}
    \group_end:
  }
\cs_new_protected:Npn \__pdf_backend_omit_charset:n #1 %#1 number
  {
    \tex_pdfomitcharset:D = #1 \scan_stop:
  }
\bool_lazy_and:nnTF
  { \int_compare_p:nNn {\tex_pdftexversion:D } > {139} }
  { \int_compare_p:nNn {\tex_pdftexrevision:D } > {24} }
  {
    \cs_new_protected:Npn \__pdf_backend_omit_info:n #1 %#1 number
     {
       \pdfomitinfodict = #1 \scan_stop:
     }
  }
  {
    \cs_new_protected:Npn \__pdf_backend_omit_info:n #1 {}%#1 number

  }

%% 
%%
%% End of file `l3backend-testphase-pdftex.def'.
