See discussion on the issue. I think I got this right. Fixes https://github.com/fonttools/fonttools/issues/2737