GetMapper() public method

public GetMapper ( ) : RtfMapper
return iTextSharp.text.rtf.RtfMapper
Beispiel #1
0
 /**
 * Constructs a RtfHeaderFooter for a HeaderFooter.
 *
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
 */
 protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter)
     : base(new Phrase(""), false)
 {
     this.document = doc;
     Paragraph par = new Paragraph();
     par.Alignment = headerFooter.Alignment;
     if (headerFooter.Before != null) {
         par.Add(headerFooter.Before);
     }
     if (headerFooter.IsNumbered()) {
         par.Add(new FD.RtfPageNumber(this.document));
     }
     if (headerFooter.After != null) {
         par.Add(headerFooter.After);
     }
     try {
         this.content = new Object[1];
         this.content[0] = doc.GetMapper().MapElement(par)[0];
         ((IRtfBasicElement) this.content[0]).SetInHeader(true);
     } catch (DocumentException) {
     }
 }
Beispiel #2
0
 /**
 * Constructs a new RtfPhrase for the RtfDocument with the given Phrase
 * 
 * @param doc The RtfDocument this RtfPhrase belongs to
 * @param phrase The Phrase this RtfPhrase is based on
 */
 public RtfPhrase(RtfDocument doc, Phrase phrase) : base(doc) {
     
     if (phrase == null) {
         return;
     }
     
     if (phrase.HasLeading()) {
         this.lineLeading = (int) (phrase.Leading * TWIPS_FACTOR);
     } else {
         this.lineLeading = 0;
     }
     
     ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font);
     for (int i = 0; i < phrase.Count; i++) {
         IElement chunk = (IElement) phrase[i];
         if (chunk is Chunk) {
             ((Chunk) chunk).Font = phraseFont.Difference(((Chunk) chunk).Font);
         }
         try {
             IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
             for (int j = 0; j < rtfElements.Length; j++) {
                 chunks.Add(rtfElements[j]);
             }
         } catch (DocumentException) {
         }
     }
 }
Beispiel #3
0
        /**
        * Constructs a new RtfList for the specified List.
        *
        * @param doc The RtfDocument this RtfList belongs to
        * @param list The List this RtfList is based on
        * @since 2.1.3
        */
        public RtfList(RtfDocument doc, List list)
            : base(doc)
        {
            // setup the listlevels
            // Then, setup the list data below

            // setup 1 listlevel if it's a simple list
            // setup 9 if it's a regular list
            // setup 9 if it's a hybrid list (default)
            CreateDefaultLevels();

            this.items = new ArrayList();       // list content
            RtfListLevel ll = (RtfListLevel)this.listLevels[0];

            // get the list number or create a new one adding it to the table
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

            if (list.SymbolIndent > 0 && list.IndentationLeft > 0) {
                ll.SetFirstIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1));
                ll.SetLeftIndent((int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR));
            } else if (list.SymbolIndent > 0) {
                ll.SetFirstIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1));
                ll.SetLeftIndent((int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR));
            } else if (list.IndentationLeft > 0) {
                ll.SetFirstIndent(0);
                ll.SetLeftIndent((int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR));
            } else {
                ll.SetFirstIndent(0);
                ll.SetLeftIndent(0);
            }
            ll.SetRightIndent((int) (list.IndentationRight * RtfElement.TWIPS_FACTOR));
            ll.SetSymbolIndent((int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR));
            ll.CorrectIndentation();
            ll.SetTentative(false);

            if (list is RomanList) {
                if (list.Lowercase) {
                    ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_ROMAN);
                } else {
                    ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_ROMAN);
                }
            } else if (list.Numbered) {
                ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED);
            } else if (list.Lettered) {
                if (list.Lowercase) {
                    ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_LETTERS);
                } else {
                    ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_LETTERS);
                }
            }
            else {
            //          Paragraph p = new Paragraph();
            //          p.Add(new Chunk(list.GetPreSymbol()) );
            //          p.Add(list.GetSymbol());
            //          p.Add(new Chunk(list.GetPostSymbol()) );
            //          ll.SetBulletChunk(list.GetSymbol());
                ll.SetBulletCharacter(list.PreSymbol + list.Symbol.Content + list.PostSymbol);
                ll.SetListType(RtfListLevel.LIST_TYPE_BULLET);
            }

            // now setup the actual list contents.
            for (int i = 0; i < list.Items.Count; i++) {
                try {
                    IElement element = (IElement) list.Items[i];

                    if (element.Type == Element.CHUNK) {
                        element = new ListItem((Chunk) element);
                    }
                    if (element is ListItem) {
                        ll.SetAlignment(((ListItem) element).Alignment);
                    }
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element);
                    for (int j = 0; j < rtfElements.Length; j++) {
                        IRtfBasicElement rtfElement = rtfElements[j];
                        if (rtfElement is RtfList) {
                            ((RtfList) rtfElement).SetParentList(this);
                        } else if (rtfElement is RtfListItem) {
                            ((RtfListItem) rtfElement).SetParent(ll);
                        }
                        ll.SetFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))) );
                        if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0) {
                            // only set this to bullet symbol is not default
                            ll.SetBulletFont( list.Symbol.Font);
                            ll.SetBulletCharacter(list.Symbol.Content.Substring(0, 1));
                        } else
                        if (list.Symbol != null && list.Symbol.Font != null) {
                            ll.SetBulletFont(list.Symbol.Font);

                        } else {
                            ll.SetBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
                        }
                        items.Add(rtfElement);
                    }

                } catch (DocumentException) {
                }
            }
        }
 /**
 * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
 * 
 * @param doc The RtfDocument this RtfParagraph belongs to
 * @param paragraph The Paragraph that this RtfParagraph is based on
 */
 public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc) {
     ST.RtfFont baseFont = null;
     if (paragraph.Font is ST.RtfParagraphStyle) {
         this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle) paragraph.Font).GetStyleName());
         baseFont = this.paragraphStyle;
     } else {
         baseFont = new ST.RtfFont(this.document, paragraph.Font);
         this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal"));
         this.paragraphStyle.SetAlignment(paragraph.Alignment);
         this.paragraphStyle.SetFirstLineIndent((int) (paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR));
         this.paragraphStyle.SetIndentLeft((int) (paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR));
         this.paragraphStyle.SetIndentRight((int) (paragraph.IndentationRight * RtfElement.TWIPS_FACTOR));
         this.paragraphStyle.SetSpacingBefore((int) (paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR));
         this.paragraphStyle.SetSpacingAfter((int) (paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR));
         if (paragraph.HasLeading()) {
             this.paragraphStyle.SetLineLeading((int) (paragraph.Leading * RtfElement.TWIPS_FACTOR));
         }
         this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether);
     }
     
     for (int i = 0; i < paragraph.Count; i++) {
         IElement chunk = (IElement) paragraph[i];
         if (chunk is Chunk) {
             ((Chunk) chunk).Font = baseFont.Difference(((Chunk) chunk).Font);
         } else if (chunk is RtfImage) {
             ((RtfImage) chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment());
         }
         try {
             IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
             for(int j = 0; j < rtfElements.Length; j++) {
                 chunks.Add(rtfElements[j]);
             }
         } catch (DocumentException) {
         }
     }
 }
