/// <summary> /// Constructs a RtfHeaderFooter for a HeaderFooter. /// </summary> /// <param name="doc">The RtfDocument this RtfHeaderFooter belongs to</param> /// <param name="headerFooter">The HeaderFooter to base this RtfHeaderFooter on</param> protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter) : base(new Phrase(""), false) { _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(_document)); } if (headerFooter.After != null) { par.Add(headerFooter.After); } try { _content = new object[1]; _content[0] = doc.GetMapper().MapElement(par)[0]; ((IRtfBasicElement)_content[0]).SetInHeader(true); } catch (DocumentException) { } }
/// <summary> /// Sets the RtfDocument this RtfElement belongs to /// </summary> /// <param name="doc">The RtfDocument to use</param> public void SetRtfDocument(RtfDocument doc) { _document = doc; if (_document != null) { for (int i = 0; i < _content.Length; i++) { try { if (_content[i] is Element) { _content[i] = _document.GetMapper().MapElement((IElement)_content[i])[0]; ((IRtfBasicElement)_content[i]).SetInHeader(true); } else if (_content[i] is IRtfBasicElement) { ((IRtfBasicElement)_content[i]).SetRtfDocument(_document); ((IRtfBasicElement)_content[i]).SetInHeader(true); } } catch (DocumentException) { } } } }
/** * 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) { } } }
/** * 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) { } } }
/// <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) { } }
/// <summary> /// Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph. /// </summary> /// <param name="doc">The RtfDocument this RtfParagraph belongs to</param> /// <param name="paragraph">The Paragraph that this RtfParagraph is based on</param> public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc) { ST.RtfFont baseFont = null; if (paragraph.Font is ST.RtfParagraphStyle) { ParagraphStyle = Document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle)paragraph.Font).GetStyleName()); baseFont = ParagraphStyle; } else { baseFont = new ST.RtfFont(Document, paragraph.Font); ParagraphStyle = new ST.RtfParagraphStyle(Document, Document.GetDocumentHeader().GetRtfParagraphStyle("Normal")); ParagraphStyle.SetAlignment(paragraph.Alignment); ParagraphStyle.SetFirstLineIndent((int)(paragraph.FirstLineIndent * TWIPS_FACTOR)); ParagraphStyle.SetIndentLeft((int)(paragraph.IndentationLeft * TWIPS_FACTOR)); ParagraphStyle.SetIndentRight((int)(paragraph.IndentationRight * TWIPS_FACTOR)); ParagraphStyle.SetSpacingBefore((int)(paragraph.SpacingBefore * TWIPS_FACTOR)); ParagraphStyle.SetSpacingAfter((int)(paragraph.SpacingAfter * TWIPS_FACTOR)); if (paragraph.HasLeading()) { ParagraphStyle.SetLineLeading((int)(paragraph.Leading * TWIPS_FACTOR)); } ParagraphStyle.SetKeepTogether(paragraph.KeepTogether); } for (var i = 0; i < paragraph.Count; i++) { var 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(ParagraphStyle.GetAlignment()); } try { var rtfElements = doc.GetMapper().MapElement(chunk); for (var j = 0; j < rtfElements.Length; j++) { Chunks.Add(rtfElements[j]); } } catch (DocumentException) { } } }
/** * Adds an Element to the Document * * @param element The element to be added * @return <code>false</code> * @throws DocumentException */ public override bool Add(IElement element) { if (pause) { return(false); } IRtfBasicElement rtfElement = rtfDoc.GetMapper().MapElement(element); if (rtfElement != null) { rtfDoc.Add(rtfElement); return(true); } else { return(false); } }
/** * 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.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.LeadingDefined) { 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 { chunks.Add(doc.GetMapper().MapElement(chunk)); } catch (DocumentException) { } } }
/// <summary> /// Constructs a RtfHeaderFooter based on a HeaderFooter with a certain type and displayAt /// location. For internal use only. /// </summary> /// <param name="doc">The RtfDocument this RtfHeaderFooter belongs to</param> /// <param name="headerFooter">The HeaderFooter to base this RtfHeaderFooter on</param> /// <param name="type">The type of RtfHeaderFooter</param> /// <param name="displayAt">The display location of this RtfHeaderFooter</param> protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter, int type, int displayAt) : base(new Phrase(""), false) { _document = doc; _type = type; _displayAt = displayAt; var par = new Paragraph { Alignment = headerFooter.Alignment }; if (headerFooter.Before != null) { par.Add(headerFooter.Before); } if (headerFooter.IsNumbered()) { par.Add(new FD.RtfPageNumber(_document)); } if (headerFooter.After != null) { par.Add(headerFooter.After); } try { _content = new object[1]; if (_document != null) { _content[0] = _document.GetMapper().MapElement(par)[0]; ((IRtfBasicElement)_content[0]).SetInHeader(true); } else { _content[0] = par; } } catch (DocumentException) { } }
/// <summary> /// Constructs a RtfHeaderFooter as a copy of an existing RtfHeaderFooter. /// For internal use only. /// </summary> /// <param name="doc">The RtfDocument this RtfHeaderFooter belongs to</param> /// <param name="headerFooter">The RtfHeaderFooter to copy</param> /// <param name="displayAt">The display location of this RtfHeaderFooter</param> protected internal RtfHeaderFooter(RtfDocument doc, RtfHeaderFooter headerFooter, int displayAt) : base(new Phrase(""), false) { _document = doc; _content = headerFooter.getContent(); _displayAt = displayAt; for (int i = 0; i < _content.Length; i++) { if (_content[i] is IElement) { try { _content[i] = _document.GetMapper().MapElement((IElement)_content[i])[0]; } catch (DocumentException) { } } if (_content[i] is IRtfBasicElement) { ((IRtfBasicElement)_content[i]).SetInHeader(true); } } }
/** * Adds an Element to the Document * * @param element The element to be added * @return <code>false</code> * @throws DocumentException */ public override bool Add(IElement element) { if (pause) { return(false); } IRtfBasicElement[] rtfElements = rtfDoc.GetMapper().MapElement(element); if (rtfElements.Length != 0) { for (int i = 0; i < rtfElements.Length; i++) { if (rtfElements[i] != null) { rtfDoc.Add(rtfElements[i]); } } return(true); } else { return(false); } }
/** * 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) { } } }
/// <summary> /// Imports the Cell properties into the RtfCell /// </summary> /// <param name="cell">The Cell to import</param> private void importCell(Cell cell) { _content = new ArrayList(); if (cell == null) { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, _parentRow.GetParentTable().GetBorders()); return; } colspan = cell.Colspan; rowspan = cell.Rowspan; if (cell.Rowspan > 1) { _mergeType = MergeVertParent; } if (cell is RtfCell) { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, ((RtfCell)cell).GetBorders()); } else { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); } verticalAlignment = cell.VerticalAlignment; if (cell.BackgroundColor == null) { _backgroundColor = new RtfColor(_document, 255, 255, 255); } else { _backgroundColor = new RtfColor(_document, cell.BackgroundColor); } _cellPadding = (int)_parentRow.GetParentTable().GetCellPadding(); Paragraph container = null; foreach (IElement element in cell.Elements) { try { // should we wrap it in a paragraph if (!(element is Paragraph) && !(element is List)) { if (container != null) { container.Add(element); } else { container = new Paragraph { Alignment = cell.HorizontalAlignment }; container.Add(element); } } else { if (container != null) { var rtfElements = _document.GetMapper().MapElement(container); for (var i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element is Paragraph && ((Paragraph)element).Alignment == ALIGN_UNDEFINED) { ((Paragraph)element).Alignment = cell.HorizontalAlignment; } var rtfElements2 = _document.GetMapper().MapElement(element); for (var i = 0; i < rtfElements2.Length; i++) { rtfElements2[i].SetInTable(true); _content.Add(rtfElements2[i]); } } } catch (DocumentException) { } } if (container != null) { try { var rtfElements = _document.GetMapper().MapElement(container); for (var i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } catch (DocumentException) { } } }
/** * 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))); }