2014-11-21 10:32:43 +00:00
|
|
|
describe("Readerhighlight module", function()
|
2017-08-08 20:35:40 +00:00
|
|
|
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, Event
|
2016-04-19 06:50:36 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2016-04-19 06:50:36 +00:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
2017-06-23 17:04:11 +00:00
|
|
|
Event = require("ui/event")
|
|
|
|
Geom = require("ui/geometry")
|
2016-04-19 06:50:36 +00:00
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
Screen = require("device").screen
|
2017-06-23 17:04:11 +00:00
|
|
|
UIManager = require("ui/uimanager")
|
2016-04-19 06:50:36 +00:00
|
|
|
end)
|
|
|
|
|
2014-11-21 10:32:43 +00:00
|
|
|
local function highlight_single_word(readerui, pos0)
|
|
|
|
readerui.highlight:onHold(nil, { pos = pos0 })
|
|
|
|
readerui.highlight:onHoldRelease()
|
|
|
|
readerui.highlight:onHighlight()
|
|
|
|
UIManager:scheduleIn(1, function()
|
|
|
|
UIManager:close(readerui.dictionary.dict_window)
|
|
|
|
UIManager:close(readerui)
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:quit()
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
|
|
|
local function highlight_text(readerui, pos0, pos1)
|
|
|
|
readerui.highlight:onHold(nil, { pos = pos0 })
|
|
|
|
readerui.highlight:onHoldPan(nil, { pos = pos1 })
|
2016-07-18 06:12:53 +00:00
|
|
|
local next_slot
|
|
|
|
for i = #UIManager._window_stack, 0, -1 do
|
|
|
|
local top_window = UIManager._window_stack[i]
|
|
|
|
-- skip modal window
|
|
|
|
if not top_window or not top_window.widget.modal then
|
|
|
|
next_slot = i + 1
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2014-11-21 10:32:43 +00:00
|
|
|
readerui.highlight:onHoldRelease()
|
|
|
|
assert.truthy(readerui.highlight.highlight_dialog)
|
2016-07-18 06:12:53 +00:00
|
|
|
assert.truthy(UIManager._window_stack[next_slot].widget
|
|
|
|
== readerui.highlight.highlight_dialog)
|
2014-11-21 10:32:43 +00:00
|
|
|
readerui.highlight:onHighlight()
|
|
|
|
UIManager:scheduleIn(1, function()
|
|
|
|
UIManager:close(readerui.highlight.highlight_dialog)
|
|
|
|
UIManager:close(readerui)
|
2016-07-18 06:12:53 +00:00
|
|
|
UIManager:quit()
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
|
|
|
local function tap_highlight_text(readerui, pos0, pos1, pos2)
|
|
|
|
readerui.highlight:onHold(nil, { pos = pos0 })
|
|
|
|
readerui.highlight:onHoldPan(nil, { pos = pos1 })
|
|
|
|
readerui.highlight:onHoldRelease()
|
|
|
|
readerui.highlight:onHighlight()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
UIManager:close(readerui.highlight.highlight_dialog)
|
|
|
|
readerui.highlight:onTap(nil, { pos = pos2 })
|
|
|
|
assert.truthy(readerui.highlight.edit_highlight_dialog)
|
2016-04-19 06:50:36 +00:00
|
|
|
UIManager:nextTick(function()
|
2014-11-21 10:32:43 +00:00
|
|
|
UIManager:close(readerui.highlight.edit_highlight_dialog)
|
|
|
|
UIManager:close(readerui)
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:quit()
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
2016-04-19 06:50:36 +00:00
|
|
|
|
2014-11-21 10:32:43 +00:00
|
|
|
describe("highlight for EPUB documents", function()
|
|
|
|
local page = 10
|
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local sample_epub = "spec/front/unit/data/juliet.epub"
|
2014-11-21 10:32:43 +00:00
|
|
|
readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.rolling:onGotoPage(page)
|
2016-04-19 06:50:36 +00:00
|
|
|
UIManager:show(readerui)
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme HACK: Mock UIManager:run x and y for readerui.dimen
|
|
|
|
--- @todo Refactor readerview's dimen handling so we can get rid of
|
2016-04-19 06:50:36 +00:00
|
|
|
-- this workaround
|
|
|
|
readerui:paintTo(Screen.bb, 0, 0)
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
2019-03-24 21:09:50 +00:00
|
|
|
highlight_single_word(readerui, Geom:new{ x = 400, y = 70 })
|
2014-11-21 10:32:43 +00:00
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_epub.png")
|
|
|
|
assert.truthy(readerui.view.highlight.saved[page])
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
highlight_text(readerui,
|
2018-12-05 12:01:49 +00:00
|
|
|
Geom:new{ x = 400, y = 110 },
|
|
|
|
Geom:new{ x = 400, y = 170 })
|
2014-11-21 10:32:43 +00:00
|
|
|
Screen:shot("screenshots/reader_highlight_text_epub.png")
|
|
|
|
assert.truthy(readerui.view.highlight.saved[page])
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
tap_highlight_text(readerui,
|
2019-11-01 22:07:41 +00:00
|
|
|
Geom:new{ x = 130, y = 100 },
|
|
|
|
Geom:new{ x = 350, y = 395 },
|
|
|
|
Geom:new{ x = 80, y = 265 })
|
2014-11-21 10:32:43 +00:00
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_epub.png")
|
|
|
|
end)
|
|
|
|
end)
|
2016-04-19 06:50:36 +00:00
|
|
|
|
2016-07-18 06:12:53 +00:00
|
|
|
describe("highlight for PDF documents in page mode", function()
|
2014-11-21 10:32:43 +00:00
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
2014-11-21 10:32:43 +00:00
|
|
|
readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
2016-07-18 06:12:53 +00:00
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
describe("for scanned page with text layer", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(10)
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
tap_highlight_text(readerui,
|
|
|
|
Geom:new{ x = 260, y = 70 },
|
|
|
|
Geom:new{ x = 260, y = 150 },
|
|
|
|
Geom:new{ x = 280, y = 110 })
|
2014-11-21 10:32:43 +00:00
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
describe("for scanned page without text layer", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(28)
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf_scanned.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf_scanned.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
|
|
|
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scanned.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
describe("for reflowed page", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
readerui.document.configurable.text_wrap = 1
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(31)
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
2016-04-19 06:50:36 +00:00
|
|
|
readerui.document.configurable.text_wrap = 0
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:close(readerui) -- close to flush settings
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf_reflowed.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf_reflowed.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
|
|
|
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf_reflowed.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
2016-07-18 06:12:53 +00:00
|
|
|
|
|
|
|
describe("highlight for PDF documents in scroll mode", function()
|
|
|
|
local readerui
|
|
|
|
setup(function()
|
|
|
|
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
|
|
|
readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
|
|
|
end)
|
|
|
|
describe("for scanned page with text layer", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
|
|
|
readerui.paging:onGotoPage(10)
|
|
|
|
readerui.zooming:setZoomMode("contentwidth")
|
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
|
|
|
tap_highlight_text(readerui,
|
|
|
|
Geom:new{ x = 260, y = 70 },
|
|
|
|
Geom:new{ x = 260, y = 150 },
|
|
|
|
Geom:new{ x = 280, y = 110 })
|
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scroll.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
describe("for scanned page without text layer", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
|
|
|
readerui.paging:onGotoPage(28)
|
|
|
|
readerui.zooming:setZoomMode("contentwidth")
|
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf_scanned_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{x = 192, y = 186}, Geom:new{x = 280, y = 186})
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf_scanned_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
|
|
|
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scanned_scroll.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
describe("for reflowed page", function()
|
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
readerui.document.configurable.text_wrap = 1
|
|
|
|
UIManager:show(readerui)
|
|
|
|
readerui.paging:onGotoPage(31)
|
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
readerui.highlight:clear()
|
|
|
|
readerui.document.configurable.text_wrap = 0
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:close(readerui) -- close to flush settings
|
2016-07-18 06:12:53 +00:00
|
|
|
end)
|
|
|
|
it("should highlight single word", function()
|
|
|
|
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_single_word_pdf_reflowed_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should highlight text", function()
|
|
|
|
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
|
|
|
Screen:shot("screenshots/reader_highlight_text_pdf_reflowed_scroll.png")
|
|
|
|
end)
|
|
|
|
it("should response on tap gesture", function()
|
|
|
|
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
|
|
|
Screen:shot("screenshots/reader_tap_highlight_text_pdf_reflowed_scroll.png")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|