Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同步2月版本 #44

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
// The following test will filter out an atomic content type file, with name
// "[Content_Types].xml", as well as an interleaved one, with piece names such as
// "[Content_Types].xml/[0].piece" or "[Content_Types].xml/[5].last.piece".
if (zipItemName.StartsWith(ContentTypeHelper.ContentTypeFileName, StringComparison.OrdinalIgnoreCase))

Check warning on line 514 in src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
return false;
else
{
Expand Down Expand Up @@ -588,7 +588,7 @@
//with the rules for comparing/normalizing partnames.
//Refer to PackUriHelper.ValidatedPartUri.GetNormalizedPartUri method.
//Currently normalization just involves upper-casing ASCII and hence the simplification.
return (string.CompareOrdinal(extensionA.ToUpperInvariant(), extensionB.ToUpperInvariant()) == 0);

Check warning on line 591 in src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 591 in src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

int IEqualityComparer<string>.GetHashCode(string extension)
Expand All @@ -599,7 +599,7 @@
//with the rules for comparing/normalizing partnames.
//Refer to PackUriHelper.ValidatedPartUri.GetNormalizedPartUri method.
//Currently normalization just involves upper-casing ASCII and hence the simplification.
return extension.ToUpperInvariant().GetHashCode();

Check warning on line 602 in src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}

Expand Down Expand Up @@ -689,7 +689,6 @@
}
}


//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 @@
}
}


// If an atomic file was found, open a stream on it.
if (_contentTypeZipArchiveEntry != null)
{
Expand Down Expand Up @@ -978,7 +976,7 @@

// 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, new CompatiblePackage.ContentType(contentTypeAttributeValue!));

Check warning on line 979 in src/DocumentFormat.OpenXml.Flatten/DocumentFormat.OpenXml.Flatten/Compatibilities/Packaging/CompatiblePackage.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

//Skip the EndElement for Override Tag
if (!reader.IsEmptyElement)
Expand Down Expand Up @@ -1016,7 +1014,7 @@

// 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 @@
((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 @@

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 @@
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
Loading