mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
@@ -82,6 +82,7 @@ end
|
||||
function ReaderConfig:onShowConfigMenu()
|
||||
self.config_dialog = ConfigDialog:new{
|
||||
dimen = self.dimen:copy(),
|
||||
document = self.document,
|
||||
ui = self.ui,
|
||||
configurable = self.configurable,
|
||||
config_options = self.options,
|
||||
|
||||
@@ -970,9 +970,12 @@ function ReaderPaging:_gotoPage(number, orig_mode)
|
||||
self.view.footer:updateFooter()
|
||||
return true
|
||||
end
|
||||
if number > self.number_of_pages or number < 1 then
|
||||
logger.warn("wrong page number: "..number.."!")
|
||||
return false
|
||||
if number > self.number_of_pages then
|
||||
logger.warn("page number too high: "..number.."!")
|
||||
number = self.number_of_pages
|
||||
elseif number < 1 then
|
||||
logger.warn("page number too low: "..number.."!")
|
||||
number = 1
|
||||
end
|
||||
-- this is an event to allow other controllers to be aware of this change
|
||||
self.ui:handleEvent(Event:new("PageUpdate", number, orig_mode))
|
||||
|
||||
@@ -812,8 +812,8 @@ function ReaderView:onGammaUpdate(gamma)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderView:onFontSizeUpdate()
|
||||
self.ui:handleEvent(Event:new("ReZoom"))
|
||||
function ReaderView:onFontSizeUpdate(font_size)
|
||||
self.ui:handleEvent(Event:new("ReZoom", font_size))
|
||||
end
|
||||
|
||||
function ReaderView:onDefectSizeUpdate()
|
||||
|
||||
@@ -211,7 +211,11 @@ function ReaderZooming:onPageUpdate(new_page_no)
|
||||
self:setZoom()
|
||||
end
|
||||
|
||||
function ReaderZooming:onReZoom()
|
||||
function ReaderZooming:onReZoom(font_size)
|
||||
if self.document.is_reflowable then
|
||||
local reflowable_font_size = self.document:convertKoptToReflowableFontSize(font_size)
|
||||
self.document:layoutDocument(reflowable_font_size)
|
||||
end
|
||||
self:setZoom()
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
return true
|
||||
|
||||
@@ -250,6 +250,7 @@ function ReaderUI:init()
|
||||
-- zooming controller
|
||||
self:registerModule("zooming", ReaderZooming:new{
|
||||
dialog = self.dialog,
|
||||
document = self.document,
|
||||
view = self.view,
|
||||
ui = self
|
||||
})
|
||||
|
||||
@@ -310,6 +310,7 @@ end
|
||||
function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, color)
|
||||
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
|
||||
..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(color and "|color" or "")
|
||||
..(self.reflowable_font_size and "|"..self.reflowable_font_size or "")
|
||||
end
|
||||
|
||||
function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
|
||||
|
||||
@@ -9,13 +9,10 @@ local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local pdf = nil
|
||||
|
||||
|
||||
local PdfDocument = Document:new{
|
||||
_document = false,
|
||||
is_pdf = true,
|
||||
dc_null = DrawContext.new(),
|
||||
epub_font_size = G_reader_settings:readSetting("copt_font_size")
|
||||
or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22,
|
||||
koptinterface = nil,
|
||||
provider = "mupdf",
|
||||
provider_name = "MuPDF",
|
||||
@@ -36,11 +33,10 @@ function PdfDocument:init()
|
||||
if not ok then
|
||||
error(self._document) -- will contain error message
|
||||
end
|
||||
self.is_reflowable = self._document:isDocumentReflowable()
|
||||
self.reflowable_font_size = self:convertKoptToReflowableFontSize()
|
||||
-- no-op on PDF
|
||||
self._document:layoutDocument(
|
||||
CanvasContext:getWidth(),
|
||||
CanvasContext:getHeight(),
|
||||
CanvasContext:scaleBySize(self.epub_font_size))
|
||||
self:layoutDocument()
|
||||
self.is_open = true
|
||||
self.info.has_pages = true
|
||||
self.info.configurable = true
|
||||
@@ -51,6 +47,37 @@ function PdfDocument:init()
|
||||
end
|
||||
end
|
||||
|
||||
function PdfDocument:layoutDocument(font_size)
|
||||
if font_size then
|
||||
self.reflowable_font_size = font_size
|
||||
end
|
||||
self._document:layoutDocument(
|
||||
CanvasContext:getWidth(),
|
||||
CanvasContext:getHeight(),
|
||||
CanvasContext:scaleBySize(self.reflowable_font_size))
|
||||
end
|
||||
|
||||
local default_font_size = 22
|
||||
-- the koptreader config goes from 0.1 to 3.0, but we want a regular font size
|
||||
function PdfDocument:convertKoptToReflowableFontSize(font_size)
|
||||
if font_size then
|
||||
return font_size * default_font_size
|
||||
end
|
||||
|
||||
local docsettings = require("docsettings"):open(self.file)
|
||||
local size = docsettings:readSetting("kopt_font_size")
|
||||
docsettings:close()
|
||||
if size then
|
||||
return size * default_font_size
|
||||
elseif G_reader_settings:readSetting("kopt_font_size") then
|
||||
return G_reader_settings:readSetting("kopt_font_size") * default_font_size
|
||||
elseif DKOPTREADER_CONFIG_FONT_SIZE then
|
||||
return DKOPTREADER_CONFIG_FONT_SIZE * default_font_size
|
||||
else
|
||||
return default_font_size
|
||||
end
|
||||
end
|
||||
|
||||
function PdfDocument:preRenderPage()
|
||||
pdf.color = self.render_color
|
||||
end
|
||||
@@ -104,7 +131,7 @@ function PdfDocument:getPageBlock(pageno, x, y)
|
||||
end
|
||||
|
||||
function PdfDocument:getUsedBBox(pageno)
|
||||
local hash = "pgubbox|"..self.file.."|"..pageno
|
||||
local hash = "pgubbox|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
||||
local cached = Cache:check(hash)
|
||||
if cached then
|
||||
return cached.ubbox
|
||||
@@ -127,7 +154,7 @@ function PdfDocument:getUsedBBox(pageno)
|
||||
end
|
||||
|
||||
function PdfDocument:getPageLinks(pageno)
|
||||
local hash = "pglinks|"..self.file.."|"..pageno
|
||||
local hash = "pgubbox|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
||||
local cached = Cache:check(hash)
|
||||
if cached then
|
||||
return cached.links
|
||||
|
||||
@@ -128,10 +128,12 @@ local KoptOptions = {
|
||||
spacing = 15,
|
||||
height = 60,
|
||||
item_font_size = {24,28,32,34,36,38,42,46},
|
||||
args = {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0},
|
||||
values = {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0},
|
||||
default_value = DKOPTREADER_CONFIG_FONT_SIZE,
|
||||
event = "FontSizeUpdate",
|
||||
enabled_func = function(configurable)
|
||||
enabled_func = function(configurable, document)
|
||||
if document.is_reflowable then return true end
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 1)
|
||||
end,
|
||||
},
|
||||
@@ -145,7 +147,8 @@ local KoptOptions = {
|
||||
event = "FineTuningFontSize",
|
||||
args = {-0.05, 0.05},
|
||||
alternate = false,
|
||||
enabled_func = function(configurable)
|
||||
enabled_func = function(configurable, document)
|
||||
if document.is_reflowable then return true end
|
||||
return optionsutil.enableIfEquals(configurable, "text_wrap", 1)
|
||||
end,
|
||||
name_text_hold_callback = function(configurable, __, prefix)
|
||||
|
||||
@@ -254,7 +254,7 @@ function ConfigOption:init()
|
||||
item_align = 0.5
|
||||
end
|
||||
if self.options[c].enabled_func then
|
||||
enabled = self.options[c].enabled_func(self.config.configurable)
|
||||
enabled = self.options[c].enabled_func(self.config.configurable, self.config.document)
|
||||
end
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
|
||||
@@ -463,6 +463,7 @@ function ConfigOption:init()
|
||||
option_item.event = self.options[c].event
|
||||
option_item.current_item = d
|
||||
option_item.config = self.config
|
||||
option_item.document = self.document
|
||||
table.insert(option_items_group, option_item)
|
||||
end
|
||||
end
|
||||
@@ -621,6 +622,7 @@ function ConfigPanel:init()
|
||||
local panel = ConfigOption:new{
|
||||
options = self.index and config_options[self.index].options or default_option,
|
||||
config = self.config_dialog,
|
||||
document = self.document,
|
||||
}
|
||||
self.dimen = panel:getSize()
|
||||
table.insert(self, panel)
|
||||
|
||||
Reference in New Issue
Block a user