Append and modify CSS when sending epubs to Kobo devices

Bug #1207151 reported by David Forrester
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

This allows users to have a "kobo_extra.css" file in the root of their device containing CSS rules. This will be appended to all stylesheets in the epub. As well, if the extra rules contain an @page rule, any existing @page rules will be stripped from the stylesheets. Finally, if any of the extra rules include "widows" and "orphans" settings, these are stripped from the rules in the stylesheets.

There is an option added to the driver configuration to enable this action.

If an epub has DRM it cannot be modified but it will still be sent.

The changes have been coordinated with the author of the KoboTouchExtended driver. He has made changes so that these changes will not break his driver. And he will have a version ready to take advantage of the change.

Tags: kobo-driver
Revision history for this message
David Forrester (davidfor) wrote :
Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1207151

When looking for css files in the book, dont look for files that end
with .css, use mimetypes instead, namely, container.mime_map.

Also, note that unless an epub has previosuly been processesd by
calibre, there is no guarantee that its style info is in css files at
all. It could be in <style> tags or style attributes inside the html. So
if you want to apply extra css robustly, you would have to add a new
stylesheet and <link> to it from every html file. You would probably
also need to add !important to all style rules to try to ensure they
override the existing rules. However, using !important will probably
have other side effects, depending on how the reader in Kobo devices
works. Generally speaking, modifying css is a highly non-trivial
excercise, which is why the calibre conversion pipeline is as complex as
it is. You could just say that the extra css is a "best effort" thing,
where the driver does not guarantee that addingthe extra css will have
any effect at all, that is up to you.

Finally, if you re-order the options in the driver, saved settings will
break, since, IIRC, the saved settings are stored as a list with
individual settings at fixed indices, though I may be misremembering.

 status incomplete

Changed in calibre:
status: New → Incomplete
Revision history for this message
David Forrester (davidfor) wrote :

I'm a little bit embarrassed about missing the mimetype. Especially as I have done exactly that elsewhere. I have changed it (i.e. stole code from the polish font subsetting) and attached the patch.

As to the stylesheets and CSS, I understand all that. And I'm expecting lots of complaints. Your description of "best effort" is exactly what it is intended to be. To be honest, I'm a bit surprised at how well it works.

You are correct about how the options work. As I want to keep two specific options at the end, I added code a while ago to handle this. It isn't perfect, but it gets close to what I want.

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

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

 status fixreleased

Changed in calibre:
status: Incomplete → Fix Released
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.