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

Gradient Part 1a - Color fixes #2262

Merged
merged 10 commits into from
Sep 29, 2023
Merged

Gradient Part 1a - Color fixes #2262

merged 10 commits into from
Sep 29, 2023

Conversation

Dherse
Copy link
Sponsor Collaborator

@Dherse Dherse commented Sep 29, 2023

Tracking issue: #2282

Follow up to #2171:

  • Fixes images not using ICC profiles when the ICC profile is not contained within the image
  • Small cleanup in raw.rs
  • Added equality between luma and rgb colors: if an rgb color is just a luma color in disguise, it will compare them as if they were luma colors Convert to syntect colors early avoiding color eq issues in syntect, fixes issue when comparing colors in the internals, it happened in raw.rs, it likely occurs in some other places. Happens to fix Regression in #show raw: set text() #2259
  • Removed Alternate color spaces of the ICC profiled colors, the default is DeviceRGB and DeviceGray, this fixes the Wrong colours in PDF export in some viewers #2257 and incorrect generated colour different to one specified #1927. Note that for Wrong colours in PDF export in some viewers #2257 it does not fix issues with readers that have poor support for ICC profiles, that's on poppler for not falling back to an appropriate color space on its own 🤷‍♂️ Mind you, falling back to DeviceRGB does fix rendering in poppler, still they have a bug that needs fixing!
  • Added regression tests for the aforementioned bug

This small PR corrects some (albeit small) mistakes, which should fix color inaccuracies that could happen. Due to relying on DeviceRGB and DeviceGray, any further color inaccuracies are solely an issue with the reader as typst is following best practices and what other PDF writers produce. It also fixes a bug that cropped up due to "naive" color comparisons. I decided to modify the PartialEq implementation instead of anything else for the sake of guaranteeing that no other bugs like this occur again. Early conversion of colors in syntect colors for raw-related stuff fixes the issue, note that it might appear somewhere else in the code, but as of know, it seems correct everywhere else. Another fix would be to revert some of the presets (i.e Color::BLACK etc.) back to RGB colors, but this would come with a filesize cost and would actually not really resolve the issue.

@l1mey112
Copy link

Amazing!

@laurmaedje
Copy link
Member

@Dherse I think arguable the bug is really in the raw code, not in the color code. There is no need for it to operate with Typst colors. It should just have let foreground as a synt::Color:

let foreground = theme.settings.foreground.unwrap_or(synt::Color::BLACK);

Then, styled can also take foreground: synt::Color and the comparison is just style.foreground != foreground. Only within the if, we need to convert to Typst colors to set the text fill.

We can decide independently of that whether luma and rgb should compare equivalently. I'm not sure about that.

@Dherse
Copy link
Sponsor Collaborator Author

Dherse commented Sep 29, 2023

We can decide independently of that whether luma and rgb should compare equivalently. I'm not sure about that.

I'll change it to that and disable the luma == rgb comp

@laurmaedje laurmaedje merged commit 62f37ad into typst:main Sep 29, 2023
3 checks passed
@laurmaedje
Copy link
Member

Thank you for the fixes!

@Dherse Dherse deleted the colors-image branch September 29, 2023 13:05
@Dherse Dherse changed the title Color fixes Gradient Part 1a - Color fixes Oct 1, 2023
@Dherse
Copy link
Sponsor Collaborator Author

Dherse commented Oct 1, 2023

It has been confirmed on Discord that this has mostly fixed color inaccuracy issues.

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.

Regression in #show raw: set text()
3 participants