From 96c2493f5339dc1999176e15d6535c917ef2f9ba Mon Sep 17 00:00:00 2001 From: lindexi Date: Mon, 25 Mar 2024 15:52:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A52=E6=9C=88=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Packaging/CompatiblePackage.cs | 11 +++--- .../Packaging/EmptyPackagePart.cs | 39 +++++++++++++++++-- .../SmartArtElementFlattenConverter.cs | 8 ++++ .../OpenMcdf/Readonly/ByteArrayPool.cs | 3 +- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs index 1cee884..c369143 100644 --- a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs +++ b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs @@ -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) { @@ -912,7 +911,6 @@ private void ParseContentTypesFile( } } - // If an atomic file was found, open a stream on it. if (_contentTypeZipArchiveEntry != null) { @@ -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; } @@ -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, @@ -1075,7 +1072,6 @@ private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeV internal Dictionary GetDefaultDictionary() => _defaultDictionary; - private Dictionary? _overrideDictionary; private readonly Dictionary _defaultDictionary; private readonly ZipArchive _zipArchive; @@ -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); } diff --git a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/EmptyPackagePart.cs b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/EmptyPackagePart.cs index 9feb694..194f3be 100644 --- a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/EmptyPackagePart.cs +++ b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/EmptyPackagePart.cs @@ -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")) diff --git a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/SmartArt/SmartArtElementFlattenConverter.cs b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/SmartArt/SmartArtElementFlattenConverter.cs index bbd3431..939cd0e 100644 --- a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/SmartArt/SmartArtElementFlattenConverter.cs +++ b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/SmartArt/SmartArtElementFlattenConverter.cs @@ -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) diff --git a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/OpenMcdf/OpenMcdf/Readonly/ByteArrayPool.cs b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/OpenMcdf/OpenMcdf/Readonly/ByteArrayPool.cs index 4b40a46..65180c5 100644 --- a/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/OpenMcdf/OpenMcdf/Readonly/ByteArrayPool.cs +++ b/src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/OpenMcdf/OpenMcdf/Readonly/ByteArrayPool.cs @@ -1,4 +1,5 @@ -// ReSharper disable once CheckNamespace 特别的命名空间 +#nullable enable +// ReSharper disable once CheckNamespace 特别的命名空间 namespace OpenMcdf {