View Single Post
Old 08-02-2013, 01:22 AM   #158
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Driver update - Modify CSS during send

With calibre 0.9.42, there is a new function added to the KoboTouch driver. This is to modify the stylesheets in an ePub during the send. The idea is to add CSS rules to the existing stylesheets in the ePubs to change the way a book is displayed.

Setup
To use this, you need to do the following:
  • Check the new option "Modify CSS" on the driver options. Note: if you have previously had the "Attempt to support new firmware" option selected, this might already be selected.
  • Create a file called "kobo_extra.css" in the root directory of your Kobo eReader
  • In this file, add any CSS rules that you want for all your books.
  • Send the books to your Kobo

What Happens
Then, when sending the books, the driver reads "kobo_extra.css" and does the following:
  • If there are any "@page" rules in "kobo_extra.css", it removes any existing @page rules from the stylesheets in the epub.
  • If any rules in "kobo_extra.css" have "widows" or "orphans" setting, all "widows" or "orphans" are removed from CSS rules in the stylesheets.
  • The contents of "kobo_extra.css" are appended at the end of all stylesheets in the ePub.

Example CSS Rule
A simple example of how this can be used is to put the following in "kobo_extra.css":
Code:
body {
	orphans: 1;
	widows: 1;
	}
That will allow the text to more fully fill the screen rather than keep lines in a paragraph together.

Disclaimer and Warnings
  • Use this at your own risk. These changes have been tested extensively, but, there still could be problems.
  • If a book is protected by DRM, it cannot be modified. It will be sent to the device unchanged.
  • If a book is already on the device, it must be resent to be modified.
  • The contents of "kobo_extra.css" must be valid CSS rules. If they are not, the ePub will probably not be displayed on the device properly.
  • The instructions above probably don't make sense. I'll fix them as people ask questions. Or if I'm really lucky, someone who can string sensible sentences together will do it for me

Acknowledgements
This would not have happened without help from people around here. jackie_w supplied a prototype for the changes which worked very well, and then tested and critiqued my changes. jgoguen helped with making sure it was compatible with the KoboTouchExtended driver. And supplied some much needed suggestions and testing. As always, Kovid of course was there when needed. Plus my beta testers who I always pick on

Support
As always, if you find a problem with the driver, please report it here. In detail. The more detail, the better. In this case, I will probably need to see the ePub that you are having problems with and the contents of your "kobo_extra.css". If the ePub is under copyright, please do not post it here. I will arrange another way to get it.

Last edited by davidfor; 07-16-2014 at 07:25 PM. Reason: Correct values for widows and orphans
davidfor is offline   Reply With Quote