Skip to content
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

feat: rgb() and rgba() support floating point numbers #14

Merged
merged 1 commit into from
Jul 14, 2023

Conversation

yisibl
Copy link
Contributor

@yisibl yisibl commented Jul 14, 2023

This PR will bring the rendering of rgb() and rgba() in resvg in line with modern browsers and specifications.

Previously, rgb(0, 127.8, 0) would be rendered as the black color of a fallback

The CSS Color L4 specification says:

contrary to CSS Color 3, the parameters of the rgb() function are of type <number>, not <integer>. Thus, any higher precision than eight bits is indicated with a fractional part.
https://drafts.csswg.org/css-color-4/#ex-hwb-serial

Closes: linebender/resvg#645

@RazrFalcon
Copy link
Collaborator

I guess it's fine as a temporary solution, but in the future we would probably have to store colors as f32.

@RazrFalcon RazrFalcon merged commit 8b44f98 into linebender:master Jul 14, 2023
@yisibl yisibl deleted the suppor-rgb-float branch July 14, 2023 13:23
@yisibl
Copy link
Contributor Author

yisibl commented Jul 14, 2023

I guess it's fine as a temporary solution, but in the future we would probably have to store colors as f32.

Yes, I see a similar change in Chrome: https://chromium-review.googlesource.com/c/chromium/src/+/4598329

@yisibl
Copy link
Contributor Author

yisibl commented Sep 18, 2023

Have you considered using the latest release of cssparser-color crate?
servo/rust-cssparser#363

@RazrFalcon
Copy link
Collaborator

It seems like cssparser-color still depends on cssparser and this is a very heavy dependency. No plans on using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rgba fill with non-round numbers results in black background
2 participants