diff --git a/CSharp/Plugins/UniversalEditor.Essential/DataFormats/Text/Formatted/RichText/RTFDataFormat.cs b/CSharp/Plugins/UniversalEditor.Essential/DataFormats/Text/Formatted/RichText/RTFDataFormat.cs new file mode 100644 index 00000000..a7fcbf89 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Essential/DataFormats/Text/Formatted/RichText/RTFDataFormat.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UniversalEditor.IO; +using UniversalEditor.ObjectModels.Text.Formatted; +using UniversalEditor.ObjectModels.Text.Formatted.Items; + +namespace UniversalEditor.DataFormats.Text.Formatted.RichText +{ + public class RTFDataFormat : DataFormat + { + private static DataFormatReference _dfr = null; + protected override DataFormatReference MakeReferenceInternal() + { + if (_dfr == null) + { + _dfr = base.MakeReferenceInternal(); + _dfr.Capabilities.Add(typeof(FormattedTextObjectModel), DataFormatCapabilities.All); + } + return _dfr; + } + + protected override void LoadInternal(ref ObjectModel objectModel) + { + } + + protected override void SaveInternal(ObjectModel objectModel) + { + FormattedTextObjectModel ftom = (objectModel as FormattedTextObjectModel); + if (ftom == null) throw new ObjectModelNotSupportedException(); + + Writer writer = base.Accessor.Writer; + writer.WriteLine("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 "); + foreach (FormattedTextItem item in ftom.Items) + { + RenderItem(writer, item); + } + writer.WriteLine(" }"); + } + + private void RenderItem(Writer writer, FormattedTextItem item) + { + if (item is FormattedTextItemHyperlink) + { + FormattedTextItemHyperlink itm = (item as FormattedTextItemHyperlink); + writer.WriteLine("{\\field{\\*\\fldinst {HYPERLINK \"" + itm.TargetURL + "\"}}{\\fldrslt {" + itm.Title + "}}}"); + } + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Essential/ObjectModels/Text/Formatted/Items/FormattedTextItemHyperlink.cs b/CSharp/Plugins/UniversalEditor.Essential/ObjectModels/Text/Formatted/Items/FormattedTextItemHyperlink.cs new file mode 100644 index 00000000..7634c2c1 --- /dev/null +++ b/CSharp/Plugins/UniversalEditor.Essential/ObjectModels/Text/Formatted/Items/FormattedTextItemHyperlink.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.ObjectModels.Text.Formatted.Items +{ + public class FormattedTextItemHyperlink : FormattedTextItem + { + private string mvarTitle = String.Empty; + public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + + private string mvarTargetURL = String.Empty; + public string TargetURL { get { return mvarTargetURL; } set { mvarTargetURL = value; } } + + public FormattedTextItemHyperlink(string targetURL = "", string title = "") + { + mvarTargetURL = targetURL; + if (String.IsNullOrEmpty(title)) + { + mvarTitle = targetURL; + } + else + { + mvarTitle = title; + } + } + + public override object Clone() + { + FormattedTextItemHyperlink clone = new FormattedTextItemHyperlink(); + clone.TargetURL = (mvarTargetURL.Clone() as string); + clone.Title = (mvarTitle.Clone() as string); + return clone; + } + } +} diff --git a/CSharp/Plugins/UniversalEditor.Essential/UniversalEditor.Essential.csproj b/CSharp/Plugins/UniversalEditor.Essential/UniversalEditor.Essential.csproj index 5ad6db9a..c2e5bad3 100644 --- a/CSharp/Plugins/UniversalEditor.Essential/UniversalEditor.Essential.csproj +++ b/CSharp/Plugins/UniversalEditor.Essential/UniversalEditor.Essential.csproj @@ -64,6 +64,7 @@ + @@ -107,6 +108,7 @@ +