Style menu cleanup (#3996)

Use epub.css as the main default style, with all file formats
except FB2 (which needs fb2.css).
(epub.css has been cleaned recently to be more conforming to HTML
specs and to not include class name based styles - with conditional
compatiblity styles for previously opened documents. It should be
usable on all HTML based documents, except FB2 which has some
incompatible specs.)

Consider all shipped css files other than "epub.css" and "fb2.css"
obsolete, and put them in a sub-menu (these other css files have
not been updated in the same way, and are kept as-is for when a
previously opened document requests one of them).

Add an icon indicating which style is set as default (like it's
been done for the Font and Style tweaks menus).

Also set the font size of the full status bar (available with
cre documents) when the setting "cre_header_status_font_size"
is present in settings.reader.lua (to add manually).
pull/4003/head
poire-z 6 years ago committed by GitHub
parent 14e77306b7
commit 9a0728e421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,13 +19,9 @@ end
function ReaderTypeset:onReadSettings(config) function ReaderTypeset:onReadSettings(config)
self.css = config:readSetting("css") or G_reader_settings:readSetting("copt_css") self.css = config:readSetting("css") or G_reader_settings:readSetting("copt_css")
or self.ui.document.default_css
local tweaks_css = self.ui.styletweak:getCssText() local tweaks_css = self.ui.styletweak:getCssText()
if self.css then self.ui.document:setStyleSheet(self.css, tweaks_css)
self.ui.document:setStyleSheet(self.css, tweaks_css)
else
self.ui.document:setStyleSheet(self.ui.document.default_css, tweaks_css)
self.css = self.ui.document.default_css
end
self.embedded_fonts = config:readSetting("embedded_fonts") self.embedded_fonts = config:readSetting("embedded_fonts")
if self.embedded_fonts == nil then if self.embedded_fonts == nil then
@ -90,41 +86,101 @@ function ReaderTypeset:onToggleEmbeddedFonts(toggle)
return true return true
end end
-- June 2018: epub.css has been cleaned to be more conforming to HTML specs
-- and to not include class name based styles (with conditional compatiblity
-- styles for previously opened documents). It should be usable on all
-- HTML based documents, except FB2 which has some incompatible specs.
-- These other css files have not been updated in the same way, and are
-- kept as-is for when a previously opened document requests one of them.
local OBSOLETED_CSS = {
"chm.css",
"cr3.css",
"doc.css",
"dict.css",
"htm.css",
"rtf.css",
"txt.css",
}
function ReaderTypeset:genStyleSheetMenu() function ReaderTypeset:genStyleSheetMenu()
local style_table = {} local getStyleMenuItem = function(text, css_file, separator)
local file_list = { return {
{ text_func = function()
text = _("Clear all external styles"), return text .. (css_file == G_reader_settings:readSetting("copt_css") and "" or "")
css = "" end,
},
{
text = _("Auto"),
css = self.ui.document.default_css
},
}
for f in lfs.dir("./data") do
if lfs.attributes("./data/"..f, "mode") == "file" and string.match(f, "%.css$") then
table.insert(file_list, {
text = f,
css = "./data/"..f
})
end
end
table.sort(file_list, function(v1,v2) return v1.text < v2.text end) -- sort by name
for i,file in ipairs(file_list) do
table.insert(style_table, {
text = file["text"],
callback = function() callback = function()
self:setStyleSheet(file["css"]) self:setStyleSheet(css_file or self.ui.document.default_css)
end, end,
hold_callback = function() hold_callback = function()
self:makeDefaultStyleSheet(file["css"], file["text"]) self:makeDefaultStyleSheet(css_file, text)
end, end,
checked_func = function() checked_func = function()
return file.css == self.css if not css_file then -- "Auto"
end return self.css == self.ui.document.default_css
}) end
return css_file == self.css
end,
separator = separator,
}
end
local style_table = {}
local obsoleted_table = {}
table.insert(style_table, getStyleMenuItem(_("Clear all external styles"), ""))
table.insert(style_table, getStyleMenuItem(_("Auto"), nil, true))
local css_files = {}
for f in lfs.dir("./data") do
if lfs.attributes("./data/"..f, "mode") == "file" and string.match(f, "%.css$") then
css_files[f] = "./data/"..f
end
end
-- Add the 2 main styles
if css_files["epub.css"] then
table.insert(style_table, getStyleMenuItem(_("HTML / EPUB (epub.css)"), css_files["epub.css"]))
css_files["epub.css"] = nil
end
if css_files["fb2.css"] then
table.insert(style_table, getStyleMenuItem(_("FictionBook (fb2.css)"), css_files["fb2.css"], true))
css_files["fb2.css"] = nil
end
-- Add the obsoleted ones to the Obsolete sub menu
local obsoleted_css = {} -- for check_func of the Obsolete sub menu itself
for __, css in ipairs(OBSOLETED_CSS) do
obsoleted_css[css_files[css]] = css
if css_files[css] then
table.insert(obsoleted_table, getStyleMenuItem(css, css_files[css]))
css_files[css] = nil
end
end
-- Sort and add the remaining (user added) files if any
local user_files = {}
for css, css_file in pairs(css_files) do
table.insert(user_files, css)
end
table.sort(user_files)
for __, css in ipairs(user_files) do
table.insert(style_table, getStyleMenuItem(css, css_files[css]))
end end
style_table[#style_table].separator = true
table.insert(style_table, {
text_func = function()
local text = _("Obsolete")
if obsoleted_css[self.css] then
text = T(_("Obsolete (%1)"), obsoleted_css[self.css])
end
if obsoleted_css[G_reader_settings:readSetting("copt_css")] then
text = text .. ""
end
return text
end,
sub_item_table = obsoleted_table,
checked_func = function()
return obsoleted_css[self.css] ~= nil
end
})
return style_table return style_table
end end
@ -226,15 +282,12 @@ function ReaderTypeset:makeDefaultFloatingPunctuation()
end end
function ReaderTypeset:makeDefaultStyleSheet(css, text) function ReaderTypeset:makeDefaultStyleSheet(css, text)
text = text or css UIManager:show(ConfirmBox:new{
if css then text = T( _("Set default style to %1?"), text),
UIManager:show(ConfirmBox:new{ ok_callback = function()
text = T( _("Set default style to %1?"), text), G_reader_settings:saveSetting("copt_css", css)
ok_callback = function() end,
G_reader_settings:saveSetting("copt_css", css) })
end,
})
end
end end
function ReaderTypeset:onSetPageMargins(margins) function ReaderTypeset:onSetPageMargins(margins)

@ -101,15 +101,18 @@ function CreDocument:init()
-- and return extention of the 1st file -- and return extention of the 1st file
file_type = self:zipContentExt(self.file) or "unknown" file_type = self:zipContentExt(self.file) or "unknown"
end end
-- these two format use the same css file
if file_type == "html" then -- June 2018: epub.css has been cleaned to be more conforming to HTML specs
file_type = "htm" -- and to not include class name based styles (with conditional compatiblity
end -- styles for previously opened documents). It should be usable on all
-- if native css-file doesn't exist, one needs to use default cr3.css -- HTML based documents, except FB2 which has some incompatible specs.
if not io.open("./data/"..file_type..".css") then -- The other css files (htm.css, rtf.css...) have not been updated in the
file_type = "cr3" -- same way, and are kept as-is for when a previously opened document
-- requests one of them.
self.default_css = "./data/epub.css"
if file_type == "fb2" then
self.default_css = "./data/fb2.css"
end end
self.default_css = "./data/"..file_type..".css"
-- @TODO check the default view_mode to a global user configurable -- @TODO check the default view_mode to a global user configurable
-- variable 22.12 2012 (houqp) -- variable 22.12 2012 (houqp)
@ -124,6 +127,11 @@ function CreDocument:init()
-- adjust font sizes according to screen dpi -- adjust font sizes according to screen dpi
self._document:adjustFontSizes(Screen:getDPI()) self._document:adjustFontSizes(Screen:getDPI())
if G_reader_settings:readSetting("cre_header_status_font_size") then
self._document:setIntProperty("crengine.page.header.font.size",
G_reader_settings:readSetting("cre_header_status_font_size"))
end
-- set fallback font face -- set fallback font face
self._document:setStringProperty("crengine.font.fallback.face", self._document:setStringProperty("crengine.font.fallback.face",
G_reader_settings:readSetting("fallback_font") or self.fallback_font) G_reader_settings:readSetting("fallback_font") or self.fallback_font)

@ -187,7 +187,7 @@ describe("Readerrolling module", function()
local ReaderView = require("apps/reader/modules/readerview") local ReaderView = require("apps/reader/modules/readerview")
local saved_handler = ReaderView.onPageUpdate local saved_handler = ReaderView.onPageUpdate
ReaderView.onPageUpdate = function(_self) ReaderView.onPageUpdate = function(_self)
assert.are.same(7, _self.ui.document:getPageCount()) assert.are.same(6, _self.ui.document:getPageCount())
end end
local test_book = "spec/front/unit/data/sample.txt" local test_book = "spec/front/unit/data/sample.txt"
require("docsettings"):open(test_book):purge() require("docsettings"):open(test_book):purge()

Loading…
Cancel
Save