Beispiel #5
0
        /**
        * Constructs a new RtfList for the specified List.
        *
        * @param doc The RtfDocument this RtfList belongs to
        * @param list The List this RtfList is based on
        */
        public RtfList(RtfDocument doc, List list)
            : base(doc)
        {
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

            this.items = new ArrayList();
            if (list.SymbolIndent > 0 && list.IndentationLeft > 0) {
                this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
                this.leftIndent = (int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR);
            } else if (list.SymbolIndent > 0) {
                this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
                this.leftIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR);
            } else if (list.IndentationLeft > 0) {
                this.firstIndent = 0;
                this.leftIndent = (int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR);
            } else {
                this.firstIndent = 0;
                this.leftIndent = 0;
            }
            this.rightIndent = (int) (list.IndentationRight * RtfElement.TWIPS_FACTOR);
            this.symbolIndent = (int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR);
            this.numbered = list.IsNumbered();

            for (int i = 0; i < list.Items.Count; i++) {
                try {
                    IElement element = (IElement) list.Items[i];
                    if (element.Type == Element.CHUNK) {
                        element = new ListItem((Chunk) element);
                    }
                    if (element is ListItem) {
                        this.alignment = ((ListItem) element).Alignment;
                    }
                    IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element);
                    if (rtfElement is RtfList) {
                        ((RtfList) rtfElement).SetListNumber(listNumber);
                        ((RtfList) rtfElement).SetListLevel(listLevel + 1);
                        ((RtfList) rtfElement).SetParent(this);
                    } else if (rtfElement is RtfListItem) {
                        ((RtfListItem) rtfElement).SetParent(this);
                        ((RtfListItem) rtfElement).InheritListSettings(listNumber, listLevel + 1);
                    }
                    items.Add(rtfElement);
                } catch (DocumentException ) {
                }
            }
            if (this.listLevel == 0) {
                CorrectIndentation();
            }

            fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
            fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
        }
Beispiel #6
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) {
     }
 }
Beispiel #7
0
        /**
        * Constructs a new RtfPhrase for the RtfDocument with the given Phrase
        *
        * @param doc The RtfDocument this RtfPhrase belongs to
        * @param phrase The Phrase this RtfPhrase is based on
        */
        public RtfPhrase(RtfDocument doc, Phrase phrase)
            : base(doc)
        {
            if (phrase == null) {
                return;
            }

            if (phrase.LeadingDefined) {
                this.lineLeading = (int) (phrase.Leading * TWIPS_FACTOR);
            } else {
                this.lineLeading = 0;
            }

            ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font);
            for (int i = 0; i < phrase.Count; i++) {
                IElement chunk = (IElement) phrase[i];
                if (chunk is Chunk) {
                    ((Chunk) chunk).Font = phraseFont.Difference(((Chunk) chunk).Font);
                }
                try {
                    chunks.Add(doc.GetMapper().MapElement(chunk));
                } catch (DocumentException) {
                }
            }
        }