/**
* Examine the metrics captured by the
* {@code PeekGraphics} instance and
* if capable of directly converting this
* print job to the printer's control language
* or the native OS's graphics primitives, then
* return a {@code PathGraphics} to perform
* that conversion. If there is not an object
* capable of the conversion then return
* {@code null}. Returning {@code null}
* causes the print job to be rasterized.
*/
@Override
protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
PrinterJob printerJob,
Printable painter,
PageFormat pageFormat,
int pageIndex) {
WPathGraphics pathGraphics;
PeekMetrics metrics = peekGraphics.getMetrics();
/* If the application has drawn anything that
* out PathGraphics class can not handle then
* return a null PathGraphics. If the property
* to force the raster pipeline has been set then
* we also want to avoid the path (pdl) pipeline
* and return null.
*/
if (forcePDL == false && (forceRaster == true
|| metrics.hasNonSolidColors()
|| metrics.hasCompositing()
)) {
pathGraphics = null;
} else {
BufferedImage bufferedImage = new BufferedImage(8, 8,
BufferedImage.TYPE_INT_RGB);
Graphics2D bufferedGraphics = bufferedImage.createGraphics();
boolean canRedraw = peekGraphics.getAWTDrawingOnly() == false;
pathGraphics = new WPathGraphics(bufferedGraphics, printerJob,
painter, pageFormat, pageIndex,
canRedraw);
}
return pathGraphics;
}
java类java.awt.print.Printable的实例源码
WPrinterJob.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
PathGraphics.java 文件源码
项目:jdk8u-jdk
阅读 35
收藏 0
点赞 0
评论 0
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
Printable painter, PageFormat pageFormat,
int pageIndex, boolean canRedraw) {
super(graphics, printerJob);
mPainter = painter;
mPageFormat = pageFormat;
mPageIndex = pageIndex;
mCanRedraw = canRedraw;
}
ImagePrinter.java 文件源码
项目:jdk8u-jdk
阅读 32
收藏 0
点赞 0
评论 0
public int print(Graphics g, PageFormat pf, int index) {
if (index > 0 || image == null) {
return Printable.NO_SUCH_PAGE;
}
((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
int w = image.getWidth(null);
int h = image.getHeight(null);
int iw = (int)pf.getImageableWidth();
int ih = (int)pf.getImageableHeight();
// ensure image will fit
int dw = w;
int dh = h;
if (dw > iw) {
dh = (int)(dh * ( (float) iw / (float) dw)) ;
dw = iw;
}
if (dh > ih) {
dw = (int)(dw * ( (float) ih / (float) dh)) ;
dh = ih;
}
// centre on page
int dx = (iw - dw) / 2;
int dy = (ih - dh) / 2;
g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
return Printable.PAGE_EXISTS;
}
PSPrinterJob.java 文件源码
项目:jdk8u-jdk
阅读 28
收藏 0
点赞 0
评论 0
/**
* The RastePrintJob super class calls this method
* at the end of each page.
*/
protected void endPage(PageFormat format, Printable painter,
int index)
throws PrinterException
{
mPSStream.println(PAGE_RESTORE);
mPSStream.println(SHOWPAGE);
}
PSPrinterJob.java 文件源码
项目:jdk8u-jdk
阅读 28
收藏 0
点赞 0
评论 0
/**
* Examine the metrics captured by the
* <code>PeekGraphics</code> instance and
* if capable of directly converting this
* print job to the printer's control language
* or the native OS's graphics primitives, then
* return a <code>PSPathGraphics</code> to perform
* that conversion. If there is not an object
* capable of the conversion then return
* <code>null</code>. Returning <code>null</code>
* causes the print job to be rasterized.
*/
protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
PrinterJob printerJob,
Printable painter,
PageFormat pageFormat,
int pageIndex) {
PSPathGraphics pathGraphics;
PeekMetrics metrics = peekGraphics.getMetrics();
/* If the application has drawn anything that
* out PathGraphics class can not handle then
* return a null PathGraphics.
*/
if (forcePDL == false && (forceRaster == true
|| metrics.hasNonSolidColors()
|| metrics.hasCompositing())) {
pathGraphics = null;
} else {
BufferedImage bufferedImage = new BufferedImage(8, 8,
BufferedImage.TYPE_INT_RGB);
Graphics2D bufferedGraphics = bufferedImage.createGraphics();
boolean canRedraw = peekGraphics.getAWTDrawingOnly() == false;
pathGraphics = new PSPathGraphics(bufferedGraphics, printerJob,
painter, pageFormat, pageIndex,
canRedraw);
}
return pathGraphics;
}
PSPrinterJob.java 文件源码
项目:jdk8u-jdk
阅读 26
收藏 0
点赞 0
评论 0
public int print(Graphics g, PageFormat pf, int pgIndex) {
if (pgIndex > 0) {
return Printable.NO_SUCH_PAGE;
} else {
// "aware" client code can detect that its been passed a
// PrinterGraphics and could theoretically print
// differently. I think this is more likely useful than
// a problem.
applet.printAll(g);
return Printable.PAGE_EXISTS;
}
}
PSPrinterJob.java 文件源码
项目:jdk8u-jdk
阅读 30
收藏 0
点赞 0
评论 0
public Printable getPrintable(int pgIndex) {
if (pgIndex > 0) {
throw new IndexOutOfBoundsException("pgIndex");
} else {
return printable;
}
}
bug8023392.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
public int print(Graphics graphics,
PageFormat pageFormat,
int pageIndex)
throws PrinterException {
if (pageIndex >= 1) {
return Printable.NO_SUCH_PAGE;
}
this.paint(graphics);
return Printable.PAGE_EXISTS;
}
WPrinterJob.java 文件源码
项目:jdk8u-jdk
阅读 22
收藏 0
点赞 0
评论 0
/**
* Examine the metrics captured by the
* <code>PeekGraphics</code> instance and
* if capable of directly converting this
* print job to the printer's control language
* or the native OS's graphics primitives, then
* return a <code>PathGraphics</code> to perform
* that conversion. If there is not an object
* capable of the conversion then return
* <code>null</code>. Returning <code>null</code>
* causes the print job to be rasterized.
*/
@Override
protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
PrinterJob printerJob,
Printable painter,
PageFormat pageFormat,
int pageIndex) {
WPathGraphics pathGraphics;
PeekMetrics metrics = peekGraphics.getMetrics();
/* If the application has drawn anything that
* out PathGraphics class can not handle then
* return a null PathGraphics. If the property
* to force the raster pipeline has been set then
* we also want to avoid the path (pdl) pipeline
* and return null.
*/
if (forcePDL == false && (forceRaster == true
|| metrics.hasNonSolidColors()
|| metrics.hasCompositing()
)) {
pathGraphics = null;
} else {
BufferedImage bufferedImage = new BufferedImage(8, 8,
BufferedImage.TYPE_INT_RGB);
Graphics2D bufferedGraphics = bufferedImage.createGraphics();
boolean canRedraw = peekGraphics.getAWTDrawingOnly() == false;
pathGraphics = new WPathGraphics(bufferedGraphics, printerJob,
painter, pageFormat, pageIndex,
canRedraw);
}
return pathGraphics;
}
ImageableAreaTest.java 文件源码
项目:jdk8u-jdk
阅读 22
收藏 0
点赞 0
评论 0
private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(
0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}")
);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}