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

📄 rtfcell.java

📁 处理PDF
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                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();                // 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;	                    }	                    // if horizontal alignment is undefined overwrite	                    // 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();//			}        }    }    /**	 * 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()));        }        this.document.outputDebugLinebreak(result);                result.write("\\clftsWidth3".getBytes());        this.document.outputDebugLinebreak(result);                result.write("\\clwWidth".getBytes());        result.write(intToByteArray(this.cellWidth));        this.document.outputDebugLinebreak(result);                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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -