Adds "Better rendering of list items" to Style tweaks (#3968)

Alternate rendering of list items as block elements (instead of
inline/final).
Check the built DOM is still coherent with styles on stylesheet
change, and propose to reload the document if not. Also
invalidate cache on close in that case so a new DOM is built
at next opening.
ReaderStyleTweak: fix tweak css duplication; when globally
enabled, when disabling and re-enabling locally, the css would
be added twice to the final CSS.
Also adds !important to "sub_sup_smaller" tweak, and increase
its priority so it can override "font_size_all_inherit".
Adds CreDocument:getCacheFilePath() for futur features.
pull/3976/head
poire-z 6 years ago committed by GitHub
parent 6a98dbaec7
commit 07713be429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit c047556aef960d71ef2ef1b2fb5b85df0326bf27 Subproject commit 354d71a97837708e4f91a69a8ceaf47077ce2cf9

@ -274,9 +274,11 @@ function ReaderMenu:onShowReaderMenu(tab_index)
end end
function ReaderMenu:onCloseReaderMenu() function ReaderMenu:onCloseReaderMenu()
self.last_tab_index = self.menu_container[1].last_index if self.menu_container then
self:onSaveSettings() self.last_tab_index = self.menu_container[1].last_index
UIManager:close(self.menu_container) self:onSaveSettings()
UIManager:close(self.menu_container)
end
return true return true
end end

@ -1,4 +1,5 @@
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device") local Device = require("device")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local Event = require("ui/event") local Event = require("ui/event")
@ -179,6 +180,30 @@ end
-- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document -- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document
function ReaderRolling:onCloseDocument() function ReaderRolling:onCloseDocument()
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent()) self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
-- also checks if DOM is coherent with styles; if not, invalidate the
-- cache, so a new DOM is built on next opening
if self.ui.document:isBuiltDomStale() then
if self.ui.document:hasCacheFile() then
logger.dbg("cre DOM may not be in sync with styles, invalidating cache file for a full reload at next opening")
self.ui.document:invalidateCacheFile()
end
end
logger.dbg("cre cache used:", self.ui.document:getCacheFilePath() or "none")
end
function ReaderRolling:onCheckDomStyleCoherence()
if self.ui.document:isBuiltDomStale() then
UIManager:show(ConfirmBox:new{
text = _("Styles have changed in such a way that fully reloading the document may be needed for a correct rendering.\nDo you want to reload the document?"),
ok_callback = function()
-- Allow for ConfirmBox to be closed before showing
-- "Opening file" InfoMessage
UIManager:scheduleIn(0.5, function ()
self.ui:reloadDocument()
end)
end,
})
end
end end
function ReaderRolling:onSaveSettings() function ReaderRolling:onSaveSettings()
@ -566,6 +591,12 @@ function ReaderRolling:updatePos()
self.view.footer:updateFooter() self.view.footer:updateFooter()
end end
UIManager:setDirty(self.view.dialog, "partial") UIManager:setDirty(self.view.dialog, "partial")
-- Allow for the new rendering to be shown before possibly showing
-- the "Styles have changes..." ConfirmBox so the user can decide
-- if it is really needed
UIManager:scheduleIn(0.1, function ()
self:onCheckDomStyleCoherence()
end)
end end
--[[ --[[

@ -263,8 +263,10 @@ function ReaderStyleTweak:updateCssText(apply)
local tweaks = {} local tweaks = {}
for id, enabled in pairs(self.global_tweaks) do for id, enabled in pairs(self.global_tweaks) do
-- there are only enabled tweaks in global_tweaks, but we don't -- there are only enabled tweaks in global_tweaks, but we don't
-- use them if they are disabled in doc_tweaks -- add them here if they appear in doc_tweaks (if enabled in
if self.doc_tweaks[id] ~= false then -- doc_tweaks, they'll be added below; if disabled, they should
-- not be added)
if self.doc_tweaks[id] == nil then
table.insert(tweaks, self.tweaks_by_id[id]) table.insert(tweaks, self.tweaks_by_id[id])
end end
end end

@ -650,4 +650,17 @@ function ReaderUI:onHome()
return true return true
end end
function ReaderUI:reloadDocument(after_close_callback)
local file = self.document.file
local provider = getmetatable(self.document).__index
self:handleEvent(Event:new("CloseReaderMenu"))
self:handleEvent(Event:new("CloseConfigMenu"))
self:onClose()
if after_close_callback then
-- allow caller to do stuff between close an re-open
after_close_callback(file, provider)
end
self:showReader(file, provider)
end
return ReaderUI return ReaderUI

@ -589,6 +589,22 @@ function CreDocument:enableInternalHistory(toggle)
self._document:setIntProperty("crengine.highlight.bookmarks", toggle and 2 or 0) self._document:setIntProperty("crengine.highlight.bookmarks", toggle and 2 or 0)
end end
function CreDocument:isBuiltDomStale()
return self._document:isBuiltDomStale()
end
function CreDocument:hasCacheFile()
return self._document:hasCacheFile()
end
function CreDocument:invalidateCacheFile()
self._document:invalidateCacheFile()
end
function CreDocument:getCacheFilePath()
return self._document:getCacheFilePath()
end
function CreDocument:register(registry) function CreDocument:register(registry)
registry:addProvider("azw", "application/vnd.amazon.mobi8-ebook", self, 90) registry:addProvider("azw", "application/vnd.amazon.mobi8-ebook", self, 90)
registry:addProvider("chm", "application/vnd.ms-htmlhelp", self, 90) registry:addProvider("chm", "application/vnd.ms-htmlhelp", self, 90)

@ -34,15 +34,40 @@ local CssTweaks = {
}, },
{ {
title = _("Text"), title = _("Text"),
{
title = _("Links color and weight"),
{
id = "a_black";
title = _("Links always black"),
css = [[a { color: black !important; }]],
},
{
id = "a_blue";
title = _("Links always blue"),
css = [[a { color: blue !important; }]],
separator = true,
},
{
id = "a_bold";
title = _("Links always bold"),
css = [[a { font-weight: bold !important; }]],
},
{
id = "a_not_bold";
title = _("Links never bold"),
css = [[a { font-weight: normal !important; }]],
},
},
{ {
id = "sub_sup_smaller"; id = "sub_sup_smaller";
title = _("Smaller sub- and superscript"), title = _("Smaller sub- and superscript"),
description = _("Prevent sub- and superscript from affecting line-height."), description = _("Prevent sub- and superscript from affecting line-height."),
priority = 5, -- so we can override "font_size_all_inherit"
-- https://friendsofepub.github.io/eBookTricks/ -- https://friendsofepub.github.io/eBookTricks/
-- https://github.com/koreader/koreader/issues/3923#issuecomment-386510294 -- https://github.com/koreader/koreader/issues/3923#issuecomment-386510294
css = [[ css = [[
sup { font-size: 50%; vertical-align: super; } sup { font-size: 50% !important; vertical-align: super !important; }
sub { font-size: 50%; vertical-align: middle; } sub { font-size: 50% !important; vertical-align: middle !important; }
]], ]],
separator = true, separator = true,
}, },
@ -66,30 +91,6 @@ sub { font-size: 50%; vertical-align: middle; }
css = [[* { font-size: inherit !important; }]], css = [[* { font-size: inherit !important; }]],
separator = true, separator = true,
}, },
{
title = _("Links color and weight"),
{
id = "a_black";
title = _("Links always black"),
css = [[a { color: black !important; }]],
},
{
id = "a_blue";
title = _("Links always blue"),
css = [[a { color: blue !important; }]],
separator = true,
},
{
id = "a_bold";
title = _("Links always bold"),
css = [[a { font-weight: bold !important; }]],
},
{
id = "a_not_bold";
title = _("Links never bold"),
css = [[a { font-weight: normal !important; }]],
},
},
}, },
{ {
title = _("Miscellaneous"), title = _("Miscellaneous"),
@ -129,12 +130,20 @@ img {
title = _("Workarounds"), title = _("Workarounds"),
{ {
id = "html_tags_fix"; id = "html_tags_fix";
title = _("Fix some HTML elements"), title = _("Correct handling of some HTML elements"),
description = _("Make some HTML elements (eg: <cite>) behave as they should (inline/block).\nThis may break past bookmarks and highlights."), description = _("Make some HTML elements (eg: <cite>) behave as they should (inline/block).\nThis may break past bookmarks and highlights."),
css = [[ css = [[
cite { display: inline; font-style: italic; } cite { display: inline; font-style: italic; }
]], ]],
}, },
{
id = "list_item_block";
title = _("Better rendering of list items"),
description = _("Correctly render list items as block elements.\nThis may break past bookmarks and highlights."),
css = [[
li {display: -cr-list-item-block; }
]],
},
{ {
id = "list_items_fix"; id = "list_items_fix";
title = _("Fix some list items issues"), title = _("Fix some list items issues"),
@ -143,6 +152,7 @@ cite { display: inline; font-style: italic; }
li > p:first-child { display: inline !important; } li > p:first-child { display: inline !important; }
li > div:first-child { display: inline !important; } li > div:first-child { display: inline !important; }
]], ]],
separator = true,
}, },
{ {
id = "border_all_none"; id = "border_all_none";

Loading…
Cancel
Save