This class defines the common format of "Sheets" in a powerpoint
document. Such sheets could be Slides, Notes, Master etc
| Method from org.apache.poi.hslf.model.Sheet Detail: |
public int _getSheetNumber() {
return _sheetNo;
}
Returns the (internal, SlideIdentifier based) sheet number, as used
to reference this sheet from other records. |
public int _getSheetRefId() {
return _container.getSheetId();
}
Returns the (internal, RefID based) sheet number, as used
to in PersistPtr stuff. |
public void addShape(Shape shape) {
PPDrawing ppdrawing = getPPDrawing();
EscherContainerRecord dgContainer = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
EscherContainerRecord spgr = (EscherContainerRecord) Shape.getEscherChild(dgContainer, EscherContainerRecord.SPGR_CONTAINER);
spgr.addChildRecord(shape.getSpContainer());
shape.setSheet(this);
shape.setShapeId(allocateShapeId());
shape.afterInsert(this);
}
Add a new Shape to this Slide |
public int allocateShapeId() {
EscherDggRecord dgg = _slideShow.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
EscherDgRecord dg = _container.getPPDrawing().getEscherDgRecord();
dgg.setNumShapesSaved( dgg.getNumShapesSaved() + 1 );
// Add to existing cluster if space available
for (int i = 0; i < dgg.getFileIdClusters().length; i++)
{
EscherDggRecord.FileIdCluster c = dgg.getFileIdClusters()[i];
if (c.getDrawingGroupId() == dg.getDrawingGroupId() && c.getNumShapeIdsUsed() != 1024)
{
int result = c.getNumShapeIdsUsed() + (1024 * (i+1));
c.incrementShapeId();
dg.setNumShapes( dg.getNumShapes() + 1 );
dg.setLastMSOSPID( result );
if (result >= dgg.getShapeIdMax())
dgg.setShapeIdMax( result + 1 );
return result;
}
}
// Create new cluster
dgg.addCluster( dg.getDrawingGroupId(), 0, false );
dgg.getFileIdClusters()[dgg.getFileIdClusters().length-1].incrementShapeId();
dg.setNumShapes( dg.getNumShapes() + 1 );
int result = (1024 * dgg.getFileIdClusters().length);
dg.setLastMSOSPID( result );
if (result >= dgg.getShapeIdMax())
dgg.setShapeIdMax( result + 1 );
return result;
}
Allocates new shape id for the new drawing group id. |
public void draw(Graphics2D graphics) {
}
|
public static TextRun[] findTextRuns(PPDrawing ppdrawing) {
Vector runsV = new Vector();
EscherTextboxWrapper[] wrappers = ppdrawing.getTextboxWrappers();
for (int i = 0; i < wrappers.length; i++) {
int s1 = runsV.size();
findTextRuns(wrappers[i].getChildRecords(), runsV);
int s2 = runsV.size();
if (s2 != s1){
TextRun t = (TextRun) runsV.get(runsV.size()-1);
t.setShapeId(wrappers[i].getShapeId());
}
}
TextRun[] runs = new TextRun[runsV.size()];
for (int i = 0; i < runs.length; i++) {
runs[i] = (TextRun) runsV.get(i);
}
return runs;
}
For a given PPDrawing, grab all the TextRuns |
protected static void findTextRuns(Record[] records,
Vector found) {
// Look for a TextHeaderAtom
for (int i = 0, slwtIndex=0; i < (records.length - 1); i++) {
if (records[i] instanceof TextHeaderAtom) {
TextRun trun = null;
TextHeaderAtom tha = (TextHeaderAtom) records[i];
StyleTextPropAtom stpa = null;
// Look for a subsequent StyleTextPropAtom
if (i < (records.length - 2)) {
if (records[i + 2] instanceof StyleTextPropAtom) {
stpa = (StyleTextPropAtom) records[i + 2];
}
}
// See what follows the TextHeaderAtom
if (records[i + 1] instanceof TextCharsAtom) {
TextCharsAtom tca = (TextCharsAtom) records[i + 1];
trun = new TextRun(tha, tca, stpa);
} else if (records[i + 1] instanceof TextBytesAtom) {
TextBytesAtom tba = (TextBytesAtom) records[i + 1];
trun = new TextRun(tha, tba, stpa);
} else if (records[i + 1].getRecordType() == 4001l) {
// StyleTextPropAtom - Safe to ignore
} else if (records[i + 1].getRecordType() == 4010l) {
// TextSpecInfoAtom - Safe to ignore
} else {
System.err.println("Found a TextHeaderAtom not followed by a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 1].getRecordType());
}
if (trun != null) {
ArrayList lst = new ArrayList();
for (int j = i; j < records.length; j++) {
if(j > i && records[j] instanceof TextHeaderAtom) break;
lst.add(records[j]);
}
Record[] recs = new Record[lst.size()];
lst.toArray(recs);
trun._records = recs;
trun.setIndex(slwtIndex);
found.add(trun);
i++;
} else {
// Not a valid one, so skip on to next and look again
}
slwtIndex++;
}
}
}
Scans through the supplied record array, looking for
a TextHeaderAtom followed by one of a TextBytesAtom or
a TextCharsAtom. Builds up TextRuns from these |
public Background getBackground() {
if (_background == null) {
PPDrawing ppdrawing = getPPDrawing();
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
EscherContainerRecord spContainer = null;
List ch = dg.getChildRecords();
for (Iterator it = ch.iterator(); it.hasNext();) {
EscherRecord rec = (EscherRecord) it.next();
if (rec.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
spContainer = (EscherContainerRecord) rec;
break;
}
}
_background = new Background(spContainer, null);
_background.setSheet(this);
}
return _background;
}
Returns the background shape for this sheet. |
public ColorSchemeAtom getColorScheme() {
return _container.getColorScheme();
}
Color scheme for this sheet. |
abstract public MasterSheet getMasterSheet()
Return the master sheet . |
protected PPDrawing getPPDrawing() {
return _container.getPPDrawing();
}
Fetch the PPDrawing from the underlying record |
public Shape[] getShapes() {
PPDrawing ppdrawing = getPPDrawing();
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
EscherContainerRecord spgr = null;
List ch = dg.getChildRecords();
for (Iterator it = ch.iterator(); it.hasNext();) {
EscherRecord rec = (EscherRecord) it.next();
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
spgr = (EscherContainerRecord) rec;
break;
}
}
ch = spgr.getChildRecords();
ArrayList shapes = new ArrayList();
for (int i = 1; i < ch.size(); i++) {
EscherContainerRecord sp = (EscherContainerRecord) ch.get(i);
Shape sh = ShapeFactory.createShape(sp, null);
sh.setSheet(this);
shapes.add(sh);
}
return (Shape[]) shapes.toArray(new Shape[shapes.size()]);
}
Returns all shapes contained in this Sheet |
public SheetContainer getSheetContainer() {
return _container;
}
Return record container for this sheet |
public SlideShow getSlideShow() {
return _slideShow;
}
Fetch the SlideShow we're attached to |
abstract public TextRun[] getTextRuns()
Returns an array of all the TextRuns in the sheet. |
public void onCreate() {
}
Called by SlideShow ater a new sheet is created |
public boolean removeShape(Shape shape) {
PPDrawing ppdrawing = getPPDrawing();
EscherContainerRecord dg = (EscherContainerRecord) ppdrawing.getEscherRecords()[0];
EscherContainerRecord spgr = null;
for (Iterator it = dg.getChildRecords().iterator(); it.hasNext();) {
EscherRecord rec = (EscherRecord) it.next();
if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
spgr = (EscherContainerRecord) rec;
break;
}
}
if(spgr == null) return false;
List lst = spgr.getChildRecords();
return lst.remove(shape.getSpContainer());
}
Removes the specified shape from this sheet. |
public void setSlideShow(SlideShow ss) {
_slideShow = ss;
TextRun[] trs = getTextRuns();
if (trs != null) {
for (int i = 0; i < trs.length; i++) {
trs[i].supplySlideShow(_slideShow);
}
}
}
Set the SlideShow we're attached to.
Also passes it on to our child RichTextRuns |