![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
ePUB Optimizer
This is an edit plugin that should work on Windows, Linux and OSX.
It is a wrapper plugin around my ePUB Optimizer program. It will subset the included fonts according to usage and optimize JPG, PNG and GIF images. If a font is in the ePUB, but not actually used, it will be removed from the ePUB . The references will also be removed from the stylesheet(s). Usage of glyphs is determined by actually looking at the formatting of all elements, taking heredity into account. Prereqs: Sigil 0.8.2 (or higher when it gets there) and Mono (for Linux/OSX). Also, on Linux the programs jpegtran/optipng/gifsicle are required. For Windows and OSX these are included. The program jpegtran is included in libjpeg-progs on Linux. I have tested the program/plugin on Ubuntu 14.04 (64-bit) and 12.04 (32-bit). The 12.04 is actually Linux Mint 3. I have tested it with Mono 3.x only. The plugin can be found here. There are two options, subsetting based on fontfamily (so all fonts in the same family is treated equally) or based on fontdefinition. By default the second option will be used. It can be turned off by opening the ePUBOptimizer.ini and changing the 'usefontfamily' option to 'true'. Current Version: "0.7.2" Last edited by Toxaris; 01-09-2016 at 03:58 AM. |
![]() |
![]() |
![]() |
#2 |
Sigil & calibre developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,487
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
|
Interesting that you're using the Python plugin interface to call a .Net application. It's just funny that Sigil is C++ which can call Python code which is now calling .Net code...
@Toxaris don't forget we designed the plugin system to be flexible to be able to call/use other languages than Python so if you're going to to make more .Net plugins we can look into a native .Net plugin interface so you don't have to go though the Python one. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Oh, it was a fun exercise. It is my first Python program and the examples and other plugins helped a lot. It is just that I am much more used to program in .Net. It also encouraged me to program in such a way that Mono could be used.
There is a small issue if there are media queries in the stylesheet, but that will be fixed later today. Bugs always tend to pop up after release... |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,335
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Just playing a bit, but I noticed that in one of my epubs, the font00345.ttf ("Kings-things") file disappears from the epub (and the css)--even though the font is used in several places. Any idea what might be going on?
Attaching a rather bloated version of "The Well at the World's End" to demonstrate. |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
I found the issue with the ePUB. The program is 'correct'. The 'King-things' font file is only used as bold. However, in the font-face it is not specified that the font is bold. If it is not specified, it will take the default, which is normal for both font-weight and font-style.
It has to do this, because a font-family can have multiple members and the used glyphs can change per member. For the defined member here, there are no glyphs in use. If you would add 'font-weight: bold;' in your font-face declaration it will work as it should. I hope I made it clear... Last edited by Toxaris; 12-01-2014 at 05:38 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
BTW, version 0.2 is placed. No change in the plugin itself, but in some cases media-queries in the stylesheet caused crashes.
|
![]() |
![]() |
![]() |
#7 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,679
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
You may want to update your plugin so that it only removes fonts if the embedded fonts are either not used in the stylesheet or stylesheet definitions that reference the embedded fonts aren't actually used. BTW, the plugin doesn't work with my Debian Linux 3.2.0-4-amd64 x86_64 distro, even though Debian mono 2.10.8.1-8 is installed. What mono version did you test it with? It fails with the following error message: Code:
Traceback (most recent call last): File "/usr/local/share/sigil/plugin_launchers//python/launcher.py", line 135, in launch self.exitcode = target_script.run(container) File "/home/user/.local/share/sigil-ebook/sigil/plugins/ePUBOptimizer/plugin.py", line 58, in run with open(actionlist) as f: IOError: [Errno 2] No such file or directory: '/home/user/.local/share/sigil-ebook/sigil/plugins/ePUBOptimizer/actionlist.txt' Error: [Errno 2] No such file or directory: '/home/user/.local/share/sigil-ebook/sigil/plugins/ePUBOptimizer/actionlist.txt' The Windows version of the plugin also failed with some books, for example this book, which crutledge uploaded a couple of days ago. I'm getting the following error message: Code:
Processing C:\Users\User\AppData\Local\sigil-ebook\sigil\plugins\ePUBOptimizer\dummy.epub Get unique characters per font [...] Unhandled exception: System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function. |
|
![]() |
![]() |
![]() |
#8 | |||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Quote:
A font-family can have multiple members and the used glyphs per usage is determined. Fonts that are not used in text or stylesheet will be removed. Quote:
Quote:
Last edited by Toxaris; 12-01-2014 at 07:03 AM. |
|||
![]() |
![]() |
![]() |
#9 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,679
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Quote:
As for the Windows issue, are there any minimum version requirements for the binaries/system libraries that your tool uses? |
||
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,335
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I'm not going to beleaguer the point (I'm not one to do much font embedding in the first place), but it does seem a little drastic to throw a font out on such a technical definition of "being used." It renders in ADE, Adobe's RMSDK, Sigil and calibre, so the font is clearly "being used" (even if it's being used improperly).
It just seems odd to me that doing nothing other than removing "font-weight: bold" from the "first-words" class, makes your plugin believe the font is suddenly being used (with no change to the @font-face declaration) ... and that adding the line back in renders the font "unused" once again. I do understand the technical distinction, but it doesn't seem appropriate to me to delete font files (and their accompanying css references) that are, in fact, being used. Inappropriately perhaps, but "used" nonetheless. If I were doing it, "used" would mean: a font-face declaration; the font-family being used in a class selector; and that class being applied to elements in the (x)html that contain text. But in the end ... it's your plugin. ![]() Last edited by DiapDealer; 12-01-2014 at 08:29 AM. |
![]() |
![]() |
![]() |
#11 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,679
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
@Toxaris: If you strongly believe in this feature, you may want to make it at least an optional feature, because I for one, won't use a plugin that might delete declarations and content, just because they're not 100% perfect. (If you don't want to create a GUI for it, you can easily define plugin settings with a user-editable .ini file. For an example, have a look at my very simple GUI-less Kindlegen plugin.) |
|
![]() |
![]() |
![]() |
#12 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Quote:
|
|
![]() |
![]() |
![]() |
#13 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Quote:
Now, if I use certain glyphs in italic but not in bold, they could be removed from bold. The way to discriminate between these fonts, are the attributes font-weight and font-style. I have to tell in the stylesheet which is which. If I don't add those, the reading application should fall back to the default value which is normal for both. If I would not use it, the wrong font would be used. The same applies for all the other default values for all classes/tags. Headers are bold by default for example. If I would ignore the font-weight and font-style, I would not know which glyphs could be deleted from the fonts in the same family. I could combine of course all used characters for that font-family, but then the font is not optimized fully. There is of course a difference between a font and a font-family. I am actually quite surprised that ADE shows the font when the usage is actually not correct. Does it also render on ADE 1.7? Perhaps I will add a feature that only discriminates on font-family used instead of actually used fonts as it is now. |
|
![]() |
![]() |
![]() |
#14 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
I would really like a .Net plugin interface, but I assume that would be quite some work to do.
|
![]() |
![]() |
![]() |
#15 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,335
Karma: 203719142
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
And yes, ADE 1.7 renders the embedded font in my sample epub. I've yet to find a device/app that doesn't (not to say there aren't any). Discrimination based on font-family would certainly be a useful feature for me. Otherwise, I have to remember that even though my epub passes validation with flying colors, there may be situations where my ornamental fonts disappear when using this plugin. But enough!! Glad to see you contributing to the plugin cause. The more the merrier. ![]() Last edited by DiapDealer; 12-01-2014 at 02:46 PM. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Comic optimizer script | rhon | Kobo Reader | 0 | 11-08-2012 06:04 PM |
Mokle - Mangas Optimizer for Kindle | devorez | Kindle Developer's Corner | 11 | 08-14-2012 07:15 PM |
Patent/Heavy graphics pdfs and Adobe PDF Optimizer | andrewscheinman | iRex | 4 | 12-26-2009 11:39 AM |
epub, ePub, EPUB, warum blos ePub? | flowoeB | Lounge | 5 | 11-27-2009 09:37 AM |
PRS-500 PDF file optimizer | phigdon | Sony Reader Dev Corner | 1 | 04-01-2007 11:40 PM |