Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 06-10-2014, 02:53 AM   #31
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Thank you very much for this new try.
roger64 is offline   Reply With Quote
Old 06-12-2014, 03:50 AM   #32
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Hi

After various tries, it seems to work pretty well for longhand CSS stylesheets... but for shorthand. In this latter case, the script just ignores the shorthand properties and lefts it untouched. Adding shorthand to the script conversion capabilities is probably doable, but it would maybe begin to stretch dangerously the regex...

Before coming back - shameful - to pingouinux for this, I thought about another possible solution: I remarked in Calibre/Look and feel that we can use ebook-convert to expand css with the following option:

Code:
--expand-css
Would it be possible to integrate this in the script as a first move ?

Here is what we get when launching --expand-css alone:
After that, the script is working quite well.

Spoiler:

Code:
roger@lmde64:~/Bureau/essai2$ ebook-convert hun.epub hun2.epub --expand-css
1% Conversion de l’entrée en HTML…
InputFormatPlugin: EPUB Input running
on /home/roger/Bureau/essai2/hun.epub
Found HTML cover titlepage.xhtml
Parsing all content...
34% Démarrage des transformations du livre numérique…
Merging user specified metadata...
Detecting structure...
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Creating EPUB Output...
67% Exécution du plugin EPUB Output
Splitting markup on page breaks and flow limits, if any...
	Looking for large trees in index_split_012.xhtml...
	No large trees found
	Looking for large trees in index_split_015.xhtml...
	No large trees found
	Looking for large trees in index_split_013.xhtml...
	No large trees found
	Looking for large trees in index_split_002.xhtml...
	No large trees found
	Looking for large trees in index_split_004.xhtml...
	No large trees found
	Looking for large trees in index_split_016.xhtml...
	No large trees found
	Looking for large trees in index_split_014.xhtml...
	No large trees found
	Looking for large trees in index_split_017.xhtml...
	No large trees found
	Looking for large trees in index_split_001.xhtml...
	No large trees found
	Looking for large trees in index_split_005.xhtml...
	No large trees found
	Looking for large trees in index_split_007.xhtml...
	No large trees found
	Looking for large trees in index_split_018.xhtml...
	No large trees found
	Looking for large trees in index_split_019.xhtml...
	No large trees found
	Looking for large trees in index_split_000.xhtml...
	No large trees found
	Looking for large trees in index_split_008.xhtml...
	No large trees found
	Looking for large trees in index_split_006.xhtml...
	No large trees found
	Looking for large trees in index_split_010.xhtml...
	No large trees found
	Looking for large trees in index_split_011.xhtml...
	No large trees found
	Looking for large trees in index_split_003.xhtml...
	No large trees found
	Looking for large trees in index_split_009.xhtml...
	No large trees found
EPUB output written to /home/roger/Bureau/essai2/hun2.epub
Sortie sauvegardée vers   /home/roger/Bureau/essai2/hun2.epub
roger@lmde64:~/Bureau/essai2$


At that point also, also, we can wonder if it would not be better to integrate the script as a new option within ebook-convert...

Last edited by roger64; 06-12-2014 at 06:22 AM. Reason: integrate
roger64 is offline   Reply With Quote
Old 06-12-2014, 07:28 AM   #33
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by roger64 View Post
Hi

After various tries, it seems to work pretty well for longhand CSS stylesheets... but for shorthand. In this latter case, the script just ignores the shorthand properties and lefts it untouched. Adding shorthand to the script conversion capabilities is probably doable, but it would maybe begin to stretch dangerously the regex...

Before coming back - shameful - to pingouinux for this, I thought about another possible solution: I remarked in Calibre/Look and feel that we can use ebook-convert to expand css with the following option:

Code:
--expand-css
Would it be possible to integrate this in the script as a first move ?
That's not something I'm interested in doing. Calibre's code is highly modularized and all the various pieces are dependent upon other pieces (and each other) to function. Rarely can you just pull a small snippet of code from calibre to do what you need. The piece you pull on gets tangled up with one of its dependencies, and before you know it ... you've pulled a mile of code.

Quote:
Here is what we get when launching --expand-css alone:

After that, the script is working quite well.
But that's not running --expand-css alone. That's doing a full epub to epub conversion with --expand-css as an additional option.

Quote:
At that point also, also, we can wonder if it would not be better to integrate the script as a new option within ebook-convert...
That would be less daunting, for sure.
DiapDealer is offline   Reply With Quote
Old 06-12-2014, 09:03 AM   #34
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,851
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@DiapDealer: While it is certainly true that using code from the conversion pipeline is not always possible standalone, in this case you can do it with the container pretty easily, like this (insert the following into my previous example:

Code:
# assume we have a parsed stylesheet as I showed before
for rule in sheet.cssRules:
   if rule.type == rule.STYLE_RULE:
        for property in rule.style.keys():
               val = property.propertyValue
                for x in val:
                     if x.type == 'DIMENSION' and x.unit == 'cm':
                           x.cssText = convert(x.value )  # Here convert should convert a float into a string in em units
                            
container.dirty(sheet_name)
This is ofcourse, only a skeleton, it does not handle @media rules or <style> tags or style attributes, but those are all equally trivial, just look around in the files inthe polish directory to learn how to iterate over them.
kovidgoyal is offline   Reply With Quote
Old 06-12-2014, 09:14 AM   #35
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
I understand.

Using the full program ebook-convert when we just wish to expand the CSS is like using a hammer to kill a fly. We are miles away from your previous "micro-surgery" operation.

If you allow me to do it, I'd like to address Kovid Goyal about it. He alone, knows which part of the Calibre code is used specifically to expand a CSS style-sheet, and, who knows?, he would be so kind as to point to it? It can't be that huge. Once a stylesheet is taken out of the water, it seems a not so different job to expand it or to convert some of its values. and both could be done successively.

On the other hand, he could see a benefit to this as he could add the cm2em conversion feature to ebook-convert, which strangely, does not have it yet.


EDIT: when posting, I realized this was nearly done!! Thank you Kovid Goyal !!

Last edited by roger64; 06-12-2014 at 09:19 AM. Reason: posted without reading the previous message
roger64 is offline   Reply With Quote
Old 06-12-2014, 09:18 AM   #36
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by kovidgoyal View Post
@DiapDealer: While it is certainly true that using code from the conversion pipeline is not always possible standalone, in this case you can do it with the container pretty easily, like this (insert the following into my previous example:
I was thinking of a stand-alone script that could function without the presence of calibre, but you keep reminding me of the exciting possibilities for running stand-alone(ish) scripts on non-library epubs/azw3s using calibre's python environment via calibre-debug.

I definitely need to explore what I can do with this powerful (and highly bash scriptable) calibre plug-out functionality.

Thanks so much for the pointers to the relevant code!
DiapDealer is offline   Reply With Quote
Old 06-12-2014, 09:29 AM   #37
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
@DiapDealer

Thanks for trying!
roger64 is offline   Reply With Quote
Old 06-12-2014, 07:34 PM   #38
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
So this is what I have.
This is not a stand-alone python script.
You must have calibre installed.

You launch the script like so:
Code:
calibre-debug cm2em_calibre.py file.epub
Should catch rules that have dimension-type properties in cm and convert them to em (whether they're in short-hand notation or not).
It's not going to work with any rules inside of @media queries if your css gets that complicated, but it should catch everything else.

I included a sample batch file and a bash script if anyone is interested in launching this in a more permanent way.

REMEMBER! THIS SCRIPT WILL MODIFY THE EPUB YOU STARTED WITH ... MAKE SURE YOU HAVE BACKUPS BEFORE USING.
Attached Files
File Type: zip cm2em.zip (1.4 KB, 132 views)

Last edited by DiapDealer; 06-13-2014 at 12:55 PM.
DiapDealer is offline   Reply With Quote
Old 06-13-2014, 01:50 AM   #39
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
@DiapDealer

This was amazingly fast. I hurried to test it on three kinds of stylesheet, condensed, beautified and shorthand, and it worked beautifully for all. The code is very elegant and economical. It's a brand new and very effective solution. I could not dream a better one!

Congratulations to you and Kovid Goyal and many thanks for that.

1. - For the second script.

Forgive me, I am very unfamiliar with it. I understand it gives to calibre-debug the path to the main script (cm2em_calibre.py). I tried to make it work using a right-click, or from the command-line and failed. I will need some additional and basic explanations.

If we use this additional script and if we do not look at the terminal window, could it be possible to get some kind of feedback to know when the epub has been processed? (a text file, a window message, whatever)

2. - An innocent question:

Suppose we have a folder with some epubs. Could it be possible to batch treat them using *.epub? I tried it but it only processed the first one and stopped.

Last edited by roger64; 06-13-2014 at 04:39 AM.
roger64 is offline   Reply With Quote
Old 06-13-2014, 07:02 AM   #40
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by roger64 View Post
@DiapDealer

This was amazingly fast. I hurried to test it on three kinds of stylesheet, condensed, beautified and shorthand, and it worked beautifully for all. The code is very elegant and economical. It's a brand new and very effective solution. I could not dream a better one!

Congratulations to you and Kovid Goyal and many thanks for that.
Great! Glad it's working for you.

Quote:
1. - For the second script.

Forgive me, I am very unfamiliar with it. I understand it gives to calibre-debug the path to the main script (cm2em_calibre.py). I tried to make it work using a right-click, or from the command-line and failed. I will need some additional and basic explanations.

If we use this additional script and if we do not look at the terminal window, could it be possible to get some kind of feedback to know when the epub has been processed? (a text file, a window message, whatever)
I assume you mean the included bash script (Linux) and or batch file (Windows)? Those aren't intended to get you away from the necessity of using the terminal. They're just intended to simplify what you have to type in the terminal (or from copying the python script and/or epub into the same directory--or including lengthy paths). I'll tell you how I use it, and maybe that will help

1) I put the script (cm2em.sh) in /usr/local/bin.
2) rename it to simply cm2em.
3) make it executable.
4) open it in an editor and change SCRIPT_DIR to wherever my cm2em_calibre.py script will be living from now on.

After that bit of setup, I can open a terminal and cd to whatever directory the epub I want to work on resides in and simply type "cm2em file.epub" (without the quotes).

Quote:
2. - An innocent question:

Suppose we have a folder with some epubs. Could it be possible to batch treat them using *.epub? I tried it but it only processed the first one and stopped.
If you have the bash script setup similarly to how I described, you could cd into the folder (terminal) and type something like:
Code:
for i in *.epub; do cm2em "$i"; done

Last edited by DiapDealer; 06-13-2014 at 12:55 PM.
DiapDealer is offline   Reply With Quote
Old 06-13-2014, 09:08 AM   #41
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Hi

Thanks again for these crystal clear - and for me necessary - explanations. We can now enjoy a powerful new tool in a very handy way.

EDIT

I did some tries. Using the cm2em script is working well only when the name of the EPUB has no white space. If there is a white space, or a -, on the terminal, (the first one is replaced by antislash) I observe a failure of the main (cm2em_calibre.py) script.

When I was launching the main script directly from the command line, this did not happen. I could use epub file names with any kind of characters, including white spaces and -.

Last edited by roger64; 06-13-2014 at 10:38 AM.
roger64 is offline   Reply With Quote
Old 06-13-2014, 01:00 PM   #42
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by roger64 View Post
EDIT

I did some tries. Using the cm2em script is working well only when the name of the EPUB has no white space. If there is a white space, or a -, on the terminal, (the first one is replaced by antislash) I observe a failure of the main (cm2em_calibre.py) script.

When I was launching the main script directly from the command line, this did not happen. I could use epub file names with any kind of characters, including white spaces and -.
I sometimes forget that people still deal with whitespace in filenames. I refuse to.

Anyway, I updated the bash script so it won't barf on epub filenames with white-space (as long as you quote those filenames in the terminal command), and modified the command to process entire folders to do the same. I PM'ed you the details.
DiapDealer is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question: Find/Replace in css stylesheet ElMiko Sigil 12 12-25-2011 06:29 AM
ePub margins : @page vs stylesheet.css Agama Calibre 1 08-16-2010 04:37 PM
How to maintain a global CSS stylesheet amoroso Sigil 7 07-18-2010 08:37 PM
EPub conversion stylesheet.css problem nycaleksey Calibre 1 03-25-2010 11:42 PM
Where is the stylesheet.css? roger64 Sigil 4 03-23-2010 02:12 PM


All times are GMT -4. The time now is 11:56 PM.


MobileRead.com is a privately owned, operated and funded community.