using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { public class RhozetHarmonic : SubtitleFormat { public override string Extension { get { return ".xml"; } } public override string Name { get { return "Rhozet Harmonic"; } } public override bool IsTimeBased { get { return true; } } public override bool IsMine(List lines, string fileName) { var subtitle = new Subtitle(); LoadSubtitle(subtitle, lines, fileName); return subtitle.Paragraphs.Count > 0; } private static string ToTimeCode(TimeCode time) { return time.ToHHMMSSFF(); } private static TimeCode DecodeTimeCode(string s) { var parts = s.Split(new[] { ':', ';' }, StringSplitOptions.RemoveEmptyEntries); string hour = parts[0]; string minutes = parts[1]; string seconds = parts[2]; string frames = parts[3]; int milliseconds = (int)Math.Round(((TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate) * int.Parse(frames))); if (milliseconds > 999) milliseconds = 999; return new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), milliseconds); } public override string ToText(Subtitle subtitle, string title) { // // string xmlStructure = "" + Environment.NewLine + ""; var xml = new XmlDocument(); xml.LoadXml(xmlStructure); XmlNode paragraph = xml.CreateElement("Data"); XmlAttribute charSize = xml.CreateAttribute("CharSize"); charSize.InnerText = HtmlUtil.RemoveHtmlTags("0.2"); paragraph.Attributes.Append(charSize); XmlAttribute posX = xml.CreateAttribute("PosX"); posX.InnerText = "0.5"; paragraph.Attributes.Append(posX); XmlAttribute posY = xml.CreateAttribute("PosY"); posY.InnerText = "0.75"; paragraph.Attributes.Append(posY); XmlAttribute colorR = xml.CreateAttribute("ColorR"); colorR.InnerText = "245"; paragraph.Attributes.Append(colorR); XmlAttribute colorG = xml.CreateAttribute("ColorG"); colorG.InnerText = "245"; paragraph.Attributes.Append(colorG); XmlAttribute colorB = xml.CreateAttribute("ColorB"); colorB.InnerText = "245"; paragraph.Attributes.Append(colorB); XmlAttribute transparency = xml.CreateAttribute("Transparency"); transparency.InnerText = "0.0"; paragraph.Attributes.Append(transparency); XmlAttribute shadowSize = xml.CreateAttribute("ShadowSize"); shadowSize.InnerText = "0.5"; paragraph.Attributes.Append(shadowSize); XmlAttribute bkgEnable = xml.CreateAttribute("BkgEnable"); bkgEnable.InnerText = "1"; paragraph.Attributes.Append(bkgEnable); XmlAttribute bkgExtraWidth = xml.CreateAttribute("BkgExtraWidth"); bkgExtraWidth.InnerText = "0.02"; paragraph.Attributes.Append(bkgExtraWidth); XmlAttribute bkgExtraHeight = xml.CreateAttribute("BkgExtraHeight"); bkgExtraHeight.InnerText = "0.02"; paragraph.Attributes.Append(bkgExtraHeight); xml.DocumentElement.AppendChild(paragraph); foreach (Paragraph p in subtitle.Paragraphs) { paragraph = xml.CreateElement("Data"); XmlAttribute start = xml.CreateAttribute("StartTimecode"); start.InnerText = ToTimeCode(p.StartTime); paragraph.Attributes.Append(start); XmlAttribute end = xml.CreateAttribute("EndTimecode"); end.InnerText = ToTimeCode(p.EndTime); paragraph.Attributes.Append(end); XmlAttribute text = xml.CreateAttribute("Title"); text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text); paragraph.Attributes.Append(text); xml.DocumentElement.AppendChild(paragraph); } string s = "" + Environment.NewLine + ToUtf8XmlString(xml, true).Replace("\"", "__@____").Replace("'", "'").Replace("__@____", "'").Replace(" />", "/>"); while (s.Contains(Environment.NewLine + " ")) s = s.Replace(Environment.NewLine + " ", Environment.NewLine); return s; } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string allText = sb.ToString(); if (!allText.Contains("