screenshotHeight = (int) ((float) screenshotWidth / (float) style.getWidth() * style.getHeight());
}
// Create the renderer. Due to a synchronization bug in the software,
// this needs to be synchronized
Java2DRenderer renderer = null;
try {
synchronized (this) {
renderer = new Java2DRenderer(xhtmlFile, screenshotWidth, screenshotHeight);
}
} catch (Throwable t) {
if (isRenderingEnvironmentSane) {
logger.warn("Error creating Java 2D renderer for previews: {}" + t.getMessage());
logger.warn("Page preview rendering will be switched off");
isRenderingEnvironmentSane = false;
}
logger.debug("Error creating Java 2D renderer for preview of page {}: {}" + uri.getPath(), t.getMessage());
return;
}
// Configure the renderer
renderer.getSharedContext().setBaseURL(site.getHostname().toExternalForm());
renderer.getSharedContext().setInteractive(false);
// Make sure the renderer is using a user agent that will correctly
// resolve urls
WebloungeUserAgent agent = userAgents.get(site.getIdentifier());
if (agent == null) {
agent = new WebloungeUserAgent(site.getHostname().getURL());
userAgents.put(site.getIdentifier(), agent);
}
renderer.getSharedContext().setUserAgentCallback(agent);
// Render the page to an image
BufferedImage img = renderer.getImage();
FSImageWriter imageWriter = new FSImageWriter(PREVIEW_FORMAT);
imageFos = new FileOutputStream(imageFile);
imageWriter.write(img, imageFos);
} catch (IOException e) {