Skip to content

Commit

Permalink
WIP Add ligatures
Browse files Browse the repository at this point in the history
  • Loading branch information
belluzj committed Jan 6, 2018
1 parent 6580d1c commit fe35ba6
Show file tree
Hide file tree
Showing 64 changed files with 1,716 additions and 106 deletions.
80 changes: 80 additions & 0 deletions Scripts/features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generate features for ligatures
#
# Adapted from https://github.com/tonsky/FiraCode/blob/master/gen_calt.clj

from textwrap import dedent
import tempfile


def update_features(font):
"""Find ligatures in the font and generate features for them."""
# [ ["dash" "greater" "greater"] ... ]
ligas = [name[:-len('.liga')].split('_')
for name in font if name.endswith('.liga') and
font[name].isWorthOutputting()]

rules = '\n\n'.join(rule(liga)
for liga in sorted(ligas, key=lambda l: -len(l)))

fea_code = dedent('''\
languagesystem DFLT dflt;
languagesystem latn dflt;
languagesystem grek dflt;
languagesystem cyrl dflt;
feature calt {{
{}
}} calt;
''').format(indent(rules, ' '))

print(fea_code)

# Add the dummy "LIG" glyph
lig = font.createChar(-1, 'LIG')
lig.width = font['space'].width
with tempfile.NamedTemporaryFile(suffix='.fea') as f:
f.write(fea_code)
f.seek(0)
font.mergeFeature(f.name)


def rule(liga):
"""
[f f i] => { [LIG LIG i] f_f_i.liga
[LIG f i] LIG
[ f f i] LIG }
"""
if len(liga) == 2:
return dedent('''\
lookup {0}_{1} {{
ignore sub {0} {0}' {1};
ignore sub {0}' {1} {1};
sub {0}' {1} by LIG;
sub LIG {1}' by {0}_{1}.liga;
}} {0}_{1};
''').format(*liga)
elif len(liga) == 3:
return dedent('''\
lookup {0}_{1}_{2} {{
ignore sub {0} {0}' {1} {2};
ignore sub {0}' {1} {2} {2};
sub {0}' {1} {2} by LIG;
sub LIG {1}' {2} by LIG;
sub LIG LIG {2}' by {0}_{1}_{2}.liga;
}} {0}_{1}_{2};
''').format(*liga)
elif len(liga) == 4:
return dedent('''\
lookup {0}_{1}_{2}_{3} {{
ignore sub {0} {0}' {1} {2} {3};
ignore sub {0}' {1} {2} {3} {3};
sub {0}' {1} {2} {3} by LIG;
sub LIG {1}' {2} {3} by LIG;
sub LIG LIG {2}' {3} by LIG;
sub LIG LIG LIG {3}' by {0}_{1}_{2}_{3}.liga;
}} {0}_{1}_{2}_{3};
''').format(*liga)


def indent(text, prefix):
return '\n'.join(prefix + line for line in text.split('\n'))
4 changes: 4 additions & 0 deletions Scripts/fontbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from os.path import basename, splitext, join
import subprocess
from features import update_features

SCRIPTS = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -93,6 +94,9 @@ def _build(dstdir, font, permutations):
for oper in option.operations[opt]:
oper(fnt)

# Update the automatic features (code ligatures)
update_features(fnt)

variant = '-'.join(variants) or 'Normal'
variant_dir = join(dstdir, variant)

Expand Down
1 change: 1 addition & 0 deletions Scripts/validate-font
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ if [ "x$error" != "x0" ]; then
fi
fi

