Skip to content

Commit

Permalink
同步2月版本
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Mar 25, 2024
1 parent 3a8087c commit 96c2493
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ internal void AddContentType(CompatiblePackage.PackUriHelper.ValidatedPartUri pa
}
}


//Returns the content type for the part, if present, else returns null.
internal CompatiblePackage.ContentType? GetContentType(CompatiblePackage.PackUriHelper.ValidatedPartUri partUri)
{
Expand Down Expand Up @@ -912,7 +911,6 @@ private void ParseContentTypesFile(
}
}


// If an atomic file was found, open a stream on it.
if (_contentTypeZipArchiveEntry != null)
{
Expand Down Expand Up @@ -1016,7 +1014,7 @@ private void AddOverrideElement(CompatiblePackage.PackUriHelper.ValidatedPartUri

// The part Uris are stored in the Override Dictionary in their original form , but they are compared
// in a normalized manner using PartUriComparer.
_overrideDictionary.Add(partUri, contentType);
_overrideDictionary?.Add(partUri, contentType);
_dirty = true;
}

Expand Down Expand Up @@ -1059,7 +1057,6 @@ private void ValidateXmlAttribute(string attributeName, string? attributeValue,
((IXmlLineInfo) reader).LineNumber, ((IXmlLineInfo) reader).LinePosition);
}


//Validate if the required Content type XML attribute is present
//Content type of a part can be empty
private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeValue, string tagName,
Expand All @@ -1075,7 +1072,6 @@ private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeV

internal Dictionary<string, CompatiblePackage.ContentType> GetDefaultDictionary() => _defaultDictionary;


private Dictionary<CompatiblePackage.PackUriHelper.ValidatedPartUri, CompatiblePackage.ContentType>? _overrideDictionary;
private readonly Dictionary<string, CompatiblePackage.ContentType> _defaultDictionary;
private readonly ZipArchive _zipArchive;
Expand Down Expand Up @@ -1105,8 +1101,11 @@ private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeV
class ValidatedPartUriIgnoreCaseEqualityComparer : IEqualityComparer<
CompatiblePackage.PackUriHelper.ValidatedPartUri>
{
public bool Equals(PackUriHelper.ValidatedPartUri x, PackUriHelper.ValidatedPartUri y)
public bool Equals(PackUriHelper.ValidatedPartUri? x, PackUriHelper.ValidatedPartUri? y)
{
if (x is null && y is null) return true;
if (x is null || y is null) return false;

return StringComparer.OrdinalIgnoreCase.Equals(x.NormalizedPartUriString, y.NormalizedPartUriString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,42 @@ protected override string GetContentTypeCore()
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml");
}

if (Regex.IsMatch(uri, @"/ppt/diagrams/drawing\d+\.xml"))
if (uri.StartsWith("/ppt/diagrams/", StringComparison.OrdinalIgnoreCase))
{
// /ppt/diagrams/drawing0.xml
// application/vnd.ms-office.drawingml.diagramDrawing+xml
return new CompatiblePackage.ContentType("application/vnd.ms-office.drawingml.diagramDrawing+xml");
if (Regex.IsMatch(uri, @"/ppt/diagrams/drawing\d+\.xml"))
{
// /ppt/diagrams/drawing0.xml
// application/vnd.ms-office.drawingml.diagramDrawing+xml
return new CompatiblePackage.ContentType("application/vnd.ms-office.drawingml.diagramDrawing+xml");
}

if (Regex.IsMatch(uri, @"/ppt/diagrams/layout\d+\.xml"))
{
// /ppt/diagrams/layout1.xml
// application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml");
}

if (Regex.IsMatch(uri, @"/ppt/diagrams/data\d+\.xml"))
{
// /ppt/diagrams/data1.xml
// application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml");
}

if (Regex.IsMatch(uri, @"/ppt/diagrams/colors\d+\.xml"))
{
// /ppt/diagrams/colors1.xml
// application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml");
}

if (Regex.IsMatch(uri, @"/ppt/diagrams/quickStyle\d+\.xml"))
{
// /ppt/diagrams/quickStyle1.xml
// application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml");
}
}

if (Regex.IsMatch(uri, @"/tags/tag\d+\.xml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ protected override GraphicFrame Convert(GraphicFrame element, ElementContext con
private void FlattenDrawingElementFromData(GraphicFrame xmlElement, DiagramDataPart diagramDataPart, DiagramColorsPart? colorsPart, in ElementContext context)
{
var dataModelRoot = diagramDataPart.DataModelRoot;

// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
if (dataModelRoot is null)
{
// 这个 dataModelRoot 是可空的,请看内部 issues/627
return;
}

var connectionList = dataModelRoot.ConnectionList;
var pointList = dataModelRoot.PointList;
if (connectionList is null || pointList is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable once CheckNamespace 特别的命名空间
#nullable enable
// ReSharper disable once CheckNamespace 特别的命名空间

namespace OpenMcdf
{
Expand Down

0 comments on commit 96c2493

Please sign in to comment.