summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pdfmanagement-testphase/l3backend-testphase.lua
blob: 8d8f5e3c635013885a119663f0e6b3026f5b9bb7 (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
-- 
--  This is file `l3backend-testphase.lua',
--  generated with the docstrip utility.
-- 
--  The original source files were:
-- 
--  l3backend-testphase.dtx  (with options: `lua')
--  
--  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



ltx= ltx or {}
ltx.__pdf      = ltx.__pdf or {}
ltx.__pdf.Page = ltx.__pdf.Page or {}
ltx.__pdf.Page.dflt = ltx.__pdf.Page.dflt or {}
ltx.__pdf.Page.Resources = ltx.__pdf.Resources or {}
ltx.__pdf.Page.Resources.Properties = ltx.__pdf.Page.Resources.Properties or {}
ltx.__pdf.Page.Resources.List={"ExtGState","ColorSpace","Pattern","Shading"}
ltx.__pdf.object = ltx.__pdf.object or {}

ltx.pdf= ltx.pdf or {} -- for "public" functions

local __pdf = ltx.__pdf
local pdf = pdf

local function __pdf_backend_Page_gput (name,value)
 __pdf.Page.dflt[name]=value
end

local function __pdf_backend_Page_gremove (name)
 __pdf.Page.dflt[name]=nil
end

local function __pdf_backend_Page_gclear ()
 __pdf.Page.dflt={}
end

local function __pdf_backend_ThisPage_gput (page,name,value)
 __pdf.Page[page] = __pdf.Page[page] or {}
 __pdf.Page[page][name]=value
end

local function __pdf_backend_ThisPage_gpush (page)
 local token=""
 local t = {}
 local tkeys= {}
 for name,value in pairs(__pdf.Page.dflt) do
   t[name]=value
 end
 if __pdf.Page[page] then
  for name,value in pairs(__pdf.Page[page]) do
   t[name] = value
  end
 end
 -- sort the table to get reliable test files.
 for name,value in pairs(t) do
  table.insert(tkeys,name)
 end
 table.sort(tkeys)
 for _,name in ipairs(tkeys) do
   token = token .. "/"..name.." "..t[name]
 end
 return token
end

function ltx.__pdf.backend_ThisPage_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
 __pdf_backend_ThisPage_gput (page,name,value)
end

function ltx.__pdf.backend_ThisPage_gpush (page)
  pdf.setpageattributes(__pdf_backend_ThisPage_gpush (page))
end

function ltx.__pdf.backend_Page_gput (name,value)
  __pdf_backend_Page_gput (name,value)
end

function ltx.__pdf.backend_Page_gremove (name)
  __pdf_backend_Page_gremove (name)
end

function ltx.__pdf.backend_Page_gclear ()
  __pdf_backend_Page_gclear ()
end

local Properties  = ltx.__pdf.Page.Resources.Properties
local ResourceList= ltx.__pdf.Page.Resources.List
local function __pdf_backend_PageResources_gpush (page)
 local token=""
 if Properties[page] then
-- we sort the table, so that the pdf test works
  local t = {}
  for name,value in pairs  (Properties[page]) do
   table.insert (t,name)
  end
  table.sort (t)
  for _,name in ipairs(t) do
   token = token .. "/"..name.." ".. Properties[page][name]
  end
  token = "/Properties <<"..token..">>"
 end
  for i,name in ipairs(ResourceList) do
   if ltx.__pdf.Page.Resources[name] then
   token = token .. "/"..name.." "..ltx.pdf.object_ref("__pdf/Page/Resources/"..name)
   end
  end
 return token
end

-- the function is public, as I probably need it in tagpdf too ...
function ltx.pdf.Page_Resources_Properties_gput (page,name,value) -- tex.count["g_shipout_readonly_int"]
 Properties[page] = Properties[page] or {}
 Properties[page][name]=value
 pdf.setpageresources(__pdf_backend_PageResources_gpush (page))
end

function ltx.pdf.Page_Resources_gpush(page)
 pdf.setpageresources(__pdf_backend_PageResources_gpush (page))
end

function ltx.pdf.object_ref (objname)
 if ltx.__pdf.object[objname] then
  local ref= ltx.__pdf.object[objname]
  return ref
 else
  return "false"
 end
end
-- 
--  End of File `l3backend-testphase.lua'.