|
|
#1276 |
|
Junior Member
![]() Posts: 3
Karma: 10
Join Date: Nov 2026
Device: Kindle for PC
|
|
|
|
|
|
|
#1277 |
|
Junior Member
![]() Posts: 1
Karma: 10
Join Date: Nov 2026
Device: none
|
kfxlib: empty inline spans counted as 0 positions (locate_offset errors)
Hi jhowell,
Thank you for KFX Input. I found an offset counting problem in kfxlib (KFX Input 2.34.2, kfxlib 20260827, calibre 9.18.0, macOS) that affects some Japanese Kindle books. Some of them fail to convert, and others convert with misplaced ruby. Symptom Conversion stops with errors like: Code:
ERROR: locate_offset failed to find offset 30 (remaining=0, split_after=True, dropcap=False) in b'<div id="a2KF">...' ERROR: locate_offset failed to find offset 34 (remaining=4, split_after=False, dropcap=False) in ... Cause These books contain empty inline containers between words (render $283, no content, e.g. style min-width: 1px; height: 0.113%; vertical-align: text-top). process_content turns them into an empty <span style="-kfx-render: inline">. Amazon counts each of them as one position in the style event offsets. locate_offset_in handles them in the span branch first, where len(text) == 0, so they take no position. Every following style event then lands too early. Example (footnote 19 of B00QT9X8EG): Code:
text: "19 Dr. Paul Carus著、Taotei King." style events (offset, length): (3,3) (9,4) (16,5) (25,6) (34,5) Suggested fix (yj_to_epub_content.py) 1. locate_offset_in: count an empty span (no text, no children) with -kfx-render: inline as one position, like img. 2. split_span: remove -kfx-render from a span that becomes empty after the split. Otherwise the empty part of a zero-length split could be mistaken for such a container. Code:
--- a/kfxlib/yj_to_epub_content.py
+++ b/kfxlib/yj_to_epub_content.py
@@ -1651,6 +1651,14 @@
if elem.tail:
log.error("locate_offset found tail in %s element" % elem.tag)
+
+ if (elem.tag == "span" and not elem.text and len(elem) == 0 and
+ self.get_style(elem).get("-kfx-render") == "inline"):
+ # empty inline container: Amazon counts it as one position
+ if offset_query == 0:
+ return elem
+
+ return offset_query - 1
if elem.tag == "span":
text_len = unicode_len_(elem.text or "")
@@ -1736,6 +1744,12 @@
parent = old_span.getparent()
parent.insert(parent.index(old_span) + 1, new_span)
+
+ for e in (old_span, new_span):
+ if not e.text and len(e) == 0:
+ sty = self.get_style(e)
+ if sty.pop("-kfx-render", None) is not None:
+ self.set_style(e, sty)
return new_span
I converted 22 KFX books to EPUB with and without the change: - 16 randomly chosen books (Japanese and English): byte-identical output. - The 4 failing books: 0 errors. Text, ruby text, ids and links are unchanged. Only the placement of ruby and nowrap spans changes, and it now matches the intended words (e.g. 文(ぶん)藻(そう), 電(でん)堆(つい), "John" instead of "ohn "). Two Kindle samples in the same batch fail with "Book is incomplete … (Missing fragments $550)". I think that is unrelated. Best regards |
|
|
|
| Advert | |
|
|
|
|
#1278 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,455
Karma: 96111109
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
Quote:
Looking further at the potential cause of the error it appears that my check for correct image dimensions was a little too restrictive. I will relax it a bit in the next release of the plugin which should eliminate the error for those books. |
|
|
|
|
|
|
#1279 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,455
Karma: 96111109
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
Quote:
Thank you for providing the patch. I will do some testing of your changes and as long as I do not experience any problems I will include it in the next release of this plugin. |
|
|
|
|
|
|
#1280 | |
|
Junior Member
![]() Posts: 3
Karma: 10
Join Date: Nov 2026
Device: Kindle for PC
|
Quote:
|
|
|
|
|
| Advert | |
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| KFX conversion, transfer back to library issue. | shoelesshunter | Conversion | 12 | 09-22-2025 10:49 AM |
| [Conversion Input] Microsoft Doc Input Plugin | igi | Plugins | 77 | 03-08-2025 05:04 AM |
| [Conversion Input] LaTeX Formulas Input Conversion Plugin | sevyls | Plugins | 0 | 03-23-2015 06:52 AM |
| [Input Plugin] DOCX Input | SauliusP. | Plugins | 42 | 06-05-2013 05:01 AM |
| Looking For MHT Input Conversion Plugin | FlooseMan Dave | Plugins | 4 | 03-30-2010 06:52 PM |