This class is a friendly wrapper on top of the more scary HSLFSlideShow.
TODO:
- figure out how to match notes to their correct sheet
(will involve understanding DocSlideList and DocNotesList)
- handle Slide creation cleaner
| Method from org.apache.poi.hslf.usermodel.SlideShow Detail: |
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;
}
Add a font in this presentation |
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. |
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);
}
Adds a picture to this presentation and returns the associated index. |
public Slide createSlide() throws IOException {
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();
_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();
record.writeOut(out);
// 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);
// All done and added
return slide;
}
|
public Document getDocumentRecord() {
return _documentRecord;
}
Helper method for usermodel and model: Get the document record |
public ObjectData[] getEmbeddedObjects() {
return _hslfSlideShow.getEmbeddedObjects();
}
Returns the data of all the embedded OLE object in the SlideShow |
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;
}
|
protected FontCollection getFontCollection() {
return _fonts;
}
Helper method for usermodel: Get the font collection |
public Record[] getMostRecentCoreRecords() {
return _mostRecentCoreRecords;
}
Returns an array of the most recent version of all the interesting
records |
public Notes[] getNotes() {
return _notes;
}
Returns an array of all the normal Notes found in the slideshow |
public int getNumberOfFonts() {
return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts();
}
get the number of fonts in the presentation |
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);
}
Return the current page size |
public PictureData[] getPictureData() {
return _hslfSlideShow.getPictures();
}
Returns the data of all the pictures attached to the SlideShow |
public Slide[] getSlides() {
return _slides;
}
Returns an array of all the normal Slides found in the slideshow |
public SlideMaster[] getSlidesMasters() {
return _masters;
}
Returns an array of all the normal Slide Masters found in the slideshow |
public SoundData[] getSoundData() {
return SoundData.find(_documentRecord);
}
Returns the data of all the embedded sounds in the SlideShow |
public TitleMaster[] getTitleMasters() {
return _titleMasters;
}
Returns an array of all the normal Title Masters found in the slideshow |
public void reorderSlide(int oldSlideNumer,
int newSlideNumber) {
// Ensure these numbers are valid
if(oldSlideNumer < 1 || newSlideNumber < 1) {
throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
}
if(oldSlideNumer > _slides.length || newSlideNumber > _slides.length) {
throw new IllegalArgumentException("Old and new slide numbers must not exceed the number of slides (" + _slides.length + ")");
}
// Shift the SlideAtomsSet
SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
slwt.repositionSlideAtomsSet(
slwt.getSlideAtomsSets()[(oldSlideNumer-1)],
(newSlideNumber-1)
);
// Re-order the slides
ArrayUtil.arrayMoveWithin(_slides, (oldSlideNumer-1), (newSlideNumber-1), 1);
// Tell the appropriate slides their new numbers
for(int i=0; i< _slides.length; i++) {
_slides[i].setSlideNumber( (i+1) );
}
}
Re-orders a slide, to a new position. |
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);
}
Change the current page size |
public void write(OutputStream out) throws IOException {
_hslfSlideShow.write(out);
}
Writes out the slideshow file the is represented by an instance of
this class |