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

📄 rtflistlevel.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Id: RtfListLevel.java 3580 2008-08-06 15:52:00Z howard_s $
 *
 * Copyright 2008 by 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 com.lowagie.text.Chunk;
import com.lowagie.text.DocWriter;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
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.RtfColor;
import com.lowagie.text.rtf.style.RtfFont;
import com.lowagie.text.rtf.style.RtfFontList;
import com.lowagie.text.rtf.style.RtfParagraphStyle;
import com.lowagie.text.rtf.text.RtfParagraph;

/**
 * The RtfListLevel is a listlevel object in a list.
 * 
 * @version $Id: RtfListLevel.java 3580 2008-08-06 15:52:00Z howard_s $
 * @author Howard Shank (hgshank@yahoo.com)
 * @since 2.1.3
 */
public class RtfListLevel extends RtfElement implements RtfExtendedElement {
    /**
     * Constant for list level
     */
    private static final byte[] LIST_LEVEL = DocWriter.getISOBytes("\\listlevel");
    /**
     * Constant for list level
     */
    private static final byte[] LIST_LEVEL_TEMPLATE_ID = DocWriter.getISOBytes("\\leveltemplateid");
    /**
     * Constant for list level style old
     */
    private static final byte[] LIST_LEVEL_TYPE = DocWriter.getISOBytes("\\levelnfc");
    /**
     * Constant for list level style new
     */
    private static final byte[] LIST_LEVEL_TYPE_NEW = DocWriter.getISOBytes("\\levelnfcn");
    /**
     * Constant for list level alignment old
     */
    private static final byte[] LIST_LEVEL_ALIGNMENT = DocWriter.getISOBytes("\\leveljc");
    /**
     * Constant for list level alignment new
     */
    private static final byte[] LIST_LEVEL_ALIGNMENT_NEW = DocWriter.getISOBytes("\\leveljcn");
    /**
     * Constant for list level start at
     */
    private static final byte[] LIST_LEVEL_START_AT = DocWriter.getISOBytes("\\levelstartat");
    /**
     * Constant for list level text
     */
    private static final byte[] LIST_LEVEL_TEXT = DocWriter.getISOBytes("\\leveltext");
    /**
     * Constant for the beginning of the list level numbered style
     */
    private static final byte[] LIST_LEVEL_STYLE_NUMBERED_BEGIN = DocWriter.getISOBytes("\\\'02\\\'");
    /**
     * Constant for the end of the list level numbered style
     */
    private static final byte[] LIST_LEVEL_STYLE_NUMBERED_END = DocWriter.getISOBytes(".;");
    /**
     * Constant for the beginning of the list level bulleted style
     */
    private static final byte[] LIST_LEVEL_STYLE_BULLETED_BEGIN = DocWriter.getISOBytes("\\\'01");
    /**
     * Constant for the end of the list level bulleted style
     */
    private static final byte[] LIST_LEVEL_STYLE_BULLETED_END = DocWriter.getISOBytes(";");
    /**
     * Constant for the beginning of the list level numbers
     */
    private static final byte[] LIST_LEVEL_NUMBERS_BEGIN = DocWriter.getISOBytes("\\levelnumbers");
    /**
     * Constant which specifies which character follows the level text
     */
    private static final byte[] LIST_LEVEL_FOLOW = DocWriter.getISOBytes("\\levelfollow");
    /**
     * Constant which specifies the levelspace controlword
     */
    private static final byte[] LIST_LEVEL_SPACE = DocWriter.getISOBytes("\\levelspace");
    /**
     * Constant which specifies the levelindent control word
     */
    private static final byte[] LIST_LEVEL_INDENT = DocWriter.getISOBytes("\\levelindent");
    /**
     * Constant which specifies (1) if list numbers from previous levels should be converted
     * to Arabic numbers; (0) if they should be left with the format specified by their
     * own level's definition.
     */
    private static final byte[] LIST_LEVEL_LEGAL = DocWriter.getISOBytes("\\levellegal");
    /**
     * Constant which specifies 
     * (1) if this level does/does not restart its count each time a super ordinate level is incremented
     * (0) if this level does not restart its count each time a super ordinate level is incremented.
     */
    private static final byte[] LIST_LEVEL_NO_RESTART = DocWriter.getISOBytes("\\levelnorestart");
    /**
     * Constant for the list level numbers
     */
    private static final byte[] LIST_LEVEL_NUMBERS_NUMBERED = DocWriter.getISOBytes("\\\'01");
    /**
     * Constant for the end of the list level numbers
     */
    private static final byte[] LIST_LEVEL_NUMBERS_END = DocWriter.getISOBytes(";");
    
    /**
     * Constant for the first indentation
     */
    private static final byte[] LIST_LEVEL_FIRST_INDENT = DocWriter.getISOBytes("\\fi");
    /**
     * Constant for the symbol indentation
     */
    private static final byte[] LIST_LEVEL_SYMBOL_INDENT = DocWriter.getISOBytes("\\tx");
    
