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

Support click and drag for svgs, as well as scene fragment caching #244

Merged
merged 4 commits into from
Jan 13, 2023

Conversation

DJMcNab
Copy link
Member

@DJMcNab DJMcNab commented Jan 11, 2023

Reopen of #236 after it was accidentally closed by GitHub UX.

The new svg example, in with_winit, now caches the SceneFragment, and allows dragging and scaling the svg (click and drag, and mouse wheel).

The scaling is centred on the top left, which isn't ideal, but it works for demonstration. Doing the correct maths centered on the cursor should be reasonably easy, but it takes some thinking

I also added support for closing the window with Escape, whilst I was editing it.

There are two new CLI flags implemented, scene and svg.

I have also increased a buffer size to be sufficient for paris-30k (as rendered partially incorrectly currently), until we get #175.

Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Confirm this works, and the code looks good. Minor nits in comments.

One thing to mention: because pico_svg currently drops path elements with no fill specified, it's not a full exercise of the paris-30k test. I've locally patched it to just add a default color, but the real solution is to parse attributes in g tags and pass them down so they're inherited.

use super::pico_svg::*;
let start = Instant::now();
eprintln!("Starting to parse svg");
let svg = PicoSvg::load(svg, 6.0).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be a command line argument (it should be -1.5 for paris), but a more principled approach is to parse transforms in <g> elements.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made it a command line flag for now. Properly parsing svg is quite a task.

Some of the work in https://github.com/google/forma/blob/main/demo/src/demos/svg.rs might be useful to us, although forma is Apache only - no MIT option; so we need to be careful that we use it correctly if we do.

@DJMcNab DJMcNab merged commit eec111c into linebender:main Jan 13, 2023
@DJMcNab DJMcNab deleted the cache_click_drag branch January 13, 2023 19:30
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.

2 participants