Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 01-22-2018, 06:14 PM   #1
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
[Plugin] SubsetFonts - Simple font subsetter

Last update: November 8, 2018
Current Version: "0.2.1"

This plugin is a simple fontTools wrapper, which'll subset all fonts in an epub.

Please note that the plugin will delete the original fonts and replace them with the subset fonts. Make sure to create a backup copy before running this plugin!

Credits: The plugin uses Alberto Pettarin's glyphIgo library to calculate the number of uninque characters in the book and the fontTools library to do the actual subsetting. The plugin icon (for Sigil 0.9.9.1 and higher) was created by BeckyEbook.

System requirements:

This plugin requires Sigil 0.9.5 or higher. If you're using an external Python interpreter, you'll also need to install the fontTools Python library.

Installation:

1. Select Manage Plugins from the Plugins menu and select Use Bundled Python, if it isn't already selected.

2. Click Add Plugin and select SubsetFonts_v0.2.1.zip. This will install the SubsetFonts plugin, which you can select via Plugins > Edit > SubsetFonts.

Troubleshooting:

By default, the plugin will check the fontTools GitHub website for updates and automatically update the fontTools package bundled with the plugin.
If the update check causes problems on your machine or if you'd rather update the embedded fontTools library yourself, change the following setting in SubsetFonts.json:

Code:
  "update_check": false,
If the update fails, visit the fontTools website, download the latest *.whl file, rename it to *.zip, unzip it and overwrite the plugin fontTools folder with the fontTools folder from the .whl file.

(Linux users may need to manually update the installed fontTool package with pip.)

License: GNU General Public License v3 (GPL-3)
Attached Files
File Type: zip SubsetFonts_v0.2.1.zip (636.7 KB, 38 views)

Last edited by Doitsu; 11-08-2018 at 08:29 AM. Reason: New version uploaded
Doitsu is offline   Reply With Quote
Old 01-22-2018, 10:56 PM   #2
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,310
Karma: 2385865
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
Thumbs up



Thanks for making these two efficient tools so easily available!!

I allowed myself to add some commentaries on the "Workshop" forum to signal that research is still on its way.
roger64 is offline   Reply With Quote
Old 01-26-2018, 02:29 PM   #3
PoP
 curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.
 
PoP's Avatar
 
Posts: 2,073
Karma: 35999999
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₂ PW3₅.₁₀.₁.₁
Very nice. Works better at subsetting than anything I had used before. Thank you.
PoP is offline   Reply With Quote
Old 02-10-2018, 01:54 PM   #4
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
I got curious about font subsetting, which I usually don't do, because I usually don't embed fonts in the first place.

I got the following error(s):
Spoiler:
Code:
Status: failed

Using external Python interpreter.

fontTools version: 3.21.2 

Characters used in this epub:

 !"#$%'()*,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXY[]abcdefghijklmnopqrstuvwxyz —

Processing font:  DejaVuSans.ttf...
Original file size:  756072
/usr/local/share/sigil/plugin_launchers/python/sigil_bs4/__init__.py:187: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

To get rid of this warning, change this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))
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/u838190/.local/share/sigil-ebook/sigil/plugins/SubsetFonts/plugin.py", line 89, in run
    subset_font_size = os.path.getsize(subset_font_path)
  File "/usr/lib/python3.5/genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/Sigil-6pXaXW/OEBPS/Fonts/DejaVuSans.subset.ttf'
Error: [Errno 2] No such file or directory: '/tmp/Sigil-6pXaXW/OEBPS/Fonts/DejaVuSans.subset.ttf'


I'm running linux, Kubuntu 16.04.3, Sigil 0.9.9 compiled from source, Qt 5.6.1. I believe I have all the needed python modules installed.

Running pyftsubset from the command line, using the above character string supplied in a file, runs successfully.

I must be missing something. Probably something obvious.

