You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/12/11 09:43:09 UTC

svn commit: r1212978 - in /poi/trunk/src: documentation/content/xdocs/slideshow/ examples/src/org/apache/poi/xslf/usermodel/ ooxml/java/org/apache/poi/xslf/usermodel/

Author: yegor
Date: Sun Dec 11 08:43:09 2011
New Revision: 1212978

URL: http://svn.apache.org/viewvc?rev=1212978&view=rev
Log:
xlsf tutorial and cookbook updates

Added:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java   (with props)
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java   (with props)
Removed:
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/SlidesAndShapes.java
Modified:
    poi/trunk/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java

Modified: poi/trunk/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml?rev=1212978&r1=1212977&r2=1212978&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml Sun Dec 11 08:43:09 2011
@@ -23,11 +23,16 @@
     <header>
         <title>XSLF Cookbook</title>
         <authors>
-            <person email="yegor@dinom.ru" name="Yegor Kozlov" id="CO"/>
+            <person email="yegor@apache.org" name="Yegor Kozlov" id="YK"/>
         </authors>
     </header>
     <body>
         <section><title>XSLF Cookbook</title>
+            <p>
+              This page offers a short introduction into the XSLF API. More examples can be found in the
+                <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/"> XSLF Examples</link>
+               in the POI SVN repository. 
+            </p>
             <note>
             Please note that XSLF is still in early development and is a subject to incompatible changes in a future release. 
             </note>

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,94 @@
+/*
+ *  ====================================================================
+ *    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 java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * Demonstrates how you can extract data from a .pptx file
+ *
+ * @author Yegor Kozlov
+ */
+public final class DataExtraction {
+
+    public static void main(String args[]) throws Exception {
+
+        if (args.length == 0) {
+           System.out.println("Input file is required");
+           return;
+        }
+
+        FileInputStream is = new FileInputStream(args[0]);
+        XMLSlideShow ppt = new XMLSlideShow(is);
+        is.close();
+
+        // Get the document's embedded files.
+        List<PackagePart> embeds = ppt.getAllEmbedds();
+        for (PackagePart p : embeds) {
+            String type = p.getContentType();
+            String name = p.getPartName().getName();  //typically file name
+            
+            InputStream pIs = p.getInputStream();
+            // make sense of the part data
+            pIs.close();
+            
+        }
+
+        // Get the document's embedded files.
+        List<XSLFPictureData> images = ppt.getAllPictures();
+        for (XSLFPictureData data : images) {
+            PackagePart p = data.getPackagePart();
+
+            String type = p.getContentType();
+            String name = data.getFileName();
+
+            InputStream pIs = p.getInputStream();
+            // make sense of the image data
+            pIs.close();
+
+
+
+        }
+
+        Dimension pageSize = ppt.getPageSize();  // size of the canvas in points
+        for(XSLFSlide slide : ppt.getSlides()) {
+            for(XSLFShape shape : slide){
+                Rectangle2D anchor = shape.getAnchor();  // position on the canvas
+                if(shape instanceof XSLFTextShape) {
+                    XSLFTextShape txShape = (XSLFTextShape)shape;
+                    System.out.println(txShape.getText());
+                } else if (shape instanceof XSLFPictureShape){
+                    XSLFPictureShape pShape = (XSLFPictureShape)shape;
+                    XSLFPictureData pData = pShape.getPictureData();
+                    System.out.println(pData.getFileName());
+                } else {
+                    System.out.println("Process me: " + shape.getClass());
+                }
+            }
+        }
+    }
+
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,50 @@
+/*
+ *  ====================================================================
+ *    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 java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+/**
+ * Merge multiple pptx presentations together
+ *
+ * @author Yegor Kozlov
+ */
+public final class MergePresentations {
+
+    public static void main(String args[]) throws Exception {
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        for(String arg : args){
+            FileInputStream is = new FileInputStream(arg);
+            XMLSlideShow src = new XMLSlideShow(is);
+            is.close();
+
+            for(XSLFSlide srcSlide : src.getSlides()){
+                ppt.createSlide().importContent(srcSlide);
+            }
+        }
+
+        FileOutputStream out = new FileOutputStream("merged.pptx");
+        ppt.write(out);
+        out.close();
+    }
+
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,72 @@
+/*
+ *  ====================================================================
+ *    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 java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Demonstrates how to create slides with predefined layout
+ * and fill the placeholder shapes
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial1 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        // XSLFSlide#createSlide() with no arguments creates a blank slide
+        XSLFSlide blankSlide = ppt.createSlide();
+
+        
+        XSLFSlideMaster master = ppt.getSlideMasters()[0];
+
+        XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);
+        XSLFSlide slide1 = ppt.createSlide(layout1) ;
+        XSLFTextShape[] ph1 = slide1.getPlaceholders();
+        XSLFTextShape titlePlaceholder1 = ph1[0];
+        titlePlaceholder1.setText("This is a title");
+        XSLFTextShape subtitlePlaceholder1 = ph1[1];
+        subtitlePlaceholder1.setText("this is a subtitle");
+
+        XSLFSlideLayout layout2 = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
+        XSLFSlide slide2 = ppt.createSlide(layout2) ;
+        XSLFTextShape[] ph2 = slide2.getPlaceholders();
+        XSLFTextShape titlePlaceholder2 = ph2[0];
+        titlePlaceholder2.setText("This is a title");
+        XSLFTextShape bodyPlaceholder = ph2[1];
+        // we are going to add text by paragraphs. Clear the default placehoder text before that
+        bodyPlaceholder.clearText();
+        XSLFTextParagraph p1 = bodyPlaceholder.addNewTextParagraph();
+        p1.setLevel(0);
+        p1.addNewTextRun().setText("Level1 text");
+        XSLFTextParagraph p2 = bodyPlaceholder.addNewTextParagraph();
+        p2.setLevel(1);
+        p2.addNewTextRun().setText("Level2 text");
+        XSLFTextParagraph p3 = bodyPlaceholder.addNewTextParagraph();
+        p3.setLevel(3);
+        p3.addNewTextRun().setText("Level3 text");
+
+        FileOutputStream out = new FileOutputStream("slides.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,83 @@
+/*
+ *  ====================================================================
+ *    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 java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Basic paragraph and text formatting
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial2 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        XSLFSlide slide1 = ppt.createSlide();
+        XSLFTextBox shape1 = slide1.createTextBox();
+        // initial height of the text box is 100 pt but
+        Rectangle anchor = new Rectangle(10, 100, 300, 100);
+        shape1.setAnchor(anchor);
+
+        XSLFTextParagraph p1 = shape1.addNewTextParagraph();
+        XSLFTextRun r1 = p1.addNewTextRun();
+        r1.setText("Paragraph Formatting");
+        r1.setFontSize(24);
+        r1.setFontColor(new Color(85, 142, 213));
+
+        XSLFTextParagraph p2 = shape1.addNewTextParagraph();
+        // If spaceBefore >= 0, then space is a percentage of normal line height.
+        // If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+        p2.setSpaceBefore(-20); // 20 pt from the previous paragraph
+        p2.setSpaceAfter(300); // 3 lines after the paragraph
+        XSLFTextRun r2 = p2.addNewTextRun();
+        r2.setText("Paragraph  properties apply to all text residing within the corresponding paragraph.");
+        r2.setFontSize(16);
+
+        XSLFTextParagraph p3 = shape1.addNewTextParagraph();
+
+        XSLFTextRun r3 = p3.addNewTextRun();
+        r3.setText("Run Formatting");
+        r3.setFontSize(24);
+        r3.setFontColor(new Color(85, 142, 213));
+
+        XSLFTextParagraph p4 = shape1.addNewTextParagraph();
+        p4.setSpaceBefore(-20); // 20 pt from the previous paragraph
+        p4.setSpaceAfter(300); // 3 lines after the paragraph
+        XSLFTextRun r4 = p4.addNewTextRun();
+        r4.setFontSize(16);
+        r4.setText(
+                "Run level formatting is the most granular property level and allows " +
+                "for the specifying of all low level text properties. The text run is " +
+                "what all paragraphs are derived from and thus specifying various " +
+                "properties per run will allow for a diversely formatted text paragraph.");
+
+        // resize the shape to fit text
+        shape1.resizeToFitText();
+
+        FileOutputStream out = new FileOutputStream("text.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,47 @@
+/*
+ *  ====================================================================
+ *    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 java.awt.*;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * How to set slide title
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial3 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        XSLFSlide slide = ppt.createSlide();
+
+        XSLFTextShape titleShape = slide.createTextBox();
+        titleShape.setPlaceholder(Placeholder.TITLE);
+        titleShape.setText("This is a slide title");
+        titleShape.setAnchor(new Rectangle(50, 50, 400, 100));
+
+        FileOutputStream out = new FileOutputStream("title.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,89 @@
+/*
+ *  ====================================================================
+ *    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 java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * PPTX Tables
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial4 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        // XSLFSlide#createSlide() with no arguments creates a blank slide
+        XSLFSlide slide = ppt.createSlide();
+
+        XSLFTable tbl = slide.createTable();
+        tbl.setAnchor(new Rectangle2D.Double(50, 50, 450, 300));
+
+        int numColumns = 3;
+        int numRows = 5;
+        XSLFTableRow headerRow = tbl.addRow();
+        headerRow.setHeight(50);
+        // header
+        for(int i = 0; i < numColumns; i++) {
+            XSLFTableCell th = headerRow.addCell();
+            XSLFTextParagraph p = th.addNewTextParagraph();
+            p.setTextAlign(TextAlign.CENTER);
+            XSLFTextRun r = p.addNewTextRun();
+            r.setText("Header " + (i+1));
+            r.setBold(true);
+            r.setFontColor(Color.white);
+            th.setFillColor(new Color(79, 129, 189));
+            th.setBorderBottom(2);
+            th.setBorderBottomColor(Color.white);
+
+            tbl.setColumnWidth(i, 150);  // all columns are equally sized
+        }
+        
+        // rows
+        
+        for(int rownum = 0; rownum < numRows; rownum ++){
+            XSLFTableRow tr = tbl.addRow();
+            tr.setHeight(50);
+            // header
+            for(int i = 0; i < numColumns; i++) {
+                XSLFTableCell cell = tr.addCell();
+                XSLFTextParagraph p = cell.addNewTextParagraph();
+                XSLFTextRun r = p.addNewTextRun();
+
+                r.setText("Cell " + (i+1));
+                if(rownum % 2 == 0)
+                    cell.setFillColor(new Color(208, 216, 232));
+                else
+                    cell.setFillColor(new Color(233, 247, 244));
+
+            }
+            
+        }
+
+
+        FileOutputStream out = new FileOutputStream("table.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,50 @@
+/*
+ *  ====================================================================
+ *    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.util.IOUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Images
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial5 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        XSLFSlide slide = ppt.createSlide();
+        File img = new File(System.getProperty("POI.testdata.path"), "slideshow/clock.jpg");
+        byte[] data = IOUtils.toByteArray(new FileInputStream(img));
+        int pictureIndex = ppt.addPicture(data, XSLFPictureData.PICTURE_TYPE_PNG);
+
+        XSLFPictureShape shape = slide.createPicture(pictureIndex);
+
+        FileOutputStream out = new FileOutputStream("images.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java?rev=1212978&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java Sun Dec 11 08:43:09 2011
@@ -0,0 +1,59 @@
+/*
+ *  ====================================================================
+ *    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 java.awt.*;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * Hyperlinks
+ *
+ * @author Yegor Kozlov
+ */
+public class Tutorial6 {
+
+    public static void main(String[] args) throws IOException{
+        XMLSlideShow ppt = new XMLSlideShow();
+
+        XSLFSlide slide1 = ppt.createSlide();
+        XSLFSlide slide2 = ppt.createSlide();
+
+        XSLFTextBox shape1 = slide1.createTextBox();
+        shape1.setAnchor(new Rectangle(50, 50, 200, 50));
+        XSLFTextRun r1 = shape1.addNewTextParagraph().addNewTextRun();
+        XSLFHyperlink link1 = r1.createHyperlink();
+        r1.setText("http://poi.apache.org"); // visible text
+        link1.setAddress("http://poi.apache.org");  // link address
+
+        XSLFTextBox shape2 = slide1.createTextBox();
+        shape2.setAnchor(new Rectangle(300, 50, 200, 50));
+        XSLFTextRun r2 = shape2.addNewTextParagraph().addNewTextRun();
+        XSLFHyperlink link2 = r2.createHyperlink();
+        r2.setText("Go to the second slide"); // visible text
+        link2.setAddress(slide2);  // link address
+
+
+
+        FileOutputStream out = new FileOutputStream("hyperlinks.pptx");
+        ppt.write(out);
+        out.close();
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java?rev=1212978&r1=1212977&r2=1212978&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java Sun Dec 11 08:43:09 2011
@@ -19,6 +19,7 @@
 
 package org.apache.poi.xslf.usermodel;
 
+import org.apache.poi.POIXMLException;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.Units;
 import org.apache.poi.xslf.model.PropertyFetcher;
@@ -455,6 +456,24 @@ public abstract class XSLFTextShape exte
     }
 
     /**
+     * Adjust the size of the shape so it encompasses the text inside it.
+     *
+     * @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.
+     */
+    public Rectangle2D resizeToFitText(){
+        Rectangle2D anchor = getAnchor();
+        if(anchor.getWidth() == 0.)  throw new POIXMLException(
+                "Anchor of the shape was not set.");
+        double height = getTextHeight(); 
+        height += 1; // add a pixel to compensate rounding errors
+        
+        anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
+        setAnchor(anchor);
+        
+        return anchor;
+    }   
+    
+    /**
      * break the contained text into lines
     */
     private void breakText(Graphics2D graphics){



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