beeware / beeware/toga

Canvas: stroke width of 1 isn't affected by scaling on Windows

Open
#4,474 4 comments 0 reactions 0 assignees View on GitHub
bug 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.

Reference image for transform_mid_paths

That uses a stroke width of 2. A width of 1 should be thinner, but still exhibit the same behavior:

Reference image when stroke width is 1

On most platforms this works fine. However on Windows, it produces this:

Output on Windows

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:

Intended output

On Windows, it generates this instead:

Actual output on Windows

### Environment details

- Operating system and version: Windows 11 (ARM)
- Toga: development branch

### Logs

### Additional context

_No response_

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.