Skip to content

Commit

Permalink
mupdf.lua: update frontend pboxes with MuPDF adjusted ones (#1388)
Browse files Browse the repository at this point in the history
MuPDF may slightly update/round annotation boxes coordinates,
and we need frontend to have them consistent for it to be
able to delete/update annotations.
  • Loading branch information
poire-z committed Jul 19, 2021
1 parent 0258347 commit 13f0d3d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ffi/mupdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ function page_mt.__index:addMarkupAnnotation(points, n, type)

ok = W.mupdf_pdf_set_markup_appearance(context(), doc, annot, color, alpha, line_thickness, line_height)
if ok == nil then merror("could not set markup appearance") end

-- Fetch back MuPDF's stored coordinates of all quadpoints, as they may have been modified/rounded
-- (we need the exact ones that were saved if we want to be able to find them for deletion/update)
for i = 0, n-1 do
W.mupdf_pdf_annot_quad_point(context(), annot, i, points+i*8)
end
end

function page_mt.__index:deleteMarkupAnnotation(annot)
Expand All @@ -713,8 +719,12 @@ function page_mt.__index:getMarkupAnnotation(points, n)
for i = 0, n-1 do
W.mupdf_pdf_annot_quad_point(context(), annot, i, quadpoint)
for k = 0, 7 do
if points[i*8 + k] ~= quadpoint[k] then match = false end
if points[i*8 + k] ~= quadpoint[k] then
match = false
break
end
end
if not match then break end
end
if match then return annot end
end
Expand Down

0 comments on commit 13f0d3d

Please sign in to comment.