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

A way to explicitly prefer OpenType shaping over AAT #4108

Open
khaledhosny opened this issue Feb 10, 2023 · 9 comments · May be fixed by #4269
Open

A way to explicitly prefer OpenType shaping over AAT #4108

khaledhosny opened this issue Feb 10, 2023 · 9 comments · May be fixed by #4269

Comments

@khaledhosny
Copy link
Collaborator

khaledhosny commented Feb 10, 2023

Currently we use some heuristics to decide whether to use AAT or OT layout table when fonts provide both and our heuristics try to match what CoreText does. All good. However, some fonts have AAT tables for historical reasons (since OSX initially didn’t support OT layout) and on non-mac platforms people were getting OT layout, now they get AAT and it can be unexpected (sometimes the AAT table are even there by accident, FontForge sometimes ”translates” OT to AAT and does it badly).

So, I’m asking for a way to always prefer OT. Currently our ot shaper does both OT and AAT layout, so changing shaper list order does not help.

One way, though probably will be ugly internally, is to introduce and new dummy aat shaper that simply prefers AAT, and may be make ot do the reverse and add a new default (or some other name) that is equivalent to current ot shaper (which is misnomer already).

Or may be some other way, I don’t really mind, though shaper list is an already existing mechanism and some clients already expose it to users (I know at least luaotfload and SILE).

@behdad
Copy link
Member

behdad commented Feb 10, 2023

Changing ot to disable aat is probably fine. We can add a new default hb to do what ot currently does. What should a default aat do though? Only apply morx and never GSUB? What about the positioning part? There are fonts with morx and GPOS.

@khaledhosny
Copy link
Collaborator Author

I’d think it would prefer AAT tables, but I’m not sure if it should be all or none (i.e. if morx is available only apply kern and skip GPOS), but I guess it makes more sense since it is likely to be used mainly for testing and debugging purposes.

@khaledhosny khaledhosny linked a pull request Jun 6, 2023 that will close this issue
@khaledhosny
Copy link
Collaborator Author

khaledhosny commented Oct 26, 2023

Here is another case where this is needed. This seems to be an official Moroccan font, it contains non-functional morx table (seems to have been autogenerated with FontForge, probably by mistake), but since Windows does not support AAT shaping it went unnoticed.

AALMAGHRIBI.ttf.zip

@khaledhosny
Copy link
Collaborator Author

Regardless of the issue here, I don’t know if we can find a heuristic to detect such broken morx tables, though I know nothing about how morx works or in what aspect this font’s table is broken.

@khaledhosny
Copy link
Collaborator Author

Reading this issue again, I probably opened it precisely about this font since this is not the first time I encounter it, though I can’t remember or find where I saw it before.

@dscorbett
Copy link
Collaborator

After reviewing AALMAGHRIBI’s 'morx' table, I think there is a bug in HarfBuzz’s AAT implementation.

This font does not enable its topographical subtables’ subfeatures in its defaultFlags. They are only enabled when the kCursiveConnection feature is set to kCursiveSelector (which it should always be for Arabic). However, feature_mappings does not have a mapping for that feature–value pair. Therefore, HarfBuzz never enables the relevant subfeatures.

@khaledhosny
Copy link
Collaborator Author

After reviewing AALMAGHRIBI’s 'morx' table, I think there is a bug in HarfBuzz’s AAT implementation.

This font does not enable its topographical subtables’ subfeatures in its defaultFlags. They are only enabled when the kCursiveConnection feature is set to kCursiveSelector (which it should always be for Arabic). However, feature_mappings does not have a mapping for that feature–value pair. Therefore, HarfBuzz never enables the relevant subfeatures.

I don’t know anything about morx, but the font is broken with Core Text as well, which why I thought it is a font issue.

@jfkthame
Copy link
Collaborator

According to the Apple font feature registry at https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html:

Cursive Connection

Feature Constant Feature Value Feature Type
kCursiveConnection 2 Exclusive

The Cursive Connection feature type is used for cursively-connected scripts. It is required for Arabic, but may be used for other scripts as well.

Selector Name Selector Constant(s) Selector Value Selector Function
Unconnected kUnconnectedSelector 0 Disables cursive connection altogether. Note that selecting this for some scripts will result in incorrect liguistic appearance.
Partially Connected kPartiallyConnectedSelector 1 Selects pre-drawn letterforms that connect in a non-contextual manner.
Cursive kCursiveSelector 2 Selects full, contextual connection of letterforms. This setting must always be the default in fonts for scripts that require this behavior.

(emphasis added).

So if the font fails to set this in its defaultFlags, I think we can reasonably dismiss it as a font bug. (Especially if it fails similarly in Core Text.)

@dscorbett
Copy link
Collaborator

You’re right: I just tried the font in Pages, and the cursive connection does work but only when explicitly enabled. So a heuristic could be that if an Arabic font’s 'morx' doesn’t enable cursive by default, HarfBuzz should fall back to OpenType.

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

Successfully merging a pull request may close this issue.

4 participants