Incomplete words read from file
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Nov 18 00:57:04 UTC 2021
On Thu, Nov 18, 2021 at 12:39:12AM +0000, jfondren via Digitalmars-d-learn wrote:
[...]
> If what you're wanting to do is to *reshape* text so that it prints
> with proper word-breaks across lines according to the current size of
> the terminal, then you've got to do this work yourself.
[...]
Just to chip in: line-breaking in Unicode is, in general, non-trivial,
because it changes depending on language, left-to-right / right-to-left
settings, font properties, and display environment. If this is what you
want to do, the `linebreak` dub package may be a good starting point (it
implements the Unicode line-breaking algorithm in Annex 14):
https://code.dlang.org/packages/linebreak/1.1.2
Note that this algorithm only gives you linebreak opportunities; you
still have to figure out yourself where among these opportunities to
actually insert a linebreak. For this you will need to measure how long
each text segment is. In general, this also depends on your font, font
size, and font properties. If you're outputting to the terminal, this
is somewhat simpler (most graphemes are 1 column wide) but you still
have to take into account double-width and zero-width characters (and
also how your terminal actually displays such characters -- not all
terminals will display double-width characters as double width, though
most will).
T
--
MAS = Mana Ada Sistem?
More information about the Digitalmars-d-learn
mailing list