adjust font sizes in credocument according to screen dpi

and font sizes list is moved to defaults.lua
pull/313/head
chrox 11 years ago
parent 4cd8a0e9e6
commit 32ffacdf77

@ -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_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 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 -- gesture detector defaults
DGESDETECT_DISABLE_DOUBLE_TAP = true DGESDETECT_DISABLE_DOUBLE_TAP = true

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

@ -1,6 +1,17 @@
require "ui/screen" require "ui/screen"
require "ui/data/strings" 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 = { CreOptions = {
prefix = 'copt', prefix = 'copt',
{ {
@ -52,13 +63,13 @@ CreOptions = {
options = { options = {
{ {
name = "font_size", 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, item_align_center = 1.0,
spacing = 15, spacing = 15,
item_font_size = {18, 20, 22, 24, 29, 33, 39, 44}, item_font_size = DCREREADER_CONFIG_FONT_SIZES,
values = {18, 20, 22, 24, 29, 33, 39, 44}, values = DCREREADER_CONFIG_FONT_SIZES,
default_value = 22, default_value = 22,
args = {18, 20, 22, 24, 29, 33, 39, 44}, args = DCREREADER_CONFIG_FONT_SIZES,
event = "SetFontSize", event = "SetFontSize",
}, },
} }

@ -141,14 +141,14 @@ end
function ReaderFont:onSetFontSize(new_size) function ReaderFont:onSetFontSize(new_size)
if new_size > 44 then new_size = 44 end 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 self.font_size = new_size
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = _("Set font size to ")..self.font_size, text = _("Set font size to ")..self.font_size,
timeout = 1, timeout = 1,
}) })
self.ui.document:setFontSize(new_size) self.ui.document:setFontSize(scaleByDPI(new_size))
self.ui:handleEvent(Event:new("UpdatePos")) self.ui:handleEvent(Event:new("UpdatePos"))
return true return true

Loading…
Cancel
Save