public void TestChildAnchorFromScratch() { HSSFChildAnchor anchor = new HSSFChildAnchor(); EscherChildAnchorRecord escher = (EscherChildAnchorRecord)HSSFTestHelper.GetEscherAnchor(anchor); anchor.SetAnchor(11, 12, 13, 14); Assert.AreEqual(anchor.Dx1, 11); Assert.AreEqual(escher.Dx1, 11); Assert.AreEqual(anchor.Dx2, 13); Assert.AreEqual(escher.Dx2, 13); Assert.AreEqual(anchor.Dy1, 12); Assert.AreEqual(escher.Dy1, 12); Assert.AreEqual(anchor.Dy2, 14); Assert.AreEqual(escher.Dy2, 14); anchor.Dx1 = (115); Assert.AreEqual(anchor.Dx1, 115); Assert.AreEqual(escher.Dx1, 115); anchor.Dx2 = (116); Assert.AreEqual(anchor.Dx2, 116); Assert.AreEqual(escher.Dx2, 116); anchor.Dy1 = (117); Assert.AreEqual(anchor.Dy1, 117); Assert.AreEqual(escher.Dy1, 117); anchor.Dy2 = (118); Assert.AreEqual(anchor.Dy2, 118); Assert.AreEqual(escher.Dy2, 118); }
/// <summary> /// Creates the anchor. /// </summary> /// <param name="userAnchor">The user anchor.</param> /// <returns></returns> public static EscherRecord CreateAnchor(HSSFAnchor userAnchor) { if (userAnchor is HSSFClientAnchor) { HSSFClientAnchor a = (HSSFClientAnchor)userAnchor; EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); anchor.RecordId = EscherClientAnchorRecord.RECORD_ID; anchor.Options = (short)0x0000; anchor.Flag = (short)a.AnchorType; anchor.Col1 = (short)Math.Min(a.Col1, a.Col2); anchor.Dx1 = (short)a.Dx1; anchor.Row1 = (short)Math.Min(a.Row1, a.Row2); anchor.Dy1 = (short)a.Dy1; anchor.Col2 = (short)Math.Max(a.Col1, a.Col2); anchor.Dx2 = (short)a.Dx2; anchor.Row2 = (short)Math.Max(a.Row1, a.Row2); anchor.Dy2 = (short)a.Dy2; return(anchor); } else { HSSFChildAnchor a = (HSSFChildAnchor)userAnchor; EscherChildAnchorRecord anchor = new EscherChildAnchorRecord(); anchor.RecordId = EscherChildAnchorRecord.RECORD_ID; anchor.Options = (short)0x0000; anchor.Dx1 = (short)Math.Min(a.Dx1, a.Dx2); anchor.Dy1 = (short)Math.Min(a.Dy1, a.Dy2); anchor.Dx2 = (short)Math.Max(a.Dx2, a.Dx1); anchor.Dy2 = (short)Math.Max(a.Dy2, a.Dy1); return(anchor); } }
public void TestNullReferenceIsFalse() { HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); Assert.IsFalse(clientAnchor.Equals(null), "Passing null to equals should return false"); HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3); Assert.IsFalse(childAnchor.Equals(null), "Passing null to equals should return false"); }
public void TestPassIncompatibleTypeIsFalse() { HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); Assert.AreNotSame(clientAnchor, "wrongType"); HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3); Assert.AreNotSame(childAnchor, "wrongType"); }
public void TestEqualsToSelf() { HSSFClientAnchor clientAnchor = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); Assert.AreEqual(clientAnchor, clientAnchor); HSSFChildAnchor childAnchor = new HSSFChildAnchor(0, 1, 2, 3); Assert.AreEqual(childAnchor, childAnchor); }
public void TestEqualsIsReflexiveIsSymmetric() { HSSFClientAnchor clientAnchor1 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); HSSFClientAnchor clientAnchor2 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); Assert.IsTrue(clientAnchor1.Equals(clientAnchor2)); Assert.IsTrue(clientAnchor1.Equals(clientAnchor2)); HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3); HSSFChildAnchor childAnchor2 = new HSSFChildAnchor(0, 1, 2, 3); Assert.IsTrue(childAnchor1.Equals(childAnchor2)); Assert.IsTrue(childAnchor2.Equals(childAnchor1)); }
public void TestChildAnchorFromEscher() { EscherChildAnchorRecord escher = new EscherChildAnchorRecord(); escher.Dx1 = ((short)15); escher.Dx2 = ((short)16); escher.Dy1 = ((short)17); escher.Dy2 = ((short)18); HSSFChildAnchor anchor = new HSSFChildAnchor(escher); Assert.AreEqual(anchor.Dx1, 15); Assert.AreEqual(escher.Dx1, 15); Assert.AreEqual(anchor.Dx2, 16); Assert.AreEqual(escher.Dx2, 16); Assert.AreEqual(anchor.Dy1, 17); Assert.AreEqual(escher.Dy1, 17); Assert.AreEqual(anchor.Dy2, 18); Assert.AreEqual(escher.Dy2, 18); }
public void TestCreateChildAnchorFromContainer() { EscherContainerRecord container = new EscherContainerRecord(); EscherChildAnchorRecord escher = new EscherChildAnchorRecord(); escher.Dx1 = ((short)15); escher.Dx2 = ((short)16); escher.Dy1 = ((short)17); escher.Dy2 = ((short)18); container.AddChildRecord(escher); HSSFChildAnchor anchor = (HSSFChildAnchor)HSSFAnchor.CreateAnchorFromEscher(container); Assert.AreEqual(anchor.Dx1, 15); Assert.AreEqual(escher.Dx1, 15); Assert.AreEqual(anchor.Dx2, 16); Assert.AreEqual(escher.Dx2, 16); Assert.AreEqual(anchor.Dy1, 17); Assert.AreEqual(escher.Dy1, 17); Assert.AreEqual(anchor.Dy2, 18); Assert.AreEqual(escher.Dy2, 18); }
public void TestDefaultValues() { HSSFClientAnchor clientAnchor = new HSSFClientAnchor(); Assert.AreEqual(clientAnchor.AnchorType, 0); Assert.AreEqual(clientAnchor.Col1, 0); Assert.AreEqual(clientAnchor.Col2, 0); Assert.AreEqual(clientAnchor.Dx1, 0); Assert.AreEqual(clientAnchor.Dx2, 0); Assert.AreEqual(clientAnchor.Dy1, 0); Assert.AreEqual(clientAnchor.Dy2, 0); Assert.AreEqual(clientAnchor.Row1, 0); Assert.AreEqual(clientAnchor.Row2, 0); clientAnchor = new HSSFClientAnchor(new EscherClientAnchorRecord()); Assert.AreEqual(clientAnchor.AnchorType, 0); Assert.AreEqual(clientAnchor.Col1, 0); Assert.AreEqual(clientAnchor.Col2, 0); Assert.AreEqual(clientAnchor.Dx1, 0); Assert.AreEqual(clientAnchor.Dx2, 0); Assert.AreEqual(clientAnchor.Dy1, 0); Assert.AreEqual(clientAnchor.Dy2, 0); Assert.AreEqual(clientAnchor.Row1, 0); Assert.AreEqual(clientAnchor.Row2, 0); HSSFChildAnchor childAnchor = new HSSFChildAnchor(); Assert.AreEqual(childAnchor.Dx1, 0); Assert.AreEqual(childAnchor.Dx2, 0); Assert.AreEqual(childAnchor.Dy1, 0); Assert.AreEqual(childAnchor.Dy2, 0); childAnchor = new HSSFChildAnchor(new EscherChildAnchorRecord()); Assert.AreEqual(childAnchor.Dx1, 0); Assert.AreEqual(childAnchor.Dx2, 0); Assert.AreEqual(childAnchor.Dy1, 0); Assert.AreEqual(childAnchor.Dy2, 0); }
public void Best49423() { HSSFWorkbook workbook = HSSFTestDataSamples.OpenSampleWorkbook("49423.xls"); bool found = false; int numSheets = workbook.NumberOfSheets; for (int i = 0; i < numSheets; i++) { HSSFSheet sheet = workbook.GetSheetAt(i) as HSSFSheet; IList <HSSFShape> shapes = (sheet.DrawingPatriarch as HSSFPatriarch).Children; foreach (HSSFShape shape in shapes) { HSSFAnchor anchor = shape.Anchor; if (anchor is HSSFClientAnchor) { // absolute coordinates HSSFClientAnchor clientAnchor = (HSSFClientAnchor)anchor; Assert.IsNotNull(clientAnchor); //System.out.Println(clientAnchor.Row1 + "," + clientAnchor.Row2); found = true; } else if (anchor is HSSFChildAnchor) { // shape is grouped and the anchor is expressed in the coordinate system of the group HSSFChildAnchor childAnchor = (HSSFChildAnchor)anchor; Assert.IsNotNull(childAnchor); //System.out.Println(childAnchor.Dy1 + "," + childAnchor.Dy2); found = true; } } } Assert.IsTrue(found, "Should find some images via Client or Child anchors, but did not find any at all"); }
public void testFlipped() { HSSFChildAnchor child = new HSSFChildAnchor(2, 2, 1, 1); Assert.AreEqual(child.IsHorizontallyFlipped, true); Assert.AreEqual(child.IsVerticallyFlipped, true); Assert.AreEqual(child.Dx1, 1); Assert.AreEqual(child.Dx2, 2); Assert.AreEqual(child.Dy1, 1); Assert.AreEqual(child.Dy2, 2); child = new HSSFChildAnchor(3, 3, 4, 4); Assert.AreEqual(child.IsHorizontallyFlipped, false); Assert.AreEqual(child.IsVerticallyFlipped, false); Assert.AreEqual(child.Dx1, 3); Assert.AreEqual(child.Dx2, 4); Assert.AreEqual(child.Dy1, 3); Assert.AreEqual(child.Dy2, 4); HSSFClientAnchor client = new HSSFClientAnchor(1, 1, 1, 1, (short)4, 4, (short)3, 3); Assert.AreEqual(client.IsVerticallyFlipped, true); Assert.AreEqual(client.IsHorizontallyFlipped, true); Assert.AreEqual(client.Col1, 3); Assert.AreEqual(client.Col2, 4); Assert.AreEqual(client.Row1, 3); Assert.AreEqual(client.Row2, 4); client = new HSSFClientAnchor(1, 1, 1, 1, (short)5, 5, (short)6, 6); Assert.AreEqual(client.IsVerticallyFlipped, false); Assert.AreEqual(client.IsHorizontallyFlipped, false); Assert.AreEqual(client.Col1, 5); Assert.AreEqual(client.Col2, 6); Assert.AreEqual(client.Row1, 5); Assert.AreEqual(client.Row2, 6); }
public void TestEqualsValues() { HSSFClientAnchor clientAnchor1 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); HSSFClientAnchor clientAnchor2 = new HSSFClientAnchor(0, 1, 2, 3, (short)4, 5, (short)6, 7); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Dx1 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Dx1 = (0); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Dy1 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Dy1 = (1); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Dx2 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Dx2 = (2); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Dy2 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Dy2 = (3); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Col1 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Col1 = (4); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Row1 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Row1 = (5); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Col2 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Col2 = (6); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.Row2 = (10); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.Row2 = (7); Assert.AreEqual(clientAnchor1, clientAnchor2); clientAnchor2.AnchorType = (3); Assert.AreNotSame(clientAnchor1, clientAnchor2); clientAnchor2.AnchorType = (0); Assert.AreEqual(clientAnchor1, clientAnchor2); HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3); HSSFChildAnchor childAnchor2 = new HSSFChildAnchor(0, 1, 2, 3); childAnchor1.Dx1 = (10); Assert.AreNotSame(childAnchor1, childAnchor2); childAnchor1.Dx1 = (0); Assert.AreEqual(childAnchor1, childAnchor2); childAnchor2.Dy1 = (10); Assert.AreNotSame(childAnchor1, childAnchor2); childAnchor2.Dy1 = (1); Assert.AreEqual(childAnchor1, childAnchor2); childAnchor2.Dx2 = (10); Assert.AreNotSame(childAnchor1, childAnchor2); childAnchor2.Dx2 = (2); Assert.AreEqual(childAnchor1, childAnchor2); childAnchor2.Dy2 = (10); Assert.AreNotSame(childAnchor1, childAnchor2); childAnchor2.Dy2 = (3); Assert.AreEqual(childAnchor1, childAnchor2); }
public void TestModify() { HSSFWorkbook wb = new HSSFWorkbook(); // create a sheet with a text box HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFShapeGroup group1 = patriarch.CreateGroup(new HSSFClientAnchor(0, 0, 0, 0, (short)0, 0, (short)15, 25)); group1.SetCoordinates(0, 0, 792, 612); HSSFTextbox textbox1 = group1.CreateTextbox(new HSSFChildAnchor(100, 100, 300, 300)); HSSFRichTextString rt1 = new HSSFRichTextString("Hello, World!"); textbox1.String = rt1; // Write, read back and check that our text box is there wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(1, patriarch.Children.Count); group1 = (HSSFShapeGroup)patriarch.Children[(0)]; Assert.AreEqual(1, group1.Children.Count); textbox1 = (HSSFTextbox)group1.Children[(0)]; Assert.AreEqual("Hello, World!", textbox1.String.String); // modify anchor Assert.AreEqual(new HSSFChildAnchor(100, 100, 300, 300), textbox1.Anchor); HSSFChildAnchor newAnchor = new HSSFChildAnchor(200, 200, 400, 400); textbox1.Anchor = newAnchor; // modify text textbox1.String = new HSSFRichTextString("Hello, World! (modified)"); // add a new text box HSSFTextbox textbox2 = group1.CreateTextbox(new HSSFChildAnchor(400, 400, 600, 600)); HSSFRichTextString rt2 = new HSSFRichTextString("Hello, World-2"); textbox2.String = rt2; Assert.AreEqual(2, group1.Children.Count); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(1, patriarch.Children.Count); group1 = (HSSFShapeGroup)patriarch.Children[(0)]; Assert.AreEqual(2, group1.Children.Count); textbox1 = (HSSFTextbox)group1.Children[(0)]; Assert.AreEqual("Hello, World! (modified)", textbox1.String.String); Assert.AreEqual(new HSSFChildAnchor(200, 200, 400, 400), textbox1.Anchor); textbox2 = (HSSFTextbox)group1.Children[(1)]; Assert.AreEqual("Hello, World-2", textbox2.String.String); Assert.AreEqual(new HSSFChildAnchor(400, 400, 600, 600), textbox2.Anchor); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sheet = wb.GetSheetAt(0) as HSSFSheet; patriarch = sheet.DrawingPatriarch as HSSFPatriarch; group1 = (HSSFShapeGroup)patriarch.Children[(0)]; textbox1 = (HSSFTextbox)group1.Children[(0)]; textbox2 = (HSSFTextbox)group1.Children[(1)]; HSSFTextbox textbox3 = group1.CreateTextbox(new HSSFChildAnchor(400, 200, 600, 400)); HSSFRichTextString rt3 = new HSSFRichTextString("Hello, World-3"); textbox3.String = rt3; }