ITADN

Investigation: Subscript and Superscript

#577OpenDJMcNab 创建于 2026-03-17
C-parley
D
DJMcNabcommented
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. <details><summary>Implementing subscript with the current Parley</summary> <p> 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. </p> </details> Some sources about implementing this with full fidelity: - #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 `subs` and `sups` opentype 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
1 条评论