09272015, 04:37 AM  #1 
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

[Script] Koboify Fonts
I wanted a quicker way of modifying fonts for use on my Kobo, so I decided to cook up a script this weekend.
I thought I would share this with you folks. Hopefully someone else may also get some use out of it. Without further ado, may I present to you... Koboify Fonts Updated to v0.3.1 Fixes a major (and silly) issue with the batch file, and changes how the script should be called. See readme for details. New! Workaround for font naming issue Please see readme for more information New! Now with included batch file for Windows 7/8/10 users With the version update to 0.2, I have also included a fancy "Drag'n'Drop" batch file for Windows users. Please view the readme for usage instructions. This is a script that takes one or more subfamilies of a font (Regular, Italic, Bold, Bold Italic), performs some modifications using FontForge, and generates new TTF files. It will rename the font, and you can chose to:
You can choose any one, or all of these tasks It should be cross platform, but I have only tested it on Windows 10 64bit it is a Python script, however Python is NOT required to be installed. It is designed to be used with the FontForge embedded Python Interpreter. The only requirement is that FontForge must be installed. Usage instructions are given in the readme, which I will duplicate at the end of this post. I hope someone finds a use for this! If you have any suggestions or improvements, please let me know. I can't guarantee that I will spend a lot more time on this however. Please not, I am not a developer. I don't program very often. Therefore this script will be buggy, not terribly efficient, and may not follow best python/coding practices... Known Bugs: None at the moment. I have created a workaround for the font naming issue as of version 0.3 Code:
Koboify Fonts by Sherman Perry This is a script that takes one or more font files (of the same font family), performs some modifications, and generates new TTF file(s). It uses FontForge to perform the modifications. It is provided ASIS. This is very rough. I may or may not make improvements in the future. ========================================================================= CHANGELOG: _0.3.1_20151018_  Fixed an error with the batch file where there was a problem if the path to the script file contained spaces.  Changed how the script is called, from running "ffpython.exr" to "fontforge.exe script " _0.3_20150929_  Created a somewhat ugly workaround to handle fonts that will not rename properly. This is set in a new commandline option, [n]  Fixed a fairly major bug in the batch fileit would break if less than four files were dragged onto it.  Moved font name processing to a seperate function _0.2 20150928_ Reworked a few internals, especially the layer curve type handling Created a Drag'n'Drop batch file for Windows 710 users _0.1_20150927_ Initial release ========================================================================= REQUIREMENTS: FontForge must be installed on your system. The script will not run using the system installed Python unless FontForge was specifically compiled to allow this. This script should now be called by using: path/to/fontforge/fontforge(.exe) script KoboifyFonts0.3.1.py [OPTIONS] FontForge is located (by default) in the following location on Windows 64bit systems: "C:\Program Files (x86)\FontForgeBuilds\bin\fontforge.exe" On Windows, the best way to run the script is to probably call it in a batch file. As of version 0.2 I have created a batch file called 'DragFontFilesHere.bat' Details on how to use this are below. I reccommend running the script/batch in the same directory as the font files you wish to convert. ========================================================================= OSX INSTALLATION: The following instructions were kindly provided by mobileread user 'GERGE': Firstly, you can't use this by just installing FontForge from its page, you need command line version of FontForge. That version is much smaller (takes 30 MB or so) and needs to be compiled and installed with Homebrew. I am not going to explain to you how to use Homebrew, there are literally hundreds of guides out there. Just don't use HEAD version, brew install fonforge is the command you need to install it. Secondly, you can't use it by internal Python of FontForge, you don't even have an internal Python. But OS X's own Python works perfectly well, just use versions of this command I used with EB Garamond: python ./KoboifyFonts0.3.py r /Users/msimsek/Downloads/EBGaramond08Regular.otf i /Users/msimsek/Downloads/EBGaramond08Italic.otf s k p d . 'EB Garamond' ========================================================================= USAGE: KoboifyFonts0.3.1.py [h] [r REGULAR] [i ITALIC] [b BOLD] [B BOLDITALIC] [s] [k] [d OUTPUTDIRECTORY] [w ADDWEIGHT] [p] [m] [n] fontname positional arguments: fontname Specify new font name optional arguments: h, help show this help message and exit r REGULAR, regular REGULAR Regular font file i ITALIC, italic ITALIC Italic font file b BOLD, bold BOLD bold font file B BOLDITALIC, bolditalic BOLDITALIC Bold Italic font file s, striphint Strip hints from font k, legacykern Include legacy kerning table d OUTPUTDIRECTORY, outputdirectory OUTPUTDIRECTORY Output directory if set. Default is "./kobomodified/" w ADDWEIGHT, addweight ADDWEIGHT Add weight to font. Values around 815 seems suitable. 50 is bold p, panosestrip Strip PANOSE data from font m, modifybearings Modify bearings when adding weight. This has no affect when not adding weight. Only use it for subtle weight changes n, namehack If the fonts generated have internal names different to what you specified, try this option to enable an ugly workaround. It basically generates the font twice. ============================================================================ USING INCLUDED BATCH FILE  The included batch file allows font files to be dragged onto it. The font files should include anywhere in their filenames the following: regular bold italic bolditalic/bold italic/bolditalic etc. This will tell the batch file how to feed the files to the python script. When files are dragged onto the batch file, you will be asked a number of questions about whether to enable the options (see above usage section). Fonts will be generated in a 'koboified/' subdirectory where the original font files are located. The batch file is set to use the FontForge python binary 'ffpython.exe' in the default FontForge installation directory. If FontForge is installed elsewhere, you will need to change this in the batch file (variable %ffpythonpath%). The batch file and the python script should be located in the same directory. ============================================================================ There has been stability issues observed with modifybearings (Windows 10 x64). It seems to have happened more with longer output file paths I have not determined the root cause of this, as the python interpreter crashes without providing a traceback This stability issue may be Windows related. Or (more likely) I've made a big mistake somewhere... ============================================================================ Last edited by sherman; 10172015 at 06:29 PM. Reason: Updated readme to include OSX installation/usage instructions 
09272015, 08:26 AM  #2 
Addict
Posts: 206
Karma: 51122
Join Date: Jan 2015
Device: bq Avant XL, Kobo Aura H2O, Onyx Boox M96C Plus

