2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2021-05-04 21:13:24 +00:00
|
|
|
local DocCache = require("document/doccache")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
2019-08-05 16:38:10 +00: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 16:18:57 +00:00
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
2019-08-05 16:38:10 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2020-11-28 16:18:57 +00:00
|
|
|
local util = require("util")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2019-08-05 16:38:10 +00:00
|
|
|
local Input = Device.input
|
|
|
|
local Screen = Device.screen
|
|
|
|
local T = require("ffi/util").template
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local ReaderZooming = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
zoom = 1.0,
|
2020-11-28 16:18:57 +00:00
|
|
|
available_zoom_modes = {
|
|
|
|
"page",
|
|
|
|
"pagewidth",
|
|
|
|
"pageheight",
|
|
|
|
"content",
|
|
|
|
"contentwidth",
|
|
|
|
"contentheight",
|
|
|
|
"columns",
|
|
|
|
"rows",
|
|
|
|
"manual",
|
|
|
|
},
|
2021-06-01 10:08:12 +00:00
|
|
|
zoom_genus_to_mode = {
|
2021-03-30 16:47:52 +00:00
|
|
|
[4] = "page",
|
|
|
|
[3] = "content",
|
|
|
|
[2] = "columns",
|
|
|
|
[1] = "rows",
|
|
|
|
[0] = "manual",
|
|
|
|
},
|
2021-06-01 10:08:12 +00:00
|
|
|
zoom_mode_to_genus = {
|
|
|
|
page = 4,
|
|
|
|
content = 3,
|
|
|
|
columns = 2,
|
|
|
|
rows = 1,
|
|
|
|
manual = 0,
|
|
|
|
},
|
|
|
|
zoom_type_to_mode = {
|
2021-03-30 16:47:52 +00:00
|
|
|
[2] = "",
|
|
|
|
[1] = "width",
|
|
|
|
[0] = "height",
|
|
|
|
},
|
2021-06-01 10:08:12 +00:00
|
|
|
zoom_mode_to_type = {
|
|
|
|
[""] = 2,
|
|
|
|
width = 1,
|
|
|
|
height = 0,
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
-- default to nil so we can trigger ZoomModeUpdate events on start up
|
|
|
|
zoom_mode = nil,
|
2019-08-05 16:38:10 +00:00
|
|
|
DEFAULT_ZOOM_MODE = "pagewidth",
|
2020-11-28 16:18:57 +00: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 01:28:52 +00:00
|
|
|
kopt_zoom_factor = 1.5,
|
2020-11-28 16:18:57 +00:00
|
|
|
zoom_pan_settings = {
|
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 01:28:52 +00:00
|
|
|
"kopt_zoom_factor",
|
2020-11-28 16:18:57 +00:00
|
|
|
"zoom_overlap_h",
|
|
|
|
"zoom_overlap_v",
|
|
|
|
"zoom_bottom_to_top",
|
|
|
|
"zoom_direction_vertical",
|
|
|
|
},
|
|
|
|
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
|
2014-03-13 13:52:43 +00:00
|
|
|
current_page = 1,
|
2019-08-05 16:38:10 +00:00
|
|
|
rotation = 0,
|
|
|
|
paged_modes = {
|
|
|
|
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 16:38:10 +00:00
|
|
|
},
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 01:30:48 +00:00
|
|
|
function ReaderZooming:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events = {
|
|
|
|
ZoomIn = {
|
|
|
|
{ "Shift", Input.group.PgFwd },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom in",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "Zoom", args = "in"
|
|
|
|
},
|
|
|
|
ZoomOut = {
|
|
|
|
{ "Shift", Input.group.PgBack },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom out",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "Zoom", args = "out"
|
|
|
|
},
|
|
|
|
ZoomToFitPage = {
|
|
|
|
{ "A" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit page",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "page"
|
|
|
|
},
|
|
|
|
ZoomToFitContent = {
|
|
|
|
{ "Shift", "A" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit content",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "content"
|
|
|
|
},
|
|
|
|
ZoomToFitPageWidth = {
|
|
|
|
{ "S" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit page width",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "pagewidth"
|
|
|
|
},
|
|
|
|
ZoomToFitContentWidth = {
|
|
|
|
{ "Shift", "S" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit content width",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "contentwidth"
|
|
|
|
},
|
|
|
|
ZoomToFitPageHeight = {
|
|
|
|
{ "D" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit page height",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "pageheight"
|
|
|
|
},
|
|
|
|
ZoomToFitContentHeight = {
|
|
|
|
{ "Shift", "D" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "zoom to fit content height",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "SetZoomMode", args = "contentheight"
|
|
|
|
},
|
2020-11-28 16:18:57 +00:00
|
|
|
ZoomManual = {
|
|
|
|
{ "Shift", "M" },
|
|
|
|
doc = "manual zoom mode",
|
|
|
|
event = "SetZoomMode", args = "manual"
|
2018-02-10 13:58:39 +00:00
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2012-12-15 01:30:48 +00:00
|
|
|
end
|
|
|
|
|
2021-06-01 10:08:12 +00: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 17:01:09 +00: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 10:08:12 +00: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 17:01:09 +00: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 01:28:52 +00:00
|
|
|
|
2021-05-23 17:01:09 +00:00
|
|
|
function ReaderZooming:onReadSettings(config)
|
2021-03-30 16:47:52 +00:00
|
|
|
-- If we have a composite zoom_mode stored, use that
|
2020-11-28 16:18:57 +00: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 01:28:52 +00:00
|
|
|
if zoom_mode then
|
|
|
|
-- Validate it first
|
|
|
|
zoom_mode = util.arrayContains(self.available_zoom_modes, zoom_mode)
|
|
|
|
and zoom_mode
|
|
|
|
or self.DEFAULT_ZOOM_MODE
|
|
|
|
|
|
|
|
-- Make sure the split genus & type match, to have an up-to-date ConfigDialog...
|
2021-05-23 17:01:09 +00: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 01:28:52 +00: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 16:47:52 +00:00
|
|
|
local zoom_mode_genus = config:readSetting("kopt_zoom_mode_genus")
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_mode_genus")
|
|
|
|
local zoom_mode_type = config:readSetting("kopt_zoom_mode_type")
|
|
|
|
or G_reader_settings:readSetting("kopt_zoom_mode_type")
|
|
|
|
if zoom_mode_genus or zoom_mode_type then
|
2021-06-01 10:08:12 +00:00
|
|
|
zoom_mode = self:combo_to_mode(zoom_mode_genus, zoom_mode_type)
|
2021-03-30 16:47:52 +00:00
|
|
|
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 01:28:52 +00:00
|
|
|
|
|
|
|
-- Validate it
|
|
|
|
zoom_mode = util.arrayContains(self.available_zoom_modes, zoom_mode)
|
|
|
|
and zoom_mode
|
|
|
|
or self.DEFAULT_ZOOM_MODE
|
|
|
|
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 17:01:09 +00: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 01:28:52 +00:00
|
|
|
config:delSetting("zoom_factor")
|
|
|
|
elseif config:has("zoom_factor") and config:has("kopt_zoom_factor") then
|
|
|
|
config:delSetting("zoom_factor")
|
2021-03-30 16:47:52 +00: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
|
2020-11-28 16:18:57 +00:00
|
|
|
for _, setting in ipairs(self.zoom_pan_settings) do
|
2021-03-06 21:44:18 +00:00
|
|
|
self[setting] = config:readSetting(setting)
|
|
|
|
or G_reader_settings:readSetting(setting)
|
|
|
|
or self[setting]
|
2020-11-28 16:18:57 +00:00
|
|
|
end
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderZooming:onSaveSettings()
|
2016-06-14 17:50:59 +00:00
|
|
|
self.ui.doc_settings:saveSetting("zoom_mode", self.orig_zoom_mode or self.zoom_mode)
|
2020-11-28 16:18:57 +00:00
|
|
|
for _, setting in ipairs(self.zoom_pan_settings) do
|
|
|
|
self.ui.doc_settings:saveSetting(setting, self[setting])
|
|
|
|
end
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2013-03-28 13:42:23 +00:00
|
|
|
function ReaderZooming:onSpread(arg, ges)
|
2014-03-13 13:52:43 +00: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 13:42:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onPinch(arg, ges)
|
2014-03-13 13:52:43 +00: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 13:42:23 +00:00
|
|
|
end
|
|
|
|
|
2014-01-02 03:08:06 +00:00
|
|
|
function ReaderZooming:onToggleFreeZoom(arg, ges)
|
2014-03-13 13:52:43 +00: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 08:10:38 +00:00
|
|
|
logger.info("zoom center", self.zoom, xpos, ypos)
|
2014-03-13 13:52:43 +00: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-14 17:50:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "page"))
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-02 03:08:06 +00:00
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderZooming:onSetDimensions(dimensions)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we were resized
|
|
|
|
self.dimen = dimensions
|
|
|
|
self:setZoom()
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2013-10-11 15:39:57 +00:00
|
|
|
function ReaderZooming:onRestoreDimensions(dimensions)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we were resized
|
|
|
|
self.dimen = dimensions
|
|
|
|
self:setZoom()
|
2013-10-11 15:39:57 +00:00
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderZooming:onRotationUpdate(rotation)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.rotation = rotation
|
|
|
|
self:setZoom()
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
function ReaderZooming:onZoom(direction)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.info("zoom", direction)
|
2014-03-13 13:52:43 +00: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 08:10:38 +00:00
|
|
|
logger.info("zoom is now at", self.zoom)
|
2014-03-13 13:52:43 +00:00
|
|
|
self:onSetZoomMode("free")
|
|
|
|
self.view:onZoomUpdate(self.zoom)
|
|
|
|
return true
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2021-01-11 17:14:19 +00:00
|
|
|
function ReaderZooming:onDefineZoom(btn, when_applied_callback)
|
2020-11-28 16:18:57 +00:00
|
|
|
local config = self.ui.document.configurable
|
|
|
|
local settings = ({
|
|
|
|
[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},
|
|
|
|
})[config.zoom_direction]
|
|
|
|
local zoom_range_number = config.zoom_range_number
|
|
|
|
local zoom_factor = config.zoom_factor
|
2021-06-01 10:08:12 +00: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 16:18:57 +00: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 10:08:12 +00:00
|
|
|
zoom_mode = zoom_mode_genus .. zoom_mode_type
|
2020-11-28 16:18:57 +00:00
|
|
|
else
|
|
|
|
zoom_mode = zoom_mode_genus
|
|
|
|
self.ui:handleEvent(Event:new("SetScrollMode", false))
|
|
|
|
end
|
|
|
|
zoom_mode = util.arrayContains(self.available_zoom_modes, zoom_mode) and zoom_mode or self.DEFAULT_ZOOM_MODE
|
|
|
|
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))
|
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 01:28:52 +00:00
|
|
|
settings.kopt_zoom_factor = self:setNumberOf(
|
2020-11-28 16:18:57 +00:00
|
|
|
zoom_mode,
|
|
|
|
zoom_range_number,
|
|
|
|
zoom_mode == "columns" and settings.zoom_overlap_h or settings.zoom_overlap_v
|
|
|
|
)
|
|
|
|
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 01:28:52 +00: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 16:18:57 +00: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 01:28:52 +00:00
|
|
|
-- No redraw here, because setNumberOf already took care of it
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", settings, true))
|
2020-11-28 16:18:57 +00: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 17:14:19 +00: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 16:18:57 +00: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]]),
|
|
|
|
zoom_mode,
|
|
|
|
("%.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 01:28:52 +00:00
|
|
|
("%.2f"):format(config.zoom_factor)),
|
2021-01-11 17:14:19 +00:00
|
|
|
dismiss_callback = when_applied_callback,
|
2020-11-28 16:18:57 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
function ReaderZooming:onSetZoomMode(new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.zoom_mode = new_mode
|
|
|
|
if self.zoom_mode ~= new_mode then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.info("setting zoom mode to", new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("ZoomModeUpdate", new_mode))
|
|
|
|
self.zoom_mode = new_mode
|
2021-05-23 17:01:09 +00:00
|
|
|
self:_updateConfigurable(new_mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self:setZoom()
|
2020-11-28 16:18:57 +00: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 13:52:43 +00:00
|
|
|
end
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onPageUpdate(new_page_no)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.current_page = new_page_no
|
|
|
|
self:setZoom()
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
2019-08-30 11:47:51 +00: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 13:52:43 +00:00
|
|
|
self:setZoom()
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
|
|
return true
|
2013-04-14 07:16:42 +00:00
|
|
|
end
|
|
|
|
|
2016-06-14 17:50:59 +00:00
|
|
|
function ReaderZooming:onEnterFlippingMode(zoom_mode)
|
2020-06-28 13:41:24 +00: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-14 17:50:59 +00: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 13:41:24 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {}
|
|
|
|
end
|
2016-06-14 17:50:59 +00:00
|
|
|
self.orig_zoom_mode = nil
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
|
|
|
|
end
|
|
|
|
|
2013-03-10 06:21:32 +00:00
|
|
|
function ReaderZooming:getZoom(pageno)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- check if we're in bbox mode and work on bbox if that's the case
|
2020-11-28 16:18:57 +00:00
|
|
|
local zoom
|
2014-10-15 14:01:39 +00:00
|
|
|
local page_size = self.ui.document:getNativePageDimensions(pageno)
|
2020-11-28 16:18:57 +00:00
|
|
|
if not (self.zoom_mode and self.zoom_mode:match("^page") or self.ui.document.configurable.trim_page == 3) then
|
2014-03-13 13:52:43 +00:00
|
|
|
local ubbox_dimen = self.ui.document:getUsedBBoxDimensions(pageno, 1)
|
2014-10-15 14:01:39 +00:00
|
|
|
-- if bbox is larger than the native page dimension render the full page
|
|
|
|
-- See discussion in koreader/koreader#970.
|
|
|
|
if ubbox_dimen.w <= page_size.w and ubbox_dimen.h <= page_size.h then
|
|
|
|
page_size = ubbox_dimen
|
|
|
|
self.view:onBBoxUpdate(ubbox_dimen)
|
|
|
|
else
|
|
|
|
self.view:onBBoxUpdate(nil)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
|
|
|
-- otherwise, operate on full page
|
|
|
|
self.view:onBBoxUpdate(nil)
|
|
|
|
end
|
|
|
|
-- calculate zoom value:
|
2016-06-09 17:22:09 +00: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 15:48:34 +00:00
|
|
|
if self.ui.view.footer_visible and not self.ui.view.footer.settings.reclaim_height then
|
2016-11-02 08:38:52 +00:00
|
|
|
zoom_h = zoom_h - self.ui.view.footer:getHeight()
|
2016-06-09 17:22:09 +00: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 13:52:43 +00:00
|
|
|
-- rotated by 90 or 270 degrees
|
2016-06-09 17:22:09 +00:00
|
|
|
zoom_w = zoom_w / page_size.h
|
|
|
|
zoom_h = zoom_h / page_size.w
|
2014-03-13 13:52:43 +00: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 16:18:57 +00: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 01:28:52 +00: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 16:18:57 +00:00
|
|
|
zoom = zoom_w * zoom_factor
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2021-05-04 21:13:24 +00:00
|
|
|
if zoom and zoom > 10 and not DocCache:willAccept(zoom * (self.dimen.w * self.dimen.h + 512)) then
|
2019-02-21 10:38:19 +00:00
|
|
|
logger.dbg("zoom too large, adjusting")
|
2021-05-04 21:13:24 +00:00
|
|
|
while not DocCache:willAccept(zoom * (self.dimen.w * self.dimen.h + 512)) do
|
2019-02-21 10:38:19 +00: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 16:18:57 +00:00
|
|
|
return zoom, zoom_w, zoom_h
|
2013-03-10 06:21:32 +00:00
|
|
|
end
|
|
|
|
|
2014-01-02 03:08:06 +00:00
|
|
|
function ReaderZooming:getRegionalZoomCenter(pageno, pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
local p_pos = self.view:getSinglePagePosition(pos)
|
|
|
|
local page_size = self.ui.document:getNativePageDimensions(pageno)
|
2016-06-14 17:50:59 +00: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 13:52:43 +00:00
|
|
|
local margin = self.ui.document.configurable.page_margin * Screen:getDPI()
|
2016-06-14 17:50:59 +00: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 13:52:43 +00:00
|
|
|
end
|
2016-06-14 17:50:59 +00:00
|
|
|
local zoom = 2*self.dimen.w / page_size.w
|
|
|
|
return zoom/(1 + 3*margin/zoom/page_size.w)
|
2014-01-02 03:08:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:setZoom()
|
2014-03-13 13:52:43 +00: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-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2012-12-15 01:26:40 +00:00
|
|
|
function ReaderZooming:genSetZoomModeCallBack(mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
return function()
|
|
|
|
self:setZoomMode(mode)
|
|
|
|
end
|
2012-12-15 01:26:40 +00:00
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
|
2021-03-30 16:47:52 +00:00
|
|
|
function ReaderZooming:setZoomMode(mode, no_warning, is_reflowed)
|
2020-11-28 16:18:57 +00: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 15:11:47 +00:00
|
|
|
%1
|
2019-08-05 16:38:10 +00:00
|
|
|
|
2020-11-28 16:18:57 +00: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 08:03:23 +00:00
|
|
|
Manual zoom works best with page view.
|
2020-11-28 16:18:57 +00: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 16:38:10 +00:00
|
|
|
end
|
|
|
|
|
2021-03-30 16:47:52 +00: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 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
2013-03-28 13:42:23 +00:00
|
|
|
end
|
|
|
|
|
2020-11-28 16:18:57 +00: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 01:28:52 +00:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomPan", {kopt_zoom_factor = zoom_factor}))
|
2020-11-28 16:18:57 +00:00
|
|
|
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:_zoomFactorChange(title_text, direction, precision)
|
|
|
|
local zoom_factor, overlap = self:getNumberOf(direction)
|
|
|
|
UIManager:show(SpinWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
|
|
|
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 21:55:58 +00:00
|
|
|
end
|
2020-11-28 16:18:57 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:_zoomPanChange(text, setting)
|
|
|
|
UIManager:show(SpinWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
|
|
|
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)
|
|
|
|
for k, v in pairs(settings) do
|
|
|
|
self[k] = v
|
|
|
|
self.ui.doc_settings:saveSetting(k, v)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2020-11-28 16:18:57 +00:00
|
|
|
if not no_redraw then
|
|
|
|
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onBBoxUpdate()
|
|
|
|
self:onDefineZoom()
|
2012-12-15 01:26:40 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderZooming
|