-
Notifications
You must be signed in to change notification settings - Fork 5
/
pdfresources.dtx
2239 lines (2122 loc) · 73.5 KB
/
pdfresources.dtx
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
%% File: pdfresources.dtx
%
% Copyright (C) 2019 The LaTeX3 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 "pdfresources bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/latex3/latex3
%
% for those people who are interested.
%
%<*driver>
\documentclass{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \begin{macrocode}
%<@@=pdf>
%<*package>
\RequirePackage{xparse,l3pdf}
%\RequirePackage{tmpl3shipout}
\RequirePackage{atbegshi,zref-lastpage}
\ProvidesExplPackage {pdfresources} {2019-07-01} {0.2}
{experimental pdf-resource management}
\DeclareOption { debug }
{
%\msg_redirect_module:nnn { pdf } { warning }{ error }
\msg_redirect_module:nnn { pdf } { none } { warning }
}
\bool_new:N\g_@@_patches_bool
\DeclareOption { patches }{\bool_gset_true:N\g_@@_patches_bool}
\ProcessOptions\relax
%</package>
% \end{macrocode}
%
% \title{\pkg{pdfresources}}
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released 2019-03-04}
%
% \maketitle
% \section{Existing resource usage}
%
% \subsection{\pkg{hyperref}}
%
% \subsection{\pkg{pgf}}
%
% In \pkg{pgf}, resource management is set up in the file |pgfutil-common.tex|.
% This then provides three functions for adding to the resources, all of which
% are objects:
% \begin{itemize}
% \item \cs{pgfutil@addpdfresource@extgs}: Extended graphics state
% \item \cs{pgfutil@addpdfresource@colorspaces}: Color spaces
% \item \cs{pgfutil@addpdfresource@patterns}: Patterns
% \end{itemize}
%
% These resource dictionaries are used by adding entries in a cumulative sense;
% the macro layer deals with ensuring that each entry is only given once. Note
% that the objects themselves must be given only once for each page.
%
% To support these functions, there are a series of set-up macros which install
% these resources. That has to take place for every page: the exact route
% therefore depends on the driver.
%
% \subsection{\pkg{media9}}
% \section{Preparation/helper Code}
%^^A still needed:
%^^A \pdf@strcmp??
%^^A \pdf@escapestring?? \pdfescapestring
% \begin{macrocode}
%<*package>
\prop_new:N\l_@@_tmpa_prop
\tl_new:N\l_@@_tmpa_tl
% helper command to output a key + value of a prop as needed in a dict.
% I don't check if #1 or #2 is empty, imho this should be done only in the pdf layer
% at the input?
\cs_new:Npn \@@_dict_item:nn #1 #2 {/#1~#2~}
%</package>
% \end{macrocode}
% \subsection{some zref code, needs to be replaced later}
% \begin{macrocode}
%<*package>
\int_new:N \g_@@_abspage_int
\int_new:N \g_@@_backend_resourceid_int
\int_new:N \g_@@_backend_name_int
\zref@newlist {l3pdf}
\zref@newprop* {pdf@abspage} [0] {\int_use:N\g_@@_abspage_int}
\zref@addprop {l3pdf} {pdf@abspage}
%</package>
% \end{macrocode}
% \subsection{luacode}
% \begin{macrocode}
%<*package>
\sys_if_engine_luatex:T
{
\directlua{require("pdfresources.lua")}
}
%</package>
% \end{macrocode}
% \subsection{end of run}
% \begin{NOTE}{UF}
% the \enquote{end-of-run} command is temporary until shipout/atendshipout code
% is ready. dvips implementation missing. Currently a noop.
% \end{NOTE}
% \begin{macrocode}
%<*package>
%
% \AtEndDocument{\clearpage #1} ? (not dvi)
% \AtEndDvi{#1} ?
\cs_new_protected:Npn \@@_backend_end_run:n #1 {} %check ...
%</package>
% \end{macrocode}
% \subsection{Shipoutcode}
% For now -- until a expl3/kernel interface exists -- code is added with atbegshi:
% \begin{macrocode}
%<*package>
\AtBeginShipout
{
\AtBeginShipoutAddToBox
{
\@@_shipout_code:
}
}
\cs_new_protected:Npn \@@_shipout_code:
{
\int_gincr:N \g_@@_abspage_int
\@@_everypage_shipout_code:V \g_@@_abspage_int
\int_compare:nNnT { \g_@@_abspage_int }={\zref@extractdefault{LastPage}{abspage}{0}}
{
\@@_lastpage_shipout_code:
}
}
\cs_new_protected:Npn \@@_everypage_shipout_code:n #1
{
\@@_backend_PageN_gpush:n { #1 }
\@@_backend_PageN_Resources_gpush:n { #1 }
}
\cs_generate_variant:Nn \@@_everypage_shipout_code:n {V}
\cs_new_protected:Npn \@@_lastpage_shipout_code:
{
\@@_Pages_gpush:
\@@_Info_gpush:
}
%</package>
% \end{macrocode}
%
% \subsection{Tree / path-Code}
% This is a bit experimental. Many code parts are quite similar: props are
% filled and output. So we define some generic commands
% based on pathes. The main question will be if one can encode the different
% inner structures (array/dict) and the cases where users shouldn't fill a value
% but it should be done by subtrees ...
% \begin{verbatim}
% /Pages %w, \pagesattr
% /PageN %w, N=1,..n or empty (=all pages) \pageattr
% /PageN/Resources %nw? \pageresources
% /PageN/Resources/ExtGState
% /PageN/Resources/ColorSpace
% /PageN/Resources/Pattern
% /PageN/Resources/Shading
% /PageN/Resources/Properties
% /Info %w, \pdfinfo
% /Catalog/OCProperties
% /Catalog/OutputIntents
% \end{verbatim}
% \begin{macrocode}
%<*package>
\cs_new:Npn \@@_tree_prop_name:n #1 % path name without /
{
g_@@_/#1_prop
}
\cs_new_protected:Npn \@@_tree_new:n #1
{
\prop_if_exist:cF { \@@_tree_prop_name:n {#1} }
{
\prop_new:c { \@@_tree_prop_name:n {#1} }
}
}
\cs_new_protected:Npn \@@_tree_gput:nnn #1 #2 #3 %#1 path, #2 name, #3 value
{ %test if tree path is allowed here?
\tl_if_empty:nTF { #3 }
{
\msg_none:nnn { pdf }{ empty-value }{ /#1/#2 }
}
{
\prop_gput:cnn { \@@_tree_prop_name:n {#1} }{ #2 } { #3 }
}
}
\cs_new_protected:Npn \@@_tree_get:nnnN #1 #2 #3
{
\prop_get:cnN { \@@_tree_prop_name:n {#1} } { #2} #3
}
\cs_new_protected:Npn \@@_tree_gremove:nn #1 #2
{
\prop_gremove:cn { \@@_tree_prop_name:n {#1} } { #2 }
}
\cs_new:Npn \@@_tree_map_dict_item:n #1
{
\prop_map_function:cN { \@@_tree_prop_name:n {#1}} \@@_dict_item:nn
}
\cs_new_protected:Npn \@@_tree_merge:nnN #1 #2 #3 % merges: first #1 then optionally #2 into prop #3
{
\prop_set_eq:Nc #3 { \@@_tree_prop_name:n { #1 } }
\prop_if_exist:cT { \@@_tree_prop_name:n { #2 } }
{
\prop_map_inline:cn { \@@_tree_prop_name:n { #2 } }
{
\prop_put:Nnn #3 { ##1 }{ ##2 }
}
}
}
%</package>
% \end{macrocode}
% \section{Resources management}
% \subsection{pdfpagesattr}
% \subsubsection{pdfpagesattr/backend}
% \begin{NOTE}{UF}
% path: Pages
% pdfpagesattr is a single token register which is used at the end of the compilation.
% dvips syntax: \verb+\special{ps: [/ABC /CDE /EFG /FGH /Rotate 90 /PAGES pdfmark}+
% dvipdfmx syntax: \verb+\special{pdf:put @pages <</ABC /WEZ /EFG /XYZ /Rotate 0>>}+
% both remove duplicate entries automatically, so there is no need to be careful.
% \end{NOTE}
% \begin{macrocode}
%<*package>
%pdftex
\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p:}
{
\cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
{
\tex_global:D \tex_pdfpagesattr:D {#1}
}
}
%luatex
\sys_if_engine_luatex:T
{
\cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
{
\tex_directlua:D {pdf.setpagesattributes(\@@_backend_luastring:n {#1})}
}
}
%dvips
\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
{
\cs_new_protected:Npx \@@_backend_Pages_primitive:n #1
{
\tex_special:D{ps:~[#1~/PAGES~pdfmark} %]
}
}
%xetex
\sys_if_engine_xetex:T
{
\cs_new_protected:Npn \@@_backend_Pages_primitive:n #1
{
\@@_backend:n{put~@pages~<<#1>>}
}
}
%</package>
% \end{macrocode}
% \subsubsection{pdfpagesattr/management}
% \begin{NOTE}{UF}
% The register is normally used only a few times in a document, so it would be
% okay to update the register/add the special at every change,
% but with dvips/dvipdfmx this would disable removing entries.
% So we issue the push code only at the end of the document.
% \end{NOTE}
% \begin{function}[added = 2019-06-04]
% {\pdf_pagesattr_gput:nn}
% \begin{syntax}
% \cs{pdf_pagesattr_gput:nn} \Arg{name} \Arg{value}
% \end{syntax}
% Adds |/|\meta{name} \meta{value} to the |/Pages| dictionary.
% It is always stored globally. The content is written to the pdf
% at the end of the compilation, so values can be added, changed or removed until then.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
% done explictly. If a \meta{name} is used twice, only the last \meta{value}
% set will be used.
% \end{function}
% \begin{function}[added = 2019-06-04]
% {\pdf_pagesattr_get:nN}
% \begin{syntax}
% \cs{pdf_pagesattr_get:nN} \Arg{name} \meta{tl var}
% \end{syntax}
% Recovers the \meta{value} stored by \cs{pdf_pagesattr_gput:nn} for
% \meta{name} and places this in the \meta{token list
% variable}. If \meta{name} is not found
% then the \meta{token list variable} is set
% to the special marker \cs{q_no_value}. The \meta{token list
% variable} is set within the current \TeX{} group.
% \end{function}
% \begin{function}[added = 2019-06-04]
% {
% \pdf_pagesattr_gremove:n
% }
% \begin{syntax}
% \pdf_pagesattr_gremove:n \Arg{name}
% \end{syntax}
% Removes |/|\meta{name} and its associated \meta{value} from the |/Pages| dictionary
% (if the name-value pair has been added by \cs{pdf_pagesattr_gput:nn}).
% If \meta{name} is not found no change occurs,
% \emph{i.e}~there is no need to test for the existence of a name before
% trying to remove it.
% \end{function}
% \begin{macrocode}
%<*package>
\@@_tree_new:n {Pages}
% setter:
%^^A documentated
\cs_new_protected:Npn \pdf_pagesattr_gput:nn #1 #2
{
\@@_tree_gput:nnn {Pages}{#1}{#2}
}
% getter from the prop:
%^^A documentated
\cs_new_protected:Npn \pdf_pagesattr_get:nN #1 #2
{
\@@_tree_get:nnN {Pages}{#1} #2
}
% remove:
%^^A documentated
\cs_new_protected:Npn \pdf_pagesattr_gremove:n #1
{
\@@_tree_gremove:nn {Pages}{#1}
}
% push to the register command / issue the special
\cs_new_protected:Npn \@@_Pages_gpush:
{
\exp_args:Nx \@@_backend_Pages_primitive:n
{
\@@_tree_map_dict_item:n {Pages}
}
}
%</package>
% \end{macrocode}
% \subsection{pdfpageattr}
% \subsubsection{pdfpageattr/backend}
% \begin{NOTE}{UF}
% path: Page
% The engines differ a lot here: pdflatex and lualatex uses a register while with
% dvips/dvipdfmx a one-shot-special ist used. So for pdflatex and lualatex code
% to assemble the content of the register is needed. Specials are used at shipout,
% the registers is set directly. With lualatex one can use
% \cs{latelua} to delay the setting, with pdflatex one has to use a shipout hook.
% To get the code on the correct page one has to use the aux with pdflatex.
% In sum this means that quite a lot backend commands are needed to handle
% this differences. Simply variants of \cs{pdfpageattr} are not enough ...%
% dvips syntax: \special{ps: [{ThisPage}<</Rotate 90>> /PUT pdfmark}%
% There seem to be an in-built management code: multiple uses don't lead to
% multiple entries (/Rotate is special: there is always a /Rotate 0 in the dict, but seems
% not to do harm).
% dvipdfmx syntax: \special{pdf: put @thispage << /Rotate 90 >>}, like dvips has an in-built
% management code.
% Both change only the current page, so to get the pdftex behaviour (which sets
% also the following pages) one need to repeat it on every shipout.
% \end{NOTE}
% \begin{macrocode}
%<*package>
%% backend commands
% a prop for global/default settings which are used for more than
% one page
\@@_tree_new:n {backend_Page}
%pdflatex
\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
{
%the primitive
\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
{
\tex_global:D \tex_pdfpageattr:D {#1}
}
% the command to store default values.
% Uses a prop with pdflatex + dvi,
% sets a lua table with lualatex
\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
{
\@@_tree_gput:nnn {backend_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 \@@_backend_Page_gremove:n #1
{
\@@_tree_gremove:nn {backend_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 \@@_backend_PageN_gput:nn #1 #2
{
\int_gincr:N\g_@@_resourceid_int
\zref@labelbylist {l3pdf\int_use:N\g_@@_backend_resourceid_int} {l3pdf}
\tl_set:Nx \l_@@_tmpa_tl
{
\zref@extractdefault{l3pdf\int_use:N\g_@@_backend_resourceid_int}
{pdf@abspage}
{0}
}
\@@_tree_new:n {backend_Page\l_@@_tmpa_tl}
\@@_tree_gput:nnn {backend_Page\l_@@_tmpa_tl}{#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 and then fills (in lua) in luatex
%issues the values stored in the global prop with dvi
\cs_new_protected:Npn \@@_backend_PageN_gpush:n #1
{
\@@_tree_merge:nnN {backend_Page}{backend_Page#1}\l_@@_tmpa_prop
\exp_args:Nx \@@_backend_Page_primitive:n
{
\prop_map_function:NN \l_@@_tmpa_prop \@@_dict_item:nn
}
}
}
\sys_if_engine_luatex:T
{% do we need to use some escaping for the values?????
\cs_new:Npn \@@_backend_luastring:n #1
{
"\tex_luaescapestring:D{\tex_unexpanded:D {#1}}"
}
%not used, only there for consistency
\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
{
\tex_latelua:D {pdf.setpageattributes(\@@_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 \@@_backend_Page_gput:nn #1 #2
{
\tex_directlua:D
{
l3kernel.@@.backend_Page_gput
(
\@@_backend_luastring:n {#1},
\@@_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 \@@_backend_Page_gremove:n #1
{
\tex_directlua:D { l3kernel.@@.backend_Page_gremove (\@@_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 \@@_backend_PageN_gput:nn #1 #2
{
\tex_latelua:D
{
l3kernel.@@.backend_PageN_gput
(
tex.count["g_@@_abspage_int"],
\@@_backend_luastring:n {#1},
\@@_backend_luastring:n {#2}
)
l3kernel.@@.backend_PageN_gpush (tex.count["g_@@_abspage_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 \@@_backend_PageN_gpush:n #1
{
\tex_latelua:D
{
l3kernel.@@.backend_PageN_gpush (tex.count["g_@@_abspage_int"])
}
}
}
\sys_if_engine_xetex:T
{
%the primitive
\cs_new_protected:Npn \@@_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 \@@_backend_Page_gput:nn #1 #2
{
\@@_tree_gput:nnn {backend_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 \@@_backend_Page_gremove:n #1
{
\@@_tree_gremove:nn {backend_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 \@@_backend_PageN_gput:nn #1 #2
{\tl_set:Nn\l_tmpa_tl{#1xx#2}\tl_show:N\l_tmpa_tl
\@@_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 \@@_backend_PageN_gpush:n #1
{
\exp_args:Nx \@@_backend_Page_primitive:n { \@@_tree_map_dict_item:n {backend_Page} }
}
}
%dvips
\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
{
\cs_new_protected:Npn \@@_backend_Page_primitive:n #1
{
\tex_special:D{ps:~[{ThisPage}<<#1>>~/PUT~pdfmark} %]
}
% the command to store default values.
% Uses a prop with pdflatex + dvi,
% sets a lua table with lualatex
\cs_new_protected:Npn \@@_backend_Page_gput:nn #1 #2
{
\@@_tree_gput:nnn {backend_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 \@@_backend_Page_gremove:n #1
{
\@@_tree_gremove:nn {backend_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 \@@_backend_PageN_gput:nn #1 #2
{
\@@_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 \@@_backend_PageN_gpush:n #1
{
\exp_args:Nx \@@_backend_Page_primitive:n { \@@_tree_map_dict_item:n {backend_Page} }
}
}
%</package>
% \end{macrocode}
% \subsubsection{pdfpageattr/management}
% \begin{NOTE}{UF}
% Open is the question if one need a command to set attribute on a page by page number.
% Open is the setter for /AF (and perhaps /OutputIntents).
% See also https://tex.stackexchange.com/questions/479812/extension-of-rotating-package-to-set-pdf-rotation
% (should work now)
% \end{NOTE}
% \begin{function}[added = 2019-06-04]
% {\pdf_pageattr_gput:nn}
% \begin{syntax}
% \cs{pdf_pageattr_gput:nn} \Arg{name} \Arg{value}
% \end{syntax}
% Adds |/|\meta{name} \meta{value} to the page dictionary of the
% current page and the following pages. The values are assigned directly,
% so one should take into account the asynchronous page breaking and use the
% command only e.g. after a \cs{clearpage} and not inside
% floats. It is always stored globally.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
% done explictly. If a \meta{name} is used twice, only the last \meta{value}
% set will be used. Names set with \cs{pdf_thispageattr_gput:nn} will overwrite
% names set with \cs{pdf_pageattr_gput:nn} if there is a clash.
% \end{function}
% \begin{function}[added = 2019-06-04]
% {
% \pdf_pageattr_gremove:n
% }
% \begin{syntax}
% \pdf_pageattr_gremove:n \Arg{name}
% \end{syntax}
% Removes |/|\meta{name} and its associated \meta{value} added by \cs{pdf_pageattr_gput:nn}
% from the page dictionaries of the current and the following pages.
% If \meta{name} is not found no change occurs,
% \emph{i.e}~there is no need to test for the existence of a name before
% trying to remove it. It doesn't affect values set with \cs{pdf_thispageattr_gput:nn}.
% \end{function}
% \begin{function}[added = 2019-06-19]
% {\pdf_thispageattr_gput:nn}
% \begin{syntax}
% \cs{pdf_thispageattr_gput:nn} \Arg{name} \Arg{value}
% \end{syntax}
% Adds |/|\meta{name} \meta{value} at shipout to the page dictionary of the
% current page.
% It is always stored globally. If \Arg{name} has already a value set with
% \cs{pdf_pageattr_gput:nn} it will overwrite it for this page.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
% done explictly. If a \meta{name} is used twice, only the last \meta{value}
% set will be used. With the engine pdflatex (at least) a second compilation is needed.
% \end{function}
% \begin{macrocode}
%<*package>
\@@_tree_new:n {Page}
% setter.
%^^A documentated
\cs_new_protected:Npn \pdf_pageattr_gput:nn #1 #2
{
\@@_backend_Page_gput:nn {#1}{#2}
}
% remove:
%^^A documentated
\cs_new_protected:Npn \pdf_pageattr_gremove:n #1
{
\@@_backend_Page_gremove:n { #1 }
}
% add to this page:
%^^A documentated
\cs_new_protected:Npn \pdf_thispageattr_gput:nn #1 #2
{
\@@_backend_PageN_gput:nn { #1 }{ #2 }
}
%</package>
% \end{macrocode}
% \subsection{The info dictionary}
% \begin{NOTE}{UF}
% path: Info
% The info dictionary is filled by e.g. \cs{pdfinfo}. Multiple appearances of
% \cs{pdfinfo} are concatenated, so one could end with multiple /Title or /Author entries.
% It is then viewer dependant which one is showed, so it is better to avoid this.
% We therefore setup a property which is filled and written to the info
% directory in one go. According to hyperref a few odd drivers (hvtex, dvipsone, dviwind)
% don't support arbitrary keys, but this should be handle elsewhere. Most entries are
% strings so there is a special command for this. As entries with empty content
% should be omited we add a test. The string command should perhaps escape the argument,
% but for now we are assuming that the argument is pdf safe.
% hyperref writes to the info dictionary at the shipout of the first page --
% probably to catch the case that \cs{title} is issued after the begin of the document.
% We are outputting at the last page -- this needs a second compilation but
% this is needed anyway.
% \end{NOTE}
% \subsubsection{Info / backend}
% The backend code is already in expl3. \verb+\__pdf_backend_info_gput:nn+
% inserts one name/value pair.
% \subsubsection{Info / management}
% \begin{function}[added = 2019-06-22]
% {
% \pdf_info_gput:nn
% }
% \begin{syntax}
% \pdf_info_gput:nn \Arg{name} \Arg{value}
% \end{syntax}
% Adds |/|\meta{name} and the \meta{value} to the info dictionary.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid pdf value. Any escaping or (re)encoding must be
% done explictly.
% The info dictionary expects utf8 in the strings, so a conversion like this is
% normally sensible:
% \begin{verbatim}
% \str_set_convert:Nnnn \l_tmpa_str { Grüße }{ utf8 } {utf8/string}
% \pdf_info_string_gput:nn {Title}{\l_tmpa_str}
% \end{verbatim}
% If a \meta{name} is used twice, only the last \meta{value}
% set will be used. The info dictionary is written at the end of the compilation,
% so values can be set at any time.
% \end{function}
% \begin{function}[added = 2019-06-22]
% {
% \pdf_info_string_gput:nn
% }
% \begin{syntax}
% \pdf_info_string_gput:nn \Arg{name} \Arg{value}
% \end{syntax}
% Adds |/|\meta{name} and the \meta{value} surrounded by parentheses to the info dictionary.
% \meta{name} should be a valid pdf name without the leading slash,
% \meta{value} should be a valid content of pdf string. Any escaping or (re)encoding must be
% done explictly.
% The info dictionary expects utf8 in the strings, so a conversion like this is
% normally sensible:
% \begin{verbatim}
% \str_set_convert:Nnnn \l_tmpa_str { Grüße }{ utf8 } {utf8/string}
% \pdf_info_string_gput:no {Title}{\l_tmpa_str}
% \end{verbatim}
% If a \meta{name} is used twice, only the last \meta{value}
% set will be used. The info dictionary is written at the end of the compilation,
% so values can be set at any time.
% \end{function}
% \begin{macrocode}
%<*package>
\@@_tree_new:n {Info}
\cs_new_protected:Npn \pdf_info_gput:nn #1 #2 %#1 key without /, #2 content
{
\@@_tree_gput:nnn {Info}{#1}{#2}
}
\cs_generate_variant:Nn \pdf_info_gput:nn {no}
% should #2 be inside a some escaping command? (no)
% hyperref passes them through
% \HyXeTeX@CheckUnicode
% \HyPsd@XeTeXBigCharstrue
% \HyPsd@PrerenderUnicode{#1}%
% \pdfstringdef\@pdftitle{#1}%
\cs_new_protected:Npn \pdf_info_string_gput:nn #1 #2 %#1 key without /, #2 content
{
\@@_tree_gput:nnn {Info}{#1}{(#2)}
}
\cs_generate_variant:Nn \pdf_info_string_gput:nn {no,oo,on}
% push to the register command / issue the special
\cs_new_protected:Npn \@@_Info_gpush:
{
\prop_map_function:cN { \@@_tree_prop_name:n {Info} } \@@_backend_info_gput:nn
\prop_gclear:c { \@@_tree_prop_name:n {Info} }
}
%</package>
% \end{macrocode}
% \subsection{page resources / Properties and bdc-mark}
% \begin{NOTE}{UF}
% we still need a switch for the case that the resource should be added to
% xform resource instead of a page resources, see pdfbase.sty
% \end{NOTE}
% Entries to the /Properties dictionary in the page resources can
% be added with dvips only through side-effect: if a bdc-mark is created dvips/ghostscript
% will automatically create the necessary objects and names.
% To get a sensible abstraction the code does the same for the other backends: There are
% no public commands to add values to the /Properties dictionary directly, only
% commands to set BDC-marks.
% \begin{function}[added = 2019-06-29]
% {
% \pdf_bdc:nn
% }
% \begin{syntax}
% \pdf_bdc:nn \Arg{tag} \Arg{object name}
% \end{syntax}
% This command adds a BDC marked content operator to the current page stream.
% \meta{tag} is the tag of this operator (without the leading slash),
% \meta{object name} is a the name of an dictionary object reserved with
% \cs{pdf_object_new:nn} and filled with \cs{\pdf_object_write:n} with
% the properties of the BDC.
% \begin{function}[added = 2019-06-30]
% {
% \pdf_emc:
% }
% \begin{syntax}
% \pdf_emc:
% \end{syntax}
% This command closes the BDC marked content operator opened with \cs{pdf_bdc:nn}.
% It should be one the same page as the bdc-command.
%
% \begin{verbatim}
% \pdf_object_new:nn {objA}{dict}
% \pdf_object_write:nn {objA}{/Type/Artifact}
% \pdf_bdc:nn {Span}{objA}
% text
% \pdf_emc:
% \end{verbatim}
% \end{function}
% \subsubsection{bcd/Properties, backend code}
% \begin{macrocode}
%<*package>
% dvips
% dvips is easy: create an object, and reference it in the bdc
% ghostscript will then automatically replace it by a name
% and add the name to the /Properties dict
% special variant von accsupp https://chat.stackexchange.com/transcript/message/50831812#50831812
\bool_if:nT {\sys_if_engine_pdftex_p: && !\sys_if_output_pdf_p: }
{
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
{
\special{ps:~mark~/#1~\@@_backend_object_ref:n{#2}~BDC~pdfmark}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\special{ps:~mark~/EMC~pdfmark} %
}
\cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
}
% xetex has so create the entries in the /Properties manually (like the other backends)
% use pdfbase special https://chat.stackexchange.com/transcript/message/50832016#50832016
\sys_if_engine_xetex:T
{
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\special{pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC}
\special{
pdf:put~@resources~
<<
/Properties~
<<
/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
\@@_backend_object_ref:n{#2}
>>
>>
}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\special{pdf:code~EMC} %pdfbase
}
\cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
}
% luatex
\sys_if_engine_luatex:T
{
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{/#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC}
\exp_args:Nx\tex_latelua:D
{
l3kernel.pdf.Page_Resources_Properties_gput
( tex.count["g_@@_abspage_int"],
"l3pdf\int_use:N\g_@@_backend_name_int",
"\@@_backend_object_ref:n{#2}"
)
}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}
\cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1 {}
}
% pdflatex is the most complicated as it has to go through the aux ...
% !!! the push command will have to be extended to take other resources too
\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
{
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\exp_args:Nx\__kernel_backend_literal_page:n
{/#1 ~ /l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC}
% code to set the property ....
\int_gincr:N\g_@@_backend_resourceid_int
\zref@labelbylist {l3pdf\int_use:N\g_@@_backend_resourceid_int} {l3pdf}
\tl_set:Nx \l_@@_tmpa_tl
{
\zref@extractdefault{l3pdf\int_use:N\g_@@_backend_resourceid_int}
{pdf@abspage}
{0}
}
\@@_tree_new:n {backend_Page\l_@@_tmpa_tl/Resources/Properties}
\exp_args:Nnx\@@_tree_gput:nnn
{backend_Page\l_@@_tmpa_tl/Resources/Properties}
{l3pdf\int_use:N\g_@@_backend_resourceid_int}
{\@@_backend_object_ref:n{#2}}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}
\cs_new_protected:Npn \@@_backend_PageN_Resources_gpush:n #1
{
\exp_args:NNx \tex_global:D \tex_pdfpageresources:D
{
\prop_if_exist:cT { \@@_tree_prop_name:n { backend_Page#1/Resources/Properties } }
{
/Properties~<<
\prop_map_function:cN
{ \@@_tree_prop_name:n { backend_Page#1/Resources/Properties } } \@@_dict_item:nn
>>
}
%% add ExtGState etc
}
}
}
%</package>
% \end{macrocode}
% ===================================
%\subsubsection{pdfxform}
% \begin{NOTE}{UF}
% As in dvi mode the xform is immediate, this is done for pdftex/luatex too. If needed
% a delayed version can be added later. dvips, dvipdfmx implementation is missing
% \end{NOTE}
% \begin{macrocode}
%<*package>
\prop_new:N \g_@@_backend_xform_prop
\bool_if:nT {\sys_if_engine_pdftex_p: && \sys_if_output_pdf_p: }
{
\cs_new_protected:Npn \@@_backend_xform_new:nnnN #1 #2 #3 #4 %name, attr, resources, box
{
\tex_immediate:D \tex_pdfxform:D~attr { #2 }~resources {#3} #4
\int_const:cn
{ c_@@_backend_xform_ \tl_to_str:n {#1} _int }
{ \tex_pdflastxform:D }
\prop_gput:Nnx \g_@@_backend_xform_prop {#1}
{
\tex_pdfxformname:D \int_use:c {c_@@_backend_xform_ \tl_to_str:n {#1} _int}
}
}
\cs_new:Npn \@@_backend_xform_use:n #1
{
\tex_pdfrefxform:D \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } \scan_stop:
}
% should there be a test if the name exists???
\cs_new:Npn \@@_backend_xform_ref:n #1
{ \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } ~ 0 ~ R }
\cs_new:Npn \@@_backend_xform_name_ref:n #1
{ /Fm\prop_item:Nn \g_@@_backend_xform_prop {#1} }
}
%nearly identical but not completly ...
\sys_if_engine_luatex:T
{
\cs_new_protected:Npn \@@_backend_xform_new:nnnN #1 #2 #3 #4 %name, attr, resources, box
{
\tex_immediate:D \tex_pdfxform:D~attr { #2 }~resources {#3} #4
\int_const:cn
{ c_@@_backend_xform_ \tl_to_str:n {#1} _int }
{ \tex_pdflastxform:D }
\prop_gput:Nnx \g_@@_backend_xform_prop {#1}
{
\tex_pdffeedback:D~xformname \int_use:c {c_@@_backend_xform_ \tl_to_str:n {#1} _int}
}
}
\cs_new:Npn \@@_backend_xform_use:n #1
{
\tex_pdfrefxform:D \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } \scan_stop:
}
\cs_new:Npn \@@_backend_xform_ref:n #1
{ \int_use:c { c_@@_backend_xform_ \tl_to_str:n {#1} _int } ~ 0 ~ R }
\cs_new:Npn \@@_backend_xform_name_ref:n #1
{ /Fm\prop_item:Nn \g_@@_backend_xform_prop {#1} }
}
%</package>
% \end{macrocode}
% \subsection{backend / pageresources}
% \begin{NOTE}{UF} Implementation for dvips missing (perhaps impossible ...), for xetex untested.
% \enquote{Correct} content needed at every shipout
% \end{NOTE}
% \begin{macrocode}
%<*package>
% backend commands the command to fill the register