Landscape FM / Refactor rotation (#6309)

* landscape FM / Refactor rotation

refactor and simplify the orientation handling code. the user generally cares about the rotation (what direction the device is facing) and not about if koreader is displaying in portrait or landscape mode

* bump base

update luasocket, libjpeg-turbo, curl
add logging to evernote-sdk-lua
update framebuffer for proper rotation
reviewable/pr6341/r1
yparitcher 4 years ago committed by GitHub
parent 09c654c7ec
commit f7d538b108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 849231bf518a6b1457459b408b9ef04e36f44b83
Subproject commit 68b3a7c5d74cb77d82a9eff5b9d9dd9c5bb368f7

@ -47,20 +47,6 @@ local C_ = _.pgettext
local Screen = Device.screen
local T = require("ffi/util").template
local function restoreScreenMode()
--- @todo: Not Yet Implemented. Layout is currently broken in Landscape.
local screen_mode = G_reader_settings:readSetting("fm_screen_mode") or "portrait"
--- @note: Basically, if we were already in Portrait/Inverted Portrait, don't mess with it,
-- as the FM supports it.
-- See setScreenMode in base's ffi/framebuffer.lua for the gory details.
-- See also ReaderView:onSetScreenMode in apps/reader/modules/readerview.lua for a similar logic,
-- if we ever need to add Landscape to the mix.
-- c.f., https://github.com/koreader/koreader/issues/5772#issuecomment-577242365
if Screen:getScreenMode() ~= screen_mode then
Screen:setScreenMode(screen_mode)
end
end
local FileManager = InputContainer:extend{
title = _("KOReader"),
root_path = lfs.currentdir(),
@ -71,6 +57,27 @@ local FileManager = InputContainer:extend{
mkdir_bin = Device:isAndroid() and "/system/bin/mkdir" or "/bin/mkdir",
}
function FileManager:onSetRotationMode(rotation)
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
Screen:setRotationMode(rotation)
if self.instance then
self:reinit(self.instance.path, self.instance.focused_file)
UIManager:setDirty(self.instance.banner, function()
return "ui", self.instance.banner.dimen
end)
end
end
return true
end
function FileManager:setRotationMode()
local locked = G_reader_settings:readSetting("lock_rotation")
local rotation_mode = G_reader_settings:readSetting("fm_rotation_mode") or 0
if locked then
self:onSetRotationMode(rotation_mode)
end
end
function FileManager:init()
if Device:isTouchDevice() then
self:registerTouchZones({
@ -1029,7 +1036,7 @@ end
function FileManager:showFiles(path, focused_file)
path = path or G_reader_settings:readSetting("lastdir") or filemanagerutil.getDefaultDir()
G_reader_settings:saveSetting("lastdir", path)
restoreScreenMode()
self:setRotationMode()
local file_manager = FileManager:new{
dimen = Screen:getSize(),
covers_fullscreen = true, -- hint for UIManager:_repaint()

@ -1975,7 +1975,7 @@ function ReaderFooter:onFrontlightStateChanged()
end
end
function ReaderFooter:onChangeScreenMode()
function ReaderFooter:onSetRotationMode()
self:updateFooterContainer()
self:resetLayout(true)
end

@ -1,4 +1,5 @@
local BD = require("ui/bidi")
local bit = require("bit")
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
@ -1551,9 +1552,8 @@ function ReaderGesture:gestureAction(action, ges)
self.ui:handleEvent(Event:new("RestoreZoomMode"))
self.ui:handleEvent(Event:new("InitScrollPageStates"))
elseif action == "toggle_rotation" then
local event_name = self.document.info.has_pages and "SwapScreenMode" or "ChangeScreenMode"
local arg = Screen:getScreenMode() == "portrait" and "landscape" or "portrait"
self.ui:handleEvent(Event:new(event_name, arg))
local arg = bit.band((Screen:getRotationMode() + 1), 3)
self.ui:handleEvent(Event:new("SetRotationMode", arg))
elseif action == "toggle_wifi" then
local NetworkMgr = require("ui/network/manager")

@ -850,14 +850,6 @@ function ReaderRolling:onSetDimensions(dimen)
end
end
function ReaderRolling:onChangeScreenMode(mode, rotation)
-- Flag it as interactive so we can properly swap to Inverted orientations
-- (we usurp the second argument, which usually means rotation)
self.ui:handleEvent(Event:new("SetScreenMode", mode, rotation or true))
-- (This had the above ReaderRolling:onSetDimensions() called to resize
-- document dimensions and keep up with current position)
end
function ReaderRolling:onColorRenderingUpdate()
self.ui.document:updateColorRendering()
UIManager:setDirty(self.view.dialog, "partial")

@ -672,45 +672,18 @@ function ReaderView:restoreViewContext(ctx)
end
end
-- NOTE: This is just a shim for koptoptions, because we want to be able to pass an optional second argument to SetScreenMode...
-- This is also used as a sink for gsensor input events, because we can only send a single event per input,
-- and we need to cover both CRe & KOpt...
function ReaderView:onSwapScreenMode(new_mode, rotation)
-- Don't do anything if an explicit rotation was requested, but it hasn't actually changed,
-- because we may be sending this event *right before* a ChangeScreenMode in CRe (gyro)
if rotation ~= nil and rotation ~= true and rotation == Screen:getRotationMode() then
return true
end
-- CRe
self.ui:handleEvent(Event:new("ChangeScreenMode", new_mode, rotation or true))
-- KOpt (On CRe, since it's redundant (RR:onChangeScreenMode already sends one), this'll get discarded early)
self.ui:handleEvent(Event:new("SetScreenMode", new_mode, rotation or true))
end
function ReaderView:onSetScreenMode(new_mode, rotation, noskip)
-- Don't do anything if an explicit rotation was requested, but it hasn't actually changed,
-- because we may be sending this event *right after* a ChangeScreenMode in CRe (gsensor)
-- We only want to let the onReadSettings one go through, otherwise the testsuite blows up...
if noskip == nil and rotation ~= nil and rotation ~= true and rotation == Screen:getRotationMode() then
return true
end
if new_mode == "landscape" or new_mode == "portrait" then
-- NOTE: Hacky hack! If rotation is "true", that's actually an "interactive" flag for setScreenMode
--- @fixme That's because we can't store nils in a table, which is what Event:new attempts to do ;).
-- c.f., <https://stackoverflow.com/q/7183998/> & <http://lua-users.org/wiki/VarargTheSecondClassCitizen>
-- With a fixed Event implementation, we'd instead stick "interactive" in a third argument,
-- which we could happily pass while still keeping rotation nil ;).
if rotation ~= nil and rotation ~= true then
Screen:setRotationMode(rotation)
else
Screen:setScreenMode(new_mode, rotation)
function ReaderView:onSetRotationMode(rotation)
if rotation ~= nil then
if rotation == Screen:getRotationMode() then
return true
end
UIManager:setDirty(self.dialog, "full")
local new_screen_size = Screen:getSize()
self.ui:handleEvent(Event:new("SetDimensions", new_screen_size))
self.ui:onScreenResize(new_screen_size)
self.ui:handleEvent(Event:new("InitScrollPageStates"))
Screen:setRotationMode(rotation)
end
UIManager:setDirty(self.dialog, "full")
local new_screen_size = Screen:getSize()
self.ui:handleEvent(Event:new("SetDimensions", new_screen_size))
self.ui:onScreenResize(new_screen_size)
self.ui:handleEvent(Event:new("InitScrollPageStates"))
return true
end
@ -750,15 +723,18 @@ In combination with zoom to fit page, page height, content height or content, co
end
function ReaderView:onReadSettings(config)
local screen_mode
self.render_mode = config:readSetting("render_mode") or 0
if self.ui.document.info.has_pages then
screen_mode = config:readSetting("screen_mode") or G_reader_settings:readSetting("kopt_screen_mode") or "portrait"
else
screen_mode = config:readSetting("screen_mode") or G_reader_settings:readSetting("copt_screen_mode") or "portrait"
local locked = G_reader_settings:readSetting("lock_rotation")
local rotation_mode = config:readSetting("rotation_mode")
if not rotation_mode and locked then
if self.ui.document.info.has_pages then
rotation_mode = G_reader_settings:readSetting("kopt_rotation_mode") or 0
else
rotation_mode = G_reader_settings:readSetting("copt_rotation_mode") or 0
end
end
if screen_mode then
self:onSetScreenMode(screen_mode, config:readSetting("rotation_mode"), true)
if rotation_mode then
self:onSetRotationMode(rotation_mode)
end
self.state.gamma = config:readSetting("gamma") or 1.0
local full_screen = config:readSetting("kopt_full_screen") or self.document.configurable.full_screen
@ -845,7 +821,6 @@ end
function ReaderView:onSaveSettings()
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
self.ui.doc_settings:saveSetting("screen_mode", Screen:getScreenMode())
self.ui.doc_settings:saveSetting("rotation_mode", Screen:getRotationMode())
self.ui.doc_settings:saveSetting("gamma", self.state.gamma)
self.ui.doc_settings:saveSetting("highlight", self.highlight.saved)

@ -667,24 +667,20 @@ end
--- Accelerometer on the Forma, c.f., drivers/hwmon/mma8x5x.c
function Input:handleMiscEvNTX(ev)
local rotation_mode, screen_mode
local rotation_mode
if ev.code == MSC_RAW then
if ev.value == MSC_RAW_GSENSOR_PORTRAIT_UP then
-- i.e., UR
rotation_mode = framebuffer.ORIENTATION_PORTRAIT
screen_mode = 'portrait'
elseif ev.value == MSC_RAW_GSENSOR_LANDSCAPE_RIGHT then
-- i.e., CW
rotation_mode = framebuffer.ORIENTATION_LANDSCAPE
screen_mode = 'landscape'
elseif ev.value == MSC_RAW_GSENSOR_PORTRAIT_DOWN then
-- i.e., UD
rotation_mode = framebuffer.ORIENTATION_PORTRAIT_ROTATED
screen_mode = 'portrait'
elseif ev.value == MSC_RAW_GSENSOR_LANDSCAPE_LEFT then
-- i.e., CCW
rotation_mode = framebuffer.ORIENTATION_LANDSCAPE_ROTATED
screen_mode = 'landscape'
else
-- Discard FRONT/BACK
return
@ -695,18 +691,10 @@ function Input:handleMiscEvNTX(ev)
end
local old_rotation_mode = self.device.screen:getRotationMode()
local old_screen_mode = self.device.screen:getScreenMode()
-- NOTE: Try to handle ScreenMode changes sanely, without wrecking the FM, which only supports Portrait/Inverted ;).
-- NOTE: See the Oasis version just above us for a variant that's locked to the current ScreenMode.
-- Might be nice to expose the two behaviors to the user, somehow?
if rotation_mode ~= old_rotation_mode then
if screen_mode ~= old_screen_mode then
return Event:new("SwapScreenMode", screen_mode, rotation_mode)
else
self.device.screen:setRotationMode(rotation_mode)
local UIManager = require("ui/uimanager")
UIManager:onRotation()
end
if rotation_mode and rotation_mode ~= old_rotation_mode then
return Event:new("SetRotationMode", rotation_mode)
end
end

@ -23,7 +23,7 @@ and optionally
--]]--
local settingsList = {
--CreOptions
screen_mode = {category="string"},
rotation_mode = {category="string"},
visible_pages = {category="string"},
h_page_margins = {category="string"},
sync_t_b_page_margins = {category="string"},

@ -1,4 +1,5 @@
local Device = require("device")
local Screen = Device.screen
local S = require("ui/data/strings")
local optionsutil = require("ui/data/optionsutil")
local _ = require("gettext")
@ -19,14 +20,15 @@ local CreOptions = {
icon = "resources/icons/appbar.transform.rotate.right.large.png",
options = {
{
name = "screen_mode",
name = "rotation_mode",
name_text = S.SCREEN_MODE,
toggle = {S.PORTRAIT, S.LANDSCAPE},
toggle = {S.LANDSCAPE_ROTATED, S.PORTRAIT, S.LANDSCAPE, S.PORTRAIT_ROTATED},
alternate = false,
args = {"portrait", "landscape"},
default_arg = "portrait",
current_func = function() return Device.screen:getScreenMode() end,
event = "ChangeScreenMode",
values = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
args = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
default_arg = 0,
current_func = function() return Device.screen:getRotationMode() end,
event = "SetRotationMode",
name_text_hold_callback = optionsutil.showValues,
},
{

@ -26,14 +26,15 @@ local KoptOptions = {
icon = "resources/icons/appbar.transform.rotate.right.large.png",
options = {
{
name = "screen_mode",
name = "rotation_mode",
name_text = S.SCREEN_MODE,
toggle = {S.PORTRAIT, S.LANDSCAPE},
toggle = {S.LANDSCAPE_ROTATED, S.PORTRAIT, S.LANDSCAPE, S.PORTRAIT_ROTATED},
alternate = false,
args = {"portrait", "landscape"},
default_arg = "portrait",
current_func = function() return Screen:getScreenMode() end,
event = "SwapScreenMode",
values = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
args = {Screen.ORIENTATION_LANDSCAPE_ROTATED, Screen.ORIENTATION_PORTRAIT, Screen.ORIENTATION_LANDSCAPE, Screen.ORIENTATION_PORTRAIT_ROTATED},
default_arg = 0,
current_func = function() return Screen:getRotationMode() end,
event = "SetRotationMode",
name_text_hold_callback = optionsutil.showValues,
}
}

@ -2,11 +2,9 @@
This module contains miscellaneous helper functions for the creoptions and koptoptions.
]]
local Device = require("device")
local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local Screen = Device.screen
local T = require("ffi/util").template
local optionsutil = {}
@ -19,9 +17,6 @@ function optionsutil.showValues(configurable, option, prefix)
local default = G_reader_settings:readSetting(prefix.."_"..option.name)
local current = configurable[option.name]
local value_default, value_current
if option.name == "screen_mode" then
current = Screen:getScreenMode()
end
if option.toggle and option.values then
-- build a table so we can see if current/default settings map
-- to a known setting with a name (in option.toggle)

@ -1,8 +1,9 @@
local _ = require("gettext")
local C_ = _.pgettext
local S = {}
S.SCREEN_MODE = _("Orientation")
S.SCREEN_MODE = _("Rotation")
S.DUAL_PAGES = _("Dual Pages")
S.PAGE_CROP = _("Page Crop")
S.FULL_SCREEN = _("Full Screen")
@ -77,8 +78,10 @@ S.HIGH = _("high")
S.ZERO_DEG = _("0 deg")
S.FIVE_DEG = _("5 deg")
S.TEN_DEG = _("10 deg")
S.PORTRAIT = _("portrait")
S.LANDSCAPE = _("landscape")
S.PORTRAIT = C_("Rotation", "↑ 0°")
S.LANDSCAPE = C_("Rotation", "⤸ 90°")
S.PORTRAIT_ROTATED = C_("Rotation", "↓ 180°")
S.LANDSCAPE_ROTATED = C_("Rotation", "⤹ 90°")
S.REGULAR = _("regular")
S.BOLD = _("bold")
S.VIEW_SCROLL = _("continuous")

@ -180,6 +180,7 @@ NetworkMgr:getMenuTable(common_settings)
common_settings.screen = {
text = _("Screen"),
}
common_settings.screen_rotation = require("ui/elements/screen_rotation_menu_table")
common_settings.screen_dpi = require("ui/elements/screen_dpi_menu_table")
common_settings.screen_eink_opt = require("ui/elements/screen_eink_opt_menu_table")
common_settings.menu_activate = require("ui/elements/menu_activate")
@ -194,10 +195,6 @@ common_settings.ignore_hold_corners = {
end,
}
if Device:canToggleGSensor() then
common_settings.screen_toggle_gsensor = require("ui/elements/screen_toggle_gsensor")
end
-- NOTE: Allow disabling color if it's mistakenly enabled on a Grayscale screen (after a settings import?)
if Screen:isColorEnabled() or Screen:isColorScreen() then
common_settings.color_rendering = require("ui/elements/screen_color_menu_table")

@ -72,12 +72,12 @@ local order = {
screen = {
"screensaver",
"----------------------------",
"screen_rotation",
"----------------------------",
"screen_dpi",
"screen_eink_opt",
"color_rendering",
"----------------------------",
"screen_toggle_gsensor",
"----------------------------",
"screen_timeout",
"fullscreen",
},

@ -93,12 +93,12 @@ local order = {
screen = {
"screensaver",
"----------------------------",
"screen_rotation",
"----------------------------",
"screen_dpi",
"screen_eink_opt",
"color_rendering",
"----------------------------",
"screen_toggle_gsensor",
"----------------------------",
"screen_timeout",
"fullscreen",
},

@ -0,0 +1,124 @@
local _ = require("gettext")
local Device = require("device")
local Event = require("ui/event")
local FileManager = require("apps/filemanager/filemanager")
local UIManager = require("ui/uimanager")
local Screen = Device.screen
local S = require("ui/data/strings")
return {
text = _("Rotation"),
sub_item_table_func = function()
local rotation_table = {}
if Device:canToggleGSensor() then
table.insert(rotation_table, {
text = _("Ignore accelerometer rotation events"),
checked_func = function()
return G_reader_settings:isTrue("input_ignore_gsensor")
end,
callback = function()
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
end,
})
end
table.insert(rotation_table, {
text = _("Keep file browser rotation"),
help_text = _("When checked the rotation of the file browser and the reader will not affect each other"),
checked_func = function()
return G_reader_settings:isTrue("lock_rotation")
end,
callback = function()
G_reader_settings:flipNilOrFalse("lock_rotation")
end,
separator = true,
})
if FileManager.instance then
table.insert(rotation_table, {
text_func = function()
local text = S.LANDSCAPE_ROTATED
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.ORIENTATION_LANDSCAPE_ROTATED then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.ORIENTATION_LANDSCAPE_ROTATED
end,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE_ROTATED))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.ORIENTATION_LANDSCAPE_ROTATED)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = S.PORTRAIT
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.ORIENTATION_PORTRAIT then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.ORIENTATION_PORTRAIT
end,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.ORIENTATION_PORTRAIT)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = S.LANDSCAPE
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.ORIENTATION_LANDSCAPE then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.ORIENTATION_LANDSCAPE
end,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.ORIENTATION_LANDSCAPE)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = S.PORTRAIT_ROTATED
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.ORIENTATION_PORTRAIT_ROTATED then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.ORIENTATION_PORTRAIT_ROTATED
end,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT_ROTATED))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.ORIENTATION_PORTRAIT_ROTATED)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
end
return rotation_table
end,
}

