Alt status bar: custom metadata support (#11463)

reviewable/pr11475/r1
hius07 2 months ago committed by GitHub
parent d4c78aaa4f
commit db2336440f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -64,6 +64,27 @@ function ReaderCoptListener:onReadSettings(config)
self:rescheduleHeaderRefreshIfNeeded() -- schedule (or not) first refresh
end
function ReaderCoptListener:onReaderReady()
-- custom metadata support for alt status bar and cre synthetic cover
for prop_key in pairs(self.document.prop_to_cre_prop) do
local orig_prop_value = self.ui.doc_settings:readSetting(prop_key)
local custom_prop_key = prop_key == "title" and "display_title" or prop_key
local custom_prop_value = self.ui.doc_props[custom_prop_key]
if custom_prop_value ~= orig_prop_value then
self.document:setAltDocumentProp(prop_key, custom_prop_value)
end
end
end
function ReaderCoptListener:onBookMetadataChanged(prop_updated)
-- custom metadata support for alt status bar and cre synthetic cover
local prop_key = prop_updated and prop_updated.metadata_key_updated
if prop_key and self.document.prop_to_cre_prop[prop_key] then
self.document:setAltDocumentProp(prop_key, prop_updated.doc_props[prop_key])
self:updateHeader()
end
end
function ReaderCoptListener:onConfigChange(option_name, option_value)
-- font_size and line_spacing are historically and sadly shared by both mupdf and cre reader modules,
-- but fortunately they can be distinguished by their different ranges

@ -171,10 +171,8 @@ function ReaderFont:onReadSettings(config)
or self.ui.document.default_font
self.ui.document:setFontFace(self.font_face)
self.header_font_face = config:readSetting("header_font_face")
or G_reader_settings:readSetting("header_font")
or self.ui.document.header_font
self.ui.document:setHeaderFont(self.header_font_face)
local header_font = G_reader_settings:readSetting("header_font") or self.ui.document.header_font
self.ui.document:setHeaderFont(header_font)
self.ui.document:setFontSize(Screen:scaleBySize(self.configurable.font_size))
self.ui.document:setFontBaseWeight(self.configurable.font_base_weight)
@ -311,7 +309,6 @@ end
function ReaderFont:onSaveSettings()
self.ui.doc_settings:saveSetting("font_face", self.font_face)
self.ui.doc_settings:saveSetting("header_font_face", self.header_font_face)
self.ui.doc_settings:saveSetting("font_family_fonts", self.font_family_fonts)
end

@ -313,8 +313,6 @@ function ReaderRolling:onReadSettings(config)
end)
end
-- in scroll mode percent_finished must be save before close document
-- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document
function ReaderRolling:onCloseDocument()
self:tearDownRerenderingAutomation()
-- Unschedule anything that might still somehow be...
@ -328,6 +326,7 @@ function ReaderRolling:onCloseDocument()
UIManager:unschedule(self.onUpdatePos)
self.current_header_height = nil -- show unload progress bar at top
-- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
local cache_file_path = self.ui.document:getCacheFilePath() -- nil if no cache file
@ -375,15 +374,8 @@ function ReaderRolling:onCheckDomStyleCoherence()
end
function ReaderRolling:onSaveSettings()
-- remove last_percent config since its deprecated
self.ui.doc_settings:delSetting("last_percent")
self.ui.doc_settings:delSetting("last_percent") -- deprecated
self.ui.doc_settings:saveSetting("last_xpointer", self.xpointer)
-- in scrolling mode, the document may already be closed,
-- so we have to check the condition to avoid crash function self:getLastPercent()
-- that uses self.ui.document
if self.ui.document then
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
end
self.ui.doc_settings:saveSetting("hide_nonlinear_flows", self.hide_nonlinear_flows)
self.ui.doc_settings:saveSetting("partial_rerendering", self.partial_rerendering)
end

@ -33,6 +33,13 @@ local CreDocument = Document:extend{
monospace_font = "Droid Sans Mono",
header_font = "Noto Sans",
prop_to_cre_prop = { -- see cre lvtinydom.h
title = "doc.title",
authors = "doc.authors",
series = "doc.series.name",
series_index = "doc.series.number",
},
-- Reasons for the fallback font ordering:
-- - Noto Sans CJK SC before FreeSans/Serif, as it has nice and larger
-- symbol glyphs for Wikipedia EPUB headings than both Free fonts)
@ -216,6 +223,14 @@ function CreDocument:getDocumentProps()
return self._document:getDocumentProps()
end
function CreDocument:setAltDocumentProp(prop, value)
logger.dbg("CreDocument: set alt document prop", prop, value)
if type(value) == "number" then -- series index
value = tostring(value)
end
self._document:setAltDocumentProp(self.prop_to_cre_prop[prop], value)
end
function CreDocument:setupDefaultView()
if self.loaded then
-- Don't apply defaults if the document has already been loaded

Loading…
Cancel
Save