Thank you for taking the time to upload your example to our bugzilla - see #61112
The transparent parts of the image can be replaced as described in Stripping Alpha Channel from Images, of course you need to use the ARGB color model first.
I've added the Arial Unicode font to the example, but you probably need a different font which covers all the used characters.
Complete example:
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.junit.Test;
public class TestRendering {
@Test
public void bug61112() throws Exception {
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("arialuni.ttf"));
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
SlideShow<?,?> ppt = SlideShowFactory.create(new File("bug61112.ppt"), null, true);
double scale = 1;
Dimension pgsize = ppt.getPageSize();
int width = (int) (pgsize.width * scale);
int height = (int) (pgsize.height * scale);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics();
DrawFactory.getInstance(graphics).fixFonts(graphics);
// default rendering options
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);
Map<String,String> fallbackMap = new HashMap<String,String>();
fallbackMap.put("*", font.getFamily());
graphics.setRenderingHint(Drawable.FONT_FALLBACK, fallbackMap);
ppt.getSlides().get(0).draw(graphics);
// Replace the transparent parts of the image
// Set composite rules to paint "behind"
graphics.setComposite(AlphaComposite.DstOver);
graphics.setPaint(Color.WHITE);
graphics.fillRect(0, 0, width, height);
ImageIO.write(img, "PNG", new File("bla.png"));
graphics.dispose();
img.flush();
}
}