public void TestLoopbackSimpleRTFTableGetsTable() { using (Stream sIn = new FileStream(TESTFILE_DIR + "SimpleRTFTable_document.xml", FileMode.Open)) { FcsToRtfWriter writerOut = new FcsToRtfWriter(); writerOut.RememberElementsWritten = true; ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsBefore = writerOut.ListOfWrittenElements(); Workshare.Compositor.FCSFilters.Reader readBack = new Workshare.Compositor.FCSFilters.Reader(); readBack.ExtractRTFFileCollectionFromWriter(writerOut); List<DocElement> elemsAfter = readBack.ReadBackAllElementsFromFileCollection(); int iCountBefore = elemsBefore.Count; int iCountAfter = elemsAfter.Count; Assert.IsTrue(iCountAfter <= iCountBefore, "Seem to have invented extra elements in teh loop back"); } }
public void TestReadSimpleRTF() { string sFileName = TESTFILE_DIR + "VerySimpleRTF.rtf"; Assert.IsTrue(File.Exists(sFileName)); Workshare.Compositor.FCSFilters.Reader readIn = new Workshare.Compositor.FCSFilters.Reader(); readIn.ReadNamedRTFFile(sFileName); int iObjectCount = readIn.FileCollectionSize(); int iRecognisedObjectCount = 0; for (int iIndex = 0; iIndex < iObjectCount; ++iIndex) { DocElement des = readIn.ReadBackElementFromFileCollection(iIndex); if (des == null) continue; ++iRecognisedObjectCount; } Assert.Greater(iRecognisedObjectCount, 0); }
public void TestReadRTFTableWithExplicitCellBorder() { string sFileName = TESTFILE_DIR + "ExplicitCellBorder.rtf"; Assert.IsTrue(File.Exists(sFileName)); Workshare.Compositor.FCSFilters.Reader readIn = new Workshare.Compositor.FCSFilters.Reader(); readIn.ReadNamedRTFFile(sFileName); List<DocElement> elems = readIn.ReadBackAllElementsFromFileCollection(); int iCount = elems.Count; Assert.Greater(iCount, 0); List<TableCell> listCells = new List<TableCell>(); for (int iIndex = 0; iIndex < iCount; ++iIndex) { if (elems[iIndex].Type == DocElementTypes.WPtableCell) listCells.Add(elems[iIndex] as TableCell); } Assert.AreEqual(8, listCells.Count); TableCell cell2Start = listCells[2]; Assert.IsTrue(cell2Start.IsStart); if (cell2Start.CellFormatting.Border != null) { Assert.AreEqual(Border.BorderStyle.None, cell2Start.CellFormatting.Border.Top.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.None, cell2Start.CellFormatting.Border.Left.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.None, cell2Start.CellFormatting.Border.Bottom.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.None, cell2Start.CellFormatting.Border.Right.BorderLineStyle); } TableCell cell2End = listCells[3]; Assert.IsTrue(cell2End.IsEnd); Assert.IsNotNull(cell2End.CellFormatting.Border); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Top.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Left.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Bottom.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Right.BorderLineStyle); Assert.AreEqual(4, cell2End.CellFormatting.Border.Top.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Left.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Bottom.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Right.PenWidth); }
public void TestLoopbackSimpleRTFTableGetsGridInfo() { using (Stream sIn = new FileStream(TESTFILE_DIR + "SimpleRTFTable_document.xml", FileMode.Open)) { Workshare.Compositor.FCSFilters.FcsToRtfWriter writerOut = new Workshare.Compositor.FCSFilters.FcsToRtfWriter(); writerOut.RememberElementsWritten = true; ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsBefore = writerOut.ListOfWrittenElements(); Workshare.Compositor.FCSFilters.Reader readBack = new Workshare.Compositor.FCSFilters.Reader(); readBack.ExtractRTFFileCollectionFromWriter(writerOut); List<DocElement> elemsAfter = readBack.ReadBackAllElementsFromFileCollection(); int iCountBefore = elemsBefore.Count; int iCountAfter = elemsAfter.Count; // At 28-11-2007 count was 15, which is wrong, but will evolve to correctednessness with time, cups of coffee and several Hob Nobbs int iIndex = 14; Assert.AreEqual(DocElementTypes.WPtable, elemsAfter[iIndex].Type); Table tableEnd = elemsAfter[iIndex] as Table; Assert.IsFalse(tableEnd.IsStart); Assert.IsTrue(tableEnd.IsEnd); TableGrid grid = tableEnd.TableGrid; Assert.IsNotNull(grid); Assert.IsNotNull(grid.ColumnWidths); Assert.AreEqual(2, grid.ColumnWidths.Count); Assert.AreEqual(1242, grid.ColumnWidths[0]); Assert.AreEqual(993, grid.ColumnWidths[1]); } }
public void TestReadSimpleRTFTable() { string sFileName = TESTFILE_DIR + "SimpleRTFTable.rtf"; Assert.IsTrue(File.Exists(sFileName)); Workshare.Compositor.FCSFilters.Reader readIn = new Workshare.Compositor.FCSFilters.Reader(); readIn.ReadNamedRTFFile(sFileName); List<DocElement> elems = readIn.ReadBackAllElementsFromFileCollection(); int iCount = elems.Count; Assert.Greater(iCount, 0); int iTableStart = -1; int iTableEnd = -1; for (int iIndex = 0; iIndex < iCount; ++iIndex) { if (elems[iIndex].Type != DocElementTypes.WPtable) continue; if ((elems[iIndex] as Table).IsStart) { Assert.AreEqual(-1, iTableStart, "Should only be 1 table"); iTableStart = iIndex; } if ((elems[iIndex] as Table).IsEnd) { Assert.AreNotEqual(-1, iTableStart, "Should have found a start before the end"); Assert.AreEqual(-1, iTableEnd, "Should only be 1 table"); iTableEnd = iIndex; } } Assert.AreNotEqual(-1, iTableEnd, "Should have found the table"); Table tableEnd = elems[iTableEnd] as Table; Assert.IsNotNull(tableEnd.TableGrid, "Should have a table grid"); Assert.AreEqual (2, tableEnd.TableGrid.ColumnWidths.Count, "Should have 2 columns"); Assert.AreEqual(1242, tableEnd.TableGrid.ColumnWidths[0]); Assert.AreEqual( 993, tableEnd.TableGrid.ColumnWidths[1]); }
public void TestLoopbackRTFTableGetsCellBorderInfo() { using (Stream sIn = new FileStream(TESTFILE_DIR + "DocumentExplicitTableAndCellBorders.xml", FileMode.Open)) { Workshare.Compositor.FCSFilters.FcsToRtfWriter writerOut = new Workshare.Compositor.FCSFilters.FcsToRtfWriter(); writerOut.RememberElementsWritten = true; ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsBefore = writerOut.ListOfWrittenElements(); Workshare.Compositor.FCSFilters.Reader readBack = new Workshare.Compositor.FCSFilters.Reader(); readBack.ExtractRTFFileCollectionFromWriter(writerOut); List<DocElement> elemsAfter = readBack.ReadBackAllElementsFromFileCollection(); int iCountBefore = elemsBefore.Count; int iCountAfter = elemsAfter.Count; int iIndex = 6; Assert.AreEqual(DocElementTypes.WPtableCell, elemsAfter[iIndex].Type); TableCell cell2End = elemsAfter[iIndex] as TableCell; Assert.IsFalse(cell2End.IsStart); Assert.IsTrue(cell2End.IsEnd); Assert.IsNotNull(cell2End.CellFormatting.Border); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Top.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Left.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Bottom.BorderLineStyle); Assert.AreEqual(Border.BorderStyle.SingleThickness, cell2End.CellFormatting.Border.Right.BorderLineStyle); Assert.AreEqual(4, cell2End.CellFormatting.Border.Top.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Left.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Bottom.PenWidth); Assert.AreEqual(4, cell2End.CellFormatting.Border.Right.PenWidth); } }
public void TestLoopbackRTFTableGetsTableBorderInfo() { using (Stream sIn = new FileStream(TESTFILE_DIR + "DocumentWithExplicitTableBorder.xml", FileMode.Open)) { Workshare.Compositor.FCSFilters.FcsToRtfWriter writerOut = new Workshare.Compositor.FCSFilters.FcsToRtfWriter(); writerOut.RememberElementsWritten = true; ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsBefore = writerOut.ListOfWrittenElements(); Workshare.Compositor.FCSFilters.Reader readBack = new Workshare.Compositor.FCSFilters.Reader(); readBack.ExtractRTFFileCollectionFromWriter(writerOut); List<DocElement> elemsAfter = readBack.ReadBackAllElementsFromFileCollection(); int iCountBefore = elemsBefore.Count; int iCountAfter = elemsAfter.Count; int iIndex = 14; Assert.AreEqual(DocElementTypes.WPtable, elemsAfter[iIndex].Type); Table tableEnd = elemsAfter[iIndex] as Table; Assert.IsFalse(tableEnd.IsStart); Assert.IsTrue(tableEnd.IsEnd); Assert.IsNotNull(tableEnd.TableProperties); Assert.IsNotNull(tableEnd.TableProperties.TableBorders); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Top); Border borderTableTop = tableEnd.TableProperties.TableBorders.Top; Assert.AreEqual(Border.BorderStyle.Dashed, borderTableTop.BorderLineStyle); Assert.AreEqual(8, borderTableTop.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Left); Border borderTableLeft = tableEnd.TableProperties.TableBorders.Left; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableLeft.BorderLineStyle); Assert.AreEqual(8, borderTableLeft.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Bottom); Border borderTableBottom = tableEnd.TableProperties.TableBorders.Bottom; Assert.AreEqual(Border.BorderStyle.None, borderTableBottom.BorderLineStyle); Assert.AreEqual(0, borderTableBottom.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Right); Border borderTableRight = tableEnd.TableProperties.TableBorders.Right; Assert.AreEqual(Border.BorderStyle.Double, borderTableRight.BorderLineStyle); Assert.AreEqual(8, borderTableRight.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.HorizontalInside); Border borderTableHorizontalInside = tableEnd.TableProperties.TableBorders.HorizontalInside; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableHorizontalInside.BorderLineStyle); Assert.AreEqual(4, borderTableHorizontalInside.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.VerticalInside); Border borderTableVerticalInside = tableEnd.TableProperties.TableBorders.VerticalInside; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableVerticalInside.BorderLineStyle); Assert.AreEqual(6, borderTableVerticalInside.PenWidth); } }
public void TestReadRTFTableWithExplicitTableBorder() { string sFileName = TESTFILE_DIR + "ExplicitTableBorder.rtf"; Assert.IsTrue(File.Exists(sFileName)); Workshare.Compositor.FCSFilters.Reader readIn = new Workshare.Compositor.FCSFilters.Reader(); readIn.ReadNamedRTFFile(sFileName); List<DocElement> elems = readIn.ReadBackAllElementsFromFileCollection(); int iIndex = 14; Assert.AreEqual(DocElementTypes.WPtable, elems[iIndex].Type); Table tableEnd = elems[iIndex] as Table; Assert.IsFalse(tableEnd.IsStart); Assert.IsTrue(tableEnd.IsEnd); Assert.IsNotNull(tableEnd.TableProperties); Assert.IsNotNull(tableEnd.TableProperties.TableBorders); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Top); Border borderTableTop = tableEnd.TableProperties.TableBorders.Top; Assert.AreEqual(Border.BorderStyle.Dashed, borderTableTop.BorderLineStyle); Assert.AreEqual(8, borderTableTop.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Left); Border borderTableLeft = tableEnd.TableProperties.TableBorders.Left; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableLeft.BorderLineStyle); Assert.AreEqual(8, borderTableLeft.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Bottom); Border borderTableBottom = tableEnd.TableProperties.TableBorders.Bottom; Assert.AreEqual(Border.BorderStyle.None, borderTableBottom.BorderLineStyle); Assert.AreEqual(0, borderTableBottom.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.Right); Border borderTableRight = tableEnd.TableProperties.TableBorders.Right; Assert.AreEqual(Border.BorderStyle.Double, borderTableRight.BorderLineStyle); Assert.AreEqual(8, borderTableRight.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.HorizontalInside); Border borderTableHorizontalInside = tableEnd.TableProperties.TableBorders.HorizontalInside; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableHorizontalInside.BorderLineStyle); Assert.AreEqual(4, borderTableHorizontalInside.PenWidth); Assert.IsNotNull(tableEnd.TableProperties.TableBorders.VerticalInside); Border borderTableVerticalInside = tableEnd.TableProperties.TableBorders.VerticalInside; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTableVerticalInside.BorderLineStyle); Assert.AreEqual(6, borderTableVerticalInside.PenWidth); }