linebender / linebender/parley

Investigation: Subscript and Superscript

Open
#577 3 comments 1 reaction 0 assignees View on GitHub
C-parley
Dominant language
Rust
Stars
736
Forks
120
Avg merge
1d 3h
Merged PRs (30d)
53

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:
- #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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading issue #291 for the vertical-alignment work, then review the linked CSS font-variant-position and OpenType OS/2 metric specifications. The issue presents a sketch and research references but does not define whether a good-enough or full-fidelity implementation is required, so completion criteria still need to be decided.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.