Unusable selection from path from text
Environment/Versions
- GIMP version: 2.10.24 (actually there since 2.4...)
- Package: Self compiled
- Operating System: Linux
Description of the bug
When you create text with a handwriting font (Google Pacifico for instance)(or if you reduce spacing with usual fonts), the characters overlap, so if you do Layer > Text to path
you get a path where strokes overlap:
If you create a selection from the path, the overlapping areas are not selected:
As far as I know this is because the selection algorithm uses the even-odd rule. From a point, if a line extending to infinity has an odd number of intersections with the path, then the point is in the selection, otherwise, it is not.
I have written a Python script (attached) to achieve the expected selection with text paths. The algorithm is quite simple:
- Put the path strokes in a tree where a parent stroke fully encloses all its children strokes. This means being able to figure out if a stroke is inside another (using the even-odd rule...). In practice the algorithm first check the bounding box of both strokes and if there is no overlap it doesn't check futher.
- The top level of the tree is the strokes that have no enclosing strokes and correspond
usually to the overall shape of characters. For instance:
- A "8" is one parent for the outline that contains the two strokes for the holes
- The zero with a dot inside used in some fonts contains
- a grand-parent for the outline
- a child for the inner border
- a grand-child for the outline of the central dot
- The nesting of the strokes determines if they are outlines (what they enclose is added
to the selection) or holes (what they enclose is subtracted from the selection).
- Top-level strokes are assumed to be outlines
- Other levels are alternately holes and outlines
- The tree is then traversed recursively and each stroke is added/subtracted from the selection based on the parity of its level. This assumes that no "hole" in a character overlaps a "fill" in another. In practice I have never seen such a case, and if necessary the selection can be obtained by adding all the first-level strokes, then subtracting all the second level ones, then adding all the third-level ones, etc...
I'm not saying that the current behavior is bad in all cases. It doesn't work with text, but there are cases where it is useful, so of this is fixed this shouldbe by adding a different way to compute the selection, not by replacing the current behavior.
Reproduction
Is the bug reproducible? Always
Reproduction steps:
- Create text with overlapping characters
Layer > Text to path
Select > From path
- Bucket-fill selection
Expected result:
The filled selection looks exactly like the original text layer
Actual result:
The filled selection has gaps where characters overlap