mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add font size control feature for credocument
also rename getFont to getFontFace
This commit is contained in:
@@ -85,13 +85,23 @@ 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
|
||||
function CreDocument:getFontFace()
|
||||
return self._document:getFontFace()
|
||||
end
|
||||
|
||||
function CreDocument:setFontFace(new_font_face)
|
||||
if new_font_face then
|
||||
self._document:setFontFace(new_font_face)
|
||||
self.font_face = new_font_face
|
||||
end
|
||||
end
|
||||
|
||||
function CreDocument:getFontSize()
|
||||
return self._document:getFontSize()
|
||||
end
|
||||
|
||||
function CreDocument:zoomFont(delta)
|
||||
self._document:zoomFont(delta)
|
||||
end
|
||||
|
||||
DocumentRegistry:addProvider("txt", "application/txt", CreDocument)
|
||||
DocumentRegistry:addProvider("epub", "application/epub", CreDocument)
|
||||
|
||||
@@ -5,8 +5,16 @@ ReaderFont = InputContainer:new{
|
||||
DecreaseSize = { { "Shift", Input.group.PgBack }, doc = "decrease font size", event = "ChangeSize", args = "decrease" },
|
||||
},
|
||||
dimen = Geom:new{ w = Screen:getWidth()-20, h = Screen:getHeight()-20},
|
||||
|
||||
font_face = nil,
|
||||
font_size = nil,
|
||||
}
|
||||
|
||||
function ReaderFont:init()
|
||||
self.font_face = self.ui.document:getFontFace()
|
||||
self.font_size = self.ui.document:getFontSize()
|
||||
end
|
||||
|
||||
function ReaderFont:onShowFontMenu()
|
||||
-- build menu item_table
|
||||
local face_list = cre.getFontFaces()
|
||||
@@ -33,15 +41,34 @@ function ReaderFont:onShowFontMenu()
|
||||
}
|
||||
|
||||
function font_menu:onMenuChoice(item)
|
||||
msg = InfoMessage:new{ text = "Redrawing with "..item.text}
|
||||
UIManager:show(msg)
|
||||
self.ui.document:setFont(item.text)
|
||||
-- signal readerrolling to update pos in new height
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
UIManager:close(msg)
|
||||
if item.text and self.font_face ~= item.text then
|
||||
self.font_face = item.text
|
||||
msg = InfoMessage:new{ text = "Redrawing with "..item.text}
|
||||
UIManager:show(msg)
|
||||
self.ui.document:setFontFace(item.text)
|
||||
-- signal readerrolling to update pos in new height
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
UIManager:close(msg)
|
||||
end
|
||||
end
|
||||
|
||||
UIManager:show(font_menu)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderFont:onChangeSize(direction)
|
||||
local delta = 1
|
||||
if direction == "decrease" then
|
||||
delta = -1
|
||||
end
|
||||
self.font_size = self.font_size + delta
|
||||
msg = InfoMessage:new{text = direction.." font size to "..self.font_size}
|
||||
UIManager:show(msg)
|
||||
self.ui.document:zoomFont(delta)
|
||||
self.ui:handleEvent(Event:new("UpdatePos"))
|
||||
UIManager:close(msg)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user