< prev index next >
src/java.desktop/share/classes/sun/print/PSPrinterJob.java
Print this page
*** 66,75 ****
--- 66,76 ----
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Destination;
import javax.print.attribute.standard.DialogTypeSelection;
import javax.print.attribute.standard.JobName;
import javax.print.attribute.standard.Sides;
+ import javax.print.attribute.standard.MediaPrintableArea;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.CharConversionException;
*** 487,496 ****
--- 488,583 ----
}
return doPrint;
}
+ @Override
+ protected void validatePaper(Paper origPaper, Paper newPaper) {
+ if (origPaper == null || newPaper == null) {
+ return;
+ } else {
+ double wid = origPaper.getWidth();
+ double hgt = origPaper.getHeight();
+ double ix = origPaper.getImageableX();
+ double iy = origPaper.getImageableY();
+ double iw = origPaper.getImageableWidth();
+ double ih = origPaper.getImageableHeight();
+ double imgX, imgY, imgWid, imgHgt;
+
+ /*
+ * this returns the imageable area of default media of chosen printer
+ * from CUPS via CUPSPrinter#getPageSizes().
+ * If it returns null (which should not be the case) we fall back
+ * to default Paper (Letter in US, A4 otherwise) imageable area
+ */
+ MediaPrintableArea mpa = (MediaPrintableArea)
+ getPrintService().getDefaultAttributeValue(MediaPrintableArea.class);
+ if (mpa != null) {
+ imgX = mpa.getX(MediaPrintableArea.INCH) * 72;
+ imgY = mpa.getY(MediaPrintableArea.INCH) * 72;
+ imgWid = mpa.getWidth(MediaPrintableArea.INCH) * 72;
+ imgHgt = mpa.getHeight(MediaPrintableArea.INCH) * 72;
+ } else {
+ imgX = newPaper.getImageableX();
+ imgY = newPaper.getImageableY();
+ imgWid = newPaper.getImageableWidth();
+ imgHgt = newPaper.getImageableHeight();
+ }
+
+ wid = ((wid > 0.0) ? wid : newPaper.getWidth());
+ hgt = ((hgt > 0.0) ? hgt : newPaper.getHeight());
+ if ((imgX*2) + imgWid > wid) {
+ imgWid = wid - imgX*2;
+ }
+ if ((imgY*2) + imgHgt > hgt) {
+ imgHgt = hgt - imgY*2;
+ }
+
+ /* We try to mitigate the effects of floating point rounding errors
+ * by only setting a value if it would differ from the value in the
+ * target by at least 0.10 points = 1/720 inches.
+ * eg if the values present in the target are close to the calculated
+ * values then we accept the target.
+ */
+ final double epsilon = 0.10;
+
+ if (ix < 0.0) {
+ ix = 0.0;
+ }
+ if (iy < 0.0) {
+ iy = 0.0;
+ }
+ if (iw < 0.0) {
+ iw = 0.0;
+ }
+ if (ih < 0.0) {
+ ih = 0.0;
+ }
+ if ((ix + epsilon) < imgX) {
+ ix = imgX;
+ }
+ if ((iy + epsilon) < imgY) {
+ iy = imgY;
+ }
+ if (iw + epsilon > imgWid) {
+ iw = imgWid;
+ }
+ if (ih + epsilon > imgHgt) {
+ ih = imgHgt;
+ }
+ if ((ix + iw + epsilon) > (imgX + imgWid)) {
+ ix = (imgX + imgWid) - iw;
+ }
+ if ((iy + ih + epsilon) > (imgY + imgHgt)) {
+ iy = (imgY + imgHgt) - ih;
+ }
+
+ newPaper.setSize(wid, hgt);
+ newPaper.setImageableArea(ix, iy, iw, ih);
+ }
+ }
+
/**
* Invoked by the RasterPrinterJob super class
* this method is called to mark the start of a
* document.
*/
< prev index next >