Skip to content
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
15 changes: 11 additions & 4 deletions OpenXmlFormats/Drawing/ShapeEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2746,9 +2746,9 @@ public class CT_BlipFillProperties
private uint dpiField;
private bool dpiFieldSpecified;

private bool rotWithShapeField;
private bool rotWithShapeField = true; // set true

private bool rotWithShapeFieldSpecified;
private bool rotWithShapeFieldSpecified = false;

public CT_Blip AddNewBlip()
{
Expand All @@ -2768,7 +2768,11 @@ public static CT_BlipFillProperties Parse(XmlNode node, XmlNamespaceManager name
return null;
CT_BlipFillProperties ctObj = new CT_BlipFillProperties();
ctObj.dpi = XmlHelper.ReadUInt(node.Attributes["dpi"]);
ctObj.rotWithShape = XmlHelper.ReadBool(node.Attributes["rotWithShape"]);
if (node.Attributes["rotWithShape"] != null)
{
ctObj.rotWithShape = XmlHelper.ReadBool(node.Attributes["rotWithShape"]);
ctObj.rotWithShapeSpecified = true;
}
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "blip")
Expand All @@ -2789,7 +2793,10 @@ internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<{0}", nodeName));
XmlHelper.WriteAttribute(sw, "dpi", this.dpi);
XmlHelper.WriteAttribute(sw, "rotWithShape", this.rotWithShape);
if (rotWithShapeSpecified && !rotWithShape)
{
XmlHelper.WriteAttribute(sw, "rotWithShape", this.rotWithShape);
}
sw.Write(">");
if (this.blip != null)
this.blip.Write(sw, "blip");
Expand Down
2 changes: 1 addition & 1 deletion main/HPSF/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Section
/// <summary>
/// This section's properties.
/// </summary>
private IDictionary<long, Property> properties = new Dictionary<long, Property>();
private Dictionary<long, Property> properties = new Dictionary<long, Property>();

/// <summary>
/// This member is <c>true</c> if the last call to {@link
Expand Down
89 changes: 89 additions & 0 deletions testcases/ooxml/TestIssue1353.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using NPOI.XWPF.UserModel;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System;
using System.IO;
using NPOI.OpenXml4Net.OPC;


namespace TestCases
{
[TestFixture]
public class TestIssue1353
{

[Test]
public void TestOutputHasNoRotWithShapeAttribute()
{
var samples = POIDataSamples.GetDocumentInstance();
string inputPath = samples.GetFileInfo("issue1353from.docx").FullName;
string projectDir = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory));
string outputPath = Path.Combine(projectDir, "issue1353to.docx");
string imagePath = samples.GetFileInfo("issue1353.png").FullName;
using FileStream fs = new(inputPath, FileMode.Open, FileAccess.Read);
XWPFDocument doc = new(fs);
XWPFTable table = doc.CreateTable(1, 1);
int row = 0;
int col = 0;
using FileStream picStream = new(imagePath, FileMode.Open, FileAccess.Read);
string picName = "image.png";
int widthEmus = 144 * 9525;
int heightEmus = 144 * 9525;
XWPFParagraph para = table.GetRow(row).GetCell(col).GetParagraphArray(0);
para.Alignment = ParagraphAlignment.LEFT;
para.SpacingAfter = 0;
para.SpacingAfterLines = 0;
para.SpacingBefore = 0;
para.SpacingBeforeLines = 0;
para.SpacingBetween = 1;
XWPFRun r = para.CreateRun();
using MemoryStream ms = new();
picStream.Position = 0;
picStream.CopyTo(ms);
ms.Position = 0;
XWPFPicture pic = r.AddPicture(ms, (int) PictureType.PNG, picName, widthEmus, heightEmus);


pic.GetCTPicture().spPr.xfrm.rot = -90 * 60000;
using(FileStream outFs = new(outputPath, FileMode.Create, FileAccess.Write))
{
doc.Write(outFs);
}
// check - Reopen the document and verify the XML content using XWPFDocument
using (FileStream checkFs = new(outputPath, FileMode.Open, FileAccess.Read))
{
XWPFDocument checkDoc = new(checkFs);
OPCPackage package = checkDoc.Package;

// Get the document.xml part by iterating through parts
PackagePart documentPart = null;
foreach (PackagePart part in package.GetParts())
{
if (part.PartName.Name.Equals("/word/document.xml", StringComparison.OrdinalIgnoreCase))
{
documentPart = part;
break;
}
}

ClassicAssert.IsNotNull(documentPart, "document.xml not found");

using (Stream stream = documentPart.GetInputStream())
using (StreamReader reader = new StreamReader(stream))
{
string xmlContent = reader.ReadToEnd();
ClassicAssert.IsFalse(xmlContent.Contains("rotWithShape"),
"document.xml should not contain 'rotWithShape'");
}
}
try
{
File.Delete(outputPath);
}
catch(Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
}
Binary file added testcases/test-data/document/issue1353.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testcases/test-data/document/issue1353from.docx
Binary file not shown.
Loading