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

View File

@ -7,6 +7,13 @@ local pairs = pairs
local setmetatable = setmetatable
local assigned = {}
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)
if not num then num = pdf:getobj() end
if pdf[num] ~= assigned then
@ -117,6 +124,7 @@ local pdfmeta = {
delayed = delayed,
delayedstream = delayedstream,
reference = reference,
written = written,
}
pdfmeta.__index = pdfmeta
local function open(filename)