schriftgestalt / ShowUnderline

Apache License 2.0
6 stars 2 forks source link

Underline drawn at incorrect position #8

Open rsms opened 2 years ago

rsms commented 2 years ago

This plugin draws the underline centered on underlinePosition while the spec says it should describe the top of the underline.

arst98l2

BTW, if this was open source I'd be happy to contribute a fix :-)

schriftgestalt commented 2 years ago

What makes you think that this plugin is not open source? https://github.com/schriftgestalt/ShowUnderline/blob/master/ShowUnderline.glyphsPlugin/Contents/Resources/plugin.py

There is a confusion with the way the values is stored in the CFF table. CFF table defines the value as the center of the underline. (Glyphs corrects for this in the CFF table). That has changed for CFF2:

UnderlinePosition: Equivalent to the underlinePosition field in the 'post' table.

rsms commented 2 years ago

Oh! I looked at the mach-o binary at ~/Library/Application\ Support/Glyphs\ 3/Plugins/ShowUnderline.glyphsPlugin/Contents/MacOS/plugin

rsms commented 2 years ago

Interestingly Safari, Chrome and Firefox all draw the underline starting at (top) underlinePosition, not centered on it, even for TrueType fonts and CFF1 fonts. I couldn't find information about underline in CFF v1 (the CFF v1 PDF only lists UnderlinePosition and UnderlineThickness as attributes of a DICT, but does not describe its interpretation.) I'm curious to learn more about this — is there a link you could share with me about this data in CFF?

I tested this by making a simple HTML page and setting the following CSS for the document to have the browsers use the font data instead of making up their own values:

text-decoration-thickness: from-font;
text-underline-position: from-font;

Underline rendered as expected: (last character is an underscore)

Screen Shot 2022-07-01 at 12 37 47

However, underline rendering is all over the place in other software. TextEdit and all other standard macOS apps ignores the font's underline position and thickness (which is a shame, but reality is reality I guess.)

Screen Shot 2022-07-01 at 12 41 36

The software that does get it right, like Affinity Designer, also does what the web browsers do and draw the underline's top (not center) at underlinePosition.

Affinity Designer example: (notice the underline matching the underscore)

Screen Shot 2022-07-01 at 12 46 48
schriftgestalt commented 2 years ago

Have you tried to mess with the CFF value to find out if anyone is using them? Maybe the Adobe apps?

rsms commented 2 years ago

No, but that's an interesting idea!

BTW, here's a minimal test font: https://rsms.me/etc/font-underline/ (https://rsms.me/etc/font-underline/RSMSTest.var.ttf) Source: https://www.dropbox.com/s/nxshpmpo70o8794/underline-test-font.zip?dl=1 ,(OFL licensed)

CleanShot 2022-07-01 at 14 38 55 mp4