mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
adjust font sizes in credocument according to screen dpi
and font sizes list is moved to defaults.lua
This commit is contained in:
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user