Merge pull request #313 from chrox/master

adjust font sizes in credocument according to screen dpi
pull/316/merge
{Qingping, Dave} Hou 11 years ago
commit ad55ff2387

@ -60,6 +60,10 @@ DKOPTREADER_CONFIG_DOC_LANGS_TEXT = {"English", "Chinese"}
DKOPTREADER_CONFIG_DOC_LANGS_CODE = {"eng", "chi_sim"} -- language code, make sure you have corresponding training data
DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE = "eng" -- that have filenames starting with the language codes
-- crereader font sizes
-- feel free to add more entries in this list
DCREREADER_CONFIG_FONT_SIZES = {16, 20, 22, 24, 28, 32, 38, 44} -- range from 16 to 44
-- gesture detector defaults
DGESDETECT_DISABLE_DOUBLE_TAP = true

@ -89,6 +89,10 @@ function CreDocument:init()
ok, self._document = pcall(cre.newDocView,
Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE
)
-- adjust font sizes according to screen dpi
self._document:adjustFontSizes(Screen:getDPI())
if not ok then
self.error_message = self.doc -- will contain error message
return

@ -1,6 +1,17 @@
require "ui/screen"
require "ui/data/strings"
-- add multiply operator to Aa dict
local Aa = setmetatable({"Aa"}, {
__mul = function(t, mul)
local new = {}
for i = 1, mul do
for _, v in ipairs(t) do table.insert(new, v) end
end
return new
end
})
CreOptions = {
prefix = 'copt',
{
@ -52,13 +63,13 @@ CreOptions = {
options = {
{
name = "font_size",
item_text = {"Aa", "Aa", "Aa", "Aa", "Aa", "Aa", "Aa", "Aa"},
item_text = Aa * #DCREREADER_CONFIG_FONT_SIZES,
item_align_center = 1.0,
spacing = 15,
item_font_size = {18, 20, 22, 24, 29, 33, 39, 44},
values = {18, 20, 22, 24, 29, 33, 39, 44},
item_font_size = DCREREADER_CONFIG_FONT_SIZES,
values = DCREREADER_CONFIG_FONT_SIZES,
default_value = 22,
args = {18, 20, 22, 24, 29, 33, 39, 44},
args = DCREREADER_CONFIG_FONT_SIZES,
event = "SetFontSize",
},
}

@ -94,13 +94,14 @@ function ReaderBookmark:onShowBookmark()
}
-- buid up menu widget method as closure
local doc = self.ui.document
local view = self.view
local sendEv = function(ev)
self.ui:handleEvent(ev)
end
function bm_menu:onMenuChoice(item)
if doc.info.has_pages then
sendEv(Event:new("PageUpdate", item.page))
elseif self.view.view_mode == "page" then
elseif view.view_mode == "page" then
sendEv(Event:new("PageUpdate", doc:getPageFromXPointer(item.page)))
else
sendEv(Event:new("PosUpdate", doc:getPosFromXPointer(item.page)))

@ -9,7 +9,7 @@ ReaderFont = InputContainer:new{
}
function ReaderFont:init()
if not Device:hasNoKeyboard() then
if Device:hasKeyboard() then
-- add shortcut for keyboard
self.key_events = {
ShowFontMenu = { {"F"}, doc = _("show font menu") },
@ -141,14 +141,14 @@ end
function ReaderFont:onSetFontSize(new_size)
if new_size > 44 then new_size = 44 end
if new_size < 18 then new_size = 18 end
if new_size < 16 then new_size = 16 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.document:setFontSize(scaleByDPI(new_size))
self.ui:handleEvent(Event:new("UpdatePos"))
return true

@ -4,7 +4,7 @@ ReaderToc = InputContainer:new{
}
function ReaderToc:init()
if not Device:hasNoKeyboard() then
if Device:hasKeyboard() then
self.key_events = {
ShowToc = {
{ "T" },

@ -75,8 +75,8 @@ end
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h)
if x then x = x < 0 and 0 or math.floor(x) end
if y then y = y < 0 and 0 or math.floor(y) end
if w then w = w > self.width and self.width or math.ceil(w) end
if h then h = h > self.height and self.height or math.ceil(h) end
if w then w = w + x > self.width and self.width - x or math.ceil(w) end
if h then h = h + y > self.height and self.height - y or math.ceil(h) end
if self.native_rotation_mode == self.cur_rotation_mode then
self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height)
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then

@ -247,9 +247,10 @@ function UIManager:run()
end
if self.update_region_func then
local update_region = self.update_region_func()
-- in some rare cases update region has 1 pixel offset
Screen:refresh(refresh_type, waveform_mode,
update_region.x, update_region.y,
update_region.w, update_region.h)
update_region.x-1, update_region.y-1,
update_region.w+2, update_region.h+2)
else
Screen:refresh(refresh_type, waveform_mode)
end

@ -23,8 +23,10 @@ function MenuBarItem:init()
end
function MenuBarItem:onTapSelect()
self[1].invert = true
self.config:onShowConfigPanel(self.index)
UIManager:scheduleIn(0.0, function() self:invert(true) end)
UIManager:scheduleIn(0.1, function()
UIManager:sendEvent(Event:new("ShowConfigPanel", self.index))
end)
UIManager:scheduleIn(0.5, function() self:invert(false) end)
return true
end

@ -13,11 +13,12 @@ InfoMessage = InputContainer:new{
function InfoMessage:init()
if Device:hasKeyboard() then
key_events = {
self.key_events = {
AnyKeyPressed = { { Input.group.Any },
seqtext = "any key", doc = _("close dialog") }
}
else
end
if Device:isTouchDevice() then
self.ges_events.TapClose = {
GestureRange:new{
ges = "tap",

@ -160,16 +160,20 @@ function MenuItem:init()
},
}
self[1] = HorizontalGroup:new{
HorizontalSpan:new{ width = 5 },
ItemShortCutIcon:new{
dimen = shortcut_icon_dimen,
key = self.shortcut,
radius = shortcut_icon_r,
style = self.shortcut_style,
},
HorizontalSpan:new{ width = 10 },
self._underline_container
self[1] = FrameContainer:new{
bordersize = 0,
padding = 0,
HorizontalGroup:new{
HorizontalSpan:new{ width = 5 },
ItemShortCutIcon:new{
dimen = shortcut_icon_dimen,
key = self.shortcut,
radius = shortcut_icon_r,
style = self.shortcut_style,
},
HorizontalSpan:new{ width = 10 },
self._underline_container
}
}
end
@ -264,10 +268,6 @@ function Menu:_recalculateDimen()
}
self.perpage = math.floor((self.dimen.h - self.dimen.x) / self.item_dimen.h) - 2
self.page_num = math.ceil(#self.item_table / self.perpage)
-- update page info layout, fixed #281
if self.page_info then
self.page_info:resetLayout()
end
end
function Menu:init()
@ -414,6 +414,7 @@ function Menu:updateItems(select_number)
-- self.layout must be updated for focusmanager
self.layout = {}
self.item_group:clear()
self.page_info:resetLayout()
self:_recalculateDimen()
-- default to select the first item

@ -11,7 +11,7 @@ Notification = InputContainer:new{
function Notification:init()
if Device:hasKeyboard() then
key_events = {
self.key_events = {
AnyKeyPressed = { { Input.group.Any }, seqtext = "any key", doc = "close dialog" }
}
end

@ -1 +1 @@
Subproject commit f406cec21ed62bd715853ed526658ae8ecbf6ae4
Subproject commit 94f2d03d555e17d68c3d65615ac83cb71099973d
Loading…
Cancel
Save