    /**
     * Constant for the lvltentative control word
     */
    private static final byte[] LIST_LEVEL_TENTATIVE = DocWriter.getISOBytes("\\lvltentative");
    /**
     * Constant for the levelpictureN control word
     */
    private static final byte[] LIST_LEVEL_PICTURE = DocWriter.getISOBytes("\\levelpicture");
    

    public static final int LIST_TYPE_NUMBERED = 1;
    public static final int LIST_TYPE_UPPER_LETTERS = 2;
    public static final int LIST_TYPE_LOWER_LETTERS = 3;
    public static final int LIST_TYPE_UPPER_ROMAN = 4;
    public static final int LIST_TYPE_LOWER_ROMAN = 5;

    public static final int LIST_TYPE_UNKNOWN = -1; 					/* unknown type */
    public static final int LIST_TYPE_BASE = 1000; 						/* BASE value to subtract to get RTF Value if above base*/
    public static final int LIST_TYPE_ARABIC = 1000; 					/* 0 Arabic (1, 2, 3) */
    public static final int LIST_TYPE_UPPERCASE_ROMAN_NUMERAL = 1001;	/* 1 Uppercase Roman numeral (I, II, III) */
    public static final int LIST_TYPE_LOWERCASE_ROMAN_NUMERAL = 1002;	/* 2 Lowercase Roman numeral (i, ii, iii)*/
    public static final int LIST_TYPE_UPPERCASE_LETTER = 1003;			/* 3 Uppercase letter (A, B, C)*/
    public static final int LIST_TYPE_LOWERCASE_LETTER = 1004;			/* 4 Lowercase letter (a, b, c)*/
    public static final int LIST_TYPE_ORDINAL_NUMBER = 1005;			/* 5 Ordinal number (1st, 2nd, 3rd)*/
    public static final int LIST_TYPE_CARDINAL_TEXT_NUMBER = 1006;		/* 6 Cardinal text number (One, Two Three)*/
    public static final int LIST_TYPE_ORDINAL_TEXT_NUMBER = 1007;		/* 7 Ordinal text number (First, Second, Third)*/
    public static final int LIST_TYPE_ARABIC_LEADING_ZERO = 1022;		/* 22	Arabic with leading zero (01, 02, 03, ..., 10, 11)*/
    public static final int LIST_TYPE_BULLET = 1023;					/* 23	Bullet (no number at all)*/
    public static final int LIST_TYPE_NO_NUMBER = 1255;				/*  255	No number */
/*
 
10	Kanji numbering without the digit character (*dbnum1)
11	Kanji numbering with the digit character (*dbnum2)
12	46 phonetic katakana characters in "aiueo" order (*aiueo)
13	46 phonetic katakana characters in "iroha" order (*iroha)
14	Double-byte character
15	Single-byte character
16	Kanji numbering 3 (*dbnum3)
17	Kanji numbering 4 (*dbnum4)
18	Circle numbering (*circlenum)
19	Double-byte Arabic numbering	
20	46 phonetic double-byte katakana characters (*aiueo*dbchar)
    21	46 phonetic double-byte katakana characters (*iroha*dbchar)
    22	Arabic with leading zero (01, 02, 03, ..., 10, 11)
    24	Korean numbering 2 (*ganada)
    25	Korean numbering 1 (*chosung)
    26	Chinese numbering 1 (*gb1)
    27	Chinese numbering 2 (*gb2)
    28	Chinese numbering 3 (*gb3)
    29	Chinese numbering 4 (*gb4)
    30	Chinese Zodiac numbering 1 (* zodiac1)
    31	Chinese Zodiac numbering 2 (* zodiac2) 
    32	Chinese Zodiac numbering 3 (* zodiac3)
    33	Taiwanese double-byte numbering 1
    34	Taiwanese double-byte numbering 2
    35	Taiwanese double-byte numbering 3
    36	Taiwanese double-byte numbering 4
    37	Chinese double-byte numbering 1
    38	Chinese double-byte numbering 2
    39	Chinese double-byte numbering 3
    40	Chinese double-byte numbering 4
    41	Korean double-byte numbering 1
    42	Korean double-byte numbering 2
    43	Korean double-byte numbering 3
    44	Korean double-byte numbering 4
    45	Hebrew non-standard decimal 
    46	Arabic Alif Ba Tah
    47	Hebrew Biblical standard
    48	Arabic Abjad style
    255	No number
*/
    /**
     * Whether this RtfList is numbered
     */
    private int listType = LIST_TYPE_UNKNOWN;

