summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pdfmanagement-testphase/hyperxmp-patches-tmp-ltx.sty
blob: ab8723947e408c3469a3804d1ce580e7ceed2b7b (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
%% This is file `hyperxmp-patches-tmp-ltx.sty"
% 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 "pdfmanagement 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.
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesExplPackage{hyperxmp-patches-tmp-ltx}{2021-05-14}{0.95d}
  {Store hyperref metadata in XMP format / temporay patches to test pdfresource management ... UF}

\cs_if_exist:NT \pdfmanagement_add:nnn
  {
    \pdfmanagement_if_active:T
     {
       \renewcommand\hyxmp@embed@packet{\hyxmp@embed@packet@generic}
     }
  }

%
\newcommand*{\hyxmp@embed@packet@generic}
 {%
   \typeout{}
   \typeout{!!~new-hyperxmp--generic~packet~command~used!!}{}
   \typeout{}
   \hyxmp@construct@packet
   %or some other command to write a object:
   \exp_args:Nnx
    \pdf_object_unnamed_write:nn{stream}{{/Type~/Metadata~/Subtype~/XML}{\hyxmp@xml}}%
    % reference in the Catalog:
    \pdfmanagement_add:nnx {Catalog} {Metadata}{\pdf_object_ref_last:}
 }

% A standard should be retrieved from the document settings.
\cs_new:Npn \__hypxmp_get_Astandard:w #1-#2#3#4\q_stop
 {
   \tl_if_eq:nnT{#1}{A}
    {
      \Hy@pdfatrue
      \tl_set:Nn \@pdfapart{#2}
      \tl_set:Nx \@pdfaconformance{#3}
    }
 }
\cs_new_protected:Npn \__hyxmp_get_metadata:
 {
  \exp_last_unbraced:Ne \__hypxmp_get_Astandard:w
    {\GetDocumentProperties{document/pdfstandard}}Z-ZZZ\q_stop
   \clist_map_inline:nn
    {
      % hyperxmp keys:
      ,pdfcopyright
      ,pdftype
      ,pdflicenseurl
      ,pdfauthortitle
      ,pdfcaptionwriter
      ,pdfmetalang
      %,pdfapart %document
      %,pdfaconformance %document
      ,pdfuapart %probably document too but later ...
      ,pdfxstandard
      ,pdfsource
      ,pdfdocumentid
      ,pdfinstanceid
      ,pdfversionid
      ,pdfrendition
      ,pdfpublication
      ,pdfpubtype
      ,pdfbytes
      ,pdfnumpages
      ,pdfissn
      ,pdfeissn
      ,pdfisbn
      ,pdfbookedition
      ,pdfpublisher
      ,pdfvolumenum
      ,pdfissuenum
      ,pdfpagerange
      ,pdfdoi
      ,pdfurl
      ,pdfidentifier
      ,pdfsubtitle
      ,pdfpubstatus
      ,pdfcontactaddress
      ,pdfcontactcity
      ,pdfcontactregion
      ,pdfcontactpostcode
      ,pdfcontactcountry
      ,pdfcontactphone
      ,pdfcontactemail
      ,pdfcontacturl
      ,pdfdate
    %hyperref, needs probably special handling
   %   ,pdftitle   %see below
   %   ,pdfsubject %see below
      ,pdfkeywords
      ,pdfproducer
    }
    {
     \tl_if_exist:cF{@##1}{\tl_new:c{@##1}}
     \tl_set:cx {@##1}{\GetDocumentProperties{hyperref/##1}}
    }

    % pdfauthor, this is only a work around for simple author
    % TODO needs improvement
    \exp_args:NNe
    \pdfstringdef\@pdfauthor{\GetDocumentProperties{hyperref/pdfauthor}}
    \cs_set_eq:NN\hyxmp@pdfauthor\@pdfauthor
    \exp_args:NNe
    \pdfstringdef\@pdfsubject{\GetDocumentProperties{hyperref/pdfsubject}}
    \cs_set_eq:NN\hyxmp@pdfsubject\@pdfsubject
    \exp_args:NNe
    \pdfstringdef\@pdftitle{\GetDocumentProperties{hyperref/pdftitle}}
    \cs_set_eq:NN\hyxmp@pdftitle\@pdftitle
    % pdflang,
    \tl_if_exist:cF{@pdflang}{\tl_new:c{@pdflang}}
    \tl_set:cx {@pdflang}{\GetDocumentProperties{document/lang}}
  }

% we need to provide a few commands so that hyperxmp stops to overwrite them
% in \AtEndPreamble
\AddToHook{begindocument/before}[pdfmanagement/firstaid/hyperxmp]{%
 \def\@pdfauthor{Author}\def\@pdftitle {Title}}

\DeclareHookRule{begindocument/before}{pdfmanagement/firstaid/hyperxmp}{before}{hyperxmp}

\AddToHook{enddocument}[pdfmanagement-firstaid]{\__hyxmp_get_metadata:}

\DeclareHookRule{enddocument}{pdfmanagement-firstaid}{before}{hyperxmp}


\endinput