Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add primary-writing-mode option ePub/azw3 output #1378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/calibre/ebooks/conversion/plugins/epub_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/calibre/ebooks/conversion/plugins/mobi_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down