/// <summary>
        /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when
        /// a match is encountered.
        /// </summary>
        /// <param name="authoringEngine"></param>
        /// <param name="parentElement"></param>
        /// <param name="match"></param>
        protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match)
        {
            FootnoteReference footnoteReference = new FootnoteReference(parentElement,
                                                                        Convert.ToInt32(match.Groups["FootnoteID"].Value));

            parentElement.AppendChild(footnoteReference);
        }
Exemplo n.º 2
0
        public void Parse()
        {
            DomDocument          document            = new DomDocument();
            IInlineElementParser inlineElementParser = new FootnoteReferenceParser();

            inlineElementParser.Parse(null, document,
                                      "This[1] is a footnote reference, whereas [2] this and\\[3] and[this] are not.");

            Assert.AreEqual(1, document.ChildElements.Count);

            FootnoteReference footnoteReference = document.ChildElements[0] as FootnoteReference;

            Assert.IsNotNull(footnoteReference);
            Assert.AreEqual(1, footnoteReference.Number);
        }
Exemplo n.º 3
0
        private void ProcessAcronym(HtmlEnumerator en)
        {
            // Transform the inline acronym/abbreviation to a reference to a foot note.

            string title = en.Attributes["title"];
            if (title == null) return;

            AlternateProcessHtmlChunks(en, en.ClosingCurrentTag);

            if (elements.Count > 0 && elements[0] is Run)
            {
                string defaultRefStyle, runStyle;
                FootnoteEndnoteReferenceType reference;

                if (this.AcronymPosition == AcronymPosition.PageEnd)
                {
                    reference = new FootnoteReference() { Id = AddFootnoteReference(title) };
                    defaultRefStyle = "footnote text";
                    runStyle = "footnote reference";
                }
                else
                {
                    reference = new EndnoteReference() { Id = AddEndnoteReference(title) };
                    defaultRefStyle = "endnote text";
                    runStyle = "endnote reference";
                }

                Run run;
                elements.Add(
                    run = new Run(
                        new RunProperties
                        {
                            RunStyle = new RunStyle() { Val = htmlStyles.GetStyle(runStyle, StyleValues.Character) }
                        },
                        reference));

                if (!htmlStyles.DoesStyleExists(defaultRefStyle))
                {
                    // Force the superscript style because if the footnote text style does not exists,
                    // the rendering will be awful.
                    run.InsertInProperties(prop =>
                        prop.VerticalTextAlignment = new VerticalTextAlignment() { Val = VerticalPositionValues.Superscript });
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Visits the <paramref name="footnoteReference"/> element.
 /// </summary>
 /// <param name="footnoteReference"></param>
 public virtual void Visit(FootnoteReference footnoteReference)
 {
     htmlBuilder.AppendFormat("<sup>[<a href=\"#{0}\">{1}</a>]</sup>",
                              GetFoonoteAnchorName(footnoteReference.Number), footnoteReference.Number);
 }
Exemplo n.º 5
0
        // Generates content of mainDocumentPart1.
        private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1)
        {
            Document document1 = new Document(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "w14 w15 wp14" }  };
            document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            document1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2010/11/wordml");
            document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Body body1 = new Body();

            Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "003E4104", RsidRunAdditionDefault = "0065051C" };

            Run run1 = new Run();

            RunProperties runProperties1 = new RunProperties();
            RunFonts runFonts1 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties1.Append(runFonts1);
            Text text1 = new Text();
            text1.Text = "A";

            run1.Append(runProperties1);
            run1.Append(text1);

            Run run2 = new Run(){ RsidRunAddition = "003E4104" };

            RunProperties runProperties2 = new RunProperties();
            RunStyle runStyle1 = new RunStyle(){ Val = "a5" };

            runProperties2.Append(runStyle1);
            FootnoteReference footnoteReference1 = new FootnoteReference(){ Id = 1 };

            run2.Append(runProperties2);
            run2.Append(footnoteReference1);
            BookmarkStart bookmarkStart1 = new BookmarkStart(){ Name = "_GoBack", Id = "0" };
            BookmarkEnd bookmarkEnd1 = new BookmarkEnd(){ Id = "0" };

            paragraph1.Append(run1);
            paragraph1.Append(run2);
            paragraph1.Append(bookmarkStart1);
            paragraph1.Append(bookmarkEnd1);

            Paragraph paragraph2 = new Paragraph(){ RsidParagraphAddition = "003E4104", RsidRunAdditionDefault = "003E4104" };

            Run run3 = new Run();

            RunProperties runProperties3 = new RunProperties();
            RunFonts runFonts2 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties3.Append(runFonts2);
            Text text2 = new Text();
            text2.Text = "B";

            run3.Append(runProperties3);
            run3.Append(text2);

            Run run4 = new Run();

            RunProperties runProperties4 = new RunProperties();
            RunStyle runStyle2 = new RunStyle(){ Val = "a5" };

            runProperties4.Append(runStyle2);
            FootnoteReference footnoteReference2 = new FootnoteReference(){ Id = 2 };

            run4.Append(runProperties4);
            run4.Append(footnoteReference2);

            paragraph2.Append(run3);
            paragraph2.Append(run4);

            Paragraph paragraph3 = new Paragraph(){ RsidParagraphAddition = "003E4104", RsidRunAdditionDefault = "003E4104" };

            Run run5 = new Run();

            RunProperties runProperties5 = new RunProperties();
            RunFonts runFonts3 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties5.Append(runFonts3);
            Text text3 = new Text();
            text3.Text = "C";

            run5.Append(runProperties5);
            run5.Append(text3);

            Run run6 = new Run();

            RunProperties runProperties6 = new RunProperties();
            RunStyle runStyle3 = new RunStyle(){ Val = "a5" };

            runProperties6.Append(runStyle3);
            FootnoteReference footnoteReference3 = new FootnoteReference(){ Id = 3 };

            run6.Append(runProperties6);
            run6.Append(footnoteReference3);

            paragraph3.Append(run5);
            paragraph3.Append(run6);

            SectionProperties sectionProperties1 = new SectionProperties(){ RsidR = "003E4104" };

            FootnoteProperties footnoteProperties1 = new FootnoteProperties();
            FootnotePosition footnotePosition1 = new FootnotePosition(){ Val = FootnotePositionValues.BeneathText };

            footnoteProperties1.Append(footnotePosition1);
            PageSize pageSize1 = new PageSize(){ Width = (UInt32Value)11906U, Height = (UInt32Value)16838U };
            PageMargin pageMargin1 = new PageMargin(){ Top = 1985, Right = (UInt32Value)1701U, Bottom = 1701, Left = (UInt32Value)1701U, Header = (UInt32Value)851U, Footer = (UInt32Value)992U, Gutter = (UInt32Value)0U };
            Columns columns1 = new Columns(){ Space = "425" };
            DocGrid docGrid1 = new DocGrid(){ Type = DocGridValues.Lines, LinePitch = 360 };
            W15.FootnoteColumns footnoteColumns1 = new W15.FootnoteColumns(){ Val = 4 };

            sectionProperties1.Append(footnoteProperties1);
            sectionProperties1.Append(pageSize1);
            sectionProperties1.Append(pageMargin1);
            sectionProperties1.Append(columns1);
            sectionProperties1.Append(docGrid1);
            sectionProperties1.Append(footnoteColumns1);

            body1.Append(paragraph1);
            body1.Append(paragraph2);
            body1.Append(paragraph3);
            body1.Append(sectionProperties1);

            document1.Append(body1);

            mainDocumentPart1.Document = document1;
        }
