common sl: reworked and unified generics definitions

made various methods available through common sl
added createTextBox,AutoShape,... methods to ShapeContainers
hslf tables created by poi, will be identified as such when the file is read again

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1697515 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-08-24 23:15:14 +00:00
parent 0d7476e130
commit cd536720dd
96 changed files with 1070 additions and 476 deletions

View File

@ -31,7 +31,6 @@ import java.util.Map;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.sl.SlideShowFactory; import org.apache.poi.sl.SlideShowFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
@ -42,7 +41,7 @@ import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.util.JvmBugs; import org.apache.poi.util.JvmBugs;
public abstract class SlideShowHandler extends POIFSFileHandler { public abstract class SlideShowHandler extends POIFSFileHandler {
public void handleSlideShow(SlideShow ss) throws IOException { public void handleSlideShow(SlideShow<?,?> ss) throws IOException {
renderSlides(ss); renderSlides(ss);
readContent(ss); readContent(ss);
@ -53,7 +52,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
readContent(ss); readContent(ss);
// read in the writen file // read in the writen file
SlideShow read; SlideShow<?,?> read;
try { try {
read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray())); read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()));
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
@ -65,7 +64,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} }
private ByteArrayOutputStream writeToArray(SlideShow ss) throws IOException { private ByteArrayOutputStream writeToArray(SlideShow<?,?> ss) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
try { try {
ss.write(stream); ss.write(stream);
@ -77,8 +76,8 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} }
private void readContent(SlideShow ss) { private void readContent(SlideShow<?,?> ss) {
for (Slide<?,?,? extends Notes<?,?>> s : ss.getSlides()) { for (Slide<?,?> s : ss.getSlides()) {
s.getTitle(); s.getTitle();
readText(s); readText(s);
readText(s.getNotes()); readText(s.getNotes());
@ -86,12 +85,11 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} }
} }
@SuppressWarnings("unchecked") private void readText(ShapeContainer<?,?> sc) {
private void readText(ShapeContainer<?> sc) {
if (sc == null) return; if (sc == null) return;
for (Shape s : sc) { for (Shape<?,?> s : sc) {
if (s instanceof TextShape) { if (s instanceof TextShape) {
for (TextParagraph<? extends TextRun> tp : (TextShape<TextParagraph<? extends TextRun>>)s) { for (TextParagraph<?,?,?> tp : (TextShape<?,?>)s) {
for (TextRun tr : tp) { for (TextRun tr : tp) {
tr.getRawText(); tr.getRawText();
} }
@ -100,10 +98,10 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} }
} }
private void renderSlides(SlideShow ss) { private void renderSlides(SlideShow<?,?> ss) {
Dimension pgsize = ss.getPageSize(); Dimension pgsize = ss.getPageSize();
for (Slide<?,?,?> s : ss.getSlides()) { for (Slide<?,?> s : ss.getSlides()) {
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB); BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics(); Graphics2D graphics = img.createGraphics();
fixFonts(graphics); fixFonts(graphics);

View File

@ -221,13 +221,13 @@ public final class EscherContainerRecord extends EscherRecord {
} }
public void addChildBefore(EscherRecord record, int insertBeforeRecordId) { public void addChildBefore(EscherRecord record, int insertBeforeRecordId) {
for (int i = 0; i < _childRecords.size(); i++) { int idx = 0;
EscherRecord rec = _childRecords.get(i); for (EscherRecord rec : _childRecords) {
if(rec.getRecordId() == insertBeforeRecordId){ if(rec.getRecordId() == (short)insertBeforeRecordId) break;
_childRecords.add(i++, record); // TODO - keep looping? Do we expect multiple matches?
// TODO - keep looping? Do we expect multiple matches? idx++;
}
} }
_childRecords.add(idx, record);
} }
public String toString() public String toString()

View File

@ -20,8 +20,8 @@ package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawAutoShape<T extends AutoShape<? extends TextParagraph<? extends TextRun>>> extends DrawTextShape<T> { public class DrawAutoShape extends DrawTextShape {
public DrawAutoShape(T shape) { public DrawAutoShape(AutoShape<?,?> shape) {
super(shape); super(shape);
} }
} }

View File

@ -17,24 +17,28 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import java.awt.*; import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.Background;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.sl.usermodel.ShapeContainer;
public class DrawBackground<T extends Background> extends DrawShape<T> { public class DrawBackground extends DrawShape {
public DrawBackground(T shape) { public DrawBackground(Background<?,?> shape) {
super(shape); super(shape);
} }
@SuppressWarnings("rawtypes")
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
Dimension pg = shape.getSheet().getSlideShow().getPageSize(); Dimension pg = shape.getSheet().getSlideShow().getPageSize();
final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight()); final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
PlaceableShape ps = new PlaceableShape(){ PlaceableShape<?,?> ps = new PlaceableShape(){
public ShapeContainer<? extends Shape> getParent() { return null; } public ShapeContainer<?,?> getParent() { return null; }
public Rectangle2D getAnchor() { return anchor; } public Rectangle2D getAnchor() { return anchor; }
public void setAnchor(Rectangle2D anchor) {} public void setAnchor(Rectangle2D anchor) {}
public double getRotation() { return 0; } public double getRotation() { return 0; }
@ -47,7 +51,7 @@ public class DrawBackground<T extends Background> extends DrawShape<T> {
DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawFactory drawFact = DrawFactory.getInstance(graphics);
DrawPaint dp = drawFact.getPaint(ps); DrawPaint dp = drawFact.getPaint(ps);
Paint fill = dp.getPaint(graphics, shape.getFillStyle().getPaint()); Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint());
Rectangle2D anchor2 = getAnchor(graphics, anchor); Rectangle2D anchor2 = getAnchor(graphics, anchor);
if(fill != null) { if(fill != null) {
@ -56,5 +60,7 @@ public class DrawBackground<T extends Background> extends DrawShape<T> {
} }
} }
protected Background<?,?> getShape() {
return (Background<?,?>)shape;
}
} }

View File

@ -17,10 +17,10 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.ConnectorShape;
public class DrawConnectorShape<T extends ConnectorShape> extends DrawSimpleShape<T> { public class DrawConnectorShape extends DrawSimpleShape {
public DrawConnectorShape(T shape) { public DrawConnectorShape(ConnectorShape<?,?> shape) {
super(shape); super(shape);
} }
} }

View File

@ -28,17 +28,14 @@ import org.apache.poi.sl.usermodel.ConnectorShape;
import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.FreeformShape;
import org.apache.poi.sl.usermodel.GroupShape; import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.PlaceableShape; import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.TableShape; import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.sl.usermodel.TextBox; import org.apache.poi.sl.usermodel.TextBox;
import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.sl.usermodel.TextShape;
public class DrawFactory { public class DrawFactory {
@ -77,90 +74,89 @@ public class DrawFactory {
return factory; return factory;
} }
@SuppressWarnings("unchecked") public Drawable getDrawable(Shape<?,?> shape) {
public Drawable getDrawable(Shape shape) {
if (shape instanceof TextBox) { if (shape instanceof TextBox) {
return getDrawable((TextBox<? extends TextParagraph<? extends TextRun>>)shape); return getDrawable((TextBox<?,?>)shape);
} else if (shape instanceof FreeformShape) { } else if (shape instanceof FreeformShape) {
return getDrawable((FreeformShape<? extends TextParagraph<? extends TextRun>>)shape); return getDrawable((FreeformShape<?,?>)shape);
} else if (shape instanceof TextShape) { } else if (shape instanceof TextShape) {
return getDrawable((TextShape<? extends TextParagraph<? extends TextRun>>)shape); return getDrawable((TextShape<?,?>)shape);
} else if (shape instanceof GroupShape) {
return getDrawable((GroupShape<? extends Shape>)shape);
} else if (shape instanceof PictureShape) {
return getDrawable((PictureShape)shape);
} else if (shape instanceof Background) {
return getDrawable((Background)shape);
} else if (shape instanceof ConnectorShape) {
return getDrawable((ConnectorShape)shape);
} else if (shape instanceof TableShape) { } else if (shape instanceof TableShape) {
return getDrawable((TableShape)shape); return getDrawable((TableShape<?,?>)shape);
} else if (shape instanceof GroupShape) {
return getDrawable((GroupShape<?,?>)shape);
} else if (shape instanceof PictureShape) {
return getDrawable((PictureShape<?,?>)shape);
} else if (shape instanceof Background) {
return getDrawable((Background<?,?>)shape);
} else if (shape instanceof ConnectorShape) {
return getDrawable((ConnectorShape<?,?>)shape);
} else if (shape instanceof Slide) { } else if (shape instanceof Slide) {
return getDrawable((Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>)shape); return getDrawable((Slide<?,?>)shape);
} else if (shape instanceof MasterSheet) { } else if (shape instanceof MasterSheet) {
return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape); return getDrawable((MasterSheet<?,?>)shape);
} else if (shape instanceof Sheet) { } else if (shape instanceof Sheet) {
return getDrawable((Sheet<? extends Shape, ? extends SlideShow>)shape); return getDrawable((Sheet<?,?>)shape);
} else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) { } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {
return new DrawNothing<Shape>(shape); return new DrawNothing(shape);
} }
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass()); throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());
} }
public <T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> DrawSlide<T> getDrawable(T sheet) { public DrawSlide getDrawable(Slide<?,?> sheet) {
return new DrawSlide<T>(sheet); return new DrawSlide(sheet);
} }
public <T extends Sheet<? extends Shape, ? extends SlideShow>> DrawSheet<T> getDrawable(T sheet) { public DrawSheet getDrawable(Sheet<?,?> sheet) {
return new DrawSheet<T>(sheet); return new DrawSheet(sheet);
} }
public <T extends MasterSheet<? extends Shape, ? extends SlideShow>> DrawMasterSheet<T> getDrawable(T sheet) { public DrawMasterSheet getDrawable(MasterSheet<?,?> sheet) {
return new DrawMasterSheet<T>(sheet); return new DrawMasterSheet(sheet);
} }
public <T extends TextBox<? extends TextParagraph<?>>> DrawTextBox<T> getDrawable(T shape) { public DrawTextBox getDrawable(TextBox<?,?> shape) {
return new DrawTextBox<T>(shape); return new DrawTextBox(shape);
} }
public <T extends FreeformShape<? extends TextParagraph<? extends TextRun>>> DrawFreeformShape<T> getDrawable(T shape) { public DrawFreeformShape getDrawable(FreeformShape<?,?> shape) {
return new DrawFreeformShape<T>(shape); return new DrawFreeformShape(shape);
} }
public <T extends ConnectorShape> DrawConnectorShape<T> getDrawable(T shape) { public DrawConnectorShape getDrawable(ConnectorShape<?,?> shape) {
return new DrawConnectorShape<T>(shape); return new DrawConnectorShape(shape);
} }
public <T extends TableShape> DrawTableShape<T> getDrawable(T shape) { public DrawTableShape getDrawable(TableShape<?,?> shape) {
return new DrawTableShape<T>(shape); return new DrawTableShape(shape);
} }
public <T extends TextShape<? extends TextParagraph<? extends TextRun>>> DrawTextShape<T> getDrawable(T shape) { public DrawTextShape getDrawable(TextShape<?,?> shape) {
return new DrawTextShape<T>(shape); return new DrawTextShape(shape);
} }
public <T extends GroupShape<? extends Shape>> DrawGroupShape<T> getDrawable(T shape) { public DrawGroupShape getDrawable(GroupShape<?,?> shape) {
return new DrawGroupShape<T>(shape); return new DrawGroupShape(shape);
} }
public <T extends PictureShape> DrawPictureShape<T> getDrawable(T shape) { public DrawPictureShape getDrawable(PictureShape<?,?> shape) {
return new DrawPictureShape<T>(shape); return new DrawPictureShape(shape);
} }
public <T extends TextRun> DrawTextParagraph<T> getDrawable(TextParagraph<T> paragraph) { public DrawTextParagraph getDrawable(TextParagraph<?,?,?> paragraph) {
return new DrawTextParagraph<T>(paragraph); return new DrawTextParagraph(paragraph);
} }
public <T extends Background> DrawBackground<T> getDrawable(T shape) { public DrawBackground getDrawable(Background<?,?> shape) {
return new DrawBackground<T>(shape); return new DrawBackground(shape);
} }
public DrawTextFragment getTextFragment(TextLayout layout, AttributedString str) { public DrawTextFragment getTextFragment(TextLayout layout, AttributedString str) {
return new DrawTextFragment(layout, str); return new DrawTextFragment(layout, str);
} }
public DrawPaint getPaint(PlaceableShape shape) { public DrawPaint getPaint(PlaceableShape<?,?> shape) {
return new DrawPaint(shape); return new DrawPaint(shape);
} }
} }

View File

@ -27,21 +27,24 @@ import org.apache.poi.sl.draw.geom.Path;
import org.apache.poi.sl.usermodel.FillStyle; import org.apache.poi.sl.usermodel.FillStyle;
import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.FreeformShape;
import org.apache.poi.sl.usermodel.StrokeStyle; import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextRun;
public class DrawFreeformShape<T extends FreeformShape<? extends TextParagraph<? extends TextRun>>> extends DrawAutoShape<T> { public class DrawFreeformShape extends DrawAutoShape {
public DrawFreeformShape(T shape) { public DrawFreeformShape(FreeformShape<?,?> shape) {
super(shape); super(shape);
} }
protected Collection<Outline> computeOutlines(Graphics2D graphics) { protected Collection<Outline> computeOutlines(Graphics2D graphics) {
List<Outline> lst = new ArrayList<Outline>(); List<Outline> lst = new ArrayList<Outline>();
java.awt.Shape sh = shape.getPath(); java.awt.Shape sh = getShape().getPath();
FillStyle fs = shape.getFillStyle(); FillStyle fs = getShape().getFillStyle();
StrokeStyle ss = shape.getStrokeStyle(); StrokeStyle ss = getShape().getStrokeStyle();
Path path = new Path(fs != null, ss != null); Path path = new Path(fs != null, ss != null);
lst.add(new Outline(sh, path)); lst.add(new Outline(sh, path));
return lst; return lst;
} }
@Override
protected FreeformShape<?,?> getShape() {
return (FreeformShape<?,?>)shape;
}
} }

View File

@ -24,18 +24,18 @@ import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawGroupShape<T extends GroupShape<? extends Shape>> extends DrawShape<T> implements Drawable { public class DrawGroupShape extends DrawShape {
public DrawGroupShape(T shape) { public DrawGroupShape(GroupShape<?,?> shape) {
super(shape); super(shape);
} }
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
// the coordinate system of this group of shape // the coordinate system of this group of shape
Rectangle2D interior = shape.getInteriorAnchor(); Rectangle2D interior = getShape().getInteriorAnchor();
// anchor of this group relative to the parent shape // anchor of this group relative to the parent shape
Rectangle2D exterior = shape.getAnchor(); Rectangle2D exterior = getShape().getAnchor();
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
AffineTransform tx0 = new AffineTransform(tx); AffineTransform tx0 = new AffineTransform(tx);
@ -50,7 +50,7 @@ public class DrawGroupShape<T extends GroupShape<? extends Shape>> extends DrawS
DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawFactory drawFact = DrawFactory.getInstance(graphics);
AffineTransform at2 = graphics.getTransform(); AffineTransform at2 = graphics.getTransform();
for (Shape child : shape) { for (Shape<?,?> child : getShape()) {
// remember the initial transform and restore it after we are done with the drawing // remember the initial transform and restore it after we are done with the drawing
AffineTransform at = graphics.getTransform(); AffineTransform at = graphics.getTransform();
graphics.setRenderingHint(Drawable.GSAVE, true); graphics.setRenderingHint(Drawable.GSAVE, true);
@ -67,4 +67,9 @@ public class DrawGroupShape<T extends GroupShape<? extends Shape>> extends DrawS
graphics.setTransform(at2); graphics.setTransform(at2);
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0); graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);
} }
@Override
protected GroupShape<?,?> getShape() {
return (GroupShape<?,?>)shape;
}
} }

