Fontforge Scripting how to add ligatures for a glyph
Asked Answered
B

2

8

I'm making a font with scripting on Fontforge. Everything goes well, but I have this problem I don't know how to specify for a selected glyph that if two other glyphs came simultaneously show the selected glyph. I have already made the Lookuptable and the subtable for that but I don't know the function that would define some ligatures for a specified glyph. Here is the code for making table and subtable for adding ligatures to a glyph.

AddLookup("Ligatures","GSUB_ligature",9,[["rlig",[["arab",["dflt"]]]]])
AddLookupSubtable("Ligatures","Ligatureshi")
Bloomers answered 5/6, 2012 at 18:14 Comment(1)
The question asks for how to add ligatures to a font using a script, but it is also possible to do in the FontForge GUI interface. I don't know how to do this well enough to add a full answer, but go to Element > Font Info > Lookups > GSUB. See this answer for how to remove ligatures.Fuzz
B
7

You need to specify the Ligature substitution using a tuple of existing Glyph names.

A contrived example:

#!/usr/bin/env python3
import fontforge

# load your font, etc…

ligature_name = 'f_l'
ligature_tuple = ('f', 'l')
font.addLookup('ligatures','gsub_ligature', (),[['rlig',[['arab',['dflt']]]]])
font.addLookupSubtable('ligatures', 'ligatureshi')
glyph = font.createChar(-1, ligature_name)
glyph.addPosSub('ligatureshi', ligature_tuple)
Bettor answered 17/2, 2016 at 19:49 Comment(0)
I
0

After you've added the lookup & subtable, do this:

Select("fl")
AddPosSub("LigatureSubtableName", "f l")

The above FontForge script will add a fl ligature.

Inherent answered 12/1, 2013 at 7:48 Comment(1)
Hi @Arthaey, This line of code that you wrote is gonna declare some substitutions in the substitution table which seems not to show "fl" when I'm writing "f" and "l", so I guess I need something that can add some information for "fl" in the ligature table for converting "f"&"l" to "fl" when they appear together. Do you have any idea? or at least have you done this before?Bloomers

© 2022 - 2024 — McMap. All rights reserved.