/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.hssf.usermodel; import java.awt.Dimension; import java.io.ByteArrayInputStream; import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherClientDataRecord; import org.apache.poi.ddf.EscherComplexProperty; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherOptRecord; import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherTextboxRecord; import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.record.CommonObjectDataSubRecord; import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.usermodel.Picture; import org.apache.poi.ss.util.ImageUtils; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** * Represents a escher picture. Eg. A GIF, JPEG etc... */ public class HSSFPicture extends HSSFSimpleShape implements Picture { @SuppressWarnings("unused") private static POILogger logger = POILogFactory.getLogger(HSSFPicture.class); public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT public static final int PICTURE_TYPE_JPEG = HSSFWorkbook.PICTURE_TYPE_JPEG; // JFIF public static final int PICTURE_TYPE_PNG = HSSFWorkbook.PICTURE_TYPE_PNG; // PNG public static final int PICTURE_TYPE_DIB = HSSFWorkbook.PICTURE_TYPE_DIB; // Windows DIB public HSSFPicture(EscherContainerRecord spContainer, ObjRecord objRecord) { super(spContainer, objRecord); } /** * Constructs a picture object. */ public HSSFPicture( HSSFShape parent, HSSFAnchor anchor ) { super( parent, anchor ); super.setShapeType(OBJECT_TYPE_PICTURE); CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0); cod.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE); } public int getPictureIndex() { EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.BLIP__BLIPTODISPLAY); if (null == property){ return -1; } return property.getPropertyValue(); } public void setPictureIndex( int pictureIndex ) { setPropertyValue(new EscherSimpleProperty( EscherProperties.BLIP__BLIPTODISPLAY, false, true, pictureIndex)); } @Override protected EscherContainerRecord createSpContainer() { EscherContainerRecord spContainer = super.createSpContainer(); EscherOptRecord opt = spContainer.getChildById(EscherOptRecord.RECORD_ID); opt.removeEscherProperty(EscherProperties.LINESTYLE__LINEDASHING); opt.removeEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH); spContainer.removeChildRecord(spContainer.getChildById(EscherTextboxRecord.RECORD_ID)); return spContainer; } /** * Reset the image to the dimension of the embedded image * *
* Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). * If the default font is changed the resized image can be streched vertically or horizontally. *
*/ public void resize(){ resize(Double.MAX_VALUE); } /** * Resize the image proportionally. * * @see #resize(double, double) */ public void resize(double scale) { resize(scale,scale); } /** * Resize the image ** Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). * If the default font is changed the resized image can be streched vertically or horizontally. *
*
* resize(1.0,1.0) keeps the original size,
* resize(0.5,0.5) resize to 50% of the original,
* resize(2.0,2.0) resizes to 200% of the original.
* resize({@link Double#MAX_VALUE},{@link Double#MAX_VALUE}) resizes to the dimension of the embedded image.
*