03-29-2017, 03:50 AM | #1 |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2017
Location: MX
Device: Calibre
|
Detect when font changes in EPUB
I am trying to use or create and event listener when the user changes the font size of the EPUB in an ereader with Javascript but I haven't find the way.
What I have tried without success: * A `resize` event listener. * A timing event that measures the font size. * A listener that measures the scale of the `viewport`. In `ebook-viewer` (aka Calibre viewer) I can see in the inspector that every time I change the font size the console prints `Viewport cfi: /2/4/2/2/1:1`. I see that when `1:1` changes, it's some sort of scale in int numbers. That is why I tried to detect the viewport scale with [this](https://tombigel.github.io/detect-zoom/) or [this](http://menacingcloud.com/source/js/F...ewportScale.js). So I suppose it is possible only because I can see trough the inspector of `ebook-viewer`... All the tries didn't work on iOS either. |
03-29-2017, 09:59 AM | #2 |
Wizard
Posts: 1,610
Karma: 8399999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
|
03-29-2017, 04:45 PM | #3 |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2017
Location: MX
Device: Calibre
|
Spanish poetry
What I am trying to solve is that in spanish poetry when a verse is larger that the box's size, it has to be a break and the next line has to be right aligned with a bracket:
Code:
A short verse. A very very long [verse. So I was wondering how I can detect that change, I cant catch it with resize listener or inspecting the font size with a timer. So I think it is something related with some sort of scale, but the ways I have found to detect a change in the viewport scale doesnt work either. The link that you send it seems that have the same issue to detect that kind of change, at least in iBooks and ebook-viewer. |
03-29-2017, 06:34 PM | #4 |
Resident Curmudgeon
Posts: 76,395
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Before you do this, where are you planning on selling this eBook? It will have to be ePub 3 and not ePub 2 compatible.
|
03-29-2017, 06:55 PM | #5 | |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2017
Location: MX
Device: Calibre
|
Quote:
The script (poetry.js) is available here: https://github.com/ColectivoPerroTri...ript/poetry.js A working example: https://jsfiddle.net/dxr9azy7/ Last edited by NikaZhenya; 03-29-2017 at 08:09 PM. |
|
03-30-2017, 04:55 PM | #6 | |
Wizard
Posts: 1,610
Karma: 8399999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
The script in the post I sent you, does detect font changes in ADE 4.5 (that supports jscript and epub3). As you know, ADE is the norm regarding epub, so the fact the script works fine there, is a plus. However I couldn't get a way to detect font-size changes in others ereaders, mainly, due to the limitations of suchs ereaders. I'm afraid it'll be very difficult for you to find something to work fine in iOS El script que te indiqué, puede detectar (de hecho lo hace) cambios en el tamaño de fuente en ADE 4.5 (y si mal no recuerdo, también lo hacía en Calibre). Dado que ADE es el estándar respecto a epubs, el que funcione bien en esa plataforma es una ventaja. Pero veo muy difícil que puedas encontrar algo que funcione bien en iOS; los lectores para esa plataforma tienen muchas limitaciones respecto a javascript Saludos Rubén |
|
03-30-2017, 09:40 PM | #7 |
Junior Member
Posts: 5
Karma: 10
Join Date: Mar 2017
Location: MX
Device: Calibre
|
Yey! Because you are using the resize event I thought it was the same approach. But not, the trick is the iframe! Well, IT DOESN'T works with iOS, but it works in Calibre, I will test in ADE. And not only that, you helped me to simplify the code when I have to detect the font or window change, thanks!
If one day you need to display spanish poetry in spanish in a correct way, you can use the script UPDATE It works on Calibre, ADE, iBooks for Mac and iOS. It is a very good solution, thanks, Rubén. I left the sample. Chingón, Rubén, gracias! Last edited by NikaZhenya; 03-31-2017 at 02:51 AM. |
03-31-2017, 12:37 PM | #8 | ||||
Wizard
Posts: 1,610
Karma: 8399999
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Quote:
Quote:
Quote:
|
||||
Tags |
calibre, epub, font-size, javascript, viewport |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
NookPress doesn't detect chapters in epub | LostSock | ePub | 1 | 12-04-2014 11:19 PM |
Epub > Epub conversion changes font size.. why? | OllieDixon | Conversion | 2 | 03-31-2014 03:30 AM |
Convert an EPUB to EPUB, so that the font restriction is gone? | bookp | Conversion | 2 | 12-09-2013 09:46 AM |
Determine font and font size on incoming epub? | peaceridge | Calibre | 4 | 01-30-2012 04:35 PM |
how do I UN-font an epub? | affa | ePub | 4 | 04-20-2011 01:50 PM |