Rendering of rotated group shapes fixed, other smaller fixes, defaulting to white transparent slide background

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1685344 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-06-13 23:26:46 +00:00
parent 4acc6a84a1
commit 2170a52383
11 changed files with 70 additions and 46 deletions

View File

@ -248,4 +248,10 @@ public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSl
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public int getSlideNumber() {
int idx = getSlideShow().getSlides().indexOf(this);
return (idx == -1) ? idx : idx+1;
}
} }

View File

@ -116,8 +116,8 @@ public final class HSLFShapeFactory {
break; break;
} }
case LINE: case LINE:
shape = new Line(spContainer, parent); // shape = new Line(spContainer, parent);
break; // break;
case NOT_PRIMITIVE: { case NOT_PRIMITIVE: {
EscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID); EscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
EscherProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES); EscherProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);

View File

@ -219,6 +219,7 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
/** /**
* Returns the (public facing) page number of this slide * Returns the (public facing) page number of this slide
*/ */
@Override
public int getSlideNumber() { return _slideNo; } public int getSlideNumber() { return _slideNo; }
/** /**

View File

@ -174,6 +174,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
return (_headerAtom != null) ? _headerAtom.getTextType() : -1; return (_headerAtom != null) ? _headerAtom.getTextType() : -1;
} }
public void setRunType(int runType) {
if (_headerAtom != null) _headerAtom.setTextType(runType);
}
/** /**
* Is this Text Run one from a {@link PPDrawing}, or is it * Is this Text Run one from a {@link PPDrawing}, or is it
* one from the {@link SlideListWithText}? * one from the {@link SlideListWithText}?
@ -1151,6 +1156,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
HSLFTextRun nextRun = new HSLFTextRun(para); HSLFTextRun nextRun = new HSLFTextRun(para);
nextRun.setText(""); nextRun.setText("");
runs.add(nextRun); runs.add(nextRun);
ccRun++;
} else { } else {
// need to add +1 to the last run of the last paragraph // need to add +1 to the last run of the last paragraph
len++; len++;

View File

@ -214,9 +214,8 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
public int getRunType() { public int getRunType() {
getEscherTextboxWrapper(); getEscherTextboxWrapper();
if (_txtbox == null) return -1; if (_txtbox == null) return -1;
TextHeaderAtom headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID); List<HSLFTextParagraph> paras = HSLFTextParagraph.findTextParagraphs(_txtbox, getSheet());
assert(headerAtom != null); return (paras.isEmpty()) ? -1 : paras.get(0).getRunType();
return headerAtom.getTextType();
} }
/** /**
@ -228,9 +227,10 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
public void setRunType(int type) { public void setRunType(int type) {
getEscherTextboxWrapper(); getEscherTextboxWrapper();
if (_txtbox == null) return; if (_txtbox == null) return;
TextHeaderAtom headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID); List<HSLFTextParagraph> paras = HSLFTextParagraph.findTextParagraphs(_txtbox, getSheet());
assert(headerAtom != null); if (!paras.isEmpty()) {
headerAtom.setTextType(type); paras.get(0).setRunType(type);
}
} }
/** /**
@ -711,10 +711,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
*/ */
public String getText() { public String getText() {
String rawText = getRawText(); String rawText = getRawText();
TextHeaderAtom _headerAtom = (TextHeaderAtom)_txtbox.findFirstOfType(TextHeaderAtom.typeID); return HSLFTextParagraph.toExternalString(rawText, getRunType());
int runType = (_headerAtom == null) ? -1 : _headerAtom.getTextType();
return HSLFTextParagraph.toExternalString(rawText, runType);
} }

View File

