Skip to content

Commit

Permalink
fix: regression cased by migration to struct inside OpenXML v3 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-tihon committed Jan 16, 2024
1 parent 820545a commit c39a689
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "8.0.0",
"version": "8.0.3",
"commands": [
"paket"
]
Expand Down
25 changes: 13 additions & 12 deletions Clippit/PowerPoint/FluentPresentationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void SaveAndCleanup()
xd.Descendants().Attributes("smtClean").Remove();
part.PutXDocument();
}
else if (part.Annotation<XDocument>() is {})
else if (part.Annotation<XDocument>() is not null)
part.PutXDocument();
}
}
Expand All @@ -84,7 +84,7 @@ private void CopyStartingParts(PresentationDocument sourceDocument)
{
// A Core File Properties part does not have implicit or explicit relationships to other parts.
var corePart = sourceDocument.CoreFilePropertiesPart;
if (corePart?.GetXDocument().Root is {})
if (corePart?.GetXDocument().Root is not null)
{
_newDocument.AddCoreFilePropertiesPart();
var newXDoc = _newDocument.CoreFilePropertiesPart.GetXDocument();
Expand Down Expand Up @@ -143,20 +143,20 @@ private void CopyPresentationParts(PresentationDocument sourceDocument)
newPresentation.Root.Add(oldElement);

// Copy Font Parts
if (oldPresentationDoc.Root.Element(P.embeddedFontLst) is {})
if (oldPresentationDoc.Root.Element(P.embeddedFontLst) is not null)
{
var newFontLst = new XElement(P.embeddedFontLst);
foreach (var font in oldPresentationDoc.Root.Element(P.embeddedFontLst).Elements(P.embeddedFont))
{
var newEmbeddedFont = new XElement(P.embeddedFont, font.Elements(P.font));

if (font.Element(P.regular) is {})
if (font.Element(P.regular) is not null)
newEmbeddedFont.Add(CreateEmbeddedFontPart(sourceDocument, font, P.regular));
if (font.Element(P.bold) is {})
if (font.Element(P.bold) is not null)
newEmbeddedFont.Add(CreateEmbeddedFontPart(sourceDocument, font, P.bold));
if (font.Element(P.italic) is {})
if (font.Element(P.italic) is not null)
newEmbeddedFont.Add(CreateEmbeddedFontPart(sourceDocument, font, P.italic));
if (font.Element(P.boldItalic) is {})
if (font.Element(P.boldItalic) is not null)
newEmbeddedFont.Add(CreateEmbeddedFontPart(sourceDocument, font, P.boldItalic));

newFontLst.Add(newEmbeddedFont);
Expand Down Expand Up @@ -357,7 +357,7 @@ internal void AppendSlides(PresentationDocument sourceDocument, int start, int c
var newPart = newSlide.AddNewPart<NotesSlidePart>();
newPart.PutXDocument(notesSlide.GetXDocument());
newPart.AddPart(newSlide);
if (_newDocument.PresentationPart.NotesMasterPart is {})
if (_newDocument.PresentationPart.NotesMasterPart is not null)
newPart.AddPart(_newDocument.PresentationPart.NotesMasterPart);
PBT.AddRelationships(notesSlide, newPart, new[] { newPart.GetXDocument().Root });
CopyRelatedPartsForContentParts(slide.NotesSlidePart, newPart, new[] { newPart.GetXDocument().Root });
Expand Down Expand Up @@ -505,7 +505,7 @@ private void CopyTableStyles(PresentationDocument oldDocument, OpenXmlPart newCo
tableStyles = _newDocument.PresentationPart.TableStylesPart.GetXDocument();

// Search new TableStylesPart to see if it contains the ID
if (tableStyles.Root.Elements(A.tblStyle).FirstOrDefault(f => f.Attribute(NoNamespace.styleId).Value == styleId) is {})
if (tableStyles.Root.Elements(A.tblStyle).FirstOrDefault(f => f.Attribute(NoNamespace.styleId).Value == styleId) is not null)
continue;

// Copy style to new part
Expand Down Expand Up @@ -803,7 +803,7 @@ private void CopyRelatedPartsForContentParts(OpenXmlPart oldContentPart, OpenXml
_ => null
};

if (vmlDrawingParts is {})
if (vmlDrawingParts is not null)
{
// Transitional: Copy VML Drawing parts, implicit relationship
foreach (var vmlPart in vmlDrawingParts)
Expand Down Expand Up @@ -863,7 +863,8 @@ private void CopyRelatedImage(OpenXmlPart oldContentPart, OpenXmlPart newContent
if (newContentPart.HasRelationship(relId))
return;

if (oldContentPart.Parts.FirstOrDefault(p => p.RelationshipId == relId) is {} oldPartIdPair)
var oldPartIdPair = oldContentPart.Parts.FirstOrDefault(p => p.RelationshipId == relId);
if (oldPartIdPair != default)
{
var oldPart = oldPartIdPair.OpenXmlPart as ImagePart;
var temp = ManageImageCopy(oldPart);
Expand Down Expand Up @@ -1042,7 +1043,7 @@ private void CopyRelatedMedia(OpenXmlPart oldContentPart, OpenXmlPart newContent
};

var existingRel = temp.ContentPartRelTypeIdList.FirstOrDefault(cp => cp.ContentPart == newContentPart && cp.RelationshipType == desiredRelType);
if (existingRel is {})
if (existingRel is not null)
{
imageReference.Attribute(attributeName).Set(existingRel.RelationshipId);
}
Expand Down
2 changes: 1 addition & 1 deletion Clippit/PowerPoint/PresentationBuilderTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ internal static void AddRelationships(OpenXmlPart oldPart, OpenXmlPart newPart,
continue;
}
var tempHyperlink = newPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
if (tempHyperlink is {})
if (tempHyperlink is not null)
continue;
var newRid = Relationships.GetNewRelationshipId();
var oldHyperlink = oldPart.HyperlinkRelationships.FirstOrDefault(h => h.Id == relId);
Expand Down
4 changes: 4 additions & 0 deletions Clippit/PtOpenXmlUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,8 @@ class ImageData : ContentData

public ImageData(ImagePart part)
{
ArgumentNullException.ThrowIfNull(part);

ContentType = part.ContentType;
using var s = part.GetStream();
Hash = s.ComputeHash();
Expand All @@ -1848,6 +1850,8 @@ class MediaData : ContentData

public MediaData(DataPart part)
{
ArgumentNullException.ThrowIfNull(part);

ContentType = part.ContentType;
using var s = part.GetStream();
Hash = s.ComputeHash();
Expand Down
3 changes: 1 addition & 2 deletions Clippit/Word/FormattingAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,8 +1771,7 @@ private static XElement FontMerge(XElement higherPriorityFont, XElement lowerPri
return lowerPriorityFont;
if (lowerPriorityFont == null)
return higherPriorityFont;
if (higherPriorityFont == null && lowerPriorityFont == null)
return null;


var rFonts = new XElement(W.rFonts,
(higherPriorityFont.Attribute(W.ascii) != null || higherPriorityFont.Attribute(W.asciiTheme) != null) ?
Expand Down
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#### 2.0.1 Jan 16, 2024
- Fix regression cased by migration to struct inside OpenXML v3
- DocumentFormat.OpenXml 3.0 -> 3.0.1
- SixLabors.Fonts 2.0 -> 2.0.1
- SixLabors.ImageSharp 3.0.2 -> 3.1.2
- SixLabors.ImageSharp.Drawing 2.0.1 -> 2.1.0

#### 2.0.0 Nov 26, 2023
- Migration to .NET 6.0
- DocumentFormat.OpenXml 3.0.0-beta0003
Expand Down
48 changes: 22 additions & 26 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ STORAGE: NONE
RESTRICTION: == net6.0
NUGET
remote: https://api.nuget.org/v3/index.json
DocumentFormat.OpenXml (3.0)
DocumentFormat.OpenXml.Framework (>= 3.0)
DocumentFormat.OpenXml.Framework (3.0)
DocumentFormat.OpenXml (3.0.1)
DocumentFormat.OpenXml.Framework (>= 3.0.1)
DocumentFormat.OpenXml.Framework (3.0.1)
System.IO.Packaging (>= 8.0)
IDisposableAnalyzers (4.0.7)
Microsoft.CodeCoverage (17.8)
Expand All @@ -18,15 +18,13 @@ NUGET
Microsoft.TestPlatform.TestHost (17.8)
Microsoft.TestPlatform.ObjectModel (>= 17.8)
Newtonsoft.Json (>= 13.0.1)
NETStandard.Library (2.0.3)
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (13.0.3)
NuGet.Frameworks (6.8)
SixLabors.Fonts (2.0)
SixLabors.ImageSharp (3.0.2)
SixLabors.ImageSharp.Drawing (2.0.1)
SixLabors.Fonts (>= 2.0)
SixLabors.ImageSharp (>= 3.0.2)
SixLabors.Fonts (2.0.1)
SixLabors.ImageSharp (3.1.2)
SixLabors.ImageSharp.Drawing (2.1)
SixLabors.Fonts (>= 2.0.1)
SixLabors.ImageSharp (>= 3.1)
System.Collections.Immutable (8.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.IO.Packaging (8.0)
Expand All @@ -35,21 +33,19 @@ NUGET
System.Runtime.CompilerServices.Unsafe (6.0)
System.Text.Encoding.CodePages (8.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
xunit (2.6.2)
xunit.analyzers (>= 1.6)
xunit.assert (>= 2.6.2)
xunit.core (2.6.2)
xunit (2.6.6)
xunit.analyzers (>= 1.10)
xunit.assert (>= 2.6.6)
xunit.core (2.6.6)
xunit.abstractions (2.0.3)
xunit.analyzers (1.6)
xunit.assert (2.6.2)
xunit.core (2.6.2)
xunit.extensibility.core (2.6.2)
xunit.extensibility.execution (2.6.2)
xunit.extensibility.core (2.6.2)
NETStandard.Library (>= 1.6.1)
xunit.analyzers (1.10)
xunit.assert (2.6.6)
xunit.core (2.6.6)
xunit.extensibility.core (2.6.6)
xunit.extensibility.execution (2.6.6)
xunit.extensibility.core (2.6.6)
xunit.abstractions (>= 2.0.3)
xunit.extensibility.execution (2.6.2)
NETStandard.Library (>= 1.6.1)
xunit.extensibility.core (2.6.2)
xunit.runner.console (2.6.2)
xunit.runner.visualstudio (2.5.4)
xunit.extensibility.execution (2.6.6)
xunit.extensibility.core (2.6.6)
xunit.runner.console (2.6.6)
xunit.runner.visualstudio (2.5.6)

0 comments on commit c39a689

Please sign in to comment.