/** * Returns index associated with this picture. * Index starts with 1 and points to a EscherBSE record which * holds information about this picture. * * @return the index to this picture (1 based). */ public int getPictureIndex(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY); return prop == null ? 0 : prop.getPropertyValue(); }
/** * Name of this picture. * * @return name of this picture */ public String getPictureName(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherComplexProperty prop = (EscherComplexProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPFILENAME); String name = null; if(prop != null){ try { name = new String(prop.getComplexData(), "UTF-16LE"); int idx = name.indexOf('\u0000'); return idx == -1 ? name : name.substring(0, idx); } catch (UnsupportedEncodingException e){ throw new HSLFException(e); } } return name; }
/** * Name of this picture. * * @param name of this picture */ public void setPictureName(String name){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); try { byte[] data = (name + '\u0000').getBytes("UTF-16LE"); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, false, data); opt.addEscherProperty(prop); } catch (UnsupportedEncodingException e){ throw new HSLFException(e); } }
/** * Create a new Picture and populate the inital structure of the <code>EscherSp</code> record which holds information about this picture. * @param idx the index of the picture which referes to <code>EscherBSE</code> container. * @return the create Picture object */ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) { _escherContainer = super.createSpContainer(isChild); _escherContainer.setOptions((short)15); EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID); spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2)); //set default properties for a picture EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080); //another weird feature of powerpoint: for picture id we must add 0x4000. setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx); return _escherContainer; }