mirror of
https://github.com/koreader/koreader
synced 2024-11-11 19:11:14 +00:00
Merge branch 'new_ui_code' into hint_page_fix
Conflicts: frontend/ui/reader/readerview.lua
This commit is contained in:
commit
79839021ed
@ -1,5 +1,75 @@
|
|||||||
require "ui/geometry"
|
require "ui/geometry"
|
||||||
|
|
||||||
|
CreOptions = {
|
||||||
|
prefix = 'copt',
|
||||||
|
default_options = {
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon = "resources/icons/appbar.column.two.large.png",
|
||||||
|
options = {
|
||||||
|
{
|
||||||
|
name = "line_spacing",
|
||||||
|
name_text = "Line Spacing",
|
||||||
|
item_text = {"decrease", "increase"},
|
||||||
|
args = {"decrease", "increase"},
|
||||||
|
default_arg = nil,
|
||||||
|
event = "ChangeLineSpace",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon = "resources/icons/appbar.text.size.large.png",
|
||||||
|
options = {
|
||||||
|
{
|
||||||
|
name = "font_size",
|
||||||
|
item_text = {"Aa", "Aa", "Aa", "Aa", "Aa", "Aa", "Aa", "Aa"},
|
||||||
|
item_align_center = 1.0,
|
||||||
|
spacing = Screen:getWidth()*0.03,
|
||||||
|
item_font_size = {18, 20, 22, 24, 29, 33, 39, 44},
|
||||||
|
values = {18, 20, 22, 24, 29, 33, 39, 44},
|
||||||
|
default_value = 1,
|
||||||
|
event = "SetFontSize",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon = "resources/icons/appbar.grade.b.large.png",
|
||||||
|
options = {
|
||||||
|
{
|
||||||
|
name = "font_weight",
|
||||||
|
name_text = "Font weight",
|
||||||
|
item_text = {"toggle bolder"},
|
||||||
|
-- args is indeed not used, we put here just to keep the
|
||||||
|
-- UI happy.
|
||||||
|
args = {1},
|
||||||
|
default_arg = nil,
|
||||||
|
event = "ToggleFontBolder",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "font_gamma",
|
||||||
|
name_text = "Gamma",
|
||||||
|
item_text = {"decrease", "increase"},
|
||||||
|
args = {"decrease", "increase"},
|
||||||
|
default_arg = nil,
|
||||||
|
event = "ChangeFontGamma",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon = "resources/icons/appbar.settings.large.png",
|
||||||
|
options = {
|
||||||
|
{
|
||||||
|
name = "view_mode",
|
||||||
|
name_text = "View mode",
|
||||||
|
item_text = {"scroll", "page"},
|
||||||
|
args = {"scroll", "page"},
|
||||||
|
default_arg = "page",
|
||||||
|
event = "SetViewMode",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
CreDocument = Document:new{
|
CreDocument = Document:new{
|
||||||
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
||||||
SCROLL_VIEW_MODE = 0,
|
SCROLL_VIEW_MODE = 0,
|
||||||
@ -10,6 +80,8 @@ CreDocument = Document:new{
|
|||||||
|
|
||||||
line_space_percent = 100,
|
line_space_percent = 100,
|
||||||
default_font = "Droid Sans Fallback",
|
default_font = "Droid Sans Fallback",
|
||||||
|
options = CreOptions,
|
||||||
|
configurable = Configurable,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- NuPogodi, 20.05.12: inspect the zipfile content
|
-- NuPogodi, 20.05.12: inspect the zipfile content
|
||||||
@ -54,6 +126,7 @@ end
|
|||||||
|
|
||||||
function CreDocument:init()
|
function CreDocument:init()
|
||||||
self:engineInit()
|
self:engineInit()
|
||||||
|
self.configurable:loadDefaults(self.options)
|
||||||
|
|
||||||
local ok
|
local ok
|
||||||
local file_type = string.lower(string.match(self.file, ".+%.([^.]+)"))
|
local file_type = string.lower(string.match(self.file, ".+%.([^.]+)"))
|
||||||
@ -83,6 +156,7 @@ function CreDocument:init()
|
|||||||
self.is_open = true
|
self.is_open = true
|
||||||
self.info.has_pages = false
|
self.info.has_pages = false
|
||||||
self:_readMetadata()
|
self:_readMetadata()
|
||||||
|
self.info.configurable = true
|
||||||
|
|
||||||
-- @TODO read line_space_percent from setting file 12.06 2012 (houqp)
|
-- @TODO read line_space_percent from setting file 12.06 2012 (houqp)
|
||||||
--self._document:setDefaultInterlineSpace(self.line_space_percent)
|
--self._document:setDefaultInterlineSpace(self.line_space_percent)
|
||||||
@ -165,6 +239,16 @@ function CreDocument:setFontSize(new_font_size)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CreDocument:setViewMode(new_mode)
|
||||||
|
if new_mode then
|
||||||
|
if new_mode == "scroll" then
|
||||||
|
self._document:setViewMode(self.SCROLL_VIEW_MODE)
|
||||||
|
else
|
||||||
|
self._document:setViewMode(self.PAGE_VIEW_MODE)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function CreDocument:zoomFont(delta)
|
function CreDocument:zoomFont(delta)
|
||||||
self._document:zoomFont(delta)
|
self._document:zoomFont(delta)
|
||||||
end
|
end
|
||||||
@ -173,6 +257,10 @@ function CreDocument:setInterlineSpacePercent(percent)
|
|||||||
self._document:setDefaultInterlineSpace(percent)
|
self._document:setDefaultInterlineSpace(percent)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CreDocument:toggleFontBolder()
|
||||||
|
self._document:toggleFontBolder()
|
||||||
|
end
|
||||||
|
|
||||||
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
||||||
DocumentRegistry:addProvider("epub", "application/epub", CreDocument)
|
DocumentRegistry:addProvider("epub", "application/epub", CreDocument)
|
||||||
DocumentRegistry:addProvider("html", "application/html", CreDocument)
|
DocumentRegistry:addProvider("html", "application/html", CreDocument)
|
||||||
|
@ -85,9 +85,13 @@ function OptionTextItem:onTapSelect()
|
|||||||
end
|
end
|
||||||
self[1].color = 15
|
self[1].color = 15
|
||||||
local option_value = nil
|
local option_value = nil
|
||||||
|
local option_arg = nil
|
||||||
if type(self.values) == "table" then
|
if type(self.values) == "table" then
|
||||||
option_value = self.values[self.current_item]
|
option_value = self.values[self.current_item]
|
||||||
self.config:onConfigChoice(self.name, option_value, self.event)
|
self.config:onConfigChoice(self.name, option_value, self.event)
|
||||||
|
elseif type(self.args) == "table" then
|
||||||
|
option_arg = self.args[self.current_item]
|
||||||
|
self.config:onConfigChoice(self.name, option_arg, self.event)
|
||||||
end
|
end
|
||||||
UIManager.repaint_all = true
|
UIManager.repaint_all = true
|
||||||
return true
|
return true
|
||||||
@ -159,18 +163,28 @@ function ConfigOption:init()
|
|||||||
-- make current index according to configurable table
|
-- make current index according to configurable table
|
||||||
local current_item = nil
|
local current_item = nil
|
||||||
if self.options[c].name then
|
if self.options[c].name then
|
||||||
local val = self.config.configurable[self.options[c].name]
|
if self.options[c].values then
|
||||||
local min_diff = math.abs(val - self.options[c].values[1])
|
local val = self.config.configurable[self.options[c].name]
|
||||||
local diff = nil
|
local min_diff = math.abs(val - self.options[c].values[1])
|
||||||
for index, val_ in pairs(self.options[c].values) do
|
local diff = nil
|
||||||
if val == val_ then
|
for index, val_ in pairs(self.options[c].values) do
|
||||||
current_item = index
|
if val == val_ then
|
||||||
break
|
current_item = index
|
||||||
|
break
|
||||||
|
end
|
||||||
|
diff = math.abs(val - val_)
|
||||||
|
if diff <= min_diff then
|
||||||
|
min_diff = diff
|
||||||
|
current_item = index
|
||||||
|
end
|
||||||
end
|
end
|
||||||
diff = math.abs(val - val_)
|
elseif self.options[c].args then
|
||||||
if diff <= min_diff then
|
local arg = self.config.configurable[self.options[c].name]
|
||||||
min_diff = diff
|
for idx, arg_ in pairs(self.options[c].args) do
|
||||||
current_item = index
|
if arg_ == arg then
|
||||||
|
current_item = idx
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -200,6 +214,8 @@ function ConfigOption:init()
|
|||||||
option_item.items = option_items
|
option_item.items = option_items
|
||||||
option_item.name = self.options[c].name
|
option_item.name = self.options[c].name
|
||||||
option_item.values = self.options[c].values
|
option_item.values = self.options[c].values
|
||||||
|
option_item.args = self.options[c].args
|
||||||
|
option_item.event = self.options[c].event
|
||||||
option_item.current_item = d
|
option_item.current_item = d
|
||||||
option_item.config = self.config
|
option_item.config = self.config
|
||||||
table.insert(option_items_group, option_item)
|
table.insert(option_items_group, option_item)
|
||||||
|
@ -19,6 +19,9 @@ function Configurable:loadDefaults(config_options)
|
|||||||
for j=1,#config_options[i].options do
|
for j=1,#config_options[i].options do
|
||||||
local key = config_options[i].options[j].name
|
local key = config_options[i].options[j].name
|
||||||
self[key] = config_options[i].options[j].default_value
|
self[key] = config_options[i].options[j].default_value
|
||||||
|
if not self[key] then
|
||||||
|
self[key] = config_options[i].options[j].default_arg
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
ReaderFont = InputContainer:new{
|
ReaderFont = InputContainer:new{
|
||||||
font_face = nil,
|
font_face = nil,
|
||||||
font_size = nil,
|
font_size = nil,
|
||||||
line_space_percent = 100,
|
line_space_percent = nil,
|
||||||
font_menu_title = "Font Menu",
|
font_menu_title = "Font Menu",
|
||||||
face_table = nil,
|
face_table = nil,
|
||||||
|
-- default gamma from crengine's lvfntman.cpp
|
||||||
|
gamma_index = 15,
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReaderFont:init()
|
function ReaderFont:init()
|
||||||
@ -60,6 +62,12 @@ function ReaderFont:onReadSettings(config)
|
|||||||
self.font_size = self.ui.document:getFontSize()
|
self.font_size = self.ui.document:getFontSize()
|
||||||
end
|
end
|
||||||
self.ui.document:setFontSize(self.font_size)
|
self.ui.document:setFontSize(self.font_size)
|
||||||
|
|
||||||
|
self.line_space_percent = config:readSetting("line_space_percent")
|
||||||
|
if not self.line_space_percent then
|
||||||
|
self.line_space_percent = 100
|
||||||
|
end
|
||||||
|
|
||||||
-- Dirty hack: we have to add folloing call in order to set
|
-- Dirty hack: we have to add folloing call in order to set
|
||||||
-- m_is_rendered(member of LVDocView) to true. Otherwise position inside
|
-- m_is_rendered(member of LVDocView) to true. Otherwise position inside
|
||||||
-- document will be reset to 0 on first view render.
|
-- document will be reset to 0 on first view render.
|
||||||
@ -101,8 +109,10 @@ function ReaderFont:onChangeSize(direction)
|
|||||||
delta = -1
|
delta = -1
|
||||||
end
|
end
|
||||||
self.font_size = self.font_size + delta
|
self.font_size = self.font_size + delta
|
||||||
msg = InfoMessage:new{text = direction.." font size to "..self.font_size}
|
UIManager:show(Notification:new{
|
||||||
UIManager:show(msg)
|
text = direction.." font size to "..self.font_size,
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
self.ui.document:zoomFont(delta)
|
self.ui.document:zoomFont(delta)
|
||||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||||
UIManager:close(msg)
|
UIManager:close(msg)
|
||||||
@ -110,6 +120,21 @@ function ReaderFont:onChangeSize(direction)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onSetFontSize(new_size)
|
||||||
|
if new_size > 44 then new_size = 44 end
|
||||||
|
if new_size < 18 then new_size = 18 end
|
||||||
|
|
||||||
|
self.font_size = new_size
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = "Set font size to "..self.font_size,
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
self.ui.document:setFontSize(new_size)
|
||||||
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderFont:onChangeLineSpace(direction)
|
function ReaderFont:onChangeLineSpace(direction)
|
||||||
if direction == "decrease" then
|
if direction == "decrease" then
|
||||||
self.line_space_percent = self.line_space_percent - 10
|
self.line_space_percent = self.line_space_percent - 10
|
||||||
@ -119,23 +144,51 @@ function ReaderFont:onChangeLineSpace(direction)
|
|||||||
self.line_space_percent = self.line_space_percent + 10
|
self.line_space_percent = self.line_space_percent + 10
|
||||||
self.line_space_percent = math.min(self.line_space_percent, 200)
|
self.line_space_percent = math.min(self.line_space_percent, 200)
|
||||||
end
|
end
|
||||||
msg = InfoMessage:new{"line spacing "..self.line_space_percent.."%"}
|
UIManager:show(Notification:new{
|
||||||
|
text = direction.." line space to "..self.line_space_percent.."%",
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
|
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
|
||||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onToggleFontBolder()
|
||||||
|
self.ui.document:toggleFontBolder()
|
||||||
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onChangeFontGamma(direction)
|
||||||
|
if direction == "increase" then
|
||||||
|
cre.setGammaIndex(self.gamma_index+2)
|
||||||
|
elseif direction == "decrease" then
|
||||||
|
cre.setGammaIndex(self.gamma_index-2)
|
||||||
|
end
|
||||||
|
self.gamma_index = cre.getGammaIndex()
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = direction.." gamma to "..self.gamma_index,
|
||||||
|
timeout = 1
|
||||||
|
})
|
||||||
|
self.ui:handleEvent(Event:new("RedrawCurrentView"))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderFont:onCloseDocument()
|
function ReaderFont:onCloseDocument()
|
||||||
|
--@TODO save gamma index (houqp)
|
||||||
self.ui.doc_settings:saveSetting("font_face", self.font_face)
|
self.ui.doc_settings:saveSetting("font_face", self.font_face)
|
||||||
self.ui.doc_settings:saveSetting("font_size", self.font_size)
|
self.ui.doc_settings:saveSetting("font_size", self.font_size)
|
||||||
|
self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderFont:setFont(face)
|
function ReaderFont:setFont(face)
|
||||||
if face and self.font_face ~= face then
|
if face and self.font_face ~= face then
|
||||||
self.font_face = face
|
self.font_face = face
|
||||||
msg = InfoMessage:new{ text = "Redrawing with "..face }
|
UIManager:show(Notification:new{
|
||||||
UIManager:show(msg)
|
text = "redrawing with font "..face,
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
|
||||||
self.ui.document:setFontFace(face)
|
self.ui.document:setFontFace(face)
|
||||||
-- signal readerrolling to update pos in new height
|
-- signal readerrolling to update pos in new height
|
||||||
|
@ -230,4 +230,5 @@ end
|
|||||||
|
|
||||||
function ReaderPaging:onRedrawCurrentPage()
|
function ReaderPaging:onRedrawCurrentPage()
|
||||||
self.ui:handleEvent(Event:new("PageUpdate", self.current_page))
|
self.ui:handleEvent(Event:new("PageUpdate", self.current_page))
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
@ -19,10 +19,10 @@ function ReaderRolling:init()
|
|||||||
GestureRange:new{
|
GestureRange:new{
|
||||||
ges = "tap",
|
ges = "tap",
|
||||||
range = Geom:new{
|
range = Geom:new{
|
||||||
x = Screen:getWidth()/2,
|
x = Screen:getWidth()/4,
|
||||||
y = Screen:getHeight()/2,
|
y = Screen:getHeight()/4,
|
||||||
w = Screen:getWidth(),
|
w = 3*Screen:getWidth()/4,
|
||||||
h = Screen:getHeight()
|
h = 5*Screen:getHeight()/8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -31,9 +31,9 @@ function ReaderRolling:init()
|
|||||||
ges = "tap",
|
ges = "tap",
|
||||||
range = Geom:new{
|
range = Geom:new{
|
||||||
x = 0,
|
x = 0,
|
||||||
y = Screen:getHeight()/2,
|
y = Screen:getHeight()/4,
|
||||||
w = Screen:getWidth()/2,
|
w = Screen:getWidth()/4,
|
||||||
h = Screen:getHeight()/2,
|
h = 5*Screen:getHeight()/8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ function ReaderRolling:onZoom()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
remember to signal this event the document has been zoomed,
|
remember to signal this event when the document has been zoomed,
|
||||||
font has been changed, or line height has been changed.
|
font has been changed, or line height has been changed.
|
||||||
--]]
|
--]]
|
||||||
function ReaderRolling:onUpdatePos()
|
function ReaderRolling:onUpdatePos()
|
||||||
@ -179,6 +179,19 @@ function ReaderRolling:onUpdatePos()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderRolling:onSetViewMode(new_mode)
|
||||||
|
self.ui.view_mode = new_mode
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderRolling:onRedrawCurrentView()
|
||||||
|
if self.view_mode == "page" then
|
||||||
|
self.ui:handleEvent(Event:new("PageUpdate", self.current_page))
|
||||||
|
else
|
||||||
|
self.ui:handleEvent(Event:new("PosUpdate", self.current_pos))
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
PosUpdate event is used to signal other widgets that pos has been changed.
|
PosUpdate event is used to signal other widgets that pos has been changed.
|
||||||
--]]
|
--]]
|
||||||
|
@ -165,6 +165,13 @@ end
|
|||||||
|
|
||||||
function ReaderView:onHintPage()
|
function ReaderView:onHintPage()
|
||||||
self.ui.document:hintPage(self.state.page+1, self.state.zoom, self.state.rotation, self.render_mode)
|
self.ui.document:hintPage(self.state.page+1, self.state.zoom, self.state.rotation, self.render_mode)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderView:onSetViewMode(new_mode)
|
||||||
|
self.ui.view_mode = new_mode
|
||||||
|
self.ui.document:setViewMode(new_mode)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderView:onCloseDocument()
|
function ReaderView:onCloseDocument()
|
||||||
|
Loading…
Reference in New Issue
Block a user