-
Notifications
You must be signed in to change notification settings - Fork 5
/
pdfresources.dtx
1916 lines (1853 loc) · 65 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-2020 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/pdfresources
%
% for those people who are interested.
%
%<*driver>
\documentclass{l3doc}
\usepackage{tabularx,array,booktabs}
\newcommand\potentialclash{\noindent\llap{\dbend\ }}
\raggedbottom
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \begin{macrocode}
%<@@=pdf>
%<*package>
\RequirePackage{xparse,l3pdf}
\RequirePackage{lthooks,zref-base,bitset}
\ProvidesExplPackage {pdfresources} {2020-06-15} {0.6}
{experimental pdf-resource management}
\DeclareOption { debug }
{
\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 2020-XX-XX}
%
% \maketitle
% \section{Introduction}
% The project here tries to resolve this situation by providing interfaces to
% the various resources and objects in a backend independent way.
%
% The supported backends are pdflatex, lualatex, (x)dvipdfmx (latex, xelatex)
% and dvips with ps2pdf (not completely yet). dvips with distiller could work too
% but is untested.
%
% That the interfaces are backend independent doesn't mean that the results and even
% the compilation behavior is identical. The backends are too different to allow
% this. Some backends expand arguments e.g. in a \cs{special} while other don't.
% Some backends can insert a resource at the first compilation, while another uses
% the aux-file and a label and so needs at least two.
%
% \section{messages}
% \begin{macrocode}
%<*package>
\msg_new:nnn { pdf } { patches }
{ loading~patch~code }
\msg_new:nnn { pdf } { pgf-too-late }
{ pgf~is~already~loaded.~Patching~not~possible.}
%</package>
% \end{macrocode}
% \section{Preparation/helper Code}
%^^A still needed:
%^^A \pdf@strcmp??
%^^A \pdf@escapestring?? \pdfescapestring
% \begin{variable}{\l_@@_tmpa_prop, \l_@@_tmpa_tl }
% Some scratch variables
% \begin{macrocode}
%<*package>
\prop_new:N \l_@@_tmpa_prop
\prop_new:N \g_@@_tmpa_prop
\tl_new:N \l_@@_tmpa_tl
\box_new:N \l_@@_tmpa_box
\box_new:N \l_@@_tmpb_box
%</package>
% \end{macrocode}
% \end{variable}
%
% \subsection{references to page objects}
% \begin{NOTE}{UF}
% a reference to the current page would be useful, but difficult to
% abstract in a sensible way. With xetex it is simply @thispage, but the other
% engines are unclear.
% \end{NOTE}
% \begin{function}[EXP, added = 2019-08-18]
% {\pdf_pageobject_ref:n}
% \begin{syntax}
% \cs{pdf_pageobject_ref:n} \Arg{number}
% \end{syntax}
% This returns the object reference of a page object. The \Arg{number} is
% the absolute page number. The count starts with one.
% \end{function}
% \begin{macro}{ \pdf_pageobject_ref:n }
% \begin{macrocode}
%<*package>
\cs_new:Npn \pdf_pageobject_ref:n #1 { \@@_backend_pageobject_ref:n { #1 }}
%</package>
% \end{macrocode}
% \end{macro}
% This loads the dict packages.
% \begin{NOTE}{UF}
% The loading order must be sorted ...
% \end{NOTE}
% \begin{macrocode}
%<*package>
\RequirePackage{l3pdfdict}
\RequirePackage{l3pdfcoredict}
%</package>
% \end{macrocode}
%
% \subsection{The \enquote{Info} dictionary (pdfinfo)}
% \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 dependent 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 omitted 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{\enquote{Info}/backend}
% The backend code is already in expl3.
% \cs{@@_backend_info_gput:nn} inserts one name/value pair.
%
% \subsubsection{\enquote{Info}/management}
% moved to l3pdfcoredict
%
% \subsection{The \enquote{Pages} dictionary (pdfpagesattr)}
% The content of the property list associated with this dictionary name is written to the
% /Pages object. This replaces \cs{pdfpagesattr}. This dictionary is global.
% \subsubsection{\enquote{Pages} / 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}
%
% \subsubsection{\enquote{Pages} / 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}
% code moved to l3pdfcoredict
%
% \subsection{\enquote{Page} and \enquote{ThisPage} (pdfpageattr)}
% \subsubsection{\enquote{Page} and \enquote{ThisPage} /backend}
% moved to l3backend-pdf-extra
% \subsubsection{\enquote{Page} and \enquote{ThisPage} / 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}
% code moved to l3pdfcoredict ...
%
% \subsection{\enquote{Page/Resources}: ExtGState, ColorSpace, Shading, Pattern }
% \begin{NOTE}{UF}
% Only for pdf/luatex and xdvipdfmx backend- and pdf-code is needed to add values
% to these resources.
% With dvips the resources are added through high-level code (e.g. transparency), so the
% backend/pdf commands are no-ops.
% For every resources there is only one object. References to these objects are added to
% all pages starting from the page where the first time something has been added to the
% resource and to all XObjects. For luatex and pdftex it must be done together
% with the /Properties, see above.
% I don't see a need to set e.g. /ColorSpace page wise: preflight handles this
% fine, see experiment colorspace-resources.
% As pgf does the same, there is a need to patch it for now. Ditto for package colorspace.
% \end{NOTE}
% \subsubsection{\enquote{Page/Resources}: ExtGState, ColorSpace, Shading, Pattern / backend}
% moved to l3backend-pdf-extra
%
% \subsection{\enquote{Catalog} \& subdirectories (pdfcatalog) }
% \subsubsection{\enquote{Catalog} \& subdirectories / backend}
% the backend command is already in the driver:
% \cs{@@_backend_catalog_gput:nn}
%
% \subsubsection{\enquote{Catalog} \& subdirectories / management }
% \begin{NOTE}{UF}
% The catalog dictionary is filled by e.g. \cs{pdfcatalog}. Multiple appearances of
% \cs{pdfcatalog} are concatenated, so one could end with multiple entries
% for the same value with luatex and pdftex -- the other backends normally
% avoid this problem.
% We therefore setup a property which is filled and executed at a sensible
% (not fixed) place.
% /AF is even an array of dictionaries.
% There is probably no way to test what has already been added to the catalog,
% so doublets can only be avoided with ``don't do it''.
% see catalogue.tex for a list of entries ...
% Perhaps some tools to create the AF-file specification dictionaries is useful.
% Open for now:
% /Extensions (dict, pdf 2.0)
% /Dests ? difference to subdict in Names?
% /DSS (dict, pdf 2.0)
% /Acroform/DR/ExtGState etc probably unneeded.
% \end{NOTE}
%
% \subsection{Local dictionaries}
%
% All dictionaries described above were global dictionaries and basically they
% are written at most once (or at most once per page) to the PDF. The pdfdict module
% predefines also a number of local dictionaries. These are used in objects like
% link annotations (see the pdfannot module) which are written in varying
% numbers to the PDF and allow to set their features and change them locally
% if needed. The predefined dictionaries are
% \begin{NOTE}{UF}
% sync that with the table in pdfdict ...
% \end{NOTE}
% \begin{tabular}{lp{6cm}}
% \multicolumn{2}{l}{annotation related: here are
% \texttt{Border} and \texttt{C} (color)}\\
% annot/Link/Goto & used in GoTo links (internal references) \\
% annot/Link/URI & used in URI links (external uri references) \\
% annot/Link/GotoR & used in GoToR links (file references) \\
% annot/Link/Named & used in Named actions (menu calls) \\
% annot/Link/Launch & used in Launch links (application calls) \\
% \end{tabular}
% \section{Various PDF contents}
% The following commands allow to create a number of important pdf objects and contents in a
% backend independant way.
%
% \subsection{BDC operator / Properties resource}
% \begin{NOTE}{UF}
% we need a switch for the case that the resource should be added to
% xform resource instead of a page resources, see pdfbase.sty
% - xdvipdfmx: looks fine, the resource is added to the xform resource automatically
% - pdftex should now work okay too
% \end{NOTE}
% Entries to the /Properties dictionary in the page resources can
% be added with dvips only through side-effects: 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}
% \cs{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.
% \end{function}
% \begin{function}[added = 2019-10-18]
% {
% \pdf_bdc:n
% }
% \begin{syntax}
% \cs{pdf_bdc:n} \Arg{tag}
% \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).
% As object this commands uses the last anonymous dictionary object created with
% \cs{pdf_object_now:nn}. It lies in the responsibility of the user that the last
% object is the wanted one.
% \end{function}
% \begin{function}[added = 2019-10-17]
% {
% \pdf_bmc:n
% }
% \begin{syntax}
% \cs{pdf_bmc:n} \Arg{tag}
% \end{syntax}
% This command created a BMC marked content operator. The argument is the
% tag without the leading slash. It can be e.g. used for simple artifact
% markers.
% \end{function}
% \begin{function}[added = 2019-06-30]
% {
% \pdf_emc:
% }
% \begin{syntax}
% \cs{pdf_emc:}
% \end{syntax}
% This command closes the BDC marked content operator opened with \cs{pdf_bdc:nn}.
% It should be on 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{BDC and Properties / backend}
% \begin{macro}
% {
% \@@_backend_bdc:nn,
% \@@_backend_bdc:n,
% \@@_backend_bmc:n,
% \@@_backend_emc:,
% \@@_backend_PageResources_gpush:n
% }
% \cs{@@_backend_bdc:nn}, \cs{@@_backend_bmc:n} and \cs{@@_backend_emc:}
% are the backend command that
% create the bdc/emc marker and store the properties.
% \cs{@@_backend_PageResources_gpush:n} outputs the /Properties and/or the other
% resources in
% \cs{@@_BACKEND_thispage_shipout_gput:n} for the current page.
% \begin{macrocode}
% pdftex and luatex (and perhaps dvips ...) need to know if there are in a
% xform stream ...
%<*drivers>
\bool_new:N \l_@@_backend_xform_bool
%</drivers>
%<*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
%
\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_bdc:n #1 % #1 eg. Span,
{
\special {ps:~mark~/#1~\@@_backend_object_last:~/BDC~pdfmark}
}
\cs_set_protected:Npn \@@_backend_emc:
{
\special {ps:~mark~/EMC~pdfmark} %
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\special {ps:~mark~/#1~/BMC~pdfmark} %
}
\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
%</dvips>
% xetex has to create the entries in the /Properties manually
% (like the other backends)
% use pdfbase special
% https://chat.stackexchange.com/transcript/message/50832016#50832016
% the property is added to xform resources automatically,
% no need to worry about it.
%<*dvipdfmx|xdvipdfmx>
\cs_set_protected:Npn \@@_backend_bdc:nn #1 #2 % #1 eg. Span, #2: object name
{
\int_gincr:N \g_@@_backend_name_int
\__kernel_backend_literal:x
{
pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
}
\__kernel_backend_literal:x
{
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_bdc:n #1 % #1 eg. Span
{
\int_gincr:N \g_@@_backend_name_int
\__kernel_backend_literal:x
{
pdf:code~/#1/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl BDC
}
\__kernel_backend_literal:x
{
pdf:put~@resources~
<<
/Properties~
<<
/l3pdf\int_use:N\g_@@_backend_name_int\c_space_tl
\@@_backend_object_last:
>>
>>
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal:n {pdf:code~/#1~BMC} %pdfbase
}
\cs_set_protected:Npn \@@_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 \@@_backend_PageResources_gpush:n #1
{
\clist_map_inline:Nn \c_@@_backend_PageResources_clist
{
\prop_if_empty:cF { \pdfdict_gname:n {Core/Page/Resources/##1} }
{
\__kernel_backend_literal:x
{
pdf:put~@resources~
<</##1~\@@_backend_object_ref:n {Page/Resources/##1}>>
}
}
}
}
%</dvipdfmx|xdvipdfmx>
% luatex
%<*pdfmode>
\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 }
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnx\pdfdict_gput:nnn
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_name_int }
{ \@@_backend_object_ref:n { #2 } }
}
{
\exp_args:Nx \tex_latelua:D
{
l3kernel.pdf.Page_Resources_Properties_gput
(
tex.count["g_shipout_readonly_int"],
"l3pdf\int_use:N\g_@@_backend_name_int",
"\@@_backend_object_ref:n { #2 }"
)
}
}
}
\cs_set_protected:Npn \@@_backend_bdc:n #1% #1 eg. Span
{
\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 }
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnx\pdfdict_gput:nnn %no handler needed
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_name_int }
{ \@@_backend_object_last: }
}
{
\exp_args:Nx \tex_latelua:D
{
l3kernel.pdf.Page_Resources_Properties_gput
(
tex.count["g_shipout_readonly_int"],
"l3pdf\int_use:N\g_@@_backend_name_int",
"\@@_backend_object_last:"
)
}
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal_page:n { /#1~BMC }
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}
\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1 {}
}
% pdflatex is the most complicated as it has to go through the aux ...
% the push command is extended to take other resources too
\sys_if_engine_pdftex: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 }
% code to set the property ....
\int_gincr:N\g_@@_backend_resourceid_int
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnxx\pdfdict_gput:nnn %no handler needed
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_ref:n { #2 } }
}
{
\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}
}
\pdfdict_if_gexist:nF { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{
\pdfdict_gnew:n { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/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_bdc:n #1% #1 eg. Span
{
\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
\bool_if:NTF \l_@@_backend_xform_bool
{
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/Xform/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_last: }
}
{
\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}
}
\pdfdict_if_gexist:nF { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{
\pdfdict_gnew:n { Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
\exp_args:Nnxx\pdfdict_gput:nnn
{ Core/backend_Page\l_@@_tmpa_tl/Resources/Properties }
{ l3pdf\int_use:N\g_@@_backend_resourceid_int }
{ \@@_backend_object_last: }
%\pdfdict_show:n { backend_Page\l_@@_tmpa_tl/Resources/Properties }
}
}
\cs_set_protected:Npn \@@_backend_bmc:n #1
{
\__kernel_backend_literal_page:n { /#1~BMC }
}
\cs_set_protected:Npn \@@_backend_emc:
{
\__kernel_backend_literal_page:n { EMC }
}
\cs_new:Npn \@@_backend_PageResources_gpush_aux:n #1 %#1 ExtGState etc
{
\prop_if_empty:cF
{ \pdfdict_gname:n {Core/Page/Resources/#1} }
{
\pdfdict_item:ne { #1 }{ \pdf_object_ref:n {Page/Resources/#1}}
}
}
\cs_new_protected:Npn \@@_backend_PageResources_gpush:n #1
{
\exp_args:NNx \tex_global:D \tex_pdfpageresources:D
{
\prop_if_exist:cT
{ \pdfdict_gname:n { Core/backend_Page#1/Resources/Properties } }
{
/Properties~
<<
\prop_map_function:cN
{ \pdfdict_gname:n { Core/backend_Page#1/Resources/Properties } }
\pdfdict_item:ne
>>
}
%% add ExtGState etc
\clist_map_function:NN
\c_@@_backend_PageResources_clist
\@@_backend_PageResources_gpush_aux:n
}
}
}
%</pdfmode>
% \end{macrocode}
% \end{macro}
%
% \subsubsection{BDC and Properties / management}
% \begin{macrocode}
%<*package>
\cs_new_protected:Npn \pdf_bdc:nn #1 #2 { \@@_backend_bdc:nn { #1 }{ #2 } }
\cs_new_protected:Npn \pdf_bdc:n #1 { \@@_backend_bdc:n { #1 } }
\cs_new_protected:Npn \pdf_bmc:n #1 { \@@_backend_bmc:n { #1 } }
\cs_new_protected:Npn \pdf_emc: { \@@_backend_emc: }
%</package>
% \end{macrocode}
%
% \subsection{Form XObject (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.
% - the argument for attributes is needed to add e.g. /StructParents
% - it is not clear if an argument for additional resources is needed, probably they
% should / need to be added automatically.
% - code for adding ExtGState etc to the local resource is missing, will be
% added when the object name is clear.!!!!!!!!!!!!
% - should the size be stored in dim or tl?
% - dvips implementation is missing for ideas: pdfbase, atfi-dvips.def,
% \end{NOTE}
%
% \subsubsection{Form XObject / management}
% \begin{function}[added = 2019-08-05]
% {
% \pdf_xform_new:nnn
% }
% \begin{syntax}
% \cs{pdf_xform_new:nnn} \Arg{name} \Arg{attributes} \Arg{content}
% \end{syntax}
% This command create a new form XObject that can be used as appearance or
% directly later.
% If the content contains BDC-marks it should \emph{not} be given as a
% previously typeset box, but directly so that the names of the
% BDC-marks can be added to the resources of the xform. The xform will automatically
% include the resources of the current page.
% The content will be typeset in a hbox. With pdflatex and luatex
% the surrounding color is \emph{not} stored in the XObject
% but should be if wanted added e.g. with |\color_select:n{.}|. This keeps
% the option of color injection open.
% \end{function}
% \begin{function}[added = 2019-08-05]
% {
% \pdf_xform_use:n
% }
% \begin{syntax}
% \cs{pdf_xform_use:n} \Arg{name}
% \end{syntax}
% This command uses (typesets) a previously created form XObject.
% If the surrounding color is different, it is injected in the XObject with the
% engines pdftex or luatex.
% \end{function}
% \begin{function}[EXP,added = 2019-08-05]
% {
% \pdf_xform_ref:n
% }
% \begin{syntax}
% \cs{pdf_xform_ref:n} \Arg{name}
% \end{syntax}
% Inserts the appropriate information to reference the xform \meta{name}
% in for example appearance dictionaries.
% \end{function}
% \begin{function}[EXP,added = 2019-08-05]
% {
% \pdf_xform_wd:n, \pdf_xform_ht:n, \pdf_xform_dp:n
% }
% \begin{syntax}
% \cs{pdf_xform_wd:n} \Arg{name}
% \end{syntax}
% These command give back the sizes of the XObject. The values are stored in
% tl-variables with the unit pt and not in dimensions!
% \end{function}
% \begin{function}[EXP,pTF,added = 2020-04-29]
% {
% \pdf_xform_if_exist:n
% }
% \begin{syntax}
% \cs{pdf_xform_if_exist_p:n} \Arg{name}
% \cs{pdf_xform_if_exist:NTF} \meta{name} \Arg{true code} \Arg{false code}
% \end{syntax}
% These command tests if an xform with name \Arg{name} has been already defined.
% \end{function}%
% \begin{macrocode}
%<*package>
\cs_new_protected:Npn \pdf_xform_new:nnn #1 #2 #3
{
\@@_backend_xform_new:nnnn { #1 } { #2 } { } { #3 }
}
\cs_new_protected:Npn \pdf_xform_use:n #1
{
\@@_backend_xform_use:n { #1 }
}
% expansion?
\cs_new:Npn \pdf_xform_ref:n #1
{
\@@_backend_xform_ref:n { #1 }
}
\cs_generate_variant:Nn \pdf_xform_ref:n {o}
\cs_new:Npn \pdf_xform_wd:n #1
{
\tl_use:c { c_@@_backend_xform_wd_ \tl_to_str:n { #1 } _tl }
}
\cs_new:Npn \pdf_xform_ht:n #1
{
\tl_use:c { c_@@_backend_xform_ht_ \tl_to_str:n { #1 } _tl }
}
\cs_new:Npn \pdf_xform_dp:n #1
{
\tl_use:c { c_@@_backend_xform_dp_ \tl_to_str:n { #1 } _tl }
}
%</package>
% \end{macrocode}
%
% \subsubsection{Form XObject / backend }
% \begin{macro}{ \@@_backend_xform_new:nnnn }
% \begin{arguments}
% \item name
% \item attributes
% \item resources %needed?? or are all resources autogenerated?
% \item content, this doesn't need to be a box!
% \end{arguments}
% \begin{macro}{ \@@_backend_xform_use:n, \@@_backend_xform_ref:n }
% \begin{macrocode}
%<*pdfmode>
\sys_if_engine_pdftex:T
{
\cs_new_protected:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
% #1 name
% #2 attributes
% #3 resources
% #4 content, not necessarily a box!
{
\hbox_set:Nn \l_@@_tmpa_box
{
\bool_set_true:N \l_@@_backend_xform_bool
\prop_gclear:c {\pdfdict_gname:n { Core/Xform/Resources/Properties }}
#4
}
%store the dimensions
\tl_const:cx
{ c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_wd:N \l_@@_tmpa_box }
\tl_const:cx
{ c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_ht:N \l_@@_tmpa_box }
\tl_const:cx
{ c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_dp:N \l_@@_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 { \pdfdict_gname:n { Core/Xform/Resources/Properties } } }
>
{ 0 }
{
/Properties~
<<
\pdfdict_gmap:n { Core/Xform/Resources/Properties }
>>
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/ExtGState } }
{
/ExtGState~ \pdf_object_ref:n { Page/Resources/ExtGState }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/Pattern } }
{
/Pattern~ \pdf_object_ref:n { Page/Resources/Pattern }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/Shading } }
{
/Shading~ \pdf_object_ref:n { Page/Resources/Shading }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/ColorSpace } }
{
/ColorSpace~ \pdf_object_ref:n { Page/Resources/ColorSpace }
}
}
\l_@@_tmpa_box
\int_const:cn
{ c_@@_backend_xform_ \tl_to_str:n {#1} _int }
{ \tex_pdflastxform:D }
}
\cs_new_protected: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
}
}
%luatex
%nearly identical but not completely ...
\sys_if_engine_luatex:T
{
\cs_new:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
% #1 name
% #2 attributes
% #3 resources
% #4 content, not necessarily a box!
{
\hbox_set:Nn \l_@@_tmpa_box
{
\bool_set_true:N \l_@@_backend_xform_bool
\prop_gclear:c { \pdfdict_gname:n { Core/Xform/Resources/Properties } }
#4
}
\tl_const:cx
{ c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_wd:N \l_@@_tmpa_box }
\tl_const:cx
{ c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_ht:N \l_@@_tmpa_box }
\tl_const:cx
{ c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_dp:N \l_@@_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 { \pdfdict_gname:n { Core/Xform/Resources/Properties } }}
>
{ 0 }
{
/Properties~
<<
\pdfdict_gmap:n { Core/Xform/Resources/Properties }
>>
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/ExtGState } }
{
/ExtGState~ \pdf_object_ref:n { Page/Resources/ExtGState }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/Pattern } }
{
/Pattern~ \pdf_object_ref:n { Page/Resources/Pattern }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/Shading } }
{
/Shading~ \pdf_object_ref:n { Page/Resources/Shading }
}
\prop_if_empty:cF
{ \pdfdict_gname:n { Core/Page/Resources/ColorSpace } }
{
/ColorSpace~ \pdf_object_ref:n { Page/Resources/ColorSpace }
}
}
\l_@@_tmpa_box
\int_const:cn
{ c_@@_backend_xform_ \tl_to_str:n {#1} _int }
{ \tex_pdflastxform:D }
}
\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 }
}
%</pdfmode>
%<*dvipdfmx|xdvipdfmx>
% xetex
% 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:Npn \@@_backend_xform_new:nnnn #1 #2 #3 #4
% #1 name
% #2 attributes
% #3 resources
% #4 content, not necessarily a box!
{
\int_gincr:N \g_@@_backend_object_int
\int_const:cn
{ c_@@_backend_xform_ \tl_to_str:n {#1} _int }
{ \g_@@_backend_object_int }
\box_new:c { g_@@_backend_xform_#1_box }
\hbox_gset:cn { g_@@_backend_xform_#1_box }
{
\bool_set_true:N \l_@@_backend_xform_bool
#4
}
\tl_const:cx
{ c_@@_backend_xform_wd_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_wd:c { g_@@_backend_xform_#1_box } }
\tl_const:cx
{ c_@@_backend_xform_ht_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_ht:c { g_@@_backend_xform_#1_box } }
\tl_const:cx
{ c_@@_backend_xform_dp_ \tl_to_str:n {#1} _tl }
{ \tex_the:D \box_dp:c { g_@@_backend_xform_#1_box } }
\box_set_dp:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
\box_set_ht:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
\box_set_wd:cn { g_@@_backend_xform_#1_box } { \c_zero_dim }
\hook_gput_next_code:nn {shipout/background}
{
\mode_leave_vertical: %needed, the xform disappears without it.
\@@_backend:x
{
bxobj ~ \@@_backend_xform_ref:n { #1 }
\c_space_tl width ~ \pdf_xform_wd:n { #1 }
\c_space_tl height ~ \pdf_xform_ht:n { #1 }
\c_space_tl depth ~ \pdf_xform_dp:n { #1 }
}
\box_use_drop:c { g_@@_backend_xform_#1_box }
\@@_backend:x {put ~ @resources ~<<#3>> }
\@@_backend:x
{
put~ @resources ~
<<
/ExtGState~ \pdf_object_ref:n { Page/Resources/ExtGState }
>>
}
\@@_backend:x
{
put~ @resources ~
<<
/Pattern~ \pdf_object_ref:n { Page/Resources/Pattern }
>>
}
\@@_backend:x
{
put~ @resources ~
<<
/Shading~ \pdf_object_ref:n { Page/Resources/Shading }
>>
}
\@@_backend:x
{