exit 0
exit $error
6 changes: 3 additions & 3 deletions Sources/FantasqueSansMono-Regular.sfdir/afii10085.glyph
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ StartChar: afii10085
Encoding: 1091 1091 803
Width: 1060
VWidth: 14
Flags: HW
HStem: -376 153<247.402 417.113> 868 153<73 191.824>
VStem: 56 156<-190.185 0> 774 158<704.432 1020>
Flags: W
HStem: -376 153<81.6222 387.962> 868 153<73 191.824>
VStem: 774 158<704.643 1020>
LayerCount: 2
Back
Refer: 24 121 N 1 0 0 1 0 0 3
Expand Down
6 changes: 3 additions & 3 deletions Sources/FantasqueSansMono-Regular.sfdir/afii10110.glyph
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
StartChar: afii10110
Encoding: 1118 1118 830
Width: 1060
Flags: HW
HStem: -376 153<247.402 417.113> 868 153<73 191.824> 1175 153<375.698 655.547>
VStem: 56 156<-190.185 0> 161 156<1389.28 1450.76> 713 166<1384.15 1441.59> 774 158<704.432 1020>
Flags: W
HStem: -376 153<81.6222 387.962> 868 153<73 191.824> 1175 153<375.698 655.547>
VStem: 161 156<1389.28 1450.76> 713 166<1384.15 1441.59> 774 158<704.643 1020>
LayerCount: 2
Back
Refer: 328 774 S 1 0 0 1 7 -182 2
Expand Down
18 changes: 10 additions & 8 deletions Sources/FantasqueSansMono-Regular.sfdir/afii61352.glyph
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ StartChar: afii61352
Encoding: 8470 8470 980
Width: 1060
VWidth: 0
Flags: HW
Flags: W
HStem: -15 21G<110.462 178> 4 141<667 968> 253 142<775.974 864.208> 878 143<773.399 862.558> 1278 20G<75 234 500.5 583.667>
VStem: 75 145<44.1935 886.866 1129.24 1294> 417 163<1 233.656> 445 132<374.144 1159.81> 642 109<405.914 867.269> 886 106<405.74 864.948>
LayerCount: 2
Fore
SplineSet
886 650 m 4
886 650 m 4x3cc0
886 804 859 878 816 878 c 4
776 878 751 805 751 643 c 4
751 458 784 395 814 395 c 5
867 395 886 459 886 650 c 4
867 395 886 459 886 650 c 4x3cc0
813 253 m 5
714 253 642 371 642 646 c 4
642 856 698 1021 808 1021 c 4
936 1020 992 860 992 663 c 4
992 378 928 253 813 253 c 5
667 145 m 5
667 145 m 5x7cc0
968 145 l 5
968 4 l 5
667 4 l 5
667 145 l 5
417 0 m 5
667 145 l 5x7cc0
417 0 m 5xbec0
397 182 370 229 192 887 c 5
192 887 220 703 220 626 c 6
220 390 l 6
Expand All @@ -34,10 +36,10 @@ SplineSet
472 374 445 571 445 766 c 4
445 1044 459 1192 542 1312 c 5
667 1252 l 5
594 1134 577 1031 577 878 c 4
594 1134 577 1031 577 878 c 4xbdc0
577 652 581 398 581 168 c 4
581 111 580 54 580 1 c 5
417 0 l 5
417 0 l 5xbec0
EndSplineSet
Validated: 1
EndChar
40 changes: 20 additions & 20 deletions Sources/FantasqueSansMono-Regular.sfdir/b.glyph
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ VStem: 93 165<5.34919 81.4914 1156.27 1403.8> 112 157<241.719 786.994 949 1399.8
LayerCount: 2
Fore
SplineSet
749 478 m 4xd8
749 761 637 865 474 865 c 4
383 865 321 795 269 744 c 5
269 307 l 5
340 193 387 147 524 147 c 4
694 147 749 274 749 478 c 4xd8
906 459 m 4
906 191 799 -7 524 -7 c 4
412 -7 332 28 269 84 c 5xd8
268 42 263 20 258 -12 c 5
93 7 l 5xe8
103 73 112 160 112 243 c 4
112 251 112 259 112 267 c 4
112 516 111 877 111 1157 c 4
111 1251 103 1335 96 1403 c 5
255 1412 l 5
264 1339 269 1243 269 1152 c 6
269 949 l 5
317 985 360 1020 460 1020 c 4
783 1020 906 795 906 459 c 4
749 478 m 0xd8
749 761 637 865 474 865 c 0
383 865 321 795 269 744 c 1
269 307 l 1
340 193 387 147 524 147 c 0
694 147 749 274 749 478 c 0xd8
906 459 m 0
906 191 799 -7 524 -7 c 0
412 -7 332 28 269 84 c 1xd8
268 42 263 20 258 -12 c 1
93 7 l 1xe8
103 73 112 160 112 243 c 0
112 251 112 259 112 267 c 0
112 516 111 877 111 1157 c 0
111 1251 103 1335 96 1403 c 1
255 1412 l 1
264 1339 269 1243 269 1152 c 2
269 949 l 1
317 985 360 1020 460 1020 c 0
783 1020 906 795 906 459 c 0
EndSplineSet
Validated: 1
EndChar
22 changes: 11 additions & 11 deletions Sources/FantasqueSansMono-Regular.sfdir/bar.glyph
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ VStem: 391 162<-194.108 1492>
LayerCount: 2
Fore
SplineSet
390 152 m 0
390 517 381 1111 381 1399 c 2
381 1492 l 1
541 1492 l 1
541 1347 l 2
541 1070 553 558 553 224 c 2
553 74 l 2
553 -41 552 -97 547 -198 c 1
386 -197 l 1
390 -135 391 -92 391 -37 c 0
391 10 390 66 390 152 c 0
390 152 m 4
390 517 381 1111 381 1399 c 6
381 1492 l 5
541 1492 l 5
541 1347 l 6
541 1070 553 558 553 224 c 6
553 74 l 6
553 -41 552 -97 547 -198 c 5
386 -197 l 5
390 -135 391 -92 391 -37 c 4
391 10 390 66 390 152 c 4
EndSplineSet
Validated: 1
EndChar
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
StartChar: bar_bar_bar_greater.liga
Encoding: 57396 57396 1025
Width: 1060
VWidth: 4
Flags: HW
LayerCount: 2
Fore
SplineSet
-2466 1000 m 2
-2466 1093 l 1
-2306 1093 l 1
-2306 948 l 2
-2306 831 -2298 504.484375 -2298 369 c 2
-2298 219 l 2
-2298 104 -2299 48 -2304 -53 c 1
-2465 -52 l 1
-2461 10 -2460 53 -2460 108 c 0
-2460 394.356445312 -2466 673.005859375 -2466 1000 c 2
-680 1000 m 2
-680 1093 l 1
-520 1093 l 1
-520 948 l 2
-520 831 -512 504.484375 -512 369 c 2
-512 219 l 2
-512 104 -513 48 -518 -53 c 1
-679 -52 l 1
-675 10 -674 53 -674 108 c 0
-674 394.356445312 -680 673.005859375 -680 1000 c 2
-1574.01074219 1000 m 2
-1574.01074219 1093 l 1
-1414.01074219 1093 l 1
-1414.01074219 948 l 2
-1414.01074219 831 -1406.01074219 504.484375 -1406.01074219 369 c 2
-1406.01074219 219 l 2
-1406.01074219 104 -1407.01074219 48 -1412.01074219 -53 c 1
-1573.01074219 -52 l 1
-1569.01074219 10 -1568.01074219 53 -1568.01074219 108 c 0
-1568.01074219 394.356445312 -1574.01074219 673.004882812 -1574.01074219 1000 c 2
318 590 m 1
318 473 l 1
222 404 -343 38 -518 -53 c 1
-548.740234375 -16.2578125 -562.995117188 40.068359375 -586 86 c 1
-415 194 -24 417 133 525 c 1
7 615 -401.563476562 827.749023438 -533.944335938 909.646484375 c 0
-565.27734375 928.940429688 -590.541992188 943.31640625 -614.99609375 969.065429688 c 1
-519 1092 l 1
-390.591796875 988.930664062 231 657 318 590 c 1
EndSplineSet
EndChar
39 changes: 39 additions & 0 deletions Sources/FantasqueSansMono-Regular.sfdir/bar_bar_greater.liga.glyph
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
StartChar: bar_bar_greater.liga
Encoding: 57395 57395 1024
Width: 1060
VWidth: 4
Flags: HW
LayerCount: 2
Fore
SplineSet
-1569 1000 m 2
-1569 1093 l 1
-1409 1093 l 1
-1409 948 l 2
-1409 831 -1401 504.484375 -1401 369 c 2
-1401 219 l 2
-1401 104 -1402 48 -1407 -53 c 1
-1568 -52 l 1
-1564 10 -1563 53 -1563 108 c 0
-1563 394.356445312 -1569 673 -1569 1000 c 2
-678 1000 m 2
-678 1093 l 1
-518 1093 l 1
-518 948 l 2
-518 831 -510 504.484375 -510 369 c 2
-510 219 l 2
-510 104 -511 48 -516 -53 c 1
-677 -52 l 1
-673 10 -672 53 -672 108 c 0
-672 394.356445312 -678 673.005859375 -678 1000 c 2
319 591 m 1
319 474 l 1
223 405 -342 39 -517 -52 c 1
-547.740234375 -15.2578125 -561.995117188 41.068359375 -585 87 c 1
-414 195 -23 418 134 526 c 1
8 616 -400.563476562 828.749023438 -532.944335938 910.646484375 c 0
-564.27734375 929.940429688 -589.541992188 944.31640625 -613.99609375 970.065429688 c 1
-518 1093 l 1
-389.591796875 989.930664062 232 658 319 591 c 1
EndSplineSet
EndChar
29 changes: 29 additions & 0 deletions Sources/FantasqueSansMono-Regular.sfdir/bar_greater.liga.glyph
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
StartChar: bar_greater.liga
Encoding: 57394 57394 1023
Width: 1060
VWidth: 4
Flags: HW
LayerCount: 2
Fore
SplineSet
-391 1000 m 6
-391 1093 l 5
-231 1093 l 5
-231 948 l 6
-231 831 -223 504.484375 -223 369 c 6
-223 219 l 6
-223 104 -224 48 -229 -53 c 5
-390 -52 l 5
-386 10 -385 53 -385 108 c 4
-385 394.356445312 -391 673.005859375 -391 1000 c 6
606 591 m 5
606 474 l 5
510 405 -55 39 -230 -52 c 5
-260.740234375 -15.2578125 -274.995117188 41.068359375 -298 87 c 5
-127 195 264 418 421 526 c 5
295 616 -113.563476562 828.749023438 -245.944335938 910.646484375 c 4
-277.27734375 929.940429688 -302.541992188 944.31640625 -326.99609375 970.065429688 c 5
-231 1093 l 5
-102.591796875 989.930664062 519 658 606 591 c 5
EndSplineSet
EndChar
Loading

0 comments on commit fe35ba6

Please sign in to comment.