diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 8b5e59670..32fec6e48 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -248,4 +248,10 @@ public final class XSLFSlide extends XSLFSheet implements Slide { 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 nextRun = new HSLFTextRun(para); nextRun.setText(""); runs.add(nextRun); + ccRun++; } else { // need to add +1 to the last run of the last paragraph len++; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java index 60e9eb84e..b9df58c43 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java @@ -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 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 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()); } diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawBackground.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawBackground.java index 30b338626..7b78c69aa 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawBackground.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawBackground.java @@ -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 extends DrawShape { @@ -16,6 +17,7 @@ public class DrawBackground extends DrawShape { final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight()); PlaceableShape ps = new PlaceableShape(){ + public ShapeContainer getParent() { return null; } public Rectangle2D getAnchor() { return anchor; } public void setAnchor(Rectangle2D anchor) {} public double getRotation() { return 0; } diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawShape.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawShape.java index 2bebbfa89..70307578b 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawShape.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawShape.java @@ -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 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 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 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 diff --git a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java index d0026f31d..551d0527d 100644 --- a/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java +++ b/src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java @@ -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> 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 master = sheet.getMasterSheet(); diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/PlaceableShape.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/PlaceableShape.java index a265e869d..f81a344b1 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/PlaceableShape.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/PlaceableShape.java @@ -20,6 +20,8 @@ package org.apache.poi.sl.usermodel; import java.awt.geom.Rectangle2D; public interface PlaceableShape { + ShapeContainer getParent(); + /** * @return the position of this shape within the drawing canvas. * The coordinates are expressed in points diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java index f151e0c08..91974b79d 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java @@ -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; diff --git a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java index a9095c80f..7b238de17 100644 --- a/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java +++ b/src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java @@ -29,4 +29,9 @@ public interface Slide