Many thanks for your efforts. Very usefull for me.

09272015, 11:19 AM  #3 
Addict
Posts: 289
Karma: 104074
Join Date: Sep 2009
Device: PRS950, Kobo Aura HD

Code:
"C:\Program Files (x86)\FontForgeBuilds\bin\ffpython.exe" KoboifyFonts0.1.py r LiterataRegular.otf i LiterataItalic.otf b LiterataBold.otf B LiterataBoldItalic.otf s k p d . Literata This font contains both a 'kern' table and a 'GPOS' table. The 'kern' table will only be read if there is no 'kern' feature in 'GPOS'. 20 Saving LiterataRegular.ttf. . . Internal Error: Attempt to output 2147483647 into a 16bit field. It will be truncated and the file may not be useful. Internal Error: Lookup sub table, 'kern' Horizontal Kerning lookup 0 per glyph data 0 in 'kern' Horizontal Kerning lookup 0, contains no data. Internal Error: Lookup sub table, 'kern' Horizontal Kerning lookup 0 kerning class 1 in 'kern' Horizontal Kerning lookup 0, contains no data. Internal Error: Lookup sub table, 'kern' Horizontal Kerning lookup 0 kerning class 2 in 'kern' Horizontal Kerning lookup 0, contains no data. Internal Error: Lookup sub table, 'kern' Horizontal Kerning lookup 0 kerning class 3 in 'kern' Horizontal Kerning lookup 0, contains no data. Internal Error: Lookup sub table, 'locl' Localized Forms in Latin lookup 0 subtable in 'locl' Localized Forms in Latin lookup 0, contains no data. Internal Error: Lookup sub table, 'locl' Localized Forms in Latin lookup 1 subtable in 'locl' Localized Forms in Latin lookup 1, contains no data. Internal Error: Lookup sub table, 'tnum' Tabular Numbers lookup 2 subtable in 'tnum' Tabular Numbers lookup 2, contains no data. Internal Error: Lookup sub table, 'pnum' Proportional Numbers lookup 3 subtable in 'pnum' Proportional Numbers lookup 3, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 0 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 1 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 2 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 3 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 4 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 5 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 6 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 7 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 8 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 9 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 10 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 11 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 12 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 13 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 14 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 15 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 16 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 17 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 18 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 19 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 4 contextual 20 in 'frac' Diagonal Fractions lookup 4, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 5 subtable in 'frac' Diagonal Fractions lookup 5, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 6 subtable in 'frac' Diagonal Fractions lookup 6, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 7 subtable in 'frac' Diagonal Fractions lookup 7, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 8 subtable in 'frac' Diagonal Fractions lookup 8, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 9 subtable in 'frac' Diagonal Fractions lookup 9, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 10 subtable in 'frac' Diagonal Fractions lookup 10, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 11 subtable in 'frac' Diagonal Fractions lookup 11, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 12 subtable in 'frac' Diagonal Fractions lookup 12, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 13 subtable in 'frac' Diagonal Fractions lookup 13, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 14 subtable in 'frac' Diagonal Fractions lookup 14, contains no data. Internal Error: Lookup sub table, 'frac' Diagonal Fractions lookup 15 subtable in 'frac' Diagonal Fractions lookup 15, contains no data. Internal Error: Lookup sub table, 'sinf' Scientific Inferiors lookup 16 subtable in 'sinf' Scientific Inferiors lookup 16, contains no data. Internal Error: Lookup sub table, 'sups' Superscript lookup 17 subtable in 'sups' Superscript lookup 17, contains no data. Internal Error: Lookup sub table, 'numr' Numerators lookup 18 subtable in 'numr' Numerators lookup 18, contains no data. Internal Error: Lookup sub table, 'dnom' Denominators lookup 19 subtable in 'dnom' Denominators lookup 19, contains no data. Internal Error: Lookup sub table, 'ordn' Ordinals lookup 20 subtable in 'ordn' Ordinals lookup 20, contains no data. Internal Error: Lookup sub table, 'liga' Standard Ligatures lookup 21 subtable in 'liga' Standard Ligatures lookup 21, contains no data. Internal Error: Lookup sub table, Single Substitution lookup 22 subtable in Single Substitution lookup 22, contains no data. Internal Error: Lookup sub table, Single Substitution lookup 23 subtable in Single Substitution lookup 23, contains no data. Note: On Windows many apps can have problems with this font's kerning, because 2503 of its glyph kern pairs cannot be mapped to unicodeBMP kern pairs (eg, they have a Unicode value of 1) To avoid this, go to Generate, Options, and check the "Windowscompatible 'kern'" option. Internal Error: File Offset wrong for ttf table (namedata), 1 expected 294 Save Failed Traceback (most recent call last): File "..\..\KoboifyFonts0.1\KoboifyFonts0.1.py", line 160, in <module> f.generate(newValTTF, flags=flagsTTF) EnvironmentError: Font generation failed 
09272015, 05:11 PM  #4 
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

