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

📄 rtflist.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return result.toByteArray();
    }
    /**
     * Writes the definition part of this list level
     */
    public void writeDefinition(final OutputStream result) throws IOException
    {
        result.write(OPEN_GROUP);
        result.write(LIST_LEVEL);
        result.write(LIST_LEVEL_TYPE);
        switch(this.listType) {
            case LIST_TYPE_BULLET        : result.write(intToByteArray(23)); break;
            case LIST_TYPE_NUMBERED      : result.write(intToByteArray(0)); break;
            case LIST_TYPE_UPPER_LETTERS : result.write(intToByteArray(3)); break;
            case LIST_TYPE_LOWER_LETTERS : result.write(intToByteArray(4)); break;
            case LIST_TYPE_UPPER_ROMAN   : result.write(intToByteArray(1)); break;
            case LIST_TYPE_LOWER_ROMAN   : result.write(intToByteArray(2)); break;
        }
        result.write(LIST_LEVEL_TYPE_NEW);
        switch(this.listType) {
            case LIST_TYPE_BULLET        : result.write(intToByteArray(23)); break;
            case LIST_TYPE_NUMBERED      : result.write(intToByteArray(0)); break;
            case LIST_TYPE_UPPER_LETTERS : result.write(intToByteArray(3)); break;
            case LIST_TYPE_LOWER_LETTERS : result.write(intToByteArray(4)); break;
            case LIST_TYPE_UPPER_ROMAN   : result.write(intToByteArray(1)); break;
            case LIST_TYPE_LOWER_ROMAN   : result.write(intToByteArray(2)); break;
        }
        result.write(LIST_LEVEL_ALIGNMENT);
        result.write(intToByteArray(0));
        result.write(LIST_LEVEL_ALIGNMENT_NEW);
        result.write(intToByteArray(0));
        result.write(LIST_LEVEL_START_AT);
        result.write(intToByteArray(1));
        result.write(OPEN_GROUP);
        result.write(LIST_LEVEL_TEXT);
        if(this.listType != LIST_TYPE_BULLET) {
            result.write(LIST_LEVEL_STYLE_NUMBERED_BEGIN);
            if(listLevel < 10) {
                result.write(intToByteArray(0));
            }
            result.write(intToByteArray(listLevel));
            result.write(LIST_LEVEL_STYLE_NUMBERED_END);
        } else {
            result.write(LIST_LEVEL_STYLE_BULLETED_BEGIN);
            this.document.filterSpecialChar(result, this.bulletCharacter, false, false);
            result.write(LIST_LEVEL_STYLE_BULLETED_END);
        }
        result.write(CLOSE_GROUP);
        result.write(OPEN_GROUP);
        result.write(LIST_LEVEL_NUMBERS_BEGIN);
        if(this.listType != LIST_TYPE_BULLET) {
            result.write(LIST_LEVEL_NUMBERS_NUMBERED);
        }
        result.write(LIST_LEVEL_NUMBERS_END);
        result.write(CLOSE_GROUP);
        result.write(RtfFontList.FONT_NUMBER);
        if(this.listType != LIST_TYPE_BULLET) {
            result.write(intToByteArray(fontNumber.getFontNumber()));
        } else {
            result.write(intToByteArray(fontBullet.getFontNumber()));
        }
        //.result.write(writeIndentations());
        writeIndentations(result);
        result.write(LIST_LEVEL_SYMBOL_INDENT);
        result.write(intToByteArray(this.leftIndent));
        result.write(CLOSE_GROUP);
        result.write("\n".getBytes());
        for(int i = 0; i < items.size(); i++) {
            RtfElement rtfElement = (RtfElement) items.get(i);
            if(rtfElement instanceof RtfList) {
            	RtfList rl = (RtfList)rtfElement;
                //.result.write(((RtfList) rtfElement).writeDefinition());
            	rl.writeDefinition(result);
                break;
            } else if(rtfElement instanceof RtfListItem) {
            	RtfListItem rli = (RtfListItem) rtfElement;
                //.byte[] data = rli.writeDefinition();
                //.if(data.length > 0) {
                //.    result.write(data);
                //.    break;
                //.}
            	if(rli.writeDefinition(result)) break;
            }
        }    	
    }

    
    /**
     * Writes the initialisation part of the RtfList
     * 
     * @return A byte array containing the initialisation part
     */
    protected byte[] writeListBeginning() {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
            result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
            if(this.inTable) {
                result.write(RtfParagraph.IN_TABLE);
            }
            switch (this.alignment) {
                case Element.ALIGN_LEFT:
                    result.write(RtfParagraphStyle.ALIGN_LEFT);
                    break;
                case Element.ALIGN_RIGHT:
                    result.write(RtfParagraphStyle.ALIGN_RIGHT);
                    break;
                case Element.ALIGN_CENTER:
                    result.write(RtfParagraphStyle.ALIGN_CENTER);
                    break;
                case Element.ALIGN_JUSTIFIED:
                case Element.ALIGN_JUSTIFIED_ALL:
                    result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
                    break;
            }
            //.result.write(writeIndentations());
            writeIndentations(result);
            result.write(RtfFont.FONT_SIZE);
            result.write(intToByteArray(fontNumber.getFontSize() * 2));
            if(this.symbolIndent > 0) {
                result.write("\\tx".getBytes());
                result.write(intToByteArray(this.leftIndent));
            }
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return result.toByteArray();
    }

    /**
     * Writes only the list number and list level number.
     * 
     * @return The list number and list level number of this RtfList.
     */
    protected byte[] writeListNumbers() {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
            result.write(RtfListTable.LIST_NUMBER);
            result.write(intToByteArray(listNumber));
            if(listLevel > 0) {
                result.write(LIST_LEVEL_NUMBER);
                result.write(intToByteArray(listLevel));
            }
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return result.toByteArray();
    }
    
    /**
     * Writes the content of the RtfList
     * 
     * @return A byte array containing the actual content of the RtfList
     * @deprecated replaced by {@link #writeContent(OutputStream)}
     */
    public byte[] write()  
    {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        try {
        	writeContent(result);
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
        return result.toByteArray();
    }
    
    
    /**
     * Writes the content of the RtfList
     */    
    public void writeContent(final OutputStream result) throws IOException
    {
        result.write(OPEN_GROUP);
        int itemNr = 0;
        for(int i = 0; i < items.size(); i++) {
            RtfElement rtfElement = (RtfElement) items.get(i);
            if(rtfElement instanceof RtfListItem) {
                itemNr++;
                result.write(writeListBeginning());
                result.write(writeListNumbers());
                result.write(OPEN_GROUP);
                result.write(LIST_TEXT);
                result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
                if(this.inTable) {
                    result.write(RtfParagraph.IN_TABLE);
                }
                result.write(RtfFontList.FONT_NUMBER);
                if(this.listType != LIST_TYPE_BULLET) {
                    result.write(intToByteArray(fontNumber.getFontNumber()));
                } else {
                    result.write(intToByteArray(fontBullet.getFontNumber()));
                }
                //.result.write(writeIndentations());
                writeIndentations(result);
                result.write(DELIMITER);
                if(this.listType != LIST_TYPE_BULLET) {
                    switch(this.listType) {
                        case LIST_TYPE_NUMBERED      : result.write(intToByteArray(itemNr)); break;
                        case LIST_TYPE_UPPER_LETTERS : result.write(RomanAlphabetFactory.getUpperCaseString(itemNr).getBytes()); break;
                        case LIST_TYPE_LOWER_LETTERS : result.write(RomanAlphabetFactory.getLowerCaseString(itemNr).getBytes()); break;
                        case LIST_TYPE_UPPER_ROMAN   : result.write(RomanNumberFactory.getUpperCaseString(itemNr).getBytes()); break;
                        case LIST_TYPE_LOWER_ROMAN   : result.write(RomanNumberFactory.getLowerCaseString(itemNr).getBytes()); break;
                    }
                    result.write(LIST_NUMBER_END);
                } else {
                    this.document.filterSpecialChar(result, this.bulletCharacter, true, false);
                }
                result.write(TAB);
                result.write(CLOSE_GROUP);                
                //.result.write(rtfElement.write());
                rtfElement.writeContent(result);
                if(i < (items.size() - 1) || !this.inTable || this.listLevel > 0) {
                    result.write(RtfParagraph.PARAGRAPH);
                }
                result.write("\n".getBytes());
            } else if(rtfElement instanceof RtfList) {
                //.result.write(rtfElement.write());
            	rtfElement.writeContent(result);
                result.write("\n".getBytes());
            }
        }
        result.write(CLOSE_GROUP);
        
        if(!this.inTable) {
            result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
        }
    }        
    
    /**
     * Gets the list level of this RtfList
     * 
     * @return Returns the list level.
     */
    public int getListLevel() {
        return listLevel;
    }
    
    /**
     * Sets the list level of this RtfList. A list level > 0 will
     * unregister this RtfList from the RtfListTable
     * 
     * @param listLevel The list level to set.
     */
    public void setListLevel(int listLevel) {
        this.listLevel = listLevel;
        if(this.listLevel != 0) {
            document.getDocumentHeader().freeListNumber(this);
            for(int i = 0; i < this.items.size(); i++) {
                if(this.items.get(i) instanceof RtfList) {
                    ((RtfList) this.items.get(i)).setListNumber(this.listNumber);
                    ((RtfList) this.items.get(i)).setListLevel(this.listLevel + 1);
                }
            }
        } else {
            this.listNumber = document.getDocumentHeader().getListNumber(this);
        }
    }
    
    /**
     * Sets the parent RtfList of this RtfList
     * 
     * @param parent The parent RtfList to use.
     */
    protected void setParent(RtfList parent) {
        this.parentList = parent;
    }
    
    /**
     * Gets the id of this list
     * 
     * @return Returns the list number.
     */
    public int getListNumber() {
        return listNumber;
    }
    
    /**
     * Sets the id of this list
     * 
     * @param listNumber The list number to set.
     */
    public void setListNumber(int listNumber) {
        this.listNumber = listNumber;
    }
    
    /**
     * Sets whether this RtfList is in a table. Sets the correct inTable setting for all
     * child elements.
     * 
     * @param inTable <code>True</code> if this RtfList is in a table, <code>false</code> otherwise
     */
    public void setInTable(boolean inTable) {
        super.setInTable(inTable);
        for(int i = 0; i < this.items.size(); i++) {
            ((RtfBasicElement) this.items.get(i)).setInTable(inTable);
        }
    }
    
    /**
     * Sets whether this RtfList is in a header. Sets the correct inTable setting for all
     * child elements.
     * 
     * @param inHeader <code>True</code> if this RtfList is in a header, <code>false</code> otherwise
     */
    public void setInHeader(boolean inHeader) {
        super.setInHeader(inHeader);
        for(int i = 0; i < this.items.size(); i++) {
            ((RtfBasicElement) this.items.get(i)).setInHeader(inHeader);
        }
    }

    /**
     * Correct the indentation of this RtfList by adding left/first line indentation
     * from the parent RtfList. Also calls correctIndentation on all child RtfLists.
     */
    protected void correctIndentation() {
        if(this.parentList != null) {
            this.leftIndent = this.leftIndent + this.parentList.getLeftIndent() + this.parentList.getFirstIndent();
        }
        for(int i = 0; i < this.items.size(); i++) {
            if(this.items.get(i) instanceof RtfList) {
                ((RtfList) this.items.get(i)).correctIndentation();
            } else if(this.items.get(i) instanceof RtfListItem) {
                ((RtfListItem) this.items.get(i)).correctIndentation();
            }
        }
    }

    /**
     * Get the left indentation of this RtfList.
     * 
     * @return The left indentation.
     */
    private int getLeftIndent() {
        return this.leftIndent;
    }
    
    /**
     * Get the first line indentation of this RtfList.
     * 
     * @return The first line indentation.
     */
    private int getFirstIndent() {
        return this.firstIndent;
    }
}

⌨️ 快捷键说明

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