From 699afb0cf2ebfefee90e2d57454800cfcc3620c6 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Tue, 15 Jan 2019 21:21:28 +0100 Subject: [PATCH] Minor refact of DCinema --- libse/SubtitleFormats/DCinemaSmpte2007.cs | 2 +- libse/SubtitleFormats/DCinemaSmpte2010.cs | 125 +++++++++++++++++++++- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/libse/SubtitleFormats/DCinemaSmpte2007.cs b/libse/SubtitleFormats/DCinemaSmpte2007.cs index 655c633c8..68536038f 100644 --- a/libse/SubtitleFormats/DCinemaSmpte2007.cs +++ b/libse/SubtitleFormats/DCinemaSmpte2007.cs @@ -535,7 +535,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } else if (ss.CurrentDCinemaEditRate == "25") { - Configuration.Settings.General.CurrentFrameRate = 24; + Configuration.Settings.General.CurrentFrameRate = 25; } if (BatchSourceFrameRate.HasValue) diff --git a/libse/SubtitleFormats/DCinemaSmpte2010.cs b/libse/SubtitleFormats/DCinemaSmpte2010.cs index e74fbb132..cc9e343e2 100644 --- a/libse/SubtitleFormats/DCinemaSmpte2010.cs +++ b/libse/SubtitleFormats/DCinemaSmpte2010.cs @@ -47,7 +47,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats string xmlAsString = sb.ToString().Trim(); if (xmlAsString.Contains("http://www.smpte-ra.org/schemas/428-7/2007/DCST")) + { return false; + } if (xmlAsString.Contains(" lines, string fileName) { _errorCount = 0; - var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); var xml = new XmlDocument { XmlResolver = null }; @@ -500,24 +540,34 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats ss.InitializeDCinameSettings(true); XmlNode node = xml.DocumentElement.SelectSingleNode("Id"); if (node != null) + { ss.CurrentDCinemaSubtitleId = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("ReelNumber"); if (node != null) + { ss.CurrentDCinemaReelNumber = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("EditRate"); if (node != null) + { ss.CurrentDCinemaEditRate = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("TimeCodeRate"); if (node != null) { ss.CurrentDCinemaTimeCodeRate = node.InnerText; if (ss.CurrentDCinemaEditRate == "24") + { Configuration.Settings.General.CurrentFrameRate = 24; + } else if (ss.CurrentDCinemaEditRate == "25") - Configuration.Settings.General.CurrentFrameRate = 24; + { + Configuration.Settings.General.CurrentFrameRate = 25; + } if (BatchSourceFrameRate.HasValue) { @@ -527,37 +577,61 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats node = xml.DocumentElement.SelectSingleNode("StartTime"); if (node != null) + { ss.CurrentDCinemaStartTime = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("Language"); if (node != null) + { ss.CurrentDCinemaLanguage = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("ContentTitleText"); if (node != null) + { ss.CurrentDCinemaMovieTitle = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("IssueDate"); if (node != null) + { ss.CurrentDCinemaIssueDate = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("LoadFont"); if (node != null) + { ss.CurrentDCinemaFontUri = node.InnerText; + } node = xml.DocumentElement.SelectSingleNode("SubtitleList/Font"); if (node != null) { if (node.Attributes["ID"] != null) + { ss.CurrentDCinemaFontId = node.Attributes["ID"].InnerText; + } + if (node.Attributes["Size"] != null) + { ss.CurrentDCinemaFontSize = Convert.ToInt32(node.Attributes["Size"].InnerText); + } + if (node.Attributes["Color"] != null) + { ss.CurrentDCinemaFontColor = System.Drawing.ColorTranslator.FromHtml("#" + node.Attributes["Color"].InnerText); + } + if (node.Attributes["Effect"] != null) + { ss.CurrentDCinemaFontEffect = node.Attributes["Effect"].InnerText; + } + if (node.Attributes["EffectColor"] != null) + { ss.CurrentDCinemaFontEffectColor = System.Drawing.ColorTranslator.FromHtml("#" + node.Attributes["EffectColor"].InnerText); + } } } catch (Exception exception) @@ -582,7 +656,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats if (vPosition != lastVPosition) { if (pText.Length > 0 && lastVPosition.Length > 0) + { pText.AppendLine(); + } + lastVPosition = vPosition; } } @@ -594,17 +671,25 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { string hAlign = innerNode.Attributes["Halign"].InnerText; if (hAlign == "left") + { alignLeft = true; + } else if (hAlign == "right") + { alignRight = true; + } } if (innerNode.Attributes["Valign"] != null) { string hAlign = innerNode.Attributes["Valign"].InnerText; if (hAlign == "top") + { alignVTop = true; + } else if (hAlign == "center") + { alignVCenter = true; + } } if (alignLeft || alignRight || alignVCenter || alignVTop) { @@ -614,27 +699,43 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats if (alignVTop) { if (alignLeft) + { pre = "{\\an7}"; + } else if (alignRight) + { pre = "{\\an9}"; + } else + { pre = "{\\an8}"; + } } else if (alignVCenter) { if (alignLeft) + { pre = "{\\an4}"; + } else if (alignRight) + { pre = "{\\an6}"; + } else + { pre = "{\\an5}"; + } } else { if (alignLeft) + { pre = "{\\an1}"; + } else if (alignRight) + { pre = "{\\an3}"; + } } string temp = pre + pText; pText.Clear(); @@ -654,16 +755,24 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase)) { if (innerInnerNode.Attributes["Color"] != null) + { pText.Append("" + innerInnerNode.InnerText + ""); + } else + { pText.Append("" + innerInnerNode.InnerText + ""); + } } else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null) { if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase)) + { pText.Append("" + innerInnerNode.InnerText + ""); + } else + { pText.Append("" + innerInnerNode.InnerText + ""); + } } else { @@ -685,9 +794,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { string text = pText.ToString(); if (text.StartsWith("{\\an", StringComparison.Ordinal) && text.Length > 6) + { text = text.Insert(6, "") + ""; + } else + { text = "" + text + ""; + } + pText = new StringBuilder(text); } @@ -701,7 +815,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } if (subtitle.Paragraphs.Count > 0) + { subtitle.Header = xml.OuterXml; // save id/language/font for later use + } subtitle.Renumber(); } @@ -712,7 +828,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats int milliseconds = (int)Math.Round(int.Parse(parts[3]) * (TimeCode.BaseUnit / _frameRate)); if (milliseconds > 999) + { milliseconds = 999; + } return new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), milliseconds); } @@ -721,7 +839,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / frameRate)); if (frames >= Configuration.Settings.General.CurrentFrameRate) + { frames = (int)(frameRate - 0.01); + } + return frames; }