* @param doc The RtfDocument this RtfParagraph belongs to
* @param paragraph The Paragraph that this RtfParagraph is based on
*/
public RtfParagraph(RtfDocument doc, Paragraph paragraph) {
super(doc);
RtfFont baseFont = null;
if(paragraph.getFont() instanceof RtfParagraphStyle) {
this.paragraphStyle = this.document.getDocumentHeader().getRtfParagraphStyle(((RtfParagraphStyle) paragraph.getFont()).getStyleName());
baseFont = this.paragraphStyle;
} else {
baseFont = new RtfFont(this.document, paragraph.getFont());
this.paragraphStyle = new RtfParagraphStyle(this.document, this.document.getDocumentHeader().getRtfParagraphStyle("Normal"));
this.paragraphStyle.setAlignment(paragraph.getAlignment());
this.paragraphStyle.setFirstLineIndent((int) (paragraph.getFirstLineIndent() * RtfElement.TWIPS_FACTOR));
this.paragraphStyle.setIndentLeft((int) (paragraph.getIndentationLeft() * RtfElement.TWIPS_FACTOR));
this.paragraphStyle.setIndentRight((int) (paragraph.getIndentationRight() * RtfElement.TWIPS_FACTOR));
this.paragraphStyle.setSpacingBefore((int) (paragraph.getSpacingBefore() * RtfElement.TWIPS_FACTOR));
this.paragraphStyle.setSpacingAfter((int) (paragraph.getSpacingAfter() * RtfElement.TWIPS_FACTOR));
if(paragraph.hasLeading()) {
this.paragraphStyle.setLineLeading((int) (paragraph.getLeading() * RtfElement.TWIPS_FACTOR));
}
this.paragraphStyle.setKeepTogether(paragraph.getKeepTogether());
}
for(int i = 0; i < paragraph.size(); i++) {
LwgElement chunk = (LwgElement) paragraph.get(i);
if(chunk instanceof Chunk) {
((Chunk) chunk).setFont(baseFont.difference(((Chunk) chunk).getFont()));
} else if(chunk instanceof RtfImage) {
((RtfImage) chunks.get(i)).setAlignment(this.paragraphStyle.getAlignment());
}
try {
RtfBasicElement[] rtfElements = doc.getMapper().mapElement(chunk);