You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HSLFSlideShow.java 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.usermodel;
  16. import static org.apache.logging.log4j.util.Unbox.box;
  17. import java.awt.Dimension;
  18. import java.io.Closeable;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.io.OutputStream;
  24. import java.util.ArrayList;
  25. import java.util.Arrays;
  26. import java.util.Collections;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. import java.util.function.Supplier;
  31. import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
  32. import org.apache.logging.log4j.LogManager;
  33. import org.apache.logging.log4j.Logger;
  34. import org.apache.poi.POIDocument;
  35. import org.apache.poi.common.usermodel.GenericRecord;
  36. import org.apache.poi.common.usermodel.fonts.FontInfo;
  37. import org.apache.poi.ddf.EscherBSERecord;
  38. import org.apache.poi.ddf.EscherContainerRecord;
  39. import org.apache.poi.ddf.EscherOptRecord;
  40. import org.apache.poi.hpsf.ClassID;
  41. import org.apache.poi.hpsf.ClassIDPredefined;
  42. import org.apache.poi.hpsf.DocumentSummaryInformation;
  43. import org.apache.poi.hpsf.PropertySet;
  44. import org.apache.poi.hpsf.SummaryInformation;
  45. import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
  46. import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
  47. import org.apache.poi.hslf.exceptions.HSLFException;
  48. import org.apache.poi.hslf.model.HeadersFooters;
  49. import org.apache.poi.hslf.model.MovieShape;
  50. import org.apache.poi.hslf.record.*;
  51. import org.apache.poi.hslf.record.Record;
  52. import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
  53. import org.apache.poi.poifs.crypt.EncryptionInfo;
  54. import org.apache.poi.poifs.filesystem.DirectoryNode;
  55. import org.apache.poi.poifs.filesystem.Ole10Native;
  56. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  57. import org.apache.poi.sl.usermodel.MasterSheet;
  58. import org.apache.poi.sl.usermodel.PictureData.PictureType;
  59. import org.apache.poi.sl.usermodel.SlideShow;
  60. import org.apache.poi.util.GenericRecordUtil;
  61. import org.apache.poi.util.IOUtils;
  62. import org.apache.poi.util.Internal;
  63. import org.apache.poi.util.Units;
  64. /**
  65. * This class is a friendly wrapper on top of the more scary HSLFSlideShow.
  66. *
  67. * TODO: - figure out how to match notes to their correct sheet (will involve
  68. * understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
  69. */
  70. public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable, GenericRecord {
  71. /** Powerpoint document entry/stream name */
  72. public static final String POWERPOINT_DOCUMENT = "PowerPoint Document";
  73. public static final String PP97_DOCUMENT = "PP97_DUALSTORAGE";
  74. public static final String PP95_DOCUMENT = "PP40";
  75. // For logging
  76. private static final Logger LOG = LogManager.getLogger(HSLFSlideShow.class);
  77. //arbitrarily selected; may need to increase
  78. private static final int DEFAULT_MAX_RECORD_LENGTH = 10_000_000;
  79. private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
  80. enum LoadSavePhase {
  81. INIT, LOADED
  82. }
  83. private static final ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<>();
  84. // What we're based on
  85. private final HSLFSlideShowImpl _hslfSlideShow;
  86. // Pointers to the most recent versions of the core records
  87. // (Document, Notes, Slide etc)
  88. private Record[] _mostRecentCoreRecords;
  89. // Lookup between the PersitPtr "sheet" IDs, and the position
  90. // in the mostRecentCoreRecords array
  91. private Map<Integer,Integer> _sheetIdToCoreRecordsLookup;
  92. // Records that are interesting
  93. private Document _documentRecord;
  94. // Friendly objects for people to deal with
  95. private final List<HSLFSlideMaster> _masters = new ArrayList<>();
  96. private final List<HSLFTitleMaster> _titleMasters = new ArrayList<>();
  97. private final List<HSLFSlide> _slides = new ArrayList<>();
  98. private final List<HSLFNotes> _notes = new ArrayList<>();
  99. private FontCollection _fonts;
  100. /**
  101. * @param length the max record length allowed for HSLFSlideShow
  102. */
  103. public static void setMaxRecordLength(int length) {
  104. MAX_RECORD_LENGTH = length;
  105. }
  106. /**
  107. * @return the max record length allowed for HSLFSlideShow
  108. */
  109. public static int getMaxRecordLength() {
  110. return MAX_RECORD_LENGTH;
  111. }
  112. /**
  113. * Constructs a Powerpoint document from the underlying
  114. * HSLFSlideShow object. Finds the model stuff from this
  115. *
  116. * @param hslfSlideShow the HSLFSlideShow to base on
  117. */
  118. public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) {
  119. super(hslfSlideShow.getDirectory());
  120. loadSavePhase.set(LoadSavePhase.INIT);
  121. // Get useful things from our base slideshow
  122. _hslfSlideShow = hslfSlideShow;
  123. // Handle Parent-aware Records
  124. for (Record record : _hslfSlideShow.getRecords()) {
  125. if(record instanceof RecordContainer){
  126. RecordContainer.handleParentAwareRecords((RecordContainer)record);
  127. }
  128. }
  129. // Find the versions of the core records we'll want to use
  130. findMostRecentCoreRecords();
  131. // Build up the model level Slides and Notes
  132. buildSlidesAndNotes();
  133. loadSavePhase.set(LoadSavePhase.LOADED);
  134. }
  135. /**
  136. * Constructs a new, empty, Powerpoint document.
  137. */
  138. public HSLFSlideShow() {
  139. this(HSLFSlideShowImpl.create());
  140. }
  141. /**
  142. * Constructs a Powerpoint document from an input stream.
  143. * @throws IOException
  144. * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
  145. * input format
  146. */
  147. @SuppressWarnings("resource")
  148. public HSLFSlideShow(InputStream inputStream) throws IOException {
  149. this(new HSLFSlideShowImpl(inputStream));
  150. }
  151. /**
  152. * Constructs a Powerpoint document from an POIFSFileSystem.
  153. * @throws IOException
  154. * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
  155. * input format
  156. */
  157. @SuppressWarnings("resource")
  158. public HSLFSlideShow(POIFSFileSystem poifs) throws IOException {
  159. this(new HSLFSlideShowImpl(poifs));
  160. }
  161. /**
  162. * Constructs a Powerpoint document from an DirectoryNode.
  163. * @throws IOException
  164. * @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
  165. * input format
  166. */
  167. @SuppressWarnings("resource")
  168. public HSLFSlideShow(DirectoryNode root) throws IOException {
  169. this(new HSLFSlideShowImpl(root));
  170. }
  171. /**
  172. * @return the current loading/saving phase
  173. */
  174. static LoadSavePhase getLoadSavePhase() {
  175. return loadSavePhase.get();
  176. }
  177. /**
  178. * Use the PersistPtrHolder entries to figure out what is the "most recent"
  179. * version of all the core records (Document, Notes, Slide etc), and save a
  180. * record of them. Do this by walking from the oldest PersistPtr to the
  181. * newest, overwriting any references found along the way with newer ones
  182. */
  183. private void findMostRecentCoreRecords() {
  184. // To start with, find the most recent in the byte offset domain
  185. Map<Integer,Integer> mostRecentByBytes = new HashMap<>();
  186. for (Record record : _hslfSlideShow.getRecords()) {
  187. if (record instanceof PersistPtrHolder) {
  188. PersistPtrHolder pph = (PersistPtrHolder) record;
  189. // If we've already seen any of the "slide" IDs for this
  190. // PersistPtr, remove their old positions
  191. int[] ids = pph.getKnownSlideIDs();
  192. for (int id : ids) {
  193. mostRecentByBytes.remove(id);
  194. }
  195. // Now, update the byte level locations with their latest values
  196. Map<Integer,Integer> thisSetOfLocations = pph.getSlideLocationsLookup();
  197. for (int id : ids) {
  198. mostRecentByBytes.put(id, thisSetOfLocations.get(id));
  199. }
  200. }
  201. }
  202. // We now know how many unique special records we have, so init
  203. // the array
  204. _mostRecentCoreRecords = new Record[mostRecentByBytes.size()];
  205. // We'll also want to be able to turn the slide IDs into a position
  206. // in this array
  207. _sheetIdToCoreRecordsLookup = new HashMap<>();
  208. Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[0]);
  209. Arrays.sort(allIDs);
  210. for (int i = 0; i < allIDs.length; i++) {
  211. _sheetIdToCoreRecordsLookup.put(allIDs[i], i);
  212. }
  213. Map<Integer,Integer> mostRecentByBytesRev = new HashMap<>(mostRecentByBytes.size());
  214. for (Map.Entry<Integer,Integer> me : mostRecentByBytes.entrySet()) {
  215. mostRecentByBytesRev.put(me.getValue(), me.getKey());
  216. }
  217. // Now convert the byte offsets back into record offsets
  218. for (Record record : _hslfSlideShow.getRecords()) {
  219. if (!(record instanceof PositionDependentRecord)) {
  220. continue;
  221. }
  222. PositionDependentRecord pdr = (PositionDependentRecord) record;
  223. int recordAt = pdr.getLastOnDiskOffset();
  224. Integer thisID = mostRecentByBytesRev.get(recordAt);
  225. if (thisID == null) {
  226. continue;
  227. }
  228. // Bingo. Now, where do we store it?
  229. int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
  230. // Tell it its Sheet ID, if it cares
  231. if (pdr instanceof PositionDependentRecordContainer) {
  232. PositionDependentRecordContainer pdrc = (PositionDependentRecordContainer) record;
  233. pdrc.setSheetId(thisID);
  234. }
  235. // Finally, save the record
  236. _mostRecentCoreRecords[storeAt] = record;
  237. }
  238. // Now look for the interesting records in there
  239. for (Record record : _mostRecentCoreRecords) {
  240. // Check there really is a record at this number
  241. if (record != null) {
  242. // Find the Document, and interesting things in it
  243. if (record.getRecordType() == RecordTypes.Document.typeID) {
  244. _documentRecord = (Document) record;
  245. if (_documentRecord.getEnvironment() != null) {
  246. _fonts = _documentRecord.getEnvironment().getFontCollection();
  247. }
  248. }
  249. } /*else {
  250. // No record at this number
  251. // Odd, but not normally a problem
  252. }*/
  253. }
  254. }
  255. /**
  256. * For a given SlideAtomsSet, return the core record, based on the refID
  257. * from the SlidePersistAtom
  258. */
  259. public Record getCoreRecordForSAS(SlideAtomsSet sas) {
  260. SlidePersistAtom spa = sas.getSlidePersistAtom();
  261. int refID = spa.getRefID();
  262. return getCoreRecordForRefID(refID);
  263. }
  264. /**
  265. * For a given refID (the internal, 0 based numbering scheme), return the
  266. * core record
  267. *
  268. * @param refID
  269. * the refID
  270. */
  271. public Record getCoreRecordForRefID(int refID) {
  272. Integer coreRecordId = _sheetIdToCoreRecordsLookup.get(refID);
  273. if (coreRecordId != null) {
  274. return _mostRecentCoreRecords[coreRecordId];
  275. }
  276. LOG.atError().log("We tried to look up a reference to a core record, but there was no core ID for reference ID {}", box(refID));
  277. return null;
  278. }
  279. /**
  280. * Build up model level Slide and Notes objects, from the underlying
  281. * records.
  282. */
  283. private void buildSlidesAndNotes() {
  284. // Ensure we really found a Document record earlier
  285. // If we didn't, then the file is probably corrupt
  286. if (_documentRecord == null) {
  287. throw new CorruptPowerPointFileException(
  288. "The PowerPoint file didn't contain a Document Record in its PersistPtr blocks. It is probably corrupt.");
  289. }
  290. // Fetch the SlideListWithTexts in the most up-to-date Document Record
  291. //
  292. // As far as we understand it:
  293. // * The first SlideListWithText will contain a SlideAtomsSet
  294. // for each of the master slides
  295. // * The second SlideListWithText will contain a SlideAtomsSet
  296. // for each of the slides, in their current order
  297. // These SlideAtomsSets will normally contain text
  298. // * The third SlideListWithText (if present), will contain a
  299. // SlideAtomsSet for each Notes
  300. // These SlideAtomsSets will not normally contain text
  301. //
  302. // Having indentified the masters, slides and notes + their orders,
  303. // we have to go and find their matching records
  304. // We always use the latest versions of these records, and use the
  305. // SlideAtom/NotesAtom to match them with the StyleAtomSet
  306. findMasterSlides();
  307. // Having sorted out the masters, that leaves the notes and slides
  308. Map<Integer,Integer> slideIdToNotes = new HashMap<>();
  309. // Start by finding the notes records
  310. findNotesSlides(slideIdToNotes);
  311. // Now, do the same thing for our slides
  312. findSlides(slideIdToNotes);
  313. }
  314. /**
  315. * Find master slides
  316. * These can be MainMaster records, but oddly they can also be
  317. * Slides or Notes, and possibly even other odd stuff....
  318. * About the only thing you can say is that the master details are in the first SLWT.
  319. */
  320. private void findMasterSlides() {
  321. SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText();
  322. if (masterSLWT == null) {
  323. return;
  324. }
  325. for (SlideAtomsSet sas : masterSLWT.getSlideAtomsSets()) {
  326. Record r = getCoreRecordForSAS(sas);
  327. int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
  328. if (r instanceof Slide) {
  329. HSLFTitleMaster master = new HSLFTitleMaster((Slide)r, sheetNo);
  330. master.setSlideShow(this);
  331. _titleMasters.add(master);
  332. } else if (r instanceof MainMaster) {
  333. HSLFSlideMaster master = new HSLFSlideMaster((MainMaster)r, sheetNo);
  334. master.setSlideShow(this);
  335. _masters.add(master);
  336. }
  337. }
  338. }
  339. private void findNotesSlides(Map<Integer,Integer> slideIdToNotes) {
  340. SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
  341. if (notesSLWT == null) {
  342. return;
  343. }
  344. // Match up the records and the SlideAtomSets
  345. int idx = -1;
  346. for (SlideAtomsSet notesSet : notesSLWT.getSlideAtomsSets()) {
  347. idx++;
  348. // Get the right core record
  349. Record r = getCoreRecordForSAS(notesSet);
  350. SlidePersistAtom spa = notesSet.getSlidePersistAtom();
  351. String loggerLoc = "A Notes SlideAtomSet at "+idx+" said its record was at refID "+spa.getRefID();
  352. // we need to add null-records, otherwise the index references to other existing don't work anymore
  353. if (r == null) {
  354. LOG.atWarn().log("{}, but that record didn't exist - record ignored.", loggerLoc);
  355. continue;
  356. }
  357. // Ensure it really is a notes record
  358. if (!(r instanceof Notes)) {
  359. LOG.atError().log("{}, but that was actually a {}", loggerLoc, r);
  360. continue;
  361. }
  362. Notes notesRecord = (Notes) r;
  363. // Record the match between slide id and these notes
  364. int slideId = spa.getSlideIdentifier();
  365. slideIdToNotes.put(slideId, idx);
  366. if (notesRecord.getNotesAtom() == null) {
  367. throw new IllegalStateException("Could not read NotesAtom from the NotesRecord for " + idx);
  368. }
  369. HSLFNotes hn = new HSLFNotes(notesRecord);
  370. hn.setSlideShow(this);
  371. _notes.add(hn);
  372. }
  373. }
  374. private void findSlides(Map<Integer,Integer> slideIdToNotes) {
  375. SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
  376. if (slidesSLWT == null) {
  377. return;
  378. }
  379. // Match up the records and the SlideAtomSets
  380. int idx = -1;
  381. for (SlideAtomsSet sas : slidesSLWT.getSlideAtomsSets()) {
  382. idx++;
  383. // Get the right core record
  384. SlidePersistAtom spa = sas.getSlidePersistAtom();
  385. Record r = getCoreRecordForSAS(sas);
  386. // Ensure it really is a slide record
  387. if (!(r instanceof Slide)) {
  388. LOG.atError().log("A Slide SlideAtomSet at {} said its record was at refID {}, but that was actually a {}",
  389. box(idx), box(spa.getRefID()), r);
  390. continue;
  391. }
  392. Slide slide = (Slide)r;
  393. if (slide.getSlideAtom() == null) {
  394. LOG.atError().log("SlideAtomSet at {} at refID {} is null", box(idx), box(spa.getRefID()));
  395. continue;
  396. }
  397. // Do we have a notes for this?
  398. HSLFNotes notes = null;
  399. // Slide.SlideAtom.notesId references the corresponding notes slide.
  400. // 0 if slide has no notes.
  401. int noteId = slide.getSlideAtom().getNotesID();
  402. if (noteId != 0) {
  403. Integer notesPos = slideIdToNotes.get(noteId);
  404. if (notesPos != null && 0 <= notesPos && notesPos < _notes.size()) {
  405. notes = _notes.get(notesPos);
  406. } else {
  407. LOG.atError().log("Notes not found for noteId={}", box(noteId));
  408. }
  409. }
  410. // Now, build our slide
  411. int slideIdentifier = spa.getSlideIdentifier();
  412. HSLFSlide hs = new HSLFSlide(slide, notes, sas, slideIdentifier, (idx + 1));
  413. hs.setSlideShow(this);
  414. _slides.add(hs);
  415. }
  416. }
  417. @Override
  418. public void write(OutputStream out) throws IOException {
  419. // check for text paragraph modifications
  420. for (HSLFSlide sl : getSlides()) {
  421. writeDirtyParagraphs(sl);
  422. }
  423. for (HSLFSlideMaster sl : getSlideMasters()) {
  424. boolean isDirty = false;
  425. for (List<HSLFTextParagraph> paras : sl.getTextParagraphs()) {
  426. for (HSLFTextParagraph p : paras) {
  427. isDirty |= p.isDirty();
  428. }
  429. }
  430. if (isDirty) {
  431. for (TxMasterStyleAtom sa : sl.getTxMasterStyleAtoms()) {
  432. if (sa != null) {
  433. // not all master style atoms are set - index 3 is typically null
  434. sa.updateStyles();
  435. }
  436. }
  437. }
  438. }
  439. _hslfSlideShow.write(out);
  440. }
  441. private void writeDirtyParagraphs(HSLFShapeContainer container) {
  442. for (HSLFShape sh : container.getShapes()) {
  443. if (sh instanceof HSLFShapeContainer) {
  444. writeDirtyParagraphs((HSLFShapeContainer)sh);
  445. } else if (sh instanceof HSLFTextShape) {
  446. HSLFTextShape hts = (HSLFTextShape)sh;
  447. boolean isDirty = false;
  448. for (HSLFTextParagraph p : hts.getTextParagraphs()) {
  449. isDirty |= p.isDirty();
  450. }
  451. if (isDirty) {
  452. hts.storeText();
  453. }
  454. }
  455. }
  456. }
  457. /**
  458. * Returns an array of the most recent version of all the interesting
  459. * records
  460. */
  461. public Record[] getMostRecentCoreRecords() {
  462. return _mostRecentCoreRecords;
  463. }
  464. /**
  465. * Returns an array of all the normal Slides found in the slideshow
  466. */
  467. @Override
  468. public List<HSLFSlide> getSlides() {
  469. return _slides;
  470. }
  471. /**
  472. * Returns an array of all the normal Notes found in the slideshow
  473. */
  474. public List<HSLFNotes> getNotes() {
  475. return _notes;
  476. }
  477. /**
  478. * Returns an array of all the normal Slide Masters found in the slideshow
  479. */
  480. @Override
  481. public List<HSLFSlideMaster> getSlideMasters() {
  482. return _masters;
  483. }
  484. /**
  485. * Returns an array of all the normal Title Masters found in the slideshow
  486. */
  487. public List<HSLFTitleMaster> getTitleMasters() {
  488. return _titleMasters;
  489. }
  490. @Override
  491. public List<HSLFPictureData> getPictureData() {
  492. return _hslfSlideShow.getPictureData();
  493. }
  494. /**
  495. * Returns the data of all the embedded OLE object in the SlideShow
  496. */
  497. @SuppressWarnings("WeakerAccess")
  498. public HSLFObjectData[] getEmbeddedObjects() {
  499. return _hslfSlideShow.getEmbeddedObjects();
  500. }
  501. /**
  502. * Returns the data of all the embedded sounds in the SlideShow
  503. */
  504. public HSLFSoundData[] getSoundData() {
  505. return HSLFSoundData.find(_documentRecord);
  506. }
  507. @Override
  508. public Dimension getPageSize() {
  509. DocumentAtom docatom = _documentRecord.getDocumentAtom();
  510. int pgx = (int)Units.masterToPoints((int)docatom.getSlideSizeX());
  511. int pgy = (int)Units.masterToPoints((int)docatom.getSlideSizeY());
  512. return new Dimension(pgx, pgy);
  513. }
  514. @Override
  515. public void setPageSize(Dimension pgsize) {
  516. DocumentAtom docatom = _documentRecord.getDocumentAtom();
  517. docatom.setSlideSizeX(Units.pointsToMaster(pgsize.width));
  518. docatom.setSlideSizeY(Units.pointsToMaster(pgsize.height));
  519. }
  520. /**
  521. * Helper method for usermodel: Get the font collection
  522. */
  523. FontCollection getFontCollection() {
  524. return _fonts;
  525. }
  526. /**
  527. * Helper method for usermodel and model: Get the document record
  528. */
  529. public Document getDocumentRecord() {
  530. return _documentRecord;
  531. }
  532. /**
  533. * Re-orders a slide, to a new position.
  534. *
  535. * @param oldSlideNumber
  536. * The old slide number (1 based)
  537. * @param newSlideNumber
  538. * The new slide number (1 based)
  539. */
  540. @SuppressWarnings("WeakerAccess")
  541. public void reorderSlide(int oldSlideNumber, int newSlideNumber) {
  542. // Ensure these numbers are valid
  543. if (oldSlideNumber < 1 || newSlideNumber < 1) {
  544. throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
  545. }
  546. if (oldSlideNumber > _slides.size() || newSlideNumber > _slides.size()) {
  547. throw new IllegalArgumentException(
  548. "Old and new slide numbers must not exceed the number of slides ("
  549. + _slides.size() + ")");
  550. }
  551. // The order of slides is defined by the order of slide atom sets in the
  552. // SlideListWithText container.
  553. SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
  554. if (slwt == null) {
  555. throw new IllegalStateException("Slide record not defined.");
  556. }
  557. SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
  558. SlideAtomsSet tmp = sas[oldSlideNumber - 1];
  559. sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
  560. sas[newSlideNumber - 1] = tmp;
  561. Collections.swap(_slides, oldSlideNumber - 1, newSlideNumber - 1);
  562. _slides.get(newSlideNumber - 1).setSlideNumber(newSlideNumber);
  563. _slides.get(oldSlideNumber - 1).setSlideNumber(oldSlideNumber);
  564. ArrayList<Record> lst = new ArrayList<>();
  565. for (SlideAtomsSet s : sas) {
  566. lst.add(s.getSlidePersistAtom());
  567. lst.addAll(Arrays.asList(s.getSlideRecords()));
  568. }
  569. Record[] r = lst.toArray(new Record[0]);
  570. slwt.setChildRecord(r);
  571. }
  572. /**
  573. * Removes the slide at the given index (0-based).
  574. * <p>
  575. * Shifts any subsequent slides to the left (subtracts one from their slide
  576. * numbers).
  577. * </p>
  578. *
  579. * @param index
  580. * the index of the slide to remove (0-based)
  581. * @return the slide that was removed from the slide show.
  582. */
  583. @SuppressWarnings("WeakerAccess")
  584. public HSLFSlide removeSlide(int index) {
  585. int lastSlideIdx = _slides.size() - 1;
  586. if (index < 0 || index > lastSlideIdx) {
  587. throw new IllegalArgumentException("Slide index (" + index + ") is out of range (0.."
  588. + lastSlideIdx + ")");
  589. }
  590. SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
  591. if (slwt == null) {
  592. throw new IllegalStateException("Slide record not defined.");
  593. }
  594. SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
  595. List<Record> records = new ArrayList<>();
  596. List<SlideAtomsSet> sa = new ArrayList<>(Arrays.asList(sas));
  597. HSLFSlide removedSlide = _slides.remove(index);
  598. _notes.remove(removedSlide.getNotes());
  599. sa.remove(index);
  600. int i=0;
  601. for (HSLFSlide s : _slides) {
  602. s.setSlideNumber(i++);
  603. }
  604. for (SlideAtomsSet s : sa) {
  605. records.add(s.getSlidePersistAtom());
  606. records.addAll(Arrays.asList(s.getSlideRecords()));
  607. }
  608. if (sa.isEmpty()) {
  609. _documentRecord.removeSlideListWithText(slwt);
  610. } else {
  611. slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[0]));
  612. slwt.setChildRecord(records.toArray(new Record[0]));
  613. }
  614. // if the removed slide had notes - remove references to them too
  615. int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
  616. if (notesId != 0) {
  617. SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
  618. records = new ArrayList<>();
  619. ArrayList<SlideAtomsSet> na = new ArrayList<>();
  620. if (nslwt != null) {
  621. for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
  622. if (ns.getSlidePersistAtom().getSlideIdentifier() == notesId) {
  623. continue;
  624. }
  625. na.add(ns);
  626. records.add(ns.getSlidePersistAtom());
  627. if (ns.getSlideRecords() != null) {
  628. records.addAll(Arrays.asList(ns.getSlideRecords()));
  629. }
  630. }
  631. if (!na.isEmpty()) {
  632. nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0]));
  633. nslwt.setChildRecord(records.toArray(new Record[0]));
  634. }
  635. }
  636. if (na.isEmpty()) {
  637. _documentRecord.removeSlideListWithText(nslwt);
  638. }
  639. }
  640. return removedSlide;
  641. }
  642. /**
  643. * Create a blank {@code Slide}.
  644. *
  645. * @return the created {@code Slide}
  646. */
  647. @Override
  648. public HSLFSlide createSlide() {
  649. // We need to add the records to the SLWT that deals
  650. // with Slides.
  651. // Add it, if it doesn't exist
  652. SlideListWithText slist = _documentRecord.getSlideSlideListWithText();
  653. if (slist == null) {
  654. // Need to add a new one
  655. slist = new SlideListWithText();
  656. slist.setInstance(SlideListWithText.SLIDES);
  657. _documentRecord.addSlideListWithText(slist);
  658. }
  659. // Grab the SlidePersistAtom with the highest Slide Number.
  660. // (Will stay as null if no SlidePersistAtom exists yet in
  661. // the slide, or only master slide's ones do)
  662. SlidePersistAtom prev = null;
  663. for (SlideAtomsSet sas : slist.getSlideAtomsSets()) {
  664. SlidePersistAtom spa = sas.getSlidePersistAtom();
  665. if (spa.getSlideIdentifier() >= 0) {
  666. // Must be for a real slide
  667. if (prev == null) {
  668. prev = spa;
  669. }
  670. if (prev.getSlideIdentifier() < spa.getSlideIdentifier()) {
  671. prev = spa;
  672. }
  673. }
  674. }
  675. // Set up a new SlidePersistAtom for this slide
  676. SlidePersistAtom sp = new SlidePersistAtom();
  677. // First slideId is always 256
  678. sp.setSlideIdentifier(prev == null ? 256 : (prev.getSlideIdentifier() + 1));
  679. // Add this new SlidePersistAtom to the SlideListWithText
  680. slist.addSlidePersistAtom(sp);
  681. // Create a new Slide
  682. HSLFSlide slide = new HSLFSlide(sp.getSlideIdentifier(), sp.getRefID(), _slides.size() + 1);
  683. slide.setSlideShow(this);
  684. slide.onCreate();
  685. // Add in to the list of Slides
  686. _slides.add(slide);
  687. LOG.atInfo().log("Added slide {} with ref {} and identifier {}", box(_slides.size()),box(sp.getRefID()),box(sp.getSlideIdentifier()));
  688. // Add the core records for this new Slide to the record tree
  689. Slide slideRecord = slide.getSlideRecord();
  690. int psrId = addPersistentObject(slideRecord);
  691. sp.setRefID(psrId);
  692. slideRecord.setSheetId(psrId);
  693. slide.setMasterSheet(_masters.get(0));
  694. // All done and added
  695. return slide;
  696. }
  697. @Override
  698. public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
  699. if (format == null || format.nativeId == -1) {
  700. throw new IllegalArgumentException("Unsupported picture format: " + format);
  701. }
  702. HSLFPictureData pd = findPictureData(data);
  703. if (pd != null) {
  704. // identical picture was already added to the SlideShow
  705. return pd;
  706. }
  707. EscherContainerRecord bstore;
  708. EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
  709. bstore = HSLFShape.getEscherChild(dggContainer,
  710. EscherContainerRecord.BSTORE_CONTAINER);
  711. if (bstore == null) {
  712. bstore = new EscherContainerRecord();
  713. bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
  714. dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
  715. }
  716. EscherBSERecord bse = addNewEscherBseRecord(bstore, format, data, 0);
  717. HSLFPictureData pict = HSLFPictureData.createFromImageData(format, bstore, bse, data);
  718. int offset = _hslfSlideShow.addPicture(pict);
  719. bse.setOffset(offset);
  720. return pict;
  721. }
  722. /**
  723. * Adds a picture to the presentation.
  724. *
  725. * @param is The stream to read the image from
  726. * @param format The format of the picture.
  727. *
  728. * @return the picture data.
  729. * @since 3.15 beta 2
  730. */
  731. @Override
  732. public HSLFPictureData addPicture(InputStream is, PictureType format) throws IOException {
  733. if (format == null || format.nativeId == -1) { // fail early
  734. throw new IllegalArgumentException("Unsupported picture format: " + format);
  735. }
  736. return addPicture(IOUtils.toByteArray(is), format);
  737. }
  738. /**
  739. * Adds a picture to the presentation.
  740. *
  741. * @param pict
  742. * the file containing the image to add
  743. * @param format
  744. * The format of the picture.
  745. *
  746. * @return the picture data.
  747. * @since 3.15 beta 2
  748. */
  749. @Override
  750. public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
  751. if (format == null || format.nativeId == -1) { // fail early
  752. throw new IllegalArgumentException("Unsupported picture format: " + format);
  753. }
  754. byte[] data = IOUtils.safelyAllocate(pict.length(), MAX_RECORD_LENGTH);
  755. try (FileInputStream is = new FileInputStream(pict)) {
  756. IOUtils.readFully(is, data);
  757. }
  758. return addPicture(data, format);
  759. }
  760. /**
  761. * check if a picture with this picture data already exists in this presentation
  762. *
  763. * @param pictureData The picture data to find in the SlideShow
  764. * @return {@code null} if picture data is not found in this slideshow
  765. * @since 3.15 beta 3
  766. */
  767. @Override
  768. public HSLFPictureData findPictureData(byte[] pictureData) {
  769. byte[] uid = HSLFPictureData.getChecksum(pictureData);
  770. for (HSLFPictureData pic : getPictureData()) {
  771. if (Arrays.equals(pic.getUID(), uid)) {
  772. return pic;
  773. }
  774. }
  775. return null;
  776. }
  777. /**
  778. * Add a font in this presentation
  779. *
  780. * @param fontInfo the font to add
  781. * @return the registered HSLFFontInfo - the font info object is unique based on the typeface
  782. */
  783. public HSLFFontInfo addFont(FontInfo fontInfo) {
  784. return getDocumentRecord().getEnvironment().getFontCollection().addFont(fontInfo);
  785. }
  786. /**
  787. * Add a font in this presentation and also embed its font data
  788. *
  789. * @param fontData the EOT font data as stream
  790. *
  791. * @return the registered HSLFFontInfo - the font info object is unique based on the typeface
  792. *
  793. * @since POI 4.1.0
  794. */
  795. @Override
  796. public HSLFFontInfo addFont(InputStream fontData) throws IOException {
  797. Document doc = getDocumentRecord();
  798. doc.getDocumentAtom().setSaveWithFonts(true);
  799. return doc.getEnvironment().getFontCollection().addFont(fontData);
  800. }
  801. /**
  802. * Get a font by index
  803. *
  804. * @param idx
  805. * 0-based index of the font
  806. * @return of an instance of {@code PPFont} or {@code null} if not
  807. * found
  808. */
  809. public HSLFFontInfo getFont(int idx) {
  810. return getDocumentRecord().getEnvironment().getFontCollection().getFontInfo(idx);
  811. }
  812. /**
  813. * get the number of fonts in the presentation
  814. *
  815. * @return number of fonts
  816. */
  817. public int getNumberOfFonts() {
  818. return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts();
  819. }
  820. @Override
  821. public List<HSLFFontInfo> getFonts() {
  822. return getDocumentRecord().getEnvironment().getFontCollection().getFonts();
  823. }
  824. /**
  825. * Return Header / Footer settings for slides
  826. *
  827. * @return Header / Footer settings for slides
  828. */
  829. public HeadersFooters getSlideHeadersFooters() {
  830. return new HeadersFooters(this, HeadersFootersContainer.SlideHeadersFootersContainer);
  831. }
  832. /**
  833. * Return Header / Footer settings for notes
  834. *
  835. * @return Header / Footer settings for notes
  836. */
  837. public HeadersFooters getNotesHeadersFooters() {
  838. if (_notes.isEmpty()) {
  839. return new HeadersFooters(this, HeadersFootersContainer.NotesHeadersFootersContainer);
  840. } else {
  841. return new HeadersFooters(_notes.get(0), HeadersFootersContainer.NotesHeadersFootersContainer);
  842. }
  843. }
  844. /**
  845. * Add a movie in this presentation
  846. *
  847. * @param path
  848. * the path or url to the movie
  849. * @return 0-based index of the movie
  850. */
  851. public int addMovie(String path, int type) {
  852. ExMCIMovie mci;
  853. switch (type) {
  854. case MovieShape.MOVIE_MPEG:
  855. mci = new ExMCIMovie();
  856. break;
  857. case MovieShape.MOVIE_AVI:
  858. mci = new ExAviMovie();
  859. break;
  860. default:
  861. throw new IllegalArgumentException("Unsupported Movie: " + type);
  862. }
  863. ExVideoContainer exVideo = mci.getExVideo();
  864. exVideo.getExMediaAtom().setMask(0xE80000);
  865. exVideo.getPathAtom().setText(path);
  866. int objectId = addToObjListAtom(mci);
  867. exVideo.getExMediaAtom().setObjectId(objectId);
  868. return objectId;
  869. }
  870. /**
  871. * Add a control in this presentation
  872. *
  873. * @param name
  874. * name of the control, e.g. "Shockwave Flash Object"
  875. * @param progId
  876. * OLE Programmatic Identifier, e.g.
  877. * "ShockwaveFlash.ShockwaveFlash.9"
  878. * @return 0-based index of the control
  879. */
  880. @SuppressWarnings("unused")
  881. public int addControl(String name, String progId) {
  882. ExControl ctrl = new ExControl();
  883. ctrl.setProgId(progId);
  884. ctrl.setMenuName(name);
  885. ctrl.setClipboardName(name);
  886. ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
  887. oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
  888. oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
  889. oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
  890. int objectId = addToObjListAtom(ctrl);
  891. oleObj.setObjID(objectId);
  892. return objectId;
  893. }
  894. /**
  895. * Add a embedded object to this presentation
  896. *
  897. * @return 0-based index of the embedded object
  898. */
  899. public int addEmbed(POIFSFileSystem poiData) {
  900. DirectoryNode root = poiData.getRoot();
  901. // prepare embedded data
  902. if (new ClassID().equals(root.getStorageClsid())) {
  903. // need to set class id
  904. Map<String,ClassID> olemap = getOleMap();
  905. ClassID classID = null;
  906. for (Map.Entry<String,ClassID> entry : olemap.entrySet()) {
  907. if (root.hasEntry(entry.getKey())) {
  908. classID = entry.getValue();
  909. break;
  910. }
  911. }
  912. if (classID == null) {
  913. throw new IllegalArgumentException("Unsupported embedded document");
  914. }
  915. root.setStorageClsid(classID);
  916. }
  917. ExEmbed exEmbed = new ExEmbed();
  918. // remove unneccessary infos, so we don't need to specify the type
  919. // of the ole object multiple times
  920. Record[] children = exEmbed.getChildRecords();
  921. exEmbed.removeChild(children[2]);
  922. exEmbed.removeChild(children[3]);
  923. exEmbed.removeChild(children[4]);
  924. ExEmbedAtom eeEmbed = exEmbed.getExEmbedAtom();
  925. eeEmbed.setCantLockServerB(true);
  926. ExOleObjAtom eeAtom = exEmbed.getExOleObjAtom();
  927. eeAtom.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
  928. eeAtom.setType(ExOleObjAtom.TYPE_EMBEDDED);
  929. // eeAtom.setSubType(ExOleObjAtom.SUBTYPE_EXCEL);
  930. // should be ignored?!?, see MS-PPT ExOleObjAtom, but Libre Office sets it ...
  931. eeAtom.setOptions(1226240);
  932. ExOleObjStg exOleObjStg = new ExOleObjStg();
  933. try {
  934. Ole10Native.createOleMarkerEntry(poiData);
  935. UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
  936. poiData.writeFilesystem(bos);
  937. exOleObjStg.setData(bos.toByteArray());
  938. } catch (IOException e) {
  939. throw new HSLFException(e);
  940. }
  941. int psrId = addPersistentObject(exOleObjStg);
  942. exOleObjStg.setPersistId(psrId);
  943. eeAtom.setObjStgDataRef(psrId);
  944. int objectId = addToObjListAtom(exEmbed);
  945. eeAtom.setObjID(objectId);
  946. return objectId;
  947. }
  948. @Override
  949. public HPSFPropertiesExtractor getMetadataTextExtractor() {
  950. return new HPSFPropertiesExtractor(getSlideShowImpl());
  951. }
  952. int addToObjListAtom(RecordContainer exObj) {
  953. ExObjList lst = getDocumentRecord().getExObjList(true);
  954. ExObjListAtom objAtom = lst.getExObjListAtom();
  955. // increment the object ID seed
  956. int objectId = (int) objAtom.getObjectIDSeed() + 1;
  957. objAtom.setObjectIDSeed(objectId);
  958. lst.addChildAfter(exObj, objAtom);
  959. return objectId;
  960. }
  961. private static Map<String,ClassID> getOleMap() {
  962. Map<String,ClassID> olemap = new HashMap<>();
  963. olemap.put(POWERPOINT_DOCUMENT, ClassIDPredefined.POWERPOINT_V8.getClassID());
  964. // as per BIFF8 spec
  965. olemap.put("Workbook", ClassIDPredefined.EXCEL_V8.getClassID());
  966. // Typically from third party programs
  967. olemap.put("WORKBOOK", ClassIDPredefined.EXCEL_V8.getClassID());
  968. // Typically odd Crystal Reports exports
  969. olemap.put("BOOK", ClassIDPredefined.EXCEL_V8.getClassID());
  970. // ... to be continued
  971. return olemap;
  972. }
  973. private int addPersistentObject(PositionDependentRecord slideRecord) {
  974. slideRecord.setLastOnDiskOffset(HSLFSlideShowImpl.UNSET_OFFSET);
  975. _hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
  976. // For position dependent records, hold where they were and now are
  977. // As we go along, update, and hand over, to any Position Dependent
  978. // records we happen across
  979. Map<RecordTypes,PositionDependentRecord> interestingRecords =
  980. new HashMap<>();
  981. try {
  982. _hslfSlideShow.updateAndWriteDependantRecords(null,interestingRecords);
  983. } catch (IOException e) {
  984. throw new HSLFException(e);
  985. }
  986. PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
  987. UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
  988. // persist ID is UserEditAtom.maxPersistWritten + 1
  989. int psrId = usr.getMaxPersistWritten() + 1;
  990. // Last view is now of the slide
  991. usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
  992. // increment the number of persistent objects
  993. usr.setMaxPersistWritten(psrId);
  994. // Add the new slide into the last PersistPtr
  995. // (Also need to tell it where it is)
  996. int slideOffset = slideRecord.getLastOnDiskOffset();
  997. slideRecord.setLastOnDiskOffset(slideOffset);
  998. ptr.addSlideLookup(psrId, slideOffset);
  999. LOG.atInfo().log("New slide/object ended up at {}", box(slideOffset));
  1000. return psrId;
  1001. }
  1002. @Override
  1003. public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() {
  1004. // TODO implement or throw exception if not supported
  1005. return null;
  1006. }
  1007. /**
  1008. * @return the handler class which holds the hslf records
  1009. */
  1010. @Internal
  1011. public HSLFSlideShowImpl getSlideShowImpl() {
  1012. return _hslfSlideShow;
  1013. }
  1014. @Override
  1015. public void close() throws IOException {
  1016. _hslfSlideShow.close();
  1017. }
  1018. @Override
  1019. public Object getPersistDocument() {
  1020. return getSlideShowImpl();
  1021. }
  1022. @Override
  1023. public Map<String, Supplier<?>> getGenericProperties() {
  1024. return GenericRecordUtil.getGenericProperties(
  1025. "pictures", this::getPictureData,
  1026. "embeddedObjects", this::getEmbeddedObjects
  1027. );
  1028. }
  1029. @Override
  1030. public List<? extends GenericRecord> getGenericChildren() {
  1031. return Arrays.asList(_hslfSlideShow.getRecords());
  1032. }
  1033. @Override
  1034. public void write() throws IOException {
  1035. getSlideShowImpl().write();
  1036. }
  1037. @Override
  1038. public void write(File newFile) throws IOException {
  1039. getSlideShowImpl().write(newFile);
  1040. }
  1041. @Override
  1042. public DocumentSummaryInformation getDocumentSummaryInformation() {
  1043. return getSlideShowImpl().getDocumentSummaryInformation();
  1044. }
  1045. @Override
  1046. public SummaryInformation getSummaryInformation() {
  1047. return getSlideShowImpl().getSummaryInformation();
  1048. }
  1049. @Override
  1050. public void createInformationProperties() {
  1051. getSlideShowImpl().createInformationProperties();
  1052. }
  1053. @Override
  1054. public void readProperties() {
  1055. getSlideShowImpl().readProperties();
  1056. }
  1057. @Override
  1058. protected PropertySet getPropertySet(String setName) throws IOException {
  1059. return getSlideShowImpl().getPropertySetImpl(setName);
  1060. }
  1061. @Override
  1062. protected PropertySet getPropertySet(String setName, EncryptionInfo encryptionInfo) throws IOException {
  1063. return getSlideShowImpl().getPropertySetImpl(setName, encryptionInfo);
  1064. }
  1065. @Override
  1066. protected void writeProperties() throws IOException {
  1067. getSlideShowImpl().writePropertiesImpl();
  1068. }
  1069. @Override
  1070. public void writeProperties(POIFSFileSystem outFS) throws IOException {
  1071. getSlideShowImpl().writeProperties(outFS);
  1072. }
  1073. @Override
  1074. protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
  1075. getSlideShowImpl().writePropertiesImpl(outFS, writtenEntries);
  1076. }
  1077. @Override
  1078. protected void validateInPlaceWritePossible() throws IllegalStateException {
  1079. getSlideShowImpl().validateInPlaceWritePossibleImpl();
  1080. }
  1081. @Override
  1082. public DirectoryNode getDirectory() {
  1083. return getSlideShowImpl().getDirectory();
  1084. }
  1085. @Override
  1086. protected void clearDirectory() {
  1087. getSlideShowImpl().clearDirectoryImpl();
  1088. }
  1089. @Override
  1090. protected boolean initDirectory() {
  1091. return getSlideShowImpl().initDirectoryImpl();
  1092. }
  1093. @Override
  1094. protected void replaceDirectory(DirectoryNode newDirectory) throws IOException {
  1095. getSlideShowImpl().replaceDirectoryImpl(newDirectory);
  1096. }
  1097. @Override
  1098. protected String getEncryptedPropertyStreamName() {
  1099. return getSlideShowImpl().getEncryptedPropertyStreamName();
  1100. }
  1101. @Override
  1102. public EncryptionInfo getEncryptionInfo() {
  1103. return getSlideShowImpl().getEncryptionInfo();
  1104. }
  1105. static EscherBSERecord addNewEscherBseRecord(EscherContainerRecord blipStore, PictureType type, byte[] imageData, int offset) {
  1106. EscherBSERecord record = new EscherBSERecord();
  1107. record.setRecordId(EscherBSERecord.RECORD_ID);
  1108. record.setOptions((short) (0x0002 | (type.nativeId << 4)));
  1109. record.setSize(imageData.length + HSLFPictureData.PREAMBLE_SIZE);
  1110. record.setUid(Arrays.copyOf(imageData, HSLFPictureData.CHECKSUM_SIZE));
  1111. record.setBlipTypeMacOS((byte) type.nativeId);
  1112. record.setBlipTypeWin32((byte) type.nativeId);
  1113. if (type == PictureType.EMF) {
  1114. record.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
  1115. } else if (type == PictureType.WMF) {
  1116. record.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
  1117. } else if (type == PictureType.PICT) {
  1118. record.setBlipTypeWin32((byte) PictureType.WMF.nativeId);
  1119. }
  1120. record.setOffset(offset);
  1121. blipStore.addChildRecord(record);
  1122. int count = blipStore.getChildCount();
  1123. blipStore.setOptions((short) ((count << 4) | 0xF));
  1124. return record;
  1125. }
  1126. }