2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local Device = require("ui/device")
|
|
|
|
local Screen = require("ui/screen")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local ReaderFont = InputContainer:new{
|
2012-06-12 12:58:15 +00:00
|
|
|
font_face = nil,
|
|
|
|
font_size = nil,
|
2013-01-08 06:06:56 +00:00
|
|
|
line_space_percent = nil,
|
2013-04-08 07:00:46 +00:00
|
|
|
font_menu_title = _("Change font"),
|
2012-12-15 01:23:02 +00:00
|
|
|
face_table = nil,
|
2013-01-07 21:42:23 +00:00
|
|
|
-- default gamma from crengine's lvfntman.cpp
|
2013-01-13 03:49:01 +00:00
|
|
|
gamma_index = nil,
|
2012-06-12 10:04:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
function ReaderFont:init()
|
2013-10-16 12:56:18 +00:00
|
|
|
if Device:hasKeyboard() then
|
2012-12-13 18:32:16 +00:00
|
|
|
-- add shortcut for keyboard
|
|
|
|
self.key_events = {
|
2013-04-08 07:00:46 +00:00
|
|
|
ShowFontMenu = { {"F"}, doc = _("show font menu") },
|
2013-03-16 00:03:50 +00:00
|
|
|
IncreaseSize = {
|
|
|
|
{ "Shift", Input.group.PgFwd },
|
2013-04-08 07:00:46 +00:00
|
|
|
doc = _("increase font size"),
|
2012-12-13 18:32:16 +00:00
|
|
|
event = "ChangeSize", args = "increase" },
|
2013-03-16 00:03:50 +00:00
|
|
|
DecreaseSize = {
|
2012-12-13 18:32:16 +00:00
|
|
|
{ "Shift", Input.group.PgBack },
|
2013-04-08 07:00:46 +00:00
|
|
|
doc = _("decrease font size"),
|
2012-12-13 18:32:16 +00:00
|
|
|
event = "ChangeSize", args = "decrease" },
|
|
|
|
IncreaseLineSpace = {
|
|
|
|
{ "Alt", Input.group.PgFwd },
|
2013-04-08 07:00:46 +00:00
|
|
|
doc = _("increase line space"),
|
2012-12-13 18:32:16 +00:00
|
|
|
event = "ChangeLineSpace", args = "increase" },
|
|
|
|
DecreaseLineSpace = {
|
|
|
|
{ "Alt", Input.group.PgBack },
|
2013-04-08 07:00:46 +00:00
|
|
|
doc = _("decrease line space"),
|
2012-12-13 18:32:16 +00:00
|
|
|
event = "ChangeLineSpace", args = "decrease" },
|
|
|
|
}
|
|
|
|
end
|
2012-12-15 01:23:02 +00:00
|
|
|
-- build face_table for menu
|
|
|
|
self.face_table = {}
|
2012-12-13 18:32:16 +00:00
|
|
|
local face_list = cre.getFontFaces()
|
|
|
|
for k,v in ipairs(face_list) do
|
|
|
|
table.insert(self.face_table, {
|
|
|
|
text = v,
|
|
|
|
callback = function()
|
|
|
|
self:setFont(v)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
face_list[k] = {text = v}
|
|
|
|
end
|
2012-12-15 01:30:48 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2012-06-26 16:59:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFont:onSetDimensions(dimen)
|
|
|
|
self.dimen = dimen
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFont:onReadSettings(config)
|
|
|
|
self.font_face = config:readSetting("font_face")
|
2013-03-16 00:03:50 +00:00
|
|
|
if not self.font_face then
|
2012-12-17 07:01:31 +00:00
|
|
|
self.font_face = self.ui.document.default_font
|
2012-06-26 09:05:49 +00:00
|
|
|
end
|
2012-12-17 06:51:50 +00:00
|
|
|
self.ui.document:setFontFace(self.font_face)
|
2012-06-26 09:05:49 +00:00
|
|
|
|
2013-01-13 03:23:30 +00:00
|
|
|
self.header_font_face = config:readSetting("header_font_face")
|
2013-03-16 00:03:50 +00:00
|
|
|
if not self.header_font_face then
|
2013-01-13 03:23:30 +00:00
|
|
|
self.header_font_face = self.ui.document.header_font
|
|
|
|
end
|
|
|
|
self.ui.document:setHeaderFont(self.header_font_face)
|
|
|
|
|
2012-06-26 16:59:47 +00:00
|
|
|
self.font_size = config:readSetting("font_size")
|
2013-03-16 00:03:50 +00:00
|
|
|
if not self.font_size then
|
2013-01-13 02:22:33 +00:00
|
|
|
--@TODO change this! 12.01 2013 (houqp)
|
|
|
|
self.font_size = 29
|
2012-06-26 09:05:49 +00:00
|
|
|
end
|
2012-12-17 06:51:50 +00:00
|
|
|
self.ui.document:setFontSize(self.font_size)
|
2013-01-08 06:06:56 +00:00
|
|
|
|
|
|
|
self.line_space_percent = config:readSetting("line_space_percent")
|
2013-03-16 00:03:50 +00:00
|
|
|
if not self.line_space_percent then
|
2013-01-08 06:06:56 +00:00
|
|
|
self.line_space_percent = 100
|
2013-01-13 02:22:33 +00:00
|
|
|
else
|
2013-01-13 03:37:28 +00:00
|
|
|
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
|
2013-01-08 06:06:56 +00:00
|
|
|
end
|
|
|
|
|
2013-01-13 03:49:01 +00:00
|
|
|
self.gamma_index = config:readSetting("gamma_index")
|
2013-03-16 00:03:50 +00:00
|
|
|
if not self.gamma_index then
|
2013-01-13 03:49:01 +00:00
|
|
|
self.gamma_index = 15
|
|
|
|
end
|
|
|
|
self.ui.document:setGammaIndex(self.gamma_index)
|
|
|
|
|
2012-12-20 22:00:51 +00:00
|
|
|
-- Dirty hack: we have to add folloing call in order to set
|
|
|
|
-- m_is_rendered(member of LVDocView) to true. Otherwise position inside
|
|
|
|
-- document will be reset to 0 on first view render.
|
|
|
|
-- So far, I don't know why this call will alter the value of m_is_rendered.
|
2013-01-13 02:22:33 +00:00
|
|
|
table.insert(self.ui.postInitCallback, function()
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
end)
|
2012-06-12 12:58:15 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 10:04:08 +00:00
|
|
|
function ReaderFont:onShowFontMenu()
|
2012-12-13 18:32:16 +00:00
|
|
|
-- build menu widget
|
|
|
|
local main_menu = Menu:new{
|
|
|
|
title = self.font_menu_title,
|
|
|
|
item_table = self.face_table,
|
|
|
|
width = Screen:getWidth() - 100,
|
2012-06-12 10:04:08 +00:00
|
|
|
}
|
2012-12-13 18:32:16 +00:00
|
|
|
-- build container
|
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
main_menu,
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
2013-03-16 00:03:50 +00:00
|
|
|
main_menu.close_callback = function ()
|
2012-12-13 18:32:16 +00:00
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
|
|
|
-- show menu
|
|
|
|
UIManager:show(menu_container)
|
2012-06-12 12:58:15 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-12-22 05:27:46 +00:00
|
|
|
--[[
|
|
|
|
UpdatePos event is used to tell ReaderRolling to update pos.
|
|
|
|
--]]
|
2012-06-12 12:58:15 +00:00
|
|
|
function ReaderFont:onChangeSize(direction)
|
|
|
|
local delta = 1
|
2013-04-08 07:00:46 +00:00
|
|
|
local msg = ""
|
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
if direction == "decrease" then
|
|
|
|
delta = -1
|
2013-04-08 07:00:46 +00:00
|
|
|
msg = _("Decrease font size to ")
|
|
|
|
else
|
|
|
|
msg = _("Increase font size to ")
|
2012-06-12 12:58:15 +00:00
|
|
|
end
|
2013-04-08 07:00:46 +00:00
|
|
|
|
2012-06-12 12:58:15 +00:00
|
|
|
self.font_size = self.font_size + delta
|
2013-04-08 07:00:46 +00:00
|
|
|
|
2013-01-07 21:51:37 +00:00
|
|
|
UIManager:show(Notification:new{
|
2013-04-08 07:00:46 +00:00
|
|
|
text = msg..self.font_size,
|
2013-01-07 21:51:37 +00:00
|
|
|
timeout = 1,
|
|
|
|
})
|
2012-06-12 12:58:15 +00:00
|
|
|
self.ui.document:zoomFont(delta)
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
UIManager:close(msg)
|
|
|
|
|
|
|
|
return true
|
2012-06-12 10:04:08 +00:00
|
|
|
end
|
|
|
|
|
2013-01-07 04:21:11 +00:00
|
|
|
function ReaderFont:onSetFontSize(new_size)
|
|
|
|
if new_size > 44 then new_size = 44 end
|
2013-10-16 09:06:28 +00:00
|
|
|
if new_size < 16 then new_size = 16 end
|
2013-01-07 04:21:11 +00:00
|
|
|
|
|
|
|
self.font_size = new_size
|
2013-01-07 21:51:37 +00:00
|
|
|
UIManager:show(Notification:new{
|
2013-04-08 07:00:46 +00:00
|
|
|
text = _("Set font size to ")..self.font_size,
|
2013-01-07 21:51:37 +00:00
|
|
|
timeout = 1,
|
|
|
|
})
|
2013-10-16 09:06:28 +00:00
|
|
|
self.ui.document:setFontSize(scaleByDPI(new_size))
|
2013-01-07 04:21:11 +00:00
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-06-12 13:12:04 +00:00
|
|
|
function ReaderFont:onChangeLineSpace(direction)
|
2013-04-08 07:00:46 +00:00
|
|
|
local msg = ""
|
2012-06-12 13:12:04 +00:00
|
|
|
if direction == "decrease" then
|
|
|
|
self.line_space_percent = self.line_space_percent - 10
|
|
|
|
-- NuPogodi, 15.05.12: reduce lowest space_percent to 80
|
|
|
|
self.line_space_percent = math.max(self.line_space_percent, 80)
|
2013-04-08 07:00:46 +00:00
|
|
|
msg = _("Decrease line space to ")
|
2012-06-12 13:12:04 +00:00
|
|
|
else
|
|
|
|
self.line_space_percent = self.line_space_percent + 10
|
|
|
|
self.line_space_percent = math.min(self.line_space_percent, 200)
|
2013-04-08 07:00:46 +00:00
|
|
|
msg = _("Increase line space to ")
|
2012-06-12 13:12:04 +00:00
|
|
|
end
|
2013-01-07 21:51:37 +00:00
|
|
|
UIManager:show(Notification:new{
|
2013-04-08 07:00:46 +00:00
|
|
|
text = msg..self.line_space_percent.."%",
|
2013-01-07 21:51:37 +00:00
|
|
|
timeout = 1,
|
|
|
|
})
|
2012-06-12 13:12:04 +00:00
|
|
|
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-01-07 17:17:34 +00:00
|
|
|
function ReaderFont:onToggleFontBolder()
|
|
|
|
self.ui.document:toggleFontBolder()
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
2013-01-07 17:51:25 +00:00
|
|
|
return true
|
2013-01-07 17:17:34 +00:00
|
|
|
end
|
|
|
|
|
2013-01-07 21:42:23 +00:00
|
|
|
function ReaderFont:onChangeFontGamma(direction)
|
2013-04-08 07:00:46 +00:00
|
|
|
local msg = ""
|
2013-01-07 21:42:23 +00:00
|
|
|
if direction == "increase" then
|
|
|
|
cre.setGammaIndex(self.gamma_index+2)
|
2013-04-08 07:00:46 +00:00
|
|
|
msg = _("Increase gamma to ")
|
2013-01-07 21:42:23 +00:00
|
|
|
elseif direction == "decrease" then
|
|
|
|
cre.setGammaIndex(self.gamma_index-2)
|
2013-04-08 07:00:46 +00:00
|
|
|
msg = _("Decrease gamma to ")
|
2013-01-07 21:42:23 +00:00
|
|
|
end
|
|
|
|
self.gamma_index = cre.getGammaIndex()
|
|
|
|
UIManager:show(Notification:new{
|
2013-04-08 07:00:46 +00:00
|
|
|
text = msg..self.gamma_index,
|
2013-01-07 21:42:23 +00:00
|
|
|
timeout = 1
|
|
|
|
})
|
|
|
|
self.ui:handleEvent(Event:new("RedrawCurrentView"))
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-06-26 09:05:49 +00:00
|
|
|
function ReaderFont:onCloseDocument()
|
|
|
|
self.ui.doc_settings:saveSetting("font_face", self.font_face)
|
2013-01-13 03:38:36 +00:00
|
|
|
self.ui.doc_settings:saveSetting("header_font_face", self.header_font_face)
|
2012-06-26 09:05:49 +00:00
|
|
|
self.ui.doc_settings:saveSetting("font_size", self.font_size)
|
2013-01-08 06:06:56 +00:00
|
|
|
self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent)
|
2013-01-13 03:49:01 +00:00
|
|
|
self.ui.doc_settings:saveSetting("gamma_index", self.gamma_index)
|
2012-06-26 09:05:49 +00:00
|
|
|
end
|
2012-12-13 18:32:16 +00:00
|
|
|
|
|
|
|
function ReaderFont:setFont(face)
|
|
|
|
if face and self.font_face ~= face then
|
|
|
|
self.font_face = face
|
2013-01-07 21:51:37 +00:00
|
|
|
UIManager:show(Notification:new{
|
2013-04-08 07:00:46 +00:00
|
|
|
text = _("Redrawing with font ")..face,
|
2013-01-07 21:51:37 +00:00
|
|
|
timeout = 1,
|
|
|
|
})
|
2012-12-13 18:32:16 +00:00
|
|
|
|
|
|
|
self.ui.document:setFontFace(face)
|
|
|
|
-- signal readerrolling to update pos in new height
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
|
|
|
|
|
|
|
UIManager:close(msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-14 05:58:42 +00:00
|
|
|
function ReaderFont:addToMainMenu(tab_item_table)
|
2012-12-15 01:23:02 +00:00
|
|
|
-- insert table to main reader menu
|
2013-03-14 05:58:42 +00:00
|
|
|
table.insert(tab_item_table.typeset, {
|
2012-12-15 01:23:02 +00:00
|
|
|
text = self.font_menu_title,
|
|
|
|
sub_item_table = self.face_table,
|
|
|
|
})
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderFont
|