use of com.lowagie.text.rtf.text.RtfChunk in project itext2 by albfernandez.
the class RtfListItem method writeContent.
/**
* Writes the content of this RtfListItem.
*/
public void writeContent(final OutputStream result) throws IOException {
if (this.paragraphStyle.getSpacingBefore() > 0) {
result.write(RtfParagraphStyle.SPACING_BEFORE);
result.write(intToByteArray(paragraphStyle.getSpacingBefore()));
}
if (this.paragraphStyle.getSpacingAfter() > 0) {
result.write(RtfParagraphStyle.SPACING_AFTER);
result.write(intToByteArray(this.paragraphStyle.getSpacingAfter()));
}
if (this.paragraphStyle.getLineLeading() > 0) {
result.write(RtfParagraph.LINE_SPACING);
result.write(intToByteArray(this.paragraphStyle.getLineLeading()));
}
for (int i = 0; i < chunks.size(); i++) {
RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i);
if (rtfElement instanceof RtfChunk) {
((RtfChunk) rtfElement).setSoftLineBreaks(true);
} else if (rtfElement instanceof RtfList) {
result.write(RtfParagraph.PARAGRAPH);
this.containsInnerList = true;
}
rtfElement.writeContent(result);
if (rtfElement instanceof RtfList) {
switch(this.parentList.getLevelFollowValue()) {
case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING:
break;
case RtfListLevel.LIST_LEVEL_FOLLOW_TAB:
this.parentList.writeListBeginning(result);
result.write(RtfList.TAB);
break;
case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE:
this.parentList.writeListBeginning(result);
result.write(DocWriter.getISOBytes(" "));
break;
}
}
}
}
use of com.lowagie.text.rtf.text.RtfChunk in project itext2 by albfernandez.
the class RtfMapper method mapElement.
/**
* Takes an Element subclass and returns an array of RtfBasicElement
* subclasses, that contained the mapped RTF equivalent to the Element
* passed in.
*
* @param element The Element to wrap
* @return An array of RtfBasicElement wrapping the Element
* @throws DocumentException
*/
public RtfBasicElement[] mapElement(Element element) throws DocumentException {
ArrayList rtfElements = new ArrayList();
if (element instanceof RtfBasicElement) {
RtfBasicElement rtfElement = (RtfBasicElement) element;
rtfElement.setRtfDocument(this.rtfDoc);
return new RtfBasicElement[] { rtfElement };
}
switch(element.type()) {
case Element.CHUNK:
Chunk chunk = (Chunk) element;
if (chunk.hasAttributes()) {
if (chunk.getAttributes().containsKey(Chunk.IMAGE)) {
rtfElements.add(new RtfImage(rtfDoc, chunk.getImage()));
} else if (chunk.getAttributes().containsKey(Chunk.NEWPAGE)) {
rtfElements.add(new RtfNewPage(rtfDoc));
} else if (chunk.getAttributes().containsKey(Chunk.TAB)) {
Float tabPos = (Float) ((Object[]) chunk.getAttributes().get(Chunk.TAB))[1];
RtfTab tab = new RtfTab(tabPos.floatValue(), RtfTab.TAB_LEFT_ALIGN);
tab.setRtfDocument(rtfDoc);
rtfElements.add(tab);
rtfElements.add(new RtfChunk(rtfDoc, new Chunk("\t")));
} else {
rtfElements.add(new RtfChunk(rtfDoc, (Chunk) element));
}
} else {
rtfElements.add(new RtfChunk(rtfDoc, (Chunk) element));
}
break;
case Element.PHRASE:
rtfElements.add(new RtfPhrase(rtfDoc, (Phrase) element));
break;
case Element.PARAGRAPH:
rtfElements.add(new RtfParagraph(rtfDoc, (Paragraph) element));
break;
case Element.ANCHOR:
rtfElements.add(new RtfAnchor(rtfDoc, (Anchor) element));
break;
case Element.ANNOTATION:
rtfElements.add(new RtfAnnotation(rtfDoc, (Annotation) element));
break;
case Element.IMGRAW:
case Element.IMGTEMPLATE:
case Element.JPEG:
rtfElements.add(new RtfImage(rtfDoc, (Image) element));
break;
case Element.AUTHOR:
case Element.SUBJECT:
case Element.KEYWORDS:
case Element.TITLE:
case Element.PRODUCER:
case Element.CREATIONDATE:
rtfElements.add(new RtfInfoElement(rtfDoc, (Meta) element));
break;
case Element.LIST:
// TODO: Testing
rtfElements.add(new RtfList(rtfDoc, (List) element));
break;
case Element.LISTITEM:
// TODO: Testing
rtfElements.add(new RtfListItem(rtfDoc, (ListItem) element));
break;
case Element.SECTION:
rtfElements.add(new RtfSection(rtfDoc, (Section) element));
break;
case Element.CHAPTER:
rtfElements.add(new RtfChapter(rtfDoc, (Chapter) element));
break;
case Element.TABLE:
try {
rtfElements.add(new RtfTable(rtfDoc, (Table) element));
} catch (ClassCastException e) {
rtfElements.add(new RtfTable(rtfDoc, ((SimpleTable) element).createTable()));
}
break;
case Element.PTABLE:
try {
rtfElements.add(new RtfTable(rtfDoc, (PdfPTable) element));
} catch (ClassCastException e) {
rtfElements.add(new RtfTable(rtfDoc, ((SimpleTable) element).createTable()));
}
break;
}
return (RtfBasicElement[]) rtfElements.toArray(new RtfBasicElement[rtfElements.size()]);
}
Aggregations