Skip to content

Commit

Permalink
use 'ccmp' feature for required ligature substitution
Browse files Browse the repository at this point in the history
instead of 'rlig', for wider compatibility. NotoColorEmoji.ttf does the same
Fixes #279
  • Loading branch information
anthrotype committed Apr 19, 2021
1 parent 67081b8 commit f1d3f98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/nanoemoji/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@
from nanoemoji.glyph import glyph_name


def generate_fea(rgi_sequences):
# Generate rlig feature with ligature lookup for multi-codepoint RGIs
DEFAULT_GSUB_FEATURE_TAG = "ccmp"


def generate_fea(rgi_sequences, feature_tag=DEFAULT_GSUB_FEATURE_TAG):
# Generate feature with ligature lookup for multi-codepoint RGIs
rules = []
rules.append("languagesystem DFLT dflt;")
rules.append("languagesystem latn dflt;")
rules.append("")

rules.append("feature rlig {")
rules.append(f"feature {feature_tag} {{")
for rgi in sorted(rgi_sequences):
if len(rgi) == 1:
continue
glyphs = [glyph_name(cp) for cp in rgi]
target = glyph_name(rgi)
rules.append(" sub %s by %s;" % (" ".join(glyphs), target))

rules.append("} rlig;")
rules.append(f"}} {feature_tag};")
rules.append("")
return "\n".join(rules)
19 changes: 19 additions & 0 deletions tests/features_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from textwrap import dedent
from nanoemoji.features import generate_fea, DEFAULT_GSUB_FEATURE_TAG
import pytest


@pytest.mark.parametrize("feature_tag", (DEFAULT_GSUB_FEATURE_TAG, "rlig"))
def test_generate_fea(feature_tag):
rgi_sequences = [(0x1F64C,), (0x1F64C, 0x1F3FB), (0x1F64C, 0x1F3FC)]
assert generate_fea(rgi_sequences, feature_tag=feature_tag) == dedent(
f"""\
languagesystem DFLT dflt;
languagesystem latn dflt;
feature {feature_tag} {{
sub g_1f64c g_1f3fb by g_1f64c_1f3fb;
sub g_1f64c g_1f3fc by g_1f64c_1f3fc;
}} {feature_tag};
"""
)

0 comments on commit f1d3f98

Please sign in to comment.