aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroldmud0 <3421260-oldmud0@users.noreply.gitlab.com>2019-05-10 17:58:06 +0000
committeroldmud0 <3421260-oldmud0@users.noreply.gitlab.com>2019-05-10 17:58:06 +0000
commit15db260639a157bffaaf55d10a6e4351aa4c154a (patch)
tree1347ce1978b7aeedf15e0e2e57faa2b43c04bfdc
parent744cf727f0102fc51dde5a2f0269433138270448 (diff)
parent2e4f0117b067c6d795a7d42fe23162d41260ff74 (diff)
Merge branch 'unicode-blips' into 'master'
Text is now advanced based on graphemes, rather than bytes. `QTextBoundaryFinder` is used to determine the end of a grapheme cluster, and then the entire cluster is copied into `f_character`. This will not influence text comparisons, like when determining formatting characters. The `f_character` being potentially more than one byte long is then used to advance the `tick_pos` to the correct position, using its length. See merge request AttorneyOnline/AO2-Client!60
-rw-r--r--include/courtroom.h1
-rw-r--r--src/courtroom.cpp19
2 files changed, 16 insertions, 4 deletions
diff --git a/include/courtroom.h b/include/courtroom.h
index ec9f9ef0..cc08f65d 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -48,6 +48,7 @@
#include <QFont>
#include <QInputDialog>
#include <QFileDialog>
+#include <QTextBoundaryFinder>
#include <stack>
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index be7629b8..c313a981 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -2024,6 +2024,7 @@ void Courtroom::chat_tick()
//do not perform heavy operations here
QString f_message = m_chatmessage[MESSAGE];
+ f_message.remove(0, tick_pos);
// Due to our new text speed system, we always need to stop the timer now.
chat_tick_timer->stop();
@@ -2038,7 +2039,7 @@ void Courtroom::chat_tick()
f_message.remove(0,2);
}
- if (tick_pos >= f_message.size())
+ if (f_message.size() == 0)
{
text_state = 2;
if (anim_state != 4)
@@ -2050,7 +2051,16 @@ void Courtroom::chat_tick()
else
{
- QString f_character = f_message.at(tick_pos);
+ QTextBoundaryFinder tbf(QTextBoundaryFinder::Grapheme, f_message);
+ QString f_character;
+
+ tbf.toNextBoundary();
+
+ if (tbf.position() == -1)
+ f_character = f_message;
+ else
+ f_character = f_message.left(tbf.position());
+
f_character = f_character.toHtmlEscaped();
if (f_character == " ")
@@ -2265,7 +2275,7 @@ void Courtroom::chat_tick()
if(blank_blip)
qDebug() << "blank_blip found true";
- if (f_message.at(tick_pos) != ' ' || blank_blip)
+ if (f_character != ' ' || blank_blip)
{
if (blip_pos % blip_rate == 0 && !formatting_char)
@@ -2277,7 +2287,7 @@ void Courtroom::chat_tick()
++blip_pos;
}
- ++tick_pos;
+ tick_pos += f_character.length();
// Restart the timer, but according to the newly set speeds, if there were any.
// Keep the speed at bay.
@@ -2304,6 +2314,7 @@ void Courtroom::chat_tick()
}
}
+
void Courtroom::show_testimony()
{
if (!testimony_in_progress || m_chatmessage[SIDE] != "wit")