MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Kobo Reader (https://www.mobileread.com/forums/forumdisplay.php?f=223)
-   -   How to invoke different fonts in CSS 2.3.1? (https://www.mobileread.com/forums/showthread.php?t=200216)

xuyn2003 12-22-2012 02:56 AM

How to invoke different fonts in CSS 2.3.1?
 
Dear all,
After updated glo to 2.3.1, some thing went wrong.

for example CSS:

Quote:

@font-face {
font-family:"zw";
url(res:///fonts/zw.ttf)
}

@font-face {
font-family:"ht";
url(res:///fonts/ht.ttf)
}
is worked well on 2.2, but failed on firmware 2.3.1.

Is anybody know how to fix the url?
Thanks!

davidfor 12-22-2012 03:31 AM

I didn't know you could do that. The path used when referring to the books includes "mnt/onboard/". I would try:

res:///mnt/onboard/fonts/ht.ttf

xuyn2003 12-22-2012 03:40 AM

Thank you Davidfor, I will have a try through this directory.

jackie_w 12-22-2012 05:01 PM

I got quite hopeful for a moment when I read xuyn2003's OP.

I have been successfully using variations on this theme for several years on my Sonys and PocketBook. When I first got the Kobo Glo I tried every 'magic path' I could think of to access external fonts in /fonts to display monospace and small-caps fonts for the few of my epubs which need them. (BTW the Kobo is the first reader I've owned which doesn't contain a monospace font. It must be difficult to read programming manuals without one.)

I'm pretty sure I tried both res:///mnt/onboard/fonts/xxx.ttf and res:///fonts/xxx.ttf but had no success whatsoever on fw2.1.5. In the end, the only way I could successfully use the special fonts was by embedding them in the epub when necessary. I've just retested with res:///fonts/xxx.ttf, but still no joy.

Given the problems I'm reading about fw 2.3.1 I've decided to stick with fw 2.1.5 for the time being, but if this unofficial v2.2 really works I'd be quite tempted to try it.

Has anyone else had success accessing the Kobo font directory from within an epub's css file?

robko 12-22-2012 06:22 PM

Quote:

Originally Posted by jackie_w (Post 2352474)
Has anyone else had success accessing the Kobo font directory from within an epub's css file?

Any particular reason you're trying to do it this way rather than just dump the font on the Kobo and picking it as the desired font when you open the book the 1st first time? It should maintain the font setting for each book, so you only need to change font once.

tshering 12-22-2012 06:35 PM

Quote:

Originally Posted by jackie_w (Post 2352474)
Has anyone else had success accessing the Kobo font directory from within an epub's css file?

Not strictly from an epub's css, but from an kepub.epub's. There, it is sufficient to write the font name without path. For instance,

Code:

body {font-family:"Arial Unicode MS"}
.sa {font-size: 130%;
      font-family:"Sanskrit 2003"}

The Kobo knows the location of the font files.

Edit: I am on 2.1.5

jackie_w 12-22-2012 07:29 PM

Quote:

Originally Posted by robko (Post 2352524)
Any particular reason you're trying to do it this way rather than just dump the font on the Kobo and picking it as the desired font when you open the book the 1st first time? It should maintain the font setting for each book, so you only need to change font once.

Perhaps I didn't explain it well enough. I have some books which have certain portions of text (not the whole book) with css style {font-family: monospace}. The Kobo seems to render these portions in the font selected in the font menu, i.e. as if the styling was {font-family: serif}.

For example, I do not want computer code snippets rendered in the book's main serif font. Neither do I want the same book's main body text rendered in a special monospace font. I want a serif font for the main book and a monospace font for the code snippets.

If I wanted to read a book which is a screenplay -- usually rendered completely in monospace -- it wouldn't be a problem to load and select a monospace font from the font list for the whole book.

I have a similar problem with some of my own created epubs which need some portions only in a small-caps font. I was quite happy to create them this way because rendering small-caps was not a problem on any of my previous readers -- mainly because of MR community hacking offerings it has to be said. I do not know of any ereader which can support font-variant: small-caps as standard.

jackie_w 12-22-2012 07:33 PM

Quote:

Originally Posted by tshering (Post 2352535)
Not strictly from an epub's css, but from an kepub.epub's. There, it is sufficient to write the font name without path. For instance,

Code:

body {font-family:"Arial Unicode MS"}
.sa {font-size: 130%;
      font-family:"Sanskrit 2003"}

The Kobo knows the location of the font files.

Edit: I am on 2.1.5

Ah-ha, OK. I hadn't thought of that.:bulb2: I don't own any kepubs. I'll experiment a bit by renaming one of my sideloaded epubs.

robko 12-22-2012 08:19 PM

Quote:

Originally Posted by jackie_w (Post 2352587)
For example, I do not want computer code snippets rendered in the book's main serif font. Neither do I want the same book's main body text rendered in a special monospace font. I want a serif font for the main book and a monospace font for the code snippets.

That makes total sense. It would be a pain to not have those rendered monospace.

xuyn2003 12-23-2012 03:40 AM

Quote:

Originally Posted by jackie_w (Post 2352592)
Ah-ha, OK. I hadn't thought of that.:bulb2: I don't own any kepubs. I'll experiment a bit by renaming one of my sideloaded epubs.

Hi Jackie,
Have you find the solution?

xuyn2003 12-23-2012 03:42 AM

Quote:

Originally Posted by davidfor (Post 2351797)
I didn't know you could do that. The path used when referring to the books includes "mnt/onboard/". I would try:

res:///mnt/onboard/fonts/ht.ttf

res:///mnt/onboard/fonts/ht.ttf, I failed on this directory, I think kobo 2.3.1 changed the mechanism of invoking fonts.
So grateful.

hubertphava 12-23-2012 05:06 AM

I put this in my epubs:

Code:

font-face {
font-family: "Name of the Font";
font-weight: normal;
font-style: normal;
src: url(../Fonts/name_of_the_font.ttf);
}

and it'll works well, both in kobo and non-kobo devices.
This manner sigil would validate your epub and you'll be sure that you can read it correctly in every ereader you want.



HTH

HP

xuyn2003 12-23-2012 08:45 AM

Quote:

Originally Posted by hubertphava (Post 2352825)
I put this in my epubs:

Code:

font-face {
font-family: "Name of the Font";
font-weight: normal;
font-style: normal;
src: url(../Fonts/name_of_the_font.ttf);
}

and it'll works well, both in kobo and non-kobo devices.
This manner sigil would validate your epub and you'll be sure that you can read it correctly in every ereader you want.



HTH

HP

Thank you hubertphava, what is the firmware version of your kobo?
I was sucessful in 2.2 but failed in 2.3 firmware.

jackie_w 12-23-2012 02:01 PM

1 Attachment(s)
@xuyn2003 & hubertphava,

I can get any font I want to display as long as I embed it inside the epub, which (if I'm not mistaken) is the method hubertphava is describing.

I've had no success at all typing something in the epub css file in an attempt to directly reference a font stored in the Kobo /fonts directory. I've tried both xuyn2003's and tshering's suggestions and neither work for me with fw 2.1.5.

In case anyone is interested I'll share a few other things that I found out.
  • For a sideloaded epub (see attached image sorry for my poor camera skills)
    Code:

    epub css style              displayed font
    --------------              ---------------
    no font-family specified    font selected from font list
    font-family: serif          built-in "Document Default" (Georgia)
    font-family: sans-serif    built-in "Avenir"
    font-family: monospace      font selected from font list

  • For a pseudo-kepub, i.e same sideloaded epub renamed to .kepub.epub
    Code:

    epub css style              displayed font
    --------------              ---------------
    no font-family specified    font selected from font list
    font-family: serif          font selected from font list
    font-family: sans-serif    font selected from font list
    font-family: monospace      font selected from font list


An accidental outcome is that for those people who would like to read with sans-serif font Avenir but don't because all italics are displayed instead as bold... If you add font-family: sans-serif; to your body css you should get the whole book displayed in Avenir with all italics, bold and bolditalics displayed correctly. If you look at line 3 in the attached image you can see this for yourself.

tshering 01-03-2013 12:04 PM

1 Attachment(s)
Quote:

Originally Posted by jackie_w (Post 2353330)
I've had no success at all typing something in the epub css file in an attempt to directly reference a font stored in the Kobo /fonts directory. I've tried both xuyn2003's and tshering's suggestions and neither work for me with fw 2.1.5.

For me it seems partly to work and partly not to work. As one can see on the picture Avenir is not working, the rest seems ok to me.
I wondered what happens if I select a font from the font menu. If the whole text is displayed in the selected font how can I go back to the original settings? When I select Amasis, Avenir and so on the whole text is displayed in the selected font, only if I select Sanskrit 2003 the css settings become active again.


All times are GMT -4. The time now is 06:52 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.