slideshow.java
来自「EXCEL read and write」· Java 代码 · 共 980 行 · 第 1/3 页
JAVA
980 行
throw new HSLFException(e); } // Grab interesting records as they come past if(_records[i].getRecordType() == RecordTypes.PersistPtrIncrementalBlock.typeID){ ptr = (PersistPtrHolder)_records[i]; } if(_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) { usr = (UserEditAtom)_records[i]; } if(i == slideRecordPos) { slideOffset = offset; } offset += out.size(); } // persist ID is UserEditAtom.maxPersistWritten + 1 int psrId = usr.getMaxPersistWritten() + 1; sp.setRefID(psrId); slideRecord.setSheetId(psrId); // Last view is now of the slide usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW); usr.setMaxPersistWritten(psrId); //increment the number of persit objects // Add the new slide into the last PersistPtr // (Also need to tell it where it is) slideRecord.setLastOnDiskOffset(slideOffset); ptr.addSlideLookup(sp.getRefID(), slideOffset); logger.log(POILogger.INFO, "New slide ended up at " + slideOffset); slide.setMasterSheet(_masters[0]); // All done and added return slide; } /** * Adds a picture to this presentation and returns the associated index. * * @param data picture data * @param format the format of the picture. One of constans defined in the <code>Picture</code> class. * @return the index to this picture (1 based). */ public int addPicture(byte[] data, int format) throws IOException { byte[] uid = PictureData.getChecksum(data); EscherContainerRecord bstore; int offset = 0; EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer(); bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); if (bstore == null){ bstore = new EscherContainerRecord(); bstore.setRecordId( EscherContainerRecord.BSTORE_CONTAINER); List child = dggContainer.getChildRecords(); for ( int i = 0; i < child.size(); i++ ) { EscherRecord rec = (EscherRecord)child.get(i); if (rec.getRecordId() == EscherOptRecord.RECORD_ID){ child.add(i, bstore); i++; } } dggContainer.setChildRecords(child); } else { List lst = bstore.getChildRecords(); for ( int i = 0; i < lst.size(); i++ ) { EscherBSERecord bse = (EscherBSERecord) lst.get(i); if (Arrays.equals(bse.getUid(), uid)){ return i + 1; } offset += bse.getSize(); } } PictureData pict = PictureData.create(format); pict.setData(data); pict.setOffset(offset); EscherBSERecord bse = new EscherBSERecord(); bse.setRecordId(EscherBSERecord.RECORD_ID); bse.setOptions( (short) ( 0x0002 | ( format << 4 ) ) ); bse.setSize(pict.getRawData().length + 8); bse.setUid(uid); bse.setBlipTypeMacOS((byte)format); bse.setBlipTypeWin32((byte)format); if (format == Picture.EMF) bse.setBlipTypeMacOS((byte)Picture.PICT); else if (format == Picture.WMF) bse.setBlipTypeMacOS((byte)Picture.PICT); else if (format == Picture.PICT) bse.setBlipTypeWin32((byte)Picture.WMF); bse.setRef(0); bse.setOffset(offset); bstore.addChildRecord(bse); int count = bstore.getChildRecords().size(); bstore.setOptions((short)( (count << 4) | 0xF )); _hslfSlideShow.addPicture(pict); return count; } /** * Adds a picture to this presentation and returns the associated index. * * @param pict the file containing the image to add * @param format the format of the picture. One of constans defined in the <code>Picture</code> class. * @return the index to this picture (1 based). */ public int addPicture(File pict, int format) throws IOException { int length = (int)pict.length(); byte[] data = new byte[length]; try { FileInputStream is = new FileInputStream(pict); is.read(data); is.close(); } catch (IOException e){ throw new HSLFException(e); } return addPicture(data, format); } /** * Add a font in this presentation * * @param font the font to add * @return 0-based index of the font */ public int addFont(PPFont font) { FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); int idx = fonts.getFontIndex(font.getFontName()); if(idx == -1){ idx = fonts.addFont(font.getFontName(), font.getCharSet(), font.getFontFlags(), font.getFontType(), font.getPitchAndFamily()); } return idx; } /** * Get a font by index * * @param idx 0-based index of the font * @return of an instance of <code>PPFont</code> or <code>null</code> if not found */ public PPFont getFont(int idx) { PPFont font = null; FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection(); Record[] ch = fonts.getChildRecords(); for (int i = 0; i < ch.length; i++) { if(ch[i] instanceof FontEntityAtom) { FontEntityAtom atom = (FontEntityAtom)ch[i]; if(atom.getFontIndex() == idx){ font = new PPFont(atom); break; } } } return font; } /** * get the number of fonts in the presentation * * @return number of fonts */ public int getNumberOfFonts() { return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts(); } /** * Return Header / Footer settings for slides * * @return Header / Footer settings for slides */ public HeadersFooters getSlideHeadersFooters(){ //detect if this ppt was saved in Office2007 String tag = getSlidesMasters()[0].getProgrammableTag(); boolean ppt2007 = "___PPT12".equals(tag); HeadersFootersContainer hdd = null; Record[] ch = _documentRecord.getChildRecords(); for (int i = 0; i < ch.length; i++) { if(ch[i] instanceof HeadersFootersContainer && ((HeadersFootersContainer)ch[i]).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer){ hdd = (HeadersFootersContainer)ch[i]; break; } } boolean newRecord = false; if(hdd == null) { hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer); newRecord = true; } return new HeadersFooters(hdd, this, newRecord, ppt2007); } /** * Return Header / Footer settings for notes * * @return Header / Footer settings for notes */ public HeadersFooters getNotesHeadersFooters(){ //detect if this ppt was saved in Office2007 String tag = getSlidesMasters()[0].getProgrammableTag(); boolean ppt2007 = "___PPT12".equals(tag); HeadersFootersContainer hdd = null; Record[] ch = _documentRecord.getChildRecords(); for (int i = 0; i < ch.length; i++) { if(ch[i] instanceof HeadersFootersContainer && ((HeadersFootersContainer)ch[i]).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer){ hdd = (HeadersFootersContainer)ch[i]; break; } } boolean newRecord = false; if(hdd == null) { hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer); newRecord = true; } if(ppt2007 && _notes.length > 0){ return new HeadersFooters(hdd, _notes[0], newRecord, ppt2007); } else { return new HeadersFooters(hdd, this, newRecord, ppt2007); } } /** * Add a movie in this presentation * * @param path the path or url to the movie * @return 0-based index of the movie */ public int addMovie(String path, int type) { ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if(lst == null){ lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); } ExObjListAtom objAtom = lst.getExObjListAtom(); //increment the object ID seed int objectId = (int)objAtom.getObjectIDSeed() + 1; objAtom.setObjectIDSeed(objectId); ExMCIMovie mci; switch (type){ case MovieShape.MOVIE_MPEG: mci = new ExMCIMovie(); break; case MovieShape.MOVIE_AVI: mci = new ExAviMovie(); break; default: throw new IllegalArgumentException("Unsupported Movie: " + type); } lst.appendChildRecord(mci); ExVideoContainer exVideo = mci.getExVideo(); exVideo.getExMediaAtom().setObjectId(objectId); exVideo.getExMediaAtom().setMask(0xE80000); exVideo.getPathAtom().setText(path); return objectId; } /** * Add a control in this presentation * * @param name name of the control, e.g. "Shockwave Flash Object" * @param progId OLE Programmatic Identifier, e.g. "ShockwaveFlash.ShockwaveFlash.9" * @return 0-based index of the control */ public int addControl(String name, String progId) { ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); } ExObjListAtom objAtom = lst.getExObjListAtom(); //increment the object ID seed int objectId = (int) objAtom.getObjectIDSeed() + 1; objAtom.setObjectIDSeed(objectId); ExControl ctrl = new ExControl(); ExOleObjAtom oleObj = ctrl.getExOleObjAtom(); oleObj.setObjID(objectId); oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE); oleObj.setType(ExOleObjAtom.TYPE_CONTROL); oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT); ctrl.setProgId(progId); ctrl.setMenuName(name); ctrl.setClipboardName(name); lst.addChildAfter(ctrl, objAtom); return objectId; } /** * Add a hyperlink to this presentation * * @return 0-based index of the hyperlink */ public int addHyperlink(Hyperlink link) { ExObjList lst = (ExObjList)_documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID); if (lst == null) { lst = new ExObjList(); _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom()); } ExObjListAtom objAtom = lst.getExObjListAtom(); //increment the object ID seed int objectId = (int) objAtom.getObjectIDSeed() + 1; objAtom.setObjectIDSeed(objectId); ExHyperlink ctrl = new ExHyperlink(); ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom(); obj.setNumber(objectId); ctrl.setLinkURL(link.getAddress()); ctrl.setLinkTitle(link.getTitle()); lst.addChildAfter(ctrl, objAtom); link.setId(objectId); return objectId; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?