Search in sources :

Example 1 with RtfBasicElement

use of com.lowagie.text.rtf.RtfBasicElement 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;
            }
        }
    }
}
Also used : RtfChunk(com.lowagie.text.rtf.text.RtfChunk) RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 2 with RtfBasicElement

use of com.lowagie.text.rtf.RtfBasicElement in project itext2 by albfernandez.

the class RtfListItem method writeDefinition.

/**
 * Writes the definition of the first element in this RtfListItem that is
 * an instanceof {@link RtfList} to the given stream.<br>
 * If this item does not contain a {@link RtfList} element nothing is written
 * and the method returns <code>false</code>.
 *
 * @param out destination stream
 * @return <code>true</code> if a RtfList definition was written, <code>false</code> otherwise
 * @throws IOException
 */
public boolean writeDefinition(OutputStream out) throws IOException {
    for (int i = 0; i < chunks.size(); i++) {
        RtfBasicElement rtfElement = (RtfBasicElement) chunks.get(i);
        if (rtfElement instanceof RtfList) {
            RtfList rl = (RtfList) rtfElement;
            rl.writeDefinition(out);
            return true;
        }
    }
    return false;
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 3 with RtfBasicElement

use of com.lowagie.text.rtf.RtfBasicElement in project itext2 by albfernandez.

the class RtfCell method importCell.

/**
 * Imports the Cell properties into the RtfCell
 *
 * @param cell The Cell to import
 */
private void importCell(Cell cell) {
    this.content = new ArrayList();
    if (cell == null) {
        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.getParentTable().getBorders());
        return;
    }
    this.colspan = cell.getColspan();
    this.rowspan = cell.getRowspan();
    if (cell.getRowspan() > 1) {
        this.mergeType = MERGE_VERT_PARENT;
    }
    if (cell instanceof RtfCell) {
        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell) cell).getBorders());
    } else {
        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.getBorder(), cell.getBorderWidth(), cell.getBorderColor());
    }
    this.verticalAlignment = cell.getVerticalAlignment();
    if (cell.getBackgroundColor() == null) {
        this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
    } else {
        this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor());
    }
    this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();
    Iterator cellIterator = cell.getElements();
    Paragraph container = null;
    while (cellIterator.hasNext()) {
        try {
            Element element = (Element) cellIterator.next();
            // should we wrap it in a paragraph
            if (!(element instanceof Paragraph) && !(element instanceof List)) {
                if (container != null) {
                    container.add(element);
                } else {
                    container = new Paragraph();
                    container.setAlignment(cell.getHorizontalAlignment());
                    container.add(element);
                }
            } else {
                if (container != null) {
                    RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
                    for (int i = 0; i < rtfElements.length; i++) {
                        rtfElements[i].setInTable(true);
                        this.content.add(rtfElements[i]);
                    }
                    container = null;
                }
                // with that of enclosing cell
                if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {
                    ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());
                }
                RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element);
                for (int i = 0; i < rtfElements.length; i++) {
                    rtfElements[i].setInTable(true);
                    this.content.add(rtfElements[i]);
                }
            }
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
    if (container != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException de) {
            de.printStackTrace();
        }
    }
}
Also used : Element(com.lowagie.text.Element) RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement) RtfExtendedElement(com.lowagie.text.rtf.RtfExtendedElement) DocumentException(com.lowagie.text.DocumentException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) RtfColor(com.lowagie.text.rtf.style.RtfColor) ArrayList(java.util.ArrayList) List(com.lowagie.text.List) RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement) Paragraph(com.lowagie.text.Paragraph) RtfParagraph(com.lowagie.text.rtf.text.RtfParagraph)

Example 4 with RtfBasicElement

use of com.lowagie.text.rtf.RtfBasicElement in project itext2 by albfernandez.

the class RtfCell method writeContent.

/**
 * Write the content of this RtfCell
 */
public void writeContent(final OutputStream result) throws IOException {
    if (this.content.size() == 0) {
        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        if (this.parentRow.getParentTable().getTableFitToPage()) {
            result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
        }
        result.write(RtfParagraph.IN_TABLE);
    } else {
        for (int i = 0; i < this.content.size(); i++) {
            RtfBasicElement rtfElement = (RtfBasicElement) this.content.get(i);
            if (rtfElement instanceof RtfParagraph) {
                ((RtfParagraph) rtfElement).setKeepTogetherWithNext(this.parentRow.getParentTable().getTableFitToPage());
            }
            rtfElement.writeContent(result);
            if (rtfElement instanceof RtfParagraph && i < (this.content.size() - 1)) {
                result.write(RtfParagraph.PARAGRAPH);
            }
        }
    }
    result.write(DocWriter.getISOBytes("\\cell"));
}
Also used : RtfParagraph(com.lowagie.text.rtf.text.RtfParagraph) RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 5 with RtfBasicElement

use of com.lowagie.text.rtf.RtfBasicElement in project itext2 by albfernandez.

the class RtfChapter method writeContent.

/**
 * Writes the RtfChapter and its contents
 */
public void writeContent(final OutputStream result) throws IOException {
    if (this.document.getLastElementWritten() != null && !(this.document.getLastElementWritten() instanceof RtfChapter)) {
        result.write(DocWriter.getISOBytes("\\page"));
    }
    result.write(DocWriter.getISOBytes("\\sectd"));
    document.getDocumentHeader().writeSectionDefinition(result);
    if (this.title != null) {
        this.title.writeContent(result);
    }
    for (int i = 0; i < items.size(); i++) {
        RtfBasicElement rbe = (RtfBasicElement) items.get(i);
        rbe.writeContent(result);
    }
    result.write(DocWriter.getISOBytes("\\sect"));
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Aggregations

RtfBasicElement (com.lowagie.text.rtf.RtfBasicElement)12 RtfParagraph (com.lowagie.text.rtf.text.RtfParagraph)3 DocumentException (com.lowagie.text.DocumentException)2 Element (com.lowagie.text.Element)2 List (com.lowagie.text.List)2 Paragraph (com.lowagie.text.Paragraph)2 RtfExtendedElement (com.lowagie.text.rtf.RtfExtendedElement)2 RtfColor (com.lowagie.text.rtf.style.RtfColor)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Image (com.lowagie.text.Image)1 Phrase (com.lowagie.text.Phrase)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1 RtfChunk (com.lowagie.text.rtf.text.RtfChunk)1