bump crengine: multiple fallback fonts (#6090)

Includes:
- Simplify libunibreak includes
- Text: fix read/write outside array bounds
- lvtextfm: dont adjust space after initial quotation mark/dash (rework)
- Fonts: allow providing and using multiple fallback fonts

Users can set their prefered fallback font, which will be completed
with a few of our shipped fonts for maximum coverage.
reviewable/pr6093/r1
poire-z 4 years ago committed by GitHub
parent b4f3f177ca
commit 7d83a0c967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 09d22ad029c08f768460269e24a8c83708d7a698 Subproject commit d74120a1c308f89cd002eeec93591d4ed80f693f

@ -60,7 +60,7 @@ function ReaderFont:init()
text_func = function() text_func = function()
-- defaults are hardcoded in credocument.lua -- defaults are hardcoded in credocument.lua
local default_font = G_reader_settings:readSetting("cre_font") or self.ui.document.default_font local default_font = G_reader_settings:readSetting("cre_font") or self.ui.document.default_font
local fallback_font = G_reader_settings:readSetting("fallback_font") or self.ui.document.fallback_font local fallback_font = G_reader_settings:readSetting("fallback_font") or self.ui.document.fallback_fonts[1]
local text = v local text = v
if v == default_font then if v == default_font then
text = text .. "" text = text .. ""
@ -298,10 +298,9 @@ function ReaderFont:makeDefault(face, touchmenu_instance)
end, end,
choice2_text = C_("Font", "Fallback"), choice2_text = C_("Font", "Fallback"),
choice2_callback = function() choice2_callback = function()
if self.ui.document:setFallbackFontFace(face) then G_reader_settings:saveSetting("fallback_font", face)
G_reader_settings:saveSetting("fallback_font", face) self.ui.document:setupFallbackFontFaces()
self.ui:handleEvent(Event:new("UpdatePos")) self.ui:handleEvent(Event:new("UpdatePos"))
end
if touchmenu_instance then touchmenu_instance:updateItems() end if touchmenu_instance then touchmenu_instance:updateItems() end
end, end,
}) })

@ -28,7 +28,32 @@ local CreDocument = Document:new{
line_space_percent = 100, line_space_percent = 100,
default_font = "Noto Serif", default_font = "Noto Serif",
header_font = "Noto Sans", header_font = "Noto Sans",
fallback_font = "Noto Sans CJK SC",
-- 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)
-- - FreeSerif after most, has it has good coverage but smaller glyphs
-- (and most other fonts are better looking)
-- - FreeSans covers areas that FreeSerif do not, and is usually
-- fine along other fonts (even serif fonts)
-- - Noto Serif & Sans at the end, just in case, and to have consistent
-- (and larger than FreeSerif) '?' glyphs for codepoints not found
-- in any fallback font. Also, we don't know if the user is using
-- a serif or a sans main font, so choosing to have one of these early
-- might not be the best decision (and moving them before FreeSans would
-- require one to set FreeSans as fallback to get its nicer glyphes, which
-- would override Noto Sans CJK good symbol glyphs with smaller ones
-- (Noto Sans & Serif do not have these symbol glyphs).
fallback_fonts = {
"Noto Sans CJK SC",
"Noto Sans Arabic UI",
"Noto Sans Devanagari UI",
"FreeSans",
"FreeSerif",
"Noto Serif",
"Noto Sans",
},
default_css = "./data/cr3.css", default_css = "./data/cr3.css",
provider = "crengine", provider = "crengine",
provider_name = "Cool Reader Engine", provider_name = "Cool Reader Engine",
@ -165,13 +190,12 @@ function CreDocument:setupDefaultView()
self._document:readDefaults() self._document:readDefaults()
logger.dbg("CreDocument: applied cr3.ini default settings.") logger.dbg("CreDocument: applied cr3.ini default settings.")
-- set fallback font face (this was formerly done in :init(), but it -- set fallback font faces (this was formerly done in :init(), but it
-- affects crengine calcGlobalSettingsHash() and would invalidate the -- affects crengine calcGlobalSettingsHash() and would invalidate the
-- cache from the main currently being read document when we just -- cache from the main currently being read document when we just
-- loadDocument(only_metadata) another document go get its metadata -- loadDocument(only_metadata) another document to get its metadata
-- or cover image, eg. from History hold menu). -- or cover image, eg. from History hold menu).
self._document:setStringProperty("crengine.font.fallback.face", self:setupFallbackFontFaces()
G_reader_settings:readSetting("fallback_font") or self.fallback_font)
-- adjust font sizes according to dpi set in canvas context -- adjust font sizes according to dpi set in canvas context
self._document:adjustFontSizes(CanvasContext:getDPI()) self._document:adjustFontSizes(CanvasContext:getDPI())
@ -601,20 +625,25 @@ function CreDocument:setFontFace(new_font_face)
end end
end end
function CreDocument:setFallbackFontFace(new_fallback_font_face) function CreDocument:setupFallbackFontFaces()
if new_fallback_font_face then local fallbacks = {}
logger.dbg("CreDocument: set fallback font face", new_fallback_font_face) local seen_fonts = {}
self._document:setStringProperty("crengine.font.fallback.face", new_fallback_font_face) local user_fallback = G_reader_settings:readSetting("fallback_font")
-- crengine may not accept our fallback font, we need to check if user_fallback then
local set_fallback_font_face = self._document:getStringProperty("crengine.font.fallback.face") table.insert(fallbacks, user_fallback)
logger.dbg("CreDocument: crengine fallback font face", set_fallback_font_face) seen_fonts[user_fallback] = true
if set_fallback_font_face ~= new_fallback_font_face then end
logger.info("CreDocument:", new_fallback_font_face, "is not usable as a fallback font") for _, font_name in pairs(self.fallback_fonts) do
return false if not seen_fonts[font_name] then
table.insert(fallbacks, font_name)
seen_fonts[font_name] = true
end end
self.fallback_font = new_fallback_font_face
return true
end end
-- We use '|' as the delimiter (which is less likely to be found in font
-- names than ',' or ';', without the need to have to use quotes.
local s_fallbacks = table.concat(fallbacks, "|")
logger.dbg("CreDocument: set fallback font faces:", s_fallbacks)
self._document:setStringProperty("crengine.font.fallback.face", s_fallbacks)
end end
-- To use the new crengine language typography facilities (hyphenation, line breaking, -- To use the new crengine language typography facilities (hyphenation, line breaking,

Loading…
Cancel
Save