From: Andreas Beeker
- * AutoShapes are drawing objects with a particular shape that may be customized through smart resizing and adjustments.
- * See {@link ShapeTypes}
- *
- * The adjustment values are given in shape coordinates:
- * the origin is at the top-left, positive-x is to the right, positive-y is down.
- * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
- *
- * The adjustment values are given in shape coordinates:
- * the origin is at the top-left, positive-x is to the right, positive-y is down.
- * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
- *
- * Shapes drawn with the "Freeform" tool have cubic bezier curve segments in the smooth sections
- * and straight-line segments in the straight sections. This object closely corresponds to
+ * AutoShapes are drawing objects with a particular shape that may be customized through smart resizing and adjustments.
+ * See {@link ShapeTypes}
+ *
+ * The adjustment values are given in shape coordinates:
+ * the origin is at the top-left, positive-x is to the right, positive-y is down.
+ * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+ *
+ * The adjustment values are given in shape coordinates:
+ * the origin is at the top-left, positive-x is to the right, positive-y is down.
+ * The region from (0,0) to (S,S) maps to the geometry box of the shape (S=21600 is a constant).
+ *
+ * Shapes drawn with the "Freeform" tool have cubic bezier curve segments in the smooth sections
+ * and straight-line segments in the straight sections. This object closely corresponds to
@@ -45,7 +43,7 @@ import java.awt.geom.Rectangle2D;
*
* @author Yegor Kozlov
*/
-public abstract class HSLFShape implements org.apache.poi.sl.usermodel.Shape
+ * For Slide we need to do the following:
+ *
+ * The title is a run of text of type
+ * Contains the text in a text frame as well as the properties and methods
+ * that control alignment and anchoring of the text.
+ * 0
means no line.
*/
public double getLineWidth() {
@@ -310,6 +310,54 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape {
return lineWidth;
}
+ /**
+ * @return the line compound
+ */
+ public LineCompound getLineCompound() {
+ PropertyFetchernull
if the
- * presentation doesn't contain pictures.
- */
- public PictureData[] getPictures() {
- if(_pictures == null) {
- try {
- readPictures();
- } catch(IOException e) {
- throw new CorruptPowerPointFileException(e.getMessage());
- }
- }
-
- return _pictures.toArray(new PictureData[_pictures.size()]);
- }
-
- /**
- * Gets embedded object data from the slide show.
- *
- * @return the embedded objects.
- */
- public ObjectData[] getEmbeddedObjects() {
- if (_objects == null) {
- ListPicture.WMF
*/
public int getType(){
- return Picture.WMF;
+ return HSLFPictureShape.WMF;
}
/**
@@ -188,4 +188,9 @@ public final class WMF extends Metafile {
}
}
+
+ public String getContentType() {
+ return "image/x-wmf";
+ }
+
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
index f46906f73c..e437f9504e 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPDrawingTextListing.java
@@ -18,6 +18,7 @@
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
@@ -33,7 +34,7 @@ public final class PPDrawingTextListing {
System.exit(1);
}
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find PPDrawings at any second level position
Record[] records = ss.getRecords();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java
index 490e3e2055..d0ab5ec98f 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTListing.java
@@ -17,7 +17,7 @@
package org.apache.poi.hslf.dev;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
@@ -35,7 +35,7 @@ public final class SLWTListing {
System.exit(1);
}
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTTextListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTTextListing.java
index 16858aa3db..fc9b224801 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTTextListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SLWTTextListing.java
@@ -18,6 +18,7 @@
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
/**
@@ -32,7 +33,7 @@ public final class SLWTTextListing {
System.exit(1);
}
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
index 2dd32a4af0..2a69c17d81 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideAndNotesAtomListing.java
@@ -18,6 +18,7 @@
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
@@ -34,7 +35,7 @@ public final class SlideAndNotesAtomListing {
System.exit(1);
}
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
System.out.println("");
// Find either Slides or Notes
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
index 010f424c33..b4f487ab8a 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideIdListing.java
@@ -20,7 +20,7 @@ package org.apache.poi.hslf.dev;
import java.io.ByteArrayOutputStream;
import java.util.Map;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.record.Notes;
import org.apache.poi.hslf.record.NotesAtom;
@@ -31,7 +31,7 @@ import org.apache.poi.hslf.record.Slide;
import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.hslf.record.SlidePersistAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.util.LittleEndian;
/**
@@ -50,8 +50,8 @@ public final class SlideIdListing {
// Create the slideshow object, for normal working with
- HSLFSlideShow hss = new HSLFSlideShow(args[0]);
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(args[0]);
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
// Grab the base contents
fileContents = hss.getUnderlyingBytes();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
index f2e7b36dc2..77415ff2dc 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowRecordDumper.java
@@ -19,10 +19,9 @@ package org.apache.poi.hslf.dev;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-
import java.util.Iterator;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.util.HexDump;
import org.apache.poi.ddf.DefaultEscherRecordFactory;
@@ -44,7 +43,7 @@ import org.apache.poi.hslf.record.StyleTextPropAtom;
public final class SlideShowRecordDumper {
private boolean optVerbose;
private boolean optEscher;
- private HSLFSlideShow doc;
+ private HSLFSlideShowImpl doc;
/**
* right now this function takes one parameter: a ppt file, and outputs
@@ -103,7 +102,7 @@ public final class SlideShowRecordDumper {
{
optVerbose = verbose;
optEscher = escher;
- doc = new HSLFSlideShow(fileName);
+ doc = new HSLFSlideShowImpl(fileName);
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
index a919f61cdd..d7fcbc6fd1 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java
@@ -18,6 +18,7 @@
package org.apache.poi.hslf.dev;
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
@@ -36,7 +37,7 @@ public final class TextStyleListing {
System.exit(1);
}
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
index 749cfa9484..c7c8057171 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/dev/UserEditAndPersistListing.java
@@ -20,7 +20,7 @@ package org.apache.poi.hslf.dev;
import java.io.ByteArrayOutputStream;
import java.util.Map;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.CurrentUserAtom;
import org.apache.poi.hslf.record.PersistPtrHolder;
import org.apache.poi.hslf.record.PositionDependentRecord;
@@ -44,7 +44,7 @@ public final class UserEditAndPersistListing {
// Create the slideshow object, for normal working with
- HSLFSlideShow ss = new HSLFSlideShow(args[0]);
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
fileContents = ss.getUnderlyingBytes();
System.out.println("");
diff --git a/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java b/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
index 24d6d9096e..268eb3b2fb 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/extractor/ImageExtractor.java
@@ -17,10 +17,10 @@
package org.apache.poi.hslf.extractor;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.model.Picture;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.model.HSLFPictureShape;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import java.io.IOException;
import java.io.FileOutputStream;
@@ -37,12 +37,12 @@ public final class ImageExtractor {
System.err.println("\tImageExtractor Fill
object for a shape.
- * Fill information will be read from shape's escher properties.
- *
- * @param shape the shape this background applies to
- */
- public Fill(HSLFShape shape){
- this.shape = shape;
- }
-
- /**
- * Returns fill type.
- * Must be one of the FILL_*
constants defined in this class.
- *
- * @return type of fill
- */
- public int getFillType(){
- EscherOptRecord opt = shape.getEscherOptRecord();
- EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE);
- return prop == null ? FILL_SOLID : prop.getPropertyValue();
- }
-
- /**
- */
- protected void afterInsert(Sheet sh){
- EscherOptRecord opt = shape.getEscherOptRecord();
- EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
- if(p != null) {
- int idx = p.getPropertyValue();
- EscherBSERecord bse = getEscherBSERecord(idx);
- bse.setRef(bse.getRef() + 1);
- }
- }
-
- protected EscherBSERecord getEscherBSERecord(int idx){
- Sheet sheet = shape.getSheet();
- if(sheet == null) {
- logger.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
- return null;
- }
- SlideShow ppt = sheet.getSlideShow();
- Document doc = ppt.getDocumentRecord();
- EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
- EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
- if(bstore == null) {
- logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
- return null;
- }
- ListFILL_*
constants defined in this class.
- *
- * @param type type of the fill
- */
- public void setFillType(int type){
- EscherOptRecord opt = shape.getEscherOptRecord();
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLTYPE, type);
- }
-
- /**
- * Foreground color
- */
- public Color getForegroundColor(){
- EscherOptRecord opt = shape.getEscherOptRecord();
- EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
-
- if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
-
- return shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
-
- }
-
- /**
- * Foreground color
- */
- public void setForegroundColor(Color color){
- EscherOptRecord opt = shape.getEscherOptRecord();
- if (color == null) {
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000);
- }
- else {
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150011);
- }
- }
-
- /**
- * Background color
- */
- public Color getBackgroundColor(){
- EscherOptRecord opt = shape.getEscherOptRecord();
- EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
-
- if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
-
- return shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
- }
-
- /**
- * Background color
- */
- public void setBackgroundColor(Color color){
- EscherOptRecord opt = shape.getEscherOptRecord();
- if (color == null) {
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1);
- }
- else {
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
- HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, rgb);
- }
- }
-
- /**
- * PictureData
object used in a texture, pattern of picture fill.
- */
- public PictureData getPictureData(){
- EscherOptRecord opt = shape.getEscherOptRecord();
- EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
- if (p == null) return null;
-
- SlideShow ppt = shape.getSheet().getSlideShow();
- PictureData[] pict = ppt.getPictureData();
- Document doc = ppt.getDocumentRecord();
-
- EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
- EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
-
- java.util.ListSlideShow.addPicture
method.
- */
- public void setPictureData(int idx){
- EscherOptRecord opt = shape.getEscherOptRecord();
- HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx);
- if( idx != 0 ) {
- if( shape.getSheet() != null ) {
- EscherBSERecord bse = getEscherBSERecord(idx);
- bse.setRef(bse.getRef() + 1);
- }
- }
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java b/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java
deleted file mode 100644
index 6bf232af46..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Freeform.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/* ====================================================================
- 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.model;
-
-import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.poi.ddf.EscherArrayProperty;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.sl.usermodel.ShapeType;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
-
-/**
- * A "Freeform" shape.
- *
- * java.awt.geom.GeneralPath
.
- * EscherSpContainer
container which holds information about this shape
- * @param parent the parent of the shape
- */
- protected Freeform(EscherContainerRecord escherRecord, ShapeContainerFill
object for a shape.
+ * Fill information will be read from shape's escher properties.
+ *
+ * @param shape the shape this background applies to
+ */
+ public HSLFFill(HSLFShape shape){
+ this.shape = shape;
+ }
+
+
+ public FillStyle getFillStyle() {
+ return new FillStyle() {
+ public PaintStyle getPaint() {
+ switch (getFillType()) {
+ case FILL_SOLID: {
+ return new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return new ColorStyle() {
+ public Color getColor() { return getForegroundColor(); }
+ public int getAlpha() { return -1; }
+ public int getLumOff() { return -1; }
+ public int getLumMod() { return -1; }
+ public int getShade() { return -1; }
+ public int getTint() { return -1; }
+ };
+ }
+ };
+ }
+ case FILL_PICTURE: {
+ return new TexturePaint() {
+ final HSLFPictureData pd = getPictureData();
+
+ public InputStream getImageData() {
+ return new ByteArrayInputStream(pd.getData());
+ }
+
+ public String getContentType() {
+ return pd.getContentType();
+ }
+
+ public int getAlpha() {
+ return (int)(shape.getAlpha(EscherProperties.FILL__FILLOPACITY)*100000.0);
+ }
+ };
+ }
+ default:
+ logger.log(POILogger.WARN, "unsuported fill type: " + getFillType());
+ break;
+ }
+ return PaintStyle.TRANSPARENT_PAINT;
+ }
+ };
+ }
+
+ /**
+ * Returns fill type.
+ * Must be one of the FILL_*
constants defined in this class.
+ *
+ * @return type of fill
+ */
+ public int getFillType(){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE);
+ return prop == null ? FILL_SOLID : prop.getPropertyValue();
+ }
+
+ /**
+ */
+ protected void afterInsert(HSLFSheet sh){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
+ if(p != null) {
+ int idx = p.getPropertyValue();
+ EscherBSERecord bse = getEscherBSERecord(idx);
+ bse.setRef(bse.getRef() + 1);
+ }
+ }
+
+ protected EscherBSERecord getEscherBSERecord(int idx){
+ HSLFSheet sheet = shape.getSheet();
+ if(sheet == null) {
+ logger.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
+ return null;
+ }
+ HSLFSlideShow ppt = sheet.getSlideShow();
+ Document doc = ppt.getDocumentRecord();
+ EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+ EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+ if(bstore == null) {
+ logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
+ return null;
+ }
+ ListFILL_*
constants defined in this class.
+ *
+ * @param type type of the fill
+ */
+ public void setFillType(int type){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLTYPE, type);
+ }
+
+ /**
+ * Foreground color
+ */
+ public Color getForegroundColor(){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
+
+ if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
+
+ return shape.getColor(EscherProperties.FILL__FILLCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
+
+ }
+
+ /**
+ * Foreground color
+ */
+ public void setForegroundColor(Color color){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ if (color == null) {
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000);
+ }
+ else {
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150011);
+ }
+ }
+
+ /**
+ * Background color
+ */
+ public Color getBackgroundColor(){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
+
+ if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
+
+ return shape.getColor(EscherProperties.FILL__FILLBACKCOLOR, EscherProperties.FILL__FILLOPACITY, -1);
+ }
+
+ /**
+ * Background color
+ */
+ public void setBackgroundColor(Color color){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ if (color == null) {
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1);
+ }
+ else {
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, rgb);
+ }
+ }
+
+ /**
+ * PictureData
object used in a texture, pattern of picture fill.
+ */
+ public HSLFPictureData getPictureData(){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
+ if (p == null) return null;
+
+ HSLFSlideShow ppt = shape.getSheet().getSlideShow();
+ HSLFPictureData[] pict = ppt.getPictureData();
+ Document doc = ppt.getDocumentRecord();
+
+ EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+ EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+
+ java.util.ListSlideShow.addPicture
method.
+ */
+ public void setPictureData(int idx){
+ EscherOptRecord opt = shape.getEscherOptRecord();
+ HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), idx);
+ if( idx != 0 ) {
+ if( shape.getSheet() != null ) {
+ EscherBSERecord bse = getEscherBSERecord(idx);
+ bse.setRef(bse.getRef() + 1);
+ }
+ }
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFFreeformShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFFreeformShape.java
new file mode 100644
index 0000000000..685e2dad2f
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFFreeformShape.java
@@ -0,0 +1,264 @@
+/* ====================================================================
+ 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.model;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.poi.ddf.EscherArrayProperty;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A "Freeform" shape.
+ *
+ * java.awt.geom.GeneralPath
.
+ * EscherSpContainer
container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainernull
- Notes Masters are not yet supported
+ */
+ public HSLFMasterSheet getMasterSheet() {
+ return null;
+ }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java
new file mode 100644
index 0000000000..e6b72a60fb
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFPictureShape.java
@@ -0,0 +1,302 @@
+/* ====================================================================
+ 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.model;
+
+import java.awt.Graphics2D;
+import java.awt.Insets;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
+
+import javax.imageio.ImageIO;
+
+import org.apache.poi.ddf.EscherBSERecord;
+import org.apache.poi.ddf.EscherComplexProperty;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.hslf.blip.Bitmap;
+import org.apache.poi.hslf.record.Document;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
+import org.apache.poi.util.Units;
+
+
+/**
+ * Represents a picture in a PowerPoint document.
+ *
+ * @author Yegor Kozlov
+ */
+public class HSLFPictureShape extends HSLFSimpleShape {
+
+ /**
+ * Windows Enhanced Metafile (EMF)
+ */
+ public static final int EMF = 2;
+
+ /**
+ * Windows Metafile (WMF)
+ */
+ public static final int WMF = 3;
+
+ /**
+ * Macintosh PICT
+ */
+ public static final int PICT = 4;
+
+ /**
+ * JPEG
+ */
+ public static final int JPEG = 5;
+
+ /**
+ * PNG
+ */
+ public static final int PNG = 6;
+
+ /**
+ * Windows DIB (BMP)
+ */
+ public static final byte DIB = 7;
+
+ /**
+ * Create a new Picture
+ *
+ * @param idx the index of the picture
+ */
+ public HSLFPictureShape(int idx){
+ this(idx, null);
+ }
+
+ /**
+ * Create a new Picture
+ *
+ * @param idx the index of the picture
+ * @param parent the parent shape
+ */
+ public HSLFPictureShape(int idx, ShapeContainerPicture
object
+ *
+ * @param escherRecord the EscherSpContainer
record which holds information about
+ * this picture in the Slide
+ * @param parent the parent shape of this picture
+ */
+ protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainerEscherSp
record which holds information about this picture.
+
+ * @param idx the index of the picture which refers to EscherBSE
container.
+ * @return the create Picture object
+ */
+ protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
+ _escherContainer = super.createSpContainer(isChild);
+ _escherContainer.setOptions((short)15);
+
+ EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+ spRecord.setOptions((short)((ShapeType.FRAME.nativeId << 4) | 0x2));
+
+ //set default properties for a picture
+ EscherOptRecord opt = getEscherOptRecord();
+ setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
+
+ //another weird feature of powerpoint: for picture id we must add 0x4000.
+ setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
+
+ return _escherContainer;
+ }
+
+ /**
+ * Resize this picture to the default size.
+ * For PNG and JPEG resizes the image to 100%,
+ * for other types sets the default size of 200x200 pixels.
+ */
+ public void setDefaultSize(){
+ HSLFPictureData pict = getPictureData();
+ if (pict instanceof Bitmap){
+ BufferedImage img = null;
+ try {
+ img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
+ }
+ catch (IOException e){}
+ catch (NegativeArraySizeException ne) {}
+
+ if(img != null) {
+ // Valid image, set anchor from it
+ setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*POINT_DPI/PIXEL_DPI, img.getHeight()*POINT_DPI/PIXEL_DPI));
+ } else {
+ // Invalid image, go with the default metafile size
+ setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
+ }
+ } else {
+ //default size of a metafile picture is 200x200
+ setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
+ }
+ }
+
+ /**
+ * Returns the picture data for this picture.
+ *
+ * @return the picture data for this picture.
+ */
+ public HSLFPictureData getPictureData(){
+ HSLFSlideShow ppt = getSheet().getSlideShow();
+ HSLFPictureData[] pict = ppt.getPictureData();
+
+ EscherBSERecord bse = getEscherBSERecord();
+ if (bse == null){
+ logger.log(POILogger.ERROR, "no reference to picture data found ");
+ } else {
+ for ( int i = 0; i < pict.length; i++ ) {
+ if (pict[i].getOffset() == bse.getOffset()){
+ return pict[i];
+ }
+ }
+ logger.log(POILogger.ERROR, "no picture found for our BSE offset " + bse.getOffset());
+ }
+ return null;
+ }
+
+ protected EscherBSERecord getEscherBSERecord(){
+ HSLFSlideShow ppt = getSheet().getSlideShow();
+ Document doc = ppt.getDocumentRecord();
+ EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+ EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+ if(bstore == null) {
+ logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
+ return null;
+ }
+ ListSlideShow
we belong to
+ */
+ private HSLFSlideShow _slideShow;
+
+ /**
+ * Sheet background
+ */
+ private HSLFBackground _background;
+
+ /**
+ * Record container that holds sheet data.
+ * For slides it is org.apache.poi.hslf.record.Slide,
+ * for notes it is org.apache.poi.hslf.record.Notes,
+ * for slide masters it is org.apache.poi.hslf.record.SlideMaster, etc.
+ */
+ private SheetContainer _container;
+
+ private int _sheetNo;
+
+ public HSLFSheet(SheetContainer container, int sheetNo) {
+ _container = container;
+ _sheetNo = sheetNo;
+ }
+
+ /**
+ * Returns an array of all the TextRuns in the sheet.
+ */
+ public abstract HSLFTextParagraph[] getTextRuns();
+
+ /**
+ * Returns the (internal, RefID based) sheet number, as used
+ * to in PersistPtr stuff.
+ */
+ public int _getSheetRefId() {
+ return _container.getSheetId();
+ }
+
+ /**
+ * Returns the (internal, SlideIdentifier based) sheet number, as used
+ * to reference this sheet from other records.
+ */
+ public int _getSheetNumber() {
+ return _sheetNo;
+ }
+
+ /**
+ * Fetch the PPDrawing from the underlying record
+ */
+ protected PPDrawing getPPDrawing() {
+ return _container.getPPDrawing();
+ }
+
+ /**
+ * Fetch the SlideShow we're attached to
+ */
+ public HSLFSlideShow getSlideShow() {
+ return _slideShow;
+ }
+
+ /**
+ * Return record container for this sheet
+ */
+ public SheetContainer getSheetContainer() {
+ return _container;
+ }
+
+ /**
+ * Set the SlideShow we're attached to.
+ * Also passes it on to our child RichTextRuns
+ */
+ public void setSlideShow(HSLFSlideShow ss) {
+ _slideShow = ss;
+ HSLFTextParagraph[] trs = getTextRuns();
+ if (trs == null) return;
+ for (HSLFTextParagraph tp : trs) {
+ tp.supplySheet(this);
+ }
+ }
+
+
+ /**
+ * For a given PPDrawing, grab all the TextRuns
+ */
+ public static HSLFTextParagraph[] findTextRuns(PPDrawing ppdrawing) {
+ final ListTextShape
or null
+ */
+ public HSLFTextShape getPlaceholderByTextType(int type){
+ HSLFShape[] shape = getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if(shape[i] instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
+ HSLFTextParagraph run = tx.getTextParagraph();
+ if(run != null && run.getRunType() == type){
+ return tx;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Search text placeholer by its type
+ *
+ * @param type type of placeholder to search. See {@link org.apache.poi.hslf.record.OEPlaceholderAtom}
+ * @return TextShape
or null
+ */
+ public HSLFTextShape getPlaceholder(int type){
+ HSLFShape[] shape = getShapes();
+ for (int i = 0; i < shape.length; i++) {
+ if(shape[i] instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
+ int placeholderId = 0;
+ OEPlaceholderAtom oep = tx.getPlaceholderAtom();
+ if(oep != null) {
+ placeholderId = oep.getPlaceholderId();
+ } else {
+ //special case for files saved in Office 2007
+ RoundTripHFPlaceholder12 hldr = tx.getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
+ if(hldr != null) placeholderId = hldr.getPlaceholderId();
+ }
+ if(placeholderId == type){
+ return tx;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return programmable tag associated with this sheet, e.g. ___PPT12
.
+ *
+ * @return programmable tag associated with this sheet.
+ */
+ public String getProgrammableTag(){
+ String tag = null;
+ RecordContainer progTags = (RecordContainer)
+ getSheetContainer().findFirstOfType(
+ RecordTypes.ProgTags.typeID
+ );
+ if(progTags != null) {
+ RecordContainer progBinaryTag = (RecordContainer)
+ progTags.findFirstOfType(
+ RecordTypes.ProgBinaryTag.typeID
+ );
+ if(progBinaryTag != null) {
+ CString binaryTag = (CString)
+ progBinaryTag.findFirstOfType(
+ RecordTypes.CString.typeID
+ );
+ if(binaryTag != null) tag = binaryTag.getText();
+ }
+ }
+
+ return tag;
+
+ }
+
+ public IteratorEscherSpContainer
container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainertrue
if the Line is inside a group, false
otherwise
+ * @return the record container which holds this shape
+ */
+ protected EscherContainerRecord createSpContainer(boolean isChild) {
+ _escherContainer = new EscherContainerRecord();
+ _escherContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
+ _escherContainer.setOptions((short)15);
+
+ EscherSpRecord sp = new EscherSpRecord();
+ int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
+ if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
+ sp.setFlags(flags);
+ _escherContainer.addChildRecord(sp);
+
+ EscherOptRecord opt = new EscherOptRecord();
+ opt.setRecordId(EscherOptRecord.RECORD_ID);
+ _escherContainer.addChildRecord(opt);
+
+ EscherRecord anchor;
+ if(isChild) anchor = new EscherChildAnchorRecord();
+ else {
+ anchor = new EscherClientAnchorRecord();
+
+ //hack. internal variable EscherClientAnchorRecord.shortRecord can be
+ //initialized only in fillFields(). We need to set shortRecord=false;
+ byte[] header = new byte[16];
+ LittleEndian.putUShort(header, 0, 0);
+ LittleEndian.putUShort(header, 2, 0);
+ LittleEndian.putInt(header, 4, 8);
+ anchor.fillFields(header, 0, null);
+ }
+ _escherContainer.addChildRecord(anchor);
+
+ return _escherContainer;
+ }
+
+ /**
+ * Returns width of the line in in points
+ */
+ public double getLineWidth(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
+ double width = (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
+ return width;
+ }
+
+ /**
+ * Sets the width of line in in points
+ * @param width the width of line in in points
+ */
+ public void setLineWidth(double width){
+ EscherOptRecord opt = getEscherOptRecord();
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
+ }
+
+ /**
+ * Sets the color of line
+ *
+ * @param color new color of the line
+ */
+ public void setLineColor(Color color){
+ EscherOptRecord opt = getEscherOptRecord();
+ if (color == null) {
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
+ } else {
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
+ setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, color == null ? 0x180010 : 0x180018);
+ }
+ }
+
+ /**
+ * @return color of the line. If color is not set returns java.awt.Color.black
+ */
+ public Color getLineColor(){
+ EscherOptRecord opt = getEscherOptRecord();
+
+ EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
+ if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
+
+ Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1);
+ return clr == null ? Color.black : clr;
+ }
+
+ /**
+ * Gets line dashing.
+ *
+ * @return dashing of the line.
+ */
+ public LineDash getLineDashing(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
+ return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
+ }
+
+ /**
+ * Sets line dashing.
+ *
+ * @param pen new style of the line.
+ */
+ public void setLineDashing(LineDash pen){
+ EscherOptRecord opt = getEscherOptRecord();
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
+ }
+
+ /**
+ * Gets the line compound style
+ *
+ * @return the compound style of the line.
+ */
+ public LineCompound getLineCompound() {
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
+ return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
+ }
+
+ /**
+ * Sets the line compound style
+ *
+ * @param style new compound style of the line.
+ */
+ public void setLineCompound(LineCompound style){
+ EscherOptRecord opt = getEscherOptRecord();
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
+ }
+
+ /**
+ * Returns line style. One of the constants defined in this class.
+ *
+ * @return style of the line.
+ */
+ public StrokeStyle getStrokeStyle(){
+ return new StrokeStyle() {
+ public PaintStyle getPaint() {
+ return null;
+ }
+
+ public LineCap getLineCap() {
+ return null;
+ }
+
+ public LineDash getLineDash() {
+ return null;
+ }
+
+ public LineCompound getLineCompound() {
+ return null;
+ }
+
+ public double getLineWidth() {
+ return 0;
+ }
+
+ };
+ }
+
+ /**
+ * The color used to fill this shape.
+ */
+ public Color getFillColor(){
+ return getFill().getForegroundColor();
+ }
+
+ /**
+ * The color used to fill this shape.
+ *
+ * @param color the background color
+ */
+ public void setFillColor(Color color){
+ getFill().setForegroundColor(color);
+ }
+
+ /**
+ *
+ * @return 'absolute' anchor of this shape relative to the parent sheet
+ */
+ public Rectangle2D getLogicalAnchor2D(){
+ Rectangle2D anchor = getAnchor2D();
+
+ //if it is a groupped shape see if we need to transform the coordinates
+ if (getParent() != null){
+ ArrayListnull
+ */
+ protected Record[] getClientRecords() {
+ if(_clientData == null){
+ EscherRecord r = getEscherChild(EscherClientDataRecord.RECORD_ID);
+ //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID
+ //convert in to EscherClientDataRecord on the fly
+ if(r != null && !(r instanceof EscherClientDataRecord)){
+ byte[] data = r.serialize();
+ r = new EscherClientDataRecord();
+ r.fillFields(data, 0, new DefaultEscherRecordFactory());
+ }
+ _clientData = (EscherClientDataRecord)r;
+ }
+ if(_clientData != null && _clientRecords == null){
+ byte[] data = _clientData.getRemainingData();
+ _clientRecords = Record.findChildRecords(data, 0, data.length);
+ }
+ return _clientRecords;
+ }
+
+ protected void updateClientData() {
+ if(_clientData != null && _clientRecords != null){
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ for (int i = 0; i < _clientRecords.length; i++) {
+ _clientRecords[i].writeOut(out);
+ }
+ } catch(Exception e){
+ throw new HSLFException(e);
+ }
+ _clientData.setRemainingData(out.toByteArray());
+ }
+ }
+
+ public void setHyperlink(Hyperlink link){
+ if(link.getId() == -1){
+ throw new HSLFException("You must call SlideShow.addHyperlink(Hyperlink link) first");
+ }
+
+ EscherClientDataRecord cldata = new EscherClientDataRecord();
+ cldata.setOptions((short)0xF);
+ getSpContainer().addChildRecord(cldata); // TODO - junit to prove getChildRecords().add is wrong
+
+ InteractiveInfo info = new InteractiveInfo();
+ InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
+
+ switch(link.getType()){
+ case Hyperlink.LINK_FIRSTSLIDE:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_FIRSTSLIDE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_FirstSlide);
+ break;
+ case Hyperlink.LINK_LASTSLIDE:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_LASTSLIDE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_LastSlide);
+ break;
+ case Hyperlink.LINK_NEXTSLIDE:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_NEXTSLIDE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NextSlide);
+ break;
+ case Hyperlink.LINK_PREVIOUSSLIDE:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_PREVIOUSSLIDE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_PreviousSlide);
+ break;
+ case Hyperlink.LINK_URL:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
+ break;
+ case Hyperlink.LINK_SLIDENUMBER:
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+ infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_SlideNumber);
+ break;
+ }
+
+ infoAtom.setHyperlinkID(link.getId());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ info.writeOut(out);
+ } catch(Exception e){
+ throw new HSLFException(e);
+ }
+ cldata.setRemainingData(out.toByteArray());
+
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java
new file mode 100644
index 0000000000..7030ce73e1
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFSlide.java
@@ -0,0 +1,515 @@
+/* ====================================================================
+ 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.model;
+
+import java.awt.Graphics2D;
+import java.util.LinkedList;
+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.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.hslf.usermodel.HSLFSlideShow;
+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 SlideTextBox
object that represents the slide's title.
+ *
+ * @return TextBox
object that represents the slide's title.
+ */
+ public HSLFTextBox addTitle() {
+ Placeholder pl = new Placeholder();
+ pl.setShapeType(ShapeType.RECT);
+ pl.getTextParagraph().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
+
+ /**
+ * Return title of this slide or null
if the slide does not have title.
+ * 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(){
+ SlideMaster[] master = getSlideShow().getSlidesMasters();
+ SlideAtom sa = getSlideRecord().getSlideAtom();
+ int masterId = sa.getMasterID();
+ HSLFMasterSheet sheet = null;
+ for (int i = 0; i < master.length; i++) {
+ if (masterId == master[i]._getSheetNumber()) {
+ sheet = master[i];
+ break;
+ }
+ }
+ if (sheet == null){
+ TitleMaster[] titleMaster = getSlideShow().getTitleMasters();
+ if(titleMaster != null) for (int i = 0; i < titleMaster.length; i++) {
+ if (masterId == titleMaster[i]._getSheetNumber()) {
+ sheet = titleMaster[i];
+ break;
+ }
+ }
+ }
+ return sheet;
+ }
+
+ /**
+ * 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; inull
if the
+ * presentation doesn't contain pictures.
+ */
+ public HSLFPictureData[] getPictures() {
+ if(_pictures == null) {
+ try {
+ readPictures();
+ } catch(IOException e) {
+ throw new CorruptPowerPointFileException(e.getMessage());
+ }
+ }
+
+ return _pictures.toArray(new HSLFPictureData[_pictures.size()]);
+ }
+
+ /**
+ * Gets embedded object data from the slide show.
+ *
+ * @return the embedded objects.
+ */
+ public HSLFObjectData[] getEmbeddedObjects() {
+ if (_objects == null) {
+ ListEscherSpContainer
container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainerEscherContainerRecord
which holds shape data
+ */
+ protected EscherContainerRecord createSpContainer(boolean isChild){
+ _escherContainer = super.createSpContainer(isChild);
+
+ setShapeType(ShapeType.TEXT_BOX);
+
+ //set default properties for a TextBox
+ setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
+ setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
+ setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100000);
+ setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
+ setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
+ setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
+
+ _txtrun = createTextRun();
+
+ return _escherContainer;
+ }
+
+ protected void setDefaultTextProperties(HSLFTextParagraph _txtrun){
+ setVerticalAlignment(HSLFTextBox.AnchorTop);
+ setEscherProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20002);
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java
new file mode 100644
index 0000000000..b23c997dbe
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextParagraph.java
@@ -0,0 +1,744 @@
+/* ====================================================================
+ 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.model;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.PPDrawing;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordContainer;
+import org.apache.poi.hslf.record.SlideListWithText;
+import org.apache.poi.hslf.record.StyleTextProp9Atom;
+import org.apache.poi.hslf.record.StyleTextPropAtom;
+import org.apache.poi.hslf.record.TextBytesAtom;
+import org.apache.poi.hslf.record.TextCharsAtom;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.record.TextRulerAtom;
+import org.apache.poi.hslf.record.TextSpecInfoAtom;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.util.StringUtil;
+
+/**
+ * This class represents a run of text in a powerpoint document. That
+ * run could be text on a sheet, or text in a note.
+ * It is only a very basic class for now
+ *
+ * @author Nick Burch
+ */
+
+public final class HSLFTextParagraph implements TextParagraphnull
if not found.
+ */
+ public Hyperlink[] getHyperlinks(){
+ return Hyperlink.find(this);
+ }
+
+ /**
+ * Fetch RichTextRun at a given position
+ *
+ * @param pos 0-based index in the text
+ * @return RichTextRun or null if not found
+ */
+ public HSLFTextRun getRichTextRunAt(int pos){
+ for (int i = 0; i < _rtRuns.length; i++) {
+ int start = _rtRuns[i].getStartIndex();
+ int end = _rtRuns[i].getEndIndex();
+ if(pos >= start && pos < end) return _rtRuns[i];
+ }
+ return null;
+ }
+
+ public TextRulerAtom getTextRuler(){
+ if(_ruler == null){
+ if(_records != null) for (int i = 0; i < _records.length; i++) {
+ if(_records[i] instanceof TextRulerAtom) {
+ _ruler = (TextRulerAtom)_records[i];
+ break;
+ }
+ }
+
+ }
+ return _ruler;
+
+ }
+
+ public TextRulerAtom createTextRuler(){
+ _ruler = getTextRuler();
+ if(_ruler == null){
+ _ruler = TextRulerAtom.getParagraphInstance();
+ _headerAtom.getParentRecord().appendChildRecord(_ruler);
+ }
+ return _ruler;
+ }
+
+ /**
+ * Returns a new string with line breaks converted into internal ppt representation
+ */
+ public String normalize(String s){
+ String ns = s.replaceAll("\\r?\\n", "\r");
+ return ns;
+ }
+
+ /**
+ * Returns records that make up this text run
+ *
+ * @return text run records
+ */
+ public Record[] getRecords(){
+ return _records;
+ }
+ /** Numbered List info */
+ public void setStyleTextProp9Atom(final StyleTextProp9Atom styleTextProp9Atom) {
+ this.styleTextProp9Atom = styleTextProp9Atom;
+ }
+ /** Numbered List info */
+ public StyleTextProp9Atom getStyleTextProp9Atom() {
+ return this.styleTextProp9Atom;
+ }
+
+ /** Characters covered */
+ public StyleTextPropAtom getStyleTextPropAtom() {
+ return this._styleAtom;
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java
new file mode 100644
index 0000000000..17e8b81d21
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HSLFTextShape.java
@@ -0,0 +1,639 @@
+/* ====================================================================
+ 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.model;
+
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.ddf.EscherTextboxRecord;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.record.EscherTextboxWrapper;
+import org.apache.poi.hslf.record.InteractiveInfo;
+import org.apache.poi.hslf.record.InteractiveInfoAtom;
+import org.apache.poi.hslf.record.OEPlaceholderAtom;
+import org.apache.poi.hslf.record.OutlineTextRefAtom;
+import org.apache.poi.hslf.record.PPDrawing;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordTypes;
+import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
+import org.apache.poi.hslf.record.StyleTextPropAtom;
+import org.apache.poi.hslf.record.TextBytesAtom;
+import org.apache.poi.hslf.record.TextCharsAtom;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A common superclass of all shapes that can hold text.
+ *
+ * @author Yegor Kozlov
+ */
+public abstract class HSLFTextShape extends HSLFSimpleShape {
+
+ /**
+ * How to anchor the text
+ */
+ public static final int AnchorTop = 0;
+ public static final int AnchorMiddle = 1;
+ public static final int AnchorBottom = 2;
+ public static final int AnchorTopCentered = 3;
+ public static final int AnchorMiddleCentered = 4;
+ public static final int AnchorBottomCentered = 5;
+ public static final int AnchorTopBaseline = 6;
+ public static final int AnchorBottomBaseline = 7;
+ public static final int AnchorTopCenteredBaseline = 8;
+ public static final int AnchorBottomCenteredBaseline = 9;
+
+ /**
+ * How to wrap the text
+ */
+ public static final int WrapSquare = 0;
+ public static final int WrapByPoints = 1;
+ public static final int WrapNone = 2;
+ public static final int WrapTopBottom = 3;
+ public static final int WrapThrough = 4;
+
+ /**
+ * How to align the text
+ */
+ public static final int AlignLeft = 0;
+ public static final int AlignCenter = 1;
+ public static final int AlignRight = 2;
+ public static final int AlignJustify = 3;
+
+ /**
+ * TextRun object which holds actual text and format data
+ */
+ protected HSLFTextParagraph _txtrun;
+
+ /**
+ * Escher container which holds text attributes such as
+ * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.
+ */
+ protected EscherTextboxWrapper _txtbox;
+
+ /**
+ * Used to calculate text bounds
+ */
+ protected static final FontRenderContext _frc = new FontRenderContext(null, true, true);
+
+ /**
+ * Create a TextBox object and initialize it from the supplied Record container.
+ *
+ * @param escherRecord EscherSpContainer
container which holds information about this shape
+ * @param parent the parent of the shape
+ */
+ protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainerPPDrawing
about it.
+ *
+ * @param sh the sheet we are adding to
+ */
+ protected void afterInsert(HSLFSheet sh){
+ super.afterInsert(sh);
+
+ EscherTextboxWrapper _txtbox = getEscherTextboxWrapper();
+ if(_txtbox != null){
+ PPDrawing ppdrawing = sh.getPPDrawing();
+ ppdrawing.addTextboxWrapper(_txtbox);
+ // Ensure the escher layer knows about the added records
+ try {
+ _txtbox.writeOut(null);
+ } catch (IOException e){
+ throw new HSLFException(e);
+ }
+ if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
+ }
+ if(_txtrun != null) {
+ _txtrun.setShapeId(getShapeId());
+ sh.onAddTextShape(this);
+ }
+ }
+
+ protected EscherTextboxWrapper getEscherTextboxWrapper(){
+ if(_txtbox == null){
+ EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID);
+ if(textRecord != null) _txtbox = new EscherTextboxWrapper(textRecord);
+ }
+ return _txtbox;
+ }
+ /**
+ * Adjust the size of the TextShape so it encompasses the text inside it.
+ *
+ * @return a Rectangle2D
that is the bounds of this TextShape
.
+ */
+ public Rectangle2D resizeToFitText(){
+ String txt = getText();
+ if(txt == null || txt.length() == 0) return new Rectangle2D.Float();
+
+ HSLFTextRun rt = getTextParagraph().getRichTextRuns()[0];
+ int size = rt.getFontSize();
+ int style = 0;
+ if (rt.isBold()) style |= Font.BOLD;
+ if (rt.isItalic()) style |= Font.ITALIC;
+ String fntname = rt.getFontName();
+ Font font = new Font(fntname, style, size);
+
+ float width = 0, height = 0, leading = 0;
+ String[] lines = txt.split("\n");
+ for (int i = 0; i < lines.length; i++) {
+ if(lines[i].length() == 0) continue;
+
+ TextLayout layout = new TextLayout(lines[i], font, _frc);
+
+ leading = Math.max(leading, layout.getLeading());
+ width = Math.max(width, layout.getAdvance());
+ height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
+ }
+
+ // add one character to width
+ Rectangle2D charBounds = font.getMaxCharBounds(_frc);
+ width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
+
+ // add leading to height
+ height += getMarginTop() + getMarginBottom() + leading;
+
+ Rectangle2D anchor = getAnchor2D();
+ anchor.setRect(anchor.getX(), anchor.getY(), width, height);
+ setAnchor(anchor);
+
+ return anchor;
+ }
+
+ /**
+ * Returns the type of vertical alignment for the text.
+ * One of the Anchor*
constants defined in this class.
+ *
+ * @return the type of alignment
+ */
+ public int getVerticalAlignment(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
+ int valign = HSLFTextShape.AnchorTop;
+ if (prop == null){
+ /**
+ * If vertical alignment was not found in the shape properties then try to
+ * fetch the master shape and search for the align property there.
+ */
+ int type = getTextParagraph().getRunType();
+ HSLFMasterSheet master = getSheet().getMasterSheet();
+ if(master != null){
+ HSLFTextShape masterShape = master.getPlaceholderByTextType(type);
+ if(masterShape != null) valign = masterShape.getVerticalAlignment();
+ } else {
+ //not found in the master sheet. Use the hardcoded defaults.
+ switch (type){
+ case TextHeaderAtom.TITLE_TYPE:
+ case TextHeaderAtom.CENTER_TITLE_TYPE:
+ valign = HSLFTextShape.AnchorMiddle;
+ break;
+ default:
+ valign = HSLFTextShape.AnchorTop;
+ break;
+ }
+ }
+ } else {
+ valign = prop.getPropertyValue();
+ }
+ return valign;
+ }
+
+ /**
+ * Sets the type of vertical alignment for the text.
+ * One of the Anchor*
constants defined in this class.
+ *
+ * @param align - the type of alignment
+ */
+ public void setVerticalAlignment(int align){
+ setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align);
+ }
+
+ /**
+ * Sets the type of horizontal alignment for the text.
+ * One of the Align*
constants defined in this class.
+ *
+ * @param align - the type of horizontal alignment
+ */
+ public void setHorizontalAlignment(int align){
+ HSLFTextParagraph tx = getTextParagraph();
+ if(tx != null) tx.getRichTextRuns()[0].setAlignment(align);
+ }
+
+ /**
+ * Gets the type of horizontal alignment for the text.
+ * One of the Align*
constants defined in this class.
+ *
+ * @return align - the type of horizontal alignment
+ */
+ public int getHorizontalAlignment(){
+ HSLFTextParagraph tx = getTextParagraph();
+ return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment();
+ }
+
+ /**
+ * Returns the distance (in points) between the bottom of the text frame
+ * and the bottom of the inscribed rectangle of the shape that contains the text.
+ * Default value is 1/20 inch.
+ *
+ * @return the botom margin
+ */
+ public float getMarginBottom(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
+ int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
+ return (float)val/EMU_PER_POINT;
+ }
+
+ /**
+ * Sets the botom margin.
+ * @see #getMarginBottom()
+ *
+ * @param margin the bottom margin
+ */
+ public void setMarginBottom(float margin){
+ setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));
+ }
+
+ /**
+ * Returns the distance (in points) between the left edge of the text frame
+ * and the left edge of the inscribed rectangle of the shape that contains
+ * the text.
+ * Default value is 1/10 inch.
+ *
+ * @return the left margin
+ */
+ public float getMarginLeft(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
+ int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
+ return (float)val/EMU_PER_POINT;
+ }
+
+ /**
+ * Sets the left margin.
+ * @see #getMarginLeft()
+ *
+ * @param margin the left margin
+ */
+ public void setMarginLeft(float margin){
+ setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));
+ }
+
+ /**
+ * Returns the distance (in points) between the right edge of the
+ * text frame and the right edge of the inscribed rectangle of the shape
+ * that contains the text.
+ * Default value is 1/10 inch.
+ *
+ * @return the right margin
+ */
+ public float getMarginRight(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
+ int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
+ return (float)val/EMU_PER_POINT;
+ }
+
+ /**
+ * Sets the right margin.
+ * @see #getMarginRight()
+ *
+ * @param margin the right margin
+ */
+ public void setMarginRight(float margin){
+ setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));
+ }
+
+ /**
+ * Returns the distance (in points) between the top of the text frame
+ * and the top of the inscribed rectangle of the shape that contains the text.
+ * Default value is 1/20 inch.
+ *
+ * @return the top margin
+ */
+ public float getMarginTop(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
+ int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
+ return (float)val/EMU_PER_POINT;
+ }
+
+ /**
+ * Sets the top margin.
+ * @see #getMarginTop()
+ *
+ * @param margin the top margin
+ */
+ public void setMarginTop(float margin){
+ setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));
+ }
+
+
+ /**
+ * Returns the value indicating word wrap.
+ *
+ * @return the value indicating word wrap.
+ * Must be one of the Wrap*
constants defined in this class.
+ */
+ public int getWordWrap(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
+ return prop == null ? WrapSquare : prop.getPropertyValue();
+ }
+
+ /**
+ * Specifies how the text should be wrapped
+ *
+ * @param wrap the value indicating how the text should be wrapped.
+ * Must be one of the Wrap*
constants defined in this class.
+ */
+ public void setWordWrap(int wrap){
+ setEscherProperty(EscherProperties.TEXT__WRAPTEXT, wrap);
+ }
+
+ /**
+ * @return id for the text.
+ */
+ public int getTextId(){
+ EscherOptRecord opt = getEscherOptRecord();
+ EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
+ return prop == null ? 0 : prop.getPropertyValue();
+ }
+
+ /**
+ * Sets text ID
+ *
+ * @param id of the text
+ */
+ public void setTextId(int id){
+ setEscherProperty(EscherProperties.TEXT__TEXTID, id);
+ }
+
+ /**
+ * @return the TextRun object for this text box
+ */
+ public HSLFTextParagraph getTextParagraph(){
+ if (null == this._txtrun) initTextRun();
+ if (null == this._txtrun && null != this._txtbox) {
+ TextHeaderAtom tha = null;
+ TextBytesAtom tba = null;
+ TextCharsAtom tca = null;
+ StyleTextPropAtom sta = null;
+ Record[] childRecords = this._txtbox.getChildRecords();
+ for (Record r : childRecords) {
+ if (r instanceof TextHeaderAtom) {
+ tha = (TextHeaderAtom) r;
+ } else if (r instanceof TextBytesAtom) {
+ tba = (TextBytesAtom) r;
+ } else if (r instanceof TextCharsAtom) {
+ tca = (TextCharsAtom) r;
+ } else if (r instanceof StyleTextPropAtom) {
+ sta = (StyleTextPropAtom) r;
+ }
+ }
+ if (tba != null) {
+ this._txtrun = new HSLFTextParagraph(tha, tba, sta);
+ } else if (tca != null) {
+ this._txtrun = new HSLFTextParagraph(tha, tca, sta);
+ }
+ }
+ return _txtrun;
+ }
+
+ public void setSheet(HSLFSheet sheet) {
+ _sheet = sheet;
+
+ // Initialize _txtrun object.
+ // (We can't do it in the constructor because the sheet
+ // is not assigned then, it's only built once we have
+ // all the records)
+ HSLFTextParagraph tx = getTextParagraph();
+ if (tx != null) {
+ // Supply the sheet to our child RichTextRuns
+ tx.supplySheet(_sheet);
+ }
+ }
+
+ protected void initTextRun(){
+ EscherTextboxWrapper txtbox = getEscherTextboxWrapper();
+ HSLFSheet sheet = getSheet();
+
+ if(sheet == null || txtbox == null) return;
+
+ OutlineTextRefAtom ota = null;
+
+ Record[] child = txtbox.getChildRecords();
+ for (int i = 0; i < child.length; i++) {
+ if (child[i] instanceof OutlineTextRefAtom) {
+ ota = (OutlineTextRefAtom)child[i];
+ break;
+ }
+ }
+
+ HSLFTextParagraph[] runs = _sheet.getTextRuns();
+ if (ota != null) {
+ int idx = ota.getTextIndex();
+ for (int i = 0; i < runs.length; i++) {
+ if(runs[i].getIndex() == idx){
+ _txtrun = runs[i];
+ break;
+ }
+ }
+ if(_txtrun == null) {
+ logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
+ }
+ } else {
+ EscherSpRecord escherSpRecord = getEscherChild(EscherSpRecord.RECORD_ID);
+ int shapeId = escherSpRecord.getShapeId();
+ if(runs != null) for (int i = 0; i < runs.length; i++) {
+ if(runs[i].getShapeId() == shapeId){
+ _txtrun = runs[i];
+ break;
+ }
+ }
+ }
+
+ // ensure the same references child records of TextRun
+ if(_txtrun != null) {
+ for (int i = 0; i < child.length; i++) {
+ for (Record r : _txtrun.getRecords()) {
+ if (child[i].getRecordType() == r.getRecordType()) {
+ child[i] = r;
+ }
+ }
+ }
+ }
+ }
+
+ public void draw(Graphics2D graphics){
+ AffineTransform at = graphics.getTransform();
+ ShapePainter.paint(this, graphics);
+ new TextPainter(this).paint(graphics);
+ graphics.setTransform(at);
+ }
+
+ /**
+ * Return OEPlaceholderAtom
, the atom that describes a placeholder.
+ *
+ * @return OEPlaceholderAtom
or null
if not found
+ */
+ public OEPlaceholderAtom getPlaceholderAtom(){
+ return getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
+ }
+
+ /**
+ *
+ * Assigns a hyperlink to this text shape
+ *
+ * @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
+ * @param beginIndex the beginning index, inclusive.
+ * @param endIndex the ending index, exclusive.
+ * @see org.apache.poi.hslf.usermodel.HSLFSlideShow#addHyperlink(Hyperlink)
+ */
+ public void setHyperlink(int linkId, int beginIndex, int endIndex){
+ //TODO validate beginIndex and endIndex and throw IllegalArgumentException
+
+ InteractiveInfo info = new InteractiveInfo();
+ InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
+ infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
+ infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
+ infoAtom.setHyperlinkID(linkId);
+
+ _txtbox.appendChildRecord(info);
+
+ TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom();
+ txiatom.setStartIndex(beginIndex);
+ txiatom.setEndIndex(endIndex);
+ _txtbox.appendChildRecord(txiatom);
+
+ }
+
+ @Override
+ public boolean isPlaceholder() {
+ OEPlaceholderAtom oep = getPlaceholderAtom();
+ if (oep != null) return true;
+
+ //special case for files saved in Office 2007
+ RoundTripHFPlaceholder12 hldr = getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
+ if (hldr != null) return true;
+
+ return false;
+ }
+
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java b/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java
index 8bb441e4e4..bd3a6da399 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/HeadersFooters.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.model;
import org.apache.poi.hslf.record.*;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/**
* Header / Footer settings.
@@ -31,19 +31,19 @@ public final class HeadersFooters {
private HeadersFootersContainer _container;
private boolean _newRecord;
- private SlideShow _ppt;
- private Sheet _sheet;
+ private HSLFSlideShow _ppt;
+ private HSLFSheet _sheet;
private boolean _ppt2007;
- public HeadersFooters(HeadersFootersContainer rec, SlideShow ppt, boolean newRecord, boolean isPpt2007){
+ public HeadersFooters(HeadersFootersContainer rec, HSLFSlideShow ppt, boolean newRecord, boolean isPpt2007){
_container = rec;
_newRecord = newRecord;
_ppt = ppt;
_ppt2007 = isPpt2007;
}
- public HeadersFooters(HeadersFootersContainer rec, Sheet sheet, boolean newRecord, boolean isPpt2007){
+ public HeadersFooters(HeadersFootersContainer rec, HSLFSheet sheet, boolean newRecord, boolean isPpt2007){
_container = rec;
_newRecord = newRecord;
_sheet = sheet;
@@ -240,8 +240,8 @@ public final class HeadersFooters {
private boolean isVisible(int flag, int placeholderId){
boolean visible;
if(_ppt2007){
- Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
- TextShape placeholder = master.getPlaceholder(placeholderId);
+ HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
+ HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
visible = placeholder != null && placeholder.getText() != null;
} else {
visible = _container.getHeadersFootersAtom().getFlag(flag);
@@ -252,8 +252,8 @@ public final class HeadersFooters {
private String getPlaceholderText(int placeholderId, CString cs){
String text = null;
if(_ppt2007){
- Sheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
- TextShape placeholder = master.getPlaceholder(placeholderId);
+ HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
+ HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
if(placeholder != null) text = placeholder.getText();
//default text in master placeholders is not visible
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java
index df207e6716..2e1f1ec586 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/Hyperlink.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.model;
import org.apache.poi.hslf.record.*;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherClientDataRecord;
@@ -95,7 +95,7 @@ public final class Hyperlink {
return address;
}
- public void setAddress(Slide slide) {
+ public void setAddress(HSLFSlide slide) {
String href = slide._getSheetNumber() + ","+slide.getSlideNumber()+",Slide " + slide.getSlideNumber();
setAddress(href);;
setTitle("Slide " + slide.getSlideNumber());
@@ -151,9 +151,9 @@ public final class Hyperlink {
* @param run TextRun
to lookup hyperlinks in
* @return found hyperlinks or null
if not found
*/
- protected static Hyperlink[] find(TextRun run){
+ protected static Hyperlink[] find(HSLFTextParagraph run){
Listnull
- Notes Masters are not yet supported
- */
- public MasterSheet getMasterSheet() {
- return null;
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java
index a1e9c94e08..49ed8c2073 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java
@@ -18,8 +18,8 @@
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.ObjectData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFObjectData;
import org.apache.poi.hslf.record.ExObjList;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.ExEmbed;
@@ -34,7 +34,7 @@ import org.apache.poi.util.POILogger;
*
* @author Yegor Kozlov
*/
-public final class OLEShape extends Picture {
+public final class OLEShape extends HSLFPictureShape {
protected ExEmbed _exEmbed;
/**
@@ -117,13 +117,13 @@ public final class OLEShape extends Picture {
*
* @return the unique identifier for the OLE object
*/
- public ObjectData getObjectData(){
- SlideShow ppt = getSheet().getSlideShow();
- ObjectData[] ole = ppt.getEmbeddedObjects();
+ public HSLFObjectData getObjectData(){
+ HSLFSlideShow ppt = getSheet().getSlideShow();
+ HSLFObjectData[] ole = ppt.getEmbeddedObjects();
//persist reference
ExEmbed exEmbed = getExEmbed();
- ObjectData data = null;
+ HSLFObjectData data = null;
if(exEmbed != null) {
int ref = exEmbed.getExOleObjAtom().getObjStgDataRef();
@@ -156,7 +156,7 @@ public final class OLEShape extends Picture {
*/
public ExEmbed getExEmbed(){
if(_exEmbed == null){
- SlideShow ppt = getSheet().getSlideShow();
+ HSLFSlideShow ppt = getSheet().getSlideShow();
ExObjList lst = ppt.getDocumentRecord().getExObjList();
if(lst == null){
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java b/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
index f775addac3..47500df2f6 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
@@ -28,7 +28,7 @@ import java.awt.image.renderable.RenderableImage;
import java.awt.geom.*;
import java.text.AttributedCharacterIterator;
import java.util.Map;
-import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
@@ -214,7 +214,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
*/
public void draw(Shape shape){
GeneralPath path = new GeneralPath(_transform.createTransformedShape(shape));
- Freeform p = new Freeform(_group);
+ HSLFFreeformShape p = new HSLFFreeformShape(_group);
p.setPath(path);
p.getFill().setForegroundColor(null);
applyStroke(p);
@@ -250,12 +250,11 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
* @see #setClip
*/
public void drawString(String s, float x, float y) {
- TextBox txt = new TextBox(_group);
- txt.getTextRun().supplySlideShow(_group.getSheet().getSlideShow());
- txt.getTextRun().setSheet(_group.getSheet());
+ HSLFTextBox txt = new HSLFTextBox(_group);
+ txt.getTextParagraph().supplySheet(_group.getSheet());
txt.setText(s);
- RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
+ HSLFTextRun rt = txt.getTextParagraph().getRichTextRuns()[0];
rt.setFontSize(_font.getSize());
rt.setFontName(_font.getFamily());
@@ -267,9 +266,9 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
txt.setMarginTop(0);
txt.setMarginLeft(0);
txt.setMarginRight(0);
- txt.setWordWrap(TextBox.WrapNone);
- txt.setHorizontalAlignment(TextBox.AlignLeft);
- txt.setVerticalAlignment(TextBox.AnchorMiddle);
+ txt.setWordWrap(HSLFTextBox.WrapNone);
+ txt.setHorizontalAlignment(HSLFTextBox.AlignLeft);
+ txt.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
TextLayout layout = new TextLayout(s, _font, getFontRenderContext());
@@ -317,7 +316,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
*/
public void fill(Shape shape){
GeneralPath path = new GeneralPath(_transform.createTransformedShape(shape));
- Freeform p = new Freeform(_group);
+ HSLFFreeformShape p = new HSLFFreeformShape(_group);
p.setPath(path);
applyPaint(p);
p.setLineColor(null); //Fills must be "No Line"
@@ -1788,7 +1787,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
}
}
- protected void applyStroke(SimpleShape shape) {
+ protected void applyStroke(HSLFSimpleShape shape) {
if (_stroke instanceof BasicStroke){
BasicStroke bs = (BasicStroke)_stroke;
shape.setLineWidth(bs.getLineWidth());
@@ -1800,7 +1799,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
}
}
- protected void applyPaint(SimpleShape shape) {
+ protected void applyPaint(HSLFSimpleShape shape) {
if (_paint instanceof Color) {
shape.getFill().setForegroundColor((Color)_paint);
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
deleted file mode 100644
index 8c3b2b6399..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/* ====================================================================
- 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.model;
-
-import java.awt.Graphics2D;
-import java.awt.Insets;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.List;
-
-import javax.imageio.ImageIO;
-
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherComplexProperty;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherRecord;
-import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.ddf.EscherSpRecord;
-import org.apache.poi.hslf.blip.Bitmap;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.sl.usermodel.ShapeType;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.StringUtil;
-import org.apache.poi.util.Units;
-
-
-/**
- * Represents a picture in a PowerPoint document.
- *
- * @author Yegor Kozlov
- */
-public class Picture extends SimpleShape {
-
- /**
- * Windows Enhanced Metafile (EMF)
- */
- public static final int EMF = 2;
-
- /**
- * Windows Metafile (WMF)
- */
- public static final int WMF = 3;
-
- /**
- * Macintosh PICT
- */
- public static final int PICT = 4;
-
- /**
- * JPEG
- */
- public static final int JPEG = 5;
-
- /**
- * PNG
- */
- public static final int PNG = 6;
-
- /**
- * Windows DIB (BMP)
- */
- public static final byte DIB = 7;
-
- /**
- * Create a new Picture
- *
- * @param idx the index of the picture
- */
- public Picture(int idx){
- this(idx, null);
- }
-
- /**
- * Create a new Picture
- *
- * @param idx the index of the picture
- * @param parent the parent shape
- */
- public Picture(int idx, ShapeContainerPicture
object
- *
- * @param escherRecord the EscherSpContainer
record which holds information about
- * this picture in the Slide
- * @param parent the parent shape of this picture
- */
- protected Picture(EscherContainerRecord escherRecord, ShapeContainerEscherSp
record which holds information about this picture.
-
- * @param idx the index of the picture which refers to EscherBSE
container.
- * @return the create Picture object
- */
- protected EscherContainerRecord createSpContainer(int idx, boolean isChild) {
- _escherContainer = super.createSpContainer(isChild);
- _escherContainer.setOptions((short)15);
-
- EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
- spRecord.setOptions((short)((ShapeType.FRAME.nativeId << 4) | 0x2));
-
- //set default properties for a picture
- EscherOptRecord opt = getEscherOptRecord();
- setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
-
- //another weird feature of powerpoint: for picture id we must add 0x4000.
- setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
-
- return _escherContainer;
- }
-
- /**
- * Resize this picture to the default size.
- * For PNG and JPEG resizes the image to 100%,
- * for other types sets the default size of 200x200 pixels.
- */
- public void setDefaultSize(){
- PictureData pict = getPictureData();
- if (pict instanceof Bitmap){
- BufferedImage img = null;
- try {
- img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
- }
- catch (IOException e){}
- catch (NegativeArraySizeException ne) {}
-
- if(img != null) {
- // Valid image, set anchor from it
- setAnchor(new java.awt.Rectangle(0, 0, img.getWidth()*POINT_DPI/PIXEL_DPI, img.getHeight()*POINT_DPI/PIXEL_DPI));
- } else {
- // Invalid image, go with the default metafile size
- setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
- }
- } else {
- //default size of a metafile picture is 200x200
- setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
- }
- }
-
- /**
- * Returns the picture data for this picture.
- *
- * @return the picture data for this picture.
- */
- public PictureData getPictureData(){
- SlideShow ppt = getSheet().getSlideShow();
- PictureData[] pict = ppt.getPictureData();
-
- EscherBSERecord bse = getEscherBSERecord();
- if (bse == null){
- logger.log(POILogger.ERROR, "no reference to picture data found ");
- } else {
- for ( int i = 0; i < pict.length; i++ ) {
- if (pict[i].getOffset() == bse.getOffset()){
- return pict[i];
- }
- }
- logger.log(POILogger.ERROR, "no picture found for our BSE offset " + bse.getOffset());
- }
- return null;
- }
-
- protected EscherBSERecord getEscherBSERecord(){
- SlideShow ppt = getSheet().getSlideShow();
- Document doc = ppt.getDocumentRecord();
- EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
- EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
- if(bstore == null) {
- logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
- return null;
- }
- ListSlideShow
we belong to
- */
- private SlideShow _slideShow;
-
- /**
- * Sheet background
- */
- private Background _background;
-
- /**
- * Record container that holds sheet data.
- * For slides it is org.apache.poi.hslf.record.Slide,
- * for notes it is org.apache.poi.hslf.record.Notes,
- * for slide masters it is org.apache.poi.hslf.record.SlideMaster, etc.
- */
- private SheetContainer _container;
-
- private int _sheetNo;
-
- public Sheet(SheetContainer container, int sheetNo) {
- _container = container;
- _sheetNo = sheetNo;
- }
-
- /**
- * Returns an array of all the TextRuns in the sheet.
- */
- public abstract TextRun[] getTextRuns();
-
- /**
- * Returns the (internal, RefID based) sheet number, as used
- * to in PersistPtr stuff.
- */
- public int _getSheetRefId() {
- return _container.getSheetId();
- }
-
- /**
- * Returns the (internal, SlideIdentifier based) sheet number, as used
- * to reference this sheet from other records.
- */
- public int _getSheetNumber() {
- return _sheetNo;
- }
-
- /**
- * Fetch the PPDrawing from the underlying record
- */
- protected PPDrawing getPPDrawing() {
- return _container.getPPDrawing();
- }
-
- /**
- * Fetch the SlideShow we're attached to
- */
- public SlideShow getSlideShow() {
- return _slideShow;
- }
-
- /**
- * Return record container for this sheet
- */
- public SheetContainer getSheetContainer() {
- return _container;
- }
-
- /**
- * Set the SlideShow we're attached to.
- * Also passes it on to our child RichTextRuns
- */
- 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);
- }
- }
- }
-
-
- /**
- * For a given PPDrawing, grab all the TextRuns
- */
- public static TextRun[] findTextRuns(PPDrawing ppdrawing) {
- final ListTextShape
or null
- */
- public TextShape getPlaceholderByTextType(int type){
- HSLFShape[] shape = getShapes();
- for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof TextShape){
- TextShape tx = (TextShape)shape[i];
- TextRun run = tx.getTextRun();
- if(run != null && run.getRunType() == type){
- return tx;
- }
- }
- }
- return null;
- }
-
- /**
- * Search text placeholer by its type
- *
- * @param type type of placeholder to search. See {@link org.apache.poi.hslf.record.OEPlaceholderAtom}
- * @return TextShape
or null
- */
- public TextShape getPlaceholder(int type){
- HSLFShape[] shape = getShapes();
- for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof TextShape){
- TextShape tx = (TextShape)shape[i];
- int placeholderId = 0;
- OEPlaceholderAtom oep = tx.getPlaceholderAtom();
- if(oep != null) {
- placeholderId = oep.getPlaceholderId();
- } else {
- //special case for files saved in Office 2007
- RoundTripHFPlaceholder12 hldr = tx.getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
- if(hldr != null) placeholderId = hldr.getPlaceholderId();
- }
- if(placeholderId == type){
- return tx;
- }
- }
- }
- return null;
- }
-
- /**
- * Return programmable tag associated with this sheet, e.g. ___PPT12
.
- *
- * @return programmable tag associated with this sheet.
- */
- public String getProgrammableTag(){
- String tag = null;
- RecordContainer progTags = (RecordContainer)
- getSheetContainer().findFirstOfType(
- RecordTypes.ProgTags.typeID
- );
- if(progTags != null) {
- RecordContainer progBinaryTag = (RecordContainer)
- progTags.findFirstOfType(
- RecordTypes.ProgBinaryTag.typeID
- );
- if(progBinaryTag != null) {
- CString binaryTag = (CString)
- progBinaryTag.findFirstOfType(
- RecordTypes.CString.typeID
- );
- if(binaryTag != null) tag = binaryTag.getText();
- }
- }
-
- return tag;
-
- }
-
- public IteratorEscherSpContainer
container which holds information about this shape
- * @param parent the parent of the shape
- */
- protected SimpleShape(EscherContainerRecord escherRecord, ShapeContainertrue
if the Line is inside a group, false
otherwise
- * @return the record container which holds this shape
- */
- protected EscherContainerRecord createSpContainer(boolean isChild) {
- _escherContainer = new EscherContainerRecord();
- _escherContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
- _escherContainer.setOptions((short)15);
-
- EscherSpRecord sp = new EscherSpRecord();
- int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
- if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
- sp.setFlags(flags);
- _escherContainer.addChildRecord(sp);
-
- EscherOptRecord opt = new EscherOptRecord();
- opt.setRecordId(EscherOptRecord.RECORD_ID);
- _escherContainer.addChildRecord(opt);
-
- EscherRecord anchor;
- if(isChild) anchor = new EscherChildAnchorRecord();
- else {
- anchor = new EscherClientAnchorRecord();
-
- //hack. internal variable EscherClientAnchorRecord.shortRecord can be
- //initialized only in fillFields(). We need to set shortRecord=false;
- byte[] header = new byte[16];
- LittleEndian.putUShort(header, 0, 0);
- LittleEndian.putUShort(header, 2, 0);
- LittleEndian.putInt(header, 4, 8);
- anchor.fillFields(header, 0, null);
- }
- _escherContainer.addChildRecord(anchor);
-
- return _escherContainer;
- }
-
- /**
- * Returns width of the line in in points
- */
- public double getLineWidth(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
- double width = prop == null ? DEFAULT_LINE_WIDTH : (double)prop.getPropertyValue()/EMU_PER_POINT;
- return width;
- }
-
- /**
- * Sets the width of line in in points
- * @param width the width of line in in points
- */
- public void setLineWidth(double width){
- EscherOptRecord opt = getEscherOptRecord();
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, (int)(width*EMU_PER_POINT));
- }
-
- /**
- * Sets the color of line
- *
- * @param color new color of the line
- */
- public void setLineColor(Color color){
- EscherOptRecord opt = getEscherOptRecord();
- if (color == null) {
- setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
- } else {
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
- setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
- setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, color == null ? 0x180010 : 0x180018);
- }
- }
-
- /**
- * @return color of the line. If color is not set returns java.awt.Color.black
- */
- public Color getLineColor(){
- EscherOptRecord opt = getEscherOptRecord();
-
- EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
- if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
-
- Color clr = getColor(EscherProperties.LINESTYLE__COLOR, EscherProperties.LINESTYLE__OPACITY, -1);
- return clr == null ? Color.black : clr;
- }
-
- /**
- * Gets line dashing. One of the PEN_* constants defined in this class.
- *
- * @return dashing of the line.
- */
- public int getLineDashing(){
- EscherOptRecord opt = getEscherOptRecord();
-
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
- return prop == null ? Line.PEN_SOLID : prop.getPropertyValue();
- }
-
- /**
- * Sets line dashing. One of the PEN_* constants defined in this class.
- *
- * @param pen new style of the line.
- */
- public void setLineDashing(int pen){
- EscherOptRecord opt = getEscherOptRecord();
-
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen);
- }
-
- /**
- * Sets line style. One of the constants defined in this class.
- *
- * @param style new style of the line.
- */
- public void setLineStyle(int style){
- EscherOptRecord opt = getEscherOptRecord();
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style);
- }
-
- /**
- * Returns line style. One of the constants defined in this class.
- *
- * @return style of the line.
- */
- public int getStrokeStyle(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
- return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue();
- }
-
- /**
- * The color used to fill this shape.
- */
- public Color getFillColor(){
- return getFill().getForegroundColor();
- }
-
- /**
- * The color used to fill this shape.
- *
- * @param color the background color
- */
- public void setFillColor(Color color){
- getFill().setForegroundColor(color);
- }
-
- /**
- *
- * @return 'absolute' anchor of this shape relative to the parent sheet
- */
- public Rectangle2D getLogicalAnchor2D(){
- Rectangle2D anchor = getAnchor2D();
-
- //if it is a groupped shape see if we need to transform the coordinates
- if (getParent() != null){
- ArrayListnull
- */
- protected Record[] getClientRecords() {
- if(_clientData == null){
- EscherRecord r = getEscherChild(EscherClientDataRecord.RECORD_ID);
- //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID
- //convert in to EscherClientDataRecord on the fly
- if(r != null && !(r instanceof EscherClientDataRecord)){
- byte[] data = r.serialize();
- r = new EscherClientDataRecord();
- r.fillFields(data, 0, new DefaultEscherRecordFactory());
- }
- _clientData = (EscherClientDataRecord)r;
- }
- if(_clientData != null && _clientRecords == null){
- byte[] data = _clientData.getRemainingData();
- _clientRecords = Record.findChildRecords(data, 0, data.length);
- }
- return _clientRecords;
- }
-
- protected void updateClientData() {
- if(_clientData != null && _clientRecords != null){
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- for (int i = 0; i < _clientRecords.length; i++) {
- _clientRecords[i].writeOut(out);
- }
- } catch(Exception e){
- throw new HSLFException(e);
- }
- _clientData.setRemainingData(out.toByteArray());
- }
- }
-
- public void setHyperlink(Hyperlink link){
- if(link.getId() == -1){
- throw new HSLFException("You must call SlideShow.addHyperlink(Hyperlink link) first");
- }
-
- EscherClientDataRecord cldata = new EscherClientDataRecord();
- cldata.setOptions((short)0xF);
- getSpContainer().addChildRecord(cldata); // TODO - junit to prove getChildRecords().add is wrong
-
- InteractiveInfo info = new InteractiveInfo();
- InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
-
- switch(link.getType()){
- case Hyperlink.LINK_FIRSTSLIDE:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_FIRSTSLIDE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_FirstSlide);
- break;
- case Hyperlink.LINK_LASTSLIDE:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_LASTSLIDE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_LastSlide);
- break;
- case Hyperlink.LINK_NEXTSLIDE:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_NEXTSLIDE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NextSlide);
- break;
- case Hyperlink.LINK_PREVIOUSSLIDE:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_PREVIOUSSLIDE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_PreviousSlide);
- break;
- case Hyperlink.LINK_URL:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
- break;
- case Hyperlink.LINK_SLIDENUMBER:
- infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
- infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_SlideNumber);
- break;
- }
-
- infoAtom.setHyperlinkID(link.getId());
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {
- info.writeOut(out);
- } catch(Exception e){
- throw new HSLFException(e);
- }
- cldata.setRemainingData(out.toByteArray());
-
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
deleted file mode 100644
index 1db3173e6a..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/model/Slide.java
+++ /dev/null
@@ -1,513 +0,0 @@
-/* ====================================================================
- 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.model;
-
-import java.awt.Graphics2D;
-import java.util.LinkedList;
-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.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.usermodel.ShapeType;
-
-/**
- * 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 Slide extends Sheet {
- private int _slideNo;
- private SlideAtomsSet _atomSet;
- private TextRun[] _runs;
- private Notes _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 Slide(org.apache.poi.hslf.record.Slide slide, Notes notes, SlideAtomsSet atomSet, int slideIdentifier, int slideNumber) {
- super(slide, slideIdentifier);
-
- _notes = notes;
- _atomSet = atomSet;
- _slideNo = slideNumber;
-
- // Grab the TextRuns from the PPDrawing
- TextRun[] _otherRuns = findTextRuns(getPPDrawing());
-
- // For the text coming in from the SlideAtomsSet:
- // Build up TextRuns from pairs of TextHeaderAtom and
- // one of TextBytesAtom or TextCharsAtom
- final List
TextBox
object that represents the slide's title.
- *
- * @return TextBox
object that represents the slide's title.
- */
- public TextBox addTitle() {
- Placeholder pl = new Placeholder();
- pl.setShapeType(ShapeType.RECT);
- pl.getTextRun().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
-
- /**
- * Return title of this slide or null
if the slide does not have title.
- *
- * 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 MasterSheet getMasterSheet(){
- SlideMaster[] master = getSlideShow().getSlidesMasters();
- SlideAtom sa = getSlideRecord().getSlideAtom();
- int masterId = sa.getMasterID();
- MasterSheet sheet = null;
- for (int i = 0; i < master.length; i++) {
- if (masterId == master[i]._getSheetNumber()) {
- sheet = master[i];
- break;
- }
- }
- if (sheet == null){
- TitleMaster[] titleMaster = getSlideShow().getTitleMasters();
- if(titleMaster != null) for (int i = 0; i < titleMaster.length; i++) {
- if (masterId == titleMaster[i]._getSheetNumber()) {
- sheet = titleMaster[i];
- break;
- }
- }
- }
- return sheet;
- }
-
- /**
- * Change Master of this slide.
- */
- public void setMasterSheet(MasterSheet 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 Background 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- * Contains the text in a text frame as well as the properties and methods - * that control alignment and anchoring of the text. - *
- * - * @author Yegor Kozlov - */ -public class TextBox extends TextShape { - - /** - * Create a TextBox object and initialize it from the supplied Record container. - * - * @param escherRecordEscherSpContainer
container which holds information about this shape
- * @param parent the parent of the shape
- */
- protected TextBox(EscherContainerRecord escherRecord, ShapeContainerEscherContainerRecord
which holds shape data
- */
- protected EscherContainerRecord createSpContainer(boolean isChild){
- _escherContainer = super.createSpContainer(isChild);
-
- setShapeType(ShapeType.TEXT_BOX);
-
- //set default properties for a TextBox
- setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
- setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
- setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100000);
- setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
- setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
- setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
-
- _txtrun = createTextRun();
-
- return _escherContainer;
- }
-
- protected void setDefaultTextProperties(TextRun _txtrun){
- setVerticalAlignment(TextBox.AnchorTop);
- setEscherProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20002);
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
index 4b8805c266..038e28a04d 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextPainter.java
@@ -35,7 +35,7 @@ import java.util.List;
import java.util.Map;
import org.apache.poi.hslf.record.TextRulerAtom;
-import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -57,27 +57,27 @@ public final class TextPainter {
*/
protected static final char DEFAULT_BULLET_CHAR = '\u25a0';
- protected TextShape _shape;
+ protected HSLFTextShape _shape;
- public TextPainter(TextShape shape){
+ public TextPainter(HSLFTextShape shape){
_shape = shape;
}
- public AttributedString getAttributedString(TextRun txrun) {
+ public AttributedString getAttributedString(HSLFTextParagraph txrun) {
return getAttributedString(txrun, null);
}
/**
* Convert the underlying set of rich text runs into java.text.AttributedString
*/
- public AttributedString getAttributedString(TextRun txrun, Graphics2D graphics){
+ public AttributedString getAttributedString(HSLFTextParagraph txrun, Graphics2D graphics){
String text = txrun.getText();
//TODO: properly process tabs
text = text.replace('\t', ' ');
text = text.replace((char)160, ' ');
AttributedString at = new AttributedString(text);
- RichTextRun[] rt = txrun.getRichTextRuns();
+ HSLFTextRun[] rt = txrun.getRichTextRuns();
for (int i = 0; i < rt.length; i++) {
int start = rt[i].getStartIndex();
int end = rt[i].getEndIndex();
@@ -157,15 +157,15 @@ public final class TextPainter {
int valign = _shape.getVerticalAlignment();
double y0 = anchor.getY();
switch (valign){
- case TextShape.AnchorTopBaseline:
- case TextShape.AnchorTop:
+ case HSLFTextShape.AnchorTopBaseline:
+ case HSLFTextShape.AnchorTop:
y0 += _shape.getMarginTop();
break;
- case TextShape.AnchorBottom:
+ case HSLFTextShape.AnchorBottom:
y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();
break;
default:
- case TextShape.AnchorMiddle:
+ case HSLFTextShape.AnchorMiddle:
float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();
y0 += _shape.getMarginTop() + delta/2;
break;
@@ -205,14 +205,14 @@ public final class TextPainter {
pen.y = y0;
switch (elem[i]._align) {
default:
- case TextShape.AlignLeft:
+ case HSLFTextShape.AlignLeft:
pen.x = anchor.getX() + _shape.getMarginLeft();
break;
- case TextShape.AlignCenter:
+ case HSLFTextShape.AlignCenter:
pen.x = anchor.getX() + _shape.getMarginLeft() +
(anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;
break;
- case TextShape.AlignRight:
+ case HSLFTextShape.AlignRight:
pen.x = anchor.getX() + _shape.getMarginLeft() +
(anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight());
break;
@@ -235,7 +235,7 @@ public final class TextPainter {
}
public TextElement[] getTextElements(float textWidth, FontRenderContext frc, Graphics2D graphics){
- TextRun run = _shape.getTextRun();
+ HSLFTextParagraph run = _shape.getTextParagraph();
if (run == null) return null;
String text = run.getText();
@@ -257,7 +257,7 @@ public final class TextPainter {
boolean prStart = text.charAt(startIndex) == '\n';
if(prStart) measurer.setPosition(startIndex++);
- RichTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
+ HSLFTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
if(rt == null) {
logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
break;
@@ -283,7 +283,7 @@ public final class TextPainter {
if(bulletOffset > 0 || prStart || startIndex == 0) wrappingWidth -= textOffset;
- if (_shape.getWordWrap() == TextShape.WrapNone) {
+ if (_shape.getWordWrap() == HSLFTextShape.WrapNone) {
wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
deleted file mode 100644
index 755482f183..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
+++ /dev/null
@@ -1,746 +0,0 @@
-/* ====================================================================
- 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.model;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.PPDrawing;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordContainer;
-import org.apache.poi.hslf.record.SlideListWithText;
-import org.apache.poi.hslf.record.StyleTextProp9Atom;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextBytesAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.record.TextRulerAtom;
-import org.apache.poi.hslf.record.TextSpecInfoAtom;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.util.StringUtil;
-
-/**
- * This class represents a run of text in a powerpoint document. That
- * run could be text on a sheet, or text in a note.
- * It is only a very basic class for now
- *
- * @author Nick Burch
- */
-
-public final class TextRun
-{
- // Note: These fields are protected to help with unit testing
- // Other classes shouldn't really go playing with them!
- protected TextHeaderAtom _headerAtom;
- protected TextBytesAtom _byteAtom;
- protected TextCharsAtom _charAtom;
- protected StyleTextPropAtom _styleAtom;
- protected TextRulerAtom _ruler;
- protected boolean _isUnicode;
- protected RichTextRun[] _rtRuns;
- private SlideShow slideShow;
- private Sheet _sheet;
- private int shapeId;
- private int slwtIndex = -1; //position in the owning SlideListWithText
- /**
- * all text run records that follow TextHeaderAtom.
- * (there can be misc InteractiveInfo, TxInteractiveInfo and other records)
- */
- protected Record[] _records;
- // private StyleTextPropAtom styleTextPropAtom;
- private StyleTextProp9Atom styleTextProp9Atom;
-
- /**
- * Constructs a Text Run from a Unicode text block
- *
- * @param tha the TextHeaderAtom that defines what's what
- * @param tca the TextCharsAtom containing the text
- * @param sta the StyleTextPropAtom which defines the character stylings
- */
- public TextRun(TextHeaderAtom tha, TextCharsAtom tca, StyleTextPropAtom sta) {
- this(tha,null,tca,sta);
- }
-
- /**
- * Constructs a Text Run from a Ascii text block
- *
- * @param tha the TextHeaderAtom that defines what's what
- * @param tba the TextBytesAtom containing the text
- * @param sta the StyleTextPropAtom which defines the character stylings
- */
- public TextRun(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) {
- this(tha,tba,null,sta);
- }
-
- /**
- * Internal constructor and initializer
- */
- private TextRun(TextHeaderAtom tha, TextBytesAtom tba, TextCharsAtom tca, StyleTextPropAtom sta) {
- _headerAtom = tha;
- _styleAtom = sta;
- if(tba != null) {
- _byteAtom = tba;
- _isUnicode = false;
- } else {
- _charAtom = tca;
- _isUnicode = true;
- }
- String runRawText = getText();
-
- // Figure out the rich text runs
- LinkedListnull
if not found.
- */
- public Hyperlink[] getHyperlinks(){
- return Hyperlink.find(this);
- }
-
- /**
- * Fetch RichTextRun at a given position
- *
- * @param pos 0-based index in the text
- * @return RichTextRun or null if not found
- */
- public RichTextRun getRichTextRunAt(int pos){
- for (int i = 0; i < _rtRuns.length; i++) {
- int start = _rtRuns[i].getStartIndex();
- int end = _rtRuns[i].getEndIndex();
- if(pos >= start && pos < end) return _rtRuns[i];
- }
- return null;
- }
-
- public TextRulerAtom getTextRuler(){
- if(_ruler == null){
- if(_records != null) for (int i = 0; i < _records.length; i++) {
- if(_records[i] instanceof TextRulerAtom) {
- _ruler = (TextRulerAtom)_records[i];
- break;
- }
- }
-
- }
- return _ruler;
-
- }
-
- public TextRulerAtom createTextRuler(){
- _ruler = getTextRuler();
- if(_ruler == null){
- _ruler = TextRulerAtom.getParagraphInstance();
- _headerAtom.getParentRecord().appendChildRecord(_ruler);
- }
- return _ruler;
- }
-
- /**
- * Returns a new string with line breaks converted into internal ppt representation
- */
- public String normalize(String s){
- String ns = s.replaceAll("\\r?\\n", "\r");
- return ns;
- }
-
- /**
- * Returns records that make up this text run
- *
- * @return text run records
- */
- public Record[] getRecords(){
- return _records;
- }
- /** Numbered List info */
- public void setStyleTextProp9Atom(final StyleTextProp9Atom styleTextProp9Atom) {
- this.styleTextProp9Atom = styleTextProp9Atom;
- }
- /** Numbered List info */
- public StyleTextProp9Atom getStyleTextProp9Atom() {
- return this.styleTextProp9Atom;
- }
-
- /** Characters covered */
- public StyleTextPropAtom getStyleTextPropAtom() {
- return this._styleAtom;
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
deleted file mode 100644
index 3f47ae6a5b..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
+++ /dev/null
@@ -1,641 +0,0 @@
-/* ====================================================================
- 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.model;
-
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.font.FontRenderContext;
-import java.awt.font.TextLayout;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.io.IOException;
-
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.ddf.EscherSpRecord;
-import org.apache.poi.ddf.EscherTextboxRecord;
-import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.record.EscherTextboxWrapper;
-import org.apache.poi.hslf.record.InteractiveInfo;
-import org.apache.poi.hslf.record.InteractiveInfoAtom;
-import org.apache.poi.hslf.record.OEPlaceholderAtom;
-import org.apache.poi.hslf.record.OutlineTextRefAtom;
-import org.apache.poi.hslf.record.PPDrawing;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
-import org.apache.poi.hslf.record.StyleTextPropAtom;
-import org.apache.poi.hslf.record.TextBytesAtom;
-import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.util.POILogger;
-
-/**
- * A common superclass of all shapes that can hold text.
- *
- * @author Yegor Kozlov
- */
-public abstract class TextShape extends SimpleShape {
-
- /**
- * How to anchor the text
- */
- public static final int AnchorTop = 0;
- public static final int AnchorMiddle = 1;
- public static final int AnchorBottom = 2;
- public static final int AnchorTopCentered = 3;
- public static final int AnchorMiddleCentered = 4;
- public static final int AnchorBottomCentered = 5;
- public static final int AnchorTopBaseline = 6;
- public static final int AnchorBottomBaseline = 7;
- public static final int AnchorTopCenteredBaseline = 8;
- public static final int AnchorBottomCenteredBaseline = 9;
-
- /**
- * How to wrap the text
- */
- public static final int WrapSquare = 0;
- public static final int WrapByPoints = 1;
- public static final int WrapNone = 2;
- public static final int WrapTopBottom = 3;
- public static final int WrapThrough = 4;
-
- /**
- * How to align the text
- */
- public static final int AlignLeft = 0;
- public static final int AlignCenter = 1;
- public static final int AlignRight = 2;
- public static final int AlignJustify = 3;
-
- /**
- * TextRun object which holds actual text and format data
- */
- protected TextRun _txtrun;
-
- /**
- * Escher container which holds text attributes such as
- * TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.
- */
- protected EscherTextboxWrapper _txtbox;
-
- /**
- * Used to calculate text bounds
- */
- protected static final FontRenderContext _frc = new FontRenderContext(null, true, true);
-
- /**
- * Create a TextBox object and initialize it from the supplied Record container.
- *
- * @param escherRecord EscherSpContainer
container which holds information about this shape
- * @param parent the parent of the shape
- */
- protected TextShape(EscherContainerRecord escherRecord, ShapeContainerPPDrawing
about it.
- *
- * @param sh the sheet we are adding to
- */
- protected void afterInsert(Sheet sh){
- super.afterInsert(sh);
-
- EscherTextboxWrapper _txtbox = getEscherTextboxWrapper();
- if(_txtbox != null){
- PPDrawing ppdrawing = sh.getPPDrawing();
- ppdrawing.addTextboxWrapper(_txtbox);
- // Ensure the escher layer knows about the added records
- try {
- _txtbox.writeOut(null);
- } catch (IOException e){
- throw new HSLFException(e);
- }
- if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
- }
- if(_txtrun != null) {
- _txtrun.setShapeId(getShapeId());
- sh.onAddTextShape(this);
- }
- }
-
- protected EscherTextboxWrapper getEscherTextboxWrapper(){
- if(_txtbox == null){
- EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID);
- if(textRecord != null) _txtbox = new EscherTextboxWrapper(textRecord);
- }
- return _txtbox;
- }
- /**
- * Adjust the size of the TextShape so it encompasses the text inside it.
- *
- * @return a Rectangle2D
that is the bounds of this TextShape
.
- */
- public Rectangle2D resizeToFitText(){
- String txt = getText();
- if(txt == null || txt.length() == 0) return new Rectangle2D.Float();
-
- RichTextRun rt = getTextRun().getRichTextRuns()[0];
- int size = rt.getFontSize();
- int style = 0;
- if (rt.isBold()) style |= Font.BOLD;
- if (rt.isItalic()) style |= Font.ITALIC;
- String fntname = rt.getFontName();
- Font font = new Font(fntname, style, size);
-
- float width = 0, height = 0, leading = 0;
- String[] lines = txt.split("\n");
- for (int i = 0; i < lines.length; i++) {
- if(lines[i].length() == 0) continue;
-
- TextLayout layout = new TextLayout(lines[i], font, _frc);
-
- leading = Math.max(leading, layout.getLeading());
- width = Math.max(width, layout.getAdvance());
- height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
- }
-
- // add one character to width
- Rectangle2D charBounds = font.getMaxCharBounds(_frc);
- width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
-
- // add leading to height
- height += getMarginTop() + getMarginBottom() + leading;
-
- Rectangle2D anchor = getAnchor2D();
- anchor.setRect(anchor.getX(), anchor.getY(), width, height);
- setAnchor(anchor);
-
- return anchor;
- }
-
- /**
- * Returns the type of vertical alignment for the text.
- * One of the Anchor*
constants defined in this class.
- *
- * @return the type of alignment
- */
- public int getVerticalAlignment(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
- int valign = TextShape.AnchorTop;
- if (prop == null){
- /**
- * If vertical alignment was not found in the shape properties then try to
- * fetch the master shape and search for the align property there.
- */
- int type = getTextRun().getRunType();
- MasterSheet master = getSheet().getMasterSheet();
- if(master != null){
- TextShape masterShape = master.getPlaceholderByTextType(type);
- if(masterShape != null) valign = masterShape.getVerticalAlignment();
- } else {
- //not found in the master sheet. Use the hardcoded defaults.
- switch (type){
- case TextHeaderAtom.TITLE_TYPE:
- case TextHeaderAtom.CENTER_TITLE_TYPE:
- valign = TextShape.AnchorMiddle;
- break;
- default:
- valign = TextShape.AnchorTop;
- break;
- }
- }
- } else {
- valign = prop.getPropertyValue();
- }
- return valign;
- }
-
- /**
- * Sets the type of vertical alignment for the text.
- * One of the Anchor*
constants defined in this class.
- *
- * @param align - the type of alignment
- */
- public void setVerticalAlignment(int align){
- setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align);
- }
-
- /**
- * Sets the type of horizontal alignment for the text.
- * One of the Align*
constants defined in this class.
- *
- * @param align - the type of horizontal alignment
- */
- public void setHorizontalAlignment(int align){
- TextRun tx = getTextRun();
- if(tx != null) tx.getRichTextRuns()[0].setAlignment(align);
- }
-
- /**
- * Gets the type of horizontal alignment for the text.
- * One of the Align*
constants defined in this class.
- *
- * @return align - the type of horizontal alignment
- */
- public int getHorizontalAlignment(){
- TextRun tx = getTextRun();
- return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment();
- }
-
- /**
- * Returns the distance (in points) between the bottom of the text frame
- * and the bottom of the inscribed rectangle of the shape that contains the text.
- * Default value is 1/20 inch.
- *
- * @return the botom margin
- */
- public float getMarginBottom(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
- int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
- }
-
- /**
- * Sets the botom margin.
- * @see #getMarginBottom()
- *
- * @param margin the bottom margin
- */
- public void setMarginBottom(float margin){
- setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));
- }
-
- /**
- * Returns the distance (in points) between the left edge of the text frame
- * and the left edge of the inscribed rectangle of the shape that contains
- * the text.
- * Default value is 1/10 inch.
- *
- * @return the left margin
- */
- public float getMarginLeft(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
- int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
- }
-
- /**
- * Sets the left margin.
- * @see #getMarginLeft()
- *
- * @param margin the left margin
- */
- public void setMarginLeft(float margin){
- setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));
- }
-
- /**
- * Returns the distance (in points) between the right edge of the
- * text frame and the right edge of the inscribed rectangle of the shape
- * that contains the text.
- * Default value is 1/10 inch.
- *
- * @return the right margin
- */
- public float getMarginRight(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
- int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
- }
-
- /**
- * Sets the right margin.
- * @see #getMarginRight()
- *
- * @param margin the right margin
- */
- public void setMarginRight(float margin){
- setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));
- }
-
- /**
- * Returns the distance (in points) between the top of the text frame
- * and the top of the inscribed rectangle of the shape that contains the text.
- * Default value is 1/20 inch.
- *
- * @return the top margin
- */
- public float getMarginTop(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
- int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
- return (float)val/EMU_PER_POINT;
- }
-
- /**
- * Sets the top margin.
- * @see #getMarginTop()
- *
- * @param margin the top margin
- */
- public void setMarginTop(float margin){
- setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));
- }
-
-
- /**
- * Returns the value indicating word wrap.
- *
- * @return the value indicating word wrap.
- * Must be one of the Wrap*
constants defined in this class.
- */
- public int getWordWrap(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
- return prop == null ? WrapSquare : prop.getPropertyValue();
- }
-
- /**
- * Specifies how the text should be wrapped
- *
- * @param wrap the value indicating how the text should be wrapped.
- * Must be one of the Wrap*
constants defined in this class.
- */
- public void setWordWrap(int wrap){
- setEscherProperty(EscherProperties.TEXT__WRAPTEXT, wrap);
- }
-
- /**
- * @return id for the text.
- */
- public int getTextId(){
- EscherOptRecord opt = getEscherOptRecord();
- EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
- return prop == null ? 0 : prop.getPropertyValue();
- }
-
- /**
- * Sets text ID
- *
- * @param id of the text
- */
- public void setTextId(int id){
- setEscherProperty(EscherProperties.TEXT__TEXTID, id);
- }
-
- /**
- * @return the TextRun object for this text box
- */
- public TextRun getTextRun(){
- if (null == this._txtrun) initTextRun();
- if (null == this._txtrun && null != this._txtbox) {
- TextHeaderAtom tha = null;
- TextBytesAtom tba = null;
- TextCharsAtom tca = null;
- StyleTextPropAtom sta = null;
- Record[] childRecords = this._txtbox.getChildRecords();
- for (Record r : childRecords) {
- if (r instanceof TextHeaderAtom) {
- tha = (TextHeaderAtom) r;
- } else if (r instanceof TextBytesAtom) {
- tba = (TextBytesAtom) r;
- } else if (r instanceof TextCharsAtom) {
- tca = (TextCharsAtom) r;
- } else if (r instanceof StyleTextPropAtom) {
- sta = (StyleTextPropAtom) r;
- }
- }
- if (tba != null) {
- this._txtrun = new TextRun(tha, tba, sta);
- } else if (tca != null) {
- this._txtrun = new TextRun(tha, tca, sta);
- }
- }
- return _txtrun;
- }
-
- public void setSheet(Sheet sheet) {
- _sheet = sheet;
-
- // Initialize _txtrun object.
- // (We can't do it in the constructor because the sheet
- // is not assigned then, it's only built once we have
- // all the records)
- TextRun tx = getTextRun();
- if (tx != null) {
- // Supply the sheet to our child RichTextRuns
- tx.setSheet(_sheet);
- RichTextRun[] rt = tx.getRichTextRuns();
- for (int i = 0; i < rt.length; i++) {
- rt[i].supplySlideShow(_sheet.getSlideShow());
- }
- }
-
- }
-
- protected void initTextRun(){
- EscherTextboxWrapper txtbox = getEscherTextboxWrapper();
- Sheet sheet = getSheet();
-
- if(sheet == null || txtbox == null) return;
-
- OutlineTextRefAtom ota = null;
-
- Record[] child = txtbox.getChildRecords();
- for (int i = 0; i < child.length; i++) {
- if (child[i] instanceof OutlineTextRefAtom) {
- ota = (OutlineTextRefAtom)child[i];
- break;
- }
- }
-
- TextRun[] runs = _sheet.getTextRuns();
- if (ota != null) {
- int idx = ota.getTextIndex();
- for (int i = 0; i < runs.length; i++) {
- if(runs[i].getIndex() == idx){
- _txtrun = runs[i];
- break;
- }
- }
- if(_txtrun == null) {
- logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
- }
- } else {
- EscherSpRecord escherSpRecord = getEscherChild(EscherSpRecord.RECORD_ID);
- int shapeId = escherSpRecord.getShapeId();
- if(runs != null) for (int i = 0; i < runs.length; i++) {
- if(runs[i].getShapeId() == shapeId){
- _txtrun = runs[i];
- break;
- }
- }
- }
- // ensure the same references child records of TextRun
- if(_txtrun != null) for (int i = 0; i < child.length; i++) {
- for (Record r : _txtrun.getRecords()) {
- if (child[i].getRecordType() == r.getRecordType()) {
- child[i] = r;
- }
- }
- }
- }
-
- public void draw(Graphics2D graphics){
- AffineTransform at = graphics.getTransform();
- ShapePainter.paint(this, graphics);
- new TextPainter(this).paint(graphics);
- graphics.setTransform(at);
- }
-
- /**
- * Return OEPlaceholderAtom
, the atom that describes a placeholder.
- *
- * @return OEPlaceholderAtom
or null
if not found
- */
- public OEPlaceholderAtom getPlaceholderAtom(){
- return getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
- }
-
- /**
- *
- * Assigns a hyperlink to this text shape
- *
- * @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
- * @param beginIndex the beginning index, inclusive.
- * @param endIndex the ending index, exclusive.
- * @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
- */
- public void setHyperlink(int linkId, int beginIndex, int endIndex){
- //TODO validate beginIndex and endIndex and throw IllegalArgumentException
-
- InteractiveInfo info = new InteractiveInfo();
- InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
- infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
- infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
- infoAtom.setHyperlinkID(linkId);
-
- _txtbox.appendChildRecord(info);
-
- TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom();
- txiatom.setStartIndex(beginIndex);
- txiatom.setEndIndex(endIndex);
- _txtbox.appendChildRecord(txiatom);
-
- }
-
- @Override
- public boolean isPlaceholder() {
- OEPlaceholderAtom oep = getPlaceholderAtom();
- if (oep != null) return true;
-
- //special case for files saved in Office 2007
- RoundTripHFPlaceholder12 hldr = getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
- if (hldr != null) return true;
-
- return false;
- }
-
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java b/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java
index 843f123890..8184c030fa 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/model/TitleMaster.java
@@ -25,8 +25,8 @@ import org.apache.poi.hslf.record.*;
*
* @author Yegor Kozlov
*/
-public final class TitleMaster extends MasterSheet {
- private TextRun[] _runs;
+public final class TitleMaster extends HSLFMasterSheet {
+ private HSLFTextParagraph[] _runs;
/**
* Constructs a TitleMaster
@@ -42,7 +42,7 @@ public final class TitleMaster extends MasterSheet {
/**
* Returns an array of all the TextRuns found
*/
- public TextRun[] getTextRuns() {
+ public HSLFTextParagraph[] getTextRuns() {
return _runs;
}
@@ -50,14 +50,14 @@ public final class TitleMaster extends MasterSheet {
* Delegate the call to the underlying slide master.
*/
public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
- MasterSheet master = getMasterSheet();
+ HSLFMasterSheet master = getMasterSheet();
return master == null ? null : master.getStyleAttribute(txtype, level, name, isCharacter);
}
/**
* Returns the slide master for this title master.
*/
- public MasterSheet getMasterSheet(){
+ public HSLFMasterSheet getMasterSheet(){
SlideMaster[] master = getSlideShow().getSlidesMasters();
SlideAtom sa = ((org.apache.poi.hslf.record.Slide)getSheetContainer()).getSlideAtom();
int masterId = sa.getMasterID();
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java
new file mode 100644
index 0000000000..f02ddbe785
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFObjectData.java
@@ -0,0 +1,70 @@
+/* ====================================================================
+ 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.io.InputStream;
+import java.io.IOException;
+
+import org.apache.poi.hslf.record.ExOleObjStg;
+
+/**
+ * A class that represents object data embedded in a slide show.
+ *
+ * @author Daniel Noll
+ */
+public class HSLFObjectData {
+ /**
+ * The record that contains the object data.
+ */
+ private ExOleObjStg storage;
+
+ /**
+ * Creates the object data wrapping the record that contains the object data.
+ *
+ * @param storage the record that contains the object data.
+ */
+ public HSLFObjectData(ExOleObjStg storage) {
+ this.storage = storage;
+ }
+
+ /**
+ * Gets an input stream which returns the binary of the embedded data.
+ *
+ * @return the input stream which will contain the binary of the embedded data.
+ */
+ public InputStream getData() {
+ return storage.getData();
+ }
+
+ /**
+ * Sets the embedded data.
+ *
+ * @param data the embedded data.
+ */
+ public void setData(byte[] data) throws IOException {
+ storage.setData(data);
+ }
+
+ /**
+ * Return the record that contains the object data.
+ *
+ * @return the record that contains the object data.
+ */
+ public ExOleObjStg getExOleObjStg() {
+ return storage;
+ }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
new file mode 100644
index 0000000000..9d9b0dc594
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java
@@ -0,0 +1,264 @@
+/* ====================================================================
+ 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.io.IOException;
+import java.io.OutputStream;
+import java.security.MessageDigest;
+
+import org.apache.poi.hslf.blip.BitmapPainter;
+import org.apache.poi.hslf.blip.DIB;
+import org.apache.poi.hslf.blip.EMF;
+import org.apache.poi.hslf.blip.ImagePainter;
+import org.apache.poi.hslf.blip.JPEG;
+import org.apache.poi.hslf.blip.PICT;
+import org.apache.poi.hslf.blip.PNG;
+import org.apache.poi.hslf.blip.WMF;
+import org.apache.poi.hslf.model.HSLFPictureShape;
+import org.apache.poi.poifs.crypt.CryptoFunctions;
+import org.apache.poi.poifs.crypt.HashAlgorithm;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+/**
+ * A class that represents image data contained in a slide show.
+ *
+ * @author Yegor Kozlov
+ */
+public abstract class HSLFPictureData {
+
+ protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
+ /**
+ * Size of the image checksum calculated using MD5 algorithm.
+ */
+ protected static final int CHECKSUM_SIZE = 16;
+
+ /**
+ * Binary data of the picture
+ */
+ private byte[] rawdata;
+ /**
+ * The offset to the picture in the stream
+ */
+ protected int offset;
+
+ /**
+ * Returns type of this picture.
+ * Must be one of the static constants defined in the Picture class.
+ *
+ * @return type of this picture.
+ */
+ public abstract int getType();
+
+
+ /**
+ * Returns content type (mime type) of this picture.
+ *
+ * @return content type of this picture.
+ */
+ public abstract String getContentType();
+
+ /**
+ * Returns the binary data of this Picture
+ * @return picture data
+ */
+ public abstract byte[] getData();
+
+ /**
+ * Set picture data
+ */
+ public abstract void setData(byte[] data) throws IOException;
+
+ /**
+ * Blip signature.
+ */
+ protected abstract int getSignature();
+
+ protected static final ImagePainter[] painters = new ImagePainter[8];
+ static {
+ HSLFPictureData.setImagePainter(HSLFPictureShape.PNG, new BitmapPainter());
+ HSLFPictureData.setImagePainter(HSLFPictureShape.JPEG, new BitmapPainter());
+ HSLFPictureData.setImagePainter(HSLFPictureShape.DIB, new BitmapPainter());
+ }
+
+ /**
+ * Returns the raw binary data of this Picture excluding the first 8 bytes
+ * which hold image signature and size of the image data.
+ *
+ * @return picture data
+ */
+ public byte[] getRawData(){
+ return rawdata;
+ }
+
+ public void setRawData(byte[] data){
+ rawdata = data;
+ }
+
+ /**
+ * File offset in the 'Pictures' stream
+ *
+ * @return offset in the 'Pictures' stream
+ */
+ public int getOffset(){
+ return offset;
+ }
+
+ /**
+ * Set offset of this picture in the 'Pictures' stream.
+ * We need to set it when a new picture is created.
+ *
+ * @param offset in the 'Pictures' stream
+ */
+ public void setOffset(int offset){
+ this.offset = offset;
+ }
+
+ /**
+ * Returns 16-byte checksum of this picture
+ */
+ public byte[] getUID(){
+ byte[] uid = new byte[16];
+ System.arraycopy(rawdata, 0, uid, 0, uid.length);
+ return uid;
+ }
+
+
+ /**
+ * Compute 16-byte checksum of this picture using MD5 algorithm.
+ */
+ public static byte[] getChecksum(byte[] data) {
+ MessageDigest md5 = CryptoFunctions.getMessageDigest(HashAlgorithm.md5);
+ md5.update(data);
+ return md5.digest();
+ }
+
+ /**
+ * Write this picture into OutputStream
+ */
+ public void write(OutputStream out) throws IOException {
+ byte[] data;
+
+ data = new byte[LittleEndian.SHORT_SIZE];
+ LittleEndian.putUShort(data, 0, getSignature());
+ out.write(data);
+
+ data = new byte[LittleEndian.SHORT_SIZE];
+ LittleEndian.putUShort(data, 0, getType() + 0xF018);
+ out.write(data);
+
+ byte[] rawdata = getRawData();
+
+ data = new byte[LittleEndian.INT_SIZE];
+ LittleEndian.putInt(data, 0, rawdata.length);
+ out.write(data);
+
+ out.write(rawdata);
+ }
+
+ /**
+ * Create an instance of PictureData
by type.
+ *
+ * @param type type of the picture data.
+ * Must be one of the static constants defined in the Picture class.
+ * @return concrete instance of PictureData
+ */
+ public static HSLFPictureData create(int type){
+ HSLFPictureData pict;
+ switch (type){
+ case HSLFPictureShape.EMF:
+ pict = new EMF();
+ break;
+ case HSLFPictureShape.WMF:
+ pict = new WMF();
+ break;
+ case HSLFPictureShape.PICT:
+ pict = new PICT();
+ break;
+ case HSLFPictureShape.JPEG:
+ pict = new JPEG();
+ break;
+ case HSLFPictureShape.PNG:
+ pict = new PNG();
+ break;
+ case HSLFPictureShape.DIB:
+ pict = new DIB();
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported picture type: " + type);
+ }
+ return pict;
+ }
+
+ /**
+ * Return 24 byte header which preceeds the actual picture data.
+ *
+ * The header consists of 2-byte signature, 2-byte type,
+ * 4-byte image size and 16-byte checksum of the image data.
+ *
+ *
+ * @return the 24 byte header which preceeds the actual picture data.
+ */
+ public byte[] getHeader() {
+ byte[] header = new byte[16 + 8];
+ LittleEndian.putInt(header, 0, getSignature());
+ LittleEndian.putInt(header, 4, getRawData().length);
+ System.arraycopy(rawdata, 0, header, 8, 16);
+ return header;
+ }
+
+ /**
+ * Return image size in bytes
+ *
+ * @return the size of the picture in bytes
+ * @deprecated Use getData().length
instead.
+ */
+ public int getSize(){
+ return getData().length;
+ }
+
+ public void draw(Graphics2D graphics, HSLFPictureShape parent){
+ ImagePainter painter = painters[getType()];
+ if(painter != null) painter.paint(graphics, this, parent);
+ else logger.log(POILogger.WARN, "Rendering is not supported: " + getClass().getName());
+ }
+
+ /**
+ * Register ImagePainter for the specified image type
+ *
+ * @param type image type, must be one of the static constants defined in the Picture class.
+ * @param painter
+ */
+ public static void setImagePainter(int type, ImagePainter painter){
+ painters[type] = painter;
+ }
+
+ /**
+ * Return ImagePainter for the specified image type
+ *
+ * @param type blip type, must be one of the static constants defined in the Picture class.
+ * @return ImagePainter for the specified image type
+ */
+ public static ImagePainter getImagePainter(int type){
+ return painters[type];
+ }
+
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
new file mode 100644
index 0000000000..1f9f6ca027
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
@@ -0,0 +1,1163 @@
+/* ====================================================================
+ 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.Dimension;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.poi.ddf.EscherBSERecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.hpsf.ClassID;
+import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
+import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.Document;
+import org.apache.poi.hslf.record.DocumentAtom;
+import org.apache.poi.hslf.record.ExAviMovie;
+import org.apache.poi.hslf.record.ExControl;
+import org.apache.poi.hslf.record.ExEmbed;
+import org.apache.poi.hslf.record.ExEmbedAtom;
+import org.apache.poi.hslf.record.ExHyperlink;
+import org.apache.poi.hslf.record.ExHyperlinkAtom;
+import org.apache.poi.hslf.record.ExMCIMovie;
+import org.apache.poi.hslf.record.ExObjList;
+import org.apache.poi.hslf.record.ExObjListAtom;
+import org.apache.poi.hslf.record.ExOleObjAtom;
+import org.apache.poi.hslf.record.ExOleObjStg;
+import org.apache.poi.hslf.record.ExVideoContainer;
+import org.apache.poi.hslf.record.FontCollection;
+import org.apache.poi.hslf.record.FontEntityAtom;
+import org.apache.poi.hslf.record.HeadersFootersContainer;
+import org.apache.poi.hslf.record.PersistPtrHolder;
+import org.apache.poi.hslf.record.PositionDependentRecord;
+import org.apache.poi.hslf.record.PositionDependentRecordContainer;
+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.SlideListWithText;
+import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
+import org.apache.poi.hslf.record.SlidePersistAtom;
+import org.apache.poi.hslf.record.UserEditAtom;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.sl.usermodel.SlideShow;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+/**
+ * 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
+ *
+ * @author Nick Burch
+ * @author Yegor kozlov
+ */
+public final class HSLFSlideShow implements SlideShow {
+ // What we're based on
+ private HSLFSlideShowImpl _hslfSlideShow;
+
+ // Pointers to the most recent versions of the core records
+ // (Document, Notes, Slide etc)
+ private Record[] _mostRecentCoreRecords;
+ // Lookup between the PersitPtr "sheet" IDs, and the position
+ // in the mostRecentCoreRecords array
+ private Map _sheetIdToCoreRecordsLookup;
+
+ // Records that are interesting
+ private Document _documentRecord;
+
+ // Friendly objects for people to deal with
+ private SlideMaster[] _masters;
+ private TitleMaster[] _titleMasters;
+ private HSLFSlide[] _slides;
+ private HSLFNotes[] _notes;
+ private FontCollection _fonts;
+
+ // For logging
+ private POILogger logger = POILogFactory.getLogger(this.getClass());
+
+
+ /* ===============================================================
+ * Setup Code
+ * ===============================================================
+ */
+
+
+ /**
+ * Constructs a Powerpoint document from the underlying
+ * HSLFSlideShow object. Finds the model stuff from this
+ *
+ * @param hslfSlideShow the HSLFSlideShow to base on
+ */
+ public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) {
+ // Get useful things from our base slideshow
+ _hslfSlideShow = hslfSlideShow;
+
+ // Handle Parent-aware Records
+ for (Record record : _hslfSlideShow.getRecords()) {
+ if(record instanceof RecordContainer){
+ RecordContainer.handleParentAwareRecords((RecordContainer)record);
+ }
+ }
+
+ // Find the versions of the core records we'll want to use
+ findMostRecentCoreRecords();
+
+ // Build up the model level Slides and Notes
+ buildSlidesAndNotes();
+ }
+
+ /**
+ * Constructs a new, empty, Powerpoint document.
+ */
+ public HSLFSlideShow() {
+ this(HSLFSlideShowImpl.create());
+ }
+
+ /**
+ * Constructs a Powerpoint document from an input stream.
+ */
+ public HSLFSlideShow(InputStream inputStream) throws IOException {
+ this(new HSLFSlideShowImpl(inputStream));
+ }
+
+ /**
+ * Use the PersistPtrHolder entries to figure out what is the "most recent"
+ * version of all the core records (Document, Notes, Slide etc), and save a
+ * record of them. Do this by walking from the oldest PersistPtr to the
+ * newest, overwriting any references found along the way with newer ones
+ */
+ private void findMostRecentCoreRecords() {
+ // To start with, find the most recent in the byte offset domain
+ Map mostRecentByBytes = new HashMap();
+ for (Record record : _hslfSlideShow.getRecords()) {
+ if (record instanceof PersistPtrHolder) {
+ PersistPtrHolder pph = (PersistPtrHolder) record;
+
+ // If we've already seen any of the "slide" IDs for this
+ // PersistPtr, remove their old positions
+ int[] ids = pph.getKnownSlideIDs();
+ for (int id : ids) {
+ if (mostRecentByBytes.containsKey(id)) {
+ mostRecentByBytes.remove(id);
+ }
+ }
+
+ // Now, update the byte level locations with their latest values
+ Map thisSetOfLocations = pph.getSlideLocationsLookup();
+ for (int id : ids) {
+ mostRecentByBytes.put(id, thisSetOfLocations.get(id));
+ }
+ }
+ }
+
+ // We now know how many unique special records we have, so init
+ // the array
+ _mostRecentCoreRecords = new Record[mostRecentByBytes.size()];
+
+ // We'll also want to be able to turn the slide IDs into a position
+ // in this array
+ _sheetIdToCoreRecordsLookup = new HashMap();
+ Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]);
+ Arrays.sort(allIDs);
+ for (int i = 0; i < allIDs.length; i++) {
+ _sheetIdToCoreRecordsLookup.put(allIDs[i], i);
+ }
+
+ Map mostRecentByBytesRev = new HashMap(mostRecentByBytes.size());
+ for (Map.Entry me : mostRecentByBytes.entrySet()) {
+ mostRecentByBytesRev.put(me.getValue(), me.getKey());
+ }
+
+ // Now convert the byte offsets back into record offsets
+ for (Record record : _hslfSlideShow.getRecords()) {
+ if (!(record instanceof PositionDependentRecord)) continue;
+
+ PositionDependentRecord pdr = (PositionDependentRecord) record;
+ int recordAt = pdr.getLastOnDiskOffset();
+
+ Integer thisID = mostRecentByBytesRev.get(recordAt);
+
+ if (thisID == null) continue;
+
+ // Bingo. Now, where do we store it?
+ int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
+
+ // Tell it its Sheet ID, if it cares
+ if (pdr instanceof PositionDependentRecordContainer) {
+ PositionDependentRecordContainer pdrc = (PositionDependentRecordContainer) record;
+ pdrc.setSheetId(thisID);
+ }
+
+ // Finally, save the record
+ _mostRecentCoreRecords[storeAt] = record;
+ }
+
+ // Now look for the interesting records in there
+ for (Record record : _mostRecentCoreRecords) {
+ // Check there really is a record at this number
+ if (record != null) {
+ // Find the Document, and interesting things in it
+ if (record.getRecordType() == RecordTypes.Document.typeID) {
+ _documentRecord = (Document) record;
+ _fonts = _documentRecord.getEnvironment().getFontCollection();
+ }
+ } else {
+ // No record at this number
+ // Odd, but not normally a problem
+ }
+ }
+ }
+
+ /**
+ * For a given SlideAtomsSet, return the core record, based on the refID
+ * from the SlidePersistAtom
+ */
+ private Record getCoreRecordForSAS(SlideAtomsSet sas) {
+ SlidePersistAtom spa = sas.getSlidePersistAtom();
+ int refID = spa.getRefID();
+ return getCoreRecordForRefID(refID);
+ }
+
+ /**
+ * For a given refID (the internal, 0 based numbering scheme), return the
+ * core record
+ *
+ * @param refID
+ * the refID
+ */
+ private Record getCoreRecordForRefID(int refID) {
+ Integer coreRecordId = _sheetIdToCoreRecordsLookup.get(refID);
+ if (coreRecordId != null) {
+ Record r = _mostRecentCoreRecords[coreRecordId];
+ return r;
+ }
+ logger.log(POILogger.ERROR,
+ "We tried to look up a reference to a core record, but there was no core ID for reference ID "
+ + refID);
+ return null;
+ }
+
+ /**
+ * Build up model level Slide and Notes objects, from the underlying
+ * records.
+ */
+ private void buildSlidesAndNotes() {
+ // Ensure we really found a Document record earlier
+ // If we didn't, then the file is probably corrupt
+ if (_documentRecord == null) {
+ throw new CorruptPowerPointFileException(
+ "The PowerPoint file didn't contain a Document Record in its PersistPtr blocks. It is probably corrupt.");
+ }
+
+ // Fetch the SlideListWithTexts in the most up-to-date Document Record
+ //
+ // As far as we understand it:
+ // * The first SlideListWithText will contain a SlideAtomsSet
+ // for each of the master slides
+ // * The second SlideListWithText will contain a SlideAtomsSet
+ // for each of the slides, in their current order
+ // These SlideAtomsSets will normally contain text
+ // * The third SlideListWithText (if present), will contain a
+ // SlideAtomsSet for each Notes
+ // These SlideAtomsSets will not normally contain text
+ //
+ // Having indentified the masters, slides and notes + their orders,
+ // we have to go and find their matching records
+ // We always use the latest versions of these records, and use the
+ // SlideAtom/NotesAtom to match them with the StyleAtomSet
+
+ SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText();
+ SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
+ SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
+
+ // Find master slides
+ // These can be MainMaster records, but oddly they can also be
+ // Slides or Notes, and possibly even other odd stuff....
+ // About the only thing you can say is that the master details are in
+ // the first SLWT.
+ SlideAtomsSet[] masterSets = new SlideAtomsSet[0];
+ if (masterSLWT != null) {
+ masterSets = masterSLWT.getSlideAtomsSets();
+
+ ArrayList mmr = new ArrayList();
+ ArrayList tmr = new ArrayList();
+
+ for (SlideAtomsSet sas : masterSets) {
+ Record r = getCoreRecordForSAS(sas);
+ int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
+ if (r instanceof org.apache.poi.hslf.record.Slide) {
+ TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide) r,
+ sheetNo);
+ master.setSlideShow(this);
+ tmr.add(master);
+ } else if (r instanceof org.apache.poi.hslf.record.MainMaster) {
+ SlideMaster master = new SlideMaster((org.apache.poi.hslf.record.MainMaster) r,
+ sheetNo);
+ master.setSlideShow(this);
+ mmr.add(master);
+ }
+ }
+
+ _masters = mmr.toArray(new SlideMaster[mmr.size()]);
+ _titleMasters = tmr.toArray(new TitleMaster[tmr.size()]);
+ }
+
+ // Having sorted out the masters, that leaves the notes and slides
+
+ // Start by finding the notes records to go with the entries in
+ // notesSLWT
+ org.apache.poi.hslf.record.Notes[] notesRecords;
+ SlideAtomsSet[] notesSets = new SlideAtomsSet[0];
+ Map slideIdToNotes = new HashMap();
+ if (notesSLWT == null) {
+ // None
+ notesRecords = new org.apache.poi.hslf.record.Notes[0];
+ } else {
+ // Match up the records and the SlideAtomSets
+ notesSets = notesSLWT.getSlideAtomsSets();
+ List notesRecordsL =
+ new ArrayList();
+ for (int i = 0; i < notesSets.length; i++) {
+ // Get the right core record
+ Record r = getCoreRecordForSAS(notesSets[i]);
+
+ // Ensure it really is a notes record
+ if (r == null || r instanceof org.apache.poi.hslf.record.Notes) {
+ if (r == null) {
+ logger.log(POILogger.WARN, "A Notes SlideAtomSet at " + i
+ + " said its record was at refID "
+ + notesSets[i].getSlidePersistAtom().getRefID()
+ + ", but that record didn't exist - record ignored.");
+ }
+ // we need to add also null-records, otherwise the index references to other existing
+ // don't work anymore
+ org.apache.poi.hslf.record.Notes notesRecord = (org.apache.poi.hslf.record.Notes) r;
+ notesRecordsL.add(notesRecord);
+
+ // Record the match between slide id and these notes
+ SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
+ int slideId = spa.getSlideIdentifier();
+ slideIdToNotes.put(slideId, i);
+ } else {
+ logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i
+ + " said its record was at refID "
+ + notesSets[i].getSlidePersistAtom().getRefID()
+ + ", but that was actually a " + r);
+ }
+ }
+ notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()];
+ notesRecords = notesRecordsL.toArray(notesRecords);
+ }
+
+ // Now, do the same thing for our slides
+ org.apache.poi.hslf.record.Slide[] slidesRecords;
+ SlideAtomsSet[] slidesSets = new SlideAtomsSet[0];
+ if (slidesSLWT == null) {
+ // None
+ slidesRecords = new org.apache.poi.hslf.record.Slide[0];
+ } else {
+ // Match up the records and the SlideAtomSets
+ slidesSets = slidesSLWT.getSlideAtomsSets();
+ slidesRecords = new org.apache.poi.hslf.record.Slide[slidesSets.length];
+ for (int i = 0; i < slidesSets.length; i++) {
+ // Get the right core record
+ Record r = getCoreRecordForSAS(slidesSets[i]);
+
+ // Ensure it really is a slide record
+ if (r instanceof org.apache.poi.hslf.record.Slide) {
+ slidesRecords[i] = (org.apache.poi.hslf.record.Slide) r;
+ } else {
+ logger.log(POILogger.ERROR, "A Slide SlideAtomSet at " + i
+ + " said its record was at refID "
+ + slidesSets[i].getSlidePersistAtom().getRefID()
+ + ", but that was actually a " + r);
+ }
+ }
+ }
+
+ // Finally, generate model objects for everything
+ // Notes first
+ _notes = new HSLFNotes[notesRecords.length];
+ for (int i = 0; i < _notes.length; i++) {
+ if (notesRecords[i] != null) {
+ _notes[i] = new HSLFNotes(notesRecords[i]);
+ _notes[i].setSlideShow(this);
+ }
+ }
+ // Then slides
+ _slides = new HSLFSlide[slidesRecords.length];
+ for (int i = 0; i < _slides.length; i++) {
+ SlideAtomsSet sas = slidesSets[i];
+ int slideIdentifier = sas.getSlidePersistAtom().getSlideIdentifier();
+
+ // Do we have a notes for this?
+ HSLFNotes notes = null;
+ // Slide.SlideAtom.notesId references the corresponding notes slide.
+ // 0 if slide has no notes.
+ int noteId = slidesRecords[i].getSlideAtom().getNotesID();
+ if (noteId != 0) {
+ Integer notesPos = slideIdToNotes.get(noteId);
+ if (notesPos != null) {
+ notes = _notes[notesPos];
+ } else {
+ logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId);
+ }
+ }
+
+ // Now, build our slide
+ _slides[i] = new HSLFSlide(slidesRecords[i], notes, sas, slideIdentifier, (i + 1));
+ _slides[i].setSlideShow(this);
+ }
+ }
+
+ /**
+ * Writes out the slideshow file the is represented by an instance of this
+ * class
+ *
+ * @param out
+ * The OutputStream to write to.
+ * @throws IOException
+ * If there is an unexpected IOException from the passed in
+ * OutputStream
+ */
+ public void write(OutputStream out) throws IOException {
+ _hslfSlideShow.write(out);
+ }
+
+ /*
+ * ===============================================================
+ * Accessor Code
+ * ===============================================================
+ */
+
+ /**
+ * Returns an array of the most recent version of all the interesting
+ * records
+ */
+ public Record[] getMostRecentCoreRecords() {
+ return _mostRecentCoreRecords;
+ }
+
+ /**
+ * Returns an array of all the normal Slides found in the slideshow
+ */
+ public HSLFSlide[] getSlides() {
+ return _slides;
+ }
+
+ /**
+ * Returns an array of all the normal Notes found in the slideshow
+ */
+ public HSLFNotes[] getNotes() {
+ return _notes;
+ }
+
+ /**
+ * Returns an array of all the normal Slide Masters found in the slideshow
+ */
+ public SlideMaster[] getSlidesMasters() {
+ return _masters;
+ }
+
+ /**
+ * Returns an array of all the normal Title Masters found in the slideshow
+ */
+ public TitleMaster[] getTitleMasters() {
+ return _titleMasters;
+ }
+
+ /**
+ * Returns the data of all the pictures attached to the SlideShow
+ */
+ public HSLFPictureData[] getPictureData() {
+ return _hslfSlideShow.getPictures();
+ }
+
+ /**
+ * Returns the data of all the embedded OLE object in the SlideShow
+ */
+ public HSLFObjectData[] getEmbeddedObjects() {
+ return _hslfSlideShow.getEmbeddedObjects();
+ }
+
+ /**
+ * Returns the data of all the embedded sounds in the SlideShow
+ */
+ public HSLFSoundData[] getSoundData() {
+ return HSLFSoundData.find(_documentRecord);
+ }
+
+ /**
+ * Return the current page size
+ */
+ public Dimension getPageSize() {
+ DocumentAtom docatom = _documentRecord.getDocumentAtom();
+ int pgx = (int) docatom.getSlideSizeX() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
+ int pgy = (int) docatom.getSlideSizeY() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
+ return new Dimension(pgx, pgy);
+ }
+
+ /**
+ * Change the current page size
+ *
+ * @param pgsize
+ * page size (in points)
+ */
+ public void setPageSize(Dimension pgsize) {
+ DocumentAtom docatom = _documentRecord.getDocumentAtom();
+ docatom.setSlideSizeX(pgsize.width * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
+ docatom.setSlideSizeY(pgsize.height * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
+ }
+
+ /**
+ * Helper method for usermodel: Get the font collection
+ */
+ protected FontCollection getFontCollection() {
+ return _fonts;
+ }
+
+ /**
+ * Helper method for usermodel and model: Get the document record
+ */
+ public Document getDocumentRecord() {
+ return _documentRecord;
+ }
+
+ /*
+ * ===============================================================
+ * Re-ordering Code
+ * ===============================================================
+ */
+
+ /**
+ * Re-orders a slide, to a new position.
+ *
+ * @param oldSlideNumber
+ * The old slide number (1 based)
+ * @param newSlideNumber
+ * The new slide number (1 based)
+ */
+ public void reorderSlide(int oldSlideNumber, int newSlideNumber) {
+ // Ensure these numbers are valid
+ if (oldSlideNumber < 1 || newSlideNumber < 1) {
+ throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
+ }
+ if (oldSlideNumber > _slides.length || newSlideNumber > _slides.length) {
+ throw new IllegalArgumentException(
+ "Old and new slide numbers must not exceed the number of slides ("
+ + _slides.length + ")");
+ }
+
+ // The order of slides is defined by the order of slide atom sets in the
+ // SlideListWithText container.
+ SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
+ SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
+
+ SlideAtomsSet tmp = sas[oldSlideNumber - 1];
+ sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
+ sas[newSlideNumber - 1] = tmp;
+
+ ArrayList lst = new ArrayList();
+ for (int i = 0; i < sas.length; i++) {
+ lst.add(sas[i].getSlidePersistAtom());
+ Record[] r = sas[i].getSlideRecords();
+ for (int j = 0; j < r.length; j++) {
+ lst.add(r[j]);
+ }
+ _slides[i].setSlideNumber(i + 1);
+ }
+ Record[] r = lst.toArray(new Record[lst.size()]);
+ slwt.setChildRecord(r);
+ }
+
+ /**
+ * Removes the slide at the given index (0-based).
+ *
+ * Shifts any subsequent slides to the left (subtracts one from their slide
+ * numbers).
+ *
+ *
+ * @param index
+ * the index of the slide to remove (0-based)
+ * @return the slide that was removed from the slide show.
+ */
+ public HSLFSlide removeSlide(int index) {
+ int lastSlideIdx = _slides.length - 1;
+ if (index < 0 || index > lastSlideIdx) {
+ throw new IllegalArgumentException("Slide index (" + index + ") is out of range (0.."
+ + lastSlideIdx + ")");
+ }
+
+ SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
+ SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
+
+ HSLFSlide removedSlide = null;
+ ArrayList records = new ArrayList();
+ ArrayList sa = new ArrayList();
+ ArrayList sl = new ArrayList();
+
+ ArrayList nt = new ArrayList();
+ for (HSLFNotes notes : getNotes())
+ nt.add(notes);
+
+ for (int i = 0, num = 0; i < _slides.length; i++) {
+ if (i != index) {
+ sl.add(_slides[i]);
+ sa.add(sas[i]);
+ _slides[i].setSlideNumber(num++);
+ records.add(sas[i].getSlidePersistAtom());
+ records.addAll(Arrays.asList(sas[i].getSlideRecords()));
+ } else {
+ removedSlide = _slides[i];
+ nt.remove(_slides[i].getNotesSheet());
+ }
+ }
+ if (sa.size() == 0) {
+ _documentRecord.removeSlideListWithText(slwt);
+ } else {
+ slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
+ slwt.setChildRecord(records.toArray(new Record[records.size()]));
+ }
+ _slides = sl.toArray(new HSLFSlide[sl.size()]);
+
+ // if the removed slide had notes - remove references to them too
+
+ if (removedSlide != null) {
+ int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
+ if (notesId != 0) {
+ SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
+ records = new ArrayList();
+ ArrayList na = new ArrayList();
+ for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
+ if (ns.getSlidePersistAtom().getSlideIdentifier() != notesId) {
+ na.add(ns);
+ records.add(ns.getSlidePersistAtom());
+ if (ns.getSlideRecords() != null)
+ records.addAll(Arrays.asList(ns.getSlideRecords()));
+ }
+ }
+ if (na.size() == 0) {
+ _documentRecord.removeSlideListWithText(nslwt);
+ } else {
+ nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()]));
+ nslwt.setChildRecord(records.toArray(new Record[records.size()]));
+ }
+
+ }
+ }
+ _notes = nt.toArray(new HSLFNotes[nt.size()]);
+
+ return removedSlide;
+ }
+
+ /*
+ * ===============================================================
+ * Addition Code
+ * ===============================================================
+ */
+
+ /**
+ * Create a blank Slide
.
+ *
+ * @return the created Slide
+ */
+ public HSLFSlide createSlide() {
+ 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();
+ slist.setInstance(SlideListWithText.SLIDES);
+ _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;
+ for (SlideAtomsSet sas : slist.getSlideAtomsSets()) {
+ SlidePersistAtom spa = sas.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
+ HSLFSlide slide = new HSLFSlide(sp.getSlideIdentifier(), sp.getRefID(), _slides.length + 1);
+ slide.setSlideShow(this);
+ slide.onCreate();
+
+ // Add in to the list of Slides
+ HSLFSlide[] s = new HSLFSlide[_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 psrId = addPersistentObject(slideRecord);
+ sp.setRefID(psrId);
+ slideRecord.setSheetId(psrId);
+
+ slide.setMasterSheet(_masters[0]);
+ // All done and added
+ return slide;
+ }
+
+ /**
+ * Adds a picture to this presentation and returns the associated index.
+ *
+ * @param data
+ * picture data
+ * @param format
+ * the format of the picture. One of constans defined in the
+ * Picture
class.
+ * @return the index to this picture (1 based).
+ */
+ public int addPicture(byte[] data, int format) throws IOException {
+ byte[] uid = HSLFPictureData.getChecksum(data);
+
+ EscherContainerRecord bstore;
+
+ EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
+ bstore = (EscherContainerRecord) HSLFShape.getEscherChild(dggContainer,
+ EscherContainerRecord.BSTORE_CONTAINER);
+ if (bstore == null) {
+ bstore = new EscherContainerRecord();
+ bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
+
+ dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
+ } else {
+ Iterator iter = bstore.getChildIterator();
+ for (int i = 0; iter.hasNext(); i++) {
+ EscherBSERecord bse = (EscherBSERecord) iter.next();
+ if (Arrays.equals(bse.getUid(), uid)) {
+ return i + 1;
+ }
+ }
+ }
+
+ HSLFPictureData pict = HSLFPictureData.create(format);
+ pict.setData(data);
+
+ int offset = _hslfSlideShow.addPicture(pict);
+
+ 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 == HSLFPictureShape.EMF)
+ bse.setBlipTypeMacOS((byte) HSLFPictureShape.PICT);
+ else if (format == HSLFPictureShape.WMF)
+ bse.setBlipTypeMacOS((byte) HSLFPictureShape.PICT);
+ else if (format == HSLFPictureShape.PICT)
+ bse.setBlipTypeWin32((byte) HSLFPictureShape.WMF);
+
+ bse.setRef(0);
+ bse.setOffset(offset);
+ bse.setRemainingData(new byte[0]);
+
+ bstore.addChildRecord(bse);
+ int count = bstore.getChildRecords().size();
+ bstore.setOptions((short) ((count << 4) | 0xF));
+
+ return count;
+ }
+
+ /**
+ * Adds a picture to this presentation and returns the associated index.
+ *
+ * @param pict
+ * the file containing the image to add
+ * @param format
+ * the format of the picture. One of constans defined in the
+ * Picture
class.
+ * @return the index to this picture (1 based).
+ */
+ public int addPicture(File pict, int format) throws IOException {
+ int length = (int) pict.length();
+ byte[] data = new byte[length];
+ FileInputStream is = null;
+ try {
+ is = new FileInputStream(pict);
+ is.read(data);
+ } finally {
+ if(is != null) is.close();
+ }
+ return addPicture(data, format);
+ }
+
+ /**
+ * Add a font in this presentation
+ *
+ * @param font
+ * the font to add
+ * @return 0-based index of the font
+ */
+ 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;
+ }
+
+ /**
+ * Get a font by index
+ *
+ * @param idx
+ * 0-based index of the font
+ * @return of an instance of PPFont
or null
if not
+ * found
+ */
+ public PPFont getFont(int idx) {
+ FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
+ for (Record ch : fonts.getChildRecords()) {
+ if (ch instanceof FontEntityAtom) {
+ FontEntityAtom atom = (FontEntityAtom) ch;
+ if (atom.getFontIndex() == idx) {
+ return new PPFont(atom);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * get the number of fonts in the presentation
+ *
+ * @return number of fonts
+ */
+ public int getNumberOfFonts() {
+ return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts();
+ }
+
+ /**
+ * Return Header / Footer settings for slides
+ *
+ * @return Header / Footer settings for slides
+ */
+ public HeadersFooters getSlideHeadersFooters() {
+ // detect if this ppt was saved in Office2007
+ String tag = getSlidesMasters()[0].getProgrammableTag();
+ boolean ppt2007 = "___PPT12".equals(tag);
+
+ HeadersFootersContainer hdd = null;
+ for (Record ch : _documentRecord.getChildRecords()) {
+ if (ch instanceof HeadersFootersContainer
+ && ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) {
+ hdd = (HeadersFootersContainer) ch;
+ break;
+ }
+ }
+ boolean newRecord = false;
+ if (hdd == null) {
+ hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
+ newRecord = true;
+ }
+ return new HeadersFooters(hdd, this, newRecord, ppt2007);
+ }
+
+ /**
+ * Return Header / Footer settings for notes
+ *
+ * @return Header / Footer settings for notes
+ */
+ public HeadersFooters getNotesHeadersFooters() {
+ // detect if this ppt was saved in Office2007
+ String tag = getSlidesMasters()[0].getProgrammableTag();
+ boolean ppt2007 = "___PPT12".equals(tag);
+
+ HeadersFootersContainer hdd = null;
+ for (Record ch : _documentRecord.getChildRecords()) {
+ if (ch instanceof HeadersFootersContainer
+ && ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) {
+ hdd = (HeadersFootersContainer) ch;
+ break;
+ }
+ }
+ boolean newRecord = false;
+ if (hdd == null) {
+ hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);
+ newRecord = true;
+ }
+ if (ppt2007 && _notes.length > 0) {
+ return new HeadersFooters(hdd, _notes[0], newRecord, ppt2007);
+ }
+ return new HeadersFooters(hdd, this, newRecord, ppt2007);
+ }
+
+ /**
+ * Add a movie in this presentation
+ *
+ * @param path
+ * the path or url to the movie
+ * @return 0-based index of the movie
+ */
+ public int addMovie(String path, int type) {
+ ExMCIMovie mci;
+ switch (type) {
+ case MovieShape.MOVIE_MPEG:
+ mci = new ExMCIMovie();
+ break;
+ case MovieShape.MOVIE_AVI:
+ mci = new ExAviMovie();
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported Movie: " + type);
+ }
+
+ ExVideoContainer exVideo = mci.getExVideo();
+ exVideo.getExMediaAtom().setMask(0xE80000);
+ exVideo.getPathAtom().setText(path);
+
+ int objectId = addToObjListAtom(mci);
+ exVideo.getExMediaAtom().setObjectId(objectId);
+
+ return objectId;
+ }
+
+ /**
+ * Add a control in this presentation
+ *
+ * @param name
+ * name of the control, e.g. "Shockwave Flash Object"
+ * @param progId
+ * OLE Programmatic Identifier, e.g.
+ * "ShockwaveFlash.ShockwaveFlash.9"
+ * @return 0-based index of the control
+ */
+ public int addControl(String name, String progId) {
+ ExControl ctrl = new ExControl();
+ ctrl.setProgId(progId);
+ ctrl.setMenuName(name);
+ ctrl.setClipboardName(name);
+
+ ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
+ oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
+ oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
+
+ int objectId = addToObjListAtom(ctrl);
+ oleObj.setObjID(objectId);
+ return objectId;
+ }
+
+ /**
+ * Add a hyperlink to this presentation
+ *
+ * @return 0-based index of the hyperlink
+ */
+ public int addHyperlink(Hyperlink link) {
+ ExHyperlink ctrl = new ExHyperlink();
+ ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
+ if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
+ ctrl.setLinkURL(link.getAddress(), 0x30);
+ } else {
+ ctrl.setLinkURL(link.getAddress());
+ }
+ ctrl.setLinkTitle(link.getTitle());
+
+ int objectId = addToObjListAtom(ctrl);
+ link.setId(objectId);
+ obj.setNumber(objectId);
+
+ return objectId;
+ }
+
+ /**
+ * Add a embedded object to this presentation
+ *
+ * @return 0-based index of the embedded object
+ */
+ public int addEmbed(POIFSFileSystem poiData) {
+ DirectoryNode root = poiData.getRoot();
+
+ // prepare embedded data
+ if (new ClassID().equals(root.getStorageClsid())) {
+ // need to set class id
+ Map olemap = getOleMap();
+ ClassID classID = null;
+ for (Map.Entry entry : olemap.entrySet()) {
+ if (root.hasEntry(entry.getKey())) {
+ classID = entry.getValue();
+ break;
+ }
+ }
+ if (classID == null) {
+ throw new IllegalArgumentException("Unsupported embedded document");
+ }
+
+ root.setStorageClsid(classID);
+ }
+
+ ExEmbed exEmbed = new ExEmbed();
+ // remove unneccessary infos, so we don't need to specify the type
+ // of the ole object multiple times
+ Record children[] = exEmbed.getChildRecords();
+ exEmbed.removeChild(children[2]);
+ exEmbed.removeChild(children[3]);
+ exEmbed.removeChild(children[4]);
+
+ ExEmbedAtom eeEmbed = exEmbed.getExEmbedAtom();
+ eeEmbed.setCantLockServerB(true);
+
+ ExOleObjAtom eeAtom = exEmbed.getExOleObjAtom();
+ eeAtom.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
+ eeAtom.setType(ExOleObjAtom.TYPE_EMBEDDED);
+ // eeAtom.setSubType(ExOleObjAtom.SUBTYPE_EXCEL);
+ // should be ignored?!?, see MS-PPT ExOleObjAtom, but Libre Office sets it ...
+ eeAtom.setOptions(1226240);
+
+ ExOleObjStg exOleObjStg = new ExOleObjStg();
+ try {
+ final String OLESTREAM_NAME = "\u0001Ole";
+ if (!root.hasEntry(OLESTREAM_NAME)) {
+ // the following data was taken from an example libre office document
+ // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
+ // OlePresXXX, but it seems, that they aren't neccessary
+ byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ poiData.createDocument(new ByteArrayInputStream(oleBytes), OLESTREAM_NAME);
+ }
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ poiData.writeFilesystem(bos);
+ exOleObjStg.setData(bos.toByteArray());
+ } catch (IOException e) {
+ throw new HSLFException(e);
+ }
+
+ int psrId = addPersistentObject(exOleObjStg);
+ exOleObjStg.setPersistId(psrId);
+ eeAtom.setObjStgDataRef(psrId);
+
+ int objectId = addToObjListAtom(exEmbed);
+ eeAtom.setObjID(objectId);
+ return objectId;
+ }
+
+ protected int addToObjListAtom(RecordContainer exObj) {
+ ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
+ if (lst == null) {
+ lst = new ExObjList();
+ _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
+ }
+ ExObjListAtom objAtom = lst.getExObjListAtom();
+ // increment the object ID seed
+ int objectId = (int) objAtom.getObjectIDSeed() + 1;
+ objAtom.setObjectIDSeed(objectId);
+
+ lst.addChildAfter(exObj, objAtom);
+
+ return objectId;
+ }
+
+ protected static Map getOleMap() {
+ Map olemap = new HashMap();
+ olemap.put("PowerPoint Document", ClassID.PPT_SHOW);
+ olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
+ olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
+ olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
+ // ... to be continued
+ return olemap;
+ }
+
+ protected int addPersistentObject(PositionDependentRecord slideRecord) {
+ slideRecord.setLastOnDiskOffset(HSLFSlideShowImpl.UNSET_OFFSET);
+ _hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
+
+ // For position dependent records, hold where they were and now are
+ // As we go along, update, and hand over, to any Position Dependent
+ // records we happen across
+ Map interestingRecords =
+ new HashMap();
+
+ try {
+ _hslfSlideShow.updateAndWriteDependantRecords(null,interestingRecords);
+ } catch (IOException e) {
+ throw new HSLFException(e);
+ }
+
+ PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
+ UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
+
+ // persist ID is UserEditAtom.maxPersistWritten + 1
+ int psrId = usr.getMaxPersistWritten() + 1;
+
+ // Last view is now of the slide
+ usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
+ // increment the number of persistent objects
+ usr.setMaxPersistWritten(psrId);
+
+ // Add the new slide into the last PersistPtr
+ // (Also need to tell it where it is)
+ int slideOffset = slideRecord.getLastOnDiskOffset();
+ slideRecord.setLastOnDiskOffset(slideOffset);
+ ptr.addSlideLookup(psrId, slideOffset);
+ logger.log(POILogger.INFO, "New slide/object ended up at " + slideOffset);
+
+ return psrId;
+ }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java
new file mode 100644
index 0000000000..7750b25f15
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java
@@ -0,0 +1,94 @@
+/* ====================================================================
+ 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 org.apache.poi.hslf.record.*;
+
+import java.util.ArrayList;
+
+/**
+ * A class that represents sound data embedded in a slide show.
+ *
+ * @author Yegor Kozlov
+ */
+public final class HSLFSoundData {
+ /**
+ * The record that contains the object data.
+ */
+ private Sound _container;
+
+ /**
+ * Creates the object data wrapping the record that contains the sound data.
+ *
+ * @param container the record that contains the sound data.
+ */
+ public HSLFSoundData(Sound container) {
+ this._container = container;
+ }
+
+ /**
+ * Name of the sound (e.g. "crash")
+ *
+ * @return name of the sound
+ */
+ public String getSoundName(){
+ return _container.getSoundName();
+ }
+
+ /**
+ * Type of the sound (e.g. ".wav")
+ *
+ * @return type of the sound
+ */
+ public String getSoundType(){
+ return _container.getSoundType();
+ }
+
+ /**
+ * Gets an input stream which returns the binary of the sound data.
+ *
+ * @return the input stream which will contain the binary of the sound data.
+ */
+ public byte[] getData() {
+ return _container.getSoundData();
+ }
+
+ /**
+ * Find all sound records in the supplied Document records
+ *
+ * @param document the document to find in
+ * @return the array with the sound data
+ */
+ public static HSLFSoundData[] find(Document document){
+ ArrayList lst = new ArrayList();
+ Record[] ch = document.getChildRecords();
+ for (int i = 0; i < ch.length; i++) {
+ if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){
+ RecordContainer col = (RecordContainer)ch[i];
+ Record[] sr = col.getChildRecords();
+ for (int j = 0; j < sr.length; j++) {
+ if(sr[j] instanceof Sound){
+ lst.add(new HSLFSoundData((Sound)sr[j]));
+ }
+ }
+ }
+
+ }
+ return lst.toArray(new HSLFSoundData[lst.size()]);
+ }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
new file mode 100644
index 0000000000..06980e9ff5
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextRun.java
@@ -0,0 +1,793 @@
+/* ====================================================================
+ 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.Color;
+
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
+import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
+import org.apache.poi.hslf.model.textproperties.TextProp;
+import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.sl.usermodel.TextRun;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+
+/**
+ * Represents a run of text, all with the same style
+ *
+ */
+public final class HSLFTextRun implements TextRun {
+ protected POILogger logger = POILogFactory.getLogger(this.getClass());
+
+ /** The TextRun we belong to */
+ private HSLFTextParagraph parentParagraph;
+ /** The SlideShow we belong to */
+ // private SlideShow slideShow;
+
+ /** Where in the parent TextRun we start from */
+ private int startPos;
+
+ /** How long a string (in the parent TextRun) we represent */
+ private int length;
+
+ private String _fontname;
+ /**
+ * Our paragraph and character style.
+ * Note - we may share these styles with other RichTextRuns
+ */
+ private TextPropCollection paragraphStyle;
+ private TextPropCollection characterStyle;
+ private boolean sharingParagraphStyle;
+ private boolean sharingCharacterStyle;
+
+ /**
+ * Create a new wrapper around a (currently not)
+ * rich text string
+ * @param parent
+ * @param startAt
+ * @param len
+ */
+ public HSLFTextRun(HSLFTextParagraph parent, int startAt, int len) {
+ this(parent, startAt, len, null, null, false, false);
+ }
+ /**
+ * Create a new wrapper around a rich text string
+ * @param parent The parent TextRun
+ * @param startAt The start position of this run
+ * @param len The length of this run
+ * @param pStyle The paragraph style property collection
+ * @param cStyle The character style property collection
+ * @param pShared The paragraph styles are shared with other runs
+ * @param cShared The character styles are shared with other runs
+ */
+ public HSLFTextRun(HSLFTextParagraph parent, int startAt, int len,
+ TextPropCollection pStyle, TextPropCollection cStyle,
+ boolean pShared, boolean cShared) {
+ parentParagraph = parent;
+ startPos = startAt;
+ length = len;
+ paragraphStyle = pStyle;
+ characterStyle = cStyle;
+ sharingParagraphStyle = pShared;
+ sharingCharacterStyle = cShared;
+ }
+
+ /**
+ * Supply (normally default) textprops, and if they're shared,
+ * when a run gets them
+ */
+ public void supplyTextProps(TextPropCollection pStyle, TextPropCollection cStyle, boolean pShared, boolean cShared) {
+ if(paragraphStyle != null || characterStyle != null) {
+ throw new IllegalStateException("Can't call supplyTextProps if run already has some");
+ }
+ paragraphStyle = pStyle;
+ characterStyle = cStyle;
+ sharingParagraphStyle = pShared;
+ sharingCharacterStyle = cShared;
+ }
+ /**
+ * Supply the SlideShow we belong to
+ */
+ public void updateSheet() {
+ if (_fontname != null) {
+ setFontName(_fontname);
+ _fontname = null;
+ }
+ }
+
+ /**
+ * Get the length of the text
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * The beginning index, inclusive.
+ *
+ * @return the beginning index, inclusive.
+ */
+ public int getStartIndex(){
+ return startPos;
+ }
+
+ /**
+ * The ending index, exclusive.
+ *
+ * @return the ending index, exclusive.
+ */
+ public int getEndIndex(){
+ return startPos + length;
+ }
+
+ /**
+ * Fetch the text, in output suitable form
+ */
+ public String getText() {
+ return parentParagraph.getText().substring(startPos, startPos+length);
+ }
+ /**
+ * Fetch the text, in raw storage form
+ */
+ public String getRawText() {
+ return parentParagraph.getRawText().substring(startPos, startPos+length);
+ }
+
+ /**
+ * Change the text
+ */
+ public void setText(String text) {
+ String s = parentParagraph.normalize(text);
+ setRawText(s);
+ }
+
+ /**
+ * Change the text
+ */
+ public void setRawText(String text) {
+ length = text.length();
+ parentParagraph.changeTextInRichTextRun(this,text);
+ }
+
+ /**
+ * Tells the RichTextRun its new position in the parent TextRun
+ * @param startAt
+ */
+ public void updateStartPosition(int startAt) {
+ startPos = startAt;
+ }
+
+
+ // --------------- Internal helpers on rich text properties -------
+
+ /**
+ * Fetch the value of the given flag in the CharFlagsTextProp.
+ * Returns false if the CharFlagsTextProp isn't present, since the
+ * text property won't be set if there's no CharFlagsTextProp.
+ */
+ private boolean isCharFlagsTextPropVal(int index) {
+ return getFlag(true, index);
+ }
+
+ private boolean getFlag(boolean isCharacter, int index) {
+ TextPropCollection props;
+ String propname;
+ if (isCharacter){
+ props = characterStyle;
+ propname = CharFlagsTextProp.NAME;
+ } else {
+ props = paragraphStyle;
+ propname = ParagraphFlagsTextProp.NAME;
+ }
+
+ BitMaskTextProp prop = null;
+ if (props != null){
+ prop = (BitMaskTextProp)props.findByName(propname);
+ }
+ if (prop == null){
+ HSLFSheet sheet = parentParagraph.getSheet();
+ if(sheet != null){
+ int txtype = parentParagraph.getRunType();
+ HSLFMasterSheet master = sheet.getMasterSheet();
+ if (master != null){
+ prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter);
+ }
+ } else {
+ logger.log(POILogger.WARN, "MasterSheet is not available");
+ }
+ }
+
+ return prop == null ? false : prop.getSubValue(index);
+ }
+
+ /**
+ * Set the value of the given flag in the CharFlagsTextProp, adding
+ * it if required.
+ */
+ private void setCharFlagsTextPropVal(int index, boolean value) {
+ if(getFlag(true, index) != value) setFlag(true, index, value);
+ }
+
+ public void setFlag(boolean isCharacter, int index, boolean value) {
+ TextPropCollection props;
+ String propname;
+ if (isCharacter){
+ props = characterStyle;
+ propname = CharFlagsTextProp.NAME;
+ } else {
+ props = paragraphStyle;
+ propname = ParagraphFlagsTextProp.NAME;
+ }
+
+ // Ensure we have the StyleTextProp atom we're going to need
+ if(props == null) {
+ parentParagraph.ensureStyleAtomPresent();
+ props = isCharacter ? characterStyle : paragraphStyle;
+ }
+
+ BitMaskTextProp prop = (BitMaskTextProp) fetchOrAddTextProp(props, propname);
+ prop.setSubValue(value,index);
+ }
+
+ /**
+ * Returns the named TextProp, either by fetching it (if it exists) or adding it
+ * (if it didn't)
+ * @param textPropCol The TextPropCollection to fetch from / add into
+ * @param textPropName The name of the TextProp to fetch/add
+ */
+ private TextProp fetchOrAddTextProp(TextPropCollection textPropCol, String textPropName) {
+ // Fetch / Add the TextProp
+ TextProp tp = textPropCol.findByName(textPropName);
+ if(tp == null) {
+ tp = textPropCol.addWithName(textPropName);
+ }
+ return tp;
+ }
+
+ /**
+ * Fetch the value of the given Character related TextProp.
+ * Returns -1 if that TextProp isn't present.
+ * If the TextProp isn't present, the value from the appropriate
+ * Master Sheet will apply.
+ */
+ private int getCharTextPropVal(String propName) {
+ TextProp prop = null;
+ if (characterStyle != null){
+ prop = characterStyle.findByName(propName);
+ }
+
+ if (prop == null){
+ HSLFSheet sheet = parentParagraph.getSheet();
+ int txtype = parentParagraph.getRunType();
+ HSLFMasterSheet master = sheet.getMasterSheet();
+ if (master != null)
+ prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
+ }
+ return prop == null ? -1 : prop.getValue();
+ }
+ /**
+ * Fetch the value of the given Paragraph related TextProp.
+ * Returns -1 if that TextProp isn't present.
+ * If the TextProp isn't present, the value from the appropriate
+ * Master Sheet will apply.
+ */
+ private int getParaTextPropVal(String propName) {
+ TextProp prop = null;
+ boolean hardAttribute = false;
+ if (paragraphStyle != null){
+ prop = paragraphStyle.findByName(propName);
+
+ BitMaskTextProp maskProp = (BitMaskTextProp)paragraphStyle.findByName(ParagraphFlagsTextProp.NAME);
+ hardAttribute = maskProp != null && maskProp.getValue() == 0;
+ }
+ if (prop == null && !hardAttribute){
+ HSLFSheet sheet = parentParagraph.getSheet();
+ int txtype = parentParagraph.getRunType();
+ HSLFMasterSheet master = sheet.getMasterSheet();
+ if (master != null)
+ prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
+ }
+
+ return prop == null ? -1 : prop.getValue();
+ }
+
+ /**
+ * Sets the value of the given Character TextProp, add if required
+ * @param propName The name of the Character TextProp
+ * @param val The value to set for the TextProp
+ */
+ public void setParaTextPropVal(String propName, int val) {
+ // Ensure we have the StyleTextProp atom we're going to need
+ if(paragraphStyle == null) {
+ parentParagraph.ensureStyleAtomPresent();
+ // paragraphStyle will now be defined
+ }
+
+ assert(paragraphStyle!=null);
+ TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
+ tp.setValue(val);
+ }
+ /**
+ * Sets the value of the given Paragraph TextProp, add if required
+ * @param propName The name of the Paragraph TextProp
+ * @param val The value to set for the TextProp
+ */
+ public void setCharTextPropVal(String propName, int val) {
+ // Ensure we have the StyleTextProp atom we're going to need
+ if(characterStyle == null) {
+ parentParagraph.ensureStyleAtomPresent();
+ // characterStyle will now be defined
+ }
+
+ assert(characterStyle!=null);
+ TextProp tp = fetchOrAddTextProp(characterStyle, propName);
+ tp.setValue(val);
+ }
+
+
+ // --------------- Friendly getters / setters on rich text properties -------
+
+ /**
+ * Is the text bold?
+ */
+ public boolean isBold() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX);
+ }
+
+ /**
+ * Is the text bold?
+ */
+ public void setBold(boolean bold) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold);
+ }
+
+ /**
+ * Is the text italic?
+ */
+ public boolean isItalic() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX);
+ }
+
+ /**
+ * Is the text italic?
+ */
+ public void setItalic(boolean italic) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic);
+ }
+
+ /**
+ * Is the text underlined?
+ */
+ public boolean isUnderline() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX);
+ }
+
+ /**
+ * Is the text underlined?
+ */
+ public void setUnderline(boolean underlined) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX, underlined);
+ }
+
+ /**
+ * Does the text have a shadow?
+ */
+ public boolean isShadowed() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.SHADOW_IDX);
+ }
+
+ /**
+ * Does the text have a shadow?
+ */
+ public void setShadowed(boolean flag) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.SHADOW_IDX, flag);
+ }
+
+ /**
+ * Is this text embossed?
+ */
+ public boolean isEmbossed() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.RELIEF_IDX);
+ }
+
+ /**
+ * Is this text embossed?
+ */
+ public void setEmbossed(boolean flag) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.RELIEF_IDX, flag);
+ }
+
+ /**
+ * Gets the strikethrough flag
+ */
+ public boolean isStrikethrough() {
+ return isCharFlagsTextPropVal(CharFlagsTextProp.STRIKETHROUGH_IDX);
+ }
+
+ /**
+ * Sets the strikethrough flag
+ */
+ public void setStrikethrough(boolean flag) {
+ setCharFlagsTextPropVal(CharFlagsTextProp.STRIKETHROUGH_IDX, flag);
+ }
+
+ /**
+ * Gets the subscript/superscript option
+ *
+ * @return the percentage of the font size. If the value is positive, it is superscript, otherwise it is subscript
+ */
+ public int getSuperscript() {
+ int val = getCharTextPropVal("superscript");
+ return val == -1 ? 0 : val;
+ }
+
+ /**
+ * Sets the subscript/superscript option
+ *
+ * @param val the percentage of the font size. If the value is positive, it is superscript, otherwise it is subscript
+ */
+ public void setSuperscript(int val) {
+ setCharTextPropVal("superscript", val);
+ }
+
+ /**
+ * Gets the font size
+ */
+ public int getFontSize() {
+ return getCharTextPropVal("font.size");
+ }
+
+
+ /**
+ * Sets the font size
+ */
+ public void setFontSize(int fontSize) {
+ setCharTextPropVal("font.size", fontSize);
+ }
+
+ /**
+ * Gets the font index
+ */
+ public int getFontIndex() {
+ return getCharTextPropVal("font.index");
+ }
+
+ /**
+ * Sets the font index
+ */
+ public void setFontIndex(int idx) {
+ setCharTextPropVal("font.index", idx);
+ }
+
+
+ /**
+ * Sets the font name to use
+ */
+ public void setFontName(String fontName) {
+ HSLFSheet sheet = parentParagraph.getSheet();
+ HSLFSlideShowImpl slideShow = (sheet == null) ? null : sheet.getSlideShow();
+ if (sheet == null || slideShow == null) {
+ //we can't set font since slideshow is not assigned yet
+ _fontname = fontName;
+ return;
+ }
+ // Get the index for this font (adding if needed)
+ int fontIdx = slideShow.getFontCollection().addFont(fontName);
+ setCharTextPropVal("font.index", fontIdx);
+ }
+
+ /**
+ * Gets the font name
+ */
+ public String getFontName() {
+ HSLFSheet sheet = parentParagraph.getSheet();
+ HSLFSlideShowImpl slideShow = (sheet == null) ? null : sheet.getSlideShow();
+ if (sheet == null || slideShow == null) {
+ return _fontname;
+ }
+ int fontIdx = getCharTextPropVal("font.index");
+ if(fontIdx == -1) { return null; }
+ return slideShow.getFontCollection().getFontWithId(fontIdx);
+ }
+
+ /**
+ * @return font color as RGB value
+ * @see java.awt.Color
+ */
+ public Color getFontColor() {
+ int rgb = getCharTextPropVal("font.color");
+
+ int cidx = rgb >> 24;
+ if (rgb % 0x1000000 == 0){
+ ColorSchemeAtom ca = parentParagraph.getSheet().getColorScheme();
+ if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx);
+ }
+ Color tmp = new Color(rgb, true);
+ return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
+ }
+
+ /**
+ * Sets color of the text, as a int bgr.
+ * (PowerPoint stores as BlueGreenRed, not the more
+ * usual RedGreenBlue)
+ * @see java.awt.Color
+ */
+ public void setFontColor(int bgr) {
+ setCharTextPropVal("font.color", bgr);
+ }
+
+ /**
+ * Sets color of the text, as a java.awt.Color
+ */
+ public void setFontColor(Color color) {
+ // In PowerPont RGB bytes are swapped, as BGR
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
+ setFontColor(rgb);
+ }
+
+ /**
+ * Sets the type of horizontal alignment for the text.
+ * One of the Align*
constants defined in the TextBox
class.
+ *
+ * @param align - the type of alignment
+ */
+ public void setAlignment(int align) {
+ setParaTextPropVal("alignment", align);
+ }
+ /**
+ * Returns the type of horizontal alignment for the text.
+ * One of the Align*
constants defined in the TextBox class.
+ *
+ * @return the type of alignment
+ */
+ public int getAlignment() {
+ return getParaTextPropVal("alignment");
+ }
+
+ /**
+ *
+ * @return indentation level
+ */
+ public int getIndentLevel() {
+ return paragraphStyle == null ? 0 : paragraphStyle.getReservedField();
+ }
+
+ /**
+ * Sets indentation level
+ *
+ * @param level indentation level. Must be in the range [0, 4]
+ */
+ public void setIndentLevel(int level) {
+ if(paragraphStyle != null ) paragraphStyle.setReservedField((short)level);
+ }
+
+ /**
+ * Sets whether this rich text run has bullets
+ */
+ public void setBullet(boolean flag) {
+ setFlag(false, ParagraphFlagsTextProp.BULLET_IDX, flag);
+ }
+
+ /**
+ * Returns whether this rich text run has bullets
+ */
+ public boolean isBullet() {
+ return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
+ }
+
+ /**
+ * Returns whether this rich text run has bullets
+ */
+ public boolean isBulletHard() {
+ return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
+ }
+
+ /**
+ * Sets the bullet character
+ */
+ public void setBulletChar(char c) {
+ setParaTextPropVal("bullet.char", c);
+ }
+
+ /**
+ * Returns the bullet character
+ */
+ public char getBulletChar() {
+ return (char)getParaTextPropVal("bullet.char");
+ }
+
+ /**
+ * Sets the bullet offset
+ */
+ public void setBulletOffset(int offset) {
+ setParaTextPropVal("bullet.offset", offset*HSLFShape.MASTER_DPI/HSLFShape.POINT_DPI);
+ }
+
+ /**
+ * Returns the bullet offset
+ */
+ public int getBulletOffset() {
+ return getParaTextPropVal("bullet.offset")*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
+ }
+
+ /**
+ * Sets the text offset
+ */
+ public void setTextOffset(int offset) {
+ setParaTextPropVal("text.offset", offset*HSLFShape.MASTER_DPI/HSLFShape.POINT_DPI);
+ }
+
+ /**
+ * Returns the text offset
+ */
+ public int getTextOffset() {
+ return getParaTextPropVal("text.offset")*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
+ }
+
+ /**
+ * Sets the bullet size
+ */
+ public void setBulletSize(int size) {
+ setParaTextPropVal("bullet.size", size);
+ }
+
+ /**
+ * Returns the bullet size
+ */
+ public int getBulletSize() {
+ return getParaTextPropVal("bullet.size");
+ }
+
+ /**
+ * Sets the bullet color
+ */
+ public void setBulletColor(Color color) {
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
+ setParaTextPropVal("bullet.color", rgb);
+ }
+
+ /**
+ * Returns the bullet color
+ */
+ public Color getBulletColor() {
+ int rgb = getParaTextPropVal("bullet.color");
+ if(rgb == -1) return getFontColor();
+
+ int cidx = rgb >> 24;
+ if (rgb % 0x1000000 == 0){
+ ColorSchemeAtom ca = parentParagraph.getSheet().getColorScheme();
+ if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx);
+ }
+ Color tmp = new Color(rgb, true);
+ return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
+ }
+
+ /**
+ * Sets the bullet font
+ */
+ public void setBulletFont(int idx) {
+ setParaTextPropVal("bullet.font", idx);
+ setFlag(false, ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, true);
+ }
+
+ /**
+ * Returns the bullet font
+ */
+ public int getBulletFont() {
+ return getParaTextPropVal("bullet.font");
+ }
+
+ /**
+ * Sets the line spacing.
+ *
+ * If linespacing >= 0, then linespacing is a percentage of normal line height.
+ * If linespacing < 0, the absolute value of linespacing is the spacing in master coordinates.
+ *
+ */
+ public void setLineSpacing(int val) {
+ setParaTextPropVal("linespacing", val);
+ }
+
+ /**
+ * Returns the line spacing
+ *
+ * If linespacing >= 0, then linespacing is a percentage of normal line height.
+ * If linespacing < 0, the absolute value of linespacing is the spacing in master coordinates.
+ *
+ *
+ * @return the spacing between lines
+ */
+ public int getLineSpacing() {
+ int val = getParaTextPropVal("linespacing");
+ return val == -1 ? 0 : val;
+ }
+
+ /**
+ * Sets spacing before a paragraph.
+ *
+ * If spacebefore >= 0, then spacebefore is a percentage of normal line height.
+ * If spacebefore < 0, the absolute value of spacebefore is the spacing in master coordinates.
+ *
+ */
+ public void setSpaceBefore(int val) {
+ setParaTextPropVal("spacebefore", val);
+ }
+
+ /**
+ * Returns spacing before a paragraph
+ *
+ * If spacebefore >= 0, then spacebefore is a percentage of normal line height.
+ * If spacebefore < 0, the absolute value of spacebefore is the spacing in master coordinates.
+ *
+ *
+ * @return the spacing before a paragraph
+ */
+ public int getSpaceBefore() {
+ int val = getParaTextPropVal("spacebefore");
+ return val == -1 ? 0 : val;
+ }
+
+ /**
+ * Sets spacing after a paragraph.
+ *
+ * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+ * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+ *
+ */
+ public void setSpaceAfter(int val) {
+ setParaTextPropVal("spaceafter", val);
+ }
+
+ /**
+ * Returns spacing after a paragraph
+ *
+ * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
+ * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
+ *
+ *
+ * @return the spacing before a paragraph
+ */
+ public int getSpaceAfter() {
+ int val = getParaTextPropVal("spaceafter");
+ return val == -1 ? 0 : val;
+ }
+ // --------------- Internal HSLF methods, not intended for end-user use! -------
+
+ /**
+ * Internal Use Only - get the underlying paragraph style collection.
+ * For normal use, use the friendly setters and getters
+ */
+ public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; }
+ /**
+ * Internal Use Only - get the underlying character style collection.
+ * For normal use, use the friendly setters and getters
+ */
+ public TextPropCollection _getRawCharacterStyle() { return characterStyle; }
+ /**
+ * Internal Use Only - are the Paragraph styles shared?
+ */
+ public boolean _isParagraphStyleShared() { return sharingParagraphStyle; }
+ /**
+ * Internal Use Only - are the Character styles shared?
+ */
+ public boolean _isCharacterStyleShared() { return sharingCharacterStyle; }
+}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java
deleted file mode 100644
index bbef87a96c..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/ObjectData.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/* ====================================================================
- 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.io.InputStream;
-import java.io.IOException;
-
-import org.apache.poi.hslf.record.ExOleObjStg;
-
-/**
- * A class that represents object data embedded in a slide show.
- *
- * @author Daniel Noll
- */
-public class ObjectData {
- /**
- * The record that contains the object data.
- */
- private ExOleObjStg storage;
-
- /**
- * Creates the object data wrapping the record that contains the object data.
- *
- * @param storage the record that contains the object data.
- */
- public ObjectData(ExOleObjStg storage) {
- this.storage = storage;
- }
-
- /**
- * Gets an input stream which returns the binary of the embedded data.
- *
- * @return the input stream which will contain the binary of the embedded data.
- */
- public InputStream getData() {
- return storage.getData();
- }
-
- /**
- * Sets the embedded data.
- *
- * @param data the embedded data.
- */
- public void setData(byte[] data) throws IOException {
- storage.setData(data);
- }
-
- /**
- * Return the record that contains the object data.
- *
- * @return the record that contains the object data.
- */
- public ExOleObjStg getExOleObjStg() {
- return storage;
- }
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java
deleted file mode 100644
index 857ad5451e..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/PictureData.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/* ====================================================================
- 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.io.IOException;
-import java.io.OutputStream;
-import java.security.MessageDigest;
-
-import org.apache.poi.hslf.blip.BitmapPainter;
-import org.apache.poi.hslf.blip.DIB;
-import org.apache.poi.hslf.blip.EMF;
-import org.apache.poi.hslf.blip.ImagePainter;
-import org.apache.poi.hslf.blip.JPEG;
-import org.apache.poi.hslf.blip.PICT;
-import org.apache.poi.hslf.blip.PNG;
-import org.apache.poi.hslf.blip.WMF;
-import org.apache.poi.hslf.model.Picture;
-import org.apache.poi.poifs.crypt.CryptoFunctions;
-import org.apache.poi.poifs.crypt.HashAlgorithm;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-
-/**
- * A class that represents image data contained in a slide show.
- *
- * @author Yegor Kozlov
- */
-public abstract class PictureData {
-
- protected POILogger logger = POILogFactory.getLogger(this.getClass());
-
- /**
- * Size of the image checksum calculated using MD5 algorithm.
- */
- protected static final int CHECKSUM_SIZE = 16;
-
- /**
- * Binary data of the picture
- */
- private byte[] rawdata;
- /**
- * The offset to the picture in the stream
- */
- protected int offset;
-
- /**
- * Returns type of this picture.
- * Must be one of the static constants defined in the Picture class.
- *
- * @return type of this picture.
- */
- public abstract int getType();
-
- /**
- * Returns the binary data of this Picture
- * @return picture data
- */
- public abstract byte[] getData();
-
- /**
- * Set picture data
- */
- public abstract void setData(byte[] data) throws IOException;
-
- /**
- * Blip signature.
- */
- protected abstract int getSignature();
-
- protected static final ImagePainter[] painters = new ImagePainter[8];
- static {
- PictureData.setImagePainter(Picture.PNG, new BitmapPainter());
- PictureData.setImagePainter(Picture.JPEG, new BitmapPainter());
- PictureData.setImagePainter(Picture.DIB, new BitmapPainter());
- }
-
- /**
- * Returns the raw binary data of this Picture excluding the first 8 bytes
- * which hold image signature and size of the image data.
- *
- * @return picture data
- */
- public byte[] getRawData(){
- return rawdata;
- }
-
- public void setRawData(byte[] data){
- rawdata = data;
- }
-
- /**
- * File offset in the 'Pictures' stream
- *
- * @return offset in the 'Pictures' stream
- */
- public int getOffset(){
- return offset;
- }
-
- /**
- * Set offset of this picture in the 'Pictures' stream.
- * We need to set it when a new picture is created.
- *
- * @param offset in the 'Pictures' stream
- */
- public void setOffset(int offset){
- this.offset = offset;
- }
-
- /**
- * Returns 16-byte checksum of this picture
- */
- public byte[] getUID(){
- byte[] uid = new byte[16];
- System.arraycopy(rawdata, 0, uid, 0, uid.length);
- return uid;
- }
-
-
- /**
- * Compute 16-byte checksum of this picture using MD5 algorithm.
- */
- public static byte[] getChecksum(byte[] data) {
- MessageDigest md5 = CryptoFunctions.getMessageDigest(HashAlgorithm.md5);
- md5.update(data);
- return md5.digest();
- }
-
- /**
- * Write this picture into OutputStream
- */
- public void write(OutputStream out) throws IOException {
- byte[] data;
-
- data = new byte[LittleEndian.SHORT_SIZE];
- LittleEndian.putUShort(data, 0, getSignature());
- out.write(data);
-
- data = new byte[LittleEndian.SHORT_SIZE];
- LittleEndian.putUShort(data, 0, getType() + 0xF018);
- out.write(data);
-
- byte[] rawdata = getRawData();
-
- data = new byte[LittleEndian.INT_SIZE];
- LittleEndian.putInt(data, 0, rawdata.length);
- out.write(data);
-
- out.write(rawdata);
- }
-
- /**
- * Create an instance of PictureData
by type.
- *
- * @param type type of the picture data.
- * Must be one of the static constants defined in the Picture class.
- * @return concrete instance of PictureData
- */
- public static PictureData create(int type){
- PictureData pict;
- switch (type){
- case Picture.EMF:
- pict = new EMF();
- break;
- case Picture.WMF:
- pict = new WMF();
- break;
- case Picture.PICT:
- pict = new PICT();
- break;
- case Picture.JPEG:
- pict = new JPEG();
- break;
- case Picture.PNG:
- pict = new PNG();
- break;
- case Picture.DIB:
- pict = new DIB();
- break;
- default:
- throw new IllegalArgumentException("Unsupported picture type: " + type);
- }
- return pict;
- }
-
- /**
- * Return 24 byte header which preceeds the actual picture data.
- *
- * The header consists of 2-byte signature, 2-byte type,
- * 4-byte image size and 16-byte checksum of the image data.
- *
- *
- * @return the 24 byte header which preceeds the actual picture data.
- */
- public byte[] getHeader() {
- byte[] header = new byte[16 + 8];
- LittleEndian.putInt(header, 0, getSignature());
- LittleEndian.putInt(header, 4, getRawData().length);
- System.arraycopy(rawdata, 0, header, 8, 16);
- return header;
- }
-
- /**
- * Return image size in bytes
- *
- * @return the size of the picture in bytes
- * @deprecated Use getData().length
instead.
- */
- public int getSize(){
- return getData().length;
- }
-
- public void draw(Graphics2D graphics, Picture parent){
- ImagePainter painter = painters[getType()];
- if(painter != null) painter.paint(graphics, this, parent);
- else logger.log(POILogger.WARN, "Rendering is not supported: " + getClass().getName());
- }
-
- /**
- * Register ImagePainter for the specified image type
- *
- * @param type image type, must be one of the static constants defined in the Picture class.
- * @param painter
- */
- public static void setImagePainter(int type, ImagePainter painter){
- painters[type] = painter;
- }
-
- /**
- * Return ImagePainter for the specified image type
- *
- * @param type blip type, must be one of the static constants defined in the Picture class.
- * @return ImagePainter for the specified image type
- */
- public static ImagePainter getImagePainter(int type){
- return painters[type];
- }
-
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
deleted file mode 100644
index 878f8c12eb..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
+++ /dev/null
@@ -1,792 +0,0 @@
-/* ====================================================================
- 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.Color;
-
-import org.apache.poi.hslf.model.MasterSheet;
-import org.apache.poi.hslf.model.HSLFShape;
-import org.apache.poi.hslf.model.Sheet;
-import org.apache.poi.hslf.model.TextRun;
-import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
-import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
-import org.apache.poi.hslf.model.textproperties.TextProp;
-import org.apache.poi.hslf.model.textproperties.TextPropCollection;
-import org.apache.poi.hslf.record.ColorSchemeAtom;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-
-
-/**
- * Represents a run of text, all with the same style
- *
- */
-public final class RichTextRun {
- protected POILogger logger = POILogFactory.getLogger(this.getClass());
-
- /** The TextRun we belong to */
- private TextRun parentRun;
- /** The SlideShow we belong to */
- private SlideShow slideShow;
-
- /** Where in the parent TextRun we start from */
- private int startPos;
-
- /** How long a string (in the parent TextRun) we represent */
- private int length;
-
- private String _fontname;
- /**
- * Our paragraph and character style.
- * Note - we may share these styles with other RichTextRuns
- */
- private TextPropCollection paragraphStyle;
- private TextPropCollection characterStyle;
- private boolean sharingParagraphStyle;
- private boolean sharingCharacterStyle;
-
- /**
- * Create a new wrapper around a (currently not)
- * rich text string
- * @param parent
- * @param startAt
- * @param len
- */
- public RichTextRun(TextRun parent, int startAt, int len) {
- this(parent, startAt, len, null, null, false, false);
- }
- /**
- * Create a new wrapper around a rich text string
- * @param parent The parent TextRun
- * @param startAt The start position of this run
- * @param len The length of this run
- * @param pStyle The paragraph style property collection
- * @param cStyle The character style property collection
- * @param pShared The paragraph styles are shared with other runs
- * @param cShared The character styles are shared with other runs
- */
- public RichTextRun(TextRun parent, int startAt, int len,
- TextPropCollection pStyle, TextPropCollection cStyle,
- boolean pShared, boolean cShared) {
- parentRun = parent;
- startPos = startAt;
- length = len;
- paragraphStyle = pStyle;
- characterStyle = cStyle;
- sharingParagraphStyle = pShared;
- sharingCharacterStyle = cShared;
- }
-
- /**
- * Supply (normally default) textprops, and if they're shared,
- * when a run gets them
- */
- public void supplyTextProps(TextPropCollection pStyle, TextPropCollection cStyle, boolean pShared, boolean cShared) {
- if(paragraphStyle != null || characterStyle != null) {
- throw new IllegalStateException("Can't call supplyTextProps if run already has some");
- }
- paragraphStyle = pStyle;
- characterStyle = cStyle;
- sharingParagraphStyle = pShared;
- sharingCharacterStyle = cShared;
- }
- /**
- * Supply the SlideShow we belong to
- */
- public void supplySlideShow(SlideShow ss) {
- slideShow = ss;
- if (_fontname != null) {
- setFontName(_fontname);
- _fontname = null;
- }
- }
-
- /**
- * Get the length of the text
- */
- public int getLength() {
- return length;
- }
-
- /**
- * The beginning index, inclusive.
- *
- * @return the beginning index, inclusive.
- */
- public int getStartIndex(){
- return startPos;
- }
-
- /**
- * The ending index, exclusive.
- *
- * @return the ending index, exclusive.
- */
- public int getEndIndex(){
- return startPos + length;
- }
-
- /**
- * Fetch the text, in output suitable form
- */
- public String getText() {
- return parentRun.getText().substring(startPos, startPos+length);
- }
- /**
- * Fetch the text, in raw storage form
- */
- public String getRawText() {
- return parentRun.getRawText().substring(startPos, startPos+length);
- }
-
- /**
- * Change the text
- */
- public void setText(String text) {
- String s = parentRun.normalize(text);
- setRawText(s);
- }
-
- /**
- * Change the text
- */
- public void setRawText(String text) {
- length = text.length();
- parentRun.changeTextInRichTextRun(this,text);
- }
-
- /**
- * Tells the RichTextRun its new position in the parent TextRun
- * @param startAt
- */
- public void updateStartPosition(int startAt) {
- startPos = startAt;
- }
-
-
- // --------------- Internal helpers on rich text properties -------
-
- /**
- * Fetch the value of the given flag in the CharFlagsTextProp.
- * Returns false if the CharFlagsTextProp isn't present, since the
- * text property won't be set if there's no CharFlagsTextProp.
- */
- private boolean isCharFlagsTextPropVal(int index) {
- return getFlag(true, index);
- }
-
- private boolean getFlag(boolean isCharacter, int index) {
- TextPropCollection props;
- String propname;
- if (isCharacter){
- props = characterStyle;
- propname = CharFlagsTextProp.NAME;
- } else {
- props = paragraphStyle;
- propname = ParagraphFlagsTextProp.NAME;
- }
-
- BitMaskTextProp prop = null;
- if (props != null){
- prop = (BitMaskTextProp)props.findByName(propname);
- }
- if (prop == null){
- Sheet sheet = parentRun.getSheet();
- if(sheet != null){
- int txtype = parentRun.getRunType();
- MasterSheet master = sheet.getMasterSheet();
- if (master != null){
- prop = (BitMaskTextProp)master.getStyleAttribute(txtype, getIndentLevel(), propname, isCharacter);
- }
- } else {
- logger.log(POILogger.WARN, "MasterSheet is not available");
- }
- }
-
- return prop == null ? false : prop.getSubValue(index);
- }
-
- /**
- * Set the value of the given flag in the CharFlagsTextProp, adding
- * it if required.
- */
- private void setCharFlagsTextPropVal(int index, boolean value) {
- if(getFlag(true, index) != value) setFlag(true, index, value);
- }
-
- public void setFlag(boolean isCharacter, int index, boolean value) {
- TextPropCollection props;
- String propname;
- if (isCharacter){
- props = characterStyle;
- propname = CharFlagsTextProp.NAME;
- } else {
- props = paragraphStyle;
- propname = ParagraphFlagsTextProp.NAME;
- }
-
- // Ensure we have the StyleTextProp atom we're going to need
- if(props == null) {
- parentRun.ensureStyleAtomPresent();
- props = isCharacter ? characterStyle : paragraphStyle;
- }
-
- BitMaskTextProp prop = (BitMaskTextProp) fetchOrAddTextProp(props, propname);
- prop.setSubValue(value,index);
- }
-
- /**
- * Returns the named TextProp, either by fetching it (if it exists) or adding it
- * (if it didn't)
- * @param textPropCol The TextPropCollection to fetch from / add into
- * @param textPropName The name of the TextProp to fetch/add
- */
- private TextProp fetchOrAddTextProp(TextPropCollection textPropCol, String textPropName) {
- // Fetch / Add the TextProp
- TextProp tp = textPropCol.findByName(textPropName);
- if(tp == null) {
- tp = textPropCol.addWithName(textPropName);
- }
- return tp;
- }
-
- /**
- * Fetch the value of the given Character related TextProp.
- * Returns -1 if that TextProp isn't present.
- * If the TextProp isn't present, the value from the appropriate
- * Master Sheet will apply.
- */
- private int getCharTextPropVal(String propName) {
- TextProp prop = null;
- if (characterStyle != null){
- prop = characterStyle.findByName(propName);
- }
-
- if (prop == null){
- Sheet sheet = parentRun.getSheet();
- int txtype = parentRun.getRunType();
- MasterSheet master = sheet.getMasterSheet();
- if (master != null)
- prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
- }
- return prop == null ? -1 : prop.getValue();
- }
- /**
- * Fetch the value of the given Paragraph related TextProp.
- * Returns -1 if that TextProp isn't present.
- * If the TextProp isn't present, the value from the appropriate
- * Master Sheet will apply.
- */
- private int getParaTextPropVal(String propName) {
- TextProp prop = null;
- boolean hardAttribute = false;
- if (paragraphStyle != null){
- prop = paragraphStyle.findByName(propName);
-
- BitMaskTextProp maskProp = (BitMaskTextProp)paragraphStyle.findByName(ParagraphFlagsTextProp.NAME);
- hardAttribute = maskProp != null && maskProp.getValue() == 0;
- }
- if (prop == null && !hardAttribute){
- Sheet sheet = parentRun.getSheet();
- int txtype = parentRun.getRunType();
- MasterSheet master = sheet.getMasterSheet();
- if (master != null)
- prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
- }
-
- return prop == null ? -1 : prop.getValue();
- }
-
- /**
- * Sets the value of the given Character TextProp, add if required
- * @param propName The name of the Character TextProp
- * @param val The value to set for the TextProp
- */
- public void setParaTextPropVal(String propName, int val) {
- // Ensure we have the StyleTextProp atom we're going to need
- if(paragraphStyle == null) {
- parentRun.ensureStyleAtomPresent();
- // paragraphStyle will now be defined
- }
-
- assert(paragraphStyle!=null);
- TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
- tp.setValue(val);
- }
- /**
- * Sets the value of the given Paragraph TextProp, add if required
- * @param propName The name of the Paragraph TextProp
- * @param val The value to set for the TextProp
- */
- public void setCharTextPropVal(String propName, int val) {
- // Ensure we have the StyleTextProp atom we're going to need
- if(characterStyle == null) {
- parentRun.ensureStyleAtomPresent();
- // characterStyle will now be defined
- }
-
- assert(characterStyle!=null);
- TextProp tp = fetchOrAddTextProp(characterStyle, propName);
- tp.setValue(val);
- }
-
-
- // --------------- Friendly getters / setters on rich text properties -------
-
- /**
- * Is the text bold?
- */
- public boolean isBold() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX);
- }
-
- /**
- * Is the text bold?
- */
- public void setBold(boolean bold) {
- setCharFlagsTextPropVal(CharFlagsTextProp.BOLD_IDX, bold);
- }
-
- /**
- * Is the text italic?
- */
- public boolean isItalic() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX);
- }
-
- /**
- * Is the text italic?
- */
- public void setItalic(boolean italic) {
- setCharFlagsTextPropVal(CharFlagsTextProp.ITALIC_IDX, italic);
- }
-
- /**
- * Is the text underlined?
- */
- public boolean isUnderlined() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX);
- }
-
- /**
- * Is the text underlined?
- */
- public void setUnderlined(boolean underlined) {
- setCharFlagsTextPropVal(CharFlagsTextProp.UNDERLINE_IDX, underlined);
- }
-
- /**
- * Does the text have a shadow?
- */
- public boolean isShadowed() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.SHADOW_IDX);
- }
-
- /**
- * Does the text have a shadow?
- */
- public void setShadowed(boolean flag) {
- setCharFlagsTextPropVal(CharFlagsTextProp.SHADOW_IDX, flag);
- }
-
- /**
- * Is this text embossed?
- */
- public boolean isEmbossed() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.RELIEF_IDX);
- }
-
- /**
- * Is this text embossed?
- */
- public void setEmbossed(boolean flag) {
- setCharFlagsTextPropVal(CharFlagsTextProp.RELIEF_IDX, flag);
- }
-
- /**
- * Gets the strikethrough flag
- */
- public boolean isStrikethrough() {
- return isCharFlagsTextPropVal(CharFlagsTextProp.STRIKETHROUGH_IDX);
- }
-
- /**
- * Sets the strikethrough flag
- */
- public void setStrikethrough(boolean flag) {
- setCharFlagsTextPropVal(CharFlagsTextProp.STRIKETHROUGH_IDX, flag);
- }
-
- /**
- * Gets the subscript/superscript option
- *
- * @return the percentage of the font size. If the value is positive, it is superscript, otherwise it is subscript
- */
- public int getSuperscript() {
- int val = getCharTextPropVal("superscript");
- return val == -1 ? 0 : val;
- }
-
- /**
- * Sets the subscript/superscript option
- *
- * @param val the percentage of the font size. If the value is positive, it is superscript, otherwise it is subscript
- */
- public void setSuperscript(int val) {
- setCharTextPropVal("superscript", val);
- }
-
- /**
- * Gets the font size
- */
- public int getFontSize() {
- return getCharTextPropVal("font.size");
- }
-
-
- /**
- * Sets the font size
- */
- public void setFontSize(int fontSize) {
- setCharTextPropVal("font.size", fontSize);
- }
-
- /**
- * Gets the font index
- */
- public int getFontIndex() {
- return getCharTextPropVal("font.index");
- }
-
- /**
- * Sets the font index
- */
- public void setFontIndex(int idx) {
- setCharTextPropVal("font.index", idx);
- }
-
-
- /**
- * Sets the font name to use
- */
- public void setFontName(String fontName) {
- if (slideShow == null) {
- //we can't set font since slideshow is not assigned yet
- _fontname = fontName;
- } else {
- // Get the index for this font (adding if needed)
- int fontIdx = slideShow.getFontCollection().addFont(fontName);
- setCharTextPropVal("font.index", fontIdx);
- }
- }
-
- /**
- * Gets the font name
- */
- public String getFontName() {
- if (slideShow == null) {
- return _fontname;
- }
- int fontIdx = getCharTextPropVal("font.index");
- if(fontIdx == -1) { return null; }
- return slideShow.getFontCollection().getFontWithId(fontIdx);
- }
-
- /**
- * @return font color as RGB value
- * @see java.awt.Color
- */
- public Color getFontColor() {
- int rgb = getCharTextPropVal("font.color");
-
- int cidx = rgb >> 24;
- if (rgb % 0x1000000 == 0){
- ColorSchemeAtom ca = parentRun.getSheet().getColorScheme();
- if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx);
- }
- Color tmp = new Color(rgb, true);
- return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
- }
-
- /**
- * Sets color of the text, as a int bgr.
- * (PowerPoint stores as BlueGreenRed, not the more
- * usual RedGreenBlue)
- * @see java.awt.Color
- */
- public void setFontColor(int bgr) {
- setCharTextPropVal("font.color", bgr);
- }
-
- /**
- * Sets color of the text, as a java.awt.Color
- */
- public void setFontColor(Color color) {
- // In PowerPont RGB bytes are swapped, as BGR
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
- setFontColor(rgb);
- }
-
- /**
- * Sets the type of horizontal alignment for the text.
- * One of the Align*
constants defined in the TextBox
class.
- *
- * @param align - the type of alignment
- */
- public void setAlignment(int align) {
- setParaTextPropVal("alignment", align);
- }
- /**
- * Returns the type of horizontal alignment for the text.
- * One of the Align*
constants defined in the TextBox class.
- *
- * @return the type of alignment
- */
- public int getAlignment() {
- return getParaTextPropVal("alignment");
- }
-
- /**
- *
- * @return indentation level
- */
- public int getIndentLevel() {
- return paragraphStyle == null ? 0 : paragraphStyle.getReservedField();
- }
-
- /**
- * Sets indentation level
- *
- * @param level indentation level. Must be in the range [0, 4]
- */
- public void setIndentLevel(int level) {
- if(paragraphStyle != null ) paragraphStyle.setReservedField((short)level);
- }
-
- /**
- * Sets whether this rich text run has bullets
- */
- public void setBullet(boolean flag) {
- setFlag(false, ParagraphFlagsTextProp.BULLET_IDX, flag);
- }
-
- /**
- * Returns whether this rich text run has bullets
- */
- public boolean isBullet() {
- return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
- }
-
- /**
- * Returns whether this rich text run has bullets
- */
- public boolean isBulletHard() {
- return getFlag(false, ParagraphFlagsTextProp.BULLET_IDX);
- }
-
- /**
- * Sets the bullet character
- */
- public void setBulletChar(char c) {
- setParaTextPropVal("bullet.char", c);
- }
-
- /**
- * Returns the bullet character
- */
- public char getBulletChar() {
- return (char)getParaTextPropVal("bullet.char");
- }
-
- /**
- * Sets the bullet offset
- */
- public void setBulletOffset(int offset) {
- setParaTextPropVal("bullet.offset", offset*HSLFShape.MASTER_DPI/HSLFShape.POINT_DPI);
- }
-
- /**
- * Returns the bullet offset
- */
- public int getBulletOffset() {
- return getParaTextPropVal("bullet.offset")*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
- }
-
- /**
- * Sets the text offset
- */
- public void setTextOffset(int offset) {
- setParaTextPropVal("text.offset", offset*HSLFShape.MASTER_DPI/HSLFShape.POINT_DPI);
- }
-
- /**
- * Returns the text offset
- */
- public int getTextOffset() {
- return getParaTextPropVal("text.offset")*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
- }
-
- /**
- * Sets the bullet size
- */
- public void setBulletSize(int size) {
- setParaTextPropVal("bullet.size", size);
- }
-
- /**
- * Returns the bullet size
- */
- public int getBulletSize() {
- return getParaTextPropVal("bullet.size");
- }
-
- /**
- * Sets the bullet color
- */
- public void setBulletColor(Color color) {
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();
- setParaTextPropVal("bullet.color", rgb);
- }
-
- /**
- * Returns the bullet color
- */
- public Color getBulletColor() {
- int rgb = getParaTextPropVal("bullet.color");
- if(rgb == -1) return getFontColor();
-
- int cidx = rgb >> 24;
- if (rgb % 0x1000000 == 0){
- ColorSchemeAtom ca = parentRun.getSheet().getColorScheme();
- if(cidx >= 0 && cidx <= 7) rgb = ca.getColor(cidx);
- }
- Color tmp = new Color(rgb, true);
- return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
- }
-
- /**
- * Sets the bullet font
- */
- public void setBulletFont(int idx) {
- setParaTextPropVal("bullet.font", idx);
- setFlag(false, ParagraphFlagsTextProp.BULLET_HARDFONT_IDX, true);
- }
-
- /**
- * Returns the bullet font
- */
- public int getBulletFont() {
- return getParaTextPropVal("bullet.font");
- }
-
- /**
- * Sets the line spacing.
- *
- * If linespacing >= 0, then linespacing is a percentage of normal line height.
- * If linespacing < 0, the absolute value of linespacing is the spacing in master coordinates.
- *
- */
- public void setLineSpacing(int val) {
- setParaTextPropVal("linespacing", val);
- }
-
- /**
- * Returns the line spacing
- *
- * If linespacing >= 0, then linespacing is a percentage of normal line height.
- * If linespacing < 0, the absolute value of linespacing is the spacing in master coordinates.
- *
- *
- * @return the spacing between lines
- */
- public int getLineSpacing() {
- int val = getParaTextPropVal("linespacing");
- return val == -1 ? 0 : val;
- }
-
- /**
- * Sets spacing before a paragraph.
- *
- * If spacebefore >= 0, then spacebefore is a percentage of normal line height.
- * If spacebefore < 0, the absolute value of spacebefore is the spacing in master coordinates.
- *
- */
- public void setSpaceBefore(int val) {
- setParaTextPropVal("spacebefore", val);
- }
-
- /**
- * Returns spacing before a paragraph
- *
- * If spacebefore >= 0, then spacebefore is a percentage of normal line height.
- * If spacebefore < 0, the absolute value of spacebefore is the spacing in master coordinates.
- *
- *
- * @return the spacing before a paragraph
- */
- public int getSpaceBefore() {
- int val = getParaTextPropVal("spacebefore");
- return val == -1 ? 0 : val;
- }
-
- /**
- * Sets spacing after a paragraph.
- *
- * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
- * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
- *
- */
- public void setSpaceAfter(int val) {
- setParaTextPropVal("spaceafter", val);
- }
-
- /**
- * Returns spacing after a paragraph
- *
- * If spaceafter >= 0, then spaceafter is a percentage of normal line height.
- * If spaceafter < 0, the absolute value of spaceafter is the spacing in master coordinates.
- *
- *
- * @return the spacing before a paragraph
- */
- public int getSpaceAfter() {
- int val = getParaTextPropVal("spaceafter");
- return val == -1 ? 0 : val;
- }
- // --------------- Internal HSLF methods, not intended for end-user use! -------
-
- /**
- * Internal Use Only - get the underlying paragraph style collection.
- * For normal use, use the friendly setters and getters
- */
- public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; }
- /**
- * Internal Use Only - get the underlying character style collection.
- * For normal use, use the friendly setters and getters
- */
- public TextPropCollection _getRawCharacterStyle() { return characterStyle; }
- /**
- * Internal Use Only - are the Paragraph styles shared?
- */
- public boolean _isParagraphStyleShared() { return sharingParagraphStyle; }
- /**
- * Internal Use Only - are the Character styles shared?
- */
- public boolean _isCharacterStyleShared() { return sharingCharacterStyle; }
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
deleted file mode 100644
index d6829b4b4e..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
+++ /dev/null
@@ -1,1172 +0,0 @@
-/* ====================================================================
- 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.Dimension;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherRecord;
-import org.apache.poi.hpsf.ClassID;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
-import org.apache.poi.hslf.exceptions.HSLFException;
-import org.apache.poi.hslf.model.HeadersFooters;
-import org.apache.poi.hslf.model.Hyperlink;
-import org.apache.poi.hslf.model.MovieShape;
-import org.apache.poi.hslf.model.Notes;
-import org.apache.poi.hslf.model.PPFont;
-import org.apache.poi.hslf.model.Picture;
-import org.apache.poi.hslf.model.HSLFShape;
-import org.apache.poi.hslf.model.Slide;
-import org.apache.poi.hslf.model.SlideMaster;
-import org.apache.poi.hslf.model.TitleMaster;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.record.DocumentAtom;
-import org.apache.poi.hslf.record.ExAviMovie;
-import org.apache.poi.hslf.record.ExControl;
-import org.apache.poi.hslf.record.ExEmbed;
-import org.apache.poi.hslf.record.ExEmbedAtom;
-import org.apache.poi.hslf.record.ExHyperlink;
-import org.apache.poi.hslf.record.ExHyperlinkAtom;
-import org.apache.poi.hslf.record.ExMCIMovie;
-import org.apache.poi.hslf.record.ExObjList;
-import org.apache.poi.hslf.record.ExObjListAtom;
-import org.apache.poi.hslf.record.ExOleObjAtom;
-import org.apache.poi.hslf.record.ExOleObjStg;
-import org.apache.poi.hslf.record.ExVideoContainer;
-import org.apache.poi.hslf.record.FontCollection;
-import org.apache.poi.hslf.record.FontEntityAtom;
-import org.apache.poi.hslf.record.HeadersFootersContainer;
-import org.apache.poi.hslf.record.PersistPtrHolder;
-import org.apache.poi.hslf.record.PositionDependentRecord;
-import org.apache.poi.hslf.record.PositionDependentRecordContainer;
-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.SlideListWithText;
-import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
-import org.apache.poi.hslf.record.SlidePersistAtom;
-import org.apache.poi.hslf.record.UserEditAtom;
-import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-
-/**
- * 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
- *
- * @author Nick Burch
- * @author Yegor kozlov
- */
-public final class SlideShow {
- // What we're based on
- private HSLFSlideShow _hslfSlideShow;
-
- // Pointers to the most recent versions of the core records
- // (Document, Notes, Slide etc)
- private Record[] _mostRecentCoreRecords;
- // Lookup between the PersitPtr "sheet" IDs, and the position
- // in the mostRecentCoreRecords array
- private Map _sheetIdToCoreRecordsLookup;
-
- // Records that are interesting
- private Document _documentRecord;
-
- // Friendly objects for people to deal with
- private SlideMaster[] _masters;
- private TitleMaster[] _titleMasters;
- private Slide[] _slides;
- private Notes[] _notes;
- private FontCollection _fonts;
-
- // For logging
- private POILogger logger = POILogFactory.getLogger(this.getClass());
-
-
- /* ===============================================================
- * Setup Code
- * ===============================================================
- */
-
-
- /**
- * Constructs a Powerpoint document from the underlying
- * HSLFSlideShow object. Finds the model stuff from this
- *
- * @param hslfSlideShow the HSLFSlideShow to base on
- */
- public SlideShow(HSLFSlideShow hslfSlideShow) {
- // Get useful things from our base slideshow
- _hslfSlideShow = hslfSlideShow;
-
- // Handle Parent-aware Records
- for (Record record : _hslfSlideShow.getRecords()) {
- if(record instanceof RecordContainer){
- RecordContainer.handleParentAwareRecords((RecordContainer)record);
- }
- }
-
- // Find the versions of the core records we'll want to use
- findMostRecentCoreRecords();
-
- // Build up the model level Slides and Notes
- buildSlidesAndNotes();
- }
-
- /**
- * Constructs a new, empty, Powerpoint document.
- */
- public SlideShow() {
- this(HSLFSlideShow.create());
- }
-
- /**
- * Constructs a Powerpoint document from an input stream.
- */
- public SlideShow(InputStream inputStream) throws IOException {
- this(new HSLFSlideShow(inputStream));
- }
-
- /**
- * Use the PersistPtrHolder entries to figure out what is the "most recent"
- * version of all the core records (Document, Notes, Slide etc), and save a
- * record of them. Do this by walking from the oldest PersistPtr to the
- * newest, overwriting any references found along the way with newer ones
- */
- private void findMostRecentCoreRecords() {
- // To start with, find the most recent in the byte offset domain
- Map mostRecentByBytes = new HashMap();
- for (Record record : _hslfSlideShow.getRecords()) {
- if (record instanceof PersistPtrHolder) {
- PersistPtrHolder pph = (PersistPtrHolder) record;
-
- // If we've already seen any of the "slide" IDs for this
- // PersistPtr, remove their old positions
- int[] ids = pph.getKnownSlideIDs();
- for (int id : ids) {
- if (mostRecentByBytes.containsKey(id)) {
- mostRecentByBytes.remove(id);
- }
- }
-
- // Now, update the byte level locations with their latest values
- Map thisSetOfLocations = pph.getSlideLocationsLookup();
- for (int id : ids) {
- mostRecentByBytes.put(id, thisSetOfLocations.get(id));
- }
- }
- }
-
- // We now know how many unique special records we have, so init
- // the array
- _mostRecentCoreRecords = new Record[mostRecentByBytes.size()];
-
- // We'll also want to be able to turn the slide IDs into a position
- // in this array
- _sheetIdToCoreRecordsLookup = new HashMap();
- Integer[] allIDs = mostRecentByBytes.keySet().toArray(new Integer[mostRecentByBytes.size()]);
- Arrays.sort(allIDs);
- for (int i = 0; i < allIDs.length; i++) {
- _sheetIdToCoreRecordsLookup.put(allIDs[i], i);
- }
-
- Map mostRecentByBytesRev = new HashMap(mostRecentByBytes.size());
- for (Map.Entry me : mostRecentByBytes.entrySet()) {
- mostRecentByBytesRev.put(me.getValue(), me.getKey());
- }
-
- // Now convert the byte offsets back into record offsets
- for (Record record : _hslfSlideShow.getRecords()) {
- if (!(record instanceof PositionDependentRecord)) continue;
-
- PositionDependentRecord pdr = (PositionDependentRecord) record;
- int recordAt = pdr.getLastOnDiskOffset();
-
- Integer thisID = mostRecentByBytesRev.get(recordAt);
-
- if (thisID == null) continue;
-
- // Bingo. Now, where do we store it?
- int storeAt = _sheetIdToCoreRecordsLookup.get(thisID);
-
- // Tell it its Sheet ID, if it cares
- if (pdr instanceof PositionDependentRecordContainer) {
- PositionDependentRecordContainer pdrc = (PositionDependentRecordContainer) record;
- pdrc.setSheetId(thisID);
- }
-
- // Finally, save the record
- _mostRecentCoreRecords[storeAt] = record;
- }
-
- // Now look for the interesting records in there
- for (Record record : _mostRecentCoreRecords) {
- // Check there really is a record at this number
- if (record != null) {
- // Find the Document, and interesting things in it
- if (record.getRecordType() == RecordTypes.Document.typeID) {
- _documentRecord = (Document) record;
- _fonts = _documentRecord.getEnvironment().getFontCollection();
- }
- } else {
- // No record at this number
- // Odd, but not normally a problem
- }
- }
- }
-
- /**
- * For a given SlideAtomsSet, return the core record, based on the refID
- * from the SlidePersistAtom
- */
- private Record getCoreRecordForSAS(SlideAtomsSet sas) {
- SlidePersistAtom spa = sas.getSlidePersistAtom();
- int refID = spa.getRefID();
- return getCoreRecordForRefID(refID);
- }
-
- /**
- * For a given refID (the internal, 0 based numbering scheme), return the
- * core record
- *
- * @param refID
- * the refID
- */
- private Record getCoreRecordForRefID(int refID) {
- Integer coreRecordId = _sheetIdToCoreRecordsLookup.get(refID);
- if (coreRecordId != null) {
- Record r = _mostRecentCoreRecords[coreRecordId];
- return r;
- }
- logger.log(POILogger.ERROR,
- "We tried to look up a reference to a core record, but there was no core ID for reference ID "
- + refID);
- return null;
- }
-
- /**
- * Build up model level Slide and Notes objects, from the underlying
- * records.
- */
- private void buildSlidesAndNotes() {
- // Ensure we really found a Document record earlier
- // If we didn't, then the file is probably corrupt
- if (_documentRecord == null) {
- throw new CorruptPowerPointFileException(
- "The PowerPoint file didn't contain a Document Record in its PersistPtr blocks. It is probably corrupt.");
- }
-
- // Fetch the SlideListWithTexts in the most up-to-date Document Record
- //
- // As far as we understand it:
- // * The first SlideListWithText will contain a SlideAtomsSet
- // for each of the master slides
- // * The second SlideListWithText will contain a SlideAtomsSet
- // for each of the slides, in their current order
- // These SlideAtomsSets will normally contain text
- // * The third SlideListWithText (if present), will contain a
- // SlideAtomsSet for each Notes
- // These SlideAtomsSets will not normally contain text
- //
- // Having indentified the masters, slides and notes + their orders,
- // we have to go and find their matching records
- // We always use the latest versions of these records, and use the
- // SlideAtom/NotesAtom to match them with the StyleAtomSet
-
- SlideListWithText masterSLWT = _documentRecord.getMasterSlideListWithText();
- SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
- SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
-
- // Find master slides
- // These can be MainMaster records, but oddly they can also be
- // Slides or Notes, and possibly even other odd stuff....
- // About the only thing you can say is that the master details are in
- // the first SLWT.
- SlideAtomsSet[] masterSets = new SlideAtomsSet[0];
- if (masterSLWT != null) {
- masterSets = masterSLWT.getSlideAtomsSets();
-
- ArrayList mmr = new ArrayList();
- ArrayList tmr = new ArrayList();
-
- for (SlideAtomsSet sas : masterSets) {
- Record r = getCoreRecordForSAS(sas);
- int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
- if (r instanceof org.apache.poi.hslf.record.Slide) {
- TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide) r,
- sheetNo);
- master.setSlideShow(this);
- tmr.add(master);
- } else if (r instanceof org.apache.poi.hslf.record.MainMaster) {
- SlideMaster master = new SlideMaster((org.apache.poi.hslf.record.MainMaster) r,
- sheetNo);
- master.setSlideShow(this);
- mmr.add(master);
- }
- }
-
- _masters = mmr.toArray(new SlideMaster[mmr.size()]);
- _titleMasters = tmr.toArray(new TitleMaster[tmr.size()]);
- }
-
- // Having sorted out the masters, that leaves the notes and slides
-
- // Start by finding the notes records to go with the entries in
- // notesSLWT
- org.apache.poi.hslf.record.Notes[] notesRecords;
- SlideAtomsSet[] notesSets = new SlideAtomsSet[0];
- Map slideIdToNotes = new HashMap();
- if (notesSLWT == null) {
- // None
- notesRecords = new org.apache.poi.hslf.record.Notes[0];
- } else {
- // Match up the records and the SlideAtomSets
- notesSets = notesSLWT.getSlideAtomsSets();
- List notesRecordsL =
- new ArrayList();
- for (int i = 0; i < notesSets.length; i++) {
- // Get the right core record
- Record r = getCoreRecordForSAS(notesSets[i]);
-
- // Ensure it really is a notes record
- if (r == null || r instanceof org.apache.poi.hslf.record.Notes) {
- if (r == null) {
- logger.log(POILogger.WARN, "A Notes SlideAtomSet at " + i
- + " said its record was at refID "
- + notesSets[i].getSlidePersistAtom().getRefID()
- + ", but that record didn't exist - record ignored.");
- }
- // we need to add also null-records, otherwise the index references to other existing
- // don't work anymore
- org.apache.poi.hslf.record.Notes notesRecord = (org.apache.poi.hslf.record.Notes) r;
- notesRecordsL.add(notesRecord);
-
- // Record the match between slide id and these notes
- SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
- int slideId = spa.getSlideIdentifier();
- slideIdToNotes.put(slideId, i);
- } else {
- logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i
- + " said its record was at refID "
- + notesSets[i].getSlidePersistAtom().getRefID()
- + ", but that was actually a " + r);
- }
- }
- notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()];
- notesRecords = notesRecordsL.toArray(notesRecords);
- }
-
- // Now, do the same thing for our slides
- org.apache.poi.hslf.record.Slide[] slidesRecords;
- SlideAtomsSet[] slidesSets = new SlideAtomsSet[0];
- if (slidesSLWT == null) {
- // None
- slidesRecords = new org.apache.poi.hslf.record.Slide[0];
- } else {
- // Match up the records and the SlideAtomSets
- slidesSets = slidesSLWT.getSlideAtomsSets();
- slidesRecords = new org.apache.poi.hslf.record.Slide[slidesSets.length];
- for (int i = 0; i < slidesSets.length; i++) {
- // Get the right core record
- Record r = getCoreRecordForSAS(slidesSets[i]);
-
- // Ensure it really is a slide record
- if (r instanceof org.apache.poi.hslf.record.Slide) {
- slidesRecords[i] = (org.apache.poi.hslf.record.Slide) r;
- } else {
- logger.log(POILogger.ERROR, "A Slide SlideAtomSet at " + i
- + " said its record was at refID "
- + slidesSets[i].getSlidePersistAtom().getRefID()
- + ", but that was actually a " + r);
- }
- }
- }
-
- // Finally, generate model objects for everything
- // Notes first
- _notes = new Notes[notesRecords.length];
- for (int i = 0; i < _notes.length; i++) {
- if (notesRecords[i] != null) {
- _notes[i] = new Notes(notesRecords[i]);
- _notes[i].setSlideShow(this);
- }
- }
- // Then slides
- _slides = new Slide[slidesRecords.length];
- for (int i = 0; i < _slides.length; i++) {
- SlideAtomsSet sas = slidesSets[i];
- int slideIdentifier = sas.getSlidePersistAtom().getSlideIdentifier();
-
- // Do we have a notes for this?
- Notes notes = null;
- // Slide.SlideAtom.notesId references the corresponding notes slide.
- // 0 if slide has no notes.
- int noteId = slidesRecords[i].getSlideAtom().getNotesID();
- if (noteId != 0) {
- Integer notesPos = slideIdToNotes.get(noteId);
- if (notesPos != null) {
- notes = _notes[notesPos];
- } else {
- logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId);
- }
- }
-
- // Now, build our slide
- _slides[i] = new Slide(slidesRecords[i], notes, sas, slideIdentifier, (i + 1));
- _slides[i].setSlideShow(this);
- }
- }
-
- /**
- * Writes out the slideshow file the is represented by an instance of this
- * class
- *
- * @param out
- * The OutputStream to write to.
- * @throws IOException
- * If there is an unexpected IOException from the passed in
- * OutputStream
- */
- public void write(OutputStream out) throws IOException {
- _hslfSlideShow.write(out);
- }
-
- /*
- * ===============================================================
- * Accessor Code
- * ===============================================================
- */
-
- /**
- * Returns an array of the most recent version of all the interesting
- * records
- */
- public Record[] getMostRecentCoreRecords() {
- return _mostRecentCoreRecords;
- }
-
- /**
- * Returns an array of all the normal Slides found in the slideshow
- */
- public Slide[] getSlides() {
- return _slides;
- }
-
- /**
- * Returns an array of all the normal Notes found in the slideshow
- */
- public Notes[] getNotes() {
- return _notes;
- }
-
- /**
- * Returns an array of all the normal Slide Masters found in the slideshow
- */
- public SlideMaster[] getSlidesMasters() {
- return _masters;
- }
-
- /**
- * Returns an array of all the normal Title Masters found in the slideshow
- */
- public TitleMaster[] getTitleMasters() {
- return _titleMasters;
- }
-
- /**
- * Returns the data of all the pictures attached to the SlideShow
- */
- public PictureData[] getPictureData() {
- return _hslfSlideShow.getPictures();
- }
-
- /**
- * Returns the data of all the embedded OLE object in the SlideShow
- */
- public ObjectData[] getEmbeddedObjects() {
- return _hslfSlideShow.getEmbeddedObjects();
- }
-
- /**
- * Returns the data of all the embedded sounds in the SlideShow
- */
- public SoundData[] getSoundData() {
- return SoundData.find(_documentRecord);
- }
-
- /**
- * Return the current page size
- */
- public Dimension getPageSize() {
- DocumentAtom docatom = _documentRecord.getDocumentAtom();
- int pgx = (int) docatom.getSlideSizeX() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
- int pgy = (int) docatom.getSlideSizeY() * HSLFShape.POINT_DPI / HSLFShape.MASTER_DPI;
- return new Dimension(pgx, pgy);
- }
-
- /**
- * Change the current page size
- *
- * @param pgsize
- * page size (in points)
- */
- public void setPageSize(Dimension pgsize) {
- DocumentAtom docatom = _documentRecord.getDocumentAtom();
- docatom.setSlideSizeX(pgsize.width * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
- docatom.setSlideSizeY(pgsize.height * HSLFShape.MASTER_DPI / HSLFShape.POINT_DPI);
- }
-
- /**
- * Helper method for usermodel: Get the font collection
- */
- protected FontCollection getFontCollection() {
- return _fonts;
- }
-
- /**
- * Helper method for usermodel and model: Get the document record
- */
- public Document getDocumentRecord() {
- return _documentRecord;
- }
-
- /*
- * ===============================================================
- * Re-ordering Code
- * ===============================================================
- */
-
- /**
- * Re-orders a slide, to a new position.
- *
- * @param oldSlideNumber
- * The old slide number (1 based)
- * @param newSlideNumber
- * The new slide number (1 based)
- */
- public void reorderSlide(int oldSlideNumber, int newSlideNumber) {
- // Ensure these numbers are valid
- if (oldSlideNumber < 1 || newSlideNumber < 1) {
- throw new IllegalArgumentException("Old and new slide numbers must be greater than 0");
- }
- if (oldSlideNumber > _slides.length || newSlideNumber > _slides.length) {
- throw new IllegalArgumentException(
- "Old and new slide numbers must not exceed the number of slides ("
- + _slides.length + ")");
- }
-
- // The order of slides is defined by the order of slide atom sets in the
- // SlideListWithText container.
- SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
- SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
-
- SlideAtomsSet tmp = sas[oldSlideNumber - 1];
- sas[oldSlideNumber - 1] = sas[newSlideNumber - 1];
- sas[newSlideNumber - 1] = tmp;
-
- ArrayList lst = new ArrayList();
- for (int i = 0; i < sas.length; i++) {
- lst.add(sas[i].getSlidePersistAtom());
- Record[] r = sas[i].getSlideRecords();
- for (int j = 0; j < r.length; j++) {
- lst.add(r[j]);
- }
- _slides[i].setSlideNumber(i + 1);
- }
- Record[] r = lst.toArray(new Record[lst.size()]);
- slwt.setChildRecord(r);
- }
-
- /**
- * Removes the slide at the given index (0-based).
- *
- * Shifts any subsequent slides to the left (subtracts one from their slide
- * numbers).
- *
- *
- * @param index
- * the index of the slide to remove (0-based)
- * @return the slide that was removed from the slide show.
- */
- public Slide removeSlide(int index) {
- int lastSlideIdx = _slides.length - 1;
- if (index < 0 || index > lastSlideIdx) {
- throw new IllegalArgumentException("Slide index (" + index + ") is out of range (0.."
- + lastSlideIdx + ")");
- }
-
- SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
- SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
-
- Slide removedSlide = null;
- ArrayList records = new ArrayList();
- ArrayList sa = new ArrayList();
- ArrayList sl = new ArrayList();
-
- ArrayList nt = new ArrayList();
- for (Notes notes : getNotes())
- nt.add(notes);
-
- for (int i = 0, num = 0; i < _slides.length; i++) {
- if (i != index) {
- sl.add(_slides[i]);
- sa.add(sas[i]);
- _slides[i].setSlideNumber(num++);
- records.add(sas[i].getSlidePersistAtom());
- records.addAll(Arrays.asList(sas[i].getSlideRecords()));
- } else {
- removedSlide = _slides[i];
- nt.remove(_slides[i].getNotesSheet());
- }
- }
- if (sa.size() == 0) {
- _documentRecord.removeSlideListWithText(slwt);
- } else {
- slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
- slwt.setChildRecord(records.toArray(new Record[records.size()]));
- }
- _slides = sl.toArray(new Slide[sl.size()]);
-
- // if the removed slide had notes - remove references to them too
-
- if (removedSlide != null) {
- int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
- if (notesId != 0) {
- SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
- records = new ArrayList();
- ArrayList na = new ArrayList();
- for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
- if (ns.getSlidePersistAtom().getSlideIdentifier() != notesId) {
- na.add(ns);
- records.add(ns.getSlidePersistAtom());
- if (ns.getSlideRecords() != null)
- records.addAll(Arrays.asList(ns.getSlideRecords()));
- }
- }
- if (na.size() == 0) {
- _documentRecord.removeSlideListWithText(nslwt);
- } else {
- nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[na.size()]));
- nslwt.setChildRecord(records.toArray(new Record[records.size()]));
- }
-
- }
- }
- _notes = nt.toArray(new Notes[nt.size()]);
-
- return removedSlide;
- }
-
- /*
- * ===============================================================
- * Addition Code
- * ===============================================================
- */
-
- /**
- * Create a blank Slide
.
- *
- * @return the created Slide
- */
- public Slide createSlide() {
- 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();
- slist.setInstance(SlideListWithText.SLIDES);
- _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;
- for (SlideAtomsSet sas : slist.getSlideAtomsSets()) {
- SlidePersistAtom spa = sas.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 psrId = addPersistentObject(slideRecord);
- sp.setRefID(psrId);
- slideRecord.setSheetId(psrId);
-
- slide.setMasterSheet(_masters[0]);
- // All done and added
- return slide;
- }
-
- /**
- * Adds a picture to this presentation and returns the associated index.
- *
- * @param data
- * picture data
- * @param format
- * the format of the picture. One of constans defined in the
- * Picture
class.
- * @return the index to this picture (1 based).
- */
- public int addPicture(byte[] data, int format) throws IOException {
- byte[] uid = PictureData.getChecksum(data);
-
- EscherContainerRecord bstore;
-
- EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
- bstore = (EscherContainerRecord) HSLFShape.getEscherChild(dggContainer,
- EscherContainerRecord.BSTORE_CONTAINER);
- if (bstore == null) {
- bstore = new EscherContainerRecord();
- bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
-
- dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
- } else {
- Iterator iter = bstore.getChildIterator();
- for (int i = 0; iter.hasNext(); i++) {
- EscherBSERecord bse = (EscherBSERecord) iter.next();
- if (Arrays.equals(bse.getUid(), uid)) {
- return i + 1;
- }
- }
- }
-
- PictureData pict = PictureData.create(format);
- pict.setData(data);
-
- int offset = _hslfSlideShow.addPicture(pict);
-
- 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);
- bse.setRemainingData(new byte[0]);
-
- bstore.addChildRecord(bse);
- int count = bstore.getChildRecords().size();
- bstore.setOptions((short) ((count << 4) | 0xF));
-
- return count;
- }
-
- /**
- * Adds a picture to this presentation and returns the associated index.
- *
- * @param pict
- * the file containing the image to add
- * @param format
- * the format of the picture. One of constans defined in the
- * Picture
class.
- * @return the index to this picture (1 based).
- */
- public int addPicture(File pict, int format) throws IOException {
- int length = (int) pict.length();
- byte[] data = new byte[length];
- FileInputStream is = null;
- try {
- is = new FileInputStream(pict);
- is.read(data);
- } finally {
- if(is != null) is.close();
- }
- return addPicture(data, format);
- }
-
- /**
- * Add a font in this presentation
- *
- * @param font
- * the font to add
- * @return 0-based index of the font
- */
- 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;
- }
-
- /**
- * Get a font by index
- *
- * @param idx
- * 0-based index of the font
- * @return of an instance of PPFont
or null
if not
- * found
- */
- public PPFont getFont(int idx) {
- FontCollection fonts = getDocumentRecord().getEnvironment().getFontCollection();
- for (Record ch : fonts.getChildRecords()) {
- if (ch instanceof FontEntityAtom) {
- FontEntityAtom atom = (FontEntityAtom) ch;
- if (atom.getFontIndex() == idx) {
- return new PPFont(atom);
- }
- }
- }
- return null;
- }
-
- /**
- * get the number of fonts in the presentation
- *
- * @return number of fonts
- */
- public int getNumberOfFonts() {
- return getDocumentRecord().getEnvironment().getFontCollection().getNumberOfFonts();
- }
-
- /**
- * Return Header / Footer settings for slides
- *
- * @return Header / Footer settings for slides
- */
- public HeadersFooters getSlideHeadersFooters() {
- // detect if this ppt was saved in Office2007
- String tag = getSlidesMasters()[0].getProgrammableTag();
- boolean ppt2007 = "___PPT12".equals(tag);
-
- HeadersFootersContainer hdd = null;
- for (Record ch : _documentRecord.getChildRecords()) {
- if (ch instanceof HeadersFootersContainer
- && ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.SlideHeadersFootersContainer) {
- hdd = (HeadersFootersContainer) ch;
- break;
- }
- }
- boolean newRecord = false;
- if (hdd == null) {
- hdd = new HeadersFootersContainer(HeadersFootersContainer.SlideHeadersFootersContainer);
- newRecord = true;
- }
- return new HeadersFooters(hdd, this, newRecord, ppt2007);
- }
-
- /**
- * Return Header / Footer settings for notes
- *
- * @return Header / Footer settings for notes
- */
- public HeadersFooters getNotesHeadersFooters() {
- // detect if this ppt was saved in Office2007
- String tag = getSlidesMasters()[0].getProgrammableTag();
- boolean ppt2007 = "___PPT12".equals(tag);
-
- HeadersFootersContainer hdd = null;
- for (Record ch : _documentRecord.getChildRecords()) {
- if (ch instanceof HeadersFootersContainer
- && ((HeadersFootersContainer) ch).getOptions() == HeadersFootersContainer.NotesHeadersFootersContainer) {
- hdd = (HeadersFootersContainer) ch;
- break;
- }
- }
- boolean newRecord = false;
- if (hdd == null) {
- hdd = new HeadersFootersContainer(HeadersFootersContainer.NotesHeadersFootersContainer);
- newRecord = true;
- }
- if (ppt2007 && _notes.length > 0) {
- return new HeadersFooters(hdd, _notes[0], newRecord, ppt2007);
- }
- return new HeadersFooters(hdd, this, newRecord, ppt2007);
- }
-
- /**
- * Add a movie in this presentation
- *
- * @param path
- * the path or url to the movie
- * @return 0-based index of the movie
- */
- public int addMovie(String path, int type) {
- ExMCIMovie mci;
- switch (type) {
- case MovieShape.MOVIE_MPEG:
- mci = new ExMCIMovie();
- break;
- case MovieShape.MOVIE_AVI:
- mci = new ExAviMovie();
- break;
- default:
- throw new IllegalArgumentException("Unsupported Movie: " + type);
- }
-
- ExVideoContainer exVideo = mci.getExVideo();
- exVideo.getExMediaAtom().setMask(0xE80000);
- exVideo.getPathAtom().setText(path);
-
- int objectId = addToObjListAtom(mci);
- exVideo.getExMediaAtom().setObjectId(objectId);
-
- return objectId;
- }
-
- /**
- * Add a control in this presentation
- *
- * @param name
- * name of the control, e.g. "Shockwave Flash Object"
- * @param progId
- * OLE Programmatic Identifier, e.g.
- * "ShockwaveFlash.ShockwaveFlash.9"
- * @return 0-based index of the control
- */
- public int addControl(String name, String progId) {
- ExControl ctrl = new ExControl();
- ctrl.setProgId(progId);
- ctrl.setMenuName(name);
- ctrl.setClipboardName(name);
-
- ExOleObjAtom oleObj = ctrl.getExOleObjAtom();
- oleObj.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
- oleObj.setType(ExOleObjAtom.TYPE_CONTROL);
- oleObj.setSubType(ExOleObjAtom.SUBTYPE_DEFAULT);
-
- int objectId = addToObjListAtom(ctrl);
- oleObj.setObjID(objectId);
- return objectId;
- }
-
- /**
- * Add a hyperlink to this presentation
- *
- * @return 0-based index of the hyperlink
- */
- public int addHyperlink(Hyperlink link) {
- ExHyperlink ctrl = new ExHyperlink();
- ExHyperlinkAtom obj = ctrl.getExHyperlinkAtom();
- if(link.getType() == Hyperlink.LINK_SLIDENUMBER) {
- ctrl.setLinkURL(link.getAddress(), 0x30);
- } else {
- ctrl.setLinkURL(link.getAddress());
- }
- ctrl.setLinkTitle(link.getTitle());
-
- int objectId = addToObjListAtom(ctrl);
- link.setId(objectId);
- obj.setNumber(objectId);
-
- return objectId;
- }
-
- /**
- * Add a embedded object to this presentation
- *
- * @return 0-based index of the embedded object
- */
- public int addEmbed(POIFSFileSystem poiData) {
- DirectoryNode root = poiData.getRoot();
-
- // prepare embedded data
- if (new ClassID().equals(root.getStorageClsid())) {
- // need to set class id
- Map olemap = getOleMap();
- ClassID classID = null;
- for (Map.Entry entry : olemap.entrySet()) {
- if (root.hasEntry(entry.getKey())) {
- classID = entry.getValue();
- break;
- }
- }
- if (classID == null) {
- throw new IllegalArgumentException("Unsupported embedded document");
- }
-
- root.setStorageClsid(classID);
- }
-
- ExEmbed exEmbed = new ExEmbed();
- // remove unneccessary infos, so we don't need to specify the type
- // of the ole object multiple times
- Record children[] = exEmbed.getChildRecords();
- exEmbed.removeChild(children[2]);
- exEmbed.removeChild(children[3]);
- exEmbed.removeChild(children[4]);
-
- ExEmbedAtom eeEmbed = exEmbed.getExEmbedAtom();
- eeEmbed.setCantLockServerB(true);
-
- ExOleObjAtom eeAtom = exEmbed.getExOleObjAtom();
- eeAtom.setDrawAspect(ExOleObjAtom.DRAW_ASPECT_VISIBLE);
- eeAtom.setType(ExOleObjAtom.TYPE_EMBEDDED);
- // eeAtom.setSubType(ExOleObjAtom.SUBTYPE_EXCEL);
- // should be ignored?!?, see MS-PPT ExOleObjAtom, but Libre Office sets it ...
- eeAtom.setOptions(1226240);
-
- ExOleObjStg exOleObjStg = new ExOleObjStg();
- try {
- final String OLESTREAM_NAME = "\u0001Ole";
- if (!root.hasEntry(OLESTREAM_NAME)) {
- // the following data was taken from an example libre office document
- // beside this "\u0001Ole" record there were several other records, e.g. CompObj,
- // OlePresXXX, but it seems, that they aren't neccessary
- byte oleBytes[] = { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- poiData.createDocument(new ByteArrayInputStream(oleBytes), OLESTREAM_NAME);
- }
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- poiData.writeFilesystem(bos);
- exOleObjStg.setData(bos.toByteArray());
- } catch (IOException e) {
- throw new HSLFException(e);
- }
-
- int psrId = addPersistentObject(exOleObjStg);
- exOleObjStg.setPersistId(psrId);
- eeAtom.setObjStgDataRef(psrId);
-
- int objectId = addToObjListAtom(exEmbed);
- eeAtom.setObjID(objectId);
- return objectId;
- }
-
- protected int addToObjListAtom(RecordContainer exObj) {
- ExObjList lst = (ExObjList) _documentRecord.findFirstOfType(RecordTypes.ExObjList.typeID);
- if (lst == null) {
- lst = new ExObjList();
- _documentRecord.addChildAfter(lst, _documentRecord.getDocumentAtom());
- }
- ExObjListAtom objAtom = lst.getExObjListAtom();
- // increment the object ID seed
- int objectId = (int) objAtom.getObjectIDSeed() + 1;
- objAtom.setObjectIDSeed(objectId);
-
- lst.addChildAfter(exObj, objAtom);
-
- return objectId;
- }
-
- protected static Map getOleMap() {
- Map olemap = new HashMap();
- olemap.put("PowerPoint Document", ClassID.PPT_SHOW);
- olemap.put("Workbook", ClassID.EXCEL97); // as per BIFF8 spec
- olemap.put("WORKBOOK", ClassID.EXCEL97); // Typically from third party programs
- olemap.put("BOOK", ClassID.EXCEL97); // Typically odd Crystal Reports exports
- // ... to be continued
- return olemap;
- }
-
- protected int addPersistentObject(PositionDependentRecord slideRecord) {
- slideRecord.setLastOnDiskOffset(HSLFSlideShow.UNSET_OFFSET);
- _hslfSlideShow.appendRootLevelRecord((Record)slideRecord);
-
- // For position dependent records, hold where they were and now are
- // As we go along, update, and hand over, to any Position Dependent
- // records we happen across
- Map interestingRecords =
- new HashMap();
-
- try {
- _hslfSlideShow.updateAndWriteDependantRecords(null,interestingRecords);
- } catch (IOException e) {
- throw new HSLFException(e);
- }
-
- PersistPtrHolder ptr = (PersistPtrHolder)interestingRecords.get(RecordTypes.PersistPtrIncrementalBlock);
- UserEditAtom usr = (UserEditAtom)interestingRecords.get(RecordTypes.UserEditAtom);
-
- // persist ID is UserEditAtom.maxPersistWritten + 1
- int psrId = usr.getMaxPersistWritten() + 1;
-
- // Last view is now of the slide
- usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
- // increment the number of persistent objects
- usr.setMaxPersistWritten(psrId);
-
- // Add the new slide into the last PersistPtr
- // (Also need to tell it where it is)
- int slideOffset = slideRecord.getLastOnDiskOffset();
- slideRecord.setLastOnDiskOffset(slideOffset);
- ptr.addSlideLookup(psrId, slideOffset);
- logger.log(POILogger.INFO, "New slide/object ended up at " + slideOffset);
-
- return psrId;
- }
-}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java
deleted file mode 100644
index 9fd85e1bdb..0000000000
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SoundData.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/* ====================================================================
- 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 org.apache.poi.hslf.record.*;
-
-import java.util.ArrayList;
-
-/**
- * A class that represents sound data embedded in a slide show.
- *
- * @author Yegor Kozlov
- */
-public final class SoundData {
- /**
- * The record that contains the object data.
- */
- private Sound _container;
-
- /**
- * Creates the object data wrapping the record that contains the sound data.
- *
- * @param container the record that contains the sound data.
- */
- public SoundData(Sound container) {
- this._container = container;
- }
-
- /**
- * Name of the sound (e.g. "crash")
- *
- * @return name of the sound
- */
- public String getSoundName(){
- return _container.getSoundName();
- }
-
- /**
- * Type of the sound (e.g. ".wav")
- *
- * @return type of the sound
- */
- public String getSoundType(){
- return _container.getSoundType();
- }
-
- /**
- * Gets an input stream which returns the binary of the sound data.
- *
- * @return the input stream which will contain the binary of the sound data.
- */
- public byte[] getData() {
- return _container.getSoundData();
- }
-
- /**
- * Find all sound records in the supplied Document records
- *
- * @param document the document to find in
- * @return the array with the sound data
- */
- public static SoundData[] find(Document document){
- ArrayList lst = new ArrayList();
- Record[] ch = document.getChildRecords();
- for (int i = 0; i < ch.length; i++) {
- if(ch[i].getRecordType() == RecordTypes.SoundCollection.typeID){
- RecordContainer col = (RecordContainer)ch[i];
- Record[] sr = col.getChildRecords();
- for (int j = 0; j < sr.length; j++) {
- if(sr[j] instanceof Sound){
- lst.add(new SoundData((Sound)sr[j]));
- }
- }
- }
-
- }
- return lst.toArray(new SoundData[lst.size()]);
- }
-}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawAutoShape.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawAutoShape.java
index f28c2cbfd4..f9fc966575 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawAutoShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawAutoShape.java
@@ -3,7 +3,7 @@ package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*;
-public class DrawAutoShape> extends DrawTextShape {
+public class DrawAutoShape>> extends DrawTextShape {
public DrawAutoShape(T shape) {
super(shape);
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java
index 80b95ee5f6..bf82208cdc 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawFactory.java
@@ -45,7 +45,7 @@ public class DrawFactory {
boolean isHint = false;
if (graphics != null) {
factory = (DrawFactory)graphics.getRenderingHint(DRAW_FACTORY);
- isHint = true;
+ isHint = (factory != null);
}
// secondly try the thread local default
if (factory == null) {
@@ -76,25 +76,25 @@ public class DrawFactory {
} else if (shape instanceof Background) {
return getDrawable((Background)shape);
} else if (shape instanceof Slide) {
- return getDrawable((Slide extends Shape>)shape);
+ return getDrawable((Slide extends Shape, ? extends SlideShow>)shape);
} else if (shape instanceof MasterSheet) {
- return getDrawable((MasterSheet extends Shape>)shape);
+ return getDrawable((MasterSheet extends Shape, ? extends SlideShow>)shape);
} else if (shape instanceof Sheet) {
- return getDrawable((Sheet extends Shape>)shape);
+ return getDrawable((Sheet extends Shape, ? extends SlideShow>)shape);
}
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
}
- public > DrawSlide getDrawable(T sheet) {
+ public > DrawSlide getDrawable(T sheet) {
return new DrawSlide(sheet);
}
- public > DrawSheet getDrawable(T sheet) {
+ public > DrawSheet getDrawable(T sheet) {
return new DrawSheet(sheet);
}
- public > DrawMasterSheet getDrawable(T sheet) {
+ public > DrawMasterSheet getDrawable(T sheet) {
return new DrawMasterSheet(sheet);
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawMasterSheet.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawMasterSheet.java
index 7a89828ede..452704a757 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawMasterSheet.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawMasterSheet.java
@@ -3,7 +3,7 @@ package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*;
-public class DrawMasterSheet> extends DrawSheet {
+public class DrawMasterSheet> extends DrawSheet {
public DrawMasterSheet(T sheet) {
super(sheet);
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java
index 77a0da740a..ca2346b207 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawPaint.java
@@ -17,6 +17,7 @@
package org.apache.poi.sl.draw;
+import static org.apache.poi.sl.usermodel.PaintStyle.TRANSPARENT_PAINT;
import java.awt.*;
import java.awt.MultipleGradientPaint.ColorSpaceType;
import java.awt.MultipleGradientPaint.CycleMethod;
@@ -35,7 +36,7 @@ import org.apache.poi.util.POILogger;
public class DrawPaint {
- public final static Color NO_PAINT = new Color(0xFF, 0xFF, 0xFF, 0);
+
private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class);
protected PlaceableShape shape;
@@ -43,6 +44,21 @@ public class DrawPaint {
public DrawPaint(PlaceableShape shape) {
this.shape = shape;
}
+
+ public static SolidPaint createSolidPaint(final Color color) {
+ return new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return new ColorStyle(){
+ public Color getColor() { return color; }
+ public int getAlpha() { return -1; }
+ public int getLumOff() { return -1; }
+ public int getLumMod() { return -1; }
+ public int getShade() { return -1; }
+ public int getTint() { return -1; }
+ };
+ }
+ };
+ }
public Paint getPaint(Graphics2D graphics, PaintStyle paint) {
if (paint instanceof SolidPaint) {
@@ -74,7 +90,7 @@ public class DrawPaint {
protected Paint getTexturePaint(TexturePaint fill, Graphics2D graphics) {
InputStream is = fill.getImageData();
- if (is == null) return NO_PAINT;
+ if (is == null) return TRANSPARENT_PAINT.getSolidColor().getColor();
assert(graphics != null);
ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER);
@@ -84,7 +100,7 @@ public class DrawPaint {
renderer.loadImage(fill.getImageData(), fill.getContentType());
} catch (IOException e) {
LOG.log(POILogger.ERROR, "Can't load image data - using transparent color", e);
- return NO_PAINT;
+ return TRANSPARENT_PAINT.getSolidColor().getColor();
}
int alpha = fill.getAlpha();
@@ -105,7 +121,9 @@ public class DrawPaint {
public static Color applyColorTransform(ColorStyle color){
Color result = color.getColor();
- if (result == null || color.getAlpha() == 100) return NO_PAINT;
+ if (result == null || color.getAlpha() == 100) {
+ return TRANSPARENT_PAINT.getSolidColor().getColor();
+ }
result = applyAlpha(result, color);
result = applyLuminanace(result, color);
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawShapeGroup.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawShapeGroup.java
index 238bb1a116..ceda9280c4 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawShapeGroup.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawShapeGroup.java
@@ -7,17 +7,12 @@ import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.*;
-public class DrawShapeGroup> implements Drawable {
+public class DrawShapeGroup> extends DrawShape implements Drawable {
- protected final T shape;
-
public DrawShapeGroup(T shape) {
- this.shape = shape;
+ super(shape);
}
- public void applyTransform(Graphics2D context) {
- }
-
public void draw(Graphics2D graphics) {
// the coordinate system of this group of shape
@@ -54,7 +49,4 @@ public class DrawShapeGroup> implements Dr
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
}
-
- public void drawContent(Graphics2D context) {
- }
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java
index d3901b39b3..d0026f31dc 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java
@@ -6,7 +6,7 @@ import java.awt.geom.AffineTransform;
import org.apache.poi.sl.usermodel.*;
-public class DrawSheet> implements Drawable {
+public class DrawSheet> implements Drawable {
protected final T sheet;
@@ -14,14 +14,9 @@ public class DrawSheet> implements Drawable {
this.sheet = sheet;
}
- public void applyTransform(Graphics2D context) {
- // TODO Auto-generated method stub
-
- }
-
public void draw(Graphics2D graphics) {
DrawFactory drawFact = DrawFactory.getInstance(graphics);
- MasterSheet extends Shape> master = sheet.getMasterSheet();
+ MasterSheet extends Shape, ? extends SlideShow> master = sheet.getMasterSheet();
if(sheet.getFollowMasterGraphics() && master != null) {
Drawable drawer = drawFact.getDrawable(master);
@@ -53,9 +48,10 @@ public class DrawSheet> implements Drawable {
}
}
+ public void applyTransform(Graphics2D context) {
+ }
+
public void drawContent(Graphics2D context) {
- // TODO Auto-generated method stub
-
}
/**
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java
index c5e5b4244c..4ff0034eba 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSimpleShape.java
@@ -18,7 +18,7 @@ import org.apache.poi.sl.draw.geom.*;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
-import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
+import org.apache.poi.sl.usermodel.StrokeStyle.*;
import org.apache.poi.util.Units;
@@ -223,15 +223,22 @@ public class DrawSimpleShape extends DrawShape {
if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt
LineDash lineDash = strokeStyle.getLineDash();
+ if (lineDash == null) {
+ lineDash = LineDash.SOLID;
+ lineWidth = 0.0f;
+ }
+
int dashPatI[] = lineDash.pattern;
float[] dashPatF = new float[dashPatI.length];
final float dash_phase = 0;
for (int i=0; i extends DrawShape {
int lineJoin = BasicStroke.JOIN_ROUND;
- return new BasicStroke(lineWidth, lineCap, lineJoin, Math.max(1, lineWidth), dashPatF, dash_phase);
+ return new BasicStroke(lineWidth, lineCap, lineJoin, lineWidth, dashPatF, dash_phase);
}
protected void drawShadow(
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java
index 8bc4eaf686..cada314ece 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSlide.java
@@ -5,7 +5,7 @@ import java.awt.Graphics2D;
import org.apache.poi.sl.usermodel.*;
-public class DrawSlide> extends DrawSheet {
+public class DrawSlide> extends DrawSheet {
public DrawSlide(T slide) {
super(slide);
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextFragment.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextFragment.java
index c9bf1f4085..4b2c79e378 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextFragment.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextFragment.java
@@ -4,8 +4,6 @@ import java.awt.Graphics2D;
import java.awt.font.TextLayout;
import java.text.*;
-import org.apache.poi.xslf.usermodel.XSLFRenderingHint;
-
public class DrawTextFragment implements Drawable {
final TextLayout layout;
final AttributedString str;
@@ -29,8 +27,8 @@ public class DrawTextFragment implements Drawable {
double yBaseline = y + layout.getAscent();
- Integer textMode = (Integer)graphics.getRenderingHint(XSLFRenderingHint.TEXT_RENDERING_MODE);
- if(textMode != null && textMode == XSLFRenderingHint.TEXT_AS_SHAPES){
+ Integer textMode = (Integer)graphics.getRenderingHint(Drawable.TEXT_RENDERING_MODE);
+ if(textMode != null && textMode == Drawable.TEXT_AS_SHAPES){
layout.draw(graphics, (float)x, (float)yBaseline);
} else {
graphics.drawString(str.getIterator(), (float)x, (float)yBaseline );
@@ -38,13 +36,9 @@ public class DrawTextFragment implements Drawable {
}
public void applyTransform(Graphics2D graphics) {
- // TODO Auto-generated method stub
-
}
public void drawContent(Graphics2D graphics) {
- // TODO Auto-generated method stub
-
}
public TextLayout getLayout() {
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextShape.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextShape.java
index cda6a1a88f..f0b4ff42b3 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawTextShape.java
@@ -8,7 +8,7 @@ import java.util.Iterator;
import org.apache.poi.sl.usermodel.*;
-public class DrawTextShape> extends DrawSimpleShape {
+public class DrawTextShape>> extends DrawSimpleShape {
public DrawTextShape(T shape) {
super(shape);
@@ -26,7 +26,7 @@ public class DrawTextShape> extends
// Transform of text in flipped shapes is special.
// At this point the flip and rotation transform is already applied
- // (see XSLFShape#applyTransform ), but we need to restore it to avoid painting "upside down".
+ // (see DrawShape#applyTransform ), but we need to restore it to avoid painting "upside down".
// See Bugzilla 54210.
if(shape.getFlipVertical()){
@@ -84,12 +84,12 @@ public class DrawTextShape> extends
Insets2D shapePadding = shape.getInsets();
double y0 = y;
- Iterator extends TextParagraph> paragraphs = shape.iterator();
+ Iterator extends TextParagraph extends TextRun>> paragraphs = shape.iterator();
boolean isFirstLine = true;
while (paragraphs.hasNext()){
- TextParagraph p = paragraphs.next();
- DrawTextParagraph dp = fact.getDrawable(p);
+ TextParagraph extends TextRun> p = paragraphs.next();
+ DrawTextParagraph extends TextRun> dp = fact.getDrawable(p);
dp.setInsets(shapePadding);
dp.breakText(graphics);
diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java b/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java
index d876d1512a..736dc0d668 100644
--- a/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java
+++ b/src/scratchpad/src/org/apache/poi/sl/draw/geom/PresetGeometries.java
@@ -45,7 +45,7 @@ public class PresetGeometries extends LinkedHashMap {
@SuppressWarnings("unused")
public void init(InputStream is) throws XMLStreamException, JAXBException {
- Reader xml = new InputStreamReader( is, Charset.forName("UTF-8") );
+ // Reader xml = new InputStreamReader( is, Charset.forName("UTF-8") );
// StAX:
@@ -58,7 +58,7 @@ public class PresetGeometries extends LinkedHashMap {
long cntElem = 0;
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
- XMLEventReader staxReader = staxFactory.createXMLEventReader(xml);
+ XMLEventReader staxReader = staxFactory.createXMLEventReader(is);
XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter);
// ignore StartElement:
XMLEvent evDoc = staxFiltRd.nextEvent();
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java
index 21c3a507fd..1bf073dfbb 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/AutoShape.java
@@ -17,5 +17,5 @@
package org.apache.poi.sl.usermodel;
-public interface AutoShape extends TextShape {
+public interface AutoShape> extends TextShape {
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/FreeformShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/FreeformShape.java
index 09d61989df..e0843a11a1 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/FreeformShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/FreeformShape.java
@@ -17,6 +17,6 @@
package org.apache.poi.sl.usermodel;
-public interface FreeformShape extends AutoShape {
+public interface FreeformShape> extends AutoShape {
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java
index 8ba80156bd..727217d3fa 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/MasterSheet.java
@@ -17,6 +17,6 @@
package org.apache.poi.sl.usermodel;
-public interface MasterSheet extends Sheet {
+public interface MasterSheet extends Sheet {
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java
index c16774c298..08f023cd9f 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Notes.java
@@ -17,6 +17,8 @@
package org.apache.poi.sl.usermodel;
-public interface Notes extends Sheet {
- public TextRun getTextRun();
+import java.util.List;
+
+public interface Notes extends Sheet {
+ List extends TextParagraph extends TextRun>> getTextParagraphs();
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/PaintStyle.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/PaintStyle.java
index 9dcd495e40..2551201692 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/PaintStyle.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/PaintStyle.java
@@ -17,8 +17,11 @@
package org.apache.poi.sl.usermodel;
+import java.awt.Color;
import java.io.InputStream;
+import org.apache.poi.sl.draw.DrawPaint;
+
public interface PaintStyle {
@@ -55,4 +58,6 @@ public interface PaintStyle {
*/
int getAlpha();
}
+
+ SolidPaint TRANSPARENT_PAINT = DrawPaint.createSolidPaint(new Color(0xFF, 0xFF, 0xFF, 0));
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java
index 6ad149b489..4de645d41f 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Shape.java
@@ -19,14 +19,11 @@ package org.apache.poi.sl.usermodel;
public interface Shape {
- ShapeContainer getParent();
+ ShapeContainer extends Shape> getParent();
/**
*
* @return the sheet this shape belongs to
*/
- Sheet getSheet();
-
-
-
+ Sheet extends Shape, ? extends SlideShow> getSheet();
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java
index 8de1dbcb06..7bd940c36c 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeGroup.java
@@ -19,6 +19,6 @@ package org.apache.poi.sl.usermodel;
import java.awt.geom.Rectangle2D;
-public interface ShapeGroup extends ShapeContainer, PlaceableShape {
+public interface ShapeGroup extends Shape, ShapeContainer, PlaceableShape {
Rectangle2D getInteriorAnchor();
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java
index 64b53a3014..6f4ba0ac67 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Sheet.java
@@ -21,8 +21,8 @@ package org.apache.poi.sl.usermodel;
/**
* Common parent of Slides, Notes and Masters
*/
-public interface Sheet extends ShapeContainer {
- SlideShow getSlideShow();
+public interface Sheet extends ShapeContainer {
+ SS getSlideShow();
/**
* @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
@@ -31,7 +31,7 @@ public interface Sheet extends ShapeContainer {
*/
boolean getFollowMasterGraphics();
- MasterSheet getMasterSheet();
+ MasterSheet getMasterSheet();
Background getBackground();
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java
index 243d9a8174..b2027c182c 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java
@@ -17,9 +17,9 @@
package org.apache.poi.sl.usermodel;
-public interface Slide extends Sheet {
- public Notes getNotes();
- public void setNotes(Notes notes);
+public interface Slide extends Sheet {
+ public Notes getNotes();
+ public void setNotes(Notes notes);
public boolean getFollowMasterBackground();
public void setFollowMasterBackground(boolean follow);
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java
index 4505ca5843..e3007f6c17 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/SlideShow.java
@@ -21,11 +21,11 @@ import java.awt.Dimension;
import java.io.IOException;
public interface SlideShow {
- Slide createSlide() throws IOException;
- MasterSheet createMasterSheet() throws IOException;
+ Slide extends Shape, ? extends SlideShow> createSlide() throws IOException;
+ MasterSheet extends Shape, ? extends SlideShow> createMasterSheet() throws IOException;
- Slide[] getSlides();
- MasterSheet[] getMasterSheet();
+ Slide extends Shape, ? extends SlideShow>[] getSlides();
+ MasterSheet extends Shape, ? extends SlideShow>[] getMasterSheet();
Resources getResources();
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java
index c02e1a33f9..a55317740a 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/StrokeStyle.java
@@ -33,27 +33,75 @@ public interface StrokeStyle {
* with actual line width
*/
enum LineDash {
- SOLID(1),
- DOT(1,1),
- DASH(3,4),
- LG_DASH(8,3),
- DASH_DOT(4,3,1,3),
- LG_DASH_DOT(8,3,1,3),
- LG_DASH_DOT_DOT(8,3,1,3,1,3),
- SYS_DASH(2,2),
- SYS_DOT(1,1),
- SYS_DASH_DOT,
- SYS_DASH_DOT_DOT;
-
- public int pattern[];
-
- LineDash(int... pattern) {
+ /** Solid (continuous) pen - native 1 */
+ SOLID(1, 1),
+ /** square dot style - native 6 */
+ DOT(6, 1,1),
+ /** dash style - native 7 */
+ DASH(7, 3,4),
+ /** dash short dash - native 9*/
+ DASH_DOT(9, 4,3,1,3),
+ /** long dash style - native 8 */
+ LG_DASH(8, 8,3),
+ /** long dash short dash - native 10 */
+ LG_DASH_DOT(10, 8,3,1,3),
+ /** long dash short dash short dash - native 11 */
+ LG_DASH_DOT_DOT(11, 8,3,1,3,1,3),
+ /** PS_DASH system dash style - native 2 */
+ SYS_DASH(2, 2,2),
+ /** PS_DOT system dash style - native 3 */
+ SYS_DOT(3, 1,1),
+ /** PS_DASHDOT system dash style - native 4 */
+ SYS_DASH_DOT(4, 2,2,1,1),
+ /** PS_DASHDOTDOT system dash style / native 5 */
+ SYS_DASH_DOT_DOT(5, 2,2,1,1,1,1);
+
+ public final int pattern[];
+ public final int nativeId;
+
+ LineDash(int nativeId, int... pattern) {
+ this.nativeId = nativeId;
this.pattern = (pattern == null || pattern.length == 0) ? new int[]{1} : pattern;
}
+
+ public static LineDash fromNativeId(int nativeId) {
+ for (LineDash ld : values()) {
+ if (ld.nativeId == nativeId) return ld;
+ }
+ return null;
+ }
+ }
+
+ enum LineCompound {
+ /** Single line (of width lineWidth) - native 0 / ooxml default */
+ SINGLE(0),
+ /** Double lines of equal width - native 1 / ooxml "dbl" */
+ DOUBLE(1),
+ /** Double lines, one thick, one thin - native 2 / ooxml "thickThin" */
+ THICK_THIN(2),
+ /** Double lines, reverse order - native 3 / ooxml "thinThick" */
+ THIN_THICK(3),
+ /** Three lines, thin, thick, thin - native 4 / ooxml "tri" */
+ TRIPLE(4);
+
+ public final int nativeId;
+
+ LineCompound(int nativeId) {
+ this.nativeId = nativeId;
+ }
+
+ public static LineCompound fromNativeId(int nativeId) {
+ for (LineCompound lc : values()) {
+ if (lc.nativeId == nativeId) return lc;
+ }
+ return null;
+ }
}
-
+
+
PaintStyle getPaint();
LineCap getLineCap();
LineDash getLineDash();
+ LineCompound getLineCompound();
double getLineWidth();
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java
index 9ac61d526a..3fa3bbe20d 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextBox.java
@@ -17,5 +17,5 @@
package org.apache.poi.sl.usermodel;
-public interface TextBox extends AutoShape {
+public interface TextBox> extends AutoShape {
}
diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java
index f9b1833610..a6a53fe1bd 100644
--- a/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java
+++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/TextShape.java
@@ -19,7 +19,7 @@ package org.apache.poi.sl.usermodel;
-public interface TextShape> extends SimpleShape, Iterable {
+public interface TextShape> extends SimpleShape, Iterable {
/**
* Vertical Text Types
*/
diff --git a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
index b3f91236ec..134f3e8ac0 100644
--- a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
+++ b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
@@ -22,9 +22,10 @@ package org.apache.poi;
import junit.framework.TestCase;
+
import java.io.*;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.poifs.filesystem.*;
@@ -47,7 +48,7 @@ public final class TestPOIDocumentScratchpad extends TestCase {
* a Word Document for our testing
*/
public void setUp() throws Exception {
- doc = new HSLFSlideShow(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
+ doc = new HSLFSlideShowImpl(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
doc2 = HWPFTestDataSamples.openSampleFile("test2.doc");
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java b/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java
index 6740708792..6207a4597d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/HSLFTestDataSamples.java
@@ -24,7 +24,8 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
public class HSLFTestDataSamples {
@@ -45,12 +46,12 @@ public class HSLFTestDataSamples {
* from a ByteArrayInputStream.
* Useful for verifying that the serialisation round trip
*/
- public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
+ public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new HSLFSlideShow(bais);
+ return new HSLFSlideShowImpl(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -61,12 +62,12 @@ public class HSLFTestDataSamples {
* from a ByteArrayInputStream.
* Useful for verifying that the serialisation round trip
*/
- public static SlideShow writeOutAndReadBack(SlideShow original) {
+ public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
original.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- return new SlideShow(bais);
+ return new HSLFSlideShow(bais);
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java
index da07810b86..3de6032ae5 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestEncryptedFile.java
@@ -21,6 +21,7 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
@@ -32,28 +33,28 @@ public final class TestEncryptedFile extends TestCase {
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
public void testLoadNonEncrypted() throws Exception {
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertNotNull(hss);
}
public void testLoadEncrypted() throws Exception {
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-np-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
}
try {
- new HSLFSlideShow(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
+ new HSLFSlideShowImpl(slTests.openResourceAsStream("Password_Protected-56-hello.ppt"));
fail();
} catch(EncryptedPowerPointFileException e) {
// Good
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
index 1398e747e1..ae64b3614d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java
@@ -25,7 +25,8 @@ import java.io.FileNotFoundException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -37,9 +38,9 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
*/
public final class TestReWrite extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow hssA;
- private HSLFSlideShow hssB;
- private HSLFSlideShow hssC;
+ private HSLFSlideShowImpl hssA;
+ private HSLFSlideShowImpl hssB;
+ private HSLFSlideShowImpl hssC;
// POIFS primed on the test data
private POIFSFileSystem pfsA;
private POIFSFileSystem pfsB;
@@ -50,20 +51,20 @@ public final class TestReWrite extends TestCase {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- hssA = new HSLFSlideShow(pfsA);
+ hssA = new HSLFSlideShowImpl(pfsA);
pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
- hssB = new HSLFSlideShow(pfsB);
+ hssB = new HSLFSlideShowImpl(pfsB);
pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
- hssC = new HSLFSlideShow(pfsC);
+ hssC = new HSLFSlideShowImpl(pfsC);
}
public void testWritesOutTheSame() throws Exception {
assertWritesOutTheSame(hssA, pfsA);
assertWritesOutTheSame(hssB, pfsB);
}
- public void assertWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
+ public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
// Write out to a byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hss.write(baos);
@@ -129,9 +130,9 @@ public final class TestReWrite extends TestCase {
// We need to identify and fix that first
//assertSlideShowWritesOutTheSame(hssB, pfsB);
}
- public void assertSlideShowWritesOutTheSame(HSLFSlideShow hss, POIFSFileSystem pfs) throws Exception {
+ public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
// Create a slideshow covering it
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
ss.getSlides();
ss.getNotes();
@@ -163,7 +164,7 @@ public final class TestReWrite extends TestCase {
}
public void test48593() throws Exception {
- SlideShow slideShow = new SlideShow();
+ HSLFSlideShow slideShow = new HSLFSlideShow();
slideShow.createSlide();
slideShow = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
slideShow.createSlide();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java
index ae76116a41..31a80ae306 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java
@@ -19,8 +19,11 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
+
import java.io.*;
import java.util.*;
+
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
@@ -33,14 +36,14 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestReWriteSanity extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow ss;
+ private HSLFSlideShowImpl ss;
// POIFS primed on the test data
private POIFSFileSystem pfs;
public TestReWriteSanity() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new HSLFSlideShow(pfs);
+ ss = new HSLFSlideShowImpl(pfs);
}
public void testUserEditAtomsRight() throws Exception {
@@ -52,7 +55,7 @@ public final class TestReWriteSanity extends TestCase {
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
// Create a new one from that
- HSLFSlideShow wss = new HSLFSlideShow(bais);
+ HSLFSlideShowImpl wss = new HSLFSlideShowImpl(bais);
// Find the location of the PersistPtrIncrementalBlocks and
// UserEditAtoms
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
index 5d509b6203..732f609381 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestRecordCounts.java
@@ -19,6 +19,8 @@ package org.apache.poi.hslf;
import junit.framework.TestCase;
+
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
import org.apache.poi.POIDataSamples;
@@ -30,11 +32,11 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestRecordCounts extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow ss;
+ private HSLFSlideShowImpl ss;
public TestRecordCounts() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- ss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
}
public void testSheetsCount() {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
index 7fc234f8ef..a00d75d03e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
@@ -23,9 +23,9 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.model.OLEShape;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -140,7 +140,7 @@ public final class TestExtractor extends POITestCase {
POIFSFileSystem fs = new POIFSFileSystem(
POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls")
);
- HSLFSlideShow ss;
+ HSLFSlideShowImpl ss;
DirectoryNode dirA = (DirectoryNode)
fs.getRoot().getEntry("MBD0000A3B6");
@@ -151,14 +151,14 @@ public final class TestExtractor extends POITestCase {
assertNotNull(dirB.getEntry("PowerPoint Document"));
// Check the first file
- ss = new HSLFSlideShow(dirA);
+ ss = new HSLFSlideShowImpl(dirA);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n",
ppe.getText(true, false)
);
// And the second
- ss = new HSLFSlideShow(dirB);
+ ss = new HSLFSlideShowImpl(dirB);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
ppe.getText(true, false)
@@ -186,7 +186,7 @@ public final class TestExtractor extends POITestCase {
num_doc++;
} else if ("Presentation".equals(name)) {
num_ppt++;
- SlideShow ppt = new SlideShow(data);
+ HSLFSlideShow ppt = new HSLFSlideShow(data);
}
}
assertEquals("Expected 2 embedded Word Documents", 2, num_doc);
@@ -241,8 +241,8 @@ public final class TestExtractor extends POITestCase {
String text;
// With a header on the notes
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Header.ppt"));
- SlideShow ss = new SlideShow(hslf);
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("45537_Header.ppt"));
+ HSLFSlideShow ss = new HSLFSlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText());
@@ -259,8 +259,8 @@ public final class TestExtractor extends POITestCase {
// And with a footer, also on notes
- hslf = new HSLFSlideShow(slTests.openResourceAsStream("45537_Footer.ppt"));
- ss = new SlideShow(hslf);
+ hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("45537_Footer.ppt"));
+ ss = new HSLFSlideShow(hslf);
assertNotNull(ss.getNotesHeadersFooters());
assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText());
@@ -281,7 +281,7 @@ public final class TestExtractor extends POITestCase {
String masterTitleText = "This is the Master Title";
String masterRandomText = "This text comes from the Master Slide";
String masterFooterText = "Footer from the master slide";
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
@@ -309,7 +309,7 @@ public final class TestExtractor extends POITestCase {
// Now with another file only containing master text
// Will always show up
String masterText = "Footer from the master slide";
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("WithMaster.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
ppe = new PowerPointExtractor(hslf);
@@ -322,7 +322,7 @@ public final class TestExtractor extends POITestCase {
* Bug #54880 Chinese text not extracted properly
*/
public void testChineseText() throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(slTests.openResourceAsStream("54880_chinese.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
ppe = new PowerPointExtractor(hslf);
String text = ppe.getText();
@@ -360,7 +360,7 @@ public final class TestExtractor extends POITestCase {
// Open via a HWPFDocument
for(DirectoryNode dir : files) {
- HSLFSlideShow slideshow = new HSLFSlideShow(dir);
+ HSLFSlideShowImpl slideshow = new HSLFSlideShowImpl(dir);
PowerPointExtractor extractor = new PowerPointExtractor(slideshow);
assertEquals(expectText, extractor.getText());
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
index 8838561501..0d1cfd9e09 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
@@ -32,9 +32,8 @@ import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Test;
@@ -52,16 +51,16 @@ public final class TestBackground {
*/
@Test
public void defaults() {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- assertEquals(Fill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
assertTrue(slide.getFollowMasterBackground());
- assertEquals(Fill.FILL_SOLID, slide.getBackground().getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SOLID, slide.getBackground().getFill().getFillType());
- HSLFShape shape = new AutoShape(ShapeType.RECT);
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+ HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
+ assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
}
/**
@@ -69,31 +68,31 @@ public final class TestBackground {
*/
@Test
public void readBackground() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("backgrounds.ppt"));
- Fill fill;
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("backgrounds.ppt"));
+ HSLFFill fill;
HSLFShape shape;
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
fill = slide[0].getBackground().getFill();
- assertEquals(Fill.FILL_PICTURE, fill.getFillType());
+ assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
shape = slide[0].getShapes()[0];
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
fill = slide[1].getBackground().getFill();
- assertEquals(Fill.FILL_PATTERN, fill.getFillType());
+ assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
shape = slide[1].getShapes()[0];
- assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slide[2].getBackground().getFill();
- assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
+ assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
shape = slide[2].getShapes()[0];
- assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
fill = slide[3].getBackground().getFill();
- assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
+ assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slide[3].getShapes()[0];
- assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
}
/**
@@ -101,9 +100,9 @@ public final class TestBackground {
*/
@Test
public void backgroundPicture() throws Exception {
- SlideShow ppt = new SlideShow();
- Slide slide;
- Fill fill;
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide;
+ HSLFFill fill;
HSLFShape shape;
int idx;
@@ -111,45 +110,45 @@ public final class TestBackground {
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
- idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PICTURE);
+ idx = ppt.addPicture(_slTests.readFile("tomcat.png"), HSLFPictureShape.PNG);
+ fill.setFillType(HSLFFill.FILL_PICTURE);
fill.setPictureData(idx);
- shape = new AutoShape(ShapeType.RECT);
+ shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
- fill.setFillType(Fill.FILL_SOLID);
+ fill.setFillType(HSLFFill.FILL_SOLID);
slide.addShape(shape);
//slide 2
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
- idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PATTERN);
+ idx = ppt.addPicture(_slTests.readFile("tomcat.png"), HSLFPictureShape.PNG);
+ fill.setFillType(HSLFFill.FILL_PATTERN);
fill.setPictureData(idx);
fill.setBackgroundColor(Color.green);
fill.setForegroundColor(Color.red);
- shape = new AutoShape(ShapeType.RECT);
+ shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
- fill.setFillType(Fill.FILL_BACKGROUND);
+ fill.setFillType(HSLFFill.FILL_BACKGROUND);
slide.addShape(shape);
//slide 3
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
- idx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_TEXTURE);
+ idx = ppt.addPicture(_slTests.readFile("tomcat.png"), HSLFPictureShape.PNG);
+ fill.setFillType(HSLFFill.FILL_TEXTURE);
fill.setPictureData(idx);
- shape = new AutoShape(ShapeType.RECT);
+ shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
- fill.setFillType(Fill.FILL_PICTURE);
- idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
+ fill.setFillType(HSLFFill.FILL_PICTURE);
+ idx = ppt.addPicture(_slTests.readFile("clock.jpg"), HSLFPictureShape.JPEG);
fill.setPictureData(idx);
slide.addShape(shape);
@@ -157,14 +156,14 @@ public final class TestBackground {
slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
fill = slide.getBackground().getFill();
- fill.setFillType(Fill.FILL_SHADE_CENTER);
+ fill.setFillType(HSLFFill.FILL_SHADE_CENTER);
fill.setBackgroundColor(Color.white);
fill.setForegroundColor(Color.darkGray);
- shape = new AutoShape(ShapeType.RECT);
+ shape = new HSLFAutoShape(ShapeType.RECT);
shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
fill = shape.getFill();
- fill.setFillType(Fill.FILL_SHADE);
+ fill.setFillType(HSLFFill.FILL_SHADE);
fill.setBackgroundColor(Color.red);
fill.setForegroundColor(Color.green);
slide.addShape(shape);
@@ -174,42 +173,42 @@ public final class TestBackground {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- Slide[] slides = ppt.getSlides();
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
+ HSLFSlide[] slides = ppt.getSlides();
fill = slides[0].getBackground().getFill();
- assertEquals(Fill.FILL_PICTURE, fill.getFillType());
+ assertEquals(HSLFFill.FILL_PICTURE, fill.getFillType());
assertEquals(3, getFillPictureRefCount(slides[0].getBackground(), fill));
shape = slides[0].getShapes()[0];
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SOLID, shape.getFill().getFillType());
fill = slides[1].getBackground().getFill();
- assertEquals(Fill.FILL_PATTERN, fill.getFillType());
+ assertEquals(HSLFFill.FILL_PATTERN, fill.getFillType());
shape = slides[1].getShapes()[0];
- assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_BACKGROUND, shape.getFill().getFillType());
fill = slides[2].getBackground().getFill();
- assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
+ assertEquals(HSLFFill.FILL_TEXTURE, fill.getFillType());
assertEquals(3, getFillPictureRefCount(slides[2].getBackground(), fill));
shape = slides[2].getShapes()[0];
- assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_PICTURE, shape.getFill().getFillType());
assertEquals(1, getFillPictureRefCount(shape, fill));
fill = slides[3].getBackground().getFill();
- assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
+ assertEquals(HSLFFill.FILL_SHADE_CENTER, fill.getFillType());
shape = slides[3].getShapes()[0];
- assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
+ assertEquals(HSLFFill.FILL_SHADE, shape.getFill().getFillType());
}
- private int getFillPictureRefCount(HSLFShape shape, Fill fill) {
+ private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {
EscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if(p != null) {
int idx = p.getPropertyValue();
- Sheet sheet = shape.getSheet();
- SlideShow ppt = sheet.getSlideShow();
+ HSLFSheet sheet = shape.getSheet();
+ HSLFSlideShow ppt = sheet.getSlideShow();
Document doc = ppt.getDocumentRecord();
EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java
index 6ff4870386..6d1365efbe 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestFreeform.java
@@ -43,7 +43,7 @@ public final class TestFreeform extends TestCase {
path1.lineTo(100, 200);
path1.closePath();
- Freeform p = new Freeform();
+ HSLFFreeformShape p = new HSLFFreeformShape();
p.setPath(path1);
java.awt.Shape path2 = p.getOutline();
@@ -54,7 +54,7 @@ public final class TestFreeform extends TestCase {
GeneralPath path1 = new GeneralPath(new Line2D.Double(100, 100, 200, 100));
- Freeform p = new Freeform();
+ HSLFFreeformShape p = new HSLFFreeformShape();
p.setPath(path1);
java.awt.Shape path2 = p.getOutline();
@@ -65,7 +65,7 @@ public final class TestFreeform extends TestCase {
GeneralPath path1 = new GeneralPath(new Rectangle2D.Double(100, 100, 200, 50));
- Freeform p = new Freeform();
+ HSLFFreeformShape p = new HSLFFreeformShape();
p.setPath(path1);
java.awt.Shape path2 = p.getOutline();
@@ -78,7 +78,7 @@ public final class TestFreeform extends TestCase {
*/
public void test54188() {
- Freeform p = new Freeform();
+ HSLFFreeformShape p = new HSLFFreeformShape();
GeneralPath path = (GeneralPath)p.getOutline();
GeneralPath emptyPath = new GeneralPath();
assertEquals(emptyPath.getBounds2D(), path.getBounds2D());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java
index 1e86b8c3af..8239a359d5 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHeadersFooters.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.model;
import java.io.*;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
import junit.framework.TestCase;
@@ -33,7 +33,7 @@ public final class TestHeadersFooters extends TestCase
public void testRead() throws Exception
{
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible());
@@ -53,7 +53,7 @@ public final class TestHeadersFooters extends TestCase
assertTrue(notesHdd.isUserDateVisible());
assertNull(notesHdd.getDateTimeText());
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
HeadersFooters hd1 = slide[0].getHeadersFooters();
assertEquals(slideHdd.isFooterVisible(), hd1.isFooterVisible());
@@ -77,7 +77,7 @@ public final class TestHeadersFooters extends TestCase
*/
public void testReadNoHeadersFooters() throws Exception
{
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertFalse(slideHdd.isFooterVisible());
@@ -97,7 +97,7 @@ public final class TestHeadersFooters extends TestCase
assertFalse(notesHdd.isUserDateVisible());
assertNull(notesHdd.getDateTimeText());
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
for(int i=0 ; i < slide.length; i++){
HeadersFooters hd1 = slide[i].getHeadersFooters();
assertFalse(hd1.isFooterVisible());
@@ -114,7 +114,7 @@ public final class TestHeadersFooters extends TestCase
*/
public void testRead2007() throws Exception
{
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("headers_footers_2007.ppt"));
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible());
@@ -137,7 +137,7 @@ public final class TestHeadersFooters extends TestCase
//assertEquals("08/12/08", notesHdd.getDateTimeText());
//per-slide headers / footers
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
HeadersFooters hd1 = slide[0].getHeadersFooters();
assertTrue(hd1.isFooterVisible());
@@ -174,7 +174,7 @@ public final class TestHeadersFooters extends TestCase
public void testCreateSlideFooters() throws Exception
{
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
HeadersFooters hdd = ppt.getSlideHeadersFooters();
hdd.setFootersText("My slide footer");
hdd.setSlideNumberVisible(true);
@@ -183,7 +183,7 @@ public final class TestHeadersFooters extends TestCase
ppt.write(out);
byte[] b = out.toByteArray();
- SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));
+ HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(b));
HeadersFooters hdd2 = ppt2.getSlideHeadersFooters();
assertTrue(hdd2.isSlideNumberVisible());
assertTrue(hdd2.isFooterVisible());
@@ -192,7 +192,7 @@ public final class TestHeadersFooters extends TestCase
public void testCreateNotesFooters() throws Exception
{
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
HeadersFooters hdd = ppt.getNotesHeadersFooters();
hdd.setFootersText("My notes footer");
hdd.setHeaderText("My notes header");
@@ -202,7 +202,7 @@ public final class TestHeadersFooters extends TestCase
ppt.write(out);
byte[] b = out.toByteArray();
- SlideShow ppt2 = new SlideShow(new ByteArrayInputStream(b));
+ HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(b));
HeadersFooters hdd2 = ppt2.getNotesHeadersFooters();
assertTrue(hdd2.isSlideNumberVisible());
assertTrue(hdd2.isFooterVisible());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java
index 6f9f9eb8b4..83e6ca6582 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestHyperlink.java
@@ -19,7 +19,7 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -31,10 +31,10 @@ public final class TestHyperlink extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testTextRunHyperlinks() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
- TextRun[] run;
- Slide slide;
+ HSLFTextParagraph[] run;
+ HSLFSlide slide;
slide = ppt.getSlides()[0];
run = slide.getTextRuns();
for (int i = 0; i < run.length; i++) {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java
index 9de8cad43e..11a64f6379 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestImagePainter.java
@@ -23,7 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.blip.BitmapPainter;
import org.apache.poi.hslf.blip.ImagePainter;
-import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
/**
* Test Picture shape.
@@ -36,19 +36,19 @@ public final class TestImagePainter extends TestCase {
public CustomImagePainter() {
// no fields to initialise
}
- public void paint(Graphics2D graphics, PictureData pict, Picture parent){
+ public void paint(Graphics2D graphics, HSLFPictureData pict, HSLFPictureShape parent){
//do noting
}
}
public void testImagePainter() {
- ImagePainter pntr = PictureData.getImagePainter(Picture.PNG);
- assertTrue(PictureData.getImagePainter(Picture.PNG) instanceof BitmapPainter);
- assertTrue(PictureData.getImagePainter(Picture.JPEG) instanceof BitmapPainter);
- assertTrue(PictureData.getImagePainter(Picture.DIB) instanceof BitmapPainter);
+ ImagePainter pntr = HSLFPictureData.getImagePainter(HSLFPictureShape.PNG);
+ assertTrue(HSLFPictureData.getImagePainter(HSLFPictureShape.PNG) instanceof BitmapPainter);
+ assertTrue(HSLFPictureData.getImagePainter(HSLFPictureShape.JPEG) instanceof BitmapPainter);
+ assertTrue(HSLFPictureData.getImagePainter(HSLFPictureShape.DIB) instanceof BitmapPainter);
- PictureData.setImagePainter(Picture.WMF, new CustomImagePainter());
- assertTrue(PictureData.getImagePainter(Picture.WMF) instanceof CustomImagePainter);
+ HSLFPictureData.setImagePainter(HSLFPictureShape.WMF, new CustomImagePainter());
+ assertTrue(HSLFPictureData.getImagePainter(HSLFPictureShape.WMF) instanceof CustomImagePainter);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
index 735fa30466..413ff8ebe8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestLine.java
@@ -21,7 +21,7 @@ import java.awt.Color;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/**
* Test Line shape.
@@ -31,9 +31,9 @@ import org.apache.poi.hslf.usermodel.SlideShow;
public final class TestLine extends TestCase {
public void testCreateLines() {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
slide.addTitle().setText("Lines tester");
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
index 9460642bb4..1b5bbd3298 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestMovieShape.java
@@ -23,7 +23,7 @@ import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -36,13 +36,13 @@ public final class TestMovieShape extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
public void testCreate() throws Exception {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
String path = "/test-movie.mpg";
int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);
- int thumbnailIdx = ppt.addPicture(_slTests.readFile("tomcat.png"), Picture.PNG);
+ int thumbnailIdx = ppt.addPicture(_slTests.readFile("tomcat.png"), HSLFPictureShape.PNG);
MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);
shape.setAnchor(new Rectangle2D.Float(300,225,120,90));
@@ -56,7 +56,7 @@ public final class TestMovieShape extends TestCase {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides()[0];
shape = (MovieShape)slide.getShapes()[0];
assertEquals(path, shape.getPath());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
index 249c4ee964..410f48226a 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestOleEmbedding.java
@@ -28,10 +28,9 @@ import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.ObjectData;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFObjectData;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
@@ -46,31 +45,31 @@ public final class TestOleEmbedding extends TestCase {
* @throws Exception if an error occurs.
*/
public void testOleEmbedding2003() throws Exception {
- HSLFSlideShow slideShow = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
+ HSLFSlideShowImpl slideShow = new HSLFSlideShowImpl(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
// Placeholder EMFs for clients that don't support the OLE components.
- PictureData[] pictures = slideShow.getPictures();
+ HSLFPictureData[] pictures = slideShow.getPictures();
assertEquals("Should be two pictures", 2, pictures.length);
//assertDigestEquals("Wrong data for picture 1", "8d1fbadf4814f321bb1ccdd056e3c788", pictures[0].getData());
//assertDigestEquals("Wrong data for picture 2", "987a698e83559cf3d38a0deeba1cc63b", pictures[1].getData());
// Actual embedded objects.
- ObjectData[] objects = slideShow.getEmbeddedObjects();
+ HSLFObjectData[] objects = slideShow.getEmbeddedObjects();
assertEquals("Should be two objects", 2, objects.length);
//assertDigestEquals("Wrong data for objecs 1", "0d1fcc61a83de5c4894dc0c88e9a019d", objects[0].getData());
//assertDigestEquals("Wrong data for object 2", "b323604b2003a7299c77c2693b641495", objects[1].getData());
}
public void testOLEShape() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ole2-embedding-2003.ppt"));
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
HSLFShape[] sh = slide.getShapes();
int cnt = 0;
for (int i = 0; i < sh.length; i++) {
if(sh[i] instanceof OLEShape){
cnt++;
OLEShape ole = (OLEShape)sh[i];
- ObjectData data = ole.getObjectData();
+ HSLFObjectData data = ole.getObjectData();
if("Worksheet".equals(ole.getInstanceName())){
//Voila! we created a workbook from the embedded OLE data
HSSFWorkbook wb = new HSSFWorkbook(data.getData());
@@ -94,11 +93,11 @@ public final class TestOleEmbedding extends TestCase {
}
public void testEmbedding() throws Exception {
- HSLFSlideShow _hslfSlideShow = HSLFSlideShow.create();
- SlideShow ppt = new SlideShow(_hslfSlideShow);
+ HSLFSlideShowImpl _hslfSlideShow = HSLFSlideShowImpl.create();
+ HSLFSlideShow ppt = new HSLFSlideShow(_hslfSlideShow);
File pict = POIDataSamples.getSlideShowInstance().getFile("clock.jpg");
- int pictId = ppt.addPicture(pict, Picture.JPEG);
+ int pictId = ppt.addPicture(pict, HSLFPictureShape.JPEG);
InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("Employee.xls");
POIFSFileSystem poiData1 = new POIFSFileSystem(is);
@@ -106,14 +105,14 @@ public final class TestOleEmbedding extends TestCase {
int oleObjectId1 = ppt.addEmbed(poiData1);
- Slide slide1 = ppt.createSlide();
+ HSLFSlide slide1 = ppt.createSlide();
OLEShape oleShape1 = new OLEShape(pictId);
oleShape1.setObjectID(oleObjectId1);
slide1.addShape(oleShape1);
oleShape1.setAnchor(new Rectangle2D.Double(100,100,100,100));
// add second slide with different order in object creation
- Slide slide2 = ppt.createSlide();
+ HSLFSlide slide2 = ppt.createSlide();
OLEShape oleShape2 = new OLEShape(pictId);
is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleWithImages.xls");
@@ -129,7 +128,7 @@ public final class TestOleEmbedding extends TestCase {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ppt.write(bos);
- ppt = new SlideShow(new ByteArrayInputStream(bos.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
OLEShape comp = (OLEShape)ppt.getSlides()[0].getShapes()[0];
byte compData[] = IOUtils.toByteArray(comp.getObjectData().getData());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
index aff848dfc5..fb04ccf5dd 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPFont.java
@@ -18,7 +18,7 @@
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/**
* Test adding fonts to the presenataion resources
@@ -28,7 +28,7 @@ import org.apache.poi.hslf.usermodel.SlideShow;
public final class TestPPFont extends TestCase{
public void testCreate() {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
assertEquals(1, ppt.getNumberOfFonts());
assertEquals("Arial", ppt.getFont(0).getFontName());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
index b58dbadecf..b71ce01035 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
@@ -18,12 +18,11 @@
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.HSLFSlideShow;
+
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
import java.awt.*;
-import java.awt.Rectangle;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
@@ -34,10 +33,10 @@ import java.io.ByteArrayInputStream;
*/
public final class TestPPGraphics2D extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
- private SlideShow ppt;
+ private HSLFSlideShow ppt;
protected void setUp() throws Exception {
- ppt = new SlideShow(_slTests.openResourceAsStream("empty.ppt"));
+ ppt = new HSLFSlideShow(_slTests.openResourceAsStream("empty.ppt"));
}
public void testGraphics() throws Exception {
@@ -45,7 +44,7 @@ public final class TestPPGraphics2D extends TestCase {
assertEquals(0, ppt.getSlides().length);
// Add a slide
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
assertEquals(1, ppt.getSlides().length);
// Add some stuff into it
@@ -73,7 +72,7 @@ public final class TestPPGraphics2D extends TestCase {
out.close();
// And read it back in
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertEquals(1, ppt.getSlides().length);
slide = ppt.getSlides()[0];
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
index fabf63beee..08077f0e00 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
@@ -36,9 +36,8 @@ import javax.imageio.ImageIO;
import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.util.JvmBugs;
import org.junit.Ignore;
import org.junit.Test;
@@ -58,16 +57,16 @@ public final class TestPicture {
*/
@Test
public void multiplePictures() throws Exception {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide s = ppt.createSlide();
- Slide s2 = ppt.createSlide();
- Slide s3 = ppt.createSlide();
+ HSLFSlide s = ppt.createSlide();
+ HSLFSlide s2 = ppt.createSlide();
+ HSLFSlide s3 = ppt.createSlide();
- int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
- Picture pict = new Picture(idx);
- Picture pict2 = new Picture(idx);
- Picture pict3 = new Picture(idx);
+ int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), HSLFPictureShape.JPEG);
+ HSLFPictureShape pict = new HSLFPictureShape(idx);
+ HSLFPictureShape pict2 = new HSLFPictureShape(idx);
+ HSLFPictureShape pict3 = new HSLFPictureShape(idx);
pict.setAnchor(new Rectangle(10,10,100,100));
s.addShape(pict);
@@ -93,12 +92,12 @@ public final class TestPicture {
*/
@Test
public void bug46122() {
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
- Picture pict = new Picture(-1); //index to non-existing picture data
+ HSLFPictureShape pict = new HSLFPictureShape(-1); //index to non-existing picture data
pict.setSheet(slide);
- PictureData data = pict.getPictureData();
+ HSLFPictureData data = pict.getPictureData();
assertNull(data);
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
@@ -108,9 +107,9 @@ public final class TestPicture {
@Test
public void macImages() throws Exception {
- HSLFSlideShow hss = new HSLFSlideShow(_slTests.openResourceAsStream("53446.ppt"));
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("53446.ppt"));
- PictureData[] pictures = hss.getPictures();
+ HSLFPictureData[] pictures = hss.getPictures();
assertEquals(15, pictures.length);
int[][] expectedSizes = {
@@ -134,7 +133,7 @@ public final class TestPicture {
for (int i = 0; i < pictures.length; i++) {
BufferedImage image = ImageIO.read(new ByteArrayInputStream(pictures[i].getData()));
- if (pictures[i].getType() != Picture.WMF && pictures[i].getType() != Picture.EMF) {
+ if (pictures[i].getType() != HSLFPictureShape.WMF && pictures[i].getType() != HSLFPictureShape.EMF) {
assertNotNull(image);
int[] dimensions = expectedSizes[i];
@@ -163,12 +162,12 @@ public final class TestPicture {
// System.out.println("########################");
InputStream is = _slTests.openResourceAsStream("54541_cropped_bitmap.ppt");
- SlideShow ss = new SlideShow(is);
+ HSLFSlideShow ss = new HSLFSlideShow(is);
is.close();
Dimension pg = ss.getPageSize();
int i=1;
- for(Slide slide : ss.getSlides()) {
+ for(HSLFSlide slide : ss.getSlides()) {
BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
fixFonts(graphics);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
index 23b798fd6f..e1703626ca 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
@@ -18,9 +18,9 @@
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.HSLFSlideShow;
+
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
@@ -36,15 +36,15 @@ public final class TestSetBoldItalic extends TestCase {
* and set some of the style attributes
*/
public void testTextBoxWrite() throws Exception {
- SlideShow ppt = new SlideShow();
- Slide sl = ppt.createSlide();
- RichTextRun rt;
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide sl = ppt.createSlide();
+ HSLFTextRun rt;
String val = "Hello, World!";
// Create a new textbox, and give it lots of properties
- TextBox txtbox = new TextBox();
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ HSLFTextBox txtbox = new HSLFTextBox();
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
txtbox.setText(val);
rt.setFontSize(42);
rt.setBold(true);
@@ -53,7 +53,7 @@ public final class TestSetBoldItalic extends TestCase {
sl.addShape(txtbox);
// Check it before save
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
assertEquals(val, rt.getText());
assertEquals(42, rt.getFontSize());
assertTrue(rt.isBold());
@@ -64,11 +64,11 @@ public final class TestSetBoldItalic extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
sl = ppt.getSlides()[0];
- txtbox = (TextBox)sl.getShapes()[0];
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ txtbox = (HSLFTextBox)sl.getShapes()[0];
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
// Check after save
assertEquals(val, rt.getText());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
index 700b758a1e..9456c211f8 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
@@ -38,9 +38,8 @@ import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Before;
import org.junit.Test;
@@ -53,17 +52,17 @@ import org.junit.Test;
public final class TestShapes {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
- private SlideShow ppt;
- private SlideShow pptB;
+ private HSLFSlideShow ppt;
+ private HSLFSlideShow pptB;
@Before
public void setUp() throws Exception {
InputStream is1 = null, is2 = null;
try {
is1 = _slTests.openResourceAsStream("empty.ppt");
- ppt = new SlideShow(is1);
+ ppt = new HSLFSlideShow(is1);
is2 = _slTests.openResourceAsStream("empty_textbox.ppt");
- pptB = new SlideShow(is2);
+ pptB = new HSLFSlideShow(is2);
} finally {
is1.close();
is2.close();
@@ -72,7 +71,7 @@ public final class TestShapes {
@Test
public void graphics() throws Exception {
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
Line line = new Line();
java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
@@ -82,7 +81,7 @@ public final class TestShapes {
line.setLineColor(Color.red);
slide.addShape(line);
- AutoShape ellipse = new AutoShape(ShapeType.ELLIPSE);
+ HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
ellipse.setAnchor(ellipseAnchor);
ellipse.setLineWidth(2);
@@ -97,7 +96,7 @@ public final class TestShapes {
//read ppt from byte array
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertEquals(1, ppt.getSlides().length);
slide = ppt.getSlides()[0];
@@ -107,7 +106,7 @@ public final class TestShapes {
assertTrue(shape[0] instanceof Line); //group shape
assertEquals(lineAnchor, shape[0].getAnchor()); //group shape
- assertTrue(shape[1] instanceof AutoShape); //group shape
+ assertTrue(shape[1] instanceof HSLFAutoShape); //group shape
assertEquals(ellipseAnchor, shape[1].getAnchor()); //group shape
}
@@ -117,17 +116,17 @@ public final class TestShapes {
*/
@Test
public void textBoxRead() throws Exception {
- ppt = new SlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
- Slide sl = ppt.getSlides()[0];
+ ppt = new HSLFSlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
+ HSLFSlide sl = ppt.getSlides()[0];
HSLFShape[] sh = sl.getShapes();
for (int i = 0; i < sh.length; i++) {
- assertTrue(sh[i] instanceof TextBox);
- TextBox txtbox = (TextBox)sh[i];
+ assertTrue(sh[i] instanceof HSLFTextBox);
+ HSLFTextBox txtbox = (HSLFTextBox)sh[i];
String text = txtbox.getText();
assertNotNull(text);
- assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
- RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];
+ assertEquals(txtbox.getTextParagraph().getRichTextRuns().length, 1);
+ HSLFTextRun rt = txtbox.getTextParagraph().getRichTextRuns()[0];
if (text.equals("Hello, World!!!")){
assertEquals(32, rt.getFontSize());
@@ -153,15 +152,15 @@ public final class TestShapes {
*/
@Test
public void textBoxWriteBytes() throws Exception {
- ppt = new SlideShow();
- Slide sl = ppt.createSlide();
- RichTextRun rt;
+ ppt = new HSLFSlideShow();
+ HSLFSlide sl = ppt.createSlide();
+ HSLFTextRun rt;
String val = "Hello, World!";
// Create a new textbox, and give it lots of properties
- TextBox txtbox = new TextBox();
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ HSLFTextBox txtbox = new HSLFTextBox();
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
txtbox.setText(val);
rt.setFontName("Arial");
rt.setFontSize(42);
@@ -172,7 +171,7 @@ public final class TestShapes {
sl.addShape(txtbox);
// Check it before save
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
assertEquals(val, rt.getText());
assertEquals(42, rt.getFontSize());
assertTrue(rt.isBold());
@@ -186,11 +185,11 @@ public final class TestShapes {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
sl = ppt.getSlides()[0];
- txtbox = (TextBox)sl.getShapes()[0];
- rt = txtbox.getTextRun().getRichTextRuns()[0];
+ txtbox = (HSLFTextBox)sl.getShapes()[0];
+ rt = txtbox.getTextParagraph().getRichTextRuns()[0];
// Check after save
assertEquals(val, rt.getText());
@@ -208,8 +207,8 @@ public final class TestShapes {
@Test
public void emptyTextBox() {
assertEquals(2, pptB.getSlides().length);
- Slide s1 = pptB.getSlides()[0];
- Slide s2 = pptB.getSlides()[1];
+ HSLFSlide s1 = pptB.getSlides()[0];
+ HSLFSlide s2 = pptB.getSlides()[1];
// Check we can get the shapes count
assertEquals(2, s1.getShapes().length);
@@ -231,11 +230,11 @@ public final class TestShapes {
}
private void textBoxSet(String filename) throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(filename));
- Slide[] sl = ppt.getSlides();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream(filename));
+ HSLFSlide[] sl = ppt.getSlides();
for (int k = 0; k < sl.length; k++) {
ArrayList lst1 = new ArrayList();
- TextRun[] txt = sl[k].getTextRuns();
+ HSLFTextParagraph[] txt = sl[k].getTextRuns();
for (int i = 0; i < txt.length; i++) {
lst1.add(txt[i].getText());
}
@@ -243,8 +242,8 @@ public final class TestShapes {
ArrayList lst2 = new ArrayList();
HSLFShape[] sh = sl[k].getShapes();
for (int i = 0; i < sh.length; i++) {
- if (sh[i] instanceof TextShape){
- TextShape tbox = (TextShape)sh[i];
+ if (sh[i] instanceof HSLFTextShape){
+ HSLFTextShape tbox = (HSLFTextShape)sh[i];
lst2.add(tbox.getText());
}
}
@@ -258,9 +257,9 @@ public final class TestShapes {
*/
@Test
public void shapeGroup() throws Exception {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
Dimension pgsize = ppt.getPageSize();
HSLFGroupShape group = new HSLFGroupShape();
@@ -268,8 +267,8 @@ public final class TestShapes {
group.setAnchor(new Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight()));
slide.addShape(group);
- int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), Picture.JPEG);
- Picture pict = new Picture(idx, group);
+ int idx = ppt.addPicture(_slTests.readFile("clock.jpg"), HSLFPictureShape.JPEG);
+ HSLFPictureShape pict = new HSLFPictureShape(idx, group);
pict.setAnchor(new Rectangle(0, 0, 200, 200));
group.addShape(pict);
@@ -283,7 +282,7 @@ public final class TestShapes {
out.close();
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
- ppt = new SlideShow(is);
+ ppt = new HSLFSlideShow(is);
is.close();
slide = ppt.getSlides()[0];
@@ -295,10 +294,10 @@ public final class TestShapes {
group = (HSLFGroupShape)shape[0];
HSLFShape[] grshape = group.getShapes();
assertEquals(2, grshape.length);
- assertTrue(grshape[0] instanceof Picture);
+ assertTrue(grshape[0] instanceof HSLFPictureShape);
assertTrue(grshape[1] instanceof Line);
- pict = (Picture)grshape[0];
+ pict = (HSLFPictureShape)grshape[0];
assertEquals(new Rectangle(0, 0, 200, 200), pict.getAnchor());
line = (Line)grshape[1];
@@ -311,8 +310,8 @@ public final class TestShapes {
@Test
public void removeShapes() throws IOException {
String file = "with_textbox.ppt";
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file));
- Slide sl = ppt.getSlides()[0];
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream(file));
+ HSLFSlide sl = ppt.getSlides()[0];
HSLFShape[] sh = sl.getShapes();
assertEquals("expected four shaped in " + file, 4, sh.length);
//remove all
@@ -328,30 +327,30 @@ public final class TestShapes {
ppt.write(out);
out.close();
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
sl = ppt.getSlides()[0];
assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length);
}
@Test
public void lineWidth() {
- SimpleShape sh = new AutoShape(ShapeType.RT_TRIANGLE);
+ HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE);
EscherOptRecord opt = sh.getEscherOptRecord();
- EscherSimpleProperty prop = SimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
+ EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNull(prop);
- assertEquals(SimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);
+ assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);
sh.setLineWidth(1.0);
- prop = SimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
+ prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNotNull(prop);
assertEquals(1.0, sh.getLineWidth(), 0);
}
@Test
public void shapeId() {
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
HSLFShape shape = null;
//EscherDgg is a document-level record which keeps track of the drawing groups
@@ -400,25 +399,25 @@ public final class TestShapes {
@Test
public void lineColor() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("51731.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("51731.ppt"));
HSLFShape[] shape = ppt.getSlides()[0].getShapes();
assertEquals(4, shape.length);
- TextShape sh1 = (TextShape)shape[0];
+ HSLFTextShape sh1 = (HSLFTextShape)shape[0];
assertEquals("Hello Apache POI", sh1.getText());
assertNull(sh1.getLineColor());
- TextShape sh2 = (TextShape)shape[1];
+ HSLFTextShape sh2 = (HSLFTextShape)shape[1];
assertEquals("Why are you showing this border?", sh2.getText());
assertNull(sh2.getLineColor());
- TextShape sh3 = (TextShape)shape[2];
+ HSLFTextShape sh3 = (HSLFTextShape)shape[2];
assertEquals("Text in a black border", sh3.getText());
assertEquals(Color.black, sh3.getLineColor());
assertEquals(0.75, sh3.getLineWidth(), 0);
- TextShape sh4 = (TextShape)shape[3];
+ HSLFTextShape sh4 = (HSLFTextShape)shape[3];
assertEquals("Border width is 5 pt", sh4.getText());
assertEquals(Color.black, sh4.getLineColor());
assertEquals(5.0, sh4.getLineWidth(), 0);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java
index a22e7eb3f9..60b8ca42e2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSheet.java
@@ -23,7 +23,7 @@ import junit.framework.TestCase;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.PPDrawing;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -42,7 +42,7 @@ public final class TestSheet extends TestCase {
String[] tests = {"SampleShow.ppt", "backgrounds.ppt", "text_shapes.ppt", "pictures.ppt"};
for (String file : tests) {
try {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream(file));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream(file));
doSlideShow(ppt);
} catch (EncryptedPowerPointFileException e){
; //skip encrypted ppt
@@ -50,21 +50,21 @@ public final class TestSheet extends TestCase {
}
}
- private void doSlideShow(SlideShow ppt) {
- Slide[] slide = ppt.getSlides();
+ private void doSlideShow(HSLFSlideShow ppt) {
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
verify(slide[i]);
- Notes notes = slide[i].getNotesSheet();
+ HSLFNotes notes = slide[i].getNotesSheet();
if(notes != null) verify(notes);
- MasterSheet master = slide[i].getMasterSheet();
+ HSLFMasterSheet master = slide[i].getMasterSheet();
assertNotNull(master);
verify(master);
}
}
- private void verify(Sheet sheet){
+ private void verify(HSLFSheet sheet){
assertNotNull(sheet.getSlideShow());
ColorSchemeAtom colorscheme = sheet.getColorScheme();
@@ -73,13 +73,13 @@ public final class TestSheet extends TestCase {
PPDrawing ppdrawing = sheet.getPPDrawing();
assertNotNull(ppdrawing);
- Background background = sheet.getBackground();
+ HSLFBackground background = sheet.getBackground();
assertNotNull(background);
assertTrue(sheet._getSheetNumber() != 0);
assertTrue(sheet._getSheetRefId() != 0);
- TextRun[] txt = sheet.getTextRuns();
+ HSLFTextParagraph[] txt = sheet.getTextRuns();
if (txt == null) {
throw new AssertionFailedError("no text runs");
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java
index 71c95f87b7..2d4fe15131 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideChangeNotes.java
@@ -20,9 +20,8 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.record.SlideAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -32,16 +31,16 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestSlideChangeNotes extends TestCase {
// SlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
public TestSlideChangeNotes() throws Exception {
POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testSetToNone() {
- Slide slideOne = ss.getSlides()[0];
+ HSLFSlide slideOne = ss.getSlides()[0];
SlideAtom sa = slideOne.getSlideRecord().getSlideAtom();
slideOne.setNotes(null);
@@ -50,8 +49,8 @@ public final class TestSlideChangeNotes extends TestCase {
}
public void testSetToSomething() {
- Slide slideOne = ss.getSlides()[0];
- Notes notesOne = ss.getNotes()[1];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFNotes notesOne = ss.getNotes()[1];
SlideAtom sa = slideOne.getSlideRecord().getSlideAtom();
slideOne.setNotes(notesOne);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
index 45c3c0c2bc..ffb6563da5 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
@@ -22,12 +22,11 @@ import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
import org.apache.poi.hslf.record.Environment;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -43,7 +42,7 @@ public final class TestSlideMaster extends TestCase{
* Check we can read their attributes.
*/
public void testSlideMaster() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
Environment env = ppt.getDocumentRecord().getEnvironment();
@@ -83,7 +82,7 @@ public final class TestSlideMaster extends TestCase{
* Test we can read default text attributes for a title master sheet
*/
public void testTitleMasterTextAttributes() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
TitleMaster[] master = ppt.getTitleMasters();
assertEquals(1, master.length);
@@ -104,14 +103,14 @@ public final class TestSlideMaster extends TestCase{
* Slide 3 has title layout and follows the TitleMaster. Verify that.
*/
public void testTitleMaster() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
- Slide slide = ppt.getSlides()[2];
- MasterSheet masterSheet = slide.getMasterSheet();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlide slide = ppt.getSlides()[2];
+ HSLFMasterSheet masterSheet = slide.getMasterSheet();
assertTrue(masterSheet instanceof TitleMaster);
- TextRun[] txt = slide.getTextRuns();
+ HSLFTextParagraph[] txt = slide.getTextRuns();
for (int i = 0; i < txt.length; i++) {
- RichTextRun rt = txt[i].getRichTextRuns()[0];
+ HSLFTextRun rt = txt[i].getRichTextRuns()[0];
switch(txt[i].getRunType()){
case TextHeaderAtom.CENTER_TITLE_TYPE:
assertEquals("Arial", rt.getFontName());
@@ -133,20 +132,20 @@ public final class TestSlideMaster extends TestCase{
* If a style attribute is not set ensure it is read from the master
*/
public void testMasterAttributes() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
- Slide[] slide = ppt.getSlides();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlide[] slide = ppt.getSlides();
assertEquals(3, slide.length);
- TextRun[] trun;
+ HSLFTextParagraph[] trun;
trun = slide[0].getTextRuns();
for (int i = 0; i < trun.length; i++) {
if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
- RichTextRun rt = trun[i].getRichTextRuns()[0];
+ HSLFTextRun rt = trun[i].getRichTextRuns()[0];
assertEquals(40, rt.getFontSize());
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontName());
} else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
- RichTextRun rt;
+ HSLFTextRun rt;
rt = trun[i].getRichTextRuns()[0];
assertEquals(0, rt.getIndentLevel());
assertEquals(32, rt.getFontSize());
@@ -163,12 +162,12 @@ public final class TestSlideMaster extends TestCase{
trun = slide[1].getTextRuns();
for (int i = 0; i < trun.length; i++) {
if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
- RichTextRun rt = trun[i].getRichTextRuns()[0];
+ HSLFTextRun rt = trun[i].getRichTextRuns()[0];
assertEquals(48, rt.getFontSize());
assertEquals(true, rt.isItalic());
assertEquals("Georgia", rt.getFontName());
} else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
- RichTextRun rt;
+ HSLFTextRun rt;
rt = trun[i].getRichTextRuns()[0];
assertEquals(0, rt.getIndentLevel());
assertEquals(32, rt.getFontSize());
@@ -182,9 +181,9 @@ public final class TestSlideMaster extends TestCase{
* Check we can dynamically assign a slide master to a slide.
*/
public void testChangeSlideMaster() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
SlideMaster[] master = ppt.getSlidesMasters();
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
int sheetNo;
//each slide uses its own master
@@ -203,7 +202,7 @@ public final class TestSlideMaster extends TestCase{
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
master = ppt.getSlidesMasters();
slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
@@ -216,19 +215,19 @@ public final class TestSlideMaster extends TestCase{
* (typical for the "bullted body" placeholder)
*/
public void testIndentation() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
- Slide slide = ppt.getSlides()[0];
- TextRun[] trun;
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
+ HSLFSlide slide = ppt.getSlides()[0];
+ HSLFTextParagraph[] trun;
trun = slide.getTextRuns();
for (int i = 0; i < trun.length; i++) {
if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
- RichTextRun rt = trun[i].getRichTextRuns()[0];
+ HSLFTextRun rt = trun[i].getRichTextRuns()[0];
assertEquals(40, rt.getFontSize());
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontName());
} else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
- RichTextRun[] rt = trun[i].getRichTextRuns();
+ HSLFTextRun[] rt = trun[i].getRichTextRuns();
for (int j = 0; j < rt.length; j++) {
int indent = rt[j].getIndentLevel();
switch (indent){
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
index 11889f4409..f5e0abef59 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
@@ -18,8 +18,8 @@
package org.apache.poi.hslf.model;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.SlideShow;
+
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
import java.io.ByteArrayOutputStream;
@@ -39,10 +39,10 @@ public final class TestSlides extends TestCase {
* @throws Exception
*/
public void testAddSlides1() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
- Slide s1 = ppt.createSlide();
+ HSLFSlide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
assertEquals(256, s1._getSheetNumber());
@@ -53,7 +53,7 @@ public final class TestSlides extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 1);
}
@@ -62,16 +62,16 @@ public final class TestSlides extends TestCase {
* @throws Exception
*/
public void testAddSlides2() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
- Slide s1 = ppt.createSlide();
+ HSLFSlide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
assertEquals(256, s1._getSheetNumber());
assertEquals(1, s1.getSlideNumber());
- Slide s2 = ppt.createSlide();
+ HSLFSlide s2 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 2);
assertEquals(4, s2._getSheetRefId());
assertEquals(257, s2._getSheetNumber());
@@ -82,7 +82,7 @@ public final class TestSlides extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 2);
}
@@ -91,22 +91,22 @@ public final class TestSlides extends TestCase {
* @throws Exception
*/
public void testAddSlides3() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
assertTrue(ppt.getSlides().length == 0);
- Slide s1 = ppt.createSlide();
+ HSLFSlide s1 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 1);
assertEquals(3, s1._getSheetRefId());
assertEquals(256, s1._getSheetNumber());
assertEquals(1, s1.getSlideNumber());
- Slide s2 = ppt.createSlide();
+ HSLFSlide s2 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 2);
assertEquals(4, s2._getSheetRefId());
assertEquals(257, s2._getSheetNumber());
assertEquals(2, s2.getSlideNumber());
- Slide s3 = ppt.createSlide();
+ HSLFSlide s3 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 3);
assertEquals(5, s3._getSheetRefId());
assertEquals(258, s3._getSheetNumber());
@@ -118,7 +118,7 @@ public final class TestSlides extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 3);
// Check IDs are still right
@@ -139,22 +139,22 @@ public final class TestSlides extends TestCase {
*/
public void testAddSlides2to3() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- SlideShow ppt = new SlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
assertTrue(ppt.getSlides().length == 2);
// First slide is 256 / 4
- Slide s1 = ppt.getSlides()[0];
+ HSLFSlide s1 = ppt.getSlides()[0];
assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId());
// Last slide is 257 / 6
- Slide s2 = ppt.getSlides()[1];
+ HSLFSlide s2 = ppt.getSlides()[1];
assertEquals(257, s2._getSheetNumber());
assertEquals(6, s2._getSheetRefId());
// Add another slide, goes in at the end
- Slide s3 = ppt.createSlide();
+ HSLFSlide s3 = ppt.createSlide();
assertTrue(ppt.getSlides().length == 3);
assertEquals(258, s3._getSheetNumber());
assertEquals(8, s3._getSheetRefId());
@@ -165,7 +165,7 @@ public final class TestSlides extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
assertTrue(ppt.getSlides().length == 3);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
index 480fd8ab65..d3fb354063 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
@@ -23,7 +23,7 @@ import java.io.ByteArrayOutputStream;
import junit.framework.TestCase;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
/**
* Test Table
object.
@@ -36,16 +36,16 @@ public final class TestTable extends TestCase {
* Test that ShapeFactory works properly and returns Table
*/
public void testShapeFactory() throws Exception {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
Table tbl = new Table(2, 5);
slide.addShape(tbl);
TableCell cell = tbl.getCell(0, 0);
//table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
- assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextRun().getRunType());
+ assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextParagraph().getRunType());
assertTrue(slide.getShapes()[0] instanceof Table);
Table tbl2 = (Table)slide.getShapes()[0];
@@ -56,7 +56,7 @@ public final class TestTable extends TestCase {
ppt.write(out);
out.close();
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides()[0];
assertTrue(slide.getShapes()[0] instanceof Table);
Table tbl3 = (Table)slide.getShapes()[0];
@@ -68,8 +68,8 @@ public final class TestTable extends TestCase {
* Error constructing Table when rownum=1
*/
public void test45889(){
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
HSLFShape[] shapes;
Table tbl1 = new Table(1, 5);
assertEquals(5, tbl1.getNumberOfColumns());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java
index 1b0119307a..01ce6a0534 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java
@@ -30,8 +30,8 @@ import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.TextBytesAtom;
import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -43,24 +43,24 @@ public final class TestTextRun extends TestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data
- private SlideShow ss;
- private SlideShow ssRich;
+ private HSLFSlideShow ss;
+ private HSLFSlideShow ssRich;
protected void setUp() throws IOException {
// Basic (non rich) test file
- ss = new SlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
// Rich test file
- ssRich = new SlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
+ ssRich = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
}
/**
* Test to ensure that getting the text works correctly
*/
public void testGetText() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
@@ -74,8 +74,8 @@ public final class TestTextRun extends TestCase {
// Now check on a rich text run
- Slide slideOneR = ssRich.getSlides()[0];
- TextRun[] textRunsR = slideOneR.getTextRuns();
+ HSLFSlide slideOneR = ssRich.getSlides()[0];
+ HSLFTextParagraph[] textRunsR = slideOneR.getTextRuns();
assertEquals(2, textRunsR.length);
assertEquals("This is a title, it\u2019s in black", textRunsR[0].getText());
@@ -88,9 +88,9 @@ public final class TestTextRun extends TestCase {
* Test to ensure changing non rich text bytes->bytes works correctly
*/
public void testSetText() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- TextRun run = textRuns[0];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextParagraph run = textRuns[0];
// Check current text
assertEquals("This is a test title", run.getText());
@@ -110,8 +110,8 @@ public final class TestTextRun extends TestCase {
* chars works correctly
*/
public void testAdvancedSetText() {
- Slide slideOne = ss.getSlides()[0];
- TextRun run = slideOne.getTextRuns()[0];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph run = slideOne.getTextRuns()[0];
TextHeaderAtom tha = run._headerAtom;
TextBytesAtom tba = run._byteAtom;
@@ -171,19 +171,19 @@ public final class TestTextRun extends TestCase {
* set up for it
*/
public void testGetRichTextNonRich() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
- TextRun trA = textRuns[0];
- TextRun trB = textRuns[1];
+ HSLFTextParagraph trA = textRuns[0];
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(1, trB.getRichTextRuns().length);
- RichTextRun rtrA = trA.getRichTextRuns()[0];
- RichTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrA = trA.getRichTextRuns()[0];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trA.getText(), rtrA.getText());
assertEquals(trB.getText(), rtrB.getText());
@@ -198,21 +198,21 @@ public final class TestTextRun extends TestCase {
* Tests to ensure that the rich text runs are built up correctly
*/
public void testGetRichText() {
- Slide slideOne = ssRich.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
+ HSLFSlide slideOne = ssRich.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
assertEquals(2, textRuns.length);
- TextRun trA = textRuns[0];
- TextRun trB = textRuns[1];
+ HSLFTextParagraph trA = textRuns[0];
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(1, trA.getRichTextRuns().length);
assertEquals(3, trB.getRichTextRuns().length);
- RichTextRun rtrA = trA.getRichTextRuns()[0];
- RichTextRun rtrB = trB.getRichTextRuns()[0];
- RichTextRun rtrC = trB.getRichTextRuns()[1];
- RichTextRun rtrD = trB.getRichTextRuns()[2];
+ HSLFTextRun rtrA = trA.getRichTextRuns()[0];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrC = trB.getRichTextRuns()[1];
+ HSLFTextRun rtrD = trB.getRichTextRuns()[2];
assertEquals(trA.getText(), rtrA.getText());
@@ -244,12 +244,12 @@ public final class TestTextRun extends TestCase {
* ensuring that everything stays with the same default styling
*/
public void testSetTextWhereNotRich() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- TextRun trB = textRuns[1];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
- RichTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
@@ -268,14 +268,14 @@ public final class TestTextRun extends TestCase {
* sets everything to the same styling
*/
public void testSetTextWhereRich() {
- Slide slideOne = ssRich.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- TextRun trB = textRuns[1];
+ HSLFSlide slideOne = ssRich.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(3, trB.getRichTextRuns().length);
- RichTextRun rtrB = trB.getRichTextRuns()[0];
- RichTextRun rtrC = trB.getRichTextRuns()[1];
- RichTextRun rtrD = trB.getRichTextRuns()[2];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrC = trB.getRichTextRuns()[1];
+ HSLFTextRun rtrD = trB.getRichTextRuns()[2];
TextPropCollection tpBP = rtrB._getRawParagraphStyle();
TextPropCollection tpBC = rtrB._getRawCharacterStyle();
TextPropCollection tpCP = rtrC._getRawParagraphStyle();
@@ -316,12 +316,12 @@ public final class TestTextRun extends TestCase {
* in a rich text run, that doesn't happen to actually be rich
*/
public void testChangeTextInRichTextRunNonRich() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- TextRun trB = textRuns[1];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(1, trB.getRichTextRuns().length);
- RichTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
assertEquals(trB.getText(), rtrB.getText());
assertNull(rtrB._getRawCharacterStyle());
assertNull(rtrB._getRawParagraphStyle());
@@ -341,16 +341,16 @@ public final class TestTextRun extends TestCase {
* correctly
*/
public void testChangeTextInRichTextRun() {
- Slide slideOne = ssRich.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- TextRun trB = textRuns[1];
+ HSLFSlide slideOne = ssRich.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextParagraph trB = textRuns[1];
assertEquals(3, trB.getRichTextRuns().length);
// We start with 3 text runs, each with their own set of styles,
// but all sharing the same paragraph styles
- RichTextRun rtrB = trB.getRichTextRuns()[0];
- RichTextRun rtrC = trB.getRichTextRuns()[1];
- RichTextRun rtrD = trB.getRichTextRuns()[2];
+ HSLFTextRun rtrB = trB.getRichTextRuns()[0];
+ HSLFTextRun rtrC = trB.getRichTextRuns()[1];
+ HSLFTextRun rtrD = trB.getRichTextRuns()[2];
TextPropCollection tpBP = rtrB._getRawParagraphStyle();
TextPropCollection tpBC = rtrB._getRawCharacterStyle();
TextPropCollection tpCP = rtrC._getRawParagraphStyle();
@@ -421,11 +421,11 @@ public final class TestTextRun extends TestCase {
*
*/
public void testBug41015() throws IOException {
- RichTextRun[] rt;
+ HSLFTextRun[] rt;
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bug-41015.ppt"));
- Slide sl = ppt.getSlides()[0];
- TextRun[] txt = sl.getTextRuns();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug-41015.ppt"));
+ HSLFSlide sl = ppt.getSlides()[0];
+ HSLFTextParagraph[] txt = sl.getTextRuns();
assertEquals(2, txt.length);
rt = txt[0].getRichTextRuns();
@@ -448,24 +448,24 @@ public final class TestTextRun extends TestCase {
* Test creation of TextRun objects.
*/
public void testAddTextRun() {
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
assertNull(slide.getTextRuns());
- TextBox shape1 = new TextBox();
- TextRun run1 = shape1.getTextRun();
+ HSLFTextBox shape1 = new HSLFTextBox();
+ HSLFTextParagraph run1 = shape1.getTextParagraph();
assertSame(run1, shape1.createTextRun());
run1.setText("Text 1");
slide.addShape(shape1);
//The array of Slide's text runs must be updated when new text shapes are added.
- TextRun[] runs = slide.getTextRuns();
+ HSLFTextParagraph[] runs = slide.getTextRuns();
assertNotNull(runs);
assertSame(run1, runs[0]);
- TextBox shape2 = new TextBox();
- TextRun run2 = shape2.getTextRun();
+ HSLFTextBox shape2 = new HSLFTextBox();
+ HSLFTextParagraph run2 = shape2.getTextParagraph();
assertSame(run2, shape2.createTextRun());
run2.setText("Text 2");
slide.addShape(shape2);
@@ -479,14 +479,14 @@ public final class TestTextRun extends TestCase {
//as getShapes()
HSLFShape[] sh = slide.getShapes();
assertEquals(2, sh.length);
- assertTrue(sh[0] instanceof TextBox);
- TextBox box1 = (TextBox)sh[0];
- assertSame(run1, box1.getTextRun());
- TextBox box2 = (TextBox)sh[1];
- assertSame(run2, box2.getTextRun());
+ assertTrue(sh[0] instanceof HSLFTextBox);
+ HSLFTextBox box1 = (HSLFTextBox)sh[0];
+ assertSame(run1, box1.getTextParagraph());
+ HSLFTextBox box2 = (HSLFTextBox)sh[1];
+ assertSame(run2, box2.getTextParagraph());
//test Table - a complex group of shapes containing text objects
- Slide slide2 = ppt.createSlide();
+ HSLFSlide slide2 = ppt.createSlide();
assertNull(slide2.getTextRuns());
Table table = new Table(2, 2);
slide2.addShape(table);
@@ -496,12 +496,12 @@ public final class TestTextRun extends TestCase {
}
public void test48916() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
- for(Slide slide : ppt.getSlides()){
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
+ for(HSLFSlide slide : ppt.getSlides()){
for(HSLFShape sh : slide.getShapes()){
- if(sh instanceof TextShape){
- TextShape tx = (TextShape)sh;
- TextRun run = tx.getTextRun();
+ if(sh instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)sh;
+ HSLFTextParagraph run = tx.getTextParagraph();
//verify that records cached in TextRun and EscherTextboxWrapper are the same
Record[] runChildren = run.getRecords();
Record[] txboxChildren = tx.getEscherTextboxWrapper().getChildRecords();
@@ -517,13 +517,13 @@ public final class TestTextRun extends TestCase {
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
- for(Slide slide : ppt.getSlides()){
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
+ for(HSLFSlide slide : ppt.getSlides()){
for(HSLFShape sh : slide.getShapes()){
- if(sh instanceof TextShape){
- TextShape tx = (TextShape)sh;
- TextRun run = tx.getTextRun();
- RichTextRun rt = run.getRichTextRuns()[0];
+ if(sh instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)sh;
+ HSLFTextParagraph run = tx.getTextParagraph();
+ HSLFTextRun rt = run.getRichTextRuns()[0];
assertTrue(rt.isBold());
assertEquals(rt.getFontColor(), Color.RED);
}
@@ -533,9 +533,9 @@ public final class TestTextRun extends TestCase {
}
public void test52244() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("52244.ppt"));
- Slide slide = ppt.getSlides()[0];
- TextRun[] runs = slide.getTextRuns();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52244.ppt"));
+ HSLFSlide slide = ppt.getSlides()[0];
+ HSLFTextParagraph[] runs = slide.getTextRuns();
assertEquals("Arial", runs[0].getRichTextRuns()[0].getFontName());
assertEquals(36, runs[0].getRichTextRuns()[0].getFontSize());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
index db55a2c052..c5a01341ae 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRunReWrite.java
@@ -19,11 +19,11 @@ package org.apache.poi.hslf.model;
import junit.framework.TestCase;
+
import java.io.*;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
@@ -36,9 +36,9 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestTextRunReWrite extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow hss;
+ private HSLFSlideShowImpl hss;
// HSLFSlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
// POIFS primed on the test data
private POIFSFileSystem pfs;
@@ -49,14 +49,14 @@ public final class TestTextRunReWrite extends TestCase {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
String filename = "Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
pfs = new POIFSFileSystem(slTests.openResourceAsStream(filename));
- hss = new HSLFSlideShow(pfs);
- ss = new SlideShow(hss);
+ hss = new HSLFSlideShowImpl(pfs);
+ ss = new HSLFSlideShow(hss);
}
public void testWritesOutTheSameNonRich() throws Exception {
// Grab the first text run on the first sheet
- TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
- TextRun tr2 = ss.getSlides()[0].getTextRuns()[1];
+ HSLFTextParagraph tr1 = ss.getSlides()[0].getTextRuns()[0];
+ HSLFTextParagraph tr2 = ss.getSlides()[0].getTextRuns()[1];
// Ensure the text lengths are as we'd expect to start with
assertEquals(1, ss.getSlides().length);
@@ -112,10 +112,10 @@ public final class TestTextRunReWrite extends TestCase {
public void testWritesOutTheSameRich() throws Exception {
// Grab the first text run on the first sheet
- TextRun tr1 = ss.getSlides()[0].getTextRuns()[0];
+ HSLFTextParagraph tr1 = ss.getSlides()[0].getTextRuns()[0];
// Get the first rich text run
- RichTextRun rtr1 = tr1.getRichTextRuns()[0];
+ HSLFTextRun rtr1 = tr1.getRichTextRuns()[0];
// Check that the text sizes are as expected
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java
index 542d608d8e..5666b8db0e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java
@@ -34,7 +34,7 @@ import java.util.Map;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.ShapeType;
import org.junit.Test;
@@ -48,14 +48,14 @@ public final class TestTextShape {
@Test
public void createAutoShape(){
- TextShape shape = new AutoShape(ShapeType.TRAPEZOID);
- assertNull(shape.getTextRun());
+ HSLFTextShape shape = new HSLFAutoShape(ShapeType.TRAPEZOID);
+ assertNull(shape.getTextParagraph());
assertNull(shape.getText());
assertNull(shape.getEscherTextboxWrapper());
- TextRun run = shape.createTextRun();
+ HSLFTextParagraph run = shape.createTextRun();
assertNotNull(run);
- assertNotNull(shape.getTextRun());
+ assertNotNull(shape.getTextParagraph());
assertNotNull(shape.getEscherTextboxWrapper());
assertEquals("", shape.getText());
assertSame(run, shape.createTextRun());
@@ -64,14 +64,14 @@ public final class TestTextShape {
@Test
public void createTextBox(){
- TextShape shape = new TextBox();
- TextRun run = shape.getTextRun();
+ HSLFTextShape shape = new HSLFTextBox();
+ HSLFTextParagraph run = shape.getTextParagraph();
assertNotNull(run);
assertNotNull(shape.getText());
assertNotNull(shape.getEscherTextboxWrapper());
assertSame(run, shape.createTextRun());
- assertNotNull(shape.getTextRun());
+ assertNotNull(shape.getTextParagraph());
assertNotNull(shape.getEscherTextboxWrapper());
assertEquals("", shape.getText());
@@ -85,15 +85,15 @@ public final class TestTextShape {
*/
@Test
public void read() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text_shapes.ppt"));
List lst1 = new ArrayList();
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
HSLFShape[] shape = slide.getShapes();
for (int i = 0; i < shape.length; i++) {
- assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof TextShape);
- TextShape tx = (TextShape)shape[i];
- TextRun run = tx.getTextRun();
+ assertTrue("Expected TextShape but found " + shape[i].getClass().getName(), shape[i] instanceof HSLFTextShape);
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
+ HSLFTextParagraph run = tx.getTextParagraph();
assertNotNull(run);
int runType = run.getRunType();
@@ -125,7 +125,7 @@ public final class TestTextShape {
}
List lst2 = new ArrayList();
- TextRun[] run = slide.getTextRuns();
+ HSLFTextParagraph[] run = slide.getTextRuns();
for (int i = 0; i < run.length; i++) {
lst2.add(run[i].getText());
}
@@ -135,18 +135,18 @@ public final class TestTextShape {
@Test
public void readWrite() throws IOException {
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
- TextShape shape1 = new TextBox();
- TextRun run1 = shape1.createTextRun();
+ HSLFTextShape shape1 = new HSLFTextBox();
+ HSLFTextParagraph run1 = shape1.createTextRun();
run1.setText("Hello, World!");
slide.addShape(shape1);
shape1.moveTo(100, 100);
- TextShape shape2 = new AutoShape(ShapeType.RIGHT_ARROW);
- TextRun run2 = shape2.createTextRun();
+ HSLFTextShape shape2 = new HSLFAutoShape(ShapeType.RIGHT_ARROW);
+ HSLFTextParagraph run2 = shape2.createTextRun();
run2.setText("Testing TextShape");
slide.addShape(shape2);
shape2.moveTo(300, 300);
@@ -155,37 +155,37 @@ public final class TestTextShape {
ppt.write(out);
out.close();
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides()[0];
HSLFShape[] shape = slide.getShapes();
- assertTrue(shape[0] instanceof TextShape);
- shape1 = (TextShape)shape[0];
+ assertTrue(shape[0] instanceof HSLFTextShape);
+ shape1 = (HSLFTextShape)shape[0];
assertEquals(ShapeType.TEXT_BOX, shape1.getShapeType());
- assertEquals("Hello, World!", shape1.getTextRun().getText());
+ assertEquals("Hello, World!", shape1.getTextParagraph().getText());
- assertTrue(shape[1] instanceof TextShape);
- shape1 = (TextShape)shape[1];
+ assertTrue(shape[1] instanceof HSLFTextShape);
+ shape1 = (HSLFTextShape)shape[1];
assertEquals(ShapeType.RIGHT_ARROW, shape1.getShapeType());
- assertEquals("Testing TextShape", shape1.getTextRun().getText());
+ assertEquals("Testing TextShape", shape1.getTextParagraph().getText());
}
@Test
public void margins() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("text-margins.ppt"));
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
- Map map = new HashMap();
+ Map map = new HashMap();
HSLFShape[] shape = slide.getShapes();
for (int i = 0; i < shape.length; i++) {
- if(shape[i] instanceof TextShape){
- TextShape tx = (TextShape)shape[i];
+ if(shape[i] instanceof HSLFTextShape){
+ HSLFTextShape tx = (HSLFTextShape)shape[i];
map.put(tx.getText(), tx);
}
}
- TextShape tx;
+ HSLFTextShape tx;
tx = map.get("TEST1");
assertEquals(0.1, tx.getMarginLeft()*HSLFShape.EMU_PER_POINT/HSLFShape.EMU_PER_INCH, 0.01);
@@ -214,22 +214,22 @@ public final class TestTextShape {
@Test
public void bug52599() throws IOException {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("52599.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("52599.ppt"));
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
HSLFShape[] sh = slide.getShapes();
assertEquals(3, sh.length);
- TextShape sh0 = (TextShape)sh[0];
+ HSLFTextShape sh0 = (HSLFTextShape)sh[0];
assertEquals(null, sh0.getText());
- assertEquals(null, sh0.getTextRun());
+ assertEquals(null, sh0.getTextParagraph());
- TextShape sh1 = (TextShape)sh[1];
+ HSLFTextShape sh1 = (HSLFTextShape)sh[1];
assertEquals(null, sh1.getText());
- assertEquals(null, sh1.getTextRun());
+ assertEquals(null, sh1.getTextParagraph());
- TextShape sh2 = (TextShape)sh[2];
+ HSLFTextShape sh2 = (HSLFTextShape)sh[2];
assertEquals("this box should be shown just once", sh2.getText());
- assertEquals(-1, sh2.getTextRun().getIndex());
+ assertEquals(-1, sh2.getTextParagraph().getIndex());
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java
index 7db3ca6c8e..7e37b47a43 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java
@@ -19,7 +19,7 @@ package org.apache.poi.hslf.model;
import org.apache.poi.hslf.record.StyleTextPropAtom;
import org.apache.poi.hslf.record.TextCharsAtom;
import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.usermodel.DummyGraphics2d;
import org.junit.Test;
@@ -27,22 +27,22 @@ import org.junit.Test;
public class TextPainterTest {
@Test
public void testTextPainter() {
- TextShape shape = new Polygon();
+ HSLFTextShape shape = new Polygon();
TextPainter painter = new TextPainter(shape);
- painter.getAttributedString(new TextRun(null, new TextCharsAtom(), null));
+ painter.getAttributedString(new HSLFTextParagraph(null, new TextCharsAtom(), null));
painter.paint(new DummyGraphics2d());
painter.getTextElements((float)1.0, null);
}
@Test
public void testTextPainterWithText() {
- TextShape shape = new Polygon();
+ HSLFTextShape shape = new Polygon();
TextPainter painter = new TextPainter(shape);
TextCharsAtom tca = new TextCharsAtom();
tca.setText("some text to read");
- TextRun txrun = new TextRun(new TextHeaderAtom(), tca, new StyleTextPropAtom(10));
- Slide sheet = new Slide(1, 1, 1);
- sheet.setSlideShow(new SlideShow());
+ HSLFTextParagraph txrun = new HSLFTextParagraph(new TextHeaderAtom(), tca, new StyleTextPropAtom(10));
+ HSLFSlide sheet = new HSLFSlide(1, 1, 1);
+ sheet.setSlideShow(new HSLFSlideShow());
txrun.setSheet(sheet);
painter.getAttributedString(txrun, new DummyGraphics2d());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
index 05478e3374..60aee0f49d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
@@ -24,8 +24,8 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Test;
@@ -72,7 +72,7 @@ public final class TestCurrentUserAtom {
new CurrentUserAtom(fs);
assertTrue(true); // not yet failed
- new HSLFSlideShow(fs);
+ new HSLFSlideShowImpl(fs);
}
@Test
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
index 114a41da8d..d7de61c877 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java
@@ -19,7 +19,7 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.POIDataSamples;
@@ -30,14 +30,14 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestDocument extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow ss;
+ private HSLFSlideShowImpl ss;
// POIFS primed on the test data
private POIFSFileSystem pfs;
public TestDocument() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
pfs = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new HSLFSlideShow(pfs);
+ ss = new HSLFSlideShowImpl(pfs);
}
private Document getDocRecord() {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java
index d9e3717842..12c114b344 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocumentEncryption.java
@@ -33,11 +33,11 @@ import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
-import org.apache.poi.hslf.model.Slide;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.HSLFSlide;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.EncryptionInfo;
@@ -71,8 +71,8 @@ public class TestDocumentEncryption {
for (String pptFile : encPpts) {
try {
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
- HSLFSlideShow hss = new HSLFSlideShow(fs);
- new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
+ new HSLFSlideShow(hss);
fs.close();
} catch (EncryptedPowerPointFileException e) {
fail(pptFile+" can't be decrypted");
@@ -85,9 +85,9 @@ public class TestDocumentEncryption {
String pptFile = "cryptoapi-proc2356.ppt";
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
- HSLFSlideShow hss = new HSLFSlideShow(fs);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
// need to cache data (i.e. read all data) before changing the key size
- PictureData picsExpected[] = hss.getPictures();
+ HSLFPictureData picsExpected[] = hss.getPictures();
hss.getDocumentSummaryInformation();
EncryptionInfo ei = hss.getDocumentEncryptionAtom().getEncryptionInfo();
((CryptoAPIEncryptionHeader)ei.getHeader()).setKeySize(0x78);
@@ -97,8 +97,8 @@ public class TestDocumentEncryption {
fs.close();
fs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
- hss = new HSLFSlideShow(fs);
- PictureData picsActual[] = hss.getPictures();
+ hss = new HSLFSlideShowImpl(fs);
+ HSLFPictureData picsActual[] = hss.getPictures();
fs.close();
assertEquals(picsExpected.length, picsActual.length);
@@ -112,7 +112,7 @@ public class TestDocumentEncryption {
/* documents with multiple edits need to be normalized for encryption */
String pptFile = "57272_corrupted_usereditatom.ppt";
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
- HSLFSlideShow hss = new HSLFSlideShow(fs);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
hss.normalizeRecords();
// normalized ppt
@@ -128,7 +128,7 @@ public class TestDocumentEncryption {
// decrypted
ByteArrayInputStream bis = new ByteArrayInputStream(encrypted.toByteArray());
fs = new NPOIFSFileSystem(bis);
- hss = new HSLFSlideShow(fs);
+ hss = new HSLFSlideShowImpl(fs);
Biff8EncryptionKey.setCurrentUserPassword(null);
ByteArrayOutputStream actual = new ByteArrayOutputStream();
hss.write(actual);
@@ -143,10 +143,10 @@ public class TestDocumentEncryption {
// http://blogs.msdn.com/b/openspecification/archive/2009/05/08/dominic-salemno.aspx
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile("cryptoapi-proc2356.ppt"));
- HSLFSlideShow hss = new HSLFSlideShow(fs);
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
- Slide slide = ss.getSlides()[0];
+ HSLFSlide slide = ss.getSlides()[0];
assertEquals("Dominic Salemno", slide.getTextRuns()[0].getText());
String picCmp[][] = {
@@ -160,9 +160,9 @@ public class TestDocumentEncryption {
};
MessageDigest md = CryptoFunctions.getMessageDigest(HashAlgorithm.sha1);
- PictureData pd[] = hss.getPictures();
+ HSLFPictureData pd[] = hss.getPictures();
int i = 0;
- for (PictureData p : pd) {
+ for (HSLFPictureData p : pd) {
byte hash[] = md.digest(p.getData());
assertEquals(Integer.parseInt(picCmp[i][0]), p.getOffset());
assertEquals(picCmp[i][1], Base64.encodeBase64String(hash));
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
index fff9d7286e..f712e20a6d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExHyperlink.java
@@ -25,8 +25,8 @@ import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -99,8 +99,8 @@ public final class TestExHyperlink extends TestCase {
public void testRealFile() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
index d3739ec3b8..836016666e 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestExObjList.java
@@ -20,8 +20,8 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.POIDataSamples;
/**
@@ -32,8 +32,8 @@ import org.apache.poi.POIDataSamples;
public class TestExObjList extends TestCase {
public void testRealFile() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("WithLinks.ppt"));
- SlideShow ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
+ HSLFSlideShow ss = new HSLFSlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
index 8481cbc70f..cecf3ee319 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordContainer.java
@@ -20,7 +20,7 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.POIDataSamples;
/**
@@ -149,7 +149,7 @@ public final class TestRecordContainer extends TestCase {
// Find a real RecordContainer record
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
Record[] r = hss.getRecords();
for(int i=0; i notesMap = new HashMap();
@@ -143,10 +128,10 @@ public final class TestBugs {
notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier");
notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L");
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
Integer slideNumber = Integer.valueOf(slide[i].getSlideNumber());
- Notes notes = slide[i].getNotesSheet();
+ HSLFNotes notes = slide[i].getNotesSheet();
if (notesMap.containsKey(slideNumber)){
assertNotNull(notes);
String text = notes.getTextRuns()[0].getRawText();
@@ -162,18 +147,18 @@ public final class TestBugs {
*/
@Test
public void bug42485 () throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
HSLFShape[] shape = ppt.getSlides()[0].getShapes();
for (int i = 0; i < shape.length; i++) {
if(shape[i] instanceof HSLFGroupShape){
HSLFGroupShape group = (HSLFGroupShape)shape[i];
HSLFShape[] sh = group.getShapes();
for (int j = 0; j < sh.length; j++) {
- if( sh[j] instanceof TextBox){
- TextBox txt = (TextBox)sh[j];
- assertNotNull(txt.getTextRun());
+ if( sh[j] instanceof HSLFTextBox){
+ HSLFTextBox txt = (HSLFTextBox)sh[j];
+ assertNotNull(txt.getTextParagraph());
}
}
}
@@ -185,9 +170,9 @@ public final class TestBugs {
*/
@Test
public void bug42484 () throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42485.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
HSLFShape[] shape = ppt.getSlides()[0].getShapes();
for (int i = 0; i < shape.length; i++) {
if(shape[i] instanceof HSLFGroupShape){
@@ -207,16 +192,16 @@ public final class TestBugs {
*/
@Test
public void bug41381() throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("alterman_security.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("alterman_security.ppt"));
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
assertEquals(1, ppt.getSlidesMasters().length);
assertEquals(1, ppt.getTitleMasters().length);
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
- MasterSheet master = slide[i].getMasterSheet();
+ HSLFMasterSheet master = slide[i].getMasterSheet();
if (i == 0) assertTrue(master instanceof TitleMaster); //the first slide follows TitleMaster
else assertTrue(master instanceof SlideMaster);
}
@@ -227,10 +212,10 @@ public final class TestBugs {
*/
@Test
public void bug42486 () throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
- SlideShow ppt = new SlideShow(hslf);
- Slide[] slide = ppt.getSlides();
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
@SuppressWarnings("unused")
HSLFShape[] shape = slide[i].getShapes();
@@ -244,11 +229,11 @@ public final class TestBugs {
*/
@Test
public void bug42524 () throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42486.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//walk down the tree and see if there were no errors while reading
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
HSLFShape[] shape = slide[i].getShapes();
for (int j = 0; j < shape.length; j++) {
@@ -272,17 +257,17 @@ public final class TestBugs {
*/
@Test
public void bug42520 () throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(_slTests.openResourceAsStream("42520.ppt"));
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//test case from the bug report
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides()[11].getShapes()[10];
- Picture picture = (Picture)shapeGroup.getShapes()[0];
+ HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes()[0];
picture.getPictureData();
//walk down the tree and see if there were no errors while reading
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
HSLFShape[] shape = slide[i].getShapes();
for (int j = 0; j < shape.length; j++) {
@@ -291,9 +276,9 @@ public final class TestBugs {
HSLFShape[] comps = group.getShapes();
for (int k = 0; k < comps.length; k++) {
HSLFShape comp = comps[k];
- if (comp instanceof Picture){
+ if (comp instanceof HSLFPictureShape){
@SuppressWarnings("unused")
- PictureData pict = ((Picture)comp).getPictureData();
+ HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
}
}
}
@@ -310,13 +295,13 @@ public final class TestBugs {
*/
@Test
public void bug38256 () throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("38256.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("38256.ppt"));
assertTrue("No Exceptions while reading file", true);
- Slide[] slide = ppt.getSlides();
+ HSLFSlide[] slide = ppt.getSlides();
assertEquals(1, slide.length);
- TextRun[] runs = slide[0].getTextRuns();
+ HSLFTextParagraph[] runs = slide[0].getTextRuns();
assertEquals(4, runs.length);
Set txt = new HashSet();
@@ -338,13 +323,13 @@ public final class TestBugs {
*/
@Test
public void bug43781 () throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("43781.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
assertTrue("No Exceptions while reading file", true);
// Check the first slide
- Slide slide = ppt.getSlides()[0];
- TextRun[] slTr = slide.getTextRuns();
+ HSLFSlide slide = ppt.getSlides()[0];
+ HSLFTextParagraph[] slTr = slide.getTextRuns();
// Has two text runs, one from slide text, one from drawing
assertEquals(2, slTr.length);
@@ -354,11 +339,11 @@ public final class TestBugs {
assertEquals("Second run", slTr[1].getText());
// Check the shape based text runs
- List lst = new ArrayList();
+ List lst = new ArrayList();
HSLFShape[] shape = slide.getShapes();
for (int i = 0; i < shape.length; i++) {
- if( shape[i] instanceof TextShape){
- TextRun textRun = ((TextShape)shape[i]).getTextRun();
+ if( shape[i] instanceof HSLFTextShape){
+ HSLFTextParagraph textRun = ((HSLFTextShape)shape[i]).getTextParagraph();
if(textRun != null) {
lst.add(textRun);
}
@@ -377,17 +362,17 @@ public final class TestBugs {
*/
@Test
public void bug44296 () throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("44296.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
- Background b = slide.getBackground();
- Fill f = b.getFill();
- assertEquals(Fill.FILL_PICTURE, f.getFillType());
+ HSLFBackground b = slide.getBackground();
+ HSLFFill f = b.getFill();
+ assertEquals(HSLFFill.FILL_PICTURE, f.getFillType());
- PictureData pict = f.getPictureData();
+ HSLFPictureData pict = f.getPictureData();
assertNotNull(pict);
- assertEquals(Picture.JPEG, pict.getType());
+ assertEquals(HSLFPictureShape.JPEG, pict.getType());
}
/**
@@ -396,7 +381,7 @@ public final class TestBugs {
@Test
public void bug44770() throws Exception {
try {
- new SlideShow(_slTests.openResourceAsStream("44770.ppt"));
+ new HSLFSlideShow(_slTests.openResourceAsStream("44770.ppt"));
} catch (RuntimeException e) {
if (e.getMessage().equals("Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing")) {
throw new AssertionFailedError("Identified bug 44770");
@@ -410,16 +395,16 @@ public final class TestBugs {
*/
@Test
public void bug41071() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("41071.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
- Slide slide = ppt.getSlides()[0];
+ HSLFSlide slide = ppt.getSlides()[0];
HSLFShape[] sh = slide.getShapes();
assertEquals(1, sh.length);
- assertTrue(sh[0] instanceof TextShape);
- TextShape tx = (TextShape)sh[0];
- assertEquals("Fundera, planera och involvera.", tx.getTextRun().getText());
+ assertTrue(sh[0] instanceof HSLFTextShape);
+ HSLFTextShape tx = (HSLFTextShape)sh[0];
+ assertEquals("Fundera, planera och involvera.", tx.getTextParagraph().getText());
- TextRun[] run = slide.getTextRuns();
+ HSLFTextParagraph[] run = slide.getTextRuns();
assertEquals(1, run.length);
assertEquals("Fundera, planera och involvera.", run[0].getText());
}
@@ -431,10 +416,10 @@ public final class TestBugs {
@Test(expected=OldPowerPointFormatException.class)
public void bug41711() throws Exception {
// New file is fine
- new SlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
+ new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
// PowerPoint 95 gives an old format exception
- new SlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
+ new HSLFSlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
}
/**
@@ -442,9 +427,9 @@ public final class TestBugs {
*/
@Test
public void bug49648() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("49648.ppt"));
- for(Slide slide : ppt.getSlides()) {
- for(TextRun run : slide.getTextRuns()) {
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
+ for(HSLFSlide slide : ppt.getSlides()) {
+ for(HSLFTextParagraph run : slide.getTextRuns()) {
String text = run.getRawText();
text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
run.setRawText(text);
@@ -458,10 +443,10 @@ public final class TestBugs {
@Test
public void bug41246a() throws Exception {
InputStream fis = _slTests.openResourceAsStream("41246-1.ppt");
- HSLFSlideShow hslf = new HSLFSlideShow(fis);
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
fis.close();
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
@@ -471,10 +456,10 @@ public final class TestBugs {
@Test
public void bug41246b() throws Exception {
InputStream fis = _slTests.openResourceAsStream("41246-2.ppt");
- HSLFSlideShow hslf = new HSLFSlideShow(fis);
+ HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
fis.close();
- SlideShow ppt = new SlideShow(hslf);
+ HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true);
ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
@@ -487,14 +472,14 @@ public final class TestBugs {
@Test
public void bug45776() throws Exception {
InputStream is = _slTests.openResourceAsStream("45776.ppt");
- SlideShow ppt = new SlideShow(new HSLFSlideShow(is));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(is));
is.close();
// get slides
- for (Slide slide : ppt.getSlides()) {
+ for (HSLFSlide slide : ppt.getSlides()) {
for (HSLFShape shape : slide.getShapes()) {
- if (!(shape instanceof TextBox)) continue;
- TextBox tb = (TextBox) shape;
+ if (!(shape instanceof HSLFTextBox)) continue;
+ HSLFTextBox tb = (HSLFTextBox) shape;
// work with TextBox
String str = tb.getText();
@@ -502,7 +487,7 @@ public final class TestBugs {
str = str.replace("$$DATE$$", new Date().toString());
tb.setText(str);
- TextRun tr = tb.getTextRun();
+ HSLFTextParagraph tr = tb.getTextParagraph();
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getParagraphStyles().getFirst().getCharactersCovered());
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getCharacterStyles().getFirst().getCharactersCovered());
}
@@ -513,12 +498,12 @@ public final class TestBugs {
public void bug55732() throws Exception {
File file = _slTests.getFile("bug55732.ppt");
- HSLFSlideShow ss = new HSLFSlideShow(file.getAbsolutePath());
- SlideShow _show = new SlideShow(ss);
- Slide[] _slides = _show.getSlides();
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
+ HSLFSlideShow _show = new HSLFSlideShow(ss);
+ HSLFSlide[] _slides = _show.getSlides();
/* Iterate over slides and extract text */
- for( Slide slide : _slides ) {
+ for( HSLFSlide slide : _slides ) {
HeadersFooters hf = slide.getHeadersFooters();
/*boolean visible =*/ hf.isHeaderVisible(); // exception happens here
}
@@ -529,9 +514,9 @@ public final class TestBugs {
public void bug56260() throws Exception {
File file = _slTests.getFile("56260.ppt");
- HSLFSlideShow ss = new HSLFSlideShow(file.getAbsolutePath());
- SlideShow _show = new SlideShow(ss);
- Slide[] _slides = _show.getSlides();
+ HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
+ HSLFSlideShow _show = new HSLFSlideShow(ss);
+ HSLFSlide[] _slides = _show.getSlides();
assertEquals(13, _slides.length);
// Check the number of TextHeaderAtoms on Slide 1
@@ -553,7 +538,7 @@ public final class TestBugs {
// Check the number of text runs based on the slide (not textbox)
// Will have skipped the empty one
int str = 0;
- for (TextRun tr : _slides[0].getTextRuns()) {
+ for (HSLFTextParagraph tr : _slides[0].getTextRuns()) {
if (! tr.isDrawingBased()) str++;
}
assertEquals(1, str);
@@ -563,10 +548,10 @@ public final class TestBugs {
public void bug37625() throws IOException {
InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
assertEquals(29, slideShow.getSlides().length);
- SlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
+ HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack);
assertEquals(29, slideBack.getSlides().length);
} finally {
@@ -578,10 +563,10 @@ public final class TestBugs {
public void bug57272() throws Exception {
InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
assertEquals(6, slideShow.getSlides().length);
- SlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
+ HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack);
assertEquals(6, slideBack.getSlides().length);
} finally {
@@ -593,10 +578,10 @@ public final class TestBugs {
public void bug49541() throws Exception {
InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
- Slide slide = slideShow.getSlides()[0];
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
+ HSLFSlide slide = slideShow.getSlides()[0];
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes()[0];
- TextBox tb = (TextBox)sg.getShapes()[0];
+ HSLFTextBox tb = (HSLFTextBox)sg.getShapes()[0];
String text = StringUtil.mapMsCodepointString(tb.getText());
assertEquals("\u226575 years", text);
} finally {
@@ -608,7 +593,7 @@ public final class TestBugs {
public void bug47261() throws Exception {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug47261.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
slideShow.removeSlide(0);
slideShow.createSlide();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -622,7 +607,7 @@ public final class TestBugs {
public void bug56240() throws Exception {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
int slideCnt = slideShow.getSlides().length;
assertEquals(105, slideCnt);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -637,8 +622,8 @@ public final class TestBugs {
public void bug46441() throws Exception {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
try {
- SlideShow slideShow = new SlideShow(inputStream);
- AutoShape as = (AutoShape)slideShow.getSlides()[0].getShapes()[0];
+ HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
+ HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides()[0].getShapes()[0];
EscherOptRecord opt = as.getEscherOptRecord();
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
double exp[][] = {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
index eb84e7711a..dbee82742f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
@@ -30,16 +31,16 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestCounts extends TestCase {
// SlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
public TestCounts() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testSheetsCount() {
- Slide[] slides = ss.getSlides();
+ HSLFSlide[] slides = ss.getSlides();
// Two sheets - master sheet is separate
assertEquals(2, slides.length);
@@ -57,7 +58,7 @@ public final class TestCounts extends TestCase {
}
public void testNotesCount() {
- Notes[] notes = ss.getNotes();
+ HSLFNotes[] notes = ss.getNotes();
// Two sheets -> two notes
// Note: there are also notes on the slide master
//assertEquals(3, notes.length); // When we do slide masters
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
index a6fa770059..37b7bb6965 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestFontRendering.java
@@ -39,7 +39,7 @@ import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.model.Slide;
+import org.apache.poi.hslf.model.HSLFSlide;
import org.apache.poi.hslf.model.TextPainter;
import org.apache.poi.util.TempFile;
import org.junit.Ignore;
@@ -82,12 +82,12 @@ public class TestFontRendering {
}
InputStream is = slTests.openResourceAsStream("bug55902-mixedFontChineseCharacters.ppt");
- SlideShow ss = new SlideShow(is);
+ HSLFSlideShow ss = new HSLFSlideShow(is);
is.close();
Dimension pgsize = ss.getPageSize();
- Slide slide = ss.getSlides()[0];
+ HSLFSlide slide = ss.getSlides()[0];
// render it
double zoom = 1;
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
index ce68b7a2d8..088dbb0cee 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestMostRecentRecords.java
@@ -19,7 +19,9 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.*;
import org.apache.poi.POIDataSamples;
@@ -30,14 +32,14 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestMostRecentRecords extends TestCase {
// HSLFSlideShow primed on the test data
- private HSLFSlideShow hss;
+ private HSLFSlideShowImpl hss;
// SlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
public TestMostRecentRecords() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testCount() {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
index 3def468f9e..22b40a22e2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestNotesText.java
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
@@ -30,16 +31,16 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestNotesText extends TestCase {
// SlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
public TestNotesText() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testNotesOne() {
- Notes notes = ss.getNotes()[0];
+ HSLFNotes notes = ss.getNotes()[0];
String[] expectText = new String[] {"These are the notes for page 1"};
assertEquals(expectText.length, notes.getTextRuns().length);
@@ -49,7 +50,7 @@ public final class TestNotesText extends TestCase {
}
public void testNotesTwo() {
- Notes notes = ss.getNotes()[1];
+ HSLFNotes notes = ss.getNotes()[1];
String[] expectText = new String[] {"These are the notes on page two, again lacking formatting"};
assertEquals(expectText.length, notes.getTextRuns().length);
for(int i=0; i 3
assertEquals(s1._getSheetNumber(), _s3._getSheetNumber());
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java
index 5475dae9c1..c15bacd1f2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRecordSetup.java
@@ -19,7 +19,9 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.model.HSLFSlideShowImpl;
import org.apache.poi.hslf.record.ParentAwareRecord;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordContainer;
@@ -34,13 +36,13 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestRecordSetup extends TestCase {
// SlideShow primed on the test data
- private SlideShow ss;
- private HSLFSlideShow hss;
+ private HSLFSlideShow ss;
+ private HSLFSlideShowImpl hss;
public TestRecordSetup() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testHandleParentAwareRecords() {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
index a71b72a28b..267e9ec7a4 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java
@@ -23,10 +23,7 @@ import java.io.FileInputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.model.Slide;
-import org.apache.poi.hslf.model.TextBox;
-import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.*;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.SlideListWithText;
@@ -39,40 +36,40 @@ public final class TestRichTextRun extends POITestCase {
private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
// SlideShow primed on the test data
- private SlideShow ss;
- private SlideShow ssRichA;
- private SlideShow ssRichB;
- private SlideShow ssRichC;
- private SlideShow ssChinese;
- private HSLFSlideShow hss;
- private HSLFSlideShow hssRichA;
- private HSLFSlideShow hssRichB;
- private HSLFSlideShow hssRichC;
- private HSLFSlideShow hssChinese;
+ private HSLFSlideShow ss;
+ private HSLFSlideShow ssRichA;
+ private HSLFSlideShow ssRichB;
+ private HSLFSlideShow ssRichC;
+ private HSLFSlideShow ssChinese;
+ private HSLFSlideShowImpl hss;
+ private HSLFSlideShowImpl hssRichA;
+ private HSLFSlideShowImpl hssRichB;
+ private HSLFSlideShowImpl hssRichC;
+ private HSLFSlideShowImpl hssChinese;
private static String filenameC;
protected void setUp() throws Exception {
// Basic (non rich) test file
- hss = new HSLFSlideShow(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ hss = new HSLFSlideShowImpl(_slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
// Rich test file A
- hssRichA = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
- ssRichA = new SlideShow(hssRichA);
+ hssRichA = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
+ ssRichA = new HSLFSlideShow(hssRichA);
// Rich test file B
- hssRichB = new HSLFSlideShow(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
- ssRichB = new SlideShow(hssRichB);
+ hssRichB = new HSLFSlideShowImpl(_slTests.openResourceAsStream("Single_Coloured_Page_With_Fonts_and_Alignments.ppt"));
+ ssRichB = new HSLFSlideShow(hssRichB);
// Rich test file C - has paragraph styles that run out before
// the character ones do
filenameC = "ParagraphStylesShorterThanCharStyles.ppt";
- hssRichC = new HSLFSlideShow(_slTests.openResourceAsStream(filenameC));
- ssRichC = new SlideShow(hssRichC);
+ hssRichC = new HSLFSlideShowImpl(_slTests.openResourceAsStream(filenameC));
+ ssRichC = new HSLFSlideShow(hssRichC);
// Rich test file with Chinese + English text in it
- hssChinese = new HSLFSlideShow(_slTests.openResourceAsStream("54880_chinese.ppt"));
- ssChinese = new SlideShow(hssChinese);
+ hssChinese = new HSLFSlideShowImpl(_slTests.openResourceAsStream("54880_chinese.ppt"));
+ ssChinese = new HSLFSlideShow(hssChinese);
}
/**
@@ -80,9 +77,9 @@ public final class TestRichTextRun extends POITestCase {
* on a non rich text run
*/
public void testBoldNonRich() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextRun rtr = textRuns[0].getRichTextRuns()[0];
assertNull(rtr._getRawCharacterStyle());
assertNull(rtr._getRawParagraphStyle());
@@ -108,9 +105,9 @@ public final class TestRichTextRun extends POITestCase {
* on a rich text run
*/
public void testBoldRich() {
- Slide slideOneR = ssRichA.getSlides()[0];
- TextRun[] textRunsR = slideOneR.getTextRuns();
- RichTextRun[] rtrs = textRunsR[1].getRichTextRuns();
+ HSLFSlide slideOneR = ssRichA.getSlides()[0];
+ HSLFTextParagraph[] textRunsR = slideOneR.getTextRuns();
+ HSLFTextRun[] rtrs = textRunsR[1].getRichTextRuns();
assertEquals(3, rtrs.length);
assertTrue(rtrs[0].isBold());
@@ -136,15 +133,15 @@ public final class TestRichTextRun extends POITestCase {
*/
public void testFontSize() {
- Slide slideOne = ss.getSlides()[0];
- TextRun[] textRuns = slideOne.getTextRuns();
- RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
+ HSLFSlide slideOne = ss.getSlides()[0];
+ HSLFTextParagraph[] textRuns = slideOne.getTextRuns();
+ HSLFTextRun rtr = textRuns[0].getRichTextRuns()[0];
- Slide slideOneR = ssRichB.getSlides()[0];
- TextRun[] textRunsR = slideOneR.getTextRuns();
- RichTextRun rtrRa = textRunsR[0].getRichTextRuns()[0];
- RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
- RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
+ HSLFSlide slideOneR = ssRichB.getSlides()[0];
+ HSLFTextParagraph[] textRunsR = slideOneR.getTextRuns();
+ HSLFTextRun rtrRa = textRunsR[0].getRichTextRuns()[0];
+ HSLFTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
+ HSLFTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
String defaultFont = "Arial";
@@ -195,14 +192,14 @@ public final class TestRichTextRun extends POITestCase {
}
public void testChangeWriteRead() throws Exception {
- HSLFSlideShow[] h = new HSLFSlideShow[] { hss, hssRichA, hssRichB };
- Slide[] s = new Slide[] { ss.getSlides()[0], ssRichA.getSlides()[0], ssRichB.getSlides()[0] };
+ HSLFSlideShowImpl[] h = new HSLFSlideShowImpl[] { hss, hssRichA, hssRichB };
+ HSLFSlide[] s = new HSLFSlide[] { ss.getSlides()[0], ssRichA.getSlides()[0], ssRichB.getSlides()[0] };
for(int i=0; i(text a)(text a)(text b)
// TR:
// (text)
- TextRun[] s7tr = slideSevenC.getTextRuns();
- RichTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
- RichTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
- RichTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
+ HSLFTextParagraph[] s7tr = slideSevenC.getTextRuns();
+ HSLFTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
+ HSLFTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
+ HSLFTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
assertEquals(1, s7rtr0.length);
assertEquals(3, s7rtr1.length);
@@ -334,11 +331,11 @@ public final class TestRichTextRun extends POITestCase {
assertMatchesSLTWC(ssRichC);
assertMatchesFileC(ssRichC);
- Slide slideSevenC = ssRichC.getSlides()[6];
- TextRun[] s7tr = slideSevenC.getTextRuns();
- RichTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
- RichTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
- RichTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
+ HSLFSlide slideSevenC = ssRichC.getSlides()[6];
+ HSLFTextParagraph[] s7tr = slideSevenC.getTextRuns();
+ HSLFTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
+ HSLFTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
+ HSLFTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
String oldText;
@@ -374,9 +371,9 @@ public final class TestRichTextRun extends POITestCase {
* contents.
* @param s
*/
- private void assertMatchesSLTWC(SlideShow s) throws Exception {
+ private void assertMatchesSLTWC(HSLFSlideShow s) throws Exception {
// Grab a new copy of slideshow C
- SlideShow refC = new SlideShow(_slTests.openResourceAsStream(filenameC));
+ HSLFSlideShow refC = new HSLFSlideShow(_slTests.openResourceAsStream(filenameC));
// Write out the 2nd SLWT in the active document
SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1];
@@ -411,7 +408,7 @@ public final class TestRichTextRun extends POITestCase {
* Checks that the supplied slideshow still matches the bytes
* of slideshow c
*/
- private static void assertMatchesFileC(SlideShow s) throws Exception {
+ private static void assertMatchesFileC(HSLFSlideShow s) throws Exception {
if (true) { // TODO - test is disabled, pending fix of bug #39800
// System.err.println("Skipping test, as would be marked as failed due to bug #39800"); //
return;
@@ -450,12 +447,12 @@ if(false) {
}
public void testIndentationLevel() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
- Slide[] sl = ppt.getSlides();
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
+ HSLFSlide[] sl = ppt.getSlides();
for (int i = 0; i < sl.length; i++) {
- TextRun[] txt = sl[i].getTextRuns();
+ HSLFTextParagraph[] txt = sl[i].getTextRuns();
for (int j = 0; j < txt.length; j++) {
- RichTextRun[] rt = txt[j].getRichTextRuns();
+ HSLFTextRun[] rt = txt[j].getRichTextRuns();
for (int k = 0; k < rt.length; k++) {
int indent = rt[k].getIndentLevel();
assertTrue(indent >= 0 && indent <= 4 );
@@ -466,12 +463,12 @@ if(false) {
}
public void testReadParagraphStyles() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
assertTrue("No Exceptions while reading file", true);
- RichTextRun rt;
- TextRun[] txt;
- Slide[] slide = ppt.getSlides();
+ HSLFTextRun rt;
+ HSLFTextParagraph[] txt;
+ HSLFSlide[] slide = ppt.getSlides();
assertEquals(2, slide.length);
txt = slide[0].getTextRuns();
@@ -516,12 +513,12 @@ if(false) {
}
public void testSetParagraphStyles() throws Exception {
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide slide = ppt.createSlide();
- TextBox shape = new TextBox();
- RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
+ HSLFTextBox shape = new HSLFTextBox();
+ HSLFTextRun rt = shape.getTextParagraph().getRichTextRuns()[0];
shape.setText(
"Hello, World!\r" +
"This should be\r" +
@@ -547,10 +544,10 @@ if(false) {
ppt.write(out);
out.close();
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides()[0];
- shape = (TextBox)slide.getShapes()[0];
- rt = shape.getTextRun().getRichTextRuns()[0];
+ shape = (HSLFTextBox)slide.getShapes()[0];
+ rt = shape.getTextParagraph().getRichTextRuns()[0];
assertEquals(42, rt.getFontSize());
assertEquals(true, rt.isBullet());
assertEquals(50, rt.getTextOffset());
@@ -559,12 +556,12 @@ if(false) {
}
public void testAddText() throws Exception {
- SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("bullets.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bullets.ppt"));
assertTrue("No Exceptions while reading file", true);
- RichTextRun rt;
- TextRun[] txt;
- Slide[] slides = ppt.getSlides();
+ HSLFTextRun rt;
+ HSLFTextParagraph[] txt;
+ HSLFSlide[] slides = ppt.getSlides();
assertEquals(2, slides.length);
txt = slides[0].getTextRuns();
@@ -605,7 +602,7 @@ if(false) {
ppt.write(out);
out.close();
- ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
+ ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slides = ppt.getSlides();
assertEquals(2, slides.length);
@@ -628,10 +625,10 @@ if(false) {
}
public void testChineseParagraphs() throws Exception {
- RichTextRun[] rts;
- RichTextRun rt;
- TextRun[] txt;
- Slide[] slides = ssChinese.getSlides();
+ HSLFTextRun[] rts;
+ HSLFTextRun rt;
+ HSLFTextParagraph[] txt;
+ HSLFSlide[] slides = ssChinese.getSlides();
// One slide
assertEquals(1, slides.length);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
index cb27d3ee92..fda2aba0d0 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
@@ -19,6 +19,7 @@ package org.apache.poi.hslf.usermodel;
import junit.framework.TestCase;
+
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples;
@@ -30,16 +31,16 @@ import org.apache.poi.POIDataSamples;
*/
public final class TestSheetText extends TestCase {
// SlideShow primed on the test data
- private SlideShow ss;
+ private HSLFSlideShow ss;
public TestSheetText() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
- HSLFSlideShow hss = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
- ss = new SlideShow(hss);
+ HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
+ ss = new HSLFSlideShow(hss);
}
public void testSheetOne() {
- Sheet slideOne = ss.getSlides()[0];
+ HSLFSheet slideOne = ss.getSlides()[0];
String[] expectText = new String[] {"This is a test title","This is a test subtitle\nThis is on page 1"};
assertEquals(expectText.length, slideOne.getTextRuns().length);
@@ -49,7 +50,7 @@ public final class TestSheetText extends TestCase {
}
public void testSheetTwo() {
- Sheet slideTwo = ss.getSlides()[1];
+ HSLFSheet slideTwo = ss.getSlides()[1];
String[] expectText = new String[] {"This is the title on page 2","This is page two\nIt has several blocks of text\nNone of them have formatting"};
assertEquals(expectText.length, slideTwo.getTextRuns().length);
for(int i=0; i