示例#1
0
        public void TestOutlineLevelMixedHeadings()
        {
            builder.AppendHeading("Toplevel heading");

            builder.PushSubHeading();
            builder.SetHeadingLevel(2);
            builder.AppendText("Nested heading", TextStyle.Normal);
            builder.ClearHeadingLevel();
            builder.PopSubHeading();

            Assert.AreEqual(2, doc.LastSection.Elements.Count, "Section has incorrect # paragraphs");
            Paragraph paragraph0 = (Paragraph)doc.LastSection.Elements[0];
            Paragraph paragraph1 = (Paragraph)doc.LastSection.Elements[1];

            Assert.AreEqual(OutlineLevel.Level1, paragraph0.Format.OutlineLevel);
            Assert.AreEqual(OutlineLevel.Level2, paragraph1.Format.OutlineLevel);
        }
示例#2
0
        /// <summary>
        /// Create a heading with the given heading level.
        /// </summary>
        /// <param name="headingLevel">Heading level.</param>
        private Style CreateHeading(uint headingLevel)
        {
            builder.StartNewParagraph();
            builder.SetHeadingLevel(headingLevel);
            builder.AppendText($"h{headingLevel}", TextStyle.Normal);
            builder.ClearHeadingLevel();
            builder.StartNewParagraph();

            // We could have some assertions here, but we have explicit tests
            // for these casts elsewhere.
            Paragraph     paragraph = (Paragraph)doc.LastSection.Elements[doc.LastSection.Elements.Count - 1];
            FormattedText formatted = (FormattedText)paragraph.Elements[0];

            return(doc.Styles[formatted.Style]);
        }
示例#3
0
        /// <summary>
        /// Render the given heading block to the PDF document.
        /// </summary>
        /// <param name="renderer">The PDF renderer.</param>
        /// <param name="heading">The heading block to be renderered.</param>
        protected override void Write(PdfBuilder renderer, HeadingBlock heading)
        {
            if (heading.Level < 0)
            {
                throw new InvalidOperationException($"Heading level is negative (heading text: '{heading}')");
            }

            if (heading.Inline.Any())
            {
                renderer.StartNewParagraph();

                renderer.SetHeadingLevel((uint)heading.Level);
                renderer.WriteChildren(heading.Inline);
                renderer.ClearHeadingLevel();

                renderer.StartNewParagraph();
            }
        }