Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 11-24-2026, 11:07 PM   #1276
rkk
Junior Member
rkk began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Nov 2026
Device: Kindle for PC
Quote:
Originally Posted by jhowell View Post
It would be helpful to know some of the specific books for which the error occurs. The ten character ASIN (Bxxxxxxxxx) is the most useful.
I've only run into this issue with a couple of books so far, with the ASIN B0D86K49V2 and B0D86CJ34T.
rkk is offline   Reply With Quote
Old 11-25-2026, 07:02 AM   #1277
Chwalin
Junior Member
Chwalin began at the beginning.
 
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 ...
I saw this in 4 Iwanami Bunko books. ASIN B00QT9X8EG (茶の本) has 2 errors; the other three have 1, 34 and 39. In books that convert without errors, the same shift silently puts ruby and white-space: nowrap on the wrong characters. For example, the ruby ぶん/そう meant for 文藻 ends up on the characters after it.

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)
The events only match "Dr.", "Paul", "Carus", "Taotei" and "King." if each empty inline span counts as 1. kfxlib counts 30 positions in this paragraph, so the last two events overflow.

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
Testing

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
Chwalin is offline   Reply With Quote
Old 11-25-2026, 12:09 PM   #1278
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 7,455
Karma: 96111109
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
Quote:
Originally Posted by rkk View Post
I've only run into this issue with a couple of books so far, with the ASIN B0D86K49V2 and B0D86CJ34T.
Thank you for the added information. Unfortunately those book editions are not available in my region and the English language equivalent for one of them uses different page dimensions and does not exhibit the problem.

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.
jhowell is online now   Reply With Quote
Old 11-25-2026, 01:09 PM   #1279
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 7,455
Karma: 96111109
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
Quote:
Originally Posted by Chwalin View Post
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.
I have not come across the problem you describe, which is not surprising since I have tested this plugin with only a limited number of Japanese language books.

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.
jhowell is online now   Reply With Quote
Old 11-25-2026, 07:57 PM   #1280
rkk
Junior Member
rkk began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Nov 2026
Device: Kindle for PC
Quote:
Originally Posted by jhowell View Post
Thank you for the added information. Unfortunately those book editions are not available in my region and the English language equivalent for one of them uses different page dimensions and does not exhibit the problem.

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.
I see, thank you so much for looking into it, and for your continued efforts to maintain this plugin.
rkk is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 08:53 AM.


MobileRead.com is a privately owned, operated and funded community.