Browse Source

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)
reviewable/pr8174/r1
NiLuJe 1 month ago
committed by GitHub
parent
commit
acbf4b7a8c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 12 deletions
  1. +1
    -1
      base
  2. +3
    -1
      frontend/document/document.lua
  3. +8
    -6
      frontend/ui/geometry.lua
  4. +2
    -2
      spec/unit/readerlink_spec.lua
  5. +2
    -2
      spec/unit/readerview_spec.lua

+ 1
- 1
base

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

+ 3
- 1
frontend/document/document.lua View File

@ -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

+ 8
- 6
frontend/ui/geometry.lua View File

@ -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

+ 2
- 2
spec/unit/readerlink_spec.lua View File

@ -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

+ 2
- 2
spec/unit/readerview_spec.lua View File

@ -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