View File

@ -20,9 +20,9 @@ package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawMasterSheet<T extends MasterSheet<? extends Shape, ? extends SlideShow>> extends DrawSheet<T> { public class DrawMasterSheet extends DrawSheet {
public DrawMasterSheet(T sheet) { public DrawMasterSheet(MasterSheet<?,?> sheet) {
super(sheet); super(sheet);
} }
@ -32,7 +32,8 @@ public class DrawMasterSheet<T extends MasterSheet<? extends Shape, ? extends Sl
* Subclasses can override it and skip certain shapes from drawings, * Subclasses can override it and skip certain shapes from drawings,
* for instance, slide masters and layouts don't display placeholders * for instance, slide masters and layouts don't display placeholders
*/ */
protected boolean canDraw(Shape shape){ @Override
return !(shape instanceof SimpleShape) || !((SimpleShape)shape).isPlaceholder(); protected boolean canDraw(Shape<?,?> shape){
return !(shape instanceof SimpleShape) || !((SimpleShape<?,?>)shape).isPlaceholder();
} }
} }

View File

@ -22,11 +22,11 @@ import java.awt.Graphics2D;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Shape;
public class DrawNothing<T extends Shape> implements Drawable { public class DrawNothing implements Drawable {
protected final T shape; protected final Shape<?,?> shape;
public DrawNothing(T shape) { public DrawNothing(Shape<?,?> shape) {
this.shape = shape; this.shape = shape;
} }

View File

@ -50,9 +50,9 @@ public class DrawPaint {
private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class); private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class);
protected PlaceableShape shape; protected PlaceableShape<?,?> shape;
public DrawPaint(PlaceableShape shape) { public DrawPaint(PlaceableShape<?,?> shape) {
this.shape = shape; this.shape = shape;
} }

View File

@ -26,22 +26,22 @@ import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.PictureShape;
public class DrawPictureShape<T extends PictureShape> extends DrawSimpleShape<T> { public class DrawPictureShape extends DrawSimpleShape {
public DrawPictureShape(T shape) { public DrawPictureShape(PictureShape<?,?> shape) {
super(shape); super(shape);
} }
@Override @Override
public void drawContent(Graphics2D graphics) { public void drawContent(Graphics2D graphics) {
PictureData data = shape.getPictureData(); PictureData data = getShape().getPictureData();
if(data == null) return; if(data == null) return;
ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER); ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER);
if (renderer == null) renderer = new ImageRenderer(); if (renderer == null) renderer = new ImageRenderer();
Rectangle2D anchor = getAnchor(graphics, shape); Rectangle2D anchor = getAnchor(graphics, getShape());
Insets insets = shape.getClipping(); Insets insets = getShape().getClipping();
try { try {
renderer.loadImage(data.getData(), data.getContentType()); renderer.loadImage(data.getData(), data.getContentType());
@ -51,4 +51,9 @@ public class DrawPictureShape<T extends PictureShape> extends DrawSimpleShape<T>
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override
protected PictureShape<?,?> getShape() {
return (PictureShape<?,?>)shape;
}
} }

View File

@ -25,14 +25,14 @@ import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Shape;
public class DrawShape<T extends Shape> implements Drawable { public class DrawShape implements Drawable {
protected final T shape; protected final Shape<?,?> shape;
public DrawShape(T shape) { public DrawShape(Shape<?,?> shape) {
this.shape = shape; this.shape = shape;
} }
/** /**
* Apply 2-D transforms before drawing this shape. This includes rotation and flipping. * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
* *
@ -40,8 +40,8 @@ public class DrawShape<T extends Shape> implements Drawable {
*/ */
public void applyTransform(Graphics2D graphics) { public void applyTransform(Graphics2D graphics) {
if (!(shape instanceof PlaceableShape)) return; if (!(shape instanceof PlaceableShape)) return;
PlaceableShape ps = (PlaceableShape)shape; PlaceableShape<?,?> ps = (PlaceableShape<?,?>)shape;
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
if (tx == null) tx = new AffineTransform(); if (tx == null) tx = new AffineTransform();
final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D(); final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();
@ -59,12 +59,12 @@ public class DrawShape<T extends Shape> implements Drawable {
int quadrant = (((int)rotation+45)/90)%4; int quadrant = (((int)rotation+45)/90)%4;
double scaleX = 1.0, scaleY = 1.0; double scaleX = 1.0, scaleY = 1.0;
// scale to bounding box (bug #53176) // scale to bounding box (bug #53176)
if (quadrant == 1 || quadrant == 3) { if (quadrant == 1 || quadrant == 3) {
// In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation
// (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple
// of 90 degrees and then resize the bounding box to its original bbox. After that we can // of 90 degrees and then resize the bounding box to its original bbox. After that we can
// rotate the shape to the exact rotation amount. // rotate the shape to the exact rotation amount.
// It's strange that you'll need to rotate the shape back and forth again, but you can // It's strange that you'll need to rotate the shape back and forth again, but you can
// think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might // think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might
@ -82,19 +82,19 @@ public class DrawShape<T extends Shape> implements Drawable {
txs.translate(-centerX, -centerY); txs.translate(-centerX, -centerY);
txs.concatenate(tx); txs.concatenate(tx);
} }
txs.translate(centerX, centerY); txs.translate(centerX, centerY);
txs.rotate(Math.PI/2.); txs.rotate(Math.PI/2.);
txs.translate(-centerX, -centerY); txs.translate(-centerX, -centerY);
Rectangle2D anchor2 = txs.createTransformedShape(ps.getAnchor()).getBounds2D(); Rectangle2D anchor2 = txs.createTransformedShape(ps.getAnchor()).getBounds2D();
scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth(); scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth();
scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight(); scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();
} else { } else {
quadrant = 0; quadrant = 0;
} }
// transformation is applied reversed ... // transformation is applied reversed ...
graphics.translate(centerX, centerY); graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation-quadrant*90.)); graphics.rotate(Math.toRadians(rotation-quadrant*90.));
@ -122,13 +122,13 @@ public class DrawShape<T extends Shape> implements Drawable {
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
} }
public void drawContent(Graphics2D context) { public void drawContent(Graphics2D graphics) {
} }
public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape shape) { public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape<?,?> shape) {
return getAnchor(graphics, shape.getAnchor()); return getAnchor(graphics, shape.getAnchor());
} }
public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) { public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) {
if(graphics == null) { if(graphics == null) {
return anchor; return anchor;
@ -139,5 +139,9 @@ public class DrawShape<T extends Shape> implements Drawable {
anchor = tx.createTransformedShape(anchor).getBounds2D(); anchor = tx.createTransformedShape(anchor).getBounds2D();
} }
return anchor; return anchor;
} }
protected Shape<?,?> getShape() {
return shape;
}
} }

View File

@ -26,11 +26,11 @@ import java.awt.geom.AffineTransform;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> implements Drawable { public class DrawSheet implements Drawable {
protected final T sheet; protected final Sheet<?,?> sheet;
public DrawSheet(T sheet) { public DrawSheet(Sheet<?,?> sheet) {
this.sheet = sheet; this.sheet = sheet;
} }
@ -41,7 +41,7 @@ public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> im
graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight()); graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight());
DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawFactory drawFact = DrawFactory.getInstance(graphics);
MasterSheet<? extends Shape, ? extends SlideShow> master = sheet.getMasterSheet(); MasterSheet<?,?> master = sheet.getMasterSheet();
if(sheet.getFollowMasterGraphics() && master != null) { if(sheet.getFollowMasterGraphics() && master != null) {
Drawable drawer = drawFact.getDrawable(master); Drawable drawer = drawFact.getDrawable(master);
@ -50,7 +50,7 @@ public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> im
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform()); graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform());
for (Shape shape : sheet.getShapes()) { for (Shape<?,?> shape : sheet.getShapes()) {
if(!canDraw(shape)) continue; if(!canDraw(shape)) continue;
// remember the initial transform and restore it after we are done with drawing // remember the initial transform and restore it after we are done with drawing
@ -85,7 +85,7 @@ public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> im
* Subclasses can override it and skip certain shapes from drawings, * Subclasses can override it and skip certain shapes from drawings,
* for instance, slide masters and layouts don't display placeholders * for instance, slide masters and layouts don't display placeholders
*/ */
protected boolean canDraw(Shape shape){ protected boolean canDraw(Shape<?,?> shape){
return true; return true;
} }
} }

View File

