poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1198658 [1/5] - in /poi/trunk: ./ src/examples/src/org/apache/poi/xslf/usermodel/tutorial/ src/ooxml/java/org/apache/poi/xslf/extractor/ src/ooxml/java/org/apache/poi/xslf/model/geom/ src/ooxml/java/org/apache/poi/xslf/usermodel/ src/ooxml...
Date Mon, 07 Nov 2011 09:12:18 GMT
Author: yegor
Date: Mon Nov  7 09:12:16 2011
New Revision: 1198658

URL: http://svn.apache.org/viewvc?rev=1198658&view=rev
Log:
more progress with xlsf: support for gradient and texture fills, backgrounds, improved drawing of preset shapes and many more updates ...

Added:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/SlideLayout.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java
    poi/trunk/src/resources/ooxml/
    poi/trunk/src/resources/ooxml/org/
    poi/trunk/src/resources/ooxml/org/apache/
    poi/trunk/src/resources/ooxml/org/apache/poi/
    poi/trunk/src/resources/ooxml/org/apache/poi/xslf/
    poi/trunk/src/resources/ooxml/org/apache/poi/xslf/usermodel/
    poi/trunk/src/resources/ooxml/org/apache/poi/xslf/usermodel/empty.pptx   (with props)
    poi/trunk/src/resources/ooxml/org/apache/poi/xslf/usermodel/presetShapeDefinitions.xml   (with props)
    poi/trunk/test-data/slideshow/pptx2svg.pptx   (with props)
    poi/trunk/test-data/slideshow/pptx2svg.svg
    poi/trunk/test-data/slideshow/themes.pptx   (with props)
Removed:
    poi/trunk/src/resources/scratchpad/org/apache/poi/xslf/
Modified:
    poi/trunk/build.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRendener.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRenderingHint.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestFormulaParser.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/geom/TestPresetGeometries.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlide.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Mon Nov  7 09:12:16 2011
@@ -108,6 +108,7 @@ under the License.
 
     <!-- OOXML support: -->
     <property name="ooxml.src" location="src/ooxml/java"/>
+    <property name="ooxml.resource1.dir" value="src/resources/ooxml"/>
     <property name="ooxml.src.test" location="src/ooxml/testcases"/>
     <property name="ooxml.reports.test" location="build/ooxml-test-results"/>
     <property name="ooxml.output.dir" location="build/ooxml-classes"/>
@@ -553,6 +554,9 @@ under the License.
                 <pathelement path="${main.output.test.dir}"/>
             </classpath>
         </javac>
