Open Bug 1399256 Opened 7 years ago Updated 2 years ago

Selection or background of text may overpaint parts of glyphs from adjacent line [was: Bounding rect is miscomputed for selected text]

Categories

(Core :: Layout: Text and Fonts, defect, P4)

defect

Tracking

()

Tracking Status
firefox57 --- fix-optional

People

(Reporter: Gankra, Unassigned)

Details

Attachments

(2 files, 1 obsolete file)

It appears the bounding rect becomes the selection rect, but this is incorrect when things like shadows are introduced, which can protrude from the selection.

The result is shadows become badly clipped.
Attached file ShadowsUnselected.png (obsolete) —
Attached image ShadowsSelected.png
Attached image ShadowsUnselected.png
Attachment #8907291 - Attachment is obsolete: true
Images are of

<p style="text-shadow: 4px 4px 1px black; color: rgba(0,0,0,0.1) !important;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
</p>
Investigating more, this appears to be an unavoidable consequence of how we draw text. The bad "clipping" is in fact the selection from the previous line drawing on top of the text. In chrome/safari this ends up looking a bit better because the selection boxes are partially transparent.

Possibly wontfix?
I think so, unless we were to move to a model where all the selection highlighting (for all the lines) is painted before any of the actual text (and its shadows) -- but that would probably have its own problems.

Note that the issue only occurs because the lines are so crowded (vertically); increasing the line-height so as to provide a reasonable amount of space for the shadows (e.g. line-height:1.5) would mitigate the issue.

The same "problem" will occur even without text-shadow any time lines are too crowded for the vertical extent of their contents:

data:text/html,<p style="font:24px/0.8 serif">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

Painting the selection with partial opacity may be worth considering, though. ISTR looking into this a bit some years ago, but don't have a bug reference to hand.
FWIW, the same issue applies to background painting of inline elements when the lines are crowded like this; it's not specific to selection highlighting:

data:text/html,<p style="font:24px/0.8 serif">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <span style="background:yellow">Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

Where the text has a yellow background, this will overpaint descenders from the preceding line.
I actually first noticed this because of inline elements which cause a new TextFrame (e.g. links). Selecting the line visibly "clips" the shadows on the boundary between the two parts of the text. But it might be fine with "normal" shadows (I had exaggerated shadows because I was testing shadow rendering).
It's possible this could be fixed or at least mitigated sometime but that would be as a side-effect of other changes (in how we paint, or in how we highlight selections, or something...); I don't think there's any prospect of an immediate fix for this in isolation.
Summary: Bounding rect is miscomputed for selected text → Selection or background of text may overpaint parts of glyphs from adjacent line [was: Bounding rect is miscomputed for selected text]
Priority: -- → P4
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: