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:
parent
4acc6a84a1
commit
2170a52383
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
||||
/**
|
||||
|
@ -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++;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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; }
|
||||
|
@ -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,6 +40,7 @@ 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;
|
||||
|
||||
@ -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();
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
graphics.translate(centerX, centerY);
|
||||
graphics.rotate(Math.toRadians(rotation));
|
||||
graphics.scale(scaleX, scaleY);
|
||||
graphics.translate(-centerX, -centerY);
|
||||
}
|
||||
// transformation is applied reversed ...
|
||||
}
|
||||
|
||||
//flip horizontal
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user