Closed Bug 182670 Opened 23 years ago Closed 20 years ago

"Rounding" error in computed style values

Categories

(Core :: Layout, defect, P3)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
Future

People

(Reporter: Erich.Iseli, Assigned: sharparrow1)

References

Details

Attachments

(2 files, 1 obsolete file)

I've got the default font-size of 16px (edit>preferences>appearance>fonts), and an author stylesheet setting an element to 90%. Normally, the computed value should be 16px*90% (mathematically that would be 16*0.9) which yelds 14.4px. However, the DOM-Inspector yelds 14.3529. On IRC, I've been told this is because of a rounding error, however I don't see where there is a rounding to be done. How does Mozilla calculate this value anyways? And a suggestion: since there are rounding errors as we see here, wouldn't it be more useful to round the result to one digit after the comma? Having 4 digits, of which all 4 are wrong is really not useful, if you come to use the DOM-Inspector.
This is very odd, I'm getting 14.3333px on Windows 2000, using Mozilla 20021128. I'm just going to attach a simple test case.
This is so not an inspector problem. As you noted, inspector just uses getComputedStyle() to obtain its info. This is so not a getComputedStyle() problem. It only gets the values from layout. This is a layout problem caused partially because we do not store lengths in pixels. We store them in twips, which varies depending on your resolution. Use a standard resolution like 96dpi and you will get better results. This is a dupe of bug 177805 and/or bug 63336 and various dependencies on the two.
Dup or not, I'm using 96dpi, and getting results way off.
Component: DOM Inspector → DOM Style
Depends on: pixels
Okay. I thought 96dpi was more reliable but that appears to not be the case. Anywya, it's because of the other bugs I mentioned. This is not an inspector problem or DOM problem at all.
Assignee: caillon → nobody
Ok, dup of bug 63336. I'll post my comment #0 there. *** This bug has been marked as a duplicate of 63336 ***
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
By the way, the DOM-Inspector issue would be to just round to 1 digit instead of 4. What do you think?
Un-duping as requested in bug 63336
Status: RESOLVED → REOPENED
Depends on: 63336
Resolution: DUPLICATE → ---
At 96 dpi, there are 15 twips per pixel. So 0.4px == 4/10 * 15 == 6twips. Thus we should really not be rounding off 0.4px to anything at 96dpi... if we do, I find that _very_ odd. In any case, this is hardly DOM style.
Assignee: nobody → other
Status: REOPENED → NEW
Component: DOM Style → Layout
QA Contact: timeless → ian
*** Bug 171761 has been marked as a duplicate of this bug. ***
Priority: -- → P3
Target Milestone: --- → Future
The issue's at http://lxr.mozilla.org/seamonkey/source/layout/style/nsRuleNode.cpp#1910. I think it should be rounding instead of truncating, although I'm not 100% sure. I'd make a patch, but it would be inconvenient because of other changes in my tree.
Attached patch Patch (obsolete) — Splinter Review
This makes percentage font sizes round consistently; the old code was truncating, leading to odd results.
Assignee: layout → sharparrow1
Status: NEW → ASSIGNED
Attachment #206770 - Flags: review?(bzbarsky)
Attachment #206770 - Flags: superreview?(dbaron)
Attachment #206770 - Flags: review?(bzbarsky)
Attachment #206770 - Flags: review+
Comment on attachment 206770 [details] [diff] [review] Patch >- aFont->mSize = (nscoord)((float)(aParentFont->mSize) * aFontData.mSize.GetPercentValue()); >+ aFont->mSize = NSToCoordRound(aParentFont->mSize * >+ aFontData.mSize.GetPercentValue()); sr=dbaron if you restore the explicit cast to float, preferably with a construction-style cast, i.e., NSToCoordRound(float(aParentFont->mSize) * aFontData.mSize.GetPercentValue())
Attachment #206770 - Flags: superreview?(dbaron) → superreview+
Attachment #206770 - Attachment is obsolete: true
Fixed on trunk. Eli, thanks for fixing this!
Status: ASSIGNED → RESOLVED
Closed: 23 years ago20 years ago
Resolution: --- → FIXED
Depends on: 384223
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: