slideshow.java
来自「EXCEL read and write」· Java 代码 · 共 980 行 · 第 1/3 页
JAVA
980 行
TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide)r, sheetNo); master.setSlideShow(this); tmr.add(master); } else if(r instanceof org.apache.poi.hslf.record.MainMaster) { SlideMaster master = new SlideMaster((org.apache.poi.hslf.record.MainMaster)r, sheetNo); master.setSlideShow(this); mmr.add(master); } } _masters = new SlideMaster[mmr.size()]; mmr.toArray(_masters); _titleMasters = new TitleMaster[tmr.size()]; tmr.toArray(_titleMasters); } // Having sorted out the masters, that leaves the notes and slides // Start by finding the notes records to go with the entries in // notesSLWT org.apache.poi.hslf.record.Notes[] notesRecords; SlideAtomsSet[] notesSets = new SlideAtomsSet[0]; Hashtable slideIdToNotes = new Hashtable(); if(notesSLWT == null) { // None notesRecords = new org.apache.poi.hslf.record.Notes[0]; } else { // Match up the records and the SlideAtomSets notesSets = notesSLWT.getSlideAtomsSets(); ArrayList notesRecordsL = new ArrayList(); for(int i=0; i<notesSets.length; i++) { // Get the right core record Record r = getCoreRecordForSAS(notesSets[i]); // Ensure it really is a notes record if(r instanceof org.apache.poi.hslf.record.Notes) { org.apache.poi.hslf.record.Notes notesRecord = (org.apache.poi.hslf.record.Notes)r; notesRecordsL.add( notesRecord ); // Record the match between slide id and these notes SlidePersistAtom spa = notesSets[i].getSlidePersistAtom(); Integer slideId = new Integer(spa.getSlideIdentifier()); slideIdToNotes.put(slideId, new Integer(i)); } else { logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i + " said its record was at refID " + notesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r); } } notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()]; notesRecords = (org.apache.poi.hslf.record.Notes[]) notesRecordsL.toArray(notesRecords); } // Now, do the same thing for our slides org.apache.poi.hslf.record.Slide[] slidesRecords; SlideAtomsSet[] slidesSets = new SlideAtomsSet[0]; if(slidesSLWT == null) { // None slidesRecords = new org.apache.poi.hslf.record.Slide[0]; } else { // Match up the records and the SlideAtomSets slidesSets = slidesSLWT.getSlideAtomsSets(); slidesRecords = new org.apache.poi.hslf.record.Slide[slidesSets.length]; for(int i=0; i<slidesSets.length; i++) { // Get the right core record Record r = getCoreRecordForSAS(slidesSets[i]); // Ensure it really is a slide record if(r instanceof org.apache.poi.hslf.record.Slide) { slidesRecords[i] = (org.apache.poi.hslf.record.Slide)r; } else { logger.log(POILogger.ERROR, "A Slide SlideAtomSet at " + i + " said its record was at refID " + slidesSets[i].getSlidePersistAtom().getRefID() + ", but that was actually a " + r); } } } // Finally, generate model objects for everything // Notes first _notes = new Notes[notesRecords.length]; for(int i=0; i<_notes.length; i++) { _notes[i] = new Notes(notesRecords[i]); _notes[i].setSlideShow(this); } // Then slides _slides = new Slide[slidesRecords.length]; for(int i=0; i<_slides.length; i++) { SlideAtomsSet sas = slidesSets[i]; int slideIdentifier = sas.getSlidePersistAtom().getSlideIdentifier(); // Do we have a notes for this? Notes notes = null; //Slide.SlideAtom.notesId references the corresponding notes slide. 0 if slide has no notes. int noteId = slidesRecords[i].getSlideAtom().getNotesID(); if (noteId != 0){ Integer notesPos = (Integer)slideIdToNotes.get(new Integer(noteId)); if (notesPos != null) notes = _notes[notesPos.intValue()]; else logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId); } // Now, build our slide _slides[i] = new Slide(slidesRecords[i], notes, sas, slideIdentifier, (i+1)); _slides[i].setSlideShow(this); } } /** * Writes out the slideshow file the is represented by an instance of * this class * @param out The OutputStream to write to. * @throws IOException If there is an unexpected IOException from the passed * in OutputStream */ public void write(OutputStream out) throws IOException { _hslfSlideShow.write(out); } /* =============================================================== * Accessor Code * =============================================================== */ /** * Returns an array of the most recent version of all the interesting * records */ public Record[] getMostRecentCoreRecords() { return _mostRecentCoreRecords; } /** * Returns an array of all the normal Slides found in the slideshow */ public Slide[] getSlides() { return _slides; } /** * Returns an array of all the normal Notes found in the slideshow */ public Notes[] getNotes() { return _notes; } /** * Returns an array of all the normal Slide Masters found in the slideshow */ public SlideMaster[] getSlidesMasters() { return _masters; } /** * Returns an array of all the normal Title Masters found in the slideshow */ public TitleMaster[] getTitleMasters() { return _titleMasters; } /** * Returns the data of all the pictures attached to the SlideShow */ public PictureData[] getPictureData() { return _hslfSlideShow.getPictures(); } /** * Returns the data of all the embedded OLE object in the SlideShow */ public ObjectData[] getEmbeddedObjects() { return _hslfSlideShow.getEmbeddedObjects(); } /** * Returns the data of all the embedded sounds in the SlideShow */ public SoundData[] getSoundData() { return SoundData.find(_documentRecord); } /** * Return the current page size */ public Dimension getPageSize(){ DocumentAtom docatom = _documentRecord.getDocumentAtom(); int pgx = (int)docatom.getSlideSizeX()*Shape.POINT_DPI/Shape.MASTER_DPI; int pgy = (int)docatom.getSlideSizeY()*Shape.POINT_DPI/Shape.MASTER_DPI; return new Dimension(pgx, pgy); } /** * Change the current page size * * @param pgsize page size (in points) */ public void setPageSize(Dimension pgsize){ DocumentAtom docatom = _documentRecord.getDocumentAtom(); docatom.setSlideSizeX(pgsize.width*Shape.MASTER_DPI/Shape.POINT_DPI); docatom.setSlideSizeY(pgsize.height*Shape.MASTER_DPI/Shape.POINT_DPI); } /** * Helper method for usermodel: Get the font collection */ protected FontCollection getFontCollection() { return _fonts; } /** * Helper method for usermodel and model: Get the document record */ public Document getDocumentRecord() { return _documentRecord; } /* =============================================================== * Re-ordering Code * =============================================================== */ /** * Re-orders a slide, to a new position. * @param oldSlideNumber The old slide number (1 based) * @param newSlideNumber The new slide number (1 based) */ public void reorderSlide(int oldSlideNumber, int newSlideNumber) { // Ensure these numbers are valid if(oldSlideNumber < 1 || newSlideNumber < 1) { throw new IllegalArgumentException("Old and new slide numbers must be greater than 0"); } if(oldSlideNumber > _slides.length || newSlideNumber > _slides.length) { throw new IllegalArgumentException("Old and new slide numbers must not exceed the number of slides (" + _slides.length + ")"); } // The order of slides is defined by the order of slide atom sets in the SlideListWithText container. SlideListWithText slwt = _documentRecord.getSlideSlideListWithText(); SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); SlideAtomsSet tmp = sas[oldSlideNumber-1]; sas[oldSlideNumber-1] = sas[newSlideNumber-1]; sas[newSlideNumber-1] = tmp; ArrayList lst = new ArrayList(); for (int i = 0; i < sas.length; i++) { lst.add(sas[i].getSlidePersistAtom()); Record[] r = sas[i].getSlideRecords(); for (int j = 0; j < r.length; j++) { lst.add(r[j]); } _slides[i].setSlideNumber(i+1); } Record[] r = (Record[])lst.toArray(new Record[lst.size()]); slwt.setChildRecord(r); } /* =============================================================== * Addition Code * =============================================================== */ /** * Create a blank <code>Slide</code>. * * @return the created <code>Slide</code> */ public Slide createSlide() { SlideListWithText slist = null; // We need to add the records to the SLWT that deals // with Slides. // Add it, if it doesn't exist slist = _documentRecord.getSlideSlideListWithText(); if(slist == null) { // Need to add a new one slist = new SlideListWithText(); slist.setInstance(SlideListWithText.SLIDES); _documentRecord.addSlideListWithText(slist); } // Grab the SlidePersistAtom with the highest Slide Number. // (Will stay as null if no SlidePersistAtom exists yet in // the slide, or only master slide's ones do) SlidePersistAtom prev = null; SlideAtomsSet[] sas = slist.getSlideAtomsSets(); for(int j=0; j<sas.length; j++) { SlidePersistAtom spa = sas[j].getSlidePersistAtom(); if(spa.getSlideIdentifier() < 0) { // This is for a master slide // Odd, since we only deal with the Slide SLWT } else { // Must be for a real slide if(prev == null) { prev = spa; } if(prev.getSlideIdentifier() < spa.getSlideIdentifier()) { prev = spa; } } } // Set up a new SlidePersistAtom for this slide SlidePersistAtom sp = new SlidePersistAtom(); // First slideId is always 256 sp.setSlideIdentifier(prev == null ? 256 : (prev.getSlideIdentifier() + 1)); // Add this new SlidePersistAtom to the SlideListWithText slist.addSlidePersistAtom(sp); // Create a new Slide Slide slide = new Slide(sp.getSlideIdentifier(), sp.getRefID(), _slides.length+1); slide.setSlideShow(this); slide.onCreate(); // Add in to the list of Slides Slide[] s = new Slide[_slides.length+1]; System.arraycopy(_slides, 0, s, 0, _slides.length); s[_slides.length] = slide; _slides = s; logger.log(POILogger.INFO, "Added slide " + _slides.length + " with ref " + sp.getRefID() + " and identifier " + sp.getSlideIdentifier()); // Add the core records for this new Slide to the record tree org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord(); int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(slideRecord); _records = _hslfSlideShow.getRecords(); // Add the new Slide into the PersistPtr stuff int offset = 0; int slideOffset = 0; PersistPtrHolder ptr = null; UserEditAtom usr = null; for (int i = 0; i < _records.length; i++) { Record record = _records[i]; ByteArrayOutputStream out = new ByteArrayOutputStream(); try { record.writeOut(out); } catch (IOException e){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?