⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtfcell.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    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
     * 
     * @return A byte array with the cell definition
     * @deprecated replaced by {@link #writeDefinition(OutputStream)}
     */
    public byte[] writeDefinition() {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
        	writeDefinition(result);
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        
        return result.toByteArray();
    }
    
    /**
     * 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;
        }
        //.result.write(this.borders.write());
        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
     * 
     * @return A byte array with the content of this RtfCell
     * @deprecated replaced by {@link #writeContent(OutputStream)}
     */
    public byte[] write() 
    {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
        	writeContent(result);
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        
        return result.toByteArray();
    }
    /**
     * 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());
                }
                //.result.write(rtfElement.write());
                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);
        }
    }

    /**
     * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -