diff --git a/base b/base index 96b4291d6..919327a4f 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 96b4291d630f591d5ab271542cd5b43a3fb568d9 +Subproject commit 919327a4f7d7a0ee2c4e1a31d6e7222f622a9061 diff --git a/frontend/ui/data/css_tweaks.lua b/frontend/ui/data/css_tweaks.lua index 70ce3e92b..4edab628a 100644 --- a/frontend/ui/data/css_tweaks.lua +++ b/frontend/ui/data/css_tweaks.lua @@ -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; diff --git a/frontend/ui/wikipedia.lua b/frontend/ui/wikipedia.lua index dd62dbade..4e94f56d2 100644 --- a/frontend/ui/wikipedia.lua +++ b/frontend/ui/wikipedia.lua @@ -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([[%s]], 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([[ - + %s @@ -1273,7 +1315,7 @@ table { %s -]], 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).