Skip to content

Commit 8c7dac2

Browse files
committed
Add Unicode word wrapping support in THelpTopic
The effects of this can be seen with a THelpViewer.
1 parent 807cb3d commit 8c7dac2

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,6 @@ Support for creating Unicode-aware views is in place, but some views that are pa
430430

431431
* At least `TFrame`, `THistoryViewer`, `TListViewer` and `TMenuBox` are able to display Unicode text properly.
432432
* `TInputLine` can display and process Unicode text.
433-
* Word wrapping in `TStaticText` is Unicode-aware.
433+
* Word wrapping in `TStaticText` and `THelpViewer` is Unicode-aware.
434434
* Automatic shortcuts in `TMenuBox` won't work with Unicode text, as shortcuts are still compared against `event.keyDown.charScan.charCode`.
435435
* `TEditor` assumes a single-byte encoding both when handling input events and when displaying text. So it won't display UTF-8 but at least it has a consistent behaviour.

source/tvision/helpbase.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ static int scan( char *p, int offset, int size, char c)
404404
}
405405
}
406406

407+
static int widthToPos(const char *text, int offset, int size, int width)
408+
{
409+
return offset + TText::wseek(TStringView(&text[offset], size), width, False);
410+
}
411+
407412
TStringView THelpTopic::wrapText( char *text, int size, int& offset, Boolean wrap )
408413
{
409414
int i;
@@ -412,24 +417,18 @@ TStringView THelpTopic::wrapText( char *text, int size, int& offset, Boolean wra
412417
i = scan(text, offset, size, '\n');
413418
if (i + offset > size )
414419
i = size - offset;
415-
if ((i >= width) && (wrap == True))
420+
if (wrap && strwidth(TStringView(&text[offset], i)) >= width)
416421
{
417-
i = offset + width;
422+
i = widthToPos(text, offset, i, width);
418423
if (i > size)
419424
i = size;
420425
else
421426
{
422427
while((i > offset) && !(isBlank(text[i])))
423428
--i;
424-
/*
425-
if (i == offset)
426-
i = offset + width;
427-
else
428-
++i;
429-
*/
430429
if( i == offset )
431430
{
432-
i = offset + width;
431+
i = widthToPos(text, offset, i - offset, width);
433432
while( (i < size) && !isBlank(text[i]) )
434433
++i;
435434
if( i < size )
@@ -439,7 +438,7 @@ TStringView THelpTopic::wrapText( char *text, int size, int& offset, Boolean wra
439438
++i;
440439
}
441440
if (i == offset)
442-
i = offset + width;
441+
i = widthToPos(text, offset, i - offset, width);
443442
i -= offset;
444443
}
445444
str = TStringView(&text[offset], i);

0 commit comments

Comments
 (0)