-
Notifications
You must be signed in to change notification settings - Fork 70
Description
I have been doing some research into what it would take to implement subscript and superscript. For my current use case, I think that the current state is actually sufficient (however, this assessment was made is before any code is written). See the details section for a sketch of how this can be done.
Implementing subscript with the current Parley
To implement a "good-enough" version of subscript in current Parley, we can emulate it with a marker associated with the brush, and a font size modifier. When we see the marker, we manually adjust the glyph.y down by (say) 30% of the line's (or possibly run's?) line height. These numbers are all tweakable, and aren't the point of this section.
Raph did point out that this has edge cases with ligatures (e.g. if you have a normal run of ff with font size of 12, then a subscripted i with a font size of 16), then this pattern would accidentally combine them together. This also applies to languages with more complex shaping.
Some sources about implementing this with full fidelity:
- Vertical alignment and the concept of a "parent" font and style #291 is tracking the vertical alignment part of this. I haven't yet dug into whether subscript and superscript in the general case run into the described issue around parent styles.
- The font-variant-position CSS attribute https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-variant-position. In particular, this describes the
subsandsupsopentype features. - The OS/2 metrics for this - https://learn.microsoft.com/en-us/typography/opentype/spec/os2#ysubscriptxsize. The CSS spec for font-variant-position has a note on this which is worth reading. https://drafts.csswg.org/css-fonts/#font-variant-position-prop:~:text=glyphs%2E-,The,glyphs