use of org.apache.poi.hssf.usermodel.DummyGraphics2d in project poi by apache.
the class TestBugs method bug57796.
@Test
public void bug57796() throws IOException {
HSLFSlideShow ppt = open("WithLinks.ppt");
HSLFSlide slide = ppt.getSlides().get(0);
HSLFTextShape shape = (HSLFTextShape) slide.getShapes().get(1);
List<HSLFHyperlink> hlList = HSLFHyperlink.find(shape);
HSLFHyperlink hlShape = hlList.get(0);
HSLFTextRun r = shape.getTextParagraphs().get(1).getTextRuns().get(0);
HSLFHyperlink hlRun = r.getHyperlink();
assertEquals(hlRun.getId(), hlShape.getId());
assertEquals(hlRun.getAddress(), hlShape.getAddress());
assertEquals(hlRun.getLabel(), hlShape.getLabel());
assertEquals(hlRun.getTypeEnum(), hlShape.getTypeEnum());
assertEquals(hlRun.getStartIndex(), hlShape.getStartIndex());
assertEquals(hlRun.getEndIndex(), hlShape.getEndIndex());
OutputStream nullOutput = new OutputStream() {
@Override
public void write(int b) throws IOException {
}
};
final boolean[] found = { false };
DummyGraphics2d dgfx = new DummyGraphics2d(new PrintStream(nullOutput)) {
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// For the test file, common sl draws textruns one by one and not mixed
// so we evaluate the whole iterator
Map<Attribute, Object> attributes = null;
StringBuffer sb = new StringBuffer();
for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next()) {
sb.append(c);
attributes = iterator.getAttributes();
}
if ("Jakarta HSSF".equals(sb.toString())) {
// this is a test for a manually modified ppt, for real hyperlink label
// one would need to access the screen tip record
String href = (String) attributes.get(DrawTextParagraph.HYPERLINK_HREF);
String label = (String) attributes.get(DrawTextParagraph.HYPERLINK_LABEL);
assertEquals("http://jakarta.apache.org/poi/hssf/", href);
assertEquals("Open Jakarta POI HSSF module test ", label);
found[0] = true;
}
}
};
ppt.getSlides().get(1).draw(dgfx);
assertTrue(found[0]);
ppt.close();
}
use of org.apache.poi.hssf.usermodel.DummyGraphics2d in project poi by apache.
the class TestPicture method bug54541.
@Test
@Ignore("Just for visual validation - antialiasing is different on various systems")
public void bug54541() throws IOException, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
String[] files = { // "54541_cropped_bitmap2.ppt",
"alterman_security.ppt" };
BitSet pages = new BitSet();
pages.set(2);
for (String file : files) {
InputStream is = _slTests.openResourceAsStream(file);
SlideShow<?, ?> ss;
if (file.endsWith("pptx")) {
Class<?> cls = Class.forName("org.apache.poi.xslf.usermodel.XMLSlideShow");
Constructor<?> ct = cls.getDeclaredConstructor(InputStream.class);
ss = (SlideShow<?, ?>) ct.newInstance(is);
} else {
ss = new HSLFSlideShow(is);
}
is.close();
boolean debugOut = false;
Dimension pg = ss.getPageSize();
for (Slide<?, ?> slide : ss.getSlides()) {
int slideNo = slide.getSlideNumber();
if (!pages.get(slideNo - 1)) {
if (pages.nextSetBit(slideNo - 1) == -1)
break;
else
continue;
}
if (debugOut) {
DummyGraphics2d graphics = new DummyGraphics2d();
slide.draw(graphics);
} else {
BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
DrawFactory.getInstance(graphics).fixFonts(graphics);
slide.draw(graphics);
graphics.setColor(Color.BLACK);
graphics.setStroke(new BasicStroke(1));
graphics.drawRect(0, 0, (int) pg.getWidth() - 1, (int) pg.getHeight() - 1);
ImageIO.write(img, "PNG", new File(file.replaceFirst(".pptx?", "-") + slideNo + ".png"));
}
}
ss.close();
}
}
Aggregations