28package com.jogamp.opengl.test.junit.jogl.tile;
30import java.awt.Container;
31import java.awt.Graphics;
32import java.awt.Graphics2D;
33import java.awt.Insets;
34import java.awt.RenderingHints;
35import java.awt.print.PageFormat;
36import java.awt.print.Paper;
37import java.awt.print.Printable;
38import java.awt.print.PrinterException;
39import java.awt.print.PrinterJob;
41import com.jogamp.common.util.awt.AWTEDTExecutor;
42import com.jogamp.opengl.util.TileRenderer;
79 public int print(
final Graphics g,
final PageFormat pf,
final int page)
throws PrinterException {
86 final Paper paper = pf.getPaper();
87 final double paperWWidthInch = paper.getWidth() / 72.0;
88 final double paperWHeightInch = paper.getHeight() / 72.0;
89 final double paperIWidthInch = paper.getImageableWidth() / 72.0;
90 final double paperIHeightInch = paper.getImageableHeight() / 72.0;
91 final double paperWWidthMM = paperWWidthInch *
MM_PER_INCH;
92 final double paperWHeightMM = paperWHeightInch *
MM_PER_INCH;
93 final double paperIWidthMM = paperIWidthInch *
MM_PER_INCH;
94 final double paperIHeightMM = paperIHeightInch *
MM_PER_INCH;
96 final double pfWWidthInch = pf.getWidth() / 72.0;
97 final double pfWHeightInch = pf.getHeight() / 72.0;
98 final double pfIWidthInch = pf.getImageableWidth() / 72.0;
99 final double pfIHeightInch = pf.getImageableHeight() / 72.0;
100 final double pfWWidthMM = pfWWidthInch *
MM_PER_INCH;
101 final double pfWHeightMM = pfWHeightInch *
MM_PER_INCH;
102 final double pfIWidthMM = pfIWidthInch *
MM_PER_INCH;
103 final double pfIHeightMM = pfIHeightInch *
MM_PER_INCH;
105 System.err.println(
"PF: Paper whole size "+
106 Math.round(paperWWidthMM)+
" x "+Math.round(paperWHeightMM)+
" mm, "+
107 Math.round(paperWWidthInch)+
" x "+Math.round(paperWHeightInch)+
" inch");
109 System.err.println(
"PF: Paper image size "+paper.getImageableX()+
" / "+paper.getImageableY()+
" "+
110 Math.round(paperIWidthMM)+
" x "+Math.round(paperIHeightMM)+
" mm, "+
111 Math.round(paperIWidthInch)+
" x "+Math.round(paperIHeightInch)+
" inch, "+
112 Math.round(paper.getImageableWidth())+
"x"+Math.round(paper.getImageableHeight())+
" 72dpi dots");
114 System.err.println(
"PF: Page whole size "+
115 Math.round(pfWWidthMM)+
" x "+Math.round(pfWHeightMM)+
" mm, "+
116 Math.round(pfWWidthInch)+
" x "+Math.round(pfWHeightInch)+
" inch");
118 System.err.println(
"PF: Page image size "+pf.getImageableX()+
" / "+pf.getImageableY()+
" "+
119 Math.round(pfIWidthMM)+
" x "+Math.round(pfIHeightMM)+
" mm, "+
120 Math.round(pfIWidthInch)+
" x "+Math.round(pfIHeightInch)+
" inch, "+
121 Math.round(pf.getImageableWidth())+
"x"+Math.round(pf.getImageableHeight())+
" 72dpi dots");
123 System.err.println(
"PF: Page orientation "+pf.getOrientation());
129 final Insets frameInsets =
cont.getInsets();
130 final int frameWidth =
cont.getWidth();
131 final int frameHeight=
cont.getHeight();
132 final double scaleGraphics =
dpi / 72.0;
133 final int frameSWidth = (int) ( frameWidth * scaleGraphics );
134 final int frameSHeight = (int) ( frameHeight * scaleGraphics );
135 final double scaleComp72;
137 final double sx = pf.getImageableWidth() / frameWidth;
138 final double sy = pf.getImageableHeight() / frameHeight;
139 scaleComp72 = Math.min(sx, sy);
141 System.err.println(
"PRINT.onscrn thread "+Thread.currentThread().getName());
142 System.err.println(
"PRINT.onscrn DPI: scaleGraphics "+scaleGraphics+
", scaleComp72 "+scaleComp72);
143 System.err.println(
"PRINT.onscrn DPI: frame: border "+frameInsets+
", size "+frameWidth+
"x"+frameHeight+
144 " -> scaled "+frameSWidth+
"x" + frameSHeight);
146 final Graphics2D g2d = (Graphics2D)g;
147 System.err.println(
"PRINT at.pre: "+g2d.getTransform());
148 g2d.translate(pf.getImageableX(), pf.getImageableY());
149 g2d.scale(scaleComp72, scaleComp72);
151 g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
153 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
int print(final Graphics g, final PageFormat pf, final int page)
OnscreenPrintable(final PrinterJob job, final Container printContainer, final int printDPI, final int numSamples, final int tileWidth, final int tileHeight)
Base Printable implementation class.
final RecursiveLock lockPrinting
static final double MM_PER_INCH