public void TestBreakCharacter_NewLine() { using (Stream sIn = new FileStream(TESTFILE_DIR + "CarriageReturn.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); br_Handler objectConsumer = new br_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsFalse(objectConsumer.HasNonDocElements(), "br tag should not generate any nondoc elements"); Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(BreakCharacter)); Assert.IsTrue(writerOut.Elements[0].IsContent); Assert.IsFalse(writerOut.Elements[0].IsStart); Assert.IsFalse(writerOut.Elements[0].IsEnd); Assert.AreEqual("\r", (writerOut.Elements[0] as BreakCharacter).Content); } }
public void TestBreakCharacter_NewColumn() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ColumnBreak.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); br_Handler objectConsumer = new br_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsFalse(objectConsumer.HasNonDocElements(), "br tag should not generate any nondoc elements"); Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(BreakCharacter)); Assert.IsTrue(writerOut.Elements[0].IsContent); Assert.IsFalse(writerOut.Elements[0].IsStart); Assert.IsFalse(writerOut.Elements[0].IsEnd); StringBuilder sb = new StringBuilder(); sb.Append((char)0xEA0D); string sExpected = sb.ToString(); Assert.AreEqual(sExpected, (writerOut.Elements[0] as BreakCharacter).Content); } }
public void TestParagraphWithBorders() { using (Stream sIn = new FileStream(TESTFILE_DIR + "Test paragraph borders document.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[0].Type); Assert.IsNotNull((elemsRead[0] as Paragraph).ParagraphFormatting); BorderDefinition bDef = (elemsRead[0] as Paragraph).ParagraphFormatting.Borders; Assert.IsNotNull(bDef); Assert.IsNotNull(bDef.Top); Assert.IsNotNull(bDef.Left); Assert.IsNotNull(bDef.Bottom); Assert.IsNotNull(bDef.Right); Border borderTop = bDef.Top; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderTop.BorderLineStyle); Assert.AreEqual(4, borderTop.PenWidth); Border borderLeft = bDef.Left; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderLeft.BorderLineStyle); Assert.AreEqual(4, borderLeft.PenWidth); Border borderBottom = bDef.Bottom; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderBottom.BorderLineStyle); Assert.AreEqual(4, borderBottom.PenWidth); Border borderRight = bDef.Right; Assert.AreEqual(Border.BorderStyle.SingleThickness, borderRight.BorderLineStyle); Assert.AreEqual(4, borderRight.PenWidth); } }
public void TestAlignment() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ParagraphPropertiesTestDocument.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[ 0].Type); ParagraphProperties parProps1 = (elemsRead[ 0] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps1.ParaAlignment == ParagraphProperties.AlignmentStyles.None); Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[ 5].Type); ParagraphProperties parProps2 = (elemsRead[ 5] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps2.ParaAlignment == ParagraphProperties.AlignmentStyles.Centre); Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[10].Type); ParagraphProperties parProps3 = (elemsRead[10] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps3.ParaAlignment == ParagraphProperties.AlignmentStyles.None); Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[15].Type); ParagraphProperties parProps4 = (elemsRead[15] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps4.ParaAlignment == ParagraphProperties.AlignmentStyles.Left); Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[20].Type); ParagraphProperties parProps5 = (elemsRead[20] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps5.ParaAlignment == ParagraphProperties.AlignmentStyles.Right); Assert.AreEqual(DocElementTypes.WPparagraph, elemsRead[25].Type); ParagraphProperties parProps6 = (elemsRead[25] as Paragraph).ParagraphFormatting.ParagraphProperties; Assert.IsTrue(parProps1.ParaAlignment == ParagraphProperties.AlignmentStyles.None); } }
public void TestSectionPropertiesDefault() { using (Stream sIn = new FileStream(TESTFILE_DIR + "SectionPropertiesDefault.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); sectPr_Handler objectConsumer = new sectPr_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "sectPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "sectPr should generate 1 nondoc element"); SectionFormatting sf = nonDocs.Dequeue() as SectionFormatting; Assert.IsNotNull(sf); Assert.IsFalse(sf.FCSPageInformation.RightGutter); } }
public void TestParagraphPropertiesWithSimpleList() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ParagraphPropertiesSimpleList.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); pPr_Handler objectConsumer = new pPr_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "pPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "pPr should generate 1 nondoc element"); FCSFormatting fmt = nonDocs.Dequeue() as FCSFormatting; Assert.IsNotNull(fmt); Assert.IsNotNull(fmt.CharacterProperties, "Not essential but may be assumed elsewhere in code"); ParagraphProperties pProps = fmt.ParagraphProperties; Assert.IsNotNull(pProps); Assert.AreEqual(2, pProps.NumberingProperties.NumberingLevelRef); Assert.AreEqual(3, pProps.NumberingProperties.NumberingDefinitionRef); } }
public void TestParagraphPropertiesOtherThanBoolProperties() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ParagraphPropertiesOtherThanBoolProperties.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.StyleSheet = new StyleSheet(); pPr_Handler objectConsumer = new pPr_Handler(context); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "pPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "pPr should generate 1 nondoc element"); FCSFormatting fmt = nonDocs.Dequeue() as FCSFormatting; Assert.IsNotNull(fmt); Assert.IsNotNull(fmt.CharacterProperties, "Not essential but may be assumed elsewhere in code"); ParagraphProperties pProps = fmt.ParagraphProperties; Assert.IsNotNull(pProps); Assert.AreEqual( 3, pProps.OutlineLevel); Assert.AreEqual(100, pProps.IndentLeft); Assert.AreEqual(200, pProps.IndentRight); Assert.AreEqual(300, pProps.Hanging); // NOTE That this is a contrived example! Assert.AreEqual(400, pProps.IndentFirst); Assert.AreEqual( 50, pProps.SpaceBefore); Assert.AreEqual( 70, pProps.SpaceAfter); Assert.AreEqual( 90, pProps.LineSpacing); Assert.AreEqual("HereBeDragons", pProps.StyleId); Assert.IsTrue(pProps.ParaAlignment == ParagraphProperties.AlignmentStyles.Centre); // TODO a couple of more tricky properties // Assert.AreEqual(2, pProps.Level); - List level is in the numbering and needs to be pulled up here // DirectAccessMember OptionalValue<KashidaJustificationPercentages> KashidaJustificationAmount; // DirectAccessMember OptionalValue<FontAlignments> FontAlignment; } }
public void TestColours() { using (Stream sIn = new FileStream(TESTFILE_DIR + "DocumentWithCharacterColourProperties.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; int iIndex = 1; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); CharacterProperties charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsNull(charProps); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsTrue(charProps.Color.RGBColor == "FF0000"); Assert.IsTrue(charProps.FontHighlight == null); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsNull(charProps); iIndex += 3; // Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); // Assert.IsTrue(charProps.Color != null); // Assert.IsTrue(charProps.Color.ThemeName == "text1"); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsNull(charProps); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsTrue(charProps.Color.RGBColor == "FF0000"); Assert.IsTrue(charProps.FontHighlight == "green"); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsTrue(charProps.Color.RGBColor == "FF0000"); Assert.IsTrue(charProps.FontHighlight == "green"); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsTrue(charProps.Color.RGBColor == "FF0000"); Assert.IsTrue(charProps.FontHighlight == "green"); iIndex += 3; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[iIndex].Type); charProps = (elemsRead[iIndex] as CharacterFormatting).Properties; Assert.IsNull(charProps); } }
public void TestHandlePNode_UseAStyle() { using (Stream sIn = new FileStream(TESTFILE_DIR + "PhandlerTest2_UseAStyle.xml", FileMode.Open)) { ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); Assert.IsNotNull(context.StyleSheet, "Expected it to be created already"); Style stylee = new Style(); stylee.Name = "Heading 2"; stylee.FCSFormatting = new FCSFormatting(); stylee.FCSFormatting.ParagraphProperties = new ParagraphProperties(); stylee.FCSFormatting.ParagraphProperties.SpaceBefore = 300; context.StyleSheet.Styles.Add("Heading2", stylee); DocXReaderTestWriter writerOut = new DocXReaderTestWriter(context); writerOut.ElementAdded += new EventHandler<TestWriterCallbackInfo>(TestHandlePNode_UseAStyle_OnAddElement); context.ParsingBody = true; BodyConsumer theBody = new BodyConsumer(context); Parser put = new Parser(sIn, theBody, writerOut); put.Parse(); } }
private static void Helper_VerifySingleDocElementWasDispatchedOfType(DocXReaderTestWriter writerOut, Type type) { List<DocElement> elemsDispatched = writerOut.Elements; Assert.AreEqual(1, elemsDispatched.Count, "The tag should generate only 1 doc element"); Assert.IsTrue(elemsDispatched[0].GetType() == type); }
public void TestTabCharacter() { using (Stream sIn = new FileStream(TESTFILE_DIR + "TabCharacter.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); tab_Handler objectConsumer = new tab_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsFalse(objectConsumer.HasNonDocElements(), "tab should not generate any nondoc elements"); Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(TabCharacter)); Assert.IsTrue(writerOut.Elements[0].IsContent); Assert.IsFalse(writerOut.Elements[0].IsStart); Assert.IsFalse(writerOut.Elements[0].IsEnd); } }
public void TestFontCalibri() { using (Stream sIn = new FileStream(TESTFILE_DIR + "FontCalibri.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); font_Handler objectConsumer = new font_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "font should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "font should generate 1 nondoc element"); FCSFont font = nonDocs.Dequeue() as FCSFont; Assert.IsNotNull(font); Assert.IsTrue(font.Family == FCSFont.FontFamilies.Swiss); Assert.AreEqual("Calibri", font.Name); Assert.AreEqual(0, font.Number, "Font number is 0 until coontext puts it into a font table"); Assert.IsTrue(font.Pitch == FCSFont.Pitches.Variable); Assert.AreEqual(-1610611985, font.UnicodeRangeUsb0); Assert.AreEqual(1073750139, font.UnicodeRangeUsb1); Assert.AreEqual(0, font.UnicodeRangeUsb2); Assert.AreEqual(0, font.UnicodeRangeUsb3); Assert.AreEqual(159, font.UnicodeRangeCsb0); Assert.AreEqual(0, font.UnicodeRangeCsb1); PanoseInformation piRead = font.PanoseInformation; Assert.AreEqual(2, piRead[0]); Assert.AreEqual(15, piRead[1]); Assert.AreEqual(5, piRead[2]); Assert.AreEqual(2, piRead[3]); Assert.AreEqual(2, piRead[4]); Assert.AreEqual(2, piRead[5]); Assert.AreEqual(4, piRead[6]); Assert.AreEqual(3, piRead[7]); Assert.AreEqual(2, piRead[8]); Assert.AreEqual(4, piRead[9]); } }
public void TestCharacterPropertiesWithValues() { using (Stream sIn = new FileStream(TESTFILE_DIR + "CharacterPropertiesWithValues.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); rPr_Handler objectConsumer = new rPr_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "rPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "rPr should generate 1 nondoc element"); CharacterProperties cp = nonDocs.Dequeue() as CharacterProperties; Assert.IsNotNull(cp); Assert.IsTrue(cp.Bold); Assert.IsTrue(cp.Italic); } }
public void TestVariousCharacterProperties_2() { using (Stream sIn = new FileStream(TESTFILE_DIR + "Test Additional Character Properties 2 Document.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; int index = 1; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); CharacterProperties charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.SmallCaps, "Expected smallcaps"); index = 7; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.AllCaps, "Expected AllCaps"); } }
public void TestVariousCharacterProperties() { using (Stream sIn = new FileStream(TESTFILE_DIR + "Test Additional Character Properties Document.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; int index = 4; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); CharacterProperties charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.StrikeThrough, "Expected strikethrough"); index = 10; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.DoubleStrikeThrough, "Expected double strikethrough"); index = 16; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Superscript, "Expected superscript"); index = 22; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Subscript, "Expected subscript"); index = 28; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Shadow, "Expected shadow"); index = 34; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Outline, "Expected outline"); index = 40; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Emboss, "Expected emboss"); index = 46; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[index].Type); charProps1 = (elemsRead[index] as CharacterFormatting).Properties; Assert.IsTrue(charProps1.Engrave, "Expected engrave"); } }
public void TestSectionPropertiesWithValues() { using (Stream sIn = new FileStream(TESTFILE_DIR + "SectionPropertiesWithValues.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); sectPr_Handler objectConsumer = new sectPr_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "sectPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "sectPr should generate 1 nondoc element"); SectionFormatting sf = nonDocs.Dequeue() as SectionFormatting; Assert.IsNotNull(sf); Assert.AreEqual(0, sf.StyleId, "Style is managed by the context so initially 0"); Assert.AreEqual(42, sf.FCSPageInformation.PaperSizeNumber); Assert.AreEqual(16838, sf.FCSPageInformation.PaperHeight); Assert.AreEqual(11906, sf.FCSPageInformation.PaperWidth); Assert.AreEqual(1440, sf.FCSPageInformation.LeftMargin); Assert.AreEqual(1430, sf.FCSPageInformation.TopMargin); Assert.AreEqual(1420, sf.FCSPageInformation.RightMargin); Assert.AreEqual(1410, sf.FCSPageInformation.BottomMargin); Assert.AreEqual(100, sf.FCSPageInformation.GutterWidth); Assert.IsTrue(sf.FCSPageInformation.RightGutter); Assert.IsTrue(sf.FCSPageInformation.Landscape); Assert.AreEqual(240, sf.LineGridPitch); Assert.AreEqual(120, sf.LineNumberingIndentFromMargin); Assert.AreEqual(3, sf.StartingLineNumber); Assert.AreEqual(1, sf.LineNumberingStep); Assert.IsTrue(sf.LineNumberingRestartType == SectionFormatting.LineNumberingRestartTypes.RestartEachPage); Assert.IsTrue(sf.BreakType == SectionFormatting.SectionBreakTypes.OddPage); Assert.AreEqual(1, sf.FirstPagePrinterBin); Assert.AreEqual(2, sf.PrinterBin); Assert.IsTrue(sf.LineBetweenColumns); Assert.AreEqual(2, sf.ColumnCount); Assert.AreEqual(500, sf.SpaceBetweenColumns); //TODO Not sure what these relate to //property bool UnlockedForForms; // Need handlers for subnodes //property PageNumberingInformation^ PageNumbering; // Direct from sectPr //property FCSPageInformation^ FCSPageInformation; - which has.... //property bool FacingPages; //property bool ParallelGutter; //property bool MirrorMargins; //property int FirstPageNumber; //property bool WidowOrphanControl; //property bool PrintTwoPagesOnOne; //property bool BookFoldPrinting; //CA_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", MessageId="Member") //property bool BookFoldPrintingBiDirectional; //property int BookFoldSheets; //property BorderDefinition^ PageBorders; //property bool BorderSurroundsHeader; //property bool BorderSurrondsFooter; //property int BorderArtStyle; //property bool AlignParaBordersAndTablesWithPageBorders; //property PageBorderOptionValues PageBorderOptions; // TODO's //property bool EndNotesAtSectionEnd; //property bool LeftToRightSection; //property bool SnapTextToCharacterGrid; //property int CharacterSpaceBasement; //Character space basement (character pitch minus font size) N in device-independent units (a device-independent unit is 1/294912th of an inch). //property Collection <ColumnDefinition>^ CustomColumns { Collection <ColumnDefinition>^ get(); } //property TextVerticalAlignments TextVerticalAlignment; //property AsianRenderingStyles AsianRendering; //property TextFlowOptions TextFlow; //property CharacterGridOptions CharacterGrid; //property NoteStyleInformation^ FootnoteStyle; //property NoteStyleInformation^ EndnoteStyle; } }
public void TestFontLotus() { using (Stream sIn = new FileStream(TESTFILE_DIR + "FontLotus.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); font_Handler objectConsumer = new font_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "font should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "font should generate 1 nondoc element"); FCSFont font = nonDocs.Dequeue() as FCSFont; Assert.IsNotNull(font); Assert.IsTrue(font.Family == FCSFont.FontFamilies.Auto); Assert.AreEqual("LotusWPSet", font.Name); Assert.AreEqual("02", font.CharSet); Assert.IsTrue(font.Type == FCSFont.FontTypes.Default); } }
public void TestFontNotTrueType() { using (Stream sIn = new FileStream(TESTFILE_DIR + "FontNotTT.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); font_Handler objectConsumer = new font_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "font should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "font should generate 1 nondoc element"); FCSFont font = nonDocs.Dequeue() as FCSFont; Assert.IsNotNull(font); Assert.IsTrue(font.Family == FCSFont.FontFamilies.Roman); Assert.AreEqual("Tms Rmn", font.Name); Assert.AreEqual("00", font.CharSet); // TODO this with another font //Assert.IsTrue(font.Type == FCSFont.FontTypes.TrueType); but it is not and there is the embedded clarify //public string AlternateName { get; set; } //public short CodePage { get; set; } //public EmbeddedFont FontData { get; set; } //public FCSFont.FontTypes Type { get; set; } } }
//[Test] //public void TestTable_SimpleSingle() //{ // using (Stream sIn = new FileStream(TESTFILE_DIR + "TableSimple2By2.xml", FileMode.Open)) // { // DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); // tbl_Handler objectConsumer = new tbl_Handler(null); // Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); // Assert.IsFalse(objectConsumer.HasNonDocElements(), "tbl tag should not generate any nondoc elements"); // Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(Table)); // Assert.IsTrue(writerOut.Elements[0].IsContent); // Assert.IsFalse(writerOut.Elements[0].IsStart); // } //} #region Helpers private static void Helper_ParseFileIntoConsumer(Stream sIn, DocXReaderTestWriter writerOut, XMLConsumer objectConsumer) { Parser pft = new Parser(sIn, objectConsumer, writerOut); pft.StopOnTopLevelTargetFinished(); pft.Parse(); Assert.AreEqual(0, pft.m_targets.Count, "Should have completed any subtargets"); Assert.IsFalse(objectConsumer.HasElementsToDispatch(), "All doc elements should have been dispatched by completion"); }
public void TestParagraphDefault() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ParagraphDefault.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); p_Handler objectConsumer = new p_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsFalse(objectConsumer.HasNonDocElements(), "default p should not generate any nondoc elements"); Helper_VerifySingleDocElementWasDispatchedOfType(writerOut, typeof(Paragraph)); Assert.IsTrue(writerOut.Elements[0].IsModifier); } }
public void TestListLevelSimple() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ListLevelSimple.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); lvl_Handler objectConsumer = new lvl_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "rPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "lvl should generate 1 nondoc element"); ListLevel ll = nonDocs.Dequeue() as ListLevel; Assert.IsNotNull(ll); Assert.AreEqual("1", ll.Id); Assert.AreEqual(7, ll.StartAt); Assert.AreEqual(42, ll.PictureId); Assert.IsTrue(ll.NumberingStyle == ListLevel.NumberingStyles.LowercaseLetter); Assert.AreEqual("%2.", ll.LevelText); Assert.IsTrue(ll.Justification == ListLevel.ListJustificationOptions.Centre); Assert.IsTrue(ll.TrailingText == ListLevel.ListItemTrailingTextOptions.Nothing); Assert.IsNotNull(ll.FCSFormatting); Assert.IsNotNull(ll.FCSFormatting.ParagraphProperties); Assert.AreEqual(900, ll.FCSFormatting.ParagraphProperties.IndentLeft); Assert.AreEqual(400, ll.FCSFormatting.ParagraphProperties.Hanging); // From the cs file // property Collection<int>^ LevelTextIndices { Collection<int>^ get(); } // Collection<int>^ m_LevelTextIndices; // property bool DoNotRestart; // property bool LegalLevel; // (Others) From the egg smell // <xsd:element name="lvlRestart" type="CT_DecimalNumber" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Restart Numbering Level Symbol</xsd:documentation> // </xsd:annotation> // </xsd:element> // <xsd:element name="pStyle" type="CT_String" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Paragraph Style's Associated Numbering Level</xsd:documentation> // </xsd:annotation> // </xsd:element> // <xsd:element name="isLgl" type="CT_OnOff" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Display All Levels Using Arabic Numerals</xsd:documentation> // </xsd:annotation> // </xsd:element> // <xsd:element name="legacy" type="CT_LvlLegacy" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Legacy Numbering Level Properties</xsd:documentation> // </xsd:annotation> // </xsd:element> // <xsd:element name="pPr" type="CT_PPr" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Numbering Level Associated Paragraph Properties</xsd:documentation> // </xsd:annotation> // </xsd:element> // <xsd:element name="rPr" type="CT_RPr" minOccurs="0"> // <xsd:annotation> // <xsd:documentation>Numbering Symbol Run Properties</xsd:documentation> // </xsd:annotation> // </xsd:element> //</xsd:sequence> //<xsd:attribute name="tplc" type="ST_LongHexNumber" use="optional"> // <xsd:annotation> // <xsd:documentation>Template Code</xsd:documentation> // </xsd:annotation> //</xsd:attribute> //<xsd:attribute name="tentative" type="ST_OnOff" use="optional"> // <xsd:annotation> // <xsd:documentation>Tentative Numbering</xsd:documentation> // </xsd:annotation> //</xsd:attribute> } }
public void TestParagraphPropertiesAllBoolFlagsOn() { using (Stream sIn = new FileStream(TESTFILE_DIR + "ParagraphPropertiesAllBoolFlagsOn.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); pPr_Handler objectConsumer = new pPr_Handler(null); Helper_ParseFileIntoConsumer(sIn, writerOut, objectConsumer); Assert.IsTrue(objectConsumer.HasNonDocElements(), "pPr should generate a nondoc element"); Queue<object> nonDocs = objectConsumer.GetNonDocElements(); Assert.AreEqual(1, nonDocs.Count, "pPr should generate 1 nondoc element"); FCSFormatting fmt = nonDocs.Dequeue() as FCSFormatting; Assert.IsNotNull(fmt); Assert.IsNotNull(fmt.CharacterProperties, "Not essential but may be assumed elsewhere in code"); ParagraphProperties pProps = fmt.ParagraphProperties; Assert.IsNotNull(pProps); Assert.IsTrue(pProps.NoAutoHyphenate); Assert.IsTrue(pProps.KeepIntact); Assert.IsTrue(pProps.KeepWithNext); Assert.IsTrue(pProps.BreakBeforePara); Assert.IsTrue(pProps.WidowOrOrphanControl); // Assert.IsTrue(pProps.NoWidowOrOrphanControl); // not sure we need both Assert.IsTrue(pProps.SuppressLineNumbersForThisParagraph); Assert.IsTrue(pProps.SpaceBeforeAuto); Assert.IsTrue(pProps.SpaceAfterAuto); // TODO revisit this for the following booleans //Assert.IsTrue(pProps.ParagraphAlwaysHidden); //Assert.IsTrue(pProps.SideBySide); //Assert.IsTrue(pProps.TreatLeftIndentAsRightForRightToLeftParagraphs); //Assert.IsTrue(pProps.TreatRightIndentAsLeftForRightToLeftParagraphs); //Assert.IsTrue(pProps.AutoAdjustRightIndent); //Assert.IsTrue(pProps.LineSpacingIsMultiple); //Assert.IsTrue(pProps.DisableSnapToGrid); //Assert.IsTrue(pProps.ReadsRightToLeft); //Assert.IsTrue(pProps.NoAsianCharacterWrapping); //Assert.IsTrue(pProps.NoAsianWordWrapping); //Assert.IsTrue(pProps.NoAsianOverflowPeriodAndComma); //Assert.IsTrue(pProps.AutoSpacingBetweenDoubleByteAndEnglish); //Assert.IsTrue(pProps.AutoSpacingBetweenDoubleByteAndNumbers); //Assert.IsTrue(pProps.CollapsedInPocketWord); } }
public void TestHandleRAndPNodes_RprInsidePpr() { using (Stream sIn = new FileStream(TESTFILE_DIR + "RAndPhandlersTest2.xml", FileMode.Open)) { ParsingContext context = new ParsingContext(); context.SetDocumentDefaultContext(); DocXReaderTestWriter writerOut = new DocXReaderTestWriter(context); writerOut.ElementAdded += new EventHandler<TestWriterCallbackInfo>(TestHandleRAndPNodes_RprInsidePpr_OnAddElement); context.ParsingBody = true; BodyConsumer theBody = new BodyConsumer(context); Parser put = new Parser(sIn, theBody, writerOut); put.Parse(); } }
public void TestUnderlining() { using (Stream sIn = new FileStream(TESTFILE_DIR + "CharacterPropertiesTestDocument.xml", FileMode.Open)) { DocXReaderTestWriter writerOut = new DocXReaderTestWriter(null); ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); context.ParsingBody = true; pft.Parse(); List<DocElement> elemsRead = writerOut.Elements; Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[ 1].Type); CharacterProperties charPropsPara1 = (elemsRead[ 1] as CharacterFormatting).Properties; Assert.IsNull(charPropsPara1); Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[ 6].Type); CharacterProperties charPropsPara2 = (elemsRead[ 6] as CharacterFormatting).Properties; Assert.IsTrue(charPropsPara2.UnderlineStyle == CharacterProperties.UnderlineStyles.Continuous); Assert.AreEqual(DocElementTypes.WPcharacterFormatting, elemsRead[11].Type); CharacterProperties charPropsPara3 = (elemsRead[11] as CharacterFormatting).Properties; Assert.IsNull(charPropsPara3); } }