/** * @return name of the shape. */ @Override public String getShapeName(){ final EscherComplexProperty ep = getEscherProperty(getEscherOptRecord(), EscherProperties.GROUPSHAPE__SHAPENAME); if (ep != null) { final byte[] cd = ep.getComplexData(); return StringUtil.getFromUnicodeLE0Terminated(cd, 0, cd.length/2); } else { return getShapeType().nativeName+" "+getShapeId(); } }
/** * Add a new Shape to this Slide * * @param shape - the Shape to add */ @Override public void addShape(HSLFShape shape) { PPDrawing ppdrawing = getPPDrawing(); EscherContainerRecord dgContainer = ppdrawing.getDgContainer(); EscherContainerRecord spgr = HSLFShape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER); spgr.addChildRecord(shape.getSpContainer()); shape.setSheet(this); shape.setShapeId(allocateShapeId()); shape.afterInsert(this); }
Color getColor(short colorProperty, short opacityProperty, int defaultColor){ AbstractEscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty p = getEscherProperty(opt, colorProperty); if(p == null && defaultColor == -1) return null; int val = (p == null) ? defaultColor : p.getPropertyValue(); EscherColorRef ecr = new EscherColorRef(val); Color col = getColor(ecr); if (col == null) { return null; } double alpha = getAlpha(opacityProperty); return new Color(col.getRed(), col.getGreen(), col.getBlue(), (int)(alpha*255.0)); }
/** * Moves the top left corner of the shape to the specified point. * * @param x the x coordinate of the top left corner of the shape * @param y the y coordinate of the top left corner of the shape */ public final void moveTo(double x, double y) { // This convenience method should be implemented via setAnchor in subclasses // see HSLFGroupShape.setAnchor() for a reference Rectangle2D anchor = getAnchor(); anchor.setRect(x, y, anchor.getWidth(), anchor.getHeight()); setAnchor(anchor); }
/** * Foreground color */ public Color getForegroundColor(){ AbstractEscherOptRecord opt = shape.getEscherOptRecord(); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST); int propVal = (p == null) ? 0 : p.getPropertyValue(); return (FILL_USE_FILLED.isSet(propVal) && !FILL_FILLED.isSet(propVal)) ? null : shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY, -1); }
HSLFSheet sheet = getSheet(); if (fSchemeIndex && sheet != null) { Color col = getSysIndexColor(ecr); col = applySysIndexProcedure(ecr, col); return col;
/** * Find hyperlink assigned to the supplied shape * * @param shape <code>Shape</code> to lookup hyperlink in * @return found hyperlink or <code>null</code> */ @SuppressWarnings("resource") protected static HSLFHyperlink find(HSLFShape shape){ HSLFSlideShow ppt = shape.getSheet().getSlideShow(); //document-level container which stores info about all links in a presentation ExObjList exobj = ppt.getDocumentRecord().getExObjList(false); HSLFEscherClientDataRecord cldata = shape.getClientData(false); if (exobj != null && cldata != null) { List<HSLFHyperlink> lst = new ArrayList<>(); find(cldata.getHSLFChildRecords(), exobj, lst); return lst.isEmpty() ? null : lst.get(0); } return null; }
public static void main(String[] args) throws IOException { try (FileInputStream fis = new FileInputStream(args[0])) { try (HSLFSlideShow ppt = new HSLFSlideShow(fis)) { HSLFSoundData[] sounds = ppt.getSoundData(); for (HSLFSlide slide : ppt.getSlides()) { for (HSLFShape shape : slide.getShapes()) { int soundRef = getSoundReference(shape); if (soundRef == -1) continue; System.out.println("Slide[" + slide.getSlideNumber() + "], shape[" + shape.getShapeId() + "], soundRef: " + soundRef); System.out.println(" " + sounds[soundRef].getSoundName()); System.out.println(" " + sounds[soundRef].getSoundType()); } } } } }
/** * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes */ @Override protected EscherContainerRecord createSpContainer(boolean isChild) { EscherContainerRecord ecr = super.createSpContainer(isChild); ecr.setRecordId(EscherContainerRecord.SPGR_CONTAINER); //The group itself is a shape, and always appears as the first EscherSpContainer in the group container. EscherContainerRecord spcont = new EscherContainerRecord(); spcont.setRecordId(EscherContainerRecord.SP_CONTAINER); spcont.setOptions((short)15); EscherSpgrRecord spg = new EscherSpgrRecord(); spg.setOptions((short)1); spcont.addChildRecord(spg); EscherSpRecord sp = new EscherSpRecord(); short type = (short)((ShapeType.NOT_PRIMITIVE.nativeId << 4) + 2); sp.setOptions(type); sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP); spcont.addChildRecord(sp); EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); spcont.addChildRecord(anchor); ecr.addChildRecord(spcont); return ecr; }
@Override public int getAlpha() { return (int)(shape.getAlpha(EscherProperties.FILL__FILLOPACITY)*100000.0); } };
/** * Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records * * @return an array of HSLF records contained in the shape's EscherClientDataRecord or <code>null</code> */ protected List<? extends Record> getClientRecords() { HSLFEscherClientDataRecord clientData = getClientData(false); return (clientData == null) ? null : clientData.getHSLFChildRecords(); }
/** * Find a record in the underlying EscherClientDataRecord * * @param recordType type of the record to search */ @SuppressWarnings("unchecked") public <T extends Record> T getClientDataRecord(int recordType) { List<? extends Record> records = getClientRecords(); if (records != null) for (Record r : records) { if (r.getRecordType() == recordType){ return (T)r; } } return null; }
/** * Check if a given shape is associated with a sound. * @return 0-based reference to a sound in the sound collection * or -1 if the shape is not associated with a sound */ protected static int getSoundReference(HSLFShape shape){ int soundRef = -1; //dive into the shape container and search for InteractiveInfoAtom InteractiveInfoAtom info = shape.getClientDataRecord(RecordTypes.InteractiveInfo.typeID); if (info != null && info.getAction() == InteractiveInfoAtom.ACTION_MEDIA) { soundRef = info.getSoundRef(); } return soundRef; } }
@Override public ColorStyle[] getGradientColors() { ColorStyle cs[]; if (colorCnt == 0) { cs = new ColorStyle[2]; cs[0] = wrapColor(getBackgroundColor()); cs[1] = wrapColor(getForegroundColor()); } else { cs = new ColorStyle[colorCnt]; int idx = 0; // TODO: handle palette colors and alpha(?) value for (byte data[] : ep) { EscherColorRef ecr = new EscherColorRef(data, 0, 4); cs[idx++] = wrapColor(shape.getColor(ecr)); } } return cs; }
/** * Background color */ public Color getBackgroundColor(){ AbstractEscherOptRecord opt = shape.getEscherOptRecord(); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST); int propVal = (p == null) ? 0 : p.getPropertyValue(); return (FILL_USE_FILLED.isSet(propVal) && !FILL_FILLED.isSet(propVal)) ? null : shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1); }
/** * Moves and scales this <code>ShapeGroup</code> to the specified anchor. */ protected void moveAndScale(Rectangle2D anchorDest){ Rectangle2D anchorSrc = getAnchor(); double scaleX = (anchorSrc.getWidth() == 0) ? 0 : anchorDest.getWidth() / anchorSrc.getWidth(); double scaleY = (anchorSrc.getHeight() == 0) ? 0 : anchorDest.getHeight() / anchorSrc.getHeight(); setExteriorAnchor(anchorDest); for (HSLFShape shape : getShapes()) { Rectangle2D chanchor = shape.getAnchor(); double x = anchorDest.getX()+(chanchor.getX()-anchorSrc.getX())*scaleX; double y = anchorDest.getY()+(chanchor.getY()-anchorSrc.getY())*scaleY; double width = chanchor.getWidth()*scaleX; double height = chanchor.getHeight()*scaleY; shape.setAnchor(new Rectangle2D.Double(x, y, width, height)); } }
EscherContainerRecord ecr = super.createSpContainer(isChild); ecr.setRecordId( EscherContainerRecord.SP_CONTAINER );
/** * Add a shape to this group. * * @param shape - the Shape to add */ @Override public void addShape(HSLFShape shape){ getSpContainer().addChildRecord(shape.getSpContainer()); HSLFSheet sheet = getSheet(); shape.setSheet(sheet); shape.setShapeId(sheet.allocateShapeId()); shape.afterInsert(sheet); }