decouple device from pdfdocument, font & bgr checking

pull/4721/head
Qingping Hou 6 years ago committed by Frans de Jonge
parent 9e57e56f95
commit d749591984

@ -1,14 +1,13 @@
local Cache = require("cache")
local CacheItem = require("cacheitem")
local Device = require("device")
local Document = require("document/document")
local DrawContext = require("ffi/drawcontext")
local logger = require("logger")
local util = require("util")
local ffi = require("ffi")
local C = ffi.C
local Screen = Device.screen
local pdf = nil
local Runtimectl = require("runtimectl")
local PdfDocument = Document:new{
@ -30,12 +29,6 @@ function PdfDocument:init()
-- and :postRenderPage() when mupdf is called without kopt involved.
pdf.color = false
self:updateColorRendering()
if pdf.bgr == nil then
pdf.bgr = false
if Device:hasBGRFrameBuffer() then
pdf.bgr = true
end
end
self.koptinterface = require("document/koptinterface")
self.koptinterface:setDefaultConfigurable(self.configurable)
local ok
@ -44,8 +37,8 @@ function PdfDocument:init()
error(self._document) -- will contain error message
end
-- no-op on PDF
self._document:layoutDocument(Screen:getWidth(), Screen:getHeight(),
Screen:scaleBySize(self.epub_font_size))
self._document:layoutDocument(Runtimectl:getRenderWidth(), Runtimectl:getRenderHeight(),
Runtimectl:scaleByRenderSize(self.epub_font_size))
self.is_open = true
self.info.has_pages = true
self.info.configurable = true

@ -1,8 +1,26 @@
local Mupdf = require("ffi/mupdf")
local Runtimectl = {
should_restrict_JIT = false,
is_color_rendering_enabled = false,
is_bgr = false,
}
function Runtimectl:setDevice(device)
self.isAndroid = device.isAndroid
self.isKindle = device.isKindle
if self.isAndroid() then
self:restrictJIT()
end
-- NOTE: Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed.
if device:hasBGRFrameBuffer() then
self.is_bgr = true
Mupdf.bgr = true
end
end
--[[
Disable jit on some modules on android to make koreader on Android more stable.
@ -22,4 +40,28 @@ function Runtimectl:setColorRenderingEnabled(val)
self.is_color_rendering_enabled = val
end
function Runtimectl:getExternalFontDir()
if self.isAndroid() then
return ANDROID_FONT_DIR
else
return os.getenv("EXT_FONT_DIR")
end
end
function Runtimectl:getRenderWidth()
return self.screen:getWidth()
end
function Runtimectl:getRenderHeight()
return self.screen:getHeight()
end
function Runtimectl:getRenderDPI()
return self.screen:getDPI()
end
function Runtimectl:scaleByRenderSize(px)
return self.screen:scaleBySize(px)
end
return Runtimectl

@ -2,11 +2,10 @@
Font module.
]]
local Device = require("device")
local Freetype = require("ffi/freetype")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local Screen = Device.screen
local Runtimectl = require("runtimectl")
local Font = {
fontmap = {
@ -86,8 +85,17 @@ local Font = {
-- face table
faces = {},
-- set by self.setScreen
screen = nil,
}
--- Sets the screen object that will be used by font module for font size scaling
-- NOTE: this call is required for using KOReader UI framework
function Font:setScreen(screen)
self.screen = screen
end
--- Gets font face object.
-- @string font
-- @int size optional size
@ -99,7 +107,7 @@ function Font:getFace(font, size)
if not size then size = self.sizemap[font] end
-- original size before scaling by screen DPI
local orig_size = size
size = Screen:scaleBySize(size)
size = self.screen:scaleBySize(size)
local hash = font..size
local face_obj = self.faces[hash]
@ -188,9 +196,8 @@ local kindle_fonts_blacklist = {
}
local function isInFontsBlacklist(f)
if Device:isKindle() then
return kindle_fonts_blacklist[f]
end
-- write test for this
return Runtimectl.isKindle() and kindle_fonts_blacklist[f]
end
function Font:_readList(target, dir)
@ -214,19 +221,11 @@ function Font:_readList(target, dir)
end
end
function Font:_getExternalFontDir()
if Device:isAndroid() then
return ANDROID_FONT_DIR
else
return os.getenv("EXT_FONT_DIR")
end
end
function Font:getFontList()
local fontlist = {}
self:_readList(fontlist, self.fontdir)
-- multiple paths should be joined with semicolon
for dir in string.gmatch(self:_getExternalFontDir() or "", "([^;]+)") do
for dir in string.gmatch(Runtimectl:getExternalFontDir() or "", "([^;]+)") do
self:_readList(fontlist, dir)
end
table.sort(fontlist)

@ -3,7 +3,6 @@ Image rendering module.
]]
local ffi = require("ffi")
local Device = require("device")
local logger = require("logger")
-- Will be loaded when needed
@ -67,13 +66,6 @@ end
-- @treturn BlitBuffer
function RenderImage:renderImageDataWithMupdf(data, size, width, height)
if not Mupdf then Mupdf = require("ffi/mupdf") end
-- NOTE: Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed.
if Mupdf.bgr == nil then
Mupdf.bgr = false
if Device:hasBGRFrameBuffer() then
Mupdf.bgr = true
end
end
local ok, image = pcall(Mupdf.renderImage, data, size, width, height)
logger.dbg("Mupdf.renderImage", ok, image)
if not ok then

@ -35,12 +35,6 @@ function HtmlBoxWidget:init()
},
}
end
if Mupdf.bgr == nil then
Mupdf.bgr = false
if Device:hasBGRFrameBuffer() then
Mupdf.bgr = true
end
end
end
function HtmlBoxWidget:setContent(body, css, default_font_size)

@ -19,7 +19,6 @@ local DataStorage = require("datastorage")
pcall(dofile, DataStorage:getDataDir() .. "/defaults.persistent.lua")
require("setupkoenv")
Runtimectl = require("runtimectl")
io.stdout:write(" [*] Version: ", require("version"):getCurrentRevision(), "\n\n")
io.stdout:flush()
@ -36,10 +35,12 @@ if lang_locale then
end
-- setup various runtime control
local Runtimectl = require("runtimectl")
local Device = require("device")
if Device:isAndroid() then
Runtimectl:restrictJIT()
end
Runtimectl:setDevice(Device)
local Font = require("ui/font")
Font:setScreen(Device.screen)
if G_reader_settings:has("color_rendering") then
Runtimectl:setColorRenderingEnabled(G_reader_settings:isTrue("color_rendering"))
@ -113,7 +114,6 @@ while argidx <= #ARGV do
end
local ConfirmBox = require("ui/widget/confirmbox")
local Font = require("ui/font")
local QuickStart = require("ui/quickstart")
local UIManager = require("ui/uimanager")
local lfs = require("libs/libkoreader-lfs")

Loading…
Cancel
Save