Conversion: Automatically set the page progression direction for books that do not have it set and have their primary language either Arabic or

Hebrew. Fixes #2592 (Automatically inserting page-progression-direction="rtl" in rtl languages ​​(Arabic and Hebrew))
This commit is contained in:
Kovid Goyal 2025-01-06 21:29:50 +05:30
parent bff5e922ae
commit 4b00f39ef0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 18 additions and 1 deletions

View File

@ -205,6 +205,7 @@ class EPUBOutput(OutputFormatPlugin):
from calibre.ebooks.oeb.transforms.filenames import UniqueFilenames
UniqueFilenames()(oeb, opts)
self.oeb.set_page_progression_direction_if_needed()
self.workaround_ade_quirks()
self.workaround_webkit_quirks()
self.upshift_markup()

View File

@ -188,6 +188,7 @@ class MOBIOutput(OutputFormatPlugin):
mobi_type = 'old' # Amazon does not support KF8 periodicals
create_kf8 = mobi_type in ('new', 'both')
self.oeb.set_page_progression_direction_if_needed()
remove_html_cover(self.oeb, self.log)
resources = Resources(oeb, opts, self.is_periodical,
add_fonts=create_kf8)
@ -313,6 +314,7 @@ class AZW3Output(OutputFormatPlugin):
self.oeb, self.opts, self.log = oeb, opts, log
opts.mobi_periodical = self.is_periodical
passthrough = getattr(opts, 'mobi_passthrough', False)
self.oeb.set_page_progression_direction_if_needed()
remove_duplicate_anchors(oeb)
resources = Resources(self.oeb, self.opts, self.is_periodical,

View File

@ -27,7 +27,7 @@ from calibre.translations.dynamic import translate
from calibre.utils.cleantext import clean_xml_chars
from calibre.utils.icu import numeric_sort_key
from calibre.utils.icu import title_case as icu_title
from calibre.utils.localization import __
from calibre.utils.localization import __, is_rtl_lang
from calibre.utils.short_uuid import uuid4
from calibre.utils.xml_parse import safe_xml_fromstring
from polyglot.builtins import codepoint_to_chr, iteritems, itervalues, string_or_bytes
@ -1823,6 +1823,16 @@ class OEBBook:
self.auto_generated_toc = True
self._temp_files = []
def set_page_progression_direction_if_needed(self):
if not self.spine.page_progression_direction:
try:
lang = self.metadata.language[0].value
if is_rtl_lang(lang):
self.spine.page_progression_direction = 'rtl'
except Exception:
raise
pass
def clean_temp_files(self):
for path in self._temp_files:
try:

View File

@ -610,3 +610,7 @@ def localize_website_link(url):
parts = list(parts)
parts[2] = path
return urlunparse(parts)
def is_rtl_lang(lang):
return lang[:2].lower() in ('ar', 'he')