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