mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Includes: - [build] FreeType: bump to 2.9.1 - [build] bump libjpeg-turbo to 1.5.3 - bump crengine: - Fix CSS selector specificity computation - [fix] crengine/src/lvfntman.cpp: improve letter_spacing limit - [fix] crengine/src/lvxml.cpp: add all empty HTML elements - html head styles: fix styles not being applied - Hyphenation: increase MAX_PATTERN_SIZE from 16 to 35 - html documents: proper handling of <BR> tags - Allows requesting old (broken) XML/DOM building code - cre.cpp: setStyleSheet(): accept filepath and/or css text, and added getIntProperty() and getStringProperty() credocument/readerrolling: request older XML/DOM building code for books previously opened, to not lose bookmarks and highlights (unit tests update because of new handling of consecutive BR via css pushed links down in the book)
154 lines
5.9 KiB
Lua
154 lines
5.9 KiB
Lua
describe("ReaderLink module", function()
|
|
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event
|
|
|
|
setup(function()
|
|
require("commonrequire")
|
|
package.unloadAll()
|
|
DocumentRegistry = require("document/documentregistry")
|
|
Event = require("ui/event")
|
|
ReaderUI = require("apps/reader/readerui")
|
|
UIManager = require("ui/uimanager")
|
|
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{
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
}
|
|
readerui.rolling:onGotoPage(6)
|
|
readerui.link:onTap(nil, {pos = {x = 336, y = 166}})
|
|
assert.is.same(40, readerui.rolling.current_page)
|
|
end)
|
|
|
|
it("should jump to links in pdf page mode", function()
|
|
UIManager:quit()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
}
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
|
readerui.paging:onGotoPage(1)
|
|
readerui.link:onTap(nil, {pos = {x = 363, y = 585}})
|
|
UIManager:run()
|
|
assert.is.same(22, readerui.paging.current_page)
|
|
end)
|
|
|
|
it("should jump to links in pdf scroll mode", function()
|
|
UIManager:quit()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
}
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
|
readerui.paging:onGotoPage(1)
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
readerui.link:onTap(nil, {pos = {x = 250, y = 534}})
|
|
UIManager:run()
|
|
-- its really hard to get the exact page number in scroll mode
|
|
-- page positions may have unexpected impact on page number
|
|
assert.truthy(readerui.paging.current_page == 21
|
|
or readerui.paging.current_page == 20)
|
|
end)
|
|
|
|
it("should be able to go back after link jump in epub #nocov", function()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
}
|
|
readerui.rolling:onGotoPage(6)
|
|
readerui.link:onTap(nil, {pos = {x = 336, y = 166}})
|
|
assert.is.same(40, readerui.rolling.current_page)
|
|
readerui.link:onGoBackLink()
|
|
assert.is.same(6, readerui.rolling.current_page)
|
|
end)
|
|
|
|
it("should be able to go back after link jump in pdf page mode", function()
|
|
UIManager:quit()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
}
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
|
readerui.paging:onGotoPage(1)
|
|
readerui.link:onTap(nil, {pos = {x = 363, y = 585}})
|
|
UIManager:run()
|
|
assert.is.same(22, readerui.paging.current_page)
|
|
readerui.link:onGoBackLink()
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
end)
|
|
|
|
it("should be able to go back after link jump in pdf scroll mode", function()
|
|
UIManager:quit()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
}
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
|
readerui.paging:onGotoPage(1)
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
readerui.link:onTap(nil, {pos = {x = 250, y = 534}})
|
|
UIManager:run()
|
|
assert.truthy(readerui.paging.current_page == 21
|
|
or readerui.paging.current_page == 20)
|
|
readerui.link:onGoBackLink()
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
end)
|
|
|
|
it("should be able to go back to the same position after link jump in pdf scroll mode", function()
|
|
UIManager:quit()
|
|
local expected_page_states = {
|
|
{
|
|
gamma = 1,
|
|
offset = {x = 17, y = 0},
|
|
page = 3,
|
|
page_area = {
|
|
x = 0, y = 0,
|
|
h = 800, w = 566,
|
|
},
|
|
rotation = 0,
|
|
visible_area = {
|
|
x = 0, y = 694,
|
|
h = 106, w = 566,
|
|
},
|
|
zoom = 0.9501187648456056456,
|
|
},
|
|
{
|
|
gamma = 1,
|
|
offset = {x = 17, y = 0},
|
|
page = 4,
|
|
page_area = {
|
|
h = 800, w = 566,
|
|
x = 0, y = 0,
|
|
},
|
|
rotation = 0,
|
|
visible_area = {
|
|
h = 686, w = 566,
|
|
x = 0, y = 0,
|
|
},
|
|
zoom = 0.9501187648456056456,
|
|
},
|
|
}
|
|
-- disable footer
|
|
G_reader_settings:saveSetting("reader_footer_mode", 0)
|
|
require("docsettings"):open(sample_pdf):purge()
|
|
local readerui = ReaderUI:new{
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
}
|
|
assert.is.falsy(readerui.view.footer_visible)
|
|
readerui.paging:onGotoPage(1)
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
readerui.view:onSetScrollMode(true)
|
|
assert.is.same(true, readerui.view.page_scroll)
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
readerui.paging:onTapForward()
|
|
assert.is.same(2, readerui.paging.current_page)
|
|
readerui.paging:onTapForward()
|
|
assert.is.same(3, readerui.paging.current_page)
|
|
readerui.paging:onTapForward()
|
|
assert.is.same(4, readerui.paging.current_page)
|
|
assert.are.same(expected_page_states, readerui.view.page_states)
|
|
readerui.link:onTap(nil, {pos = {x = 181, y = 366}})
|
|
UIManager:run()
|
|
assert.is.same(22, readerui.paging.current_page)
|
|
readerui.link:onGoBackLink()
|
|
assert.is.same(3, readerui.paging.current_page)
|
|
assert.are.same(expected_page_states, readerui.view.page_states)
|
|
end)
|
|
end)
|