Search code examples
fontsfontforge

Automatically generate italic fonts from a given typeface


I'm currently building a FontForge script which converts the Cantarell set of fonts for use as webfonts. However, Cantarell doesn't actually feature oblique/italic versions of the fonts, and I prefer to automatically generate them through FontForge. I tried using foreach to select all glyphs and Italic() to generate italic versions for each of the glyphs. However, the results are still the same as the original fonts.

#!/usr/bin/fontforge
FONT_NAME = "Cantarell"
VARIANTS = ["Bold", "ExtraBold", "Light", "Regular", "Thin"]
i = 0

while (i < SizeOf(VARIANTS))
  FILE_NAME = "fonts/" + FONT_NAME + "-" + VARIANTS[i] + ".otf"
  FILE_NAME_ITALIC = "fonts/" + FONT_NAME + "-" + VARIANTS[i] + "Italic.otf"
  Print(FILE_NAME)
  Open(FILE_NAME)
  Generate(FILE_NAME:r + ".svg")
  Generate(FILE_NAME:r + ".eot")
  Generate(FILE_NAME:r + ".ttf")
  Generate(FILE_NAME:r + ".woff")
  Generate(FILE_NAME:r + ".woff2")
  foreach
    Italic()
  endloop
  Generate(FILE_NAME_ITALIC)
  Generate(FILE_NAME_ITALIC:r + ".svg")
  Generate(FILE_NAME_ITALIC:r + ".eot")
  Generate(FILE_NAME_ITALIC:r + ".ttf")
  Generate(FILE_NAME_ITALIC:r + ".woff")
  Generate(FILE_NAME_ITALIC:r + ".woff2")
  i = i + 1
endloop

enter image description here

Notes

  • I know that I need to change the italic fonts' metadata for use in TrueType and OpenType. However, I still need this issue to be solved.
  • The original OTF files aren't directly available on https://gitlab.gnome.org/GNOME/cantarell-fonts/ (You still need to compile them manually). However, they are easily available by extracting the precompiled packages (e.g. in Debian's DEB archive)
  • Google Fonts ships a way older version of Cantarell and they are ugly, so I decided to make this script as a modern alternative.

Solution

  • Try

    SelectAll()
    Italic(15)
    

    instead of foreach-loop. Maybe Skew() instead of Italic() Method is better choice. I don't know the differeces of theese two. 15 is the number of degrees to skew.