MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   [Plugin] ConvertAbs2RelCSSValues (https://www.mobileread.com/forums/showthread.php?t=289473)

slowsmile 08-10-2017 09:33 PM

[Plugin] ConvertAbs2RelCSSValues
 
1 Attachment(s)
Converts cm, mm, inch, pica and point values to relative 'em' values in the css

Requirements
Plugin Type: Edit
MIT Licence(OSI)
Minimum Sigil requirement: v0.9.3 or higher
Requirements: Python 3.4+ (Bundled or External)
OS Requirements: Windows, Linux or OSX
Current Version: "0.1.4"

Installation
* Select Manage Plugins from the Plugins menu. In the dialog box, select either the Bundled Python or the External Python(Python 3.4+ should be installed on your computer to run this plugin externally).

* Click Add Plugin and select ConvertAbs2RelCSSValues_vXXX.zip. This will load and install the plugin into Sigil, which you can then select and run it using Plugins > Edit > ConvertAbs2RelCSSValues

Description
This is an edit plugin that automatically converts all absolute values such as cm, mm, inch, pica and point values to relative em values in the epub stylesheet(s). Depending on user choice, this plugin will also convert all shorthand forms of "padding" or "margin" to their long forms(see User Options). This plugin should only be used for standard epubs only(not epub 3).

Examples of the various shorthand forms for 'margin'(it's the same format for 'padding') are shown below:
margin: 0;
margin: 1.5pt 0;
margin 1pt 0pt 1.5pt;
margin 24pt 0pt 12pt 0pt;

The above forms will be converted to the long form. Example shown below:
margin-top: 2em;
margin-bottom: 1.0em;
margin-left: 1.5em;
margin-right: 0em;

The other benefit of converting to the long form is that certain ereaders like the Nook ereader are known to have problems with the shorthand forms of 'margin' and 'padding'. That's why it's much safer to use the long forms -- because using the long forms should never give you any problems on any ereader conversion.

User Dialog
This dialog will ask the user whether or not he/she wants to convert the 'margin' and 'padding' shorthand forms to their long forms. If 'Yes' is chosen then the shorthand forms will all be converted to the long form as before. But if 'No' is chosen then all the shorthand form values will be converted to 'em' values in place.

Plugin Run
First load your epub into Sigil and then just run this plugin.

Caveats
* This plugin will not convert pixel values or percentage values to 'em' values
* This plugin will not convert 'margin: 0 auto' to the long form.

In the past I've had several problems with sizing and spacing in my epub after I have converted my ebooks to the vendor format. I've read that some Nook readers have problems with the shorthand forms of both 'padding' and 'margin' properties. I've also had some weird problems using absolute values(e.g. pts, cm, mm, pc, etc) in the CSS with my Kindle conversions. Hopefully this plugin should go some way towards both saving you some time and will also help to alleviate most of these sizing and spacing problems in your epubs.

Update:
* Redesigned the absolute to relative value conversion with better precision.
* Added a dialog to choose whether or not to convert the shorthand margin/padding forms to their long forms.
* The plugin will now also convert all forms of shorthand margin/padding values to em values as well.

Changes

Spoiler:

v0.1.4
-- Now uses a standard tkinter askyesno dialog for the user dialog.
v0.1.3
-- Added MIT Licence
v0.1.2
-- Redesigned the absolute to relative value conversion with better
precision.
-- Added a dialog to choose whether or not to convert the shorthand
margin/padding forms to their long forms.
-- The plugin will now also convert all forms of shorthand margin/padding
values to 'em' values as well.
-- Changed and updated the release notes.
v0.1.1
-- Fixed a bug on conversion with the 'size' property
v0.1.0
-- Initial release

DiapDealer 08-13-2017 12:22 PM

Added to the plugin index thread. Thanks for your contribution!

JSWolf 08-13-2017 12:56 PM

The title of this thread is a tad confusing and I think some may not get it.

Convert Absolute to Relative Values in CSS

would be much easier to understand.

DiapDealer 08-13-2017 01:07 PM

Quote:

Originally Posted by JSWolf (Post 3567390)
The title of this thread is a tad confusing and I think some may not get it.

Convert Absolute to Relative Values in CSS

would be much easier to understand.

The plugin names have ALWAYS been the threads' titles, Jon. Get over it. Use the Plugin Index or the Plugin Description if you need more help "getting it." Those who have a need for such a thing have little trouble understanding.

theducks 08-13-2017 10:41 PM

:thanks: I have wanted that function for quite a while since some publishers still use inches :eek:
What do the think they are formatting? Paper?
(Wait, where is my Pica stick)

slowsmile 08-13-2017 11:10 PM

@theducks...Although your comment is quite valid, it's almost a given that some people would not understand what absolute and relative values are when describing css values. Sure a developer or formatter would understand these terms but I've learned from hard experience that if you want lay people(with no html or css knowledge) to use your plugins then you've got to give a simple short description of the plugin for them to fully understand what it actually does. And I think that my description(below the title) does that:

Converts cm, mm, inch, pica and point values to relative 'em' values in the css

slowsmile 08-13-2017 11:15 PM

@DiapDealer....Thanks for that !!

slowsmile 09-04-2017 07:00 AM

I've changed/upgraded the plugin in the following way:

* Redesigned the absolute to relative value conversion with better precision.

* Added a dialog to choose whether or not to convert the shorthand margin/padding forms to their long forms.

* The plugin will now also convert all forms of shorthand margin/padding values to 'em' values as well.


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

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