From 908b3dfef0baec7edca9c164fcf83d3198b45ccd Mon Sep 17 00:00:00 2001 From: Yoshiki Shibukawa Date: Wed, 31 Aug 2016 00:11:30 +0900 Subject: [PATCH 1/3] Epub3Builder supports vertical writing mode --- sphinx/builders/epub3.py | 36 +++++++++++++++++-- .../epub/static/{epub.css => epub.css_t} | 11 ++++++ 2 files changed, 44 insertions(+), 3 deletions(-) rename sphinx/themes/epub/static/{epub.css => epub.css_t} (97%) diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 9630f41a3..fd32b4df6 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -70,6 +70,7 @@ PACKAGE_DOC_TEMPLATE = u'''\ %(version)s true true + %(ibook_scroll_axis)s @@ -129,12 +130,41 @@ class Epub3Builder(EpubBuilder): files, spine, guide) metadata['description'] = self.esc(self.config.epub3_description) metadata['contributor'] = self.esc(self.config.epub3_contributor) - metadata['page_progression_direction'] = self.esc( - self.config.epub3_page_progression_direction) or 'default' + metadata['page_progression_direction'] = self._page_progression_direction() + metadata['ibook_scroll_axis'] = self._ibook_scroll_axis() metadata['date'] = self.esc(datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")) metadata['version'] = self.esc(self.config.version) return metadata + def _page_progression_direction(self): + if self.config.epub3_writing_mode == 'horizontal': + page_progression_direction = 'ltr' + elif self.config.epub3_writing_mode == 'vertical': + page_progression_direction = 'rtl' + else: + page_progression_direction = 'default' + return self.esc(page_progression_direction) + + def _ibook_scroll_axis(self): + if self.config.epub3_writing_mode == 'horizontal': + scroll_axis = 'vertical' + elif self.config.epub3_writing_mode == 'vertical': + scroll_axis = 'horizontal' + else: + scroll_axis = 'default' + return self.esc(scroll_axis) + + def _css_writing_mode(self): + if self.config.epub3_writing_mode == 'vertical': + editing_mode = 'vertical-rl' + else: + editing_mode = 'horizontal-tb' + return editing_mode + + def prepare_writing(self, docnames): + super(Epub3Builder, self).prepare_writing(docnames) + self.globalcontext['theme_writing_mode'] = self._css_writing_mode() + def new_navlist(self, node, level, has_child): """Create a new entry in the toc from the node at given level.""" # XXX Modifies the node @@ -232,4 +262,4 @@ def setup(app): app.add_config_value('epub3_description', '', 'epub3', string_classes) app.add_config_value('epub3_contributor', 'unknown', 'epub3', string_classes) - app.add_config_value('epub3_page_progression_direction', 'ltr', 'epub3', string_classes) + app.add_config_value('epub3_writing_mode', 'horizontal', 'epub3', string_classes) diff --git a/sphinx/themes/epub/static/epub.css b/sphinx/themes/epub/static/epub.css_t similarity index 97% rename from sphinx/themes/epub/static/epub.css rename to sphinx/themes/epub/static/epub.css_t index 6b72901c3..ab8610072 100644 --- a/sphinx/themes/epub/static/epub.css +++ b/sphinx/themes/epub/static/epub.css_t @@ -11,6 +11,17 @@ /* -- main layout ----------------------------------------------------------- */ +{% if theme_writing_mode is defined %} +body{ + writing-mode: {{ theme_writing_mode }}; + line-break: normal; + -epub-writing-mode: {{ theme_writing_mode }}; + -webkit-writing-mode: {{ theme_writing_mode }}; + -epub-line-break: normal; + -webkit-line-break: normal; +} +{% endif %} + div.clearer { clear: both; } From ddd0d192e1b9c4348fd93ebd7afd7d4b220b0147 Mon Sep 17 00:00:00 2001 From: Yoshiki Shibukawa Date: Wed, 31 Aug 2016 01:40:15 +0900 Subject: [PATCH 2/3] Add warning when conf.py uses deprecated epub3_page_progression_direction option --- sphinx/builders/epub3.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index fd32b4df6..44c384bfa 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -111,6 +111,13 @@ class Epub3Builder(EpubBuilder): content_template = PACKAGE_DOC_TEMPLATE doctype = DOCTYPE + # Warning deprecated option + def init(self): + if self.config.epub3_page_progression_direction: + self.warn('epub3_page_progression_direction option is deprecated' + ' from 1.5. Use epub3_writing_mode instead of this.') + super(Epub3Builder, self).init() + # Finish by building the epub file def handle_finish(self): """Create the metainfo files and finally the epub.""" @@ -263,3 +270,4 @@ def setup(app): app.add_config_value('epub3_description', '', 'epub3', string_classes) app.add_config_value('epub3_contributor', 'unknown', 'epub3', string_classes) app.add_config_value('epub3_writing_mode', 'horizontal', 'epub3', string_classes) + app.add_config_value('epub3_page_progression_direction', '', 'epub3', string_classes) From 87019afe975ec7415662d233e52c5a34b14b5c79 Mon Sep 17 00:00:00 2001 From: Yoshiki Shibukawa Date: Wed, 31 Aug 2016 01:40:31 +0900 Subject: [PATCH 3/3] fix CHANGES and document --- CHANGES | 2 ++ doc/config.rst | 27 +++++++++++++++++++++++++++ sphinx/builders/epub3.py | 6 +++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index b2678bdcf..86d7679fc 100644 --- a/CHANGES +++ b/CHANGES @@ -47,6 +47,7 @@ Incompatible changes * `html_translator_class` is now deprecated. Use `Sphinx.set_translator()` API instead. * Drop python 3.3 support +* Drop epub3 builder's ``epub3_page_progression_direction`` option (use ``epub3_writing_mode``). Features added -------------- @@ -113,6 +114,7 @@ Features added * #646: ``option`` directive support '.' character as a part of options * Add document about kindlegen and fix document structure for it. * #2474: Add ``intersphinx_timeout`` option to ``sphinx.ext.intersphinx`` +* #2926: EPUB3 builder supports vertical mode (``epub3_writing_mode`` option) Bugs fixed ---------- diff --git a/doc/config.rst b/doc/config.rst index 52aa0992b..fb77769d0 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1460,6 +1460,30 @@ the `Dublin Core metadata `_. .. versionadded:: 1.2 +.. confval:: epub3_writing_mode + + It specifies writing direction. It can accept ``'horizontal'`` (default) and + ``'vertical'`` + + .. list-table:: + :header-rows: 1 + :stub-columns: 1 + + - * ``epub3_writing_mode`` + * ``'horizontal'`` + * ``'vertical'`` + - * writing-mode [#]_ + * ``horizontal-tb`` + * ``vertical-rl`` + - * page progression + * left to right + * right to left + - * iBook's Scroll Theme support + * scroll-axis is vertical. + * scroll-axis is horizontal. + + .. [#] https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode + .. confval:: epub3_page_progression_direction The global direction in which the content flows. @@ -1471,6 +1495,9 @@ the `Dublin Core metadata `_. .. versionadded:: 1.4 + .. deprecated:: 1.5 + Use ``epub3_writing_mode``. + .. _latex-options: Options for LaTeX output diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 44c384bfa..d706867fa 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -54,7 +54,7 @@ PACKAGE_DOC_TEMPLATE = u'''\ + prefix="ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"> %(lang)s @@ -150,7 +150,7 @@ class Epub3Builder(EpubBuilder): page_progression_direction = 'rtl' else: page_progression_direction = 'default' - return self.esc(page_progression_direction) + return page_progression_direction def _ibook_scroll_axis(self): if self.config.epub3_writing_mode == 'horizontal': @@ -159,7 +159,7 @@ class Epub3Builder(EpubBuilder): scroll_axis = 'horizontal' else: scroll_axis = 'default' - return self.esc(scroll_axis) + return scroll_axis def _css_writing_mode(self): if self.config.epub3_writing_mode == 'vertical':