01-22-2018, 06:14 PM | #1 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
[Plugin] SubsetFonts - Simple font subsetter
Last update: January 5, 2021
Current Version: "0.2.4" 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.4.zip. This will install the SubsetFonts plugin, which you can select via Plugins > Edit > SubsetFonts. Troubleshooting: By default, the plugin will check the fontTools PyPi 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,
(Linux users may need to manually update the installed fontTool package with pip.) License: GNU General Public License v3 (GPL-3) Last edited by Doitsu; 01-05-2021 at 02:30 PM. Reason: New version with better auto-updater |
01-22-2018, 10:56 PM | #2 |
Wizard
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
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. |
Advert | |
|
01-26-2018, 02:29 PM | #3 |
curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
Posts: 3,008
Karma: 50506927
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₃ PW3&4₅.₁₃.₃
|
Very nice. Works better at subsetting than anything I had used before. Thank you.
|
02-10-2018, 01:54 PM | #4 |
Guru
Posts: 697
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:
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 |
02-10-2018, 02:42 PM | #5 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
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.) |
Advert | |
|
02-10-2018, 06:20 PM | #6 |
Guru
Posts: 697
Karma: 150000
Join Date: Feb 2010
Device: none
|
Here you go. Note that ark crashed at the end, after creating the archive, but the font seems OK.
|
02-10-2018, 07:05 PM | #7 | |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Spoiler:
Try the following: change line #51 in plugin.py from: Code:
text += BeautifulSoup(html).text Code:
text += BeautifulSoup(html,'html.parser').text
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. |
|
02-10-2018, 11:22 PM | #8 |
Guru
Posts: 697
Karma: 150000
Join Date: Feb 2010
Device: none
|
Thanks. Will do, probably tomorrow.
Albert |
02-11-2018, 01:26 PM | #9 |
Guru
Posts: 697
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:
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 at line 88 in plugin.py I changed: Code:
subset_font_path = original_font_path.replace(ext, '.subset' + ext) Code:
subset_font_path = original_font_path.replace(ext, ext + '.subset')] 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. 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. |
02-11-2018, 01:47 PM | #10 | |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
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. |
|
02-11-2018, 03:15 PM | #11 |
Guru
Posts: 697
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. |
02-12-2018, 11:08 AM | #12 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
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. |
02-14-2018, 01:37 PM | #13 | |
Guru
Posts: 697
Karma: 150000
Join Date: Feb 2010
Device: none
|
Quote:
Thanks again! Albert. |
|
04-08-2018, 01:52 AM | #14 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
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. |
11-08-2018, 07:27 AM | #15 |
Zealot
Posts: 103
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 |
Thread Tools | Search this Thread |
|
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 |