rtfdestinationshppict.java

来自「有关对pdf操作的代码」· Java 代码 · 共 519 行 · 第 1/2 页

JAVA
519
字号
/* * $Id: RtfDestinationShppict.java 3271 2008-04-18 20:39:42Z xlv $ * $Name$ * * 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.io.ByteArrayOutputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.net.MalformedURLException;import com.lowagie.text.BadElementException;import com.lowagie.text.DocumentException;import com.lowagie.text.Image;import com.lowagie.text.pdf.ByteBuffer;import com.lowagie.text.rtf.direct.RtfDirectContent;import com.lowagie.text.rtf.document.RtfDocument;import com.lowagie.text.rtf.graphic.RtfImage;import com.lowagie.text.rtf.parser.RtfParser;import com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData;/** * <code>RtfDestinationShppict</code> handles data destined for picture destinations *  * @author Howard Shank (hgshank@yahoo.com) * @since 2.0.8 */public class RtfDestinationShppict extends RtfDestination {//	private StringBuffer data = null;	private ByteBuffer data = null;	private StringBuffer hexChars = new StringBuffer(0);	private StringBuffer buffer = new StringBuffer();	/* picttype */	private int pictureType = Image.ORIGINAL_NONE;//	public static final int ORIGINAL_NONE = 0;//	public static final int ORIGINAL_GIF = 3;//	public static final int ORIGINAL_TIFF = 5;//  public static final int ORIGINAL_PS = 7;	// emfblip - EMF (nhanced metafile) - NOT HANDLED	// pngblip int ORIGINAL_PNG = 2;	// jpegblip Image.ORIGINAL_JPEG = 1; ORIGINAL_JPEG2000 = 8;	// shppict - Destination	// nonshpict - Destination - SKIP THIS	// macpict - Mac QuickDraw- NOT HANDLED	// pmmetafileN - OS/2 Metafile - NOT HANDLED		// N * Meaning		// 0x0004 PU_ARBITRARY		// 0x0008 PU_PELS		// 0x000C PU_LOMETRIC		// 0x0010 PU_HIMETRIC		// 0x0014 PU_LOENGLISH		// 0x0018 PU_HIENGLISH		// 0x001C PU_TWIPS	private int pmmetafile = 0;	// wmetafileN Image.RIGINAL_WMF = 6;	// N * Type	// 1 = MM_TEXT	// 2 = M_LOMETRIC	// 3 = MM_HIMETRIC	// 4 = MM_LOENGLISH	// 5 = MM_HIENGLISH	// 6 = MM_TWIPS	// 7 = MM_ISOTROPIC	// 8 = MM_ANISOTROPIC	// dibitmapN - DIB - Convert to BMP?	// wbitmapN Image.ORIGINAL_BMP = 4;		/* bitapinfo */	// wbmbitspixelN - number of bits per pixel - 1 monochrome, 4 16 color, 8 256 color, 24 RGB - Default 1	private Integer bitsPerPixel = new Integer(1);	// wbmplanesN - number of color planes - must be 1	private Integer planes = new Integer(1);	// wbmwidthbytesN - number of bytes in each raster line	private Integer widthBytes = null;				/* pictsize */	// picwN Ext field if the picture is a Windows metafile; picture width in pixels if the picture is a bitmap or	// from quickdraw	private Long width = null;	// pichN	private Long height = null;	// picwgoalN	private Long desiredWidth = null;	// picgoalN	private Long desiredHeight = null;	// picscalexN	private Integer scaleX = new Integer(100);	// picscaleyN	private Integer scaleY = new Integer(100);	// picscaled - macpict setting	private Boolean scaled = null;	// picprop	private Boolean inlinePicture = Boolean.FALSE;	// defshp	private Boolean wordArt = Boolean.FALSE;	// piccroptN	private Integer cropTop = new Integer(0);	// piccropbN	private Integer cropBottom = new Integer(0);	// piccroplN	private Integer cropLeft = new Integer(0);	// piccroprN	private Integer cropRight = new Integer(0);		/* metafileinfo */	// picbmp	private boolean bitmap = false;	//picbppN - Valid 1,4,8,24	private int bbp = 1;		/* data */	// binN	// 0 = HEX, 1 = BINARY	public static final int FORMAT_HEXADECIMAL = 0;	public static final int FORMAT_BINARY = 1;	private int dataFormat = FORMAT_HEXADECIMAL;	private long binaryLength = 0;	// blipupiN	private Integer unitsPerInch = null;	// bliptagN	private String tag = "";	private static final int NORMAL = 0;	private static final int BLIPUID = 1;		private int state = NORMAL;    /**     * Constant for converting pixels to twips     */    private static final int PIXEL_TWIPS_FACTOR = 15;    	ByteArrayOutputStream dataOS = null;    	public RtfDestinationShppict() {		super(null);	}	/**	 * Constructs a new RtfDestinationShppict.	 */	public RtfDestinationShppict(RtfParser parser) {		super(parser);	}		/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()	 */	public boolean closeDestination() {		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();			}//			if(this.data.size() > 0) {			if(dataOS != null) {				addImage();				dataOS = null;			}			this.writeText("}");			return true;		}		if(this.rtfParser.isConvert()) {		}		return true;	}		private boolean addImage() {		Image img = null;		try {//			img = Image.getInstance(data.getBuffer());			img = Image.getInstance(dataOS.toByteArray());				//data=null;			} catch (BadElementException e) {				e.printStackTrace();			} catch (MalformedURLException e) {				e.printStackTrace();			} catch (IOException e) {				// log there was in unsupported image found. Continue to import/convert the document.				e.printStackTrace();			}						if(img != null) {								// DEBUG: Write test file to see what is in Image object.				FileOutputStream out =null;				try {					out = new FileOutputStream("c:\\testOrig.png");//					out.write(data.getBuffer());					out.write(dataOS.toByteArray());					out.close();					out = new FileOutputStream("c:\\testNew.png");					out.write(img.getOriginalData());					out.close();				} catch (FileNotFoundException e1) {

⌨️ 快捷键说明

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