fixed issues with surrogate pairs in text selection and rendering

This commit is contained in:
fourtf
2018-10-21 13:03:26 +02:00
parent 1fde45f59b
commit f4cf464ddb
2 changed files with 29 additions and 14 deletions
+10 -3
View File
@@ -214,13 +214,20 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
int x = this->getRect().left();
for (int i = 0; i < this->getText().size(); i++) {
int w = metrics.width(this->getText()[i]);
auto &text = this->getText();
auto width = metrics.width(this->getText()[i]);
if (x + width > abs.x()) {
if (text.size() > i + 1 &&
QChar::isLowSurrogate(text[i].unicode())) //
{
i++;
}
if (x + w > abs.x()) {
return i;
}
x += w;
x += width;
}
return this->getSelectionIndexCount();