From acbf4b7a8c60326220ec52c3edf93ea7ead4ba2a Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 2 Sep 2021 23:50:10 +0200 Subject: [PATCH] Document: Round dimensions properly in getPageDimensions (#8170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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) --- base | 2 +- frontend/document/document.lua | 4 +++- frontend/ui/geometry.lua | 14 ++++++++------ spec/unit/readerlink_spec.lua | 4 ++-- spec/unit/readerview_spec.lua | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/base b/base index 2a526000d..ac9a8757d 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 2a526000d9c0a92e4951caef9202d0f12e8b343b +Subproject commit ac9a8757de78769150c3ac084170cb6744183435 diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 2d673eb97..44a8c0d1f 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -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 diff --git a/frontend/ui/geometry.lua b/frontend/ui/geometry.lua index 5037b9303..d6e929c26 100644 --- a/frontend/ui/geometry.lua +++ b/frontend/ui/geometry.lua @@ -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, + @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 diff --git a/spec/unit/readerlink_spec.lua b/spec/unit/readerlink_spec.lua index 98786961d..e94e0fca8 100644 --- a/spec/unit/readerlink_spec.lua +++ b/spec/unit/readerlink_spec.lua @@ -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 diff --git a/spec/unit/readerview_spec.lua b/spec/unit/readerview_spec.lua index bc06153a8..52aca89c1 100644 --- a/spec/unit/readerview_spec.lua +++ b/spec/unit/readerview_spec.lua @@ -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)