Bug 53191 - Problems with line style when converting ppt to png
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765196 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e3633daac5
commit
bf95861693
@ -18,6 +18,8 @@
|
|||||||
package org.apache.poi.sl.draw;
|
package org.apache.poi.sl.draw;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Path2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -35,11 +37,20 @@ public class DrawFreeformShape extends DrawAutoShape {
|
|||||||
|
|
||||||
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 = getShape().getPath();
|
FreeformShape<?,?> fsh = getShape();
|
||||||
FillStyle fs = getShape().getFillStyle();
|
Path2D sh = fsh.getPath();
|
||||||
StrokeStyle ss = getShape().getStrokeStyle();
|
|
||||||
|
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
|
||||||
|
if (tx == null) {
|
||||||
|
tx = new AffineTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
java.awt.Shape canvasShape = tx.createTransformedShape(sh);
|
||||||
|
|
||||||
|
FillStyle fs = fsh.getFillStyle();
|
||||||
|
StrokeStyle ss = fsh.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(canvasShape, path));
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,31 @@ public class DrawShape implements Drawable {
|
|||||||
if (!(shape instanceof PlaceableShape)) return;
|
if (!(shape instanceof PlaceableShape)) return;
|
||||||
|
|
||||||
PlaceableShape<?,?> ps = (PlaceableShape<?,?>)shape;
|
PlaceableShape<?,?> ps = (PlaceableShape<?,?>)shape;
|
||||||
|
final boolean isHSLF = ps.getClass().getCanonicalName().toLowerCase(Locale.ROOT).contains("hslf");
|
||||||
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();
|
||||||
|
|
||||||
|
char cmds[] = isHSLF ? new char[]{ 'h','v','r' } : new char[]{ 'r','h','v' };
|
||||||
|
for (char ch : cmds) {
|
||||||
|
switch (ch) {
|
||||||
|
case 'h':
|
||||||
|
//flip horizontal
|
||||||
|
if (ps.getFlipHorizontal()) {
|
||||||
|
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
|
||||||
|
graphics.scale(-1, 1);
|
||||||
|
graphics.translate(-anchor.getX(), -anchor.getY());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
//flip vertical
|
||||||
|
if (ps.getFlipVertical()) {
|
||||||
|
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
|
||||||
|
graphics.scale(1, -1);
|
||||||
|
graphics.translate(-anchor.getX(), -anchor.getY());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
// rotation
|
// rotation
|
||||||
double rotation = ps.getRotation();
|
double rotation = ps.getRotation();
|
||||||
if (rotation != 0.) {
|
if (rotation != 0.) {
|
||||||
@ -77,7 +98,7 @@ public class DrawShape implements Drawable {
|
|||||||
// 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 ...
|
||||||
|
|
||||||
AffineTransform txs;
|
AffineTransform txs;
|
||||||
if (ps.getClass().getCanonicalName().toLowerCase(Locale.ROOT).contains("hslf")) {
|
if (isHSLF) {
|
||||||
txs = new AffineTransform(tx);
|
txs = new AffineTransform(tx);
|
||||||
} else {
|
} else {
|
||||||
// this handling is only based on try and error ... not sure why xslf is handled differently.
|
// this handling is only based on try and error ... not sure why xslf is handled differently.
|
||||||
@ -113,19 +134,8 @@ public class DrawShape implements Drawable {
|
|||||||
}
|
}
|
||||||
graphics.translate(-centerX, -centerY);
|
graphics.translate(-centerX, -centerY);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
//flip horizontal
|
|
||||||
if (ps.getFlipHorizontal()) {
|
|
||||||
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
|
|
||||||
graphics.scale(-1, 1);
|
|
||||||
graphics.translate(-anchor.getX(), -anchor.getY());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//flip vertical
|
|
||||||
if (ps.getFlipVertical()) {
|
|
||||||
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
|
|
||||||
graphics.scale(1, -1);
|
|
||||||
graphics.translate(-anchor.getX(), -anchor.getY());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,12 +230,12 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
|
|||||||
EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
|
EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
|
||||||
verticesProp.setNumberOfElementsInArray(pntInfo.size());
|
verticesProp.setNumberOfElementsInArray(pntInfo.size());
|
||||||
verticesProp.setNumberOfElementsInMemory(pntInfo.size());
|
verticesProp.setNumberOfElementsInMemory(pntInfo.size());
|
||||||
verticesProp.setSizeOfElements(0xFFF0);
|
verticesProp.setSizeOfElements(8);
|
||||||
for (int i = 0; i < pntInfo.size(); i++) {
|
for (int i = 0; i < pntInfo.size(); i++) {
|
||||||
Point2D.Double pnt = pntInfo.get(i);
|
Point2D.Double pnt = pntInfo.get(i);
|
||||||
byte[] data = new byte[4];
|
byte[] data = new byte[8];
|
||||||
LittleEndian.putShort(data, 0, (short)Units.pointsToMaster(pnt.getX() - bounds.getX()));
|
LittleEndian.putInt(data, 0, Units.pointsToMaster(pnt.getX() - bounds.getX()));
|
||||||
LittleEndian.putShort(data, 2, (short)Units.pointsToMaster(pnt.getY() - bounds.getY()));
|
LittleEndian.putInt(data, 4, Units.pointsToMaster(pnt.getY() - bounds.getY()));
|
||||||
verticesProp.setElement(i, data);
|
verticesProp.setElement(i, data);
|
||||||
}
|
}
|
||||||
opt.addEscherProperty(verticesProp);
|
opt.addEscherProperty(verticesProp);
|
||||||
@ -282,6 +282,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
|
|||||||
|
|
||||||
Iterator<byte[]> vertIter = verticesProp.iterator();
|
Iterator<byte[]> vertIter = verticesProp.iterator();
|
||||||
Iterator<byte[]> segIter = segmentsProp.iterator();
|
Iterator<byte[]> segIter = segmentsProp.iterator();
|
||||||
|
double xyPoints[] = new double[2];
|
||||||
|
|
||||||
while (vertIter.hasNext() && segIter.hasNext()) {
|
while (vertIter.hasNext() && segIter.hasNext()) {
|
||||||
byte[] segElem = segIter.next();
|
byte[] segElem = segIter.next();
|
||||||
@ -292,30 +293,30 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case moveTo: {
|
case moveTo: {
|
||||||
byte[] p = vertIter.next();
|
fillPoint(vertIter.next(), xyPoints);
|
||||||
double x = Units.masterToPoints(LittleEndian.getShort(p, 0));
|
double x = xyPoints[0];
|
||||||
double y = Units.masterToPoints(LittleEndian.getShort(p, 2));
|
double y = xyPoints[1];
|
||||||
path.moveTo(x,y);
|
path.moveTo(x,y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case curveTo: {
|
case curveTo: {
|
||||||
byte[] p1 = vertIter.next();
|
fillPoint(vertIter.next(), xyPoints);
|
||||||
double x1 = Units.masterToPoints(LittleEndian.getShort(p1, 0));
|
double x1 = xyPoints[0];
|
||||||
double y1 = Units.masterToPoints(LittleEndian.getShort(p1, 2));
|
double y1 = xyPoints[1];
|
||||||
byte[] p2 = vertIter.next();
|
fillPoint(vertIter.next(), xyPoints);
|
||||||
double x2 = Units.masterToPoints(LittleEndian.getShort(p2, 0));
|
double x2 = xyPoints[0];
|
||||||
double y2 = Units.masterToPoints(LittleEndian.getShort(p2, 2));
|
double y2 = xyPoints[1];
|
||||||
byte[] p3 = vertIter.next();
|
fillPoint(vertIter.next(), xyPoints);
|
||||||
double x3 = Units.masterToPoints(LittleEndian.getShort(p3, 0));
|
double x3 = xyPoints[0];
|
||||||
double y3 = Units.masterToPoints(LittleEndian.getShort(p3, 2));
|
double y3 = xyPoints[1];
|
||||||
path.curveTo(x1,y1,x2,y2,x3,y3);
|
path.curveTo(x1,y1,x2,y2,x3,y3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case lineTo:
|
case lineTo:
|
||||||
if (vertIter.hasNext()) {
|
if (vertIter.hasNext()) {
|
||||||
byte[] p = vertIter.next();
|
fillPoint(vertIter.next(), xyPoints);
|
||||||
double x = Units.masterToPoints(LittleEndian.getShort(p, 0));
|
double x = xyPoints[0];
|
||||||
double y = Units.masterToPoints(LittleEndian.getShort(p, 2));
|
double y = xyPoints[1];
|
||||||
path.lineTo(x,y);
|
path.lineTo(x,y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -344,6 +345,25 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh
|
|||||||
return new Path2D.Double(at.createTransformedShape(path));
|
return new Path2D.Double(at.createTransformedShape(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillPoint(byte xyMaster[], double xyPoints[]) {
|
||||||
|
if (xyMaster == null || xyPoints == null || (xyMaster.length != 4 && xyMaster.length != 8) || xyPoints.length != 2) {
|
||||||
|
logger.log(POILogger.WARN, "Invalid number of master bytes for a single point - ignore point");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
if (xyMaster.length == 4) {
|
||||||
|
x = LittleEndian.getShort(xyMaster, 0);
|
||||||
|
y = LittleEndian.getShort(xyMaster, 2);
|
||||||
|
} else {
|
||||||
|
x = LittleEndian.getInt(xyMaster, 0);
|
||||||
|
y = LittleEndian.getInt(xyMaster, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
xyPoints[0] = Units.masterToPoints(x);
|
||||||
|
xyPoints[1] = Units.masterToPoints(y);
|
||||||
|
}
|
||||||
|
|
||||||
private static <T extends EscherProperty> T getShapeProp(AbstractEscherOptRecord opt, int propId) {
|
private static <T extends EscherProperty> T getShapeProp(AbstractEscherOptRecord opt, int propId) {
|
||||||
T prop = getEscherProperty(opt, (short)(propId + 0x4000));
|
T prop = getEscherProperty(opt, (short)(propId + 0x4000));
|
||||||
if (prop == null) {
|
if (prop == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user