Canvas: stroke width of 1 isn't affected by scaling on Windows
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 9h 45m
- Merged PRs (30d)
- 58
Description
### Describe the bug
While working on #4473, I seem to have come across one corner case where an aspect #2206 still persists.
The reference image for `test_transform_mid_paths` verifies, among other things, that the stroke itself is affected by transformations; the uneven scale applied stretches the horizontal dimension of not only the central shapes themselves, but the lines making them up as well.
That uses a stroke width of 2. A width of 1 should be thinner, but still exhibit the same behavior:
On most platforms this works fine. However on Windows, it produces this:
For some reason, when the stroke width is 1, it stays a consistent width even when it should be distorted.
### How to reproduce the bug
At time of writing, the default stroke width is 2, so you'll need to add `canvas.line_width = 1.0` to `tests/widgets/canvas/test_canvas.py::test_mid_path_transforms` in the testbed to see the above result.
Once #4473 is merged, the default width will be 1, and there'll be a line *setting* it to 2 in that test. Commenting out that line should then exhibit the behavior.
### Minimum example code
```shell
import toga
class CanvasApp(toga.App):
def startup(self):
canvas = toga.Canvas(width=200, height=200, background_color="white")
canvas.line_width = 1.0
canvas.scale(10, 1) # Make things ten times as wide as tall.
with canvas.stroke():
canvas.move_to(0, 100)
canvas.line_to(20, 100)
canvas.move_to(10, 0)
canvas.line_to(10, 200)
self.main_window = toga.MainWindow(content=toga.Box(children=[canvas]))
self.main_window.show()
CanvasApp("Line width demo", "org.example").main_loop()
```
### Screenshots
The example code above should generate this:
On Windows, it generates this instead:
### Environment details
- Operating system and version: Windows 11 (ARM)
- Toga: development branch
### Logs
### Additional context
_No response_
Contributor guide
Research direction
Start with tests/widgets/canvas/test_canvas.py::test_mid_path_transforms and reproduce the issue on Windows using canvas.line_width = 1.0 and the supplied scaling example. Trace the Windows canvas rendering path involved in transformed strokes. Done means a width-1 stroke is distorted by the scale on Windows as it is on other platforms, with regression coverage for the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics, desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100