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/10/21 15:17:34 UTC

svn commit: r1187328 [3/5] - in /poi/trunk: src/documentation/content/xdocs/ src/ooxml/java/org/apache/poi/util/ src/ooxml/java/org/apache/poi/xslf/model/ src/ooxml/java/org/apache/poi/xslf/usermodel/ src/ooxml/java/org/apache/poi/xslf/util/ src/ooxml/...

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java?rev=1187328&r1=1187327&r2=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTheme.java Fri Oct 21 13:17:33 2011
@@ -22,15 +22,21 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.Internal;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideLayout;
-import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme;
 import org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeStyleSheet;
-import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor;
 
 import javax.xml.namespace.QName;
+
+import java.awt.Color;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Map;
@@ -39,7 +45,8 @@ import java.util.HashMap;
 @Beta
 public class XSLFTheme extends POIXMLDocumentPart {
     private CTOfficeStyleSheet _theme;
-
+    private Map<String, XSLFColor> _schemeColors;
+    
     XSLFTheme() {
         super();
         _theme = CTOfficeStyleSheet.Factory.newInstance();
@@ -50,8 +57,24 @@ public class XSLFTheme extends POIXMLDoc
         ThemeDocument doc =
             ThemeDocument.Factory.parse(getPackagePart().getInputStream());
         _theme = doc.getTheme();
+        initialize();
     }
 
+    private void initialize(){
+    	CTBaseStyles elems = _theme.getThemeElements();
+    	CTColorScheme scheme = elems.getClrScheme();
+    	// The color scheme is responsible for defining a list of twelve colors. 
+    	_schemeColors = new HashMap<String, XSLFColor>(12);
+    	for(XmlObject o : scheme.selectPath("*")){
+    		CTColor c = (CTColor)o;
+    		String name = c.getDomNode().getLocalName();
+    		_schemeColors.put(name, new XSLFColor(c));
+    	}
+    	_schemeColors.put("bg1", _schemeColors.get("lt1"));
+    	_schemeColors.put("bg2", _schemeColors.get("lt2"));
+        _schemeColors.put("tx1", _schemeColors.get("dk1"));
+        _schemeColors.put("tx2", _schemeColors.get("dk2"));
+    }
 
     public String getName(){
         return _theme.getName();
@@ -62,6 +85,146 @@ public class XSLFTheme extends POIXMLDoc
     }
 
     /**
+     * Get a color from the theme's color scheme by name
+     * 
+     * @return a theme color or <code>null</code> if not found
+     */
+    public XSLFColor getColor(String name){
+    	return _schemeColors.get(name);
+    }
+    
+    Color getSchemeColor(CTSchemeColor schemeColor){
+        String colorRef = schemeColor.getVal().toString();
+        int alpha = 0xFF;
+        if(schemeColor.sizeOfAlphaArray() > 0){
+            int aval = schemeColor.getAlphaArray(0).getVal();
+            alpha =  Math.round(255 * aval / 100000f);
+        }
+        Color themeColor = _schemeColors.get(colorRef).getColor(alpha);
+
+        int lumMod = 100, lumOff = 0;
+        if (schemeColor.sizeOfLumModArray() > 0) {
+            lumMod = schemeColor.getLumModArray(0).getVal() / 1000;
+        }
+        if (schemeColor.sizeOfLumOffArray() > 0) {
+            lumOff = schemeColor.getLumOffArray(0).getVal() / 1000;
+        }
+        if(schemeColor.sizeOfShadeArray() > 0) {
+            lumMod = schemeColor.getShadeArray(0).getVal() / 1000;
+        }
+        Color color = modulateLuminanace(themeColor, lumMod, lumOff);
+
+        if(schemeColor.sizeOfTintArray() > 0) {
+            float tint = schemeColor.getTintArray(0).getVal() / 100000f;
+            int red = Math.round(tint * themeColor.getRed() + (1 - tint) * 255);
+            int green = Math.round(tint * themeColor.getGreen() + (1 - tint) * 255);
+            int blue = Math.round(tint * themeColor.getBlue() + (1 - tint) * 255);
+            color = new Color(red, green, blue);
+        }
+
+        return color;
+    }
+
+    /**
+     * TODO get rid of code duplication. Re-write to use xpath instead of beans
+     */
+    Color getPresetColor(CTPresetColor presetColor){
+        String colorName = presetColor.getVal().toString();
+        Color color;
+        try {
+            color = (Color)Color.class.getField(colorName).get(null);
+        } catch (Exception e){
+            color = Color.black;
+        }
+        if(presetColor.sizeOfAlphaArray() > 0){
+            int aval = presetColor.getAlphaArray(0).getVal();
+            int alpha =  Math.round(255 * aval / 100000f);
+            color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); 
+        }
+
+        int lumMod = 100, lumOff = 0;
+        if (presetColor.sizeOfLumModArray() > 0) {
+            lumMod = presetColor.getLumModArray(0).getVal() / 1000;
+        }
+        if (presetColor.sizeOfLumOffArray() > 0) {
+            lumOff = presetColor.getLumOffArray(0).getVal() / 1000;
+        }
+        if(presetColor.sizeOfShadeArray() > 0) {
+            lumMod = presetColor.getShadeArray(0).getVal() / 1000;
+        }
+        color = modulateLuminanace(color, lumMod, lumOff);
+
+        if(presetColor.sizeOfTintArray() > 0) {
+            float tint = presetColor.getTintArray(0).getVal() / 100000f;
+            int red = Math.round(tint * color.getRed() + (1 - tint) * 255);
+            int green = Math.round(tint * color.getGreen() + (1 - tint) * 255);
+            int blue = Math.round(tint * color.getBlue() + (1 - tint) * 255);
+            color = new Color(red, green, blue);
+        }
+
+        return color;
+    }
+
+    public Color brighter(Color color, double tint) {
+        int r = color.getRed();
+        int g = color.getGreen();
+        int b = color.getBlue();
+
+        /* From 2D group:
+         * 1. black.brighter() should return grey
+         * 2. applying brighter to blue will always return blue, brighter
+         * 3. non pure color (non zero rgb) will eventually return white
+         */
+        int i = (int)(1.0/(1.0-tint));
+        if ( r == 0 && g == 0 && b == 0) {
+           return new Color(i, i, i);
+        }
+        if ( r > 0 && r < i ) r = i;
+        if ( g > 0 && g < i ) g = i;
+        if ( b > 0 && b < i ) b = i;
+
+        return new Color(Math.min((int)(r/tint), 255),
+                         Math.min((int)(g/tint), 255),
+                         Math.min((int)(b/tint), 255));
+    }
+
+    Color getSrgbColor(CTSRgbColor srgb){
+        byte[] val = srgb.getVal();
+        int alpha = 0xFF;
+        if(srgb.sizeOfAlphaArray() > 0){
+            int aval = srgb.getAlphaArray(0).getVal();
+            alpha =  Math.round(255 * aval / 100000f);
+        }
+        return new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2], alpha);
+    }
+
+    Color getSolidFillColor(CTSolidColorFillProperties solidFill){
+        Color color;
+        if (solidFill.isSetSrgbClr()) {
+            color = getSrgbColor(solidFill.getSrgbClr());
+        } else if (solidFill.isSetSchemeClr()) {
+            color = getSchemeColor(solidFill.getSchemeClr());
+        } else {
+            // TODO support other types
+            color = Color.black;
+        }
+        return color;
+    }
+
+    Color getColor(CTColor solidFill){
+        Color color;
+        if (solidFill.isSetSrgbClr()) {
+            color = getSrgbColor(solidFill.getSrgbClr());
+        } else if (solidFill.isSetSchemeClr()) {
+            color = getSchemeColor(solidFill.getSchemeClr());
+        } else {
+            // TODO support other types
+            color = Color.black;
+        }
+        return color;
+    }
+
+     /**
      * While developing only!
      */
     @Internal
@@ -84,4 +247,31 @@ public class XSLFTheme extends POIXMLDoc
         out.close();
     }
 
-}
\ No newline at end of file
+    public static Color modulateLuminanace(Color c, int lumMod, int lumOff) {
+        Color color;
+        if (lumOff > 0) {
+            color = new Color(
+                    (int) (Math.round((255 - c.getRed()) * (100.0 - lumMod) / 100.0 + c.getRed())),
+                    (int) (Math.round((255 - c.getGreen()) * lumOff / 100.0 + c.getGreen())),
+                    (int) (Math.round((255 - c.getBlue()) * lumOff / 100.0 + c.getBlue())),
+                    c.getAlpha()
+            );
+        } else {
+            color = new Color(
+                    (int) (Math.round(c.getRed() * lumMod / 100.0)),
+                    (int) (Math.round(c.getGreen() * lumMod / 100.0)),
+                    (int) (Math.round(c.getBlue() * lumMod / 100.0)),
+                    c.getAlpha()
+            );
+        }
+        return color;
+    }
+
+    public String getMajorFont(){
+        return _theme.getThemeElements().getFontScheme().getMajorFont().getLatin().getTypeface();
+    }
+
+    public String getMinorFont(){
+        return _theme.getThemeElements().getFontScheme().getMinorFont().getLatin().getTypeface();
+    }
+}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1187328&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Fri Oct 21 13:17:33 2011
@@ -0,0 +1,101 @@
+/*
+ *  ====================================================================
+ *    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.util;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+
+import javax.imageio.ImageIO;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+
+/**
+ * Date: 10/11/11
+ *
+ * @author Yegor Kozlov
+ */
+public class PPTX2PNG {
+    public static void main(String[] args) throws Exception {
+        if (args.length == 0) {
+            System.out.println("Usage: PPTX2PNG [options] <pptx file>");
+            return;
+        }
+
+        int slidenum = -1;
+        float scale = 1;
+        String file = null;
+
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].startsWith("-")) {
+                if ("-scale".equals(args[i])) {
+                    scale = Float.parseFloat(args[++i]);
+                } else if ("-slide".equals(args[i])) {
+                    slidenum = Integer.parseInt(args[++i]);
+                }
+            } else {
+                file = args[i];
+            }
+        }
+
+        System.out.println("Processing " + file);
+        XMLSlideShow ppt = new XMLSlideShow(OPCPackage.open(file));
+
+        Dimension pgsize = ppt.getPageSize();
+        int width = (int) (pgsize.width * scale);
+        int height = (int) (pgsize.height * scale);
+
+        XSLFSlide[] slide = ppt.getSlides();
+        for (int i = 0; i < slide.length; i++) {
+            if (slidenum != -1 && slidenum != (i + 1)) continue;
+
+            String title = slide[i].getTitle();
+            System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title));
+
+            BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+            Graphics2D graphics = img.createGraphics();
+
+            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+            graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+            graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+
+            graphics.setPaint(Color.white);
+            graphics.fill(new Rectangle2D.Float(0, 0, width, height));
+
+            graphics.scale((double) width / pgsize.width, (double) height / pgsize.height);
+
+            slide[i].draw(graphics);
+
+            String fname = file.replaceAll("\\.pptx", "-" + (i + 1) + ".png");
+            FileOutputStream out = new FileOutputStream(fname);
+            ImageIO.write(img, "png", out);
+            out.close();
+        }
+        System.out.println("Done");
+    }
+}

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java?rev=1187328&r1=1187327&r2=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXMLSlideShow.java Fri Oct 21 13:17:33 2011
@@ -41,7 +41,6 @@ public class TestXMLSlideShow extends Te
          if(part.getContentType().equals(XSLFRelation.MAIN.getContentType())) {
             found = true;
          }
