Commit 0b35b04f authored by svilayphiou's avatar svilayphiou
Browse files

A new script to merge metrics and kerning data from an existing font.

parent bc8362ff
......@@ -18,26 +18,13 @@ Process
#### Get a bitmap image of characters (crop unnecessary white parts for a faster process, you can use Gimp's automatic crop for that).
![](
http://osp.kitchen/api/osp.tools.fons/raw/input/scan_bitmap.jpg)
![](http://osp.kitchen/api/osp.tools.fons/raw/input/scan_bitmap.jpg)
: A scan in bitmap
![](
http://osp.kitchen/api/osp.tools.fons/raw/input/scan_gray_1200dpi.jpg)
![](http://osp.kitchen/api/osp.tools.fons/raw/input/scan_gray_1200dpi.jpg)
: A scan in gray levels
![](
http://osp.kitchen/api/osp.tools.fons/raw/input/rasterized_ospDIN.png)
![](http://osp.kitchen/api/osp.tools.fons/raw/input/rasterized_ospDIN.png)
: A rasterized font
......@@ -46,8 +33,7 @@ http://osp.kitchen/api/osp.tools.fons/raw/input/rasterized_ospDIN.png)
#### Levels (have a white background, black characters but still shades of gray)
![](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/01-bitmap_levels.png)
![](http://osp.kitchen/api/osp.tools.fons/raw/documentation/01-bitmap_levels.png)
......@@ -55,8 +41,7 @@ http://osp.kitchen/api/osp.tools.fons/raw/documentation/01-bitmap_levels.png)
Scale up the image to something like 254% with the "Sinc (Lanczos 3)" algorithm. We choose on purpose a non-round number of scaling to break the bitmap patterns.
![](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/02-scale-254percent.png)
![](http://osp.kitchen/api/osp.tools.fons/raw/documentation/02-scale-254percent.png)
......@@ -64,15 +49,12 @@ http://osp.kitchen/api/osp.tools.fons/raw/documentation/02-scale-254percent.png)
Put the amount to the maximum and then search for the point where you don't see
![bad](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-too_few.png)
![bad](http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-too_few.png)
: Radius too small
![ok](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-ok.png)
![ok](http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-ok.png)
![bad](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-too_much.png)
![bad](http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-too_much.png)
......@@ -80,20 +62,17 @@ http://osp.kitchen/api/osp.tools.fons/raw/documentation/03-sharpen-too_much.png)
Scale up to 403% (check on notebook or with PierreH if it's enough)
![](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/04-big_boost.png)
![](http://osp.kitchen/api/osp.tools.fons/raw/documentation/04-big_boost.png)
#### Threshold
![bad](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/05-threshold-bad.png)
![bad](http://osp.kitchen/api/osp.tools.fons/raw/documentation/05-threshold-bad.png)
![ok](
http://osp.kitchen/api/osp.tools.fons/raw/documentation/05-threshold-ok.png)
![ok](http://osp.kitchen/api/osp.tools.fons/raw/documentation/05-threshold-ok.png)
Save as a .bmp file.
......@@ -110,13 +89,28 @@ Save as a .bmp file.
IMPORTANT: If you zoom out to select the letters, don't forget to go back to zoom 1 before generating the font file. Don't close GlyphTracer before checking the .sfd file, then you can export again if you forgot to zoom back in.
### Merging fonts
In case you want to complete an existing font, you can use the script `mergeFonts.py`.
python mergeFonts.py fonte1.ufo fonte2.ufo ... fonte17.ufo fonte-out.ufo
### Metrics and kernings
A big part of type design is about managing the white space around the letters (metrics) and exceptions for specific couples of letters (kernings).
- For the metrics, we make an auto-spacing while generating the .sfd file with GlyphTracer.
- For the kernings, you can try the tool (Kernagic)[https://github.com/hodefoting/kernagic].
But if you want to get back metric and kerning data from an existing font, you can use the script `mergeSpacing.py`. It can be any font format than `.otf`.
python mergeSpacing.py font.otf original-font.otf spaced-font.otf
Troubleshooting
----------------------
---------------
### My image is too big to manipulate it.
Split it into several images and generate several .sfd files. Then you can merge the fonts with the script `mergeFonts.py`.
......
#! /usr/bin/python
"""
Merges the spacing information from one base font to your font and produces a new font (keeping the original fonts intact).
It can take any font format that Fontforge can open: .ufo, .otf, .sfd...
Usage:
python mergeSpacing.py MyFont.ufo BaseFont.ufo SpacedFont.ufo
"""
import fontforge
import sys
font = fontforge.open(sys.argv[1])
original = fontforge.open(sys.argv[2])
# MERGE SPACINGS
for g in font.glyphs():
char = g.glyphname
# Gets original font bearings
left = original[char].left_side_bearing
right = original[char].right_side_bearing
# Sets current bearings to 0
font[char].left_side_bearing = 0
font[char].right_side_bearing = 0
# Gets drawing width
width = font[char].width
# Resize the width with original bearings
font[char].width = left + width + right
font[char].left_side_bearing = left
font[char].right_side_bearing = right
# EXPORT ORIGINAL FONT AS PFA/AFM TO GET OPENTYPE FEATURES FROM AN AFM FILE
afm = original.generate("%s.pfa" % sys.argv[2])
# MERGE OPENTYPE FEATURES (including kernings)
font.mergeFeature("%s.afm" % sys.argv[2])
#font.mergeLookups(original)
#font.mergeLookupSubtables(original)
font.generate(sys.argv[3])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment