Closed Bug 1636655 Opened 5 years ago Closed 4 years ago

scrollWidth incorrect when font-weight is bold

Categories

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

76 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1226695

People

(Reporter: gsn880, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

Steps to reproduce:

I had a div with
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 100px;
font-weight:bold;

and use scrollWidth to detect if it is overflowing

https://jsfiddle.net/8wudgyfh/1/

Actual results:

scrollWidth returned the incorrect size however with no bold styling it works fine
I suspect scrollWidth is returning the size without the bold styling.

Expected results:

scrollWidth should of returned the size of the content with all styles applied.
it works as expected in chrome and edge

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Layout: Text and Fonts
Product: Firefox → Core

Because this bug's Severity is normal and has not been changed, and this bug's priority is -- (none,) indicating it has has not been previously triaged, the bug's Severity is being updated to -- (default, untriaged.)

Severity: normal → --

Hi gsn880,

I want to clarify the bug a bit. I check your test case, the "Check scrollWidth" returns a bigger value for the bold text. On my Linux system, the first scrollWidth is 127 (bold) and the second scrollWidth is 115 (normal). Do you see the same value for both?

Flags: needinfo?(gsn880)
Priority: -- → P3
Severity: -- → S3
Priority: P3 → --

Reporter's testcase checks overflow like this:

function isOverflowing(element) {
       return (element.scrollWidth > element.offsetWidth);
}

That doesn't work because the returned values are integers:
https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface
https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
so when the underlying internal layout width has a fractional value, say 100.1px, it will be rounded to 100px. text-overflow acts on the actual internal layout sizes though.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Flags: needinfo?(gsn880)
You need to log in before you can comment on or make changes to this bug.