06-19-2011, 04:38 AM | #106 |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@Idolse - so can you post what such CSS will look like with all the possible variations and what you want done to it?
|
06-19-2011, 06:36 AM | #107 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
Kovid might be better able to comment on this, but I believe you can use cssutils (already bundled into Calibre) to parse the css canonically - i.e. you wouldn't need to worry about all the potential string level variations in the css file. I've never worked with cssutils myself, so I'm not 100% sure it's applicable.
Docs: http://cssutils.googlecode.com/svn/t.../docs/css.html If you're just going to parse as a string then I suppose the trick would be to look for 'body' or 'page' and then grab the text between the next pair of open and closing brackets. Then either delete or zero any margins that are set. Anyway here's an example: Code:
.tp { margin-top: 1em; margin-bottom: 1em; margin-left: -.4em; text-align: center; } @page { margin-bottom: 1em;margin-left: 1em;margin-right: 1em;margin-top: 1em;} body { margin-bottom: 1em;margin-left: 1.5em;margin-right: 1.5em;margin-top: 1em;} .center { text-align:center; } .small { font-size: -1em; } Code:
.tp { margin-top: 1em; margin-bottom: 1em; margin-left: -.4em; text-align: center; } @page { margin-bottom: 0em;margin-left: 0em;margin-right: 0em;margin-top: 0em;} body { margin-bottom: 0em;margin-left: 0em;margin-right: 0em;margin-top: 0em;} .center { text-align:center; } .small { font-size: -1em; } Code:
.tp { margin-top: 1em; margin-bottom: 1em; margin-left: -.4em; text-align: center; } @page { } body { } .center { text-align:center; } .small { font-size: -1em; } |
Advert | |
|
06-19-2011, 09:53 AM | #108 |
Guru
Posts: 776
Karma: 2751519
Join Date: Jul 2010
Location: UK
Device: PW2, Nexus7
|
Code:
font-size: -1em |
06-19-2011, 09:56 AM | #109 |
Chasing Butterflies
Posts: 3,132
Karma: 5074169
Join Date: Mar 2011
Location: American Southwest
Device: Uses batteries.
|
I really appreciate all the work that everyone is putting into this. I have nothing of value to contribute except cheerleading, but YOU GO GUYS! Especially KiwiDude!
|
06-19-2011, 10:27 AM | #110 |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@capnm - thanks for sending me the epub.
The problem is caused by the mimetype of the ncx file - it is set to "text/xml" rather than something more conventional like "application/x-dtbncx+xml". To fix this requires a change to the Calibre code. ebooks.epub.fix.container.py - line 181 - currently just looks for mt.endswith('+xml') To be honest I may give up on using the Calibre class - I already override half the functions in it anyway to either "fix" things to the requirements for this plugin or add functionality. That would allow the plugin to be changed independently of the Calibre source. @Idolse - thx for your post. I think I would probably go down the text replacement route to minimise the impact on the CSS file, should just be a case of figuring out an appropriate regex to use. |
Advert | |
|
06-19-2011, 12:22 PM | #111 |
Groupie
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
|
I ran a couple of searches against my library to see what variations of @page, body were in the css.
Some books have multiple css files. I'd just say "no" to messing with those. There were a couple with extra labeled @page statements, which aren't 'book level'. My first thought was that therefore this variant shouldn't be touched, but as I reconsider, it probably doesn't matter. Code:
#cover @page { margin-top: 0; } Some books had multiple body statements. I think simplest would be to just delete all occurrences of the five margin properties in all the @page and body statements. Fancier would be to then insert a user configured string to set the four margins. The plugin configuration could ask for four numbers, or, my preference, ask for a string. Asking for a string is simple and powerful, but leaves more room for user error Here are some other example variations: Code:
body { margin: 0; padding: 0; border-width: 0; font-size: 95%; text-align: justify; line-height: 120%; font-family:sans-serif; } @page { margin: 3pt; } Code:
@page { margin: 14pt 0pt 16pt 0pt; } body { margin: 0 auto; padding: 0.75em 5%; } |
06-19-2011, 01:15 PM | #112 |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thx for the extra posts. They show just how complicated the variations are. I think allowing a user to set values would make things even more complicated as then you have the whole units thing - em, in, pt, px, % etc.
So what is the difference between @page and body anyway? How do they relate? I'll be honest, my enthusiasm for this has always been lukewarm for this as in editing hundreds of ePubs I haven't once hit one that needed this. If it was trivial then I would jump in and add it, but I think the examples above show it isn't. If someone else is prepared to knock up the Python code I will happily make the effort to integrate it. Just write a function assuming you have the contents of a CSS file as input and I can take care of the rest, either PM it to me or post it here... |
06-19-2011, 02:51 PM | #113 | ||
Groupie
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
|
Unfortunately Python is way outside my comfort zone.
Quote:
Or you could just ask for a string and offer "margin-left: 5pt; margin-right: 5pt; margin-top: 10pt; margin-bottom: 10pt;" as an example. That way if the user provides an invalid string it's their fault , but it's also empowers those with a little knowledge (or daring). Quote:
body defines the text block, the "default" font, fontsize, spacing, etc and can have margins for the text inside the page box. Actually I'm a little confused by Idolse's example, because I don't think you can use em units (which are font size dependent) at the @page level, only fixed units or %. But maybe that's just more poor coding by commercial publishers I *think*, as Idolse said, search the css for @page or body then grab the text between the {} following, then strip out anything that begins "margin" and ends with a ";" should complete margin removal. Then to add the desired margins you could just add them to the first @page or body you found. Or a little cleaner would be to add a new @page. Cleaner still would be to then completely delete existing any @page that is now empty. And I wouldn't try too hard for perfection on this -- if it doesn't produce the desired result that just means the user has to hand edit that book if they really care. And hopefully my blather will help whoever can be talked into coding this |
||
06-20-2011, 08:23 AM | #114 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
Regarding all the weirdness in my css example, both Agama's and Capnm's queries - it's not my css, it's the publisher's. I don't really know why they've done what they've done in those specific examples, I just know I have an a lot of margin on these books as I think the @page and body are cumulative, which is different from how margins work inside of body.
@kiwidude, if you're just going to go the string manipulation route and aren't feeling too motivated I can give this one a shot and mock something up. |
06-20-2011, 09:13 AM | #115 |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@Idolse - sure, go for it, using whatever means you think appropriate. My hesitation in using cssutils is that (a) I have never used it before, and (b) I am presuming it would result in writing out a completely new css file. Which introduces the "potential" for something else to be changed within it. Maybe it is me being paranoid, but of course the philosophy behind this plugin is to make as minimal changes as is possible to the ePub.
So if you can come up with something that covers all your scenarios and can send it to me that would be great. |
06-20-2011, 11:30 AM | #116 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
v0.3.2 beta
Changes in this Release
Well here goes. For now I just included this as an additional function tied to the Adobe xpgt checkbox, partially because I don't like messing with gui's so much, and partially because one checkbox to remove all the junk margins makes a bit more sense to me. Your call if you want to change it. Note this only removes margins - replacing with a user configurable margin isn't quite so easy, so I'm just going to leave that alone for now. I've just tested on a handful of epubs, so use at your own risk. btw, if you want to add a check for this to quality check, the regex to run against css is: Code:
re.compile(r'(?P<element_id>#\w+\s+)?(?P<selector>\bbody|@page)\b\s*{(?P<styles>[^}]+margin[^}]+);?\s*\}', re.IGNORECASE) Last edited by ldolse; 06-20-2011 at 10:15 PM. Reason: Updated regex, removed old version |
06-20-2011, 12:02 PM | #117 |
Groupie
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
|
|
06-20-2011, 12:49 PM | #118 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
One variation I didn't cover just now - I couldn't find any books in my library that use #id in front of body or @page like capnm's example. I think I know how these should be handled, but I'd like a real example to test. If someone can PM me with a sample I'd appreciate it.
BTW, I searched through my library, and I've got several hundred epubs that have some sort of margin set on these selectors, it's almost as common as xpgt by itself, though I suspect in many cases the margins aren't quite as egregious... |
06-20-2011, 01:37 PM | #119 | |
Groupie
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
|
Quote:
e.g. https://www.mobileread.com/forums/sho...d.php?t=117930 |
|
06-20-2011, 10:12 PM | #120 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
v0.3.3 beta
Changes in this release:
I updated some of the dialog text based on silence being tacit approval to leave this tied with the xpgt margin removal, simple enough to change later if desired. I've tested these changes on quite a few more files now and all seems fine. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Any web-to-epub plugin for internet browser? | bthoven | ePub | 7 | 07-10-2011 05:14 AM |
[Old Thread] Reading epub on viewer inexplicably changes the time stamp of epub | greenapple | Library Management | 20 | 03-19-2011 10:18 PM |
Easy way to modify thread subscription emails in bulk? | snipenekkid | Feedback | 11 | 02-06-2011 03:47 AM |
Another plugin dev question | DiapDealer | Plugins | 2 | 12-11-2010 01:46 PM |
Epub plugin dev | DiapDealer | Plugins | 15 | 11-12-2010 09:36 AM |