mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
use scaleByDPI in all widgets
This commit is contained in:
@@ -43,8 +43,8 @@ function Font:getFace(font, size)
|
||||
-- default to content font
|
||||
font = self.cfont
|
||||
end
|
||||
|
||||
local size = math.floor(size*Screen:getDPI()/167)
|
||||
|
||||
local size = math.floor(scaleByDPI(size))
|
||||
|
||||
local face = self.faces[font..size]
|
||||
-- build face if not found
|
||||
|
||||
@@ -13,11 +13,11 @@ function ReaderFont:init()
|
||||
-- add shortcut for keyboard
|
||||
self.key_events = {
|
||||
ShowFontMenu = { {"F"}, doc = "show font menu" },
|
||||
IncreaseSize = {
|
||||
{ "Shift", Input.group.PgFwd },
|
||||
doc = "increase font size",
|
||||
IncreaseSize = {
|
||||
{ "Shift", Input.group.PgFwd },
|
||||
doc = "increase font size",
|
||||
event = "ChangeSize", args = "increase" },
|
||||
DecreaseSize = {
|
||||
DecreaseSize = {
|
||||
{ "Shift", Input.group.PgBack },
|
||||
doc = "decrease font size",
|
||||
event = "ChangeSize", args = "decrease" },
|
||||
@@ -52,33 +52,33 @@ end
|
||||
|
||||
function ReaderFont:onReadSettings(config)
|
||||
self.font_face = config:readSetting("font_face")
|
||||
if not self.font_face then
|
||||
if not self.font_face then
|
||||
self.font_face = self.ui.document.default_font
|
||||
end
|
||||
self.ui.document:setFontFace(self.font_face)
|
||||
|
||||
self.header_font_face = config:readSetting("header_font_face")
|
||||
if not self.header_font_face then
|
||||
if not self.header_font_face then
|
||||
self.header_font_face = self.ui.document.header_font
|
||||
end
|
||||
self.ui.document:setHeaderFont(self.header_font_face)
|
||||
|
||||
self.font_size = config:readSetting("font_size")
|
||||
if not self.font_size then
|
||||
if not self.font_size then
|
||||
--@TODO change this! 12.01 2013 (houqp)
|
||||
self.font_size = 29
|
||||
end
|
||||
self.ui.document:setFontSize(self.font_size)
|
||||
|
||||
self.line_space_percent = config:readSetting("line_space_percent")
|
||||
if not self.line_space_percent then
|
||||
if not self.line_space_percent then
|
||||
self.line_space_percent = 100
|
||||
else
|
||||
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
|
||||
end
|
||||
|
||||
self.gamma_index = config:readSetting("gamma_index")
|
||||
if not self.gamma_index then
|
||||
if not self.gamma_index then
|
||||
self.gamma_index = 15
|
||||
end
|
||||
self.ui.document:setGammaIndex(self.gamma_index)
|
||||
@@ -104,7 +104,7 @@ function ReaderFont:onShowFontMenu()
|
||||
main_menu,
|
||||
dimen = Screen:getSize(),
|
||||
}
|
||||
main_menu.close_callback = function ()
|
||||
main_menu.close_callback = function ()
|
||||
UIManager:close(menu_container)
|
||||
end
|
||||
-- show menu
|
||||
|
||||
@@ -6,38 +6,38 @@ ReaderPaging = InputContainer:new{
|
||||
visible_area = nil,
|
||||
page_area = nil,
|
||||
show_overlap_enable = true,
|
||||
overlap = 20 * Screen:getDPI()/167,
|
||||
overlap = scaleByDPI(20),
|
||||
}
|
||||
|
||||
function ReaderPaging:init()
|
||||
if Device:hasKeyboard() then
|
||||
self.key_events = {
|
||||
GotoNextPage = {
|
||||
GotoNextPage = {
|
||||
{Input.group.PgFwd}, doc = "go to next page",
|
||||
event = "GotoPageRel", args = 1 },
|
||||
GotoPrevPage = {
|
||||
GotoPrevPage = {
|
||||
{Input.group.PgBack}, doc = "go to previous page",
|
||||
event = "GotoPageRel", args = -1 },
|
||||
|
||||
GotoFirst = {
|
||||
GotoFirst = {
|
||||
{"1"}, doc = "go to start", event = "GotoPercent", args = 0},
|
||||
Goto11 = {
|
||||
Goto11 = {
|
||||
{"2"}, doc = "go to 11%", event = "GotoPercent", args = 11},
|
||||
Goto22 = {
|
||||
Goto22 = {
|
||||
{"3"}, doc = "go to 22%", event = "GotoPercent", args = 22},
|
||||
Goto33 = {
|
||||
Goto33 = {
|
||||
{"4"}, doc = "go to 33%", event = "GotoPercent", args = 33},
|
||||
Goto44 = {
|
||||
Goto44 = {
|
||||
{"5"}, doc = "go to 44%", event = "GotoPercent", args = 44},
|
||||
Goto55 = {
|
||||
Goto55 = {
|
||||
{"6"}, doc = "go to 55%", event = "GotoPercent", args = 55},
|
||||
Goto66 = {
|
||||
Goto66 = {
|
||||
{"7"}, doc = "go to 66%", event = "GotoPercent", args = 66},
|
||||
Goto77 = {
|
||||
Goto77 = {
|
||||
{"8"}, doc = "go to 77%", event = "GotoPercent", args = 77},
|
||||
Goto88 = {
|
||||
Goto88 = {
|
||||
{"9"}, doc = "go to 88%", event = "GotoPercent", args = 88},
|
||||
GotoLast = {
|
||||
GotoLast = {
|
||||
{"0"}, doc = "go to end", event = "GotoPercent", args = 100},
|
||||
}
|
||||
end
|
||||
@@ -62,7 +62,7 @@ function ReaderPaging:initGesListener()
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0,
|
||||
x = 0,
|
||||
y = Screen:getHeight()/4,
|
||||
w = Screen:getWidth()/4,
|
||||
h = 5*Screen:getHeight()/8,
|
||||
@@ -361,7 +361,7 @@ function ReaderPaging:onScrollPageRel(diff)
|
||||
}
|
||||
-- Scroll down offset should always be greater than 0
|
||||
-- otherwise if offset is less than 0 the height of blank area will be
|
||||
-- larger than 0 even if page area is much larger than visible area,
|
||||
-- larger than 0 even if page area is much larger than visible area,
|
||||
-- which will trigger the drawing of next page leaving part of current
|
||||
-- page undrawn. This should also be true for scroll up offset.
|
||||
if offset.y < 0 then offset.y = 0 end
|
||||
|
||||
@@ -3,14 +3,14 @@ ReaderScreenshot = InputContainer:new{}
|
||||
|
||||
function ReaderScreenshot:init()
|
||||
local diagonal = math.sqrt(
|
||||
math.pow(Screen:getWidth(), 2) +
|
||||
math.pow(Screen:getWidth(), 2) +
|
||||
math.pow(Screen:getHeight(), 2)
|
||||
)
|
||||
self.ges_events = {
|
||||
Screenshot = {
|
||||
GestureRange:new{
|
||||
ges = "two_finger_tap",
|
||||
scale = {diagonal - 80*Screen:getDPI()/167, diagonal},
|
||||
scale = {diagonal - scaleByDPI(80), diagonal},
|
||||
rate = 1.0,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ require "ui/reader/readerdogear"
|
||||
ReaderView = OverlapGroup:new{
|
||||
_name = "ReaderView",
|
||||
document = nil,
|
||||
|
||||
|
||||
-- single page state
|
||||
state = {
|
||||
page = 0,
|
||||
@@ -23,8 +23,8 @@ ReaderView = OverlapGroup:new{
|
||||
page_states = {},
|
||||
scroll_mode = "vertical",
|
||||
page_gap = {
|
||||
width = 8 * Screen:getDPI()/167,
|
||||
height = 8 * Screen:getDPI()/167,
|
||||
width = scaleByDPI(8),
|
||||
height = scaleByDPI(8),
|
||||
color = 8,
|
||||
},
|
||||
-- DjVu page rendering mode (used in djvu.c:drawPage())
|
||||
@@ -32,14 +32,14 @@ ReaderView = OverlapGroup:new{
|
||||
-- Crengine view mode
|
||||
view_mode = "page", -- default to page mode
|
||||
hinting = true,
|
||||
|
||||
|
||||
-- visible area within current viewing page
|
||||
visible_area = Geom:new{x = 0, y = 0},
|
||||
-- dimen for current viewing page
|
||||
page_area = Geom:new{},
|
||||
-- dimen for area to dim
|
||||
dim_area = Geom:new{w = 0, h = 0},
|
||||
-- has footer
|
||||
-- has footer
|
||||
footer_visible = false,
|
||||
-- has dogear
|
||||
dogear_visible = false,
|
||||
@@ -73,7 +73,7 @@ function ReaderView:paintTo(bb, x, y)
|
||||
else
|
||||
self:drawPageSurround(bb, x, y)
|
||||
end
|
||||
|
||||
|
||||
-- draw page content
|
||||
if self.ui.document.info.has_pages then
|
||||
if self.page_scroll then
|
||||
@@ -88,16 +88,16 @@ function ReaderView:paintTo(bb, x, y)
|
||||
self:drawScrollView(bb, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- dim last read area
|
||||
if self.document.view_mode ~= "page"
|
||||
if self.document.view_mode ~= "page"
|
||||
and self.dim_area.w ~= 0 and self.dim_area.h ~= 0 then
|
||||
bb:dimRect(
|
||||
self.dim_area.x, self.dim_area.y,
|
||||
self.dim_area.w, self.dim_area.h
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
-- paint dogear
|
||||
if self.dogear_visible then
|
||||
self.dogear:paintTo(bb, x, y)
|
||||
@@ -119,12 +119,12 @@ end
|
||||
function ReaderView:drawPageSurround(bb, x, y)
|
||||
if self.dimen.h > self.visible_area.h then
|
||||
bb:paintRect(x, y, self.dimen.w, self.state.offset.y, self.outer_page_color)
|
||||
bb:paintRect(x, y + self.dimen.h - self.state.offset.y - 1,
|
||||
bb:paintRect(x, y + self.dimen.h - self.state.offset.y - 1,
|
||||
self.dimen.w, self.state.offset.y + 1, self.outer_page_color)
|
||||
end
|
||||
if self.dimen.w > self.visible_area.w then
|
||||
bb:paintRect(x, y, self.state.offset.x, self.dimen.h, self.outer_page_color)
|
||||
bb:paintRect(x + self.dimen.w - self.state.offset.x - 1, y,
|
||||
bb:paintRect(x + self.dimen.w - self.state.offset.x - 1, y,
|
||||
self.state.offset.x + 1, self.dimen.h, self.outer_page_color)
|
||||
end
|
||||
end
|
||||
@@ -143,7 +143,7 @@ function ReaderView:drawScrollPages(bb, x, y)
|
||||
state.gamma,
|
||||
self.render_mode)
|
||||
pos.y = pos.y + state.visible_area.h
|
||||
-- draw page gap if not the last part
|
||||
-- draw page gap if not the last part
|
||||
if page ~= #self.page_states then
|
||||
self:drawPageGap(bb, pos.x, pos.y)
|
||||
pos.y = pos.y + self.page_gap.height
|
||||
|
||||
@@ -159,7 +159,9 @@ function ConfigOption:init()
|
||||
local default_option_height = 50
|
||||
local default_option_padding = 15
|
||||
local vertical_group = VerticalGroup:new{}
|
||||
table.insert(vertical_group, VerticalSpan:new{ width = default_option_padding * Screen:getDPI()/167 })
|
||||
table.insert(vertical_group, VerticalSpan:new{
|
||||
width = scaleByDPI(default_option_padding),
|
||||
})
|
||||
for c = 1, #self.options do
|
||||
if self.options[c].show ~= false then
|
||||
local name_align = self.options[c].name_align_right and self.options[c].name_align_right or 0.33
|
||||
@@ -168,9 +170,9 @@ function ConfigOption:init()
|
||||
local name_font_size = self.options[c].name_font_size and self.options[c].name_font_size or default_name_font_size
|
||||
local item_font_face = self.options[c].item_font_face and self.options[c].item_font_face or "cfont"
|
||||
local item_font_size = self.options[c].item_font_size and self.options[c].item_font_size or default_item_font_size
|
||||
local option_height = (self.options[c].height and self.options[c].height or default_option_height) * Screen:getDPI()/167
|
||||
local option_height = scaleByDPI(self.options[c].height and self.options[c].height or default_option_height)
|
||||
local items_spacing = HorizontalSpan:new{
|
||||
width = (self.options[c].spacing and self.options[c].spacing or default_items_spacing) * Screen:getDPI()/167
|
||||
width = scaleByDPI(self.options[c].spacing and self.options[c].spacing or default_items_spacing)
|
||||
}
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
if self.options[c].name_text then
|
||||
|
||||
Reference in New Issue
Block a user