mirror of
https://github.com/belluzj/fantasque-sans.git
synced 2024-12-22 15:31:31 +01:00
Added support for longer ligatures
- Breaking out the ligature substitution rules like this also allows for easy logical extensions, to handle edge cases as FiraCode does.
This commit is contained in:
parent
f26bc2f418
commit
824cd6a9f8
|
@ -44,36 +44,41 @@ def rule(liga):
|
||||||
[LIG f i] LIG
|
[LIG f i] LIG
|
||||||
[ f f i] LIG }
|
[ f f i] LIG }
|
||||||
"""
|
"""
|
||||||
if len(liga) == 2:
|
# ignores:
|
||||||
return dedent('''\
|
# ignore sub {0} {0}' {1};
|
||||||
lookup {0}_{1} {{
|
# ignore sub {0}' {1} {1};
|
||||||
ignore sub {0} {0}' {1};
|
rules = [
|
||||||
ignore sub {0}' {1} {1};
|
ignore(prefix=liga[:1], head=liga[0], suffix=liga[1:]),
|
||||||
sub {0}' {1} by LIG;
|
ignore(head=liga[0], suffix=(liga[1:] + [liga[-1]])),
|
||||||
sub LIG {1}' by {0}_{1}.liga;
|
]
|
||||||
}} {0}_{1};
|
|
||||||
''').format(*liga)
|
name = "_".join(liga)
|
||||||
elif len(liga) == 3:
|
# substitution logic
|
||||||
return dedent('''\
|
# sub {0}' {1} by LIG;
|
||||||
lookup {0}_{1}_{2} {{
|
# sub LIG {1}' by {0}_{1}.liga;
|
||||||
ignore sub {0} {0}' {1} {2};
|
for i in range(len(liga)):
|
||||||
ignore sub {0}' {1} {2} {2};
|
init = _join(["LIG" for lig in liga[:i]])
|
||||||
sub {0}' {1} {2} by LIG;
|
tail = _join(liga[i + 1 :])
|
||||||
sub LIG {1}' {2} by LIG;
|
replace = "LIG" if (i + 1 < len(liga)) else (name + ".liga")
|
||||||
sub LIG LIG {2}' by {0}_{1}_{2}.liga;
|
rules.append("sub{0} {1}'{2} by {3};".format(init, liga[i], tail, replace))
|
||||||
}} {0}_{1}_{2};
|
|
||||||
''').format(*liga)
|
# put it all together
|
||||||
elif len(liga) == 4:
|
lines = (
|
||||||
return dedent('''\
|
["lookup " + name + " {"] + [" " + r for r in rules] + ["}} {0};".format(name)]
|
||||||
lookup {0}_{1}_{2}_{3} {{
|
)
|
||||||
ignore sub {0} {0}' {1} {2} {3};
|
return "\n".join(lines)
|
||||||
ignore sub {0}' {1} {2} {3} {3};
|
|
||||||
sub {0}' {1} {2} {3} by LIG;
|
|
||||||
sub LIG {1}' {2} {3} by LIG;
|
def _join(items):
|
||||||
sub LIG LIG {2}' {3} by LIG;
|
return (" " + " ".join(items)) if items else ""
|
||||||
sub LIG LIG LIG {3}' by {0}_{1}_{2}_{3}.liga;
|
|
||||||
}} {0}_{1}_{2}_{3};
|
|
||||||
''').format(*liga)
|
def ignore(prefix=None, head=None, suffix=None):
|
||||||
|
""" don't substitute `head` if it's surrounded by `prefix` and `suffix` """
|
||||||
|
assert head
|
||||||
|
pref = _join(prefix)
|
||||||
|
rest = _join(suffix)
|
||||||
|
return "ignore sub{0} {1}'{2};".format(pref, head, rest)
|
||||||
|
|
||||||
|
|
||||||
def indent(text, prefix):
|
def indent(text, prefix):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user