Albert
st_albert is offline   Reply With Quote
Old 02-10-2018, 02:42 PM   #5
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by st_albert View Post
I must be missing something. Probably something obvious.
No, this is definitely my fault. I mostly tested this plugin on my Windows machine and didn't check for Linux pyftsubset conversion errors.
Can you please zip up your version of DejaVuSans and attach it to your post?
(My DejaVuSans version has a different file size.)
Doitsu is offline   Reply With Quote
Old 02-10-2018, 06:20 PM   #6
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
Quote:
Originally Posted by Doitsu View Post
Can you please zip up your version of DejaVuSans and attach it to your post?
(My DejaVuSans version has a different file size.)
Here you go. Note that ark crashed at the end, after creating the archive, but the font seems OK.
Attached Files
File Type: zip DejaVuSans.zip (354.2 KB, 45 views)
st_albert is offline   Reply With Quote
Old 02-10-2018, 07:05 PM   #7
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by st_albert View Post
Here you go. Note that ark crashed at the end, after creating the archive, but the font seems OK.
Unfortunately, I'm not able to reproduce this error. I'm getting the following message:

Spoiler:
Code:
Status: success

Using external Python interpreter.

fontTools version: 3.21.2 

Characters used in this epub:

 !"#$%'()*,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXY[]abcdefghijklmnopqrstuvwxyz—

Processing font:  DejaVuSans.ttf...
Original file size:  756072
Subset file size:  22752 (3.01%)
Original font replaced with subset font.

Click OK to close.


Try the following:

change line #51 in plugin.py from:

Code:
text += BeautifulSoup(html).text
to:
Code:
text += BeautifulSoup(html,'html.parser').text
This should suppress the phony bs4 error message. Also please check if your DejaVuSans font files are read-only and/or obfuscated or if your temp folder requires special permissions.

IIRC, you also have a Windows machine. Please try to subset the same file on your Windows machine. This will use a Python library instead of the pyftsubset command line tool and you'll hopefully get a meaningful error message.

I'll look into this in more detail either tomorrow or on Monday.
Doitsu is offline   Reply With Quote
Old 02-10-2018, 11:22 PM   #8
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
Thanks. Will do, probably tomorrow.

Albert
st_albert is offline   Reply With Quote
Old 02-11-2018, 01:26 PM   #9
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
After making the suggested change in plugin.py and changing permissions on DejaVuSans.ttf to 666 (was 664) I still get the file not found error...
Spoiler:
Code:
Status: failed

Using external Python interpreter.

fontTools version: 3.21.2 

Characters used in this epub:

 !"#$%'()*,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXY[]abcdefghijklmnopqrstuvwxyz —

Processing font:  DejaVuSans.ttf...
Original file size:  756072
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/u838190/.local/share/sigil-ebook/sigil/plugins/SubsetFonts/plugin.py", line 89, in run
    subset_font_size = os.path.getsize(subset_font_path)
  File "/usr/lib/python3.5/genericpath.py", line 50, in getsize
    return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/Sigil-2PHn8A/OEBPS/Fonts/DejaVuSans.subset.ttf'
Error: [Errno 2] No such file or directory: '/tmp/Sigil-2PHn8A/OEBPS/Fonts/DejaVuSans.subset.ttf'


but checking the temporary files,
Code:
$ ls -la /tmp/Sigil-2PHn8A/OEBPS/Fonts
total 772
drwxrwxr-x 2 u838190 u838190   4096 Feb 11 11:41 .
drwxrwxr-x 9 u838190 u838190   4096 Feb 11 11:37 ..
-rw-rw-rw- 1 u838190 u838190 756072 Feb 11 11:38 DejaVuSans.ttf
-rw-rw-r-- 1 u838190 u838190  21652 Feb 11 11:41 DejaVuSans.ttf.subset
so evidently pyftsubset was able to write the subsetted font to the disk, using its default naming.

so at line 88 in plugin.py I changed:
Code:
subset_font_path = original_font_path.replace(ext, '.subset' + ext)
to:
Code:
subset_font_path = original_font_path.replace(ext, ext + '.subset')]
and lo and behold,
Code:
Status: success

Using external Python interpreter.

fontTools version: 3.21.2 

Characters used in this epub:

 !"#$%'()*,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXY[]abcdefghijklmnopqrstuvwxyz —

