Open Bug 969917 Opened 11 years ago Updated 3 years ago

Imprecise calculation of element size (height/width) if element uses REM units.

Categories

(Core :: Layout, defect, P5)

26 Branch
x86_64
All
defect

Tracking

()

UNCONFIRMED

People

(Reporter: agamemnus, Unassigned)

References

()

Details

(Whiteboard: DUPEME[bugday-20140212])

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0 (Beta/Release) Build ID: 20140127194636 Steps to reproduce: var display = document.getElementById("display") document.documentElement.style.fontSize = '1.23px' console.log (display.getBoundingClientRect().height) // Correct value should be "123". // Chrome: "123". // Firefox 26: "123.333328247070311". // IE11: "120". document.documentElement.style.fontSize = '1.225px' console.log (display.getBoundingClientRect().height) // Correct value should be "122.5". // Chrome: "122.5". // Firefox 26: "123.333328247070311". // IE11: "120". http://jsfiddle.net/E8RgY/
Severity: normal → major
Version: 27 Branch → 26 Branch
Attached image screenshot.png
By opening http://jsfiddle.net/E8RgY/ I can see the same output with both latest Nightly and Chrome on Win 7 64-bit: please see the attached screenshot. Is this what you're seeing, too?
Yes, but the screenshot doesn't tell the story... it is the console.log.
Same 123.33332824707031 in 2014-02-12-03-02-01-mozilla-central-firefox-30.0a1.en-US.linux-x86_64.
Component: Untriaged → Layout
OS: Windows 7 → All
Product: Firefox → Core
Whiteboard: [bugday-20140212]
CSS lengths in Gecko are stored in fixed-point units: an integer number which should be divided by 60 to get the number of CSS pixels. That means that we can only express lengths to the nearest 0.0166666. 1.23 * 60 == 73.8, so we can't express 1.23 exactly. It gets rounded to 74/60 = 1.2333333 Which is why you see the values that you see. Chrome seems to compute heights to the nearest 1/64px but store font-size as a float, maybe? It's a bit hard to tell exactly what it's doing. In any case, there are existing bugs tracking the limited precision of length units. These are usually not an issue in practice because people don't actually use 1.23px fonts.
Severity: major → normal
Whiteboard: [bugday-20140212] → DUPEME[bugday-20140212]
Priority: -- → P5
I realized I wasn't clear on the connection. It's a problem if you're using REMs to scale websites. Scaling sites with REMs and some Javascript (to adjust body font size based on window width/height) creates very fractional pixel font sizes even though the fonts themselves might not be. Do you have a link for the existing bug reports?
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: