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

Able to access the history of the draw commands in Canvas #148631

Closed
mimbrown opened this issue May 19, 2024 · 5 comments
Closed

Able to access the history of the draw commands in Canvas #148631

mimbrown opened this issue May 19, 2024 · 5 comments
Labels
c: new feature Nothing broken; request for a new capability engine flutter/engine repository. See also e: labels. r: invalid Issue is closed as not valid team-engine Owned by Engine team

Comments

@mimbrown
Copy link

Use case

I would like to write a custom class which implements Canvas so that I can experiment with writing a Widget -> SVG converter. But the Flutter classes don't seem to give me the necessary information I would have expected to have in order to do this. For example, when implementing drawPath, the passed Path does not seem to support actually accessing the history of the commands (lineTo, moveTo, etc) used to define the path. Similarly the Paragraph passed to drawParagraph doesn't expose the actual text itself (that I can tell), which I would need.

Proposal

I see in the source that the Path and Paragraph classes are wrappers around native implementations. Could these and other dart:ui types expose, in the wrapper and its implementations, the information necessary to actually do something meaningful in pure Dart? My use case is generating SVG I'm sure there are others.

For example, something like getSegments() on the Path class that outputs an array of the commands given to define the path would enable what I'm trying to do. I don't know all that would be required in which classes, so I don't know how big of an ask this is. But the main ask is, please expose what is necessary for custom implementations to do meaningful things.

@huycozy huycozy added the in triage Presently being triaged by the triage team label May 20, 2024
@huycozy
Copy link
Member

huycozy commented May 20, 2024

the passed Path does not seem to support actually accessing the history of the commands (lineTo, moveTo, etc) used to define the path.

Similarly the Paragraph passed to drawParagraph doesn't expose the actual text itself (that I can tell), which I would need.

Could you please be more specific by giving an example of these expectations?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@mimbrown
Copy link
Author

mimbrown commented May 20, 2024

@huycozy sure. For example, a Widget's painter might do something like this:

final path = Path();
path.moveTo(0, 0);
path.lineTo(5, 5);
canvas.drawPath(path, paint);

In my custom Canvas implementation, I need to know what commands were called (in this case, a moveTo followed by a lineTo). So I implement drawPath:

class MyCanvas implements Canvas {
  @override
  void drawPath(Path path, Paint paint) {
    // `path` was called with `moveTo(0, 0)` and `lineTo(5, 5)`, but I can't extract that information

    // I would like to do something like this (`getCommands` doesn't exist)
    for (final command in path.getCommands()) {
      // do something with command
      switch (command) {
        case MoveTo(:x, :y): {
          // build svg
        }
      }
    }
  }
}

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@huycozy
Copy link
Member

huycozy commented May 21, 2024

Thanks for clarifying it. Marking this as a feature request.

@huycozy huycozy added c: new feature Nothing broken; request for a new capability engine flutter/engine repository. See also e: labels. team-engine Owned by Engine team and removed in triage Presently being triaged by the triage team labels May 21, 2024
@huycozy huycozy changed the title Enable custom canvas use cases like Widget -> SVG Able to access the history of the draw commands in Canvas May 21, 2024
@mimbrown
Copy link
Author

@huycozy that's just one example of what I feel is missing. Another would be accessing the sets of styled "runs" of text from the Paragraph class passed to drawParagraph.

The basic problem statement is, the classes passed to the various draw* commands in the Canvas class don't seem like they were designed to be useful outside of their native implementations. There's no particular reason for this that I can think of except that it just hasn't been done yet.

@jonahwilliams
Copy link
Member

We're not going to add the functionality to introspect over all canvas operations. I would suggest writing shim classes that intercept the path/canvas ops you care about and then implementing your own recorder in Dart.

@huycozy huycozy added the r: invalid Issue is closed as not valid label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability engine flutter/engine repository. See also e: labels. r: invalid Issue is closed as not valid team-engine Owned by Engine team
Projects
None yet
Development

No branches or pull requests

3 participants