/** * 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) { } } }