Better handle duplicate destinations

This commit is contained in:
Marcel Krüger 2020-06-03 23:59:59 +02:00
parent f20e543cce
commit 279a85109d
2 changed files with 13 additions and 1 deletions

View File

@ -142,8 +142,12 @@ local function do_dest(prop, p, n, x, y)
elseif dest_type == "fitbv" then elseif dest_type == "fitbv" then
data = string.format("[%i 0 R/FitBV %.5f]", cur_page, sp2bp(x)) data = string.format("[%i 0 R/FitBV %.5f]", cur_page, sp2bp(x))
end end
if pfile:written(dests[id]) then
texio.write_nl(string.format("Duplicate destination %q", id))
else
dests[id] = pfile:indirect(dests[id], data) dests[id] = pfile:indirect(dests[id], data)
end end
end
local function do_refobj(prop, p, n, x, y) local function do_refobj(prop, p, n, x, y)
pfile:reference(prop.obj) pfile:reference(prop.obj)
end end

View File

@ -7,6 +7,13 @@ local pairs = pairs
local setmetatable = setmetatable local setmetatable = setmetatable
local assigned = {} local assigned = {}
local delayed = {} local delayed = {}
-- slightly tricky interface: No/nil return means that the objects content
-- isn't known yet, while false indicates a delayed object.
local function written(pdf, num)
num = pdf[num]
if not num or num == assigned then return end
return num ~= delayed
end
local function stream(pdf, num, dict, content, isfile) local function stream(pdf, num, dict, content, isfile)
if not num then num = pdf:getobj() end if not num then num = pdf:getobj() end
if pdf[num] ~= assigned then if pdf[num] ~= assigned then
@ -117,6 +124,7 @@ local pdfmeta = {
delayed = delayed, delayed = delayed,
delayedstream = delayedstream, delayedstream = delayedstream,
reference = reference, reference = reference,
written = written,
} }
pdfmeta.__index = pdfmeta pdfmeta.__index = pdfmeta
local function open(filename) local function open(filename)