/** * 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) { 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++) { Element chunk = (Element) 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); for (int j = 0; j < rtfElements.length; j++) { chunks.add(rtfElements[j]); } } catch (DocumentException de) { } } }
/** * 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) { super(doc); this.listNumber = document.getDocumentHeader().getListNumber(this); this.items = new ArrayList(); if (list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) { this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1); this.leftIndent = (int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR); } else if (list.getSymbolIndent() > 0) { this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1); this.leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR); } else if (list.getIndentationLeft() > 0) { this.firstIndent = 0; this.leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR); } else { this.firstIndent = 0; this.leftIndent = 0; } this.rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR); this.symbolIndent = (int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR); if (list instanceof RomanList) { if (list.isLowercase()) { this.listType = LIST_TYPE_LOWER_ROMAN; } else { this.listType = LIST_TYPE_UPPER_ROMAN; } } else if (list.isNumbered()) { this.listType = LIST_TYPE_NUMBERED; } else if (list.isLettered()) { if (list.isLowercase()) { this.listType = LIST_TYPE_LOWER_LETTERS; } else { this.listType = LIST_TYPE_UPPER_LETTERS; } } for (int i = 0; i < list.getItems().size(); i++) { try { Element element = (Element) list.getItems().get(i); if (element.type() == Element.CHUNK) { element = new ListItem((Chunk) element); } if (element instanceof ListItem) { this.alignment = ((ListItem) element).getAlignment(); } RtfBasicElement rtfElement = doc.getMapper().mapElement(element); if (rtfElement instanceof RtfList) { ((RtfList) rtfElement).setListNumber(listNumber); ((RtfList) rtfElement).setListLevel(listLevel + 1); ((RtfList) rtfElement).setParent(this); } else if (rtfElement instanceof RtfListItem) { ((RtfListItem) rtfElement).setParent(this); ((RtfListItem) rtfElement).inheritListSettings(listNumber, listLevel + 1); } items.add(rtfElement); } catch (DocumentException de) { de.printStackTrace(); } } if (this.listLevel == 0) { correctIndentation(); } fontNumber = new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))); if (list.getSymbol() != null && list.getSymbol().getFont() != null && !list.getSymbol().getContent().startsWith("-") && list.getSymbol().getContent().length() > 0) { // only set this to bullet symbol is not default this.fontBullet = new RtfFont(document, list.getSymbol().getFont()); this.bulletCharacter = list.getSymbol().getContent().substring(0, 1); } else { this.fontBullet = new RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0))); } }