simoncozens / fontFeatures

Python library for manipulating OpenType font features
BSD 3-Clause "New" or "Revised" License
73 stars 10 forks source link

Do not output script/language tags into aalt #64

Open kontur opened 7 months ago

kontur commented 7 months ago

Came across this when round-tripping OTF > UFO > OTF.

I'm extracting UFOs from Opentype files with ufo-extractor. fontFeatures will output aalt features like these:

feature aalt {
    script DFLT;
    language dflt;
            script DFLT;
        language dflt;
        lookup SingleSubstitution1;

} aalt;

feature aalt {
    script latn;
    language dflt;
            script latn;
        language dflt;
        lookup SingleSubstitution1;

} aalt;

feature aalt {
    script latn;
    language AZE;
            script latn;
        language AZE;
        lookup SingleSubstitution1;

} aalt;
...

which will ultimately fail to recompile in fontTools' feaLib here.

These need not be split by script/language to begin with.

kontur commented 7 months ago

hmm... maybe this is indicative of other things going wrong here.

when looking at the fea output SingleSubstitution1 is weird:

lookup SingleSubstitution1 {
    lookupflag 0;
    ;
    sub Scedilla by uni0218;
    sub b by bsuperior;
    sub c by csuperior;
    sub d by dsuperior;
    sub e by esuperior;
    sub egrave by egravesuperior;
    sub f by fsuperior;
    sub g by gsuperior;
    sub h by uni02B0;
    sub j by uni02B2;
    sub k by ksuperior;
    sub l by uni02E1;
    sub m by msuperior;
    sub n by uni207F;
    sub p by psuperior;
    sub q by qsuperior;
    sub r by rsuperior;
    sub s by uni02E2;
    sub scedilla by uni0219;
    sub t by tsuperior;
    sub u by usuperior;
    sub v by vsuperior;
    sub w by uni02B7;
    sub x by uni02E3;
    sub y by uni02B8;
    sub z by zsuperior;
} SingleSubstitution1;

I don't have access to the font source only the binary, but this looks like a mix of a sups lookup (but missing some stuff) with a locl for ROM with the Scedilla replacement. While these are single substitutions, for example the extracted sups feature uses another lookup with wider character range, and if this is all of aalt I'd expect other single substitutions from other features as well (okay, this could be the font source doing aalt wrong, but it seems random that sups and one locl would be in there.).

NightFurySL2001 commented 5 months ago

Actually, this seems to be a problem/miscommunication (?) with the Adobe FEA syntax. The Microsoft OpenType specs seems to not disallow any script/language tags in aalt feature.

Tag: 'aalt'

Friendly name: Access All Alternates

Registered by: Adobe

Function: This feature makes all variations of a selected character accessible. This serves several purposes: An application might not support the feature by which the desired glyph would normally be accessed; the user could need a glyph outside the context supported by the normal substitution, or the user might not know what feature produces the desired glyph.

Example: A user inputs the P in Poetica and is presented with a choice of the four standard capital forms, the eight swash capital forms, the initial capital form and the small capital form.

Recommended implementation: A GSUB type 3 lookup subtable should normally be used. The type 3 formats arrange glyphs into groupings of related glyphs. For example, the default glyph for a Unicode character and the associated set of alternate glyphs for that character. The default glyph can be included in the set of alternates, in which case it should be the first alternate.

A GSUB type 1 lookup subtable could also be used if a default glyph has only one alternate. A lookup could combine type 3 and type 1 subtables. Other lookup subtable types are not recommended.

Ligature glyphs should not be included as alternates of the glyph for any ligature component. For example, an fi ligature glyph should not be included as an alternate for f. Ligature glyphs can be included in an alternate set if they are variants of another ligature glyph, however.

If different fonts within a typographic family have the same alternates, the ordering of glyphs within the alternate sets should match across these fonts so that corresponding alternates will be selected when switching between fonts in the family.

Application interface: Discretionary feature: can be applied to glyph runs based on document markup, user control or other application criteria. The application determines the glyph ID for the default form of a given character (default glyph from the 'cmap' table with no features applied). It then checks to see whether the glyph ID is found in the coverage table of an 'aalt' lookup. If so, the application retrieves the alternate glyphs mapped in the alternate substitution lookup and selects one.

UI suggestion: The application should indicate to the user which glyphs in the user’s document have alternative forms (i.e., which are in the coverage table for 'aalt'), and provide some means for the user to select an alternate glyph. An application could display the forms sequentially in context, or present a palette showing all the forms at once, or give the user a choice between these approaches. The application may assume that the first glyph in a set is the preferred form, so the font developer should order them accordingly. When only one alternate exists, this feature could toggle directly between the alternate and default forms.

Script/language sensitivity: None.

Feature interaction: This feature may be used in combination with other features.

It is only specified in the Adobe FEA syntax, which states that the default behaviour is to register aalt under all language systems.

Specifying language system: This feature will be registered under all language systems specified by languagesystem statements; see §4.b.i above.

The following are not allowed in the aalt feature definition: script, language, lookupflag, and subtable statements; named lookup blocks and lookup reference statements. The aalt lookups will be created with LookupFlag 0.

When comparing this to the OpenType feature editor in FontCreator, FC requires the languages/scripts to be set up manually (not all are used by default). This has caused similar problem to appear when using FC to export UFO font. Other feature syntax like Microsoft VOLT and their own OTLFD allows languages/scripts in aalt feature.