mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Merge pull request #1983 from koreader/houqp-master
fix end of book detection for crengine
This commit is contained in:
@@ -5,7 +5,7 @@ source "${CI_DIR}/common.sh"
|
||||
|
||||
set +e
|
||||
|
||||
make coverage
|
||||
travis_retry make coverage
|
||||
pushd koreader-*/koreader
|
||||
luajit $(which luacov-coveralls) -v
|
||||
popd
|
||||
|
||||
5
Makefile
5
Makefile
@@ -107,7 +107,10 @@ test:
|
||||
$(MAKE) testfront
|
||||
|
||||
coverage: $(INSTALL_DIR)/koreader/.luacov
|
||||
cd $(INSTALL_DIR)/koreader && ./luajit $(shell which busted) -o verbose_print --coverage --exclude-tags=nocov
|
||||
cd $(INSTALL_DIR)/koreader && \
|
||||
./luajit $(shell which busted) -o verbose_print \
|
||||
--no-auto-insulate \
|
||||
--coverage --exclude-tags=nocov
|
||||
# coverage report summary
|
||||
cd $(INSTALL_DIR)/koreader && tail -n \
|
||||
+$$(($$(grep -nm1 Summary luacov.report.out|cut -d: -f1)-1)) \
|
||||
|
||||
2
base
2
base
Submodule base updated: b5c82144e2...02c4e24e73
@@ -295,7 +295,7 @@ function ReaderFooter:updateFooterText()
|
||||
|
||||
if #ticks_candidates > 0 then
|
||||
self.progress_bar.ticks = ticks_candidates[1]
|
||||
self.progress_bar.last = self.pages
|
||||
self.progress_bar.last = self.pages or self.view.document:getPageCount()
|
||||
else
|
||||
-- we still set ticks here so self.progress_bar.ticks will not be
|
||||
-- initialized again if ticks_candidates is empty
|
||||
|
||||
@@ -357,11 +357,6 @@ end
|
||||
|
||||
function ReaderRolling:onGotoViewRel(diff)
|
||||
DEBUG("goto relative screen:", diff, ", in mode: ", self.view.view_mode)
|
||||
local prev_xp
|
||||
-- save xpointer to check whether we reach the end of the book
|
||||
if diff > 0 then
|
||||
prev_xp = self.xpointer
|
||||
end
|
||||
if self.view.view_mode == "scroll" then
|
||||
local pan_diff = diff * self.ui.dimen.h
|
||||
if self.show_overlap_enable then
|
||||
@@ -371,15 +366,20 @@ function ReaderRolling:onGotoViewRel(diff)
|
||||
pan_diff = pan_diff + self.overlap
|
||||
end
|
||||
end
|
||||
local old_pos = self.current_pos
|
||||
self:_gotoPos(self.current_pos + pan_diff)
|
||||
if diff > 0 and old_pos == self.current_pos then
|
||||
self.ui:handleEvent(Event:new("EndOfBook"))
|
||||
end
|
||||
elseif self.view.view_mode == "page" then
|
||||
local page_count = self.ui.document:getVisiblePageCount()
|
||||
local old_page = self.current_page
|
||||
self:_gotoPage(self.current_page + diff*page_count)
|
||||
if diff > 0 and old_page == self.current_page then
|
||||
self.ui:handleEvent(Event:new("EndOfBook"))
|
||||
end
|
||||
end
|
||||
self.xpointer = self.ui.document:getXPointer()
|
||||
if self.xpointer == prev_xp then
|
||||
self.ui:handleEvent(Event:new("EndOfBook"))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ function BookStatusWidget:init()
|
||||
self.stats = {
|
||||
total_time_in_sec = 0,
|
||||
performance_in_pages = {},
|
||||
pages = self.document:getPageCount(),
|
||||
total_pages = self.document:getPageCount(),
|
||||
}
|
||||
self:getStatisticsSettings()
|
||||
if self.settings then
|
||||
@@ -123,8 +123,8 @@ function BookStatusWidget:getStatHours(stats)
|
||||
end
|
||||
|
||||
function BookStatusWidget:getReadPages(stats)
|
||||
if stats and stats.performance_in_pages and stats.pages then
|
||||
return util.tableSize(stats.performance_in_pages) .. "/" .. stats.pages
|
||||
if stats and stats.performance_in_pages and stats.total_pages then
|
||||
return util.tableSize(stats.performance_in_pages) .. "/" .. stats.total_pages
|
||||
end
|
||||
return "none"
|
||||
end
|
||||
@@ -253,12 +253,14 @@ function BookStatusWidget:genBookInfoGroup()
|
||||
}
|
||||
)
|
||||
-- progress bar
|
||||
local total_pages = self.document:getPageCount()
|
||||
local total_pages = self.stats.total_pages
|
||||
local read_percentage = self.view.state.page / total_pages
|
||||
local progress_bar = ProgressWidget:new{
|
||||
width = width * 0.7,
|
||||
height = Screen:scaleBySize(10),
|
||||
percentage = read_percentage,
|
||||
ticks = nil,
|
||||
last = nil,
|
||||
}
|
||||
table.insert(book_meta_info_group,
|
||||
CenterContainer:new{
|
||||
|
||||
@@ -14,7 +14,7 @@ Configurable attributes:
|
||||
* rectcolor -- infill color
|
||||
* ticks (list) -- default to nil, use this if you want to insert markers
|
||||
* tick_width
|
||||
* last -- maximum tick
|
||||
* last -- maximum tick, used with ticks
|
||||
|
||||
Example:
|
||||
|
||||
@@ -68,7 +68,7 @@ function ProgressWidget:paintTo(bb, x, y)
|
||||
bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize),
|
||||
math.ceil((my_size.w-2*self.margin_h)*self.percentage),
|
||||
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
|
||||
if self.ticks then
|
||||
if self.ticks and self.last then
|
||||
for i=1, #self.ticks do
|
||||
bb:paintRect(
|
||||
x + (my_size.w-2*self.margin_h)*(self.ticks[i]/self.last),
|
||||
|
||||
@@ -20,12 +20,14 @@ describe("Readerrolling module", function()
|
||||
it("should goto portrait screen mode", function()
|
||||
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
|
||||
end)
|
||||
|
||||
it("should goto certain page", function()
|
||||
for i = 1, 10, 5 do
|
||||
rolling:onGotoPage(i)
|
||||
assert.are.same(i, rolling.current_page)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should goto relative page", function()
|
||||
for i = 20, 40, 5 do
|
||||
rolling:onGotoPage(i)
|
||||
@@ -35,6 +37,7 @@ describe("Readerrolling module", function()
|
||||
assert.are.same(i, rolling.current_page)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should goto next chapter", function()
|
||||
local toc = readerui.toc
|
||||
for i = 30, 50, 5 do
|
||||
@@ -43,6 +46,7 @@ describe("Readerrolling module", function()
|
||||
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
|
||||
end
|
||||
end)
|
||||
|
||||
it("should goto previous chapter", function()
|
||||
local toc = readerui.toc
|
||||
for i = 60, 80, 5 do
|
||||
@@ -51,18 +55,58 @@ describe("Readerrolling module", function()
|
||||
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
|
||||
end
|
||||
end)
|
||||
it("should emit EndOfBook event at the end", function()
|
||||
rolling:onGotoPage(readerui.document:getPageCount())
|
||||
|
||||
it("should emit EndOfBook event at the end of sample epub", function()
|
||||
local called = false
|
||||
readerui.onEndOfBook = function()
|
||||
called = true
|
||||
end
|
||||
-- check beginning of the book
|
||||
rolling:onGotoPage(1)
|
||||
assert.is.falsy(called)
|
||||
rolling:onGotoViewRel(-1)
|
||||
rolling:onGotoViewRel(-1)
|
||||
assert.is.falsy(called)
|
||||
-- check end of the book
|
||||
rolling:onGotoPage(readerui.document:getPageCount())
|
||||
assert.is.falsy(called)
|
||||
rolling:onGotoViewRel(1)
|
||||
assert.is.truthy(called)
|
||||
rolling:onGotoViewRel(1)
|
||||
assert.is.truthy(called)
|
||||
readerui.onEndOfBook = nil
|
||||
end)
|
||||
|
||||
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{
|
||||
document = DocumentRegistry:openDocument(sample_txt),
|
||||
}
|
||||
local called = false
|
||||
txt_readerui.onEndOfBook = function()
|
||||
called = true
|
||||
end
|
||||
local txt_rolling = txt_readerui.rolling
|
||||
-- check beginning of the book
|
||||
txt_rolling:onGotoPage(1)
|
||||
assert.is.falsy(called)
|
||||
txt_rolling:onGotoViewRel(-1)
|
||||
txt_rolling:onGotoViewRel(-1)
|
||||
assert.is.falsy(called)
|
||||
-- not at the end of the book
|
||||
txt_rolling:onGotoPage(3)
|
||||
assert.is.falsy(called)
|
||||
txt_rolling:onGotoViewRel(1)
|
||||
assert.is.falsy(called)
|
||||
-- at the end of the book
|
||||
txt_rolling:onGotoPage(txt_readerui.document:getPageCount())
|
||||
assert.is.falsy(called)
|
||||
txt_rolling:onGotoViewRel(1)
|
||||
assert.is.truthy(called)
|
||||
readerui.onEndOfBook = nil
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("test in landscape screen mode", function()
|
||||
it("should go to landscape screen mode", function()
|
||||
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
|
||||
@@ -110,6 +154,7 @@ describe("Readerrolling module", function()
|
||||
readerui.onEndOfBook = nil
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("switching screen mode should not change current page number", function()
|
||||
it("for portrait-landscape-portrait switching", function()
|
||||
for i = 80, 100, 10 do
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
require("commonrequire")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
describe("Menu widget", function()
|
||||
local Menu, dbg
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
Menu = require("ui/widget/menu")
|
||||
dbg = require("dbg")
|
||||
end)
|
||||
|
||||
it("should convert item table from touch menu properly", function()
|
||||
local cb1 = function() end
|
||||
local cb2 = function() end
|
||||
|
||||
18
spec/unit/widget_progresswidget_spec.lua
Normal file
18
spec/unit/widget_progresswidget_spec.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
describe("ProgressWidget widget", function()
|
||||
local ProgressWidget, Screen
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
ProgressWidget = require("ui/widget/progresswidget")
|
||||
Screen = require("device").screen
|
||||
end)
|
||||
|
||||
it("should not crash with nil self.last #ok", function()
|
||||
local progress = ProgressWidget:new{
|
||||
width = 100,
|
||||
height = 50,
|
||||
percentage = 5/100,
|
||||
ticks = {1},
|
||||
}
|
||||
progress:paintTo(Screen.bb, 0, 0)
|
||||
end)
|
||||
end)
|
||||
94
test/sample.txt
Normal file
94
test/sample.txt
Normal file
@@ -0,0 +1,94 @@
|
||||
Lorem ipsum
|
||||
Dolor sit amet, foo@bar.com
|
||||
v0.1, 99 September 7999
|
||||
|
||||
Lorem ipsum dolor sit amet, pri id laudem vulputate disputando, ad mea
|
||||
pericula consetetur. Nusquam detraxit ad sed, tritani mandamus aliquando et
|
||||
has, porro graeco at pri. Sale denique ut sit, mel suas erroribus repudiare
|
||||
ea. Vim probo dicit consequuntur te.
|
||||
______________________________________________________________________
|
||||
|
||||
Table of Contents
|
||||
|
||||
|
||||
1. Eos ex eius iusto delicata
|
||||
|
||||
2. Illum argumentum sed a
|
||||
|
||||
3. In eum magna iusto integre
|
||||
|
||||
|
||||
|
||||
______________________________________________________________________
|
||||
|
||||
1. Eos ex eius iusto delicata
|
||||
|
||||
|
||||
Eos ex eius iusto delicata, ius ne facer invenire electram, cu mel assum
|
||||
novum efficiendi. Duo enim eleifend te. Elitr nihil vivendo vix ex, ex homero
|
||||
salutatus sed, ea nec posse commune consetetur. Ea iusto labore docendi his,
|
||||
at per mollis mentitum. Ex esse recteque eos, ex iudicabit gloriatur mei.
|
||||
|
||||
Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue:
|
||||
|
||||
1. Maecenas nec odio et ante tincidunt tempus.
|
||||
|
||||
2. Donec sodales sagittis magna.
|
||||
|
||||
3. Phasellus viverra nulla ut metus varius laoreet.
|
||||
|
||||
Li Europan lingues es membres del sam familie. Lor separat existentie es un
|
||||
myth.
|
||||
|
||||
It va esser tam simplic quam Occidental in fact, it va esser Occidental. A un
|
||||
Angleso it va semblar un simplificat Angles, quam un skeptic Cambridge amico
|
||||
dit me que Occidental es.Li Europan lingues es membres del sam familie. Lor
|
||||
separat existentie es un myth. Por scientie, musica, sport etc, litot Europa
|
||||
usa li sam vocabular. Li lingues differe solmen in li grammatica, li
|
||||
pronunciation e li plu commun vocabules. Omnicos directe al desirabilite de
|
||||
un nov lingua franca: On refusa continuar payar custosi traductores. At
|
||||
solmen va esser necessi far uniform grammatica, pronunciation e plu sommun
|
||||
paroles.
|
||||
|
||||
|
||||
2. Illum argumentum sed a
|
||||
|
||||
Illum argumentum sed ad, vel accumsan noluisse eu. Nam ne minimum consulatu,
|
||||
vim nullam quidam ut. Ea pro temporibus ullamcorper, at case aeque vix. Est
|
||||
id consetetur intellegam. Eu cum oratio gubergren, aeque tritani feugiat vel
|
||||
te.
|
||||
|
||||
· Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
|
||||
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
|
||||
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
|
||||
|
||||
· Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam
|
||||
nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas
|
||||
nulla pariatur?
|
||||
|
||||
cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod
|
||||
maxime placeat facere.
|
||||
|
||||
To install the tar.gz source, use the commands:
|
||||
|
||||
______________________________________________________________________
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
______________________________________________________________________
|
||||
|
||||
|
||||
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed
|
||||
quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
|
||||
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
|
||||
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
|
||||
et dolore magnam aliquam quaerat voluptatem.
|
||||
|
||||
|
||||
3. In eum magna iusto integre
|
||||
|
||||
In eum magna iusto integre, cu solet commodo constituto pro. Te nec tota
|
||||
altera, diam periculis ius eu, eum te velit partiendo conclusionemque. Diam
|
||||
mnesarchum at usu, agam nonumes at nec. Vix aliquip liberavisse ex, nam at
|
||||
quis choro accusam. Eu his zril graecis, latine legendos inimicus eum at, qui
|
||||
te adolescens adipiscing.
|
||||
Reference in New Issue
Block a user