In contrast to English, many languages use compound words, resulting in sometimes very long words. Tux Paint tries to fit each word on one line, but for long words, the font becomes very narrow and the words difficult to read. To fix this, I propose two changes to the line-breaking algorithm:
Details:
Treat hyphens are line-breaking opportunities
See the screenshot, which shows the magic tool buttons with the Norwegian Nynorsk (‘nn’) translations of ‘Real Rainbow’ (left) and ‘ROYGBIV Rainbow’ (right). The translation of ‘ROYGBIV Rainbow’ is ‘ROGGBIF-regnboge’, but since Tux Paint only considers spaces, not hyphens, as line-breaking opportunities, it tries to fit the entire word on one line, and the word becomes difficult to read.
To fix this, simply consider hyphens (hyphen-minus characters, U+002D) as line-breaking opportunities. The result should then be:
ROGGBIF-
regnboge
(If the entire word could fit on one line (without compressing it very much), don’t break at the hyphen.)
Support soft hyphens
An example of a long word not containing a hyphen is the translation of the word ‘Rainbow Cycle’. In Norwegian Nynorsk, this becomes ‘Regnbogesyklus’, with no opportunity for a line break. But it’s possible to include so-called soft hyphens (U+00AD) characters in the translations, which basically means ‘you can break the word here, and if you do, add a hyphen’.
The Norwegian Nynorsk translation (latest Git version) does include soft hyphens for some words, including ‘Regnbogesyklus’, which becomes ‘Regnboge(soft-hyphen)syklus’. When rendering it, it should be displayed as:
Regnboge-
syklus
(But if it would fit on one line, it should be ‘Regnbogesyklus’.)
Treating hyphens as line-breaking opportunities should hopefully be easy to implement (and is standard in almost all software). Supporting soft hyphens is slightly more complicated, but would be very useful for the non-English translations of Tux Paint.
Thanks Karl! I've made an attempt. At first, I just added wrapping on visible hyphens: https://sourceforge.net/p/tuxpaint/tuxpaint/ci/217e653d3aee6acd27e5d88a3f5b99d380e5b7f4/
Then I updated and reworked it to both support invisible soft hyphens, and allow for more than two lines of wrapping based on this. In the end, I might want to try reworking all of this to just use the SDL2_Pango library to manage this, but hopefully this works sufficiently to improve things.
Please pull from
masterand try it out. Let me know if there are any issues!I’ve tested it, and it seems to work very well. Thank you! But I think the threshold for wrapping should be reduced a bit, perhaps to 1.4 (down from 1.5). For example, the long word ‘Kruse(softhyphen)dullar’ (translation of ‘Squiggles’) doesn’t get wrapped when the threshold is 1.5, and it is quite difficult to read.
Further adjustments made -- I went for 1.3x width as being the limit before it wants to word-wrap, based on testing things with small (32x32 and 48x48, the default), what I use (64x64), and fairly large (auto-sized in a 1280x1024 window) button sizes.
While I was in there I noticed we had a y-nudge for label text, only ever used with Khmer locale, and apparently no longer necessary (since nowadays it actually made the text appear too low), so I was able to remove some cruft while I was at it.
I'm now eyeing
need_right_to_left_word, which I believe can go, but it's a lot more involved, and I think it's owed its own ticket. ;)