View Single Post
Old 02-07-2020, 06:39 AM   #747
wzyboy
Junior Member
wzyboy began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Sep 2012
Device: Kindle Keyboard 3G, Kindle Paperwhite [1-4]
Workaround for vertical text and ruby

Hi, I would like to share a workaround from my friend, to deal with books with vertical text and/or ruby tags.

Japanese (ja) and Traditional Chinese (zh, zh-tw) books are printed vertically. They also sometimes use special HTML tags called "ruby": https://developer.mozilla.org/en-US/...L/Element/ruby

However, for some reason, Kindle Previewer only supports vertical text and ruby tags for Japanese (dc:language=ja) books. If you feed a Chinese book (dc:language=zh or dc:language=zh-tw) with vertical text to Kindle Previewer, it will simply reject it with error message: https://www.mobileread.com/forums/sh...&postcount=456

For ruby tags, Kindle Previewer fails silently if the book does not have dc:language=ja set.

Strangely, the requirement of dc:language=ja only exists in Kindle Previewer. A Chinese ePub book with vertical text and ruby tags could be converted to KF8 (.azw3) without any issues with KindleGen.

So, to support vertifical text and ruby tags in KFX, one should set xml:lang=ja even for non-Japanese books:

Code:
--- a/previewer_prep_epub.py	2020-01-18 07:55:20.000000000 +0000
+++ b/previewer_prep_epub.py	2020-02-07 02:14:33.000000000 +0000
@@ -406,6 +406,11 @@
                         lang.text = "en"
                         fixed = True
 
+                    if lang.text.lower().partition(" ")[0] in ["zh", "zh-tw"]:
+                        self.log.info("Changed EPUB language from '%s' to 'ja'" % lang.text)
+                        lang.text = "ja"
+                        fixed = True
+
                     if FIX_LANGUAGE_SUFFIX and "-" not in lang.text:
                         current_language_pattern = re.compile(re.escape(lang.text) + "(-.+)?$", re.IGNORECASE)
                         best_language_variant, best_language_count = lang.text, 0
This hack, however, will result Japanese fonts to be used for non-Japanese books. A custom font should be used to remedy this.

Could we consider add this hack (but maybe not enabled by default) to the KFX output plugin?



BTW, calibre currently does not recognize -webkit-writing-mode and -epub-writing-mode and strips these CSS during conversion. So one must use calibre-debug to run KFX Output, instead of using calibre GUI.

I have attached a sample Chinese ePub file with vertical text and ruby. After setting the language to "ja" in KFX Output plugin, it could be rendered without issues on Kindle Paperwhite 4.
Attached Thumbnails
Click image for larger version

Name:	screenshot_2020_02_06T17_15_16-0801.png
Views:	122
Size:	15.6 KB
ID:	176984  
Attached Files
File Type: epub vertical-text-with-ruby.epub (2.1 KB, 148 views)
wzyboy is offline   Reply With Quote