Exemplo n.º 6
0
        public static MemoryStream GenerateMasterSideLetterDocument(SearchSettings searchSettings, MasterSideLetterContent masterSideLetter)
        {
            //grab the template from assembly resources
            var template = Resources.template;
            //copy the template to a new stream
            var stream = new MemoryStream();

            stream.Write(template, 0, template.Length);
            using (var doc = WordprocessingDocument.Open(stream, true))
            {
                //add numbering definition
                var numberingPart = doc.MainDocumentPart.AddNewPart <NumberingDefinitionsPart>("numberingDefinitionId");
                numberingPart.Numbering =
                    new Numbering(
                        new AbstractNum(
                            new Level(
                                new StartNumberingValue {
                    Val = 1
                },
                                new NumberingFormat {
                    Val = NumberFormatValues.Decimal
                },
                                new LevelText {
                    Val = "%1."
                },
                                new ParagraphProperties {
                    Indentation = new Indentation {
                        Hanging = "720", Left = "720"
                    }
                }
                                )
                            )
                {
                    AbstractNumberId = 1
                },
                        new NumberingInstance(
                            new AbstractNumId {
                    Val = 1
                }
                            )
                {
                    NumberID = 1
                }
                        );

                var body = doc.MainDocumentPart.Document.Body;
                //find the title and subtitle
                var paragraphs = body.Elements <Paragraph>().Take(2).ToList();
                paragraphs[0].GetFirstChild <Run>().GetFirstChild <Text>().Text = masterSideLetter.Fund.Name;
                paragraphs[1].GetFirstChild <Run>().GetFirstChild <Text>().Text = masterSideLetter.Fund.SponsorName;


                body.AppendChild(new Paragraph(
                                     new ParagraphProperties {
                    ParagraphStyleId = new ParagraphStyleId {
                        Val = "Heading1"
                    }
                },
                                     new Run(new Text("Investor List"))
                                     ));

                //insert the investors table
                var table = body.AppendChild(
                    new Table(
                        new TableProperties(
                            new TableStyle {
                    Val = "TableGrid"
                },
                            new TableWidth {
                    Type = TableWidthUnitValues.Auto, Width = "0"
                },
                            new TableLook
                {
                    Val              = "04A0",
                    FirstRow         = OnOffValue.FromBoolean(true),
                    LastRow          = OnOffValue.FromBoolean(false),
                    FirstColumn      = OnOffValue.FromBoolean(true),
                    LastColumn       = OnOffValue.FromBoolean(false),
                    NoHorizontalBand = OnOffValue.FromBoolean(false),
                    NoVerticalBand   = OnOffValue.FromBoolean(true)
                }
                            ),
                        new TableGrid(
                            new GridColumn {
                    Width = "4045"
                },
                            new GridColumn {
                    Width = "3330"
                },
                            new GridColumn {
                    Width = "1975"
                }
                            )
                        )
                    );
                //table header row
                table.AppendChild(
                    new TableRow(
                        new TableRowProperties(new TableRowHeight {
                    Val = 288
                }),
                        CreateCell("Investor Name", "4045", "E7E6E6", "Strong"),
                        CreateCell("Entity", "3330", "E7E6E6", "Strong"),
                        CreateCell("Commitment", "1975", "E7E6E6", "Strong", JustificationValues.Right)
                        )
                    );

                //table rows
                foreach (var fundInvestor in masterSideLetter.FundInvestors)
                {
                    table.AppendChild(
                        new TableRow(new TableRowProperties(new TableRowHeight {
                        Val = 288
                    }),
                                     CreateCell(fundInvestor.InvestorName, "4045"),
                                     CreateCell(fundInvestor.Entity, "3330"),
                                     CreateCell($"{fundInvestor.Commitment:c0}", "1975", null, null, JustificationValues.Right)
                                     )
                        );
                }
                body.AppendChild(CreatePageBreak());

                //insert the Provision Type Sections
                var footnoteId = 1;

                var provisionTypeSectionNumber = 0;
                foreach (var provisionTypeSection in masterSideLetter.ProvisionTypeSections)
                {
                    provisionTypeSectionNumber++;
                    if (provisionTypeSection != masterSideLetter.ProvisionTypeSections[0])
                    {
                        body.AppendChild(CreatePageBreak());
                    }

                    body.AppendChild(new Paragraph(
                                         new ParagraphProperties {
                        ParagraphStyleId = new ParagraphStyleId {
                            Val = "Heading1"
                        }
                    },
                                         new Run(
                                             new Text($"{provisionTypeSection.ProvisionType}")
                                             )
                                         ));

                    //create a score matrix
                    var scores = new Dictionary <MasterSideLetterContent.ProvisionSection, Dictionary <MasterSideLetterContent.ProvisionSection, double> >();
                    foreach (var provisionSectionA in provisionTypeSection.ProvisionSections)
                    {
                        scores.Add(provisionSectionA, new Dictionary <MasterSideLetterContent.ProvisionSection, double>());
                        foreach (var provisionSectionB in provisionTypeSection.ProvisionSections)
                        {
                            if (provisionSectionA == provisionSectionB)
                            {
                                continue;
                            }
                            var score = ProvisionComparison.GetProvisionScore(searchSettings, provisionSectionA.Content, provisionSectionB.Content);
                            if (score >= searchSettings.MslGroupingThreshold)
                            {
                                scores[provisionSectionA].Add(provisionSectionB, score);
                            }
                        }
                    }

                    var used = new List <MasterSideLetterContent.ProvisionSection>();
                    foreach (var pair in scores.OrderByDescending(p => p.Key.FundInvestors.Count).ThenByDescending(p => p.Value.Count).ThenByDescending(p => p.Value.Sum(s => s.Value)))
                    {
                        if (!used.Contains(pair.Key))
                        {
                            used.Add(pair.Key);
                            var contentParagraph = body.AppendChild(new Paragraph(
                                                                        new ParagraphProperties(new NumberingProperties(new NumberingLevelReference {
                                Val = 0
                            }, new NumberingId {
                                Val = provisionTypeSectionNumber
                            }))));
                            contentParagraph.AppendChild(new Run(new Text($"{pair.Key.Content}")));

                            var footnoteReference = new FootnoteReference {
                                Id = footnoteId
                            };
                            var footnoteReferenceRun = new Run(new RunProperties(new VerticalTextAlignment {
                                Val = VerticalPositionValues.Superscript
                            }));
                            footnoteReferenceRun.AppendChild(footnoteReference);
                            contentParagraph.AppendChild(footnoteReferenceRun);

                            var fundInvestorNames = string.Join("; ", pair.Key.FundInvestors.Select(fi => fi.InvestorName).Distinct().OrderBy(n => n));
                            doc.MainDocumentPart.FootnotesPart.Footnotes.AppendChild(
                                new Footnote(
                                    new Paragraph(
                                        new Run(
                                            new RunProperties(
                                                new VerticalTextAlignment {
                                Val = VerticalPositionValues.Superscript
                            }
                                                ),
                                            new FootnoteReferenceMark()
                                            ),
                                        new Run(new Text(" " + fundInvestorNames)
                            {
                                Space = SpaceProcessingModeValues.Preserve
                            })
                                        )
                                    )
                            {
                                Id = footnoteId
                            }
                                );
                            footnoteId++;
                        }

                        foreach (var scoredPair in pair.Value.OrderByDescending(p => p.Value))
                        {
                            if (!used.Contains(scoredPair.Key))
                            {
                                used.Add(scoredPair.Key);
                                var contentParagraph = body.AppendChild(new Paragraph(
                                                                            new ParagraphProperties(new NumberingProperties(new NumberingLevelReference {
                                    Val = 0
                                }, new NumberingId {
                                    Val = provisionTypeSectionNumber
                                }))));
                                var diffs = Dmp.diff_wordMode(pair.Key.Content, scoredPair.Key.Content);
                                Dmp.diff_cleanupSemantic(diffs);
                                foreach (var diff in diffs)
                                {
                                    if (diff.operation == Operation.EQUAL)
                                    {
                                        contentParagraph.AppendChild(new Run(new Text($"{diff.text}")
                                        {
                                            Space = SpaceProcessingModeValues.Preserve
                                        }));
                                    }
                                    else if (diff.operation == Operation.INSERT)
                                    {
                                        contentParagraph.AppendChild(new Run(new RunProperties(new Color {
                                            Val = "FF0000"
                                        }), new Text($"{diff.text}")
                                        {
                                            Space = SpaceProcessingModeValues.Preserve
                                        }));
                                    }
                                }

                                var footnoteReference = new FootnoteReference {
                                    Id = footnoteId
                                };
                                var footnoteReferenceRun = new Run(new RunProperties(new VerticalTextAlignment {
                                    Val = VerticalPositionValues.Superscript
                                }));
                                footnoteReferenceRun.AppendChild(footnoteReference);
                                contentParagraph.AppendChild(footnoteReferenceRun);

                                var fundInvestorNames = string.Join("; ", scoredPair.Key.FundInvestors.Select(fi => fi.InvestorName).Distinct().OrderBy(n => n));
                                doc.MainDocumentPart.FootnotesPart.Footnotes.AppendChild(
                                    new Footnote(
                                        new Paragraph(
                                            new Run(
                                                new RunProperties(
                                                    new VerticalTextAlignment {
                                    Val = VerticalPositionValues.Superscript
                                }
                                                    ),
                                                new FootnoteReferenceMark()
                                                ),
                                            new Run(new Text(" " + fundInvestorNames)
                                {
                                    Space = SpaceProcessingModeValues.Preserve
                                })
                                            )

                                        )
                                {
                                    Id = footnoteId
                                }
                                    );
                                footnoteId++;
                            }
                        }
                    }
                }
            }

            return(stream);
        }