From 049e63c70bb58cf5059e3f54c0b3aa565dc44bf7 Mon Sep 17 00:00:00 2001 From: Euphoriyy <96319862+Euphoriyy@users.noreply.github.com> Date: Tue, 17 Mar 2026 04:31:21 -0400 Subject: [PATCH] kopt: fix Invert Document regression with Reflow/Auto Straighten (#15123) Due to changes to renderOptimizedPage(...) made by #15067, which was merged after #14954 was made, a regression was introduced that causes instability and even crashes on mobile devices and e-readers when Invert Document is enabled along with Reflow or Auto Straighten. This PR fixes the regression and simplifies the drawContextPage(...) method. --- frontend/document/koptinterface.lua | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index bd68d7fd5..69beef781 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -597,28 +597,13 @@ Inherited from common document interface. --]] function KoptInterface:drawContextPage(doc, target, x, y, rect, pageno, zoom, rotation, nightmode_invert) local tile = self:renderPage(doc, pageno, rect, zoom, rotation, 1.0) - local offs_x = rect.x - tile.excerpt.x - local offs_y = rect.y - tile.excerpt.y + target:blitFrom(tile.bb, + x, y, + rect.x - tile.excerpt.x, + rect.y - tile.excerpt.y, + rect.w, rect.h) if nightmode_invert then - if doc.configurable.page_opt == 1 then - -- Dewatermark enabled: draw tile, then invert the drawn area - target:blitFrom(tile.bb, - x, y, - offs_x, offs_y, - rect.w, rect.h) - target:invertRect(x, y, rect.w, rect.h) - else - -- Dewatermark disabled: invert tile directly - target:invertblitFrom(tile.bb, - x, y, - offs_x, offs_y, - rect.w, rect.h) - end - else - target:blitFrom(tile.bb, - x, y, - offs_x, offs_y, - rect.w, rect.h) + target:invertRect(x, y, rect.w, rect.h) end end