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

📄 rtfdestinationdocument.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: RtfDestinationDocument.java 3456 2008-05-26 15:26:57Z howard_s $ * * Copyright 2007 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-2006 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000-2006 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.parser.destinations;import java.awt.Color;import java.util.Arrays;import java.util.HashMap;import java.util.List;import com.lowagie.text.Chunk;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.Font;import com.lowagie.text.FontFactory;import com.lowagie.text.Paragraph;import com.lowagie.text.rtf.direct.RtfDirectContent;import com.lowagie.text.rtf.document.*;import com.lowagie.text.rtf.parser.RtfParser;import com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData;import com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordType;import com.lowagie.text.rtf.parser.properties.RtfProperty;import com.lowagie.text.rtf.parser.properties.RtfPropertyListener;/** * <code>RtfDestinationDocument</code> handles data destined for the document destination *  * @author Howard Shank (hgshank@yahoo.com) * @since 2.1.0 */public final class RtfDestinationDocument extends RtfDestination implements RtfPropertyListener {	/**	 * The RtfDocument object.	 * 	 * @see com.lowagie.text.rtf.document.RtfDocument	 */	private RtfDocument rtfDoc = null;		/**	 * The iText Document object.	 * 	 * @see com.lowagie.text.Document	 */	private Document doc = null;		private StringBuffer buffer = null;	/**	 * Indicates the parser action. Import or Conversion.	 * 	 * @see com.lowagie.text.rtf.parser.RtfParser#TYPE_UNIDENTIFIED	 * @see com.lowagie.text.rtf.parser.RtfParser#TYPE_CONVERT	 * @see com.lowagie.text.rtf.parser.RtfParser#TYPE_IMPORT_FRAGMENT	 * @see com.lowagie.text.rtf.parser.RtfParser#TYPE_IMPORT_FULL	 */	private int conversionType = 0;			/**	 * Indicates the current table level being processed	 */	private int tableLevel = 0;		private static final List IMPORT_IGNORED_CTRLWORDS = Arrays.asList(new String[]{		"rtf",		"ansicpg",		"deff",		"ansi",		"mac",		"pca",		"pc",		"stshfdbch",		"stshfloch",		"stshfhich",		"stshfbi",		"deflang",		"deflangfe",		"adeflang",		"adeflangfe"});	private static final List CONVERT_IGNORED_CTRLWORDS = Arrays.asList(new String[]{"rtf"});	private Paragraph iTextParagraph = null;		public RtfDestinationDocument() {		super(null);	}	/**	 * Constructs a new <code>RtfDestinationDocument</code> using	 * the parameters to initialize the object.	 * @param parser an RtfParser.	 */	public RtfDestinationDocument(RtfParser parser) {		super(parser);		this.rtfDoc = parser.getRtfDocument();		this.doc = parser.getDocument();		this.conversionType = parser.getConversionType();		setToDefaults();		if(this.rtfParser.isConvert()) {			this.rtfParser.getState().properties.addRtfPropertyListener(this);		}	}			/* (non-Javadoc)	 * @see java.lang.Object#finalize()	 */	protected void finalize() throws Throwable {		// TODO Auto-generated method stub		if(this.rtfParser.isConvert()) {			this.rtfParser.getState().properties.removeRtfPropertyListener(this);		}		super.finalize();	}	public void setParser(RtfParser parser) {		this.rtfParser = parser;		this.rtfDoc = parser.getRtfDocument();		this.doc = parser.getDocument();		this.conversionType = parser.getConversionType();		setToDefaults();		if(this.rtfParser.isConvert()) {			this.rtfParser.getState().properties.addRtfPropertyListener(this);		}	}		/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()	 */	public boolean closeDestination() {		if(this.rtfParser.isImport()) {			if(this.buffer.length()>0) {				writeBuffer();			}		}				this.rtfParser.getState().properties.removeRtfPropertyListener(this);		return true;	}	/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()	 */	public boolean handleOpenGroup() {		this.onOpenGroup();	// event handler				if(this.rtfParser.isImport()) {		}		if(this.rtfParser.isConvert()) {			if(this.iTextParagraph == null) this.iTextParagraph = new Paragraph();		}		return true;	}	/* (non-Javadoc)	 * @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()	 */	public boolean handleOpeningSubGroup() {		if(this.rtfParser.isImport()) {			if(this.buffer.length()>0) {				writeBuffer();			}		}		return true;	}	/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()	 */	public boolean handleCloseGroup() {		this.onCloseGroup();	// event handler				if(this.rtfParser.isImport()) {			if(this.buffer.length()>0) {				writeBuffer();			}			writeText("}");		}		if(this.rtfParser.isConvert()) {			if(this.buffer.length() > 0 && this.iTextParagraph == null) {				this.iTextParagraph = new Paragraph();			}			if(this.buffer.length() > 0 ) {				Chunk chunk = new Chunk();				chunk.append(this.buffer.toString());				this.iTextParagraph.add(chunk);			}			if(this.iTextParagraph != null) {				addParagraphToDocument();			}		}		return true;	}	/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)	 */	public boolean handleCharacter(int ch) {		boolean result = true;		this.onCharacter(ch);	// event handler				if(this.rtfParser.isImport()) {			if(buffer.length() > 254) {				this.writeBuffer();			}			buffer.append((char)ch);		}		if(this.rtfParser.isConvert()) {			buffer.append((char)ch);		}		return result;	}		public boolean handleControlWord(RtfCtrlWordData ctrlWordData) {		boolean result = false;		this.onCtrlWord(ctrlWordData);	// event handler				if(this.rtfParser.isImport()) {			// map font information			if(ctrlWordData.ctrlWord.equals("f")) { ctrlWordData.param =  this.rtfParser.getImportManager().mapFontNr(ctrlWordData.param);}						// map color information			//colors			if(ctrlWordData.ctrlWord.equals("cb")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			if(ctrlWordData.ctrlWord.equals("cf")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			//cells			if(ctrlWordData.ctrlWord.equals("clcbpat")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			if(ctrlWordData.ctrlWord.equals("clcbpatraw")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			if(ctrlWordData.ctrlWord.equals("clcfpat")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			if(ctrlWordData.ctrlWord.equals("clcfpatraw")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			//table rows			if(ctrlWordData.ctrlWord.equals("trcfpat")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			if(ctrlWordData.ctrlWord.equals("trcbpat")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			//paragraph border			if(ctrlWordData.ctrlWord.equals("brdrcf")) { ctrlWordData.param = this.rtfParser.getImportManager().mapColorNr(ctrlWordData.param);}			// map lists			if(ctrlWordData.ctrlWord.equals("ls")) { ctrlWordData.param = this.rtfParser.getImportManager().mapListNr(ctrlWordData.param);}		}						if(this.rtfParser.isConvert()) {			if(ctrlWordData.ctrlWord.equals("par")) { addParagraphToDocument(); }			// Set Font			if(ctrlWordData.ctrlWord.equals("f")) {}						// color information			//colors			if(ctrlWordData.ctrlWord.equals("cb")) {}			if(ctrlWordData.ctrlWord.equals("cf")) {}			//cells			if(ctrlWordData.ctrlWord.equals("clcbpat")) {}			if(ctrlWordData.ctrlWord.equals("clcbpatraw")) {}			if(ctrlWordData.ctrlWord.equals("clcfpat")) {}			if(ctrlWordData.ctrlWord.equals("clcfpatraw")) {}			//table rows			if(ctrlWordData.ctrlWord.equals("trcfpat")) {}			if(ctrlWordData.ctrlWord.equals("trcbpat")) {}			//paragraph border			if(ctrlWordData.ctrlWord.equals("brdrcf")) {}						/* TABLES */			if(ctrlWordData.ctrlWord.equals("trowd")) /*Beginning of row*/ { tableLevel++;}

⌨️ 快捷键说明

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