diff --git a/defaults.lua b/defaults.lua index 396bf842e..1893c6876 100644 --- a/defaults.lua +++ b/defaults.lua @@ -34,6 +34,10 @@ DCREREADER_VIEW_MODE = "page" -- default to false DSHOWOVERLAP = false +-- show hidden files in filemanager +-- default to false +DSHOWHIDDENFILES = false + -- koptreader config defaults DKOPTREADER_CONFIG_FONT_SIZE = 1.0 -- range from 0.1 to 3.0 DKOPTREADER_CONFIG_TEXT_WRAP = 0 -- 1 = on, 0 = off @@ -52,9 +56,9 @@ DKOPTREADER_CONFIG_CONTRAST = 1.0 -- range from 0.2 to 2.0 DKOPTREADER_CONFIG_WORD_SAPCINGS = {0.05, 0.15, 0.375} -- range from 0.05 to 0.5 DKOPTREADER_CONFIG_DEFAULT_WORD_SAPCING = 0.15 -- range from 0.05 to 0.5 -- document languages for OCR -DKOPTREADER_CONFIG_DOC_LANGS_TEXT = {"English", "Chinese_S", "Chinese_T"} -DKOPTREADER_CONFIG_DOC_LANGS_CODE = {"eng", "chi_sim", "chi_tra"} -- ISO 639-3 language string, -DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE = "eng" -- and make sure you have corresponding training data +DKOPTREADER_CONFIG_DOC_LANGS_TEXT = {"English", "Chinese"} +DKOPTREADER_CONFIG_DOC_LANGS_CODE = {"eng", "chi_sim"} -- language code, make sure you have corresponding training data +DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE = "eng" -- that have filenames starting with the language codes -- gesture detector defaults DGESDETECT_DISABLE_DOUBLE_TAP = true diff --git a/frontend/dbg.lua b/frontend/dbg.lua index 3d373685b..d87b6f299 100644 --- a/frontend/dbg.lua +++ b/frontend/dbg.lua @@ -36,3 +36,6 @@ function LvDEBUG(lv, ...) print("#"..line) end +function DEBUGBT() + DEBUG(debug.traceback()) +end diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 917124ef7..eeadb287f 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -28,6 +28,14 @@ function DocumentRegistry:openDocument(file) end end +TileCacheItem = CacheItem:new{} + +function TileCacheItem:onFree() + if self.bb.free then + DEBUG("free blitbuffer", self.bb) + self.bb:free() + end +end --[[ This is an abstract interface to a document @@ -216,7 +224,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode) end -- prepare cache item with contained blitbuffer - local tile = CacheItem:new{ + local tile = TileCacheItem:new{ size = size.w * size.h / 2 + 64, -- estimation excerpt = size, pageno = pageno, @@ -296,7 +304,6 @@ function Document:getPageText(pageno) return text end - -- load implementations: require "document/pdfdocument" diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index eb8fab15d..51a03ca3d 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -100,7 +100,7 @@ end --[[ auto detect bbox --]] -function KoptInterface:getAutoBBox(doc, pageno) +function KoptInterface:getAutoBBox(doc, pageno) local native_size = Document.getNativePageDimensions(doc, pageno) local bbox = { x0 = 0, y0 = 0, @@ -113,8 +113,9 @@ function KoptInterface:getAutoBBox(doc, pageno) if not cached then local page = doc._document:openPage(pageno) local kc = self:createContext(doc, pageno, bbox) + --DEBUGBT() bbox.x0, bbox.y0, bbox.x1, bbox.y1 = page:getAutoBBox(kc) - DEBUG("Auto detected bbox", bbox) + --DEBUG("Auto detected bbox", bbox) Cache:insert(hash, CacheItem:new{ autobbox = bbox }) page:close() kc:free() @@ -212,6 +213,8 @@ function KoptInterface:getRFPageDimensions(doc, pageno, zoom, rotation) end function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, render_mode) + --DEBUG("log memory usage at renderPage") + --self:logMemoryUsage(pageno) if doc.configurable.text_wrap == 1 then return self:renderreflowedPage(doc, pageno, rect, zoom, rotation, render_mode) else @@ -240,7 +243,7 @@ function KoptInterface:renderreflowedPage(doc, pageno, rect, zoom, rotation, ren end local page = doc._document:openPage(pageno) -- prepare cache item with contained blitbuffer - local tile = CacheItem:new{ + local tile = TileCacheItem:new{ size = fullwidth * fullheight / 2 + 64, -- estimation excerpt = Geom:new{ w = fullwidth, h = fullheight }, pageno = pageno, @@ -604,7 +607,6 @@ end get word and word box from position in native page ]]-- function KoptInterface:getWordFromNativePosition(doc, boxes, pos) - DEBUG("boxes", boxes) local native_word_box = self:getWordFromBoxes(boxes, pos) local word_box = { word = native_word_box.word, @@ -726,7 +728,7 @@ end helper functions --]] function KoptInterface:logReflowDuration(pageno, dur) - local file = io.open("reflowlog.txt", "a+") + local file = io.open("reflow_dur_log.txt", "a+") if file then if file:seek("end") == 0 then -- write the header only once file:write("PAGE\tDUR\n") @@ -735,3 +737,25 @@ function KoptInterface:logReflowDuration(pageno, dur) file:close() end end + +function KoptInterface:logMemoryUsage(pageno) + local status_file = io.open("/proc/self/status", "r") + local log_file = io.open("reflow_mem_log.txt", "a+") + local data = -1 + if status_file then + for line in status_file:lines() do + local s, n + s, n = line:gsub("VmData:%s-(%d+) kB", "%1") + if n ~= 0 then data = tonumber(s) end + if data ~= -1 then break end + end + status_file:close() + end + if log_file then + if log_file:seek("end") == 0 then -- write the header only once + log_file:write("PAGE\tMEM\n") + end + log_file:write(string.format("%s\t%s\n", pageno, data)) + log_file:close() + end +end diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index db93869ff..dd4f0a775 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -24,6 +24,7 @@ KoptOptions = { { name = "trim_page", name_text = PAGE_CROP_STR, + width = 225, toggle = {MANUAL_STR, AUTO_STR, SEMIAUTO_STR}, alternate = false, values = {0, 1, 2}, @@ -187,7 +188,7 @@ KoptOptions = { name = "defect_size", name_text = DEFECT_SIZE_STR, toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR}, - values = {1.0, 8.0, 15.0}, + values = {1.0, 3.0, 5.0}, default_value = DKOPTREADER_CONFIG_DEFECT_SIZE, event = "DefectSizeUpdate", }, diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 4a43e89a4..ac4460d44 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -99,7 +99,8 @@ function Device:isKobo() end function Device:hasNoKeyboard() - return self:isTouchDevice() or (self:getModel() == "Kindle4") + local model = self:getModel() + return (model == "KindlePaperWhite") or (model == "KindleTouch") or self:isKobo() end function Device:hasKeyboard() diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index c97038363..e7564f353 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -434,7 +434,6 @@ function ReaderView:onSetScreenMode(new_mode, rotation) if new_mode == "landscape" and self.document.info.has_pages then self.ui:handleEvent(Event:new("SetZoomMode", "contentwidth")) - self.ui:handleEvent(Event:new("InitScrollPageStates")) end return true end @@ -482,6 +481,7 @@ function ReaderView:onReadSettings(config) self.render_mode = config:readSetting("render_mode") or 0 local screen_mode = config:readSetting("screen_mode") if screen_mode then + Screen:setScreenMode(screen_mode) table.insert(self.ui.postInitCallback, function() self:onSetScreenMode(screen_mode, config:readSetting("rotation_mode")) end) diff --git a/frontend/ui/widget/config.lua b/frontend/ui/widget/config.lua index 2bcb3bf97..001439a7e 100644 --- a/frontend/ui/widget/config.lua +++ b/frontend/ui/widget/config.lua @@ -323,6 +323,7 @@ function ConfigOption:init() if self.options[c].toggle then local switch = ToggleSwitch:new{ + width = scaleByDPI(self.options[c].width or 216), name = self.options[c].name, toggle = self.options[c].toggle, alternate = self.options[c].alternate, diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 86cd45afe..cb042f4d3 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -6,7 +6,7 @@ FileChooser = Menu:extend{ no_title = true, path = lfs.currentdir(), parent = nil, - show_hidden = false, + show_hidden = DSHOWHIDDENFILES, filter = function(filename) return true end, } diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 2d71a99b4..dcc200fb6 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -32,6 +32,7 @@ function ItemShortCutIcon:init() end --@TODO calculate font size by icon size 01.05 2012 (houqp) + local sc_face = nil if self.key:len() > 1 then sc_face = Font:getFace("ffont", 14) else @@ -49,6 +50,7 @@ function ItemShortCutIcon:init() TextWidget:new{ text = self.key, face = sc_face, + bgcolor = background/15, }, }, } @@ -123,7 +125,8 @@ function MenuItem:init() doc = "Select Menu Item", }, } - else + end + if Device:hasKeyboard() then self.active_key_events = { Select = { {"Press"}, doc = "chose selected item" }, } @@ -261,6 +264,10 @@ function Menu:_recalculateDimen() } self.perpage = math.floor((self.dimen.h - self.dimen.x) / self.item_dimen.h) - 2 self.page_num = math.ceil(#self.item_table / self.perpage) + -- update page info layout, fixed #281 + if self.page_info then + self.page_info:resetLayout() + end end function Menu:init() @@ -374,7 +381,8 @@ function Menu:init() range = self.dimen, } } - else + end + if Device:hasKeyboard() then -- set up keyboard events self.key_events.Close = { {"Back"}, doc = _("close menu") } self.key_events.NextPage = { diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index 620ad5059..47a31819a 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -11,6 +11,8 @@ end ToggleSwitch = InputContainer:new{ width = scaleByDPI(216), height = scaleByDPI(30), + bgcolor = 0, -- unfoused item color + fgcolor = 7, -- focused item color } function ToggleSwitch:init() @@ -65,13 +67,13 @@ function ToggleSwitch:update() local pos = self.position for i=1,#self.toggle_content do if pos == i then - self.toggle_content[i].color = 7 - self.toggle_content[i].background = 7 - self.toggle_content[i][1][1].bgcolor = 0.5 + self.toggle_content[i].color = self.fgcolor + self.toggle_content[i].background = self.fgcolor + self.toggle_content[i][1][1].bgcolor = self.fgcolor/15 self.toggle_content[i][1][1].fgcolor = 0.0 else - self.toggle_content[i].color = 0 - self.toggle_content[i].background = 0 + self.toggle_content[i].color = self.bgcolor + self.toggle_content[i].background = self.bgcolor self.toggle_content[i][1][1].bgcolor = 0.0 self.toggle_content[i][1][1].fgcolor = 1.0 end