]> source.dussan.org Git - poi.git/commitdiff
Rendering of rotated group shapes fixed, other smaller fixes, defaulting to white...
authorAndreas Beeker <kiwiwings@apache.org>
Sat, 13 Jun 2015 23:26:46 +0000 (23:26 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sat, 13 Jun 2015 23:26:46 +0000 (23:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1685344 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java
src/scratchpad/src/org/apache/poi/sl/draw/DrawBackground.java
src/scratchpad/src/org/apache/poi/sl/draw/DrawShape.java
src/scratchpad/src/org/apache/poi/sl/draw/DrawSheet.java
src/scratchpad/src/org/apache/poi/sl/usermodel/PlaceableShape.java
src/scratchpad/src/org/apache/poi/sl/usermodel/ShapeType.java
src/scratchpad/src/org/apache/poi/sl/usermodel/Slide.java

index 8b5e596702fde57e5036c725c5f2c71cbf416cb3..32fec6e48caac3657ed7719cf7e2e3018d2b30cc 100644 (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;
+    }
 }
index 9f715fb389e126f03b5ea6f29775c2972978c7a5..7e2f6f01a0f9a07ab46aeca6d3fdb3116d4ad4f4 100644 (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);
index e2387510381b7cae4fd121c6e9f0072c74210c77..211bc00c06f263442d3692fea1aba2e0edf4f7fe 100644 (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; }
 
        /**
index f80bd3fc92a1385b39ab94b770c5da2db7053626..c0d381e912b21f69fb5a57c48e07fbd397fd87d2 100644 (file)
@@ -174,6 +174,11 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
         return (_headerAtom != null) ? _headerAtom.getTextType() : -1;\r
     }\r
 \r
+    public void setRunType(int runType) {\r
+        if (_headerAtom != null) _headerAtom.setTextType(runType);\r
+    }\r
+    \r
+    \r
     /**\r
      * Is this Text Run one from a {@link PPDrawing}, or is it\r
      *  one from the {@link SlideListWithText}?\r
@@ -1151,6 +1156,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
                         HSLFTextRun nextRun = new HSLFTextRun(para);\r
                         nextRun.setText("");\r
                         runs.add(nextRun);\r
+                        ccRun++;\r
                     } else {\r
                         // need to add +1 to the last run of the last paragraph\r
                         len++;\r
index 60e9eb84e26c964639eb004450f60b12d12bad8e..b9df58c43ae5b1d1babe7d44a002482d03d78a0c 100644 (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());
     }
 
     
index 30b3386266f00100679e7371d6c0fc2c59a776da..7b78c69aa363d522b841cd7ae8cd7b7d4c19428c 100644 (file)
@@ -4,6 +4,7 @@ import java.awt.*;
 import java.awt.geom.Rectangle2D;\r
 \r
 import org.apache.poi.sl.usermodel.*;\r
+import org.apache.poi.sl.usermodel.Shape;\r
 \r
 \r
 public class DrawBackground<T extends Background> extends DrawShape<T> {\r
@@ -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());\r
 \r
         PlaceableShape ps = new PlaceableShape(){\r
+            public ShapeContainer<? extends Shape> getParent() { return null; }\r
             public Rectangle2D getAnchor() { return anchor; }\r
             public void setAnchor(Rectangle2D anchor) {}\r
             public double getRotation() { return 0; }\r
index 2bebbfa892728e9dcd33e7c1b98f488d60baf8e0..70307578bfe28576f061a289928ab3894388e866 100644 (file)
@@ -4,6 +4,7 @@ import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;\r
 import java.awt.geom.Rectangle2D;\r
 \r
+import org.apache.poi.hslf.usermodel.HSLFShape;\r
 import org.apache.poi.sl.usermodel.PlaceableShape;\r
 import org.apache.poi.sl.usermodel.Shape;\r
 \r
@@ -26,9 +27,8 @@ public class DrawShape<T extends Shape> implements Drawable {
         \r
         PlaceableShape ps = (PlaceableShape)shape;\r
         AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);\r
-        final Rectangle2D anchor = (tx != null)\r
-            ? tx.createTransformedShape(ps.getAnchor()).getBounds2D()\r
-            : ps.getAnchor();\r
+        if (tx == null) tx = new AffineTransform();\r
+        final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();\r
 \r
         // rotation\r
         double rotation = ps.getRotation();\r
@@ -40,9 +40,10 @@ public class DrawShape<T extends Shape> implements Drawable {
             // normalize rotation\r
             rotation %= 360.;\r
             if (rotation < 0) rotation += 360.;\r
+\r
             int quadrant = (((int)rotation+45)/90)%4;\r
             double scaleX = 1.0, scaleY = 1.0;\r
-\r
+            \r
             // scale to bounding box (bug #53176)\r
             if (quadrant == 1 || quadrant == 3) {\r
                 // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation \r
@@ -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\r
                 // and later on, turn it around again to compare it with its original size ...\r
 \r
-                // graphics coordinate space\r
-                AffineTransform txg = new AffineTransform();\r
-                txg.translate(centerX, centerY);\r
-                txg.rotate(Math.toRadians(90));\r
-                txg.translate(-centerX, -centerY);\r
-\r
-                boolean oldVariant = true;\r
-                Rectangle2D anchor2;\r
-                \r
-                if (oldVariant) {\r
-                    // shape coordinate space\r
-                    AffineTransform txs = new AffineTransform(tx);\r
+                AffineTransform txs;\r
+                if (ps instanceof HSLFShape) {\r
+                    txs = new AffineTransform(tx);\r
+                } else {\r
+                    // this handling is only based on try and error ... not sure why xslf is handled differently.\r
+                    txs = new AffineTransform();\r
                     txs.translate(centerX, centerY);\r
-                    txs.rotate(Math.toRadians(90));\r
+                    txs.rotate(Math.PI/2.); // actually doesn't matter if +/- 90 degrees\r
                     txs.translate(-centerX, -centerY);\r
-                    txg.concatenate(txs);\r
-                    anchor2 = txg.createTransformedShape(ps.getAnchor()).getBounds2D();\r
-                } else {\r
-                    anchor2 = txg.createTransformedShape(anchor).getBounds2D();\r
+                    txs.concatenate(tx);\r
                 }\r
-\r
+                \r
+                txs.translate(centerX, centerY);\r
+                txs.rotate(Math.PI/2.);\r
+                txs.translate(-centerX, -centerY);\r
+                \r
+                Rectangle2D anchor2 = txs.createTransformedShape(ps.getAnchor()).getBounds2D();\r
+                \r
                 scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth();\r
                 scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();\r
-                \r
-                graphics.translate(centerX, centerY);\r
-                graphics.rotate(Math.toRadians(rotation-quadrant*90.));\r
-                graphics.scale(scaleX, scaleY);\r
-                graphics.rotate(Math.toRadians(quadrant*90));\r
-                graphics.translate(-centerX, -centerY);\r
             } else {\r
-                graphics.translate(centerX, centerY);\r
-                graphics.rotate(Math.toRadians(rotation));\r
-                graphics.scale(scaleX, scaleY);\r
-                graphics.translate(-centerX, -centerY);\r
+                quadrant = 0;\r
             }\r
+            \r
             // transformation is applied reversed ...\r
+            graphics.translate(centerX, centerY);\r
+            graphics.rotate(Math.toRadians(rotation-quadrant*90.));\r
+            graphics.scale(scaleX, scaleY);\r
+            graphics.rotate(Math.toRadians(quadrant*90));\r
+            graphics.translate(-centerX, -centerY);\r
         }\r
 \r
         //flip horizontal\r
index d0026f31dcef1ad8d7dc21fd4e807daaa2f90ad3..551d0527d6611923d93c508892ee17037cab9133 100644 (file)
@@ -1,6 +1,9 @@
 package org.apache.poi.sl.draw;\r
 \r
+import java.awt.Dimension;\r
+import java.awt.Color;\r
 import java.awt.Graphics2D;\r
+\r
 import java.awt.geom.AffineTransform;\r
 \r
 import org.apache.poi.sl.usermodel.*;\r
@@ -15,6 +18,11 @@ public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> im
     }\r
     \r
     public void draw(Graphics2D graphics) {\r
+        Dimension dim = sheet.getSlideShow().getPageSize();\r
+        Color whiteTrans = new Color(1f,1f,1f,0f);\r
+        graphics.setColor(whiteTrans);\r
+        graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight());\r
+        \r
         DrawFactory drawFact = DrawFactory.getInstance(graphics);\r
         MasterSheet<? extends Shape, ? extends SlideShow> master = sheet.getMasterSheet();\r
         \r
index a265e869d7b5f0bd703708e4f0d31b60d2c7ab26..f81a344b178d4e25f497b4d781dce2fb855a606b 100644 (file)
@@ -20,6 +20,8 @@ package org.apache.poi.sl.usermodel;
 import java.awt.geom.Rectangle2D;\r
 \r
 public interface PlaceableShape {\r
+    ShapeContainer<? extends Shape> getParent();\r
+    \r
     /**\r
      * @return the position of this shape within the drawing canvas.\r
      *         The coordinates are expressed in points\r
index f151e0c0822fc8969f52bd1659baf7fadf1b2bf0..91974b79dfc8fca82571bbc150ada16dc83f53e4 100644 (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;
index a9095c80ff349eaaa37c878bec903b75ad97fec1..7b238de1762b4fdec685185c06b4fa536cc81b3a 100644 (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();
 }