rtfcell.java

来自「有关对pdf操作的代码」· Java 代码 · 共 507 行 · 第 1/2 页

JAVA
507
字号
                    // with that of enclosing cell                    if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) {                        ((Paragraph) element).setAlignment(cell.getHorizontalAlignment());                    }                    RtfBasicElement rtfElement = this.document.getMapper().mapElement(element);                    rtfElement.setInTable(true);                    this.content.add(rtfElement);                }            } catch(DocumentException de) {                de.printStackTrace();            }        }        if(container != null) {            try {                RtfBasicElement rtfElement = this.document.getMapper().mapElement(container);                rtfElement.setInTable(true);                this.content.add(rtfElement);            } catch(DocumentException de) {                de.printStackTrace();            }        }    }        /**     * Write the cell definition part of this RtfCell     */    public void writeDefinition(final OutputStream result) throws IOException     {        if(this.mergeType == MERGE_VERT_PARENT) {            result.write("\\clvmgf".getBytes());        } else if(this.mergeType == MERGE_VERT_CHILD) {            result.write("\\clvmrg".getBytes());        }        switch (verticalAlignment) {            case Element.ALIGN_BOTTOM:                result.write("\\clvertalb".getBytes());                break;            case Element.ALIGN_CENTER:            case Element.ALIGN_MIDDLE:                result.write("\\clvertalc".getBytes());                break;            case Element.ALIGN_TOP:                result.write("\\clvertalt".getBytes());                break;        }        this.borders.writeContent(result);        if(this.backgroundColor != null) {            result.write("\\clcbpat".getBytes());            result.write(intToByteArray(this.backgroundColor.getColorNumber()));        }        result.write('\n');                result.write("\\clftsWidth3".getBytes());        result.write('\n');                result.write("\\clwWidth".getBytes());        result.write(intToByteArray(this.cellWidth));        result.write('\n');                if(this.cellPadding > 0) {            result.write("\\clpadl".getBytes());            result.write(intToByteArray(this.cellPadding / 2));            result.write("\\clpadt".getBytes());            result.write(intToByteArray(this.cellPadding / 2));            result.write("\\clpadr".getBytes());            result.write(intToByteArray(this.cellPadding / 2));            result.write("\\clpadb".getBytes());            result.write(intToByteArray(this.cellPadding / 2));            result.write("\\clpadfl3".getBytes());            result.write("\\clpadft3".getBytes());            result.write("\\clpadfr3".getBytes());            result.write("\\clpadfb3".getBytes());        }        result.write("\\cellx".getBytes());        result.write(intToByteArray(this.cellRight));    }        /**     * 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("\\cell".getBytes());    }            /**     * Sets the right margin of this cell. Used in merge operations     *      * @param cellRight The right margin to use     */    protected void setCellRight(int cellRight) {        this.cellRight = cellRight;    }        /**     * Gets the right margin of this RtfCell     *      * @return The right margin of this RtfCell.     */    protected int getCellRight() {        return this.cellRight;    }        /**     * Sets the cell width of this RtfCell. Used in merge operations.     *      * @param cellWidth The cell width to use     */    protected void setCellWidth(int cellWidth) {        this.cellWidth = cellWidth;    }        /**     * Gets the cell width of this RtfCell     *      * @return The cell width of this RtfCell     */    protected int getCellWidth() {        return this.cellWidth;    }        /**     * Gets the cell padding of this RtfCell     *      * @return The cell padding of this RtfCell     */    protected int getCellpadding() {        return this.cellPadding;    }    /**     * Gets the borders of this RtfCell     *      * @return The borders of this RtfCell     */    protected RtfBorderGroup getBorders() {        return this.borders;    }        /**     * Set the borders of this RtfCell     *      * @param borderGroup The RtfBorderGroup to use as borders     */    public void setBorders(RtfBorderGroup borderGroup) {        this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, borderGroup);    }	/**     * Get the background color of this RtfCell     *      * @return The background color of this RtfCell     */    protected RtfColor getRtfBackgroundColor() {        return this.backgroundColor;    }    /**     * Merge this cell into the parent cell.     *      * @param mergeParent The RtfCell to merge with     */    protected void setCellMergeChild(RtfCell mergeParent) {        this.mergeType = MERGE_VERT_CHILD;        this.cellWidth = mergeParent.getCellWidth();        this.cellRight = mergeParent.getCellRight();        this.cellPadding = mergeParent.getCellpadding();        this.borders = mergeParent.getBorders();        this.verticalAlignment = mergeParent.getVerticalAlignment();        this.backgroundColor = mergeParent.getRtfBackgroundColor();    }    /**     * Sets the RtfDocument this RtfCell belongs to     *      * @param doc The RtfDocument to use     */    public void setRtfDocument(RtfDocument doc) {        this.document = doc;    }        /**     * Unused     * @param inTable     */    public void setInTable(boolean inTable) {    }        /**     * Sets whether this RtfCell is in a header     *      * @param inHeader <code>True</code> if this RtfCell is in a header, <code>false</code> otherwise     */    public void setInHeader(boolean inHeader) {        this.inHeader = inHeader;        for(int i = 0; i < this.content.size(); i++) {            ((RtfBasicElement) this.content.get(i)).setInHeader(inHeader);        }    }        /**     * Gets whether this <code>RtfCell</code> is in a header     *      * @return <code>True</code> if this <code>RtfCell</code> is in a header, <code>false</code> otherwise     * @since 2.1.0     */    public boolean isInHeader() {        return this.inHeader;    }    /**     * Transforms an integer into its String representation and then returns the bytes     * of that string.     *     * @param i The integer to convert     * @return A byte array representing the integer     */    private byte[] intToByteArray(int i) {        return Integer.toString(i).getBytes();    }        /**     * Checks whether this RtfCell is a placeholder for     * a table cell that has been removed due to col/row spanning.     *      * @return <code>True</code> if this RtfCell is deleted, <code>false</code> otherwise.     */    public boolean isDeleted() {        return this.deleted;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?