-         //System.out.println(part);
       }
       assertTrue(found);
    }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java?rev=1187328&r1=1187327&r2=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java Fri Oct 21 13:17:33 2011
@@ -33,11 +33,11 @@ public class TestXSLFAutoShape extends T
         XSLFAutoShape shape = slide.createAutoShape();
         shape.addNewTextParagraph().addNewTextRun().setText("POI");
 
-        // margins
-        assertEquals(-1., shape.getMarginBottom());
-        assertEquals(-1., shape.getMarginTop());
-        assertEquals(-1., shape.getMarginLeft());
-        assertEquals(-1., shape.getMarginRight());
+        // default margins from slide master
+        assertEquals(3.6, shape.getMarginBottom());
+        assertEquals(3.6, shape.getMarginTop());
+        assertEquals(7.2, shape.getMarginLeft());
+        assertEquals(7.2, shape.getMarginRight());
 
         shape.setMarginBottom(1.0);
         assertEquals(1.0, shape.getMarginBottom());
@@ -57,21 +57,22 @@ public class TestXSLFAutoShape extends T
         shape.setMarginRight(0.0);
         assertEquals(0.0, shape.getMarginRight());
 
+        // unset to defauls
         shape.setMarginBottom(-1);
-        assertEquals(-1., shape.getMarginBottom());
+        assertEquals(3.6, shape.getMarginBottom());
         shape.setMarginTop(-1);
-        assertEquals(-1.0, shape.getMarginTop());
+        assertEquals(3.6, shape.getMarginTop());
         shape.setMarginLeft(-1);
-        assertEquals(-1.0, shape.getMarginLeft());
+        assertEquals(7.2, shape.getMarginLeft());
         shape.setMarginRight(-1);
-        assertEquals(-1.0, shape.getMarginRight());
+        assertEquals(7.2, shape.getMarginRight());
 
         // shape
-        assertFalse(shape.getWordWrap());
-        shape.setWordWrap(true);
         assertTrue(shape.getWordWrap());
         shape.setWordWrap(false);
         assertFalse(shape.getWordWrap());
+        shape.setWordWrap(true);
+        assertTrue(shape.getWordWrap());
 
         // shape
         assertEquals(TextAutofit.NORMAL, shape.getTextAutofit());