    /**
     * The text to use as the bullet character
     */
    private String bulletCharacter = "\u00b7"; 
    /**
     * @since 2.1.4
     */
    private Chunk bulletChunk = null;
    /**
     * The number to start counting at
     */
    private int listStartAt = 1;
    /**
     * The level of this RtfListLevel
     */
    private int listLevel = 0;
    /**
     * The first indentation of this RtfList
     */
    private int firstIndent = 0;
    /**
     * The left indentation of this RtfList
     */
    private int leftIndent = 0;
    /**
     * The right indentation of this RtfList
     */
    private int rightIndent = 0;
    /**
     * The symbol indentation of this RtfList
     */
    private int symbolIndent = 0;
    /**
     * Flag to indicate if the tentative control word should be emitted.
     */
    private boolean isTentative = true;
    /**
     * Flag to indicate if the levellegal control word should be emitted.
     * true  if any list numbers from previous levels should be converted to Arabic numbers; 
     * false if they should be left with the format specified by their own level definition.
     */
    private boolean isLegal = false;
    
    /**
     * Does the list restart numbering each time a super ordinate level is incremented
     */
    private int listNoRestart = 0;
    public static final int LIST_LEVEL_FOLLOW_TAB = 0; 
    public static final int LIST_LEVEL_FOLLOW_SPACE = 1; 
    public static final int LIST_LEVEL_FOLLOW_NOTHING = 2; 
    private int levelFollowValue = LIST_LEVEL_FOLLOW_TAB;

    /**
     * The alignment of this RtfList
     */
    private int alignment = Element.ALIGN_LEFT;
    /**
     * Which picture bullet from the \listpicture destination should be applied
     */
    private int levelPicture = -1;
    
    private int levelTextNumber = 0;
    /**
     * The RtfFont for numbered lists
     */
    private RtfFont fontNumber;
    /**
     * The RtfFont for bulleted lists
     */
    private RtfFont fontBullet;
    
    private int templateID = -1;
    
    private RtfListLevel listLevelParent = null;
    
    /** 
     * Parent list object
     */
    private RtfList parent = null;
    
	public RtfListLevel(RtfDocument doc)
	{
		super(doc);
		templateID = document.getRandomInt();
        setFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))));
        setBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
	}
	
	public RtfListLevel(RtfDocument doc, RtfList parent)
	{
		super(doc);
		this.parent = parent;
		templateID = document.getRandomInt();
		setFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))));
        setBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
	}
	
	public RtfListLevel(RtfListLevel ll)
	{
		super(ll.document);
		templateID = document.getRandomInt();
		this.alignment = ll.alignment;
		this.bulletCharacter = ll.bulletCharacter;
		this.firstIndent = ll.firstIndent;
		this.fontBullet = ll.fontBullet;
		this.fontNumber = ll.fontNumber;
		this.inHeader = ll.inHeader;
		this.inTable = ll.inTable;
		this.leftIndent = ll.leftIndent;
		this.listLevel = ll.listLevel;
		this.listNoRestart = ll.listNoRestart;
		this.listStartAt = ll.listStartAt;
		this.listType = ll.listType;
		this.parent = ll.parent;
		this.rightIndent = ll.rightIndent;
		this.symbolIndent = ll.symbolIndent;
	}

	/**
	 * @return the listNoRestart
	 */
	public int getListNoRestart() {
		return listNoRestart;
	}

	/**
	 * @param listNoRestart the listNoRestart to set
	 */
	public void setListNoRestart(int listNoRestart) {
		this.listNoRestart = listNoRestart;
	}

	/**
	 * @return the alignment
	 */
	public int getAlignment() {
		return alignment;
	}

	/**
	 * @param alignment the alignment to set
	 */
	public void setAlignment(int alignment) {
		this.alignment = alignment;
	}

	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;
            /* New types */
            case LIST_TYPE_ARABIC   	 : result.write(intToByteArray(0)); break;
            case LIST_TYPE_UPPERCASE_ROMAN_NUMERAL   	 : result.write(intToByteArray(1)); break;
            case LIST_TYPE_LOWERCASE_ROMAN_NUMERAL   	 : result.write(intToByteArray(2)); break;
            case LIST_TYPE_UPPERCASE_LETTER   	 : result.write(intToByteArray(3)); break;
            case LIST_TYPE_ORDINAL_NUMBER   	 : result.write(intToByteArray(4)); break;
            case LIST_TYPE_CARDINAL_TEXT_NUMBER   	 : result.write(intToByteArray(5)); break;
            case LIST_TYPE_ORDINAL_TEXT_NUMBER   	 : result.write(intToByteArray(6)); break;
            case LIST_TYPE_LOWERCASE_LETTER   	 : result.write(intToByteArray(7)); break;
            case LIST_TYPE_ARABIC_LEADING_ZERO   	 : result.write(intToByteArray(22)); break;
            case LIST_TYPE_NO_NUMBER   	 : result.write(intToByteArray(255)); break;

⌨️ 快捷键说明

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