bump crengine: text typography by language (#6069)

Includes:
- Fix a few clang-tidy warnings
- Add support for <img src="data:image/png;base64,...>
- XML parsing: add more HTML5 named entities, optimize search
- Text: fix standalone BR not making an empty line
- Fix BR with "display: block" not making an empty line
- Fix hyphens from soft-hyphens not part of highlighted segments
- Use libunibreak for line breaking
- Adds TextLangMan for text typography by language

Tweak ReaderHyphenation to work with the new TextLangMan
(even if it will be replaced soon by ReaderTypography).
reviewable/pr6072/r1
poire-z 4 years ago committed by GitHub
parent 377bbe77ed
commit 6336927cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 3091ad3096f3646af8abf8ee6422e4626055c9db
Subproject commit 504b967463f1ecdd62807837537ed7d655b9527a

@ -44,6 +44,10 @@ function ReaderHyphenation:init()
local alg_right_hyphen_min = hyph_settings.right_hyphen_min
local hyph_limits_widget = DoubleSpinWidget:new{
-- Min (1) and max (10) values are enforced by crengine
-- Note that when hitting "Use language defaults", we show the default
-- values from languages.json, but we give 0 to crengine, which will
-- use its own default hardcoded values (in textlang.cpp).
-- Try to keep these values in sync.
left_value = G_reader_settings:readSetting("hyph_left_hyphen_min") or alg_left_hyphen_min or 2,
left_min = 1,
left_max = 10,
@ -65,9 +69,8 @@ These settings will apply to all books with any hyphenation dictionary.
callback = function(left_hyphen_min, right_hyphen_min)
G_reader_settings:saveSetting("hyph_left_hyphen_min", left_hyphen_min)
G_reader_settings:saveSetting("hyph_right_hyphen_min", right_hyphen_min)
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or alg_left_hyphen_min)
self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or alg_right_hyphen_min)
self.ui.toc:onUpdateToc()
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or 0)
self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or 0)
-- signal readerrolling to update pos in new height, and redraw page
self.ui:handleEvent(Event:new("UpdatePos"))
end
@ -83,7 +86,6 @@ These settings will apply to all books with any hyphenation dictionary.
callback = function()
G_reader_settings:flipNilOrFalse("hyph_trust_soft_hyphens")
self.ui.document:setTrustSoftHyphens(G_reader_settings:isTrue("hyph_trust_soft_hyphens"))
self.ui.toc:onUpdateToc()
self.ui:handleEvent(Event:new("UpdatePos"))
end,
checked_func = function()
@ -127,10 +129,7 @@ These settings will apply to all books with any hyphenation dictionary.
text = T(_("Changed hyphenation to %1."), BD.wrap(v.name)),
})
self.ui.document:setHyphDictionary(v.filename)
-- Apply hyphenation sides limits
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or v.left_hyphen_min)
self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or v.right_hyphen_min)
self.ui.toc:onUpdateToc()
-- (No need to apply hyphenation sides limits: previous values will stick)
-- signal readerrolling to update pos in new height, and redraw page
self.ui:handleEvent(Event:new("UpdatePos"))
end,
@ -258,6 +257,9 @@ function ReaderHyphenation:onReadSettings(config)
logger.dbg("Hyphenation: no algo set")
self:setHyphAlgo()
logger.dbg("Hyphenation: keeping current crengine algo:", self.hyph_alg)
-- Note: it would be better to select English_US here, rather than
-- keeping the hyph dict possibly set from the previous book language,
-- to keep it consistent and avoid a re-rendering on the new book.
end
function ReaderHyphenation:onPreRenderDocument(config)
@ -291,14 +293,14 @@ function ReaderHyphenation:setHyphAlgo(hyph_alg)
-- If we haven't set any (nil, or invalid), hardcoded
-- English_US.pattern (in cre.cpp) will be used
self.hyph_alg = cre.getSelectedHyphDict()
-- Apply hyphenation sides limits
local hyph_settings = self.hyph_algs_settings[self.hyph_alg] or {}
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or hyph_settings.left_hyphen_min)
self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or hyph_settings.right_hyphen_min)
-- Apply hyphenation sides limits (default to 0, to use language defaults)
self.ui.document:setHyphLeftHyphenMin(G_reader_settings:readSetting("hyph_left_hyphen_min") or 0)
self.ui.document:setHyphRightHyphenMin(G_reader_settings:readSetting("hyph_right_hyphen_min") or 0)
self.ui.document:setTrustSoftHyphens(G_reader_settings:isTrue("hyph_trust_soft_hyphens"))
end
function ReaderHyphenation:addToMainMenu(menu_items)
self.hyph_table.max_per_page = 5
-- insert table to main reader menu
menu_items.hyphenation = {
text = self.hyph_menu_title,

@ -17,9 +17,9 @@ describe("ReaderLink module", function()
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(4)
readerui.link:onTap(nil, {pos = {x = 320, y = 120}})
assert.is.same(36, readerui.rolling.current_page)
readerui.rolling:onGotoPage(5)
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
assert.is.same(37, readerui.rolling.current_page)
end)
it("should jump to links in pdf page mode", function()
@ -56,11 +56,11 @@ describe("ReaderLink module", function()
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(4)
readerui.link:onTap(nil, {pos = {x = 320, y = 120}})
assert.is.same(36, readerui.rolling.current_page)
readerui.rolling:onGotoPage(5)
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
assert.is.same(37, readerui.rolling.current_page)
readerui.link:onGoBackLink()
assert.is.same(4, readerui.rolling.current_page)
assert.is.same(5, readerui.rolling.current_page)
end)
it("should be able to go back after link jump in pdf page mode", function()

Loading…
Cancel
Save