%%
%% This is file `l3backend-testphase-xetex.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3backend-testphase.dtx  (with options: `drivers,xdvipdfmx')
%% 
%% Copyright (C) 2019-2025 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 bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: l3backend-testphase.dtx
\ProvidesExplFile
  {l3backend-testphase-xetex.def}{2026-01-23}{0.96y}
  {LaTeX~PDF~management~bundle~backend~support: XeTeX}
\cs_generate_variant:Nn \__kernel_backend_literal:n { e }
\cs_generate_variant:Nn \__pdf_backend:n { e }
\cs_new_protected:Npn \__kernel_backend_shipout_literal:e #1
  { \tex_special:D~shipout { #1} }

\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_generate_variant:Nn \__pdf_backend_record_abspage:n {e}
\cs_generate_variant:Nn \__pdf_backend_ref_abspage:n {e}
    \__kernel_backend_literal:n { dvipdfmx:config~C~ 0x0010 }
\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@shipout@lastpage
  {
    \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
  {
    \__pdf_backend:n{put~@pages~<<#1>>}
  }
  %the primitive
\cs_new_protected:Npn \__pdf_backend_Page_primitive:n #1
  {
    \tex_special:D{pdf:~put~@thispage~<<#1>>}
  }
  % the command to store default values.
  % Uses a prop with pdflatex + dvi,
  % sets a lua table with lualatex
\cs_new_protected:Npn \__pdf_backend_Page_gput:nn #1 #2
  {
    \pdfdict_gput:nnn {g__pdf_Core/Page}{ #1 }{ #2 }
  }
  % the command to remove a default value.
  % Uses a prop with pdflatex + dvi,
  % changes a lua table with lualatex
\cs_new_protected:Npn \__pdf_backend_Page_gremove:n #1
   {
     \pdfdict_gremove:nn  {g__pdf_Core/Page}{ #1 }
   }
  % the command used in the document.
  % direct call of the primitive special with dvips/dvipdfmx
  % \latelua: fill a page related table with lualatex, merge it with the page
  % table and push it directly
  % write to aux and store in prop with pdflatex
\cs_new_protected:Npn \__pdf_backend_ThisPage_gput:nn #1 #2
  {
    \__pdf_backend_Page_primitive:n { /#1~#2 }
  }
  %the code to push the values, used in shipout
  %merges the two props and then fills the register in pdflatex
  %merges the two tables (the one is probably still empty)
  % and then fills (in lua) in luatex
  %issues the values stored in the global prop with dvi
\cs_new_protected:Npn \__pdf_backend_ThisPage_gpush:n #1
  {
    \__pdf_backend_Page_primitive:e
      { \pdfdict_use:n { g__pdf_Core/Page} }
  }
\cs_generate_variant:Nn \__pdf_backend_Page_primitive:n { e }
\clist_const:Nn \c__pdf_backend_PageResources_clist
  {
    ExtGState,
    ColorSpace,
    Pattern,
    Shading,
  }
\hook_gset_rule:nnnn{shipout/firstpage}{l3backend-xetex}{after}{pdf}
\clist_map_inline:Nn \c__pdf_backend_PageResources_clist
  {
    \pdf_object_new:n   { __pdf/Page/Resources/#1 }
    \hook_gput_code:nnn
      {shipout/firstpage}
      {pdf}
      {\pdf_object_write:nnn { __pdf/Page/Resources/#1 } { dict } {}}
  }
\cs_new_protected:Npn \__pdf_backend_PageResources:n #1
  {
    \__pdf_backend:n {put~@resources~<<#1>>}
  }
\cs_new_protected:Npn \__pdf_backend_PageResources_gput:nnn #1 #2 #3
  {
   % this is not used for output, but there is a test if the resource is empty
   \prop_gput:cne { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/#1} }
     { \str_convert_pdfname:n {#2} }{ #3 }
   %objects are not filled with \pdf_object_write as this is not additive!
    \__pdf_backend:e
      {
        put~\pdf_object_ref:n {__pdf/Page/Resources/#1}<</#2~#3>>
      }
  }

\cs_new_protected:Npn \__pdf_backend_PageResources_obj_gpush: {}
\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:e
       {
         pdf:code~/#1/l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC
       }
     \__kernel_backend_literal:e
       {
         pdf:put~@resources~
           <<
             /Properties~
               <<
                 /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl
                 \pdf_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:e
       {
         pdf:code~/\exp_not:n{#1}/l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC
       }
     \__kernel_backend_literal:e
       {
         pdf:put~@resources~
           <<
             /Properties~
               <<
                 /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl
                 \__pdf_backend_object_last:
               >>
           >>
       }
   }
\cs_set_protected:Npn \__pdf_backend_bmc:n #1
   {
     \__kernel_backend_literal:n {pdf:code~/#1~BMC}  %pdfbase
   }

\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:n {pdf:code~ /#1~<<#2>>~BDC }
  }

\cs_set_protected:Npn \__pdf_backend_bdc:nn #1 #2
  {
    \cs_gset_eq:NN \__pdf_backend_bdc:nn \__pdf_backend_bdc_contobj:nn
    \__pdf_backend_bdc:nn {#1}{#2}
  }

\cs_set_protected:Npn \__pdf_backend_bdc_shipout_contstream:ee #1 #2
  {
    \__kernel_backend_shipout_literal:e {pdf:code~ /#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:n {pdf:code~EMC}  %pdfbase
  }
  % properties are handled automatically, but the other resources should be added
  % at shipout
\cs_new_protected:Npn \__pdf_backend_PageResources_gpush:n #1
  {
    \clist_map_inline:Nn \c__pdf_backend_PageResources_clist
      {
        \prop_if_empty:cF { \__kernel_pdfdict_name:n { g__pdf_Core/Page/Resources/##1} }
          {
            \__kernel_backend_literal:e
              {
                pdf:put~@resources~
                  <</##1~\pdf_object_ref:n {__pdf/Page/Resources/##1}>>
              }
          }
      }
  }
\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] }
     \__pdf_backend:e {put~@names~<</#1~\pdf_object_ref_last: >>}
  }

\cs_new_protected:Npn  \__pdf_backend_NamesEmbeddedFiles_add:nn #1 #2 {}
   % it needs a bit testing if it really works to set the box to 0 before the special ...
   % does it disturb viewing the xobject?
   % what happens with the resources (bdc)? (should work as they are specials too)
   % xetex requires that the special is in horizontal mode. This means it affects
   % typesetting. But we can no delay the whole form code to shipout
   % as the object reference and the size is often wanted on the current page.
   % so we need to allocate a box - but probably they won't be thousands xform
   % in a document so it shouldn't matter.
    \cs_new_protected:Npn \__pdf_backend_xform_new:nnnn #1 #2 #3 #4
    % #1 name
    % #2 attributes
    % #3 resources
    % #4 content, not necessarily a box!
      {
         \int_gincr:N \g__pdf_backend_object_int
         \int_const:cn
           { c__pdf_backend_xform_ \tl_to_str:n {#1} _int }
           { \g__pdf_backend_object_int }
         \box_new:c { g__pdf_backend_xform_#1_box }
         \hbox_gset:cn { g__pdf_backend_xform_#1_box }
           {
             \bool_set_true:N \l__pdf_backend_xform_bool
             #4
           }
         \tl_const:ce
           { c__pdf_backend_xform_wd_ \tl_to_str:n {#1} _tl }
           { \tex_the:D \box_wd:c { g__pdf_backend_xform_#1_box } }
         \tl_const:ce
           { c__pdf_backend_xform_ht_ \tl_to_str:n {#1} _tl }
           { \tex_the:D \box_ht:c { g__pdf_backend_xform_#1_box } }
         \tl_const:ce
           { c__pdf_backend_xform_dp_ \tl_to_str:n {#1} _tl }
           { \tex_the:D \box_dp:c { g__pdf_backend_xform_#1_box } }
         \box_set_dp:cn  { g__pdf_backend_xform_#1_box } { \c_zero_dim }
         \box_set_ht:cn  { g__pdf_backend_xform_#1_box } { \c_zero_dim }
         \box_set_wd:cn  { g__pdf_backend_xform_#1_box } { \c_zero_dim }
         \hook_gput_next_code:nn {shipout/background}
           {
             \mode_leave_vertical: %needed, the xform disappears without it.
             \__pdf_backend:e
               {
                 bxobj  ~ \__pdf_backend_xform_ref:n  { #1 }
                 \c_space_tl width  ~ \pdfxform_wd:n { #1 }
                 \c_space_tl height ~ \pdfxform_ht:n { #1 }
                 \c_space_tl depth  ~ \pdfxform_dp:n { #1 }
               }
             \box_use_drop:c { g__pdf_backend_xform_#1_box }
             \__pdf_backend:e {put ~ @resources ~<<#3>> }
             \__pdf_backend:e
               {
                 put~ @resources ~
                   <<
                     /ExtGState~ \pdf_object_ref:n { __pdf/Page/Resources/ExtGState }
                   >>
               }
             \__pdf_backend:e
               {
                 put~ @resources ~
                 <<
                   /Pattern~ \pdf_object_ref:n { __pdf/Page/Resources/Pattern }
                 >>
               }
             \__pdf_backend:e
               {
                 put~ @resources ~
                 <<
                   /Shading~ \pdf_object_ref:n { __pdf/Page/Resources/Shading }
                 >>
               }
             \__pdf_backend:e
               {
                 put~ @resources ~
                 <<
                   /ColorSpace~
                   \pdf_object_ref:n { __pdf/Page/Resources/ColorSpace }
                 >>
               }
             \__pdf_backend:e {exobj ~<<#2>>}
           }
      }

    \cs_new:Npn \__pdf_backend_xform_ref:n #1
      {
        @pdf.xform \int_use:c { c__pdf_backend_xform_ \tl_to_str:n {#1} _int }
      }

    \cs_new_protected:Npn \__pdf_backend_xform_use:n #1
     {
       \hbox_set:Nn \l__pdf_backend_tmpa_box
         {
           \__pdf_backend:e
             {
               uxobj~ \__pdf_backend_xform_ref:n { #1 }
             }
         }
       \box_set_wd:Nn  \l__pdf_backend_tmpa_box { \pdfxform_wd:n { #1 } }
       \box_set_ht:Nn  \l__pdf_backend_tmpa_box { \pdfxform_ht:n { #1 } }
       \box_set_dp:Nn  \l__pdf_backend_tmpa_box { \pdfxform_dp:n { #1 } }
       \box_use_drop:N \l__pdf_backend_tmpa_box
     }
%% 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 \__pdfannot_backend_link_begin_goto:nnw  \__pdfannot_backend_link_begin_structure_goto:nnw
 }
\cs_new_protected:Npn \pdf_activate_indexed_structure_destination:
 {
   \cs_gset_eq:NN \__pdf_backend_destination:nn       \__pdf_backend_indexed_structure_destination:nn
   \cs_gset_eq:NN \__pdf_backend_destination:nnnn     \__pdf_backend_indexed_structure_destination:nnnn
   \cs_gset_eq:NN \__pdfannot_backend_link_begin_goto:nnw  \__pdfannot_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 \__pdfannot_backend_link_begin_structure_goto:nnw  \__pdfannot_backend_link_begin_goto:nnw
\cs_set_eq:NN \__pdf_backend_indexed_structure_destination:nn       \__pdf_backend_destination:nn
\cs_set_eq:NN \__pdf_backend_indexed_structure_destination:nnnn     \__pdf_backend_destination:nnnn
\cs_set_protected:Npn \__pdf_backend_structure_destination:nn #1#2
  {
    \__pdf_backend:e
      {
        dest ~ ( \exp_not:n {#1} )
        [
          @thispage
          \str_case:nnF {#2}
            {
              { xyz }   { /XYZ ~ @xpos ~ @ypos ~ null }
              { fit }   { /Fit }
              { fitb }  { /FitB }
              { fitbh } { /FitBH }
              { fitbv } { /FitBV ~ @xpos }
              { fith }  { /FitH ~ @ypos }
              { fitv }  { /FitV ~ @xpos }
              { fitr }  { /Fit }
            }
            { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
        ]
      }
    \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
      {
        \__pdf_backend:e
         {
          obj ~ @pdf.SDest.\exp_not:n{#1}
          [
            \exp_args:Ne \pdf_object_ref:n { \l_pdf_current_structure_destination_tl }
            \str_case:nnF {#2}
              {
                { xyz }   { /XYZ ~ @xpos ~ @ypos ~ null }
                { fit }   { /Fit }
                { fitb }  { /FitB }
                { fitbh } { /FitBH }
                { fitbv } { /FitBV ~ @xpos }
                { fith }  { /FitH ~ @ypos }
                { fitv }  { /FitV ~ @xpos }
                { fitr }  { /Fit }
              }
              { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
          ]
        }
      }
  }
\cs_new_protected:Npn \__pdf_backend_structure_destination_aux:nnnn #1#2#3#4
  {
    \vbox_to_zero:n
      {
        \__kernel_kern:n {#4}
        \hbox:n
          {
            \__pdf_backend:n { obj ~ @pdf_ #2 _llx ~ @xpos }
            \__pdf_backend:n { obj ~ @pdf_ #2 _lly ~ @ypos }
          }
        \tex_vss:D
      }
    \__kernel_kern:n {#1}
    \vbox_to_zero:n
      {
        \__kernel_kern:n { -#3 }
        \hbox:n
          {
            \__pdf_backend:n
              {
                dest ~ (#2)
                [
                  @thispage
                  /FitR ~
                    @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
                    @xpos ~ @ypos
                ]
              }
            \exp_args:Ne \pdf_object_if_exist:nT { \l_pdf_current_structure_destination_tl }
              {
                \__pdf_backend:e
                  {
                    obj ~ @pdf.SDest.\exp_not:n{#2}
                    [
                      \exp_args:Ne \pdf_object_ref:n { \l_pdf_current_structure_destination_tl }
                      /FitR ~
                        @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
                        @xpos ~ @ypos
                    ]
                  }
              }
          }
        \tex_vss:D
      }
    \__kernel_kern:n { -#1 }
  }
\cs_set_protected:Npn \__pdf_backend_structure_destination:nnnn #1#2#3#4
  {
    \exp_args:Ne \__pdf_backend_structure_destination_aux:nnnn
      { \dim_eval:n {#2} } {#1} {#3} {#4}
  }
\cs_set_protected:Npn \__pdfannot_backend_link_begin_structure_goto:nnw #1#2
  {
    \__pdfannot_backend_link_begin:n { #1 /Subtype /Link /A << /S /GoTo /D ( #2 ) /SD~@pdf.SDest.#2  >> }
  }
\cs_set_protected:Npn \__pdf_backend_indexed_structure_destination:nn #1#2
  {
    \__pdf_backend:e
      {
        dest ~ ( \exp_not:n {#1} )
        [
          @thispage
          \str_case:nnF {#2}
            {
              { xyz }   { /XYZ ~ @xpos ~ @ypos ~ null }
              { fit }   { /Fit }
              { fitb }  { /FitB }
              { fitbh } { /FitBH }
              { fitbv } { /FitBV ~ @xpos }
              { fith }  { /FitH ~ @ypos }
              { fitv }  { /FitV ~ @xpos }
              { fitr }  { /Fit }
            }
            { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
        ]
      }
        \__pdf_backend:e
         {
          obj ~ @pdf.SDest.\exp_not:n{#1}
          [
            \exp_after:wN \pdf_object_ref_indexed:nn  \l_pdf_current_structure_destination_tl
            \str_case:nnF {#2}
              {
                { xyz }   { /XYZ ~ @xpos ~ @ypos ~ null }
                { fit }   { /Fit }
                { fitb }  { /FitB }
                { fitbh } { /FitBH }
                { fitbv } { /FitBV ~ @xpos }
                { fith }  { /FitH ~ @ypos }
                { fitv }  { /FitV ~ @xpos }
                { fitr }  { /Fit }
              }
              { /XYZ ~ @xpos ~ @ypos ~ \fp_eval:n { (#2) / 100 } }
          ]
        }
  }
\cs_new_protected:Npn \__pdf_backend_indexed_structure_destination_aux:nnnn #1#2#3#4
  {
    \vbox_to_zero:n
      {
        \__kernel_kern:n {#4}
        \hbox:n
          {
            \__pdf_backend:n { obj ~ @pdf_ #2 _llx ~ @xpos }
            \__pdf_backend:n { obj ~ @pdf_ #2 _lly ~ @ypos }
          }
        \tex_vss:D
      }
    \__kernel_kern:n {#1}
    \vbox_to_zero:n
      {
        \__kernel_kern:n { -#3 }
        \hbox:n
          {
            \__pdf_backend:n
              {
                dest ~ (#2)
                [
                  @thispage
                  /FitR ~
                    @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
                    @xpos ~ @ypos
                ]
              }
             \__pdf_backend:e
               {
                 obj ~ @pdf.SDest.\exp_not:n{#2}
                 [
                   \exp_after:wN \pdf_object_ref_indexed:nn  \l_pdf_current_structure_destination_tl
                   /FitR ~
                     @pdf_ #2 _llx ~ @pdf_ #2 _lly ~
                     @xpos ~ @ypos
                 ]
               }
          }
        \tex_vss:D
      }
    \__kernel_kern:n { -#1 }
  }
\cs_set_protected:Npn \__pdf_backend_indexed_structure_destination:nnnn #1#2#3#4
  {
    \exp_args:Ne \__pdf_backend_indexed_structure_destination_aux:nnnn
      { \dim_eval:n {#2} } {#1} {#3} {#4}
  }
\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}{(xetex)}
    \__kernel_backend_literal:e
      {pdf:trailerid [~
      <00112233445566778899aabbccddeeff>~
      <00112233445566778899aabbccddeeff>~
          ]}
    \pdfdict_put:nne  {l_pdffile/Params} {ModDate}{(\c_sys_timestamp_str)}
    \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
  {
    \pdf_object_write:nnn{__pdfmeta/xmp} {stream}{{/Type~/Metadata~/Subtype~/XML}{#1}}
  }
\cs_new_protected:Npn \__pdf_backend_omit_charset:n #1 {} %#1 number
\cs_new_protected:Npn \__pdf_backend_omit_info:n #1 {} %#1 number
\cs_new_protected:Npn \__pdf_backend_omit_cidset:n #1 {} %#1 number

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