summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pdfmanagement-testphase/l3backend-testphase-luatex.def
blob: 1d1cfd154c3cae101c2e25f1994419441da449aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
%%
%% This is file `l3backend-testphase-luatex.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3backend-testphase.dtx  (with options: `drivers,luatex')
%% 
%% 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-luatex.def}{2022-02-16}{}
  {LaTeX~PDF~management~testphase~bundle~backend~support: PDF output (LuaTeX)}
\RequirePackage{l3ref-tmp}
\cs_generate_variant:Nn \ref_label:nn {en}
\cs_generate_variant:Nn \ref_value:nn {en}
\cs_new_protected:Npn \__pdf_backend_ref_label:nn #1 #2
  {
     \@bsphack
     \ref_label:nn{#1}{abspage}
     \@esphack
  }
\cs_new:Npn \__pdf_backend_ref_value:nn #1 #2
  {
     \ref_value:nn{#1}{#2}
  }
\cs_generate_variant:Nn \__pdf_backend_ref_label:nn {en}
\cs_generate_variant:Nn \__pdf_backend_ref_value:nn {en}
\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
    \directlua { require("l3backend-testphase.lua") }
\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
      }
  }

\sys_if_engine_luatex:T
  {
    \cs_new_protected:Npn \__pdf_backend_Pages_primitive:n #1
      {
        \tex_directlua:D
          {
            pdf.setpagesattributes( \__pdf_backend_luastring:n { #1 } )
          }
      }
  }
\cs_new:Npn \__pdf_backend_luastring:n #1
  {
    "\tex_luaescapestring:D { \tex_unexpanded:D { #1 } }"
  }
 %not used, only there for consistency
\cs_new_protected:Npn \__pdf_backend_Page_primitive:n #1
  {
    \tex_latelua:D
      {
        pdf.setpageattributes(\__pdf_backend_luastring:n { #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
  {
    \tex_directlua:D
      {
        ltx.__pdf.backend_Page_gput
          (
            \__pdf_backend_luastring:n { #1 },
            \__pdf_backend_luastring:n { #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
  {
    \tex_directlua:D
      {
        ltx.__pdf.backend_Page_gremove (\__pdf_backend_luastring:n { #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
  {
    \tex_latelua:D
      {
        ltx.__pdf.backend_ThisPage_gput
          (
            tex.count["g_shipout_readonly_int"],
            \__pdf_backend_luastring:n { #1 },
            \__pdf_backend_luastring:n { #2 }
          )
        ltx.__pdf.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
      }
  }
  %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
  {
    \tex_latelua:D
      {
        ltx.__pdf.backend_ThisPage_gpush (tex.count["g_shipout_readonly_int"])
      }
  }

\clist_const:Nn \c__pdf_backend_PageResources_clist
  {
    ExtGState,
    ColorSpace,
    Pattern,
    Shading,
  }
\clist_map_inline:Nn \c__pdf_backend_PageResources_clist
  {
    \__pdf_backend_object_new:nn {__pdf/Page/Resources/#1} {dict}
    \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 }
    \tex_latelua:D{ltx.__pdf.Page.Resources.#1=true}
    \tex_latelua:D
      {
        ltx.pdf.Page_Resources_gpush(tex.count["g_shipout_readonly_int"])
      }
  }
\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_backend_object_write:nx
              { __pdf/Page/Resources/##1 }
              { \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
    \exp_args:Nx\__kernel_backend_literal_page:n
      { /#1 ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC }
    \bool_if:NTF \l__pdf_backend_xform_bool
      {
        \exp_args:Nnx\pdfdict_gput:nnn
          { g__pdf_Core/Xform/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_name_int }
          { \__pdf_backend_object_ref:n { #2 } }
      }
      {
        \exp_args:Nx \tex_latelua:D
          {
            ltx.pdf.Page_Resources_Properties_gput
              (
                tex.count["g_shipout_readonly_int"],
                "l3pdf\int_use:N\g__pdf_backend_name_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
    \exp_args:Nx\__kernel_backend_literal_page:n
      { /#1 ~ /l3pdf\int_use:N\g__pdf_backend_name_int\c_space_tl BDC }
    \bool_if:NTF \l__pdf_backend_xform_bool
      {
        \exp_args:Nnx\pdfdict_gput:nnn %no handler needed
          { g__pdf_Core/Xform/Resources/Properties }
          { l3pdf\int_use:N\g__pdf_backend_name_int }
          { \__pdf_backend_object_last: }
      }
      {
        \exp_args:Nx \tex_latelua:D
          {
            ltx.pdf.Page_Resources_Properties_gput
              (
                tex.count["g_shipout_readonly_int"],
                "l3pdf\int_use:N\g__pdf_backend_name_int",
                "\__pdf_backend_object_last:"
              )
          }
      }
  }
\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}
  }
\cs_set_protected:Npn \__pdf_backend_emc:
  {
    \__kernel_backend_literal_page:n { EMC }
  }

\cs_new_protected:Npn \__pdf_backend_PageResources_gpush:n #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] }
     \tex_pdfextension:D~names~ {/#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: {}
\int_compare:nNnT {\tex_luatexversion:D } > {112}
 {
   \cs_set_protected:Npn \__pdf_backend_link_off:
    {
      \pdfextension linkstate 1
    }
   \cs_set_protected:Npn \__pdf_backend_link_on:
    {
      \pdfextension linkstate 0
    }
 }
\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
      }
    \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 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 %protected as with xelatex
  {
    \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
 \int_compare:nNnT {\directlua{tex.print(status.list()["development_id"])} } > {7468}
  {
    \cs_set_protected:Npn \__pdf_backend_structure_destination:nn #1#2
      {
        \tex_pdfextension:D dest
           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_pdfextension:D dest
               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_pdfextension:D dest
        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_pdfextension:D dest
             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}
      }
  }
%% 
%%
%% End of file `l3backend-testphase-luatex.def'.