iTextSharp.text.rtf.RtfMapper.MapElement C# (CSharp) Method

MapElement() public method

public MapElement ( IElement element ) : IRtfBasicElement[]
element IElement
return IRtfBasicElement[]
        public IRtfBasicElement[] MapElement(IElement element) {
            ArrayList rtfElements = new ArrayList();

            if (element is IRtfBasicElement) {
                IRtfBasicElement rtfElement = (IRtfBasicElement) element;
                rtfElement.SetRtfDocument(this.rtfDoc);
                return new IRtfBasicElement[]{rtfElement};
            }
            switch (element.Type) {
                case Element.CHUNK:
                    Chunk chunk = (Chunk) element;
                    if (chunk.HasAttributes()) {
                        if (chunk.Attributes.ContainsKey(Chunk.IMAGE)) {
                            rtfElements.Add(new RtfImage(rtfDoc, chunk.GetImage()));
                        } else if (chunk.Attributes.ContainsKey(Chunk.NEWPAGE)) {
                            rtfElements.Add(new RtfNewPage(rtfDoc));
                        } else if (chunk.Attributes.ContainsKey(Chunk.TAB)) {
                            float tabPos = (float) ((Object[]) chunk.Attributes[Chunk.TAB])[1];
                            RtfTab tab = new RtfTab(tabPos, RtfTab.TAB_LEFT_ALIGN);
                            tab.SetRtfDocument(rtfDoc);
                            rtfElements.Add(tab);
                            rtfElements.Add(new RtfChunk(rtfDoc, new Chunk("\t")));
                        } else {
                            rtfElements.Add(new RtfChunk(rtfDoc, (Chunk) element));
                        }
                    } else {
                        rtfElements.Add(new RtfChunk(rtfDoc, (Chunk) element));
                    }
                    break;
                case Element.PHRASE:
                    rtfElements.Add(new RtfPhrase(rtfDoc, (Phrase) element));
                    break;
                case Element.PARAGRAPH:
                    rtfElements.Add(new RtfParagraph(rtfDoc, (Paragraph) element));
                    break;
                case Element.ANCHOR:
                    rtfElements.Add(new RtfAnchor(rtfDoc, (Anchor) element));
                    break;
                case Element.ANNOTATION:
                    rtfElements.Add(new RtfAnnotation(rtfDoc, (Annotation) element));
                    break;
                case Element.IMGRAW:
                case Element.IMGTEMPLATE:
                case Element.JPEG:
                    rtfElements.Add(new RtfImage(rtfDoc, (Image) element));
                    break;
                case Element.AUTHOR: 
                case Element.SUBJECT:
                case Element.KEYWORDS:
                case Element.TITLE:
                case Element.PRODUCER:
                case Element.CREATIONDATE:
                    rtfElements.Add(new RtfInfoElement(rtfDoc, (Meta) element));
                    break;
                case Element.LIST:
                    rtfElements.Add(new RtfList(rtfDoc, (List) element));
                    break;
                case Element.LISTITEM:
                    rtfElements.Add(new RtfListItem(rtfDoc, (ListItem) element));
                    break;
                case Element.SECTION:
                    rtfElements.Add(new RtfSection(rtfDoc, (Section) element));
                    break;
                case Element.CHAPTER:
                    rtfElements.Add(new RtfChapter(rtfDoc, (Chapter) element));
                    break;
                case Element.TABLE:
                    try {
                        rtfElements.Add(new RtfTable(rtfDoc, (Table) element));
                    }
                    catch (InvalidCastException) {
                        rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable) element).CreateTable()));
                    }
                    break;
                case Element.PTABLE:
                    try {
                        rtfElements.Add(new RtfTable(rtfDoc, (PdfPTable) element));
                    }
                    catch(InvalidCastException) {
                        rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable) element).CreateTable()));
                    }
                    break;
            }
            
            return (IRtfBasicElement[]) rtfElements.ToArray(typeof(IRtfBasicElement));
        }
    }