@@ -209,7 +210,7 @@ public class TestXSLFAutoShape extends T
         assertEquals(1, p.getTextRuns().size());
         assertSame(r, p.getTextRuns().get(0));
 
-        assertEquals(-1.0, r.getFontSize());
+        assertEquals(18.0, r.getFontSize()); // default font size for text boxes
         assertFalse(r.getXmlObject().getRPr().isSetSz());
         r.setFontSize(10.0);
         assertTrue(r.getXmlObject().isSetRPr());
@@ -220,9 +221,9 @@ public class TestXSLFAutoShape extends T
         assertFalse(r.getXmlObject().getRPr().isSetSz());
 
         assertFalse(r.getXmlObject().getRPr().isSetLatin());
-        assertNull(r.getFontFamily());
+        assertEquals("Calibri", r.getFontFamily()); // comes from the slide master
         r.setFontFamily(null);
-        assertNull(r.getFontFamily());
+        assertEquals("Calibri", r.getFontFamily()); // comes from the slide master
         r.setFontFamily("Arial");
         assertEquals("Arial", r.getFontFamily());
         assertEquals("Arial", r.getXmlObject().getRPr().getLatin().getTypeface());
@@ -230,7 +231,7 @@ public class TestXSLFAutoShape extends T
         assertEquals("Symbol", r.getFontFamily());
         assertEquals("Symbol", r.getXmlObject().getRPr().getLatin().getTypeface());
         r.setFontFamily(null);
-        assertNull(r.getFontFamily());
+        assertEquals("Calibri", r.getFontFamily()); // comes from the slide master
         assertFalse(r.getXmlObject().getRPr().isSetLatin());
 
         assertFalse(r.isStrikethrough());

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java?rev=1187328&r1=1187327&r2=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java Fri Oct 21 13:17:33 2011
@@ -21,8 +21,10 @@ import junit.framework.TestCase;
 import org.apache.poi.util.Units;
 import org.apache.poi.xslf.usermodel.LineCap;
 import org.apache.poi.xslf.usermodel.LineDash;
+import org.apache.poi.xslf.XSLFTestDataSamples;
 import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
 import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
 
 import java.awt.*;
 
@@ -129,4 +131,107 @@ public class TestXSLFSimpleShape extends
         assertFalse(shape.getSpPr().isSetSolidFill());
     }
 
+    public void testDefaultProperties() {
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+
+        XSLFSlide slide6 = ppt.getSlides()[5];
+        XSLFShape[] shapes = slide6.getShapes();
+        for(int i = 1; i < shapes.length; i++){
+            XSLFSimpleShape s = (XSLFSimpleShape) shapes[i];
+            // all shapes have a theme color="accent1"
+            assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString());
+            assertEquals(2.0, s.getLineWidth());
+            assertEquals(LineCap.FLAT, s.getLineCap());
+            // YK: calculated color is slightly different from PowerPoint
+            assertEquals(new Color(40, 65, 95), s.getLineColor());
+        }
+
+        XSLFSimpleShape s0 = (XSLFSimpleShape) shapes[0];
+        // fill is not set
+        assertNull(s0.getSpPr().getSolidFill());
+        assertEquals(slide6.getTheme().getColor("accent1").getColor(), s0.getFillColor());
+        assertEquals(new Color(79, 129, 189), s0.getFillColor());
+
+        // lighter 80%
+        XSLFSimpleShape s1 = (XSLFSimpleShape)shapes[1];
+        CTSchemeColor ref1 = s1.getSpPr().getSolidFill().getSchemeClr();
+        assertEquals(1, ref1.sizeOfLumModArray());
+        assertEquals(1, ref1.sizeOfLumOffArray());
+        assertEquals(20000, ref1.getLumModArray(0).getVal());
+        assertEquals(80000, ref1.getLumOffArray(0).getVal());
+        assertEquals("accent1", ref1.getVal().toString());
+        assertEquals(new Color(220, 230, 242), s1.getFillColor());
+
+        // lighter 60%
+        XSLFSimpleShape s2 = (XSLFSimpleShape)shapes[2];
+        CTSchemeColor ref2 = s2.getSpPr().getSolidFill().getSchemeClr();
+        assertEquals(1, ref2.sizeOfLumModArray());
+        assertEquals(1, ref2.sizeOfLumOffArray());
+        assertEquals(40000, ref2.getLumModArray(0).getVal());
+        assertEquals(60000, ref2.getLumOffArray(0).getVal());
+        assertEquals("accent1", ref2.getVal().toString());
+        assertEquals(new Color(185, 205, 229), s2.getFillColor());
+
+        // lighter 40%
+        XSLFSimpleShape s3 = (XSLFSimpleShape)shapes[3];
+        CTSchemeColor ref3 = s3.getSpPr().getSolidFill().getSchemeClr();
+        assertEquals(1, ref3.sizeOfLumModArray());
+        assertEquals(1, ref3.sizeOfLumOffArray());
+        assertEquals(60000, ref3.getLumModArray(0).getVal());
+        assertEquals(40000, ref3.getLumOffArray(0).getVal());
+        assertEquals("accent1", ref3.getVal().toString());
+        assertEquals(new Color(149, 179, 215), s3.getFillColor());
+
+        // darker 25%
+        XSLFSimpleShape s4 = (XSLFSimpleShape)shapes[4];
+        CTSchemeColor ref4 = s4.getSpPr().getSolidFill().getSchemeClr();
+        assertEquals(1, ref4.sizeOfLumModArray());
+        assertEquals(0, ref4.sizeOfLumOffArray());
+        assertEquals(75000, ref4.getLumModArray(0).getVal());
+        assertEquals("accent1", ref3.getVal().toString());
+        // YK: calculated color is slightly different from PowerPoint
+        assertEquals(new Color(59, 97, 142), s4.getFillColor());
+
+        XSLFSimpleShape s5 = (XSLFSimpleShape)shapes[5];
+        CTSchemeColor ref5 = s5.getSpPr().getSolidFill().getSchemeClr();
+        assertEquals(1, ref5.sizeOfLumModArray());
+        assertEquals(0, ref5.sizeOfLumOffArray());
+        assertEquals(50000, ref5.getLumModArray(0).getVal());
+        assertEquals("accent1", ref5.getVal().toString());
+        // YK: calculated color is slightly different from PowerPoint
+        assertEquals(new Color(40, 65, 95), s5.getFillColor());
+    }
+
+    public void testAnchor(){
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+        XSLFSlide[] slide = ppt.getSlides();
+
+        XSLFSlide slide2 = slide[1];
+        XSLFSlideLayout layout2 = slide2.getSlideLayout();
+        XSLFShape[] shapes2 = slide2.getShapes();
+        XSLFTextShape sh1 = (XSLFTextShape)shapes2[0];
+        assertEquals(Placeholder.CENTERED_TITLE, sh1.getTextType());
+        assertEquals("PPTX Title", sh1.getText());
+        assertNull(sh1.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
+        assertEquals(sh1.getAnchor(), layout2.getTextShapeByType(Placeholder.CENTERED_TITLE).getAnchor());
+
+        XSLFTextShape sh2 = (XSLFTextShape)shapes2[1];
+        assertEquals("Subtitle\nAnd second line", sh2.getText());
+        assertEquals(Placeholder.SUBTITLE, sh2.getTextType());
+        assertNull(sh2.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
+        assertEquals(sh2.getAnchor(), layout2.getTextShapeByType(Placeholder.SUBTITLE).getAnchor());
+
+        XSLFSlide slide5 = slide[4];
+        XSLFSlideLayout layout5 = slide5.getSlideLayout();
+        XSLFTextShape shTitle = slide5.getTextShapeByType(Placeholder.TITLE);
+        assertEquals("Hyperlinks", shTitle.getText());
+        // xfrm is not set, the query is delegated to the slide layout
+        assertNull(shTitle.getSpPr().getXfrm());
+        // xfrm is not set, the query is delegated to the slide master
+        assertNull(layout5.getTextShapeByType(Placeholder.TITLE).getSpPr().getXfrm());
+        assertNotNull(layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE).getSpPr().getXfrm());
+        assertEquals(shTitle.getAnchor(), layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE).getAnchor());
+
+    }
+
 }
\ No newline at end of file

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java?rev=1187328&r1=1187327&r2=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java Fri Oct 21 13:17:33 2011
@@ -28,10 +28,10 @@ public class TestXSLFTextBox extends Tes
         XSLFSlide slide = ppt.createSlide();
 
         XSLFTextBox shape = slide.createTextBox();
-        assertNull(shape.getPlaceholder());
+        assertNull(shape.getTextType());
         shape.setPlaceholder(Placeholder.TITLE);
-        assertEquals(Placeholder.TITLE, shape.getPlaceholder());
+        assertEquals(Placeholder.TITLE, shape.getTextType());
         shape.setPlaceholder(null);
-        assertNull(shape.getPlaceholder());
+        assertNull(shape.getTextType());
     }
 }
\ No newline at end of file

Copied: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java (from r1182759, poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java?p2=poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java&p1=poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java&r1=1182759&r2=1187328&rev=1187328&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextBox.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextShape.java Fri Oct 21 13:17:33 2011
@@ -17,21 +17,593 @@
 package org.apache.poi.xslf.usermodel;
 
 import junit.framework.TestCase;
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
+
+import java.awt.*;
 
 /**
  * @author Yegor Kozlov
  */
-public class TestXSLFTextBox extends TestCase {
+public class TestXSLFTextShape extends TestCase {
+
+    public void testLayouts(){
+        XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
+
+        XSLFSlide[] slide = ppt.getSlides();
+
+        verifySlide1(slide[0]);
+        verifySlide2(slide[1]);
+        verifySlide3(slide[2]);
+        verifySlide4(slide[3]);
+        verifySlide7(slide[6]);
+        verifySlide8(slide[7]);
+        verifySlide10(slide[9]);
+    }
+
+    void verifySlide1(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Title Slide",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.CTR_TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
+        assertNotNull(masterShape1.getSpPr().getXfrm());
+        assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Centered Title", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(44.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+        CTPlaceholder ph2 = shape2.getCTPlaceholder();
+        assertEquals(STPlaceholderType.SUB_TITLE, ph2.getType());
+        // anchor is not defined in the shape
+        assertNull(shape2.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
+        assertNotNull(masterShape2.getSpPr().getXfrm());
+        assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
+
+        assertEquals("subtitle", shape2.getText());
+        XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals("Calibri", r2.getFontFamily());
+        assertEquals(32.0, r2.getFontSize());
+        // TODO fix calculation of tint
+        //assertEquals(new Color(137, 137, 137), r2.getFontColor());
+    }
+
+    void verifySlide2(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Title and Content",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
+        // layout does not have anchor info either, it is in the slide master
+        assertNull(masterShape1.getSpPr().getXfrm());
+        masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
+        assertNotNull(masterShape1.getSpPr().getXfrm());
+        assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Title", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(44.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+        CTPlaceholder ph2 = shape2.getCTPlaceholder();
+        assertFalse(ph2.isSetType()); // <p:ph idx="1"/>
+        assertTrue(ph2.isSetIdx());
+        assertEquals(1, ph2.getIdx());
+        // anchor is not defined in the shape
+        assertNull(shape2.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
+        // anchor of the body text is missing in the slide layout, llokup in the slide master
+        assertNull(masterShape2.getSpPr().getXfrm());
+        masterShape2 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph2);
+        assertNotNull(masterShape2.getSpPr().getXfrm());
+        assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
+
+        XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr1.getParentParagraph().getLevel());
+        assertEquals("Content", pr1.getText());
+        assertEquals("Calibri", pr1.getFontFamily());
+        assertEquals(32.0, pr1.getFontSize());
+        assertEquals(27.0, pr1.getParentParagraph().getLeftMargin()); 
+        assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter()); 
+        assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
+        assertEquals(1, pr2.getParentParagraph().getLevel());
+        assertEquals("Level 2", pr2.getText());
+        assertEquals("Calibri", pr2.getFontFamily());
+        assertEquals(28.0, pr2.getFontSize());
+        assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
+        assertEquals(2, pr3.getParentParagraph().getLevel());
+        assertEquals("Level 3", pr3.getText());
+        assertEquals("Calibri", pr3.getFontFamily());
+        assertEquals(24.0, pr3.getFontSize());
+        assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
+        assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
+        assertEquals(3, pr4.getParentParagraph().getLevel());
+        assertEquals("Level 4", pr4.getText());
+        assertEquals("Calibri", pr4.getFontFamily());
+        assertEquals(20.0, pr4.getFontSize());
+        assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
+        assertEquals(4, pr5.getParentParagraph().getLevel());
+        assertEquals("Level 5", pr5.getText());
+        assertEquals("Calibri", pr5.getFontFamily());
+        assertEquals(20.0, pr5.getFontSize());
+        assertEquals(162.0, pr5.getParentParagraph().getLeftMargin());
+        assertEquals("\u00bb", pr5.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
+
+    }
+
+    void verifySlide3(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Section Header",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
+        assertNotNull(masterShape1.getSpPr().getXfrm());
+        assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Section Title", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(40.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+        assertTrue(r1.isBold());
+        assertFalse(r1.isItalic());
+        assertFalse(r1.isUnderline());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+        CTPlaceholder ph2 = shape2.getCTPlaceholder();
+        assertEquals(STPlaceholderType.BODY, ph2.getType());
+        // anchor is not defined in the shape
+        assertNull(shape2.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
+        assertNotNull(masterShape2.getSpPr().getXfrm());
+        assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
+
+        assertEquals("Section Header", shape2.getText());
+        XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r2.getFontFamily());
+        assertEquals(20.0, r2.getFontSize());
+        // TODO fix calculation of tint
+        //assertEquals(new Color(137, 137, 137), r2.getFontColor());
+    }
+
+    void verifySlide4(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Two Content",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
+        // layout does not have anchor info either, it is in the slide master
+        assertNull(masterShape1.getSpPr().getXfrm());
+        masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
+        assertNotNull(masterShape1.getSpPr().getXfrm());
+        assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Title", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(44.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+        CTPlaceholder ph2 = shape2.getCTPlaceholder();
+        assertFalse(ph2.isSetType());
+        assertTrue(ph2.isSetIdx());
+        assertEquals(1, ph2.getIdx());  //<p:ph sz="half" idx="1"/>
+        // anchor is not defined in the shape
+        assertNull(shape2.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
+        assertNotNull(masterShape2.getSpPr().getXfrm());
+        assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
+
+        XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr1.getParentParagraph().getLevel());
+        assertEquals("Left", pr1.getText());
+        assertEquals("Calibri", pr1.getFontFamily());
+        assertEquals(28.0, pr1.getFontSize());
+        assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
+        assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
+        assertEquals(1, pr2.getParentParagraph().getLevel());
+        assertEquals("Level 2", pr2.getParentParagraph().getText());
+        assertEquals("Calibri", pr2.getFontFamily());
+        assertEquals(24.0, pr2.getFontSize());
+        assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
+        assertEquals(2, pr3.getParentParagraph().getLevel());
+        assertEquals("Level 3", pr3.getParentParagraph().getText());
+        assertEquals("Calibri", pr3.getFontFamily());
+        assertEquals(20.0, pr3.getFontSize());
+        assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
+        assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
+        assertEquals(3, pr4.getParentParagraph().getLevel());
+        assertEquals("Level 4", pr4.getParentParagraph().getText());
+        assertEquals("Calibri", pr4.getFontFamily());
+        assertEquals(18.0, pr4.getFontSize());
+        assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
+
+        XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
+        XSLFTextRun pr5 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr5.getParentParagraph().getLevel());
+        assertEquals("Right", pr5.getText());
+        assertEquals("Calibri", pr5.getFontFamily());
+        assertEquals(Color.black, pr5.getFontColor());
+    }
+
+    void verifySlide5(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        // TODO
+    }    
+
+    void verifySlide7(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Blank",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Blank with Default Title", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(44.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+        assertFalse(r1.isBold());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
+
+        XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr1.getParentParagraph().getLevel());
+        assertEquals("Default Text", pr1.getText());
+        assertEquals("Calibri", pr1.getFontFamily());
+        assertEquals(18.0, pr1.getFontSize());
+
+        XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
+        assertEquals("Default", shape3.getTextParagraphs().get(0).getText());
+        assertEquals("Text with levels", shape3.getTextParagraphs().get(1).getText());
+        assertEquals("Level 1", shape3.getTextParagraphs().get(2).getText());
+        assertEquals("Level 2", shape3.getTextParagraphs().get(3).getText());
+        assertEquals("Level 3", shape3.getTextParagraphs().get(4).getText());
+
+        for(int p = 0; p < 5; p++) {
+            XSLFTextParagraph pr = shape3.getTextParagraphs().get(p);
+            assertEquals("Calibri", pr.getTextRuns().get(0).getFontFamily());
+            assertEquals(18.0, pr.getTextRuns().get(0).getFontSize());
+        }
+    }
+
+    void verifySlide8(XSLFSlide slide){
+        XSLFSlideLayout layout = slide.getSlideLayout();
+        XSLFShape[] shapes = slide.getShapes();
+        assertEquals("Content with Caption",layout.getName());
+
+        XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
+        CTPlaceholder ph1 = shape1.getCTPlaceholder();
+        assertEquals(STPlaceholderType.TITLE, ph1.getType());
+        // anchor is not defined in the shape
+        assertNull(shape1.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
+        // layout does not have anchor info either, it is in the slide master
+        assertNotNull(masterShape1.getSpPr().getXfrm());
+        assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
+
+        CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
+                !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
+                !bodyPr1.isSetAnchor()
+        );
+        assertEquals(7.2, shape1.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape1.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape1.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape1.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.BOTTOM, shape1.getVerticalAlignment());
+
+        // now check text properties
+        assertEquals("Caption", shape1.getText());
+        XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(20.0, r1.getFontSize());
+        assertEquals(Color.black, r1.getFontColor());
+        assertTrue(r1.isBold());
+
+        XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
+        CTPlaceholder ph2 = shape2.getCTPlaceholder();
+        assertFalse(ph2.isSetType());
+        assertTrue(ph2.isSetIdx());
+        assertEquals(1, ph2.getIdx());
+        // anchor is not defined in the shape
+        assertNull(shape2.getSpPr().getXfrm());
+
+        XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
+        assertNotNull(masterShape2.getSpPr().getXfrm());
+        assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
+
+        CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
+        // none of the following properties are set in the shapes and fetched from the master shape
+        assertTrue(
+                !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
+                !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
+                !bodyPr2.isSetAnchor()
+        );
+        assertEquals(7.2, shape2.getMarginLeft());  // 0.1"
+        assertEquals(7.2, shape2.getMarginRight()); // 0.1"
+        assertEquals(3.6, shape2.getMarginTop());  // 0.05"
+        assertEquals(3.6, shape2.getMarginBottom()); // 0.05"
+        assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
+
+        XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr1.getParentParagraph().getLevel());
+        assertEquals("Level 1", pr1.getText());
+        assertEquals("Calibri", pr1.getFontFamily());
+        assertEquals(32.0, pr1.getFontSize());
+        assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
+        assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
+        assertEquals(1, pr2.getParentParagraph().getLevel());
+        assertEquals("Level 2", pr2.getParentParagraph().getText());
+        assertEquals("Calibri", pr2.getFontFamily());
+        assertEquals(28.0, pr2.getFontSize());
+        assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
+        assertEquals(2, pr3.getParentParagraph().getLevel());
+        assertEquals("Level 3", pr3.getParentParagraph().getText());
+        assertEquals("Calibri", pr3.getFontFamily());
+        assertEquals(24.0, pr3.getFontSize());
+        assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
+        assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
+
+        XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
+        assertEquals(3, pr4.getParentParagraph().getLevel());
+        assertEquals("Level 4", pr4.getParentParagraph().getText());
+        assertEquals("Calibri", pr4.getFontFamily());
+        assertEquals(20.0, pr4.getFontSize());
+        assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
+        assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
+        assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
+
+        XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
+        assertEquals(VerticalAlignment.TOP, shape3.getVerticalAlignment());
+        assertEquals("Content with caption", shape3.getText());
+
+        pr1 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(0, pr1.getParentParagraph().getLevel());
+        assertEquals("Content with caption", pr1.getText());
+        assertEquals("Calibri", pr1.getFontFamily());
+        assertEquals(14.0, pr1.getFontSize());
+
+    }
+
+    void verifySlide10(XSLFSlide slide){
+        XSLFTextShape footer = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_FTR);
+
+        // now check text properties
+        assertEquals("Apache Software Foundation", footer.getText());
+        assertEquals(VerticalAlignment.MIDDLE, footer.getVerticalAlignment());
+
+        XSLFTextRun r1 = footer.getTextParagraphs().get(0).getTextRuns().get(0);
+        assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
+        assertEquals("Calibri", r1.getFontFamily());
+        assertEquals(12.0, r1.getFontSize());
+        // TODO calculation of tint is incorrect
+        assertEquals(new Color(64,64,64), r1.getFontColor());
+
+        XSLFTextShape dt = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_DT);
+        assertEquals("Friday, October 21, 2011", dt.getText());
 
