2014-10-30 19:42:18 +01:00
|
|
|
local Device = require("device")
|
2021-05-04 23:13:24 +02:00
|
|
|
local DocCache = require("document/doccache")
|
2013-10-18 22:38:07 +02:00
|
|
|
local Event = require("ui/event")
|
2019-08-05 18:38:10 +02:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2020-11-28 17:18:57 +01:00
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
2019-08-05 18:38:10 +02:00
|
|
|
local UIManager = require("ui/uimanager")
|
2016-12-29 00:10:38 -08:00
|
|
|
local logger = require("logger")
|
2013-10-18 22:38:07 +02:00
|
|
|
local _ = require("gettext")
|
2019-08-05 18:38:10 +02:00
|
|
|
local Input = Device.input
|
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
local T = require("ffi/util").template
|
2013-10-18 22:38:07 +02:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
local ReaderZooming = InputContainer:extend{
|
2014-03-13 21:52:43 +08:00
|
|
|
zoom = 1.0,
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
available_zoom_modes = { -- const
|
2020-11-28 17:18:57 +01:00
|
|
|
"page",
|
|
|
|
|
"pagewidth",
|
|
|
|
|
"pageheight",
|
|
|
|
|
"content",
|
|
|
|
|
"contentwidth",
|
|
|
|
|
"contentheight",
|
|
|
|
|
"columns",
|
|
|
|
|
"rows",
|
|
|
|
|
"manual",
|
|
|
|
|
},
|
2022-10-29 08:23:29 -04:00
|
|
|
zoom_mode_label = { -- const
|
|
|
|
|
page = _("page") .. " - " .. _("full"),
|
|
|
|
|
pagewidth = _("page") .. " - " .. _("width"),
|
|
|
|
|
pageheight = _("page") .. " - " .. _("height"),
|
|
|
|
|
content = _("content") .. " - " .. _("full"),
|
|
|
|
|
contentwidth = _("content") .. " - " .. _("width"),
|
|
|
|
|
contentheight = _("content") .. " - " .. _("height"),
|
|
|
|
|
columns = _("columns"),
|
|
|
|
|
rows = _("rows"),
|
|
|
|
|
manual = _("manual"),
|
|
|
|
|
},
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
zoom_genus_to_mode = { -- const
|
2021-03-30 18:47:52 +02:00
|
|
|
[4] = "page",
|
|
|
|
|
[3] = "content",
|
|
|
|
|
[2] = "columns",
|
|
|
|
|
[1] = "rows",
|
|
|
|
|
[0] = "manual",
|
|
|
|
|
},
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
zoom_mode_to_genus = { -- const
|
2021-06-01 12:08:12 +02:00
|
|
|
page = 4,
|
|
|
|
|
content = 3,
|
|
|
|
|
columns = 2,
|
|
|
|
|
rows = 1,
|
|
|
|
|
manual = 0,
|
|
|
|
|
},
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
zoom_type_to_mode = { -- const
|
2021-03-30 18:47:52 +02:00
|
|
|
[2] = "",
|
|
|
|
|
[1] = "width",
|
|
|
|
|
[0] = "height",
|
|
|
|
|
},
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
zoom_mode_to_type = { -- const
|
2021-06-01 12:08:12 +02:00
|
|
|
[""] = 2,
|
|
|
|
|
width = 1,
|
|
|
|
|
height = 0,
|
|
|
|
|
},
|
2014-03-13 21:52:43 +08:00
|
|
|
-- default to nil so we can trigger ZoomModeUpdate events on start up
|
|
|
|
|
zoom_mode = nil,
|
2019-08-05 18:38:10 +02:00
|
|
|
DEFAULT_ZOOM_MODE = "pagewidth",
|
2020-11-28 17:18:57 +01:00
|
|
|
-- for pan mode: fit to width/zoom_factor,
|
|
|
|
|
-- with overlap of zoom_overlap_h % (horizontally)
|
|
|
|
|
-- and zoom_overlap_v % (vertically).
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
kopt_zoom_factor = 1.5,
|
2020-11-28 17:18:57 +01:00
|
|
|
zoom_overlap_h = 40,
|
|
|
|
|
zoom_overlap_v = 40,
|
|
|
|
|
zoom_bottom_to_top = nil, -- true for bottom-to-top
|
|
|
|
|
zoom_direction_vertical = nil, -- true for column mode
|
2023-03-23 10:04:59 +02:00
|
|
|
zoom_direction_settings = { -- const
|
|
|
|
|
[7] = {right_to_left = false, zoom_bottom_to_top = false, zoom_direction_vertical = false},
|
|
|
|
|
[6] = {right_to_left = false, zoom_bottom_to_top = false, zoom_direction_vertical = true },
|
|
|
|
|
[5] = {right_to_left = false, zoom_bottom_to_top = true, zoom_direction_vertical = false},
|
|
|
|
|
[4] = {right_to_left = false, zoom_bottom_to_top = true, zoom_direction_vertical = true },
|
|
|
|
|
[3] = {right_to_left = true, zoom_bottom_to_top = true, zoom_direction_vertical = true },
|
|
|
|
|
[2] = {right_to_left = true, zoom_bottom_to_top = true, zoom_direction_vertical = false},
|
|
|
|
|
[1] = {right_to_left = true, zoom_bottom_to_top = false, zoom_direction_vertical = true },
|
|
|
|
|
[0] = {right_to_left = true, zoom_bottom_to_top = false, zoom_direction_vertical = false},
|
|
|
|
|
},
|
2014-03-13 21:52:43 +08:00
|
|
|
current_page = 1,
|
2019-08-05 18:38:10 +02:00
|
|
|
rotation = 0,
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 02:14:48 +02:00
|
|
|
paged_modes = { -- const
|
2019-08-05 18:38:10 +02:00
|
|
|
page = _("Zoom to fit page works best with page view."),
|
|
|
|
|
pageheight = _("Zoom to fit page height works best with page view."),
|
|
|
|
|
contentheight = _("Zoom to fit content height works best with page view."),
|
|
|
|
|
content = _("Zoom to fit content works best with page view."),
|
2020-12-11 18:28:55 +00:00
|
|
|
columns = _("Zoom to fit columns works best with page view."),
|
2019-08-05 18:38:10 +02:00
|
|
|
},
|
2012-05-19 00:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
2012-12-15 09:30:48 +08:00
|
|
|
function ReaderZooming:init()
|
2022-11-01 23:22:07 +01:00
|
|
|
self:registerKeyEvents()
|
2022-11-01 00:17:25 +01:00
|
|
|
end
|
|
|
|
|
|
2022-11-01 23:22:07 +01:00
|
|
|
function ReaderZooming:registerKeyEvents()
|
2014-03-13 21:52:43 +08:00
|
|
|
if Device:hasKeyboard() then
|
|
|
|
|
self.key_events = {
|
|
|
|
|
ZoomIn = {
|
|
|
|
|
{ "Shift", Input.group.PgFwd },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "Zoom",
|
|
|
|
|
args = "in",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomOut = {
|
|
|
|
|
{ "Shift", Input.group.PgBack },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "Zoom",
|
|
|
|
|
args = "out",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitPage = {
|
|
|
|
|
{ "A" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "page",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitContent = {
|
|
|
|
|
{ "Shift", "A" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "content",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitPageWidth = {
|
|
|
|
|
{ "S" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "pagewidth",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitContentWidth = {
|
|
|
|
|
{ "Shift", "S" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "contentwidth",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitPageHeight = {
|
|
|
|
|
{ "D" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "pageheight",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
|
|
|
|
ZoomToFitContentHeight = {
|
|
|
|
|
{ "Shift", "D" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "contentheight",
|
2014-03-13 21:52:43 +08:00
|
|
|
},
|
2020-11-28 17:18:57 +01:00
|
|
|
ZoomManual = {
|
|
|
|
|
{ "Shift", "M" },
|
2022-10-27 02:01:51 +02:00
|
|
|
event = "SetZoomMode",
|
|
|
|
|
args = "manual",
|
2018-02-10 14:58:39 +01:00
|
|
|
},
|
2014-03-13 21:52:43 +08:00
|
|
|
}
|
|
|
|
|
end
|
2012-12-15 09:30:48 +08:00
|
|
|
end
|
|
|
|
|
|
2022-11-01 00:17:25 +01:00
|
|
|
ReaderZooming.onPhysicalKeyboardConnected = ReaderZooming.registerKeyEvents
|
|
|
|
|
|
2021-06-01 12:08:12 +02:00
|
|
|
-- Conversions between genus/type combos and zoom_mode...
|
|
|
|
|
function ReaderZooming:mode_to_combo(zoom_mode)
|
|
|
|
|
if not zoom_mode then
|
|
|
|
|
zoom_mode = self.DEFAULT_ZOOM_MODE
|
|
|
|
|
end
|
2021-05-23 19:01:09 +02:00
|
|
|
|
|
|
|
|
-- Quick'n dirty zoom_mode to genus/type conversion...
|
|
|
|
|
local zgenus, ztype = zoom_mode:match("^(page)(%l*)$")
|
|
|
|
|
if not zgenus then
|
|
|
|
|
zgenus, ztype = zoom_mode:match("^(content)(%l*)$")
|
|
|
|
|
end
|
|
|
|
|
if not zgenus then
|
|
|
|
|
zgenus = zoom_mode
|
|
|
|
|
end
|
|
|
|
|
if not ztype then
|
|
|
|
|
ztype = ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local zoom_mode_genus = self.zoom_mode_to_genus[zgenus]
|
|
|
|
|
local zoom_mode_type = self.zoom_mode_to_type[ztype]
|
2021-06-01 12:08:12 +02:00
|
|
|
|
|
|
|
|
return zoom_mode_genus, zoom_mode_type
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:combo_to_mode(zoom_mode_genus, zoom_mode_type)
|
|
|
|
|
local default_genus, default_type = self:mode_to_combo(self.DEFAULT_ZOOM_MODE)
|
|
|
|
|
if not zoom_mode_genus then
|
|
|
|
|
zoom_mode_genus = default_genus
|
|
|
|
|
end
|
|
|
|
|
if not zoom_mode_type then
|
|
|
|
|
zoom_mode_type = default_type
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local zoom_genus = self.zoom_genus_to_mode[zoom_mode_genus]
|
|
|
|
|
local zoom_type = self.zoom_type_to_mode[zoom_mode_type]
|
|
|
|
|
|
|
|
|
|
local zoom_mode
|
|
|
|
|
if zoom_genus == "page" or zoom_genus == "content" then
|
|
|
|
|
zoom_mode = zoom_genus .. zoom_type
|
|
|
|
|
else
|
|
|
|
|
zoom_mode = zoom_genus
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return zoom_mode
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Update the genus/type Configurables given a specific zoom_mode...
|
|
|
|
|
function ReaderZooming:_updateConfigurable(zoom_mode)
|
|
|
|
|
-- We may need to poke at the Configurable directly, because ReaderConfig is instantiated before us,
|
|
|
|
|
-- so simply updating the DocSetting doesn't cut it...
|
|
|
|
|
-- Technically ought to be conditional,
|
|
|
|
|
-- because this is an optional engine feature (only if self.document.info.configurable is true).
|
|
|
|
|
-- But the rest of the code (as well as most other modules) assumes this is supported on all paged engines (it is).
|
|
|
|
|
local configurable = self.document.configurable
|
|
|
|
|
|
|
|
|
|
local zoom_mode_genus, zoom_mode_type = self:mode_to_combo(zoom_mode)
|
|
|
|
|
|
2021-05-23 19:01:09 +02:00
|
|
|
-- Configurable keys aren't prefixed, unlike the actual settings...
|
|
|
|
|
configurable.zoom_mode_genus = zoom_mode_genus
|
|
|
|
|
configurable.zoom_mode_type = zoom_mode_type
|
|
|
|
|
|
|
|
|
|
return zoom_mode_genus, zoom_mode_type
|
|
|
|
|
end
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
|
2021-05-23 19:01:09 +02:00
|
|
|
function ReaderZooming:onReadSettings(config)
|
2021-03-30 18:47:52 +02:00
|
|
|
-- If we have a composite zoom_mode stored, use that
|
2020-11-28 17:18:57 +01:00
|
|
|
local zoom_mode = config:readSetting("zoom_mode")
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
if zoom_mode then
|
|
|
|
|
-- Validate it first
|
2022-10-29 08:23:29 -04:00
|
|
|
zoom_mode = self.zoom_mode_label[zoom_mode] and zoom_mode or self.DEFAULT_ZOOM_MODE
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
|
|
|
|
|
-- Make sure the split genus & type match, to have an up-to-date ConfigDialog...
|
2021-05-23 19:01:09 +02:00
|
|
|
local zoom_mode_genus, zoom_mode_type = self:_updateConfigurable(zoom_mode)
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
config:saveSetting("kopt_zoom_mode_genus", zoom_mode_genus)
|
|
|
|
|
config:saveSetting("kopt_zoom_mode_type", zoom_mode_type)
|
|
|
|
|
else
|
|
|
|
|
-- Otherwise, build it from the split genus & type settings
|
2021-03-30 18:47:52 +02:00
|
|
|
local zoom_mode_genus = config:readSetting("kopt_zoom_mode_genus")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_mode_genus")
|
2024-03-13 20:15:10 -03:00
|
|
|
or 3 -- autocrop is default then pagewidth will be the default as well
|
2021-03-30 18:47:52 +02:00
|
|
|
local zoom_mode_type = config:readSetting("kopt_zoom_mode_type")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_mode_type")
|
2024-03-13 20:15:10 -03:00
|
|
|
zoom_mode = self:combo_to_mode(zoom_mode_genus, zoom_mode_type)
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
|
|
|
|
|
-- Validate it
|
2022-10-29 08:23:29 -04:00
|
|
|
zoom_mode = self.zoom_mode_label[zoom_mode] and zoom_mode or self.DEFAULT_ZOOM_MODE
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Import legacy zoom_factor settings
|
|
|
|
|
if config:has("zoom_factor") and config:hasNot("kopt_zoom_factor") then
|
|
|
|
|
config:saveSetting("kopt_zoom_factor", config:readSetting("zoom_factor"))
|
2021-05-23 19:01:09 +02:00
|
|
|
self.document.configurable.zoom_factor = config:readSetting("kopt_zoom_factor")
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
config:delSetting("zoom_factor")
|
|
|
|
|
elseif config:has("zoom_factor") and config:has("kopt_zoom_factor") then
|
|
|
|
|
config:delSetting("zoom_factor")
|
2021-03-30 18:47:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Don't stomp on normal_zoom_mode in ReaderKoptListener if we're reflowed...
|
|
|
|
|
local is_reflowed = config:has("kopt_text_wrap") and config:readSetting("kopt_text_wrap") == 1
|
|
|
|
|
|
|
|
|
|
self:setZoomMode(zoom_mode, true, is_reflowed) -- avoid informative message on load
|
2023-03-23 10:04:59 +02:00
|
|
|
|
|
|
|
|
self.kopt_zoom_factor = config:readSetting("kopt_zoom_factor")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_factor") or self.kopt_zoom_factor
|
|
|
|
|
self.zoom_overlap_h = config:readSetting("kopt_zoom_overlap_h")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_overlap_h") or self.zoom_overlap_h
|
|
|
|
|
self.zoom_overlap_v = config:readSetting("kopt_zoom_overlap_v")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_overlap_v") or self.zoom_overlap_v
|
|
|
|
|
|
|
|
|
|
-- update zoom direction parameters
|
2023-06-12 09:08:56 +03:00
|
|
|
local zoom_direction_setting = self.zoom_direction_settings[self.document.configurable.zoom_direction
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_direction") or 7]
|
2023-03-23 10:04:59 +02:00
|
|
|
self.zoom_bottom_to_top = zoom_direction_setting.zoom_bottom_to_top
|
|
|
|
|
self.zoom_direction_vertical = zoom_direction_setting.zoom_direction_vertical
|
2012-12-04 15:19:50 +08:00
|
|
|
end
|
|
|
|
|
|
2013-12-27 23:18:16 +08:00
|
|
|
function ReaderZooming:onSaveSettings()
|
2016-06-15 01:50:59 +08:00
|
|
|
self.ui.doc_settings:saveSetting("zoom_mode", self.orig_zoom_mode or self.zoom_mode)
|
2012-12-04 15:19:50 +08:00
|
|
|
end
|
|
|
|
|
|
2013-03-28 21:42:23 +08:00
|
|
|
function ReaderZooming:onSpread(arg, ges)
|
2014-03-13 21:52:43 +08:00
|
|
|
if ges.direction == "horizontal" then
|
|
|
|
|
self:genSetZoomModeCallBack("contentwidth")()
|
|
|
|
|
elseif ges.direction == "vertical" then
|
|
|
|
|
self:genSetZoomModeCallBack("contentheight")()
|
|
|
|
|
elseif ges.direction == "diagonal" then
|
|
|
|
|
self:genSetZoomModeCallBack("content")()
|
|
|
|
|
end
|
|
|
|
|
return true
|
2013-03-28 21:42:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onPinch(arg, ges)
|
2014-03-13 21:52:43 +08:00
|
|
|
if ges.direction == "diagonal" then
|
|
|
|
|
self:genSetZoomModeCallBack("page")()
|
|
|
|
|
elseif ges.direction == "horizontal" then
|
|
|
|
|
self:genSetZoomModeCallBack("pagewidth")()
|
|
|
|
|
elseif ges.direction == "vertical" then
|
|
|
|
|
self:genSetZoomModeCallBack("pageheight")()
|
|
|
|
|
end
|
|
|
|
|
return true
|
2013-03-28 21:42:23 +08:00
|
|
|
end
|
|
|
|
|
|
2014-01-02 11:08:06 +08:00
|
|
|
function ReaderZooming:onToggleFreeZoom(arg, ges)
|
2014-03-13 21:52:43 +08:00
|
|
|
if self.zoom_mode ~= "free" then
|
|
|
|
|
self.orig_zoom = self.zoom
|
|
|
|
|
local xpos, ypos
|
|
|
|
|
self.zoom, xpos, ypos = self:getRegionalZoomCenter(self.current_page, ges.pos)
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.info("zoom center", self.zoom, xpos, ypos)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "free"))
|
|
|
|
|
if xpos == nil or ypos == nil then
|
|
|
|
|
xpos = ges.pos.x * self.zoom / self.orig_zoom
|
|
|
|
|
ypos = ges.pos.y * self.zoom / self.orig_zoom
|
|
|
|
|
end
|
|
|
|
|
self.view:SetZoomCenter(xpos, ypos)
|
|
|
|
|
else
|
2016-06-15 01:50:59 +08:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "page"))
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2014-01-02 11:08:06 +08:00
|
|
|
end
|
|
|
|
|
|
2012-05-19 00:50:26 +02:00
|
|
|
function ReaderZooming:onSetDimensions(dimensions)
|
2014-03-13 21:52:43 +08:00
|
|
|
-- we were resized
|
|
|
|
|
self.dimen = dimensions
|
|
|
|
|
self:setZoom()
|
2012-05-19 00:50:26 +02:00
|
|
|
end
|
|
|
|
|
|
2013-10-11 23:39:57 +08:00
|
|
|
function ReaderZooming:onRestoreDimensions(dimensions)
|
2014-03-13 21:52:43 +08:00
|
|
|
-- we were resized
|
|
|
|
|
self.dimen = dimensions
|
|
|
|
|
self:setZoom()
|
2013-10-11 23:39:57 +08:00
|
|
|
end
|
|
|
|
|
|
Document: Do not cache panel-zoom tiles to disk and fix their caching and rendering (#12303)
* Use a dedicated cache hash for partial tiles from panel-zoom
* Never dump them to disk, as it confuses DocCache's crappy heuristics that rewinds the cache to skip over the hinted page to try to dump the on-screen page to disk.
* Apply the zoom factor in the exact same way as any other page rect (i.e., floor coordinates, ceil dimensions), and make sure said rect is actually a Geom so it doesn't break the cache hash, which relies on Geom's custom tostring method for rects. Said scaling method *also* belongs to the Geom class anyway.
* Handle such pre-scaled rects properly in renderPage, so as not to apply the zoom factor to the full page, which would attempt to create a gigantic buffer.
* And now that the rect is rendered properly in an appropriately-sized buffer, use the rendered tile as-is, no need to blit it to another (potentially way too large because of the above issue) blank BB.
* The zoom factor is now computed for a scale to best-fit (honoring `imageviewer_rotate_auto_for_best_fit`), ensuring the best efficiency (ImageViewer won't have to re-scale).
* Cache: Reduce the maximum item size to 50% of the cache, instead of 75%.
* Warn about the legacy ReaderRotation module, as it turned out to be horribly broken. The whole machinery (which is spread over *a lot* of various codepaths) is left as-is, peppered with notes & fixmes hinting at the problem. Thankfully, that's not how we actually handle rotation, so it was probably hardly ever used (which possibly explains why nobody ever noticed it breaking, and that nugget possibly dates back to the inception of the kpv -> ko refactor!). (#12309)
2024-08-08 04:52:24 +02:00
|
|
|
--- @note: From ReaderRotation, which is broken and disabled.
|
2012-05-19 00:50:26 +02:00
|
|
|
function ReaderZooming:onRotationUpdate(rotation)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.rotation = rotation
|
|
|
|
|
self:setZoom()
|
2012-05-19 00:50:26 +02:00
|
|
|
end
|
|
|
|
|
|
2012-12-04 15:19:50 +08:00
|
|
|
function ReaderZooming:onZoom(direction)
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.info("zoom", direction)
|
2014-03-13 21:52:43 +08:00
|
|
|
if direction == "in" then
|
|
|
|
|
self.zoom = self.zoom * 1.333333
|
|
|
|
|
elseif direction == "out" then
|
|
|
|
|
self.zoom = self.zoom * 0.75
|
|
|
|
|
end
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.info("zoom is now at", self.zoom)
|
2014-03-13 21:52:43 +08:00
|
|
|
self:onSetZoomMode("free")
|
|
|
|
|
self.view:onZoomUpdate(self.zoom)
|
|
|
|
|
return true
|
2012-12-04 15:19:50 +08:00
|
|
|
end
|
|
|
|
|
|
2021-01-11 18:14:19 +01:00
|
|
|
function ReaderZooming:onDefineZoom(btn, when_applied_callback)
|
2020-11-28 17:18:57 +01:00
|
|
|
local config = self.ui.document.configurable
|
2023-03-23 10:04:59 +02:00
|
|
|
local zoom_direction_setting = self.zoom_direction_settings[config.zoom_direction]
|
|
|
|
|
local settings = { -- unpack the table, work on a local copy
|
|
|
|
|
right_to_left = zoom_direction_setting.right_to_left,
|
|
|
|
|
zoom_bottom_to_top = zoom_direction_setting.zoom_bottom_to_top,
|
|
|
|
|
zoom_direction_vertical = zoom_direction_setting.zoom_direction_vertical,
|
|
|
|
|
}
|
2020-11-28 17:18:57 +01:00
|
|
|
local zoom_range_number = config.zoom_range_number
|
|
|
|
|
local zoom_factor = config.zoom_factor
|
2021-06-01 12:08:12 +02:00
|
|
|
local zoom_mode_genus = self.zoom_genus_to_mode[config.zoom_mode_genus]
|
|
|
|
|
local zoom_mode_type = self.zoom_type_to_mode[config.zoom_mode_type]
|
2020-11-28 17:18:57 +01:00
|
|
|
settings.zoom_overlap_h = config.zoom_overlap_h
|
|
|
|
|
settings.zoom_overlap_v = config.zoom_overlap_v
|
|
|
|
|
if btn == "set_zoom_overlap_h" then
|
|
|
|
|
self:_zoomPanChange(_("Set horizontal overlap"), "zoom_overlap_h")
|
|
|
|
|
settings.zoom_overlap_h = self.zoom_overlap_h
|
|
|
|
|
elseif btn == "set_zoom_overlap_v" then
|
|
|
|
|
self:_zoomPanChange(_("Set vertical overlap"), "zoom_overlap_v")
|
|
|
|
|
settings.zoom_overlap_v = self.zoom_overlap_v
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local zoom_mode
|
|
|
|
|
if zoom_mode_genus == "page" or zoom_mode_genus == "content" then
|
2021-06-01 12:08:12 +02:00
|
|
|
zoom_mode = zoom_mode_genus .. zoom_mode_type
|
2020-11-28 17:18:57 +01:00
|
|
|
else
|
|
|
|
|
zoom_mode = zoom_mode_genus
|
|
|
|
|
self.ui:handleEvent(Event:new("SetScrollMode", false))
|
|
|
|
|
end
|
2022-10-29 08:23:29 -04:00
|
|
|
zoom_mode = self.zoom_mode_label[zoom_mode] and zoom_mode or self.DEFAULT_ZOOM_MODE
|
2020-11-28 17:18:57 +01:00
|
|
|
settings.zoom_mode = zoom_mode
|
|
|
|
|
|
|
|
|
|
if settings.right_to_left then
|
|
|
|
|
if settings.zoom_bottom_to_top then
|
|
|
|
|
config.writing_direction = 2
|
|
|
|
|
else
|
|
|
|
|
config.writing_direction = 1
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
config.writing_direction = 0
|
|
|
|
|
end
|
|
|
|
|
settings.right_to_left = nil
|
|
|
|
|
|
|
|
|
|
if zoom_mode == "columns" or zoom_mode == "rows" then
|
|
|
|
|
if btn ~= "columns" and btn ~= "rows" then
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", settings, true))
|
2021-07-15 15:34:13 +02:00
|
|
|
config.zoom_factor = self:setNumberOf(
|
2020-11-28 17:18:57 +01:00
|
|
|
zoom_mode,
|
|
|
|
|
zoom_range_number,
|
|
|
|
|
zoom_mode == "columns" and settings.zoom_overlap_h or settings.zoom_overlap_v
|
|
|
|
|
)
|
2021-07-15 15:34:13 +02:00
|
|
|
settings.kopt_zoom_factor = config.zoom_factor
|
2020-11-28 17:18:57 +01:00
|
|
|
end
|
|
|
|
|
elseif zoom_mode == "manual" then
|
|
|
|
|
if btn == "manual" then
|
|
|
|
|
config.zoom_factor = self:getNumberOf("columns")
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
settings.kopt_zoom_factor = config.zoom_factor
|
|
|
|
|
-- We *want* a redraw the first time we swap to manual mode (like any other mode swap)
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", settings))
|
2020-11-28 17:18:57 +01:00
|
|
|
else
|
|
|
|
|
self:setNumberOf("columns", zoom_factor)
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
-- No redraw here, because setNumberOf already took care of it
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", settings, true))
|
2020-11-28 17:18:57 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
|
|
|
|
|
if btn == "columns" or btn == "rows" then
|
|
|
|
|
config.zoom_range_number = self:getNumberOf(
|
|
|
|
|
zoom_mode,
|
|
|
|
|
btn == "columns" and settings.zoom_overlap_h or settings.zoom_overlap_v
|
|
|
|
|
)
|
|
|
|
|
end
|
2021-01-11 18:14:19 +01:00
|
|
|
if when_applied_callback then
|
|
|
|
|
-- Provided when hide_on_apply, and ConfigDialog temporarily hidden:
|
|
|
|
|
-- show an InfoMessage with the values, and call when_applied_callback on dismiss
|
2020-11-28 17:18:57 +01:00
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
|
text = T(_([[Zoom set to:
|
|
|
|
|
|
|
|
|
|
mode: %1
|
|
|
|
|
number of columns: %2
|
|
|
|
|
number of rows: %4
|
|
|
|
|
horizontal overlap: %3 %
|
|
|
|
|
vertical overlap: %5 %
|
|
|
|
|
zoom factor: %6]]),
|
2022-10-29 08:23:29 -04:00
|
|
|
self.zoom_mode_label[zoom_mode],
|
2020-11-28 17:18:57 +01:00
|
|
|
("%.2f"):format(self:getNumberOf("columns", settings.zoom_overlap_h)),
|
|
|
|
|
settings.zoom_overlap_h,
|
|
|
|
|
("%.2f"):format(self:getNumberOf("rows", settings.zoom_overlap_v)),
|
|
|
|
|
settings.zoom_overlap_v,
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
("%.2f"):format(config.zoom_factor)),
|
2021-01-11 18:14:19 +01:00
|
|
|
dismiss_callback = when_applied_callback,
|
2020-11-28 17:18:57 +01:00
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-12-04 15:19:50 +08:00
|
|
|
function ReaderZooming:onSetZoomMode(new_mode)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.view.zoom_mode = new_mode
|
|
|
|
|
if self.zoom_mode ~= new_mode then
|
2016-12-29 00:10:38 -08:00
|
|
|
logger.info("setting zoom mode to", new_mode)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.ui:handleEvent(Event:new("ZoomModeUpdate", new_mode))
|
|
|
|
|
self.zoom_mode = new_mode
|
2021-05-23 19:01:09 +02:00
|
|
|
self:_updateConfigurable(new_mode)
|
2014-03-13 21:52:43 +08:00
|
|
|
self:setZoom()
|
2020-11-28 17:18:57 +01:00
|
|
|
if new_mode == "manual" then
|
|
|
|
|
self.ui:handleEvent(Event:new("SetScrollMode", false))
|
|
|
|
|
else
|
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates", new_mode))
|
|
|
|
|
end
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2012-12-04 15:19:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onPageUpdate(new_page_no)
|
2014-03-13 21:52:43 +08:00
|
|
|
self.current_page = new_page_no
|
|
|
|
|
self:setZoom()
|
2012-12-04 15:19:50 +08:00
|
|
|
end
|
|
|
|
|
|
2019-08-30 13:47:51 +02:00
|
|
|
function ReaderZooming:onReZoom(font_size)
|
|
|
|
|
if self.document.is_reflowable then
|
|
|
|
|
local reflowable_font_size = self.document:convertKoptToReflowableFontSize(font_size)
|
|
|
|
|
self.document:layoutDocument(reflowable_font_size)
|
|
|
|
|
end
|
2014-03-13 21:52:43 +08:00
|
|
|
self:setZoom()
|
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
|
|
|
return true
|
2013-04-14 15:16:42 +08:00
|
|
|
end
|
|
|
|
|
|
2016-06-15 01:50:59 +08:00
|
|
|
function ReaderZooming:onEnterFlippingMode(zoom_mode)
|
2020-06-28 15:41:24 +02:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
|
|
|
|
Spread = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "spread",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
Pinch = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "pinch",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ToggleFreeZoom = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "double_tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2016-06-15 01:50:59 +08:00
|
|
|
self.orig_zoom_mode = self.zoom_mode
|
|
|
|
|
if zoom_mode == "free" then
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "page"))
|
|
|
|
|
else
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onExitFlippingMode(zoom_mode)
|
2020-06-28 15:41:24 +02:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {}
|
|
|
|
|
end
|
2016-06-15 01:50:59 +08:00
|
|
|
self.orig_zoom_mode = nil
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
|
|
|
|
|
end
|
|
|
|
|
|
2013-03-10 14:21:32 +08:00
|
|
|
function ReaderZooming:getZoom(pageno)
|
2014-03-13 21:52:43 +08:00
|
|
|
-- check if we're in bbox mode and work on bbox if that's the case
|
2020-11-28 17:18:57 +01:00
|
|
|
local zoom
|
2014-10-15 22:01:39 +08:00
|
|
|
local page_size = self.ui.document:getNativePageDimensions(pageno)
|
2020-11-28 17:18:57 +01:00
|
|
|
if not (self.zoom_mode and self.zoom_mode:match("^page") or self.ui.document.configurable.trim_page == 3) then
|
2014-03-13 21:52:43 +08:00
|
|
|
local ubbox_dimen = self.ui.document:getUsedBBoxDimensions(pageno, 1)
|
2014-10-15 22:01:39 +08:00
|
|
|
-- if bbox is larger than the native page dimension render the full page
|
|
|
|
|
-- See discussion in koreader/koreader#970.
|
2024-02-16 21:26:21 -03:00
|
|
|
if ubbox_dimen.w <= page_size.w and ubbox_dimen.h <= page_size.h then
|
2014-10-15 22:01:39 +08:00
|
|
|
page_size = ubbox_dimen
|
|
|
|
|
self.view:onBBoxUpdate(ubbox_dimen)
|
|
|
|
|
else
|
|
|
|
|
self.view:onBBoxUpdate(nil)
|
|
|
|
|
end
|
2014-03-13 21:52:43 +08:00
|
|
|
else
|
|
|
|
|
-- otherwise, operate on full page
|
|
|
|
|
self.view:onBBoxUpdate(nil)
|
|
|
|
|
end
|
|
|
|
|
-- calculate zoom value:
|
2016-06-09 10:22:09 -07:00
|
|
|
local zoom_w = self.dimen.w
|
|
|
|
|
local zoom_h = self.dimen.h
|
Another round of ReaderFooter fixes (#6830)
* When auto_refresh_time is enabled, don't actually refresh anything when the footer is hidden.
* Fix a bunch of state tracking related to height computations, meaning `getHeight()` is now actually accurate, always, and we don't need shitty workarounds anymore.
* `footer_container.dimen.h` *includes* the progress bar, so, never reset it to 0 unless the progress bar is disabled (some `settings.progress_bar_position` codepaths were mistakenly doing just that).
* More aggressively set/reset `footer_text.height` (not sure this one makes much of a difference, and/or if it's actually useful at all, but, the tracking was already there, but hella inconsistent, so, just fix it).
* Honor `settings.reclaim_height` in other bits of code that were only checking `footer_visible` to figure out the visible page area.
* Ask ReaderView to update the `visible_area` *now* when toggling the footer's visibility (for ReaderPaging).
2020-10-27 16:48:34 +01:00
|
|
|
if self.ui.view.footer_visible and not self.ui.view.footer.settings.reclaim_height then
|
2016-11-02 01:38:52 -07:00
|
|
|
zoom_h = zoom_h - self.ui.view.footer:getHeight()
|
2016-06-09 10:22:09 -07:00
|
|
|
end
|
|
|
|
|
if self.rotation % 180 == 0 then
|
|
|
|
|
-- No rotation or rotated by 180 degrees
|
|
|
|
|
zoom_w = zoom_w / page_size.w
|
|
|
|
|
zoom_h = zoom_h / page_size.h
|
|
|
|
|
else
|
2014-03-13 21:52:43 +08:00
|
|
|
-- rotated by 90 or 270 degrees
|
2016-06-09 10:22:09 -07:00
|
|
|
zoom_w = zoom_w / page_size.h
|
|
|
|
|
zoom_h = zoom_h / page_size.w
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
|
|
|
|
if self.zoom_mode == "content" or self.zoom_mode == "page" then
|
|
|
|
|
if zoom_w < zoom_h then
|
|
|
|
|
zoom = zoom_w
|
|
|
|
|
else
|
|
|
|
|
zoom = zoom_h
|
|
|
|
|
end
|
|
|
|
|
elseif self.zoom_mode == "contentwidth" or self.zoom_mode == "pagewidth" then
|
|
|
|
|
zoom = zoom_w
|
|
|
|
|
elseif self.zoom_mode == "contentheight" or self.zoom_mode == "pageheight" then
|
|
|
|
|
zoom = zoom_h
|
|
|
|
|
elseif self.zoom_mode == "free" then
|
|
|
|
|
zoom = self.zoom
|
2020-11-28 17:18:57 +01:00
|
|
|
else
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
local zoom_factor = self.ui.doc_settings:readSetting("kopt_zoom_factor")
|
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_factor")
|
|
|
|
|
or self.kopt_zoom_factor
|
2020-11-28 17:18:57 +01:00
|
|
|
zoom = zoom_w * zoom_factor
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2021-05-04 23:13:24 +02:00
|
|
|
if zoom and zoom > 10 and not DocCache:willAccept(zoom * (self.dimen.w * self.dimen.h + 512)) then
|
2019-02-21 11:38:19 +01:00
|
|
|
logger.dbg("zoom too large, adjusting")
|
2021-05-04 23:13:24 +02:00
|
|
|
while not DocCache:willAccept(zoom * (self.dimen.w * self.dimen.h + 512)) do
|
2019-02-21 11:38:19 +01:00
|
|
|
if zoom > 100 then
|
|
|
|
|
zoom = zoom - 50
|
|
|
|
|
elseif zoom > 10 then
|
|
|
|
|
zoom = zoom - 5
|
|
|
|
|
elseif zoom > 1 then
|
|
|
|
|
zoom = zoom - 0.5
|
|
|
|
|
elseif zoom > 0.1 then
|
|
|
|
|
zoom = zoom - 0.05
|
|
|
|
|
else
|
|
|
|
|
zoom = zoom - 0.005
|
|
|
|
|
end
|
|
|
|
|
logger.dbg("new zoom: "..zoom)
|
|
|
|
|
|
|
|
|
|
if zoom < 0 then return 0 end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-11-28 17:18:57 +01:00
|
|
|
return zoom, zoom_w, zoom_h
|
2013-03-10 14:21:32 +08:00
|
|
|
end
|
|
|
|
|
|
2014-01-02 11:08:06 +08:00
|
|
|
function ReaderZooming:getRegionalZoomCenter(pageno, pos)
|
2014-03-13 21:52:43 +08:00
|
|
|
local p_pos = self.view:getSinglePagePosition(pos)
|
|
|
|
|
local page_size = self.ui.document:getNativePageDimensions(pageno)
|
2016-06-15 01:50:59 +08:00
|
|
|
local pos_x = p_pos.x / page_size.w
|
|
|
|
|
local pos_y = p_pos.y / page_size.h
|
|
|
|
|
local block = self.ui.document:getPageBlock(pageno, pos_x, pos_y)
|
2014-03-13 21:52:43 +08:00
|
|
|
local margin = self.ui.document.configurable.page_margin * Screen:getDPI()
|
2016-06-15 01:50:59 +08:00
|
|
|
if block then
|
|
|
|
|
local zoom = self.dimen.w / page_size.w / (block.x1 - block.x0)
|
|
|
|
|
zoom = zoom/(1 + 3*margin/zoom/page_size.w)
|
|
|
|
|
local xpos = (block.x0 + block.x1)/2 * zoom * page_size.w
|
|
|
|
|
local ypos = p_pos.y / p_pos.zoom * zoom
|
|
|
|
|
return zoom, xpos, ypos
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2016-06-15 01:50:59 +08:00
|
|
|
local zoom = 2*self.dimen.w / page_size.w
|
|
|
|
|
return zoom/(1 + 3*margin/zoom/page_size.w)
|
2014-01-02 11:08:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:setZoom()
|
2014-03-13 21:52:43 +08:00
|
|
|
if not self.dimen then
|
|
|
|
|
self.dimen = self.ui.dimen
|
|
|
|
|
end
|
|
|
|
|
self.zoom = self:getZoom(self.current_page)
|
|
|
|
|
self.ui:handleEvent(Event:new("ZoomUpdate", self.zoom))
|
2012-05-19 00:50:26 +02:00
|
|
|
end
|
|
|
|
|
|
2012-12-15 09:26:40 +08:00
|
|
|
function ReaderZooming:genSetZoomModeCallBack(mode)
|
2014-03-13 21:52:43 +08:00
|
|
|
return function()
|
|
|
|
|
self:setZoomMode(mode)
|
|
|
|
|
end
|
2012-12-15 09:26:40 +08:00
|
|
|
end
|
2012-05-19 00:50:26 +02:00
|
|
|
|
2021-03-30 18:47:52 +02:00
|
|
|
function ReaderZooming:setZoomMode(mode, no_warning, is_reflowed)
|
2020-11-28 17:18:57 +01:00
|
|
|
if not no_warning and self.ui.view.page_scroll then
|
|
|
|
|
local message
|
|
|
|
|
if self.paged_modes[mode] then
|
|
|
|
|
message = T(_([[
|
2019-08-22 17:11:47 +02:00
|
|
|
%1
|
2019-08-05 18:38:10 +02:00
|
|
|
|
2020-11-28 17:18:57 +01:00
|
|
|
In combination with continuous view (scroll mode), this can cause unexpected vertical shifts when turning pages.]]),
|
|
|
|
|
self.paged_modes[mode])
|
|
|
|
|
elseif self.zoom_mode == "manual" then
|
|
|
|
|
message = _([[
|
2020-11-30 09:03:23 +01:00
|
|
|
Manual zoom works best with page view.
|
2020-11-28 17:18:57 +01:00
|
|
|
|
|
|
|
|
Please enable page view instead of continuous view (scroll mode).]])
|
|
|
|
|
end
|
|
|
|
|
if message then
|
|
|
|
|
UIManager:show(InfoMessage:new{text = message, timeout = 5})
|
|
|
|
|
end
|
2019-08-05 18:38:10 +02:00
|
|
|
end
|
|
|
|
|
|
2021-03-30 18:47:52 +02:00
|
|
|
-- Dirty hack to prevent ReaderKoptListener from stomping on normal_zoom_mode...
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", mode, is_reflowed and "koptlistener"))
|
2014-03-13 21:52:43 +08:00
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
2013-03-28 21:42:23 +08:00
|
|
|
end
|
|
|
|
|
|
2020-11-28 17:18:57 +01:00
|
|
|
local function _getOverlapFactorForNum(n, overlap)
|
|
|
|
|
-- Auxiliary function to "distribute" an overlap between tiles
|
|
|
|
|
overlap = overlap * (n - 1) / n
|
|
|
|
|
return (100 / (100 - overlap))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:getNumberOf(what, overlap)
|
|
|
|
|
-- Number of columns (if what ~= "rows") or rows (if what == "rows")
|
|
|
|
|
local zoom, zoom_w, zoom_h = self:getZoom(self.current_page)
|
|
|
|
|
local zoom_factor = zoom / (what == "rows" and zoom_h or zoom_w)
|
|
|
|
|
if overlap then
|
|
|
|
|
overlap = (what == "rows" and self.zoom_overlap_v or self.zoom_overlap_h)
|
|
|
|
|
zoom_factor = (overlap - 100 * zoom_factor) / (overlap - 100) -- Thanks Xcas for this one...
|
|
|
|
|
end
|
|
|
|
|
return zoom_factor
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:setNumberOf(what, num, overlap)
|
|
|
|
|
-- Sets number of columns (if what ~= "rows") or rows (if what == "rows")
|
|
|
|
|
local _, zoom_w, zoom_h = self:getZoom(self.current_page)
|
|
|
|
|
local overlap_factor = overlap and _getOverlapFactorForNum(num, overlap) or 1
|
|
|
|
|
local zoom_factor = num / overlap_factor
|
|
|
|
|
if what == "rows" then
|
|
|
|
|
zoom_factor = zoom_factor * zoom_h / zoom_w
|
|
|
|
|
end
|
ReaderZooming: Deal with some more fallout of the new zoom modes (#7728)
* Namely, ensure zoom_mode is consistent with genus & type *both ways*. (I only dealt with the "no zoom_mode" case in my original fixup).
Because documents with settings dating back from before the new zoom modes had "old" zoom_mode settings mixed with "new" genus/type defaults that didn't agree with each other.
It lead to super-confusing ConfigDialog behavior, because ConfigDialog was in fact not reflecting the reality.
(As the source of truth is actually `zoom_mode`).
* There was a snafu in manual mode, because of the extremely weird way prefixes are handled by Configurable/ReaderConfig/DocSettings/ConfigDialog.
So, make sure we only have a *single* zoom_factor, and that it's updated and saved properly under the right name everywhere.
Fixes inconsistencies between first swapping to manual mode, and what the ConfigDialog said/did (because again: possibly a lie), vs., re-opening the same document, which would magically use *different* settings, closer to what was expected (but still broken because of the prefix mismatch and a disagreement on defaults between the two variants).
Fallout from #6885
2021-05-22 03:28:52 +02:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", {kopt_zoom_factor = zoom_factor}))
|
2021-07-15 15:34:13 +02:00
|
|
|
return zoom_factor
|
2020-11-28 17:18:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:_zoomFactorChange(title_text, direction, precision)
|
|
|
|
|
local zoom_factor, overlap = self:getNumberOf(direction)
|
|
|
|
|
UIManager:show(SpinWidget:new{
|
|
|
|
|
value = zoom_factor,
|
|
|
|
|
value_min = 0.1,
|
|
|
|
|
value_max = 10,
|
|
|
|
|
value_step = 0.1,
|
|
|
|
|
value_hold_step = 1,
|
|
|
|
|
precision = "%.1f",
|
|
|
|
|
ok_text = title_text,
|
|
|
|
|
title_text = title_text,
|
|
|
|
|
callback = function(spin)
|
|
|
|
|
zoom_factor = spin.value
|
|
|
|
|
self:setNumberOf(direction, zoom_factor, overlap)
|
2018-09-04 23:55:58 +02:00
|
|
|
end
|
2020-11-28 17:18:57 +01:00
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:_zoomPanChange(text, setting)
|
|
|
|
|
UIManager:show(SpinWidget:new{
|
|
|
|
|
value = self[setting],
|
|
|
|
|
value_min = 0,
|
|
|
|
|
value_max = 90,
|
|
|
|
|
value_step = 1,
|
|
|
|
|
value_hold_step = 10,
|
|
|
|
|
ok_text = _("Set"),
|
|
|
|
|
title_text = text,
|
|
|
|
|
callback = function(spin)
|
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", {[setting] = spin.value}))
|
|
|
|
|
end
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onZoomFactorChange()
|
|
|
|
|
self:_zoomFactorChange(_("Set Zoom factor"), false, "%.1f")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onSetZoomPan(settings, no_redraw)
|
2023-03-23 10:04:59 +02:00
|
|
|
self.ui.doc_settings:saveSetting("kopt_zoom_factor", settings.kopt_zoom_factor)
|
|
|
|
|
self.ui.doc_settings:saveSetting("zoom_mode", settings.zoom_mode)
|
2020-11-28 17:18:57 +01:00
|
|
|
for k, v in pairs(settings) do
|
|
|
|
|
self[k] = v
|
2021-07-15 15:34:13 +02:00
|
|
|
-- Configurable keys aren't prefixed...
|
|
|
|
|
local configurable_key = k:gsub("^kopt_", "")
|
|
|
|
|
if self.ui.document.configurable[configurable_key] then
|
|
|
|
|
self.ui.document.configurable[configurable_key] = v
|
|
|
|
|
end
|
2014-03-13 21:52:43 +08:00
|
|
|
end
|
2020-11-28 17:18:57 +01:00
|
|
|
if not no_redraw then
|
|
|
|
|
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ReaderZooming:onBBoxUpdate()
|
|
|
|
|
self:onDefineZoom()
|
2012-12-15 09:26:40 +08:00
|
|
|
end
|
2013-10-18 22:38:07 +02:00
|
|
|
|
2023-03-30 08:36:41 +03:00
|
|
|
function ReaderZooming:getZoomModeActions() -- for Dispatcher
|
|
|
|
|
local action_toggles = {}
|
|
|
|
|
for _, v in ipairs(ReaderZooming.available_zoom_modes) do
|
|
|
|
|
table.insert(action_toggles, ReaderZooming.zoom_mode_label[v])
|
|
|
|
|
end
|
|
|
|
|
return ReaderZooming.available_zoom_modes, action_toggles
|
|
|
|
|
end
|
|
|
|
|
|
2013-10-18 22:38:07 +02:00
|
|
|
return ReaderZooming
|