I suppose, I missed the concept behind setting anchors on XSLF group shapes:

First I noticed, that when I use grouping to create a PPTX slide show, the PPTX 
looks empty in MS
Powerpoint 2007 in contrast to Libre Office where it looks fine. After some 
investigation, I found
that the PPTX looks fine in MS Powerpoint, when I set an arbitrary anchor on 
the XSLFGroupShape,
e.g. [0,0,1,1]. But now the PPTX seems empty in Libre-Office. After some more 
investigation I came
out with setting an arbitrary anchor AND an interior anchor on the group shape 
lets the PPTX look
fine in MS Powerpoint 2007 AND Libre Office.

Now my questions:

1) Shouldn't a PPTX created by the XSLF high-level API (only), look the same in 
MS Powerpoint 2007
and Libre Office?
2) Shouldn't the anchors of a group computed implicitely from the anchors of 
their children?
3) What do I miss, how to use group anchors correctly?

I have attached a small self-contained test class which describes the behaviour 
from above in for
cases:

1) Test cases 1 and 4 (with no anchor at all or with both the anchor and the 
interior anchor set)
look fine in Libre Office while test cases 2 and 3 (with either the anchor or 
the interior anchor
set) do not.
2) Test cases 2 and 4 (with at least the anchor set) look fine in MS Powerpoint 
2007 while test
cases 1 and 3 (without the regular anchor set) do not.

Fortunately test case 4 looks fine in MS Powerpoint as well as Libre Office, 
but I would prefer to
understand, why, instead of ending up with the outcome of trial and error.

Thanks in advance for any comment on this,
Frank-Michael
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.TextAutofit;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFGroupShape;
import org.apache.poi.xslf.usermodel.XSLFShapeContainer;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTextBox;

public class XSLFGroupingTester {

        static XSLFTextBox createText(XSLFShapeContainer container, String 
text, Rectangle2D r) {
                XSLFTextBox box = container.createTextBox();
                box.setAnchor(r);
                box.setText(text);
                box.setTextAutofit(TextAutofit.NORMAL);
                return box;
        }

        static XMLSlideShow createSlideShow(boolean createAnchor, boolean 
createInteriorAnchor) {
                XMLSlideShow ppt = new XMLSlideShow();
                XSLFSlide slide = ppt.createSlide();
                XSLFGroupShape group = slide.createGroup();

                if (createAnchor) {
                        group.setAnchor(new Rectangle(0, 0, 1, 1));
                }

                if (createInteriorAnchor) {
                        group.setInteriorAnchor(new Rectangle(0, 0, 1, 1));
                }

                createText(group, "A", new Rectangle(10, 11, 40, 50));
                createText(group, "B", new Rectangle(100, 101, 75, 90));

                return ppt;
        }

        public static void main(String[] args) throws IOException {
                System.out.println(new File(".").getAbsolutePath());
                createSlideShow(false, false).write(new 
FileOutputStream("test1-no-anchor-no-interioranchor.pptx"));
                createSlideShow(true, false).write(new 
FileOutputStream("test2-with-anchor-no-interioranchor.pptx"));
                createSlideShow(false, true).write(new 
FileOutputStream("test3-no-anchor-with-interioranchor.pptx"));
                createSlideShow(true, true).write(new 
FileOutputStream("test4-with-anchor-with-interioranchor.pptx"));
        }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to