public int print( Graphics graphics, PageFormat format, int index ) {
Graphics2D g2d = (Graphics2D)graphics;
double scalex = g2d.getTransform().getScaleX();
double scaley = g2d.getTransform().getScaleY();
double centerx = ( format.getImageableX() +
( format.getImageableWidth() / 2 ) ) * scalex;
double centery = ( format.getImageableY() +
( format.getImageableHeight() / 2 ) ) * scaley;
// The following 2 lines cause an error when printing in landscape.
g2d.scale( 1 / scalex, 1 / scaley );
g2d.translate( centerx, centery );
Path2D.Double path = new Path2D.Double();
path.moveTo( -scalex * 72, -scaley * 72 );
path.lineTo( -scalex * 72, scaley * 72 );
path.lineTo( scalex * 72, scaley * 72 );
path.lineTo( scalex * 72, -scaley * 72 );
path.closePath();
g2d.draw( path );
return index == 0 ? PAGE_EXISTS : NO_SUCH_PAGE;
}
LandscapeStackOverflow.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:openjdk-jdk10
作者:
评论列表
文章目录