@ -17,39 +17,60 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import java.awt.*; import java.awt.BasicStroke;
import java.awt.geom.*; import java.awt.Color;
import java.io.*; import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.xml.bind.*; import javax.xml.bind.JAXBContext;
import javax.xml.stream.*; import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.EventFilter; import javax.xml.stream.EventFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.StartElement; import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import org.apache.poi.sl.draw.binding.CTCustomGeometry2D; import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
import org.apache.poi.sl.draw.geom.*; import org.apache.poi.sl.draw.geom.Context;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.draw.geom.CustomGeometry;
import org.apache.poi.sl.draw.geom.Outline;
import org.apache.poi.sl.draw.geom.Path;
import org.apache.poi.sl.usermodel.LineDecoration;
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize; import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.StrokeStyle.*; import org.apache.poi.sl.usermodel.Shadow;
import org.apache.poi.sl.usermodel.SimpleShape;
import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> { public class DrawSimpleShape extends DrawShape {
public DrawSimpleShape(T shape) { public DrawSimpleShape(SimpleShape<?,?> shape) {
super(shape); super(shape);
} }
@Override @Override
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(shape); DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape());
Paint fill = drawPaint.getPaint(graphics, shape.getFillStyle().getPaint()); Paint fill = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint());
Paint line = drawPaint.getPaint(graphics, shape.getStrokeStyle().getPaint()); Paint line = drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint());
BasicStroke stroke = getStroke(); // the stroke applies both to the shadow and the shape BasicStroke stroke = getStroke(); // the stroke applies both to the shadow and the shape
graphics.setStroke(stroke); graphics.setStroke(stroke);
@ -94,7 +115,7 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
graphics.setPaint(line); graphics.setPaint(line);
List<Outline> lst = new ArrayList<Outline>(); List<Outline> lst = new ArrayList<Outline>();
LineDecoration deco = shape.getLineDecoration(); LineDecoration deco = getShape().getLineDecoration();
Outline head = getHeadDecoration(graphics, deco, stroke); Outline head = getHeadDecoration(graphics, deco, stroke);
if (head != null) lst.add(head); if (head != null) lst.add(head);
Outline tail = getTailDecoration(graphics, deco, stroke); Outline tail = getTailDecoration(graphics, deco, stroke);
@ -117,7 +138,7 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
double lineWidth = Math.max(2.5, stroke.getLineWidth()); double lineWidth = Math.max(2.5, stroke.getLineWidth());
Rectangle2D anchor = getAnchor(graphics, shape); Rectangle2D anchor = getAnchor(graphics, getShape());
double x2 = anchor.getX() + anchor.getWidth(), double x2 = anchor.getX() + anchor.getWidth(),
y2 = anchor.getY() + anchor.getHeight(); y2 = anchor.getY() + anchor.getHeight();
@ -175,7 +196,7 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
double lineWidth = Math.max(2.5, stroke.getLineWidth()); double lineWidth = Math.max(2.5, stroke.getLineWidth());
Rectangle2D anchor = getAnchor(graphics, shape); Rectangle2D anchor = getAnchor(graphics, getShape());
double x1 = anchor.getX(), double x1 = anchor.getX(),
y1 = anchor.getY(); y1 = anchor.getY();
@ -228,7 +249,7 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
} }
public BasicStroke getStroke() { public BasicStroke getStroke() {
StrokeStyle strokeStyle = shape.getStrokeStyle(); StrokeStyle strokeStyle = getShape().getStrokeStyle();
float lineWidth = (float) strokeStyle.getLineWidth(); float lineWidth = (float) strokeStyle.getLineWidth();
if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt
@ -275,14 +296,14 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
, Paint fill , Paint fill
, Paint line , Paint line
) { ) {
Shadow shadow = shape.getShadow(); Shadow shadow = getShape().getShadow();
if (shadow == null || (fill == null && line == null)) return; if (shadow == null || (fill == null && line == null)) return;
SolidPaint shadowPaint = shadow.getFillStyle(); SolidPaint shadowPaint = shadow.getFillStyle();
Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor()); Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor());
double shapeRotation = shape.getRotation(); double shapeRotation = getShape().getRotation();
if(shape.getFlipVertical()) { if(getShape().getFlipVertical()) {
shapeRotation += 180; shapeRotation += 180;
} }
double angle = shadow.getAngle() - shapeRotation; double angle = shadow.getAngle() - shapeRotation;
@ -366,12 +387,12 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
protected Collection<Outline> computeOutlines(Graphics2D graphics) { protected Collection<Outline> computeOutlines(Graphics2D graphics) {
List<Outline> lst = new ArrayList<Outline>(); List<Outline> lst = new ArrayList<Outline>();
CustomGeometry geom = shape.getGeometry(); CustomGeometry geom = getShape().getGeometry();
if(geom == null) { if(geom == null) {
return lst; return lst;
} }
Rectangle2D anchor = getAnchor(graphics, shape); Rectangle2D anchor = getAnchor(graphics, getShape());
for (Path p : geom) { for (Path p : geom) {
double w = p.getW() == -1 ? anchor.getWidth() * Units.EMU_PER_POINT : p.getW(); double w = p.getW() == -1 ? anchor.getWidth() * Units.EMU_PER_POINT : p.getW();
@ -381,7 +402,7 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
// so we build the path starting from (0,0). // so we build the path starting from (0,0).
final Rectangle2D pathAnchor = new Rectangle2D.Double(0,0,w,h); final Rectangle2D pathAnchor = new Rectangle2D.Double(0,0,w,h);
Context ctx = new Context(geom, pathAnchor, shape); Context ctx = new Context(geom, pathAnchor, getShape());
java.awt.Shape gp = p.getPath(ctx); java.awt.Shape gp = p.getPath(ctx);
@ -411,4 +432,8 @@ public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {
return lst; return lst;
} }
@Override
protected SimpleShape<?,?> getShape() {
return (SimpleShape<?,?>)shape;
}
} }

View File

@ -22,14 +22,14 @@ import java.awt.Graphics2D;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawSlide<T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> extends DrawSheet<T> { public class DrawSlide extends DrawSheet {
public DrawSlide(T slide) { public DrawSlide(Slide<?,?> slide) {
super(slide); super(slide);
} }
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
Background bg = sheet.getBackground(); Background<?,?> bg = sheet.getBackground();
if(bg != null) { if(bg != null) {
DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawFactory drawFact = DrawFactory.getInstance(graphics);
Drawable db = drawFact.getDrawable(bg); Drawable db = drawFact.getDrawable(bg);

View File

@ -17,11 +17,45 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*; import java.awt.Graphics2D;
public class DrawTableShape<T extends TableShape> extends DrawShape<T> { import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.TableShape;
public class DrawTableShape extends DrawShape {
// to be implemented ... // to be implemented ...
public DrawTableShape(T shape) { public DrawTableShape(TableShape<?,?> shape) {
super(shape); super(shape);
} }
protected Drawable getDrawable(Graphics2D graphics) {
if (shape instanceof GroupShape) {
DrawFactory df = DrawFactory.getInstance(graphics);
return df.getDrawable((GroupShape<?,?>)shape);
}
return null;
}
public void applyTransform(Graphics2D graphics) {
Drawable d = getDrawable(graphics);
if (d != null) {
d.applyTransform(graphics);
}
}
public void draw(Graphics2D graphics) {
Drawable d = getDrawable(graphics);
if (d != null) {
d.draw(graphics);
}
}
public void drawContent(Graphics2D graphics) {
Drawable d = getDrawable(graphics);
if (d != null) {
d.drawContent(graphics);
}
}
} }

View File

@ -19,8 +19,8 @@ package org.apache.poi.sl.draw;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
public class DrawTextBox<T extends TextBox<? extends TextParagraph<? extends TextRun>>> extends DrawAutoShape<T> { public class DrawTextBox extends DrawAutoShape {
public DrawTextBox(T shape) { public DrawTextBox(TextBox<?,?> shape) {
super(shape); super(shape);
} }
} }

View File

@ -35,7 +35,6 @@ import org.apache.poi.sl.usermodel.AutoNumberingScheme;
import org.apache.poi.sl.usermodel.Insets2D; import org.apache.poi.sl.usermodel.Insets2D;
import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PlaceableShape; import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle; import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
@ -45,8 +44,8 @@ import org.apache.poi.sl.usermodel.TextRun.TextCap;
import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.sl.usermodel.TextShape;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
public class DrawTextParagraph<T extends TextRun> implements Drawable { public class DrawTextParagraph implements Drawable {
protected TextParagraph<T> paragraph; protected TextParagraph<?,?,?> paragraph;
double x, y; double x, y;
protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>(); protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>();
protected String rawText; protected String rawText;
@ -58,7 +57,7 @@ public class DrawTextParagraph<T extends TextRun> implements Drawable {
*/ */
protected double maxLineHeight; protected double maxLineHeight;
public DrawTextParagraph(TextParagraph<T> paragraph) { public DrawTextParagraph(TextParagraph<?,?,?> paragraph) {
this.paragraph = paragraph; this.paragraph = paragraph;
} }
@ -266,7 +265,7 @@ public class DrawTextParagraph<T extends TextRun> implements Drawable {
if (buFont == null) buFont = paragraph.getDefaultFontFamily(); if (buFont == null) buFont = paragraph.getDefaultFontFamily();
assert(buFont != null); assert(buFont != null);
PlaceableShape ps = getParagraphShape(); PlaceableShape<?,?> ps = getParagraphShape();
PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor(); PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();
Paint fgPaint; Paint fgPaint;
if (fgPaintStyle == null) { if (fgPaintStyle == null) {
@ -377,7 +376,7 @@ public class DrawTextParagraph<T extends TextRun> implements Drawable {
} }
double width; double width;
TextShape<? extends TextParagraph<T>> ts = paragraph.getParentShape(); TextShape<?,?> ts = paragraph.getParentShape();
if (!ts.getWordWrap()) { if (!ts.getWordWrap()) {
// if wordWrap == false then we return the advance to the right border of the sheet // if wordWrap == false then we return the advance to the right border of the sheet
width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX(); width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX();
@ -413,9 +412,10 @@ public class DrawTextParagraph<T extends TextRun> implements Drawable {
/** /**
* Helper method for paint style relative to bounds, e.g. gradient paint * Helper method for paint style relative to bounds, e.g. gradient paint
*/ */
private PlaceableShape getParagraphShape() { @SuppressWarnings("rawtypes")
PlaceableShape ps = new PlaceableShape(){ private PlaceableShape<?,?> getParagraphShape() {
public ShapeContainer<? extends Shape> getParent() { return null; } PlaceableShape<?,?> ps = new PlaceableShape(){
public ShapeContainer<?,?> getParent() { return null; }
public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); } public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }
public void setAnchor(Rectangle2D anchor) {} public void setAnchor(Rectangle2D anchor) {}
public double getRotation() { return 0; } public double getRotation() { return 0; }
@ -432,7 +432,7 @@ public class DrawTextParagraph<T extends TextRun> implements Drawable {
List<AttributedStringData> attList = new ArrayList<AttributedStringData>(); List<AttributedStringData> attList = new ArrayList<AttributedStringData>();
if (text == null) text = new StringBuilder(); if (text == null) text = new StringBuilder();
PlaceableShape ps = getParagraphShape(); PlaceableShape<?,?> ps = getParagraphShape();
DrawFontManager fontHandler = (DrawFontManager)graphics.getRenderingHint(Drawable.FONT_HANDLER); DrawFontManager fontHandler = (DrawFontManager)graphics.getRenderingHint(Drawable.FONT_HANDLER);

View File

@ -27,9 +27,9 @@ import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle; import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
import org.apache.poi.util.JvmBugs; import org.apache.poi.util.JvmBugs;
public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends TextRun>>> extends DrawSimpleShape<T> { public class DrawTextShape extends DrawSimpleShape {
public DrawTextShape(T shape) { public DrawTextShape(TextShape<?,?> shape) {
super(shape); super(shape);
} }
@ -37,8 +37,8 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
public void drawContent(Graphics2D graphics) { public void drawContent(Graphics2D graphics) {
fixFonts(graphics); fixFonts(graphics);
Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); Rectangle2D anchor = DrawShape.getAnchor(graphics, getShape());
Insets2D insets = shape.getInsets(); Insets2D insets = getShape().getInsets();
double x = anchor.getX() + insets.left; double x = anchor.getX() + insets.left;
double y = anchor.getY(); double y = anchor.getY();
@ -50,7 +50,7 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
// (see DrawShape#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. // See Bugzilla 54210.
if(shape.getFlipVertical()){ if(getShape().getFlipVertical()){
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight()); graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
graphics.scale(1, -1); graphics.scale(1, -1);
graphics.translate(-anchor.getX(), -anchor.getY()); graphics.translate(-anchor.getX(), -anchor.getY());
@ -65,7 +65,7 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
// Horizontal flipping applies only to shape outline and not to the text in the shape. // Horizontal flipping applies only to shape outline and not to the text in the shape.
// Applying flip second time restores the original not-flipped transform // Applying flip second time restores the original not-flipped transform
if(shape.getFlipHorizontal()){ if(getShape().getFlipHorizontal()){
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY()); graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
graphics.scale(-1, 1); graphics.scale(-1, 1);
graphics.translate(-anchor.getX() , -anchor.getY()); graphics.translate(-anchor.getX() , -anchor.getY());
@ -73,9 +73,9 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
// first dry-run to calculate the total height of the text // first dry-run to calculate the total height of the text
double textHeight = shape.getTextHeight(); double textHeight = getShape().getTextHeight();
switch (shape.getVerticalAlignment()){ switch (getShape().getVerticalAlignment()){
case TOP: case TOP:
y += insets.top; y += insets.top;
break; break;
@ -104,12 +104,12 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
DrawFactory fact = DrawFactory.getInstance(graphics); DrawFactory fact = DrawFactory.getInstance(graphics);
double y0 = y; double y0 = y;
Iterator<? extends TextParagraph<? extends TextRun>> paragraphs = shape.iterator(); Iterator<? extends TextParagraph<?,?,? extends TextRun>> paragraphs = getShape().iterator();
boolean isFirstLine = true; boolean isFirstLine = true;
for (int autoNbrIdx=0; paragraphs.hasNext(); autoNbrIdx++){ for (int autoNbrIdx=0; paragraphs.hasNext(); autoNbrIdx++){
TextParagraph<? extends TextRun> p = paragraphs.next(); TextParagraph<?,?,? extends TextRun> p = paragraphs.next();
DrawTextParagraph<? extends TextRun> dp = fact.getDrawable(p); DrawTextParagraph dp = fact.getDrawable(p);
BulletStyle bs = p.getBulletStyle(); BulletStyle bs = p.getBulletStyle();
if (bs == null || bs.getAutoNumberingScheme() == null) { if (bs == null || bs.getAutoNumberingScheme() == null) {
autoNbrIdx = -1; autoNbrIdx = -1;
@ -180,4 +180,9 @@ public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends
if (!fontMap.containsKey("Calibri")) fontMap.put("Calibri", "Lucida Sans"); if (!fontMap.containsKey("Calibri")) fontMap.put("Calibri", "Lucida Sans");
if (!fontMap.containsKey("Cambria")) fontMap.put("Cambria", "Lucida Bright"); if (!fontMap.containsKey("Cambria")) fontMap.put("Cambria", "Lucida Bright");
} }
@Override
protected TextShape<?,?> getShape() {
return (TextShape<?,?>)shape;
}
} }

View File

@ -17,5 +17,8 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface AutoShape<T extends TextParagraph<? extends TextRun>> extends TextShape<T> { public interface AutoShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends TextShape<S,P> {
} }

View File

@ -17,6 +17,9 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface Background extends Shape { public interface Background<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Shape<S,P> {
FillStyle getFillStyle(); FillStyle getFillStyle();
} }

View File

@ -17,6 +17,9 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface ConnectorShape extends SimpleShape { public interface ConnectorShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends SimpleShape<S,P> {
} }

View File

@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
public interface FreeformShape<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> { public interface FreeformShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends AutoShape<S,P> {
/** /**
* Gets the shape path. * Gets the shape path.
* <p> * <p>

View File

@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
public interface GroupShape<T extends Shape> extends Shape, ShapeContainer<T>, PlaceableShape { public interface GroupShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Shape<S,P>, ShapeContainer<S,P>, PlaceableShape<S,P> {
/** /**
* Gets the coordinate space of this group. All children are constrained * Gets the coordinate space of this group. All children are constrained

View File

@ -25,6 +25,9 @@ import org.apache.poi.util.Internal;
*/ */
@Internal @Internal
public interface Line<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> { public interface Line<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends AutoShape<S,P> {
} }

View File

@ -17,6 +17,9 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface MasterSheet<T extends Shape, SS extends SlideShow> extends Sheet<T,SS> { public interface MasterSheet<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Sheet<S,P> {
} }

View File

@ -19,6 +19,9 @@ package org.apache.poi.sl.usermodel;
import java.util.List; import java.util.List;
public interface Notes<T extends Shape, SS extends SlideShow> extends Sheet<T,SS> { public interface Notes<
List<? extends List<? extends TextParagraph<? extends TextRun>>> getTextParagraphs(); S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Sheet<S,P> {
List<? extends List<P>> getTextParagraphs();
} }

View File

@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel;
import java.awt.Insets; import java.awt.Insets;
public interface PictureShape extends SimpleShape { public interface PictureShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends SimpleShape<S,P> {
/** /**
* Returns the picture data for this picture. * Returns the picture data for this picture.
* *

View File

@ -19,8 +19,11 @@ package org.apache.poi.sl.usermodel;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
public interface PlaceableShape { public interface PlaceableShape<
ShapeContainer<? extends Shape> getParent(); S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> {
ShapeContainer<S,P> getParent();
/** /**
* @return the position of this shape within the drawing canvas. * @return the position of this shape within the drawing canvas.

View File

@ -18,12 +18,15 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface Shape { public interface Shape<
ShapeContainer<? extends Shape> getParent(); S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> {
ShapeContainer<S,P> getParent();
/** /**
* *
* @return the sheet this shape belongs to * @return the sheet this shape belongs to
*/ */
Sheet<? extends Shape, ? extends SlideShow> getSheet(); Sheet<S,P> getSheet();
} }

View File

@ -20,7 +20,10 @@ package org.apache.poi.sl.usermodel;
import java.util.List; import java.util.List;
public interface ShapeContainer<T extends Shape> extends Iterable<T> { public interface ShapeContainer<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Iterable<S> {
/** /**
* Returns an list containing all of the elements in this container in proper * Returns an list containing all of the elements in this container in proper
* sequence (from first to last element). * sequence (from first to last element).
@ -28,9 +31,9 @@ public interface ShapeContainer<T extends Shape> extends Iterable<T> {
* @return an list containing all of the elements in this container in proper * @return an list containing all of the elements in this container in proper
* sequence * sequence
*/ */
List<T> getShapes(); List<S> getShapes();
void addShape(T shape); void addShape(S shape);
/** /**
* Removes the specified shape from this sheet, if it is present * Removes the specified shape from this sheet, if it is present
@ -42,5 +45,43 @@ public interface ShapeContainer<T extends Shape> extends Iterable<T> {
* @throws IllegalArgumentException if the type of the specified shape * @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional) * is incompatible with this sheet (optional)
*/ */
boolean removeShape(T shape); boolean removeShape(S shape);
/**
* create a new shape with a predefined geometry and add it to this shape container
*/
AutoShape<S,P> createAutoShape();
/**
* create a new shape with a custom geometry
*/
FreeformShape<S,P> createFreeform();
/**
* create a text box
*/
TextBox<S,P> createTextBox();
/**
* create a connector
*/
ConnectorShape<S,P> createConnector();
/**
* create a group of shapes belonging to this container
*/
GroupShape<S,P> createGroup();
/**
* create a picture belonging to this container
*/
PictureShape<S,P> createPicture(PictureData pictureData);
/**
* Create a new Table of the given number of rows and columns
*
* @param numrows the number of rows
* @param numcols the number of columns
*/
TableShape<S,P> createTable(int numRows, int numCols);
} }

View File

@ -23,8 +23,11 @@ import java.awt.Graphics2D;
/** /**
* Common parent of Slides, Notes and Masters * Common parent of Slides, Notes and Masters
*/ */
public interface Sheet<T extends Shape, SS extends SlideShow> extends ShapeContainer<T> { public interface Sheet<
SS getSlideShow(); S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends ShapeContainer<S,P> {
SlideShow<S,P> getSlideShow();
/** /**
* @return whether shapes on the master sheet should be shown. By default master graphics is turned off. * @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
@ -33,9 +36,9 @@ public interface Sheet<T extends Shape, SS extends SlideShow> extends ShapeConta
*/ */
boolean getFollowMasterGraphics(); boolean getFollowMasterGraphics();
MasterSheet<T,SS> getMasterSheet(); MasterSheet<S,P> getMasterSheet();
Background getBackground(); Background<S,P> getBackground();
/** /**
* Convenience method to draw a sheet to a graphics context * Convenience method to draw a sheet to a graphics context

View File

@ -21,7 +21,10 @@ import org.apache.poi.sl.draw.geom.CustomGeometry;
import org.apache.poi.sl.draw.geom.IAdjustableShape; import org.apache.poi.sl.draw.geom.IAdjustableShape;
public interface SimpleShape extends Shape, IAdjustableShape, PlaceableShape { public interface SimpleShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Shape<S,P>, IAdjustableShape, PlaceableShape<S,P> {
FillStyle getFillStyle(); FillStyle getFillStyle();
LineDecoration getLineDecoration(); LineDecoration getLineDecoration();
StrokeStyle getStrokeStyle(); StrokeStyle getStrokeStyle();

View File

@ -17,9 +17,12 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface Slide<T extends Shape, SS extends SlideShow, N extends Notes<T,SS>> extends Sheet<T, SS> { public interface Slide<
N getNotes(); S extends Shape<S,P>,
void setNotes(N notes); P extends TextParagraph<S,P,? extends TextRun>
> extends Sheet<S,P> {
Notes<S,P> getNotes();
void setNotes(Notes<S,P> notes);
boolean getFollowMasterBackground(); boolean getFollowMasterBackground();
void setFollowMasterBackground(boolean follow); void setFollowMasterBackground(boolean follow);

View File

@ -24,18 +24,21 @@ import java.util.List;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
public interface SlideShow { public interface SlideShow<
Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>> createSlide() throws IOException; S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> {
Slide<S,P> createSlide() throws IOException;
List<? extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> getSlides(); List<? extends Slide<S,P>> getSlides();
MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet() throws IOException; MasterSheet<S,P> createMasterSheet() throws IOException;
/** /**
* Returns all slide masters. * Returns all slide masters.
* This doesn't include notes master and other arbitrary masters. * This doesn't include notes master and other arbitrary masters.
*/ */
List<? extends MasterSheet<? extends Shape, ? extends SlideShow>> getSlideMasters(); List<? extends MasterSheet<S,P>> getSlideMasters();
Resources getResources(); Resources getResources();

View File

@ -0,0 +1,25 @@
/* ====================================================================
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.sl.usermodel;
public interface TableCell<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends TextShape<S,P> {
}

View File

@ -17,6 +17,9 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface TableShape extends Shape, PlaceableShape { public interface TableShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends Shape<S,P>, PlaceableShape<S,P> {
// to be defined ... // to be defined ...
} }

View File

@ -17,5 +17,8 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
public interface TextBox<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> { public interface TextBox<
S extends Shape<S,P>,
P extends TextParagraph<S,P,? extends TextRun>
> extends AutoShape<S,P> {
} }

View File

@ -21,7 +21,11 @@ import java.awt.Color;
public interface TextParagraph<T extends TextRun> extends Iterable<T> { public interface TextParagraph<
S extends Shape<S,P>,
P extends TextParagraph<S,P,T>,
T extends TextRun
> extends Iterable<T> {
/** /**
* Specifies a list of text alignment types * Specifies a list of text alignment types
@ -334,5 +338,5 @@ public interface TextParagraph<T extends TextRun> extends Iterable<T> {
Double getDefaultTabSize(); Double getDefaultTabSize();
TextShape<? extends TextParagraph<T>> getParentShape(); TextShape<S,P> getParentShape();
} }

View File

@ -17,11 +17,12 @@
package org.apache.poi.sl.usermodel; package org.apache.poi.sl.usermodel;
import org.apache.poi.ss.usermodel.HorizontalAlignment; import java.util.List;
public interface TextShape<
S extends Shape<S,P>,
public interface TextShape<T extends TextParagraph<? extends TextRun>> extends SimpleShape, Iterable<T> { P extends TextParagraph<S,P,? extends TextRun>
> extends SimpleShape<S,P>, Iterable<P> {
/** /**
* Vertical Text Types * Vertical Text Types
*/ */
@ -87,40 +88,45 @@ public interface TextShape<T extends TextParagraph<? extends TextRun>> extends S
* </p> * </p>
*/ */
SHAPE SHAPE
} }
/**
* @return the TextParagraphs for this text box
*/
List<? extends TextParagraph<S,P,? extends TextRun>> getTextParagraphs();
/** /**
* @return text shape margin * @return text shape margin
*/ */
Insets2D getInsets(); Insets2D getInsets();
/** /**
* Compute the cumulative height occupied by the text * Compute the cumulative height occupied by the text
*/ */
double getTextHeight(); double getTextHeight();
/** /**
* Returns the type of vertical alignment for the text. * Returns the type of vertical alignment for the text.
* *
* @return the type of vertical alignment * @return the type of vertical alignment
*/ */
VerticalAlignment getVerticalAlignment(); VerticalAlignment getVerticalAlignment();
/** /**
* Returns if the text is centered. * Returns if the text is centered.
* If true and if the individual paragraph settings allow it, * If true and if the individual paragraph settings allow it,
* the whole text block will be displayed centered, i.e. its left and right * the whole text block will be displayed centered, i.e. its left and right
* margin will be maximized while still keeping the alignment of the paragraphs * margin will be maximized while still keeping the alignment of the paragraphs
* *
* @return true, if the text anchor is horizontal centered * @return true, if the text anchor is horizontal centered
*/ */
boolean isHorizontalCentered(); boolean isHorizontalCentered();
/** /**
* @return whether to wrap words within the bounding rectangle * @return whether to wrap words within the bounding rectangle
*/ */
boolean getWordWrap(); boolean getWordWrap();
/** /**
* @return vertical orientation of the text * @return vertical orientation of the text
*/ */

View File

@ -68,7 +68,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument
* top level object for creating new slides/etc. * top level object for creating new slides/etc.
*/ */
@Beta @Beta
public class XMLSlideShow extends POIXMLDocument implements SlideShow { public class XMLSlideShow extends POIXMLDocument
implements SlideShow<XSLFShape,XSLFTextParagraph> {
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class); private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
private CTPresentation _presentation; private CTPresentation _presentation;
@ -512,7 +513,8 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
return null; return null;
} }
public MasterSheet<XSLFShape, XMLSlideShow> createMasterSheet() throws IOException { @Override
public MasterSheet<XSLFShape,XSLFTextParagraph> createMasterSheet() throws IOException {
// TODO: implement! // TODO: implement!
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -36,7 +36,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFAutoShape extends XSLFTextShape implements AutoShape<XSLFTextParagraph> { public class XSLFAutoShape extends XSLFTextShape
implements AutoShape<XSLFShape,XSLFTextParagraph> {
/*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) { /*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
super(shape, sheet); super(shape, sheet);

View File

@ -35,7 +35,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class XSLFBackground extends XSLFSimpleShape implements Background { public class XSLFBackground extends XSLFSimpleShape
implements Background<XSLFShape,XSLFTextParagraph> {
/* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) { /* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
super(shape, sheet); super(shape, sheet);

View File

@ -34,7 +34,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFConnectorShape extends XSLFSimpleShape implements ConnectorShape { public class XSLFConnectorShape extends XSLFSimpleShape
implements ConnectorShape<XSLFShape,XSLFTextParagraph> {
/*package*/ XSLFConnectorShape(CTConnector shape, XSLFSheet sheet) { /*package*/ XSLFConnectorShape(CTConnector shape, XSLFSheet sheet) {
super(shape, sheet); super(shape, sheet);

View File

@ -49,7 +49,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFFreeformShape extends XSLFAutoShape implements FreeformShape<XSLFTextParagraph> { public class XSLFFreeformShape extends XSLFAutoShape
implements FreeformShape<XSLFShape,XSLFTextParagraph> {
/*package*/ XSLFFreeformShape(CTShape shape, XSLFSheet sheet) { /*package*/ XSLFFreeformShape(CTShape shape, XSLFSheet sheet) {
super(shape, sheet); super(shape, sheet);

View File

@ -28,6 +28,7 @@ import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.usermodel.GroupShape; import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -49,7 +50,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, GroupShape<XSLFShape> { public class XSLFGroupShape extends XSLFShape
implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
private static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class); private static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class);
private final List<XSLFShape> _shapes; private final List<XSLFShape> _shapes;
@ -237,8 +239,12 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Gro
return sh; return sh;
} }
public XSLFPictureShape createPicture(XSLFPictureData pictureData){ public XSLFPictureShape createPicture(PictureData pictureData){
PackagePart pic = pictureData.getPackagePart(); if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
PackagePart pic = xPictureData.getPackagePart();
PackageRelationship rel = getSheet().getPackagePart().addRelationship( PackageRelationship rel = getSheet().getPackagePart().addRelationship(
pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation()); pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
@ -257,6 +263,24 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Gro
return sh; return sh;
} }
@Override
public XSLFTable createTable(int numRows, int numCols){
if (numRows < 1 || numCols < 1) {
throw new IllegalArgumentException("numRows and numCols must be greater than 0");
}
XSLFTable sh = getDrawing().createTable();
_shapes.add(sh);
sh.setParent(this);
for (int r=0; r<numRows; r++) {
XSLFTableRow row = sh.addRow();
for (int c=0; c<numCols; c++) {
row.addCell();
}
}
return sh;
}
@Override @Override
public void setFlipHorizontal(boolean flip){ public void setFlipHorizontal(boolean flip){
getSafeXfrm().setFlipH(flip); getSafeXfrm().setFlipH(flip);

View File

@ -31,7 +31,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument; import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
@Beta @Beta
public final class XSLFNotes extends XSLFSheet implements Notes<XSLFShape,XMLSlideShow> { public final class XSLFNotes extends XSLFSheet
implements Notes<XSLFShape,XSLFTextParagraph> {
private CTNotesSlide _notes; private CTNotesSlide _notes;
/** /**
@ -83,6 +84,7 @@ public final class XSLFNotes extends XSLFSheet implements Notes<XSLFShape,XMLSli
return getMasterSheet().getTheme(); return getMasterSheet().getTheme();
} }
@Override
public XSLFNotesMaster getMasterSheet() { public XSLFNotesMaster getMasterSheet() {
for (POIXMLDocumentPart p : getRelations()) { for (POIXMLDocumentPart p : getRelations()) {
if (p instanceof XSLFNotesMaster){ if (p instanceof XSLFNotesMaster){

View File

@ -47,7 +47,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFNotesMaster extends XSLFSheet implements MasterSheet<XSLFShape,XMLSlideShow> { public class XSLFNotesMaster extends XSLFSheet
implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTNotesMaster _slide; private CTNotesMaster _slide;
private XSLFTheme _theme; private XSLFTheme _theme;
@ -94,7 +95,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
} }
@Override @Override
public MasterSheet<XSLFShape,XMLSlideShow> getMasterSheet() { public MasterSheet<XSLFShape,XSLFTextParagraph> getMasterSheet() {
return null; return null;
} }

View File

@ -51,7 +51,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual;
* Represents a picture shape * Represents a picture shape
*/ */
@Beta @Beta
public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape { public class XSLFPictureShape extends XSLFSimpleShape
implements PictureShape<XSLFShape,XSLFTextParagraph> {
private XSLFPictureData _data; private XSLFPictureData _data;
/*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) { /*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {

View File

@ -65,7 +65,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public abstract class XSLFShape implements Shape { public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
private final XmlObject _shape; private final XmlObject _shape;
private final XSLFSheet _sheet; private final XSLFSheet _sheet;
private XSLFShapeContainer _parent; private XSLFShapeContainer _parent;
@ -130,8 +130,8 @@ public abstract class XSLFShape implements Shape {
} }
if (this instanceof PlaceableShape) { if (this instanceof PlaceableShape) {
PlaceableShape ps = (PlaceableShape)this; PlaceableShape<?,?> ps = (PlaceableShape<?,?>)this;
ps.setAnchor(((PlaceableShape)sh).getAnchor()); ps.setAnchor(((PlaceableShape<?,?>)sh).getAnchor());
} }

View File

@ -19,43 +19,32 @@
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
/** /**
* Common interface for shape containers, e.g. sheets or groups of shapes * Common interface for shape containers, e.g. sheets or groups of shapes
*/ */
public interface XSLFShapeContainer extends ShapeContainer<XSLFShape> { public interface XSLFShapeContainer
extends ShapeContainer<XSLFShape,XSLFTextParagraph> {
/** @Override
* create a new shape with a predefined geometry and add it to this shape container
*/
XSLFAutoShape createAutoShape(); XSLFAutoShape createAutoShape();
/** @Override
* create a new shape with a custom geometry
*/
XSLFFreeformShape createFreeform(); XSLFFreeformShape createFreeform();
/** @Override
* create a text box
*/
XSLFTextBox createTextBox(); XSLFTextBox createTextBox();
/** @Override
*
* create a connector
*/
XSLFConnectorShape createConnector(); XSLFConnectorShape createConnector();
/** @Override
* create a group of shapes belonging to this container
*/
XSLFGroupShape createGroup(); XSLFGroupShape createGroup();
/** @Override
* create a picture belonging to this container XSLFPictureShape createPicture(PictureData pictureData);
*/
XSLFPictureShape createPicture(XSLFPictureData pictureData);
/** /**
* Removes all of the elements from this container (optional operation). * Removes all of the elements from this container (optional operation).

View File

@ -37,6 +37,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
@ -53,7 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
@Beta @Beta
public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet<XSLFShape, XMLSlideShow> { public abstract class XSLFSheet extends POIXMLDocumentPart
implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
private XSLFCommonSlideData _commonSlideData; private XSLFCommonSlideData _commonSlideData;
private XSLFDrawing _drawing; private XSLFDrawing _drawing;
private List<XSLFShape> _shapes; private List<XSLFShape> _shapes;
@ -72,9 +74,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
} }
/** /**
*
* @return the XMLSlideShow this sheet belongs to * @return the XMLSlideShow this sheet belongs to
*/ */
@Override
public XMLSlideShow getSlideShow() { public XMLSlideShow getSlideShow() {
POIXMLDocumentPart p = getParent(); POIXMLDocumentPart p = getParent();
while(p != null) { while(p != null) {
@ -158,6 +160,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
// shape factory methods // shape factory methods
@Override
public XSLFAutoShape createAutoShape(){ public XSLFAutoShape createAutoShape(){
XSLFAutoShape sh = getDrawing().createAutoShape(); XSLFAutoShape sh = getDrawing().createAutoShape();
getShapes().add(sh); getShapes().add(sh);
@ -165,6 +168,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
@Override
public XSLFFreeformShape createFreeform(){ public XSLFFreeformShape createFreeform(){
XSLFFreeformShape sh = getDrawing().createFreeform(); XSLFFreeformShape sh = getDrawing().createFreeform();
getShapes().add(sh); getShapes().add(sh);
@ -172,6 +176,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
@Override
public XSLFTextBox createTextBox(){ public XSLFTextBox createTextBox(){
XSLFTextBox sh = getDrawing().createTextBox(); XSLFTextBox sh = getDrawing().createTextBox();
getShapes().add(sh); getShapes().add(sh);
@ -179,6 +184,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
@Override
public XSLFConnectorShape createConnector(){ public XSLFConnectorShape createConnector(){
XSLFConnectorShape sh = getDrawing().createConnector(); XSLFConnectorShape sh = getDrawing().createConnector();
getShapes().add(sh); getShapes().add(sh);
@ -186,6 +192,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
@Override
public XSLFGroupShape createGroup(){ public XSLFGroupShape createGroup(){
XSLFGroupShape sh = getDrawing().createGroup(); XSLFGroupShape sh = getDrawing().createGroup();
getShapes().add(sh); getShapes().add(sh);
@ -193,8 +200,13 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
public XSLFPictureShape createPicture(XSLFPictureData pictureData){ @Override
PackagePart pic = pictureData.getPackagePart(); public XSLFPictureShape createPicture(PictureData pictureData){
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
PackagePart pic = xPictureData.getPackagePart();
PackageRelationship rel = getPackagePart().addRelationship( PackageRelationship rel = getPackagePart().addRelationship(
pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation()); pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
@ -214,6 +226,24 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
return sh; return sh;
} }
@Override
public XSLFTable createTable(int numRows, int numCols){
if (numRows < 1 || numCols < 1) {
throw new IllegalArgumentException("numRows and numCols must be greater than 0");
}
XSLFTable sh = getDrawing().createTable();
getShapes().add(sh);
sh.setParent(this);
for (int r=0; r<numRows; r++) {
XSLFTableRow row = sh.addRow();
for (int c=0; c<numCols; c++) {
row.addCell();
}
}
return sh;
}
/** /**
* Returns an iterator over the shapes in this sheet * Returns an iterator over the shapes in this sheet
* *
@ -481,9 +511,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
} }
/** /**
*
* @return background for this sheet * @return background for this sheet
*/ */
@Override
public XSLFBackground getBackground() { public XSLFBackground getBackground() {
return null; return null;
} }

View File

@ -54,7 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { public abstract class XSLFSimpleShape extends XSLFShape
implements SimpleShape<XSLFShape,XSLFTextParagraph> {
private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance(); private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance();
/* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) { /* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) {

View File

@ -24,6 +24,7 @@ import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
@ -41,7 +42,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
@Beta @Beta
public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSlideShow, XSLFNotes> { public final class XSLFSlide extends XSLFSheet
implements Slide<XSLFShape,XSLFTextParagraph> {
private final CTSlide _slide; private final CTSlide _slide;
private XSLFSlideLayout _layout; private XSLFSlideLayout _layout;
private XSLFComments _comments; private XSLFComments _comments;
@ -254,11 +256,12 @@ public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSl
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void setNotes(XSLFNotes notes) { @Override
public void setNotes(Notes<XSLFShape,XSLFTextParagraph> notes) {
assert(notes instanceof XSLFNotes);
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public int getSlideNumber() { public int getSlideNumber() {
int idx = getSlideShow().getSlides().indexOf(this); int idx = getSlideShow().getSlides().indexOf(this);

View File

@ -31,7 +31,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideLayout;
import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument; import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument;
@Beta @Beta
public class XSLFSlideLayout extends XSLFSheet implements MasterSheet<XSLFShape, XMLSlideShow> { public class XSLFSlideLayout extends XSLFSheet
implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTSlideLayout _layout; private CTSlideLayout _layout;
private XSLFSlideMaster _master; private XSLFSlideMaster _master;

View File

@ -54,7 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFSlideMaster extends XSLFSheet implements MasterSheet<XSLFShape, XMLSlideShow> { public class XSLFSlideMaster extends XSLFSheet
implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTSlideMaster _slide; private CTSlideMaster _slide;
private Map<String, XSLFSlideLayout> _layouts; private Map<String, XSLFSlideLayout> _layouts;
private XSLFTheme _theme; private XSLFTheme _theme;
@ -83,7 +84,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument;
} }
@Override @Override
public MasterSheet<XSLFShape, XMLSlideShow> getMasterSheet() { public XSLFSlideMaster getMasterSheet() {
return null; return null;
} }

View File

@ -46,7 +46,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow>, TableShape { public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow>,
TableShape<XSLFShape,XSLFTextParagraph> {
static String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table"; static String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
private CTTable _table; private CTTable _table;

View File

@ -21,14 +21,29 @@ package org.apache.poi.xslf.usermodel;
import java.awt.Color; import java.awt.Color;
import org.apache.poi.sl.usermodel.TableCell;
import org.apache.poi.sl.usermodel.VerticalAlignment; import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment;
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
/** /**
* Represents a cell of a table in a .pptx presentation * Represents a cell of a table in a .pptx presentation
*/ */
public class XSLFTableCell extends XSLFTextShape { public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,XSLFTextParagraph> {
static double defaultBorderWidth = 1.0; static double defaultBorderWidth = 1.0;
private CTTableCellProperties _tcPr = null; private CTTableCellProperties _tcPr = null;

View File

@ -19,6 +19,7 @@
package org.apache.poi.xslf.usermodel; package org.apache.poi.xslf.usermodel;
import org.apache.poi.sl.usermodel.TextBox;
import org.apache.poi.util.Beta; import org.apache.poi.util.Beta;
import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
@ -29,7 +30,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
@Beta @Beta
public class XSLFTextBox extends XSLFAutoShape { public class XSLFTextBox extends XSLFAutoShape
implements TextBox<XSLFShape,XSLFTextParagraph> {
/*package*/ XSLFTextBox(CTShape shape, XSLFSheet sheet){ /*package*/ XSLFTextBox(CTShape shape, XSLFSheet sheet){
super(shape, sheet); super(shape, sheet);

View File

@ -44,7 +44,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
* @since POI-3.8 * @since POI-3.8
*/ */
@Beta @Beta
public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> { public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagraph,XSLFTextRun> {
private final CTTextParagraph _p; private final CTTextParagraph _p;
private final List<XSLFTextRun> _runs; private final List<XSLFTextRun> _runs;
private final XSLFTextShape _shape; private final XSLFTextShape _shape;

View File

@ -48,7 +48,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
* Represents a shape that can hold text. * Represents a shape that can hold text.
*/ */
@Beta @Beta
public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape<XSLFTextParagraph> { public abstract class XSLFTextShape extends XSLFSimpleShape
implements TextShape<XSLFShape,XSLFTextParagraph> {
private final List<XSLFTextParagraph> _paragraphs; private final List<XSLFTextParagraph> _paragraphs;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -96,10 +97,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
addNewTextParagraph().addNewTextRun().setText(text); addNewTextParagraph().addNewTextRun().setText(text);
} }
/** @Override
*
* @return text paragraphs in this shape
*/
public List<XSLFTextParagraph> getTextParagraphs() { public List<XSLFTextParagraph> getTextParagraphs() {
return _paragraphs; return _paragraphs;
} }
@ -459,7 +457,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
@Override @Override
public double getTextHeight(){ public double getTextHeight(){
DrawFactory drawFact = DrawFactory.getInstance(null); DrawFactory drawFact = DrawFactory.getInstance(null);
DrawTextShape<XSLFTextShape> dts = drawFact.getDrawable(this); DrawTextShape dts = drawFact.getDrawable(this);
return dts.getTextHeight(); return dts.getTextHeight();
} }

View File

@ -116,8 +116,8 @@ public class PPTX2PNG {
if (!quite) { if (!quite) {
System.out.println("Processing " + file); System.out.println("Processing " + file);
} }
SlideShow ss = SlideShowFactory.create(file, null, true); SlideShow<?,?> ss = SlideShowFactory.create(file, null, true);
List<? extends Slide<?,?,?>> slides = ss.getSlides(); List<? extends Slide<?,?>> slides = ss.getSlides();
if (slidenum < -1 || slidenum == 0 || slidenum > slides.size()) { if (slidenum < -1 || slidenum == 0 || slidenum > slides.size()) {
@ -130,7 +130,7 @@ public class PPTX2PNG {
int height = (int) (pgsize.height * scale); int height = (int) (pgsize.height * scale);
int slideNo=1; int slideNo=1;
for(Slide<?,?,?> slide : slides) { for(Slide<?,?> slide : slides) {
if (slidenum == -1 || slideNo == slidenum) { if (slidenum == -1 || slideNo == slidenum) {
String title = slide.getTitle(); String title = slide.getTitle();
if (!quite) { if (!quite) {

View File

@ -44,7 +44,7 @@ import org.junit.Test;
public class TestXSLFTextParagraph { public class TestXSLFTextParagraph {
// private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class); // private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class);
static class DrawTextParagraphProxy extends DrawTextParagraph<XSLFTextRun> { static class DrawTextParagraphProxy extends DrawTextParagraph {
DrawTextParagraphProxy(XSLFTextParagraph p) { DrawTextParagraphProxy(XSLFTextParagraph p) {
super(p); super(p);
} }

View File

@ -20,10 +20,10 @@ package org.apache.poi.hslf.model;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.Iterator; import java.util.Iterator;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherClientDataRecord; import org.apache.poi.ddf.EscherClientDataRecord;
import org.apache.poi.ddf.EscherComplexProperty; import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.ddf.EscherSpRecord;
@ -34,7 +34,11 @@ import org.apache.poi.hslf.record.ExObjList;
import org.apache.poi.hslf.record.OEShapeAtom; import org.apache.poi.hslf.record.OEShapeAtom;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.usermodel.*; import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSheet;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -66,7 +70,7 @@ public final class ActiveXShape extends HSLFPictureShape {
* this picture in the <code>Slide</code> * this picture in the <code>Slide</code>
* @param parent the parent shape of this picture * @param parent the parent shape of this picture
*/ */
protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -172,7 +176,7 @@ public final class ActiveXShape extends HSLFPictureShape {
String name = ctrl.getProgId() + "-" + getControlIndex() + '\u0000'; String name = ctrl.getProgId() + "-" + getControlIndex() + '\u0000';
byte[] data = StringUtil.getToUnicodeLE(name); byte[] data = StringUtil.getToUnicodeLE(name);
EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(prop); opt.addEscherProperty(prop);
} }
} }

View File

@ -55,7 +55,7 @@ public final class MovieShape extends HSLFPictureShape {
* @param pictureData the picture data * @param pictureData the picture data
* @param parent the parent shape * @param parent the parent shape
*/ */
public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer<HSLFShape> parent) { public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(pictureData, parent); super(pictureData, parent);
setMovieIndex(movieIdx); setMovieIndex(movieIdx);
} }
@ -67,7 +67,7 @@ public final class MovieShape extends HSLFPictureShape {
* this picture in the <code>Slide</code> * this picture in the <code>Slide</code>
* @param parent the parent shape of this picture * @param parent the parent shape of this picture
*/ */
public MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ public MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }

View File

@ -51,7 +51,7 @@ public final class OLEShape extends HSLFPictureShape {
* @param data the picture data * @param data the picture data
* @param parent the parent shape * @param parent the parent shape
*/ */
public OLEShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) { public OLEShape(HSLFPictureData data, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(data, parent); super(data, parent);
} }
@ -62,7 +62,7 @@ public final class OLEShape extends HSLFPictureShape {
* this picture in the <code>Slide</code> * this picture in the <code>Slide</code>
* @param parent the parent shape of this picture * @param parent the parent shape of this picture
*/ */
public OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ public OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }

View File

@ -21,6 +21,7 @@ import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.OEPlaceholderAtom; import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.usermodel.HSLFShape; import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFTextBox; import org.apache.poi.hslf.usermodel.HSLFTextBox;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
@ -33,11 +34,11 @@ import java.io.ByteArrayOutputStream;
*/ */
public final class Placeholder extends HSLFTextBox { public final class Placeholder extends HSLFTextBox {
protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
public Placeholder(ShapeContainer<HSLFShape> parent){ public Placeholder(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent); super(parent);
} }
@ -59,7 +60,7 @@ public final class Placeholder extends HSLFTextBox {
EscherClientDataRecord cldata = new EscherClientDataRecord(); EscherClientDataRecord cldata = new EscherClientDataRecord();
cldata.setOptions((short)15); cldata.setOptions((short)15);
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
//Placeholders can't be grouped //Placeholders can't be grouped
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144); setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);

View File

@ -38,7 +38,7 @@ public final class Polygon extends HSLFAutoShape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected Polygon(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected Polygon(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -49,7 +49,7 @@ public final class Polygon extends HSLFAutoShape {
* @param parent the parent of this Shape. For example, if this text box is a cell * @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table. * in a table then the parent is Table.
*/ */
public Polygon(ShapeContainer<HSLFShape> parent){ public Polygon(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super((EscherContainerRecord)null, parent); super((EscherContainerRecord)null, parent);
_escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape);
} }
@ -75,7 +75,7 @@ public final class Polygon extends HSLFAutoShape {
float left = findSmallest(xPoints); float left = findSmallest(xPoints);
float top = findSmallest(yPoints); float top = findSmallest(yPoints);
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(right - left))); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(right - left)));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bottom - top))); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bottom - top)));

View File

@ -31,13 +31,13 @@ import org.apache.poi.ss.usermodel.ShapeTypes;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFTextParagraph> { public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape,HSLFTextParagraph> {
protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
public HSLFAutoShape(ShapeType type, ShapeContainer<HSLFShape> parent){ public HSLFAutoShape(ShapeType type, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent); super(null, parent);
_escherContainer = createSpContainer(type, parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(type, parent instanceof HSLFGroupShape);
} }

View File

@ -26,9 +26,9 @@ import org.apache.poi.sl.usermodel.ShapeContainer;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFBackground extends HSLFShape implements Background { public final class HSLFBackground extends HSLFShape implements Background<HSLFShape,HSLFTextParagraph> {
protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent) { protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(escherRecord, parent); super(escherRecord, parent);
} }

View File

@ -0,0 +1,65 @@
/*
* ====================================================================
* 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.ddf.EscherContainerRecord;
import org.apache.poi.sl.usermodel.ConnectorShape;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.util.Beta;
/**
* Specifies a connection shape.
*
* This is currently only a dummy implementation.
*/
@Beta
public class HSLFConnectorShape extends HSLFSimpleShape
implements ConnectorShape<HSLFShape,HSLFTextParagraph> {
/**
* Create a ConnectorShape object and initialize it from the supplied Record container.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
protected HSLFConnectorShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
/**
* Create a new ConnectorShape. This constructor is used when a new shape is created.
*
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
public HSLFConnectorShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
}
/**
* Create a new ConnectorShape. This constructor is used when a new shape is created.
*
*/
public HSLFConnectorShape(){
this(null);
}
}

View File

@ -22,9 +22,9 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
@ -155,7 +155,7 @@ public final class HSLFFill {
* @return type of fill * @return type of fill
*/ */
public int getFillType(){ public int getFillType(){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE); EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE);
return prop == null ? FILL_SOLID : prop.getPropertyValue(); return prop == null ? FILL_SOLID : prop.getPropertyValue();
} }
@ -163,7 +163,7 @@ public final class HSLFFill {
/** /**
*/ */
protected void afterInsert(HSLFSheet sh){ protected void afterInsert(HSLFSheet sh){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if(p != null) { if(p != null) {
int idx = p.getPropertyValue(); int idx = p.getPropertyValue();
@ -197,7 +197,7 @@ public final class HSLFFill {
* @param type type of the fill * @param type type of the fill
*/ */
public void setFillType(int type){ public void setFillType(int type){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLTYPE, type); HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLTYPE, type);
} }
@ -205,7 +205,7 @@ public final class HSLFFill {
* Foreground color * Foreground color
*/ */
public Color getForegroundColor(){ public Color getForegroundColor(){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
if(p != null && (p.getPropertyValue() & 0x10) == 0) return null; if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
@ -218,7 +218,7 @@ public final class HSLFFill {
* Foreground color * Foreground color
*/ */
public void setForegroundColor(Color color){ public void setForegroundColor(Color color){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
if (color == null) { if (color == null) {
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000); HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000);
} }
@ -233,7 +233,7 @@ public final class HSLFFill {
* Background color * Background color
*/ */
public Color getBackgroundColor(){ public Color getBackgroundColor(){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
if(p != null && (p.getPropertyValue() & 0x10) == 0) return null; if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
@ -245,7 +245,7 @@ public final class HSLFFill {
* Background color * Background color
*/ */
public void setBackgroundColor(Color color){ public void setBackgroundColor(Color color){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
if (color == null) { if (color == null) {
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1); HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1);
} }
@ -259,7 +259,7 @@ public final class HSLFFill {
* <code>PictureData</code> object used in a texture, pattern of picture fill. * <code>PictureData</code> object used in a texture, pattern of picture fill.
*/ */
public HSLFPictureData getPictureData(){ public HSLFPictureData getPictureData(){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if (p == null) return null; if (p == null) return null;
@ -292,7 +292,7 @@ public final class HSLFFill {
* @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method. * @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method.
*/ */
public void setPictureData(HSLFPictureData data){ public void setPictureData(HSLFPictureData data){
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), (data == null ? 0 : data.getIndex())); HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), (data == null ? 0 : data.getIndex()));
if(data != null && shape.getSheet() != null) { if(data != null && shape.getSheet() != null) {
EscherBSERecord bse = getEscherBSERecord(data.getIndex()); EscherBSERecord bse = getEscherBSERecord(data.getIndex());

View File

@ -26,9 +26,9 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.FreeformShape;
@ -47,7 +47,7 @@ import org.apache.poi.util.Units;
* </p> * </p>
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFTextParagraph> { public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFShape,HSLFTextParagraph> {
public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40}; public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40};
public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC}; public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC};
@ -64,7 +64,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -75,7 +75,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
* @param parent the parent of this Shape. For example, if this text box is a cell * @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table. * in a table then the parent is Table.
*/ */
public HSLFFreeformShape(ShapeContainer<HSLFShape> parent){ public HSLFFreeformShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super((EscherContainerRecord)null, parent); super((EscherContainerRecord)null, parent);
_escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape);
} }
@ -140,7 +140,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
if(!isClosed) segInfo.add(SEGMENTINFO_LINETO); if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(new byte[]{0x00, (byte)0x80}); segInfo.add(new byte[]{0x00, (byte)0x80});
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null); EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
@ -178,7 +178,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
@Override @Override
public GeneralPath getPath(){ public GeneralPath getPath(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4)); opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000)); EscherArrayProperty verticesProp = getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000));

View File

@ -17,11 +17,22 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.*; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.ddf.EscherSpgrRecord;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
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.LittleEndian;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
@ -31,7 +42,8 @@ import org.apache.poi.util.Units;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class HSLFGroupShape extends HSLFShape implements GroupShape<HSLFShape> { public class HSLFGroupShape extends HSLFShape
implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
/** /**
* Create a new ShapeGroup. This constructor is used when a new shape is created. * Create a new ShapeGroup. This constructor is used when a new shape is created.
@ -43,12 +55,22 @@ public class HSLFGroupShape extends HSLFShape implements GroupShape<HSLFShape> {
} }
/** /**
* Create a ShapeGroup object and initilize it from the supplied Record container. * Create a new ShapeGroup. This constructor is used when a new shape is created.
*
* @param parent the parent of the shape
*/
public HSLFGroupShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
this(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
}
/**
* Create a ShapeGroup object and initialize it from the supplied Record container.
* *
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -273,4 +295,68 @@ public class HSLFGroupShape extends HSLFShape implements GroupShape<HSLFShape> {
return shapeList; return shapeList;
} }
@Override
public HSLFTextBox createTextBox() {
HSLFTextBox s = new HSLFTextBox(this);
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFAutoShape createAutoShape() {
HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT, this);
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFFreeformShape createFreeform() {
HSLFFreeformShape s = new HSLFFreeformShape(this);
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFConnectorShape createConnector() {
HSLFConnectorShape s = new HSLFConnectorShape(this);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFGroupShape createGroup() {
HSLFGroupShape s = new HSLFGroupShape(this);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFPictureShape createPicture(PictureData pictureData) {
if (!(pictureData instanceof HSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
}
HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData, this);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFTable createTable(int numRows, int numCols) {
if (numRows < 1 || numCols < 1) {
throw new IllegalArgumentException("numRows and numCols must be greater than 0");
}
HSLFTable s = new HSLFTable(numRows,numCols,this);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
} }

View File

@ -17,8 +17,8 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.sl.usermodel.Line; import org.apache.poi.sl.usermodel.Line;
@ -30,12 +30,12 @@ import org.apache.poi.sl.usermodel.ShapeType;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFLine extends HSLFTextShape implements Line<HSLFTextParagraph> { public final class HSLFLine extends HSLFTextShape implements Line<HSLFShape,HSLFTextParagraph> {
public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
public HSLFLine(ShapeContainer<HSLFShape> parent){ public HSLFLine(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent); super(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
} }
@ -54,7 +54,7 @@ public final class HSLFLine extends HSLFTextShape implements Line<HSLFTextParagr
spRecord.setOptions(type); spRecord.setOptions(type);
//set default properties for a line //set default properties for a line
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
//default line properties //default line properties
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4); setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);

View File

@ -28,7 +28,7 @@ import org.apache.poi.sl.usermodel.MasterSheet;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class HSLFMasterSheet extends HSLFSheet implements MasterSheet<HSLFShape,HSLFSlideShow> { public abstract class HSLFMasterSheet extends HSLFSheet implements MasterSheet<HSLFShape,HSLFTextParagraph> {
public HSLFMasterSheet(SheetContainer container, int sheetNo){ public HSLFMasterSheet(SheetContainer container, int sheetNo){
super(container, sheetNo); super(container, sheetNo);
} }

View File

@ -32,7 +32,7 @@ import org.apache.poi.util.POILogger;
* @author Nick Burch * @author Nick Burch
*/ */
public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape, HSLFSlideShow> { public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape,HSLFTextParagraph> {
protected static final POILogger logger = POILogFactory.getLogger(HSLFNotes.class); protected static final POILogger logger = POILogFactory.getLogger(HSLFNotes.class);
private List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>(); private List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>();

View File

@ -26,10 +26,10 @@ import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherComplexProperty; import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
@ -49,7 +49,7 @@ import org.apache.poi.util.Units;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HSLFShape,HSLFTextParagraph> {
/** /**
* Create a new <code>Picture</code> * Create a new <code>Picture</code>
@ -66,7 +66,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
* @param data the picture data * @param data the picture data
* @param parent the parent shape * @param parent the parent shape
*/ */
public HSLFPictureShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) { public HSLFPictureShape(HSLFPictureData data, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(null, parent); super(null, parent);
_escherContainer = createSpContainer(data.getIndex(), parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(data.getIndex(), parent instanceof HSLFGroupShape);
} }
@ -78,7 +78,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
* this picture in the <code>Slide</code> * this picture in the <code>Slide</code>
* @param parent the parent shape of this picture * @param parent the parent shape of this picture
*/ */
protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -90,7 +90,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
* @return the index to this picture (1 based). * @return the index to this picture (1 based).
*/ */
public int getPictureIndex(){ public int getPictureIndex(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY);
return prop == null ? 0 : prop.getPropertyValue(); return prop == null ? 0 : prop.getPropertyValue();
} }
@ -109,7 +109,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
spRecord.setOptions((short)((ShapeType.FRAME.nativeId << 4) | 0x2)); spRecord.setOptions((short)((ShapeType.FRAME.nativeId << 4) | 0x2));
//set default properties for a picture //set default properties for a picture
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080); setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
//another weird feature of powerpoint: for picture id we must add 0x4000. //another weird feature of powerpoint: for picture id we must add 0x4000.
@ -189,7 +189,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
* @return name of this picture * @return name of this picture
*/ */
public String getPictureName(){ public String getPictureName(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherComplexProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPFILENAME); EscherComplexProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPFILENAME);
if (prop == null) return null; if (prop == null) return null;
String name = StringUtil.getFromUnicodeLE(prop.getComplexData()); String name = StringUtil.getFromUnicodeLE(prop.getComplexData());
@ -202,7 +202,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
* @param name of this picture * @param name of this picture
*/ */
public void setPictureName(String name){ public void setPictureName(String name){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
byte[] data = StringUtil.getToUnicodeLE(name + '\u0000'); byte[] data = StringUtil.getToUnicodeLE(name + '\u0000');
EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, false, data); EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, false, data);
opt.addEscherProperty(prop); opt.addEscherProperty(prop);
@ -228,7 +228,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
public Insets getClipping() { public Insets getClipping() {
// The anchor specified by the escher properties is the displayed size, // The anchor specified by the escher properties is the displayed size,
// i.e. the size of the already clipped image // i.e. the size of the already clipped image
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
double top = getFractProp(opt, EscherProperties.BLIP__CROPFROMTOP); double top = getFractProp(opt, EscherProperties.BLIP__CROPFROMTOP);
double bottom = getFractProp(opt, EscherProperties.BLIP__CROPFROMBOTTOM); double bottom = getFractProp(opt, EscherProperties.BLIP__CROPFROMBOTTOM);
@ -244,7 +244,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
/** /**
* @return the fractional property or 0 if not defined * @return the fractional property or 0 if not defined
*/ */
private static double getFractProp(EscherOptRecord opt, short propertyId) { private static double getFractProp(AbstractEscherOptRecord opt, short propertyId) {
EscherSimpleProperty prop = getEscherProperty(opt, propertyId); EscherSimpleProperty prop = getEscherProperty(opt, propertyId);
if (prop == null) return 0; if (prop == null) return 0;
int fixedPoint = prop.getPropertyValue(); int fixedPoint = prop.getPropertyValue();

View File

@ -44,7 +44,7 @@ import org.apache.poi.util.*;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class HSLFShape implements Shape { public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
// For logging // For logging
protected POILogger logger = POILogFactory.getLogger(this.getClass()); protected POILogger logger = POILogFactory.getLogger(this.getClass());
@ -59,7 +59,7 @@ public abstract class HSLFShape implements Shape {
* Parent of this shape. * Parent of this shape.
* <code>null</code> for the topmost shapes. * <code>null</code> for the topmost shapes.
*/ */
protected ShapeContainer<HSLFShape> _parent; protected ShapeContainer<HSLFShape,HSLFTextParagraph> _parent;
/** /**
* The <code>Sheet</code> this shape belongs to * The <code>Sheet</code> this shape belongs to
@ -77,7 +77,7 @@ public abstract class HSLFShape implements Shape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of this Shape * @param parent the parent of this Shape
*/ */
protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
_escherContainer = escherRecord; _escherContainer = escherRecord;
_parent = parent; _parent = parent;
} }
@ -90,7 +90,7 @@ public abstract class HSLFShape implements Shape {
/** /**
* @return the parent of this shape * @return the parent of this shape
*/ */
public ShapeContainer<HSLFShape> getParent(){ public ShapeContainer<HSLFShape,HSLFTextParagraph> getParent(){
return _parent; return _parent;
} }
@ -229,7 +229,7 @@ public abstract class HSLFShape implements Shape {
* *
* @return escher property or <code>null</code> if not found. * @return escher property or <code>null</code> if not found.
*/ */
public static <T extends EscherProperty> T getEscherProperty(EscherOptRecord opt, int propId){ public static <T extends EscherProperty> T getEscherProperty(AbstractEscherOptRecord opt, int propId){
if (opt == null) return null; if (opt == null) return null;
return opt.lookup(propId); return opt.lookup(propId);
} }
@ -241,7 +241,7 @@ public abstract class HSLFShape implements Shape {
* @param propId The id of the property. One of the constants defined in EscherOptRecord. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
* @param value value of the property. If value = -1 then the property is removed. * @param value value of the property. If value = -1 then the property is removed.
*/ */
public static void setEscherProperty(EscherOptRecord opt, short propId, int value){ public static void setEscherProperty(AbstractEscherOptRecord opt, short propId, int value){
java.util.List<EscherProperty> props = opt.getEscherProperties(); java.util.List<EscherProperty> props = opt.getEscherProperties();
for ( Iterator<EscherProperty> iterator = props.iterator(); iterator.hasNext(); ) { for ( Iterator<EscherProperty> iterator = props.iterator(); iterator.hasNext(); ) {
if (iterator.next().getPropertyNumber() == propId){ if (iterator.next().getPropertyNumber() == propId){
@ -262,7 +262,7 @@ public abstract class HSLFShape implements Shape {
* @param value value of the property. If value = -1 then the property is removed. * @param value value of the property. If value = -1 then the property is removed.
*/ */
public void setEscherProperty(short propId, int value){ public void setEscherProperty(short propId, int value){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, propId, value); setEscherProperty(opt, propId, value);
} }
@ -272,7 +272,7 @@ public abstract class HSLFShape implements Shape {
* @param propId The id of the property. One of the constants defined in EscherOptRecord. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
*/ */
public int getEscherProperty(short propId){ public int getEscherProperty(short propId){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId); EscherSimpleProperty prop = getEscherProperty(opt, propId);
return prop == null ? 0 : prop.getPropertyValue(); return prop == null ? 0 : prop.getPropertyValue();
} }
@ -283,7 +283,7 @@ public abstract class HSLFShape implements Shape {
* @param propId The id of the property. One of the constants defined in EscherOptRecord. * @param propId The id of the property. One of the constants defined in EscherOptRecord.
*/ */
public int getEscherProperty(short propId, int defaultValue){ public int getEscherProperty(short propId, int defaultValue){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId); EscherSimpleProperty prop = getEscherProperty(opt, propId);
return prop == null ? defaultValue : prop.getPropertyValue(); return prop == null ? defaultValue : prop.getPropertyValue();
} }
@ -327,7 +327,7 @@ public abstract class HSLFShape implements Shape {
} }
Color getColor(short colorProperty, short opacityProperty, int defaultColor){ Color getColor(short colorProperty, short opacityProperty, int defaultColor){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, colorProperty); EscherSimpleProperty p = getEscherProperty(opt, colorProperty);
if(p == null && defaultColor == -1) return null; if(p == null && defaultColor == -1) return null;
@ -367,7 +367,7 @@ public abstract class HSLFShape implements Shape {
} }
double getAlpha(short opacityProperty) { double getAlpha(short opacityProperty) {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty op = getEscherProperty(opt, opacityProperty); EscherSimpleProperty op = getEscherProperty(opt, opacityProperty);
int defaultOpacity = 0x00010000; int defaultOpacity = 0x00010000;
int opacity = (op == null) ? defaultOpacity : op.getPropertyValue(); int opacity = (op == null) ? defaultOpacity : op.getPropertyValue();
@ -444,8 +444,8 @@ public abstract class HSLFShape implements Shape {
logger.log(POILogger.INFO, "Rendering " + getShapeName()); logger.log(POILogger.INFO, "Rendering " + getShapeName());
} }
public EscherOptRecord getEscherOptRecord() { public AbstractEscherOptRecord getEscherOptRecord() {
EscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID); AbstractEscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID);
if (opt == null) { if (opt == null) {
opt = getEscherChild(RecordTypes.EscherUserDefined); opt = getEscherChild(RecordTypes.EscherUserDefined);
} }

View File

@ -0,0 +1,49 @@
/*
* ====================================================================
* 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.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.ShapeContainer;
/**
* Common interface for shape containers, e.g. sheets or groups of shapes
*/
public interface HSLFShapeContainer extends ShapeContainer<HSLFShape,HSLFTextParagraph> {
@Override
HSLFAutoShape createAutoShape();
@Override
HSLFFreeformShape createFreeform();
@Override
HSLFTextBox createTextBox();
@Override
HSLFConnectorShape createConnector();
@Override
HSLFGroupShape createGroup();
@Override
HSLFPictureShape createPicture(PictureData pictureData);
}

View File

@ -40,38 +40,39 @@ public final class HSLFShapeFactory {
/** /**
* Create a new shape from the data provided. * Create a new shape from the data provided.
*/ */
public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){ public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){ if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
return createShapeGroup(spContainer, parent); return createShapeGroup(spContainer, parent);
} }
return createSimpleShape(spContainer, parent); return createSimpleShape(spContainer, parent);
} }
public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){ public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
HSLFGroupShape group = null; boolean isTable = false;
EscherRecord opt = HSLFShape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122); EscherContainerRecord ecr = (EscherContainerRecord)spContainer.getChild(0);
if(opt != null){ EscherRecord opt = HSLFShape.getEscherChild(ecr, (short)RecordTypes.EscherUserDefined);
try {
EscherPropertyFactory f = new EscherPropertyFactory();
List<EscherProperty> props = f.createProperties( opt.serialize(), 8, opt.getInstance() );
EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() == 1){
group = new HSLFTable(spContainer, parent);
} else {
group = new HSLFGroupShape(spContainer, parent);
}
} catch (Exception e){
logger.log(POILogger.WARN, e.getMessage());
group = new HSLFGroupShape(spContainer, parent);
}
} else {
group = new HSLFGroupShape(spContainer, parent);
}
if (opt != null) {
EscherPropertyFactory f = new EscherPropertyFactory();
List<EscherProperty> props = f.createProperties( opt.serialize(), 8, opt.getInstance() );
for (EscherProperty ep : props) {
if (ep.getPropertyNumber() == 0x39F
&& ep instanceof EscherSimpleProperty
&& ((EscherSimpleProperty)ep).getPropertyValue() == 1) {
isTable = true;
break;
}
}
}
HSLFGroupShape group = (isTable)
? new HSLFTable(spContainer, parent)
: new HSLFGroupShape(spContainer, parent);
return group; return group;
} }
public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){ public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
HSLFShape shape = null; HSLFShape shape = null;
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID); EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
@ -106,7 +107,7 @@ public final class HSLFShapeFactory {
shape = new HSLFLine(spContainer, parent); shape = new HSLFLine(spContainer, parent);
break; break;
case NOT_PRIMITIVE: { case NOT_PRIMITIVE: {
EscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID); AbstractEscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
EscherProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES); EscherProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
if(prop != null) if(prop != null)
shape = new HSLFFreeformShape(spContainer, parent); shape = new HSLFFreeformShape(spContainer, parent);

View File

@ -18,15 +18,28 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.util.*; import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.hslf.record.*; import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hslf.record.CString;
import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.record.PPDrawing;
import org.apache.poi.hslf.record.RecordContainer;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
import org.apache.poi.hslf.record.SheetContainer;
import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* This class defines the common format of "Sheets" in a powerpoint * This class defines the common format of "Sheets" in a powerpoint
@ -36,9 +49,7 @@ import org.apache.poi.util.POILogger;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> { public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,HSLFTextParagraph> {
private static POILogger logger = POILogFactory.getLogger(HSLFSheet.class);
/** /**
* The <code>SlideShow</code> we belong to * The <code>SlideShow</code> we belong to
*/ */
@ -387,4 +398,68 @@ public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
} }
@Override
public HSLFTextBox createTextBox() {
HSLFTextBox s = new HSLFTextBox();
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFAutoShape createAutoShape() {
HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT);
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFFreeformShape createFreeform() {
HSLFFreeformShape s = new HSLFFreeformShape();
s.setHorizontalCentered(true);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFConnectorShape createConnector() {
HSLFConnectorShape s = new HSLFConnectorShape();
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFGroupShape createGroup() {
HSLFGroupShape s = new HSLFGroupShape();
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFPictureShape createPicture(PictureData pictureData) {
if (!(pictureData instanceof HSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
}
HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
@Override
public HSLFTable createTable(int numRows, int numCols) {
if (numRows < 1 || numCols < 1) {
throw new IllegalArgumentException("numRows and numCols must be greater than 0");
}
HSLFTable s = new HSLFTable(numRows,numCols);
s.setAnchor(new Rectangle(0, 0, 100, 100));
addShape(s);
return s;
}
} }

View File

@ -39,7 +39,7 @@ import org.apache.poi.util.Units;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> {
public final static double DEFAULT_LINE_WIDTH = 0.75; public final static double DEFAULT_LINE_WIDTH = 0.75;
@ -55,7 +55,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -76,7 +76,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
sp.setFlags(flags); sp.setFlags(flags);
_escherContainer.addChildRecord(sp); _escherContainer.addChildRecord(sp);
EscherOptRecord opt = new EscherOptRecord(); AbstractEscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID); opt.setRecordId(EscherOptRecord.RECORD_ID);
_escherContainer.addChildRecord(opt); _escherContainer.addChildRecord(opt);
@ -102,7 +102,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* Returns width of the line in in points * Returns width of the line in in points
*/ */
public double getLineWidth(){ public double getLineWidth(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
double width = (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue()); double width = (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
return width; return width;
@ -113,7 +113,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @param width the width of line in in points * @param width the width of line in in points
*/ */
public void setLineWidth(double width){ public void setLineWidth(double width){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width)); setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
} }
@ -123,7 +123,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @param color new color of the line * @param color new color of the line
*/ */
public void setLineColor(Color color){ public void setLineColor(Color color){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
if (color == null) { if (color == null) {
setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000); setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
} else { } else {
@ -137,7 +137,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @return color of the line. If color is not set returns <code>java.awt.Color.black</code> * @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
*/ */
public Color getLineColor(){ public Color getLineColor(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH); EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) return null; if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
@ -152,7 +152,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @return dashing of the line. * @return dashing of the line.
*/ */
public LineDash getLineDashing(){ public LineDash getLineDashing(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue()); return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
} }
@ -163,7 +163,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @param pen new style of the line. * @param pen new style of the line.
*/ */
public void setLineDashing(LineDash pen){ public void setLineDashing(LineDash pen){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId); setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
} }
@ -173,7 +173,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @return the compound style of the line. * @return the compound style of the line.
*/ */
public LineCompound getLineCompound() { public LineCompound getLineCompound() {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue()); return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
} }
@ -184,7 +184,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
* @param style new compound style of the line. * @param style new compound style of the line.
*/ */
public void setLineCompound(LineCompound style){ public void setLineCompound(LineCompound style){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId); setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
} }
@ -389,7 +389,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
public double getShadowAngle() { public double getShadowAngle() {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue(); int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY); prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
@ -398,7 +398,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
} }
public double getShadowDistance() { public double getShadowDistance() {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue(); int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY); prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
@ -415,12 +415,12 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
} }
public Shadow getShadow() { public Shadow getShadow() {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE); EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE);
if (shadowType == null) return null; if (shadowType == null) return null;
return new Shadow(){ return new Shadow(){
public SimpleShape getShadowParent() { public SimpleShape<HSLFShape,HSLFTextParagraph> getShadowParent() {
return HSLFSimpleShape.this; return HSLFSimpleShape.this;
} }

View File

@ -21,12 +21,28 @@ import java.awt.Graphics2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.*; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.hslf.model.*; import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.hslf.record.*; import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.model.Comment;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.model.Placeholder;
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.SlideListWithText.SlideAtomsSet;
import org.apache.poi.hslf.record.StyleTextProp9Atom;
import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable; import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.sl.usermodel.Slide;
@ -39,7 +55,7 @@ import org.apache.poi.sl.usermodel.Slide;
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSlideShow,HSLFNotes> { public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTextParagraph> {
private int _slideNo; private int _slideNo;
private SlideAtomsSet _atomSet; private SlideAtomsSet _atomSet;
private final List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>(); private final List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>();
@ -110,8 +126,11 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
* references in the records to point to the new ID * references in the records to point to the new ID
*/ */
@Override @Override
public void setNotes(HSLFNotes notes) { public void setNotes(Notes<HSLFShape,HSLFTextParagraph> notes) {
_notes = notes; if (notes != null && !(notes instanceof HSLFNotes)) {
throw new IllegalArgumentException("notes needs to be of type HSLFNotes");
}
_notes = (HSLFNotes)notes;
// Update the Slide Atom's ID of where to point to // Update the Slide Atom's ID of where to point to
SlideAtom sa = getSlideRecord().getSlideAtom(); SlideAtom sa = getSlideRecord().getSlideAtom();

View File

@ -48,7 +48,6 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.Resources; import org.apache.poi.sl.usermodel.Resources;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -63,7 +62,7 @@ import org.apache.poi.util.Units;
* @author Nick Burch * @author Nick Burch
* @author Yegor kozlov * @author Yegor kozlov
*/ */
public final class HSLFSlideShow implements SlideShow { public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph> {
// What we're based on // What we're based on
private HSLFSlideShowImpl _hslfSlideShow; private HSLFSlideShowImpl _hslfSlideShow;
@ -671,6 +670,7 @@ public final class HSLFSlideShow implements SlideShow {
* *
* @return the created <code>Slide</code> * @return the created <code>Slide</code>
*/ */
@Override
public HSLFSlide createSlide() { public HSLFSlide createSlide() {
SlideListWithText slist = null; SlideListWithText slist = null;
@ -1131,8 +1131,7 @@ public final class HSLFSlideShow implements SlideShow {
return psrId; return psrId;
} }
public MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet() public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException {
throws IOException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -24,6 +24,7 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord; import org.apache.poi.ddf.EscherOptRecord;
@ -31,6 +32,7 @@ import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.ddf.EscherTextboxRecord; import org.apache.poi.ddf.EscherTextboxRecord;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.TableShape; import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -41,7 +43,8 @@ import org.apache.poi.util.Units;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFTable extends HSLFGroupShape implements TableShape { public final class HSLFTable extends HSLFGroupShape
implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
protected static final int BORDER_TOP = 1; protected static final int BORDER_TOP = 1;
protected static final int BORDER_RIGHT = 2; protected static final int BORDER_RIGHT = 2;
@ -59,17 +62,28 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape {
/** /**
* Create a new Table of the given number of rows and columns * Create a new Table of the given number of rows and columns
* *
* @param numrows the number of rows * @param numRows the number of rows
* @param numcols the number of columns * @param numCols the number of columns
*/ */
public HSLFTable(int numrows, int numcols) { public HSLFTable(int numRows, int numCols) {
super(); this(numRows, numCols, null);
}
/**
* Create a new Table of the given number of rows and columns
*
* @param numRows the number of rows
* @param numCols the number of columns
* @param parent the parent shape, or null if table is added to sheet
*/
public HSLFTable(int numRows, int numCols, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(parent);
if(numrows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1"); if(numRows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");
if(numcols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1"); if(numCols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");
int x=0, y=0, tblWidth=0, tblHeight=0; int x=0, y=0, tblWidth=0, tblHeight=0;
cells = new HSLFTableCell[numrows][numcols]; cells = new HSLFTableCell[numRows][numCols];
for (int i = 0; i < cells.length; i++) { for (int i = 0; i < cells.length; i++) {
x = 0; x = 0;
for (int j = 0; j < cells[i].length; j++) { for (int j = 0; j < cells[i].length; j++) {
@ -85,17 +99,15 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape {
setAnchor(new Rectangle(0, 0, tblWidth, tblHeight)); setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0); EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
EscherOptRecord opt = new EscherOptRecord(); AbstractEscherOptRecord opt = new EscherOptRecord();
opt.setRecordId((short)0xF122); opt.setRecordId((short)RecordTypes.EscherUserDefined);
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1)); opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
EscherArrayProperty p = new EscherArrayProperty((short)(0x4000 | 0x3A0), false, null); EscherArrayProperty p = new EscherArrayProperty((short)(0x4000 | 0x3A0), false, null);
p.setSizeOfElements(0x0004); p.setSizeOfElements(0x0004);
p.setNumberOfElementsInArray(numrows); p.setNumberOfElementsInArray(numRows);
p.setNumberOfElementsInMemory(numrows); p.setNumberOfElementsInMemory(numRows);
opt.addEscherProperty(p); opt.addEscherProperty(p);
List<EscherRecord> lst = spCont.getChildRecords(); spCont.addChildBefore(opt, RecordTypes.EscherClientAnchor);
lst.add(lst.size()-1, opt);
spCont.setChildRecords(lst);
} }
/** /**
@ -104,7 +116,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent) { public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -131,7 +143,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape {
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0); EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
List<EscherRecord> lst = spCont.getChildRecords(); List<EscherRecord> lst = spCont.getChildRecords();
EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2); AbstractEscherOptRecord opt = (AbstractEscherOptRecord)lst.get(lst.size()-2);
EscherArrayProperty p = opt.lookup(0x3A0); EscherArrayProperty p = opt.lookup(0x3A0);
for (int i = 0; i < cells.length; i++) { for (int i = 0; i < cells.length; i++) {
HSLFTableCell cell = cells[i][0]; HSLFTableCell cell = cells[i][0];
@ -359,7 +371,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape {
public HSLFLine createBorder(){ public HSLFLine createBorder(){
HSLFLine line = new HSLFLine(this); HSLFLine line = new HSLFLine(this);
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1); setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1);
setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1); setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1);
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000); setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);

View File

@ -19,18 +19,19 @@ package org.apache.poi.hslf.usermodel;
import java.awt.Rectangle; import java.awt.Rectangle;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.TableCell;
/** /**
* Represents a cell in a ppt table * Represents a cell in a ppt table
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public final class HSLFTableCell extends HSLFTextBox { public final class HSLFTableCell extends HSLFTextBox implements TableCell<HSLFShape,HSLFTextParagraph> {
protected static final int DEFAULT_WIDTH = 100; protected static final int DEFAULT_WIDTH = 100;
protected static final int DEFAULT_HEIGHT = 40; protected static final int DEFAULT_HEIGHT = 40;
@ -45,7 +46,7 @@ public final class HSLFTableCell extends HSLFTextBox {
* @param escherRecord EscherSpContainer which holds information about this shape * @param escherRecord EscherSpContainer which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -55,7 +56,7 @@ public final class HSLFTableCell extends HSLFTextBox {
* @param parent the parent of this Shape. For example, if this text box is a cell * @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table. * in a table then the parent is Table.
*/ */
public HSLFTableCell(ShapeContainer<HSLFShape> parent){ public HSLFTableCell(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent); super(parent);
setShapeType(ShapeType.RECT); setShapeType(ShapeType.RECT);
@ -65,7 +66,7 @@ public final class HSLFTableCell extends HSLFTextBox {
protected EscherContainerRecord createSpContainer(boolean isChild){ protected EscherContainerRecord createSpContainer(boolean isChild){
_escherContainer = super.createSpContainer(isChild); _escherContainer = super.createSpContainer(isChild);
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0); setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000); setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001); setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);

View File

@ -29,7 +29,7 @@ import org.apache.poi.sl.usermodel.*;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public class HSLFTextBox extends HSLFTextShape { public class HSLFTextBox extends HSLFTextShape implements TextBox<HSLFShape,HSLFTextParagraph> {
/** /**
* Create a TextBox object and initialize it from the supplied Record container. * Create a TextBox object and initialize it from the supplied Record container.
@ -37,7 +37,7 @@ public class HSLFTextBox extends HSLFTextShape {
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
@ -48,7 +48,7 @@ public class HSLFTextBox extends HSLFTextShape {
* @param parent the parent of this Shape. For example, if this text box is a cell * @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table. * in a table then the parent is Table.
*/ */
public HSLFTextBox(ShapeContainer<HSLFShape> parent){ public HSLFTextBox(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent); super(parent);
} }

View File

@ -42,7 +42,7 @@ import org.apache.poi.util.*;
* @author Nick Burch * @author Nick Burch
*/ */
public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> { public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFTextParagraph,HSLFTextRun> {
protected static final POILogger logger = POILogFactory.getLogger(HSLFTextParagraph.class); protected static final POILogger logger = POILogFactory.getLogger(HSLFTextParagraph.class);
/** /**

View File

@ -39,7 +39,8 @@ import org.apache.poi.util.Units;
* *
* @author Yegor Kozlov * @author Yegor Kozlov
*/ */
public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape<HSLFTextParagraph> { public abstract class HSLFTextShape extends HSLFSimpleShape
implements TextShape<HSLFShape,HSLFTextParagraph> {
/** /**
* How to anchor the text * How to anchor the text
@ -93,9 +94,8 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape * @param parent the parent of the shape
*/ */
protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){ protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent); super(escherRecord, parent);
} }
/** /**
@ -104,7 +104,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @param parent the parent of this Shape. For example, if this text box is a cell * @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table. * in a table then the parent is Table.
*/ */
public HSLFTextShape(ShapeContainer<HSLFShape> parent){ public HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent); super(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape); _escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
} }
@ -241,7 +241,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @return the type of alignment * @return the type of alignment
*/ */
/* package */ int getAlignment(){ /* package */ int getAlignment(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
int align = HSLFTextShape.AnchorTop; int align = HSLFTextShape.AnchorTop;
if (prop == null){ if (prop == null){
@ -465,7 +465,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @return the inset in points * @return the inset in points
*/ */
private double getInset(short propId, double defaultInch) { private double getInset(short propId, double defaultInch) {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId); EscherSimpleProperty prop = getEscherProperty(opt, propId);
int val = prop == null ? (int)(Units.toEMU(Units.POINT_DPI)*defaultInch) : prop.getPropertyValue(); int val = prop == null ? (int)(Units.toEMU(Units.POINT_DPI)*defaultInch) : prop.getPropertyValue();
return Units.toPoints(val); return Units.toPoints(val);
@ -494,7 +494,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @see <a href="https://msdn.microsoft.com/en-us/library/dd948168(v=office.12).aspx">MSOWRAPMODE</a> * @see <a href="https://msdn.microsoft.com/en-us/library/dd948168(v=office.12).aspx">MSOWRAPMODE</a>
*/ */
public int getWordWrapEx() { public int getWordWrapEx() {
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
return prop == null ? WrapSquare : prop.getPropertyValue(); return prop == null ? WrapSquare : prop.getPropertyValue();
} }
@ -513,7 +513,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @return id for the text. * @return id for the text.
*/ */
public int getTextId(){ public int getTextId(){
EscherOptRecord opt = getEscherOptRecord(); AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
return prop == null ? 0 : prop.getPropertyValue(); return prop == null ? 0 : prop.getPropertyValue();
} }
@ -527,9 +527,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
setEscherProperty(EscherProperties.TEXT__TEXTID, id); setEscherProperty(EscherProperties.TEXT__TEXTID, id);
} }
/** @Override
* @return the TextParagraphs for this text box
*/
public List<HSLFTextParagraph> getTextParagraphs(){ public List<HSLFTextParagraph> getTextParagraphs(){
if (!_paragraphs.isEmpty()) return _paragraphs; if (!_paragraphs.isEmpty()) return _paragraphs;
@ -704,7 +702,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
@Override @Override
public double getTextHeight(){ public double getTextHeight(){
DrawFactory drawFact = DrawFactory.getInstance(null); DrawFactory drawFact = DrawFactory.getInstance(null);
DrawTextShape<HSLFTextShape> dts = drawFact.getDrawable(this); DrawTextShape dts = drawFact.getDrawable(this);
return dts.getTextHeight(); return dts.getTextHeight();
} }

View File

@ -26,9 +26,9 @@ import java.io.ByteArrayOutputStream;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
@ -209,7 +209,7 @@ public final class TestBackground {
} }
private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) { private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {
EscherOptRecord opt = shape.getEscherOptRecord(); AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE); EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if(p != null) { if(p != null) {
int idx = p.getPropertyValue(); int idx = p.getPropertyValue();

View File

@ -36,13 +36,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherDgRecord; import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord; import org.apache.poi.ddf.EscherDggRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty; import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hslf.usermodel.HSLFAutoShape; import org.apache.poi.hslf.usermodel.HSLFAutoShape;
import org.apache.poi.hslf.usermodel.HSLFGroupShape; import org.apache.poi.hslf.usermodel.HSLFGroupShape;
import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.hslf.usermodel.HSLFPictureData; import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.hslf.usermodel.HSLFPictureShape; import org.apache.poi.hslf.usermodel.HSLFPictureShape;
import org.apache.poi.hslf.usermodel.HSLFShape; import org.apache.poi.hslf.usermodel.HSLFShape;
@ -54,7 +55,6 @@ import org.apache.poi.hslf.usermodel.HSLFTextBox;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph; import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.usermodel.HSLFTextRun; import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.hslf.usermodel.HSLFTextShape; import org.apache.poi.hslf.usermodel.HSLFTextShape;
import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.sl.usermodel.PictureData.PictureType; import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.ShapeType; import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
@ -400,7 +400,7 @@ public final class TestShapes {
public void lineWidth() { public void lineWidth() {
HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE); HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE);
EscherOptRecord opt = sh.getEscherOptRecord(); AbstractEscherOptRecord opt = sh.getEscherOptRecord();
EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNull(prop); assertNull(prop);
assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0); assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);

View File

@ -126,17 +126,17 @@ public final class TestTable {
*/ */
@Test @Test
public void test57820() throws Exception { public void test57820() throws Exception {
SlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt")); SlideShow<?,?> ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt"));
List<? extends Slide<?,?,?>> slides = ppt.getSlides(); List<? extends Slide<?,?>> slides = ppt.getSlides();
assertEquals(1, slides.size()); assertEquals(1, slides.size());
List<? extends Shape> shapes = slides.get(0).getShapes(); //throws NullPointerException List<? extends Shape<?,?>> shapes = slides.get(0).getShapes(); //throws NullPointerException
TableShape tbl = null; TableShape<?,?> tbl = null;
for(Shape s : shapes) { for(Shape<?,?> s : shapes) {
if(s instanceof TableShape) { if(s instanceof TableShape) {
tbl = (TableShape)s; tbl = (TableShape<?,?>)s;
break; break;
} }
} }

View File

@ -38,9 +38,9 @@ import java.util.Set;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty; import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherColorRef; import org.apache.poi.ddf.EscherColorRef;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties; import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.hslf.HSLFTestDataSamples; import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
@ -612,7 +612,7 @@ public final class TestBugs {
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0); HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
EscherOptRecord opt = as.getEscherOptRecord(); AbstractEscherOptRecord opt = as.getEscherOptRecord();
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS); EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
double exp[][] = { double exp[][] = {
// r, g, b, position // r, g, b, position

View File

@ -172,11 +172,11 @@ public final class TestPicture {
for (String file : files) { for (String file : files) {
InputStream is = _slTests.openResourceAsStream(file); InputStream is = _slTests.openResourceAsStream(file);
SlideShow ss; SlideShow<?,?> ss;
if (file.endsWith("pptx")) { if (file.endsWith("pptx")) {
Class<?> cls = Class.forName("org.apache.poi.xslf.usermodel.XMLSlideShow"); Class<?> cls = Class.forName("org.apache.poi.xslf.usermodel.XMLSlideShow");
Constructor<?> ct = cls.getDeclaredConstructor(InputStream.class); Constructor<?> ct = cls.getDeclaredConstructor(InputStream.class);
ss = (SlideShow)ct.newInstance(is); ss = (SlideShow<?,?>)ct.newInstance(is);
} else { } else {
ss = new HSLFSlideShow(is); ss = new HSLFSlideShow(is);
} }
@ -184,7 +184,7 @@ public final class TestPicture {
boolean debugOut = false; boolean debugOut = false;
Dimension pg = ss.getPageSize(); Dimension pg = ss.getPageSize();
for (Slide<?,?,?> slide : ss.getSlides()) { for (Slide<?,?> slide : ss.getSlides()) {
int slideNo = slide.getSlideNumber(); int slideNo = slide.getSlideNumber();
if (!pages.get(slideNo-1)) { if (!pages.get(slideNo-1)) {
if (pages.nextSetBit(slideNo-1) == -1) break; else continue; if (pages.nextSetBit(slideNo-1) == -1) break; else continue;