use of org.apache.poi.sl.usermodel.PictureData in project poi by apache.
the class TestXSLFBugs method bug59434.
@Test
public void bug59434() throws IOException {
String url1 = "http://poi.apache.org/changes.html";
String url2 = "http://poi.apache.org/faq.html";
XMLSlideShow ppt1 = new XMLSlideShow();
PictureData pd1 = ppt1.addPicture(slTests.readFile("tomcat.png"), PictureType.PNG);
PictureData pd2 = ppt1.addPicture(slTests.readFile("santa.wmf"), PictureType.WMF);
XSLFSlide slide = ppt1.createSlide();
XSLFPictureShape ps1 = slide.createPicture(pd1);
ps1.setAnchor(new Rectangle2D.Double(20, 20, 100, 100));
XSLFHyperlink hl1 = ps1.createHyperlink();
hl1.linkToUrl(url1);
XSLFPictureShape ps2 = slide.createPicture(pd2);
ps2.setAnchor(new Rectangle2D.Double(120, 120, 100, 100));
XSLFHyperlink hl2 = ps2.createHyperlink();
hl2.linkToUrl(url2);
XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt1.close();
slide = ppt2.getSlides().get(0);
ps1 = (XSLFPictureShape) slide.getShapes().get(0);
ps2 = (XSLFPictureShape) slide.getShapes().get(1);
assertEquals(url1, ps1.getHyperlink().getAddress());
assertEquals(url2, ps2.getHyperlink().getAddress());
ppt2.close();
}
use of org.apache.poi.sl.usermodel.PictureData in project poi by apache.
the class SlideShowHandler method readPictures.
private void readPictures(SlideShow<?, ?> ss) {
for (PictureData pd : ss.getPictureData()) {
Dimension dim = pd.getImageDimension();
assertTrue(dim.getHeight() >= 0);
assertTrue(dim.getWidth() >= 0);
}
}
use of org.apache.poi.sl.usermodel.PictureData in project poi by apache.
the class DrawPictureShape method drawContent.
@Override
public void drawContent(Graphics2D graphics) {
PictureData data = getShape().getPictureData();
if (data == null)
return;
Rectangle2D anchor = getAnchor(graphics, getShape());
Insets insets = getShape().getClipping();
try {
ImageRenderer renderer = getImageRenderer(graphics, data.getContentType());
renderer.loadImage(data.getData(), data.getContentType());
renderer.drawImage(graphics, anchor, insets);
} catch (IOException e) {
LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e);
}
}
use of org.apache.poi.sl.usermodel.PictureData 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();
}
use of org.apache.poi.sl.usermodel.PictureData in project poi by apache.
the class TestHwmfParsing method fetchWmfFromGovdocs.
@Test
@Ignore("This is work-in-progress and not a real unit test ...")
public void fetchWmfFromGovdocs() throws IOException {
URL url = new URL("http://digitalcorpora.org/corpora/files/govdocs1/by_type/ppt.zip");
File outdir = new File("build/ppt");
outdir.mkdirs();
ZipInputStream zis = new ZipInputStream(url.openStream());
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
String basename = ze.getName().replaceAll(".*?([^/]+)\\.wmf", "$1");
FilterInputStream fis = new FilterInputStream(zis) {
@Override
public void close() throws IOException {
}
};
try {
SlideShow<?, ?> ss = SlideShowFactory.create(fis);
int wmfIdx = 1;
for (PictureData pd : ss.getPictureData()) {
if (pd.getType() != PictureType.WMF)
continue;
byte[] wmfData = pd.getData();
String filename = String.format(Locale.ROOT, "%s-%04d.wmf", basename, wmfIdx);
FileOutputStream fos = new FileOutputStream(new File(outdir, filename));
fos.write(wmfData);
fos.close();
wmfIdx++;
}
ss.close();
} catch (Exception e) {
System.out.println(ze.getName() + " ignored.");
}
}
}
Aggregations