plot icon indicating copy to clipboard operation
plot copied to clipboard

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

Open josharian opened this issue 5 years ago • 6 comments

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 avatar Feb 13 '19 21:02 josharian

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

josharian avatar Feb 13 '19 21:02 josharian

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

kortschak avatar Feb 15 '19 07:02 kortschak

ping @josharian ?

sbinet avatar Feb 21 '19 09:02 sbinet

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 avatar Feb 21 '19 17:02 ctessum

@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.)

josharian avatar Feb 21 '19 18:02 josharian

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.

kortschak avatar Feb 21 '19 21:02 kortschak