From 494a6fad5024bff7652ad4c56df328e24f166b9f Mon Sep 17 00:00:00 2001 From: niksedk Date: Sat, 11 Mar 2023 17:15:06 +0100 Subject: [PATCH] Add read of image format RhozetHarmonic - thx Arianna :) --- .../SubtitleFormats/RhozetHarmonicImage.cs | 125 ++++++++++++++++++ src/ui/Forms/Main.cs | 22 +++ 2 files changed, 147 insertions(+) create mode 100644 src/libse/SubtitleFormats/RhozetHarmonicImage.cs diff --git a/src/libse/SubtitleFormats/RhozetHarmonicImage.cs b/src/libse/SubtitleFormats/RhozetHarmonicImage.cs new file mode 100644 index 000000000..83cb1c020 --- /dev/null +++ b/src/libse/SubtitleFormats/RhozetHarmonicImage.cs @@ -0,0 +1,125 @@ +using Nikse.SubtitleEdit.Core.Common; +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace Nikse.SubtitleEdit.Core.SubtitleFormats +{ + public class RhozetHarmonicImage : SubtitleFormat + { + public override string Extension => ".xml"; + + public override string Name => "Rhozet Harmonic Image"; + + private static string ToTimeCode(TimeCode time) + { + return time.ToHHMMSSFF(); + } + + public override string ToText(Subtitle subtitle, string title) + { + // + // + // + + string xmlStructure = + "" + Environment.NewLine + + ""; + + var xml = new XmlDocument(); + xml.LoadXml(xmlStructure); + + XmlNode paragraph = xml.CreateElement("Data"); + + xml.DocumentElement.AppendChild(paragraph); + + foreach (var p in subtitle.Paragraphs) + { + paragraph = xml.CreateElement("Data"); + + var start = xml.CreateAttribute("StartTimecode"); + start.InnerText = ToTimeCode(p.StartTime); + paragraph.Attributes.Append(start); + + var end = xml.CreateAttribute("EndTimecode"); + end.InnerText = ToTimeCode(p.EndTime); + paragraph.Attributes.Append(end); + + var text = xml.CreateAttribute("Image"); + text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text); + paragraph.Attributes.Append(text); + + xml.DocumentElement.AppendChild(paragraph); + } + + var 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("(File.ReadAllLines(fileName, encodingFromFile)); + if (rhozetHarmonicImage.IsMine(list, fileName)) + { + if (ContinueNewOrExit()) + { + ImportAndOcrDost(fileName, rhozetHarmonicImage, list); + } + + return; + } + } + catch + { + // ignore + } + } + if (format == null) { try