Skip to content

Instantly share code, notes, and snippets.

@austinhappel
Created May 23, 2014 23:39
Show Gist options
  • Save austinhappel/ee022da7d3b376f37ca9 to your computer and use it in GitHub Desktop.
Save austinhappel/ee022da7d3b376f37ca9 to your computer and use it in GitHub Desktop.
Quick gist on making webfonts - converting otf to ttf to eot.

Converting Fonts

This is a quick and dirty process for converting otf fonts to TTF fonts, then converting those TTF fonts into M$-compatible eot fonts.

NOTE This process has only been tested to work in osx, using macports.

Requirements

  • FontForge CLI port install fontforge
  • ttf2eot port install ttf2eot
  • rename port install rename
  • An otf to ttf script for font forge (see below)

Save this as otf2ttf.sh, or something.

#!/usr/local/bin/fontforge

Print("Opening "+$1);
Open($1);
Print("Saving "+$1:r+".ttf");
SetFontNames($1:r,$1:r,$1:r);
Generate($1:r + ".ttf");
Quit(0);

To convert OTF to TTF

First, open a terminal and cd into the font directory.

Second, run this:

for i in *.otf; do fontforge -script ~/Desktop/otf2ttf.sh $i; done

To convert TTF to EOT

First, open a terminal and cd into the font directory where the ttfs are found.

Second, run this:

for i in *.ttf; do ttf2eot < $i > $i.eot; done; rename 's/\.ttf//' *.eot

CSS font template

@font-face {
    font-family: 'MyFontnormal';
    src: url('MyFont-webfont.eot');
    src: url('MyFont-webfont.eot?#iefix') format('embedded-opentype'),
         url('MyFont-webfont.woff') format('woff'),
         url('MyFont-webfont.ttf') format('truetype'),
         url('MyFont-webfont.svg#MyFontnormal') format('svg');
    font-weight: normal;
    font-style: normal;

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment