From bc5da29e9c73be42b55bf0761ab80d52c8487c2b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=BCng?= Date: Mon, 27 Dec 2021 11:52:46 +0100 Subject: [PATCH] Calculate the char width when wrapping using real text MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit (fixes issue #3799) Signed-off-by: Stefan Küng Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/TortoiseMerge/BaseView.cpp | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 608a503ed..dd4fa950c 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -33,6 +33,7 @@ Released: unreleased * Fixes issue #3826: Help links to TortoiseGit site don't open in a sensible browser * Fixed issue #3815: TortoiseGitMerge crashes on Windows 7 on startup when winrt libraries are installed * Fixed issue #3831: TortoiseGitMerge omits text after null byte when word wrap is enabled + * Fixed issue #3799: Display of Long lines with Chinese characters is truncated in TortoiseGitMerge dialog = Release 2.12.0 = Released: 2021-03-31 diff --git a/src/TortoiseMerge/BaseView.cpp b/src/TortoiseMerge/BaseView.cpp index 1680a3749..40afb829b 100644 --- a/src/TortoiseMerge/BaseView.cpp +++ b/src/TortoiseMerge/BaseView.cpp @@ -4899,12 +4899,41 @@ int CBaseView::CountMultiLines( int nViewLine ) auto multiLines = CStringUtils::WordWrap(m_pViewData->GetLine(nViewLine), GetScreenChars() - 1, GetTabSize()); TScreenedViewLine oScreenedLine; + bool subLinesSet = true; + if (m_pMainFrame->m_bWrapLines) + { + CDC* pDC = GetDC(); + CFont* pOldFont = pDC->SelectObject(GetFont()); - for (const auto& line : multiLines) + for (const auto& line : multiLines) + { + if (line.GetLength()) + { + // we use the 'X' char to determine the char width, + // but e.g. chinese chars are much wider. To make sure + // that we wrap correctly, we calculate the average char width + // here by using the real line text + const CSize szCharExt = pDC->GetTextExtent(line); + if (szCharExt.cx / line.GetLength() > m_nCharWidth) + { + m_nCharWidth = szCharExt.cx / line.GetLength(); + subLinesSet = false; + } + } + oScreenedLine.SubLines.push_back(line); + } + pDC->SelectObject(pOldFont); + ReleaseDC(pDC); + } + else { - oScreenedLine.SubLines.push_back(line); + for (const auto& line : multiLines) + { + oScreenedLine.SubLines.push_back(line); + } } - oScreenedLine.bSublinesSet = true; + + oScreenedLine.bSublinesSet = subLinesSet; m_ScreenedViewLine[nViewLine] = oScreenedLine; return CountMultiLines(nViewLine); -- 2.11.4.GIT