Improvements to XPS data format

This commit is contained in:
Michael Becker 2016-02-05 16:33:44 -05:00
parent be42644300
commit e38482fcc3
5 changed files with 112 additions and 5 deletions

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.DataFormats.Markup.XML;
using UniversalEditor.ObjectModels.Markup;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocumentSequence;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS.FixedDocumentSequence
{
public class FDSEQDataFormat : XMLDataFormat
{
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
{
base.BeforeLoadInternal(objectModels);
objectModels.Push(new MarkupObjectModel());
}
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
{
base.AfterLoadInternal(objectModels);
MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel);
FixedDocumentSequenceObjectModel fdseq = (objectModels.Pop() as FixedDocumentSequenceObjectModel);
MarkupTagElement tagFixedDocumentSequence = (mom.Elements["FixedDocumentSequence"] as MarkupTagElement);
foreach (MarkupElement elDocumentReference in tagFixedDocumentSequence.Elements)
{
MarkupTagElement tagDocumentReference = (elDocumentReference as MarkupTagElement);
if (tagDocumentReference == null) continue;
if (tagDocumentReference.FullName != "DocumentReference") continue;
MarkupAttribute attSource = tagDocumentReference.Attributes["Source"];
if (attSource == null) continue;
DocumentReference docref = new DocumentReference();
docref.Source = attSource.Value;
fdseq.DocumentReferences.Add(docref);
}
}
}
}

View File

@ -20,11 +20,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor.DataFormats.Package.OpenPackagingConvention;
using UniversalEditor.DataFormats.Text.Formatted.XPS.FixedDocumentSequence;
using UniversalEditor.ObjectModels.FileSystem;
using UniversalEditor.ObjectModels.Package;
using UniversalEditor.ObjectModels.Text.Formatted;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocumentSequence;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
@ -53,6 +54,14 @@ namespace UniversalEditor.DataFormats.Text.Formatted.XPS
PackageObjectModel package = (objectModels.Pop() as PackageObjectModel);
FormattedTextObjectModel text = (objectModels.Pop() as FormattedTextObjectModel);
// we need to get the FixedRepresentation for the XPS document
File[] files = package.GetFilesBySchema("http://schemas.microsoft.com/xps/2005/06/fixedrepresentation");
FixedDocumentSequenceObjectModel fdom = files[0].GetObjectModel<FixedDocumentSequenceObjectModel>(new FDSEQDataFormat());
File fdoc = package.FileSystem.FindFile(fdom.DocumentReferences[0].Source.Substring(1));
// FixedDocument fdoc = file.GetObjectModel<FixedDocumentObjectModel>(new FDOCDataFormat());
}
protected override void BeforeSaveInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocumentSequence
{
public class DocumentReference : ICloneable
{
public class DocumentReferenceCollection
: System.Collections.ObjectModel.Collection<DocumentReference>
{
}
private string mvarSource = String.Empty;
public string Source { get { return mvarSource; } set { mvarSource = value; } }
public object Clone()
{
DocumentReference clone = new DocumentReference();
clone.Source = (mvarSource.Clone() as string);
return clone;
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocumentSequence
{
public class FixedDocumentSequenceObjectModel : ObjectModel
{
public override void Clear()
{
mvarDocumentReferences.Clear();
}
public override void CopyTo(ObjectModel where)
{
FixedDocumentSequenceObjectModel clone = (where as FixedDocumentSequenceObjectModel);
if (clone == null) throw new ObjectModelNotSupportedException();
foreach (DocumentReference item in mvarDocumentReferences)
{
clone.DocumentReferences.Add(item.Clone() as DocumentReference);
}
}
private DocumentReference.DocumentReferenceCollection mvarDocumentReferences = new DocumentReference.DocumentReferenceCollection();
public DocumentReference.DocumentReferenceCollection DocumentReferences { get { return mvarDocumentReferences; } }
}
}

View File

@ -86,6 +86,9 @@
<Compile Include="DataFormats\Shortcut\Microsoft\LNKHotkey.cs" />
<Compile Include="DataFormats\Shortcut\Microsoft\LNKLocationFlags.cs" />
<Compile Include="DataFormats\Shortcut\Microsoft\LNKWindowState.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\FixedDocumentSequence\FDSEQDataFormat.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedDocumentSequence\DocumentReference.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedDocumentSequence\FixedDocumentSequenceObjectModel.cs" />
<Compile Include="ObjectModels\Help\Compiled\CompiledHelpObjectModel.cs" />
<Compile Include="ObjectModels\Package\ContentTypes\ContentType.cs" />
<Compile Include="ObjectModels\Package\ContentTypes\ContentTypesObjectModel.cs" />
@ -113,9 +116,7 @@
<Name>UniversalEditor.Plugins.FileSystem</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="ObjectModels\Text\Formatted\XPS\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.