Search in sources :

Example 1 with PictureShape

use of org.apache.poi.sl.usermodel.PictureShape in project poi by apache.

the class TestDrawPictureShape method testResize.

public void testResize(String file) throws IOException {
    SlideShow<?, ?> ss = openSampleDocument(file);
    Slide<?, ?> slide = ss.getSlides().get(0);
    PictureShape<?, ?> picShape = null;
    for (Shape<?, ?> shape : slide.getShapes()) {
        if (shape instanceof PictureShape) {
            picShape = (PictureShape<?, ?>) shape;
            break;
        }
    }
    assertNotNull(picShape);
    PictureData pd = picShape.getPictureData();
    Dimension dimPd = pd.getImageDimension();
    new DrawPictureShape(picShape).resize();
    Dimension dimShape = new Dimension((int) picShape.getAnchor().getWidth(), (int) picShape.getAnchor().getHeight());
    assertEquals(dimPd, dimShape);
    double newWidth = (dimPd.getWidth() * (100d / dimPd.getHeight()));
    // ... -1 is a rounding error
    Rectangle2D expRect = new Rectangle2D.Double(rbf(50 + 300 - newWidth, picShape), 50, rbf(newWidth, picShape), 100);
    Rectangle2D target = new Rectangle2D.Double(50, 50, 300, 100);
    new DrawPictureShape(picShape).resize(target, RectAlign.BOTTOM_RIGHT);
    Rectangle2D actRect = picShape.getAnchor();
    assertEquals(expRect.getX(), actRect.getX(), .0001);
    assertEquals(expRect.getY(), actRect.getY(), .0001);
    assertEquals(expRect.getWidth(), actRect.getWidth(), .0001);
    assertEquals(expRect.getHeight(), actRect.getHeight(), .0001);
    ss.close();
}
Also used : PictureShape(org.apache.poi.sl.usermodel.PictureShape) Rectangle2D(java.awt.geom.Rectangle2D) Dimension(java.awt.Dimension) PictureData(org.apache.poi.sl.usermodel.PictureData)

Aggregations

Dimension (java.awt.Dimension)1 Rectangle2D (java.awt.geom.Rectangle2D)1 PictureData (org.apache.poi.sl.usermodel.PictureData)1 PictureShape (org.apache.poi.sl.usermodel.PictureShape)1