From 437440978bca1bd84e70ee61ba7974f63fe0630a Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Wed, 6 Jul 2016 22:25:33 +0200 Subject: [PATCH] Fix rendering of decomposed Hangul When looking backwards to combine into a character, it didn't take into account characters with two column width. It also assumed that all characters that needed to be combined were in the Mn unicode character category, while the Hangul starting consonants are in the Lo category. --- src/Screen.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Screen.cpp b/src/Screen.cpp index 8e052490d..8ad4dee00 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -634,34 +634,34 @@ void Screen::displayCharacter(unsigned short c) // putting the cursor one right to the last column of the screen. int w = konsole_wcwidth(c); - if (w < 0) + + if (w < 0) { + // Non-printable character return; - else if (w == 0) { - if (QChar(c).category() != QChar::Mark_NonSpacing) + } else if (w == 0) { + const QChar::Category category = QChar(c).category(); + if (category != QChar::Mark_NonSpacing && category != QChar::Letter_Other) { return; - int charToCombineWithX = -1; - int charToCombineWithY = -1; - if (_cuX == 0) { - // We are at the beginning of a line, check - // if previous line has a character at the end we can combine with - if (_cuY > 0 && _columns == _screenLines[_cuY - 1].size()) { - charToCombineWithX = _columns - 1; - charToCombineWithY = _cuY - 1; + } + // Find previous "real character" to try to combine with + int charToCombineWithX = _cuX; + int charToCombineWithY = _cuY; + do { + if (charToCombineWithX > 0) { + charToCombineWithX--; + } else if (charToCombineWithY > 0) { // Try previous line + charToCombineWithY--; + charToCombineWithX = _screenLines[charToCombineWithY].length() - 1; } else { - // There is nothing to combine with - // TODO Seems gnome-terminal shows the characters alone - // might be worth investigating how to do that + // Give up return; } - } else { - charToCombineWithX = _cuX - 1; - charToCombineWithY = _cuY; - } - // Prevent "cat"ing binary files from causing crashes. - if (charToCombineWithX >= _screenLines[charToCombineWithY].size()) { - return; - } + // Failsafe + if (charToCombineWithX < 0) { + return; + } + } while(!_screenLines[charToCombineWithY][charToCombineWithX].isRealCharacter); Character& currentChar = _screenLines[charToCombineWithY][charToCombineWithX]; if ((currentChar.rendition & RE_EXTENDED_CHAR) == 0) {