Search in sources :

Example 6 with RtfBasicElement

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

the class RtfParagraph method writeContent.

/**
 * Writes the content of this RtfParagraph. First paragraph specific data is written
 * and then the RtfChunks of this RtfParagraph are added.
 */
public void writeContent(final OutputStream result) throws IOException {
    result.write(PARAGRAPH_DEFAULTS);
    result.write(PLAIN);
    if (inTable) {
        result.write(IN_TABLE);
    }
    if (this.paragraphStyle != null) {
        this.paragraphStyle.writeBegin(result);
    }
    result.write(DocWriter.getISOBytes("\\plain"));
    for (int i = 0; i < chunks.size(); i++) {
        RtfBasicElement rbe = (RtfBasicElement) chunks.get(i);
        rbe.writeContent(result);
    }
    if (this.paragraphStyle != null) {
        this.paragraphStyle.writeEnd(result);
    }
    if (!inTable) {
        result.write(PARAGRAPH);
    }
    this.document.outputDebugLinebreak(result);
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 7 with RtfBasicElement

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

the class RtfSection method updateIndentation.

/**
 * Updates the left, right and content indentation of all RtfParagraph and RtfSection
 * elements that this RtfSection contains.
 *
 * @param indentLeft The left indentation to add.
 * @param indentRight The right indentation to add.
 * @param indentContent The content indentation to add.
 */
private void updateIndentation(float indentLeft, float indentRight, float indentContent) {
    if (this.title != null) {
        this.title.setIndentLeft((int) (this.title.getIndentLeft() + indentLeft * RtfElement.TWIPS_FACTOR));
        this.title.setIndentRight((int) (this.title.getIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
    }
    for (int i = 0; i < this.items.size(); i++) {
        RtfBasicElement rtfElement = (RtfBasicElement) this.items.get(i);
        if (rtfElement instanceof RtfSection) {
            ((RtfSection) rtfElement).updateIndentation(indentLeft + indentContent, indentRight, 0);
        } else if (rtfElement instanceof RtfParagraph) {
            ((RtfParagraph) rtfElement).setIndentLeft((int) (((RtfParagraph) rtfElement).getIndentLeft() + (indentLeft + indentContent) * RtfElement.TWIPS_FACTOR));
            ((RtfParagraph) rtfElement).setIndentRight((int) (((RtfParagraph) rtfElement).getIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
        }
    }
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 8 with RtfBasicElement

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

the class RtfSection method writeContent.

/**
 * Write this RtfSection and its contents
 */
public void writeContent(final OutputStream result) throws IOException {
    result.write(RtfParagraph.PARAGRAPH);
    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);
    }
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 9 with RtfBasicElement

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

the class RtfPhrase method writeContent.

/**
 * Write the content of this RtfPhrase. First resets to the paragraph defaults
 * then if the RtfPhrase is in a RtfCell a marker for this is written and finally
 * the RtfChunks of this RtfPhrase are written.
 */
public void writeContent(final OutputStream result) throws IOException {
    result.write(PARAGRAPH_DEFAULTS);
    result.write(PLAIN);
    if (inTable) {
        result.write(IN_TABLE);
    }
    if (this.lineLeading > 0) {
        result.write(LINE_SPACING);
        result.write(intToByteArray(this.lineLeading));
    }
    for (int i = 0; i < chunks.size(); i++) {
        RtfBasicElement rbe = (RtfBasicElement) chunks.get(i);
        rbe.writeContent(result);
    }
}
Also used : RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement)

Example 10 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 PdfPCell to import
 * @since 2.1.3
 */
private void importCell(PdfPCell cell) {
    this.content = new ArrayList();
    if (cell == null) {
        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.getParentTable().getBorders());
        return;
    }
    // padding
    this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding();
    this.cellPaddingBottom = cell.getPaddingBottom();
    this.cellPaddingTop = cell.getPaddingTop();
    this.cellPaddingRight = cell.getPaddingRight();
    this.cellPaddingLeft = cell.getPaddingLeft();
    // BORDERS
    this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.getBorder(), cell.getBorderWidth(), cell.getBorderColor());
    // border colors
    this.border = cell.getBorder();
    this.borderColor = cell.getBorderColor();
    this.borderColorBottom = cell.getBorderColorBottom();
    this.borderColorTop = cell.getBorderColorTop();
    this.borderColorLeft = cell.getBorderColorLeft();
    this.borderColorRight = cell.getBorderColorRight();
    // border widths
    this.borderWidth = cell.getBorderWidth();
    this.borderWidthBottom = cell.getBorderWidthBottom();
    this.borderWidthTop = cell.getBorderWidthTop();
    this.borderWidthLeft = cell.getBorderWidthLeft();
    this.borderWidthRight = cell.getBorderWidthRight();
    this.colspan = cell.getColspan();
    // cell.getRowspan();
    this.rowspan = 1;
    // if(cell.getRowspan() > 1) {
    // this.mergeType = MERGE_VERT_PARENT;
    // }
    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());
    }
    // does it have column composite info?
    java.util.List compositeElements = cell.getCompositeElements();
    if (compositeElements != null) {
        Iterator cellIterator = compositeElements.iterator();
        // does it have column info?
        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();
            }
        }
    }
    // does it have image info?
    Image img = cell.getImage();
    if (img != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(img);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // does it have phrase info?
    Phrase phrase = cell.getPhrase();
    if (phrase != null) {
        try {
            RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(phrase);
            for (int i = 0; i < rtfElements.length; i++) {
                rtfElements[i].setInTable(true);
                this.content.add(rtfElements[i]);
            }
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // does it have table info?
    PdfPTable table = cell.getTable();
    if (table != null) {
        this.add(table);
    // try {
    // RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(table);
    // for (int i = 0; i < rtfElements.length; i++) {
    // rtfElements[i].setInTable(true);
    // this.content.add(rtfElements[i]);
    // }
    // } catch (DocumentException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    }
}
Also used : Element(com.lowagie.text.Element) RtfBasicElement(com.lowagie.text.rtf.RtfBasicElement) RtfExtendedElement(com.lowagie.text.rtf.RtfExtendedElement) ArrayList(java.util.ArrayList) Phrase(com.lowagie.text.Phrase) Image(com.lowagie.text.Image) Paragraph(com.lowagie.text.Paragraph) RtfParagraph(com.lowagie.text.rtf.text.RtfParagraph) PdfPTable(com.lowagie.text.pdf.PdfPTable) DocumentException(com.lowagie.text.DocumentException) 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)

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