-    public void testPlaceholder() {
-        XMLSlideShow ppt = new XMLSlideShow();
-        XSLFSlide slide = ppt.createSlide();
-
-        XSLFTextBox shape = slide.createTextBox();
-        assertNull(shape.getPlaceholder());
-        shape.setPlaceholder(Placeholder.TITLE);
-        assertEquals(Placeholder.TITLE, shape.getPlaceholder());
-        shape.setPlaceholder(null);
-        assertNull(shape.getPlaceholder());
+        XSLFTextShape sldNum = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_SLD_NUM);
+        assertEquals("10", sldNum.getText());
     }
 }
\ No newline at end of file

Added: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java?rev=1187328&view=auto
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java (added)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTheme.java Fri Oct 21 13:17:33 2011
@@ -0,0 +1,39 @@
+/* ====================================================================
+   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 junit.framework.TestCase;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+
+/**
+ * test common properties for sheets (slides, masters, layouts, etc.)
+ *
+ * @author Yegor Kozlov
+ */
+public class TestXSLFTheme extends TestCase {
+    public void testRead(){
+        XMLSlideShow ppt = new XMLSlideShow();
+        XSLFSlide slide = ppt.createSlide();
+        XSLFTheme theme = slide.getSlideLayout().getSlideMaster().getTheme();
+        assertNotNull(theme);
+        
+        assertEquals("Office Theme", theme.getName());
+        XSLFColor accent1 = theme.getColor("accent1");
+        assertNotNull(accent1);
+    }
+}



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