Bug 211683 - Text is clipped when rendered with fonts which have a negative line gap metric
Summary: Text is clipped when rendered with fonts which have a negative line gap metric
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Myles C. Maxfield
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-09 21:13 PDT by Myles C. Maxfield
Modified: 2020-05-12 13:32 PDT (History)
4 users (show)

See Also:


Attachments
Patch (10.58 KB, patch)
2020-05-09 21:17 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (18.65 KB, patch)
2020-05-09 21:53 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff
Patch (26.73 KB, patch)
2020-05-09 23:43 PDT, Myles C. Maxfield
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Myles C. Maxfield 2020-05-09 21:13:47 PDT
Text is clipped when rendered with fonts which have a negative line gap metric
Comment 1 Myles C. Maxfield 2020-05-09 21:17:33 PDT
Created attachment 398957 [details]
Patch
Comment 2 Myles C. Maxfield 2020-05-09 21:17:36 PDT
<rdar://problem/62192986>
Comment 3 Myles C. Maxfield 2020-05-09 21:53:57 PDT
Created attachment 398958 [details]
Patch
Comment 4 Myles C. Maxfield 2020-05-09 23:43:01 PDT
Created attachment 398961 [details]
Patch
Comment 5 Sam Weinig 2020-05-10 10:04:02 PDT
Comment on attachment 398961 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=398961&action=review

> Source/WebCore/ChangeLog:17
> +        There are some typographical reasons to want a negative line gap, which is why this clamping
> +        behavior shouldn't be done in the platform text library. In the interest of matching other
> +        browsers, we should perform this clamping ourselves in WebKit.

Out of curiosity, what are the reasons one might want a negative line gap? Given that WebKit is used for more than just browsers, would any of those reasons apply to other uses of WebKit? Should this perhaps be a preference?
Comment 6 Darin Adler 2020-05-10 15:43:54 PDT
Comment on attachment 398961 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=398961&action=review

>> Source/WebCore/ChangeLog:17
>> +        browsers, we should perform this clamping ourselves in WebKit.
> 
> Out of curiosity, what are the reasons one might want a negative line gap? Given that WebKit is used for more than just browsers, would any of those reasons apply to other uses of WebKit? Should this perhaps be a preference?

(Heretic speaks) Or a non-standard CSS property?
Comment 7 Myles C. Maxfield 2020-05-10 19:53:04 PDT
(In reply to Darin Adler from comment #6)
> Comment on attachment 398961 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398961&action=review
> 
> >> Source/WebCore/ChangeLog:17
> >> +        browsers, we should perform this clamping ourselves in WebKit.
> > 
> > Out of curiosity, what are the reasons one might want a negative line gap? Given that WebKit is used for more than just browsers, would any of those reasons apply to other uses of WebKit? Should this perhaps be a preference?
> 
> (Heretic speaks) Or a non-standard CSS property?

There are two reasons why a designer or font creator might want it:

1. They just plain want tighter line spacing. One reason for this is the font's design might include swashes and diacritics which necessitate a large ascent (for things like the text selection rectangle), but the line height looks too large. Another possible reason is the font is designed for a script which has these typographic attributes.

2. CSS uses a different model of line-height than most other design systems. In CSS, half-leading is added to the ascent and descent of the line during layout. However, in most other layout systems, the line gap is modeled as a strut between successive lines. For interior lines of a paragraph, there is no difference, but for the first and last lines, there is a difference. I most other layout systems, if a font has a negative line gap, it means that the interior lines of a paragraph appear closer together, but the first line of the paragraph still has plenty of space on its upper half. This look can add emphasis on the first line of text in a paragraph, which can be typographically valuable. However, for CSS's model, this logic doesn't really hold so much.

I could see this being configurable, but I think this specific patch is too low-level to warrant its own switch. If anything, we might want to have a "make line layout work the same as native TextKit" where we redesign line-height to act like their design, and honor these negative line gaps in that mode. If we do something like this, it makes sense for the switch to be API or SPI rather than a CSS property, because the audience for this kind of switch would be app developers who want to present a native-like interface.
Comment 8 EWS 2020-05-12 13:32:22 PDT
Committed r261573: <https://trac.webkit.org/changeset/261573>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398961 [details].