Document: Round dimensions properly in getPageDimensions (#8170)

* Geom:transformByScale:
  * Apply the right scaling factor to the y axis
  * Round in a more sensible fashion (àla fz_round_rect, since we pretty much exclusively use it in a similar fashion).
* Bump base (https://github.com/koreader/koreader-base/pull/1407)
pull/8174/head
NiLuJe 3 years ago committed by GitHub
parent 1a127633c2
commit acbf4b7a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 2a526000d9c0a92e4951caef9202d0f12e8b343b
Subproject commit ac9a8757de78769150c3ac084170cb6744183435

@ -256,7 +256,8 @@ function Document:getPageDimensions(pageno, zoom, rotation)
-- switch orientation
native_dimen.w, native_dimen.h = native_dimen.h, native_dimen.w
end
native_dimen:scaleBy(zoom)
-- Apply the zoom factor, and round to integer in a sensible manner
native_dimen:transformByScale(zoom)
return native_dimen
end
@ -305,6 +306,7 @@ function Document:getUsedBBoxDimensions(pageno, zoom, rotation)
w = bbox.x1 - bbox.x0,
h = bbox.y1 - bbox.y0,
}
--- @note: Should we round this regardless of zoom?
if zoom ~= 1 then
ubbox_dimen:transformByScale(zoom)
end

@ -81,7 +81,7 @@ function Geom:offsetTo(x, y)
end
--[[--
Scales rectangle (grow to bottom and to the right) or dimension
Scales rectangle (top-left corner is rounded down, bottom-right corner is rounded up) or dimension
If a single factor is given, it is applied to both width and height
@ -89,20 +89,22 @@ If a single factor is given, it is applied to both width and height
@int zy scale for y axis
]]
function Geom:scaleBy(zx, zy)
self.w = Math.round(self.w * zx)
self.h = Math.round(self.h * (zy or zx))
self.w = math.ceil(self.w * zx - 0.001)
self.h = math.ceil(self.h * (zy or zx) - 0.001)
return self
end
--[[--
This method also takes care of x and y on top of @{Geom:scaleBy}
This method also takes care of x and y on top of @{Geom:scaleBy},
c.f., fz_round_rect in MµPDF,
<https://github.com/ArtifexSoftware/mupdf/blob/d00de0e96a4a5ec90ffc30837d40cd624a6a89e0/source/fitz/geometry.c#L400-L416>
@int zx scale for x axis
@int zy scale for y axis
]]
function Geom:transformByScale(zx, zy)
self.x = Math.round(self.x * zx)
self.y = Math.round(self.y * (zx or zy))
self.x = math.floor(self.x * zx + 0.001)
self.y = math.floor(self.y * (zy or zx) + 0.001)
self:scaleBy(zx, zy)
end

@ -130,7 +130,7 @@ describe("ReaderLink module", function()
x = 0, y = 694,
h = 106, w = 566,
},
zoom = 0.9501187648456056456,
zoom = 0.95032191328269044472,
},
{
gamma = 1,
@ -145,7 +145,7 @@ describe("ReaderLink module", function()
h = 686, w = 566,
x = 0, y = 0,
},
zoom = 0.9501187648456056456,
zoom = 0.95032191328269044472,
},
}
-- disable footer

@ -90,7 +90,7 @@ describe("Readerview module", function()
},
}
assert.are.same(saved_ctx, ctx)
assert.is.near(0.95011876484561, zoom, 0.0001)
assert.is.near(0.95024316487116200491, zoom, 0.0001)
assert.is.same(view.state.page, 1)
assert.is.same(view.visible_area.x, 0)
@ -144,7 +144,7 @@ describe("Readerview module", function()
}
assert.are.same(saved_ctx, ctx)
assert.is.near(0.95011876484561, zoom, 0.0001)
assert.is.near(0.95024316487116200491, zoom, 0.0001)
assert.is.same(view.state.page, 1)
assert.is.same(view.visible_area.x, 0)

Loading…
Cancel
Save