rtfdestinationshppict.java

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

JAVA
519
字号
					e1.printStackTrace();				} catch (IOException e1) {					e1.printStackTrace();				}				// set the image attributes								img.scaleAbsolute(this.desiredWidth.floatValue()/PIXEL_TWIPS_FACTOR, this.desiredHeight.floatValue()/PIXEL_TWIPS_FACTOR);				img.scaleAbsolute(this.width.floatValue()/PIXEL_TWIPS_FACTOR, this.height.floatValue()/PIXEL_TWIPS_FACTOR);				img.scalePercent(this.scaleX.floatValue(), this.scaleY.floatValue());//				img.setBorder(value);								try {					if(this.rtfParser.isImport()) {						RtfDocument rtfDoc = this.rtfParser.getRtfDocument();						RtfImage rtfImage = new RtfImage(rtfDoc, img);						rtfDoc.add(rtfImage);					}					if(this.rtfParser.isConvert()) {						this.rtfParser.getDocument().add(img);					}				} catch (DocumentException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}			//			data = new ByteBuffer();			dataFormat = FORMAT_HEXADECIMAL;			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()) {		}		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#handleCharacter(int)	 */	public boolean handleCharacter(int ch) {				if(this.rtfParser.isImport()) {			if(buffer.length() > 254)				writeBuffer();		}		if(data == null) data = new ByteBuffer();		switch(dataFormat) {		case FORMAT_HEXADECIMAL:			hexChars.append(ch);			if(hexChars.length() == 2) {				try {					data.append((char)Integer.parseInt(hexChars.toString() , 16));				} catch (NumberFormatException e) {					e.printStackTrace();				}				hexChars = new StringBuffer();			}			break;		case FORMAT_BINARY:			if (dataOS == null) { 				dataOS = new ByteArrayOutputStream();			}			// HGS - FIX ME IF PROBLEM!			dataOS.write((char)(ch));			// PNG signature should be.//			   (decimal)              137  80  78  71  13  10  26  10//			   (hexadecimal)           89  50  4e  47  0d  0a  1a  0a//			   (ASCII C notation)    \211   P   N   G  \r  \n \032 \n//			data.append(b1[0]);			binaryLength--;			if(binaryLength == 0) { dataFormat = FORMAT_HEXADECIMAL; }			break;		}				return true;	}	public boolean handleControlWord(RtfCtrlWordData ctrlWordData) {		boolean result = false;		boolean skipCtrlWord = false;		if(this.rtfParser.isImport()) {			skipCtrlWord = true;			if(ctrlWordData.ctrlWord.equals("shppict")) { result = true;}			if(ctrlWordData.ctrlWord.equals("nonshppict")) {	// never gets here because this is a destination set to null				skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;				}			if(ctrlWordData.ctrlWord.equals("blipuid")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("picprop")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("pict")) { result = true;}			if(ctrlWordData.ctrlWord.equals("emfblip")) { result = true; pictureType = Image.ORIGINAL_NONE;}			if(ctrlWordData.ctrlWord.equals("pngblip")) { result = true; pictureType = Image.ORIGINAL_PNG;}			if(ctrlWordData.ctrlWord.equals("jepgblip")) { result = true; pictureType = Image.ORIGINAL_JPEG;}			if(ctrlWordData.ctrlWord.equals("macpict")) { result = true; pictureType = Image.ORIGINAL_NONE;}			if(ctrlWordData.ctrlWord.equals("pmmetafile")) { result = true; pictureType = Image.ORIGINAL_NONE;}			if(ctrlWordData.ctrlWord.equals("wmetafile")) { result = true; pictureType = Image.ORIGINAL_WMF;}			if(ctrlWordData.ctrlWord.equals("dibitmap")) { result = true; pictureType = Image.ORIGINAL_NONE;}			if(ctrlWordData.ctrlWord.equals("wbitmap")) { result = true; pictureType = Image.ORIGINAL_BMP;}			/* bitmap information */			if(ctrlWordData.ctrlWord.equals("wbmbitspixel")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wbmplanes")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wbmwidthbytes")) { result = true;}			/* picture size, scaling and cropping */			if(ctrlWordData.ctrlWord.equals("picw")) { this.width = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("pich")) { this.height = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("picwgoal")) { this.desiredWidth = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("pichgoal")) { this.desiredHeight = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("picscalex")) { this.scaleX = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("picscaley")) { this.scaleY = ctrlWordData.toInteger();result = true;}			if(ctrlWordData.ctrlWord.equals("picscaled")) { result = true;}			if(ctrlWordData.ctrlWord.equals("picprop")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("defshp")) { result = true;}			if(ctrlWordData.ctrlWord.equals("piccropt")) { this.cropTop = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropb")) { this.cropBottom = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropl")) { this.cropLeft = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropr")) { this.cropRight = ctrlWordData.toInteger(); result = true;}			/* metafile information */			if(ctrlWordData.ctrlWord.equals("picbmp")) { result = true;}			if(ctrlWordData.ctrlWord.equals("picbpp")) { result = true;}			/* picture data */			if(ctrlWordData.ctrlWord.equals("bin")) { 				this.dataFormat = FORMAT_BINARY;				// set length to param				this.binaryLength = ctrlWordData.longValue();				this.rtfParser.setTokeniserStateBinary(binaryLength);				result = true;			}			if(ctrlWordData.ctrlWord.equals("blipupi")) { result = true;}			if(ctrlWordData.ctrlWord.equals("blipuid")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("bliptag")) { result = true;}		}		if(this.rtfParser.isConvert()) {			if(ctrlWordData.ctrlWord.equals("shppict")) { result = true;}			if(ctrlWordData.ctrlWord.equals("nonshppict")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("blipuid")) { result = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("pict")) { result = true;}			if(ctrlWordData.ctrlWord.equals("emfblip")) { result = true;}			if(ctrlWordData.ctrlWord.equals("pngblip")) { result = true;}			if(ctrlWordData.ctrlWord.equals("jepgblip")) { result = true;}			if(ctrlWordData.ctrlWord.equals("macpict")) { result = true;}			if(ctrlWordData.ctrlWord.equals("pmmetafile")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wmetafile")) {  skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("dibitmap")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wbitmap")) { result = true;}			/* bitmap information */			if(ctrlWordData.ctrlWord.equals("wbmbitspixel")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wbmplanes")) { result = true;}			if(ctrlWordData.ctrlWord.equals("wbmwidthbytes")) { result = true;}			/* picture size, scaling and cropping */			if(ctrlWordData.ctrlWord.equals("picw")) { this.width = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("pich")) { this.height = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("picwgoal")) { this.desiredWidth = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("pichgoal")) { this.desiredHeight = ctrlWordData.toLong(); result = true;}			if(ctrlWordData.ctrlWord.equals("picscalex")) { this.scaleX = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("picscaley")) { this.scaleY = ctrlWordData.toInteger();result = true;}			if(ctrlWordData.ctrlWord.equals("picscaled")) { result = true;}			if(ctrlWordData.ctrlWord.equals("picprop")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("defshp")) { result = true;}			if(ctrlWordData.ctrlWord.equals("piccropt")) { this.cropTop = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropb")) { this.cropBottom = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropl")) { this.cropLeft = ctrlWordData.toInteger(); result = true;}			if(ctrlWordData.ctrlWord.equals("piccropr")) { this.cropRight = ctrlWordData.toInteger(); result = true;}			/* metafile information */			if(ctrlWordData.ctrlWord.equals("picbmp")) { result = true;}			if(ctrlWordData.ctrlWord.equals("picbpp")) { result = true;}			/* picture data */			if(ctrlWordData.ctrlWord.equals("bin")) { 				dataFormat = FORMAT_BINARY; result = true;			}			if(ctrlWordData.ctrlWord.equals("blipupi")) { result = true;}			if(ctrlWordData.ctrlWord.equals("blipuid")) { skipCtrlWord = true; this.rtfParser.setTokeniserStateSkipGroup(); result = true;}			if(ctrlWordData.ctrlWord.equals("bliptag")) { result = true;}				}		if(!skipCtrlWord) {			switch(this.rtfParser.getConversionType()) {			case RtfParser.TYPE_IMPORT_FULL:					writeBuffer();					writeText(ctrlWordData.toString());				result = true;				break;					case RtfParser.TYPE_IMPORT_FRAGMENT:					writeBuffer();					writeText(ctrlWordData.toString());				result = true;				break;			case RtfParser.TYPE_CONVERT:				result = true;				break;			default:	// error because is should be an import or convert				result = false;				break;			}		}		return result;	}	/* (non-Javadoc)	 * @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()	 */	public void setToDefaults() {				this.buffer = new StringBuffer();		this.data = null;		this.width = null;		this.height = null;		this.desiredWidth = null;		this.desiredHeight = null;		this.scaleX = new Integer(100);		this.scaleY = new Integer(100);		this.scaled = null;		this.inlinePicture = Boolean.FALSE;		this.wordArt = Boolean.FALSE;		this.cropTop = new Integer(0);		this.cropBottom = new Integer(0);		this.cropLeft = new Integer(0);		this.cropRight = new Integer(0);		this.bitmap = false;		this.bbp = 1;		this.dataFormat = FORMAT_HEXADECIMAL;		this.binaryLength = 0;		this.unitsPerInch = null;		this.tag = "";	}	private void writeBuffer() {		writeText(this.buffer.toString());		//setToDefaults();	}	private void writeText(String value) {		if(this.rtfParser.getState().newGroup) {			this.rtfParser.getRtfDocument().add(new RtfDirectContent("{"));			this.rtfParser.getState().newGroup = false;		}		if(value.length() > 0) {			this.rtfParser.getRtfDocument().add(new RtfDirectContent(value));		}	}}

⌨️ 快捷键说明

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