What version of FontForge and Literata are you using?
I tried it with the version of Literata I have (1.001) and it works fine. My FontForge version is 20150804 Here's what I get when I run almost the same command as you: Code:
C:\Users\sherm\Documents\Fonts\Literata\Original>"C:\Program Files (x86)\FontFor geBuilds\bin\ffpython.exe" "C:\Users\sherm\OneDrive\Documents\Scripts\KoboifyFon ts0.1.py" r literata.otf i literataitalic.otf b literatabold.otf B litera tabolditalic.otf s k p "Literata" This font contains both a 'kern' table and a 'GPOS' table. The 'kern' table will only be read if there is no 'kern' feature in 'GPOS'. 30 Saving koboified\LiterataRegular.ttf. . . Note: On Windows many apps can have problems with this font's kerning, because 2 527 of its glyph kern pairs cannot be mapped to unicodeBMP kern pairs (eg, they have a Unicode value of 1) To avoid this, go to Generate, Options, and check t he "Windowscompatible 'kern'" option. This font contains both a 'kern' table and a 'GPOS' table. The 'kern' table will only be read if there is no 'kern' feature in 'GPOS'. 27 Saving koboified\LiterataBold.ttf. . . Note: On Windows many apps can have problems with this font's kerning, because 2 393 of its glyph kern pairs cannot be mapped to unicodeBMP kern pairs (eg, they have a Unicode value of 1) To avoid this, go to Generate, Options, and check t he "Windowscompatible 'kern'" option. This font contains both a 'kern' table and a 'GPOS' table. The 'kern' table will only be read if there is no 'kern' feature in 'GPOS'. 29 Saving koboified\LiterataItalic.ttf. . . Note: On Windows many apps can have problems with this font's kerning, because 2 936 of its glyph kern pairs cannot be mapped to unicodeBMP kern pairs (eg, they have a Unicode value of 1) To avoid this, go to Generate, Options, and check t he "Windowscompatible 'kern'" option. This font contains both a 'kern' table and a 'GPOS' table. The 'kern' table will only be read if there is no 'kern' feature in 'GPOS'. 33 Saving koboified\LiterataBoldItalic.ttf. . . Note: On Windows many apps can have problems with this font's kerning, because 2 691 of its glyph kern pairs cannot be mapped to unicodeBMP kern pairs (eg, they have a Unicode value of 1) To avoid this, go to Generate, Options, and check t he "Windowscompatible 'kern'" option. C:\Users\sherm\Documents\Fonts\Literata\Original>pause Press any key to continue . . . 
09282015, 01:03 AM  #5 
Guru
Posts: 621
Karma: 5548554
Join Date: Jun 2010
Location: Turkey
Device: Kobo Glo HD & iPad

Don't use this twice on the same font file, if added weight is too small or too much just start from the beginning. Adding weight twice sometimes damages glyphs too much.

09282015, 01:14 AM  #6  
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

Quote:
Using the original files as input should always generate new files. ...unless fontforge.font.save() does something silly like modifying existing files, rather than overwrite them. The documentation doesn't state either way 

