use of com.xenoage.zong.renderer.awt.canvas.AwtCanvas in project Zong by Xenoage.
the class PdfPrinter method print.
/**
* Prints the given {@link Layout} into the given PDF output stream.
*/
public static void print(Layout layout, OutputStream out) {
Document document = new Document();
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(document, out);
} catch (Exception e) {
handle(warning(Voc.ErrorWhilePrinting));
}
document.open();
PdfContentByte cb = writer.getDirectContent();
It<Page> pages = it(layout.getPages());
for (Page page : pages) {
// create PDF page
Size2f pageSize = page.getFormat().getSize();
float width = Units.mmToPx(pageSize.width, 1);
float height = Units.mmToPx(pageSize.height, 1);
document.newPage();
PdfTemplate tp = cb.createTemplate(width, height);
// fill PDF page
Graphics2D g2d = new PdfGraphics2D(cb, width, height);
INSTANCE.log(Companion.remark("Printing page " + pages.getIndex() + "..."));
LayoutRenderer.paintToCanvas(layout, pages.getIndex(), new AwtCanvas(g2d, pageSize, CanvasFormat.Vector, CanvasDecoration.None, CanvasIntegrity.Perfect));
// finish page
g2d.dispose();
cb.addTemplate(tp, 0, 0);
}
document.close();
}
use of com.xenoage.zong.renderer.awt.canvas.AwtCanvas in project Zong by Xenoage.
the class PrintProcess method print.
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
// valid page number?
if (pageIndex < 0 || pageIndex >= layout.getPages().size()) {
return Printable.NO_SUCH_PAGE;
}
// print page
INSTANCE.log(Companion.remark("Printing page " + pageIndex + "..."));
Graphics2D g2d = (Graphics2D) g;
Size2f pageSize = layout.getPages().get(pageIndex).getFormat().getSize();
LayoutRenderer.paintToCanvas(layout, pageIndex, new AwtCanvas(g2d, pageSize, CanvasFormat.Vector, CanvasDecoration.None, CanvasIntegrity.Perfect));
return Printable.PAGE_EXISTS;
}
use of com.xenoage.zong.renderer.awt.canvas.AwtCanvas in project Zong by Xenoage.
the class AwtLayoutRenderer method paintToImage.
/**
* Returns a {@link BufferedImage} with the given page of the given {@link Layout}
* which is rendered at the given zoom level.
*/
public static BufferedImage paintToImage(Layout layout, int pageIndex, float zoom) {
Page page = layout.getPages().get(pageIndex);
Size2f pageSize = page.getFormat().getSize();
int width = Units.mmToPxInt(pageSize.width, zoom);
int height = Units.mmToPxInt(pageSize.height, zoom);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);
LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin, new AwtCanvas(g2d, pageSize, CanvasFormat.Raster, CanvasDecoration.Interactive, CanvasIntegrity.Perfect));
g2d.dispose();
return img;
}
Aggregations