From 279a85109de091df32665fa854c6764a19ab21d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Wed, 3 Jun 2020 23:59:59 +0200 Subject: [PATCH] Better handle duplicate destinations --- luametalatex-back-pdf.lua | 6 +++++- luametalatex-pdf.lua | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/luametalatex-back-pdf.lua b/luametalatex-back-pdf.lua index f1cfec5..a4e490c 100644 --- a/luametalatex-back-pdf.lua +++ b/luametalatex-back-pdf.lua @@ -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) diff --git a/luametalatex-pdf.lua b/luametalatex-pdf.lua index 1b35f6e..bb067cc 100644 --- a/luametalatex-pdf.lua +++ b/luametalatex-pdf.lua @@ -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)