Beginning to implement RTFDataFormat
This commit is contained in:
parent
1ba47802a2
commit
930d683cfe
@ -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 + "}}}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,6 +64,7 @@
|
||||
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutStartupNotifyBehavior.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\FreeDesktop\DesktopShortcutType.cs" />
|
||||
<Compile Include="DataFormats\Text\Formatted\RichText\RTFDataFormat.cs" />
|
||||
<Compile Include="DataFormats\UEPackage\UEPackageXMLDataFormat.cs" />
|
||||
<Compile Include="ExpandedString.cs" />
|
||||
<Compile Include="ObjectModels\AbstractSyntax\AbstractSyntaxObjectModel.cs" />
|
||||
@ -107,6 +108,7 @@
|
||||
<Compile Include="ObjectModels\Text\Formatted\FormattedTextStyle.cs" />
|
||||
<Compile Include="ObjectModels\Text\Formatted\FormattedTextStyleGroup.cs" />
|
||||
<Compile Include="ObjectModels\Text\Formatted\Items\Container.cs" />
|
||||
<Compile Include="ObjectModels\Text\Formatted\Items\FormattedTextItemHyperlink.cs" />
|
||||
<Compile Include="ObjectModels\Text\Formatted\Items\Literal.cs" />
|
||||
<Compile Include="ObjectModels\Text\Plain\PlainTextObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\UEPackage\UEPackageObjectModel.cs" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user