mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
feat: add logger module & rewrite kobo suspend script in lua
This commit is contained in:
@@ -6,7 +6,7 @@ local DataStorage = require("datastorage")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("device").screen
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local logger = require("logger")
|
||||
local ffi = require("ffi")
|
||||
|
||||
local CreDocument = Document:new{
|
||||
@@ -61,7 +61,7 @@ function CreDocument:engineInit()
|
||||
if not _v:find("/urw/") then
|
||||
local ok, err = pcall(cre.registerFont, _v)
|
||||
if not ok then
|
||||
DEBUG(err)
|
||||
logger.err("failed to register crengine font", err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -157,9 +157,9 @@ end
|
||||
|
||||
function CreDocument:getWordFromPosition(pos)
|
||||
local word_box = self._document:getWordFromPosition(pos.x, pos.y)
|
||||
DEBUG("CreDocument: get word box", word_box)
|
||||
logger.dbg("CreDocument: get word box", word_box)
|
||||
local text_range = self._document:getTextFromPositions(pos.x, pos.y, pos.x, pos.y)
|
||||
DEBUG("CreDocument: get text range", text_range)
|
||||
logger.dbg("CreDocument: get text range", text_range)
|
||||
local wordbox = {
|
||||
word = text_range.text == "" and word_box.word or text_range.text,
|
||||
page = self._document:getCurrentPage(),
|
||||
@@ -182,7 +182,7 @@ end
|
||||
|
||||
function CreDocument:getTextFromPositions(pos0, pos1)
|
||||
local text_range = self._document:getTextFromPositions(pos0.x, pos0.y, pos1.x, pos1.y)
|
||||
DEBUG("CreDocument: get text range", text_range)
|
||||
logger.dbg("CreDocument: get text range", text_range)
|
||||
if text_range then
|
||||
-- local line_boxes = self:getScreenBoxesFromPositions(text_range.pos0, text_range.pos1)
|
||||
return {
|
||||
@@ -198,7 +198,6 @@ function CreDocument:getScreenBoxesFromPositions(pos0, pos1)
|
||||
local line_boxes = {}
|
||||
if pos0 and pos1 then
|
||||
local word_boxes = self._document:getWordBoxesFromPositions(pos0, pos1)
|
||||
-- DEBUG("word boxes", word_boxes)
|
||||
for i = 1, #word_boxes do
|
||||
local line_box = word_boxes[i]
|
||||
table.insert(line_boxes, Geom:new{
|
||||
@@ -207,7 +206,6 @@ function CreDocument:getScreenBoxesFromPositions(pos0, pos1)
|
||||
h = line_box.y1 - line_box.y0,
|
||||
})
|
||||
end
|
||||
--DEBUG("line boxes", line_boxes)
|
||||
end
|
||||
return line_boxes
|
||||
end
|
||||
@@ -244,7 +242,7 @@ function CreDocument:renderPage(pageno, rect, zoom, rotation)
|
||||
end
|
||||
|
||||
function CreDocument:gotoXPointer(xpointer)
|
||||
DEBUG("CreDocument: goto xpointer", xpointer)
|
||||
logger.dbg("CreDocument: goto xpointer", xpointer)
|
||||
self._document:gotoXPointer(xpointer)
|
||||
end
|
||||
|
||||
@@ -277,27 +275,27 @@ function CreDocument:getLinkFromPosition(pos)
|
||||
end
|
||||
|
||||
function Document:gotoPos(pos)
|
||||
DEBUG("CreDocument: goto position", pos)
|
||||
logger.dbg("CreDocument: goto position", pos)
|
||||
self._document:gotoPos(pos)
|
||||
end
|
||||
|
||||
function CreDocument:gotoPage(page)
|
||||
DEBUG("CreDocument: goto page", page)
|
||||
logger.dbg("CreDocument: goto page", page)
|
||||
self._document:gotoPage(page)
|
||||
end
|
||||
|
||||
function CreDocument:gotoLink(link)
|
||||
DEBUG("CreDocument: goto link", link)
|
||||
logger.dbg("CreDocument: goto link", link)
|
||||
self._document:gotoLink(link)
|
||||
end
|
||||
|
||||
function CreDocument:goBack()
|
||||
DEBUG("CreDocument: go back")
|
||||
logger.dbg("CreDocument: go back")
|
||||
self._document:goBack()
|
||||
end
|
||||
|
||||
function CreDocument:goForward(link)
|
||||
DEBUG("CreDocument: go forward")
|
||||
logger.dbg("CreDocument: go forward")
|
||||
self._document:goForward()
|
||||
end
|
||||
|
||||
@@ -307,20 +305,20 @@ end
|
||||
|
||||
function CreDocument:setFontFace(new_font_face)
|
||||
if new_font_face then
|
||||
DEBUG("CreDocument: set font face", new_font_face)
|
||||
logger.dbg("CreDocument: set font face", new_font_face)
|
||||
self._document:setStringProperty("font.face.default", new_font_face)
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:setHyphDictionary(new_hyph_dictionary)
|
||||
if new_hyph_dictionary then
|
||||
DEBUG("CreDocument: set hyphenation dictionary", new_hyph_dictionary)
|
||||
logger.dbg("CreDocument: set hyphenation dictionary", new_hyph_dictionary)
|
||||
self._document:setStringProperty("crengine.hyphenation.directory", new_hyph_dictionary)
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:clearSelection()
|
||||
DEBUG("clear selection")
|
||||
logger.dbg("clear selection")
|
||||
self._document:clearSelection()
|
||||
end
|
||||
|
||||
@@ -330,14 +328,14 @@ end
|
||||
|
||||
function CreDocument:setFontSize(new_font_size)
|
||||
if new_font_size then
|
||||
DEBUG("CreDocument: set font size", new_font_size)
|
||||
logger.dbg("CreDocument: set font size", new_font_size)
|
||||
self._document:setFontSize(new_font_size)
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:setViewMode(new_mode)
|
||||
if new_mode then
|
||||
DEBUG("CreDocument: set view mode", new_mode)
|
||||
logger.dbg("CreDocument: set view mode", new_mode)
|
||||
if new_mode == "scroll" then
|
||||
self._document:setViewMode(self.SCROLL_VIEW_MODE)
|
||||
else
|
||||
@@ -347,50 +345,50 @@ function CreDocument:setViewMode(new_mode)
|
||||
end
|
||||
|
||||
function CreDocument:setViewDimen(dimen)
|
||||
DEBUG("CreDocument: set view dimen", dimen)
|
||||
logger.dbg("CreDocument: set view dimen", dimen)
|
||||
self._document:setViewDimen(dimen.w, dimen.h)
|
||||
end
|
||||
|
||||
function CreDocument:setHeaderFont(new_font)
|
||||
if new_font then
|
||||
DEBUG("CreDocument: set header font", new_font)
|
||||
logger.dbg("CreDocument: set header font", new_font)
|
||||
self._document:setHeaderFont(new_font)
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:zoomFont(delta)
|
||||
DEBUG("CreDocument: zoom font", delta)
|
||||
logger.dbg("CreDocument: zoom font", delta)
|
||||
self._document:zoomFont(delta)
|
||||
end
|
||||
|
||||
function CreDocument:setInterlineSpacePercent(percent)
|
||||
DEBUG("CreDocument: set interline space", percent)
|
||||
logger.dbg("CreDocument: set interline space", percent)
|
||||
self._document:setDefaultInterlineSpace(percent)
|
||||
end
|
||||
|
||||
function CreDocument:toggleFontBolder(toggle)
|
||||
DEBUG("CreDocument: toggle font bolder", toggle)
|
||||
logger.dbg("CreDocument: toggle font bolder", toggle)
|
||||
self._document:setIntProperty("font.face.weight.embolden", toggle)
|
||||
end
|
||||
|
||||
function CreDocument:setGammaIndex(index)
|
||||
DEBUG("CreDocument: set gamma index", index)
|
||||
logger.dbg("CreDocument: set gamma index", index)
|
||||
cre.setGammaIndex(index)
|
||||
end
|
||||
|
||||
function CreDocument:setStyleSheet(new_css)
|
||||
DEBUG("CreDocument: set style sheet", new_css)
|
||||
logger.dbg("CreDocument: set style sheet", new_css)
|
||||
self._document:setStyleSheet(new_css)
|
||||
end
|
||||
|
||||
function CreDocument:setEmbeddedStyleSheet(toggle)
|
||||
-- FIXME: occasional segmentation fault when switching embedded style sheet
|
||||
DEBUG("CreDocument: set embedded style sheet", toggle)
|
||||
logger.dbg("CreDocument: set embedded style sheet", toggle)
|
||||
self._document:setIntProperty("crengine.doc.embedded.styles.enabled", toggle)
|
||||
end
|
||||
|
||||
function CreDocument:setPageMargins(left, top, right, bottom)
|
||||
DEBUG("CreDocument: set page margins", left, top, right, bottom)
|
||||
logger.dbg("CreDocument: set page margins", left, top, right, bottom)
|
||||
self._document:setIntProperty("crengine.page.margin.left", left)
|
||||
self._document:setIntProperty("crengine.page.margin.top", top)
|
||||
self._document:setIntProperty("crengine.page.margin.right", right)
|
||||
@@ -399,7 +397,7 @@ end
|
||||
|
||||
function CreDocument:setFloatingPunctuation(enabled)
|
||||
-- FIXME: occasional segmentation fault when toggling floating punctuation
|
||||
DEBUG("CreDocument: set floating punctuation", enabled)
|
||||
logger.dbg("CreDocument: set floating punctuation", enabled)
|
||||
self._document:setIntProperty("crengine.style.floating.punctuation.enabled", enabled)
|
||||
end
|
||||
|
||||
@@ -408,27 +406,27 @@ function CreDocument:getVisiblePageCount()
|
||||
end
|
||||
|
||||
function CreDocument:setVisiblePageCount(new_count)
|
||||
DEBUG("CreDocument: set visible page count", new_count)
|
||||
logger.dbg("CreDocument: set visible page count", new_count)
|
||||
self._document:setVisiblePageCount(new_count)
|
||||
end
|
||||
|
||||
function CreDocument:setBatteryState(state)
|
||||
DEBUG("CreDocument: set battery state", state)
|
||||
logger.dbg("CreDocument: set battery state", state)
|
||||
self._document:setBatteryState(state)
|
||||
end
|
||||
|
||||
function CreDocument:isXPointerInCurrentPage(xp)
|
||||
DEBUG("CreDocument: check xpointer in current page", xp)
|
||||
logger.dbg("CreDocument: check xpointer in current page", xp)
|
||||
return self._document:isXPointerInCurrentPage(xp)
|
||||
end
|
||||
|
||||
function CreDocument:setStatusLineProp(prop)
|
||||
DEBUG("CreDocument: set status line property", prop)
|
||||
logger.dbg("CreDocument: set status line property", prop)
|
||||
self._document:setStringProperty("window.status.line", prop)
|
||||
end
|
||||
|
||||
function CreDocument:findText(pattern, origin, reverse, caseInsensitive)
|
||||
DEBUG("CreDocument: find text", pattern, origin, reverse, caseInsensitive)
|
||||
logger.dbg("CreDocument: find text", pattern, origin, reverse, caseInsensitive)
|
||||
return self._document:findText(
|
||||
pattern, origin, reverse, caseInsensitive and 1 or 0)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user