pharo-project / pharo

Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk.
http://pharo.org
Other
1.21k stars 355 forks source link

FormCanvas draws transparent rectangle border incorrectly #14523

Open Rinzwind opened 1 year ago

Rinzwind commented 1 year ago

In the FormCanvas drawing snippet given below, the blue rectangle border is made more translucent at each iteration:

I would expect the ‘form’ in each iteration to have only one red pixel, but the last one unexpectedly has three more red pixels. Note that replacing drawRectangle: rectangle by drawPolygon: rectangle corners gives a similar unexpected result at the last iteration.

(1 to: 5) collect: [ :i |
    | rectangle form scaledForm |
    rectangle := 1@1 corner: 3@3.
    (form := Form extent: 5@5 depth: Display depth)
        fillColor: Color white.
    (0@0 corner: 1@1) corners do: [ :extension |
        (rectangle expandBy: extension) corners do: [ :point |
            form colorAt: point put: Color green ] ].
    form getCanvas drawRectangle: rectangle color: Color red
        borderWidth: 1 borderColor: (Color blue alpha: 0.25 * (5 - i)).
    PNGReadWriter putForm: (scaledForm := form scaledToSize: form extent * 10)
        onFileNamed: FileLocator imageDirectory / (i asString , '.png').
    scaledForm ]

Tested using: Pharo 12 build 686, with VM v10.0.6 (Commit: b67609b9 - Date: 2023-08-16 18:51:13 +0200)

Rinzwind commented 1 year ago

I seem to have missed that #drawRectangle:color:borderWidth:borderColor: is in a ‘private’ protocol. The only two senders use 0 as the border width. But #drawPolygon:color:borderWidth:borderColor: is not in a ‘private’ protocol and is, as noted above, also affected by this issue.