diff --git a/src/calibre/ebooks/conversion/plugins/epub_output.py b/src/calibre/ebooks/conversion/plugins/epub_output.py index ac107e32e3d0..ee9a8c4ded3f 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_output.py +++ b/src/calibre/ebooks/conversion/plugins/epub_output.py @@ -125,6 +125,12 @@ class EPUBOutput(OutputFormatPlugin): ' actually need it.') ), + OptionRecommendation(name='primary_writing_mode', recommended_value=None, + help=_('The `primary-writing-mode` metadata for controlling page rendering order,' + ' reading mode and reader navigation. Valid values are: %s' % + ['horizontal-lr', 'horizontal-rl', 'vertical-lr', 'vertical-rl']) + ), + } recommendations = {('pretty_print', True, OptionRecommendation.HIGH)} @@ -236,6 +242,12 @@ def convert(self, oeb, output_path, input_plugin, opts, log): uuid = unicode_type(uuid4()) oeb.metadata.add('identifier', uuid, scheme='uuid', id=uuid) + valid_writing_mode = ['horizontal-lr', 'horizontal-rl', 'vertical-lr', 'vertical-rl'] + if opts.primary_writing_mode in valid_writing_mode: + self.oeb.metadata.add('primary-writing-mode', opts.primary_writing_mode) + _, direction = opts.primary_writing_mode.split('-') + self.oeb.spine.page_progression_direction = 'rtl' if direction == 'rl' else 'ltr' + if encrypted_fonts and not uuid.startswith('urn:uuid:'): # Apparently ADE requires this value to start with urn:uuid: # for some absurd reason, or it will throw a hissy fit and refuse diff --git a/src/calibre/ebooks/conversion/plugins/mobi_output.py b/src/calibre/ebooks/conversion/plugins/mobi_output.py index e0501ca63904..a4422667c5c8 100644 --- a/src/calibre/ebooks/conversion/plugins/mobi_output.py +++ b/src/calibre/ebooks/conversion/plugins/mobi_output.py @@ -306,6 +306,11 @@ class AZW3Output(OutputFormatPlugin): ' the book will not auto sync its last read position ' ' on multiple devices. Complain to Amazon.') ), + OptionRecommendation(name='primary_writing_mode', recommended_value=None, + help=_('The `primary-writing-mode` metadata for controlling page rendering order,' + ' reading mode and reader navigation. Valid values are: %s' % + ['horizontal-lr', 'horizontal-rl', 'vertical-lr', 'vertical-rl']) + ), } def convert(self, oeb, output_path, input_plugin, opts, log): @@ -318,6 +323,12 @@ def convert(self, oeb, output_path, input_plugin, opts, log): passthrough = getattr(opts, 'mobi_passthrough', False) remove_duplicate_anchors(oeb) + valid_writing_mode = ['horizontal-lr', 'horizontal-rl', 'vertical-lr', 'vertical-rl'] + if opts.primary_writing_mode in valid_writing_mode: + self.oeb.metadata.add('primary-writing-mode', opts.primary_writing_mode) + _, direction = opts.primary_writing_mode.split('-') + self.oeb.spine.page_progression_direction = 'rtl' if direction == 'rl' else 'ltr' + resources = Resources(self.oeb, self.opts, self.is_periodical, add_fonts=True, process_images=False) if not passthrough: