private static int GetSingleLineWidth(string s) { return(TextWidth.CalcPixelWidth(HtmlUtil.RemoveHtmlTags(s, true))); }
private List <string> GetErrors(Paragraph paragraph, int i, IReadOnlyList <Paragraph> paragraphs) { var errors = new List <string>(); if (paragraph.StartTime.IsMaxTime || paragraph.EndTime.IsMaxTime) { errors.Add("START/END: No time code"); } else { if (paragraph.WordsPerMinute > Configuration.Settings.General.SubtitleMaximumWordsPerMinute) { errors.Add($"WPM: {paragraph.WordsPerMinute:#,###.00} > {Configuration.Settings.General.SubtitleMaximumWordsPerMinute}"); } var charactersPerSecond = Utilities.GetCharactersPerSecond(paragraph); if (charactersPerSecond > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds) { errors.Add($"CPS: {charactersPerSecond:#,###.00} > {Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds}"); } if (paragraph.Duration.TotalMilliseconds < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds) { errors.Add($"Min duration: {paragraph.Duration.TotalMilliseconds:#,###.00} < {Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds}"); } if (paragraph.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds) { errors.Add($"Max duration: {paragraph.Duration.TotalMilliseconds:#,###.00} > {Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds}"); } if (i > 0 && i < paragraphs.Count) { var prev = paragraphs[i - 1]; if (paragraph.StartTime.TotalMilliseconds < prev.EndTime.TotalMilliseconds && !prev.EndTime.IsMaxTime) { errors.Add("Overlap with prev"); } } if (i >= 0 && i < paragraphs.Count - 1) { var next = paragraphs[i + 1]; var gapMilliseconds = (int)Math.Round(next.StartTime.TotalMilliseconds - paragraph.EndTime.TotalMilliseconds); if (gapMilliseconds < 0) { errors.Add("Overlap with next"); } else if (gapMilliseconds < Configuration.Settings.General.MinimumMillisecondsBetweenLines) { errors.Add($"Gap to next too small ({gapMilliseconds} < {Configuration.Settings.General.MinimumMillisecondsBetweenLines})"); } } } var s = HtmlUtil.RemoveHtmlTags(paragraph.Text, true); foreach (var line in s.SplitToLines()) { var count = line.CountCharacters(); if (count > Configuration.Settings.General.SubtitleLineMaximumLength) { errors.Add($"Line too long: {count} > {Configuration.Settings.General.SubtitleLineMaximumLength}"); } } var noOfLines = paragraph.NumberOfLines; if (s.CountCharacters() <= Configuration.Settings.General.SubtitleLineMaximumLength * noOfLines) { if (noOfLines > Configuration.Settings.General.MaxNumberOfLines) { errors.Add($"Too many lines: {noOfLines} > {Configuration.Settings.General.MaxNumberOfLines}"); } } if (Configuration.Settings.Tools.ListViewSyntaxColorWideLines) { s = HtmlUtil.RemoveHtmlTags(paragraph.Text, true); foreach (var line in s.SplitToLines()) { var pixels = TextWidth.CalcPixelWidth(line); if (pixels > Configuration.Settings.General.SubtitleLineMaximumPixelWidth) { errors.Add($"Line too wide in pixels: {pixels} > {Configuration.Settings.General.SubtitleLineMaximumPixelWidth}"); } } } return(errors); }