Closed
Bug 182670
Opened 23 years ago
Closed 20 years ago
"Rounding" error in computed style values
Categories
(Core :: Layout, defect, P3)
Tracking
()
RESOLVED
FIXED
Future
People
(Reporter: Erich.Iseli, Assigned: sharparrow1)
References
Details
Attachments
(2 files, 1 obsolete file)
182 bytes,
text/html
|
Details | |
1.21 KB,
patch
|
Details | Diff | Splinter Review |
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.
Comment 1•23 years ago
|
||
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.
Comment 2•23 years ago
|
||
Comment 3•23 years ago
|
||
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.
Comment 4•23 years ago
|
||
Dup or not, I'm using 96dpi, and getting results way off.
Comment 5•23 years ago
|
||
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
Reporter | ||
Comment 6•23 years ago
|
||
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
Reporter | ||
Comment 7•23 years ago
|
||
By the way, the DOM-Inspector issue would be to just round to 1 digit instead of
4. What do you think?
![]() |
||
Comment 9•23 years ago
|
||
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
![]() |
||
Comment 10•23 years ago
|
||
*** Bug 171761 has been marked as a duplicate of this bug. ***
Updated•23 years ago
|
Priority: -- → P3
Target Milestone: --- → Future
Assignee | ||
Comment 11•20 years ago
|
||
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.
Assignee | ||
Comment 12•20 years ago
|
||
This makes percentage font sizes round consistently; the old code was truncating, leading to odd results.
![]() |
||
Updated•20 years ago
|
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+
![]() |
||
Comment 14•20 years ago
|
||
Attachment #206770 -
Attachment is obsolete: true
![]() |
||
Comment 15•20 years ago
|
||
Fixed on trunk. Eli, thanks for fixing this!
Status: ASSIGNED → RESOLVED
Closed: 23 years ago → 20 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•