Native KEPUB conversion causing some justification issues

Bug #2107778 reported by Hengyu Lim
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

As discussed on the Mobileread forums, Calibre 8's native KEPUB conversion leads to a slightly different final output in how the justified text appears around some of the punctuation that seems a little buggy and uneven, compared to the output from Calibre 7 using the extended Kobo driver.

I'm attaching 3 files,

- The original EPUB
- The final output KEPUB using Calibre 7 + extended driver, retrieved from the device
- The final output KEPUB using Calibre 8, retrieved from the device

Revision history for this message
Hengyu Lim (hengyu95) wrote :
Revision history for this message
Carlos (the-carlos) wrote :

Because I was bored, I've done some searching, and this is what I've found.

In the original file, the sentence in question is:

This hinges on understanding what we <i class="calibre2">can</i> and <i class="calibre2">cannot</i> control.

In the file generated with v7:

This hinges on understanding what we</span> <i class="calibre2"><span class="koboSpan" id="kobo.21.1">can</span></i> <span class="koboSpan" id="kobo.22.1">and</span> <i class="calibre2"><span class="koboSpan" id="kobo.23.1">cannot</span></i> <span class="koboSpan" id="kobo.24.1">control.</span> <span class="koboSpan" id="kobo.24.2">

In the file generated with v8:

This hinges on understanding what we </span><i class="calibre2"><span class="koboSpan" id="kobo.6.11">can</span></i><span class="koboSpan" id="kobo.6.12"> and </span><i class="calibre2"><span class="koboSpan" id="kobo.6.13">cannot</span></i><span class="koboSpan" id="kobo.6.14"> control. </span><span class="koboSpan" id="kobo.6.15">

Hope this helps.

Revision history for this message
Kovid Goyal (kovid) wrote :

Looks like kobo rendered barfs if trailing space after sentence is not
moved to next span, sigh.

Should be an easy fix, when I have a moment.

Revision history for this message
Hengyu Lim (hengyu95) wrote :

Thanks Carlos!

Seems like the spaces around the word "and" is outside the span tags in the old version as well, and if they were inside the span the Kobo engine does not adjust them like the rest of the spaces for justification?

Revision history for this message
Kovid Goyal (kovid) wrote :

Not a bug as far as I can see. Moving the spaces out of the spans will
mean that when you try to highlight the text you get unsightly breaks
in the highlight because of the spaces not in spans. This was explicitly
changed to fix bug number: 2103926.

I will note that the standalone kepubify tool also matches calibre 8
output. Basically, the justification engine in the Kobo firmware needs
to be fixed. As it stands it cannot do both proper justification and
highlighting at the same time.

Changed in calibre:
status: New → Invalid
Revision history for this message
Hengyu Lim (hengyu95) wrote (last edit ):

Could there maybe be an option to switch between the two then?

I think it's quite likely that many people would rather have unsightly breaks in highlighting than broken justification that looks like this, and the only fix is to stay on Calibre 7 forever

Revision history for this message
Kovid Goyal (kovid) wrote :

Not something I am interested in implementing, but patches are welcome.

Revision history for this message
Hengyu Lim (hengyu95) wrote :

Alternatively, might there be the possibility to simply resume supporting KoboExtendedTouch in latest Calibre versions?

Revision history for this message
Kovid Goyal (kovid) wrote : Re: [Bug 2107778] Re: Native KEPUB conversion causing some justification issues

On Tue, Apr 22, 2025 at 01:16:05PM -0000, Hengyu Lim wrote:
> Alternatively, might there be the possibility to simply resume
> supporting KoboExtendedTouch in latest Calibre versions?

Definitely not. I am not going to be on the hook for maintaining
code I haven't written.

Revision history for this message
Hengyu Lim (hengyu95) wrote :

Is there any particular reason why the original plugin is not able to run on Calibre 8? Given that it's now the only way to get functional KEPUB justification, which is a pretty fundamental aspect of reading on a eBook device, it would be great if we could just stick to using the plugin!

Revision history for this message
Kovid Goyal (kovid) wrote :

It's been over a month since calibre 8 was released with over a million
downloads and you are the first person to complain about justification.
Justification is definitely not a fundamental aspect of reading.
Justification on the Kobo is badly broken. I suggest you complain to
Kobo to fix it, or turn it off. Or submit a PR adding an option for moving
spaces outside spans. I have spent enough time on this. Good luck.

Revision history for this message
Hengyu Lim (hengyu95) wrote :

Hey man, fair enough.

I definitely get the take that a lot of the blame lies on Kobo's own rendering.

I'm not sure why nobody else noticed, but I'm sure even you would agree from the screenshots that justification as it is now IS objectively broken, where it wasn't before.

I can respect that you value gapless highlighting is more important than justification, and that you personally feel strongly about this. I'm just not sure why the existing plugin needs to be de-supported since it offers an *alternate* functionality that would complement your implementation that only serves to improve the experience for everyone.

No need to get hostile, and apologies if I have offended.

Revision history for this message
Jackie Stockdale (jackiestockdale) wrote :

Hope you don't mind me commenting because I have posted about this issue on MR several times since 2016.

Restoring the old KoboTouchExtended plugin functionality would not solve anything. Users have been complaining about "choppy full justification" in kepubs long before calibre v8 was released.

As you have already noticed, the problems show up at the junction of 2 consecutive koboSpans. The problem is at its worst when:
- a kepub is styled with text-align:justify
- a kepub is styled with text-rendering:optimizeLegibility (or geometricPrecision) either via the CSS file or via the Kobo on-device config file. Either of these is needed to enable font ligatures/kerning in kepubs.
- a large font-size and/or wide left/right margins are in use.

I don't believe the basic problem can be "fixed" without Kobo's intervention, but it could be improved, at least for some users, by doing:
1. Move any leading and/or trailing space outside each koboSpan. This would upset those who object to gaps in highlights (as you've already seen).

2. Minimise the number of koboSpans created by removing the requirement to split a paragraph's text into sentences, i.e. create one koboSpan per-node not per-sentence. I don't know whether this would upset anyone because I don't use note-taking/highlighting much.

3. Even without 1 & 2, some users report a small improvement by reducing the inter-word gap a little via CSS (e.g. body {word-spacing: -0.05em}). The KoboTouch driver's Modify CSS option can be used to do this (or kobopatch also has this option)

Revision history for this message
Hengyu Lim (hengyu95) wrote :

Hi Jackie,

Thank you for your insights.

Does the old plugin functionality not do option 1? I've downgraded to Calibre 7 and I'm using the old plugin and I'm golden for now, and the trailing spaces are outside spans in my current KEPUB outputs and text justification looks correct.

I think most people reading novels would do text justification (like how printed pieces of literature tend to look) and not have the need to highlight things. I think that's a worthy trade-off I can make there.

It's just that I'd like to not be stuck on Calibre 7 for the rest of time, and was of the opinion that it could be just a simple checkbox in the conversion process. Is there an alternate way to get option 1?

Does this also mean that official KEPUBS that are purchased OOTB also have broken text justification by default?

Revision history for this message
Jackie Stockdale (jackiestockdale) wrote :

Hi Hengyu,

Re: option 1, the old KTE plugin never used to allow any space chars outside the koboSpans, but it sounds as if your info may be more up-to-date than mine. I haven't used the official KTE plugin since 2016 when I forked it for my own version but I did keep a casual eye on official updates until late last year. I stopped looking when all those KTE update problems arose with "lost spaces" due to faulty regex in the koboSpan creation. Perhaps that's when trailing spaces suddenly appeared outside the spans. By this time, my own plugin had drifted so far from the original due to constant tinkering that detailed comparisons were pointless.

As far as I know official Kobo kepubs are still delivered with ALL body text enclosed within spans. I had a look at one of my own purchased kepubs to check, but it was quite an old book. I don't usually keep originals once it's in calibre and I've de-kepubified it for archive.

Revision history for this message
Kovid Goyal (kovid) wrote :

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

Changed in calibre:
status: Invalid → Fix Released
Revision history for this message
Hengyu Lim (hengyu95) wrote :

Very much appreciated, thank you Kovid!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.