private int calcCenteredPageLeftOffset(int maxPageWidth) {
return (getWidth() - maxPageWidth) / 2;
}
public void paintPage(Graphics2D g, int pageNo) {
Layer root = getRootLayer();
if (root == null) {
throw new RuntimeException("Document needs layout");
}
if (pageNo < 0 || pageNo >= root.getPages().size()) {
throw new IllegalArgumentException("Page " + pageNo + " is not between 0 " +
"and " + root.getPages().size());
}
RenderingContext c = newRenderingContext(g);
PageBox page = (PageBox)root.getPages().get(pageNo);
c.setPageCount(root.getPages().size());
c.setPage(pageNo, page);
page.paintBackground(c, 0, Layer.PAGED_MODE_PRINT);
page.paintMarginAreas(c, 0, Layer.PAGED_MODE_PRINT);
page.paintBorder(c, 0, Layer.PAGED_MODE_PRINT);
Shape working = g.getClip();
Rectangle content = page.getPrintClippingBounds(c);
g.clip(content);
int top = -page.getPaintingTop() +
page.getMarginBorderPadding(c, CalculatedStyle.TOP);
int left = page.getMarginBorderPadding(c, CalculatedStyle.LEFT);
g.translate(left, top);
root.paint(c);
g.translate(-left, -top);
g.setClip(working);
}