09282015, 02:53 AM  #7 
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

New! Version 0.2. Now with fancy barch
Presenting Version 0.2 with fancy batch file
I've updated a few internals in the main python script, mainly to do with layer processing. There is no change to how the script should be used. I've decided to make my (and hopefully others...) life easier by including a "Drag'n'Drop" enabled batch file to easily add fonts for processing. See the first post and/or readme for usage instructions. First post has been updated with the new version. 
09282015, 11:36 PM  #8 
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

Version 0.3 released
New version
First post has been updated with the latest version This is a bugfix release mainly. I've created a workaround for the font naming issue that could occur with some fonts (not all!). There was also a major issue with the batch file which I've corrected. For those interested in the workaround, I have added an option that when enabled, the script will reopen the generated TTF file, rename the font, then generate a new TTF. It's an inelegant workaround at best, and I'm not all that happy with it, but unless the cause of the bug can be tracked down, there's not a lot I can think of to do better. The problem seems to lie in the fontforge provided font.appendSFNTName() method. It simply isn't appending/replacing data like it should in some fonts. 
09292015, 06:01 AM  #9 
Connoisseur
Posts: 85
Karma: 18420
Join Date: Feb 2013
Location: Brussels, Belgium
Device: Kobo Glo, Kindle 3

would be great if you also share some of your 'cleaned' fonts for Kobo with the community

09292015, 08:53 AM  #10 
Addict
Posts: 289
Karma: 104074
Join Date: Sep 2009
Device: PRS950, Kobo Aura HD


09292015, 09:41 AM  #11 
Grand Sorcerer
Posts: 9,155
Karma: 55202677
Join Date: Nov 2007
Location: Toronto
Device: Wife: Touch, Arc, Vox Me: Nexus 7, Glo

One has to be careful with this; it would depend to a large degree on the licensing of the original font as to whether or not one can redistribute a modified version of the font.

09292015, 01:04 PM  #12 
Guru
Posts: 621
Karma: 5548554
Join Date: Jun 2010
Location: Turkey
Device: Kobo Glo HD & iPad

Here is one: Unbelievably gorgeous EB Garamond, quite possibly the best opensource typeface: http://drop.muratcansimsek.com/EBGaramond.zip
But there is something more you should add to the readme, here are the instructions to use this on OS X: Firstly, you can't use this by just installing FontForge from its page, you need command line version of FontForge. That version is much smaller (takes 30 MB or so) and needs to be compiled and installed with Homebrew. I am not going to explain to you how to use Homebrew, there are literally hundreds of guides out there. Just don't use HEAD version, brew install fonforge is the command you need to install it. Secondly, you can't use it by internal Python of FontForge, you don't even have an internal Python. But OS X's own Python works perfectly well, just use versions of this command I used with EB Garamond: Code:
python ./KoboifyFonts0.3.py r /Users/msimsek/Downloads/EBGaramond08Regular.otf i /Users/msimsek/Downloads/EBGaramond08Italic.otf s k p d . 'EB Garamond' 
09292015, 04:21 PM  #13  
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

Quote:
My problem with EB Garamond is the lack of bold and bold italic variants. I personally prefer a complete font set on my reader. 

09292015, 04:45 PM  #14  
Addict
Posts: 392
Karma: 753385
Join Date: Aug 2008
Location: Auckland  NZ
Device: Sony PRS505/SC, B&N Nook, Sony PRS650/BC, Kobo Glo, Kobo Aura H2O

Quote:
This tool is not really set up to properly handle the licensing side of things.' The purpose of this script was to make it (hopefully) simple and (hopefully) quick to modify fonts for your own personal use, without having to delve into the....unusual... FontForge interface, or buy (or otherwise... obtain) commercial font software. 

09302015, 01:18 AM  #15 
Bibliophagist
Posts: 2,713
Karma: 7781036
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Aura HD, Glo, Nexus 7 HD, iPad Air


Tags 
font 
Thread Tools  Search this Thread 

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
How to add alternate fonts without replacing system fonts.(this time this is a guide)  techiemonkey  Kindle Developer's Corner  17  09122012 04:55 PM 
An Observation on Fonts  Improving readability by using *bold* versions of fonts  nesler  General Discussions  12  06242012 12:33 PM 
need the fonts in /usr/java/lib/fonts of kindle touch5.0.0  hanpal  Kindle Developer's Corner  1  02202012 10:40 AM 
Troubleshooting need the fonts in /usr/java/lib/fonts of kindle touch5.0.0  hanpal  Amazon Kindle  0  02202012 08:51 AM 
Touch Fonts question (special characters in stock and custom fonts)  levil  Kobo Reader  20  09232011 01:51 PM 