Skip to content

Improve: add autowrap and support for Chinese/other language word wrapping#6207

Merged
vadi2 merged 55 commits intoMudlet:developmentfrom
hhsiao:Text-Wrapping
Sep 1, 2022
Merged

Improve: add autowrap and support for Chinese/other language word wrapping#6207
vadi2 merged 55 commits intoMudlet:developmentfrom
hhsiao:Text-Wrapping

Conversation

@hhsiao
Copy link
Copy Markdown
Contributor

@hhsiao hhsiao commented Aug 2, 2022

Modify text wrapping to use actual text width as calculated by "horizontalAdvance", this allows the wrapping to work for a language where character width is not the same across available characters.

Brief overview of PR changes/additions

Text wrapping now uses QFontMetrics(font).horizontalAdvance to determine where the wrap should happen.

Motivation for adding to Mudlet

Text wrapping was assuming all characters are equal width, thus it completely breaks if that isn't the case.

Other info (issues closed, discussion etc)

closes #5564

Modify text wrapping to use actual text width as calculated by "horizontalAdvance", this allows the wrapping to work for a language where character width is not the same across available characters.
@hhsiao hhsiao requested a review from a team as a code owner August 2, 2022 17:34
@hhsiao hhsiao requested a review from a team August 2, 2022 17:34
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Aug 2, 2022

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@mudlet-machine-account mudlet-machine-account added this to the 4.17.0 milestone Aug 2, 2022
@hhsiao hhsiao changed the title [Improvement] Update TBuffer.cpp Improve: Text Wrapping to support multibyte / language with variable character width Aug 2, 2022
@hhsiao
Copy link
Copy Markdown
Contributor Author

hhsiao commented Aug 2, 2022

sample

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this needs a rework... 🙁

hhsiao and others added 14 commits August 3, 2022 11:34
TBuffer now uses the more efficient at(i) instead of operator=[i]
Wrapping position calculation now uses QTextBoundaryFinder::word to find boundary
Auto wrapping for wrap setting below 10, and should properly autowrap all mini console.
Took what I did with TBuffer::wrap and implemented for TBuffer::append
Fix CodeFactor issues
wrapLine is a special version of wrap, basically wrap that only wrap one line.
Code in wrap is now refactored into wrapLine.
Also removed two of the debug message, since those were used only for me to figure out what was going on.
Missed a line when I did the refactoring, pSpace should be format that's passed in
Removed unused variables
Added space around =
Wrapping now accounts for LineFeed, instead of pushing it in, it actually does a new line (which is what line feed is supposed to do)

wrapLine now properly does the single line mode, and uses remove -> insert , as oppose to "pop_back" "push_back".

Change different place where wrapLine was being called with incorrect width.
Added comment explaining what wrapLine does
Change the QTextBoundaryFinder mode from Word to Line
src/TBuffer.cpp Outdated
@@ -2500,41 +2633,52 @@ inline int TBuffer::wrap(int startLine)
bool hasContent = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Well spotted - I suspect this is why previously, wrapped text (when there was a non-zero indent) was being preceded by black spaces instead of those in the correct background colour... 😀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually everywhere that pass in "format" is actually just passing in a generic pSpace, so this wouldn't fix that. Now I am interested in fixing that problem, but I believe it isn't related to this PR, so as such I would do a separate PR for that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I may not be grasping the problem discussed here, but is it really an issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what the code "should do", is figure out what the format of the indent "should be". Now that's what I would need to find out, which is what is a generic space supposed to look like?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually everywhere that pass in "format" is actually just passing in a generic pSpace, so this wouldn't fix that. Now I am interested in fixing that problem,...

I am not sure that is the case - this method TBuffer::wrapLine(...) is used in more than just TConsole::luaWrapLine(int) and in those other cases (TConsole::printCommand(...), TConsole::insertText(...), TConsole::insertLink(...)) a format is supplied...

<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ When you save the form/dialogue from the stand-alone Qt Designer utility or the version integrated into the Qt Creator IDE it remembers the current tab you are on - you need to always switch back to the first tab (or avoid this change getting into the end PR) to prevent this (change of the "currentIndex" away from 0) from appearing...

As it happens I have put code into the dlgProfilePrefences constructor to prevent this from having any effect (it forces the current tab to the first one automatically) - but basically this change is not wanted... 😀

</item>
<item>
<widget class="QLabel" name="label_23">
<widget class="QLabel" name="label_wrapCharacters">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for giving a meaningful name to the label for the control - too many of them have been left at the default of label_ and a number...! 😀

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 6, 2022

Warnings
⚠️ PR makes changes to 11 source files. Double check the scope hasn't gotten out of hand

Generated by 🚫 dangerJS against 6faecdb

vadi2 and others added 3 commits August 6, 2022 09:36
Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
Change instance where we are doing size() == 0, to do isEmpty() instead.
@hhsiao
Copy link
Copy Markdown
Contributor Author

hhsiao commented Aug 19, 2022

Done with optimization for this PR, ready for review

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Aug 19, 2022

Awesome, reviewing it.

I'll also enable the clang-tidy review bot, it might have some suggestions. You've done so much work on this already, so I can apply those for you in case your battery is running low =)

@hhsiao
Copy link
Copy Markdown
Contributor Author

hhsiao commented Aug 27, 2022

I've incorporated your recommendation (PR), and also addressed your questions.
Variable also renamed to be more descriptive.

@vadi2 vadi2 changed the title Improve: Text Wrapping to support multibyte / language with variable character width Improve: add autowrap and support for Chinese/other language word wrapping Aug 27, 2022
@vadi2 vadi2 enabled auto-merge (squash) August 27, 2022 04:46
@vadi2 vadi2 disabled auto-merge August 27, 2022 04:46
hhsiao added 4 commits August 27, 2022 00:25
Added suggested changes to the comment
Remove redundant variable
Fixed an indention bug
Fixed a bug where horizontal advance was being skipped due to truncation in the calculation
@vadi2 vadi2 merged commit d8b9380 into Mudlet:development Sep 1, 2022
demonnic added a commit that referenced this pull request Nov 12, 2022
demonnic added a commit that referenced this pull request Nov 14, 2022
#### Brief overview of PR changes/additions
#6207 and subsequently #6277 have since been discovered to be the source of several bugs, and so we have decided to revert the changes in development but open a new PR for the changes themselves.

#### Motivation for adding to Mudlet

#### Other info (issues closed, discussion etc)
resolve the following issues:
#6416
#6394 
#6321 
#6290

Co-authored-by: Kebap <kebap_spam@gmx.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Miniconsole won't autowrap for languages with no word-splitters like Chinese.

5 participants