Move canGroup code to Character.h

This is a function that's completely related to character
and has nothing to do with painting, so the correct place
for it is on the Character class.

This will make testing easier, too.
wilder
Tomaz Canabrava 4 years ago
parent b1410cedd0
commit 1cd4dea483
  1. 9
      src/characters/Character.h
  2. 19
      src/terminalDisplay/TerminalPainter.cpp

@ -153,6 +153,15 @@ public:
QVector<uint> ucs4Str = str.toUcs4(); QVector<uint> ucs4Str = str.toUcs4();
return stringWidth(ucs4Str.constData(), ucs4Str.length()); return stringWidth(ucs4Str.constData(), ucs4Str.length());
} }
inline bool canBeGrouped(bool bidirectionalEnabled, bool isDoubleWidth) const
{
if (QChar::script(character) == QChar::Script_Braille) {
return false;
}
return character <= 0x7e || (rendition & RE_EXTENDED_CHAR) || (bidirectionalEnabled && !isDoubleWidth);
}
}; };
constexpr bool operator==(const Character &a, const Character &b) constexpr bool operator==(const Character &a, const Character &b)

@ -138,24 +138,11 @@ void TerminalPainter::drawContents(Character *image,
return currentScript == script; return currentScript == script;
}; };
// returns true if it's a braile char, false otherwise. const Character &char_value = image[display->loc(x, y)];
const auto isBraileChar = [&](int column) -> bool {
char32_t maybeBraile = image[display->loc(column, y)].character;
return maybeBraile >= 0x2800 && maybeBraile <= 0x28FF;
};
const auto canBeGrouped = [&](int column) {
if (isBraileChar(x)) {
return false;
}
return image[display->loc(column, y)].character <= 0x7e || (image[display->loc(column, y)].rendition & RE_EXTENDED_CHAR)
|| (bidiEnabled && !doubleWidth);
};
if (canBeGrouped(x)) { if (char_value.canBeGrouped(bidiEnabled, doubleWidth)) {
while (isInsideDrawArea(x + len) && hasSameColors(x + len) && hasSameRendition(x + len) && hasSameWidth(x + len) while (isInsideDrawArea(x + len) && hasSameColors(x + len) && hasSameRendition(x + len) && hasSameWidth(x + len)
&& hasSameLineDrawStatus(x + len) && isSameScript(x + len) && canBeGrouped(x + len)) { && hasSameLineDrawStatus(x + len) && isSameScript(x + len) && image[display->loc(x + len, y)].canBeGrouped(bidiEnabled, doubleWidth)) {
const uint c = image[display->loc(x + len, y)].character; const uint c = image[display->loc(x + len, y)].character;
if ((image[display->loc(x + len, y)].rendition & RE_EXTENDED_CHAR) != 0) { if ((image[display->loc(x + len, y)].rendition & RE_EXTENDED_CHAR) != 0) {
// sequence of characters // sequence of characters

Loading…
Cancel
Save