Skip to content
/ svgs2ttf Public
forked from pteromys/svgs2ttf

Bundle SVG images into a TTF via FontForge.

License

Notifications You must be signed in to change notification settings

ocodo/svgs2ttf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svgs2ttf

Description

A quick & dirty FontForge + Python script to generate fonts from a directory of SVG files (or other outline formats importable by FontForge) and some JSON metadata.

Not to be confused with svg2ttf. Users with more sophisticated needs probably want Font Custom, grunt-webfont, or IcoMoon.

Dependencies

  • FontForge (A version with python. Developed on 20140101)
  • Python >= 2.6 or 3

Usage

$ svgs2ttf metadata.json

Example metadata.json:

{ "props":
  { "ascent": 800
  , "descent": 200
  , "em": 1000
  , "family": "Example"
  }
, "input": "src"
, "output": [ "example.ttf" ]
, "glyphs":
  { "0x41": { "src": "a.svg" }
  , "0x42": { "src": "b.svg" }
  , "67": "c.svg"
  }
}
  • props holds three kinds of font properties:
    • Shortcuts: family and style (name your font), and lang (default language for entries in the sfnt name table).
    • Any properties of fontforge.font; get attached to the font object as an attribute. The lengths ascent, descent, and em are probably useful to set.
    • Everything else gets added to the sfnt name table.
  • input, if specified, is the directory where images are found. (default: '.') All paths are relative to the JSON file.
  • output is an array of output filenames. FontForge guesses the type from the extension. Supported types are listed in FontForge's menu and include SVG, TTF, and WOFF. (EOT currently requires a 3rd-party converter, e.g. ttf2eot.)
  • glyphs is a mapping whose keys are integer codepoints (as strings in base 2, 8, 10, or 16).
    • Values are filenames or dictionaries with the filename in src.
    • Other dictionary entries become attributes of the glyph object. See supported attributes. Useful ones may include altuni, comments, width, and vwidth.
    • If a filename is not provided (value is an empty string or a dict without the src key), then (codepoint).svg is guessed.
  • sfnt_names, if specified, lists entries to add directly to the sfnt name table.

See examples/example.json for an example that specifies more options. Some customizations might be best done by editing the script. (See the FontForge python reference.)

Input file restrictions

  • The JSON must be valid JSON. The format is fairly unforgiving of misplaced commas and single quotes, though if you want to write comments you can interpose yajl's json_reformat like so:

    $ svgs2ttf <(json_reformat < with_comments.json)
    
  • It's better if the input pictures are just plain filled paths. FontForge tries to do the right thing for stroked paths and unions of overlapping regions, but support for clipping is missing (fontforge#1276), and some interactions between stroke expansion and overlap removal (e.g. fontforge#1374) were only recently corrected.

About

Bundle SVG images into a TTF via FontForge.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 86.7%
  • Shell 13.3%