Skip to content

Commit

Permalink
MµPDF: Don't accumulate rounding errors when computing page dimensions (
Browse files Browse the repository at this point in the history
#1407)

* Do *NOT* round the dimensions in getSize

This is a weird MµPDF internal @ 72dpi representation, not a final
dimension.

We use it to compute and apply our own scale factor, so if we lose
precision here, we can end up with severe rounding errors with large
scale factors.

And, for some mysterious reason, for image files, scale factors can be
really large, even when the files actually match the target screen size
exactly :?.
  • Loading branch information
NiLuJe committed Sep 2, 2021
1 parent 2a52600 commit ac9a875
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ffi/mupdf.lua
Expand Up @@ -370,9 +370,20 @@ function page_mt.__index:getSize(draw_context)
M.fz_bound_page(context(), self.page, bounds)
M.fz_transform_rect(bounds, ctm)
M.fz_round_rect(bbox, bounds)
-- NOTE: fz_bound_page returns an internal representation computed @ 72dpi...
-- It is often superbly mysterious, even for images,
-- so we do *NOT* want to round it right now,
-- as it would introduce rounding errors much too early in the pipeline...
-- NOTE: ReaderZooming uses it to compute the scale factor, where accuracy matters!
-- NOTE: This is also used in conjunction with getUsedBBox,
-- which also returns precise, floating point rectangles!
--[[
M.fz_round_rect(bbox, bounds)
return bbox[0].x1-bbox[0].x0, bbox[0].y1-bbox[0].y0
--]]
return bounds[0].x1 - bounds[0].x0, bounds[0].y1 - bounds[0].y0
end
--[[
Expand Down

0 comments on commit ac9a875

Please sign in to comment.