Lines 25-45
Link Here
|
25 |
|
25 |
|
26 |
import org.apache.poi.hslf.*; |
26 |
import org.apache.poi.hslf.*; |
27 |
import org.apache.poi.hslf.model.*; |
27 |
import org.apache.poi.hslf.model.*; |
28 |
import org.apache.poi.hslf.record.Document; |
28 |
import org.apache.poi.hslf.model.Notes; |
29 |
import org.apache.poi.hslf.record.DocumentAtom; |
29 |
import org.apache.poi.hslf.model.Slide; |
30 |
import org.apache.poi.hslf.record.FontCollection; |
|
|
31 |
import org.apache.poi.hslf.record.ParentAwareRecord; |
32 |
import org.apache.poi.hslf.record.Record; |
33 |
import org.apache.poi.hslf.record.RecordContainer; |
34 |
import org.apache.poi.hslf.record.RecordTypes; |
35 |
import org.apache.poi.hslf.record.SlideAtom; |
36 |
import org.apache.poi.hslf.record.SlideListWithText; |
37 |
import org.apache.poi.hslf.record.SlidePersistAtom; |
38 |
import org.apache.poi.hslf.record.UserEditAtom; |
39 |
import org.apache.poi.hslf.record.SlideListWithText.*; |
30 |
import org.apache.poi.hslf.record.SlideListWithText.*; |
40 |
import org.apache.poi.hslf.record.PersistPtrHolder; |
31 |
import org.apache.poi.hslf.record.*; |
41 |
import org.apache.poi.hslf.record.PositionDependentRecord; |
|
|
42 |
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; |
32 |
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; |
|
|
33 |
import org.apache.poi.util.LittleEndian; |
34 |
import org.apache.poi.ddf.*; |
43 |
|
35 |
|
44 |
/** |
36 |
/** |
45 |
* This class is a friendly wrapper on top of the more scary HSLFSlideShow. |
37 |
* This class is a friendly wrapper on top of the more scary HSLFSlideShow. |
Lines 50-55
Link Here
|
50 |
* - handle Slide creation cleaner |
42 |
* - handle Slide creation cleaner |
51 |
* |
43 |
* |
52 |
* @author Nick Burch |
44 |
* @author Nick Burch |
|
|
45 |
* @author Yegor kozlov |
53 |
*/ |
46 |
*/ |
54 |
|
47 |
|
55 |
public class SlideShow |
48 |
public class SlideShow |
Lines 99-106
Link Here
|
99 |
// Build up the model level Slides and Notes |
92 |
// Build up the model level Slides and Notes |
100 |
buildSlidesAndNotes(); |
93 |
buildSlidesAndNotes(); |
101 |
} |
94 |
} |
102 |
|
95 |
|
103 |
|
96 |
/** |
|
|
97 |
* Constructs a new Powerpoint document. |
98 |
*/ |
99 |
public SlideShow() throws IOException { |
100 |
this(new HSLFSlideShow()); |
101 |
} |
102 |
|
104 |
/** |
103 |
/** |
105 |
* Find the records that are parent-aware, and tell them |
104 |
* Find the records that are parent-aware, and tell them |
106 |
* who their parent is |
105 |
* who their parent is |
Lines 515-521
Link Here
|
515 |
/** |
514 |
/** |
516 |
* Returns all the pictures attached to the SlideShow |
515 |
* Returns all the pictures attached to the SlideShow |
517 |
*/ |
516 |
*/ |
518 |
public Picture[] getPictures() throws IOException { |
517 |
public PictureData[] getPictures() { |
519 |
return _hslfSlideShow.getPictures(); |
518 |
return _hslfSlideShow.getPictures(); |
520 |
} |
519 |
} |
521 |
|
520 |
|
Lines 535-538
Link Here
|
535 |
* Helper method for usermodel: Get the document record |
534 |
* Helper method for usermodel: Get the document record |
536 |
*/ |
535 |
*/ |
537 |
protected Document getDocumentRecord() { return _documentRecord; } |
536 |
protected Document getDocumentRecord() { return _documentRecord; } |
|
|
537 |
|
538 |
/** |
539 |
* Adds a picture to this presentation and returns the associated index. |
540 |
* |
541 |
* @param data picture data |
542 |
* @param format the format of the picture. One of constans defined in the <code>Picture</code> class. |
543 |
* @return the index to this picture (1 based). |
544 |
*/ |
545 |
public int addPicture(byte[] data, int format) { |
546 |
byte[] uid = PictureData.getChecksum(data); |
547 |
|
548 |
EscherContainerRecord bstore; |
549 |
int offset = 0; |
550 |
|
551 |
EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer(); |
552 |
bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); |
553 |
if (bstore == null){ |
554 |
bstore = new EscherContainerRecord(); |
555 |
bstore.setRecordId( EscherContainerRecord.BSTORE_CONTAINER); |
556 |
|
557 |
List child = dggContainer.getChildRecords(); |
558 |
for ( int i = 0; i < child.size(); i++ ) { |
559 |
EscherRecord rec = (EscherRecord)child.get(i); |
560 |
if (rec.getRecordId() == EscherOptRecord.RECORD_ID){ |
561 |
child.add(i, bstore); |
562 |
i++; |
563 |
} |
564 |
} |
565 |
dggContainer.setChildRecords(child); |
566 |
} else { |
567 |
List lst = bstore.getChildRecords(); |
568 |
for ( int i = 0; i < lst.size(); i++ ) { |
569 |
EscherBSERecord bse = (EscherBSERecord) lst.get(i); |
570 |
if (Arrays.equals(bse.getUid(), uid)){ |
571 |
return i + 1; |
572 |
} |
573 |
offset += bse.getSize(); |
574 |
} |
575 |
} |
576 |
|
577 |
EscherBSERecord bse = new EscherBSERecord(); |
578 |
bse.setRecordId(EscherBSERecord.RECORD_ID); |
579 |
bse.setOptions( (short) ( 0x0002 | ( format << 4 ) ) ); |
580 |
bse.setSize(data.length + PictureData.HEADER_SIZE); |
581 |
bse.setUid(uid); |
582 |
bse.setBlipTypeMacOS((byte)format); |
583 |
bse.setBlipTypeWin32((byte)format); |
584 |
|
585 |
bse.setRef(1); |
586 |
bse.setOffset(offset); |
587 |
|
588 |
bstore.addChildRecord(bse); |
589 |
int count = bstore.getChildRecords().size(); |
590 |
bstore.setOptions((short)( (count << 4) | 0xF )); |
591 |
|
592 |
PictureData pict = new PictureData(); |
593 |
pict.setUID(uid); |
594 |
pict.setData(data); |
595 |
pict.setType(format); |
596 |
|
597 |
_hslfSlideShow.addPicture(pict); |
598 |
|
599 |
return count; |
600 |
} |
601 |
|
602 |
/** |
603 |
* Adds a picture to this presentation and returns the associated index. |
604 |
* |
605 |
* @param pict the file containing the image to add |
606 |
* @param format the format of the picture. One of constans defined in the <code>Picture</code> class. |
607 |
* @return the index to this picture (1 based). |
608 |
*/ |
609 |
public int addPicture(File pict, int format) { |
610 |
int length = (int)pict.length(); |
611 |
byte[] data = new byte[length]; |
612 |
try { |
613 |
FileInputStream is = new FileInputStream(pict); |
614 |
is.read(data); |
615 |
is.close(); |
616 |
} catch (IOException e){ |
617 |
throw new RuntimeException(e); |
618 |
} |
619 |
return addPicture(data, format); |
620 |
} |
538 |
} |
621 |
} |