Inheritance: RtfPhrase
 /// <summary>
 /// Constructs a RtfSection for a given Section. If the autogenerateTOCEntries
 /// property of the RtfDocument is set and the title is not empty then a TOC entry
 /// is generated for the title.
 /// </summary>
 /// <param name="doc">The RtfDocument this RtfSection belongs to</param>
 /// <param name="section">The Section this RtfSection is based on</param>
 public RtfSection(RtfDocument doc, Section section) : base(doc)
 {
     Items = new ArrayList();
     try
     {
         if (section.Title != null)
         {
             Title = (RtfParagraph)doc.GetMapper().MapElement(section.Title)[0];
         }
         if (Document.GetAutogenerateTocEntries())
         {
             StringBuilder titleText = new StringBuilder();
             foreach (IElement element in section.Title)
             {
                 if (element.Type == Element.CHUNK)
                 {
                     titleText.Append(((Chunk)element).Content);
                 }
             }
             if (titleText.ToString().Trim().Length > 0)
             {
                 FD.RtfTocEntry tocEntry = new FD.RtfTocEntry(titleText.ToString());
                 tocEntry.SetRtfDocument(Document);
                 Items.Add(tocEntry);
             }
         }
         foreach (IElement element in section)
         {
             IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element);
             for (int i = 0; i < rtfElements.Length; i++)
             {
                 if (rtfElements[i] != null)
                 {
                     Items.Add(rtfElements[i]);
                 }
             }
         }
         updateIndentation(section.IndentationLeft, section.IndentationRight, section.Indentation);
     }
     catch (DocumentException)
     {
     }
 }
Example #2
0
        /**
        * Takes an Element subclass and returns the correct IRtfBasicElement
        * subclass, that wraps the Element subclass.
        *
        * @param element The Element to wrap
        * @return A IRtfBasicElement wrapping the Element
        * @throws DocumentException
        */
        public IRtfBasicElement MapElement(IElement element)
        {
            IRtfBasicElement rtfElement = null;

            if (element is IRtfBasicElement) {
                rtfElement = (IRtfBasicElement) element;
                rtfElement.SetRtfDocument(this.rtfDoc);
                return rtfElement;
            }
            switch (element.Type) {
                case Element.CHUNK:
                    if (((Chunk) element).GetImage() != null) {
                        rtfElement = new RtfImage(rtfDoc, ((Chunk) element).GetImage());
                    } else if (((Chunk) element).HasAttributes() && ((Chunk) element).Attributes.ContainsKey(Chunk.NEWPAGE)) {
                        rtfElement = new RtfNewPage(rtfDoc);
                    } else {
                        rtfElement = new RtfChunk(rtfDoc, (Chunk) element);
                    }
                    break;
                case Element.PHRASE:
                    rtfElement = new RtfPhrase(rtfDoc, (Phrase) element);
                    break;
                case Element.PARAGRAPH:
                    rtfElement = new RtfParagraph(rtfDoc, (Paragraph) element);
                    break;
                case Element.ANCHOR:
                    rtfElement = new RtfAnchor(rtfDoc, (Anchor) element);
                    break;
                case Element.ANNOTATION:
                    rtfElement = new RtfAnnotation(rtfDoc, (Annotation) element);
                    break;
                case Element.IMGRAW:
                case Element.IMGTEMPLATE:
                case Element.JPEG:
                    rtfElement = new RtfImage(rtfDoc, (Image) element);
                    break;
                case Element.AUTHOR:
                case Element.SUBJECT:
                case Element.KEYWORDS:
                case Element.TITLE:
                case Element.PRODUCER:
                case Element.CREATIONDATE:
                    rtfElement = new RtfInfoElement(rtfDoc, (Meta) element);
                    break;
                case Element.LIST:
                    rtfElement = new RtfList(rtfDoc, (List) element);
                    break;
                case Element.LISTITEM:
                    rtfElement = new RtfListItem(rtfDoc, (ListItem) element);
                    break;
                case Element.SECTION:
                    rtfElement = new RtfSection(rtfDoc, (Section) element);
                    break;
                case Element.CHAPTER:
                    rtfElement = new RtfChapter(rtfDoc, (Chapter) element);
                    break;
                case Element.TABLE:
                    try {
                        rtfElement = new TB.RtfTable(rtfDoc, (Table) element);
                    }
                    catch (InvalidCastException) {
                        rtfElement = new TB.RtfTable(rtfDoc, ((SimpleTable) element).CreateTable());
                    }
                    break;
            }

            return rtfElement;
        }
Example #3
0
 /**
 * Constructs a RtfSection for a given Section. If the autogenerateTOCEntries
 * property of the RtfDocument is set and the title is not empty then a TOC entry
 * is generated for the title.
 *
 * @param doc The RtfDocument this RtfSection belongs to
 * @param section The Section this RtfSection is based on
 */
 public RtfSection(RtfDocument doc, Section section)
     : base(doc)
 {
     items = new ArrayList();
     try {
         if (section.Title != null) {
             this.title = (RtfParagraph) doc.GetMapper().MapElement(section.Title);
         }
         if (document.GetAutogenerateTOCEntries()) {
             StringBuilder titleText = new StringBuilder();
             foreach (IElement element in section.Title) {
                 if (element.Type == Element.CHUNK) {
                     titleText.Append(((Chunk) element).Content);
                 }
             }
             if (titleText.ToString().Trim().Length > 0) {
                 FD.RtfTOCEntry tocEntry = new FD.RtfTOCEntry(titleText.ToString());
                 tocEntry.SetRtfDocument(this.document);
                 this.items.Add(tocEntry);
             }
         }
         foreach (IElement element in section) {
             IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element);
             if (rtfElement != null) {
                 items.Add(rtfElement);
             }
         }
         UpdateIndentation(section.IndentationLeft, section.IndentationRight, section.Indentation);
     } catch (DocumentException) {
     }
 }