aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawFactory.java8
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawShape.java44
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawSimpleShape.java43
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTableShape.java110
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextParagraph.java38
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTextShape.java19
-rw-r--r--src/java/org/apache/poi/sl/usermodel/TableCell.java28
7 files changed, 223 insertions, 67 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawFactory.java b/src/java/org/apache/poi/sl/draw/DrawFactory.java
index d0584dadb3..f06ccdc1b0 100644
--- a/src/java/org/apache/poi/sl/draw/DrawFactory.java
+++ b/src/java/org/apache/poi/sl/draw/DrawFactory.java
@@ -56,6 +56,14 @@ public class DrawFactory {
defaultFactory.set(factory);
}
+ /**
+ * Returns the DrawFactory, preferably via a graphics instance.
+ * If graphics is null, the current thread local is checked or
+ * if it is not set, a new factory is created.
+ *
+ * @param graphics the current graphics context or null
+ * @return the draw factory
+ */
public static DrawFactory getInstance(Graphics2D graphics) {
// first try to find the factory over the rendering hint
DrawFactory factory = null;
diff --git a/src/java/org/apache/poi/sl/draw/DrawShape.java b/src/java/org/apache/poi/sl/draw/DrawShape.java
index 0c465bc52a..f4f53b52d2 100644
--- a/src/java/org/apache/poi/sl/draw/DrawShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawShape.java
@@ -17,6 +17,7 @@
package org.apache.poi.sl.draw;
+import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
@@ -24,6 +25,9 @@ import java.util.Locale;
import org.apache.poi.sl.usermodel.PlaceableShape;
import org.apache.poi.sl.usermodel.Shape;
+import org.apache.poi.sl.usermodel.StrokeStyle;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
public class DrawShape implements Drawable {
@@ -157,4 +161,44 @@ public class DrawShape implements Drawable {
protected Shape<?,?> getShape() {
return shape;
}
+
+ protected static BasicStroke getStroke(StrokeStyle strokeStyle) {
+ float lineWidth = (float) strokeStyle.getLineWidth();
+ if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt
+
+ LineDash lineDash = strokeStyle.getLineDash();
+ if (lineDash == null) {
+ lineDash = LineDash.SOLID;
+ }
+
+ int dashPatI[] = lineDash.pattern;
+ final float dash_phase = 0;
+ float[] dashPatF = null;
+ if (dashPatI != null) {
+ dashPatF = new float[dashPatI.length];
+ for (int i=0; i<dashPatI.length; i++) {
+ dashPatF[i] = dashPatI[i]*Math.max(1, lineWidth);
+ }
+ }
+
+ LineCap lineCapE = strokeStyle.getLineCap();
+ if (lineCapE == null) lineCapE = LineCap.FLAT;
+ int lineCap;
+ switch (lineCapE) {
+ case ROUND:
+ lineCap = BasicStroke.CAP_ROUND;
+ break;
+ case SQUARE:
+ lineCap = BasicStroke.CAP_SQUARE;
+ break;
+ default:
+ case FLAT:
+ lineCap = BasicStroke.CAP_BUTT;
+ break;
+ }
+
+ int lineJoin = BasicStroke.JOIN_ROUND;
+
+ return new BasicStroke(lineWidth, lineCap, lineJoin, lineWidth, dashPatF, dash_phase);
+ }
}
diff --git a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
index 748b691dba..1032750690 100644
--- a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
@@ -53,9 +53,6 @@ import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
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;
@@ -282,45 +279,7 @@ public class DrawSimpleShape extends DrawShape {
}
public BasicStroke getStroke() {
- StrokeStyle strokeStyle = getShape().getStrokeStyle();
-
- float lineWidth = (float) strokeStyle.getLineWidth();
- if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt
-
- LineDash lineDash = strokeStyle.getLineDash();
- if (lineDash == null) {
- lineDash = LineDash.SOLID;
- }
-
- int dashPatI[] = lineDash.pattern;
- final float dash_phase = 0;
- float[] dashPatF = null;
- if (dashPatI != null) {
- dashPatF = new float[dashPatI.length];
- for (int i=0; i<dashPatI.length; i++) {
- dashPatF[i] = dashPatI[i]*Math.max(1, lineWidth);
- }
- }
-
- LineCap lineCapE = strokeStyle.getLineCap();
- if (lineCapE == null) lineCapE = LineCap.FLAT;
- int lineCap;
- switch (lineCapE) {
- case ROUND:
- lineCap = BasicStroke.CAP_ROUND;
- break;
- case SQUARE:
- lineCap = BasicStroke.CAP_SQUARE;
- break;
- default:
- case FLAT:
- lineCap = BasicStroke.CAP_BUTT;
- break;
- }
-
- int lineJoin = BasicStroke.JOIN_ROUND;
-
- return new BasicStroke(lineWidth, lineCap, lineJoin, lineWidth, dashPatF, dash_phase);
+ return getStroke(getShape().getStrokeStyle());
}
protected void drawShadow(
diff --git a/src/java/org/apache/poi/sl/draw/DrawTableShape.java b/src/java/org/apache/poi/sl/draw/DrawTableShape.java
index b44427838a..970c9b4e0b 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTableShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTableShape.java
@@ -19,21 +19,31 @@ package org.apache.poi.sl.draw;
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
import org.apache.poi.sl.usermodel.GroupShape;
+import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.sl.usermodel.TableCell;
import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
+import org.apache.poi.util.Internal;
import org.apache.poi.sl.usermodel.TableShape;
public class DrawTableShape extends DrawShape {
- // to be implemented ...
+ /**
+ * Additional spacing between cells
+ */
+ @Internal
+ public static final int borderSize = 2;
+
public DrawTableShape(TableShape<?,?> shape) {
super(shape);
}
-
- protected Drawable getDrawable(Graphics2D graphics) {
+
+ protected Drawable getGroupShape(Graphics2D graphics) {
if (shape instanceof GroupShape) {
DrawFactory df = DrawFactory.getInstance(graphics);
return df.getDrawable((GroupShape<?,?>)shape);
@@ -42,31 +52,102 @@ public class DrawTableShape extends DrawShape {
}
public void applyTransform(Graphics2D graphics) {
- Drawable d = getDrawable(graphics);
+ Drawable d = getGroupShape(graphics);
if (d != null) {
d.applyTransform(graphics);
+ } else {
+ super.applyTransform(graphics);
}
}
public void draw(Graphics2D graphics) {
- Drawable d = getDrawable(graphics);
+ Drawable d = getGroupShape(graphics);
if (d != null) {
d.draw(graphics);
+ return;
}
+
+ TableShape<?,?> ts = getShape();
+ DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(ts);
+ final int rows = ts.getNumberOfRows();
+ final int cols = ts.getNumberOfColumns();
+
+ // draw background boxes
+ for (int row=0; row<rows; row++) {
+ for (int col=0; col<cols; col++) {
+ TableCell<?,?> tc = ts.getCell(row, col);
+ if (tc == null || tc.isMerged()) {
+ continue;
+ }
+
+ Paint fillPaint = drawPaint.getPaint(graphics, tc.getFillStyle().getPaint());
+ graphics.setPaint(fillPaint);
+ Rectangle2D cellAnc = tc.getAnchor();
+ graphics.fill(cellAnc);
+
+ for (BorderEdge edge : BorderEdge.values()) {
+ StrokeStyle stroke = tc.getBorderStyle(edge);
+ if (stroke == null) {
+ continue;
+ }
+ graphics.setStroke(getStroke(stroke));
+ Paint linePaint = drawPaint.getPaint(graphics, stroke.getPaint());
+ graphics.setPaint(linePaint);
+
+ double x=cellAnc.getX(), y=cellAnc.getY(), w=cellAnc.getWidth(), h=cellAnc.getHeight();
+ Line2D line;
+ switch (edge) {
+ default:
+ case bottom:
+ line = new Line2D.Double(x-borderSize, y+h, x+w+borderSize, y+h);
+ break;
+ case left:
+ line = new Line2D.Double(x, y, x, y+h+borderSize);
+ break;
+ case right:
+ line = new Line2D.Double(x+w, y, x+w, y+h+borderSize);
+ break;
+ case top:
+ line = new Line2D.Double(x-borderSize, y, x+w+borderSize, y);
+ break;
+ }
+
+ graphics.draw(line);
+ }
+ }
+ }
+
+ // draw text
+ drawContent(graphics);
}
public void drawContent(Graphics2D graphics) {
- Drawable d = getDrawable(graphics);
+ Drawable d = getGroupShape(graphics);
if (d != null) {
d.drawContent(graphics);
+ return;
+ }
+
+ TableShape<?,?> ts = getShape();
+ DrawFactory df = DrawFactory.getInstance(graphics);
+
+ final int rows = ts.getNumberOfRows();
+ final int cols = ts.getNumberOfColumns();
+
+ for (int row=0; row<rows; row++) {
+ for (int col=0; col<cols; col++) {
+ TableCell<?,?> tc = ts.getCell(row, col);
+ DrawTextShape dts = df.getDrawable(tc);
+ dts.drawContent(graphics);
+ }
}
}
@Override
protected TableShape<?,?> getShape() {
return (TableShape<?,?>)shape;
- }
-
+ }
+
/**
* Format the table and apply the specified Line to all cell boundaries,
* both outside and inside.
@@ -79,7 +160,7 @@ public class DrawTableShape extends DrawShape {
TableShape<?,?> table = getShape();
final int rows = table.getNumberOfRows();
final int cols = table.getNumberOfColumns();
-
+
BorderEdge edges[] = { BorderEdge.top, BorderEdge.left, null, null };
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
@@ -99,11 +180,11 @@ public class DrawTableShape extends DrawShape {
*/
public void setOutsideBorders(Object... args){
if (args.length == 0) return;
-
+
TableShape<?,?> table = getShape();
final int rows = table.getNumberOfRows();
final int cols = table.getNumberOfColumns();
-
+
BorderEdge edges[] = new BorderEdge[4];
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
@@ -125,11 +206,11 @@ public class DrawTableShape extends DrawShape {
*/
public void setInsideBorders(Object... args) {
if (args.length == 0) return;
-
+
TableShape<?,?> table = getShape();
final int rows = table.getNumberOfRows();
final int cols = table.getNumberOfColumns();
-
+
BorderEdge edges[] = new BorderEdge[2];
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
@@ -139,7 +220,7 @@ public class DrawTableShape extends DrawShape {
}
}
}
-
+
/**
* Apply the border attributes (args) to the given cell and edges
*
@@ -168,5 +249,4 @@ public class DrawTableShape extends DrawShape {
}
}
}
-
}
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
index 1ffa3cb94c..efdd7f4dae 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
@@ -17,6 +17,7 @@
package org.apache.poi.sl.draw;
+import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.font.FontRenderContext;
@@ -45,9 +46,11 @@ import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextRun.TextCap;
import org.apache.poi.sl.usermodel.TextShape;
+import org.apache.poi.sl.usermodel.TextShape.TextDirection;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.Units;
+
public class DrawTextParagraph implements Drawable {
/** Keys for passing hyperlinks to the graphics context */
public static final XlinkAttribute HYPERLINK_HREF = new XlinkAttribute("href");
@@ -390,14 +393,13 @@ public class DrawTextParagraph implements Drawable {
* @return wrapping width in points
*/
protected double getWrappingWidth(boolean firstLine, Graphics2D graphics){
- // internal margins for the text box
+ TextShape<?,?> ts = paragraph.getParentShape();
- Insets2D insets = paragraph.getParentShape().getInsets();
+ // internal margins for the text box
+ Insets2D insets = ts.getInsets();
double leftInset = insets.left;
double rightInset = insets.right;
- Rectangle2D anchor = DrawShape.getAnchor(graphics, paragraph.getParentShape());
-
int indentLevel = paragraph.getIndentLevel();
if (indentLevel == -1) {
// default to 0, if indentLevel is not set
@@ -417,13 +419,33 @@ public class DrawTextParagraph implements Drawable {
rightMargin = 0d;
}
+ Rectangle2D anchor = DrawShape.getAnchor(graphics, ts);
+ TextDirection textDir = ts.getTextDirection();
double width;
- TextShape<?,?> ts = paragraph.getParentShape();
if (!ts.getWordWrap()) {
- // if wordWrap == false then we return the advance to the right border of the sheet
- width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX();
+ Dimension pageDim = ts.getSheet().getSlideShow().getPageSize();
+ // if wordWrap == false then we return the advance to the (right) border of the sheet
+ switch (textDir) {
+ default:
+ width = pageDim.getWidth() - anchor.getX();
+ break;
+ case VERTICAL:
+ width = pageDim.getHeight() - anchor.getX();
+ break;
+ case VERTICAL_270:
+ width = anchor.getX();
+ break;
+ }
} else {
- width = anchor.getWidth() - leftInset - rightInset - leftMargin - rightMargin;
+ switch (textDir) {
+ default:
+ width = anchor.getWidth() - leftInset - rightInset - leftMargin - rightMargin;
+ break;
+ case VERTICAL:
+ case VERTICAL_270:
+ width = anchor.getHeight() - leftInset - rightInset - leftMargin - rightMargin;
+ break;
+ }
if (firstLine && !isHSLF()) {
if (bullet != null){
if (indent > 0) width -= indent;
diff --git a/src/java/org/apache/poi/sl/draw/DrawTextShape.java b/src/java/org/apache/poi/sl/draw/DrawTextShape.java
index 24944c83b0..b1179349d7 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTextShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTextShape.java
@@ -30,6 +30,7 @@ import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.sl.usermodel.TextShape;
+import org.apache.poi.sl.usermodel.TextShape.TextDirection;
public class DrawTextShape extends DrawSimpleShape {
@@ -50,7 +51,7 @@ public class DrawTextShape extends DrawSimpleShape {
// remember the initial transform
AffineTransform tx = graphics.getTransform();
-
+
// Transform of text in flipped shapes is special.
// At this point the flip and rotation transform is already applied
// (see DrawShape#applyTransform ), but we need to restore it to avoid painting "upside down".
@@ -73,7 +74,7 @@ public class DrawTextShape extends DrawSimpleShape {
graphics.scale(-1, 1);
graphics.translate(-anchor.getX(), -anchor.getY());
}
-
+
Double textRot = s.getTextRotation();
if (textRot != null && textRot != 0) {
graphics.translate(anchor.getCenterX(), anchor.getCenterY());
@@ -98,6 +99,20 @@ public class DrawTextShape extends DrawSimpleShape {
break;
}
+ TextDirection textDir = s.getTextDirection();
+ if (textDir == TextDirection.VERTICAL || textDir == TextDirection.VERTICAL_270) {
+ double deg = (textDir == TextDirection.VERTICAL) ? 90 : 270;
+ graphics.translate(anchor.getCenterX(), anchor.getCenterY());
+ graphics.rotate(Math.toRadians(deg));
+ graphics.translate(-anchor.getCenterX(), -anchor.getCenterY());
+
+ // old top/left edge is now bottom/left or top/right - as we operate on the already
+ // rotated drawing context, both verticals can be moved in the same direction
+ double w = anchor.getWidth();
+ double h = anchor.getHeight();
+ graphics.translate((w-h)/2d,(h-w)/2d);
+ }
+
drawParagraphs(graphics, x, y);
// restore the transform
diff --git a/src/java/org/apache/poi/sl/usermodel/TableCell.java b/src/java/org/apache/poi/sl/usermodel/TableCell.java
index 0b8d7dc549..9516196de9 100644
--- a/src/java/org/apache/poi/sl/usermodel/TableCell.java
+++ b/src/java/org/apache/poi/sl/usermodel/TableCell.java
@@ -83,4 +83,32 @@ public interface TableCell<
* @param edge the border edge to be cleared
*/
void removeBorder(BorderEdge edge);
+
+ /**
+ * Get the number of columns to be spanned/merged
+ *
+ * @return the grid span
+ *
+ * @since POI 3.15-beta2
+ */
+ int getGridSpan();
+
+ /**
+ * Get the number of rows to be spanned/merged
+ *
+ * @return the row span
+ *
+ * @since POI 3.15-beta2
+ */
+ int getRowSpan();
+
+ /**
+ * Return if this cell is part of a merged cell. The top/left cell of a merged region is not regarded as merged -
+ * its grid and/or row span is greater than one.
+ *
+ * @return true if this a merged cell
+ *
+ * @since POI 3.15-beta2
+ */
+ boolean isMerged();
}