-
-
Notifications
You must be signed in to change notification settings - Fork 258
Enable processing pixel lengths as float #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This is very impressive work!
I think the
You are right, this is the only painless way. As for API break - the library is in beta status. API is changed frequently. The latest master is not compatible with the latest numerical version because of new features and removing legacy. It is OK.
It is interesting, how many tests will fail after switching to the floats? |
Cool, should I still keep the
Oh, alright, I didn't realize that.
Yeah, so there are 242 failures right now. |
You are right, using
It is good result 😀 I've expected more failed tests. Anyway the |
@DRKV333, please let me know when you finish with this PR. Don't worry about failed tests, I'll update them by myself. |
So, in a lot of test failures, the difference from the expected image is basically imperceptible. Some of these happen because of lines of text being shifted down slightly, due to less rounding error in line height calculations. Any test that has list markers is also falling. Makers appear a bit smaller now. This is because their size is a third of the line height, which is usually a fraction. The exact size of the marker doesn't really matter anyway, so this should be fine. Here's a summary of test failures worth looking at:
These are actually failing, in that the output contains "red pixels". This happens because of weirdness in fractional pixel rendering. e.g. in After going trough the spec it looks like this behavior is not correct, and at least borders have to be rounded in a particular way. (https://www.w3.org/TR/css-values-4/#lengths) So I'll still need to fix this. This doesn't apply to heights though, so that test will be even more wrong. In this case implementations get to decide what to do, so I guess just not rounding and letting the container deal with the fractions is still correct. Though in practice browsers do seem to round things to whole pixels, but the exact behavior varies.
See #416, this is failing, thought not directly because of this PR.
These tests use the "Ahem" font. They now have noticeable spaces between characters that weren't there before. I think this is actually correct, it looks similar in other browsers.
This test says that the size for scalable fonts should be rounded to the nearest whole pixel. I did not find this in the standard though. All that says is that fonts are typically rounded to the nearest whole pixel. (https://www.w3.org/TR/css-fonts-4/#font-style-matching, point 4.4) That is true, that's how other browsers do it, but not rounding should be fine as well. |
Ok, I think I'm ready. I've ended up adding some rounding, right before draw operations. This is the way others do it, and it does fix a lot of issues with things being blurry. It also resolves the "red pixel visible" test failures, and reduces the number of failed tests to 375, from the 472 it was before. |
Hey, this is still very much WIP, but I would like to get some feedback on it.
I've started work on converting the whole library to use
float
rather thanint
when calculating the length of things in pixels, to avoid compounding rounding errors. This is something users have requested a few times by now. The general plan was:pixel_t
typedef intypes.h
to represent pixel sizes, just pointing toint
initiallyint
everywhere, and if it represents a size in pixels, replace it withpixel_t
pixel_t
point tofloat
insteadAt this point I have looked through the code and replaced everything. I've also tested it with
float
and it does compile, but there are a few things to fix still.I do have a few questions though on how to proceed:
Are you sure you would want to support both
int
andfloat
pixel types?It seems like this would be quite annoying. Both variants would have to be tested, or if one isn't tested it might break. I'm not sure what the benefit of
int
would be (other than backward compatibility maybe). A page would have to be several million pixels large before precision becomes a problem. The performance seems about the same from what I've measured.How should the API be handled?
I think it would make the most sense to keep the pixels as
float
all the way until the document container, and then that can decide what to do with them. But then this would be a breaking change. From what I can tell the API surface is basically most things in the include folder, and a lot of that has changed. In theory it might be possible to keep having the API useint
by duplicating a bunch of structures, but that would be very painful.Right now, with
pixel_t
being an alias forint
, there is no breakage, so keeping that the default and adding a switch could solve this problem.Also there are some structures whose name doesn't make sense now, like
typed_int
andint_int_cache
. These also always store pixel sizes so they now usepixel_t
. But they are part of the API surface so renaming them would be breaking.I've also replaced font size and media query related pixel values with
pixel_t
for consistency, though I'm not sure how necessary that is really.As a demonstration consider an example similar to #14:
HTML
int
:float
:The right edge of the red box should line up with the right edge of the green box, but with
int
there is a noticeable gap. Usingfloat
fixes this.Closes #47
Closes #14