[80_3] Enhance sup/subscript kerning via OpenType math table #2090
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
We have utilized the italic correction table and kerning table in OpenType to optimize the typesetting of superscripts and subscripts.
However, it is important to note that this implementation is non-standard.
The italic correction table is used to improve the typesetting on the right side of glyphs. For general characters, the right subscript uses the default position, while the right superscript needs to be shifted to the right by this correction. For symbols like integral signs, the official documentation suggests that both the right superscript and right subscript should be moved by half the offset, while some documents recommend that the superscript remain stationary and the subscript be moved by the full offset. For aesthetic reasons, we have adopted a compromise solution here, where the subscript is shifted left by 0.6 times the offset and the superscript is shifted right by 0.4 times the offset.
For the kerning table, it provides correction values for the left and right superscripts and subscripts of a glyph based on their height. According to the OpenType standard recommendations, we should select an optimal correction value by considering both the base glyph and the superscript/subscript glyph at the two recommended correction heights. However, we are unable to handle this in the font's cpp file, so we have opted for a simpler approach, using
fn->y1
andfn->y2
as the correction heights for the subscript and superscript, respectively, which also yields satisfactory results.Another fact is that many fonts do not provide a kerning table or only provide a very limited kerning table, and almost none of them provide correction values for left superscripts and subscripts. So it can be considered that this PR does not actually change any left-side typesetting.
Why
For certain OpenType fonts, some symbols such as integral signs and superscripts/subscripts appear in incorrect positions. Now, we can improve this by utilizing the metrics provided in OpenType.
How to test
Open
devel/80_3.tmu
.Before:
After:
It can be seen that the first two Opentype fonts have been correctly improved, while the latter two have not changed because we used a hardcoded solution.