@ -1,13 +0,0 @@
local Device = require("device")
local _ = require("gettext")
return {
text = _("Ignore accelerometer rotation events"),
checked_func = function()
return G_reader_settings:isTrue("input_ignore_gsensor")
end,
callback = function()
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
end,
}

@ -1,14 +1,16 @@
describe("Evernote plugin module", function()
local readerui, match
local sample_clippings, sample_epub
local DocumentRegistry
local DocumentRegistry, Screen
setup(function()
require("commonrequire")
match = require("luassert.match")
local ReaderUI = require("apps/reader/readerui")
DocumentRegistry = require("document/documentregistry")
Screen = require("device").screen
sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}

@ -48,6 +48,7 @@ describe("ReaderBookmark module", function()
setup(function()
DocSettings:open(sample_epub):purge()
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.status.enabled = false
@ -130,6 +131,7 @@ describe("ReaderBookmark module", function()
setup(function()
DocSettings:open(sample_pdf):purge()
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui.status.enabled = false

@ -13,6 +13,7 @@ describe("Readerdictionary module", function()
setup(function()
local sample_epub = "spec/front/unit/data/leaves.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
rolling = readerui.rolling

@ -70,6 +70,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
assert.is.same(true, readerui.view.footer_visible)
@ -95,6 +96,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
assert.is.same(true, readerui.view.footer_visible)
@ -112,6 +114,7 @@ describe("Readerfooter module", function()
cfg:flush()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
assert.is.same(false, readerui.view.footer_visible)
@ -128,6 +131,7 @@ describe("Readerfooter module", function()
cfg:flush()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
assert.is.same(false, readerui.view.footer_visible)
@ -144,6 +148,7 @@ describe("Readerfooter module", function()
cfg:flush()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
assert.is.same(true, readerui.view.footer_visible)
@ -156,6 +161,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_epub))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -174,6 +180,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -189,6 +196,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local fake_menu = {setting = {}}
@ -240,6 +248,7 @@ describe("Readerfooter module", function()
it("should rotate through different modes", function()
local sample_pdf = "spec/front/unit/data/2col.pdf"
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -281,6 +290,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -309,6 +319,7 @@ describe("Readerfooter module", function()
os.remove(DocSettings:getHistoryPath(sample_epub))
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -331,6 +342,7 @@ describe("Readerfooter module", function()
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -357,6 +369,7 @@ describe("Readerfooter module", function()
auto_refresh_time = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -391,6 +404,7 @@ describe("Readerfooter module", function()
auto_refresh_time = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -416,6 +430,7 @@ describe("Readerfooter module", function()
auto_refresh_time = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -469,6 +484,7 @@ describe("Readerfooter module", function()
time = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -508,6 +524,7 @@ describe("Readerfooter module", function()
pages_left = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
local footer = readerui.view.footer
@ -539,6 +556,7 @@ describe("Readerfooter module", function()
pages_left = true,
})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf)
}
local footer = readerui.view.footer
@ -557,6 +575,7 @@ describe("Readerfooter module", function()
assert.are.same({}, UIManager._task_queue)
G_reader_settings:saveSetting("footer", {})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -593,6 +612,7 @@ describe("Readerfooter module", function()
G_reader_settings:saveSetting("reader_footer_mode", 2)
G_reader_settings:saveSetting("footer", { time = true })
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -611,6 +631,7 @@ describe("Readerfooter module", function()
G_reader_settings:saveSetting("reader_footer_mode", 1)
G_reader_settings:saveSetting("footer", {})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -629,6 +650,7 @@ describe("Readerfooter module", function()
G_reader_settings:saveSetting("reader_footer_mode", 1)
G_reader_settings:saveSetting("footer", {disable_progress_bar = true})
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -645,6 +667,7 @@ describe("Readerfooter module", function()
G_reader_settings:saveSetting("footer", { disabled = true })
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
local footer = readerui.view.footer
@ -657,6 +680,7 @@ describe("Readerfooter module", function()
it("should toggle between full and min progress bar for cre documents", function()
local sample_txt = "spec/front/unit/data/sample.txt"
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_txt),
}
local footer = readerui.view.footer

@ -70,6 +70,7 @@ describe("Readerhighlight module", function()
setup(function()
local sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
end)
@ -111,6 +112,7 @@ describe("Readerhighlight module", function()
setup(function()
local sample_pdf = "spec/front/unit/data/sample.pdf"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", false))
@ -194,6 +196,7 @@ describe("Readerhighlight module", function()
setup(function()
local sample_pdf = "spec/front/unit/data/sample.pdf"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", true))

@ -1,5 +1,5 @@
describe("ReaderLink module", function()
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event, Screen
setup(function()
require("commonrequire")
@ -9,12 +9,14 @@ describe("ReaderLink module", function()
Event = require("ui/event")
ReaderUI = require("apps/reader/readerui")
UIManager = require("ui/uimanager")
Screen = require("device").screen
sample_epub = "spec/front/unit/data/leaves.epub"
sample_pdf = "spec/front/unit/data/paper.pdf"
end)
it("should jump to links in epub #nocov", function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(5)
@ -25,6 +27,7 @@ describe("ReaderLink module", function()
it("should jump to links in pdf page mode", function()
UIManager:quit()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", false))
@ -38,6 +41,7 @@ describe("ReaderLink module", function()
it("should jump to links in pdf scroll mode", function()
UIManager:quit()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", true))
@ -54,6 +58,7 @@ describe("ReaderLink module", function()
it("should be able to go back after link jump in epub #nocov", function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(5)
@ -66,6 +71,7 @@ describe("ReaderLink module", function()
it("should be able to go back after link jump in pdf page mode", function()
UIManager:quit()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", false))
@ -81,6 +87,7 @@ describe("ReaderLink module", function()
it("should be able to go back after link jump in pdf scroll mode", function()
UIManager:quit()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", true))
@ -133,6 +140,7 @@ describe("ReaderLink module", function()
G_reader_settings:saveSetting("reader_footer_mode", 0)
require("docsettings"):open(sample_pdf):purge()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetZoomMode", "page"))

@ -1,6 +1,6 @@
describe("Readerpaging module", function()
local sample_pdf = "spec/front/unit/data/sample.pdf"
local readerui, UIManager, Event, DocumentRegistry, ReaderUI
local readerui, UIManager, Event, DocumentRegistry, ReaderUI, Screen
local paging
setup(function()
@ -9,11 +9,13 @@ describe("Readerpaging module", function()
Event = require("ui/event")
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
Screen = require("device").screen
end)
describe("Page mode", function()
setup(function()
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
paging = readerui.paging
@ -46,6 +48,7 @@ describe("Readerpaging module", function()
os.remove(DocSettings:getHistoryPath(sample_pdf))
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
paging = readerui.paging
@ -74,6 +77,7 @@ describe("Readerpaging module", function()
it("should scroll backward on the first page without crash", function()
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
local tmp_readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_djvu),
}
tmp_readerui.paging:onScrollPanRel(-100)
@ -82,6 +86,7 @@ describe("Readerpaging module", function()
it("should scroll forward on the last page without crash", function()
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
local tmp_readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_djvu),
}
paging = tmp_readerui.paging

@ -1,5 +1,5 @@
describe("Readerrolling module", function()
local DocumentRegistry, ReaderUI, Event
local DocumentRegistry, ReaderUI, Event, Screen
local readerui, rolling
setup(function()
@ -7,9 +7,11 @@ describe("Readerrolling module", function()
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
Event = require("ui/event")
Screen = require("device").screen
local sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
rolling = readerui.rolling
@ -17,7 +19,7 @@ describe("Readerrolling module", function()
describe("test in portrait screen mode", function()
it("should goto portrait screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
end)
it("should goto certain page", function()
@ -79,6 +81,7 @@ describe("Readerrolling module", function()
it("should emit EndOfBook event at the end sample txt", function()
local sample_txt = "spec/front/unit/data/sample.txt"
local txt_readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_txt),
}
local called = false
@ -108,7 +111,7 @@ describe("Readerrolling module", function()
describe("test in landscape screen mode", function()
it("should go to landscape screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
end)
it("should goto certain page", function()
for i = 1, 10, 5 do
@ -156,27 +159,27 @@ describe("Readerrolling module", function()
describe("switching screen mode should not change current page number", function()
teardown(function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
end)
it("for portrait-landscape-portrait switching", function()
for i = 80, 100, 10 do
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
assert.are_not.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
assert.are.same(i, rolling.current_page)
end
end)
it("for landscape-portrait-landscape switching", function()
for i = 110, 130, 10 do
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
assert.are_not.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
assert.are.same(i, rolling.current_page)
end
end)
@ -184,14 +187,11 @@ describe("Readerrolling module", function()
describe("test changing word gap - space condensing", function()
it("should show pages for different word gap", function()
readerui.document:setWordSpacing({100, 90})
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetWordSpacing", {100, 90}))
assert.are.same(252, readerui.document:getPageCount())
readerui.document:setWordSpacing({95, 75})
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetWordSpacing", {95, 75}))
assert.are.same(241, readerui.document:getPageCount())
readerui.document:setWordSpacing({75, 50})
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetWordSpacing", {75, 50}))
assert.are.same(231, readerui.document:getPageCount())
end)
end)

@ -1,12 +1,13 @@
describe("Readersearch module", function()
local sample_epub = "spec/front/unit/data/juliet.epub"
local sample_pdf = "spec/front/unit/data/sample.pdf"
local DocumentRegistry, ReaderUI, dbg
local DocumentRegistry, ReaderUI, Screen, dbg
setup(function()
require("commonrequire")
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
Screen = require("device").screen
dbg = require("dbg")
end)
@ -14,6 +15,7 @@ describe("Readersearch module", function()
local doc, search, rolling
setup(function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
doc = readerui.document
@ -118,6 +120,7 @@ describe("Readersearch module", function()
local doc, search, paging
setup(function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
doc = readerui.document

@ -1,15 +1,17 @@
describe("Readertoc module", function()
local DocumentRegistry, ReaderUI, DEBUG
local DocumentRegistry, ReaderUI, Screen, DEBUG
local readerui, toc, toc_max_depth, title
setup(function()
require("commonrequire")
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
Screen = require("device").screen
DEBUG = require("dbg")
local sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
-- reset book to first page

@ -1,5 +1,5 @@
describe("Readerui module", function()
local DocumentRegistry, ReaderUI, DocSettings, UIManager
local DocumentRegistry, ReaderUI, DocSettings, UIManager, Screen
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui
setup(function()
@ -8,8 +8,10 @@ describe("Readerui module", function()
ReaderUI = require("apps/reader/readerui")
DocSettings = require("docsettings")
UIManager = require("ui/uimanager")
Screen = require("device").screen
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
end)
@ -40,6 +42,7 @@ describe("Readerui module", function()
local new_readerui = ReaderUI:_getRunningInstance()
assert.is.truthy(new_readerui.document)
ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub)
}:onClose()
assert.is.truthy(new_readerui.document)

@ -1,5 +1,5 @@
describe("Readerview module", function()
local DocumentRegistry, Blitbuffer, ReaderUI, UIManager, Event
local DocumentRegistry, Blitbuffer, ReaderUI, UIManager, Event, Screen
setup(function()
require("commonrequire")
@ -10,11 +10,13 @@ describe("Readerview module", function()
ReaderUI = require("apps/reader/readerui")
UIManager = require("ui/uimanager")
Event = require("ui/event")
Screen = require("device").screen
end)
it("should stop hinting on document close event", function()
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
for i = #UIManager._task_queue, 1, -1 do
@ -52,6 +54,7 @@ describe("Readerview module", function()
G_reader_settings:saveSetting("reader_footer_mode", 0)
local sample_pdf = "spec/front/unit/data/2col.pdf"
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", false))
@ -103,6 +106,7 @@ describe("Readerview module", function()
G_reader_settings:saveSetting("reader_footer_mode", 0)
local sample_pdf = "spec/front/unit/data/2col.pdf"
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", true))

@ -1,5 +1,5 @@
describe("ReaderScreenshot module", function()
local DocumentRegistry, ReaderUI, lfs, UIManager, Event
local DocumentRegistry, ReaderUI, lfs, UIManager, Event, Screen
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui
setup(function()
@ -9,19 +9,21 @@ describe("ReaderScreenshot module", function()
lfs = require("libs/libkoreader-lfs")
UIManager = require("ui/uimanager")
Event = require("ui/event")
Screen = require("device").screen
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
end)
teardown(function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
end)
it("should get screenshot in portrait", function()
local name = "screenshots/reader_screenshot_portrait.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
@ -33,7 +35,7 @@ describe("ReaderScreenshot module", function()
it("should get screenshot in landscape", function()
local name = "screenshots/reader_screenshot_landscape.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(2, function() UIManager:close(readerui) end)

Loading…
Cancel
Save