/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hslf.usermodel;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.model.Comment;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.Comment2000;
import org.apache.poi.hslf.record.EscherTextboxWrapper;
import org.apache.poi.hslf.record.HeadersFootersContainer;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.SSSlideInfoAtom;
import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
import org.apache.poi.hslf.record.StyleTextProp9Atom;
import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Slide;
/**
* This class represents a slide in a PowerPoint Document. It allows
* access to the text within, and the layout. For now, it only does
* the text side of things though
*
* @author Nick Burch
* @author Yegor Kozlov
*/
public final class HSLFSlide extends HSLFSheet implements Slide
* For Slide we need to do the following:
* > _paragraphs = new ArrayList
>();
private HSLFNotes _notes; // usermodel needs to set this
/**
* Constructs a Slide from the Slide record, and the SlideAtomsSet
* containing the text.
* Initializes TextRuns, to provide easier access to the text
*
* @param slide the Slide record we're based on
* @param notes the Notes sheet attached to us
* @param atomSet the SlideAtomsSet to get the text from
*/
public HSLFSlide(org.apache.poi.hslf.record.Slide slide, HSLFNotes notes, SlideAtomsSet atomSet, int slideIdentifier, int slideNumber) {
super(slide, slideIdentifier);
_notes = notes;
_atomSet = atomSet;
_slideNo = slideNumber;
// For the text coming in from the SlideAtomsSet:
// Build up TextRuns from pairs of TextHeaderAtom and
// one of TextBytesAtom or TextCharsAtom
if (_atomSet != null && _atomSet.getSlideRecords().length > 0) {
// Grab text from SlideListWithTexts entries
_paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
if (_paragraphs.isEmpty()) {
throw new RuntimeException("No text records found for slide");
}
} else {
// No text on the slide, must just be pictures
}
// Grab text from slide's PPDrawing
for (List
TextBox
object that represents the slide's title.
*
* @return TextBox
object that represents the slide's title.
*/
public HSLFTextBox addTitle() {
HSLFPlaceholder pl = new HSLFPlaceholder();
pl.setShapeType(ShapeType.RECT);
pl.setPlaceholder(Placeholder.TITLE);
pl.setRunType(TextHeaderAtom.TITLE_TYPE);
pl.setText("Click to edit title");
pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
addShape(pl);
return pl;
}
// Complex Accesser methods follow
/**
*
* The title is a run of text of type TextHeaderAtom.CENTER_TITLE_TYPE
or
* TextHeaderAtom.TITLE_TYPE
*
SlideListWithtext
container
* which hold text data for this slide (typically for placeholders).
*/
protected SlideAtomsSet getSlideAtomsSet() { return _atomSet; }
/**
* Returns master sheet associated with this slide.
* It can be either SlideMaster or TitleMaster objects.
*
* @return the master sheet associated with this slide.
*/
public HSLFMasterSheet getMasterSheet(){
int masterId = getSlideRecord().getSlideAtom().getMasterID();
for (HSLFSlideMaster sm : getSlideShow().getSlideMasters()) {
if (masterId == sm._getSheetNumber()) return sm;
}
for (HSLFTitleMaster tm : getSlideShow().getTitleMasters()) {
if (masterId == tm._getSheetNumber()) return tm;
}
return null;
}
/**
* Change Master of this slide.
*/
public void setMasterSheet(HSLFMasterSheet master){
SlideAtom sa = getSlideRecord().getSlideAtom();
int sheetNo = master._getSheetNumber();
sa.setMasterID(sheetNo);
}
/**
* Sets whether this slide follows master background
*
* @param flag true
if the slide follows master,
* false
otherwise
*/
public void setFollowMasterBackground(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterBackground(flag);
}
/**
* Whether this slide follows master sheet background
*
* @return true
if the slide follows master background,
* false
otherwise
*/
public boolean getFollowMasterBackground(){
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterBackground();
}
/**
* Sets whether this slide draws master sheet objects
*
* @param flag true
if the slide draws master sheet objects,
* false
otherwise
*/
public void setFollowMasterObjects(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterObjects(flag);
}
/**
* Whether this slide follows master color scheme
*
* @return true
if the slide follows master color scheme,
* false
otherwise
*/
public boolean getFollowMasterScheme(){
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterScheme();
}
/**
* Sets whether this slide draws master color scheme
*
* @param flag true
if the slide draws master color scheme,
* false
otherwise
*/
public void setFollowMasterScheme(boolean flag){
SlideAtom sa = getSlideRecord().getSlideAtom();
sa.setFollowMasterScheme(flag);
}
/**
* Whether this slide draws master sheet objects
*
* @return true
if the slide draws master sheet objects,
* false
otherwise
*/
public boolean getFollowMasterObjects(){
SlideAtom sa = getSlideRecord().getSlideAtom();
return sa.getFollowMasterObjects();
}
/**
* Background for this slide.
*/
public HSLFBackground getBackground() {
if(getFollowMasterBackground()) {
return getMasterSheet().getBackground();
}
return super.getBackground();
}
/**
* Color scheme for this slide.
*/
public ColorSchemeAtom getColorScheme() {
if(getFollowMasterScheme()){
return getMasterSheet().getColorScheme();
}
return super.getColorScheme();
}
/**
* Get the comment(s) for this slide.
* Note - for now, only works on PPT 2000 and
* PPT 2003 files. Doesn't work for PPT 97
* ones, as they do their comments oddly.
*/
public Comment[] getComments() {
// If there are any, they're in
// ProgTags -> ProgBinaryTag -> BinaryTagData
RecordContainer progTags = (RecordContainer)
getSheetContainer().findFirstOfType(
RecordTypes.ProgTags.typeID
);
if(progTags != null) {
RecordContainer progBinaryTag = (RecordContainer)
progTags.findFirstOfType(
RecordTypes.ProgBinaryTag.typeID
);
if(progBinaryTag != null) {
RecordContainer binaryTags = (RecordContainer)
progBinaryTag.findFirstOfType(
RecordTypes.BinaryTagData.typeID
);
if(binaryTags != null) {
// This is where they'll be
int count = 0;
for(int i=0; i