Skip to content

Commit fae8b53

Browse files
authored
Merge pull request #44 from dotnet-campus/t/lindexi/Percentage
同步2月版本
2 parents bd6aebc + 96c2493 commit fae8b53

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ internal void AddContentType(CompatiblePackage.PackUriHelper.ValidatedPartUri pa
689689
}
690690
}
691691

692-
693692
//Returns the content type for the part, if present, else returns null.
694693
internal CompatiblePackage.ContentType? GetContentType(CompatiblePackage.PackUriHelper.ValidatedPartUri partUri)
695694
{
@@ -912,7 +911,6 @@ private void ParseContentTypesFile(
912911
}
913912
}
914913

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

10171015
// The part Uris are stored in the Override Dictionary in their original form , but they are compared
10181016
// in a normalized manner using PartUriComparer.
1019-
_overrideDictionary.Add(partUri, contentType);
1017+
_overrideDictionary?.Add(partUri, contentType);
10201018
_dirty = true;
10211019
}
10221020

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

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

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

1078-
10791075
private Dictionary<CompatiblePackage.PackUriHelper.ValidatedPartUri, CompatiblePackage.ContentType>? _overrideDictionary;
10801076
private readonly Dictionary<string, CompatiblePackage.ContentType> _defaultDictionary;
10811077
private readonly ZipArchive _zipArchive;
@@ -1105,8 +1101,11 @@ private void ThrowIfXmlAttributeMissing(string attributeName, string? attributeV
11051101
class ValidatedPartUriIgnoreCaseEqualityComparer : IEqualityComparer<
11061102
CompatiblePackage.PackUriHelper.ValidatedPartUri>
11071103
{
1108-
public bool Equals(PackUriHelper.ValidatedPartUri x, PackUriHelper.ValidatedPartUri y)
1104+
public bool Equals(PackUriHelper.ValidatedPartUri? x, PackUriHelper.ValidatedPartUri? y)
11091105
{
1106+
if (x is null && y is null) return true;
1107+
if (x is null || y is null) return false;
1108+
11101109
return StringComparer.OrdinalIgnoreCase.Equals(x.NormalizedPartUriString, y.NormalizedPartUriString);
11111110
}
11121111

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/EmptyPackagePart.cs

+35-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,42 @@ protected override string GetContentTypeCore()
8484
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml");
8585
}
8686

87-
if (Regex.IsMatch(uri, @"/ppt/diagrams/drawing\d+\.xml"))
87+
if (uri.StartsWith("/ppt/diagrams/", StringComparison.OrdinalIgnoreCase))
8888
{
89-
// /ppt/diagrams/drawing0.xml
90-
// application/vnd.ms-office.drawingml.diagramDrawing+xml
91-
return new CompatiblePackage.ContentType("application/vnd.ms-office.drawingml.diagramDrawing+xml");
89+
if (Regex.IsMatch(uri, @"/ppt/diagrams/drawing\d+\.xml"))
90+
{
91+
// /ppt/diagrams/drawing0.xml
92+
// application/vnd.ms-office.drawingml.diagramDrawing+xml
93+
return new CompatiblePackage.ContentType("application/vnd.ms-office.drawingml.diagramDrawing+xml");
94+
}
95+
96+
if (Regex.IsMatch(uri, @"/ppt/diagrams/layout\d+\.xml"))
97+
{
98+
// /ppt/diagrams/layout1.xml
99+
// application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml
100+
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml");
101+
}
102+
103+
if (Regex.IsMatch(uri, @"/ppt/diagrams/data\d+\.xml"))
104+
{
105+
// /ppt/diagrams/data1.xml
106+
// application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml
107+
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml");
108+
}
109+
110+
if (Regex.IsMatch(uri, @"/ppt/diagrams/colors\d+\.xml"))
111+
{
112+
// /ppt/diagrams/colors1.xml
113+
// application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml
114+
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml");
115+
}
116+
117+
if (Regex.IsMatch(uri, @"/ppt/diagrams/quickStyle\d+\.xml"))
118+
{
119+
// /ppt/diagrams/quickStyle1.xml
120+
// application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml
121+
return new CompatiblePackage.ContentType("application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml");
122+
}
92123
}
93124

94125
if (Regex.IsMatch(uri, @"/tags/tag\d+\.xml"))

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/ElementConverters/SmartArt/SmartArtElementFlattenConverter.cs

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ protected override GraphicFrame Convert(GraphicFrame element, ElementContext con
6969
private void FlattenDrawingElementFromData(GraphicFrame xmlElement, DiagramDataPart diagramDataPart, DiagramColorsPart? colorsPart, in ElementContext context)
7070
{
7171
var dataModelRoot = diagramDataPart.DataModelRoot;
72+
73+
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
74+
if (dataModelRoot is null)
75+
{
76+
// 这个 dataModelRoot 是可空的,请看内部 issues/627
77+
return;
78+
}
79+
7280
var connectionList = dataModelRoot.ConnectionList;
7381
var pointList = dataModelRoot.PointList;
7482
if (connectionList is null || pointList is null)

src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/OpenMcdf/OpenMcdf/Readonly/ByteArrayPool.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// ReSharper disable once CheckNamespace 特别的命名空间
1+
#nullable enable
2+
// ReSharper disable once CheckNamespace 特别的命名空间
23

34
namespace OpenMcdf
45
{

0 commit comments

Comments
 (0)