Debian Codegraph @

texmf-dist/tex/latex/pdfmanagement/l3backend-pdf.lua

raw
1 --
2 -- This is file `l3backend-pdf.lua',
3 -- generated with the docstrip utility.
4 --
5 -- The original source files were:
6 --
7 -- l3backend-pdfmanagement.dtx (with options: `lua')
8 --
9 -- Copyright (C) 2019-2026 The LaTeX Project
10 --
11 -- It may be distributed and/or modified under the conditions of
12 -- the LaTeX Project Public License (LPPL), either version 1.3c of
13 -- this license or (at your option) any later version. The latest
14 -- version of this license is in the file:
15 --
16 -- https://www.latex-project.org/lppl.txt
17 --
18 -- This file is part of the "LaTeX PDF management bundle" (The Work in LPPL)
19 -- and all files in that bundle must be distributed together.
20 --
21 -- File: l3backend-pdfmanagement.dtx
22
23
24
25 ltx= ltx or {}
26 ltx.__pdf = ltx.__pdf or {}
27 ltx.__pdf.Page = ltx.__pdf.Page or {}
28 ltx.__pdf.Page.dflt = ltx.__pdf.Page.dflt or {}
29 ltx.__pdf.Page.Resources = ltx.__pdf.Resources or {}
30 ltx.__pdf.Page.Resources.Properties = ltx.__pdf.Page.Resources.Properties or {}
31 ltx.__pdf.Page.Resources.List={"ExtGState","ColorSpace","Pattern","Shading"}
32 ltx.__pdf.object = ltx.__pdf.object or {}
33
34 ltx.pdf= ltx.pdf or {} -- for "public" functions
35
36 local __pdf = ltx.__pdf
37 local pdf = pdf
38
39 local function __pdf_backend_Page_gput (name,value)
40 __pdf.Page.dflt[name]=value
41 end
42
43 local function __pdf_backend_Page_gremove (name)
44 __pdf.Page.dflt[name]=nil
45 end
46
47 local function __pdf_backend_Page_gclear ()
48 __pdf.Page.dflt={}
49 end
50
51 local function __pdf_backend_ThisPage_gput (page,name,value)
52 __pdf.Page[page] = __pdf.Page[page] or {}
53 __pdf.Page[page][name]=value
54 end
55
56 local function __pdf_backend_ThisPage_gpush (page)
57 local token=""
58 local t = {}
59 local tkeys= {}
60 for name,value in pairs(__pdf.Page.dflt) do
61 t[name]=value
62 end
63 if __pdf.Page[page] then
64 for name,value in pairs(__pdf.Page[page]) do
65 t[name] = value
66 end
67 end
68 -- sort the table to get reliable test files.
69 for name,value in pairs(t) do
70 table.insert(tkeys,name)
71 end
72 table.sort(tkeys)
73 for _,name in ipairs(tkeys) do
74 token = token .. "/"..name.." "..t[name]
75 end
76 return token
77 end
78
79 function ltx.__pdf.backend_ThisPage_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
80 __pdf_backend_ThisPage_gput (page,name,value)
81 end
82
83 function ltx.__pdf.backend_ThisPage_gpush (page)
84 pdf.setpageattributes(__pdf_backend_ThisPage_gpush (page))
85 end
86
87 function ltx.__pdf.backend_Page_gput (name,value)
88 __pdf_backend_Page_gput (name,value)
89 end
90
91 function ltx.__pdf.backend_Page_gremove (name)
92 __pdf_backend_Page_gremove (name)
93 end
94
95 function ltx.__pdf.backend_Page_gclear ()
96 __pdf_backend_Page_gclear ()
97 end
98
99 local Properties = ltx.__pdf.Page.Resources.Properties
100 local ResourceList= ltx.__pdf.Page.Resources.List
101 local function __pdf_backend_PageResources_gpush (page)
102 local token=""
103 if Properties[page] then
104 -- we sort the table, so that the pdf test works
105 local t = {}
106 for name,value in pairs (Properties[page]) do
107 table.insert (t,name)
108 end
109 table.sort (t)
110 for _,name in ipairs(t) do
111 token = token .. "/"..name.." ".. Properties[page][name]
112 end
113 token = "/Properties <<"..token..">>"
114 end
115 for i,name in ipairs(ResourceList) do
116 if ltx.__pdf.Page.Resources[name] then
117 token = token .. "/"..name.." "..ltx.pdf.object_ref("__pdf/Page/Resources/"..name)
118 end
119 end
120 return token
121 end
122
123 -- the function is public, as I probably need it in tagpdf too ...
124 function ltx.pdf.Page_Resources_Properties_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
125 Properties[page] = Properties[page] or {}
126 Properties[page][name]=value
127 pdf.setpageresources(__pdf_backend_PageResources_gpush (page))
128 end
129
130 function ltx.pdf.Page_Resources_gpush(page)
131 pdf.setpageresources(__pdf_backend_PageResources_gpush (page))
132 end
133
134 function ltx.pdf.object_ref (objname)
135 if ltx.__pdf.object[objname] then
136 local ref= ltx.__pdf.object[objname]
137 return ref
138 else
139 return "false"
140 end
141 end
142 --
143 -- End of File `l3backend-pdf.lua'.