BUG:477164 Fix brush preview outlines being aligned based on incorrect bounding box.
The root cause of this bug is that the class KisOptimizedBrushOutline does not keep track of the original 'center' of the brush. It instead uses the center of the non-transparent pixels in the brush.
When a bitmap brush is converted into a KisOptimizedBrushOutline its outline is computed and stored as a list of QPolygonFs. When this brush outline is rendered as a preview, the center of the bounding box around the polygons is anchored to the mouse. For the preview to be drawn in the correct place, we instead should anchor the center of the original brush bitmap to the mouse.
Consider a 128x256 brush with the top half filled in and bottom half empty. The QPolygon krita creates to represent the outline will have top-left and bottom-right corners of (0, 0), and (128, 128). This is indistinguishable from what would be created by a completely filled in 128x128 brush, so we have lost the information about the original size when we convert the brush into an outline polygon.
I feel like I'm struggling to accurately describe how this changes things so some pictures to clarify. The following two picture both use the brush I described above, attached here:
Setting that as my brushtip, I see the following in an unmodified build of the latest master. This shows both the preview and where the stroke actually gets painted. Note that the actual stroke is high because the correct shape gets applied to the canvas, only the preview is wrong. Here the preview square is centered on my mouse.
And with my fix. It is hard to see but I promise there is a preview line is overlapping the black square. Here the bottom edge of the square is centered on my mouse.
In both cases, what ended up on the canvas relative to the position of my mouse is exactly the same, only the position of the preview is different.
I have also verified that the preview stays correctly aligned when using scaling and rotation based on tablet pressure.
Test Plan
In a patched krita:
- Add the brush uploaded above (top image) to the krita brush resource directory
- Choose any brush using the
Pixelengine and set the above image as your brushttip - Observe that no matter how you move the mouse/pen the preview will now always accurately track exactly where the canvas will change.
Formalities Checklist
-
I confirmed this builds. -
I confirmed Krita ran and the relevant functions work. -
I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!) -
I made sure my commits build individually and have good descriptions as per KDE guidelines. -
I made sure my code conforms to the standards set in the HACKING file. -
I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy. -
Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?
Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.


