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
}
@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;
}
case LINE:
shape = new Line(spContainer, parent);
break;
// shape = new Line(spContainer, parent);
// break;
case NOT_PRIMITIVE: {
EscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
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
*/
@Override
public int getSlideNumber() { return _slideNo; }
/**

View File

@ -174,6 +174,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
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
* one from the {@link SlideListWithText}?
@ -1151,6 +1156,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
HSLFTextRun nextRun = new HSLFTextRun(para);
nextRun.setText("");
runs.add(nextRun);
ccRun++;
} else {
// need to add +1 to the last run of the last paragraph
len++;

View File

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

View File

@ -4,6 +4,7 @@ import java.awt.*;
import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.Shape;
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());
PlaceableShape ps = new PlaceableShape(){
public ShapeContainer<? extends Shape> getParent() { return null; }
public Rectangle2D getAnchor() { return anchor; }
public void setAnchor(Rectangle2D anchor) {}
public double getRotation() { return 0; }

View File

@ -4,6 +4,7 @@ import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
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.Shape;
@ -26,9 +27,8 @@ public class DrawShape<T extends Shape> implements Drawable {
PlaceableShape ps = (PlaceableShape)shape;
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
final Rectangle2D anchor = (tx != null)
? tx.createTransformedShape(ps.getAnchor()).getBounds2D()
: ps.getAnchor();
if (tx == null) tx = new AffineTransform();
final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();
// rotation
double rotation = ps.getRotation();
@ -40,9 +40,10 @@ public class DrawShape<T extends Shape> implements Drawable {
// normalize rotation
rotation %= 360.;
if (rotation < 0) rotation += 360.;
int quadrant = (((int)rotation+45)/90)%4;
double scaleX = 1.0, scaleY = 1.0;
// scale to bounding box (bug #53176)
if (quadrant == 1 || quadrant == 3) {
// In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation
@ -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
// and later on, turn it around again to compare it with its original size ...
// graphics coordinate space
AffineTransform txg = new AffineTransform();
txg.translate(centerX, centerY);
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();
AffineTransform txs;
if (ps instanceof HSLFShape) {
txs = new AffineTransform(tx);
} 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();
scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();
graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation-quadrant*90.));
graphics.scale(scaleX, scaleY);
graphics.rotate(Math.toRadians(quadrant*90));
graphics.translate(-centerX, -centerY);
} else {
graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation));
graphics.scale(scaleX, scaleY);
graphics.translate(-centerX, -centerY);
quadrant = 0;
}
// transformation is applied reversed ...
graphics.translate(centerX, centerY);
graphics.rotate(Math.toRadians(rotation-quadrant*90.));
graphics.scale(scaleX, scaleY);
graphics.rotate(Math.toRadians(quadrant*90));
graphics.translate(-centerX, -centerY);
}
//flip horizontal

View File

@ -1,6 +1,9 @@
package org.apache.poi.sl.draw;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
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) {
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);
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;
public interface PlaceableShape {
ShapeContainer<? extends Shape> getParent();
/**
* @return the position of this shape within the drawing canvas.
* The coordinates are expressed in points

View File

@ -288,7 +288,9 @@ public enum ShapeType {
/** name of the presetShapeDefinit(i)on entry */
public String 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();
boolean toLower = true;

View File

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