Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why enum every class-glyph, glyph-class kerning pairs? #355

Open
typemytype opened this issue Nov 23, 2019 · 1 comment
Open

why enum every class-glyph, glyph-class kerning pairs? #355

typemytype opened this issue Nov 23, 2019 · 1 comment

Comments

@typemytype
Copy link
Contributor

see https://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#6.b.ii

in this example there is a glyph-class pair and an glyph-glyph exception, there is no reason to enumerate.

Compiling this with FDK results in a warning: Pair positioning has conflicting statements in standalone lookup 'kern_ltr'; choosing the first value: A B

ufo2fdk has a method to determine if a higher level pair is possible which is solving this issue.

import defcon
font = defcon.Font()
font.newGlyph("A")
font.newGlyph("B")
font.newGlyph("C")

font.groups["public.kern2.test"] = ["B", "C"]
font.groups["public.kern1.test"] = ["B", "C"]

font.kerning['A', 'public.kern2.test'] = -100
font.kerning['A', 'B'] = 100

def ufo2fdk():
    from ufo2fdk.kernFeatureWriter import KernFeatureWriter

    w = KernFeatureWriter(font)
    print(w.write())

def ufo2ft():
    from ufo2ft.featureWriters.kernFeatureWriter import KernFeatureWriter, ast

    feaFile = ast.FeatureFile()
    w = KernFeatureWriter()
    w.write(font, feaFile)
    print(feaFile)

ufo2ft()
@kern1.test = [B C];
@kern2.test = [B C];

lookup kern_ltr {
    lookupflag IgnoreMarks;
    pos A B 100;
    enum pos A @kern2.test -100;
} kern_ltr;

feature kern {
    lookup kern_ltr;
} kern;
@anthrotype
Copy link
Member

this is perfectly valid and it is why in feaLib we demoted that to debug message rather than a warning message.
Quoting from FEA spec:
https://github.com/adobe-type-tools/afdko/blob/develop/docs/OpenTypeFeatureFileSpecification.md#6bii-enumerating-pairs

Since this representation is convenient for generating a large number of specific pairs, it may be used even when some of the pairs generated by the enum rules are incorrect. Specific pairs generated by an enum rule may be overridden by specifying preceding single pairs. Because of this case, it is not an error when specific kern pairs conflict because they have the same glyphs. When specific kern pair rules conflict, the first rule specified is used, and later conflicting rule are skipped.

On the other hand it may be the case that treating these specific exception pairs as class kerning instead of enumerating them as glyph-to-glyph could produce a more compact encoding, but that's not guaranteed in all cases.
If one wants to avoid this, one can wrap the single glyph in a group, in which case ufo2ft will treat the pairs as class kerning as desired.
This was a trade-off for simplicity, but I am open to review PRs in that direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants