Improvements to the filesystem behind the XPS format - still not actually doing anything with text yet

This commit is contained in:
Michael Becker 2019-08-19 12:26:00 -04:00
parent 7d832b6143
commit b9965ccda9
16 changed files with 465 additions and 4 deletions

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using UniversalEditor.DataFormats.Markup.XML;
using UniversalEditor.ObjectModels.Markup;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocument;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS.FixedDocument
{
public class FDOCDataFormat : XMLDataFormat
{
public FDOCDataFormat()
{
}
public FDOCDataFormat(XPSSchemaVersion schemaVersion)
{
SchemaVersion = schemaVersion;
}
public XPSSchemaVersion SchemaVersion { get; set; } = XPSSchemaVersion.OpenXPS;
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);
FixedDocumentObjectModel fdoc = (objectModels.Pop() as FixedDocumentObjectModel);
MarkupTagElement tagFixedDocument = (mom.Elements["FixedDocument"] as MarkupTagElement);
if (tagFixedDocument != null)
{
foreach (MarkupElement el in tagFixedDocument.Elements)
{
MarkupTagElement tag = (el as MarkupTagElement);
if (tag == null) continue;
if (tag.Name != "PageContent") continue;
MarkupAttribute attSource = tag.Attributes["Source"];
if (attSource == null) continue;
PageContent pc = new PageContent(attSource.Value);
fdoc.PageContents.Add(pc);
}
}
}
protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
{
FixedDocumentObjectModel fdoc = (objectModels.Pop() as FixedDocumentObjectModel);
MarkupObjectModel mom = new MarkupObjectModel();
MarkupTagElement tagFixedDocument = new MarkupTagElement();
tagFixedDocument.FullName = "FixedDocument";
tagFixedDocument.Attributes.Add("xmlns", XPSSchemas.GetSchema(SchemaVersion, XPSSchemaType.FixedDocument));
foreach (PageContent pc in fdoc.PageContents)
{
MarkupTagElement tag = new MarkupTagElement();
tag.FullName = "PageContent";
tag.Attributes.Add("Source", pc.Source);
tagFixedDocument.Elements.Add(tag);
}
mom.Elements.Add(tagFixedDocument);
objectModels.Push(mom);
base.BeforeSaveInternal(objectModels);
}
}
}

View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Text;
using UniversalEditor.DataFormats.Markup.XML;
using UniversalEditor.ObjectModels.Markup;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedPage;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS.FixedPage
{
public class FPAGEDataFormat : XMLDataFormat
{
public XPSGenerator Generator { get; set; } = new XPSGenerator();
public XPSSchemaVersion SchemaVersion { get; set; } = XPSSchemaVersion.OpenXPS;
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);
FixedPageObjectModel fpage = (objectModels.Pop() as FixedPageObjectModel);
MarkupTagElement tagFixedPage = (mom.Elements["FixedPage"] as MarkupTagElement);
if (tagFixedPage != null)
{
MarkupAttribute attWidth = tagFixedPage.Attributes["Width"];
MarkupAttribute attHeight = tagFixedPage.Attributes["Height"];
foreach (MarkupElement el in tagFixedPage.Elements)
{
MarkupTagElement tag = (el as MarkupTagElement);
if (tag == null) continue;
switch (tag.Name)
{
case "Glyphs":
{
break;
}
case "Path":
{
break;
}
}
}
}
}
protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
{
FixedPageObjectModel fpage = (objectModels.Pop() as FixedPageObjectModel);
MarkupObjectModel mom = new MarkupObjectModel();
MarkupTagElement tagFixedPage = new MarkupTagElement();
tagFixedPage.FullName = "FixedPage";
tagFixedPage.Attributes.Add("xmlns", XPSSchemas.GetSchema(SchemaVersion, XPSSchemaType.FixedPage));
if (!String.IsNullOrEmpty(Generator.Name))
tagFixedPage.Elements.Add(new MarkupCommentElement(Generator.Name + " Generated! Version: " + Generator.Version.ToString()));
// TODO: glyphs, paths, etc.
foreach (FixedPageItem item in fpage.Items)
{
if (item is Glyph)
{
Glyph glyph = (item as Glyph);
MarkupTagElement tagGlyph = new MarkupTagElement();
tagGlyph.FullName = "Glyphs";
tagGlyph.Attributes.Add("Fill", glyph.FillColor.ToHexadecimalHTML());
// tagGlyph.Attributes.Add("FontUri", glyph.FontURI);
tagGlyph.Attributes.Add("FontRenderingEmSize", glyph.FontRenderingEmSize.ToString());
tagGlyph.Attributes.Add("Indices", GetIndices(glyph.Text));
tagGlyph.Attributes.Add("UnicodeString", glyph.Text);
tagFixedPage.Elements.Add(tagGlyph);
}
else if (item is Path)
{
MarkupTagElement tagPath = new MarkupTagElement();
tagPath.FullName = "Path";
tagFixedPage.Elements.Add(tagPath);
}
}
mom.Elements.Add(tagFixedPage);
objectModels.Push(mom);
base.BeforeSaveInternal(objectModels);
}
public static Dictionary<char, int> _indices = new Dictionary<char, int>();
static FPAGEDataFormat()
{
_indices.Add(' ', 3);
for (int i = 0; i < 26; i++)
{
_indices.Add((char)((int)'A' + i), (int)(((int)'A' + i) + 35));
}
for (int i = 0; i < 26; i++)
{
_indices.Add((char)((int)'a' + i), (int)(((int)'a' + i) + 68));
}
}
/// <summary>
/// returns the indices associated with the given string
/// </summary>
/// <returns>The indices.</returns>
/// <param name="value">Value.</param>
public string GetIndices(string value)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < value.Length; i++)
{
sb.Append(_indices[value[i]].ToString());
if (i < value.Length - 1)
{
sb.Append(';');
}
}
return sb.ToString();
}
}
}

View File

@ -21,11 +21,14 @@
using System;
using UniversalEditor.DataFormats.Package.OpenPackagingConvention;
using UniversalEditor.DataFormats.Text.Formatted.XPS.FixedDocument;
using UniversalEditor.DataFormats.Text.Formatted.XPS.FixedDocumentSequence;
using UniversalEditor.DataFormats.Text.Formatted.XPS.FixedPage;
using UniversalEditor.DataFormats.Text.Formatted.XPS.PrintTicket;
using UniversalEditor.ObjectModels.FileSystem;
using UniversalEditor.ObjectModels.Package;
using UniversalEditor.ObjectModels.Text.Formatted;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocument;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocumentSequence;
using UniversalEditor.ObjectModels.Text.Formatted.XPS.PrintTicket;
@ -43,6 +46,13 @@ namespace UniversalEditor.DataFormats.Text.Formatted.XPS
}
return _dfr;
}
private static System.Collections.Generic.Dictionary<XPSSchemaKey, string> Schemas = new System.Collections.Generic.Dictionary<XPSSchemaKey, string>();
static XPSDataFormat()
{
}
public XPSSchemaVersion SchemaVersion { get; set; } = XPSSchemaVersion.OpenXPS;
protected override void BeforeLoadInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)
{
@ -57,17 +67,19 @@ namespace UniversalEditor.DataFormats.Text.Formatted.XPS
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");
File[] files = package.GetFilesBySchema(XPSSchemas.GetSchema(SchemaVersion, XPSSchemaType.FixedRepresentation));
// get the related print tickets
File[] printTickets = package.GetFilesBySchema("http://schemas.microsoft.com/xps/2005/06/printticket", "FixedDocumentSequence.fdseq");
File[] printTickets = package.GetFilesBySchema(XPSSchemas.GetSchema(SchemaVersion, XPSSchemaType.PrintTicket), "FixedDocumentSequence.fdseq");
PrintTicketObjectModel printTicket = printTickets[0].GetObjectModel<PrintTicketObjectModel>(new PrintTicketXMLDataFormat());
FixedDocumentSequenceObjectModel fdom = files[0].GetObjectModel<FixedDocumentSequenceObjectModel>(new FDSEQDataFormat());
File fdoc = package.FileSystem.FindFile(fdom.DocumentReferences[0].Source.Substring(1));
File fileFDOC = package.FileSystem.FindFile(fdom.DocumentReferences[0].Source.Substring(1));
FixedDocumentObjectModel fdoc = fileFDOC.GetObjectModel<FixedDocumentObjectModel>(new FDOCDataFormat(SchemaVersion));
// FixedDocument fdoc = file.GetObjectModel<FixedDocumentObjectModel>(new FDOCDataFormat());
}
protected override void BeforeSaveInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)
@ -75,6 +87,35 @@ namespace UniversalEditor.DataFormats.Text.Formatted.XPS
FormattedTextObjectModel text = (objectModels.Pop() as FormattedTextObjectModel);
PackageObjectModel package = new PackageObjectModel();
package.DefaultContentTypes.Add("fdseq", "application/vnd.ms-package.xps-fixeddocumentsequence+xml");
package.DefaultContentTypes.Add("fdoc", "application/vnd.ms-package.xps-fixeddocument+xml");
package.DefaultContentTypes.Add("fpage", "application/vnd.ms-package.xps-fixedpage+xml");
package.DefaultContentTypes.Add("odttf", "application/vnd.ms-package.obfuscated-opentype");
package.DefaultContentTypes.Add("xml", "application/vnd.ms-printing.printticket+xml");
package.DefaultContentTypes.Add("JPG", "image/jpeg");
FixedDocumentObjectModel fdoc = new FixedDocumentObjectModel();
Folder fldDocuments = package.FileSystem.Folders.Add("Documents");
Folder fldDocument1 = fldDocuments.Folders.Add("1");
Folder fldDocument1Metadata = fldDocument1.Folders.Add("Metadata");
for (int i = 0; i < 1; i++)
{
File fldDocument1MetadataPage1PT = new File();
fldDocument1MetadataPage1PT.Name = "Page" + (i + 1).ToString() + "_PT.xml";
PrintTicketObjectModel pt = new PrintTicketObjectModel();
fldDocument1MetadataPage1PT.SetObjectModel<PrintTicketObjectModel>(new PrintTicketXMLDataFormat(), pt);
File fldDocument1MetadataPage1Thumbnail = new File();
fldDocument1MetadataPage1Thumbnail.Name = "Page" + (i + 1).ToString() + "_Thumbnail.JPG";
}
FPAGEDataFormat fpageDF = new FPAGEDataFormat();
fpageDF.Generator = new XPSGenerator("Universal Editor", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
fpageDF.SchemaVersion = SchemaVersion;
objectModels.Push(package);
}

View File

@ -0,0 +1,15 @@
using System;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
public struct XPSGenerator
{
public string Name;
public Version Version;
public XPSGenerator(string name, Version version)
{
Name = name;
Version = version;
}
}
}

View File

@ -0,0 +1,15 @@
using System;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
public struct XPSSchemaKey
{
public XPSSchemaVersion Version;
public XPSSchemaType Type;
public XPSSchemaKey(XPSSchemaVersion version, XPSSchemaType type)
{
Version = version;
Type = type;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
public enum XPSSchemaType
{
FixedDocument,
FixedRepresentation,
FixedPage,
PrintTicket,
Thumbnail
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
public enum XPSSchemaVersion
{
XPS,
OpenXPS
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
{
public static class XPSSchemas
{
private static Dictionary<XPSSchemaKey, string> _Schema = new Dictionary<XPSSchemaKey, string>();
public static string GetSchema(XPSSchemaVersion version, XPSSchemaType type)
{
if (_Schema.ContainsKey(new XPSSchemaKey(version, type)))
return _Schema[new XPSSchemaKey(version, type)];
return null;
}
static XPSSchemas()
{
_Schema[new XPSSchemaKey(XPSSchemaVersion.XPS, XPSSchemaType.FixedRepresentation)] = "http://schemas.microsoft.com/xps/2005/06/fixedrepresentation";
_Schema[new XPSSchemaKey(XPSSchemaVersion.XPS, XPSSchemaType.PrintTicket)] = "http://schemas.microsoft.com/xps/2005/06/printticket";
_Schema[new XPSSchemaKey(XPSSchemaVersion.XPS, XPSSchemaType.Thumbnail)] = "http://schemas.microsoft.com/xps/2005/06/printticket";
_Schema[new XPSSchemaKey(XPSSchemaVersion.XPS, XPSSchemaType.FixedDocument)] = "http://schemas.microsoft.com/xps/2005/06";
_Schema[new XPSSchemaKey(XPSSchemaVersion.XPS, XPSSchemaType.FixedPage)] = "http://schemas.microsoft.com/xps/2005/06";
_Schema[new XPSSchemaKey(XPSSchemaVersion.OpenXPS, XPSSchemaType.FixedRepresentation)] = "http://schemas.openxps.org/oxps/v1.0/fixedrepresentation";
_Schema[new XPSSchemaKey(XPSSchemaVersion.OpenXPS, XPSSchemaType.PrintTicket)] = "http://schemas.openxps.org/oxps/v1.0/printticket";
_Schema[new XPSSchemaKey(XPSSchemaVersion.OpenXPS, XPSSchemaType.Thumbnail)] = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; //yes this is the same as OpenXPS
_Schema[new XPSSchemaKey(XPSSchemaVersion.OpenXPS, XPSSchemaType.FixedDocument)] = "http://schemas.openxps.org/oxps/v1.0";
_Schema[new XPSSchemaKey(XPSSchemaVersion.OpenXPS, XPSSchemaType.FixedPage)] = "http://schemas.openxps.org/oxps/v1.0";
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocument
{
public class FixedDocumentObjectModel : ObjectModel
{
public PageContent.PageContentCollection PageContents { get; } = new PageContent.PageContentCollection();
public override void Clear()
{
PageContents.Clear();
}
public override void CopyTo(ObjectModel where)
{
FixedDocumentObjectModel clone = (where as FixedDocumentObjectModel);
if (clone == null) return;
foreach (PageContent pcoc in PageContents)
{
clone.PageContents.Add(pcoc.Clone() as PageContent);
}
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedDocument
{
public class PageContent : ICloneable
{
public class PageContentCollection
: System.Collections.ObjectModel.Collection<PageContent>
{
}
public string Source { get; set; } = String.Empty;
public PageContent(string source)
{
Source = source;
}
public object Clone()
{
PageContent clone = new PageContent(Source.Clone() as string);
return clone;
}
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedPage
{
public abstract class FixedPageItem
{
public class FixedPageItemCollection
: System.Collections.ObjectModel.Collection<FixedPageItem>
{
}
}
}

View File

@ -0,0 +1,21 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedPage
{
public class FixedPageObjectModel : ObjectModel
{
// public Measurement Width { get; set; }
// public Measurement Height { get; set; }
public FixedPageItem.FixedPageItemCollection Items { get; } = new FixedPageItem.FixedPageItemCollection();
public override void Clear()
{
throw new NotImplementedException();
}
public override void CopyTo(ObjectModel where)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,17 @@
using System;
using MBS.Framework.Drawing;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedPage
{
public class Glyph : FixedPageItem
{
public Color FillColor { get; set; } = Color.Empty;
public double FontRenderingEmSize { get; set; } = 16.0006;
public XPSStyleSimulations StyleSimulations { get; set; } = XPSStyleSimulations.None;
public double OriginX { get; set; } = 0.0;
public double OriginY { get; set; } = 0.0;
public string Text { get; set; } = String.Empty;
}
}

View File

@ -0,0 +1,8 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS.FixedPage
{
public class Path : FixedPageItem
{
}
}

View File

@ -0,0 +1,8 @@
using System;
namespace UniversalEditor.ObjectModels.Text.Formatted.XPS
{
public enum XPSStyleSimulations
{
None
}
}

View File

@ -115,6 +115,20 @@
<Compile Include="DataFormats\PropertyList\Registry\MicrosoftRegistryKeyValueDataType.cs" />
<Compile Include="DataFormats\PropertyList\Registry\MicrosoftRegistryKeyValueFlags.cs" />
<Compile Include="ObjectModels\Package\ContentTypes\OverrideDefinition.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\XPSSchemaType.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\XPSSchemaVersion.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\XPSSchemaKey.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedDocument\FixedDocumentObjectModel.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\FixedDocument\FDOCDataFormat.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedDocument\PageContent.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\XPSSchemas.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\XPSGenerator.cs" />
<Compile Include="DataFormats\Text\Formatted\XPS\FixedPage\FPAGEDataFormat.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedPage\FixedPageObjectModel.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedPage\Glyph.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedPage\FixedPageItem.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\XPSStyleSimulations.cs" />
<Compile Include="ObjectModels\Text\Formatted\XPS\FixedPage\Path.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Compression\UniversalEditor.Compression.csproj">
@ -137,6 +151,10 @@
<Project>{8622EBC4-8E20-476E-B284-33D472081F5C}</Project>
<Name>UniversalEditor.UserInterface</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\MBS.Framework\MBS.Framework\MBS.Framework.csproj">
<Project>{23ACD09E-E096-4B05-A6CE-6853EDDC589A}</Project>
<Name>MBS.Framework</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@ -151,5 +169,9 @@
<ItemGroup>
<Folder Include="DataFormats\PropertyList\" />
<Folder Include="DataFormats\PropertyList\Registry\" />
<Folder Include="ObjectModels\Text\Formatted\XPS\FixedDocument\" />
<Folder Include="DataFormats\Text\Formatted\XPS\FixedDocument\" />
<Folder Include="DataFormats\Text\Formatted\XPS\FixedPage\" />
<Folder Include="ObjectModels\Text\Formatted\XPS\FixedPage\" />
</ItemGroup>
</Project>