mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
font menu for readerui
This commit is contained in:
@@ -85,6 +85,13 @@ end
|
||||
function CreDocument:renderPage(pageno, rect, zoom, rotation)
|
||||
end
|
||||
|
||||
function CreDocument:setFont(new_font_face)
|
||||
if new_font_face and self.font_face ~= new_font_face then
|
||||
self._document:setFontFace(new_font_face)
|
||||
self.font_face = new_font_face
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
||||
DocumentRegistry:addProvider("epub", "application/epub", CreDocument)
|
||||
|
||||
@@ -46,7 +46,7 @@ Document = {
|
||||
|
||||
number_of_pages = 0,
|
||||
-- if not pageable, length of the document in pixels
|
||||
length = 0,
|
||||
doc_height = 0,
|
||||
|
||||
-- other metadata
|
||||
title = "",
|
||||
@@ -103,7 +103,7 @@ function Document:_readMetadata()
|
||||
if self.info.has_pages then
|
||||
self.info.number_of_pages = self._document:getPages()
|
||||
else
|
||||
self.info.length = self._document:getFullHeight()
|
||||
self.info.doc_height = self._document:getFullHeight()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -20,13 +20,15 @@ ReaderRolling = InputContainer:new{
|
||||
GotoLast = { {"0"}, doc = "go to end", event = "GotoPercent", args = 100},
|
||||
},
|
||||
|
||||
old_doc_height = nil,
|
||||
current_pos = 0,
|
||||
length = nil,
|
||||
doc_height = nil,
|
||||
panning_steps = ReaderPanning.panning_steps,
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
self.length = self.ui.document.info.length
|
||||
self.doc_height = self.ui.document.info.doc_height
|
||||
self.old_doc_height = self.doc_height
|
||||
end
|
||||
|
||||
function ReaderRolling:onPosUpdate(new_pos)
|
||||
@@ -36,12 +38,27 @@ end
|
||||
function ReaderRolling:gotoPos(new_pos)
|
||||
if new_pos == self.current_pos then return end
|
||||
if new_pos < 0 then new_pos = 0 end
|
||||
if new_pos > self.length then new_pos = self.length end
|
||||
if new_pos > self.doc_height then new_pos = self.doc_height end
|
||||
self.ui:handleEvent(Event:new("PosUpdate", new_pos))
|
||||
end
|
||||
|
||||
function ReaderRolling:gotoPercent(new_percent)
|
||||
self:gotoPos(new_percent * self.length / 10000)
|
||||
self:gotoPos(new_percent * self.doc_height / 10000)
|
||||
end
|
||||
|
||||
-- remember to signal this event the document has been zoomed,
|
||||
-- font has been changed, or line height has been changed.
|
||||
function ReaderRolling:onUpdatePos()
|
||||
-- reread document height
|
||||
self.ui.document:_readMetadata()
|
||||
-- update self.current_pos if the height of document has been changed.
|
||||
if self.old_doc_height ~= self.ui.document.info.doc_height then
|
||||
self:gotoPos(self.current_pos *
|
||||
(self.ui.document.info.doc_height - self.dialog.dimen.h) /
|
||||
(self.old_doc_height - self.dialog.dimen.h))
|
||||
self.old_doc_height = self.ui.document.info.doc_height
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderRolling:onGotoPercent(percent)
|
||||
@@ -64,5 +81,6 @@ function ReaderRolling:onPanning(args, key)
|
||||
end
|
||||
|
||||
function ReaderRolling:onZoom()
|
||||
--@TODO re-read length info after font or lineheight changes 05.06 2012 (houqp)
|
||||
--@TODO re-read doc_height info after font or lineheight changes 05.06 2012 (houqp)
|
||||
self:onUpdatePos()
|
||||
end
|
||||
|
||||
@@ -59,8 +59,7 @@ function ReaderToc:onShowToc()
|
||||
local toc_menu = Menu:new{
|
||||
title = "Table of Contents",
|
||||
item_table = items,
|
||||
width = self.dimen.w,
|
||||
height = self.dimen.h,
|
||||
dimen = self.dimen,
|
||||
ui = self.ui
|
||||
}
|
||||
function toc_menu:onMenuChoice(item)
|
||||
|
||||
@@ -107,3 +107,12 @@ function ReaderView:onRotationUpdate(rotation)
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onFontChange(font_face)
|
||||
msg = InfoMessage:new{ text = "Redrawing with "..font_face}
|
||||
UIManager:show(msg)
|
||||
self.ui.document:setFont(font_face)
|
||||
-- signal readerrolling to update pos in new height
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
UIManager:close(msg)
|
||||
end
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ require "ui/reader/readerrotation"
|
||||
require "ui/reader/readerpaging"
|
||||
require "ui/reader/readerrolling"
|
||||
require "ui/reader/readertoc"
|
||||
require "ui/reader/readerfont"
|
||||
require "ui/reader/readermenu"
|
||||
|
||||
--[[
|
||||
@@ -90,6 +91,7 @@ function ReaderUI:init()
|
||||
end
|
||||
pager:gotoPage(self.start_pos)
|
||||
else
|
||||
-- rolling controller
|
||||
local roller = ReaderRolling:new{
|
||||
dialog = self.dialog,
|
||||
view = self[1],
|
||||
@@ -100,6 +102,13 @@ function ReaderUI:init()
|
||||
self.start_pos = 0
|
||||
end
|
||||
roller:gotoPercent(self.start_pos)
|
||||
-- font menu
|
||||
local font_menu = ReaderFont:new{
|
||||
dialog = self.dialog,
|
||||
view = self[1],
|
||||
ui = self
|
||||
}
|
||||
table.insert(self, font_menu)
|
||||
end
|
||||
-- notify childs of dimensions
|
||||
self:handleEvent(Event:new("SetDimensions", self.dimen))
|
||||
|
||||
Reference in New Issue
Block a user