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

📄 rtflist.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: RtfList.java 3580 2008-08-06 15:52:00Z howard_s $ * * Copyright 2008 Howard Shank (hgshank@yahoo.com) * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the * provisions of LGPL are applicable instead of those above.  If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.rtf.list;import java.awt.Color;import java.io.IOException;import java.io.OutputStream;import java.security.InvalidParameterException;import java.util.ArrayList;import com.lowagie.text.Chunk;import com.lowagie.text.DocWriter;import com.lowagie.text.DocumentException;import com.lowagie.text.Element;import com.lowagie.text.Font;import com.lowagie.text.List;import com.lowagie.text.ListItem;import com.lowagie.text.Paragraph;import com.lowagie.text.RomanList;import com.lowagie.text.factories.RomanAlphabetFactory;import com.lowagie.text.factories.RomanNumberFactory;import com.lowagie.text.rtf.RtfBasicElement;import com.lowagie.text.rtf.RtfElement;import com.lowagie.text.rtf.RtfExtendedElement;import com.lowagie.text.rtf.document.RtfDocument;import com.lowagie.text.rtf.style.RtfFont;import com.lowagie.text.rtf.style.RtfFontList;import com.lowagie.text.rtf.text.RtfParagraph;/** * The RtfList stores one List. It also provides the methods to write the * list declaration and the list data. *   * @version $Id: RtfList.java 3580 2008-08-06 15:52:00Z howard_s $ * @author Mark Hall (Mark.Hall@mail.room3b.eu) * @author Howard Shank (hgshank@yahoo.com) * @since 2.1.3 */public class RtfList extends RtfElement implements RtfExtendedElement {    /**     * Constant for the list number     * @since 2.1.3     */    public static final byte[] LIST_NUMBER = DocWriter.getISOBytes("\\ls");    /**     * Constant for the list     */    private static final byte[] LIST = DocWriter.getISOBytes("\\list");    /**     * Constant for the list id     * @since 2.1.3     */    public static final byte[] LIST_ID = DocWriter.getISOBytes("\\listid");    /**     * Constant for the list template id     */    private static final byte[] LIST_TEMPLATE_ID = DocWriter.getISOBytes("\\listtemplateid");    /**     * Constant for the simple list     */    private static final byte[] LIST_SIMPLE = DocWriter.getISOBytes("\\listsimple");    /**     * Constant for the hybrid list     */    private static final byte[] LIST_HYBRID = DocWriter.getISOBytes("\\listhybrid");    /**     * Constant to indicate if the list restarts at each section. Word 7 compatiblity     */    private static final byte[] LIST_RESTARTHDN = DocWriter.getISOBytes("\\listrestarthdn");    /**     * Constant for the name of this list     */    private static final byte[] LIST_NAME = DocWriter.getISOBytes("\\listname");    /**     * Constant for the identifier of the style of this list. Mutually exclusive with \\liststylename     */    private static final byte[] LIST_STYLEID = DocWriter.getISOBytes("\\liststyleid");    /**     * Constant for the identifier of the style of this list. Mutually exclusive with \\liststyleid     */    private static final byte[] LIST_STYLENAME = DocWriter.getISOBytes("\\liststylename");    // character properties    /**     * Constant for the list level value     * @since 2.1.3     */    public static final byte[] LIST_LEVEL_NUMBER = DocWriter.getISOBytes("\\ilvl");        	/**     * Constant for the old list text     * @since 2.1.3     */    public static final byte[] LIST_TEXT = DocWriter.getISOBytes("\\listtext");    /**     * Constant for the old list number end     * @since 2.1.3     */    public static final byte[] LIST_NUMBER_END = DocWriter.getISOBytes(".");            /**     * Constant for a tab character     * @since 2.1.3     */    public static final byte[] TAB = DocWriter.getISOBytes("\\tab");        /**     * The subitems of this RtfList     */    private ArrayList items;        /**     * The parent list if there is one.     */    private RtfList parentList = null;    /**     * The list id     */    private int listID = -1;        /**     * List type of NORMAL - no control word     * @since 2.1.3     */    public static final int LIST_TYPE_NORMAL = 0;				/*  Normal list type */        /**     * List type of listsimple     * @since 2.1.3     */    public static final int LIST_TYPE_SIMPLE = 1;				/*  Simple list type */        /**     * List type of listhybrid     * @since 2.1.3     */    public static final int LIST_TYPE_HYBRID = 2;				/*  Hybrid list type */        /**     * This RtfList type     */    private int listType = LIST_TYPE_HYBRID;        /**     * The name of the list if it exists      */    private String name = null;        /**     * The list number of this RtfList     */    private int listNumber = -1;    /**     * The RtfList lists managed by this RtfListTable     */    private ArrayList listLevels = null;;        /**     * Constructs an empty RtfList object.     * @since 2.1.3     */    public RtfList() {    	super(null);        createDefaultLevels();    }        /**     * Set the document.     * @param doc The RtfDocument     * @since 2.1.3     */    public void setDocument(RtfDocument doc) {    	this.document = doc;        // get the list number or create a new one adding it to the table        this.listNumber = document.getDocumentHeader().getListNumber(this);     	    }    /**     * Constructs an empty RtfList object.     * @param doc The RtfDocument this RtfList belongs to     * @since 2.1.3     */    public RtfList(RtfDocument doc) {        super(doc);        createDefaultLevels();        // get the list number or create a new one adding it to the table        this.listNumber = document.getDocumentHeader().getListNumber(this);     }        /**     * Constructs a new RtfList for the specified List.     *      * @param doc The RtfDocument this RtfList belongs to     * @param list The List this RtfList is based on     * @since 2.1.3     */    public RtfList(RtfDocument doc, List list) {        // setup the listlevels        // Then, setup the list data below                // setup 1 listlevel if it's a simple list        // setup 9 if it's a regular list        // setup 9 if it's a hybrid list (default)        super(doc);        createDefaultLevels();                this.items = new ArrayList();		// list content        RtfListLevel ll = (RtfListLevel)this.listLevels.get(0);                // get the list number or create a new one adding it to the table        this.listNumber = document.getDocumentHeader().getListNumber(this);                 if(list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {            ll.setFirstIndent((int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1));            ll.setLeftIndent((int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR));        } else if(list.getSymbolIndent() > 0) {        	ll.setFirstIndent((int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1));        	ll.setLeftIndent((int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR));        } else if(list.getIndentationLeft() > 0) {        	ll.setFirstIndent(0);        	ll.setLeftIndent((int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR));        } else {        	ll.setFirstIndent(0);        	ll.setLeftIndent(0);        }        ll.setRightIndent((int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR));        ll.setSymbolIndent((int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR));        ll.correctIndentation();        ll.setTentative(false);                if (list instanceof RomanList) {			if (list.isLowercase()) {				ll.setListType(RtfListLevel.LIST_TYPE_LOWER_ROMAN);			} else {				ll.setListType(RtfListLevel.LIST_TYPE_UPPER_ROMAN);			}		} else if (list.isNumbered()) {			ll.setListType(RtfListLevel.LIST_TYPE_NUMBERED);		} else if (list.isLettered()) {			if (list.isLowercase()) {				ll.setListType(RtfListLevel.LIST_TYPE_LOWER_LETTERS);			} else {				ll.setListType(RtfListLevel.LIST_TYPE_UPPER_LETTERS);			}		} 		else {//			Paragraph p = new Paragraph();//			p.add(new Chunk(list.getPreSymbol()) );//			p.add(list.getSymbol());//			p.add(new Chunk(list.getPostSymbol()) );//			ll.setBulletChunk(list.getSymbol());			ll.setBulletCharacter(list.getPreSymbol() + list.getSymbol().getContent() + list.getPostSymbol());			ll.setListType(RtfListLevel.LIST_TYPE_BULLET);		}                // now setup the actual list contents.        for(int i = 0; i < list.getItems().size(); i++) {            try {                Element element = (Element) list.getItems().get(i);                                if(element.type() == Element.CHUNK) {                    element = new ListItem((Chunk) element);                }                if(element instanceof ListItem) {                    ll.setAlignment(((ListItem) element).getAlignment());                }                RtfBasicElement[] rtfElements = doc.getMapper().mapElement(element);                for(int j = 0; j < rtfElements.length; j++) {                    RtfBasicElement rtfElement = rtfElements[j];                    if(rtfElement instanceof RtfList) {                        ((RtfList) rtfElement).setParentList(this);                    } else if(rtfElement instanceof RtfListItem) {                        ((RtfListItem) rtfElement).setParent(ll);                    }                    ll.setFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))) );                    if (list.getSymbol() != null && list.getSymbol().getFont() != null && !list.getSymbol().getContent().startsWith("-") && list.getSymbol().getContent().length() > 0) {                        // only set this to bullet symbol is not default                        ll.setBulletFont( list.getSymbol().getFont());                        ll.setBulletCharacter(list.getSymbol().getContent().substring(0, 1));                    } else                	 if (list.getSymbol() != null && list.getSymbol().getFont() != null) {                     	ll.setBulletFont(list.getSymbol().getFont());                	                 	 } else {                    	ll.setBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));                    }                     items.add(rtfElement);                }            } catch(DocumentException de) {                de.printStackTrace();

⌨️ 快捷键说明

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