EPUB: more support for RTL documents (#5436)

bump crengine: enhanced RTL block rendering.
Includes:
- Re-enable: Use the same FT load flags in HB as in FT
- Avoid redundant calls to getStyle()
- CSS: parse and store "direction:"
- Enhanced block rendering: handle RTL direction
- Enhanced block rendering: handle RTL tables
- Pagesplitting: account for lines' text direction
- CSS: add support for more pseudo-classes
- epub.css: a few updates for RTL documents
- Fix LVDocView::getBookmark() which could be slow or wrong

Add a few style tweaks useful to RTL readers.

Wikipedia Save as EPUB: build proper RTL documents from
persian, arabic, hebrew (and others) Wikipedia articles.
pull/5438/head
poire-z 5 years ago committed by GitHub
parent f7861bc1eb
commit 3e3b00429f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 96b4291d630f591d5ab271542cd5b43a3fb568d9
Subproject commit 919327a4f7d7a0ee2c4e1a31d6e7222f622a9061

@ -161,7 +161,48 @@ h1 + h6, h2 + h6, h3 + h6, h4 + h6, h5 + h6 { page-break-before: avoid !importan
id = "headings_align_center",
title = _("Center headings"),
css = [[h1, h2, h3, h4, h5, h6 { text-align: center !important; }]],
priority = 3, -- so it overrides the ones above
priority = 4, -- so it overrides the ones above
},
},
{
title = _("Text direction"),
{
title = _("About text direction"),
info_text = _([[
Languages like Arabic or Hebrew use right-to-left writing systems (Right-To-Left or RTL). This doesn't only affect text layout, but also list item bullets and numbers, which have to be put on the right side of the page, as well as tables, where the cells are laid out from right to left.
Usually, the publisher will have set the appropriate tags to enable RTL rendering. But if these are missing, or if you're reading plain text documents, you may want to manually enable RTL with these tweaks.
Note that in the absence of such specifications, KOReader will try to detect the language of each paragraph to set the appropriate rendering per paragraph.
You may also want to enable, in the top menu Gear Navigation , Invert page turn taps and swipes.]]),
separator = true,
},
{
id = "body_direction_rtl",
title = _("Document direction RTL"),
css = [[body { direction: rtl !important; }]],
priority = 2, -- so it overrides the LTR one below
},
{
id = "text_align_most_right",
title = _("Right align most text"),
description = _("Enforce right alignment of text in common text elements."),
-- Includes H1..H6 as this is probably most useful for RTL readers
css = [[body, p, li, h1, h2, h3, h4, h5, h6 { text-align: right !important; }]],
priority = 3, -- so it overrides the ones from Text alignment
},
{
id = "text_align_all_right",
title = _("Right align all elements"),
description = _("Enforce right alignment of text in all elements."),
css = [[* { text-align: right !important; }]],
priority = 3, -- so it overrides the ones from Text alignment
separator = true,
},
{
id = "body_direction_ltr",
title = _("Document direction LTR"),
css = [[body { direction: ltr !important; }]],
},
},
{
@ -280,7 +321,7 @@ This might be needed with some documents that expect this style as the default,
priority = -1,
css = [[
p {
text-align: left;
text-align: start;
text-indent: 0;
margin-top: 1em;
margin-bottom: 1em;

@ -655,6 +655,31 @@ local ext_to_mimetype = {
woff = "application/font-woff",
}
-- Display from these Wikipedia should be RTL
-- The API looks like it does not give any info about the LTR/RTL
-- direction of the content it returns...
-- (list made by quickly and manually checking links from:
-- https://meta.wikimedia.org/wiki/List_of_Wikipedias )
local rtl_wiki_code = {
fa = "Persian",
ar = "Arabic",
he = "Hebrew",
ur = "Urdu",
azb = "South Azerbaijani",
pnb = "Western Punjabi",
ckb = "Sorani",
arz = "Egyptian Arabic",
yi = "Yiddish",
sd = "Sindhi",
mzn = "Mazandarani",
ps = "Pashto",
glk = "Gilaki",
lrc = "Northern Luri",
ug = "Uyghur",
dv = "Divehi",
arc = "Aramaic",
ks = "Kashmiri",
}
-- Create an epub file (with possibly images)
function Wikipedia:createEpub(epub_path, page, lang, with_images)
@ -916,19 +941,19 @@ h1, h2 {
page-break-before: always;
page-break-inside: avoid;
page-break-after: avoid;
text-align: left;
text-align: start;
}
h3, h4, h5, h6 {
page-break-before: auto;
page-break-inside: avoid;
page-break-after: avoid;
text-align: left;
text-align: start;
}
/* Styles for our centered titles on first page */
h1.koreaderwikifrontpage, h5.koreaderwikifrontpage {
page-break-before: avoid;
text-align: center;
margin-top: 0em;
margin-top: 0;
}
p.koreaderwikifrontpage {
font-style: italic;
@ -955,7 +980,10 @@ a.newwikinonexistent {
/* Don't waste left margin for TOC, notes and other lists */
ul, ol {
margin-left: 0em;
margin-left: 0;
}
ul:dir(rtl), ol:dir(rtl) {
margin-right: 0;
}
/* OL in Wikipedia pages may inherit their style-type from a wrapping div,
* ensure they fallback to decimal with inheritance */
@ -982,12 +1010,18 @@ body > div > div.thumb {
/* Change some of their styles when floating */
-cr-only-if: float-floatboxes;
clear: right;
margin: 0em 0em 0.2em 0.5em !important;
margin: 0 0 0.2em 0.5em !important;
font-size: 80% !important;
/* Ensure a fixed width when not in "web" render mode */
-cr-only-if: float-floatboxes -allow-style-w-h-absolute-units;
width: 33% !important;
}
body > div:dir(rtl) > div.thumb { /* invert if RTL */
float: left !important;
-cr-only-if: float-floatboxes;
clear: left;
margin: 0 0.5em 0.2em 0 !important;
}
body > div > div.thumb img {
/* Make float's inner images 100% of their container's width when not in "web" mode */
-cr-only-if: float-floatboxes -allow-style-w-h-absolute-units;
@ -1034,6 +1068,9 @@ li.gallerybox {
/* Set a fixed width when not in "web" mode */
width: 25% !important;
}
li:dir(rtl).gallerybox {
float: right;
}
li.gallerybox p {
/* Reset indent as we have everything centered */
text-indent: 0;
@ -1259,8 +1296,13 @@ table {
local saved_on = T(_("Saved on %1"), os.date("%b %d, %Y %H:%M:%S"))
local online_version_htmllink = string.format([[<a href="%s/wiki/%s">%s</a>]], wiki_base_url, page:gsub(" ", "_"), _("online version"))
local see_online_version = T(_("See %1 for up-to-date content"), online_version_htmllink)
-- Set dir= attribute on the HTML tag for RTL languages
local html_dir = ""
if rtl_wiki_code[lang:lower()] then
html_dir = ' dir="rtl"'
end
epub:add("OEBPS/content.html", string.format([[
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml"%s>
<head>
<title>%s</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
@ -1273,7 +1315,7 @@ table {
%s
</body>
</html>
]], page_cleaned, page_htmltitle, lang:upper(), saved_on, see_online_version, html))
]], html_dir, page_cleaned, page_htmltitle, lang:upper(), saved_on, see_online_version, html))
-- Force a GC to free the memory we used till now (the second call may
-- help reclaim more memory).

Loading…
Cancel
Save