From c7c729365244527f72ef5dfa3ca64bd3a059177a Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Fri, 3 Aug 2018 18:25:33 +0200 Subject: [PATCH] Respect line break for waveform preview text - thx Leon :) Fix #2992 --- src/Controls/AudioVisualizer.cs | 49 +++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/Controls/AudioVisualizer.cs b/src/Controls/AudioVisualizer.cs index 250ac2f11..4adf7c050 100644 --- a/src/Controls/AudioVisualizer.cs +++ b/src/Controls/AudioVisualizer.cs @@ -746,23 +746,8 @@ namespace Nikse.SubtitleEdit.Controls // paragraph text if (n > 80) { - string text = HtmlUtil.RemoveHtmlTags(paragraph.Text, true).Replace(Environment.NewLine, " "); - if (Configuration.Settings.General.RightToLeftMode && LanguageAutoDetect.CouldBeRightToLeftLanguge(new Subtitle(_displayableParagraphs))) - text = Utilities.ReverseStartAndEndingForRightToLeft(text); - int removeLength = 1; - if (text.Length > 500) - text = text.Substring(0, 500); // don't now allow very long texts as they can make SE unresponsive - see https://github.com/SubtitleEdit/subtitleedit/issues/2536 - while (text.Length > removeLength && graphics.MeasureString(text, font).Width > currentRegionWidth - padding - 1) - { - text = text.Remove(text.Length - removeLength).TrimEnd() + "…"; - if (text.Length > 200) - removeLength = 21; - else if (text.Length > 100) - removeLength = 11; - else - removeLength = 2; - } - drawStringOutlined(text, currentRegionLeft + padding, padding); + string text = HtmlUtil.RemoveHtmlTags(paragraph.Text, true); //.Replace(Environment.NewLine, " "); + DrawParagraphText(graphics, text, font, currentRegionWidth, padding, drawStringOutlined, currentRegionLeft); } // paragraph number @@ -785,6 +770,36 @@ namespace Nikse.SubtitleEdit.Controls } } + private void DrawParagraphText(Graphics graphics, string text, Font font, int currentRegionWidth, int padding, Action drawStringOutlined, int currentRegionLeft) + { + if (Configuration.Settings.General.RightToLeftMode && LanguageAutoDetect.CouldBeRightToLeftLanguge(new Subtitle(_displayableParagraphs))) + text = Utilities.ReverseStartAndEndingForRightToLeft(text); + if (text.Length > 500) + text = text.Substring(0, 500); // don't now allow very long texts as they can make SE unresponsive - see https://github.com/SubtitleEdit/subtitleedit/issues/2536 + int y = padding; + var max = currentRegionWidth - padding - 1; + foreach (var line in text.SplitToLines()) + { + text = line; + int removeLength = 1; + var measureResult = graphics.MeasureString(text, font); + while (text.Length > removeLength && graphics.MeasureString(text, font).Width > max) + { + text = text.Remove(text.Length - removeLength).TrimEnd() + "…"; + if (text.Length > 200) + removeLength = 21; + else if (text.Length > 100) + removeLength = 11; + else + removeLength = 2; + measureResult = graphics.MeasureString(text, font); + } + drawStringOutlined(text, currentRegionLeft + padding, y); + y += (int)Math.Round(measureResult.Height, MidpointRounding.AwayFromZero); + } + + } + private double RelativeXPositionToSeconds(int x) { return _startPositionSeconds + (double)x / _wavePeaks.SampleRate / _zoomFactor;