espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.75k stars 739 forks source link

Fix `drawString` and `setClipRect` with 90/270-degree rotation #2343

Closed dzhu closed 1 year ago

dzhu commented 1 year ago

Previously, the calculation of minX, minY, maxX, and maxY inside jswrap_graphics_drawString was what graphicsToDeviceCoordinates does, just written out explicitly. With 90- or 270-degree rotations, that meant that the final values ended up rotated 180 degrees relative to what they should have been. As a result, characters could end up effectively clipped twice and hence incorrectly not being drawn. What we actually want instead is to do the reverse transformation of graphicsToDeviceCoordinates, which fortunately already exists as deviceToGraphicsCoordinates.

The PR includes a test that would fail before and is fixed by this change.

gfwilliams commented 1 year ago

Thanks - this looks great! I was sure there was a reason it was done that way, but I can't remember now - maybe it's just that deviceToGraphicsCoordinates didn't exist at the time or I'd forgotten about it...