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

vg/draw: Cropped canvases don't fill text according to the crop #522

Open
josharian opened this issue Feb 13, 2019 · 6 comments
Open

vg/draw: Cropped canvases don't fill text according to the crop #522

josharian opened this issue Feb 13, 2019 · 6 comments

Comments

@josharian
Copy link

josharian commented Feb 13, 2019

What I did:

  • Crop a canvas.
  • Use FillText/FillString to draw a string at (0,0) in the cropped canvas.

Expected:

The string at (0,0) of the cropped canvas.

Got:

The string at (0,0) of the uncropped canvas.

It seems that the FillString method needs to be made aware of any cropping.

@josharian
Copy link
Author

The obvious fix breaks everything else. This may be a documentation issue.

@kortschak
Copy link
Member

Would you post a small reproducer and the image it generates for you, please?

@sbinet
Copy link
Member

sbinet commented Feb 21, 2019

ping @josharian ?

@ctessum
Copy link
Contributor

ctessum commented Feb 21, 2019

I think you have to draw at canvas.Min rather than (0,0). The absolute coordinates are always relative to the parent canvas rather than the cropped one. As mentioned above, documentation could probably be improved.

@josharian
Copy link
Author

@ctessum has it exactly right. If I were redesigning this, I would encourage each canvas to have its own coordinate space, since this makes the mental model easier. But we're not---so this is just a docs issue. (So I'm not going to spend time putting together a reproducer, apologies.)

@kortschak
Copy link
Member

It seems to me there should be a simple way to set an origin offset after cropped draw.Canvas has been returned. There isn't. You can get the min points, so you can do this, c.Translate(c.Min.Scale(-1)), but this then leaves the canvas and its rectangle discordant AFAICS. The embedding of the two types in draw.Canvas has left an overly happy compiler that doesn't give code with the expected semantics.

This at least should be fixed.

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

No branches or pull requests

4 participants