|
|
|
local EventListener = require("ui/widget/eventlistener")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local ReaderZooming = require("apps/reader/modules/readerzooming")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
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.
2 years ago
|
|
|
local ReaderKoptListener = EventListener:extend{}
|
|
|
|
|
|
|
|
function ReaderKoptListener:setZoomMode(zoom_mode)
|
|
|
|
if self.document.configurable.text_wrap == 1 then
|
|
|
|
-- in reflow mode only "page" zoom mode is valid so override any other zoom mode
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "page", "koptlistener"))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode, "koptlistener"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onReadSettings(config)
|
|
|
|
-- normal zoom mode is zoom mode used in non-reflow mode.
|
|
|
|
local normal_zoom_mode = config:readSetting("normal_zoom_mode")
|
|
|
|
or ReaderZooming:combo_to_mode(G_reader_settings:readSetting("kopt_zoom_mode_genus"), G_reader_settings:readSetting("kopt_zoom_mode_type"))
|
|
|
|
normal_zoom_mode = ReaderZooming.zoom_mode_label[normal_zoom_mode] and normal_zoom_mode or ReaderZooming.DEFAULT_ZOOM_MODE
|
|
|
|
self.normal_zoom_mode = normal_zoom_mode
|
|
|
|
self:setZoomMode(normal_zoom_mode)
|
|
|
|
self.ui:handleEvent(Event:new("GammaUpdate", self.document.configurable.contrast))
|
|
|
|
-- since K2pdfopt v2.21 negative value of word spacing is also used, for config
|
|
|
|
-- compatability we should manually change previous -1 to a more reasonable -0.2
|
|
|
|
if self.document.configurable.word_spacing == -1 then
|
|
|
|
self.document.configurable.word_spacing = -0.2
|
|
|
|
end
|
|
|
|
self.ui:handleEvent(Event:new("DitheringUpdate"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onSaveSettings()
|
|
|
|
self.ui.doc_settings:saveSetting("normal_zoom_mode", self.normal_zoom_mode)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onRestoreZoomMode()
|
|
|
|
-- "RestoreZoomMode" event is sent when reflow mode on/off is toggled
|
|
|
|
self:setZoomMode(self.normal_zoom_mode)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onSetZoomMode(zoom_mode, orig)
|
|
|
|
if orig == "koptlistener" then return end
|
|
|
|
-- capture zoom mode set outside of koptlistener which should always be normal zoom mode
|
|
|
|
self.normal_zoom_mode = zoom_mode
|
|
|
|
self:setZoomMode(self.normal_zoom_mode)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onFineTuningFontSize(delta)
|
|
|
|
self.document.configurable.font_size = self.document.configurable.font_size + delta
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onZoomUpdate(zoom)
|
|
|
|
-- an exceptional case is reflow mode
|
|
|
|
if self.document.configurable.text_wrap == 1 then
|
|
|
|
self.view.state.zoom = 1.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- misc koptoption handler
|
|
|
|
function ReaderKoptListener:onDocLangUpdate(lang)
|
|
|
|
if lang == "chi_sim" or lang == "chi_tra" or
|
|
|
|
lang == "jpn" or lang == "kor" then
|
|
|
|
self.document.configurable.word_spacing = G_defaults:readSetting("DKOPTREADER_CONFIG_WORD_SPACINGS")[1]
|
|
|
|
else
|
|
|
|
self.document.configurable.word_spacing = G_defaults:readSetting("DKOPTREADER_CONFIG_WORD_SPACINGS")[3]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderKoptListener:onConfigChange(option_name, option_value)
|
|
|
|
-- font_size and line_spacing are historically and sadly shared by both mupdf and cre reader modules,
|
|
|
|
-- but fortunately they can be distinguished by their different ranges
|
|
|
|
if (option_name == "font_size" or option_name == "line_spacing") and option_value > 5 then return end
|
|
|
|
self.document.configurable[option_name] = option_value
|
|
|
|
self.ui:handleEvent(Event:new("StartActivityIndicator"))
|
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return ReaderKoptListener
|