plot
plot copied to clipboard
vg/draw: Cropped canvases don't fill text according to the crop
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.
The obvious fix breaks everything else. This may be a documentation issue.
Would you post a small reproducer and the image it generates for you, please?
ping @josharian ?
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.
@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.)
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.