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

Implement Tiny-Skia example #55

Merged
merged 14 commits into from
May 23, 2024
Merged

Conversation

nicoburns
Copy link
Contributor

@nicoburns nicoburns commented May 21, 2024

This example uses skrifa and tiny-skia rather than swash and image as in #54.

Output

tiny_skia_render

Notes

  • This has the same issue as Implement simple example using swash to render to png #54 around emoji rendering not working / being implemented
  • There is an issue with the centers of closed letter forms incorrectly being filled
  • The code for this is IMO much nicer than the swash version (at the cost of the heavier tiny-skia dependency)
  • This example does not have hinting enabled

@nicoburns nicoburns requested review from dfrg and xorgy May 21, 2024 14:52
Copy link
Contributor

@waywardmonkeys waywardmonkeys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these should have their own Cargo.toml so that these things don't all end up being dev dependencies and polluting stuff. That might be better if this repo were using the multi-crate layout...

@nicoburns
Copy link
Contributor Author

nicoburns commented May 21, 2024

Maybe these should have their own Cargo.toml so that these things don't all end up being dev dependencies and polluting stuff. That might be better if this repo were using the multi-crate layout...

Yeah, that makes sense. I believe you can have example be their own crate and have them still work as examples if you set things up correctly (reference them from the Cargo.toml) (EDIT: maybe not. You can certainly have them in a non-standard location but perhaps not as their own crates. It's probably worth making them their own crates anyway).

@nicoburns nicoburns force-pushed the tiny-skia-example branch from 77fb6be to 49551e7 Compare May 21, 2024 15:29
@xorgy
Copy link
Member

xorgy commented May 21, 2024

Perhaps understandably, I am partial to the example which renders plain text correctly.. but I agree this looks simpler. I also second Bruce's feedback.

@xorgy
Copy link
Member

xorgy commented May 21, 2024

Do you think rendering errors are related to a different default fill rule or something similarly easy to change?

@dfrg
Copy link
Collaborator

dfrg commented May 21, 2024

Do you think rendering errors are related to a different default fill rule or something similarly easy to change?

Yes, the fill rule should be non-zero. Looks like it’s set to even-odd here.

@nicoburns
Copy link
Contributor Author

Do you think rendering errors are related to a different default fill rule or something similarly easy to change?

Yes, the fill rule should be non-zero. Looks like it’s set to even-odd here.

It is EvenOdd. Tiny-Skia has FillRule::EvenOdd and FillRule::Winding (https://docs.rs/tiny-skia/latest/tiny_skia/enum.FillRule.html), but both seem to produce the same result.

@nicoburns nicoburns force-pushed the tiny-skia-example branch from 49551e7 to 67c8ab7 Compare May 21, 2024 22:14
examples/tiny-skia.rs Outdated Show resolved Hide resolved
examples/tiny-skia.rs Outdated Show resolved Hide resolved
@nicoburns nicoburns force-pushed the tiny-skia-example branch from 67c8ab7 to 877ac29 Compare May 21, 2024 22:33
@nicoburns nicoburns force-pushed the tiny-skia-example branch 4 times, most recently from b9a9773 to 439b079 Compare May 22, 2024 11:52
@nicoburns
Copy link
Contributor Author

Don't really understand these CI failures. The example crate compiles fine if specifically targeted with cargo run -p tiny_skia_render or if cargo run is run from it's directory but with cargo test --workspace it fails to find the tiny_skia dependency. Possible cargo bug?

I'm thinking we ought to land this without making it into it's own crate, and we can do the workspace changes in a followup?

@waywardmonkeys
Copy link
Contributor

The reason is that it is getting compiled 2 ways: One via the example and one via parley picking it up as an example.

That won't happen if you put main.rs in a src directory.

@waywardmonkeys
Copy link
Contributor

@nicoburns You'll need to remove a couple of lines from your example's Cargo.toml as well.

@nicoburns nicoburns force-pushed the tiny-skia-example branch 3 times, most recently from 7d77eca to cd9d6a7 Compare May 22, 2024 13:35
@@ -11,7 +11,9 @@ env:
RUST_MIN_VER: "1.70"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p parley -p fontique"
PRIMARY_PKGS: "-p parley -p fontique"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't use PRIMARY_PKGS below, but you do use PUBIC_PKGS ...

Is the purpose of renaming this away from RUST_MIN_VER_PKGS to denote which are published and not?

Copy link
Contributor Author

@nicoburns nicoburns May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're running check/build/test/doc etc over parley and fontique crates with --features std and --features libm, neither of which work with the tiny_skia_render example crate because it doesn't have those features. So we can't use --workspace to run those checks. So I'm using this "primary packages" variable to do specify "parley and fontique".

examples/tiny_skia_render/Cargo.toml Show resolved Hide resolved
examples/tiny_skia_render/src/main.rs Outdated Show resolved Hide resolved
@nicoburns
Copy link
Contributor Author

@dfrg What's the current situation regarding rendering emoji with skrifa?

@dfrg
Copy link
Collaborator

dfrg commented May 22, 2024

@dfrg What's the current situation regarding rendering emoji with skrifa?

Emoji is going to be a heavy lift in this example.

  • I can see the ColorPainter trait which seems to be for COLRv1 (and presumably applies to COLRv0?). Although it doesn't look that easy to implement on top of tiny-skia. I think we'd need to do the transforms and clipping ourselves? And I can't find any example implementation anywhere.

Yes, this covers COLRv1 and v0. The mapping is not difficult but is going to be very tedious. This is implemented in Skia both here: https://github.com/google/skia/blob/907372c4cceee9ab7cf30c8043eba9afd837681e/src/ports/fontations/src/ffi.rs#L148 and here: https://github.com/google/skia/blob/907372c4cceee9ab7cf30c8043eba9afd837681e/src/ports/SkTypeface_fontations.cpp#L1158

Also, tiny-skia is missing some functionality (full two-point conical gradients, sweep gradients and a couple blend modes, I think). We'll probably need to add this functionality ourselves.

Correct. We have low-level support in read-fonts and for Skia, the additional logic was implemented directly there because we never settled on an API for skrifa. Most of that bitmap logic is here: https://github.com/google/skia/blob/907372c4cceee9ab7cf30c8043eba9afd837681e/src/ports/fontations/src/ffi.rs#L1037

edit: I don't think we should block this PR on emoji support

@nicoburns nicoburns force-pushed the tiny-skia-example branch from c2cb2b6 to 09fbc75 Compare May 22, 2024 18:26
@nicoburns
Copy link
Contributor Author

edit: I don't think we should block this PR on emoji support

I am inclined to agree. And given that, I believe this PR may now be ready :)

Copy link
Collaborator

@dfrg dfrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can’t really speak for the CI stuff (which seems fine?) but the code all LGTM. Thanks for taking this on!

src/style/brush.rs Show resolved Hide resolved
Copy link
Member

@xorgy xorgy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good to me now. I love the detailed comments in the actual example code.

@nicoburns nicoburns dismissed waywardmonkeys’s stale review May 23, 2024 13:00

Changes have been addressed. And we have too many PRs in flight. We can fix any outstanding issues in follow up PRs

@nicoburns nicoburns added this pull request to the merge queue May 23, 2024
Merged via the queue into linebender:main with commit 94c5d78 May 23, 2024
19 checks passed
@nicoburns nicoburns deleted the tiny-skia-example branch May 23, 2024 13:03
github-merge-queue bot pushed a commit that referenced this pull request May 23, 2024
With #55 we introduced a package that doesn't have the `std` feature.
The CI was adjusted to cope with that.

This PR here improves support for such packages in key ways:
* Automatically support it using the `--ignore-unknown-features` flag.
* Remove the manual listing of `PRIMARY_PKGS` and `EXAMPLE_PKGS` and
restore usage of `--workspace` so that the CI will automatically pick up
new packages.
* Restores support for "primary packages" that don't need to follow
MSRV.
This was referenced May 23, 2024
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.

4 participants