@ -4,6 +4,7 @@ import java.awt.*;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.Shape;
public class DrawBackground<T extends Background> extends DrawShape<T> { public class DrawBackground<T extends Background> extends DrawShape<T> {
@ -16,6 +17,7 @@ public class DrawBackground<T extends Background> extends DrawShape<T> {
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 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; }

View File

@ -4,6 +4,7 @@ import java.awt.Graphics2D;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.apache.poi.hslf.usermodel.HSLFShape;
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;
@ -26,9 +27,8 @@ public class DrawShape<T extends Shape> implements Drawable {
PlaceableShape ps = (PlaceableShape)shape; PlaceableShape ps = (PlaceableShape)shape;
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
final Rectangle2D anchor = (tx != null) if (tx == null) tx = new AffineTransform();
? tx.createTransformedShape(ps.getAnchor()).getBounds2D() final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();
: ps.getAnchor();
// rotation // rotation
double rotation = ps.getRotation(); double rotation = ps.getRotation();
@ -40,6 +40,7 @@ public class DrawShape<T extends Shape> implements Drawable {
// normalize rotation // normalize rotation
rotation %= 360.; rotation %= 360.;
if (rotation < 0) rotation += 360.; if (rotation < 0) rotation += 360.;
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;
@ -54,42 +55,36 @@ public class DrawShape<T extends Shape> implements Drawable {
// be already (differently) scaled, so you can paint the shape in its default orientation // be already (differently) scaled, so you can paint the shape in its default orientation
// and later on, turn it around again to compare it with its original size ... // and later on, turn it around again to compare it with its original size ...
// graphics coordinate space AffineTransform txs;
AffineTransform txg = new AffineTransform(); if (ps instanceof HSLFShape) {
txg.translate(centerX, centerY); txs = new AffineTransform(tx);
txg.rotate(Math.toRadians(90));
txg.translate(-centerX, -centerY);
boolean oldVariant = true;
Rectangle2D anchor2;
if (oldVariant) {
// shape coordinate space
AffineTransform txs = new AffineTransform(tx);
txs.translate(centerX, centerY);
txs.rotate(Math.toRadians(90));
txs.translate(-centerX, -centerY);
txg.concatenate(txs);
anchor2 = txg.createTransformedShape(ps.getAnchor()).getBounds2D();
} else { } else {
anchor2 = txg.createTransformedShape(anchor).getBounds2D(); // this handling is only based on try and error ... not sure why xslf is handled differently.
txs = new AffineTransform();
txs.translate(centerX, centerY);
txs.rotate(Math.PI/2.); // actually doesn't matter if +/- 90 degrees
txs.translate(-centerX, -centerY);
txs.concatenate(tx);
} }
txs.translate(centerX, centerY);
txs.rotate(Math.PI/2.);
txs.translate(-centerX, -centerY);
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 {
quadrant = 0;
}
// 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.));
graphics.scale(scaleX, scaleY); graphics.scale(scaleX, scaleY);
graphics.rotate(Math.toRadians(quadrant*90)); graphics.rotate(Math.toRadians(quadrant*90));
graphics.translate(-centerX, -centerY); graphics.translate(-centerX, -centerY);
} else {
graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation));
graphics.scale(scaleX, scaleY);
graphics.translate(-centerX, -centerY);
}
// transformation is applied reversed ...
} }
//flip horizontal //flip horizontal

View File

@ -1,6 +1,9 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.*;
@ -15,6 +18,11 @@ public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> im
} }
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
Dimension dim = sheet.getSlideShow().getPageSize();
Color whiteTrans = new Color(1f,1f,1f,0f);
graphics.setColor(whiteTrans);
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<? extends Shape, ? extends SlideShow> master = sheet.getMasterSheet();

View File

@ -20,6 +20,8 @@ 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();
/** /**
* @return the position of this shape within the drawing canvas. * @return the position of this shape within the drawing canvas.
* The coordinates are expressed in points * The coordinates are expressed in points

View File

@ -288,7 +288,9 @@ public enum ShapeType {
/** name of the presetShapeDefinit(i)on entry */ /** name of the presetShapeDefinit(i)on entry */
public String getOoxmlName() { public String getOoxmlName() {
if (this == SEAL) return STAR_16.getOoxmlName(); if (this == SEAL) return STAR_16.getOoxmlName();
if (ooxmlId == -1) return null; if (ooxmlId == -1) {
return (name().startsWith("TEXT")) ? RECT.getOoxmlName() : null;
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
boolean toLower = true; boolean toLower = true;

View File

@ -29,4 +29,9 @@ public interface Slide<T extends Shape, SS extends SlideShow, N extends Notes<T,
boolean getFollowMasterObjects(); boolean getFollowMasterObjects();
void setFollowMasterObjects(boolean follow); void setFollowMasterObjects(boolean follow);
/**
* @return the 1-based slide no.
*/
int getSlideNumber();
} }