Processing font:  DejaVuSans.ttf...
Original file size:  756072
Subset file size:  21652 (2.86%)
Original font replaced with subset font.

Click OK to close.
The epub size was reduced from ~408 kB before subsetting to ~52.4 kB afterwards.
For comparison, subsetting with Calibre's epub editor gave ~111.5 kB
and with no fonts embedded, it was 38.6 kB

Thanks for the pointers, without which I probably wouldn't have known where to begin.

Albert

Last edited by st_albert; 02-11-2018 at 01:29 PM.
st_albert is offline   Reply With Quote
Old 02-11-2018, 01:47 PM   #10
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by st_albert View Post
Thanks for the pointers, without which I probably wouldn't have known where to begin.
Thank you for your investigation! I'm glad that you got it working.

I'll have to run some more tests tomorrow to figure out why the original code didn't work for you but worked fine on my Arch Linux and Elementary OS machines.

Maybe your pyftsubset version was compiled differently or, more likely, on my Linux machines the embedded Python library was used instead of the command line tool. Either way I'll post a new version on Monday.
Doitsu is offline   Reply With Quote
Old 02-11-2018, 03:15 PM   #11
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
FYI:

$ apt-cache policy fonttools
fonttools:
Installed: 3.0-1
Candidate: 3.0-1
Version table:
*** 3.0-1 500
500 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
500 http://us.archive.ubuntu.com/ubuntu xenial/universe i386 Packages
100 /var/lib/dpkg/status

Should have mentioned this earlier.
st_albert is offline   Reply With Quote
Old 02-12-2018, 11:08 AM   #12
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
@st_albert: Apparently the fontTools developers changed the default subset font file naming scheme in fontTools version 3.21.2, which I used for testing.

The fontTools 3.0.1 Debian package provided by Ubuntu uses DejaVuSans.ttf.subset, however, the latest fontTools 3.21.2 version (installed via pip3) uses DejaVuSans.subset.ttf. I've updated the plugin code to also look for subset font files with the older naming scheme.

BTW, since the Ubuntu fontTools package is totally outdated, you might want to consider uninstalling it and installing the latest fontTools version via pip/pip3.
Doitsu is offline   Reply With Quote
Old 02-14-2018, 01:37 PM   #13
st_albert
Guru
st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'st_albert gives new meaning to the word 'superlative.'
 
Posts: 670
Karma: 150000
Join Date: Feb 2010
Device: none
Quote:
Originally Posted by Doitsu View Post
BTW, since the Ubuntu fontTools package is totally outdated, you might want to consider uninstalling it and installing the latest fontTools version via pip/pip3.
Yes, much better. It works with both the original 0.1.0 version and the newer 01.1.

Thanks again!

Albert.
st_albert is offline   Reply With Quote
Old 04-08-2018, 01:52 AM   #14
Doitsu
Wizard
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 4,341
Karma: 14300083
Join Date: Dec 2010
Device: Kindle PW2
I've attached a new version with the latest fontTools version (3.25.0) to the first post. The new version will also check the fontTools GitHub website for updates and automatically update the bundled fontTools library.

Last edited by Doitsu; 04-08-2018 at 01:55 AM.
Doitsu is offline   Reply With Quote
Old 11-08-2018, 07:27 AM   #15
bravosx
Connoisseur
bravosx began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
The plugin does not work. From 7 days there is a new version of fonttools 3.32.0 but there is no * whl file
Doitsu, can you help it?
Thanks you for the plugin, it is very useful for me.

bravosx
bravosx is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre annotations and highlight extract plugin for the Nook Simple Touch? einkuser Plugins 15 01-24-2015 09:13 PM
Install of simple plugin works on Linux and Win but not on OSX kabirmaar Development 9 07-26-2014 08:49 PM
Make a simple Plugin for Full Text Search using Recoll Satas Development 9 07-20-2013 05:15 PM
Nook Simple Touch font issue. xstealx ePub 4 11-17-2011 11:11 AM
Touch Font Change no longer works on Nook Simple? localbuyer Barnes & Noble NOOK 13 07-09-2011 12:29 PM


All times are GMT -4. The time now is 06:45 PM.


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