add font size control feature for credocument

also rename getFont to getFontFace
pull/2/merge
Qingping Hou 12 years ago
parent 9e6940621b
commit b3cdbeee19

@ -85,13 +85,23 @@ end
function CreDocument:renderPage(pageno, rect, zoom, rotation) function CreDocument:renderPage(pageno, rect, zoom, rotation)
end end
function CreDocument:setFont(new_font_face) function CreDocument:getFontFace()
if new_font_face and self.font_face ~= new_font_face then return self._document:getFontFace()
end
function CreDocument:setFontFace(new_font_face)
if new_font_face then
self._document:setFontFace(new_font_face) self._document:setFontFace(new_font_face)
self.font_face = new_font_face
end end
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("txt", "application/txt", CreDocument)
DocumentRegistry:addProvider("epub", "application/epub", 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" }, DecreaseSize = { { "Shift", Input.group.PgBack }, doc = "decrease font size", event = "ChangeSize", args = "decrease" },
}, },
dimen = Geom:new{ w = Screen:getWidth()-20, h = Screen:getHeight()-20}, 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() function ReaderFont:onShowFontMenu()
-- build menu item_table -- build menu item_table
local face_list = cre.getFontFaces() local face_list = cre.getFontFaces()
@ -33,15 +41,34 @@ function ReaderFont:onShowFontMenu()
} }
function font_menu:onMenuChoice(item) function font_menu:onMenuChoice(item)
msg = InfoMessage:new{ text = "Redrawing with "..item.text} if item.text and self.font_face ~= item.text then
UIManager:show(msg) self.font_face = item.text
self.ui.document:setFont(item.text) msg = InfoMessage:new{ text = "Redrawing with "..item.text}
-- signal readerrolling to update pos in new height UIManager:show(msg)
self.ui:handleEvent(Event:new("UpdatePos")) self.ui.document:setFontFace(item.text)
UIManager:close(msg) -- signal readerrolling to update pos in new height
self.ui:handleEvent(Event:new("UpdatePos"))
UIManager:close(msg)
end
end end
UIManager:show(font_menu) 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 end

Loading…
Cancel
Save