+        <copy todir="${ooxml.output.dir}">
+            <fileset dir="${ooxml.resource1.dir}"/>
+        </copy>
     </target>
 
     <target name="compile-excelant" depends="compile-main,compile-ooxml">

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java?rev=1198658&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java Mon Nov  7 09:12:16 2011
@@ -0,0 +1,68 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.usermodel.tutorial;
+
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFShape;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
+import org.apache.poi.xslf.usermodel.XSLFTextRun;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
+
+import java.io.FileInputStream;
+
+/**
+ * Reading a .pptx presentation and printing basic shape properties
+ *
+ * @author Yegor Kozlov
+ */
+public class Step1 {
+
+    public static void main(String[] args) throws Exception {
+        if(args.length == 0)  {
+            System.out.println("Input file is required");
+            return;
+        }
+
+        XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(args[0]));
+
+        for(XSLFSlide slide : ppt.getSlides()){
+            System.out.println("Title: " + slide.getTitle());
+
+            for(XSLFShape shape : slide.getShapes()){
+                if(shape instanceof XSLFTextShape) {
+                    XSLFTextShape tsh = (XSLFTextShape)shape;
+                    for(XSLFTextParagraph p : tsh){
+                        System.out.println("Paragraph level: " + p.getLevel());
+                        for(XSLFTextRun r : p){
+                            System.out.println(r.getText());
+                            System.out.println("  bold: " + r.isBold());
+                            System.out.println("  italic: " + r.isItalic());
+                            System.out.println("  underline: " + r.isUnderline());
+                            System.out.println("  font.family: " + r.getFontFamily());
+                            System.out.println("  font.size: " + r.getFontSize());
+                            System.out.println("  font.color: " + r.getFontColor());
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java?rev=1198658&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java Mon Nov  7 09:12:16 2011
@@ -0,0 +1,80 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.usermodel.tutorial;
+
+import org.apache.poi.xslf.usermodel.SlideLayout;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
+import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
+
+import java.io.FileOutputStream;
+
+/**
+ * Create slides from pre-defined slide layouts
+ *
+ * @author Yegor Kozlov
+ */
+public class Step2 {
+    public static void main(String[] args) throws Exception{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+
+        // first see what slide layouts are available by default
+        System.out.println("Available slide layouts:");
+        for(XSLFSlideMaster master : ppt.getSlideMasters()){
+            for(XSLFSlideLayout layout : master.getSlideLayouts()){
+                System.out.println(layout.getType());
+            }
+        }
+
+        // blank slide
+        XSLFSlide blankSlide = ppt.createSlide();
+
+        XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
+
+        // title slide
+        XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
+        XSLFSlide slide1 = ppt.createSlide(titleLayout);
+        XSLFTextShape title1 = slide1.getPlaceholder(0);
+        title1.setText("First Title");
+
+        // title and content
+        XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
+        XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);
+
+        XSLFTextShape title2 = slide2.getPlaceholder(0);
+        title2.setText("Second Title");
+
+        XSLFTextShape body2 = slide2.getPlaceholder(1);
+        body2.clearText(); // unset any existing text
+        body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
+        body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
+        body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
+
+
+
+        FileOutputStream out = new FileOutputStream("step2.pptx");
+        ppt.write(out);
+        out.close();
+
+    }
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java Mon Nov  7 09:12:16 2011
@@ -128,7 +128,7 @@ public class XSLFPowerPointExtractor ext
             XSLFNotes notes = slide.getNotes();
             XSLFComments comments = slide.getComments();
             XSLFSlideLayout layout = slide.getSlideLayout();
-            XSLFSlideMaster master = slide.getMasterSheet();
+            XSLFSlideMaster master = layout.getSlideMaster();
 
             // TODO Do the slide's name
             // (Stored in docProps/app.xml)

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java Mon Nov  7 09:12:16 2011
@@ -57,15 +57,11 @@ public class ArcToCommand implements Pat
         double x0 = pt.getX() - rx - rx * Math.cos(Math.toRadians(start));
         double y0 = pt.getY() - ry - ry * Math.sin(Math.toRadians(start));
 
-        if(start == 180 && extent == 180) {
-            x0 -= rx*2;   //YK: TODO revisit the code and get rid of this hack
-        }
-
         Arc2D arc = new Arc2D.Double(
                          x0,
                          y0,
                          2 * rx, 2 * ry,
-                         -start, -extent, // negate angles because DrawingML rotates counter-clockwise
+                         -start, -extent, 
                          Arc2D.OPEN);
 		path.append(arc, true);
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java Mon Nov  7 09:12:16 2011
@@ -29,17 +29,19 @@ import java.util.Map;
  * @author Yegor Kozlov
  */
 public class Context {
-    Map<String, Double> _ctx = new HashMap<String, Double>();
-    IAdjustableShape _props;
-
-   public Context(CustomGeometry geom, IAdjustableShape props){
+    final Map<String, Double> _ctx = new HashMap<String, Double>();
+    final IAdjustableShape _props;
+    final Rectangle2D _anchor;
+    
+    public Context(CustomGeometry geom, Rectangle2D anchor, IAdjustableShape props){
         _props = props;
+        _anchor = anchor;
         for(Guide gd : geom.adjusts) evaluate(gd);
         for(Guide gd : geom.guides) evaluate(gd);
     }
 
     public Rectangle2D getShapeAnchor(){
-        return _props.getAnchor();
+        return _anchor;
     }
 
     public Guide getAdjustValue(String name){

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java Mon Nov  7 09:12:16 2011
@@ -24,6 +24,7 @@ import org.openxmlformats.schemas.drawin
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.awt.geom.Rectangle2D;
 
 /**
  * Definition of a custom geometric shape
@@ -34,8 +35,9 @@ public class CustomGeometry implements I
     List<Guide> adjusts = new ArrayList<Guide>();
     List<Guide> guides = new ArrayList<Guide>();
     List<Path> paths = new ArrayList<Path>();
+    Path textBounds;
 
-    public CustomGeometry(CTCustomGeometry2D geom){
+    public CustomGeometry(CTCustomGeometry2D geom) {
         CTGeomGuideList avLst = geom.getAvLst();
         if(avLst != null) for(CTGeomGuide gd : avLst.getGdList()){
             adjusts.add(new AdjustValue(gd));
@@ -50,6 +52,21 @@ public class CustomGeometry implements I
         if(pathLst != null) for(CTPath2D spPath : pathLst.getPathList()){
             paths.add(new Path(spPath));
         }
+
+        if(geom.isSetRect()) {
+            CTGeomRect rect = geom.getRect();
+            textBounds = new Path();
+            textBounds.addCommand(
+                    new MoveToCommand(rect.getL().toString(), rect.getT().toString()));
+            textBounds.addCommand(
+                    new LineToCommand(rect.getR().toString(), rect.getT().toString()));
+            textBounds.addCommand(
+                    new LineToCommand(rect.getR().toString(), rect.getB().toString()));
+            textBounds.addCommand(
+                    new LineToCommand(rect.getL().toString(), rect.getB().toString()));
+            textBounds.addCommand(
+                    new ClosePathCommand());
+        }
     }
 
 
@@ -58,4 +75,7 @@ public class CustomGeometry implements I
         return paths.iterator();
     }
 
+    public Path getTextBounds(){
+        return textBounds;        
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java Mon Nov  7 09:12:16 2011
@@ -19,7 +19,6 @@
 
 package org.apache.poi.xslf.model.geom;
 
-import java.awt.geom.Rectangle2D;
 
 /**
  * A bridge to the consumer application.
@@ -31,12 +30,6 @@ import java.awt.geom.Rectangle2D;
 public interface IAdjustableShape {
     /**
      *
-     * @return bounds of the shape
-     */
-    Rectangle2D getAnchor();
-
-    /**
-     *
      * @param  name name of a adjust value, e.g. adj1
      * @return adjust guide defined in the shape or null
      */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java Mon Nov  7 09:12:16 2011
@@ -36,6 +36,11 @@ public class LineToCommand implements Pa
         arg2 = pt.getY().toString();
     }
 
+    LineToCommand(String s1, String s2){
+        arg1 = s1;
+        arg2 = s2;
+    }
+
     public void execute(GeneralPath path, Context ctx){
         double x = ctx.getValue(arg1);
         double y = ctx.getValue(arg2);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java Mon Nov  7 09:12:16 2011
@@ -36,6 +36,11 @@ public class MoveToCommand implements Pa
         arg2 = pt.getY().toString();
     }
 
+    MoveToCommand(String s1, String s2){
+        arg1 = s1;
+        arg2 = s2;
+    }
+
     public void execute(GeneralPath path, Context ctx){
         double x = ctx.getValue(arg1);
         double y = ctx.getValue(arg2);

Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java?rev=1198658&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java Mon Nov  7 09:12:16 2011
@@ -0,0 +1,45 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.model.geom;
+
+import java.awt.Shape;
+
+/**
+* Date: 11/6/11
+*
+* @author Yegor Kozlov
+*/
+public class Outline {
+    private Shape shape;
+    private Path path;
+
+    public Outline(Shape shape, Path path){
+        this.shape = shape;
+        this.path = path;
+    }
+
+    public Path getPath(){
+        return path;
+    }
+
+    public Shape getOutline(){
+        return shape;
+    }
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java Mon Nov  7 09:12:16 2011
@@ -39,11 +39,26 @@ import java.util.List;
 public class Path {
     private final List<PathCommand> commands;
     boolean _fill, _stroke;
+    long _w, _h;
+
+    public Path(){
+        this(true, true);
+    }
+
+    public Path(boolean fill, boolean stroke){
+        commands = new ArrayList<PathCommand>();
+        _w = -1;
+        _h = -1;
+        _fill = fill;
+        _stroke = stroke;
+    }
 
     public Path(CTPath2D spPath){
         _fill = spPath.getFill() != STPathFillMode.NONE;
         _stroke = spPath.getStroke();
-
+        _w = spPath.isSetW() ? spPath.getW() : -1;	
+        _h = spPath.isSetH() ? spPath.getH() : -1;	
+        
         commands = new ArrayList<PathCommand>();
         for(XmlObject ch : spPath.selectPath("*")){
             if(ch instanceof CTPath2DMoveTo){
@@ -74,6 +89,13 @@ public class Path {
         }
     }
 
+    public void addCommand(PathCommand cmd){
+        commands.add(cmd);
+    }
+
+    /**
+     * Convert the internal represenation to java.awt.GeneralPath
+     */
     public GeneralPath getPath(Context ctx) {
         GeneralPath path = new GeneralPath();
         for(PathCommand cmd : commands)
@@ -88,4 +110,12 @@ public class Path {
     public boolean isFilled(){
         return _fill;
     }
+    
+    public long getW(){
+    	return _w;
+    }
+
+    public long getH(){
+    	return _h;
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/Placeholder.java Mon Nov  7 09:12:16 2011
@@ -30,7 +30,7 @@ public enum Placeholder {
     SLIDE_NUMBER,
     FOOTER,
     HEADER,
-    OBJECT,
+    CONTENT,
     CHART,
     TABLE,
     CLIP_ART,
@@ -38,5 +38,4 @@ public enum Placeholder {
     MEDIA,
     SLIDE_IMAGE,
     PICTURE
-
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java Mon Nov  7 09:12:16 2011
@@ -1,11 +1,563 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
 package org.apache.poi.xslf.usermodel;
 
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
+import org.apache.poi.xslf.model.PropertyFetcher;
+import org.apache.poi.xslf.model.geom.Context;
+import org.apache.poi.xslf.model.geom.CustomGeometry;
+import org.apache.poi.xslf.model.geom.Guide;
+import org.apache.poi.xslf.model.geom.IAdjustableShape;
+import org.apache.poi.xslf.model.geom.Outline;
+import org.apache.poi.xslf.model.geom.Path;
+import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPathShadeProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.TexturePaint;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+
 /**
- * Created by IntelliJ IDEA.
- * User: yegor
- * Date: Oct 27, 2011
- * Time: 4:50:08 PM
- * To change this template use File | Settings | File Templates.
+ * Encapsulates logic to translate DrawingML objects to Java2D
  */
+@Internal
 class RenderableShape {
+    public final static Color NO_PAINT = new Color(0xFF, 0xFF, 0xFF, 0);
+
+    private XSLFSimpleShape _shape;
+
+    public RenderableShape(XSLFSimpleShape shape){
+        _shape = shape;
+    }
+
+    /**
+     * Convert shape fill into java.awt.Paint. The result is either Color or
+     * TexturePaint or GradientPaint or null
+     *
+     * @param graphics  the target graphics
+     * @param obj       the xml to read. Must contain elements from the EG_ColorChoice group:
+     * <code>
+     *     a:scrgbClr    RGB Color Model - Percentage Variant
+     *     a:srgbClr    RGB Color Model - Hex Variant
+     *     a:hslClr    Hue, Saturation, Luminance Color Model
+     *     a:sysClr    System Color
+     *     a:schemeClr    Scheme Color
+     *     a:prstClr    Preset Color
+     *  </code>
+     *
+     * @param phClr     context color
+     * @param parentPart    the parent package part. Any external references (images, etc.) are resolved relative to it.
+     *
+     * @return  the applied Paint or null if none was applied
+     */
+    public Paint selectPaint(Graphics2D graphics, XmlObject obj, CTSchemeColor phClr, PackagePart parentPart) {
+        XSLFTheme theme = _shape.getSheet().getTheme();
+        Rectangle2D anchor = _shape.getAnchor();
+
+        Paint paint = null;
+        if (obj instanceof CTNoFillProperties) {
+            paint = NO_PAINT;
+
+        }
+        else if (obj instanceof CTSolidColorFillProperties) {
+            CTSolidColorFillProperties solidFill = (CTSolidColorFillProperties) obj;
+            XSLFColor c = new XSLFColor(solidFill, theme, phClr);
+            paint = c.getColor();
+        }
+        else if (obj instanceof CTBlipFillProperties) {
+            CTBlipFillProperties blipFill = (CTBlipFillProperties)obj;
+            paint = createTexturePaint(blipFill, graphics, parentPart);
+        }
+        else if (obj instanceof CTGradientFillProperties) {
+            CTGradientFillProperties gradFill = (CTGradientFillProperties) obj;
+            if (gradFill.isSetLin()) {
+                 paint = createLinearGradientPaint(gradFill, anchor, theme, phClr);
+            } else if (gradFill.isSetPath()){
+                CTPathShadeProperties ps = gradFill.getPath();
+                if(ps.getPath() ==  STPathShadeType.CIRCLE){
+                    paint = createRadialGradientPaint(gradFill, anchor, theme, phClr);
+                }
+            }
+        }
+
+        return paint;
+    }
+
+    private Paint createTexturePaint(CTBlipFillProperties blipFill, Graphics2D graphics,
+            PackagePart parentPart){
+        Paint paint = null;
+        CTBlip blip = blipFill.getBlip();
+        String blipId = blip.getEmbed();
+        PackageRelationship rel = parentPart.getRelationship(blipId);
+        if (rel != null) {
+            XSLFImageRendener renderer = null;
+            if (graphics != null)
+                renderer = (XSLFImageRendener) graphics.getRenderingHint(XSLFRenderingHint.IMAGE_RENDERER);
+            if (renderer == null) renderer = new XSLFImageRendener();
+
+            try {
+                BufferedImage img = renderer.readImage(parentPart.getRelatedPart(rel));
+                if (blip.sizeOfAlphaModFixArray() > 0) {
+                    float alpha = blip.getAlphaModFixArray(0).getAmt() / 100000.f;
+                    AlphaComposite ac = AlphaComposite.getInstance(
+                            AlphaComposite.SRC_OVER, alpha);
+                    if (graphics != null) graphics.setComposite(ac);
+                }
+
+                if(img != null) {
+                    paint = new TexturePaint(
+                            img, new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()));
+                }
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return paint;
+    }
+
+    private static Paint createLinearGradientPaint(
+            CTGradientFillProperties gradFill, Rectangle2D anchor,
+            XSLFTheme theme, CTSchemeColor phClr) {
+        double angle = gradFill.getLin().getAng() / 60000;
+        CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
+
+        Arrays.sort(gs, new Comparator<CTGradientStop>() {
+            public int compare(CTGradientStop o1, CTGradientStop o2) {
+                Integer pos1 = o1.getPos();
+                Integer pos2 = o2.getPos();
+                return pos1.compareTo(pos2);
+            }
+        });
+
+        Color[] colors = new Color[gs.length];
+        float[] fractions = new float[gs.length];
+
+        AffineTransform at = AffineTransform.getRotateInstance(
+                Math.toRadians(angle),
+                anchor.getX() + anchor.getWidth() / 2,
+                anchor.getY() + anchor.getHeight() / 2);
+
+        double diagonal = Math.sqrt(anchor.getHeight() * anchor.getHeight() + anchor.getWidth() * anchor.getWidth());
+        Point2D p1 = new Point2D.Double(anchor.getX() + anchor.getWidth() / 2 - diagonal / 2,
+                anchor.getY() + anchor.getHeight() / 2);
+        p1 = at.transform(p1, null);
+
+        Point2D p2 = new Point2D.Double(anchor.getX() + anchor.getWidth(), anchor.getY() + anchor.getHeight() / 2);
+        p2 = at.transform(p2, null);
+
+        snapToAnchor(p1, anchor);
+        snapToAnchor(p2, anchor);
+
+        for (int i = 0; i < gs.length; i++) {
+            CTGradientStop stop = gs[i];
+            colors[i] = new XSLFColor(stop, theme, phClr).getColor();
+            fractions[i] = stop.getPos() / 100000.f;
+        }
+
+        // Trick to return GradientPaint on JDK 1.5 and LinearGradientPaint on JDK 1.6+
+        Paint paint;
+        try {
+            Class clz = Class.forName("java.awt.LinearGradientPaint");
+            Constructor c =
+                    clz.getConstructor(Point2D.class, Point2D.class, float[].class, Color[].class);
+            paint = (Paint) c.newInstance(p1, p2, fractions, colors);
+        } catch (ClassNotFoundException e) {
+            paint = new GradientPaint(p1, colors[0], p2, colors[colors.length - 1]);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return paint;
+    }
+
+    private static Paint createRadialGradientPaint(
+            CTGradientFillProperties gradFill, Rectangle2D anchor,
+            XSLFTheme theme, CTSchemeColor phClr) {
+        CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
+
+        Point2D pCenter = new Point2D.Double(anchor.getX() + anchor.getWidth()/2,
+                anchor.getY() + anchor.getHeight()/2);
+
+        float radius = (float)Math.max(anchor.getWidth(), anchor.getHeight());
+
+        Arrays.sort(gs, new Comparator<CTGradientStop>() {
+            public int compare(CTGradientStop o1, CTGradientStop o2) {
+                Integer pos1 = o1.getPos();
+                Integer pos2 = o2.getPos();
+                return pos1.compareTo(pos2);
+            }
+        });
+
+        Color[] colors = new Color[gs.length];
+        float[] fractions = new float[gs.length];
+
+
+        for (int i = 0; i < gs.length; i++) {
+            CTGradientStop stop = gs[i];
+            colors[i] = new XSLFColor(stop, theme, phClr).getColor();
+            fractions[i] = stop.getPos() / 100000.f;
+        }
+
+        // Trick to return GradientPaint on JDK 1.5 and RadialGradientPaint on JDK 1.6+
+        Paint paint;
+        try {
+            Class clz = Class.forName("java.awt.RadialGradientPaint");
+            Constructor c =
+                    clz.getConstructor(Point2D.class, float.class,
+                            float[].class, Color[].class);
+            paint = (Paint) c.newInstance(pCenter, radius, fractions, colors);
+        } catch (ClassNotFoundException e) {
+            // the result on JDK 1.5 is incorrect, but it is better than nothing
+            paint = new GradientPaint(
+                    new Point2D.Double(anchor.getX(), anchor.getY()),
+                    colors[0], pCenter, colors[colors.length - 1]);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return paint;
+    }
+
+    private static void snapToAnchor(Point2D p, Rectangle2D anchor) {
+        if (p.getX() < anchor.getX()) {
+            p.setLocation(anchor.getX(), p.getY());
+        } else if (p.getX() > (anchor.getX() + anchor.getWidth())) {
+            p.setLocation(anchor.getX() + anchor.getWidth(), p.getY());
+        }
+
+        if (p.getY() < anchor.getY()) {
+            p.setLocation(p.getX(), anchor.getY());
+        } else if (p.getY() > (anchor.getY() + anchor.getHeight())) {
+            p.setLocation(p.getX(), anchor.getY() + anchor.getHeight());
+        }
+    }
+
+
+    @SuppressWarnings("deprecation") //  getXYZArray() array accessors are deprecated
+    Paint getPaint(Graphics2D graphics, XmlObject spPr, CTSchemeColor phClr) {
+
+        Paint paint = null;
+        for (XmlObject obj : spPr.selectPath("*")) {
+            paint = selectPaint(graphics, obj, phClr, _shape.getSheet().getPackagePart());
+            if(paint != null) break;
+        }
+        return paint == NO_PAINT ? null : paint;
+    }
+
+
+    /**
+     * fetch shape fill as a java.awt.Paint
+     *
+     * @return either Color or GradientPaint or TexturePaint or null
+     */
+    Paint getFillPaint(final Graphics2D graphics) {
+        PropertyFetcher<Paint> fetcher = new PropertyFetcher<Paint>() {
+            public boolean fetch(XSLFSimpleShape shape) {
+                CTShapeProperties spPr = shape.getSpPr();
+                if (spPr.isSetNoFill()) {
+                    setValue(RenderableShape.NO_PAINT); // use it as 'nofill' value
+                    return true;
+                }
+                Paint paint = getPaint(graphics, spPr, null);
+                if (paint != null) {
+                    setValue(paint);
+                    return true;
+                }
+                return false;
+            }
+        };
+        _shape.fetchShapeProperty(fetcher);
+
+        Paint paint = fetcher.getValue();
+        if (paint == null) {
+            // fill color was not found, check if it is defined in the theme
+            CTShapeStyle style = _shape.getSpStyle();
+            if (style != null) {
+                // get a reference to a fill style within the style matrix.
+                CTStyleMatrixReference fillRef = style.getFillRef();
+                // The idx attribute refers to the index of a fill style or
+                // background fill style within the presentation's style matrix, defined by the fmtScheme element.
+                // value of 0 or 1000 indicates no background,
+                // values 1-999 refer to the index of a fill style within the fillStyleLst element
+                // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
+                int idx = (int)fillRef.getIdx();
+                CTSchemeColor phClr = fillRef.getSchemeClr();
+                XSLFSheet sheet = _shape.getSheet();
+                XSLFTheme theme = sheet.getTheme();
+                XmlObject fillProps = null;
+                if(idx >= 1 && idx <= 999){
+                    fillProps = theme.getXmlObject().
+                            getThemeElements().getFmtScheme().getFillStyleLst().selectPath("*")[idx - 1];
+                } else if (idx >= 1001 ){
+                    fillProps = theme.getXmlObject().
+                            getThemeElements().getFmtScheme().getBgFillStyleLst().selectPath("*")[idx - 1001];
+                }
+                if(fillProps != null) {
+                    paint = selectPaint(graphics, fillProps, phClr, sheet.getPackagePart());
+                }
+            }
+        }
+        return paint == RenderableShape.NO_PAINT ? null : paint;
+    }
+
+    public Paint getLinePaint(final Graphics2D graphics) {
+        PropertyFetcher<Paint> fetcher = new PropertyFetcher<Paint>() {
+            public boolean fetch(XSLFSimpleShape shape) {
+                CTLineProperties spPr = shape.getSpPr().getLn();
+                if (spPr != null) {
+                    if (spPr.isSetNoFill()) {
+                        setValue(NO_PAINT); // use it as 'nofill' value
+                        return true;
+                    }
+                    Paint paint = getPaint(graphics, spPr, null);
+                    if (paint != null) {
+                        setValue(paint);
+                        return true;
+                    }
+                }
+                return false;
+
+            }
+        };
+        _shape.fetchShapeProperty(fetcher);
+
+        Paint paint = fetcher.getValue();
+        if (paint == null) {
+            // line color was not found, check if it is defined in the theme
+            CTShapeStyle style = _shape.getSpStyle();
+            if (style != null) {
+                // get a reference to a line style within the style matrix.
+                CTStyleMatrixReference lnRef = style.getLnRef();
+                int idx = (int)lnRef.getIdx();
+                CTSchemeColor phClr = lnRef.getSchemeClr();
+                if(idx > 0){
+                    XSLFTheme theme = _shape.getSheet().getTheme();
+                    XmlObject lnProps = theme.getXmlObject().
+                            getThemeElements().getFmtScheme().getLnStyleLst().selectPath("*")[idx - 1];
+                    paint = getPaint(graphics, lnProps, phClr);
+                }
+            }
+        }
+
+        return paint == NO_PAINT ? null : paint;
+    }
+
+    /**
+     * convert PPT dash into java.awt.BasicStroke
+     *
+     * The mapping is derived empirically on PowerPoint 2010
+     */
+    private static float[] getDashPattern(LineDash lineDash, float lineWidth) {
+        float[] dash = null;
+        switch (lineDash) {
+            case SYS_DOT:
+                dash = new float[]{lineWidth, lineWidth};
+                break;
+            case SYS_DASH:
+                dash = new float[]{2 * lineWidth, 2 * lineWidth};
+                break;
+            case DASH:
+                dash = new float[]{3 * lineWidth, 4 * lineWidth};
+                break;
+            case DASH_DOT:
+                dash = new float[]{4 * lineWidth, 3 * lineWidth, lineWidth,
+                        3 * lineWidth};
+                break;
+            case LG_DASH:
+                dash = new float[]{8 * lineWidth, 3 * lineWidth};
+                break;
+            case LG_DASH_DOT:
+                dash = new float[]{8 * lineWidth, 3 * lineWidth, lineWidth,
+                        3 * lineWidth};
+                break;
+            case LG_DASH_DOT_DOT:
+                dash = new float[]{8 * lineWidth, 3 * lineWidth, lineWidth,
+                        3 * lineWidth, lineWidth, 3 * lineWidth};
+                break;
+        }
+        return dash;
+    }
+
+
+    public Stroke applyStroke(Graphics2D graphics) {
+
+        float lineWidth = (float) _shape.getLineWidth();
+        LineDash lineDash = _shape.getLineDash();
+        float[] dash = null;
+        float dash_phase = 0;
+        if (lineDash != null) {
+            dash = getDashPattern(lineDash, lineWidth);
+        }
+
+        int cap = BasicStroke.CAP_BUTT;
+        LineCap lineCap = _shape.getLineCap();
+        if (lineCap != null) {
+            switch (lineCap) {
+                case ROUND:
+                    cap = BasicStroke.CAP_ROUND;
+                    break;
+                case SQUARE:
+                    cap = BasicStroke.CAP_SQUARE;
+                    break;
+                default:
+                    cap = BasicStroke.CAP_BUTT;
+                    break;
+            }
+        }
+
+        int meter = BasicStroke.JOIN_ROUND;
+
+        Stroke stroke = new BasicStroke(lineWidth, cap, meter, Math.max(1, lineWidth), dash,
+                dash_phase);
+        graphics.setStroke(stroke);
+        return stroke;
+    }
+
+    public void render(Graphics2D graphics){
+        Collection<Outline> elems = computeOutlines();
+
+        // shadow
+        XSLFShadow shadow = _shape.getShadow();
+
+        // first fill
+        Paint fill = getFillPaint(graphics);
+        if(fill != null) for(Outline o : elems){
+            if(o.getPath().isFilled()){
+                if(shadow != null) shadow.fill(graphics, o.getOutline());
+
+                graphics.setPaint(fill);
+                graphics.fill(o.getOutline());
+            }
+        }
+
+        // then draw any content within this shape (text, image, etc.)
+        _shape.drawContent(graphics);
+
+        // then stroke the shape outline
+        Paint line = getLinePaint(graphics);
+        if(line != null) for(Outline o : elems){
+            if(o.getPath().isStroked()){
+                applyStroke(graphics); // the stroke applies both to the shadow and the shape
+
+                if(shadow != null) shadow.draw(graphics, o.getOutline());
+
+                graphics.setPaint(line);
+                graphics.draw(o.getOutline());
+            }
+        }
+    }
+
+    private Collection<Outline> computeOutlines() {
+        CustomGeometry geom = _shape.getGeometry();
+
+        Collection<Outline> lst = new ArrayList<Outline>();
+
+        Rectangle2D anchor = _shape.getAnchor();
+        for (Path p : geom) {
+
+            double w = p.getW() == -1 ? anchor.getWidth() * Units.EMU_PER_POINT : p.getW();
+            double h = p.getH() == -1 ? anchor.getHeight() * Units.EMU_PER_POINT : p.getH();
+
+            // the guides in the shape definitions are all defined relative to each other,
+            // so we build the path starting from (0,0).
+            final Rectangle2D pathAnchor = new Rectangle2D.Double(
+                    0,
+                    0,
+                    w,
+                    h
+            );
+
+            Context ctx = new Context(geom, pathAnchor, new IAdjustableShape() {
+
+                public Guide getAdjustValue(String name) {
+                    CTPresetGeometry2D prst = _shape.getSpPr().getPrstGeom();
+                    if (prst.isSetAvLst()) {
+                        for (CTGeomGuide g : prst.getAvLst().getGdList()) {
+                            if (g.getName().equals(name)) {
+                                return new Guide(g);
+                            }
+                        }
+                    }
+                    return null;
+                }
+            }) ;
+
+            Shape gp = p.getPath(ctx);
+
+            // translate the result to the canvas coordinates in points
+            AffineTransform at = new AffineTransform();
+            at.translate(anchor.getX(), anchor.getY());
+
+            double scaleX, scaleY;
+            if (p.getW() != -1) {
+                scaleX = anchor.getWidth() / p.getW();
+            } else {
+                scaleX = 1.0 / Units.EMU_PER_POINT;
+            }
+            if (p.getH() != -1) {
+                scaleY = anchor.getHeight() / p.getH();
+            } else {
+                scaleY = 1.0 / Units.EMU_PER_POINT;
+            }
+
+            at.scale(scaleX, scaleY);
+
+            Shape canvasShape = at.createTransformedShape(gp);
+
+            lst.add(new Outline(canvasShape, p));
+        }
+
+        // add any shape-specific stuff here (line decorations, etc.)
+        lst.addAll(_shape.getCustomOutlines());
+        return lst;
+    }
+
 }

Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/SlideLayout.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/SlideLayout.java?rev=1198658&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/SlideLayout.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/SlideLayout.java Mon Nov  7 09:12:16 2011
@@ -0,0 +1,99 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.usermodel;
+
+/**
+ * Date: 11/5/11
+ *
+ * @author Yegor Kozlov
+ */
+public enum SlideLayout {
+    /**
+     * Title layout with centered title and subtitle placeholders
+     */
+    TITLE,
+    /**
+     * Title and text
+     */
+    TEXT,
+
+    TWO_COL_TX,
+    TBL,
+    TEXT_AND_CHART,
+
+    /**
+     * Title, chart on left and text on right
+     */
+    CHART_AND_TEXT,
+
+    DGM,
+
+    /**
+     * Title and chart
+     */
+    CHART,
+
+    TX_AND_CLIP_ART,
+    /**
+     * Title, clipart on left, text on right
+     */
+    CLIP_ART_AND_TEXT,
+
+    /**
+     * Title only
+     */
+    TITLE_ONLY,
+
+    /**
+     * Blank
+     */
+    BLANK,
+
+    TX_AND_OBJ,
+    OBJ_AND_TX,
+    OBJ_ONLY,
+    /**
+     * title and content
+     */
+    TITLE_AND_CONTENT,
+    TX_AND_MEDIA,
+    MEDIA_AND_TX,
+    OBJ_OVER_TX,
+    TX_OVER_OBJ,
+    TX_AND_TWO_OBJ,
+    TWO_OBJ_AND_TX,
+    TWO_OBJ_OVER_TX,
+    FOUR_OBJ,
+    VERT_TX,
+    CLIP_ART_AND_VERT_TX,
+    VERT_TITLE_AND_TX,
+    VERT_TITLE_AND_TX_OVER_CHART,
+    TWO_OBJ,
+    OBJ_AND_TWO_OBJ,
+    TWO_OBJ_AND_OBJ,
+    CUST,
+    /**
+     * Section Header
+     */
+    SECTION_HEADER,
+    TWO_TX_TWO_OBJ,
+    OBJ_TX,
+    PIC_TX,
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java Mon Nov  7 09:12:16 2011
@@ -43,5 +43,8 @@ public enum TextAlign {
      * is smart in the sense that it will not justify sentences
      * which are short
      */
-    JUSTIFY
+    JUSTIFY,
+    JUSTIFY_LOW,
+    DIST,
+    THAI_DIST
 }

Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java?rev=1198658&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java Mon Nov  7 09:12:16 2011
@@ -0,0 +1,33 @@
+/*
+ *  ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one or more
+ *    contributor license agreements.  See the NOTICE file distributed with
+ *    this work for additional information regarding copyright ownership.
+ *    The ASF licenses this file to You under the Apache License, Version 2.0
+ *    (the "License"); you may not use this file except in compliance with
+ *    the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.usermodel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: yegor
+ * Date: 11/3/11
+ * Time: 5:07 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public enum TextCap {
+    NONE,
+    SMALL,
+    ALL
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Mon Nov  7 09:12:16 2011
@@ -40,7 +40,7 @@ import org.openxmlformats.schemas.presen
 import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
 import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
 
-import java.awt.*;
+import java.awt.Dimension;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -190,7 +190,13 @@ public class XMLSlideShow  extends POIXM
         return Collections.unmodifiableList(_pictures);
     }
 
-    public XSLFSlide createSlide() {
+    /**
+     * Create a slide and initialize it from the specified layout.
+     *
+     * @param layout
+     * @return created slide
+     */
+    public XSLFSlide createSlide(XSLFSlideLayout layout) {
         int slideNumber = 256, cnt = 1;
         CTSlideIdList slideList;
         if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
@@ -209,12 +215,7 @@ public class XMLSlideShow  extends POIXM
         slideId.setId(slideNumber);
         slideId.setId2(slide.getPackageRelationship().getId());
 
-        String masterId = _presentation.getSldMasterIdLst().getSldMasterIdArray(0).getId2();
-        XSLFSlideMaster master = _masters.get(masterId);
-
-        XSLFSlideLayout layout = master.getLayout("blank");
-        if(layout == null) throw new IllegalArgumentException("Blank layout was not found");
-
+        layout.copyLayout(slide);
         slide.addRelation(layout.getPackageRelationship().getId(), layout);
 
         PackagePartName ppName = layout.getPackagePart().getPartName();
@@ -224,7 +225,20 @@ public class XMLSlideShow  extends POIXM
         _slides.add(slide);
         return slide;
     }
-    
+
+    /**
+     * Create a blank slide.
+     */
+    public XSLFSlide createSlide() {
+        String masterId = _presentation.getSldMasterIdLst().getSldMasterIdArray(0).getId2();
+        XSLFSlideMaster master = _masters.get(masterId);
+
+        XSLFSlideLayout layout = master.getLayout(SlideLayout.BLANK);
+        if(layout == null) throw new IllegalArgumentException("Blank layout was not found");
+
+        return createSlide(layout);
+    }
+
     /**
      * Return the Notes Master, if there is one.
      * (May not be present if no notes exist)  

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java Mon Nov  7 09:12:16 2011
@@ -28,16 +28,14 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
 
-import java.util.regex.Pattern;
 
 /**
- * Represents a preset geometric shape. 
+ * Represents a shape with a preset geometry.
  *
  * @author Yegor Kozlov
  */
 @Beta
 public class XSLFAutoShape extends XSLFTextShape {
-    private static final Pattern adjPtrn = Pattern.compile("val\\s+(\\d+)");
 
     /*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
         super(shape, sheet);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java Mon Nov  7 09:12:16 2011
@@ -17,16 +17,16 @@
 
 package org.apache.poi.xslf.usermodel;
 
-import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlCursor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
 
-import javax.xml.namespace.QName;
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.Paint;
 import java.awt.geom.Rectangle2D;
 
 /**
@@ -49,31 +49,46 @@ public class XSLFBackground extends XSLF
     public void draw(Graphics2D graphics) {
         Rectangle2D anchor = getAnchor();
 
-        XmlObject spPr = null;
+        Paint fill = getPaint(graphics);
+        if(fill != null) {
+            graphics.setPaint(fill);
+            graphics.fill(anchor);
+        }
+    }
+
+    /**
+     * @return the Paint object to fill
+     */
+    Paint getPaint(Graphics2D graphics){
+        RenderableShape rShape = new RenderableShape(this);
+
+        Paint fill = null;
         CTBackground bg = (CTBackground)getXmlObject();
         if(bg.isSetBgPr()){
-            spPr = bg.getBgPr();
+            XmlObject spPr = bg.getBgPr();
+            fill = rShape.getPaint(graphics, spPr, null);
         } else if (bg.isSetBgRef()){
             CTStyleMatrixReference bgRef= bg.getBgRef();
-            int idx = (int)bgRef.getIdx() - 1000;
+            CTSchemeColor phClr = bgRef.getSchemeClr();
+
+            int idx = (int)bgRef.getIdx() - 1001;
             XSLFTheme theme = getSheet().getTheme();
             CTBackgroundFillStyleList bgStyles =
                     theme.getXmlObject().getThemeElements().getFmtScheme().getBgFillStyleLst();
 
-            // TODO pass this to getPaint
             XmlObject bgStyle = bgStyles.selectPath("*")[idx];
+            fill = rShape.selectPaint(graphics, bgStyle, phClr, theme.getPackagePart());
         }
 
-        if(spPr == null){
-            return;
-        }
+        return fill;
+    }
 
-        Paint fill = getPaint(graphics, spPr);
-        if(fill != null) {
-            graphics.setPaint(fill);
-            graphics.fill(anchor);
+    @Override
+    public Color getFillColor(){
+        Paint p = getPaint(null);
+        if(p instanceof Color){
+            return (Color)p;
         }
+        return null;
     }
-
-    
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java Mon Nov  7 09:12:16 2011
@@ -30,7 +30,7 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
 import org.w3c.dom.Node;
 
-import java.awt.*;
+import java.awt.Color;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -40,12 +40,15 @@ import java.util.Map;
  * @author Yegor Kozlov
  */
 @Beta
+@Internal
 public class XSLFColor {
     private XmlObject _xmlObject;
     private Color _color;
+    private CTSchemeColor _phClr;
 
-    XSLFColor(XmlObject obj, XSLFTheme theme) {
+    public XSLFColor(XmlObject obj, XSLFTheme theme, CTSchemeColor phClr) {
         _xmlObject = obj;
+        _phClr = phClr;
         _color = toColor(obj, theme);
     }
 
@@ -94,7 +97,7 @@ public class XSLFColor {
         return result;
     }
 
-    static Color toColor(XmlObject obj, XSLFTheme theme) {
+    Color toColor(XmlObject obj, XSLFTheme theme) {
         Color color = null;
         for (XmlObject ch : obj.selectPath("*")) {
             if (ch instanceof CTHslColor) {
@@ -102,7 +105,8 @@ public class XSLFColor {
                 int h = hsl.getHue2();
                 int s = hsl.getSat2();
                 int l = hsl.getLum2();
-                // is it correct ? 
+                // This conversion is not correct and differs from PowerPoint.
+                // TODO: Revisit and improve.
                 color = Color.getHSBColor(h / 60000f, s / 100000f, l / 100000f);
             } else if (ch instanceof CTPresetColor) {
                 CTPresetColor prst = (CTPresetColor)ch;
@@ -111,12 +115,13 @@ public class XSLFColor {
             } else if (ch instanceof CTSchemeColor) {
                 CTSchemeColor schemeColor = (CTSchemeColor)ch;
                 String colorRef = schemeColor.getVal().toString();
+                if(_phClr != null) {
+                    // context color overrides the theme
+                    colorRef = _phClr.getVal().toString();
+                }
                 // find referenced CTColor in the theme and convert it to java.awt.Color via a recursive call
                 CTColor ctColor = theme.getCTColor(colorRef);
                 if(ctColor != null) color = toColor(ctColor, null);
-                else {
-                    color = Color.black;
-                }
             } else if (ch instanceof CTScRgbColor) {
                 // same as CTSRgbColor but with values expressed in percents
                 CTScRgbColor scrgb = (CTScRgbColor)ch;
@@ -145,21 +150,59 @@ public class XSLFColor {
         return color;
     }
 
+    /**
+     * Read a perecentage value from the supplied xml bean.
+     * Example:
+     *   <a:tint val="45000"/>
+     *
+     * the returned value is 45
+     *
+     * @return  the percentage value in the range [0 .. 100]
+     */
     private int getPercentageValue(String elem){
-        XmlObject[] obj = _xmlObject.selectPath(
-                "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem);
+        String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
+
+        XmlObject[] obj;
+
+        // first ask the context color and if not found, ask the actual color bean
+        if(_phClr != null){
+            obj = _phClr.selectPath(query);
+            if(obj.length == 1){
+                Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
+                if(attr != null) {
+                    return Integer.parseInt(attr.getNodeValue()) / 1000;
+                }
+            }
+        }
+
+        obj = _xmlObject.selectPath(query);
         if(obj.length == 1){
             Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
             if(attr != null) {
                 return Integer.parseInt(attr.getNodeValue()) / 1000;
             }
         }
+
+
         return -1;
     }
 
     private int getAngleValue(String elem){
-        XmlObject[] obj = _xmlObject.selectPath(
-                "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem);
+        String color = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
+        XmlObject[] obj;
+
+        // first ask the context color and if not found, ask the actual color bean
+        if(_phClr != null){
+            obj = _xmlObject.selectPath( color );
+            if(obj.length == 1){
+                Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
+                if(attr != null) {
+                    return Integer.parseInt(attr.getNodeValue()) / 60000;
+                }
+            }
+        }
+
+        obj = _xmlObject.selectPath( color );
         if(obj.length == 1){
             Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
             if(attr != null) {
@@ -341,7 +384,7 @@ public class XSLFColor {
      * A 10% shade is 10% of the input color combined with 90% black.
      * 
      * @return the value of the shade specified as a
-     * percentage with 0% indicating minimal blue and 100% indicating maximum
+     * percentage with 0% indicating minimal shade and 100% indicating maximum
      * or -1 if the value is not set
      */
     int getShade(){
@@ -353,7 +396,7 @@ public class XSLFColor {
      * A 10% tint is 10% of the input color combined with 90% white.
      *
      * @return the value of the tint specified as a
-     * percentage with 0% indicating minimal blue and 100% indicating maximum
+     * percentage with 0% indicating minimal tint and 100% indicating maximum
      * or -1 if the value is not set
      */
     int getTint(){
@@ -389,6 +432,10 @@ public class XSLFColor {
         return color;
     }
 
+    /**
+     * This algorithm returns result different from PowerPoint.
+     * TODO: revisit and improve
+     */
     private static Color shade(Color c, int shade) {
         return new Color(
                 (int)(c.getRed() * shade * 0.01),
@@ -397,6 +444,10 @@ public class XSLFColor {
                 c.getAlpha());
     }
 
+    /**
+     * This algorithm returns result different from PowerPoint.
+     * TODO: revisit and improve
+     */
     private static Color tint(Color c, int tint) {
         int r = c.getRed();
         int g = c.getGreen();
@@ -414,7 +465,7 @@ public class XSLFColor {
     /**
      * Preset colors defined in DrawingML
      */
-    static Map<String, Color> presetColors;
+    static final Map<String, Color> presetColors;
 
     static {
         presetColors = new HashMap<String, Color>();    

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java Mon Nov  7 09:12:16 2011
@@ -20,6 +20,8 @@
 package org.apache.poi.xslf.usermodel;
 
 import org.apache.poi.util.Beta;
+import org.apache.poi.xslf.model.geom.Outline;
+import org.apache.poi.xslf.model.geom.Path;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
@@ -32,11 +34,14 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual;
 
-import java.awt.*;
+import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 /**
  * Specifies a connection shape.
@@ -197,36 +202,7 @@ public class XSLFConnectorShape extends 
         return len == null ? LineEndLength.MEDIUM : LineEndLength.values()[len.intValue() - 1];
     }
 
-    @Override
-    public void draw(Graphics2D graphics) {
-        java.awt.Shape outline = getOutline();
-
-        // shadow
-        XSLFShadow shadow = getShadow();
-
-        //border
-        Paint line = getLinePaint(graphics);
-        if (line != null) {
-            if (shadow != null) shadow.draw(graphics);
-
-            graphics.setPaint(line);
-            applyStroke(graphics);
-            graphics.draw(outline);
-
-            Shape tailDecoration = getTailDecoration();
-            if (tailDecoration != null) {
-                graphics.draw(tailDecoration);
-            }
-
-            Shape headDecoration = getHeadDecoration();
-            if (headDecoration != null) {
-                graphics.draw(headDecoration);
-
-            }
-        }
-    }
-
-    Shape getTailDecoration() {
+    Outline getTailDecoration() {
         LineEndLength tailLength = getLineTailLength();
         LineEndWidth tailWidth = getLineTailWidth();
 
@@ -239,17 +215,20 @@ public class XSLFConnectorShape extends 
 
         AffineTransform at = new AffineTransform();
         Shape shape = null;
+        Path p = null;
         Rectangle2D bounds;
         double scaleY = Math.pow(2, tailWidth.ordinal());
         double scaleX = Math.pow(2, tailLength.ordinal());
-        switch (getLineHeadDecoration()) {
+        switch (getLineTailDecoration()) {
             case OVAL:
+                p = new Path();
                 shape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
                 bounds = shape.getBounds2D();
                 at.translate(x2 - bounds.getWidth() / 2, y2 - bounds.getHeight() / 2);
                 at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2);
                 break;
             case ARROW:
+                p = new Path();
                 GeneralPath arrow = new GeneralPath();
                 arrow.moveTo((float) (-lineWidth * 3), (float) (-lineWidth * 2));
                 arrow.lineTo(0, 0);
@@ -259,6 +238,7 @@ public class XSLFConnectorShape extends 
                 at.rotate(alpha);
                 break;
             case TRIANGLE:
+                p = new Path();
                 scaleY = tailWidth.ordinal() + 1;
                 scaleX = tailLength.ordinal() + 1;
                 GeneralPath triangle = new GeneralPath();
@@ -277,10 +257,10 @@ public class XSLFConnectorShape extends 
         if (shape != null) {
             shape = at.createTransformedShape(shape);
         }
-        return shape;
+        return shape == null ? null : new Outline(shape, p);
     }
 
-    Shape getHeadDecoration() {
+    Outline getHeadDecoration() {
         LineEndLength headLength = getLineHeadLength();
         LineEndWidth headWidth = getLineHeadWidth();
 
@@ -293,11 +273,13 @@ public class XSLFConnectorShape extends 
 
         AffineTransform at = new AffineTransform();
         Shape shape = null;
+        Path p = null;
         Rectangle2D bounds;
         double scaleY = 1;
         double scaleX = 1;
         switch (getLineHeadDecoration()) {
             case OVAL:
+                p = new Path();
                 shape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY);
                 bounds = shape.getBounds2D();
                 at.translate(x1 - bounds.getWidth() / 2, y1 - bounds.getHeight() / 2);
@@ -305,6 +287,7 @@ public class XSLFConnectorShape extends 
                 break;
             case STEALTH:
             case ARROW:
+                p = new Path();
                 GeneralPath arrow = new GeneralPath();
                 arrow.moveTo((float) (lineWidth * 3 * scaleX), (float) (-lineWidth * scaleY * 2));
                 arrow.lineTo(0, 0);
@@ -314,6 +297,7 @@ public class XSLFConnectorShape extends 
                 at.rotate(alpha);
                 break;
             case TRIANGLE:
+                p = new Path();
                 scaleY = headWidth.ordinal() + 1;
                 scaleX = headLength.ordinal() + 1;
                 GeneralPath triangle = new GeneralPath();
@@ -332,7 +316,19 @@ public class XSLFConnectorShape extends 
         if (shape != null) {
             shape = at.createTransformedShape(shape);
         }
-        return shape;
+        return shape == null ? null : new Outline(shape, p);
+    }
+
+    @Override
+    List<Outline> getCustomOutlines(){
+        List<Outline> lst = new ArrayList<Outline>();
+
+        Outline head = getHeadDecoration();
+        if(head != null) lst.add(head);
+
+        Outline tail = getTailDecoration();
+        if(tail != null) lst.add(tail);
+        return lst;
     }
 
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFDrawing.java Mon Nov  7 09:12:16 2011
@@ -25,7 +25,8 @@ import org.openxmlformats.schemas.presen
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
 
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Rectangle;
 
 
 /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java Mon Nov  7 09:12:16 2011
@@ -188,10 +188,4 @@ public class XSLFFreeformShape extends X
         geom.addNewPathLst();
         return ct;
     }
-
-    @Override
-    protected java.awt.Shape getOutline(){
-        return getPath();
-    }
-
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java Mon Nov  7 09:12:16 2011
@@ -26,7 +26,7 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
 
-import java.awt.*;
+import java.awt.Graphics2D;
 import java.awt.geom.Rectangle2D;
 
 /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java Mon Nov  7 09:12:16 2011
@@ -35,7 +35,7 @@ import org.openxmlformats.schemas.presen
 import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
 
-import java.awt.*;
+import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.util.List;
@@ -62,10 +62,12 @@ public class XSLFGroupShape extends XSLF
         _spPr = shape.getGrpSpPr();
     }
 
+    @Override
     public CTGroupShape getXmlObject(){
         return _shape;
     }
 
+    @Override
     public Rectangle2D getAnchor(){
         CTGroupTransform2D xfrm = _spPr.getXfrm();
         CTPoint2D off = xfrm.getOff();
@@ -79,6 +81,7 @@ public class XSLFGroupShape extends XSLF
                 Units.toPoints(cx), Units.toPoints(cy));
     }
 
+    @Override
     public void setAnchor(Rectangle2D anchor){
         CTGroupTransform2D xfrm = _spPr.isSetXfrm() ? _spPr.getXfrm() : _spPr.addNewXfrm();
         CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
@@ -93,6 +96,12 @@ public class XSLFGroupShape extends XSLF
         ext.setCy(cy);
     }
 
+    /**
+     *
+     * @return the coordinates of the child extents rectangle
+     * used for calculations of grouping, scaling, and rotation
+     * behavior of shapes placed within a group.
+     */
     public Rectangle2D getInteriorAnchor(){
         CTGroupTransform2D xfrm = _spPr.getXfrm();
         CTPoint2D off = xfrm.getChOff();
@@ -106,6 +115,12 @@ public class XSLFGroupShape extends XSLF
                 Units.toPoints(cx), Units.toPoints(cy));
     }
 
+    /**
+     *
+     * @param anchor the coordinates of the child extents rectangle
+     * used for calculations of grouping, scaling, and rotation
+     * behavior of shapes placed within a group.
+     */
     public void setInteriorAnchor(Rectangle2D anchor){
         CTGroupTransform2D xfrm = _spPr.isSetXfrm() ? _spPr.getXfrm() : _spPr.addNewXfrm();
         CTPoint2D off = xfrm.isSetChOff() ? xfrm.getChOff() : xfrm.addNewChOff();
@@ -120,10 +135,17 @@ public class XSLFGroupShape extends XSLF
         ext.setCy(cy);
     }
 
+    /**
+     *
+     * @return child shapes contained witin this group
+     */
     public XSLFShape[] getShapes(){
         return _shapes.toArray(new XSLFShape[_shapes.size()]);
     }
 
+    /**
+     * Remove the specified shape from this group
+     */
     public boolean removeShape(XSLFShape xShape) {
         XmlObject obj = xShape.getXmlObject();
         if(obj instanceof CTShape){
@@ -138,10 +160,12 @@ public class XSLFGroupShape extends XSLF
         return _shapes.remove(xShape);
     }
 
+    @Override
     public String getShapeName(){
         return _shape.getNvGrpSpPr().getCNvPr().getName();
     }
 
+    @Override
     public int getShapeId(){
         return (int)_shape.getNvGrpSpPr().getCNvPr().getId();
     }
@@ -216,53 +240,37 @@ public class XSLFGroupShape extends XSLF
         return sh;
     }
 
-
+    @Override
     public void setFlipHorizontal(boolean flip){
         _spPr.getXfrm().setFlipH(flip);
     }
 
+    @Override
     public void setFlipVertical(boolean flip){
         _spPr.getXfrm().setFlipV(flip);
     }
-    /**
-     * Whether the shape is horizontally flipped
-     *
-     * @return whether the shape is horizontally flipped
-     */
+
+    @Override
     public boolean getFlipHorizontal(){
          return _spPr.getXfrm().getFlipH();
     }
 
+    @Override
     public boolean getFlipVertical(){
          return _spPr.getXfrm().getFlipV();
     }
 
-    /**
-     * Rotate this shape.
-     * <p>
-     * Positive angles are clockwise (i.e., towards the positive y axis);
-     * negative angles are counter-clockwise (i.e., towards the negative y axis).
-     * </p>
-     *
-     * @param theta the rotation angle in degrees.
-     */
+    @Override
     public void setRotation(double theta){
         _spPr.getXfrm().setRot((int)(theta*60000));
     }
 
-    /**
-     * Rotation angle in degrees
-     * <p>
-     * Positive angles are clockwise (i.e., towards the positive y axis);
-     * negative angles are counter-clockwise (i.e., towards the negative y axis).
-     * </p>
-     *
-     * @return rotation angle in degrees
-     */
+    @Override
     public double getRotation(){
         return (double)_spPr.getXfrm().getRot()/60000;
     }
 
+    @Override
     public void draw(Graphics2D graphics){
 
     	// the coordinate system of this group of shape
@@ -278,16 +286,14 @@ public class XSLFGroupShape extends XSLF
 
         for (XSLFShape shape : getShapes()) {
         	// remember the initial transform and restore it after we are done with the drawing
-        	AffineTransform at0 = graphics.getTransform();
+        	AffineTransform at = graphics.getTransform();
             graphics.setRenderingHint(XSLFRenderingHint.GSAVE, true);
 
-            // apply rotation and flipping
-        	shape.applyTransform(graphics);
-
+            shape.applyTransform(graphics);
         	shape.draw(graphics);
 
             // restore the coordinate system
-            graphics.setTransform(at0);
+            graphics.setTransform(at);
             graphics.setRenderingHint(XSLFRenderingHint.GRESTORE, true);
         }
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRendener.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRendener.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRendener.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFImageRendener.java Mon Nov  7 09:12:16 2011
@@ -19,10 +19,11 @@
 
 package org.apache.poi.xslf.usermodel;
 
+import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.util.Beta;
 
 import javax.imageio.ImageIO;
-import java.awt.*;
+import java.awt.Graphics2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
@@ -76,11 +77,10 @@ public class XSLFImageRendener {
 	public boolean drawImage(Graphics2D graphics, XSLFPictureData data,
 			Rectangle2D anchor) {
 		try {
-			BufferedImage img = readImage(new ByteArrayInputStream(data.getData()));
-			if (img != null){
-                graphics.drawImage(img, (int) anchor.getX(), (int) anchor.getY(),
-                        (int) anchor.getWidth(), (int) anchor.getHeight(), null);
-            }
+			BufferedImage img = ImageIO.read(data.getPackagePart().getInputStream());
+            graphics.drawImage(img,
+                    (int) anchor.getX(), (int) anchor.getY(),
+                    (int) anchor.getWidth(), (int) anchor.getHeight(), null);
 			return true;
 		} catch (Exception e) {
 			return false;
@@ -89,12 +89,13 @@ public class XSLFImageRendener {
 	}
 
     /**
-     * create a buffered image from input stream
+     * Create a buffered image from the supplied package part.
+     * This method is called to create texture paints.
      *
      * @return a <code>BufferedImage</code> containing the decoded
      * contents of the input, or <code>null</code>.
      */
-    public BufferedImage readImage(InputStream is) throws IOException {
-        return ImageIO.read(is);
+    public BufferedImage readImage(PackagePart packagePart) throws IOException {
+        return ImageIO.read(packagePart.getInputStream());
     }
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java Mon Nov  7 09:12:16 2011
@@ -75,4 +75,9 @@ public final class XSLFNotes extends XSL
     protected String getRootElementName(){
         return "notes";        
     }
+
+    @Override
+    public XSLFSheet getMasterSheet() {
+        return null;
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java?rev=1198658&r1=1198657&r2=1198658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java Mon Nov  7 09:12:16 2011
@@ -24,7 +24,6 @@ import org.openxmlformats.schemas.presen
 import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
 * Notes master object associated with this layout.
@@ -45,8 +44,6 @@ import java.util.Map;
 @Beta
  public class XSLFNotesMaster extends XSLFSheet {
 	 private CTNotesMaster _slide;
-    private Map<String, XSLFSlideLayout> _layouts;
-    private XSLFTheme _theme;
 
     XSLFNotesMaster() {
         super();
@@ -70,4 +67,10 @@ import java.util.Map;
     protected String getRootElementName(){
         return "notesMaster";
     }
+
+    @Override
+    public XSLFSheet getMasterSheet() {
+        return null;
+    }
+
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message