View Single Post
Old 04-11-2015, 04:05 PM   #29
dmapr
Evangelist
dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.dmapr ought to be getting tired of karma fortunes by now.
 
Posts: 469
Karma: 600816
Join Date: Sep 2009
Device: Kobo Aura HD, Kobo Aura One
Quote:
Originally Posted by jackie_w View Post
There are 2 methods depending on why your book needs monospace. I did document option 2 below somewhere in this forum but I can't, for the life of me, remember which thread it was part of, so here it is again:
  1. If you want to read the whole book in monospace (e.g. Screenplays often expect mono throughout) you just need to sideload a monospace font (preferably all 4 flavours, regular, italic, bold, bolditalic, but not essential) and pick the new mono font from the Kobo font menu. Don't forget to power off/on after adding new fonts.

  2. If there are just selected parts of a book which need to be mono (e.g. author wants to simulate an old typewritten letter, code samples in tech manuals).

    Firstly, make sure you've already sideloaded a monospace font into your Kobo fonts directory.

    Secondly, the internal css in the epub needs to have font-family: monospace in all the relevant places.

    Thirdly, you need to enable this feature in the calibre KOBOTOUCH driver. Then in your custom kobo_extra.css include css statements something along these lines (where Dark Courier is the internal name of my sideloaded mono font. It's important to make the code match the internal font name exactly)
    Code:
    @font-face {font-family: monospace; font-weight: normal; font-style: normal; src: url("res:///fonts/normal/Dark Courier")}
    @font-face {font-family: monospace; font-weight: bold; font-style: normal; src: url("res:///fonts/bold/Dark Courier")}
    @font-face {font-family: monospace; font-weight: normal; font-style: italic; src: url("res:///fonts/italic/Dark Courier")}
    @font-face {font-family: monospace; font-weight: bold; font-style: italic; src: url("res:///fonts/bolditalic/Dark Courier")}
    If you've only got a single ttf (i.e. only the regular), you can simplify the extra code in kobo_extra.css to
    Code:
    @font-face {font-family: monospace; src: url("res:///fonts/normal/Dark Courier")}
    Once you've added the mono stuff to your custom kobo_extra.css, all future epubs transferred to the Kobo via calibre will get the extra css inserted into the epub during the Send-to-Device process. The calibre library copy of the epub remains untouched. You don't need to worry about adding this extra mono css to epubs which won't need it as it will just be ignored.

I'm not sure whether option 2 will work for kepubs but it definitely works for standard epubs (at least in fw 3.1.1 and many earlier releases).

Sorry to drag out this old post, but I was trying to make monospace work with no avail following these steps and here's what I was able to determine:

The following lines are in my kobo_extra.css (and it doesn't matter whether the font file urls are single- or double-quoted):
Code:
@font-face {font-family: monospace; font-weight: normal; font-style: normal; src: url('res:///fonts/normal/Consolas')}
@font-face {font-family: monospace; font-weight: bold; font-style: normal; src: url('res:///fonts/bold/Consolas')}
@font-face {font-family: monospace; font-weight: normal; font-style: italic; src: url('res:///fonts/italic/Consolas')}
@font-face {font-family: monospace; font-weight: bold; font-style: italic; src: url('res:///fonts/bolditalic/Consolas')}
However, when the book is transferred to the device, here's what becomes of that CSS:
Code:
@font-face {
    font-family: monospace;
    font-weight: normal;
    font-style: normal;
    src: url(res:///fonts/normal/Consolas)
    }
@font-face {
    font-family: monospace;
    font-weight: bold;
    font-style: normal;
    src: url(res:///fonts/bold/Consolas)
    }
@font-face {
    font-family: monospace;
    font-weight: normal;
    font-style: italic;
    src: url(res:///fonts/italic/Consolas)
    }
@font-face {
    font-family: monospace;
    font-weight: bold;
    font-style: italic;
    src: url(res:///fonts/bolditalic/Consolas)
    }
Note that along with formatting the quotes around the urls were dropped. Now, if I paste the code from my kobo_extra.css directly into the EPUB's file stylesheet, the monospace works. If I use the kobo_extra.css, it doesn't. The quotes were the only significant difference I could see between the two. Any ideas what I might be doing wrong?
dmapr is offline   Reply With Quote