From 18122fe067949b3eaa8bb79924254e366e5cd79f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 1 Jul 2013 02:41:33 -0400 Subject: [PATCH 1/3] add defaults.lua --- frontend/cache.lua | 8 ++- frontend/defaults.lua | 95 +++++++++++++++++++++++++++++ frontend/document/koptinterface.lua | 10 +-- frontend/ui/data/koptoptions.lua | 27 ++++---- frontend/ui/reader/readerview.lua | 14 ++--- frontend/ui/uimanager.lua | 3 +- 6 files changed, 128 insertions(+), 29 deletions(-) create mode 100644 frontend/defaults.lua diff --git a/frontend/cache.lua b/frontend/cache.lua index 2425b9102..6fedfa371 100644 --- a/frontend/cache.lua +++ b/frontend/cache.lua @@ -1,6 +1,10 @@ --[[ Inheritable abstraction for cache items -]]-- +--]] + +require "defaults" + + CacheItem = { size = 64, -- some reasonable default for simple Lua values / small tables } @@ -20,7 +24,7 @@ A global LRU cache ]]-- Cache = { -- cache configuration: - max_memsize = 1024*1024*10, -- 10MB cache size + max_memsize = DGLOBAL_CACHE_SIZE, -- cache state: current_memsize = 0, -- associative cache diff --git a/frontend/defaults.lua b/frontend/defaults.lua new file mode 100644 index 000000000..ad480da93 --- /dev/null +++ b/frontend/defaults.lua @@ -0,0 +1,95 @@ +-- number of page turns between full screen refresh +-- default to full refresh on every page turn +DRCOUNTMAX = 6 + +-- default gamma setting: +DGLOBALGAMMA = 1.0 + +-- DjVu page rendering mode (used in djvu.c:drawPage()) +-- See comments in djvureader.lua:DJVUReader:select_render_mode() +DRENDER_MODE = 0 -- 0 is COLOUR + +DGLOBAL_CACHE_SIZE = 1024*1024*10 + +-- background colour in non scroll mode: 8 = gray, 0 = white, 15 = black +DBACKGROUND_COLOR = 0 + +-- outer page colour in scroll mode: 8 = gray, 0 = white, 15 = black +DOUTER_PAGE_COLOR = 0 + +-- supported view mode includes: "scroll" and "page" +DCREREADER_VIEW_MODE = "page" + +-- 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 +DKOPTREADER_CONFIG_TRIM_PAGE = 1 -- 1 = auto, 0 = manual +DKOPTREADER_CONFIG_DETECT_INDENT = 1 -- 1 = enable, 0 = disable +DKOPTREADER_CONFIG_DEFECT_SIZE = 1.0 -- range from 0.0 to 3.0 +DKOPTREADER_CONFIG_PAGE_MARGIN = 0.10 -- range from 0.0 to 1.0 +DKOPTREADER_CONFIG_LINE_SPACING = 1.2 -- range from 0.5 to 2.0 +DKOPTREADER_CONFIG_WORD_SAPCING = 0.15 -- range from 0.05 to 0.5 +DKOPTREADER_CONFIG_RENDER_QUALITY = 0.8 -- range from 0.5 to 1.0 +DKOPTREADER_CONFIG_AUTO_STRAIGHTEN = 0 -- range from 0 to 10 +DKOPTREADER_CONFIG_JUSTIFICATION = -1 -- -1 = auto, 0 = left, 1 = center, 2 = right, 3 = full +DKOPTREADER_CONFIG_MAX_COLUMNS = 2 -- range from 1 to 4 +DKOPTREADER_CONFIG_CONTRAST = 1.0 -- range from 0.2 to 2.0 + + +-- #################################################################### +-- following features are not supported right now +-- #################################################################### + +-- set panning distance +--DSHIFT_X = 100 +--DSHIFT_Y = 50 + +-- step to change zoom manually, default = 16% +--DSTEP_MANUAL_ZOOM = 16 +--DPAN_BY_PAGE = false -- using shift_[xy] or width/height +--DPAN_MARGIN = 5 -- horizontal margin for two-column zoom (in pixels) +--DPAN_OVERLAP_VERTICAL = 30 + +-- tile cache configuration: +--DCACHE_MAX_MEMSIZE = 1024*1024*5 -- 5MB tile cache +--DCACHE_MAX_TTL = 20 -- time to live + +-- renderer cache size +--DCACHE_DOCUMENT_SIZE = 1024*1024*8 -- FIXME random, needs testing + +-- default value for battery level logging +--DBATTERY_LOGGING = false + + +-- delay for info messages in ms +--DINFO_NODELAY=0 +--DINFO_DELAY=1500 + +-- toggle defaults +--DUNIREADER_SHOW_OVERLAP_ENABLE = true +--DUNIREADER_SHOW_LINKS_ENABLE = true +--DUNIREADER_COMICS_MODE_ENABLE = true +--DUNIREADER_RTL_MODE_ENABLE = false +--DUNIREADER_PAGE_MODE_ENABLE = false + +--DDJVUREADER_SHOW_OVERLAP_ENABLE = true +--DDJVUREADER_SHOW_LINKS_ENABLE = false +--DDJVUREADER_COMICS_MODE_ENABLE = true +--DDJVUREADER_RTL_MODE_ENABLE = false +--DDJVUREADER_PAGE_MODE_ENABLE = false + +--DKOPTREADER_SHOW_OVERLAP_ENABLE = true +--DKOPTREADER_SHOW_LINKS_ENABLE = false +--DKOPTREADER_COMICS_MODE_ENABLE = false +--DKOPTREADER_RTL_MODE_ENABLE = false +--DKOPTREADER_PAGE_MODE_ENABLE = false + +--DPICVIEWER_SHOW_OVERLAP_ENABLE = false +--DPICVIEWER_SHOW_LINKS_ENABLE = false +--DPICVIEWER_COMICS_MODE_ENABLE = true +--DPICVIEWER_RTL_MODE_ENABLE = false +--DPICVIEWER_PAGE_MODE_ENABLE = false + + +--DKOPTREADER_CONFIG_MULTI_THREADS = 1 -- 1 = on, 0 = off +--DKOPTREADER_CONFIG_SCREEN_ROTATION = 0 -- 0, 90, 180, 270 degrees diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index c9df1e10e..e40ddcd81 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -196,7 +196,7 @@ end --[[ get cached koptcontext for centain page. if context doesn't exist in cache make -new context and reflow the src page immediatly, or wait background thread for +new context and reflow the src page immediatly, or wait background thread for reflowed context. --]] function KoptInterface:getCachedContext(doc, pageno) @@ -272,10 +272,10 @@ function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, render_mode end --[[ -inherited from common document interface -render reflowed page into cache in background thread. this method returns immediatly -leaving the precache flag on in context. subsequent usage of this context should -wait for the precache flag off by calling self:waitForContext(kctx) +inherited from common document interface render reflowed page into cache in +background thread. this method returns immediatly leaving the precache flag on +in context. subsequent usage of this context should wait for the precache flag +off by calling self:waitForContext(kctx) --]] function KoptInterface:hintPage(doc, pageno, zoom, rotation, gamma, render_mode) local bbox = doc:getPageBBox(pageno) diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 29d0f6e55..7e5c6dc40 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -1,5 +1,6 @@ require "ui/screen" require "ui/data/strings" +require "defaults" KoptOptions = { prefix = 'kopt', @@ -26,7 +27,7 @@ KoptOptions = { toggle = {AUTO_STR, MANUAL_STR}, alternate = false, values = {1, 0}, - default_value = 1, + default_value = DKOPTREADER_CONFIG_TRIM_PAGE, event = "PageCrop", args = {"auto", "manual"}, } @@ -58,7 +59,7 @@ KoptOptions = { name_text = PAGE_MARGIN_STR, toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR}, values = {0.05, 0.10, 0.15}, - default_value = 0.10, + default_value = DKOPTREADER_CONFIG_PAGE_MARGIN, event = "MarginUpdate", }, { @@ -66,7 +67,7 @@ KoptOptions = { name_text = LINE_SPACING_STR, toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR}, values = {1.0, 1.2, 1.4}, - default_value = 1.2, + default_value = DKOPTREADER_CONFIG_LINE_SPACING, }, { name = "max_columns", @@ -77,7 +78,7 @@ KoptOptions = { "resources/icons/appbar.column.three.png", }, values = {1,2,3}, - default_value = 2, + default_value = DKOPTREADER_CONFIG_MAX_COLUMNS, }, { name = "justification", @@ -90,7 +91,7 @@ KoptOptions = { "resources/icons/appbar.align.justify.png", }, values = {-1,0,1,2,3}, - default_value = -1, + default_value = DKOPTREADER_CONFIG_JUSTIFICATION, }, } }, @@ -105,7 +106,7 @@ KoptOptions = { height = 60, item_font_size = {22,24,28,32,34,36,38,42,46,50}, values = {0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0, 4.0}, - default_value = 1.0, + default_value = DKOPTREADER_CONFIG_FONT_SIZE, event = "FontSizeUpdate", }, { @@ -132,7 +133,7 @@ KoptOptions = { item_font_size = 18, item_align_center = 0.8, values = {2.0, 1.5, 1.0, 0.5, 0.2}, - default_value = 1.0, + default_value = DKOPTREADER_CONFIG_CONTRAST, event = "GammaUpdate", args = {0.5, 0.8, 1.0, 2.0, 4.0}, } @@ -146,7 +147,7 @@ KoptOptions = { name_text = _("Reflow"), toggle = {ON_STR, OFF_STR}, values = {1, 0}, - default_value = 0, + default_value = DKOPTREADER_CONFIG_TEXT_WRAP, events = { { event = "RedrawCurrentPage", @@ -171,14 +172,14 @@ KoptOptions = { name_text = WORD_GAP_STR, toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR}, values = {0.05, 0.15, 0.375}, - default_value = 0.15, + default_value = DKOPTREADER_CONFIG_WORD_SAPCING, }, { name = "defect_size", name_text = DEFECT_SIZE_STR, toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR}, values = {1.0, 8.0, 15.0}, - default_value = 1.0, + default_value = DKOPTREADER_CONFIG_DEFECT_SIZE, event = "DefectSizeUpdate", }, { @@ -186,21 +187,21 @@ KoptOptions = { name_text = RENDER_QUALITY_STR, toggle = {LOW_STR, DEFAULT_STR, HIGH_STR}, values={0.5, 1.0, 1.5}, - default_value = 0.8, + default_value = DKOPTREADER_CONFIG_RENDER_QUALITY, }, { name = "auto_straighten", name_text = AUTO_STRAIGHTEN_STR, toggle = {ZERO_DEG_STR, FIVE_DEG_STR, TEN_DEG_STR}, values = {0, 5, 10}, - default_value = 0, + default_value = DKOPTREADER_CONFIG_AUTO_STRAIGHTEN, }, { name = "detect_indent", name_text = INDENTATION_STR, toggle = {ON_STR, OFF_STR}, values = {1, 0}, - default_value = 1, + default_value = DKOPTREADER_CONFIG_DETECT_INDENT, show = false, }, } diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index 4608f23d9..ed176f6c9 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -1,6 +1,7 @@ require "ui/reader/readerflip" require "ui/reader/readerfooter" require "ui/reader/readerdogear" +require "defaults" ReaderView = OverlapGroup:new{ document = nil, @@ -15,7 +16,7 @@ ReaderView = OverlapGroup:new{ offset = nil, bbox = nil, }, - outer_page_color = 0, + outer_page_color = DOUTER_PAGE_COLOR, -- hightlight highlight = { lighten_color = 0.2, -- color range [0.0, 1.0] @@ -27,7 +28,7 @@ ReaderView = OverlapGroup:new{ highlight_visible = true, -- PDF/DjVu continuous paging page_scroll = nil, - page_bgcolor = 0, + page_bgcolor = DBACKGROUND_COLOR, page_states = {}, scroll_mode = "vertical", page_gap = { @@ -36,9 +37,9 @@ ReaderView = OverlapGroup:new{ color = 8, }, -- DjVu page rendering mode (used in djvu.c:drawPage()) - render_mode = 0, -- default to COLOR + render_mode = DRENDER_MODE, -- default to COLOR -- Crengine view mode - view_mode = "page", -- default to page mode + view_mode = DCREREADER_VIEW_MODE, -- default to page mode hinting = true, -- visible area within current viewing page @@ -105,17 +106,14 @@ function ReaderView:paintTo(bb, x, y) self.dim_area.w, self.dim_area.h ) end - -- draw saved highlight if self.highlight_visible then self:drawSavedHighlight(bb, x, y) end - -- draw temporary highlight if self.highlight.temp then self:drawTempHighlight(bb, x, y) end - -- paint dogear if self.dogear_visible then self.dogear:paintTo(bb, x, y) @@ -478,7 +476,7 @@ function ReaderView:onReadSettings(config) table.insert(self.ui.postInitCallback, function() self:onSetScreenMode(screen_mode) end) end - self.state.gamma = config:readSetting("gamma") or 1.0 + self.state.gamma = config:readSetting("gamma") or DGLOBALGAMMA local full_screen = config:readSetting("kopt_full_screen") if full_screen == nil then full_screen = self.document.configurable.full_screen diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index b30964024..ff0ee116e 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -4,6 +4,7 @@ require "ui/inputevent" require "ui/screen" require "debug" require "gettext" +require "defaults" -- initialize output module, this must be initialized before Input Screen:init() @@ -23,7 +24,7 @@ UIManager = { -- after each ui loop full_refresh = false, -- trigger a full refresh when counter reaches FULL_REFRESH_COUNT - FULL_REFRESH_COUNT = 6, + FULL_REFRESH_COUNT = DRCOUNTMAX, refresh_count = 0, _running = true, From 561c7902ca2dd2b981721f82be815238dae067aa Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 1 Jul 2013 02:55:28 -0400 Subject: [PATCH 2/3] move defaults.lua to root directory --- Makefile | 1 + frontend/defaults.lua => defaults.lua | 0 frontend/cache.lua | 2 -- frontend/ui/data/koptoptions.lua | 1 - frontend/ui/reader/readerview.lua | 1 - frontend/ui/uimanager.lua | 1 - reader.lua | 1 + 7 files changed, 2 insertions(+), 5 deletions(-) rename frontend/defaults.lua => defaults.lua (100%) diff --git a/Makefile b/Makefile index 93eedc669..71bbecf81 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ bootstrapemu: test -e $(EMU_DIR)/history || (mkdir $(EMU_DIR)/history) test -e $(EMU_DIR)/$(MO_DIR) || (cd $(EMU_DIR) && ln -s ../$(MO_DIR) ./) test -e $(EMU_DIR)/ev_replay.py || (cd $(EMU_DIR) && ln -s ../$(KOR_BASE)/ev_replay.py ./) + test -e $(EMU_DIR)/defaults.lua || (cd $(EMU_DIR) && ln -s ../defaults.lua ./) customupdate: all # ensure that the binaries were built for ARM diff --git a/frontend/defaults.lua b/defaults.lua similarity index 100% rename from frontend/defaults.lua rename to defaults.lua diff --git a/frontend/cache.lua b/frontend/cache.lua index 6fedfa371..92f9f42f0 100644 --- a/frontend/cache.lua +++ b/frontend/cache.lua @@ -2,8 +2,6 @@ Inheritable abstraction for cache items --]] -require "defaults" - CacheItem = { size = 64, -- some reasonable default for simple Lua values / small tables diff --git a/frontend/ui/data/koptoptions.lua b/frontend/ui/data/koptoptions.lua index 7e5c6dc40..da4eaa0fb 100644 --- a/frontend/ui/data/koptoptions.lua +++ b/frontend/ui/data/koptoptions.lua @@ -1,6 +1,5 @@ require "ui/screen" require "ui/data/strings" -require "defaults" KoptOptions = { prefix = 'kopt', diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index ed176f6c9..7358df8af 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -1,7 +1,6 @@ require "ui/reader/readerflip" require "ui/reader/readerfooter" require "ui/reader/readerdogear" -require "defaults" ReaderView = OverlapGroup:new{ document = nil, diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index ff0ee116e..962b95915 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -4,7 +4,6 @@ require "ui/inputevent" require "ui/screen" require "debug" require "gettext" -require "defaults" -- initialize output module, this must be initialized before Input Screen:init() diff --git a/reader.lua b/reader.lua index e4c04ab8a..e90860bab 100755 --- a/reader.lua +++ b/reader.lua @@ -1,5 +1,6 @@ #!./koreader-base +require "defaults" package.path = "./frontend/?.lua" package.cpath = "/usr/lib/lua/?.so" require "ui/uimanager" From 84801e6f51af8f3eaca3b65c66c5e01cdb852638 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 1 Jul 2013 02:58:06 -0400 Subject: [PATCH 3/3] add defaults.lua in customupdate --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 71bbecf81..6dcd9630d 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ customupdate: all cp -r git-rev resources $(INSTALL_DIR) rm -r $(INSTALL_DIR)/resources/fonts cp -rpL frontend $(INSTALL_DIR) + cp defaults.lua $(INSTALL_DIR) mkdir $(INSTALL_DIR)/fonts/host zip -9 -r koreader-$(VERSION).zip $(INSTALL_DIR) launchpad/ extensions/ rm -rf $(INSTALL_DIR)